Skip to content

The Unified and Autonomous Development Platform

midwork

robin shinee40c0f71d1b8
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/SurroundAware.java
index 639a90eeb1..e5f9268cf1 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/SurroundAware.java
@@ -37,14 +37,14 @@ public abstract class SurroundAware {
}
public List<InputSuggestion> suggest(ElementSpec spec, String matchWith) {
- if (matchWith.endsWith(suffix))
- return new ArrayList<>();
-
+ String unsurroundedMatchWith = matchWith;
if (matchWith.startsWith(prefix))
- matchWith = matchWith.substring(prefix.length());
- matchWith = matchWith.trim();
+ unsurroundedMatchWith = unsurroundedMatchWith.substring(prefix.length());
+ unsurroundedMatchWith = unsurroundedMatchWith.trim();
+ if (unsurroundedMatchWith.endsWith(suffix))
+ return new ArrayList<>();
- List<InputSuggestion> suggestions = match(matchWith);
+ List<InputSuggestion> suggestions = match(unsurroundedMatchWith);
if (suggestions != null) {
List<InputSuggestion> checkedSuggestions = new ArrayList<>();
@@ -70,13 +70,16 @@ 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() && !matches(spec, matchWith)) {
- matchWith = prefix + matchWith + suffix;
- if (matches(spec, matchWith)) {
- Highlight highlight = new Highlight(1, matchWith.length()-1);
- checkedSuggestions.add(new InputSuggestion(matchWith, getSurroundDescription(), highlight));
+ 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())
+ checkedSuggestions.add(new InputSuggestion(prefix, null, null));
return checkedSuggestions;
} else {
return null;
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 f0bc0743a9..1023000272 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
@@ -55,29 +55,32 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
return new SurroundAware(codeAssist.getGrammar(), "(", ")") {
@Override
- protected List<InputSuggestion> match(String matchWith) {
- matchWith = matchWith.toLowerCase();
+ protected List<InputSuggestion> match(String unsurroundedMatchWith) {
+ int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();
+ unsurroundedMatchWith = unsurroundedMatchWith.toLowerCase();
int numSuggestions = 0;
List<InputSuggestion> suggestions = new ArrayList<>();
- int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();
- if (tokenType == CommitQueryParser.BRANCH) {
+ switch (tokenType) {
+ case CommitQueryParser.BRANCH:
for (String value: repoModel.getObject().getBranches()) {
- int index = value.toLowerCase().indexOf(matchWith);
+ int index = value.toLowerCase().indexOf(unsurroundedMatchWith);
if (index != -1 && numSuggestions++<count) {
- Highlight highlight = new Highlight(index, index+matchWith.length());
+ Highlight highlight = new Highlight(index, index+unsurroundedMatchWith.length());
suggestions.add(new InputSuggestion(value, highlight));
}
}
- } else if (tokenType == CommitQueryParser.TAG) {
+ break;
+ case CommitQueryParser.TAG:
for (String value: repoModel.getObject().getTags()) {
- int index = value.toLowerCase().indexOf(matchWith);
+ int index = value.toLowerCase().indexOf(unsurroundedMatchWith);
if (index != -1 && numSuggestions++<count) {
- Highlight highlight = new Highlight(index, index+matchWith.length());
+ Highlight highlight = new Highlight(index, index+unsurroundedMatchWith.length());
suggestions.add(new InputSuggestion(value, highlight));
}
}
- } else if (tokenType == CommitQueryParser.AUTHOR
- || tokenType == CommitQueryParser.COMMITTER) {
+ break;
+ case CommitQueryParser.AUTHOR:
+ case CommitQueryParser.COMMITTER:
Map<String, Highlight> suggestedInputs = new LinkedHashMap<>();
AuxiliaryManager auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);
List<NameAndEmail> contributors = auxiliaryManager.getContributors(repoModel.getObject());
@@ -87,7 +90,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
content = contributor.getName() + " <" + contributor.getEmailAddress() + ">";
else
content = contributor.getName();
- WildcardApplied applied = WildcardUtils.applyWildcard(content, matchWith, false);
+ WildcardApplied applied = WildcardUtils.applyWildcard(content, unsurroundedMatchWith, false);
if (applied != null) {
suggestedInputs.put(applied.getText(), applied.getHighlight());
if (suggestedInputs.size() == count)
@@ -97,19 +100,21 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
for (Map.Entry<String, Highlight> entry: suggestedInputs.entrySet())
suggestions.add(new InputSuggestion(entry.getKey(), -1, true, null, entry.getValue()));
- } else if (tokenType == CommitQueryParser.BEFORE
- || tokenType == CommitQueryParser.AFTER) {
- if (!matchWith.endsWith(")")) {
+ break;
+ case CommitQueryParser.BEFORE:
+ case CommitQueryParser.AFTER:
+ if (!unsurroundedMatchWith.endsWith(")")) {
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)
suggestions.add(new InputSuggestion(dateExample));
}
- } else if (tokenType == CommitQueryParser.PATH) {
+ break;
+ case CommitQueryParser.PATH:
List<WildcardApplied> allApplied = new ArrayList<>();
- AuxiliaryManager auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);
+ auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);
for (String path: auxiliaryManager.getFiles(repoModel.getObject())) {
- WildcardApplied applied = WildcardUtils.applyWildcard(path, matchWith, false);
+ WildcardApplied applied = WildcardUtils.applyWildcard(path, unsurroundedMatchWith, false);
if (applied != null)
allApplied.add(applied);
}
@@ -122,7 +127,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
});
- Map<String, Highlight> suggestedInputs = new LinkedHashMap<>();
+ suggestedInputs = new LinkedHashMap<>();
for (WildcardApplied applied: allApplied) {
Highlight highlight = applied.getHighlight();
String suffix = applied.getText().substring(highlight.getTo());
@@ -146,7 +151,8 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
caret = -1;
suggestions.add(new InputSuggestion(text, caret, true, null, entry.getValue()));
}
- }
+ break;
+ }
return suggestions;
}
@@ -166,7 +172,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")) {
+ if (spec.getRuleName().equals("Value") && !matchWith.endsWith(")")) {
int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();
if (tokenType == CommitQueryParser.COMMITTER) {
hints.add("Use * to match any part of committer");