Skip to content

Commit 94c1ef3

Browse files
committed
New interface method DotAutocompletions.getStream
1 parent 04cec1c commit 94c1ef3

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

src/main/java/org/scijava/plugins/scripteditor/jython/DotAutocompletions.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import java.lang.reflect.Method;
3333
import java.lang.reflect.Modifier;
3434
import java.util.ArrayList;
35+
import java.util.Arrays;
3536
import java.util.List;
37+
import java.util.stream.Stream;
3638

3739
import org.scijava.ui.swing.script.autocompletion.CompletionText;
3840

@@ -49,6 +51,10 @@ default public String getSummary() {
4951
}
5052

5153
public List<CompletionText> get();
54+
55+
default public Stream<CompletionText> getStream() {
56+
return get().stream();
57+
}
5258

5359
static public List<CompletionText> getPublicFieldsAndMethods(final String className) {
5460
final List<CompletionText> ac = new ArrayList<>();
@@ -60,7 +66,7 @@ static public List<CompletionText> getPublicFieldsAndMethods(final String classN
6066
for (final Method m: c.getMethods())
6167
ac.add(new CompletionText(m.getName() + "()", c, m)); // TODO could do a parameter-driven autocompletion
6268
} catch (final Exception e) {
63-
if (JythonAutocompletionProvider.debug >= 2) System.out.println("Could not load class " + className + " :: " + e.getMessage());
69+
JythonDev.print("Could not load class " + className, e);
6470
}
6571
}
6672
return ac;
@@ -78,7 +84,7 @@ static public void staticFieldsAndStaticMethodsInto(final Class<?> c, final List
7884
ac.add(new CompletionText(f.getName(), c, f));
7985
for (final Method m: c.getDeclaredMethods())
8086
if (Modifier.isStatic(m.getModifiers()))
81-
ac.add(new CompletionText(m.getName() + "()", c, m)); // TODO could do a parameter-driven autocompletion
87+
ac.add(new CompletionText(m.getName() + "()", c, m));
8288
}
8389

8490
/** Collect non-static fields and non-static methods of class {@code c} into {@code ac}.
@@ -92,7 +98,27 @@ static public void fieldsAndMethodsInto(final Class<?> c, final List<CompletionT
9298
ac.add(new CompletionText(f.getName(), c, f));
9399
for (final Method m: c.getDeclaredMethods())
94100
if (!Modifier.isStatic(m.getModifiers()))
95-
ac.add(new CompletionText(m.getName() + "()", c, m)); // TODO could do a parameter-driven autocompletion
101+
ac.add(new CompletionText(m.getName() + "()", c, m));
102+
}
103+
104+
static public Stream<CompletionText> staticFieldsAndStaticMethodsStream(final Class<?> c, final boolean staticFields, final boolean staticMethods) {
105+
return Stream.concat(
106+
Arrays.stream(c.getDeclaredFields())
107+
.filter(f -> Modifier.isStatic(f.getModifiers()))
108+
.map(f -> new CompletionText(f.getName(), c, f)),
109+
Arrays.stream(c.getDeclaredMethods())
110+
.filter(m -> Modifier.isStatic(m.getModifiers()))
111+
.map(m -> new CompletionText(m.getName(), c, m)));
112+
}
113+
114+
static public Stream<CompletionText> fieldsAndMethodsStream(final Class<?> c, final boolean staticFields, final boolean staticMethods) {
115+
return Stream.concat(
116+
Arrays.stream(c.getFields())
117+
.filter(f -> !Modifier.isStatic(f.getModifiers()))
118+
.map(f -> new CompletionText(f.getName(), c, f)),
119+
Arrays.stream(c.getMethods())
120+
.filter(m -> !Modifier.isStatic(m.getModifiers()))
121+
.map(m -> new CompletionText(m.getName(), c, m)));
96122
}
97123

98124
}

0 commit comments

Comments
 (0)