< prev index next >
src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java
Print this page
*** 53,68 ****
// A simple source completer for nashorn
final class NashornCompleter implements Completer {
private final Context context;
private final Global global;
private final PartialParser partialParser;
private final Parser parser;
! NashornCompleter(final Context context, final Global global, final PartialParser partialParser) {
this.context = context;
this.global = global;
this.partialParser = partialParser;
this.parser = Parser.create();
}
// Pattern to match a unfinished member selection expression. object part and "."
// but property name missing pattern.
--- 53,71 ----
// A simple source completer for nashorn
final class NashornCompleter implements Completer {
private final Context context;
private final Global global;
private final PartialParser partialParser;
+ private final PropertiesHelper propsHelper;
private final Parser parser;
! NashornCompleter(final Context context, final Global global,
! final PartialParser partialParser, final PropertiesHelper propsHelper) {
this.context = context;
this.global = global;
this.partialParser = partialParser;
+ this.propsHelper = propsHelper;
this.parser = Parser.create();
}
// Pattern to match a unfinished member selection expression. object part and "."
// but property name missing pattern.
*** 120,153 ****
// try to evaluate the object expression part as a script
Object obj = null;
try {
obj = context.eval(global, objExprCode, global, "<suggestions>");
! } catch (Exception ignored) {
! // throw the exception - this is during tab-completion
}
if (obj != null && obj != ScriptRuntime.UNDEFINED) {
if (endsWithDot) {
// no user specified "prefix". List all properties of the object
! result.addAll(PropertiesHelper.getProperties(obj));
return cursor;
} else {
// list of properties matching the user specified prefix
final String prefix = select.getIdentifier();
! result.addAll(PropertiesHelper.getProperties(obj, prefix));
return cursor - prefix.length();
}
}
return cursor;
}
private int completeIdentifier(final String test, final int cursor, final List<CharSequence> result,
final IdentifierTree ident) {
final String name = ident.getName();
! result.addAll(PropertiesHelper.getProperties(global, name));
return cursor - name.length();
}
// returns ExpressionTree if the given code parses to a top level expression.
// Or else returns null.
--- 123,159 ----
// try to evaluate the object expression part as a script
Object obj = null;
try {
obj = context.eval(global, objExprCode, global, "<suggestions>");
! } catch (Exception exp) {
! // throw away the exception - this is during tab-completion
! if (Main.DEBUG) {
! exp.printStackTrace();
! }
}
if (obj != null && obj != ScriptRuntime.UNDEFINED) {
if (endsWithDot) {
// no user specified "prefix". List all properties of the object
! result.addAll(propsHelper.getProperties(obj));
return cursor;
} else {
// list of properties matching the user specified prefix
final String prefix = select.getIdentifier();
! result.addAll(propsHelper.getProperties(obj, prefix));
return cursor - prefix.length();
}
}
return cursor;
}
private int completeIdentifier(final String test, final int cursor, final List<CharSequence> result,
final IdentifierTree ident) {
final String name = ident.getName();
! result.addAll(propsHelper.getProperties(global, name));
return cursor - name.length();
}
// returns ExpressionTree if the given code parses to a top level expression.
// Or else returns null.
< prev index next >