Skip to content

Commit 54eed82

Browse files
committed
Start 0.13.0 development
Fix JSP parsing Added default methods to MatchingStateOption to indicate type of state (code, comment, string literal)
1 parent 71951c9 commit 54eed82

File tree

10 files changed

+259
-66
lines changed

10 files changed

+259
-66
lines changed

BEXCodeCompare/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>info.codesaway</groupId>
66
<artifactId>bex</artifactId>
7-
<version>0.12.0</version>
7+
<version>0.13.0</version>
88
<name>Be Enhanced Code Compare (BEϽC)</name>
99
<description>An enhanced code compare, utilities, and code matching</description>
1010
<properties>

BEXCodeCompare/src/main/java/info/codesaway/bex/diff/DiffHelper.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.TreeMap;
3131
import java.util.TreeSet;
3232
import java.util.function.BiFunction;
33+
import java.util.function.BiPredicate;
3334
import java.util.function.Function;
3435
import java.util.function.ToIntFunction;
3536
import java.util.stream.Collectors;
@@ -971,6 +972,8 @@ public static List<DiffUnit> combineToDiffBlocks(final List<DiffEdit> diff) {
971972
return combineToDiffBlocks(diff, false);
972973
}
973974

975+
private static final BiPredicate<DiffEdit, DiffEdit> ALWAYS_SHOULD_COMBINE = (x, y) -> true;
976+
974977
/**
975978
* Combines consecutive DiffEdit to form DiffBlock when possible
976979
*
@@ -980,12 +983,32 @@ public static List<DiffUnit> combineToDiffBlocks(final List<DiffEdit> diff) {
980983
* @return
981984
*/
982985
public static List<DiffUnit> combineToDiffBlocks(final List<DiffEdit> diff, final boolean allowReplacements) {
986+
return combineToDiffBlocks(diff, allowReplacements, ALWAYS_SHOULD_COMBINE);
987+
}
988+
989+
/**
990+
* Combines consecutive DiffEdit to form DiffBlock when possible and <code>shouldCombinePredicate</code> returns true
991+
*
992+
* <p>The returned list will consist of DiffUnit objects (either DiffBlock or DiffEdit)</p>
993+
*
994+
* @param diff
995+
* @param allowReplacements
996+
* @param shouldCombinePredicate indicates whether the two DiffEdits should be combined, if this method determines they can be combined (return <code>false</code> to prevent the combining)
997+
* @return
998+
* @since 0.13
999+
*/
1000+
public static List<DiffUnit> combineToDiffBlocks(final List<DiffEdit> diff, final boolean allowReplacements,
1001+
final BiPredicate<DiffEdit, DiffEdit> shouldCombinePredicate) {
9831002
List<DiffUnit> diffBlocks = new ArrayList<>();
9841003

1004+
BiPredicate<DiffEdit, DiffEdit> usedShouldCombinePredicate = shouldCombinePredicate != null
1005+
? shouldCombinePredicate
1006+
: ALWAYS_SHOULD_COMBINE;
1007+
9851008
for (int i = 0; i < diff.size(); i++) {
9861009
DiffEdit diffEdit = diff.get(i);
9871010

988-
if (isNextDiffPartOfBlock(diff, i, allowReplacements)) {
1011+
if (isNextDiffPartOfBlock(diff, i, allowReplacements, usedShouldCombinePredicate)) {
9891012
DiffType blockDiffType = diffEdit.getType();
9901013

9911014
List<DiffEdit> edits = new ArrayList<>();
@@ -997,7 +1020,7 @@ public static List<DiffUnit> combineToDiffBlocks(final List<DiffEdit> diff, fina
9971020
if (blockDiffType != REPLACEMENT_BLOCK && !blockDiffType.equals(nextDiffEdit.getType())) {
9981021
blockDiffType = REPLACEMENT_BLOCK;
9991022
}
1000-
} while (isNextDiffPartOfBlock(diff, i, allowReplacements));
1023+
} while (isNextDiffPartOfBlock(diff, i, allowReplacements, usedShouldCombinePredicate));
10011024

10021025
diffBlocks.add(new DiffBlock(blockDiffType, edits));
10031026
} else {
@@ -1017,7 +1040,7 @@ public static List<DiffUnit> combineToDiffBlocks(final List<DiffEdit> diff, fina
10171040
* @return
10181041
*/
10191042
private static boolean isNextDiffPartOfBlock(final List<DiffEdit> diff, final int i,
1020-
final boolean allowReplacements) {
1043+
final boolean allowReplacements, final BiPredicate<DiffEdit, DiffEdit> shouldCombinePredicate) {
10211044

10221045
if (i + 1 >= diff.size()) {
10231046
return false;
@@ -1040,7 +1063,8 @@ private static boolean isNextDiffPartOfBlock(final List<DiffEdit> diff, final in
10401063
}
10411064
}
10421065

1043-
return hasConsecutiveLines(diffEdit, nextDiffEdit, isReplancement);
1066+
return hasConsecutiveLines(diffEdit, nextDiffEdit, isReplancement)
1067+
&& shouldCombinePredicate.test(diffEdit, nextDiffEdit);
10441068
}
10451069

10461070
private static boolean canBePartOfReplacement(final DiffEdit diffEdit) {

BEXCodeCompare/src/main/java/info/codesaway/bex/matching/BEXMatchingLanguage.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ public enum BEXMatchingLanguage implements MatchingLanguage {
3131
*/
3232
SQL(BEXMatchingUtilities::parseSQLTextStates, "@#$", true, bexPair("BEGIN", "END")),
3333

34+
/**
35+
* Language which gives no special meaning to any characters
36+
*
37+
* <p>For example, brackets aren't checked that they balance</p>
38+
* @since 0.13
39+
*/
40+
TEXT(x -> ImmutableIntRangeMap.of()) {
41+
@Override
42+
public Optional<BEXPair<String>> findStartDelimiter(final CharSequence text, final int index,
43+
final Set<MatchingLanguageSetting> settings) {
44+
return Optional.empty();
45+
}
46+
47+
@Override
48+
public MatchingDelimiterState findEndDelimiter(final BEXPair<String> lastDelimiter, final CharSequence text,
49+
final int index, final Set<MatchingLanguageSetting> settings) {
50+
return MatchingDelimiterState.NOT_FOUND;
51+
}
52+
},
53+
3454
// End of enum
3555
;
3656

@@ -92,11 +112,11 @@ public MatchingDelimiterState findEndDelimiter(final BEXPair<String> lastDelimit
92112

93113
BiPredicate<String, String> equals = this.hasCaseInsensitiveDelimiters
94114
? String::equalsIgnoreCase
95-
: String::equals;
115+
: String::equals;
96116

97117
MatchingDelimiterResult result = lastDelimiter != null && equals.test(s, lastDelimiter.getRight())
98118
? MatchingDelimiterResult.FOUND
99-
: MatchingDelimiterResult.MISMATCHED;
119+
: MatchingDelimiterResult.MISMATCHED;
100120

101121
return new MatchingDelimiterState(result, s);
102122
}
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package info.codesaway.bex.matching;
22

3-
public enum BEXMatchingStateOption implements MatchingStateOption {
4-
IN_STRING_LITERAL, MISMATCHED_DELIMITERS, IN_LINE_COMMENT, IN_MULTILINE_COMMENT, IN_EXPRESSION_BLOCK(true),
5-
IN_SECONDARY_STRING_LITERAL;
3+
import static info.codesaway.bex.util.BEXUtilities.in;
64

7-
private final boolean isCode;
5+
public enum BEXMatchingStateOption implements MatchingStateOption {
6+
// Code
7+
IN_EXPRESSION_BLOCK, IN_TAG,
8+
// Comment
9+
IN_LINE_COMMENT, IN_MULTILINE_COMMENT, IN_SECONDARY_MULTILINE_COMMENT,
10+
// String literal
11+
IN_STRING_LITERAL, IN_SECONDARY_STRING_LITERAL,
12+
// Other states
13+
MISMATCHED_DELIMITERS;
814

9-
private BEXMatchingStateOption() {
10-
this(false);
15+
@Override
16+
public boolean isCode() {
17+
return in(this, IN_EXPRESSION_BLOCK, IN_TAG);
1118
}
1219

13-
private BEXMatchingStateOption(final boolean isCode) {
14-
this.isCode = isCode;
20+
@Override
21+
public boolean isComment() {
22+
return in(this, IN_LINE_COMMENT, IN_MULTILINE_COMMENT, IN_SECONDARY_MULTILINE_COMMENT);
1523
}
1624

1725
@Override
18-
public boolean isCode() {
19-
return this.isCode;
26+
public boolean isStringLiteral() {
27+
return in(this, IN_STRING_LITERAL, IN_SECONDARY_STRING_LITERAL);
2028
}
2129
}

0 commit comments

Comments
 (0)