Skip to content

Commit b14a940

Browse files
committed
Polishing
1 parent 4ecbf65 commit b14a940

11 files changed

+89
-83
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ plugins {
22
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
33
id 'io.spring.ge.conventions' version '0.0.7'
44
id 'io.spring.nohttp' version '0.0.5.RELEASE'
5-
id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
5+
id "io.freefair.aspectj" version '4.1.6' apply false
66
id 'org.jetbrains.dokka' version '0.10.1' apply false
7+
id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
78
id 'org.asciidoctor.jvm.convert' version '2.4.0'
89
id 'org.asciidoctor.jvm.pdf' version '2.4.0'
9-
id 'de.undercouch.download' version '4.1.1'
10-
id "io.freefair.aspectj" version '4.1.6' apply false
1110
id "com.github.ben-manes.versions" version '0.28.0'
1211
id 'com.gradle.build-scan' version '3.2'
12+
id 'de.undercouch.download' version '4.1.1'
1313
}
1414

1515
apply from: "$rootDir/gradle/build-scan-user-data.gradle"

spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,24 +83,29 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
8383
}
8484

8585
private String pathToString(int fromSegment, List<Element> pathElements) {
86-
StringBuilder buf = new StringBuilder();
86+
StringBuilder sb = new StringBuilder();
8787
for (int i = fromSegment, max = pathElements.size(); i < max; i++) {
8888
Element element = pathElements.get(i);
8989
if (element instanceof PathSegment) {
90-
buf.append(((PathSegment)element).valueToMatch());
90+
sb.append(((PathSegment)element).valueToMatch());
9191
}
9292
else {
93-
buf.append(element.value());
93+
sb.append(element.value());
9494
}
9595
}
96-
return buf.toString();
96+
return sb.toString();
9797
}
9898

9999
@Override
100100
public int getNormalizedLength() {
101101
return 1;
102102
}
103103

104+
@Override
105+
public char[] getChars() {
106+
return ("/{*" + this.variableName + "}").toCharArray();
107+
}
108+
104109
@Override
105110
public int getWildcardCount() {
106111
return 0;
@@ -117,8 +122,4 @@ public String toString() {
117122
return "CaptureTheRest(/{*" + this.variableName + "})";
118123
}
119124

120-
@Override
121-
public char[] getChars() {
122-
return ("/{*"+this.variableName+"}").toCharArray();
123-
}
124125
}

spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ class CaptureVariablePathElement extends PathElement {
3535
private final String variableName;
3636

3737
@Nullable
38-
private Pattern constraintPattern;
38+
private final Pattern constraintPattern;
3939

4040

4141
/**
@@ -55,6 +55,7 @@ class CaptureVariablePathElement extends PathElement {
5555
if (colon == -1) {
5656
// no constraint
5757
this.variableName = new String(captureDescriptor, 1, captureDescriptor.length - 2);
58+
this.constraintPattern = null;
5859
}
5960
else {
6061
this.variableName = new String(captureDescriptor, 1, colon - 1);
@@ -134,6 +135,18 @@ public int getNormalizedLength() {
134135
return 1;
135136
}
136137

138+
@Override
139+
public char[] getChars() {
140+
StringBuilder sb = new StringBuilder();
141+
sb.append('{');
142+
sb.append(this.variableName);
143+
if (this.constraintPattern != null) {
144+
sb.append(':').append(this.constraintPattern.pattern());
145+
}
146+
sb.append('}');
147+
return sb.toString().toCharArray();
148+
}
149+
137150
@Override
138151
public int getWildcardCount() {
139152
return 0;
@@ -156,16 +169,4 @@ public String toString() {
156169
(this.constraintPattern != null ? ":" + this.constraintPattern.pattern() : "") + "})";
157170
}
158171

159-
@Override
160-
public char[] getChars() {
161-
StringBuilder b = new StringBuilder();
162-
b.append("{");
163-
b.append(this.variableName);
164-
if (this.constraintPattern != null) {
165-
b.append(":").append(this.constraintPattern.pattern());
166-
}
167-
b.append("}");
168-
return b.toString().toCharArray();
169-
}
170-
171172
}

spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,14 +26,15 @@
2626
* literal path elements 'foo', 'bar' and 'goo'.
2727
*
2828
* @author Andy Clement
29+
* @since 5.0
2930
*/
3031
class LiteralPathElement extends PathElement {
3132

32-
private char[] text;
33+
private final char[] text;
3334

34-
private int len;
35+
private final int len;
3536

36-
private boolean caseSensitive;
37+
private final boolean caseSensitive;
3738

3839

3940
public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, char separator) {
@@ -69,7 +70,7 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
6970
return false;
7071
}
7172

72-
char[] data = ((PathContainer.PathSegment)element).valueToMatchAsChars();
73+
char[] data = ((PathContainer.PathSegment) element).valueToMatchAsChars();
7374
if (this.caseSensitive) {
7475
for (int i = 0; i < this.len; i++) {
7576
if (data[i] != this.text[i]) {

spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -332,18 +332,18 @@ public PathContainer extractPathWithinPattern(PathContainer path) {
332332
PathContainer resultPath = null;
333333
if (multipleAdjacentSeparators) {
334334
// Need to rebuild the path without the duplicate adjacent separators
335-
StringBuilder buf = new StringBuilder();
335+
StringBuilder sb = new StringBuilder();
336336
int i = startIndex;
337337
while (i < endIndex) {
338338
Element e = pathElements.get(i++);
339-
buf.append(e.value());
339+
sb.append(e.value());
340340
if (e instanceof Separator) {
341341
while (i < endIndex && (pathElements.get(i) instanceof Separator)) {
342342
i++;
343343
}
344344
}
345345
}
346-
resultPath = PathContainer.parsePath(buf.toString(), this.pathOptions);
346+
resultPath = PathContainer.parsePath(sb.toString(), this.pathOptions);
347347
}
348348
else if (startIndex >= endIndex) {
349349
resultPath = PathContainer.parsePath("");
@@ -487,13 +487,13 @@ String toChainString() {
487487
* @return the string form of the pattern
488488
*/
489489
String computePatternString() {
490-
StringBuilder buf = new StringBuilder();
490+
StringBuilder sb = new StringBuilder();
491491
PathElement pe = this.head;
492492
while (pe != null) {
493-
buf.append(pe.getChars());
493+
sb.append(pe.getChars());
494494
pe = pe.next;
495495
}
496-
return buf.toString();
496+
return sb.toString();
497497
}
498498

499499
@Nullable

spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,14 +66,14 @@ public String getMessage() {
6666
* with a pointer to the error position, as well as the error message.
6767
*/
6868
public String toDetailedString() {
69-
StringBuilder buf = new StringBuilder();
70-
buf.append(this.pattern).append('\n');
69+
StringBuilder sb = new StringBuilder();
70+
sb.append(this.pattern).append('\n');
7171
for (int i = 0; i < this.position; i++) {
72-
buf.append(' ');
72+
sb.append(' ');
7373
}
74-
buf.append("^\n");
75-
buf.append(getMessage());
76-
return buf.toString();
74+
sb.append("^\n");
75+
sb.append(getMessage());
76+
return sb.toString();
7777
}
7878

7979
public int getPosition() {

spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,19 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
136136
if (matches) {
137137
if (isNoMorePattern()) {
138138
if (matchingContext.determineRemainingPath &&
139-
(this.variableNames.isEmpty() || textToMatch.length() > 0)) {
139+
(this.variableNames.isEmpty() || textToMatch.length() > 0)) {
140140
matchingContext.remainingPathIndex = pathIndex + 1;
141141
matches = true;
142142
}
143143
else {
144144
// No more pattern, is there more data?
145145
// If pattern is capturing variables there must be some actual data to bind to them
146-
matches = (pathIndex + 1) >= matchingContext.pathLength
147-
&& (this.variableNames.isEmpty() || textToMatch.length() > 0);
146+
matches = (pathIndex + 1 >= matchingContext.pathLength) &&
147+
(this.variableNames.isEmpty() || textToMatch.length() > 0);
148148
if (!matches && matchingContext.isMatchOptionalTrailingSeparator()) {
149-
matches = (this.variableNames.isEmpty()
150-
|| textToMatch.length() > 0)
151-
&& (pathIndex + 2) >= matchingContext.pathLength
152-
&& matchingContext.isSeparator(pathIndex + 1);
149+
matches = (this.variableNames.isEmpty() || textToMatch.length() > 0) &&
150+
(pathIndex + 2 >= matchingContext.pathLength) &&
151+
matchingContext.isSeparator(pathIndex + 1);
153152
}
154153
}
155154
}
@@ -160,11 +159,11 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
160159

161160
if (matches && matchingContext.extractingVariables) {
162161
// Process captures
163-
if (this.variableNames.size() != matcher.groupCount()) { // SPR-8455
164-
throw new IllegalArgumentException("The number of capturing groups in the pattern segment "
165-
+ this.pattern + " does not match the number of URI template variables it defines, "
166-
+ "which can occur if capturing groups are used in a URI template regex. "
167-
+ "Use non-capturing groups instead.");
162+
if (this.variableNames.size() != matcher.groupCount()) { // SPR-8455
163+
throw new IllegalArgumentException("The number of capturing groups in the pattern segment " +
164+
this.pattern + " does not match the number of URI template variables it defines, " +
165+
"which can occur if capturing groups are used in a URI template regex. " +
166+
"Use non-capturing groups instead.");
168167
}
169168
for (int i = 1; i <= matcher.groupCount(); i++) {
170169
String name = this.variableNames.get(i - 1);
@@ -187,6 +186,11 @@ public int getNormalizedLength() {
187186
return (this.regex.length - varsLength - this.variableNames.size());
188187
}
189188

189+
@Override
190+
public char[] getChars() {
191+
return this.regex;
192+
}
193+
190194
@Override
191195
public int getCaptureCount() {
192196
return this.variableNames.size();
@@ -208,8 +212,4 @@ public String toString() {
208212
return "Regex(" + String.valueOf(this.regex) + ")";
209213
}
210214

211-
@Override
212-
public char[] getChars() {
213-
return this.regex;
214-
}
215215
}

spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,13 +63,14 @@ public int getNormalizedLength() {
6363
}
6464

6565
@Override
66-
public String toString() {
67-
return "Separator(" + this.separator + ")";
66+
public char[] getChars() {
67+
return new char[] {this.separator};
6868
}
6969

70+
7071
@Override
71-
public char[] getChars() {
72-
return new char[] {this.separator};
72+
public String toString() {
73+
return "Separator(" + this.separator + ")";
7374
}
7475

7576
}

spring-web/src/main/java/org/springframework/web/util/pattern/SingleCharWildcardedPathElement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
7474
return false;
7575
}
7676

77-
char[] data = ((PathSegment)element).valueToMatchAsChars();
77+
char[] data = ((PathSegment) element).valueToMatchAsChars();
7878
if (this.caseSensitive) {
7979
for (int i = 0; i < this.len; i++) {
8080
char ch = this.text[i];
@@ -125,15 +125,15 @@ public int getNormalizedLength() {
125125
return this.len;
126126
}
127127

128-
129128
@Override
130-
public String toString() {
131-
return "SingleCharWildcarded(" + String.valueOf(this.text) + ")";
129+
public char[] getChars() {
130+
return this.text;
132131
}
133132

133+
134134
@Override
135-
public char[] getChars() {
136-
return this.text;
135+
public String toString() {
136+
return "SingleCharWildcarded(" + String.valueOf(this.text) + ")";
137137
}
138138

139139
}

spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -86,6 +86,11 @@ public int getNormalizedLength() {
8686
return 1;
8787
}
8888

89+
@Override
90+
public char[] getChars() {
91+
return new char[] {'*'};
92+
}
93+
8994
@Override
9095
public int getWildcardCount() {
9196
return 1;
@@ -102,8 +107,4 @@ public String toString() {
102107
return "Wildcard(*)";
103108
}
104109

105-
@Override
106-
public char[] getChars() {
107-
return new char[] {'*'};
108-
}
109110
}

0 commit comments

Comments
 (0)