Skip to content

Commit 253b9b4

Browse files
committed
refactoring
1 parent 70e5fbd commit 253b9b4

11 files changed

Lines changed: 24 additions & 82 deletions

File tree

jcp/pom.xml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -575,26 +575,6 @@
575575
</configuration>
576576
</plugin>
577577

578-
<plugin>
579-
<groupId>org.codehaus.mojo</groupId>
580-
<artifactId>animal-sniffer-maven-plugin</artifactId>
581-
<configuration>
582-
<signature>
583-
<groupId>org.codehaus.mojo.signature</groupId>
584-
<artifactId>java18</artifactId>
585-
<version>1.0</version>
586-
</signature>
587-
</configuration>
588-
<executions>
589-
<execution>
590-
<id>check-java-api</id>
591-
<phase>test</phase>
592-
<goals>
593-
<goal>check</goal>
594-
</goals>
595-
</execution>
596-
</executions>
597-
</plugin>
598578
</plugins>
599579
</build>
600580

jcp/src/main/java/com/igormaznitsa/jcp/InfoHelper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ private static String makeColumns(final String name, final String reference,
215215
final int firstColumnWidth) {
216216
final int spaces = firstColumnWidth - name.length();
217217
final StringBuilder result = new StringBuilder(name);
218-
for (int i = 0; i < spaces; i++) {
219-
result.append(' ');
220-
}
218+
result.append(" ".repeat(Math.max(0, spaces)));
221219
result.append(reference);
222220
return result.toString();
223221
}

jcp/src/main/java/com/igormaznitsa/jcp/context/PreprocessorContext.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
package com.igormaznitsa.jcp.context;
2323

24-
import static java.util.Arrays.asList;
2524
import static java.util.Collections.singletonList;
26-
import static java.util.Collections.unmodifiableList;
2725

2826
import com.igormaznitsa.jcp.containers.FileInfoContainer;
2927
import com.igormaznitsa.jcp.containers.TextFileDataContainer;
@@ -68,7 +66,7 @@ public class PreprocessorContext {
6866
Collections.singletonList("." + File.separatorChar);
6967
public static final String DEFAULT_DEST_DIRECTORY = ".." + File.separatorChar + "preprocessed";
7068
public static final List<String> DEFAULT_PROCESSING_EXTENSIONS =
71-
unmodifiableList(asList("java", "txt", "htm", "html"));
69+
List.of("java", "txt", "htm", "html");
7270
public static final List<String> DEFAULT_EXCLUDED_EXTENSIONS = singletonList("xml");
7371
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
7472

@@ -233,9 +231,7 @@ private static String makeStackView(
233231
final StringBuilder builder = new StringBuilder();
234232
int tab = 5;
235233

236-
for (int s = 0; s < tab; s++) {
237-
builder.append(' ');
238-
}
234+
builder.append(" ".repeat(tab));
239235

240236
builder.append('{');
241237
if (cloned) {
@@ -251,9 +247,7 @@ private static String makeStackView(
251247
for (int i = list.size() - 1; i >= 0; i--) {
252248
final TextFileDataContainer cur = list.get(i);
253249
builder.append('\n');
254-
for (int s = 0; s < tab; s++) {
255-
builder.append(' ');
256-
}
250+
builder.append(" ".repeat(Math.max(0, tab)));
257251
builder.append("└>");
258252
builder.append(fileIndex++).append(". ");
259253
builder.append(cur.getFile().getName()).append(':').append(cur.getLastReadStringIndex() + 1);
@@ -281,8 +275,7 @@ private static Charset decodeCharset(final String charsetName) {
281275
* @since 7.0.3
282276
*/
283277
public Set<File> findAllInputFiles() {
284-
final Set<File> result = new HashSet<>();
285-
result.addAll(this.configFiles);
278+
final Set<File> result = new HashSet<>(this.configFiles);
286279
this.preprocessedResources.forEach(x -> {
287280
result.addAll(x.getIncludedSources());
288281
if (x.getSourceFile() != null &&

jcp/src/main/java/com/igormaznitsa/jcp/exceptions/PreprocessorException.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ private static String makeStackView(final FilePositionInfo[] list, final char fi
5353
final StringBuilder builder = new StringBuilder();
5454
int tab = 5;
5555

56-
for (int s = 0; s < tab; s++) {
57-
builder.append(fill);
58-
}
56+
builder.append(String.valueOf(fill).repeat(tab));
5957
builder.append("{File chain}");
6058
tab += 5;
6159

6260
int fileIndex = 1;
6361
for (int i = list.length - 1; i >= 0; i--) {
6462
final FilePositionInfo cur = list[i];
6563
builder.append('\n');
66-
for (int s = 0; s < tab; s++) {
67-
builder.append(fill);
68-
}
64+
builder.append(String.valueOf(fill).repeat(Math.max(0, tab)));
6965
builder.append("└>");
7066
builder.append(fileIndex++).append(". ");
7167
builder.append(cur.getFile().getName()).append(':').append(cur.getLineNumber());

jcp/src/main/java/com/igormaznitsa/jcp/expression/ExpressionParser.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
package com.igormaznitsa.jcp.expression;
2323

24+
import static java.util.Objects.requireNonNullElseGet;
25+
2426
import com.igormaznitsa.jcp.context.PreprocessingState;
2527
import com.igormaznitsa.jcp.context.PreprocessorContext;
2628
import com.igormaznitsa.jcp.exceptions.FilePositionInfo;
@@ -610,11 +612,7 @@ ExpressionItem nextItem(final PushbackReader reader, final PreprocessorContext c
610612
result = Value.BOOLEAN_FALSE;
611613
} else {
612614
final AbstractFunction function = AbstractFunction.findForName(str);
613-
if (function == null) {
614-
result = new Variable(str);
615-
} else {
616-
result = function;
617-
}
615+
result = requireNonNullElseGet(function, () -> new Variable(str));
618616
}
619617
}
620618
break;

jcp/src/main/java/com/igormaznitsa/jcp/expression/functions/FunctionSTR2GO.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ private static String toUnicode(final char c) {
4242
final StringBuilder result = new StringBuilder(4);
4343
final String hex = Integer.toHexString(c);
4444

45-
for (int i = 0; i < 4 - hex.length(); i++) {
46-
result.append('0');
47-
}
45+
result.append("0".repeat(4 - hex.length()));
4846

4947
result.append(hex);
5048

jcp/src/main/java/com/igormaznitsa/jcp/extension/PreprocessorExtension.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ public interface PreprocessorExtension {
4343
*/
4444
boolean processAction(PreprocessorContext context, Value[] parameters);
4545

46-
/**
47-
* Call to process a user function (the function starts with $)
48-
*
49-
* @param functionName the name of the function (without $ and in low case),
50-
* must not be null
51-
* @param arguments the function arguments as an array, must not be null
52-
* @return a calculated value, it must not be null
53-
* @see #processUserFunction(PreprocessorContext, String, Value[])
54-
* @deprecated since 7.1.2
55-
*/
56-
@Deprecated
57-
default Value processUserFunction(String functionName, Value[] arguments) {
58-
throw new UnsupportedOperationException("Use version with PreprocessorContext for call");
59-
}
60-
6146
/**
6247
* Call to process a user function (such functions start with $)
6348
*
@@ -66,13 +51,10 @@ default Value processUserFunction(String functionName, Value[] arguments) {
6651
* must not be null
6752
* @param arguments the function arguments as an array, must not be null
6853
* @return a calculated value, it must not be null
69-
* @see #processUserFunction(String, Value[])
7054
* @since 7.1.2
7155
*/
72-
default Value processUserFunction(PreprocessorContext context, String functionName,
73-
Value[] arguments) {
74-
return this.processUserFunction(functionName, arguments);
75-
}
56+
Value processUserFunction(PreprocessorContext context, String functionName,
57+
Value[] arguments);
7658

7759
/**
7860
* When a preprocessor meets a user defined function (the function starts with

jcp/src/main/java/com/igormaznitsa/jcp/utils/AntPathMatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static String[] tokenizeToStringArray(
4848
if (trimTokens) {
4949
token = token.trim();
5050
}
51-
if (!ignoreEmptyTokens || token.length() > 0) {
51+
if (!ignoreEmptyTokens || !token.isEmpty()) {
5252
tokens.add(token);
5353
}
5454
}
@@ -204,7 +204,7 @@ private boolean isPotentialMatch(String path, String[] pattDirs) {
204204
pos += skipped;
205205
skipped = skipSegment(path, pos, pattDir);
206206
if (skipped < pattDir.length()) {
207-
return (skipped > 0 || (pattDir.length() > 0 && isWildcardChar(pattDir.charAt(0))));
207+
return (skipped > 0 || (!pattDir.isEmpty() && isWildcardChar(pattDir.charAt(0))));
208208
}
209209
pos += skipped;
210210
}

jcp/src/main/java/com/igormaznitsa/jcp/utils/PreprocessorUtils.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ public static String replacePartByChar(final String text, final char chr, final
237237
final StringBuilder result = new StringBuilder(text.length());
238238

239239
result.append(text.subSequence(0, Math.min(text.length(), startPosition)));
240-
for (int i = startPosition; i < Math.min(text.length(), startPosition + length); i++) {
241-
result.append(chr);
242-
}
240+
result.append(String.valueOf(chr)
241+
.repeat(Math.max(0, Math.min(text.length(), startPosition + length) - startPosition)));
243242
result.append(text.subSequence(Math.min(startPosition + length, text.length()), text.length()));
244243

245244
return result.toString();
@@ -248,9 +247,7 @@ public static String replacePartByChar(final String text, final char chr, final
248247

249248
public static String generateStringForChar(final char chr, final int length) {
250249
final StringBuilder buffer = new StringBuilder(Math.max(length, 1));
251-
for (int i = 0; i < length; i++) {
252-
buffer.append(chr);
253-
}
250+
buffer.append(String.valueOf(chr).repeat(Math.max(0, length)));
254251
return buffer.toString();
255252
}
256253

jcp/src/test/java/com/igormaznitsa/jcp/context/PreprocessorContextTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,20 @@ public void warning(String message) {
254254
@Override
255255
public boolean processAction(PreprocessorContext context, Value[] parameters) {
256256
throw new UnsupportedOperationException(
257-
"Not supported yet."); //To change body of generated methods, choose Tools | Templates.
257+
"Not supported yet.");
258258
}
259259

260260
@Override
261-
public Value processUserFunction(String functionName, Value[] arguments) {
261+
public Value processUserFunction(PreprocessorContext context, String functionName,
262+
Value[] arguments) {
262263
throw new UnsupportedOperationException(
263-
"Not supported yet."); //To change body of generated methods, choose Tools | Templates.
264+
"Not supported yet.");
264265
}
265266

266267
@Override
267268
public int getUserFunctionArity(String functionName) {
268269
throw new UnsupportedOperationException(
269-
"Not supported yet."); //To change body of generated methods, choose Tools | Templates.
270+
"Not supported yet.");
270271
}
271272
};
272273

0 commit comments

Comments
 (0)