Skip to content

Commit

Permalink
replace 'measure' with 'action' in descriptions of rule options (SAP#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgrassau committed Jun 10, 2023
1 parent aca32c5 commit e1a09b5
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ final String getSummary(boolean wereMultipleFilesProcessed) {
continue;
if (entryCount > 1)
result.append(" - in " + Cult.format(countOfSeverities[i]) + (countOfSeverities[i] == 1 ? " case " : " cases "));
String measure;
String action;
switch (ExceptionSeverity.forValue(i)) {
case S0_STOP_COMMAND:
measure = "a command was skipped due to unexpected syntax";
action = "a command was skipped due to unexpected syntax";
break;
case S1_STOP_RULE:
measure = "the execution of a rule was stopped";
action = "the execution of a rule was stopped";
break;
case S2_STOP_TASK:
measure = (wereMultipleFilesProcessed ? "the cleanup was cancelled" : "the cleanup of a code file was cancelled");
action = (wereMultipleFilesProcessed ? "the cleanup was cancelled" : "the cleanup of a code file was cancelled");
break;
case S3_STOP_JOB:
measure = "the whole operation was cancelled";
action = "the whole operation was cancelled";
break;
default:
throw new IndexOutOfBoundsException();
}
result.append(measure).append(System.lineSeparator());
result.append(action).append(System.lineSeparator());
}
return result.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String getExample() {
final ConfigEnumValue<ChangeType> configContinueAfterMethodName = new ConfigEnumValue<ChangeType>(this, "ContinueAfterMethodName", "Continue line after method name", changeTypeSelection, ChangeType.KEEP_AS_IS);
final ConfigEnumValue<ChangeType> configContinueAfterAccess = new ConfigEnumValue<ChangeType>(this, "ContinueAfterAccess", "Continue line after IMPORTING etc.", changeTypeSelection, ChangeType.ALWAYS);
final ConfigIntValue configFillPercentageToJustifyOwnColumn = new ConfigIntValue(this, "FillPercentageToJustifyOwnColumn", "Fill ratio to justify own column for DEFAULT / OPTIONAL", "%", 1, 40, 100);
final ConfigEnumValue<MethodsOneLinerMeasure> configHandleOneLiners = new ConfigEnumValue<MethodsOneLinerMeasure>(this, "HandleOneLiners", "Handling of (potential) one-liners", handleOneLinersSelection, MethodsOneLinerMeasure.KEEP_EXISTING);
final ConfigEnumValue<MethodsOneLinerAction> configHandleOneLiners = new ConfigEnumValue<MethodsOneLinerAction>(this, "HandleOneLiners", "Handling of (potential) one-liners", handleOneLinersSelection, MethodsOneLinerAction.KEEP_EXISTING);
final ConfigEnumValue<MethodsSequenceAlignment> configAlignConsecutive = new ConfigEnumValue<MethodsSequenceAlignment>(this, "AlignConsecutive", "Align consecutive declarations", alignConsecutiveSelection, MethodsSequenceAlignment.ONE_LINERS, MethodsSequenceAlignment.NEVER, LocalDate.of(2022, 6, 5));
final ConfigBoolValue configSeparateWithEmptyLine = new ConfigBoolValue(this, "SeparateWithEmptyLine", "Separate multi-line declarations with empty lines", true, false, LocalDate.of(2022, 6, 5));

Expand Down Expand Up @@ -506,7 +506,7 @@ private void executeOn(Code code, Command startCommand, AlignTable table, boolea
private void changeLineBreaks(Code code, AlignTable table, boolean alwaysContinueLine, int basicIndent) {
boolean isPotentialOneLiner = (table.getLineCount() == 1 && !table.getLine(0).containsComments());
boolean isCurrentOneLiner = isPotentialOneLiner && !table.getLine(0).containsInnerLineBreaks();
MethodsOneLinerMeasure oneLinerMeasure = MethodsOneLinerMeasure.forValue(configHandleOneLiners.getValue());
MethodsOneLinerAction oneLinerAction = MethodsOneLinerAction.forValue(configHandleOneLiners.getValue());

// insert line breaks depending on rule configuration
for (int colIndex = Columns.KEYWORD.getValue(); colIndex <= Columns.ACCESS.getValue(); ++colIndex) {
Expand All @@ -518,9 +518,9 @@ private void changeLineBreaks(Code code, AlignTable table, boolean alwaysContinu
ChangeType continueLine;
if (alwaysContinueLine) {
continueLine = (colIndex == Columns.KEYWORD.getValue()) ? ChangeType.KEEP_AS_IS : ChangeType.ALWAYS;
} else if (isPotentialOneLiner && oneLinerMeasure == MethodsOneLinerMeasure.CREATE) {
} else if (isPotentialOneLiner && oneLinerAction == MethodsOneLinerAction.CREATE) {
continueLine = ChangeType.ALWAYS;
} else if (isCurrentOneLiner && oneLinerMeasure == MethodsOneLinerMeasure.KEEP_EXISTING) {
} else if (isCurrentOneLiner && oneLinerAction == MethodsOneLinerAction.KEEP_EXISTING) {
continueLine = ChangeType.KEEP_AS_IS;
} else {
// for multi-liners, or if the one-liner doesn't get special treatment, use regular configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sap.adt.abapcleaner.rules.alignment;

public enum MethodsOneLinerMeasure {
public enum MethodsOneLinerAction {
CREATE,
KEEP_EXISTING,
SAME_AS_MULTI_LINERS;
Expand All @@ -11,7 +11,7 @@ public int getValue() {
return this.ordinal();
}

public static MethodsOneLinerMeasure forValue(int value) {
public static MethodsOneLinerAction forValue(int value) {
return values()[value];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sap.adt.abapcleaner.rules.declarations;

public enum EmptySectionsMeasure {
public enum EmptySectionsAction {
REMOVE_PROTECTED_OF_FINAL_CLASS,
REMOVE_ANY_FROM_NON_EMPTY_CLASS,
REMOVE_ANY;
Expand All @@ -9,7 +9,7 @@ public int getValue() {
return this.ordinal();
}

public static EmptySectionsMeasure forValue(int value) {
public static EmptySectionsAction forValue(int value) {
return values()[value];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public String getExample() {
+ LINE_SEP + "ENDCLASS.";
}

final ConfigEnumValue<EmptySectionsMeasure> configEmptySectionsMeasure = new ConfigEnumValue<EmptySectionsMeasure>(this, "EmptySectionsMeasure", "Scope:",
new String[] { "Remove empty PROTECTED SECTIONs from FINAL classes", "Remove any empty SECTION from non-empty class definitions", "Remove any empty SECTION" }, EmptySectionsMeasure.REMOVE_ANY_FROM_NON_EMPTY_CLASS);
final ConfigEnumValue<EmptySectionsAction> configEmptySectionsAction = new ConfigEnumValue<EmptySectionsAction>(this, "EmptySectionsMeasure", "Scope:",
new String[] { "Remove empty PROTECTED SECTIONs from FINAL classes", "Remove any empty SECTION from non-empty class definitions", "Remove any empty SECTION" }, EmptySectionsAction.REMOVE_ANY_FROM_NON_EMPTY_CLASS);

private final ConfigValue[] configValues = new ConfigValue[] { configEmptySectionsMeasure };
private final ConfigValue[] configValues = new ConfigValue[] { configEmptySectionsAction };

private EmptySectionsMeasure getConfigEmptySectionsMeasure() {
return EmptySectionsMeasure.forValue(configEmptySectionsMeasure.getValue());
private EmptySectionsAction getConfigEmptySectionsAction() {
return EmptySectionsAction.forValue(configEmptySectionsAction.getValue());
}

@Override
Expand Down Expand Up @@ -170,16 +170,16 @@ private boolean executeOn(Code code, Command command) throws UnexpectedSyntaxAft
return false;
}

EmptySectionsMeasure configMeasure = getConfigEmptySectionsMeasure();
if (configMeasure == EmptySectionsMeasure.REMOVE_PROTECTED_OF_FINAL_CLASS) {
EmptySectionsAction configAction = getConfigEmptySectionsAction();
if (configAction == EmptySectionsAction.REMOVE_PROTECTED_OF_FINAL_CLASS) {
// only work on empty PROTECTED SECTION of a FINAL class
if (!command.firstCodeTokenIsKeyword("PROTECTED"))
return false;
if (!classStart.getFirstToken().matchesOnSiblings(true, TokenSearch.ASTERISK, "FINAL"))
return false;
// otherwise, remove section below

} else if (configMeasure == EmptySectionsMeasure.REMOVE_ANY_FROM_NON_EMPTY_CLASS) {
} else if (configAction == EmptySectionsAction.REMOVE_ANY_FROM_NON_EMPTY_CLASS) {
// only remove section if at least one of the SECTIONs is non-empty
boolean areAllSectionsEmpty = true;
Command testSection = classStart.getNextSibling();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sap.adt.abapcleaner.rules.declarations;

public enum EscapeCharMeasure {
public enum EscapeCharAction {
ALWAYS,
KEEP_AS_IS,
ONLY_FOR_ABAP_WORDS,
Expand All @@ -12,7 +12,7 @@ public int getValue() {
return this.ordinal();
}

public static EscapeCharMeasure forValue(int value) {
public static EscapeCharAction forValue(int value) {
return values()[value];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String getExample() {
private static final String[] changeTypeSelection = new String[] { "always", "keep as is", "only if parameter name is an ABAP word", "only to avoid syntax errors" };
private static final String[] criticalParamNames = new String[] { "EXPORTING", "CHANGING", "RAISING", "EXCEPTIONS", "DEFAULT", "OPTIONAL", "PREFERRED" };

final ConfigEnumValue<EscapeCharMeasure> configUseEscapeCharForParams = new ConfigEnumValue<EscapeCharMeasure>(this, "UseEscapeCharForParams", "Use ! escape character for parameters", changeTypeSelection, EscapeCharMeasure.ONLY_FOR_ABAP_WORDS, EscapeCharMeasure.ONLY_FOR_ABAP_WORDS, LocalDate.of(2023, 5, 30));
final ConfigEnumValue<EscapeCharAction> configUseEscapeCharForParams = new ConfigEnumValue<EscapeCharAction>(this, "UseEscapeCharForParams", "Use ! escape character for parameters", changeTypeSelection, EscapeCharAction.ONLY_FOR_ABAP_WORDS, EscapeCharAction.ONLY_FOR_ABAP_WORDS, LocalDate.of(2023, 5, 30));

private final ConfigValue[] configValues = new ConfigValue[] { configUseEscapeCharForParams };

Expand All @@ -116,8 +116,8 @@ protected boolean executeOn(Code code, Command command, int releaseRestriction)
if (!command.firstCodeTokenIsAnyKeyword("METHODS", "CLASS-METHODS"))
return false;

EscapeCharMeasure useEscapeChar = EscapeCharMeasure.forValue(configUseEscapeCharForParams.getValue());
if (useEscapeChar == EscapeCharMeasure.KEEP_AS_IS)
EscapeCharAction useEscapeChar = EscapeCharAction.forValue(configUseEscapeCharForParams.getValue());
if (useEscapeChar == EscapeCharAction.KEEP_AS_IS)
return false;

boolean changedCommand = false;
Expand Down Expand Up @@ -153,7 +153,7 @@ protected boolean executeOn(Code code, Command command, int releaseRestriction)
return changedCommand;
}

private boolean executeOnParameterName(Token paramName, EscapeCharMeasure useEscapeChar) {
private boolean executeOnParameterName(Token paramName, EscapeCharAction useEscapeChar) {
final String ESCAPE_CHAR = ABAP.OPERAND_ESCAPE_CHAR_STRING;

boolean isValueOrReference = false;
Expand All @@ -171,18 +171,18 @@ private boolean executeOnParameterName(Token paramName, EscapeCharMeasure useEsc
if (paramName.textStartsWith(ESCAPE_CHAR) && !requiresEscapeChar) {
// remove escape char if a) configured or b) in case of VALUE(...), REFERENCE(...), where SAP GUI does not use ! either
if ( isValueOrReference
|| useEscapeChar == EscapeCharMeasure.ONLY_FOR_ABAP_WORDS && !isAbapWord
|| useEscapeChar == EscapeCharMeasure.ONLY_AVOID_ERRORS && !requiresEscapeChar) {
|| useEscapeChar == EscapeCharAction.ONLY_FOR_ABAP_WORDS && !isAbapWord
|| useEscapeChar == EscapeCharAction.ONLY_AVOID_ERRORS && !requiresEscapeChar) {
paramName.setText(paramName.getText().substring(ESCAPE_CHAR.length()), false);
return true;
}

} else if (!paramName.textStartsWith(ESCAPE_CHAR) && !isValueOrReference) {
// add escape char if a) needed to avoid syntax errors or b) configured
if ( requiresEscapeChar
|| useEscapeChar == EscapeCharMeasure.ALWAYS
|| useEscapeChar == EscapeCharMeasure.ONLY_FOR_ABAP_WORDS && isAbapWord
|| useEscapeChar == EscapeCharMeasure.ONLY_AVOID_ERRORS && requiresEscapeChar) {
|| useEscapeChar == EscapeCharAction.ALWAYS
|| useEscapeChar == EscapeCharAction.ONLY_FOR_ABAP_WORDS && isAbapWord
|| useEscapeChar == EscapeCharAction.ONLY_AVOID_ERRORS && requiresEscapeChar) {
paramName.setText(ESCAPE_CHAR + paramName.getText(), false);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sap.adt.abapcleaner.rules.declarations;

public enum UnusedVariableMeasure {
public enum UnusedVariableAction {
DELETE,
COMMENT_OUT_WITH_ASTERISK,
COMMENT_OUT_WITH_QUOT,
Expand All @@ -9,7 +9,7 @@ public enum UnusedVariableMeasure {

public int getValue() { return this.ordinal(); }

public static UnusedVariableMeasure forValue(int value) {
public static UnusedVariableAction forValue(int value) {
return values()[value];
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.sap.adt.abapcleaner.rules.declarations;

public enum UnusedVariableMeasureIfAssigned {
public enum UnusedVariableActionIfAssigned {
ADD_TODO_COMMENT,
IGNORE;

public int getValue() { return this.ordinal(); }

public static UnusedVariableMeasureIfAssigned forValue(int value) {
public static UnusedVariableActionIfAssigned forValue(int value) {
return values()[value];
}
}
Loading

0 comments on commit e1a09b5

Please sign in to comment.