|
1 | | -package org.scijava.ui.swing.script; |
| 1 | +package org.scijava.ui.swing.script.autocompletion; |
2 | 2 |
|
3 | 3 | import java.lang.reflect.Field; |
4 | 4 | import java.lang.reflect.Method; |
5 | 5 | import java.lang.reflect.Modifier; |
6 | 6 | import java.util.ArrayList; |
7 | 7 | import java.util.Collections; |
8 | 8 | import java.util.List; |
| 9 | +import java.util.function.Function; |
9 | 10 | import java.util.regex.Matcher; |
10 | 11 | import java.util.regex.Pattern; |
11 | 12 | import java.util.stream.Collectors; |
|
17 | 18 | import org.fife.ui.autocomplete.Completion; |
18 | 19 | import org.fife.ui.autocomplete.DefaultCompletionProvider; |
19 | 20 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; |
| 21 | +import org.scijava.ui.swing.script.ClassUtil; |
20 | 22 |
|
21 | 23 | public class AutocompletionProvider extends DefaultCompletionProvider { |
22 | 24 |
|
@@ -67,10 +69,18 @@ public List<Completion> getCompletionsImpl(final JTextComponent comp) { |
67 | 69 |
|
68 | 70 | final String text = this.getAlreadyEnteredText(comp); |
69 | 71 |
|
70 | | - // E.g. "from ij" to expand to a package name like ij or ij.gui or ij.plugin |
| 72 | + // E.g. "from ij" to expand to a package name and class like ij or ij.gui or ij.plugin |
71 | 73 | final Matcher m1 = fromImport.matcher(text); |
72 | 74 | if (m1.find()) |
73 | | - return asCompletionList(ClassUtil.findPackageNamesStartingWith(m1.group(2)), m1.group(1)); |
| 75 | + return asCompletionList(ClassUtil.findClassNamesContaining(m1.group(2)) |
| 76 | + .map(new Function<String, String>() { |
| 77 | + @Override |
| 78 | + public final String apply(final String s) { |
| 79 | + final int idot = s.lastIndexOf('.'); |
| 80 | + return s.substring(0, Math.max(0, idot)) + " import " + s.substring(idot +1); |
| 81 | + } |
| 82 | + }), |
| 83 | + m1.group(1)); |
74 | 84 |
|
75 | 85 | final Matcher m1f = fastImport.matcher(text); |
76 | 86 | if (m1f.find()) |
|
0 commit comments