Merge
authorlana
Thu, 26 Jan 2017 21:20:40 +0000
changeset 43371 ff36ce949e5b
parent 43362 7c20cb28b379 (current diff)
parent 43370 5969237f927c (diff)
child 43372 4b28b3f27a64
Merge
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/Elements.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/Elements.java	Thu Jan 26 21:20:40 2017 +0000
@@ -52,7 +52,7 @@
      * If running with modules, all modules in the modules graph are searched for matching packages.
      *
      * @param name  fully qualified package name, or an empty string for an unnamed package
-     * @return the named package, or {@code null} if it cannot be uniquely found
+     * @return the specified package, or {@code null} if it cannot be uniquely found
      */
     PackageElement getPackageElement(CharSequence name);
 
@@ -61,7 +61,7 @@
      *
      * @param name  fully qualified package name, or an empty string for an unnamed package
      * @param module module relative to which the lookup should happen
-     * @return the named package, or {@code null} if it cannot be found
+     * @return the specified package, or {@code null} if it cannot be found
      * @since 9
      */
     PackageElement getPackageElement(ModuleElement module, CharSequence name);
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Thu Jan 26 21:20:40 2017 +0000
@@ -190,7 +190,7 @@
             compiler.genEndPos = true;
             notYetEntered = new HashMap<>();
             if (forParse) {
-                compiler.initProcessAnnotations(processors);
+                compiler.initProcessAnnotations(processors, args.getFileObjects(), args.getClassNames());
                 for (JavaFileObject file: args.getFileObjects())
                     notYetEntered.put(file, null);
                 genList = new ListBuffer<>();
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Jan 26 21:20:40 2017 +0000
@@ -921,7 +921,7 @@
         start_msec = now();
 
         try {
-            initProcessAnnotations(processors);
+            initProcessAnnotations(processors, sourceFileObjects, classnames);
 
             for (String className : classnames) {
                 int sep = className.indexOf('/');
@@ -1123,7 +1123,9 @@
      * @param processors user provided annotation processors to bypass
      * discovery, {@code null} means that no processors were provided
      */
-    public void initProcessAnnotations(Iterable<? extends Processor> processors) {
+    public void initProcessAnnotations(Iterable<? extends Processor> processors,
+                                       Collection<? extends JavaFileObject> initialFiles,
+                                       Collection<String> initialClassNames) {
         // Process annotations if processing is not disabled and there
         // is at least one Processor available.
         if (options.isSet(PROC, "none")) {
@@ -1141,6 +1143,7 @@
                 if (!taskListener.isEmpty())
                     taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
                 deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
+                procEnvImpl.getFiler().setInitialState(initialFiles, initialClassNames);
             } else { // free resources
                 procEnvImpl.close();
             }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java	Thu Jan 26 21:20:40 2017 +0000
@@ -140,8 +140,6 @@
 
     private PackageSymbol doGetPackageElement(ModuleElement module, CharSequence name) {
         ensureEntered("getPackageElement");
-        if (name.length() == 0)
-            return syms.unnamedModule.unnamedPackage;
         return doGetElement(module, "getPackageElement", name, PackageSymbol.class);
     }
 
@@ -165,7 +163,7 @@
     private <S extends Symbol> S doGetElement(ModuleElement module, String methodName,
                                               CharSequence name, Class<S> clazz) {
         String strName = name.toString();
-        if (!SourceVersion.isName(strName)) {
+        if (!SourceVersion.isName(strName) && (!strName.isEmpty() || clazz == ClassSymbol.class)) {
             return null;
         }
         if (module == null) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java	Thu Jan 26 21:20:40 2017 +0000
@@ -51,9 +51,11 @@
 import static javax.tools.StandardLocation.CLASS_OUTPUT;
 
 import com.sun.tools.javac.code.Lint;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
 import com.sun.tools.javac.code.Symtab;
 import com.sun.tools.javac.comp.Modules;
+import com.sun.tools.javac.model.JavacElements;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.DefinedBy.Api;
 
@@ -321,6 +323,7 @@
     }
 
     JavaFileManager fileManager;
+    JavacElements elementUtils;
     Log log;
     Modules modules;
     Names names;
@@ -331,6 +334,12 @@
     private final boolean lint;
 
     /**
+     * Initial inputs passed to the tool.  This set must be
+     * synchronized.
+     */
+    private final Set<FileObject> initialInputs;
+
+    /**
      * Logical names of all created files.  This set must be
      * synchronized.
      */
@@ -373,26 +382,30 @@
      */
     private final Set<Pair<ModuleSymbol, String>> aggregateGeneratedClassNames;
 
+    private final Set<String> initialClassNames;
 
     JavacFiler(Context context) {
         this.context = context;
         fileManager = context.get(JavaFileManager.class);
+        elementUtils = JavacElements.instance(context);
 
         log = Log.instance(context);
         modules = Modules.instance(context);
         names = Names.instance(context);
         syms = Symtab.instance(context);
 
-        fileObjectHistory = synchronizedSet(new LinkedHashSet<FileObject>());
-        generatedSourceNames = synchronizedSet(new LinkedHashSet<String>());
-        generatedSourceFileObjects = synchronizedSet(new LinkedHashSet<JavaFileObject>());
+        initialInputs = synchronizedSet(new LinkedHashSet<>());
+        fileObjectHistory = synchronizedSet(new LinkedHashSet<>());
+        generatedSourceNames = synchronizedSet(new LinkedHashSet<>());
+        generatedSourceFileObjects = synchronizedSet(new LinkedHashSet<>());
 
         generatedClasses = synchronizedMap(new LinkedHashMap<>());
 
-        openTypeNames  = synchronizedSet(new LinkedHashSet<String>());
+        openTypeNames  = synchronizedSet(new LinkedHashSet<>());
 
         aggregateGeneratedSourceNames = new LinkedHashSet<>();
         aggregateGeneratedClassNames  = new LinkedHashSet<>();
+        initialClassNames  = new LinkedHashSet<>();
 
         lint = (Lint.instance(context)).isEnabled(PROCESSING);
     }
@@ -596,8 +609,13 @@
         // TODO: Check if type already exists on source or class path?
         // If so, use warning message key proc.type.already.exists
         checkName(typename, allowUnnamedPackageInfo);
-        if (aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) ||
-            aggregateGeneratedClassNames.contains(Pair.of(mod, typename))) {
+        ClassSymbol existing;
+        boolean alreadySeen = aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) ||
+                              aggregateGeneratedClassNames.contains(Pair.of(mod, typename)) ||
+                              initialClassNames.contains(typename) ||
+                              ((existing = elementUtils.getTypeElement(typename)) != null &&
+                               initialInputs.contains(existing.sourcefile));
+        if (alreadySeen) {
             if (lint)
                 log.warning("proc.type.recreate", typename);
             throw new FilerException("Attempt to recreate a file for type " + typename);
@@ -611,16 +629,48 @@
      * Check to see if the file has already been opened; if so, throw
      * an exception, otherwise add it to the set of files.
      */
-    private void checkFileReopening(FileObject fileObject, boolean addToHistory) throws FilerException {
+    private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException {
+        if (isInFileObjectHistory(fileObject, forWriting)) {
+            if (lint)
+                log.warning("proc.file.reopening", fileObject.getName());
+            throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
+        }
+        if (forWriting)
+            fileObjectHistory.add(fileObject);
+    }
+
+    private boolean isInFileObjectHistory(FileObject fileObject, boolean forWriting) {
+        if (forWriting) {
+            for(FileObject veteran : initialInputs) {
+                try {
+                    if (fileManager.isSameFile(veteran, fileObject)) {
+                        return true;
+                    }
+                } catch (IllegalArgumentException e) {
+                    //ignore...
+                }
+            }
+            for (String className : initialClassNames) {
+                try {
+                    ClassSymbol existing = elementUtils.getTypeElement(className);
+                    if (   existing != null
+                        && (   (existing.sourcefile != null && fileManager.isSameFile(existing.sourcefile, fileObject))
+                            || (existing.classfile != null && fileManager.isSameFile(existing.classfile, fileObject)))) {
+                        return true;
+                    }
+                } catch (IllegalArgumentException e) {
+                    //ignore...
+                }
+            }
+        }
+
         for(FileObject veteran : fileObjectHistory) {
             if (fileManager.isSameFile(veteran, fileObject)) {
-                if (lint)
-                    log.warning("proc.file.reopening", fileObject.getName());
-                throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
+                return true;
             }
         }
-        if (addToHistory)
-            fileObjectHistory.add(fileObject);
+
+        return false;
     }
 
     public boolean newFiles() {
@@ -656,9 +706,17 @@
         this.lastRound = lastRound;
     }
 
+    public void setInitialState(Collection<? extends JavaFileObject> initialInputs,
+                                Collection<String> initialClassNames) {
+        this.initialInputs.addAll(initialInputs);
+        this.initialClassNames.addAll(initialClassNames);
+    }
+
     public void close() {
         clearRoundState();
         // Cross-round state
+        initialClassNames.clear();
+        initialInputs.clear();
         fileObjectHistory.clear();
         openTypeNames.clear();
         aggregateGeneratedSourceNames.clear();
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Jan 26 21:20:40 2017 +0000
@@ -1628,7 +1628,7 @@
     }
 
     @DefinedBy(Api.ANNOTATION_PROCESSING)
-    public Filer getFiler() {
+    public JavacFiler getFiler() {
         return filer;
     }
 
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Thu Jan 26 21:20:40 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -437,23 +437,23 @@
     protected void createSearchIndexFiles() throws DocFileIOException {
         if (configuration.showModules) {
             createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JSON, DocPaths.MODULE_SEARCH_INDEX_ZIP,
-                    configuration.moduleSearchIndex);
+                    DocPaths.MODULE_SEARCH_INDEX_JS, configuration.moduleSearchIndex, "moduleSearchIndex");
         }
         createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JSON, DocPaths.PACKAGE_SEARCH_INDEX_ZIP,
-                configuration.packageSearchIndex);
+                DocPaths.PACKAGE_SEARCH_INDEX_JS, configuration.packageSearchIndex, "packageSearchIndex");
         createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JSON, DocPaths.TYPE_SEARCH_INDEX_ZIP,
-                configuration.typeSearchIndex);
+                DocPaths.TYPE_SEARCH_INDEX_JS, configuration.typeSearchIndex, "typeSearchIndex");
         createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JSON, DocPaths.MEMBER_SEARCH_INDEX_ZIP,
-                configuration.memberSearchIndex);
+                DocPaths.MEMBER_SEARCH_INDEX_JS, configuration.memberSearchIndex, "memberSearchIndex");
         createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JSON, DocPaths.TAG_SEARCH_INDEX_ZIP,
-                configuration.tagSearchIndex);
+                DocPaths.TAG_SEARCH_INDEX_JS, configuration.tagSearchIndex, "tagSearchIndex");
     }
 
     /**
      * @throws DocFileIOException if there is a problem creating the search index file
      */
     protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip,
-            List<SearchIndexItem> searchIndex) throws DocFileIOException {
+            DocPath searchIndexJS, List<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
         if (!searchIndex.isEmpty()) {
             StringBuilder searchVar = new StringBuilder("[");
             boolean first = true;
@@ -466,6 +466,14 @@
                 }
             }
             searchVar.append("]");
+            DocFile jsFile = DocFile.createFileForOutput(configuration, searchIndexJS);
+            try (Writer wr = jsFile.openWriter()) {
+                wr.write(varName);
+                wr.write(" = ");
+                wr.write(searchVar.toString());
+            } catch (IOException ie) {
+                throw new DocFileIOException(jsFile, DocFileIOException.Mode.WRITE, ie);
+            }
 
             DocFile zipFile = DocFile.createFileForOutput(configuration, searchIndexZip);
             try (OutputStream fos = zipFile.openOutputStream();
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js	Thu Jan 26 21:20:40 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -77,6 +77,21 @@
                     tagSearchIndex = JSON.parse(zip.file("tag-search-index.json").asText());
                 });
             });
+    if (!moduleSearchIndex) {
+        createElem(doc, tag, 'module-search-index.js');
+    }
+    if (!packageSearchIndex) {
+        createElem(doc, tag, 'package-search-index.js');
+    }
+    if (!typeSearchIndex) {
+        createElem(doc, tag, 'type-search-index.js');
+    }
+    if (!memberSearchIndex) {
+        createElem(doc, tag, 'member-search-index.js');
+    }
+    if (!tagSearchIndex) {
+        createElem(doc, tag, 'tag-search-index.js');
+    }
 }
 
 function createElem(doc, tag, path) {
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java	Thu Jan 26 21:20:40 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -121,12 +121,18 @@
     /** The name of the member search index zip file. */
     public static final DocPath MEMBER_SEARCH_INDEX_ZIP = DocPath.create("member-search-index.zip");
 
+    /** The name of the member search index js file. */
+    public static final DocPath MEMBER_SEARCH_INDEX_JS = DocPath.create("member-search-index.js");
+
     /** The name of the module search index file. */
     public static final DocPath MODULE_SEARCH_INDEX_JSON = DocPath.create("module-search-index.json");
 
-    /** The name of the module search index zipfile. */
+    /** The name of the module search index zip file. */
     public static final DocPath MODULE_SEARCH_INDEX_ZIP = DocPath.create("module-search-index.zip");
 
+    /** The name of the module search index js file. */
+    public static final DocPath MODULE_SEARCH_INDEX_JS = DocPath.create("module-search-index.js");
+
     /** The name of the file for the overview frame. */
     public static final DocPath OVERVIEW_FRAME = DocPath.create("overview-frame.html");
 
@@ -149,9 +155,12 @@
     /** The name of the package search index file. */
     public static final DocPath PACKAGE_SEARCH_INDEX_JSON = DocPath.create("package-search-index.json");
 
-    /** The name of the package search index zipfile. */
+    /** The name of the package search index zip file. */
     public static final DocPath PACKAGE_SEARCH_INDEX_ZIP = DocPath.create("package-search-index.zip");
 
+    /** The name of the package search index js file. */
+    public static final DocPath PACKAGE_SEARCH_INDEX_JS = DocPath.create("package-search-index.js");
+
     /** The name of the file for the package summary. */
     public static final DocPath PACKAGE_SUMMARY = DocPath.create("package-summary.html");
 
@@ -202,12 +211,18 @@
     /** The name of the tag search index zip file. */
     public static final DocPath TAG_SEARCH_INDEX_ZIP = DocPath.create("tag-search-index.zip");
 
+    /** The name of the tag search index js file. */
+    public static final DocPath TAG_SEARCH_INDEX_JS = DocPath.create("tag-search-index.js");
+
     /** The name of the type search index file. */
     public static final DocPath TYPE_SEARCH_INDEX_JSON = DocPath.create("type-search-index.json");
 
     /** The name of the type search index zip file. */
     public static final DocPath TYPE_SEARCH_INDEX_ZIP = DocPath.create("type-search-index.zip");
 
+    /** The name of the type search index js file. */
+    public static final DocPath TYPE_SEARCH_INDEX_JS = DocPath.create("type-search-index.js");
+
     /** The name of the image file for undo button on the search box. */
     public static final DocPath X_IMG = DocPath.create("x.png");
 
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java	Thu Jan 26 21:20:40 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -56,6 +56,7 @@
 import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
 import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
 import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute;
+import com.sun.tools.classfile.RuntimeParameterAnnotations_attribute;
 import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
 import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute;
 import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute;
@@ -164,6 +165,7 @@
         print("default_value: ");
         annotationWriter.write(attr.default_value);
         indent(-1);
+        println();
         return null;
     }
 
@@ -764,9 +766,8 @@
         return null;
     }
 
-    @Override
-    public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) {
-        println("RuntimeVisibleParameterAnnotations:");
+    private void visitParameterAnnotations(String message, RuntimeParameterAnnotations_attribute attr) {
+        println(message);
         indent(+1);
         for (int param = 0; param < attr.parameter_annotations.length; param++) {
             println("parameter " + param + ": ");
@@ -779,24 +780,17 @@
             indent(-1);
         }
         indent(-1);
+    }
+
+    @Override
+    public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) {
+        visitParameterAnnotations("RuntimeVisibleParameterAnnotations:", (RuntimeParameterAnnotations_attribute) attr);
         return null;
     }
 
     @Override
     public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, Void ignore) {
-        println("RuntimeInvisibleParameterAnnotations:");
-        indent(+1);
-        for (int param = 0; param < attr.parameter_annotations.length; param++) {
-            println(param + ": ");
-            indent(+1);
-            for (int i = 0; i < attr.parameter_annotations[param].length; i++) {
-                print(i + ": ");
-                annotationWriter.write(attr.parameter_annotations[param][i]);
-                println();
-            }
-            indent(-1);
-        }
-        indent(-1);
+        visitParameterAnnotations("RuntimeInvisibleParameterAnnotations:", (RuntimeParameterAnnotations_attribute) attr);
         return null;
     }
 
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java	Thu Jan 26 21:20:40 2017 +0000
@@ -45,6 +45,7 @@
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -57,6 +58,7 @@
 import jdk.internal.jline.WindowsTerminal;
 import jdk.internal.jline.console.ConsoleReader;
 import jdk.internal.jline.console.KeyMap;
+import jdk.internal.jline.console.Operation;
 import jdk.internal.jline.console.UserInterruptException;
 import jdk.internal.jline.console.completer.Completer;
 import jdk.internal.jline.console.history.History;
@@ -90,7 +92,12 @@
             term = new JShellUnixTerminal(input);
         }
         term.init();
-        in = new ConsoleReader(cmdin, cmdout, term);
+        AtomicBoolean allowSmart = new AtomicBoolean();
+        in = new ConsoleReader(cmdin, cmdout, term) {
+            @Override public KeyMap getKeys() {
+                return new CheckCompletionKeyMap(super.getKeys(), allowSmart);
+            }
+        };
         in.setExpandEvents(false);
         in.setHandleUserInterrupt(true);
         List<String> persistenHistory = Stream.of(repl.prefs.keys())
@@ -106,9 +113,6 @@
         in.setBellEnabled(true);
         in.setCopyPasteDetection(true);
         in.addCompleter(new Completer() {
-            private String lastTest;
-            private int lastCursor;
-            private boolean allowSmart = false;
             @Override public int complete(String test, int cursor, List<CharSequence> result) {
                 int[] anchor = new int[] {-1};
                 List<Suggestion> suggestions;
@@ -119,16 +123,11 @@
                     suggestions = repl.analysis.completionSuggestions(prefix + test, cursor + prefixLength, anchor);
                     anchor[0] -= prefixLength;
                 }
-                if (!Objects.equals(lastTest, test) || lastCursor != cursor)
-                    allowSmart = true;
-
-                boolean smart = allowSmart &&
+                boolean smart = allowSmart.get() &&
                                 suggestions.stream()
                                            .anyMatch(Suggestion::matchesType);
 
-                lastTest = test;
-                lastCursor = cursor;
-                allowSmart = !allowSmart;
+                allowSmart.set(!allowSmart.get());
 
                 suggestions.stream()
                            .filter(s -> !smart || s.matchesType())
@@ -736,4 +735,57 @@
         }
 
     }
+
+    private static final class CheckCompletionKeyMap extends KeyMap {
+
+        private final KeyMap del;
+        private final AtomicBoolean allowSmart;
+
+        public CheckCompletionKeyMap(KeyMap del, AtomicBoolean allowSmart) {
+            super(del.getName(), del.isViKeyMap());
+            this.del = del;
+            this.allowSmart = allowSmart;
+        }
+
+        @Override
+        public void bind(CharSequence keySeq, Object function) {
+            del.bind(keySeq, function);
+        }
+
+        @Override
+        public void bindIfNotBound(CharSequence keySeq, Object function) {
+            del.bindIfNotBound(keySeq, function);
+        }
+
+        @Override
+        public void from(KeyMap other) {
+            del.from(other);
+        }
+
+        @Override
+        public Object getAnotherKey() {
+            return del.getAnotherKey();
+        }
+
+        @Override
+        public Object getBound(CharSequence keySeq) {
+            Object res = del.getBound(keySeq);
+
+            if (res != Operation.COMPLETE) {
+                allowSmart.set(true);
+            }
+
+            return res;
+        }
+
+        @Override
+        public void setBlinkMatchingParen(boolean on) {
+            del.setBlinkMatchingParen(on);
+        }
+
+        @Override
+        public String toString() {
+            return "check: " + del.toString();
+        }
+    }
 }
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Thu Jan 26 21:20:40 2017 +0000
@@ -426,7 +426,8 @@
         private final OptionSpecBuilder argHelp = parser.acceptsAll(asList("h", "help"));
         private final OptionSpecBuilder argVersion = parser.accepts("version");
         private final OptionSpecBuilder argFullVersion = parser.accepts("full-version");
-        private final OptionSpecBuilder argX = parser.accepts("X");
+        private final OptionSpecBuilder argShowVersion = parser.accepts("show-version");
+        private final OptionSpecBuilder argHelpExtra = parser.acceptsAll(asList("X", "help-extra"));
 
         private String feedbackMode = null;
         private Startup initialStartup = null;
@@ -450,7 +451,7 @@
                 printUsage();
                 return null;
             }
-            if (options.has(argX)) {
+            if (options.has(argHelpExtra)) {
                 printUsageX();
                 return null;
             }
@@ -462,6 +463,9 @@
                 cmdout.printf("jshell %s\n", fullVersion());
                 return null;
             }
+            if (options.has(argShowVersion)) {
+                cmdout.printf("jshell %s\n", version());
+            }
             if ((options.valuesOf(argFeedback).size() +
                     (options.has(argQ) ? 1 : 0) +
                     (options.has(argS) ? 1 : 0) +
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties	Thu Jan 26 21:20:40 2017 +0000
@@ -187,9 +187,10 @@
 \                            Use one -R for each remote flag or flag argument\n\
 \    -C<flag>              Pass <flag> to the compiler.\n\
 \                            Use one -C for each compiler flag or flag argument\n\
-\    --help                Print this synopsis of standard options\n\
-\    --version             Version information\n\
-\    -X                    Print help on non-standard options\n
+\    --version             Print version information and exit\n\
+\    --show-version        Print version information and continue\n\
+\    --help                Print this synopsis of standard options and exit\n\
+\    --help-extra, -X      Print help on non-standard options and exit\n
 help.usage.x = \
 \    --add-exports <module>/<package>   Export specified module-private package to snippets\n\
 \    --execution <spec>                 Specify an alternate execution engine.\n\
--- a/langtools/test/ProblemList.txt	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/test/ProblemList.txt	Thu Jan 26 21:20:40 2017 +0000
@@ -36,8 +36,7 @@
 #
 # jshell
 
-jdk/jshell/ToolFormatTest.java                                                  8170216    solaris-sparcv9
-jdk/jshell/ReplaceTest.java                                                     8170216    solaris-sparcv9
+jdk/jshell/UserJdiUserRemoteTest.java                                           8173204    linux-all
 jdk/jshell/UserInputTest.java                                                   8169536    generic-all   
 
 ###########################################################################
--- a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Thu Jan 26 21:20:40 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8141492 8071982 8141636 8147890
+ * @bug 8141492 8071982 8141636 8147890 8166175
  * @summary Test the search feature of javadoc.
  * @author bpatel
  * @library ../lib
@@ -47,10 +47,14 @@
         checkSearchJS();
         checkFiles(false,
                 "package-search-index.zip",
-                "tag-search-index.zip");
+                "tag-search-index.zip",
+                "package-search-index.js",
+                "tag-search-index.js");
         checkFiles(true,
                 "member-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -67,7 +71,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -84,7 +92,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -100,6 +112,10 @@
                 "package-search-index.zip",
                 "tag-search-index.zip",
                 "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js",
                 "index-all.html");
     }
 
@@ -117,7 +133,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -133,6 +153,10 @@
                 "package-search-index.zip",
                 "tag-search-index.zip",
                 "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js",
                 "index-all.html");
     }
 
@@ -150,7 +174,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -167,7 +195,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -184,7 +216,11 @@
                 "member-search-index.zip",
                 "package-search-index.zip",
                 "tag-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "tag-search-index.js",
+                "type-search-index.js");
     }
 
     @Test
@@ -197,11 +233,15 @@
         checkJqueryAndImageFiles(true);
         checkSearchJS();
         checkFiles(false,
-                "tag-search-index.zip");
+                "tag-search-index.zip",
+                "tag-search-index.js");
         checkFiles(true,
                 "member-search-index.zip",
                 "package-search-index.zip",
-                "type-search-index.zip");
+                "type-search-index.zip",
+                "member-search-index.js",
+                "package-search-index.js",
+                "type-search-index.js");
     }
 
     void checkDocLintErrors() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/jshell/ForwardReferenceImportTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -0,0 +1,392 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test 8173232
+ * @summary Test of forward referencing of snippets (related to import).
+ * @build KullaTesting TestingInputStream
+ * @run testng ForwardReferenceImportTest
+ */
+
+import jdk.jshell.Snippet;
+import jdk.jshell.DeclarationSnippet;
+import org.testng.annotations.Test;
+
+import static jdk.jshell.Snippet.Status.*;
+
+@Test
+public class ForwardReferenceImportTest extends KullaTesting {
+
+    public void testImportDeclare() {
+        Snippet singleImport = importKey(assertEval("import java.util.List;", added(VALID)));
+        Snippet importOnDemand = importKey(assertEval("import java.util.*;", added(VALID)));
+        Snippet singleStaticImport = importKey(assertEval("import static java.lang.Math.abs;", added(VALID)));
+        Snippet staticImportOnDemand = importKey(assertEval("import static java.lang.Math.*;", added(VALID)));
+        assertEval("import java.util.List; //again",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(singleImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertEval("import java.util.*; //again",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(importOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertEval("import static java.lang.Math.abs; //again",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(singleStaticImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertEval("import static java.lang.Math.*; //again",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(staticImportOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertActiveKeys();
+    }
+
+    public void testForwardSingleImportMethodToMethod() {
+        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
+                added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
+        assertEvalUnresolvedException("string();", "string", 1, 0);
+        assertEval("import static java.lang.String.format;",
+                added(VALID),
+                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("string();", "\"string\"");
+
+        assertEval("double format(String s) { return 0; }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
+        assertEvalUnresolvedException("string();", "string", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardImportMethodOnDemandToMethod() {
+        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
+                added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
+        assertEvalUnresolvedException("string();", "string", 1, 0);
+        assertEval("import static java.lang.String.*;",
+                added(VALID),
+                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("string();", "\"string\"");
+
+        assertEval("double format(String s) { return 0; }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
+        assertEvalUnresolvedException("string();", "string", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardSingleImportFieldToMethod() {
+        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
+                added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
+        assertEvalUnresolvedException("pi();", "pi", 1, 0);
+        assertEval("import static java.lang.Math.PI;",
+                added(VALID),
+                ste(pi, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
+
+        assertEval("String PI;",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(pi, VALID, RECOVERABLE_DEFINED, false, null));
+        assertEvalUnresolvedException("pi();", "pi", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardImportFieldOnDemandToMethod() {
+        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
+                added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
+        assertEvalUnresolvedException("pi();", "pi", 1, 0);
+        assertEval("import static java.lang.Math.*;",
+                added(VALID),
+                ste(pi, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
+        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
+
+        assertEval("String PI;",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(pi, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        assertEvalUnresolvedException("pi();", "pi", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardSingleImportMethodToClass1() {
+        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.String.format;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("new A().s;", "\"10\"");
+        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(format,
+                ste(format, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
+    }
+
+    public void testForwardSingleImportMethodToClass2() {
+        Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.String.format;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("new A().s();", "\"10\"");
+        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(format,
+                ste(format, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
+    }
+
+    public void testForwardSingleImportClassToClass1() {
+        Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
+                added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+        assertEval("import java.util.List;",
+                added(VALID),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
+        assertEval("import java.util.Arrays;", added(VALID));
+        assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
+
+        Snippet list = classKey(assertEval("class List {}",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
+        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.static.single.import");
+        assertActiveKeys();
+        assertDrop(list,
+                ste(list, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
+    }
+
+    public void testForwardSingleImportClassToClass2() {
+        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
+                added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+        assertEval("import java.util.ArrayList;",
+                added(VALID),
+                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
+        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
+
+        Snippet arraylist = classKey(assertEval("class ArrayList {}",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
+                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
+        assertDeclareFail("A a = new A();", "compiler.err.cant.resolve.location",
+                ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, REJECTED, false, null),
+                ste(vara, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertActiveKeys();
+        assertDrop(arraylist,
+                ste(arraylist, VALID, DROPPED, true, null),
+                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist));
+    }
+
+    public void testForwardImportOnDemandMethodToClass1() {
+        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.String.*;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("A x = new A();");
+        assertEval("x.s;", "\"10\"");
+        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(format,
+                ste(format, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
+        assertEval("x.s;", "\"10\"");
+    }
+
+    public void testForwardImportOnDemandMethodToClass2() {
+        Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.String.*;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("new A().s();", "\"10\"");
+        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(format,
+                ste(format, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
+    }
+
+    public void testForwardImportOnDemandClassToClass1() {
+        Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
+                added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+        assertEval("import java.util.*;",
+                added(VALID),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
+        assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
+
+        Snippet list = classKey(assertEval("class List {}",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
+        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.cant.resolve.location");
+        assertActiveKeys();
+        assertDrop(list,
+                ste(list, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
+    }
+
+    public void testForwardImportOnDemandClassToClass2() {
+        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
+                added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+        assertEval("import java.util.*;",
+                added(VALID),
+                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
+        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
+
+        Snippet arraylist = classKey(assertEval("class ArrayList {}",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
+                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+        assertActiveKeys();
+        assertDrop(arraylist,
+                ste(arraylist, VALID, DROPPED, true, null),
+                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist),
+                ste(vara, RECOVERABLE_NOT_DEFINED, VALID, true, clsA));
+    }
+
+    public void testForwardSingleImportFieldToClass1() {
+        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.Math.PI;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
+
+        Snippet list = varKey(assertEval("String PI;",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(list,
+                ste(list, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
+    }
+
+    public void testForwardSingleImportFieldToClass2() {
+        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.Math.PI;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
+        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
+
+        Snippet list = varKey(assertEval("String PI;",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(list,
+                ste(list, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
+    }
+
+    public void testForwardImportOnDemandFieldToClass1() {
+        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.Math.*;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
+
+        Snippet list = varKey(assertEval("String PI;",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(list,
+                ste(list, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
+    }
+
+    public void testForwardImportOnDemandFieldToClass2() {
+        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
+                added(RECOVERABLE_DEFINED)));
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        assertEval("import static java.lang.Math.*;",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
+        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
+
+        Snippet list = varKey(assertEval("String PI;",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                added(VALID),
+                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
+        assertEvalUnresolvedException("new A();", "A", 0, 1);
+        assertActiveKeys();
+        assertDrop(list,
+                ste(list, VALID, DROPPED, true, null),
+                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
+        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/jshell/ForwardReferenceTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test 8173232
+ * @summary Test of forward referencing of snippets.
+ * @build KullaTesting TestingInputStream
+ * @run testng ForwardReferenceTest
+ */
+
+import java.util.List;
+import jdk.jshell.Snippet;
+import jdk.jshell.MethodSnippet;
+import jdk.jshell.VarSnippet;
+import jdk.jshell.DeclarationSnippet;
+import org.testng.annotations.Test;
+
+import jdk.jshell.SnippetEvent;
+import jdk.jshell.UnresolvedReferenceException;
+import static org.testng.Assert.assertEquals;
+import static jdk.jshell.Snippet.Status.*;
+import static org.testng.Assert.assertTrue;
+
+@Test
+public class ForwardReferenceTest extends KullaTesting {
+
+    public void testOverwriteMethodForwardReferenceClass() {
+        Snippet k1 = methodKey(assertEval("int q(Boo b) { return b.x; }",
+                added(RECOVERABLE_NOT_DEFINED)));
+        assertUnresolvedDependencies1((MethodSnippet) k1, RECOVERABLE_NOT_DEFINED, "class Boo");
+        assertEval("class Boo { int x = 55; }",
+                added(VALID),
+                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
+        assertMethodDeclSnippet((MethodSnippet) k1, "q", "(Boo)int", VALID, 0, 0);
+        assertEval("q(new Boo());", "55");
+        assertActiveKeys();
+    }
+
+    public void testOverwriteMethodForwardReferenceClassImport() {
+        MethodSnippet k1 = methodKey(assertEval("int ff(List lis) { return lis.size(); }",
+                added(RECOVERABLE_NOT_DEFINED)));
+        assertUnresolvedDependencies1(k1, RECOVERABLE_NOT_DEFINED, "class List");
+        assertEval("import java.util.*;",
+                added(VALID),
+                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
+        assertMethodDeclSnippet(k1, "ff", "(List)int", VALID, 0, 0);
+        assertEval("ff(new ArrayList());", "0");
+        assertActiveKeys();
+    }
+
+    public void testForwardVarToMethod() {
+        DeclarationSnippet t = methodKey(assertEval("int t() { return x; }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "variable x");
+        assertEvalUnresolvedException("t();", "t", 1, 0);
+        Snippet x = varKey(assertEval("int x = 33;", "33",
+                added(VALID),
+                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("t();", "33");
+        assertEval("double x = 0.88;",
+                "0.88", null,
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        assertEvalUnresolvedException("t();", "t", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardMethodToMethod() {
+        Snippet t = methodKey(assertEval("int t() { return f(); }", added(RECOVERABLE_DEFINED)));
+        Snippet f = methodKey(assertEval("int f() { return g(); }",
+                added(RECOVERABLE_DEFINED),
+                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertUnresolvedDependencies1((DeclarationSnippet) f, RECOVERABLE_DEFINED, "method g()");
+        assertEvalUnresolvedException("t();", "f", 1, 0);
+        Snippet g = methodKey(assertEval("int g() { return 55; }",
+                added(VALID),
+                ste(f, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("t();", "55");
+        assertEval("double g() { return 3.14159; }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(f, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        DeclarationSnippet exsn = assertEvalUnresolvedException("t();", "f", 0, 1);
+        assertTrue(exsn == f, "Identity must not change");
+        assertActiveKeys();
+    }
+
+    public void testForwardClassToMethod() {
+        DeclarationSnippet t = methodKey(assertEval("int t() { return new A().f(); }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "class A");
+        assertEvalUnresolvedException("t();", "t", 1, 0);
+        Snippet a = classKey(assertEval(
+                "class A {\n" +
+                        "   int f() { return 10; }\n" +
+                "}",
+                added(VALID),
+                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("t();", "10");
+        assertEval(
+                "class A {\n" +
+                "   double f() { return 88.0; }\n" +
+                "}",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        assertEvalUnresolvedException("t();", "t", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardVarToClass() {
+        DeclarationSnippet a = classKey(assertEval("class A { int f() { return g; } }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
+        Snippet g = varKey(assertEval("int g = 10;", "10",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("new A().f();", "10");
+        assertEval("double g = 10;", "10.0", null,
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        assertUnresolvedDependencies(a, 0);
+        assertActiveKeys();
+    }
+
+    public void testForwardVarToClassGeneric() {
+        DeclarationSnippet a = classKey(assertEval("class A<T> { final T x; A(T v) { this.x = v; } ; T get() { return x; } int core() { return g; } }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
+
+        List<SnippetEvent> events = assertEval("A<String> as = new A<>(\"hi\");", null,
+                UnresolvedReferenceException.class, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, null);
+        SnippetEvent ste = events.get(0);
+        Snippet assn = ste.snippet();
+        DeclarationSnippet unsn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
+        assertEquals(unsn.name(), "A", "Wrong with unresolved");
+        assertEquals(getState().unresolvedDependencies(unsn).count(), 1, "Wrong size unresolved");
+        assertEquals(getState().diagnostics(unsn).count(), 0L, "Expected no diagnostics");
+
+        Snippet g = varKey(assertEval("int g = 10;", "10",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
+        assertEval("A<String> as = new A<>(\"low\");",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(assn, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertEval("as.get();", "\"low\"");
+        assertUnresolvedDependencies(a, 0);
+        assertActiveKeys();
+    }
+
+   public void testForwardVarToClassExtendsImplements() {
+        DeclarationSnippet ik = classKey(assertEval("interface I { default int ii() { return 1; } }", added(VALID)));
+        DeclarationSnippet jk = classKey(assertEval("interface J { default int jj() { return 2; } }", added(VALID)));
+        DeclarationSnippet ck = classKey(assertEval("class C { int cc() { return 3; } }", added(VALID)));
+        DeclarationSnippet dk = classKey(assertEval("class D extends C implements I,J { int dd() { return g; } }", added(RECOVERABLE_DEFINED)));
+        DeclarationSnippet ek = classKey(assertEval("class E extends D { int ee() { return 5; } }", added(VALID)));
+        assertUnresolvedDependencies1(dk, RECOVERABLE_DEFINED, "variable g");
+        assertEvalUnresolvedException("new D();", "D", 1, 0);
+        assertEvalUnresolvedException("new E();", "D", 1, 0);
+        VarSnippet g = varKey(assertEval("int g = 10;", "10",
+                added(VALID),
+                ste(dk, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
+        assertEval("E e = new E();");
+        assertDrop(g,
+                ste(g, VALID, DROPPED, true, null),
+                ste(dk, VALID, RECOVERABLE_DEFINED, false, g));
+        assertEvalUnresolvedException("new D();", "D", 1, 0);
+        assertEvalUnresolvedException("new E();", "D", 1, 0);
+        assertEval("e.ee();", "5");
+        assertEvalUnresolvedException("e.dd();", "D", 1, 0);
+        assertEval("e.cc();", "3");
+        assertEval("e.jj();", "2");
+        assertEval("e.ii();", "1");
+        assertActiveKeys();
+    }
+
+    public void testForwardVarToInterface() {
+        DeclarationSnippet i = classKey(assertEval("interface I { default int f() { return x; } }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(i, RECOVERABLE_DEFINED, "variable x");
+        DeclarationSnippet c = classKey(assertEval("class C implements I { int z() { return 2; } }", added(VALID)));
+        assertEval("C c = new C();");
+        assertEval("c.z();", "2");
+        assertEvalUnresolvedException("c.f()", "I", 1, 0);
+        Snippet g = varKey(assertEval("int x = 55;", "55",
+                added(VALID),
+                ste(i, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("c.f();", "55");
+        assertUnresolvedDependencies(i, 0);
+        assertActiveKeys();
+    }
+
+    public void testForwardVarToEnum() {
+        DeclarationSnippet a = classKey(assertEval("enum E { Q, W, E; float ff() { return fff; } }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable fff");
+        Snippet g = varKey(assertEval("float fff = 4.5f;", "4.5",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("E.Q.ff();", "4.5");
+        assertEval("double fff = 3.3;", "3.3", null,
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        assertUnresolvedDependencies(a, 0);
+        assertActiveKeys();
+    }
+
+    public void testForwardMethodToClass() {
+        DeclarationSnippet a = classKey(assertEval("class A { int f() { return g(); } }", added(RECOVERABLE_DEFINED)));
+        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method g()");
+        assertEval("A foo() { return null; }");
+        assertEvalUnresolvedException("new A();", "A", 1, 0);
+        Snippet g = methodKey(assertEval("int g() { return 10; }",
+                added(VALID),
+                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
+        assertEval("new A().f();", "10");
+        assertEval("double g() { return 10; }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
+        assertUnresolvedDependencies(a, 0);
+        assertActiveKeys();
+    }
+
+    public void testForwardClassToClass1() {
+        Snippet a = classKey(assertEval("class A { B b = new B(); }", added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
+
+        Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
+                added(VALID),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
+        assertEval("new A().b;", "B");
+        assertEval("interface B { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(a, VALID, RECOVERABLE_DEFINED, true, MAIN_SNIPPET));
+        assertEvalUnresolvedException("new A().b;", "A", 0, 1);
+        assertActiveKeys();
+    }
+
+    public void testForwardClassToClass2() {
+        Snippet a = classKey(assertEval("class A extends B { }", added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+
+        Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
+                added(VALID),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
+        assertEval("new A();", "B");
+        assertEval("interface B { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
+        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
+        assertActiveKeys();
+    }
+
+    public void testForwardClassToClass3() {
+        Snippet a = classKey(assertEval("interface A extends B { static int f() { return 10; } }", added(RECOVERABLE_NOT_DEFINED)));
+        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
+
+        Snippet b = classKey(assertEval("interface B { }",
+                added(VALID),
+                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
+        assertEval("A.f();", "10");
+        assertEval("class B { }",
+                DiagCheck.DIAG_OK,
+                DiagCheck.DIAG_ERROR,
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
+                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
+        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
+        assertActiveKeys();
+    }
+
+    public void testForwardVariable() {
+        assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
+        assertEvalUnresolvedException("f();", "f", 1, 0);
+        assertActiveKeys();
+    }
+
+    public void testLocalClassInUnresolved() {
+        Snippet f = methodKey(assertEval("void f() { class A {} g(); }", added(RECOVERABLE_DEFINED)));
+        assertEval("void g() {}",
+                added(VALID),
+                ste(f, RECOVERABLE_DEFINED, VALID, false, null));
+        assertEval("f();", "");
+    }
+}
--- a/langtools/test/jdk/jshell/ReplaceTest.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/test/jdk/jshell/ReplaceTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -29,18 +29,13 @@
  */
 
 import java.util.Iterator;
-import java.util.List;
 import java.util.stream.Stream;
 import jdk.jshell.Snippet;
 import jdk.jshell.MethodSnippet;
 import jdk.jshell.TypeDeclSnippet;
 import jdk.jshell.VarSnippet;
-import jdk.jshell.DeclarationSnippet;
 import org.testng.annotations.Test;
 
-import jdk.jshell.SnippetEvent;
-import jdk.jshell.UnresolvedReferenceException;
-import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static jdk.jshell.Snippet.Status.*;
 import static jdk.jshell.Snippet.SubKind.*;
@@ -198,267 +193,6 @@
         assertActiveKeys();
     }
 
-    public void testOverwriteMethodForwardReferenceClass() {
-        Snippet k1 = methodKey(assertEval("int q(Boo b) { return b.x; }",
-                added(RECOVERABLE_NOT_DEFINED)));
-        assertUnresolvedDependencies1((MethodSnippet) k1, RECOVERABLE_NOT_DEFINED, "class Boo");
-        assertEval("class Boo { int x = 55; }",
-                added(VALID),
-                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
-        assertMethodDeclSnippet((MethodSnippet) k1, "q", "(Boo)int", VALID, 0, 0);
-        assertEval("q(new Boo());", "55");
-        assertActiveKeys();
-    }
-
-    public void testOverwriteMethodForwardReferenceClassImport() {
-        MethodSnippet k1 = methodKey(assertEval("int ff(List lis) { return lis.size(); }",
-                added(RECOVERABLE_NOT_DEFINED)));
-        assertUnresolvedDependencies1(k1, RECOVERABLE_NOT_DEFINED, "class List");
-        assertEval("import java.util.*;",
-                added(VALID),
-                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
-        assertMethodDeclSnippet(k1, "ff", "(List)int", VALID, 0, 0);
-        assertEval("ff(new ArrayList());", "0");
-        assertActiveKeys();
-    }
-
-    public void testForwardVarToMethod() {
-        DeclarationSnippet t = methodKey(assertEval("int t() { return x; }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "variable x");
-        assertEvalUnresolvedException("t();", "t", 1, 0);
-        Snippet x = varKey(assertEval("int x = 33;", "33",
-                added(VALID),
-                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("t();", "33");
-        assertEval("double x = 0.88;",
-                "0.88", null,
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        assertEvalUnresolvedException("t();", "t", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardMethodToMethod() {
-        Snippet t = methodKey(assertEval("int t() { return f(); }", added(RECOVERABLE_DEFINED)));
-        Snippet f = methodKey(assertEval("int f() { return g(); }",
-                added(RECOVERABLE_DEFINED),
-                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertUnresolvedDependencies1((DeclarationSnippet) f, RECOVERABLE_DEFINED, "method g()");
-        assertEvalUnresolvedException("t();", "f", 1, 0);
-        Snippet g = methodKey(assertEval("int g() { return 55; }",
-                added(VALID),
-                ste(f, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("t();", "55");
-        assertEval("double g() { return 3.14159; }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(f, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        DeclarationSnippet exsn = assertEvalUnresolvedException("t();", "f", 0, 1);
-        assertTrue(exsn == f, "Identity must not change");
-        assertActiveKeys();
-    }
-
-    public void testForwardClassToMethod() {
-        DeclarationSnippet t = methodKey(assertEval("int t() { return new A().f(); }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "class A");
-        assertEvalUnresolvedException("t();", "t", 1, 0);
-        Snippet a = classKey(assertEval(
-                "class A {\n" +
-                        "   int f() { return 10; }\n" +
-                "}",
-                added(VALID),
-                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("t();", "10");
-        assertEval(
-                "class A {\n" +
-                "   double f() { return 88.0; }\n" +
-                "}",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        assertEvalUnresolvedException("t();", "t", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardVarToClass() {
-        DeclarationSnippet a = classKey(assertEval("class A { int f() { return g; } }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
-        Snippet g = varKey(assertEval("int g = 10;", "10",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("new A().f();", "10");
-        assertEval("double g = 10;", "10.0", null,
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        assertUnresolvedDependencies(a, 0);
-        assertActiveKeys();
-    }
-
-    public void testForwardVarToClassGeneric() {
-        DeclarationSnippet a = classKey(assertEval("class A<T> { final T x; A(T v) { this.x = v; } ; T get() { return x; } int core() { return g; } }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
-
-        List<SnippetEvent> events = assertEval("A<String> as = new A<>(\"hi\");", null,
-                UnresolvedReferenceException.class, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, null);
-        SnippetEvent ste = events.get(0);
-        Snippet assn = ste.snippet();
-        DeclarationSnippet unsn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
-        assertEquals(unsn.name(), "A", "Wrong with unresolved");
-        assertEquals(getState().unresolvedDependencies(unsn).count(), 1, "Wrong size unresolved");
-        assertEquals(getState().diagnostics(unsn).count(), 0L, "Expected no diagnostics");
-
-        Snippet g = varKey(assertEval("int g = 10;", "10",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
-        assertEval("A<String> as = new A<>(\"low\");",
-                ste(MAIN_SNIPPET, VALID, VALID, false, null),
-                ste(assn, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
-        assertEval("as.get();", "\"low\"");
-        assertUnresolvedDependencies(a, 0);
-        assertActiveKeys();
-    }
-
-   public void testForwardVarToClassExtendsImplements() {
-        DeclarationSnippet ik = classKey(assertEval("interface I { default int ii() { return 1; } }", added(VALID)));
-        DeclarationSnippet jk = classKey(assertEval("interface J { default int jj() { return 2; } }", added(VALID)));
-        DeclarationSnippet ck = classKey(assertEval("class C { int cc() { return 3; } }", added(VALID)));
-        DeclarationSnippet dk = classKey(assertEval("class D extends C implements I,J { int dd() { return g; } }", added(RECOVERABLE_DEFINED)));
-        DeclarationSnippet ek = classKey(assertEval("class E extends D { int ee() { return 5; } }", added(VALID)));
-        assertUnresolvedDependencies1(dk, RECOVERABLE_DEFINED, "variable g");
-        assertEvalUnresolvedException("new D();", "D", 1, 0);
-        assertEvalUnresolvedException("new E();", "D", 1, 0);
-        VarSnippet g = varKey(assertEval("int g = 10;", "10",
-                added(VALID),
-                ste(dk, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
-        assertEval("E e = new E();");
-        assertDrop(g,
-                ste(g, VALID, DROPPED, true, null),
-                ste(dk, VALID, RECOVERABLE_DEFINED, false, g));
-        assertEvalUnresolvedException("new D();", "D", 1, 0);
-        assertEvalUnresolvedException("new E();", "D", 1, 0);
-        assertEval("e.ee();", "5");
-        assertEvalUnresolvedException("e.dd();", "D", 1, 0);
-        assertEval("e.cc();", "3");
-        assertEval("e.jj();", "2");
-        assertEval("e.ii();", "1");
-        assertActiveKeys();
-    }
-
-    public void testForwardVarToInterface() {
-        DeclarationSnippet i = classKey(assertEval("interface I { default int f() { return x; } }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(i, RECOVERABLE_DEFINED, "variable x");
-        DeclarationSnippet c = classKey(assertEval("class C implements I { int z() { return 2; } }", added(VALID)));
-        assertEval("C c = new C();");
-        assertEval("c.z();", "2");
-        assertEvalUnresolvedException("c.f()", "I", 1, 0);
-        Snippet g = varKey(assertEval("int x = 55;", "55",
-                added(VALID),
-                ste(i, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("c.f();", "55");
-        assertUnresolvedDependencies(i, 0);
-        assertActiveKeys();
-    }
-
-    public void testForwardVarToEnum() {
-        DeclarationSnippet a = classKey(assertEval("enum E { Q, W, E; float ff() { return fff; } }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable fff");
-        Snippet g = varKey(assertEval("float fff = 4.5f;", "4.5",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("E.Q.ff();", "4.5");
-        assertEval("double fff = 3.3;", "3.3", null,
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        assertUnresolvedDependencies(a, 0);
-        assertActiveKeys();
-    }
-
-    public void testForwardMethodToClass() {
-        DeclarationSnippet a = classKey(assertEval("class A { int f() { return g(); } }", added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method g()");
-        assertEval("A foo() { return null; }");
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        Snippet g = methodKey(assertEval("int g() { return 10; }",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
-        assertEval("new A().f();", "10");
-        assertEval("double g() { return 10; }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        assertUnresolvedDependencies(a, 0);
-        assertActiveKeys();
-    }
-
-    public void testForwardClassToClass1() {
-        Snippet a = classKey(assertEval("class A { B b = new B(); }", added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
-
-        Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
-                added(VALID),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
-        assertEval("new A().b;", "B");
-        assertEval("interface B { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(a, VALID, RECOVERABLE_DEFINED, true, MAIN_SNIPPET));
-        assertEvalUnresolvedException("new A().b;", "A", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardClassToClass2() {
-        Snippet a = classKey(assertEval("class A extends B { }", added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-
-        Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
-                added(VALID),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
-        assertEval("new A();", "B");
-        assertEval("interface B { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-        assertActiveKeys();
-    }
-
-    public void testForwardClassToClass3() {
-        Snippet a = classKey(assertEval("interface A extends B { static int f() { return 10; } }", added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
-
-        Snippet b = classKey(assertEval("interface B { }",
-                added(VALID),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
-        assertEval("A.f();", "10");
-        assertEval("class B { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                ste(MAIN_SNIPPET, VALID, VALID, true, null),
-                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
-                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
-        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
-        assertActiveKeys();
-    }
-
     public void testImportDeclare() {
         Snippet singleImport = importKey(assertEval("import java.util.List;", added(VALID)));
         Snippet importOnDemand = importKey(assertEval("import java.util.*;", added(VALID)));
@@ -479,20 +213,6 @@
         assertActiveKeys();
     }
 
-    public void testForwardVariable() {
-        assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
-        assertEvalUnresolvedException("f();", "f", 1, 0);
-        assertActiveKeys();
-    }
-
-    public void testLocalClassInUnresolved() {
-        Snippet f = methodKey(assertEval("void f() { class A {} g(); }", added(RECOVERABLE_DEFINED)));
-        assertEval("void g() {}",
-                added(VALID),
-                ste(f, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("f();", "");
-    }
-
     @Test(enabled = false) // TODO 8129420
     public void testLocalClassEvolve() {
         Snippet j = methodKey(assertEval("Object j() { return null; }", added(VALID)));
@@ -507,339 +227,6 @@
         assertEval("j();", "Yep");
     }
 
-    public void testForwardSingleImportMethodToMethod() {
-        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
-                added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
-        assertEvalUnresolvedException("string();", "string", 1, 0);
-        assertEval("import static java.lang.String.format;",
-                added(VALID),
-                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("string();", "\"string\"");
-
-        assertEval("double format(String s) { return 0; }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
-        assertEvalUnresolvedException("string();", "string", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardImportMethodOnDemandToMethod() {
-        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
-                added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
-        assertEvalUnresolvedException("string();", "string", 1, 0);
-        assertEval("import static java.lang.String.*;",
-                added(VALID),
-                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("string();", "\"string\"");
-
-        assertEval("double format(String s) { return 0; }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
-        assertEvalUnresolvedException("string();", "string", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardSingleImportFieldToMethod() {
-        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
-                added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
-        assertEvalUnresolvedException("pi();", "pi", 1, 0);
-        assertEval("import static java.lang.Math.PI;",
-                added(VALID),
-                ste(pi, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
-
-        assertEval("String PI;",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(pi, VALID, RECOVERABLE_DEFINED, false, null));
-        assertEvalUnresolvedException("pi();", "pi", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardImportFieldOnDemandToMethod() {
-        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
-                added(RECOVERABLE_DEFINED)));
-        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
-        assertEvalUnresolvedException("pi();", "pi", 1, 0);
-        assertEval("import static java.lang.Math.*;",
-                added(VALID),
-                ste(pi, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
-        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
-
-        assertEval("String PI;",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(pi, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
-        assertEvalUnresolvedException("pi();", "pi", 0, 1);
-        assertActiveKeys();
-    }
-
-    public void testForwardSingleImportMethodToClass1() {
-        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.String.format;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("new A().s;", "\"10\"");
-        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(format,
-                ste(format, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
-    }
-
-    public void testForwardSingleImportMethodToClass2() {
-        Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.String.format;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("new A().s();", "\"10\"");
-        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(format,
-                ste(format, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
-    }
-
-    public void testForwardSingleImportClassToClass1() {
-        Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
-                added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-        assertEval("import java.util.List;",
-                added(VALID),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
-        assertEval("import java.util.Arrays;", added(VALID));
-        assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
-
-        Snippet list = classKey(assertEval("class List {}",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
-        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.static.single.import");
-        assertActiveKeys();
-        assertDrop(list,
-                ste(list, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
-    }
-
-    public void testForwardSingleImportClassToClass2() {
-        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
-                added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-        assertEval("import java.util.ArrayList;",
-                added(VALID),
-                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
-        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
-
-        Snippet arraylist = classKey(assertEval("class ArrayList {}",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
-                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
-        assertDeclareFail("A a = new A();", "compiler.err.cant.resolve.location",
-                ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, REJECTED, false, null),
-                ste(vara, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET));
-        assertActiveKeys();
-        assertDrop(arraylist,
-                ste(arraylist, VALID, DROPPED, true, null),
-                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist));
-    }
-
-    public void testForwardImportOnDemandMethodToClass1() {
-        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.String.*;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("A x = new A();");
-        assertEval("x.s;", "\"10\"");
-        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(format,
-                ste(format, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
-        assertEval("x.s;", "\"10\"");
-    }
-
-    public void testForwardImportOnDemandMethodToClass2() {
-        Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.String.*;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("new A().s();", "\"10\"");
-        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(format,
-                ste(format, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
-    }
-
-    public void testForwardImportOnDemandClassToClass1() {
-        Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
-                added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-        assertEval("import java.util.*;",
-                added(VALID),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
-        assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
-
-        Snippet list = classKey(assertEval("class List {}",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
-        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.cant.resolve.location");
-        assertActiveKeys();
-        assertDrop(list,
-                ste(list, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
-    }
-
-    public void testForwardImportOnDemandClassToClass2() {
-        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
-                added(RECOVERABLE_NOT_DEFINED)));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-        assertEval("import java.util.*;",
-                added(VALID),
-                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
-        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
-
-        Snippet arraylist = classKey(assertEval("class ArrayList {}",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
-                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
-        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
-        assertActiveKeys();
-        assertDrop(arraylist,
-                ste(arraylist, VALID, DROPPED, true, null),
-                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist),
-                ste(vara, RECOVERABLE_NOT_DEFINED, VALID, true, clsA));
-    }
-
-    public void testForwardSingleImportFieldToClass1() {
-        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.Math.PI;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
-
-        Snippet list = varKey(assertEval("String PI;",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(list,
-                ste(list, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
-    }
-
-    public void testForwardSingleImportFieldToClass2() {
-        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.Math.PI;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
-        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
-
-        Snippet list = varKey(assertEval("String PI;",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(list,
-                ste(list, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
-    }
-
-    public void testForwardImportOnDemandFieldToClass1() {
-        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.Math.*;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
-        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
-
-        Snippet list = varKey(assertEval("String PI;",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(list,
-                ste(list, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
-    }
-
-    public void testForwardImportOnDemandFieldToClass2() {
-        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
-                added(RECOVERABLE_DEFINED)));
-        assertEvalUnresolvedException("new A();", "A", 1, 0);
-        assertEval("import static java.lang.Math.*;",
-                added(VALID),
-                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
-        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
-
-        Snippet list = varKey(assertEval("String PI;",
-                DiagCheck.DIAG_OK,
-                DiagCheck.DIAG_ERROR,
-                added(VALID),
-                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
-        assertEvalUnresolvedException("new A();", "A", 0, 1);
-        assertActiveKeys();
-        assertDrop(list,
-                ste(list, VALID, DROPPED, true, null),
-                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
-        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
-    }
-
     public void testReplaceCausesMethodReferenceError() {
         Snippet l = classKey(assertEval("interface Logger { public void log(String message); }", added(VALID)));
         Snippet v = varKey(assertEval("Logger l = System.out::println;", added(VALID)));
--- a/langtools/test/jdk/jshell/StartOptionTest.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/test/jdk/jshell/StartOptionTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -22,7 +22,7 @@
  */
 
 /*
- * @test 8151754 8080883 8160089 8170162 8166581 8172102
+ * @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343
  * @summary Testing start-up options.
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -33,7 +33,9 @@
  * @run testng StartOptionTest
  */
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.io.PrintStream;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
@@ -46,6 +48,7 @@
 import org.testng.annotations.Test;
 import jdk.jshell.tool.JavaShellToolBuilder;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
@@ -57,12 +60,14 @@
     private ByteArrayOutputStream console;
     private ByteArrayOutputStream userout;
     private ByteArrayOutputStream usererr;
+    private InputStream cmdInStream;
 
     private JavaShellToolBuilder builder() {
         return JavaShellToolBuilder
                     .builder()
                     .out(new PrintStream(cmdout), new PrintStream(console), new PrintStream(userout))
                     .err(new PrintStream(cmderr), new PrintStream(usererr))
+                    .in(cmdInStream, null)
                     .persistence(new HashMap<>())
                     .env(new HashMap<>())
                     .locale(Locale.ROOT);
@@ -119,6 +124,7 @@
         console = new ByteArrayOutputStream();
         userout = new ByteArrayOutputStream();
         usererr = new ByteArrayOutputStream();
+        cmdInStream = new ByteArrayInputStream("/exit\n".getBytes());
     }
 
     protected String writeToFile(String stuff) throws Exception {
@@ -138,6 +144,19 @@
             start(s -> {
                 assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
                 assertTrue(s.startsWith("Usage:   jshell <options>"), "Unexpect usage start: " + s);
+                assertTrue(s.contains("--show-version"), "Expected help: " + s);
+                assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
+            }, null, null, opt);
+        }
+    }
+
+    public void testHelpExtra() throws Exception {
+        for (String opt : new String[]{"-X", "--help-extra"}) {
+            start(s -> {
+                assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s);
+                assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s);
+                assertTrue(s.contains("--execution"), "Expected --add-exports: " + s);
+                assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
             }, null, null, opt);
         }
     }
@@ -201,7 +220,29 @@
     }
 
     public void testVersion() throws Exception {
-        start(s -> assertTrue(s.startsWith("jshell"), "unexpected version: " + s), null, null, "--version");
+        start(
+                s -> {
+                    assertTrue(s.startsWith("jshell"), "unexpected version: " + s);
+                    assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
+                },
+                null, null,
+                "--version");
+    }
+
+    public void testShowVersion() throws Exception {
+        runShell("--show-version");
+        check(cmdout,
+                s -> {
+                    assertTrue(s.startsWith("jshell"), "unexpected version: " + s);
+                    assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s);
+                },
+                "cmdout");
+        check(cmderr, null, "cmderr");
+        check(console,
+                s -> assertTrue(s.trim().startsWith("jshell>"), "Expected prompt, got: " + s),
+                "console");
+        check(userout, null, "userout");
+        check(usererr, null, "usererr");
     }
 
     @AfterMethod
@@ -211,5 +252,6 @@
         console = null;
         userout = null;
         usererr = null;
+        cmdInStream = null;
     }
 }
--- a/langtools/test/jdk/jshell/ToolProviderTest.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/test/jdk/jshell/ToolProviderTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -23,16 +23,18 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.util.ServiceLoader;
 import java.util.function.Consumer;
 import javax.tools.Tool;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
+import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 /*
  * @test
- * @bug 8170044
+ * @bug 8170044 8171343
  * @summary Test ServiceLoader launching of jshell tool
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -47,12 +49,14 @@
 
     private ByteArrayOutputStream cmdout;
     private ByteArrayOutputStream cmderr;
+    private InputStream cmdInStream;
 
     @BeforeMethod
     @Override
     public void setUp() {
         cmdout = new ByteArrayOutputStream();
         cmderr = new ByteArrayOutputStream();
+        cmdInStream = new ByteArrayInputStream("/exit\n".getBytes());
     }
 
     @Override
@@ -70,7 +74,7 @@
         ServiceLoader<Tool> sl = ServiceLoader.load(Tool.class);
         for (Tool provider : sl) {
             if (provider.name().equals("jshell")) {
-                return provider.run(new ByteArrayInputStream(new byte[0]), cmdout, cmderr, args);
+                return provider.run(cmdInStream, cmdout, cmderr, args);
             }
         }
         throw new AssertionError("Repl tool not found by ServiceLoader: " + sl);
@@ -90,4 +94,16 @@
             check(cmderr, s -> s.startsWith("Launching JShell execution engine threw: Failed remote"), "cmderr");
         }
     }
+
+    @Override
+    public void testShowVersion() throws Exception {
+        start(
+                s -> {
+                    assertTrue(s.startsWith("jshell "), "unexpected version: " + s);
+                    assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s);
+                    assertTrue(s.trim().contains("jshell>"), "Expected prompt, got: " + s);
+                },
+                null, null,
+                "--show-version");
+    }
 }
--- a/langtools/test/tools/javac/modules/EdgeCases.java	Thu Jan 26 19:22:40 2017 +0000
+++ b/langtools/test/tools/javac/modules/EdgeCases.java	Thu Jan 26 21:20:40 2017 +0000
@@ -23,13 +23,14 @@
 
 /*
  * @test
- * @bug 8154283 8167320 8171098 8172809 8173117
+ * @bug 8154283 8167320 8171098 8172809 8173068 8173117
  * @summary tests for multi-module mode compilation
  * @library /tools/lib
  * @modules
  *      jdk.compiler/com.sun.tools.javac.api
  *      jdk.compiler/com.sun.tools.javac.code
  *      jdk.compiler/com.sun.tools.javac.main
+ *      jdk.compiler/com.sun.tools.javac.processing
  *      jdk.compiler/com.sun.tools.javac.util
  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
  * @run main EdgeCases
@@ -53,8 +54,10 @@
 import javax.lang.model.element.Element;
 import javax.lang.model.element.ModuleElement;
 import javax.lang.model.element.ModuleElement.RequiresDirective;
+import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.util.ElementFilter;
+import javax.lang.model.util.Elements;
 import javax.tools.JavaCompiler;
 import javax.tools.JavaFileObject;
 import javax.tools.StandardJavaFileManager;
@@ -64,7 +67,10 @@
 //import com.sun.source.util.JavacTask; // conflicts with toolbox.JavacTask
 import com.sun.tools.javac.api.JavacTaskImpl;
 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
+import com.sun.tools.javac.code.Symbol.PackageSymbol;
 import com.sun.tools.javac.code.Symtab;
+import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import com.sun.tools.javac.util.Context;
 
 import toolbox.JarTask;
 import toolbox.JavacTask;
@@ -654,4 +660,156 @@
         }
     }
 
+    @Test
+    public void testUnnamedPackage(Path base) throws Exception {
+        List<String> out;
+        List<String> expected;
+
+        //-source 8:
+        Path src8 = base.resolve("src8");
+        Files.createDirectories(src8);
+        tb.writeJavaFiles(src8,
+                          "package test; public class Test {}");
+        Path classes = base.resolve("classes");
+        tb.createDirectories(classes);
+
+        out = new JavacTask(tb)
+                .options("--source-path", src8.toString(),
+                         "-processor", UnnamedPackageProcessor.class.getName(),
+                         "-source", "8")
+                .outdir(classes)
+                .files(findJavaFiles(src8))
+                .run()
+                .writeAll()
+                .getOutputLines(OutputKind.STDOUT);
+
+        expected = Arrays.asList("noModule");
+
+        if (!expected.equals(out)) {
+            throw new AssertionError("Unexpected output: " + out);
+        }
+
+        //-source 9, unnamed:
+        Path srcUnnamed = base.resolve("srcUnnamed");
+        Files.createDirectories(srcUnnamed);
+        tb.writeJavaFiles(srcUnnamed,
+                          "public class Test {}");
+        Path classesUnnamed = base.resolve("classesUnnamed");
+        tb.createDirectories(classesUnnamed);
+
+        out = new JavacTask(tb)
+                .options("--source-path", srcUnnamed.toString(),
+                         "-processor", UnnamedPackageProcessor.class.getName())
+                .outdir(classesUnnamed)
+                .files(findJavaFiles(srcUnnamed))
+                .run()
+                .writeAll()
+                .getOutputLines(OutputKind.STDOUT);
+
+        expected = Arrays.asList("unnamedModule");
+
+        if (!expected.equals(out)) {
+            throw new AssertionError("Unexpected output: " + out);
+        }
+
+        //-source 9, named:
+        Path srcNamed = base.resolve("srcNamed");
+        Files.createDirectories(srcNamed);
+        tb.writeJavaFiles(srcNamed,
+                          "module m {}",
+                          "public class Test {}");
+        Path classesNamed = base.resolve("classesNamed");
+        tb.createDirectories(classesNamed);
+
+        out = new JavacTask(tb)
+                .options("--source-path", srcNamed.toString(),
+                         "-classpath", "",
+                         "-processorpath", System.getProperty("test.class.path"),
+                         "-processor", UnnamedPackageProcessor.class.getName())
+                .outdir(classesNamed)
+                .files(findJavaFiles(srcNamed))
+                .run()
+                .writeAll()
+                .getOutputLines(OutputKind.STDOUT);
+
+        expected = Arrays.asList("m");
+
+        if (!expected.equals(out)) {
+            throw new AssertionError("Unexpected output: " + out);
+        }
+
+        //-source 9, conflict:
+        Path srcNamed2 = base.resolve("srcNamed2");
+        Path srcNamed2m1 = srcNamed2.resolve("m1x");
+        Files.createDirectories(srcNamed2m1);
+        tb.writeJavaFiles(srcNamed2m1,
+                          "module m1x {}",
+                          "public class Test {}");
+        Path srcNamed2m2 = srcNamed2.resolve("m2x");
+        Files.createDirectories(srcNamed2m2);
+        tb.writeJavaFiles(srcNamed2m2,
+                          "module m2x {}",
+                          "public class Test {}");
+        Path classesNamed2 = base.resolve("classesNamed2");
+        tb.createDirectories(classesNamed2);
+
+        out = new JavacTask(tb)
+                .options("--module-source-path", srcNamed2.toString(),
+                         "-classpath", "",
+                         "-processorpath", System.getProperty("test.class.path"),
+                         "-processor", UnnamedPackageProcessor.class.getName(),
+                         "-XDshould-stop.ifError=FLOW")
+                .outdir(classesNamed2)
+                .files(findJavaFiles(srcNamed2))
+                .run(Expect.FAIL)
+                .writeAll()
+                .getOutputLines(OutputKind.STDOUT);
+
+        expected = Arrays.asList("null",
+                                 "m1x: true",
+                                 "m2x: true");
+
+        if (!expected.equals(out)) {
+            throw new AssertionError("Unexpected output: " + out);
+        }
+    }
+
+    @SupportedAnnotationTypes("*")
+    public static final class UnnamedPackageProcessor extends AbstractProcessor {
+
+        int round = 0;
+
+        @Override
+        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+            if (round++ != 0)
+                return false;
+
+            Elements elements = processingEnv.getElementUtils();
+            PackageElement pe = elements.getPackageElement("");
+
+            if (pe == null) {
+                System.out.println("null");
+            } else {
+                ModuleElement mod = (ModuleElement) pe.getEnclosingElement();
+                if (mod == null) {
+                    System.out.println("noModule");
+                } else if (mod.isUnnamed()) {
+                    System.out.println("unnamedModule");
+                } else {
+                    System.out.println(mod);
+                }
+            }
+
+            ModuleElement m1x = elements.getModuleElement("m1x");
+            ModuleElement m2x = elements.getModuleElement("m2x");
+
+            if (m1x != null && m2x != null) {
+                System.out.println("m1x: " + (elements.getPackageElement(m1x, "") != null));
+                System.out.println("m2x: " + (elements.getPackageElement(m2x, "") != null));
+            }
+
+            return false;
+        }
+
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/OverwriteInitialInput.java	Thu Jan 26 21:20:40 2017 +0000
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2015, 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8067747
+ * @summary Verify the correct Filer behavior w.r.t. initial inputs
+ *          (should throw FilerException when overwriting initial inputs).
+ * @library /tools/lib /tools/javac/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ * @build toolbox.ToolBox toolbox.JavacTask toolbox.Task
+ * @build OverwriteInitialInput JavacTestingAbstractProcessor
+ * @run main OverwriteInitialInput
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Set;
+
+import javax.annotation.processing.FilerException;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedOptions;
+import javax.lang.model.element.TypeElement;
+import javax.tools.StandardLocation;
+
+import toolbox.JavacTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+@SupportedOptions({OverwriteInitialInput.EXPECT_EXCEPTION_OPTION,
+                   OverwriteInitialInput.TEST_SOURCE
+                  })
+public class OverwriteInitialInput extends JavacTestingAbstractProcessor {
+
+    public static final String EXPECT_EXCEPTION_OPTION = "exception";
+    public static final String TEST_SOURCE = "testSource";
+
+    @Override
+    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+        if (roundEnv.processingOver()) {
+            if (processingEnv.getOptions().containsKey(EXPECT_EXCEPTION_OPTION)) {
+                try (Writer w = processingEnv.getFiler().createSourceFile("Test").openWriter()) {
+                    throw new AssertionError("Expected IOException not seen.");
+                } catch (FilerException ex) {
+                    //expected
+                } catch (IOException ex) {
+                    throw new IllegalStateException(ex);
+                }
+                try (OutputStream out = processingEnv.getFiler().createClassFile("Test").openOutputStream()) {
+                    throw new AssertionError("Expected IOException not seen.");
+                } catch (FilerException ex) {
+                    //expected
+                } catch (IOException ex) {
+                    throw new IllegalStateException(ex);
+                }
+                if (processingEnv.getOptions().containsKey(TEST_SOURCE)) {
+                    try (OutputStream out = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", "Test.java").openOutputStream()) {
+                        throw new AssertionError("Expected IOException not seen.");
+                    } catch (FilerException ex) {
+                        //expected
+                    } catch (IOException ex) {
+                        throw new IllegalStateException(ex);
+                    }
+                } else {
+                    try (OutputStream out = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "Test2.class").openOutputStream()) {
+                        throw new AssertionError("Expected IOException not seen.");
+                    } catch (FilerException ex) {
+                        //expected
+                    } catch (IOException ex) {
+                        throw new IllegalStateException(ex);
+                    }
+                }
+            } else {
+                try (Writer w = processingEnv.getFiler().createSourceFile("Test").openWriter()) {
+                    w.append("public class Test {}");
+                } catch (IOException ex) {
+                    throw new IllegalStateException(ex);
+                }
+                try (OutputStream out = processingEnv.getFiler().createClassFile("Test2").openOutputStream()) {
+                    try (ToolBox.MemoryFileManager mfm = new ToolBox.MemoryFileManager()) {
+                        ToolBox tb = new ToolBox();
+                        new JavacTask(tb)
+                          .sources("public class Test2 {}")
+                          .fileManager(mfm)
+                          .run()
+                          .writeAll();
+
+                        out.write(mfm.getFileBytes(StandardLocation.CLASS_OUTPUT, "Test2"));
+                    }
+                } catch (IOException ex) {
+                    throw new IllegalStateException(ex);
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public static void main(String... args) throws IOException {
+        new OverwriteInitialInput().run();
+    }
+
+    void run() throws IOException {
+        run(Task.Mode.API);
+        run(Task.Mode.CMDLINE);
+    }
+
+    void run(Task.Mode mode) throws IOException {
+        ToolBox tb = new ToolBox();
+        Path path = Paths.get("output");
+        if (Files.isDirectory(path))
+            tb.cleanDirectory(path);
+        Files.deleteIfExists(path);
+        tb.createDirectories(path);
+        Path thisSource = Paths.get(System.getProperty("test.src"), "OverwriteInitialInput.java");
+        new JavacTask(tb, mode).options("-processor", "OverwriteInitialInput",
+                                        "-d", path.toString(),
+                                        "-XDaccessInternalAPI=true")
+                               .files(thisSource)
+                               .run()
+                               .writeAll();
+        new JavacTask(tb, mode).options("-processor", "OverwriteInitialInput",
+                                        "-d", path.toString(),
+                                        "-A" + EXPECT_EXCEPTION_OPTION,
+                                        "-A" + TEST_SOURCE,
+                                        "-XDaccessInternalAPI=true")
+                               .files(thisSource, path.resolve("Test.java"))
+                               .run()
+                               .writeAll();
+        new JavacTask(tb, mode).options("-processor", "OverwriteInitialInput",
+                                        "-classpath", path.toString(),
+                                        "-processorpath", System.getProperty("test.class.path"),
+                                        "-d", path.toString(),
+                                        "-A" + EXPECT_EXCEPTION_OPTION,
+                                        "-XDaccessInternalAPI=true")
+                               .classes("Test", "Test2")
+                               .run()
+                               .writeAll();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javap/typeAnnotations/AnnotationDefaultNewlineTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8041793
+ * @summary Verify that javap prints newline character after AnnotationDefault value
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavacTask toolbox.JavapTask toolbox.Assert
+ * @run main AnnotationDefaultNewlineTest
+ */
+
+import java.util.Collections;
+import java.util.List;
+
+import toolbox.Assert;
+import toolbox.JavacTask;
+import toolbox.JavapTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+public class AnnotationDefaultNewlineTest {
+
+    private static final String TestSrc =
+            "public @interface AnnotationDefault { \n" +
+                "public abstract int value() default 1; \n" +
+            "}";
+
+    private static final String ExpectedSubstring =
+            "    AnnotationDefault:\n" +
+            "      default_value: I#7\n";
+
+    public static void main(String[] args) throws Exception {
+        ToolBox tb = new ToolBox();
+        new JavacTask(tb).sources(TestSrc).run();
+
+        List<String> res = new JavapTask(tb)
+                .options("-v")
+                .classes("AnnotationDefault.class")
+                .run()
+                .getOutputLines(Task.OutputKind.DIRECT);
+
+        List<String> goldenList = tb.split(ExpectedSubstring, "\n");
+        Boolean found = Collections.indexOfSubList(res, goldenList) > -1;
+
+        Assert.check(found, "expected output not found: " + ExpectedSubstring);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javap/typeAnnotations/InvisibleParameterAnnotationsTest.java	Thu Jan 26 21:20:40 2017 +0000
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8051768
+ * @summary Verify that javap prints "param" for RuntimeInvisibleParameterAnnotations
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.jdeps/com.sun.tools.javap
+ * @build toolbox.ToolBox toolbox.JavacTask toolbox.JavapTask toolbox.Assert
+ * @run main InvisibleParameterAnnotationsTest
+ */
+
+import toolbox.Assert;
+import toolbox.JavacTask;
+import toolbox.JavapTask;
+import toolbox.Task;
+import toolbox.ToolBox;
+
+import java.util.Collections;
+import java.util.List;
+
+public class InvisibleParameterAnnotationsTest {
+
+    private static final String TestSrc =
+            "import java.lang.annotation.Retention \n;" +
+            "import java.lang.annotation.RetentionPolicy \n;" +
+
+            "public class Sample { \n" +
+
+                "@Retention(RetentionPolicy.CLASS) \n" +
+                "public @interface InvisAnno{} \n" +
+                "@Retention(RetentionPolicy.RUNTIME) \n" +
+                "public @interface VisAnno{} \n" +
+
+                "public void Method(@InvisAnno int arg1,@VisAnno int arg2){};" +
+            "}";
+
+    private static final String ExpectedSubstring =
+            "    RuntimeVisibleParameterAnnotations:\n" +
+            "      parameter 0:\n" +
+            "      parameter 1:\n" +
+            "        0: #16()\n" +
+            "    RuntimeInvisibleParameterAnnotations:\n" +
+            "      parameter 0:\n" +
+            "        0: #18()\n" +
+            "      parameter 1:";
+
+    public static void main(String[] args) throws Exception {
+        ToolBox tb = new ToolBox();
+        new JavacTask(tb).sources(TestSrc).run();
+
+        List<String> res = new JavapTask(tb)
+                .options("-v")
+                .classes("Sample.class")
+                .run()
+                .getOutputLines(Task.OutputKind.DIRECT);
+
+        List<String> expectedList = tb.split(ExpectedSubstring, "\n");
+        Boolean found = Collections.indexOfSubList(res, expectedList) > -1;
+        Assert.check(found, "expected output not found: " + ExpectedSubstring);
+    }
+}