Skip to content

Commit

Permalink
Groovy REPL: improved constructor statement completion
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Sep 15, 2020
1 parent ff28596 commit 4d8aa74
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,7 @@ public void complete(LineReader reader, ParsedLine commandLine, List<Candidate>
} catch (Exception e) {
return;
}
if (brackets.openQuote() || (commandLine.wordIndex() > 0 && !commandLine.words().get(0).matches("(new|\\w+=new)")
&& brackets.numberOfRounds() == 0 && !brackets.openRound() && !brackets.openCurly())) {
if (brackets.openQuote()) {
return;
}
inspector = new Inspector(groovyEngine);
Expand All @@ -679,10 +678,7 @@ public void complete(LineReader reader, ParsedLine commandLine, List<Candidate>
String hint = wordbuffer.substring(vs + 1);
doMethodCandidates(candidates, clazz, curBuf, hint);
}
} else if (!wordbuffer.contains("(") &&
((commandLine.wordIndex() == 1 && commandLine.words().get(0).matches("(new|\\w+=new)"))
|| (commandLine.wordIndex() > 1 && Helpers.constructorStatement(commandLine.words().get(commandLine.wordIndex() - 1))))
) {
} else if (completingConstructor(commandLine)) {
if (wordbuffer.matches("[a-z]+.*")) {
int idx = wordbuffer.lastIndexOf('.');
if (idx > 0 && wordbuffer.substring(idx + 1).matches("[A-Z]+.*")) {
Expand Down Expand Up @@ -752,6 +748,15 @@ public void complete(LineReader reader, ParsedLine commandLine, List<Candidate>
}
}

private boolean completingConstructor(ParsedLine commandLine) {
return !commandLine.word().contains("(") && (
(commandLine.wordIndex() == 1 && commandLine.words().get(0).matches("(new|\\w+=[{]?new)"))
||
(commandLine.wordIndex() > 1
&& Helpers.constructorStatement(commandLine.words().get(commandLine.wordIndex() - 1)))
);
}

private void doMethodCandidates(List<Candidate> candidates, Class<?> clazz, String curBuf, String hint) {
if (clazz == null) {
return;
Expand Down

0 comments on commit 4d8aa74

Please sign in to comment.