Skip to content

Commit ea705a7

Browse files
committed
Fix autocompletions for instance variables: must list instance fields and methods,
not the static ones. Tested with: from ij.process import ShortProcessor from ij import ImagePlus imp = ImagePlus("this", ShortProcessor(100, 100) # test 1: imp. # expand to instance fields and methods # test 2: ImagePlus. # expand to static fields and methods
1 parent 0943f79 commit ea705a7

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/main/java/org/scijava/jython/autocompletion/JythonScriptParser.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ static public Map<String, DotAutocompletions> parseImportStatement(final Import
163163
return classes;
164164
}
165165

166+
static private DotAutocompletions maybeStaticToDot(final PythonTree node, final DotAutocompletions da) {
167+
System.out.println("children count:" + node.getChildCount() + ", children: " + (null != node.getChildren() ? node.getChildren().stream().map(c -> c.toString()).collect(Collectors.toList()) : ""));
168+
if (node.getChildCount() > 0 && da instanceof StaticDotAutocompletions) {
169+
// It's a right expression (a constructor invocation assigned to a variable on the left) so the left is an instance of the class
170+
return new VarDotAutocompletions(da.getClassname());
171+
}
172+
return da;
173+
}
174+
166175
/**
167176
* Parse an assignment (an equal sign) to find out the class of the left side (the variable)
168177
* by asking the right side about what it is or returns.
@@ -186,13 +195,13 @@ static public Map<String, DotAutocompletions> parseAssignStatement(final Assign
186195
continue;
187196
}
188197
final String name = ct.toString();
189-
final DotAutocompletions val = parseRight(right.getChildren().get(i), scope);
198+
final DotAutocompletions val = maybeStaticToDot(right, parseRight(right.getChildren().get(i), scope));
190199
if (null != val) assigns.put(name, val);
191200
}
192201
} else {
193202
// Left is a Name: simple assignment e.g. "one = 1"
194203
if ( left instanceof Name ) {
195-
assigns.put(((Name)left).getInternalId(), parseRight(right, scope));
204+
assigns.put(((Name)left).getInternalId(), maybeStaticToDot(right, parseRight(right, scope)));
196205
return assigns;
197206
}
198207
// Assignment to an attribute

0 commit comments

Comments
 (0)