Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine6aa6d9fe57f1
diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java
index d574dc2a92..d5d6eb5860 100644
--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java
+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java
@@ -417,23 +417,28 @@ public abstract class CodeAssist implements Serializable {
for (ElementSuggestion suggestion: suggestions) {
int replaceBegin = inputStatus.getCaret() - suggestion.getMatchWith().length();
int replaceEnd = inputStatus.getCaret();
-
+
/*
* if input around the caret matches spec of the suggestion, we then replace
* the matched text with suggestion, instead of simply inserting the
* suggested content
*/
- tokens = grammar.lex(inputContent.substring(replaceBegin));
+ ElementSpec elementSpec = suggestion.getExpectedElement().getSpec();
+ String contentAfterReplaceBegin = inputContent.substring(replaceBegin);
+
+ tokens = grammar.lex(contentAfterReplaceBegin);
if (!tokens.isEmpty() && tokens.get(0).getStartIndex() == 0) {
- ElementSpec elementSpec = (ElementSpec) suggestion.getExpectedElement().getSpec();
- int endOfMatch = elementSpec.getEndOfMatch(tokens);
- if (endOfMatch > 0) { // there exist an element match
- int charIndex = replaceBegin + tokens.get(endOfMatch-1).getStopIndex()+1;
- if (charIndex > replaceEnd)
- replaceEnd = charIndex;
+ int endOfMatch = getEndOfMatch(elementSpec, contentAfterReplaceBegin);
+ if (endOfMatch <= 0) {
+ endOfMatch = elementSpec.getEndOfMatch(tokens);
+ if (endOfMatch > 0) // there exist an element match
+ endOfMatch = tokens.get(endOfMatch-1).getStopIndex()+1; // convert to char index
}
+ endOfMatch += replaceBegin;
+ if (endOfMatch > replaceEnd)
+ replaceEnd = endOfMatch;
}
-
+
String before = inputContent.substring(0, replaceBegin);
for (InputSuggestion inputSuggestion: suggestion.getInputSuggestions()) {
@@ -556,6 +561,10 @@ public abstract class CodeAssist implements Serializable {
return new ArrayList<>();
}
+ protected int getEndOfMatch(ElementSpec spec, String content) {
+ return 0;
+ }
+
/**
* Wrap specified literal of specified terminal element as suggestion.
*
diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundAware.java
similarity index 94%
rename from commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java
rename to commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundAware.java
index e42ddf3f0e..639a90eeb1 100644
--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java
+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundAware.java
@@ -11,7 +11,7 @@ import com.pmease.commons.antlr.grammar.ElementSpec;
import com.pmease.commons.antlr.grammar.Grammar;
import com.pmease.commons.util.pattern.Highlight;
-public abstract class SurroundingAware {
+public abstract class SurroundAware {
private final Grammar grammar;
@@ -19,7 +19,7 @@ public abstract class SurroundingAware {
private final String suffix;
- public SurroundingAware(Grammar grammar, String prefix, String suffix) {
+ public SurroundAware(Grammar grammar, String prefix, String suffix) {
this.grammar = grammar;
this.prefix = prefix;
this.suffix = suffix;
@@ -74,7 +74,7 @@ public abstract class SurroundingAware {
matchWith = prefix + matchWith + suffix;
if (matches(spec, matchWith)) {
Highlight highlight = new Highlight(1, matchWith.length()-1);
- checkedSuggestions.add(new InputSuggestion(matchWith, getSurroundingDescription(), highlight));
+ checkedSuggestions.add(new InputSuggestion(matchWith, getSurroundDescription(), highlight));
}
}
return checkedSuggestions;
@@ -83,7 +83,7 @@ public abstract class SurroundingAware {
}
}
- protected String getSurroundingDescription() {
+ protected String getSurroundDescription() {
return null;
}
diff --git a/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java b/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java
index 1493f755eb..18379ebd95 100644
--- a/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java
+++ b/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java
@@ -12,7 +12,7 @@ import com.pmease.commons.antlr.codeassist.InputCompletion;
import com.pmease.commons.antlr.codeassist.InputStatus;
import com.pmease.commons.antlr.codeassist.InputSuggestion;
import com.pmease.commons.antlr.codeassist.ParentedElement;
-import com.pmease.commons.antlr.codeassist.SurroundingAware;
+import com.pmease.commons.antlr.codeassist.SurroundAware;
import com.pmease.commons.antlr.grammar.LexerRuleRefElementSpec;
public class CodeAssistTest2 {
@@ -28,7 +28,7 @@ public class CodeAssistTest2 {
if (element.getSpec() instanceof LexerRuleRefElementSpec) {
LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) element.getSpec();
if (spec.getRuleName().equals("Value")) {
- return new SurroundingAware(codeAssist.getGrammar(), "(", ")") {
+ return new SurroundAware(codeAssist.getGrammar(), "(", ")") {
@Override
protected List<InputSuggestion> match(String matchWith) {
diff --git a/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest3.java b/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest3.java
index e90c722ffe..e90d5b9765 100644
--- a/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest3.java
+++ b/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest3.java
@@ -12,7 +12,7 @@ import com.pmease.commons.antlr.codeassist.InputCompletion;
import com.pmease.commons.antlr.codeassist.InputStatus;
import com.pmease.commons.antlr.codeassist.InputSuggestion;
import com.pmease.commons.antlr.codeassist.ParentedElement;
-import com.pmease.commons.antlr.codeassist.SurroundingAware;
+import com.pmease.commons.antlr.codeassist.SurroundAware;
import com.pmease.commons.antlr.grammar.RuleRefElementSpec;
import com.pmease.commons.antlr.parser.Element;
@@ -29,7 +29,7 @@ public class CodeAssistTest3 {
if (element.getSpec() instanceof RuleRefElementSpec) {
RuleRefElementSpec spec = (RuleRefElementSpec) element.getSpec();
if (spec.getRuleName().equals("value")) {
- return new SurroundingAware(codeAssist.getGrammar(), "\"", "\"") {
+ return new SurroundAware(codeAssist.getGrammar(), "\"", "\"") {
@Override
protected List<InputSuggestion> match(String matchWith) {
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/ANTLRAssistBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/ANTLRAssistBehavior.java
index 1984fdf24f..ad9c45226d 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/ANTLRAssistBehavior.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/ANTLRAssistBehavior.java
@@ -26,6 +26,7 @@ import com.pmease.commons.antlr.codeassist.InputCompletion;
import com.pmease.commons.antlr.codeassist.InputStatus;
import com.pmease.commons.antlr.codeassist.InputSuggestion;
import com.pmease.commons.antlr.codeassist.ParentedElement;
+import com.pmease.commons.antlr.grammar.ElementSpec;
import com.pmease.commons.util.StringUtils;
@SuppressWarnings("serial")
@@ -78,6 +79,11 @@ public abstract class ANTLRAssistBehavior extends InputAssistBehavior {
boolean complete) {
return ANTLRAssistBehavior.this.wrapAsSuggestion(expectedElement, suggestedLiteral, complete);
}
+
+ @Override
+ protected int getEndOfMatch(ElementSpec spec, String content) {
+ return ANTLRAssistBehavior.this.getEndOfMatch(spec, content);
+ }
};
this.ruleName = ruleName;
@@ -88,6 +94,10 @@ public abstract class ANTLRAssistBehavior extends InputAssistBehavior {
return codeAssist.suggest(inputStatus, ruleName, count);
}
+ protected int getEndOfMatch(ElementSpec spec, String content) {
+ return 0;
+ }
+
private Constructor<? extends Lexer> getLexerCtor() {
if (lexerCtor == null) {
try {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java
index e9f992fee3..ab146c7c24 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java
@@ -12,7 +12,7 @@ import org.apache.wicket.model.IModel;
import com.pmease.commons.antlr.codeassist.InputSuggestion;
import com.pmease.commons.antlr.codeassist.ParentedElement;
-import com.pmease.commons.antlr.codeassist.SurroundingAware;
+import com.pmease.commons.antlr.codeassist.SurroundAware;
import com.pmease.commons.antlr.grammar.LexerRuleRefElementSpec;
import com.pmease.commons.git.NameAndEmail;
import com.pmease.commons.util.StringUtils;
@@ -51,7 +51,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
if (spec.getRuleName().equals("Value")) {
- return new SurroundingAware(codeAssist.getGrammar(), "(", ")") {
+ return new SurroundAware(codeAssist.getGrammar(), "(", ")") {
@Override
protected List<InputSuggestion> match(String matchWith) {