Skip to content

Commit

Permalink
Groovy identifiers completion a couple of improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Sep 28, 2020
1 parent ce3c930 commit 36d3bc7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ public static void doCandidates(List<Candidate> candidates, Map<String,String> f
group = "Fields";
} else if (type == CandidateType.IDENTIFIER) {
group = "Identifiers";
if (s.contains("-") || s.contains("+") || s.contains(" ") || s.contains("#")
|| !s.matches("[a-zA-Z$_].*")){
continue;
}
} else if (type == CandidateType.META_METHOD) {
postFix = "(";
group = "MetaMethods";
Expand Down Expand Up @@ -906,13 +910,17 @@ private void doMethodCandidates(List<Candidate> candidates, Class<?> clazz, Stri
Set<String> identifiers = new HashSet<>();
for (String m : methods) {
if (m.matches("get[A-Z].*")) {
try {
clazz.getDeclaredMethod(m);
char[] c = m.substring(3).toCharArray();
c[0] = Character.toLowerCase(c[0]);
identifiers.add(new String(c));
} catch (NoSuchMethodException e) {
// ignore
Class<?> cc = clazz;
while (cc != null) {
try {
cc.getDeclaredMethod(m);
char[] c = m.substring(3).toCharArray();
c[0] = Character.toLowerCase(c[0]);
identifiers.add(new String(c));
break;
} catch (NoSuchMethodException e) {
cc = cc.getSuperclass();
}
}
}
}
Expand Down

0 comments on commit 36d3bc7

Please sign in to comment.