The Unified and Autonomous Development Platform
midwork
robin shinea32f78be17b8
diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundAware.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/FenceAware.javasimilarity index 61%rename from commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundAware.javarename to commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/FenceAware.javaindex e5f9268cf1..a0882103a9 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundAware.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/FenceAware.java@@ -11,18 +11,18 @@ import com.pmease.commons.antlr.grammar.ElementSpec;import com.pmease.commons.antlr.grammar.Grammar;import com.pmease.commons.util.pattern.Highlight;-public abstract class SurroundAware {+public abstract class FenceAware {private final Grammar grammar;- private final String prefix;+ private final String open;- private final String suffix;+ private final String close;- public SurroundAware(Grammar grammar, String prefix, String suffix) {+ public FenceAware(Grammar grammar, String open, String close) {this.grammar = grammar;- this.prefix = prefix;- this.suffix = suffix;+ this.open = open;+ this.close = close;}private boolean matches(ElementSpec spec, String content) {@@ -37,14 +37,12 @@ public abstract class SurroundAware {}public List<InputSuggestion> suggest(ElementSpec spec, String matchWith) {- String unsurroundedMatchWith = matchWith;- if (matchWith.startsWith(prefix))- unsurroundedMatchWith = unsurroundedMatchWith.substring(prefix.length());- unsurroundedMatchWith = unsurroundedMatchWith.trim();- if (unsurroundedMatchWith.endsWith(suffix))- return new ArrayList<>();+ String unfencedMatchWith = matchWith;+ if (matchWith.startsWith(open))+ unfencedMatchWith = unfencedMatchWith.substring(open.length());+ unfencedMatchWith = unfencedMatchWith.trim();- List<InputSuggestion> suggestions = match(unsurroundedMatchWith);+ List<InputSuggestion> suggestions = match(unfencedMatchWith);if (suggestions != null) {List<InputSuggestion> checkedSuggestions = new ArrayList<>();@@ -52,12 +50,12 @@ public abstract class SurroundAware {String content = suggestion.getContent();int caret = suggestion.getCaret();if (!matches(spec, content)) {- content = prefix + content + suffix;+ content = open + content + close;Highlight highlight = suggestion.getHighlight();if (caret != -1)- caret += prefix.length();+ caret += open.length();if (highlight != null)- highlight = new Highlight(highlight.getFrom()+prefix.length(), highlight.getTo()+prefix.length());+ highlight = new Highlight(highlight.getFrom()+open.length(), highlight.getTo()+open.length());checkedSuggestions.add(new InputSuggestion(content, caret, true, suggestion.getDescription(), highlight));} else {checkedSuggestions.add(suggestion);@@ -70,36 +68,36 @@ public abstract class SurroundAware {* should be quoted, in this case, below code will suggest you to quote the value if it* contains spaces as otherwise it will fail the match below*/- if (checkedSuggestions.isEmpty() && matchWith.length() != 0 && !matches(spec, unsurroundedMatchWith)) {- unsurroundedMatchWith = prefix + unsurroundedMatchWith + suffix;- if (matches(spec, unsurroundedMatchWith)) {- Highlight highlight = new Highlight(1, unsurroundedMatchWith.length()-1);- checkedSuggestions.add(new InputSuggestion(unsurroundedMatchWith, getSurroundDescription(), highlight));+ if (checkedSuggestions.isEmpty() && matchWith.length() != 0 && !matches(spec, unfencedMatchWith)) {+ unfencedMatchWith = open + unfencedMatchWith + close;+ if (matches(spec, unfencedMatchWith)) {+ Highlight highlight = new Highlight(1, unfencedMatchWith.length()-1);+ checkedSuggestions.add(new InputSuggestion(unfencedMatchWith, getFencingDescription(), highlight));}}- if (checkedSuggestions.isEmpty())- checkedSuggestions.add(new InputSuggestion(prefix, null, null));+ if (checkedSuggestions.isEmpty() && matchWith.length() == 0)+ checkedSuggestions.add(new InputSuggestion(open, null, null));return checkedSuggestions;} else {return null;}}- protected String getSurroundDescription() {+ protected String getFencingDescription() {return null;}/*** Match with provided string to give a list of suggestions*- * @param surroundlessMatchWith- * string with surrounding literals removed+ * @param unfencedMatchWith+ * string with fencing literals removed* @return* a list of suggestions. If you do not have any suggestions and want code assist to* drill down the element to provide default suggestions, return a <tt>null</tt> value* instead of an empty list*/@Nullable- protected abstract List<InputSuggestion> match(String surroundlessMatchWith);+ protected abstract List<InputSuggestion> match(String unfencedMatchWith);}diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/parser/State.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/parser/State.javaindex 3ebb2ddfee..52703e6c6e 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/parser/State.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/parser/State.java@@ -1,5 +1,6 @@package com.pmease.commons.antlr.parser;+import java.util.ArrayList;import java.util.List;import javax.annotation.Nullable;@@ -130,6 +131,21 @@ public class State {return expectedElementSpecIndex == getElementSpecs().size();}+ public State getScannedState(EarleyParser parser, int tokenIndex) {+ ElementSpec expectedElementSpec = getExpectedElementSpec();+ List<Element> elements = new ArrayList<>(getElements());+ elements.add(new Element(parser, expectedElementSpec, tokenIndex+1, null));+ if (!expectedElementSpec.isMultiple()) {+ return new State(getOriginPosition(), getRuleSpec(),+ getAlternativeSpecIndex(), getExpectedElementSpecIndex()+1,+ false, elements);+ } else {+ return new State(getOriginPosition(), getRuleSpec(),+ getAlternativeSpecIndex(), getExpectedElementSpecIndex(),+ true, elements);+ }+ }+@Overridepublic boolean equals(Object other) {if (!(other instanceof State))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.javaindex 18379ebd95..94e3078916 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.SurroundAware;+import com.pmease.commons.antlr.codeassist.FenceAware;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 SurroundAware(codeAssist.getGrammar(), "(", ")") {+ return new FenceAware(codeAssist.getGrammar(), "(", ")") {@Overrideprotected 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.javaindex e90d5b9765..122a57d7f6 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.SurroundAware;+import com.pmease.commons.antlr.codeassist.FenceAware;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 SurroundAware(codeAssist.getGrammar(), "\"", "\"") {+ return new FenceAware(codeAssist.getGrammar(), "\"", "\"") {@Overrideprotected List<InputSuggestion> match(String matchWith) {@@ -79,7 +79,8 @@ public class CodeAssistTest3 {assertEquals("author::7", suggestions.get(1).toString());suggestions = suggest(new InputStatus("title:"), "query");- assertEquals(0, suggestions.size());+ assertEquals(1, suggestions.size());+ assertEquals("title:\":7", suggestions.get(0).toString());suggestions = suggest(new InputStatus("author: dustin"), "query");assertEquals(0, suggestions.size());diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.jsindex 88108799ef..6057f0091d 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.js@@ -49,6 +49,7 @@ pmease.commons.inputassist = {}$dropdown.find(".suggestions").scrollIntoView("tr.active");pmease.commons.inputassist.updateHelp($dropdown);+ $dropdown.align($dropdown.data("alignment"));return false;}});@@ -68,6 +69,7 @@ pmease.commons.inputassist = {}$dropdown.find(".suggestions").scrollIntoView("tr.active");pmease.commons.inputassist.updateHelp($dropdown);+ $dropdown.align($dropdown.data("alignment"));return false;}});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 70387f8889..c869c7f33d 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.SurroundAware;+import com.pmease.commons.antlr.codeassist.FenceAware;import com.pmease.commons.antlr.grammar.ElementSpec;import com.pmease.commons.antlr.grammar.LexerRuleRefElementSpec;import com.pmease.commons.git.NameAndEmail;@@ -31,6 +31,10 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {private final IModel<Repository> repoModel;+ private static final String VALUE_OPEN = "(";++ private static final String VALUE_CLOSE = ")";+private static final String[] DATE_EXAMPLES = new String[]{"one hour ago", "2 hours ago", "3PM", "noon", "today", "yesterday","yesterday midnight", "3 days ago", "last week", "last Monday",@@ -52,29 +56,29 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();if (spec.getRuleName().equals("Value")) {- return new SurroundAware(codeAssist.getGrammar(), "(", ")") {+ return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {@Override- protected List<InputSuggestion> match(String unsurroundedMatchWith) {+ protected List<InputSuggestion> match(String unfencedMatchWith) {int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();- unsurroundedMatchWith = unsurroundedMatchWith.toLowerCase();+ String unfencedLowerCaseMatchWith = unfencedMatchWith.toLowerCase();int numSuggestions = 0;List<InputSuggestion> suggestions = new ArrayList<>();switch (tokenType) {case CommitQueryParser.BRANCH:for (String value: repoModel.getObject().getBranches()) {- int index = value.toLowerCase().indexOf(unsurroundedMatchWith);+ int index = value.toLowerCase().indexOf(unfencedLowerCaseMatchWith);if (index != -1 && numSuggestions++<count) {- Highlight highlight = new Highlight(index, index+unsurroundedMatchWith.length());+ Highlight highlight = new Highlight(index, index+unfencedLowerCaseMatchWith.length());suggestions.add(new InputSuggestion(value, highlight));}}break;case CommitQueryParser.TAG:for (String value: repoModel.getObject().getTags()) {- int index = value.toLowerCase().indexOf(unsurroundedMatchWith);+ int index = value.toLowerCase().indexOf(unfencedLowerCaseMatchWith);if (index != -1 && numSuggestions++<count) {- Highlight highlight = new Highlight(index, index+unsurroundedMatchWith.length());+ Highlight highlight = new Highlight(index, index+unfencedLowerCaseMatchWith.length());suggestions.add(new InputSuggestion(value, highlight));}}@@ -91,7 +95,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {elsecontent = contributor.getName();content = content.trim();- WildcardApplied applied = WildcardUtils.applyWildcard(content, unsurroundedMatchWith, false);+ WildcardApplied applied = WildcardUtils.applyWildcard(content, unfencedLowerCaseMatchWith, false);if (applied != null) {suggestedInputs.put(applied.getText(), applied.getHighlight());if (suggestedInputs.size() == count)@@ -104,7 +108,12 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {break;case CommitQueryParser.BEFORE:case CommitQueryParser.AFTER:- if (!unsurroundedMatchWith.endsWith(")")) {+ if (!unfencedMatchWith.contains(VALUE_CLOSE)) {+ if (unfencedMatchWith.length() != 0) {+ String fenced = VALUE_OPEN + unfencedMatchWith + VALUE_CLOSE;+ Highlight highlight = new Highlight(0, fenced.length());+ suggestions.add(new InputSuggestion(fenced, -1, true, getFencingDescription(), highlight));+ }suggestions.add(new InputSuggestion(Constants.DATETIME_FORMATTER.print(System.currentTimeMillis())));suggestions.add(new InputSuggestion(Constants.DATE_FORMATTER.print(System.currentTimeMillis())));for (String dateExample: DATE_EXAMPLES)@@ -115,7 +124,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {List<WildcardApplied> allApplied = new ArrayList<>();auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);for (String path: auxiliaryManager.getFiles(repoModel.getObject())) {- WildcardApplied applied = WildcardUtils.applyWildcard(path, unsurroundedMatchWith, false);+ WildcardApplied applied = WildcardUtils.applyWildcard(path, unfencedLowerCaseMatchWith, false);if (applied != null)allApplied.add(applied);}@@ -158,7 +167,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {}@Override- protected String getSurroundDescription() {+ protected String getFencingDescription() {return "value needs to be enclosed in brackets";}@@ -173,7 +182,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {List<String> hints = new ArrayList<>();if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();- if (spec.getRuleName().equals("Value") && !matchWith.endsWith(")")) {+ if (spec.getRuleName().equals("Value") && !matchWith.contains(VALUE_CLOSE)) {int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();if (tokenType == CommitQueryParser.COMMITTER) {hints.add("Use * to match any part of committer");@@ -191,7 +200,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {@Overrideprotected int getEndOfMatch(ElementSpec spec, String content) {- if (content.startsWith("()"))+ if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))return 2;elsereturn super.getEndOfMatch(spec, content);