The Unified and Autonomous Development Platform
midwork
robin shineb15642a220c2
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.javaindex 4d3b8cbdf6..e682784d62 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@@ -601,5 +601,39 @@ public abstract class CodeAssist implements Serializable {protected abstract List<InputSuggestion> suggest(@Nullable ParseTree parseTree,Node elementNode, String matchWith);-++ public List<InputSuggestion> decorate(Suggester suggester,+ @Nullable ParseTree parseTree, Node elementNode, String matchWith,+ String prefix, String suffix) {+ if (matchWith.startsWith(prefix))+ matchWith = matchWith.substring(prefix.length());+ List<InputSuggestion> suggestions = suggester.suggest(matchWith);+ List<InputSuggestion> surroundedSuggestions = new ArrayList<>();++ boolean matchFound = false;+ for (InputSuggestion suggestion: suggestions) {+ String content = suggestion.getContent();+ int caret = suggestion.getCaret();+ if (!elementNode.getSpec().matches(lex(content))) {+ content = prefix + content + suffix;+ if (caret == suggestion.getContent().length())+ caret = content.length();+ else+ caret += prefix.length();+ surroundedSuggestions.add(new InputSuggestion(content, caret, suggestion.getDescription()));+ } else {+ surroundedSuggestions.add(suggestion);+ }+ if (suggestion.getContent().equals(matchWith))+ matchFound = true;+ }+ if (!matchFound && !elementNode.getSpec().matches(lex(matchWith))) {+ String surroundedMatchWith = prefix + matchWith + suffix;+ if (elementNode.getSpec().matches(lex(surroundedMatchWith))) {+ surroundedSuggestions.add(new InputSuggestion(surroundedMatchWith,+ surroundedMatchWith.length(), surroundedMatchWith));+ }+ }+ return surroundedSuggestions;+ }}diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/ElementSpec.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/ElementSpec.javaindex 985b6e2e4b..b472dacd97 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/ElementSpec.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/ElementSpec.java@@ -146,9 +146,9 @@ public abstract class ElementSpec extends Spec {public List<ElementSuggestion> suggestFirst(@Nullable ParseTree parseTree, Node parent,String matchWith, Set<String> checkedRules) {Node elementNode = new Node(this, parent, null);- List<InputSuggestion> texts = codeAssist.suggest(parseTree, elementNode, matchWith);- if (texts != null)- return Lists.newArrayList(new ElementSuggestion(parseTree, elementNode, matchWith, texts));+ List<InputSuggestion> suggestions = codeAssist.suggest(parseTree, elementNode, matchWith);+ if (suggestions != null && !suggestions.isEmpty())+ return Lists.newArrayList(new ElementSuggestion(parseTree, elementNode, matchWith, suggestions));elsereturn doSuggestFirst(parent, parseTree, matchWith, checkedRules);}diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/Suggester.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/Suggester.javanew file mode 100644index 0000000000..31ba9ea557--- /dev/null+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/Suggester.java@@ -0,0 +1,7 @@+package com.pmease.commons.antlr.codeassist;++import java.util.List;++public interface Suggester {+ List<InputSuggestion> suggest(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.javaindex 104af8a471..602cc23755 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@@ -25,6 +25,7 @@ import com.pmease.commons.antlr.codeassist.InputStatus;import com.pmease.commons.antlr.codeassist.InputSuggestion;import com.pmease.commons.antlr.codeassist.Node;import com.pmease.commons.antlr.codeassist.ParseTree;+import com.pmease.commons.antlr.codeassist.Suggester;import com.pmease.commons.util.StringUtils;@SuppressWarnings("serial")@@ -184,6 +185,13 @@ public abstract class ANTLRAssistBehavior extends InputAssistBehavior {}}- protected abstract List<InputSuggestion> suggest(ParseTree parseTree, Node elementNode, String matchWith);+ protected abstract List<InputSuggestion> suggest(ParseTree parseTree,+ Node elementNode, String matchWith);++ protected List<InputSuggestion> decorate(Suggester suggester, ParseTree parseTree,+ Node elementNode, String matchWith, String prefix, String suffix) {+ return codeAssist.decorate(suggester, parseTree, elementNode,+ matchWith, prefix, suffix);+ }}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.javaindex 111b3199cd..44e9b21d45 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@@ -7,6 +7,7 @@ import com.pmease.commons.antlr.codeassist.InputSuggestion;import com.pmease.commons.antlr.codeassist.LexerRuleRefElementSpec;import com.pmease.commons.antlr.codeassist.Node;import com.pmease.commons.antlr.codeassist.ParseTree;+import com.pmease.commons.antlr.codeassist.Suggester;import com.pmease.commons.wicket.behavior.inputassist.ANTLRAssistBehavior;@SuppressWarnings("serial")@@ -19,18 +20,25 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {}@Override- protected List<InputSuggestion> suggest(ParseTree parseTree, Node elementNode, String matchWith) {+ protected List<InputSuggestion> suggest(final ParseTree parseTree, Node elementNode, String matchWith) {if (elementNode.getSpec() instanceof LexerRuleRefElementSpec) {LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) elementNode.getSpec();- if (spec.getRuleName().equals("Value")- && parseTree.getLastNode().getToken().getType() == CommitQueryParser.BRANCH) {- List<InputSuggestion> suggestions = new ArrayList<>();- for (String value: BRANCHS) {- String bracedValue = "(" + value + ")";- if (bracedValue.toLowerCase().contains(matchWith.toLowerCase()))- suggestions.add(new InputSuggestion(bracedValue, bracedValue));- }- return suggestions;+ if (spec.getRuleName().equals("Value")) {+ return decorate(new Suggester() {++ @Override+ public List<InputSuggestion> suggest(String matchWith) {+ List<InputSuggestion> suggestions = new ArrayList<>();+ if (parseTree.getLastNode().getToken().getType() == CommitQueryParser.BRANCH) {+ for (String value: BRANCHS) {+ if (value.toLowerCase().contains(matchWith.toLowerCase()))+ suggestions.add(new InputSuggestion(value, value));+ }+ }+ return suggestions;+ }++ }, parseTree, elementNode, matchWith, "(", ")");}}return null;