--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/ReplParserFactory.java Mon Feb 06 15:57:35 2017 +0100
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/ReplParserFactory.java Mon Feb 06 09:00:02 2017 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -36,25 +36,26 @@
*/
class ReplParserFactory extends ParserFactory {
- public static ParserFactory instance(Context context) {
- ParserFactory instance = context.get(parserFactoryKey);
- if (instance == null) {
- instance = new ReplParserFactory(context);
- }
- return instance;
+ // force starting in expression mode
+ private final boolean forceExpression;
+
+ public static void preRegister(Context context, boolean forceExpression) {
+ context.put(parserFactoryKey, (Context.Factory<ParserFactory>)
+ (c -> new ReplParserFactory(c, forceExpression)));
}
private final ScannerFactory scannerFactory;
- protected ReplParserFactory(Context context) {
+ protected ReplParserFactory(Context context, boolean forceExpression) {
super(context);
+ this.forceExpression = forceExpression;
this.scannerFactory = ScannerFactory.instance(context);
}
@Override
public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) {
com.sun.tools.javac.parser.Lexer lexer = scannerFactory.newScanner(input, keepDocComments);
- return new ReplParser(this, lexer, keepDocComments, keepLineMap, keepEndPos);
+ return new ReplParser(this, lexer, keepDocComments, keepLineMap, keepEndPos, forceExpression);
}
@Override