Skip to content

Commit

Permalink
Groovy REPL: chained metaMethods completion with inline Closure param…
Browse files Browse the repository at this point in the history
…eters
  • Loading branch information
mattirn committed Sep 30, 2020
1 parent 546c8ff commit 280d75c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,16 @@ public static void doCandidates(List<Candidate> candidates, Map<String,String> f
}
}

public static int statementBegin(String buffer) {
String buf = buffer;
while (buf.matches(".*\\)\\.\\w+$")) {
int idx = buf.lastIndexOf(".");
int openingRound = Brackets.indexOfOpeningRound(buf.substring(0,idx));
buf = buf.substring(0,openingRound);
}
return statementBegin(new Brackets(buf));
}

public static int statementBegin(String buffer, String wordbuffer, Brackets brackets) {
int out = -1;
int idx = buffer.lastIndexOf(wordbuffer);
Expand All @@ -661,7 +671,7 @@ public static int statementBegin(String buffer, String wordbuffer, Brackets brac
return out;
}

public static int statementBegin(Brackets brackets) {
private static int statementBegin(Brackets brackets) {
return statementBegin(brackets.lastDelim()
, brackets.lastOpenRound()
, brackets.lastComma()
Expand Down Expand Up @@ -760,7 +770,7 @@ public void complete(LineReader reader, ParsedLine commandLine, List<Candidate>
access = new AccessRules(groovyEngine.groovyOptions());
inspector = new Inspector(groovyEngine);
inspector.loadStatementVars(buffer);
int eqsep = Helpers.statementBegin(brackets);
int eqsep = Helpers.statementBegin(buffer);
if (brackets.numberOfRounds() > 0 && brackets.lastCloseRound() > eqsep) {
int varsep = buffer.lastIndexOf('.');
if (varsep > 0 && varsep > brackets.lastCloseRound() && !restrictedCompletion) {
Expand Down Expand Up @@ -897,10 +907,6 @@ private void doMethodCandidates(List<Candidate> candidates, Object object, Strin
, identifierCompletion && !(object instanceof Map), metaMethods);
}

private void doMethodCandidates(List<Candidate> candidates, Class<?> clazz, String curBuf, String hint) {
doMethodCandidates(candidates, clazz, curBuf, hint, false, null);
}

private void doMethodCandidates(List<Candidate> candidates, Class<?> clazz, String curBuf, String hint
, boolean addIdentifiers, Set<String> metaMethods) {
if (clazz == null) {
Expand Down Expand Up @@ -1103,7 +1109,7 @@ private String stripVarType(String statement) {
private String defineArgs(String[] args) {
StringBuilder out = new StringBuilder();
for (String v : args) {
Matcher matcher = PATTERN_TYPE_VAR.matcher(v);
Matcher matcher = PATTERN_TYPE_VAR.matcher(v.trim());
if (matcher.matches()) {
out.append(constructVariable(matcher.group(1), matcher.group(2)));
} else {
Expand Down Expand Up @@ -1258,7 +1264,7 @@ private CmdDesc methodDescription(CmdLine line) {
Class<?> clazz = null;
String methodName = null;
String buffer = line.getHead();
int eqsep = Helpers.statementBegin(new Brackets(buffer));
int eqsep = Helpers.statementBegin(buffer);
int varsep = buffer.lastIndexOf('.');
if (varsep > 0 && varsep > eqsep) {
loadStatementVars(buffer);
Expand Down Expand Up @@ -1421,9 +1427,12 @@ private CmdDesc checkSyntax(CmdLine line) {
if (openingRound == -1) {
return out;
}
String cuttedLine = line.getHead().substring(0, openingRound);
if (new Brackets(cuttedLine).openQuote()) {
return out;
}
loadStatementVars(line.getHead());
Brackets brackets = new Brackets(line.getHead().substring(0, openingRound));
int eqsep = Helpers.statementBegin(brackets);
int eqsep = Helpers.statementBegin(cuttedLine);
int end = line.getHead().length();
if (eqsep > 0 && Helpers.constructorStatement(line.getHead().substring(0, eqsep))) {
eqsep = line.getHead().substring(0, eqsep).lastIndexOf("new") - 1;
Expand Down

0 comments on commit 280d75c

Please sign in to comment.