Skip to content

Commit c372793

Browse files
committed
refactoring
1 parent 23a2f6f commit c372793

25 files changed

+104
-120
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private void createTargetFolder() throws IOException {
415415
final boolean targetExists = target.isDirectory();
416416

417417
if (context.isClearTarget() && targetExists) {
418-
this.context.logForVerbose("Cleaining target folder: " + target);
418+
this.context.logForVerbose("Cleaning target folder: " + target);
419419
try {
420420
FileUtils.cleanDirectory(target);
421421
} catch (IOException ex) {

jcp/src/main/java/com/igormaznitsa/jcp/cmdline/CommandLineHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.igormaznitsa.jcp.context.PreprocessorContext;
2525

2626
/**
27-
* The interface describes a command line key handler. It is not just a handler
27+
* The interface describes a command line key handler. It is not just a handler,
2828
* but it will be called for all met keys to recognize one to be processed.
2929
*
3030
* @author Igor Maznitsa (igor.maznitsa@igormaznitsa.com)

jcp/src/main/java/com/igormaznitsa/jcp/cmdline/GlobalVariableHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* The handler for global variables, it adds met global variables into the
32-
* inside storage
32+
* internal storage
3333
*
3434
* @author Igor Maznitsa (igor.maznitsa@igormaznitsa.com)
3535
*/

jcp/src/main/java/com/igormaznitsa/jcp/cmdline/RemoveCommentsHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import com.igormaznitsa.jcp.context.PreprocessorContext;
2626

2727
/**
28-
* The handler processing the flag to clear all sources in the destination
29-
* directory from inside comments
28+
* Processes the flag that clears all source files from the destination directory, stripping them even from within comments.
3029
*
3130
* @author Igor Maznitsa (igor.maznitsa@igormaznitsa.com)
3231
*/
@@ -36,7 +35,7 @@ public class RemoveCommentsHandler implements CommandLineHandler {
3635

3736
@Override
3837
public String getDescription() {
39-
return "strip all comments from output files";
38+
return "strip all comments in result files";
4039
}
4140

4241
@Override

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import static com.igormaznitsa.jcp.removers.AbstractCommentRemover.makeCommentRemover;
2525
import static com.igormaznitsa.jcp.utils.IOUtils.closeQuietly;
26-
import static com.igormaznitsa.jcp.utils.PreprocessorUtils.findFirstActiveFileContainer;
26+
import static com.igormaznitsa.jcp.utils.PreprocessorUtils.findActiveFileInfoContainer;
2727
import static java.util.Objects.requireNonNull;
2828
import static java.util.Objects.requireNonNullElse;
2929

@@ -160,16 +160,20 @@ public String getLastReadString() {
160160
return this.lastReadString;
161161
}
162162

163-
public void pushExcludeIfData(final FileInfoContainer infoContainer,
164-
final String excludeIfCondition, final int stringIndex) {
163+
public void pushExcludeIfData(
164+
final FileInfoContainer infoContainer,
165+
final String excludeIfCondition,
166+
final int stringIndex
167+
) {
165168
requireNonNull(infoContainer, "File info is null");
166169
requireNonNull(excludeIfCondition, "Condition is null");
167170

168171
if (stringIndex < 0) {
169172
throw new IllegalArgumentException("Unexpected string index [" + stringIndex + ']');
170173
}
171174

172-
deferredExcludeStack.push(new ExcludeIfInfo(infoContainer, excludeIfCondition, stringIndex));
175+
this.deferredExcludeStack.push(
176+
new ExcludeIfInfo(infoContainer, excludeIfCondition, stringIndex));
173177
}
174178

175179
public ResettablePrinter getSelectedPrinter() {
@@ -296,11 +300,6 @@ public boolean isIncludeStackEmpty() {
296300
return includeStack.isEmpty();
297301
}
298302

299-
public boolean isOnlyRootOnStack() {
300-
return includeStack.size() == 1;
301-
}
302-
303-
304303
private TextFileDataContainer cloneTopTextDataContainer() {
305304
final TextFileDataContainer topElement = requireNonNull(includeStack.peek());
306305
return new TextFileDataContainer(topElement,
@@ -553,7 +552,7 @@ public boolean saveBuffersToFile(final File outFile, final CommentRemoverType ke
553552
}
554553

555554
if (wasSaved) {
556-
findFirstActiveFileContainer(context).ifPresent(t -> t.getGeneratedResources().add(outFile));
555+
findActiveFileInfoContainer(context).ifPresent(t -> t.getGeneratedResources().add(outFile));
557556
if (this.context.isKeepAttributes() && outFile.exists()) {
558557
PreprocessorUtils.copyFileAttributes(this.getRootFileInfo().getSourceFile(), outFile);
559558
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void logWarning(final String text) {
506506
}
507507

508508
/**
509-
* Set a shared source, it is an object saved into the inside map for a name
509+
* Set a shared source, it is an object saved into the internal map for a name
510510
*
511511
* @param name the name for the saved project, must not be null
512512
* @param obj the object to be saved in, must not be null
@@ -519,7 +519,7 @@ public void setSharedResource(final String name, final Object obj) {
519519
}
520520

521521
/**
522-
* Get a shared source from inside map
522+
* Get a shared source from internal map
523523
*
524524
* @param name the name of the needed object, it must not be null
525525
* @return a cached object or null if it is not found
@@ -531,7 +531,7 @@ public Object getSharedResource(final String name) {
531531
}
532532

533533
/**
534-
* Remove a shared object from the inside map for its name
534+
* Remove a shared object from the internal map for its name
535535
*
536536
* @param name the object name, it must not be null
537537
* @return removing object or null if it is not found
@@ -754,7 +754,7 @@ public boolean containsLocalVariable(final String name) {
754754
}
755755

756756
/**
757-
* Remove all local variables from the inside storage
757+
* Remove all local variables from the internal storage
758758
*
759759
* @return this preprocessor context
760760
*/
@@ -812,10 +812,10 @@ public PreprocessorContext setGlobalVariable(final String name, final Value valu
812812
}
813813

814814
/**
815-
* Check that there is a named global variable in the inside storage
815+
* Check that there is a named global variable in the internal storage
816816
*
817817
* @param name the checking name, it will be normalized to the supported format, it can be null
818-
* @return true if such variable is presented for its name in the inside storage, otherwise false (also it is false if the name is null)
818+
* @return true if such variable is presented for its name in the internal storage, otherwise false (also it is false if the name is null)
819819
*/
820820
public boolean containsGlobalVariable(final String name) {
821821
if (name == null) {

jcp/src/main/java/com/igormaznitsa/jcp/directives/ActionDirectiveHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ public AfterDirectiveProcessingBehaviour execute(final String string,
8383
null);
8484
}
8585

86-
final Value[] results = new Value[args.size()];
86+
final Value[] argValues = new Value[args.size()];
8787
int index = 0;
8888
for (final ExpressionTree expr : args) {
8989
final Value val = Expression.evalTree(expr, context);
90-
results[index++] = val;
90+
argValues[index++] = val;
9191
}
9292

93-
if (!extension.processAction(context, results)) {
93+
if (!extension.processAction(context, argValues)) {
9494
throw context.makeException("Unable to process an action", null);
9595
}
9696
} catch (IOException ex) {

jcp/src/main/java/com/igormaznitsa/jcp/directives/ExcludeIfDirectiveHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
package com.igormaznitsa.jcp.directives;
2323

24+
import static java.util.Objects.requireNonNull;
25+
2426
import com.igormaznitsa.jcp.context.PreprocessingState;
2527
import com.igormaznitsa.jcp.context.PreprocessorContext;
26-
import java.util.Objects;
2728

2829
/**
2930
* The class implements the //#excludeif directive handler
@@ -62,7 +63,7 @@ public AfterDirectiveProcessingBehaviour execute(final String string,
6263
final PreprocessorContext context) {
6364
final PreprocessingState state = context.getPreprocessingState();
6465
state.pushExcludeIfData(state.getRootFileInfo(), string,
65-
Objects.requireNonNull(state.peekIncludeStackFile(), "'IF' stack is empty!")
66+
requireNonNull(state.peekIncludeStackFile(), "'IF' stack is empty!")
6667
.getLastReadStringIndex());
6768
return AfterDirectiveProcessingBehaviour.PROCESSED;
6869
}

jcp/src/main/java/com/igormaznitsa/jcp/directives/FlushDirectiveHandler.java

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

2222
package com.igormaznitsa.jcp.directives;
2323

24-
import static com.igormaznitsa.jcp.utils.PreprocessorUtils.findFirstActiveFileContainer;
24+
import static com.igormaznitsa.jcp.utils.PreprocessorUtils.findActiveFileInfoContainer;
2525

2626
import com.igormaznitsa.jcp.context.PreprocessingState;
2727
import com.igormaznitsa.jcp.context.PreprocessorContext;
@@ -62,7 +62,7 @@ public AfterDirectiveProcessingBehaviour execute(final String string,
6262
"Content was " + (saved ? "saved" : "not saved") + " into file '" + outFile + "'");
6363
}
6464

65-
findFirstActiveFileContainer(context)
65+
findActiveFileInfoContainer(context)
6666
.ifPresent(f -> f.getGeneratedResources().add(outFile));
6767

6868
state.resetPrinters();

jcp/src/main/java/com/igormaznitsa/jcp/directives/IncludeDirectiveHandler.java

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

2222
package com.igormaznitsa.jcp.directives;
2323

24-
import static com.igormaznitsa.jcp.utils.PreprocessorUtils.findFirstActiveFileContainer;
24+
import static com.igormaznitsa.jcp.utils.PreprocessorUtils.findActiveFileInfoContainer;
2525

2626
import com.igormaznitsa.jcp.context.PreprocessingState;
2727
import com.igormaznitsa.jcp.context.PreprocessorContext;
@@ -67,7 +67,7 @@ public AfterDirectiveProcessingBehaviour execute(final String string,
6767
}
6868
state.openFile(fileToInclude);
6969

70-
findFirstActiveFileContainer(context)
70+
findActiveFileInfoContainer(context)
7171
.ifPresent(f -> f.getIncludedSources().add(fileToInclude));
7272
} catch (IOException ex) {
7373
throw context.makeException("Can't open file '" + filePath + '\'', ex);

0 commit comments

Comments
 (0)