Merge

Tue, 07 Sep 2010 15:49:48 -0700

author
ohair
date
Tue, 07 Sep 2010 15:49:48 -0700
changeset 677
c388fa8c6a43
parent 646
47e7ff871196
parent 676
bfdfc13fe641
child 678
014cf6234586

Merge

test/tools/javac/T6341023.java file | annotate | diff | comparison | revisions
test/tools/javac/meth/MakeNegTests.sh file | annotate | diff | comparison | revisions
test/tools/javac/quid/MakeNegTests.sh file | annotate | diff | comparison | revisions
     1.1 --- a/make/build.xml	Tue Sep 07 15:14:49 2010 -0700
     1.2 +++ b/make/build.xml	Tue Sep 07 15:49:48 2010 -0700
     1.3 @@ -673,6 +673,7 @@
     1.4                      <filterset begintoken="#" endtoken="#">
     1.5                          <filter token="PROGRAM" value="@{name}"/>
     1.6                          <filter token="TARGET_JAVA" value="@{java}"/>
     1.7 +                        <filter token="PS" value="${path.separator}"/>
     1.8                      </filterset>
     1.9                  </copy>
    1.10                  <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
     2.1 --- a/src/share/bin/launcher.sh-template	Tue Sep 07 15:14:49 2010 -0700
     2.2 +++ b/src/share/bin/launcher.sh-template	Tue Sep 07 15:49:48 2010 -0700
     2.3 @@ -40,8 +40,8 @@
     2.4  if [ "$LANGTOOLS_USE_BOOTCLASSPATH" != "no" ]; then
     2.5     cp=`unzip -c "$mylib/#PROGRAM#.jar" META-INF/MANIFEST.MF |
     2.6         grep "Class-Path:" |
     2.7 -       sed -e 's|Class-Path: *||' -e 's|\([a-z]*\.jar\) *|'"$mylib"'/\1:|g'`
     2.8 -   bcp="$mylib/#PROGRAM#.jar":$cp 
     2.9 +       sed -e 's|Class-Path: *||' -e 's|\([a-z]*\.jar\) *|'"$mylib"'/\1#PS#|g'`
    2.10 +   bcp="$mylib/#PROGRAM#.jar#PS#$cp"
    2.11  fi
    2.12  
    2.13  # tools currently assumes that assertions are enabled in the launcher
     3.1 --- a/src/share/classes/com/sun/source/tree/Tree.java	Tue Sep 07 15:14:49 2010 -0700
     3.2 +++ b/src/share/classes/com/sun/source/tree/Tree.java	Tue Sep 07 15:49:48 2010 -0700
     3.3 @@ -94,7 +94,7 @@
     3.4          CATCH(CatchTree.class),
     3.5  
     3.6          /**
     3.7 -         * Used for instances of {@link ClassTree}.
     3.8 +         * Used for instances of {@link ClassTree} representing classes.
     3.9           */
    3.10          CLASS(ClassTree.class),
    3.11  
    3.12 @@ -558,6 +558,21 @@
    3.13          ERRONEOUS(ErroneousTree.class),
    3.14  
    3.15          /**
    3.16 +         * Used for instances of {@link ClassTree} representing interfaces.
    3.17 +         */
    3.18 +        INTERFACE(ClassTree.class),
    3.19 +
    3.20 +        /**
    3.21 +         * Used for instances of {@link ClassTree} representing enums.
    3.22 +         */
    3.23 +        ENUM(ClassTree.class),
    3.24 +
    3.25 +        /**
    3.26 +         * Used for instances of {@link ClassTree} representing annotation types.
    3.27 +         */
    3.28 +        ANNOTATION_TYPE(ClassTree.class),
    3.29 +
    3.30 +        /**
    3.31           * An implementation-reserved node. This is the not the node
    3.32           * you are looking for.
    3.33           */
     4.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Tue Sep 07 15:14:49 2010 -0700
     4.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Tue Sep 07 15:49:48 2010 -0700
     4.3 @@ -45,6 +45,7 @@
     4.4  import com.sun.source.util.SourcePositions;
     4.5  import com.sun.source.util.TreePath;
     4.6  import com.sun.source.util.Trees;
     4.7 +import com.sun.tools.javac.code.Flags;
     4.8  import com.sun.tools.javac.code.Symbol.ClassSymbol;
     4.9  import com.sun.tools.javac.code.Symbol.TypeSymbol;
    4.10  import com.sun.tools.javac.code.Symbol;
    4.11 @@ -189,8 +190,24 @@
    4.12      }
    4.13  
    4.14      public Element getElement(TreePath path) {
    4.15 -        Tree t = path.getLeaf();
    4.16 -        return TreeInfo.symbolFor((JCTree) t);
    4.17 +        JCTree tree = (JCTree) path.getLeaf();
    4.18 +        Symbol sym = TreeInfo.symbolFor(tree);
    4.19 +        if (sym == null && TreeInfo.isDeclaration(tree)) {
    4.20 +            for (TreePath p = path; p != null; p = p.getParentPath()) {
    4.21 +                JCTree t = (JCTree) p.getLeaf();
    4.22 +                if (t.getTag() == JCTree.CLASSDEF) {
    4.23 +                    JCClassDecl ct = (JCClassDecl) t;
    4.24 +                    if (ct.sym != null) {
    4.25 +                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
    4.26 +                            attr.attribClass(ct.pos(), ct.sym);
    4.27 +                            sym = TreeInfo.symbolFor(tree);
    4.28 +                        }
    4.29 +                        break;
    4.30 +                    }
    4.31 +                }
    4.32 +            }
    4.33 +        }
    4.34 +        return sym;
    4.35      }
    4.36  
    4.37      public TypeMirror getTypeMirror(TreePath path) {
     5.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java	Tue Sep 07 15:14:49 2010 -0700
     5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java	Tue Sep 07 15:49:48 2010 -0700
     5.3 @@ -295,4 +295,11 @@
     5.4          void visitEnum(Attribute.Enum e);
     5.5          void visitError(Attribute.Error e);
     5.6      }
     5.7 +
     5.8 +    /** A mirror of java.lang.annotation.RetentionPolicy. */
     5.9 +    public static enum RetentionPolicy {
    5.10 +        SOURCE,
    5.11 +        CLASS,
    5.12 +        RUNTIME
    5.13 +    }
    5.14  }
     6.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Tue Sep 07 15:14:49 2010 -0700
     6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Tue Sep 07 15:49:48 2010 -0700
     6.3 @@ -241,6 +241,12 @@
     6.4       */
     6.5      public static final long POLYMORPHIC_SIGNATURE = 1L<<40;
     6.6  
     6.7 +    /**
     6.8 +     * Flag that marks a special kind of bridge methods (the ones that
     6.9 +     * come from restricted supertype bounds)
    6.10 +     */
    6.11 +    public static final long OVERRIDE_BRIDGE = 1L<<41;
    6.12 +
    6.13      /** Modifier masks.
    6.14       */
    6.15      public static final int
     7.1 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java	Tue Sep 07 15:14:49 2010 -0700
     7.2 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java	Tue Sep 07 15:49:48 2010 -0700
     7.3 @@ -272,6 +272,12 @@
     7.4          return false;
     7.5      }
     7.6  
     7.7 +    static final Filter<Symbol> noFilter = new Filter<Symbol>() {
     7.8 +        public boolean accepts(Symbol s) {
     7.9 +            return true;
    7.10 +        }
    7.11 +    };
    7.12 +
    7.13      /** Return the entry associated with given name, starting in
    7.14       *  this scope and proceeding outwards. If no entry was found,
    7.15       *  return the sentinel, which is characterized by having a null in
    7.16 @@ -279,13 +285,20 @@
    7.17       *  for regular entries.
    7.18       */
    7.19      public Entry lookup(Name name) {
    7.20 +        return lookup(name, noFilter);
    7.21 +    }
    7.22 +    public Entry lookup(Name name, Filter<Symbol> sf) {
    7.23          Entry e = table[name.hashCode() & hashMask];
    7.24 -        while (e.scope != null && e.sym.name != name)
    7.25 +        while (e.scope != null && (e.sym.name != name || !sf.accepts(e.sym)))
    7.26              e = e.shadowed;
    7.27          return e;
    7.28      }
    7.29  
    7.30      public Iterable<Symbol> getElements() {
    7.31 +        return getElements(noFilter);
    7.32 +    }
    7.33 +
    7.34 +    public Iterable<Symbol> getElements(final Filter<Symbol> sf) {
    7.35          return new Iterable<Symbol>() {
    7.36              public Iterator<Symbol> iterator() {
    7.37                  return new Iterator<Symbol>() {
    7.38 @@ -301,7 +314,9 @@
    7.39  
    7.40                      public Symbol next() {
    7.41                          Symbol sym = (currEntry == null ? null : currEntry.sym);
    7.42 -                        currEntry = currEntry.sibling;
    7.43 +                        if (currEntry != null) {
    7.44 +                            currEntry = currEntry.sibling;
    7.45 +                        }
    7.46                          update();
    7.47                          return sym;
    7.48                      }
    7.49 @@ -311,9 +326,17 @@
    7.50                      }
    7.51  
    7.52                      private void update() {
    7.53 +                        skipToNextMatchingEntry();
    7.54                          while (currEntry == null && currScope.next != null) {
    7.55                              currScope = currScope.next;
    7.56                              currEntry = currScope.elems;
    7.57 +                            skipToNextMatchingEntry();
    7.58 +                        }
    7.59 +                    }
    7.60 +
    7.61 +                    void skipToNextMatchingEntry() {
    7.62 +                        while (currEntry != null && !sf.accepts(currEntry.sym)) {
    7.63 +                            currEntry = currEntry.sibling;
    7.64                          }
    7.65                      }
    7.66                  };
     8.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java	Tue Sep 07 15:14:49 2010 -0700
     8.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java	Tue Sep 07 15:49:48 2010 -0700
     8.3 @@ -171,11 +171,10 @@
     8.4      public boolean allowUnderscoresInLiterals() {
     8.5          return compareTo(JDK1_7) >= 0;
     8.6      }
     8.7 -    public boolean allowStringsInSwitch() {
     8.8 +    public boolean allowExoticIdentifiers() {
     8.9          return compareTo(JDK1_7) >= 0;
    8.10      }
    8.11 -    // JSR 292: recognize @PolymorphicSignature on java/dyn names
    8.12 -    public boolean allowPolymorphicSignature() {
    8.13 +    public boolean allowStringsInSwitch() {
    8.14          return compareTo(JDK1_7) >= 0;
    8.15      }
    8.16      public static SourceVersion toSourceVersion(Source source) {
     9.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Sep 07 15:14:49 2010 -0700
     9.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Sep 07 15:49:48 2010 -0700
     9.3 @@ -214,6 +214,16 @@
     9.4          return (flags() & INTERFACE) != 0;
     9.5      }
     9.6  
     9.7 +    /** Recognize if this symbol was marked @PolymorphicSignature in the source. */
     9.8 +    public boolean isPolymorphicSignatureGeneric() {
     9.9 +        return (flags() & (POLYMORPHIC_SIGNATURE | HYPOTHETICAL)) == POLYMORPHIC_SIGNATURE;
    9.10 +    }
    9.11 +
    9.12 +    /** Recognize if this symbol was split from a @PolymorphicSignature symbol in the source. */
    9.13 +    public boolean isPolymorphicSignatureInstance() {
    9.14 +        return (flags() & (POLYMORPHIC_SIGNATURE | HYPOTHETICAL)) == (POLYMORPHIC_SIGNATURE | HYPOTHETICAL);
    9.15 +    }
    9.16 +
    9.17      /** Is this symbol declared (directly or indirectly) local
    9.18       *  to a method or variable initializer?
    9.19       *  Also includes fields of inner classes which are in
    9.20 @@ -579,6 +589,9 @@
    9.21  
    9.22          public java.util.List<Symbol> getEnclosedElements() {
    9.23              List<Symbol> list = List.nil();
    9.24 +            if (kind == TYP && type.tag == TYPEVAR) {
    9.25 +                return list;
    9.26 +            }
    9.27              for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
    9.28                  if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
    9.29                      list = list.prepend(e.sym);
    9.30 @@ -1214,7 +1227,18 @@
    9.31           *  as possible implementations.
    9.32           */
    9.33          public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
    9.34 -            MethodSymbol res = types.implementation(this, origin, types, checkResult);
    9.35 +            return implementation(origin, types, checkResult, implementation_filter);
    9.36 +        }
    9.37 +        // where
    9.38 +            private static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
    9.39 +                public boolean accepts(Symbol s) {
    9.40 +                    return s.kind == Kinds.MTH &&
    9.41 +                            (s.flags() & SYNTHETIC) == 0;
    9.42 +                }
    9.43 +            };
    9.44 +
    9.45 +        public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
    9.46 +            MethodSymbol res = types.implementation(this, origin, types, checkResult, implFilter);
    9.47              if (res != null)
    9.48                  return res;
    9.49              // if origin is derived from a raw type, we might have missed
    10.1 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java	Tue Sep 07 15:14:49 2010 -0700
    10.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java	Tue Sep 07 15:49:48 2010 -0700
    10.3 @@ -93,6 +93,10 @@
    10.4       */
    10.5      public final ClassSymbol errSymbol;
    10.6  
    10.7 +    /** The unknown symbol.
    10.8 +     */
    10.9 +    public final ClassSymbol unknownSymbol;
   10.10 +
   10.11      /** A value for the errType, with a originalType of noType */
   10.12      public final Type errType;
   10.13  
   10.14 @@ -354,6 +358,7 @@
   10.15  
   10.16          // create the error symbols
   10.17          errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
   10.18 +        unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
   10.19          errType = new ErrorType(errSymbol, Type.noType);
   10.20  
   10.21          // initialize builtin types
   10.22 @@ -368,7 +373,7 @@
   10.23          initType(voidType, "void", "Void");
   10.24          initType(botType, "<nulltype>");
   10.25          initType(errType, errSymbol);
   10.26 -        initType(unknownType, "<any?>");
   10.27 +        initType(unknownType, unknownSymbol);
   10.28  
   10.29          // the builtin class of all arrays
   10.30          arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
    11.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Sep 07 15:14:49 2010 -0700
    11.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Sep 07 15:49:48 2010 -0700
    11.3 @@ -32,6 +32,7 @@
    11.4  import com.sun.tools.javac.util.List;
    11.5  
    11.6  import com.sun.tools.javac.jvm.ClassReader;
    11.7 +import com.sun.tools.javac.code.Attribute.RetentionPolicy;
    11.8  import com.sun.tools.javac.comp.Check;
    11.9  
   11.10  import static com.sun.tools.javac.code.Type.*;
   11.11 @@ -914,7 +915,7 @@
   11.12              return true;
   11.13  
   11.14          if (t.isPrimitive() != s.isPrimitive())
   11.15 -            return allowBoxing && isConvertible(t, s, warn);
   11.16 +            return allowBoxing && (isConvertible(t, s, warn) || isConvertible(s, t, warn));
   11.17  
   11.18          if (warn != warnStack.head) {
   11.19              try {
   11.20 @@ -1973,45 +1974,74 @@
   11.21              hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s);
   11.22      }
   11.23  
   11.24 -    private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>> implCache_check =
   11.25 -            new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>>();
   11.26 -
   11.27 -    private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>> implCache_nocheck =
   11.28 -            new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>>();
   11.29 -
   11.30 -    public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult) {
   11.31 -        Map<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>> implCache = checkResult ?
   11.32 -            implCache_check : implCache_nocheck;
   11.33 -        SoftReference<Map<TypeSymbol, MethodSymbol>> ref_cache = implCache.get(ms);
   11.34 -        Map<TypeSymbol, MethodSymbol> cache = ref_cache != null ? ref_cache.get() : null;
   11.35 -        if (cache == null) {
   11.36 -            cache = new HashMap<TypeSymbol, MethodSymbol>();
   11.37 -            implCache.put(ms, new SoftReference<Map<TypeSymbol, MethodSymbol>>(cache));
   11.38 +    // <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site">
   11.39 +    class ImplementationCache {
   11.40 +
   11.41 +        private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>> _map =
   11.42 +                new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>>();
   11.43 +
   11.44 +        class Entry {
   11.45 +            final MethodSymbol cachedImpl;
   11.46 +            final Filter<Symbol> implFilter;
   11.47 +            final boolean checkResult;
   11.48 +
   11.49 +            public Entry(MethodSymbol cachedImpl,
   11.50 +                    Filter<Symbol> scopeFilter,
   11.51 +                    boolean checkResult) {
   11.52 +                this.cachedImpl = cachedImpl;
   11.53 +                this.implFilter = scopeFilter;
   11.54 +                this.checkResult = checkResult;
   11.55 +            }
   11.56 +
   11.57 +            boolean matches(Filter<Symbol> scopeFilter, boolean checkResult) {
   11.58 +                return this.implFilter == scopeFilter &&
   11.59 +                        this.checkResult == checkResult;
   11.60 +            }
   11.61          }
   11.62 -        MethodSymbol impl = cache.get(origin);
   11.63 -        if (impl == null) {
   11.64 +
   11.65 +        MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) {
   11.66 +            SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms);
   11.67 +            Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null;
   11.68 +            if (cache == null) {
   11.69 +                cache = new HashMap<TypeSymbol, Entry>();
   11.70 +                _map.put(ms, new SoftReference<Map<TypeSymbol, Entry>>(cache));
   11.71 +            }
   11.72 +            Entry e = cache.get(origin);
   11.73 +            if (e == null ||
   11.74 +                    !e.matches(implFilter, checkResult)) {
   11.75 +                MethodSymbol impl = implementationInternal(ms, origin, Types.this, checkResult, implFilter);
   11.76 +                cache.put(origin, new Entry(impl, implFilter, checkResult));
   11.77 +                return impl;
   11.78 +            }
   11.79 +            else {
   11.80 +                return e.cachedImpl;
   11.81 +            }
   11.82 +        }
   11.83 +
   11.84 +        private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
   11.85              for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = types.supertype(t)) {
   11.86                  while (t.tag == TYPEVAR)
   11.87                      t = t.getUpperBound();
   11.88                  TypeSymbol c = t.tsym;
   11.89 -                for (Scope.Entry e = c.members().lookup(ms.name);
   11.90 +                for (Scope.Entry e = c.members().lookup(ms.name, implFilter);
   11.91                       e.scope != null;
   11.92                       e = e.next()) {
   11.93 -                    if (e.sym.kind == Kinds.MTH) {
   11.94 -                        MethodSymbol m = (MethodSymbol) e.sym;
   11.95 -                        if (m.overrides(ms, origin, types, checkResult) &&
   11.96 -                            (m.flags() & SYNTHETIC) == 0) {
   11.97 -                            impl = m;
   11.98 -                            cache.put(origin, m);
   11.99 -                            return impl;
  11.100 -                        }
  11.101 -                    }
  11.102 +                    if (e.sym != null &&
  11.103 +                             e.sym.overrides(ms, origin, types, checkResult))
  11.104 +                        return (MethodSymbol)e.sym;
  11.105                  }
  11.106              }
  11.107 +            return null;
  11.108          }
  11.109 -        return impl;
  11.110      }
  11.111  
  11.112 +    private ImplementationCache implCache = new ImplementationCache();
  11.113 +
  11.114 +    public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
  11.115 +        return implCache.get(ms, origin, checkResult, implFilter);
  11.116 +    }
  11.117 +    // </editor-fold>
  11.118 +
  11.119      /**
  11.120       * Does t have the same arguments as s?  It is assumed that both
  11.121       * types are (possibly polymorphic) method types.  Monomorphic
  11.122 @@ -3554,4 +3584,24 @@
  11.123          public Type visitType(Type t, S s) { return t; }
  11.124      }
  11.125      // </editor-fold>
  11.126 +
  11.127 +
  11.128 +    // <editor-fold defaultstate="collapsed" desc="Annotation support">
  11.129 +
  11.130 +    public RetentionPolicy getRetention(Attribute.Compound a) {
  11.131 +        RetentionPolicy vis = RetentionPolicy.CLASS; // the default
  11.132 +        Attribute.Compound c = a.type.tsym.attribute(syms.retentionType.tsym);
  11.133 +        if (c != null) {
  11.134 +            Attribute value = c.member(names.value);
  11.135 +            if (value != null && value instanceof Attribute.Enum) {
  11.136 +                Name levelName = ((Attribute.Enum)value).value.name;
  11.137 +                if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE;
  11.138 +                else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS;
  11.139 +                else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME;
  11.140 +                else ;// /* fail soft */ throw new AssertionError(levelName);
  11.141 +            }
  11.142 +        }
  11.143 +        return vis;
  11.144 +    }
  11.145 +    // </editor-fold>
  11.146  }
    12.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Tue Sep 07 15:14:49 2010 -0700
    12.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Tue Sep 07 15:49:48 2010 -0700
    12.3 @@ -182,6 +182,7 @@
    12.4              if (!method.type.isErroneous())
    12.5                  buf.append(new Pair<MethodSymbol,Attribute>
    12.6                             ((MethodSymbol)method, value));
    12.7 +            t.type = result;
    12.8          }
    12.9          return new Attribute.Compound(a.type, buf.toList());
   12.10      }
   12.11 @@ -234,6 +235,7 @@
   12.12                                                 l.head,
   12.13                                                 env));
   12.14              }
   12.15 +            na.type = expected;
   12.16              return new Attribute.
   12.17                  Array(expected, buf.toArray(new Attribute[buf.length()]));
   12.18          }
    13.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Sep 07 15:14:49 2010 -0700
    13.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Sep 07 15:49:48 2010 -0700
    13.3 @@ -328,6 +328,12 @@
    13.4              attribExpr(expr, env);
    13.5          } catch (BreakAttr b) {
    13.6              return b.env;
    13.7 +        } catch (AssertionError ae) {
    13.8 +            if (ae.getCause() instanceof BreakAttr) {
    13.9 +                return ((BreakAttr)(ae.getCause())).env;
   13.10 +            } else {
   13.11 +                throw ae;
   13.12 +            }
   13.13          } finally {
   13.14              breakTree = null;
   13.15              log.useSource(prev);
   13.16 @@ -342,6 +348,12 @@
   13.17              attribStat(stmt, env);
   13.18          } catch (BreakAttr b) {
   13.19              return b.env;
   13.20 +        } catch (AssertionError ae) {
   13.21 +            if (ae.getCause() instanceof BreakAttr) {
   13.22 +                return ((BreakAttr)(ae.getCause())).env;
   13.23 +            } else {
   13.24 +                throw ae;
   13.25 +            }
   13.26          } finally {
   13.27              breakTree = null;
   13.28              log.useSource(prev);
   13.29 @@ -578,6 +590,8 @@
   13.30                     boolean classExpected,
   13.31                     boolean interfaceExpected,
   13.32                     boolean checkExtensible) {
   13.33 +        if (t.isErroneous())
   13.34 +            return t;
   13.35          if (t.tag == TYPEVAR && !classExpected && !interfaceExpected) {
   13.36              // check that type variable is already visible
   13.37              if (t.getUpperBound() == null) {
   13.38 @@ -595,7 +609,7 @@
   13.39          } else if (checkExtensible &&
   13.40                     classExpected &&
   13.41                     (t.tsym.flags() & INTERFACE) != 0) {
   13.42 -            log.error(tree.pos(), "no.intf.expected.here");
   13.43 +                log.error(tree.pos(), "no.intf.expected.here");
   13.44              return types.createErrorType(t);
   13.45          }
   13.46          if (checkExtensible &&
   13.47 @@ -1171,7 +1185,10 @@
   13.48      }
   13.49  
   13.50      public void visitExec(JCExpressionStatement tree) {
   13.51 -        attribExpr(tree.expr, env);
   13.52 +        //a fresh environment is required for 292 inference to work properly ---
   13.53 +        //see Infer.instantiatePolymorphicSignatureInstance()
   13.54 +        Env<AttrContext> localEnv = env.dup(tree);
   13.55 +        attribExpr(tree.expr, localEnv);
   13.56          result = null;
   13.57      }
   13.58  
   13.59 @@ -1429,23 +1446,19 @@
   13.60                                restype.tsym);
   13.61              }
   13.62  
   13.63 -            // as a special case, MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc)
   13.64 -            // has type <T>, and T can be a primitive type.
   13.65 -            if (tree.meth.getTag() == JCTree.SELECT && !typeargtypes.isEmpty()) {
   13.66 -              JCFieldAccess mfield = (JCFieldAccess) tree.meth;
   13.67 -              if ((mfield.selected.type.tsym != null &&
   13.68 -                   (mfield.selected.type.tsym.flags() & POLYMORPHIC_SIGNATURE) != 0)
   13.69 -                  ||
   13.70 -                  (mfield.sym != null &&
   13.71 -                   (mfield.sym.flags() & POLYMORPHIC_SIGNATURE) != 0)) {
   13.72 -                  assert types.isSameType(restype, typeargtypes.head) : mtype;
   13.73 -                  assert mfield.selected.type == syms.methodHandleType
   13.74 -                      || mfield.selected.type == syms.invokeDynamicType;
   13.75 -                  typeargtypesNonRefOK = true;
   13.76 -              }
   13.77 +            // Special case logic for JSR 292 types.
   13.78 +            if (rs.allowTransitionalJSR292 &&
   13.79 +                    tree.meth.getTag() == JCTree.SELECT &&
   13.80 +                    !typeargtypes.isEmpty()) {
   13.81 +                JCFieldAccess mfield = (JCFieldAccess) tree.meth;
   13.82 +                // MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc)
   13.83 +                // has type <T>, and T can be a primitive type.
   13.84 +                if (mfield.sym != null &&
   13.85 +                        mfield.sym.isPolymorphicSignatureInstance())
   13.86 +                    typeargtypesNonRefOK = true;
   13.87              }
   13.88  
   13.89 -            if (!typeargtypesNonRefOK) {
   13.90 +            if (!(rs.allowTransitionalJSR292 && typeargtypesNonRefOK)) {
   13.91                  chk.checkRefTypes(tree.typeargs, typeargtypes);
   13.92              }
   13.93  
   13.94 @@ -2009,7 +2022,10 @@
   13.95      public void visitTypeCast(JCTypeCast tree) {
   13.96          Type clazztype = attribType(tree.clazz, env);
   13.97          chk.validate(tree.clazz, env, false);
   13.98 -        Type exprtype = attribExpr(tree.expr, env, Infer.anyPoly);
   13.99 +        //a fresh environment is required for 292 inference to work properly ---
  13.100 +        //see Infer.instantiatePolymorphicSignatureInstance()
  13.101 +        Env<AttrContext> localEnv = env.dup(tree);
  13.102 +        Type exprtype = attribExpr(tree.expr, localEnv, Infer.anyPoly);
  13.103          Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
  13.104          if (exprtype.constValue() != null)
  13.105              owntype = cfolder.coerce(exprtype, owntype);
  13.106 @@ -2845,7 +2861,6 @@
  13.107                  if (tree.bounds.tail.nonEmpty()) {
  13.108                      log.error(tree.bounds.tail.head.pos(),
  13.109                                "type.var.may.not.be.followed.by.other.bounds");
  13.110 -                    log.unrecoverableError = true;
  13.111                      tree.bounds = List.of(tree.bounds.head);
  13.112                      a.bound = bs.head;
  13.113                  }
  13.114 @@ -3186,4 +3201,104 @@
  13.115              super.visitMethodDef(tree);
  13.116          }
  13.117      };
  13.118 +
  13.119 +    // <editor-fold desc="post-attribution visitor">
  13.120 +
  13.121 +    /**
  13.122 +     * Handle missing types/symbols in an AST. This routine is useful when
  13.123 +     * the compiler has encountered some errors (which might have ended up
  13.124 +     * terminating attribution abruptly); if the compiler is used in fail-over
  13.125 +     * mode (e.g. by an IDE) and the AST contains semantic errors, this routine
  13.126 +     * prevents NPE to be progagated during subsequent compilation steps.
  13.127 +     */
  13.128 +    public void postAttr(Env<AttrContext> env) {
  13.129 +        new PostAttrAnalyzer().scan(env.tree);
  13.130 +    }
  13.131 +
  13.132 +    class PostAttrAnalyzer extends TreeScanner {
  13.133 +
  13.134 +        private void initTypeIfNeeded(JCTree that) {
  13.135 +            if (that.type == null) {
  13.136 +                that.type = syms.unknownType;
  13.137 +            }
  13.138 +        }
  13.139 +
  13.140 +        @Override
  13.141 +        public void scan(JCTree tree) {
  13.142 +            if (tree == null) return;
  13.143 +            if (tree instanceof JCExpression) {
  13.144 +                initTypeIfNeeded(tree);
  13.145 +            }
  13.146 +            super.scan(tree);
  13.147 +        }
  13.148 +
  13.149 +        @Override
  13.150 +        public void visitIdent(JCIdent that) {
  13.151 +            if (that.sym == null) {
  13.152 +                that.sym = syms.unknownSymbol;
  13.153 +            }
  13.154 +        }
  13.155 +
  13.156 +        @Override
  13.157 +        public void visitSelect(JCFieldAccess that) {
  13.158 +            if (that.sym == null) {
  13.159 +                that.sym = syms.unknownSymbol;
  13.160 +            }
  13.161 +            super.visitSelect(that);
  13.162 +        }
  13.163 +
  13.164 +        @Override
  13.165 +        public void visitClassDef(JCClassDecl that) {
  13.166 +            initTypeIfNeeded(that);
  13.167 +            if (that.sym == null) {
  13.168 +                that.sym = new ClassSymbol(0, that.name, that.type, syms.noSymbol);
  13.169 +            }
  13.170 +            super.visitClassDef(that);
  13.171 +        }
  13.172 +
  13.173 +        @Override
  13.174 +        public void visitMethodDef(JCMethodDecl that) {
  13.175 +            initTypeIfNeeded(that);
  13.176 +            if (that.sym == null) {
  13.177 +                that.sym = new MethodSymbol(0, that.name, that.type, syms.noSymbol);
  13.178 +            }
  13.179 +            super.visitMethodDef(that);
  13.180 +        }
  13.181 +
  13.182 +        @Override
  13.183 +        public void visitVarDef(JCVariableDecl that) {
  13.184 +            initTypeIfNeeded(that);
  13.185 +            if (that.sym == null) {
  13.186 +                that.sym = new VarSymbol(0, that.name, that.type, syms.noSymbol);
  13.187 +                that.sym.adr = 0;
  13.188 +            }
  13.189 +            super.visitVarDef(that);
  13.190 +        }
  13.191 +
  13.192 +        @Override
  13.193 +        public void visitNewClass(JCNewClass that) {
  13.194 +            if (that.constructor == null) {
  13.195 +                that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol);
  13.196 +            }
  13.197 +            if (that.constructorType == null) {
  13.198 +                that.constructorType = syms.unknownType;
  13.199 +            }
  13.200 +            super.visitNewClass(that);
  13.201 +        }
  13.202 +
  13.203 +        @Override
  13.204 +        public void visitBinary(JCBinary that) {
  13.205 +            if (that.operator == null)
  13.206 +                that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol);
  13.207 +            super.visitBinary(that);
  13.208 +        }
  13.209 +
  13.210 +        @Override
  13.211 +        public void visitUnary(JCUnary that) {
  13.212 +            if (that.operator == null)
  13.213 +                that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol);
  13.214 +            super.visitUnary(that);
  13.215 +        }
  13.216 +    }
  13.217 +    // </editor-fold>
  13.218  }
    14.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java	Tue Sep 07 15:14:49 2010 -0700
    14.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java	Tue Sep 07 15:49:48 2010 -0700
    14.3 @@ -38,6 +38,7 @@
    14.4  
    14.5  import com.sun.tools.javac.code.Type.*;
    14.6  import com.sun.tools.javac.code.Symbol.*;
    14.7 +import com.sun.tools.javac.main.RecognizedOptions.PkgInfo;
    14.8  import com.sun.tools.javac.tree.JCTree.*;
    14.9  
   14.10  import static com.sun.tools.javac.code.Flags.*;
   14.11 @@ -102,6 +103,7 @@
   14.12      Lint lint;
   14.13      Names names;
   14.14      JavaFileManager fileManager;
   14.15 +    PkgInfo pkginfoOpt;
   14.16  
   14.17      private final Todo todo;
   14.18  
   14.19 @@ -132,6 +134,9 @@
   14.20          predefClassDef.sym = syms.predefClass;
   14.21          todo = Todo.instance(context);
   14.22          fileManager = context.get(JavaFileManager.class);
   14.23 +
   14.24 +        Options options = Options.instance(context);
   14.25 +        pkginfoOpt = PkgInfo.get(options);
   14.26      }
   14.27  
   14.28      /** A hashtable mapping classes and packages to the environments current
   14.29 @@ -278,7 +283,7 @@
   14.30                                                               JavaFileObject.Kind.SOURCE);
   14.31          if (tree.pid != null) {
   14.32              tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid));
   14.33 -            if (tree.packageAnnotations.nonEmpty()) {
   14.34 +            if (tree.packageAnnotations.nonEmpty() || pkginfoOpt == PkgInfo.ALWAYS) {
   14.35                  if (isPkgInfo) {
   14.36                      addEnv = true;
   14.37                  } else {
    15.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 07 15:14:49 2010 -0700
    15.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 07 15:49:48 2010 -0700
    15.3 @@ -408,7 +408,9 @@
    15.4          tree = TreeInfo.skipParens(tree);
    15.5          if (tree.getTag() == JCTree.IDENT || tree.getTag() == JCTree.SELECT) {
    15.6              Symbol sym = TreeInfo.symbol(tree);
    15.7 -            letInit(tree.pos(), (VarSymbol)sym);
    15.8 +            if (sym.kind == VAR) {
    15.9 +                letInit(tree.pos(), (VarSymbol)sym);
   15.10 +            }
   15.11          }
   15.12      }
   15.13  
   15.14 @@ -481,12 +483,13 @@
   15.15  
   15.16      /** Split (duplicate) inits/uninits into WhenTrue/WhenFalse sets
   15.17       */
   15.18 -    void split() {
   15.19 +    void split(boolean setToNull) {
   15.20          initsWhenFalse = inits.dup();
   15.21          uninitsWhenFalse = uninits.dup();
   15.22          initsWhenTrue = inits;
   15.23          uninitsWhenTrue = uninits;
   15.24 -        inits = uninits = null;
   15.25 +        if (setToNull)
   15.26 +            inits = uninits = null;
   15.27      }
   15.28  
   15.29      /** Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets.
   15.30 @@ -568,9 +571,11 @@
   15.31              uninitsWhenTrue = uninits;
   15.32          } else {
   15.33              scan(tree);
   15.34 -            if (inits != null) split();
   15.35 +            if (inits != null)
   15.36 +                split(tree.type != syms.unknownType);
   15.37          }
   15.38 -        inits = uninits = null;
   15.39 +        if (tree.type != syms.unknownType)
   15.40 +            inits = uninits = null;
   15.41      }
   15.42  
   15.43      /* ------------ Visitor methods for various sorts of trees -------------*/
   15.44 @@ -1007,7 +1012,7 @@
   15.45                  List.of(resource.type);
   15.46              for (Type sup : closeableSupertypes) {
   15.47                  if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) {
   15.48 -                    Symbol closeMethod = rs.resolveInternalMethod(tree,
   15.49 +                    Symbol closeMethod = rs.resolveQualifiedMethod(tree,
   15.50                              attrEnv,
   15.51                              sup,
   15.52                              names.close,
   15.53 @@ -1050,20 +1055,22 @@
   15.54              List<Type> rethrownTypes = chk.diff(thrownInTry, caughtInTry);
   15.55              for (JCExpression ct : subClauses) {
   15.56                  Type exc = ct.type;
   15.57 -                ctypes = ctypes.append(exc);
   15.58 -                if (types.isSameType(exc, syms.objectType))
   15.59 -                    continue;
   15.60 -                if (chk.subset(exc, caughtInTry)) {
   15.61 -                    log.error(l.head.pos(),
   15.62 -                              "except.already.caught", exc);
   15.63 -                } else if (!chk.isUnchecked(l.head.pos(), exc) &&
   15.64 -                           exc.tsym != syms.throwableType.tsym &&
   15.65 -                           exc.tsym != syms.exceptionType.tsym &&
   15.66 -                           !chk.intersects(exc, thrownInTry)) {
   15.67 -                    log.error(l.head.pos(),
   15.68 -                              "except.never.thrown.in.try", exc);
   15.69 +                if (exc != syms.unknownType) {
   15.70 +                    ctypes = ctypes.append(exc);
   15.71 +                    if (types.isSameType(exc, syms.objectType))
   15.72 +                        continue;
   15.73 +                    if (chk.subset(exc, caughtInTry)) {
   15.74 +                        log.error(l.head.pos(),
   15.75 +                                  "except.already.caught", exc);
   15.76 +                    } else if (!chk.isUnchecked(l.head.pos(), exc) &&
   15.77 +                               exc.tsym != syms.throwableType.tsym &&
   15.78 +                               exc.tsym != syms.exceptionType.tsym &&
   15.79 +                               !chk.intersects(exc, thrownInTry)) {
   15.80 +                        log.error(l.head.pos(),
   15.81 +                                  "except.never.thrown.in.try", exc);
   15.82 +                    }
   15.83 +                    caughtInTry = chk.incl(exc, caughtInTry);
   15.84                  }
   15.85 -                caughtInTry = chk.incl(exc, caughtInTry);
   15.86              }
   15.87              inits = initsTry.dup();
   15.88              uninits = uninitsTry.dup();
    16.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Sep 07 15:14:49 2010 -0700
    16.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Sep 07 15:49:48 2010 -0700
    16.3 @@ -25,6 +25,8 @@
    16.4  
    16.5  package com.sun.tools.javac.comp;
    16.6  
    16.7 +import com.sun.tools.javac.tree.JCTree;
    16.8 +import com.sun.tools.javac.tree.JCTree.JCTypeCast;
    16.9  import com.sun.tools.javac.util.*;
   16.10  import com.sun.tools.javac.util.List;
   16.11  import com.sun.tools.javac.code.*;
   16.12 @@ -543,4 +545,56 @@
   16.13                                  args.head, bounds);
   16.14          }
   16.15      }
   16.16 +
   16.17 +    /**
   16.18 +     * Compute a synthetic method type corresponding to the requested polymorphic
   16.19 +     * method signature. If no explicit return type is supplied, a provisional
   16.20 +     * return type is computed (just Object in case of non-transitional 292)
   16.21 +     */
   16.22 +    Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
   16.23 +                                            Name name,
   16.24 +                                            MethodSymbol spMethod,  // sig. poly. method or null if none
   16.25 +                                            List<Type> argtypes,
   16.26 +                                            List<Type> typeargtypes) {
   16.27 +        final Type restype;
   16.28 +        if (rs.allowTransitionalJSR292 && typeargtypes.nonEmpty()) {
   16.29 +            restype = typeargtypes.head;
   16.30 +        } else {
   16.31 +            //The return type for a polymorphic signature call is computed from
   16.32 +            //the enclosing tree E, as follows: if E is a cast, then use the
   16.33 +            //target type of the cast expression as a return type; if E is an
   16.34 +            //expression statement, the return type is 'void' - otherwise the
   16.35 +            //return type is simply 'Object'.
   16.36 +            switch (env.outer.tree.getTag()) {
   16.37 +                case JCTree.TYPECAST:
   16.38 +                    restype = ((JCTypeCast)env.outer.tree).clazz.type; break;
   16.39 +                case JCTree.EXEC:
   16.40 +                    restype = syms.voidType; break;
   16.41 +                default:
   16.42 +                    restype = syms.objectType;
   16.43 +            }
   16.44 +        }
   16.45 +
   16.46 +        List<Type> paramtypes = Type.map(argtypes, implicitArgType);
   16.47 +        List<Type> exType = spMethod != null ?
   16.48 +            spMethod.getThrownTypes() :
   16.49 +            List.of(syms.throwableType); // make it throw all exceptions
   16.50 +
   16.51 +        MethodType mtype = new MethodType(paramtypes,
   16.52 +                                          restype,
   16.53 +                                          exType,
   16.54 +                                          syms.methodClass);
   16.55 +        return mtype;
   16.56 +    }
   16.57 +    //where
   16.58 +        Mapping implicitArgType = new Mapping ("implicitArgType") {
   16.59 +                public Type apply(Type t) {
   16.60 +                    t = types.erasure(t);
   16.61 +                    if (t.tag == BOT)
   16.62 +                        // nulls type as the marker type Null (which has no instances)
   16.63 +                        // infer as java.lang.Void for now
   16.64 +                        t = types.boxedClass(syms.voidType).type;
   16.65 +                    return t;
   16.66 +                }
   16.67 +        };
   16.68  }
    17.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Sep 07 15:14:49 2010 -0700
    17.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Sep 07 15:49:48 2010 -0700
    17.3 @@ -29,6 +29,7 @@
    17.4  
    17.5  import com.sun.tools.javac.code.*;
    17.6  import com.sun.tools.javac.jvm.*;
    17.7 +import com.sun.tools.javac.main.RecognizedOptions.PkgInfo;
    17.8  import com.sun.tools.javac.tree.*;
    17.9  import com.sun.tools.javac.util.*;
   17.10  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
   17.11 @@ -82,6 +83,7 @@
   17.12      private final Name classDollar;
   17.13      private Types types;
   17.14      private boolean debugLower;
   17.15 +    private PkgInfo pkginfoOpt;
   17.16  
   17.17      protected Lower(Context context) {
   17.18          context.put(lowerKey, this);
   17.19 @@ -106,6 +108,7 @@
   17.20          types = Types.instance(context);
   17.21          Options options = Options.instance(context);
   17.22          debugLower = options.get("debuglower") != null;
   17.23 +        pkginfoOpt = PkgInfo.get(options);
   17.24      }
   17.25  
   17.26      /** The currently enclosing class.
   17.27 @@ -2161,7 +2164,7 @@
   17.28      }
   17.29  
   17.30      public void visitTopLevel(JCCompilationUnit tree) {
   17.31 -        if (tree.packageAnnotations.nonEmpty()) {
   17.32 +        if (needPackageInfoClass(tree)) {
   17.33              Name name = names.package_info;
   17.34              long flags = Flags.ABSTRACT | Flags.INTERFACE;
   17.35              if (target.isPackageInfoSynthetic())
   17.36 @@ -2183,6 +2186,23 @@
   17.37              translated.append(packageAnnotationsClass);
   17.38          }
   17.39      }
   17.40 +    // where
   17.41 +    private boolean needPackageInfoClass(JCCompilationUnit tree) {
   17.42 +        switch (pkginfoOpt) {
   17.43 +            case ALWAYS:
   17.44 +                return true;
   17.45 +            case LEGACY:
   17.46 +                return tree.packageAnnotations.nonEmpty();
   17.47 +            case NONEMPTY:
   17.48 +                for (Attribute.Compound a: tree.packge.attributes_field) {
   17.49 +                    Attribute.RetentionPolicy p = types.getRetention(a);
   17.50 +                    if (p != Attribute.RetentionPolicy.SOURCE)
   17.51 +                        return true;
   17.52 +                }
   17.53 +                return false;
   17.54 +        }
   17.55 +        throw new AssertionError();
   17.56 +    }
   17.57  
   17.58      public void visitClassDef(JCClassDecl tree) {
   17.59          ClassSymbol currentClassPrev = currentClass;
   17.60 @@ -2869,8 +2889,17 @@
   17.61      /** Unbox an object to a primitive value. */
   17.62      JCExpression unbox(JCExpression tree, Type primitive) {
   17.63          Type unboxedType = types.unboxedType(tree.type);
   17.64 -        // note: the "primitive" parameter is not used.  There muse be
   17.65 -        // a conversion from unboxedType to primitive.
   17.66 +        if (unboxedType.tag == NONE) {
   17.67 +            unboxedType = primitive;
   17.68 +            if (!unboxedType.isPrimitive())
   17.69 +                throw new AssertionError(unboxedType);
   17.70 +            make_at(tree.pos());
   17.71 +            tree = make.TypeCast(types.boxedClass(unboxedType).type, tree);
   17.72 +        } else {
   17.73 +            // There must be a conversion from unboxedType to primitive.
   17.74 +            if (!types.isSubtype(unboxedType, primitive))
   17.75 +                throw new AssertionError(tree);
   17.76 +        }
   17.77          make_at(tree.pos());
   17.78          Symbol valueSym = lookupMethod(tree.pos(),
   17.79                                         unboxedType.tsym.name.append(names.Value), // x.intValue()
    18.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Sep 07 15:14:49 2010 -0700
    18.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Sep 07 15:49:48 2010 -0700
    18.3 @@ -769,9 +769,17 @@
    18.4                  && types.isSameType(c.type, syms.deprecatedType))
    18.5                  s.flags_field |= Flags.DEPRECATED;
    18.6              // Internally to java.dyn, a @PolymorphicSignature annotation
    18.7 -            // translates to a classfile attribute.
    18.8 -            if (!c.type.isErroneous()
    18.9 -                && types.isSameType(c.type, syms.polymorphicSignatureType)) {
   18.10 +            // acts like a classfile attribute.
   18.11 +            if (!c.type.isErroneous() &&
   18.12 +                    types.isSameType(c.type, syms.polymorphicSignatureType)) {
   18.13 +                if (!target.hasMethodHandles()) {
   18.14 +                    // Somebody is compiling JDK7 source code to a JDK6 target.
   18.15 +                    // Make it a strict warning, since it is unlikely but important.
   18.16 +                    log.strictWarning(env.tree.pos(),
   18.17 +                            "wrong.target.for.polymorphic.signature.definition",
   18.18 +                            target.name);
   18.19 +                }
   18.20 +                // Pull the flag through for better diagnostics, even on a bad target.
   18.21                  s.flags_field |= Flags.POLYMORPHIC_SIGNATURE;
   18.22              }
   18.23              if (!annotated.add(a.type.tsym))
    19.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Sep 07 15:14:49 2010 -0700
    19.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Sep 07 15:49:48 2010 -0700
    19.3 @@ -69,9 +69,13 @@
    19.4      JCDiagnostic.Factory diags;
    19.5      public final boolean boxingEnabled; // = source.allowBoxing();
    19.6      public final boolean varargsEnabled; // = source.allowVarargs();
    19.7 -    public final boolean allowPolymorphicSignature;
    19.8 +    public final boolean allowMethodHandles;
    19.9 +    public final boolean allowInvokeDynamic;
   19.10 +    public final boolean allowTransitionalJSR292;
   19.11      private final boolean debugResolve;
   19.12  
   19.13 +    Scope polymorphicSignatureScope;
   19.14 +
   19.15      public static Resolve instance(Context context) {
   19.16          Resolve instance = context.get(resolveKey);
   19.17          if (instance == null)
   19.18 @@ -107,7 +111,14 @@
   19.19          varargsEnabled = source.allowVarargs();
   19.20          Options options = Options.instance(context);
   19.21          debugResolve = options.get("debugresolve") != null;
   19.22 -        allowPolymorphicSignature = source.allowPolymorphicSignature() || options.get("invokedynamic") != null;
   19.23 +        allowTransitionalJSR292 = options.get("allowTransitionalJSR292") != null;
   19.24 +        Target target = Target.instance(context);
   19.25 +        allowMethodHandles = allowTransitionalJSR292 ||
   19.26 +                target.hasMethodHandles();
   19.27 +        allowInvokeDynamic = (allowTransitionalJSR292 ||
   19.28 +                target.hasInvokedynamic()) &&
   19.29 +                options.get("invokedynamic") != null;
   19.30 +        polymorphicSignatureScope = new Scope(syms.noSymbol);
   19.31      }
   19.32  
   19.33      /** error symbols, which are returned when resolution fails
   19.34 @@ -246,7 +257,8 @@
   19.35      /* `sym' is accessible only if not overridden by
   19.36       * another symbol which is a member of `site'
   19.37       * (because, if it is overridden, `sym' is not strictly
   19.38 -     * speaking a member of `site'.)
   19.39 +     * speaking a member of `site'). A polymorphic signature method
   19.40 +     * cannot be overridden (e.g. MH.invokeExact(Object[])).
   19.41       */
   19.42      private boolean notOverriddenIn(Type site, Symbol sym) {
   19.43          if (sym.kind != MTH || sym.isConstructor() || sym.isStatic())
   19.44 @@ -254,6 +266,7 @@
   19.45          else {
   19.46              Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
   19.47              return (s2 == null || s2 == sym ||
   19.48 +                    s2.isPolymorphicSignatureGeneric() ||
   19.49                      !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym)));
   19.50          }
   19.51      }
   19.52 @@ -303,7 +316,8 @@
   19.53                          boolean useVarargs,
   19.54                          Warner warn)
   19.55          throws Infer.InferenceException {
   19.56 -        assert ((m.flags() & (POLYMORPHIC_SIGNATURE|HYPOTHETICAL)) != POLYMORPHIC_SIGNATURE);
   19.57 +        boolean polymorphicSignature = (m.isPolymorphicSignatureGeneric() && allowMethodHandles) ||
   19.58 +                                        isTransitionalDynamicCallSite(site, m);
   19.59          if (useVarargs && (m.flags() & VARARGS) == 0) return null;
   19.60          Type mt = types.memberType(site, m);
   19.61  
   19.62 @@ -311,7 +325,10 @@
   19.63          // need to inferred.
   19.64          List<Type> tvars = env.info.tvars;
   19.65          if (typeargtypes == null) typeargtypes = List.nil();
   19.66 -        if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
   19.67 +        if (allowTransitionalJSR292 && polymorphicSignature && typeargtypes.nonEmpty()) {
   19.68 +            //transitional 292 call sites might have wrong number of targs
   19.69 +        }
   19.70 +        else if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
   19.71              // This is not a polymorphic method, but typeargs are supplied
   19.72              // which is fine, see JLS3 15.12.2.1
   19.73          } else if (mt.tag == FORALL && typeargtypes.nonEmpty()) {
   19.74 @@ -339,7 +356,8 @@
   19.75          }
   19.76  
   19.77          // find out whether we need to go the slow route via infer
   19.78 -        boolean instNeeded = tvars.tail != null/*inlined: tvars.nonEmpty()*/;
   19.79 +        boolean instNeeded = tvars.tail != null || /*inlined: tvars.nonEmpty()*/
   19.80 +                polymorphicSignature;
   19.81          for (List<Type> l = argtypes;
   19.82               l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded;
   19.83               l = l.tail) {
   19.84 @@ -347,8 +365,9 @@
   19.85          }
   19.86  
   19.87          if (instNeeded)
   19.88 -            return
   19.89 -            infer.instantiateMethod(env,
   19.90 +            return polymorphicSignature ?
   19.91 +                infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes, typeargtypes) :
   19.92 +                infer.instantiateMethod(env,
   19.93                                      tvars,
   19.94                                      (MethodType)mt,
   19.95                                      m,
   19.96 @@ -363,6 +382,14 @@
   19.97              : null;
   19.98      }
   19.99  
  19.100 +    boolean isTransitionalDynamicCallSite(Type site, Symbol sym) {
  19.101 +        return allowTransitionalJSR292 &&  // old logic that doesn't use annotations
  19.102 +                !sym.isPolymorphicSignatureInstance() &&
  19.103 +                ((allowMethodHandles && site == syms.methodHandleType && // invokeExact, invokeGeneric, invoke
  19.104 +                    (sym.name == names.invoke && sym.isPolymorphicSignatureGeneric())) ||
  19.105 +                (site == syms.invokeDynamicType && allowInvokeDynamic)); // InvokeDynamic.XYZ
  19.106 +    }
  19.107 +
  19.108      /** Same but returns null instead throwing a NoInstanceException
  19.109       */
  19.110      Type instantiate(Env<AttrContext> env,
  19.111 @@ -580,14 +607,6 @@
  19.112          if (sym.kind == ERR) return bestSoFar;
  19.113          if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
  19.114          assert sym.kind < AMBIGUOUS;
  19.115 -        if ((sym.flags() & POLYMORPHIC_SIGNATURE) != 0 && allowPolymorphicSignature) {
  19.116 -            assert(site.tag == CLASS);
  19.117 -            // Never match a MethodHandle.invoke directly.
  19.118 -            if (useVarargs | allowBoxing | operator)
  19.119 -                return bestSoFar;
  19.120 -            // Supply an exactly-typed implicit method instead.
  19.121 -            sym = findPolymorphicSignatureInstance(env, sym.owner.type, sym.name, (MethodSymbol) sym, argtypes, typeargtypes);
  19.122 -        }
  19.123          try {
  19.124              if (rawInstantiate(env, site, sym, argtypes, typeargtypes,
  19.125                                 allowBoxing, useVarargs, Warner.noWarnings) == null) {
  19.126 @@ -759,13 +778,6 @@
  19.127                        boolean useVarargs,
  19.128                        boolean operator) {
  19.129          Symbol bestSoFar = methodNotFound;
  19.130 -        if ((site.tsym.flags() & POLYMORPHIC_SIGNATURE) != 0 &&
  19.131 -            allowPolymorphicSignature &&
  19.132 -            site.tag == CLASS &&
  19.133 -            !(useVarargs | allowBoxing | operator)) {
  19.134 -            // supply an exactly-typed implicit method in java.dyn.InvokeDynamic
  19.135 -            bestSoFar = findPolymorphicSignatureInstance(env, site, name, null, argtypes, typeargtypes);
  19.136 -        }
  19.137          return findMethod(env,
  19.138                            site,
  19.139                            name,
  19.140 @@ -907,90 +919,6 @@
  19.141          return bestSoFar;
  19.142      }
  19.143  
  19.144 -    /** Find or create an implicit method of exactly the given type (after erasure).
  19.145 -     *  Searches in a side table, not the main scope of the site.
  19.146 -     *  This emulates the lookup process required by JSR 292 in JVM.
  19.147 -     *  @param env       The current environment.
  19.148 -     *  @param site      The original type from where the selection
  19.149 -     *                   takes place.
  19.150 -     *  @param name      The method's name.
  19.151 -     *  @param argtypes  The method's value arguments.
  19.152 -     *  @param typeargtypes The method's type arguments
  19.153 -     */
  19.154 -    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
  19.155 -                                            Type site,
  19.156 -                                            Name name,
  19.157 -                                            MethodSymbol spMethod,  // sig. poly. method or null if none
  19.158 -                                            List<Type> argtypes,
  19.159 -                                            List<Type> typeargtypes) {
  19.160 -        assert allowPolymorphicSignature;
  19.161 -        //assert site == syms.invokeDynamicType || site == syms.methodHandleType : site;
  19.162 -        ClassSymbol c = (ClassSymbol) site.tsym;
  19.163 -        Scope implicit = c.members().next;
  19.164 -        if (implicit == null) {
  19.165 -            c.members().next = implicit = new Scope(c);
  19.166 -        }
  19.167 -        Type restype;
  19.168 -        if (typeargtypes.isEmpty()) {
  19.169 -            restype = syms.objectType;
  19.170 -        } else {
  19.171 -            restype = typeargtypes.head;
  19.172 -            if (!typeargtypes.tail.isEmpty())
  19.173 -                return methodNotFound;
  19.174 -        }
  19.175 -        List<Type> paramtypes = Type.map(argtypes, implicitArgType);
  19.176 -        long flags;
  19.177 -        List<Type> exType;
  19.178 -        if (spMethod != null) {
  19.179 -            exType = spMethod.getThrownTypes();
  19.180 -            flags = spMethod.flags() & AccessFlags;
  19.181 -        } else {
  19.182 -            // make it throw all exceptions
  19.183 -            //assert(site == syms.invokeDynamicType);
  19.184 -            exType = List.of(syms.throwableType);
  19.185 -            flags = PUBLIC | STATIC;
  19.186 -        }
  19.187 -        MethodType mtype = new MethodType(paramtypes,
  19.188 -                                          restype,
  19.189 -                                          exType,
  19.190 -                                          syms.methodClass);
  19.191 -        flags |= ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE;
  19.192 -        Symbol m = null;
  19.193 -        for (Scope.Entry e = implicit.lookup(name);
  19.194 -             e.scope != null;
  19.195 -             e = e.next()) {
  19.196 -            Symbol sym = e.sym;
  19.197 -            assert sym.kind == MTH;
  19.198 -            if (types.isSameType(mtype, sym.type)
  19.199 -                && (sym.flags() & STATIC) == (flags & STATIC)) {
  19.200 -                m = sym;
  19.201 -                break;
  19.202 -            }
  19.203 -        }
  19.204 -        if (m == null) {
  19.205 -            // create the desired method
  19.206 -            m = new MethodSymbol(flags, name, mtype, c);
  19.207 -            implicit.enter(m);
  19.208 -        }
  19.209 -        assert argumentsAcceptable(argtypes, types.memberType(site, m).getParameterTypes(),
  19.210 -                                   false, false, Warner.noWarnings);
  19.211 -        assert null != instantiate(env, site, m, argtypes, typeargtypes, false, false, Warner.noWarnings);
  19.212 -        return m;
  19.213 -    }
  19.214 -    //where
  19.215 -        Mapping implicitArgType = new Mapping ("implicitArgType") {
  19.216 -                public Type apply(Type t) { return implicitArgType(t); }
  19.217 -            };
  19.218 -        Type implicitArgType(Type argType) {
  19.219 -            argType = types.erasure(argType);
  19.220 -            if (argType.tag == BOT)
  19.221 -                // nulls type as the marker type Null (which has no instances)
  19.222 -                // TO DO: figure out how to access java.lang.Null safely, else throw nice error
  19.223 -                //argType = types.boxedClass(syms.botType).type;
  19.224 -                argType = types.boxedClass(syms.voidType).type;  // REMOVE
  19.225 -            return argType;
  19.226 -        }
  19.227 -
  19.228      /** Load toplevel or member class with given fully qualified name and
  19.229       *  verify that it is accessible.
  19.230       *  @param env       The current environment.
  19.231 @@ -1369,16 +1297,77 @@
  19.232              methodResolutionCache.put(steps.head, sym);
  19.233              steps = steps.tail;
  19.234          }
  19.235 -        if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
  19.236 -            MethodResolutionPhase errPhase =
  19.237 -                    firstErroneousResolutionPhase();
  19.238 -            sym = access(methodResolutionCache.get(errPhase),
  19.239 -                    pos, site, name, true, argtypes, typeargtypes);
  19.240 -            env.info.varArgs = errPhase.isVarargsRequired;
  19.241 +        if (sym.kind >= AMBIGUOUS) {
  19.242 +            if (site.tsym.isPolymorphicSignatureGeneric() ||
  19.243 +                    isTransitionalDynamicCallSite(site, sym)) {
  19.244 +                //polymorphic receiver - synthesize new method symbol
  19.245 +                env.info.varArgs = false;
  19.246 +                sym = findPolymorphicSignatureInstance(env,
  19.247 +                        site, name, null, argtypes, typeargtypes);
  19.248 +            }
  19.249 +            else {
  19.250 +                //if nothing is found return the 'first' error
  19.251 +                MethodResolutionPhase errPhase =
  19.252 +                        firstErroneousResolutionPhase();
  19.253 +                sym = access(methodResolutionCache.get(errPhase),
  19.254 +                        pos, site, name, true, argtypes, typeargtypes);
  19.255 +                env.info.varArgs = errPhase.isVarargsRequired;
  19.256 +            }
  19.257 +        } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
  19.258 +            //non-instantiated polymorphic signature - synthesize new method symbol
  19.259 +            env.info.varArgs = false;
  19.260 +            sym = findPolymorphicSignatureInstance(env,
  19.261 +                    site, name, (MethodSymbol)sym, argtypes, typeargtypes);
  19.262          }
  19.263          return sym;
  19.264      }
  19.265  
  19.266 +    /** Find or create an implicit method of exactly the given type (after erasure).
  19.267 +     *  Searches in a side table, not the main scope of the site.
  19.268 +     *  This emulates the lookup process required by JSR 292 in JVM.
  19.269 +     *  @param env       Attribution environment
  19.270 +     *  @param site      The original type from where the selection takes place.
  19.271 +     *  @param name      The method's name.
  19.272 +     *  @param spMethod  A template for the implicit method, or null.
  19.273 +     *  @param argtypes  The required argument types.
  19.274 +     *  @param typeargtypes  The required type arguments.
  19.275 +     */
  19.276 +    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site,
  19.277 +                                            Name name,
  19.278 +                                            MethodSymbol spMethod,  // sig. poly. method or null if none
  19.279 +                                            List<Type> argtypes,
  19.280 +                                            List<Type> typeargtypes) {
  19.281 +        if (typeargtypes.nonEmpty() && (site.tsym.isPolymorphicSignatureGeneric() ||
  19.282 +                (spMethod != null && spMethod.isPolymorphicSignatureGeneric()))) {
  19.283 +            log.warning(env.tree.pos(), "type.parameter.on.polymorphic.signature");
  19.284 +        }
  19.285 +
  19.286 +        Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
  19.287 +                site, name, spMethod, argtypes, typeargtypes);
  19.288 +        long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE |
  19.289 +                    (spMethod != null ?
  19.290 +                        spMethod.flags() & Flags.AccessFlags :
  19.291 +                        Flags.PUBLIC | Flags.STATIC);
  19.292 +        Symbol m = null;
  19.293 +        for (Scope.Entry e = polymorphicSignatureScope.lookup(name);
  19.294 +             e.scope != null;
  19.295 +             e = e.next()) {
  19.296 +            Symbol sym = e.sym;
  19.297 +            if (types.isSameType(mtype, sym.type) &&
  19.298 +                (sym.flags() & Flags.STATIC) == (flags & Flags.STATIC) &&
  19.299 +                types.isSameType(sym.owner.type, site)) {
  19.300 +               m = sym;
  19.301 +               break;
  19.302 +            }
  19.303 +        }
  19.304 +        if (m == null) {
  19.305 +            // create the desired method
  19.306 +            m = new MethodSymbol(flags, name, mtype, site.tsym);
  19.307 +            polymorphicSignatureScope.enter(m);
  19.308 +        }
  19.309 +        return m;
  19.310 +    }
  19.311 +
  19.312      /** Resolve a qualified method identifier, throw a fatal error if not
  19.313       *  found.
  19.314       *  @param pos       The position to use for error reporting.
    20.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Sep 07 15:14:49 2010 -0700
    20.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Tue Sep 07 15:49:48 2010 -0700
    20.3 @@ -283,12 +283,13 @@
    20.4                             ListBuffer<JCTree> bridges) {
    20.5          if (sym.kind == MTH &&
    20.6              sym.name != names.init &&
    20.7 -            (sym.flags() & (PRIVATE | SYNTHETIC | STATIC)) == 0 &&
    20.8 +            (sym.flags() & (PRIVATE | STATIC)) == 0 &&
    20.9 +            (sym.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC &&
   20.10              sym.isMemberOf(origin, types))
   20.11          {
   20.12              MethodSymbol meth = (MethodSymbol)sym;
   20.13              MethodSymbol bridge = meth.binaryImplementation(origin, types);
   20.14 -            MethodSymbol impl = meth.implementation(origin, types, true);
   20.15 +            MethodSymbol impl = meth.implementation(origin, types, true, overrideBridgeFilter);
   20.16              if (bridge == null ||
   20.17                  bridge == meth ||
   20.18                  (impl != null && !bridge.owner.isSubClass(impl.owner, types))) {
   20.19 @@ -304,7 +305,7 @@
   20.20                      // reflection design error.
   20.21                      addBridge(pos, meth, impl, origin, false, bridges);
   20.22                  }
   20.23 -            } else if ((bridge.flags() & SYNTHETIC) != 0) {
   20.24 +            } else if ((bridge.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) == SYNTHETIC) {
   20.25                  MethodSymbol other = overridden.get(bridge);
   20.26                  if (other != null && other != meth) {
   20.27                      if (impl == null || !impl.overrides(other, origin, types, true)) {
   20.28 @@ -327,6 +328,11 @@
   20.29          }
   20.30      }
   20.31      // where
   20.32 +        Filter<Symbol> overrideBridgeFilter = new Filter<Symbol>() {
   20.33 +            public boolean accepts(Symbol s) {
   20.34 +                return (s.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC;
   20.35 +            }
   20.36 +        };
   20.37          /**
   20.38           * @param method The symbol for which a bridge might have to be added
   20.39           * @param impl The implementation of method
   20.40 @@ -754,6 +760,90 @@
   20.41          return types.erasure(t);
   20.42      }
   20.43  
   20.44 +    private boolean boundsRestricted(ClassSymbol c) {
   20.45 +        Type st = types.supertype(c.type);
   20.46 +        if (st.isParameterized()) {
   20.47 +            List<Type> actuals = st.allparams();
   20.48 +            List<Type> formals = st.tsym.type.allparams();
   20.49 +            while (!actuals.isEmpty() && !formals.isEmpty()) {
   20.50 +                Type actual = actuals.head;
   20.51 +                Type formal = formals.head;
   20.52 +
   20.53 +                if (!types.isSameType(types.erasure(actual),
   20.54 +                        types.erasure(formal)))
   20.55 +                    return true;
   20.56 +
   20.57 +                actuals = actuals.tail;
   20.58 +                formals = formals.tail;
   20.59 +            }
   20.60 +        }
   20.61 +        return false;
   20.62 +    }
   20.63 +
   20.64 +    private List<JCTree> addOverrideBridgesIfNeeded(DiagnosticPosition pos,
   20.65 +                                    final ClassSymbol c) {
   20.66 +        ListBuffer<JCTree> buf = ListBuffer.lb();
   20.67 +        if (c.isInterface() || !boundsRestricted(c))
   20.68 +            return buf.toList();
   20.69 +        Type t = types.supertype(c.type);
   20.70 +            Scope s = t.tsym.members();
   20.71 +            if (s.elems != null) {
   20.72 +                for (Symbol sym : s.getElements(new NeedsOverridBridgeFilter(c))) {
   20.73 +
   20.74 +                    MethodSymbol m = (MethodSymbol)sym;
   20.75 +                    MethodSymbol member = (MethodSymbol)m.asMemberOf(c.type, types);
   20.76 +                    MethodSymbol impl = m.implementation(c, types, false);
   20.77 +
   20.78 +                    if ((impl == null || impl.owner != c) &&
   20.79 +                            !types.isSameType(member.erasure(types), m.erasure(types))) {
   20.80 +                        addOverrideBridges(pos, m, member, c, buf);
   20.81 +                    }
   20.82 +                }
   20.83 +            }
   20.84 +        return buf.toList();
   20.85 +    }
   20.86 +    // where
   20.87 +        class NeedsOverridBridgeFilter implements Filter<Symbol> {
   20.88 +
   20.89 +            ClassSymbol c;
   20.90 +
   20.91 +            NeedsOverridBridgeFilter(ClassSymbol c) {
   20.92 +                this.c = c;
   20.93 +            }
   20.94 +            public boolean accepts(Symbol s) {
   20.95 +                return s.kind == MTH &&
   20.96 +                            !s.isConstructor() &&
   20.97 +                            s.isInheritedIn(c, types) &&
   20.98 +                            (s.flags() & FINAL) == 0 &&
   20.99 +                            (s.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC;
  20.100 +            }
  20.101 +        }
  20.102 +
  20.103 +    private void addOverrideBridges(DiagnosticPosition pos,
  20.104 +                                    MethodSymbol impl,
  20.105 +                                    MethodSymbol member,
  20.106 +                                    ClassSymbol c,
  20.107 +                                    ListBuffer<JCTree> bridges) {
  20.108 +        Type implErasure = impl.erasure(types);
  20.109 +        long flags = (impl.flags() & AccessFlags) | SYNTHETIC | BRIDGE | OVERRIDE_BRIDGE;
  20.110 +        member = new MethodSymbol(flags, member.name, member.type, c);
  20.111 +        JCMethodDecl md = make.MethodDef(member, null);
  20.112 +        JCExpression receiver = make.Super(types.supertype(c.type).tsym.erasure(types), c);
  20.113 +        Type calltype = erasure(impl.type.getReturnType());
  20.114 +        JCExpression call =
  20.115 +            make.Apply(null,
  20.116 +                       make.Select(receiver, impl).setType(calltype),
  20.117 +                       translateArgs(make.Idents(md.params),
  20.118 +                                     implErasure.getParameterTypes(), null))
  20.119 +            .setType(calltype);
  20.120 +        JCStatement stat = (member.getReturnType().tag == VOID)
  20.121 +            ? make.Exec(call)
  20.122 +            : make.Return(coerce(call, member.erasure(types).getReturnType()));
  20.123 +        md.body = make.Block(0, List.of(stat));
  20.124 +        c.members().enter(member);
  20.125 +        bridges.append(md);
  20.126 +    }
  20.127 +
  20.128  /**************************************************************************
  20.129   * main method
  20.130   *************************************************************************/
  20.131 @@ -786,6 +876,7 @@
  20.132                  make.at(tree.pos);
  20.133                  if (addBridges) {
  20.134                      ListBuffer<JCTree> bridges = new ListBuffer<JCTree>();
  20.135 +                    bridges.appendList(addOverrideBridgesIfNeeded(tree, c));
  20.136                      if ((tree.sym.flags() & INTERFACE) == 0)
  20.137                          addBridges(tree.pos(), tree.sym, bridges);
  20.138                      tree.defs = bridges.toList().prependList(tree.defs);
    21.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Sep 07 15:14:49 2010 -0700
    21.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Sep 07 15:49:48 2010 -0700
    21.3 @@ -1098,12 +1098,6 @@
    21.4                  }
    21.5              },
    21.6  
    21.7 -            new AttributeReader(names.PolymorphicSignature, V45_3/*S.B.V51*/, CLASS_OR_MEMBER_ATTRIBUTE) {
    21.8 -                void read(Symbol sym, int attrLen) {
    21.9 -                    sym.flags_field |= POLYMORPHIC_SIGNATURE;
   21.10 -                }
   21.11 -            },
   21.12 -
   21.13  
   21.14              // The following attributes for a Code attribute are not currently handled
   21.15              // StackMapTable
   21.16 @@ -1289,6 +1283,9 @@
   21.17                      sym.flags_field |= PROPRIETARY;
   21.18                  else
   21.19                      proxies.append(proxy);
   21.20 +                if (majorVersion >= V51.major && proxy.type.tsym == syms.polymorphicSignatureType.tsym) {
   21.21 +                    sym.flags_field |= POLYMORPHIC_SIGNATURE;
   21.22 +                }
   21.23              }
   21.24              annotate.later(new AnnotationCompleter(sym, proxies.toList()));
   21.25          }
    22.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue Sep 07 15:14:49 2010 -0700
    22.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue Sep 07 15:49:48 2010 -0700
    22.3 @@ -34,6 +34,7 @@
    22.4  import javax.tools.JavaFileObject;
    22.5  
    22.6  import com.sun.tools.javac.code.*;
    22.7 +import com.sun.tools.javac.code.Attribute.RetentionPolicy;
    22.8  import com.sun.tools.javac.code.Symbol.*;
    22.9  import com.sun.tools.javac.code.Type.*;
   22.10  import com.sun.tools.javac.file.BaseFileObject;
   22.11 @@ -651,13 +652,6 @@
   22.12              endAttr(alenIdx);
   22.13              acount++;
   22.14          }
   22.15 -        if ((flags & POLYMORPHIC_SIGNATURE) != 0) {
   22.16 -            if (target.majorVersion < 51)
   22.17 -                throw new AssertionError("PolymorphicSignature attributes in java/dyn must be written with -target 7 (required major version is 51, current is"+target.majorVersion+")");
   22.18 -            int alenIdx = writeAttr(names.PolymorphicSignature);
   22.19 -            endAttr(alenIdx);
   22.20 -            acount++;
   22.21 -        }
   22.22          return acount;
   22.23      }
   22.24  
   22.25 @@ -692,7 +686,7 @@
   22.26          boolean hasInvisible = false;
   22.27          if (m.params != null) for (VarSymbol s : m.params) {
   22.28              for (Attribute.Compound a : s.getAnnotationMirrors()) {
   22.29 -                switch (getRetention(a.type.tsym)) {
   22.30 +                switch (types.getRetention(a)) {
   22.31                  case SOURCE: break;
   22.32                  case CLASS: hasInvisible = true; break;
   22.33                  case RUNTIME: hasVisible = true; break;
   22.34 @@ -708,7 +702,7 @@
   22.35              for (VarSymbol s : m.params) {
   22.36                  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
   22.37                  for (Attribute.Compound a : s.getAnnotationMirrors())
   22.38 -                    if (getRetention(a.type.tsym) == RetentionPolicy.RUNTIME)
   22.39 +                    if (types.getRetention(a) == RetentionPolicy.RUNTIME)
   22.40                          buf.append(a);
   22.41                  databuf.appendChar(buf.length());
   22.42                  for (Attribute.Compound a : buf)
   22.43 @@ -723,7 +717,7 @@
   22.44              for (VarSymbol s : m.params) {
   22.45                  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
   22.46                  for (Attribute.Compound a : s.getAnnotationMirrors())
   22.47 -                    if (getRetention(a.type.tsym) == RetentionPolicy.CLASS)
   22.48 +                    if (types.getRetention(a) == RetentionPolicy.CLASS)
   22.49                          buf.append(a);
   22.50                  databuf.appendChar(buf.length());
   22.51                  for (Attribute.Compound a : buf)
   22.52 @@ -747,7 +741,7 @@
   22.53          ListBuffer<Attribute.Compound> visibles = new ListBuffer<Attribute.Compound>();
   22.54          ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>();
   22.55          for (Attribute.Compound a : attrs) {
   22.56 -            switch (getRetention(a.type.tsym)) {
   22.57 +            switch (types.getRetention(a)) {
   22.58              case SOURCE: break;
   22.59              case CLASS: invisibles.append(a); break;
   22.60              case RUNTIME: visibles.append(a); break;
   22.61 @@ -785,7 +779,7 @@
   22.62              if (tc.position.type == TargetType.UNKNOWN
   22.63                  || !tc.position.emitToClassfile())
   22.64                  continue;
   22.65 -            switch (getRetention(tc.type.tsym)) {
   22.66 +            switch (types.getRetention(tc)) {
   22.67              case SOURCE: break;
   22.68              case CLASS: invisibles.append(tc); break;
   22.69              case RUNTIME: visibles.append(tc); break;
   22.70 @@ -815,29 +809,6 @@
   22.71          return attrCount;
   22.72      }
   22.73  
   22.74 -    /** A mirror of java.lang.annotation.RetentionPolicy. */
   22.75 -    enum RetentionPolicy {
   22.76 -        SOURCE,
   22.77 -        CLASS,
   22.78 -        RUNTIME
   22.79 -    }
   22.80 -
   22.81 -    RetentionPolicy getRetention(TypeSymbol annotationType) {
   22.82 -        RetentionPolicy vis = RetentionPolicy.CLASS; // the default
   22.83 -        Attribute.Compound c = annotationType.attribute(syms.retentionType.tsym);
   22.84 -        if (c != null) {
   22.85 -            Attribute value = c.member(names.value);
   22.86 -            if (value != null && value instanceof Attribute.Enum) {
   22.87 -                Name levelName = ((Attribute.Enum)value).value.name;
   22.88 -                if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE;
   22.89 -                else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS;
   22.90 -                else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME;
   22.91 -                else ;// /* fail soft */ throw new AssertionError(levelName);
   22.92 -            }
   22.93 -        }
   22.94 -        return vis;
   22.95 -    }
   22.96 -
   22.97      /** A visitor to write an attribute including its leading
   22.98       *  single-character marker.
   22.99       */
    23.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Target.java	Tue Sep 07 15:14:49 2010 -0700
    23.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Target.java	Tue Sep 07 15:49:48 2010 -0700
    23.3 @@ -259,6 +259,14 @@
    23.4          return compareTo(JDK1_7) >= 0;
    23.5      }
    23.6  
    23.7 +    /** Does the VM support polymorphic method handle invocation?
    23.8 +     *  Affects the linkage information output to the classfile.
    23.9 +     *  An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together.
   23.10 +     */
   23.11 +    public boolean hasMethodHandles() {
   23.12 +        return hasInvokedynamic();
   23.13 +    }
   23.14 +
   23.15      /** Although we may not have support for class literals, should we
   23.16       *  avoid initializing the class that the literal refers to?
   23.17       *  See 4468823
    24.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Sep 07 15:14:49 2010 -0700
    24.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Sep 07 15:49:48 2010 -0700
    24.3 @@ -59,6 +59,7 @@
    24.4  import javax.annotation.processing.Processor;
    24.5  
    24.6  import static javax.tools.StandardLocation.CLASS_OUTPUT;
    24.7 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
    24.8  import static com.sun.tools.javac.util.ListBuffer.lb;
    24.9  
   24.10  // TEMP, until we have a more efficient way to save doc comment info
   24.11 @@ -579,10 +580,8 @@
   24.12                  TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
   24.13                  taskListener.started(e);
   24.14              }
   24.15 -            int initialErrorCount = log.nerrors;
   24.16              Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
   24.17              tree = parser.parseCompilationUnit();
   24.18 -            log.unrecoverableError |= (log.nerrors > initialErrorCount);
   24.19              if (verbose) {
   24.20                  printVerbose("parsing.done", Long.toString(elapsed(msec)));
   24.21              }
   24.22 @@ -608,7 +607,7 @@
   24.23       *  @param filename     The name of the file to be parsed.
   24.24       */
   24.25      @Deprecated
   24.26 -    public JCTree.JCCompilationUnit parse(String filename) throws IOException {
   24.27 +    public JCTree.JCCompilationUnit parse(String filename) {
   24.28          JavacFileManager fm = (JavacFileManager)fileManager;
   24.29          return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next());
   24.30      }
   24.31 @@ -778,7 +777,6 @@
   24.32      public void compile(List<JavaFileObject> sourceFileObjects,
   24.33                          List<String> classnames,
   24.34                          Iterable<? extends Processor> processors)
   24.35 -        throws IOException // TODO: temp, from JavacProcessingEnvironment
   24.36      {
   24.37          if (processors != null && processors.iterator().hasNext())
   24.38              explicitAnnotationProcessingRequested = true;
   24.39 @@ -868,7 +866,7 @@
   24.40      /**
   24.41       * Parses a list of files.
   24.42       */
   24.43 -   public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) throws IOException {
   24.44 +   public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
   24.45         if (shouldStop(CompileState.PARSE))
   24.46             return List.nil();
   24.47  
   24.48 @@ -916,6 +914,15 @@
   24.49              }
   24.50              rootClasses = cdefs.toList();
   24.51          }
   24.52 +
   24.53 +        // Ensure the input files have been recorded. Although this is normally
   24.54 +        // done by readSource, it may not have been done if the trees were read
   24.55 +        // in a prior round of annotation processing, and the trees have been
   24.56 +        // cleaned and are being reused.
   24.57 +        for (JCCompilationUnit unit : roots) {
   24.58 +            inputFiles.add(unit.sourcefile);
   24.59 +        }
   24.60 +
   24.61          return roots;
   24.62      }
   24.63  
   24.64 @@ -941,8 +948,7 @@
   24.65       * @param processors user provided annotation processors to bypass
   24.66       * discovery, {@code null} means that no processors were provided
   24.67       */
   24.68 -    public void initProcessAnnotations(Iterable<? extends Processor> processors)
   24.69 -                throws IOException {
   24.70 +    public void initProcessAnnotations(Iterable<? extends Processor> processors) {
   24.71          // Process annotations if processing is not disabled and there
   24.72          // is at least one Processor available.
   24.73          Options options = Options.instance(context);
   24.74 @@ -960,8 +966,7 @@
   24.75                  keepComments = true;
   24.76                  if (taskListener != null)
   24.77                      taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
   24.78 -
   24.79 -
   24.80 +                log.deferDiagnostics = true;
   24.81              } else { // free resources
   24.82                  procEnvImpl.close();
   24.83              }
   24.84 @@ -969,8 +974,7 @@
   24.85      }
   24.86  
   24.87      // TODO: called by JavacTaskImpl
   24.88 -    public JavaCompiler processAnnotations(List<JCCompilationUnit> roots)
   24.89 -            throws IOException {
   24.90 +    public JavaCompiler processAnnotations(List<JCCompilationUnit> roots) {
   24.91          return processAnnotations(roots, List.<String>nil());
   24.92      }
   24.93  
   24.94 @@ -979,16 +983,23 @@
   24.95       * @param roots a list of compilation units
   24.96       * @return an instance of the compiler in which to complete the compilation
   24.97       */
   24.98 +    // Implementation note: when this method is called, log.deferredDiagnostics
   24.99 +    // will have been set true by initProcessAnnotations, meaning that any diagnostics
  24.100 +    // that are reported will go into the log.deferredDiagnostics queue.
  24.101 +    // By the time this method exits, log.deferDiagnostics must be set back to false,
  24.102 +    // and all deferredDiagnostics must have been handled: i.e. either reported
  24.103 +    // or determined to be transient, and therefore suppressed.
  24.104      public JavaCompiler processAnnotations(List<JCCompilationUnit> roots,
  24.105 -                                           List<String> classnames)
  24.106 -            throws IOException  { // TODO: see TEMP note in JavacProcessingEnvironment
  24.107 +                                           List<String> classnames) {
  24.108          if (shouldStop(CompileState.PROCESS)) {
  24.109              // Errors were encountered.
  24.110 -            // If log.unrecoverableError is set, the errors were parse errors
  24.111 +            // Unless all the errors are resolve errors, the errors were parse errors
  24.112              // or other errors during enter which cannot be fixed by running
  24.113              // any annotation processors.
  24.114 -            if (log.unrecoverableError)
  24.115 +            if (unrecoverableError()) {
  24.116 +                log.reportDeferredDiagnostics();
  24.117                  return this;
  24.118 +            }
  24.119          }
  24.120  
  24.121          // ASSERT: processAnnotations and procEnvImpl should have been set up by
  24.122 @@ -1010,6 +1021,7 @@
  24.123                  log.error("proc.no.explicit.annotation.processing.requested",
  24.124                            classnames);
  24.125              }
  24.126 +            log.reportDeferredDiagnostics();
  24.127              return this; // continue regular compilation
  24.128          }
  24.129  
  24.130 @@ -1022,6 +1034,7 @@
  24.131                  if (!explicitAnnotationProcessingRequested()) {
  24.132                      log.error("proc.no.explicit.annotation.processing.requested",
  24.133                                classnames);
  24.134 +                    log.reportDeferredDiagnostics();
  24.135                      return this; // TODO: Will this halt compilation?
  24.136                  } else {
  24.137                      boolean errors = false;
  24.138 @@ -1036,7 +1049,6 @@
  24.139                              if (sym.kind == Kinds.PCK)
  24.140                                  sym.complete();
  24.141                              if (sym.exists()) {
  24.142 -                                Name name = names.fromString(nameStr);
  24.143                                  if (sym.kind == Kinds.PCK)
  24.144                                      pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
  24.145                                  else
  24.146 @@ -1052,23 +1064,36 @@
  24.147                              continue;
  24.148                          }
  24.149                      }
  24.150 -                    if (errors)
  24.151 +                    if (errors) {
  24.152 +                        log.reportDeferredDiagnostics();
  24.153                          return this;
  24.154 +                    }
  24.155                  }
  24.156              }
  24.157              try {
  24.158                  JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols);
  24.159                  if (c != this)
  24.160                      annotationProcessingOccurred = c.annotationProcessingOccurred = true;
  24.161 +                // doProcessing will have handled deferred diagnostics
  24.162 +                assert c.log.deferDiagnostics == false;
  24.163 +                assert c.log.deferredDiagnostics.size() == 0;
  24.164                  return c;
  24.165              } finally {
  24.166                  procEnvImpl.close();
  24.167              }
  24.168          } catch (CompletionFailure ex) {
  24.169              log.error("cant.access", ex.sym, ex.getDetailValue());
  24.170 +            log.reportDeferredDiagnostics();
  24.171              return this;
  24.172 +        }
  24.173 +    }
  24.174  
  24.175 +    private boolean unrecoverableError() {
  24.176 +        for (JCDiagnostic d: log.deferredDiagnostics) {
  24.177 +            if (d.getKind() == JCDiagnostic.Kind.ERROR && !d.isFlagSet(RESOLVE_ERROR))
  24.178 +                return true;
  24.179          }
  24.180 +        return false;
  24.181      }
  24.182  
  24.183      boolean explicitAnnotationProcessingRequested() {
  24.184 @@ -1119,6 +1144,11 @@
  24.185                                    env.toplevel.sourcefile);
  24.186          try {
  24.187              attr.attribClass(env.tree.pos(), env.enclClass.sym);
  24.188 +            if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) {
  24.189 +                //if in fail-over mode, ensure that AST expression nodes
  24.190 +                //are correctly initialized (e.g. they have a type/symbol)
  24.191 +                attr.postAttr(env);
  24.192 +            }
  24.193              compileStates.put(env, CompileState.ATTR);
  24.194          }
  24.195          finally {
    25.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java	Tue Sep 07 15:14:49 2010 -0700
    25.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Tue Sep 07 15:49:48 2010 -0700
    25.3 @@ -282,6 +282,13 @@
    25.4              }
    25.5          }
    25.6  
    25.7 +        // phase this out with JSR 292 PFD
    25.8 +        if ("no".equals(options.get("allowTransitionalJSR292"))) {
    25.9 +            options.put("allowTransitionalJSR292", null);
   25.10 +        } else if (target.hasInvokedynamic() && options.get("allowTransitionalJSR292") == null) {
   25.11 +            options.put("allowTransitionalJSR292", "allowTransitionalJSR292");
   25.12 +        }
   25.13 +
   25.14          // handle this here so it works even if no other options given
   25.15          String showClass = options.get("showClass");
   25.16          if (showClass != null) {
   25.17 @@ -467,10 +474,13 @@
   25.18          ex.printStackTrace(out);
   25.19      }
   25.20  
   25.21 -    /** Print a message reporting an fatal error.
   25.22 +    /** Print a message reporting a fatal error.
   25.23       */
   25.24      void feMessage(Throwable ex) {
   25.25          Log.printLines(out, ex.getMessage());
   25.26 +        if (ex.getCause() != null && options.get("dev") != null) {
   25.27 +            ex.getCause().printStackTrace(out);
   25.28 +        }
   25.29      }
   25.30  
   25.31      /** Print a message reporting an input/output error.
    26.1 --- a/src/share/classes/com/sun/tools/javac/main/OptionName.java	Tue Sep 07 15:14:49 2010 -0700
    26.2 +++ b/src/share/classes/com/sun/tools/javac/main/OptionName.java	Tue Sep 07 15:49:48 2010 -0700
    26.3 @@ -80,6 +80,7 @@
    26.4      XMAXERRS("-Xmaxerrs"),
    26.5      XMAXWARNS("-Xmaxwarns"),
    26.6      XSTDOUT("-Xstdout"),
    26.7 +    XPKGINFO("-Xpkginfo:"),
    26.8      XPRINT("-Xprint"),
    26.9      XPRINTROUNDS("-XprintRounds"),
   26.10      XPRINTPROCESSORINFO("-XprintProcessorInfo"),
    27.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Tue Sep 07 15:14:49 2010 -0700
    27.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Tue Sep 07 15:49:48 2010 -0700
    27.3 @@ -160,6 +160,7 @@
    27.4          XMAXERRS,
    27.5          XMAXWARNS,
    27.6          XSTDOUT,
    27.7 +        XPKGINFO,
    27.8          XPRINT,
    27.9          XPRINTROUNDS,
   27.10          XPRINTPROCESSORINFO,
   27.11 @@ -217,6 +218,7 @@
   27.12          XMAXERRS,
   27.13          XMAXWARNS,
   27.14          // XSTDOUT,
   27.15 +        XPKGINFO,
   27.16          XPRINT,
   27.17          XPRINTROUNDS,
   27.18          XPRINTPROCESSORINFO,
   27.19 @@ -532,6 +534,9 @@
   27.20          new XOption(XPREFER,                                    "opt.prefer",
   27.21                  Option.ChoiceKind.ONEOF, "source", "newer"),
   27.22  
   27.23 +        new XOption(XPKGINFO,                                   "opt.pkginfo",
   27.24 +                Option.ChoiceKind.ONEOF, "always", "legacy", "nonempty"),
   27.25 +
   27.26          /* -O is a no-op, accepted for backward compatibility. */
   27.27          new HiddenOption(O),
   27.28  
   27.29 @@ -598,6 +603,16 @@
   27.30      };
   27.31      }
   27.32  
   27.33 +    public enum PkgInfo {
   27.34 +        ALWAYS, LEGACY, NONEMPTY;
   27.35 +        public static PkgInfo get(Options options) {
   27.36 +            String v = options.get(XPKGINFO);
   27.37 +            return (v == null
   27.38 +                    ? PkgInfo.LEGACY
   27.39 +                    : PkgInfo.valueOf(v.toUpperCase()));
   27.40 +        }
   27.41 +    }
   27.42 +
   27.43      private static Map<String,Boolean> getXLintChoices() {
   27.44          Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>();
   27.45          choices.put("all", false);
    28.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java	Tue Sep 07 15:14:49 2010 -0700
    28.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java	Tue Sep 07 15:49:48 2010 -0700
    28.3 @@ -103,7 +103,7 @@
    28.4      public boolean contains(TypeMirror t1, TypeMirror t2) {
    28.5          validateTypeNotIn(t1, EXEC_OR_PKG);
    28.6          validateTypeNotIn(t2, EXEC_OR_PKG);
    28.7 -        return ((Type) t1).contains((Type) t2);
    28.8 +        return types.containsType((Type) t1, (Type) t2);
    28.9      }
   28.10  
   28.11      public boolean isSubsignature(ExecutableType m1, ExecutableType m2) {
    29.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Sep 07 15:14:49 2010 -0700
    29.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Sep 07 15:49:48 2010 -0700
    29.3 @@ -2781,7 +2781,7 @@
    29.4      List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) {
    29.5          if (S.token() == SEMI) {
    29.6              S.nextToken();
    29.7 -            return List.<JCTree>of(F.at(Position.NOPOS).Block(0, List.<JCStatement>nil()));
    29.8 +            return List.<JCTree>nil();
    29.9          } else {
   29.10              String dc = S.docComment();
   29.11              int pos = S.pos();
    30.1 --- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java	Tue Sep 07 15:14:49 2010 -0700
    30.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java	Tue Sep 07 15:49:48 2010 -0700
    30.3 @@ -108,6 +108,10 @@
    30.4       */
    30.5      private boolean allowUnderscoresInLiterals;
    30.6  
    30.7 +    /** Allow exotic identifiers.
    30.8 +     */
    30.9 +    private boolean allowExoticIdentifiers;
   30.10 +
   30.11      /** The source language setting.
   30.12       */
   30.13      private Source source;
   30.14 @@ -181,6 +185,7 @@
   30.15          allowBinaryLiterals = source.allowBinaryLiterals();
   30.16          allowHexFloats = source.allowHexFloats();
   30.17          allowUnderscoresInLiterals = source.allowBinaryLiterals();
   30.18 +        allowExoticIdentifiers = source.allowExoticIdentifiers();  // for invokedynamic
   30.19      }
   30.20  
   30.21      private static final boolean hexFloatsWork = hexFloatsWork();
   30.22 @@ -1010,6 +1015,10 @@
   30.23                  case '#':
   30.24                      scanChar();
   30.25                      if (ch == '\"') {
   30.26 +                        if (!allowExoticIdentifiers) {
   30.27 +                            lexError("unsupported.exotic.id", source.name);
   30.28 +                            allowExoticIdentifiers = true;
   30.29 +                        }
   30.30                          scanChar();
   30.31                          if (ch == '\"')
   30.32                              lexError(pos, "empty.bytecode.ident");
    31.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java	Tue Sep 07 15:14:49 2010 -0700
    31.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java	Tue Sep 07 15:49:48 2010 -0700
    31.3 @@ -34,6 +34,7 @@
    31.4  import java.util.*;
    31.5  
    31.6  import java.io.Closeable;
    31.7 +import java.io.FileNotFoundException;
    31.8  import java.io.InputStream;
    31.9  import java.io.OutputStream;
   31.10  import java.io.FilterOutputStream;
   31.11 @@ -450,10 +451,15 @@
   31.12          // TODO: Only support reading resources in selected output
   31.13          // locations?  Only allow reading of non-source, non-class
   31.14          // files from the supported input locations?
   31.15 -        FileObject fileObject = fileManager.getFileForOutput(location,
   31.16 -                                                             pkg.toString(),
   31.17 -                                                             relativeName.toString(),
   31.18 -                                                             null);
   31.19 +        FileObject fileObject = fileManager.getFileForInput(location,
   31.20 +                    pkg.toString(),
   31.21 +                    relativeName.toString());
   31.22 +        if (fileObject == null) {
   31.23 +            String name = (pkg.length() == 0)
   31.24 +                    ? relativeName.toString() : (pkg + "/" + relativeName);
   31.25 +            throw new FileNotFoundException(name);
   31.26 +        }
   31.27 +
   31.28          // If the path was already opened for writing, throw an exception.
   31.29          checkFileReopening(fileObject, false);
   31.30          return new FilerInputFileObject(fileObject);
    32.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Tue Sep 07 15:14:49 2010 -0700
    32.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Tue Sep 07 15:49:48 2010 -0700
    32.3 @@ -67,6 +67,8 @@
    32.4  import com.sun.tools.javac.util.Abort;
    32.5  import com.sun.tools.javac.util.Context;
    32.6  import com.sun.tools.javac.util.Convert;
    32.7 +import com.sun.tools.javac.util.FatalError;
    32.8 +import com.sun.tools.javac.util.JCDiagnostic;
    32.9  import com.sun.tools.javac.util.List;
   32.10  import com.sun.tools.javac.util.Log;
   32.11  import com.sun.tools.javac.util.JavacMessages;
   32.12 @@ -75,6 +77,7 @@
   32.13  import com.sun.tools.javac.util.Options;
   32.14  
   32.15  import static javax.tools.StandardLocation.*;
   32.16 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
   32.17  
   32.18  /**
   32.19   * Objects of this class hold and manage the state needed to support
   32.20 @@ -95,6 +98,7 @@
   32.21      private final boolean procOnly;
   32.22      private final boolean fatalErrors;
   32.23      private final boolean werror;
   32.24 +    private final boolean showResolveErrors;
   32.25      private boolean foundTypeProcessors;
   32.26  
   32.27      private final JavacFiler filer;
   32.28 @@ -131,6 +135,10 @@
   32.29       */
   32.30      Log log;
   32.31  
   32.32 +    /** Diagnostic factory.
   32.33 +     */
   32.34 +    JCDiagnostic.Factory diags;
   32.35 +
   32.36      /**
   32.37       * Source level of the compile.
   32.38       */
   32.39 @@ -146,10 +154,11 @@
   32.40      private Context context;
   32.41  
   32.42      public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
   32.43 -        options = Options.instance(context);
   32.44          this.context = context;
   32.45          log = Log.instance(context);
   32.46          source = Source.instance(context);
   32.47 +        diags = JCDiagnostic.Factory.instance(context);
   32.48 +        options = Options.instance(context);
   32.49          printProcessorInfo = options.get("-XprintProcessorInfo") != null;
   32.50          printRounds = options.get("-XprintRounds") != null;
   32.51          verbose = options.get("-verbose") != null;
   32.52 @@ -157,6 +166,7 @@
   32.53          procOnly = options.get("-proc:only") != null ||
   32.54              options.get("-Xprint") != null;
   32.55          fatalErrors = options.get("fatalEnterError") != null;
   32.56 +        showResolveErrors = options.get("showResolveErrors") != null;
   32.57          werror = options.get("-Werror") != null;
   32.58          platformAnnotations = initPlatformAnnotations();
   32.59          foundTypeProcessors = false;
   32.60 @@ -818,6 +828,7 @@
   32.61  
   32.62              compiler = JavaCompiler.instance(context);
   32.63              log = Log.instance(context);
   32.64 +            log.deferDiagnostics = true;
   32.65  
   32.66              // the following is for the benefit of JavacProcessingEnvironment.getContext()
   32.67              JavacProcessingEnvironment.this.context = context;
   32.68 @@ -848,8 +859,7 @@
   32.69  
   32.70          /** Create a new round. */
   32.71          private Round(Round prev,
   32.72 -                Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles)
   32.73 -                throws IOException {
   32.74 +                Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) {
   32.75              this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings);
   32.76              this.genClassFiles = prev.genClassFiles;
   32.77  
   32.78 @@ -882,8 +892,7 @@
   32.79          }
   32.80  
   32.81          /** Create the next round to be used. */
   32.82 -        Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles)
   32.83 -                throws IOException {
   32.84 +        Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) {
   32.85              try {
   32.86                  return new Round(this, newSourceFiles, newClassFiles);
   32.87              } finally {
   32.88 @@ -919,10 +928,24 @@
   32.89  
   32.90          /** Return whether or not an unrecoverable error has occurred. */
   32.91          boolean unrecoverableError() {
   32.92 -            return log.unrecoverableError
   32.93 -                    || messager.errorRaised()
   32.94 -                    || (werror && log.nwarnings > 0)
   32.95 -                    || (fatalErrors && log.nerrors > 0);
   32.96 +            if (messager.errorRaised())
   32.97 +                return true;
   32.98 +
   32.99 +            for (JCDiagnostic d: log.deferredDiagnostics) {
  32.100 +                switch (d.getKind()) {
  32.101 +                    case WARNING:
  32.102 +                        if (werror)
  32.103 +                            return true;
  32.104 +                        break;
  32.105 +
  32.106 +                    case ERROR:
  32.107 +                        if (fatalErrors || !d.isFlagSet(RESOLVE_ERROR))
  32.108 +                            return true;
  32.109 +                        break;
  32.110 +                }
  32.111 +            }
  32.112 +
  32.113 +            return false;
  32.114          }
  32.115  
  32.116          /** Find the set of annotations present in the set of top level
  32.117 @@ -938,7 +961,7 @@
  32.118          }
  32.119  
  32.120          /** Enter a set of generated class files. */
  32.121 -        List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
  32.122 +        private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
  32.123              ClassReader reader = ClassReader.instance(context);
  32.124              Names names = Names.instance(context);
  32.125              List<ClassSymbol> list = List.nil();
  32.126 @@ -965,7 +988,7 @@
  32.127          }
  32.128  
  32.129          /** Enter a set of syntax trees. */
  32.130 -        void enterTrees(List<JCCompilationUnit> roots) {
  32.131 +        private void enterTrees(List<JCCompilationUnit> roots) {
  32.132              compiler.enterTrees(roots);
  32.133          }
  32.134  
  32.135 @@ -995,6 +1018,15 @@
  32.136              }
  32.137          }
  32.138  
  32.139 +        void showDiagnostics(boolean showAll) {
  32.140 +            Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class);
  32.141 +            if (!showAll) {
  32.142 +                // suppress errors, which are all presumed to be transient resolve errors
  32.143 +                kinds.remove(JCDiagnostic.Kind.ERROR);
  32.144 +            }
  32.145 +            log.reportDeferredDiagnostics(kinds);
  32.146 +        }
  32.147 +
  32.148          /** Update the processing state for the current context. */
  32.149          private void updateProcessingState() {
  32.150              filer.newRound(context);
  32.151 @@ -1083,8 +1115,7 @@
  32.152      public JavaCompiler doProcessing(Context context,
  32.153                                       List<JCCompilationUnit> roots,
  32.154                                       List<ClassSymbol> classSymbols,
  32.155 -                                     Iterable<? extends PackageSymbol> pckSymbols)
  32.156 -        throws IOException {
  32.157 +                                     Iterable<? extends PackageSymbol> pckSymbols) {
  32.158  
  32.159          TaskListener taskListener = context.get(TaskListener.class);
  32.160          log = Log.instance(context);
  32.161 @@ -1107,6 +1138,8 @@
  32.162              errorStatus = round.unrecoverableError();
  32.163              moreToDo = moreToDo();
  32.164  
  32.165 +            round.showDiagnostics(errorStatus || showResolveErrors);
  32.166 +
  32.167              // Set up next round.
  32.168              // Copy mutable collections returned from filer.
  32.169              round = round.next(
  32.170 @@ -1121,6 +1154,7 @@
  32.171  
  32.172          // run last round
  32.173          round.run(true, errorStatus);
  32.174 +        round.showDiagnostics(true);
  32.175  
  32.176          filer.warnIfUnclosedFiles();
  32.177          warnIfUnmatchedOptions();
  32.178 @@ -1184,13 +1218,19 @@
  32.179      /**
  32.180       * Free resources related to annotation processing.
  32.181       */
  32.182 -    public void close() throws IOException {
  32.183 +    public void close() {
  32.184          filer.close();
  32.185          if (discoveredProcs != null) // Make calling close idempotent
  32.186              discoveredProcs.close();
  32.187          discoveredProcs = null;
  32.188 -        if (processorClassLoader != null && processorClassLoader instanceof Closeable)
  32.189 -            ((Closeable) processorClassLoader).close();
  32.190 +        if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
  32.191 +            try {
  32.192 +                ((Closeable) processorClassLoader).close();
  32.193 +            } catch (IOException e) {
  32.194 +                JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader");
  32.195 +                throw new FatalError(msg, e);
  32.196 +            }
  32.197 +        }
  32.198      }
  32.199  
  32.200      private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
    33.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Sep 07 15:14:49 2010 -0700
    33.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Sep 07 15:49:48 2010 -0700
    33.3 @@ -128,6 +128,11 @@
    33.4  compiler.err.no.superclass=\
    33.5      {0} has no superclass
    33.6  
    33.7 +compiler.warn.type.parameter.on.polymorphic.signature=\
    33.8 +    change obsolete notation for MethodHandle invocations from x.<T>invoke(y) to (T)x.invoke(y)
    33.9 +compiler.warn.wrong.target.for.polymorphic.signature.definition=\
   33.10 +    MethodHandle API building requires -target 7 runtimes or better; current is -target {0}
   33.11 +
   33.12  compiler.err.concrete.inheritance.conflict=\
   33.13      methods {0} from {1} and {2} from {3} are inherited with the same signature
   33.14  
   33.15 @@ -550,6 +555,8 @@
   33.16      Fatal Error: Unable to find field {0}
   33.17  compiler.misc.fatal.err.cant.locate.ctor=\
   33.18      Fatal Error: Unable to find constructor for {0}
   33.19 +compiler.misc.fatal.err.cant.close.loader=\
   33.20 +    Fatal Error: Cannot close class loader for annotation processors
   33.21  
   33.22  #####
   33.23  
   33.24 @@ -1240,6 +1247,10 @@
   33.25      underscores in literals are not supported in -source {0}\n\
   33.26  (use -source 7 or higher to enable underscores in literals)
   33.27  
   33.28 +compiler.err.unsupported.exotic.id=\
   33.29 +    exotic identifiers #"___" are not supported in -source {0}\n\
   33.30 +(use -source 7 or higher to enable exotic identifiers)
   33.31 +
   33.32  compiler.err.automatic.resource.management.not.supported.in.source=\
   33.33      automatic resource management is not supported in -source {0}\n\
   33.34  (use -source 7 or higher to enable automatic resource management)
    34.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties	Tue Sep 07 15:14:49 2010 -0700
    34.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties	Tue Sep 07 15:49:48 2010 -0700
    34.3 @@ -74,7 +74,9 @@
    34.4  javac.opt.A=\
    34.5      Options to pass to annotation processors
    34.6  javac.opt.implicit=\
    34.7 -    Specify whether or not to generate class files for implicitly referenced files 
    34.8 +    Specify whether or not to generate class files for implicitly referenced files
    34.9 +javac.opt.pkginfo=\
   34.10 +    Specify handling of package-info files
   34.11  javac.opt.arg.class=\
   34.12      <class>
   34.13  javac.opt.arg.class.list=\
   34.14 @@ -189,7 +191,7 @@
   34.15  
   34.16  javac.msg.usage.nonstandard.footer=\
   34.17  These options are non-standard and subject to change without notice.
   34.18 -	
   34.19 +
   34.20  javac.msg.bug=\
   34.21  An exception has occurred in the compiler ({0}). \
   34.22  Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  \
    35.1 --- a/src/share/classes/com/sun/tools/javac/resources/legacy.properties	Tue Sep 07 15:14:49 2010 -0700
    35.2 +++ b/src/share/classes/com/sun/tools/javac/resources/legacy.properties	Tue Sep 07 15:49:48 2010 -0700
    35.3 @@ -565,6 +565,7 @@
    35.4  sun.tools.jar.resources = tiger legacy
    35.5  sun.util = tiger legacy
    35.6  sun.util.calendar = tiger legacy
    35.7 +sun.util.locale = tiger legacy
    35.8  sun.util.logging.resources = tiger legacy
    35.9  sunw.io = tiger legacy
   35.10  sunw.util = tiger legacy
    36.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Sep 07 15:14:49 2010 -0700
    36.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Sep 07 15:49:48 2010 -0700
    36.3 @@ -340,6 +340,7 @@
    36.4      public abstract int getTag();
    36.5  
    36.6      /** Convert a tree to a pretty-printed string. */
    36.7 +    @Override
    36.8      public String toString() {
    36.9          StringWriter s = new StringWriter();
   36.10          try {
   36.11 @@ -375,6 +376,7 @@
   36.12  
   36.13      /** Return a shallow copy of this tree.
   36.14       */
   36.15 +    @Override
   36.16      public Object clone() {
   36.17          try {
   36.18              return super.clone();
   36.19 @@ -587,7 +589,17 @@
   36.20          @Override
   36.21          public void accept(Visitor v) { v.visitClassDef(this); }
   36.22  
   36.23 -        public Kind getKind() { return Kind.CLASS; }
   36.24 +        public Kind getKind() {
   36.25 +            if ((mods.flags & Flags.ANNOTATION) != 0)
   36.26 +                return Kind.ANNOTATION_TYPE;
   36.27 +            else if ((mods.flags & Flags.INTERFACE) != 0)
   36.28 +                return Kind.INTERFACE;
   36.29 +            else if ((mods.flags & Flags.ENUM) != 0)
   36.30 +                return Kind.ENUM;
   36.31 +            else
   36.32 +                return Kind.CLASS;
   36.33 +        }
   36.34 +
   36.35          public JCModifiers getModifiers() { return mods; }
   36.36          public Name getSimpleName() { return name; }
   36.37          public List<JCTypeParameter> getTypeParameters() {
    37.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Tue Sep 07 15:14:49 2010 -0700
    37.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Tue Sep 07 15:49:48 2010 -0700
    37.3 @@ -501,6 +501,10 @@
    37.4                  if (that.sym == sym) result = that;
    37.5                  else super.visitVarDef(that);
    37.6              }
    37.7 +            public void visitTypeParameter(JCTypeParameter that) {
    37.8 +                if (that.type.tsym == sym) result = that;
    37.9 +                else super.visitTypeParameter(that);
   37.10 +            }
   37.11          }
   37.12          DeclScanner s = new DeclScanner();
   37.13          tree.accept(s);
   37.14 @@ -633,6 +637,18 @@
   37.15          }
   37.16      }
   37.17  
   37.18 +    public static boolean isDeclaration(JCTree node) {
   37.19 +        node = skipParens(node);
   37.20 +        switch (node.getTag()) {
   37.21 +        case JCTree.CLASSDEF:
   37.22 +        case JCTree.METHODDEF:
   37.23 +        case JCTree.VARDEF:
   37.24 +            return true;
   37.25 +        default:
   37.26 +            return false;
   37.27 +        }
   37.28 +    }
   37.29 +
   37.30      /** If this tree is an identifier or a field, return its symbol,
   37.31       *  otherwise return null.
   37.32       */
    38.1 --- a/src/share/classes/com/sun/tools/javac/util/FatalError.java	Tue Sep 07 15:14:49 2010 -0700
    38.2 +++ b/src/share/classes/com/sun/tools/javac/util/FatalError.java	Tue Sep 07 15:49:48 2010 -0700
    38.3 @@ -37,12 +37,6 @@
    38.4  public class FatalError extends Error {
    38.5      private static final long serialVersionUID = 0;
    38.6  
    38.7 -    /** Construct a <code>FatalError</code> with no detail message.
    38.8 -     */
    38.9 -    public FatalError() {
   38.10 -        super();
   38.11 -    }
   38.12 -
   38.13      /** Construct a <code>FatalError</code> with the specified detail message.
   38.14       *  @param d A diagnostic containing the reason for failure.
   38.15       */
   38.16 @@ -50,6 +44,15 @@
   38.17          super(d.toString());
   38.18      }
   38.19  
   38.20 +    /** Construct a <code>FatalError</code> with the specified detail message
   38.21 +     * and cause.
   38.22 +     *  @param d A diagnostic containing the reason for failure.
   38.23 +     *  @param t An exception causing the error
   38.24 +     */
   38.25 +    public FatalError(JCDiagnostic d, Throwable t) {
   38.26 +        super(d.toString(), t);
   38.27 +    }
   38.28 +
   38.29      /** Construct a <code>FatalError</code> with the specified detail message.
   38.30       *  @param s An English(!) string describing the failure, typically because
   38.31       *           the diagnostic resources are missing.
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/src/share/classes/com/sun/tools/javac/util/Filter.java	Tue Sep 07 15:49:48 2010 -0700
    39.3 @@ -0,0 +1,39 @@
    39.4 +/*
    39.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    39.7 + *
    39.8 + * This code is free software; you can redistribute it and/or modify it
    39.9 + * under the terms of the GNU General Public License version 2 only, as
   39.10 + * published by the Free Software Foundation.  Oracle designates this
   39.11 + * particular file as subject to the "Classpath" exception as provided
   39.12 + * by Oracle in the LICENSE file that accompanied this code.
   39.13 + *
   39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   39.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   39.17 + * version 2 for more details (a copy is included in the LICENSE file that
   39.18 + * accompanied this code).
   39.19 + *
   39.20 + * You should have received a copy of the GNU General Public License version
   39.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   39.23 + *
   39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   39.25 + * or visit www.oracle.com if you need additional information or have any
   39.26 + * questions.
   39.27 + */
   39.28 +
   39.29 +package com.sun.tools.javac.util;
   39.30 +
   39.31 +/**
   39.32 + * Simple filter acting as a boolean predicate. Method accepts return true if
   39.33 + * the supplied element matches against the filter.
   39.34 + */
   39.35 +public interface Filter<T> {
   39.36 +    /**
   39.37 +     * Does this element match against the filter?
   39.38 +     * @param t element to be checked
   39.39 +     * @return true if the element satisfy constraints imposed by filter
   39.40 +     */
   39.41 +    boolean accepts(T t);
   39.42 +}
    40.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Tue Sep 07 15:14:49 2010 -0700
    40.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Tue Sep 07 15:49:48 2010 -0700
    40.3 @@ -27,8 +27,10 @@
    40.4  
    40.5  import java.io.*;
    40.6  import java.util.Arrays;
    40.7 +import java.util.EnumSet;
    40.8  import java.util.HashSet;
    40.9  import java.util.Map;
   40.10 +import java.util.Queue;
   40.11  import java.util.Set;
   40.12  import javax.tools.DiagnosticListener;
   40.13  import javax.tools.JavaFileObject;
   40.14 @@ -110,6 +112,12 @@
   40.15       */
   40.16      private JavacMessages messages;
   40.17  
   40.18 +    /**
   40.19 +     * Deferred diagnostics
   40.20 +     */
   40.21 +    public boolean deferDiagnostics;
   40.22 +    public Queue<JCDiagnostic> deferredDiagnostics = new ListBuffer<JCDiagnostic>();
   40.23 +
   40.24      /** Construct a log with given I/O redirections.
   40.25       */
   40.26      @Deprecated
   40.27 @@ -204,12 +212,6 @@
   40.28       */
   40.29      public int nwarnings = 0;
   40.30  
   40.31 -    /**
   40.32 -     * Whether or not an unrecoverable error has been seen.
   40.33 -     * Unrecoverable errors prevent subsequent annotation processing.
   40.34 -     */
   40.35 -    public boolean unrecoverableError;
   40.36 -
   40.37      /** A set of all errors generated so far. This is used to avoid printing an
   40.38       *  error message more than once. For each error, a pair consisting of the
   40.39       *  source file name and source code position of the error is added to the set.
   40.40 @@ -347,12 +349,32 @@
   40.41          nwarnings++;
   40.42      }
   40.43  
   40.44 +    /** Report all deferred diagnostics, and clear the deferDiagnostics flag. */
   40.45 +    public void reportDeferredDiagnostics() {
   40.46 +        reportDeferredDiagnostics(EnumSet.allOf(JCDiagnostic.Kind.class));
   40.47 +    }
   40.48 +
   40.49 +    /** Report selected deferred diagnostics, and clear the deferDiagnostics flag. */
   40.50 +    public void reportDeferredDiagnostics(Set<JCDiagnostic.Kind> kinds) {
   40.51 +        deferDiagnostics = false;
   40.52 +        JCDiagnostic d;
   40.53 +        while ((d = deferredDiagnostics.poll()) != null) {
   40.54 +            if (kinds.contains(d.getKind()))
   40.55 +                report(d);
   40.56 +        }
   40.57 +    }
   40.58 +
   40.59      /**
   40.60       * Common diagnostic handling.
   40.61       * The diagnostic is counted, and depending on the options and how many diagnostics have been
   40.62       * reported so far, the diagnostic may be handed off to writeDiagnostic.
   40.63       */
   40.64      public void report(JCDiagnostic diagnostic) {
   40.65 +        if (deferDiagnostics) {
   40.66 +            deferredDiagnostics.add(diagnostic);
   40.67 +            return;
   40.68 +        }
   40.69 +
   40.70          if (expectDiagKeys != null)
   40.71              expectDiagKeys.remove(diagnostic.getCode());
   40.72  
    41.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java	Tue Sep 07 15:14:49 2010 -0700
    41.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Tue Sep 07 15:49:48 2010 -0700
    41.3 @@ -103,7 +103,6 @@
    41.4      public final Name RuntimeInvisibleTypeAnnotations;
    41.5      public final Name RuntimeVisibleParameterAnnotations;
    41.6      public final Name RuntimeInvisibleParameterAnnotations;
    41.7 -    public final Name PolymorphicSignature;
    41.8      public final Name Value;
    41.9      public final Name EnclosingMethod;
   41.10      public final Name desiredAssertionStatus;
   41.11 @@ -116,6 +115,7 @@
   41.12      public final Name value;
   41.13      public final Name getMessage;
   41.14      public final Name getClass;
   41.15 +    public final Name invoke;  //allowTransitionalJSR292 only
   41.16      public final Name TYPE;
   41.17      public final Name TYPE_USE;
   41.18      public final Name TYPE_PARAMETER;
   41.19 @@ -215,7 +215,6 @@
   41.20          RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
   41.21          RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
   41.22          RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
   41.23 -        PolymorphicSignature = fromString("PolymorphicSignature");
   41.24          Value = fromString("Value");
   41.25          EnclosingMethod = fromString("EnclosingMethod");
   41.26  
   41.27 @@ -230,6 +229,7 @@
   41.28          value = fromString("value");
   41.29          getMessage = fromString("getMessage");
   41.30          getClass = fromString("getClass");
   41.31 +        invoke = fromString("invoke");  //allowTransitionalJSR292 only
   41.32  
   41.33          TYPE = fromString("TYPE");
   41.34          TYPE_USE = fromString("TYPE_USE");
    42.1 --- a/src/share/classes/com/sun/tools/javap/CodeWriter.java	Tue Sep 07 15:14:49 2010 -0700
    42.2 +++ b/src/share/classes/com/sun/tools/javap/CodeWriter.java	Tue Sep 07 15:49:48 2010 -0700
    42.3 @@ -239,7 +239,10 @@
    42.4                  new ArrayList<InstructionDetailWriter>();
    42.5          if (options.details.contains(InstructionDetailWriter.Kind.SOURCE)) {
    42.6              sourceWriter.reset(classWriter.getClassFile(), attr);
    42.7 -            detailWriters.add(sourceWriter);
    42.8 +            if (sourceWriter.hasSource())
    42.9 +                detailWriters.add(sourceWriter);
   42.10 +            else
   42.11 +                println("(Source code not available)");
   42.12          }
   42.13  
   42.14          if (options.details.contains(InstructionDetailWriter.Kind.LOCAL_VARS)) {
    43.1 --- a/src/share/classes/com/sun/tools/javap/SourceWriter.java	Tue Sep 07 15:14:49 2010 -0700
    43.2 +++ b/src/share/classes/com/sun/tools/javap/SourceWriter.java	Tue Sep 07 15:49:48 2010 -0700
    43.3 @@ -99,7 +99,10 @@
    43.4                  }
    43.5              }
    43.6          }
    43.7 +    }
    43.8  
    43.9 +    public boolean hasSource() {
   43.10 +        return (sourceLines.length > 0);
   43.11      }
   43.12  
   43.13      private void setLineMap(Code_attribute attr) {
    44.1 --- a/src/share/classes/javax/tools/ToolProvider.java	Tue Sep 07 15:14:49 2010 -0700
    44.2 +++ b/src/share/classes/javax/tools/ToolProvider.java	Tue Sep 07 15:49:48 2010 -0700
    44.3 @@ -26,10 +26,14 @@
    44.4  package javax.tools;
    44.5  
    44.6  import java.io.File;
    44.7 +import java.lang.ref.Reference;
    44.8 +import java.lang.ref.WeakReference;
    44.9  import java.net.URL;
   44.10  import java.net.URLClassLoader;
   44.11  import java.net.MalformedURLException;
   44.12 +import java.util.HashMap;
   44.13  import java.util.Locale;
   44.14 +import java.util.Map;
   44.15  import java.util.logging.Logger;
   44.16  import java.util.logging.Level;
   44.17  import static java.util.logging.Level.*;
   44.18 @@ -44,8 +48,6 @@
   44.19   */
   44.20  public class ToolProvider {
   44.21  
   44.22 -    private ToolProvider() {}
   44.23 -
   44.24      private static final String propertyName = "sun.tools.ToolProvider";
   44.25      private static final String loggerName   = "javax.tools";
   44.26  
   44.27 @@ -87,6 +89,9 @@
   44.28          return null;
   44.29      }
   44.30  
   44.31 +    private static final String defaultJavaCompilerName
   44.32 +        = "com.sun.tools.javac.api.JavacTool";
   44.33 +
   44.34      /**
   44.35       * Gets the Java&trade; programming language compiler provided
   44.36       * with this platform.
   44.37 @@ -94,13 +99,7 @@
   44.38       * {@code null} if no compiler is provided
   44.39       */
   44.40      public static JavaCompiler getSystemJavaCompiler() {
   44.41 -        if (Lazy.compilerClass == null)
   44.42 -            return trace(WARNING, "Lazy.compilerClass == null");
   44.43 -        try {
   44.44 -            return Lazy.compilerClass.newInstance();
   44.45 -        } catch (Throwable e) {
   44.46 -            return trace(WARNING, e);
   44.47 -        }
   44.48 +        return instance().getSystemTool(JavaCompiler.class, defaultJavaCompilerName);
   44.49      }
   44.50  
   44.51      /**
   44.52 @@ -113,63 +112,109 @@
   44.53       * or {@code null} if no tools are provided
   44.54       */
   44.55      public static ClassLoader getSystemToolClassLoader() {
   44.56 -        if (Lazy.compilerClass == null)
   44.57 -            return trace(WARNING, "Lazy.compilerClass == null");
   44.58 -        return Lazy.compilerClass.getClassLoader();
   44.59 +        try {
   44.60 +            Class<? extends JavaCompiler> c =
   44.61 +                    instance().getSystemToolClass(JavaCompiler.class, defaultJavaCompilerName);
   44.62 +            return c.getClassLoader();
   44.63 +        } catch (Throwable e) {
   44.64 +            return trace(WARNING, e);
   44.65 +        }
   44.66      }
   44.67  
   44.68 -    /**
   44.69 -     * This class will not be initialized until one of the above
   44.70 -     * methods are called.  This ensures that searching for the
   44.71 -     * compiler does not affect platform start up.
   44.72 -     */
   44.73 -    static class Lazy  {
   44.74 -        private static final String defaultJavaCompilerName
   44.75 -            = "com.sun.tools.javac.api.JavacTool";
   44.76 -        private static final String[] defaultToolsLocation
   44.77 -            = { "lib", "tools.jar" };
   44.78 -        static final Class<? extends JavaCompiler> compilerClass;
   44.79 -        static {
   44.80 -            Class<? extends JavaCompiler> c = null;
   44.81 +
   44.82 +    private static ToolProvider instance;
   44.83 +
   44.84 +    private static synchronized ToolProvider instance() {
   44.85 +        if (instance == null)
   44.86 +            instance = new ToolProvider();
   44.87 +        return instance;
   44.88 +    }
   44.89 +
   44.90 +    // Cache for tool classes.
   44.91 +    // Use weak references to avoid keeping classes around unnecessarily
   44.92 +    private Map<String, Reference<Class<?>>> toolClasses = new HashMap<String, Reference<Class<?>>>();
   44.93 +
   44.94 +    // Cache for tool classloader.
   44.95 +    // Use a weak reference to avoid keeping it around unnecessarily
   44.96 +    private Reference<ClassLoader> refToolClassLoader = null;
   44.97 +
   44.98 +
   44.99 +    private ToolProvider() { }
  44.100 +
  44.101 +    private <T> T getSystemTool(Class<T> clazz, String name) {
  44.102 +        Class<? extends T> c = getSystemToolClass(clazz, name);
  44.103 +        try {
  44.104 +            return c.asSubclass(clazz).newInstance();
  44.105 +        } catch (Throwable e) {
  44.106 +            trace(WARNING, e);
  44.107 +            return null;
  44.108 +        }
  44.109 +    }
  44.110 +
  44.111 +    private <T> Class<? extends T> getSystemToolClass(Class<T> clazz, String name) {
  44.112 +        Reference<Class<?>> refClass = toolClasses.get(name);
  44.113 +        Class<?> c = (refClass == null ? null : refClass.get());
  44.114 +        if (c == null) {
  44.115              try {
  44.116 -                c = findClass().asSubclass(JavaCompiler.class);
  44.117 -            } catch (Throwable t) {
  44.118 -                trace(WARNING, t);
  44.119 +                c = findSystemToolClass(name);
  44.120 +            } catch (Throwable e) {
  44.121 +                return trace(WARNING, e);
  44.122              }
  44.123 -            compilerClass = c;
  44.124 +            toolClasses.put(name, new WeakReference<Class<?>>(c));
  44.125 +        }
  44.126 +        return c.asSubclass(clazz);
  44.127 +    }
  44.128 +
  44.129 +    private static final String[] defaultToolsLocation = { "lib", "tools.jar" };
  44.130 +
  44.131 +    private Class<?> findSystemToolClass(String toolClassName)
  44.132 +        throws MalformedURLException, ClassNotFoundException
  44.133 +    {
  44.134 +        // try loading class directly, in case tool is on the bootclasspath
  44.135 +        try {
  44.136 +            return enableAsserts(Class.forName(toolClassName, false, null));
  44.137 +        } catch (ClassNotFoundException e) {
  44.138 +            trace(FINE, e);
  44.139 +
  44.140 +            // if tool not on bootclasspath, look in default tools location (tools.jar)
  44.141 +            ClassLoader cl = (refToolClassLoader == null ? null : refToolClassLoader.get());
  44.142 +            if (cl == null) {
  44.143 +                File file = new File(System.getProperty("java.home"));
  44.144 +                if (file.getName().equalsIgnoreCase("jre"))
  44.145 +                    file = file.getParentFile();
  44.146 +                for (String name : defaultToolsLocation)
  44.147 +                    file = new File(file, name);
  44.148 +
  44.149 +                // if tools not found, no point in trying a URLClassLoader
  44.150 +                // so rethrow the original exception.
  44.151 +                if (!file.exists())
  44.152 +                    throw e;
  44.153 +
  44.154 +                URL[] urls = { file.toURI().toURL() };
  44.155 +                trace(FINE, urls[0].toString());
  44.156 +
  44.157 +                cl = URLClassLoader.newInstance(urls);
  44.158 +                cl.setPackageAssertionStatus("com.sun.tools.javac", true);
  44.159 +                refToolClassLoader = new WeakReference<ClassLoader>(cl);
  44.160 +            }
  44.161 +
  44.162 +            return Class.forName(toolClassName, false, cl);
  44.163          }
  44.164  
  44.165 -        private static Class<?> findClass()
  44.166 -            throws MalformedURLException, ClassNotFoundException
  44.167 -        {
  44.168 -            try {
  44.169 -                return enableAsserts(Class.forName(defaultJavaCompilerName, false, null));
  44.170 -            } catch (ClassNotFoundException e) {
  44.171 -                trace(FINE, e);
  44.172 -            }
  44.173 -            File file = new File(System.getProperty("java.home"));
  44.174 -            if (file.getName().equalsIgnoreCase("jre"))
  44.175 -                file = file.getParentFile();
  44.176 -            for (String name : defaultToolsLocation)
  44.177 -                file = new File(file, name);
  44.178 -            URL[] urls = {file.toURI().toURL()};
  44.179 -            trace(FINE, urls[0].toString());
  44.180 -            ClassLoader cl = URLClassLoader.newInstance(urls);
  44.181 -            cl.setPackageAssertionStatus("com.sun.tools.javac", true);
  44.182 -            return Class.forName(defaultJavaCompilerName, false, cl);
  44.183 +    }
  44.184 +
  44.185 +    private static Class<?> enableAsserts(Class<?> cls) {
  44.186 +        try {
  44.187 +            ClassLoader loader = cls.getClassLoader();
  44.188 +            if (loader != null)
  44.189 +                loader.setPackageAssertionStatus("com.sun.tools.javac", true);
  44.190 +            else
  44.191 +                trace(FINE, "loader == null");
  44.192 +        } catch (SecurityException ex) {
  44.193 +            trace(FINE, ex);
  44.194          }
  44.195 +        return cls;
  44.196 +    }
  44.197  
  44.198 -        private static Class<?> enableAsserts(Class<?> cls) {
  44.199 -            try {
  44.200 -                ClassLoader loader = cls.getClassLoader();
  44.201 -                if (loader != null)
  44.202 -                    loader.setPackageAssertionStatus("com.sun.tools.javac", true);
  44.203 -                else
  44.204 -                    trace(FINE, "loader == null");
  44.205 -            } catch (SecurityException ex) {
  44.206 -                trace(FINE, ex);
  44.207 -            }
  44.208 -            return cls;
  44.209 -        }
  44.210 -    }
  44.211 +
  44.212  }
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD34.java	Tue Sep 07 15:49:48 2010 -0700
    45.3 @@ -0,0 +1,40 @@
    45.4 +/*
    45.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    45.7 + *
    45.8 + * This code is free software; you can redistribute it and/or modify it
    45.9 + * under the terms of the GNU General Public License version 2 only, as
   45.10 + * published by the Free Software Foundation.
   45.11 + *
   45.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   45.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   45.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   45.15 + * version 2 for more details (a copy is included in the LICENSE file that
   45.16 + * accompanied this code).
   45.17 + *
   45.18 + * You should have received a copy of the GNU General Public License version
   45.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   45.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   45.21 + *
   45.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   45.23 + * or visit www.oracle.com if you need additional information or have any
   45.24 + * questions.
   45.25 + */
   45.26 +
   45.27 +/*
   45.28 + * @test
   45.29 + * @bug 6979683
   45.30 + * @summary Verify that casts can narrow and unbox at the same time
   45.31 + * @author jrose
   45.32 + *
   45.33 + * @compile/fail/ref=TestCast6979683_BAD34.java.errlog -XDrawDiagnostics TestCast6979683_BAD34.java
   45.34 + */
   45.35 +
   45.36 +public class TestCast6979683_BAD34 {
   45.37 +    static boolean zconvBAD1(Number o) { return o; } //BAD
   45.38 +    //...
   45.39 +    //...
   45.40 +    //...
   45.41 +    //...
   45.42 +    //...
   45.43 +}
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD34.java.errlog	Tue Sep 07 15:49:48 2010 -0700
    46.3 @@ -0,0 +1,2 @@
    46.4 +TestCast6979683_BAD34.java:34:49: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Number, boolean
    46.5 +1 error
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD35.java	Tue Sep 07 15:49:48 2010 -0700
    47.3 @@ -0,0 +1,40 @@
    47.4 +/*
    47.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    47.7 + *
    47.8 + * This code is free software; you can redistribute it and/or modify it
    47.9 + * under the terms of the GNU General Public License version 2 only, as
   47.10 + * published by the Free Software Foundation.
   47.11 + *
   47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   47.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   47.15 + * version 2 for more details (a copy is included in the LICENSE file that
   47.16 + * accompanied this code).
   47.17 + *
   47.18 + * You should have received a copy of the GNU General Public License version
   47.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   47.21 + *
   47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   47.23 + * or visit www.oracle.com if you need additional information or have any
   47.24 + * questions.
   47.25 + */
   47.26 +
   47.27 +/*
   47.28 + * @test
   47.29 + * @bug 6979683
   47.30 + * @summary Verify that casts can narrow and unbox at the same time
   47.31 + * @author jrose
   47.32 + *
   47.33 + * @compile/fail/ref=TestCast6979683_BAD35.java.errlog -XDrawDiagnostics TestCast6979683_BAD35.java
   47.34 + */
   47.35 +
   47.36 +public class TestCast6979683_BAD35 {
   47.37 +    //...
   47.38 +    static int iconvBAD1(Number o) { return o; } //BAD: cast needed
   47.39 +    //...
   47.40 +    //...
   47.41 +    //...
   47.42 +    //...
   47.43 +}
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD35.java.errlog	Tue Sep 07 15:49:48 2010 -0700
    48.3 @@ -0,0 +1,2 @@
    48.4 +TestCast6979683_BAD35.java:35:45: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Number, int
    48.5 +1 error
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD36.java	Tue Sep 07 15:49:48 2010 -0700
    49.3 @@ -0,0 +1,40 @@
    49.4 +/*
    49.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    49.7 + *
    49.8 + * This code is free software; you can redistribute it and/or modify it
    49.9 + * under the terms of the GNU General Public License version 2 only, as
   49.10 + * published by the Free Software Foundation.
   49.11 + *
   49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   49.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   49.15 + * version 2 for more details (a copy is included in the LICENSE file that
   49.16 + * accompanied this code).
   49.17 + *
   49.18 + * You should have received a copy of the GNU General Public License version
   49.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   49.21 + *
   49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   49.23 + * or visit www.oracle.com if you need additional information or have any
   49.24 + * questions.
   49.25 + */
   49.26 +
   49.27 +/*
   49.28 + * @test
   49.29 + * @bug 6979683
   49.30 + * @summary Verify that casts can narrow and unbox at the same time
   49.31 + * @author jrose
   49.32 + *
   49.33 + * @compile/fail/ref=TestCast6979683_BAD36.java.errlog -XDrawDiagnostics TestCast6979683_BAD36.java
   49.34 + */
   49.35 +
   49.36 +public class TestCast6979683_BAD36 {
   49.37 +    //...
   49.38 +    //...
   49.39 +    static int iconvBAD2(Comparable<Integer> o) { return o; } //BAD: cast needed
   49.40 +    //...
   49.41 +    //...
   49.42 +    //...
   49.43 +}
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD36.java.errlog	Tue Sep 07 15:49:48 2010 -0700
    50.3 @@ -0,0 +1,2 @@
    50.4 +TestCast6979683_BAD36.java:36:58: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Comparable<java.lang.Integer>, int
    50.5 +1 error
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD37.java	Tue Sep 07 15:49:48 2010 -0700
    51.3 @@ -0,0 +1,40 @@
    51.4 +/*
    51.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    51.7 + *
    51.8 + * This code is free software; you can redistribute it and/or modify it
    51.9 + * under the terms of the GNU General Public License version 2 only, as
   51.10 + * published by the Free Software Foundation.
   51.11 + *
   51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   51.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   51.15 + * version 2 for more details (a copy is included in the LICENSE file that
   51.16 + * accompanied this code).
   51.17 + *
   51.18 + * You should have received a copy of the GNU General Public License version
   51.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   51.21 + *
   51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   51.23 + * or visit www.oracle.com if you need additional information or have any
   51.24 + * questions.
   51.25 + */
   51.26 +
   51.27 +/*
   51.28 + * @test
   51.29 + * @bug 6979683
   51.30 + * @summary Verify that casts can narrow and unbox at the same time
   51.31 + * @author jrose
   51.32 + *
   51.33 + * @compile/fail/ref=TestCast6979683_BAD37.java.errlog -XDrawDiagnostics TestCast6979683_BAD37.java
   51.34 + */
   51.35 +
   51.36 +public class TestCast6979683_BAD37 {
   51.37 +    //...
   51.38 +    //...
   51.39 +    //...
   51.40 +    static int iconvBAD3(Comparable<Short> o) { return (int)o; } //BAD: wrong instance
   51.41 +    //...
   51.42 +    //...
   51.43 +}
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD37.java.errlog	Tue Sep 07 15:49:48 2010 -0700
    52.3 @@ -0,0 +1,2 @@
    52.4 +TestCast6979683_BAD37.java:37:61: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), java.lang.Comparable<java.lang.Short>, int
    52.5 +1 error
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD38.java	Tue Sep 07 15:49:48 2010 -0700
    53.3 @@ -0,0 +1,40 @@
    53.4 +/*
    53.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    53.7 + *
    53.8 + * This code is free software; you can redistribute it and/or modify it
    53.9 + * under the terms of the GNU General Public License version 2 only, as
   53.10 + * published by the Free Software Foundation.
   53.11 + *
   53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   53.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   53.15 + * version 2 for more details (a copy is included in the LICENSE file that
   53.16 + * accompanied this code).
   53.17 + *
   53.18 + * You should have received a copy of the GNU General Public License version
   53.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   53.21 + *
   53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   53.23 + * or visit www.oracle.com if you need additional information or have any
   53.24 + * questions.
   53.25 + */
   53.26 +
   53.27 +/*
   53.28 + * @test
   53.29 + * @bug 6979683
   53.30 + * @summary Verify that casts can narrow and unbox at the same time
   53.31 + * @author jrose
   53.32 + *
   53.33 + * @compile/fail/ref=TestCast6979683_BAD38.java.errlog -XDrawDiagnostics TestCast6979683_BAD38.java
   53.34 + */
   53.35 +
   53.36 +public class TestCast6979683_BAD38 {
   53.37 +    //...
   53.38 +    //...
   53.39 +    //...
   53.40 +    //...
   53.41 +    static float cconvBAD1(Comparable<Character> o) { return o; } //BAD
   53.42 +    //...
   53.43 +}
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD38.java.errlog	Tue Sep 07 15:49:48 2010 -0700
    54.3 @@ -0,0 +1,2 @@
    54.4 +TestCast6979683_BAD38.java:38:62: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Comparable<java.lang.Character>, float
    54.5 +1 error
    55.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD39.java	Tue Sep 07 15:49:48 2010 -0700
    55.3 @@ -0,0 +1,40 @@
    55.4 +/*
    55.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    55.7 + *
    55.8 + * This code is free software; you can redistribute it and/or modify it
    55.9 + * under the terms of the GNU General Public License version 2 only, as
   55.10 + * published by the Free Software Foundation.
   55.11 + *
   55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   55.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   55.15 + * version 2 for more details (a copy is included in the LICENSE file that
   55.16 + * accompanied this code).
   55.17 + *
   55.18 + * You should have received a copy of the GNU General Public License version
   55.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   55.21 + *
   55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   55.23 + * or visit www.oracle.com if you need additional information or have any
   55.24 + * questions.
   55.25 + */
   55.26 +
   55.27 +/*
   55.28 + * @test
   55.29 + * @bug 6979683
   55.30 + * @summary Verify that casts can narrow and unbox at the same time
   55.31 + * @author jrose
   55.32 + *
   55.33 + * @compile/fail/ref=TestCast6979683_BAD39.java.errlog -XDrawDiagnostics TestCast6979683_BAD39.java
   55.34 + */
   55.35 +
   55.36 +public class TestCast6979683_BAD39 {
   55.37 +    //...
   55.38 +    //...
   55.39 +    //...
   55.40 +    //...
   55.41 +    //...
   55.42 +    static float cconvBAD2(Number o) { return (char)o; } //BAD
   55.43 +}
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD39.java.errlog	Tue Sep 07 15:49:48 2010 -0700
    56.3 @@ -0,0 +1,2 @@
    56.4 +TestCast6979683_BAD39.java:39:53: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), java.lang.Number, char
    56.5 +1 error
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/test/tools/javac/6979683/TestCast6979683_GOOD.java	Tue Sep 07 15:49:48 2010 -0700
    57.3 @@ -0,0 +1,111 @@
    57.4 +/*
    57.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    57.7 + *
    57.8 + * This code is free software; you can redistribute it and/or modify it
    57.9 + * under the terms of the GNU General Public License version 2 only, as
   57.10 + * published by the Free Software Foundation.
   57.11 + *
   57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   57.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   57.15 + * version 2 for more details (a copy is included in the LICENSE file that
   57.16 + * accompanied this code).
   57.17 + *
   57.18 + * You should have received a copy of the GNU General Public License version
   57.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   57.21 + *
   57.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   57.23 + * or visit www.oracle.com if you need additional information or have any
   57.24 + * questions.
   57.25 + */
   57.26 +
   57.27 +/*
   57.28 + * @test
   57.29 + * @bug 6979683
   57.30 + * @summary Verify that casts can narrow and unbox at the same time
   57.31 + * @author jrose
   57.32 + *
   57.33 + * @compile TestCast6979683_GOOD.java
   57.34 + * @run main TestCast6979683_GOOD
   57.35 + */
   57.36 +
   57.37 +public class TestCast6979683_GOOD {
   57.38 +    public static void main(String... av) {
   57.39 +        bugReportExample();
   57.40 +        for (int x = -1; x <= 2; x++) {
   57.41 +            zconvTests(x != 0);
   57.42 +            iconvTests(x);
   57.43 +            bconvTests((byte)x);
   57.44 +            cconvTests((char)x);
   57.45 +        }
   57.46 +        System.out.println("Successfully ran "+tests+" tests.");
   57.47 +    }
   57.48 +
   57.49 +    static int tests;
   57.50 +    static void assertEquals(Object x, Object y) {
   57.51 +        if (!x.equals(y)) {
   57.52 +            throw new RuntimeException("assertEquals: "+x+" != "+y);
   57.53 +        }
   57.54 +        ++tests;
   57.55 +    }
   57.56 +
   57.57 +    static void bugReportExample() {
   57.58 +  {} // example in bug report:
   57.59 +  Object x = (Object)1;
   57.60 +  int y = (int)x;
   57.61 +  {} // end example
   57.62 +    }
   57.63 +
   57.64 +    static boolean zconv1(Boolean o) { return o; }
   57.65 +    static boolean zconv2(Object o) { return (boolean)o; }
   57.66 +    static boolean zconv3(Comparable<Boolean> o) { return (boolean)o; }
   57.67 +
   57.68 +    static void zconvTests(boolean x) {
   57.69 +        assertEquals(x, zconv1(x));
   57.70 +        assertEquals(x, zconv2(x));
   57.71 +        assertEquals(x, zconv3(x));
   57.72 +    }
   57.73 +
   57.74 +    static int iconv1(Integer o) { return o; }
   57.75 +    static int iconv2(Object o) { return (int)o; }
   57.76 +    static int iconv3(java.io.Serializable o) { return (int)o; }
   57.77 +    static int iconv4(Number o) { return (int)o; }
   57.78 +    static int iconv5(Comparable<Integer> o) { return (int)o; }
   57.79 +
   57.80 +    static void iconvTests(int x) {
   57.81 +        assertEquals(x, iconv1(x));
   57.82 +        assertEquals(x, iconv2(x));
   57.83 +        assertEquals(x, iconv3(x));
   57.84 +        assertEquals(x, iconv4(x));
   57.85 +        assertEquals(x, iconv5(x));
   57.86 +    }
   57.87 +
   57.88 +    static float bconv1(Byte o) { return o; }  // note type "float"
   57.89 +    static float bconv2(Object o) { return (byte)o; }
   57.90 +    static float bconv3(java.io.Serializable o) { return (byte)o; }
   57.91 +    static float bconv4(Number o) { return (byte)o; }
   57.92 +
   57.93 +    static void bconvTests(byte x) {
   57.94 +        float xf = x;
   57.95 +        assertEquals(xf, bconv1(x));
   57.96 +        assertEquals(xf, bconv2(x));
   57.97 +        assertEquals(xf, bconv3(x));
   57.98 +        assertEquals(xf, bconv4(x));
   57.99 +    }
  57.100 +
  57.101 +    static float cconv1(Character o) { return o; }  // note type "float"
  57.102 +    static float cconv2(Object o) { return (char)o; }
  57.103 +    static float cconv3(java.io.Serializable o) { return (char)o; }
  57.104 +    static float cconv4(Comparable<Character> o) { return (char)o; }
  57.105 +
  57.106 +    static void cconvTests(char x) {
  57.107 +        float xf = x;
  57.108 +        assertEquals(xf, cconv1(x));
  57.109 +        assertEquals(xf, cconv2(x));
  57.110 +        assertEquals(xf, cconv3(x));
  57.111 +        assertEquals(xf, cconv4(x));
  57.112 +    }
  57.113 +
  57.114 +}
    58.1 --- a/test/tools/javac/InterfaceAssert.java	Tue Sep 07 15:14:49 2010 -0700
    58.2 +++ b/test/tools/javac/InterfaceAssert.java	Tue Sep 07 15:49:48 2010 -0700
    58.3 @@ -23,9 +23,11 @@
    58.4  
    58.5  /*
    58.6   * @test
    58.7 - * @bug 4399129
    58.8 + * @bug 4399129 6980724
    58.9   * @summary Check that assertions compile properly when nested in an interface
   58.10   * @author gafter
   58.11 + * @compile InterfaceAssert.java
   58.12 + * @run main InterfaceAssert
   58.13   */
   58.14  
   58.15  /*
    59.1 --- a/test/tools/javac/T6341023.java	Tue Sep 07 15:14:49 2010 -0700
    59.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.3 @@ -1,125 +0,0 @@
    59.4 -/*
    59.5 - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
    59.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    59.7 - *
    59.8 - * This code is free software; you can redistribute it and/or modify it
    59.9 - * under the terms of the GNU General Public License version 2 only, as
   59.10 - * published by the Free Software Foundation.
   59.11 - *
   59.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
   59.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   59.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   59.15 - * version 2 for more details (a copy is included in the LICENSE file that
   59.16 - * accompanied this code).
   59.17 - *
   59.18 - * You should have received a copy of the GNU General Public License version
   59.19 - * 2 along with this work; if not, write to the Free Software Foundation,
   59.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   59.21 - *
   59.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   59.23 - * or visit www.oracle.com if you need additional information or have any
   59.24 - * questions.
   59.25 - */
   59.26 -
   59.27 -/*
   59.28 - * @test
   59.29 - * @bug 6341023
   59.30 - * @summary Tree API: Tree.Kind should have mapping to interface
   59.31 - */
   59.32 -
   59.33 -import com.sun.source.tree.*;
   59.34 -
   59.35 -public class T6341023 {
   59.36 -    public static void main(String... args) {
   59.37 -        boolean ok = true;
   59.38 -
   59.39 -        for (Tree.Kind k: Tree.Kind.values()) {
   59.40 -            //System.err.println(k + " " + k.asInterface());
   59.41 -            Class<? extends Tree> i = k.asInterface();
   59.42 -            switch (k) {
   59.43 -            case POSTFIX_INCREMENT:
   59.44 -            case POSTFIX_DECREMENT:
   59.45 -            case PREFIX_INCREMENT:
   59.46 -            case PREFIX_DECREMENT:
   59.47 -            case UNARY_PLUS:
   59.48 -            case UNARY_MINUS:
   59.49 -            case BITWISE_COMPLEMENT:
   59.50 -            case LOGICAL_COMPLEMENT:
   59.51 -                ok = ok & verify(k, i, i == UnaryTree.class);
   59.52 -                break;
   59.53 -
   59.54 -            case MULTIPLY:
   59.55 -            case DIVIDE:
   59.56 -            case REMAINDER:
   59.57 -            case PLUS:
   59.58 -            case MINUS:
   59.59 -            case LEFT_SHIFT:
   59.60 -            case RIGHT_SHIFT:
   59.61 -            case UNSIGNED_RIGHT_SHIFT:
   59.62 -            case LESS_THAN:
   59.63 -            case GREATER_THAN:
   59.64 -            case LESS_THAN_EQUAL:
   59.65 -            case GREATER_THAN_EQUAL:
   59.66 -            case EQUAL_TO:
   59.67 -            case NOT_EQUAL_TO:
   59.68 -            case AND:
   59.69 -            case XOR:
   59.70 -            case OR:
   59.71 -            case CONDITIONAL_AND:
   59.72 -            case CONDITIONAL_OR:
   59.73 -                ok = ok & verify(k, i, i == BinaryTree.class);
   59.74 -                break;
   59.75 -
   59.76 -            case MULTIPLY_ASSIGNMENT:
   59.77 -            case DIVIDE_ASSIGNMENT:
   59.78 -            case REMAINDER_ASSIGNMENT:
   59.79 -            case PLUS_ASSIGNMENT:
   59.80 -            case MINUS_ASSIGNMENT:
   59.81 -            case LEFT_SHIFT_ASSIGNMENT:
   59.82 -            case RIGHT_SHIFT_ASSIGNMENT:
   59.83 -            case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
   59.84 -            case AND_ASSIGNMENT:
   59.85 -            case XOR_ASSIGNMENT:
   59.86 -            case OR_ASSIGNMENT:
   59.87 -                ok = ok & verify(k, i, i == CompoundAssignmentTree.class);
   59.88 -                break;
   59.89 -
   59.90 -            case INT_LITERAL:
   59.91 -            case LONG_LITERAL:
   59.92 -            case FLOAT_LITERAL:
   59.93 -            case DOUBLE_LITERAL:
   59.94 -            case BOOLEAN_LITERAL:
   59.95 -            case CHAR_LITERAL:
   59.96 -            case STRING_LITERAL:
   59.97 -            case NULL_LITERAL:
   59.98 -                ok = ok & verify(k, i, i == LiteralTree.class);
   59.99 -                break;
  59.100 -
  59.101 -            case UNBOUNDED_WILDCARD:
  59.102 -            case EXTENDS_WILDCARD:
  59.103 -            case SUPER_WILDCARD:
  59.104 -                ok = ok & verify(k, i, i == WildcardTree.class);
  59.105 -                break;
  59.106 -
  59.107 -            case OTHER:
  59.108 -                ok = ok & verify(k, i, i == null);
  59.109 -                break;
  59.110 -
  59.111 -            default:
  59.112 -                String ks = k.toString().replace("_", "") + "tree";
  59.113 -                String iName = i.getName();
  59.114 -                String is = iName.substring(iName.lastIndexOf(".") + 1);
  59.115 -                ok = ok & verify(k, i, ks.equalsIgnoreCase(is));
  59.116 -            }
  59.117 -        }
  59.118 -
  59.119 -        if (!ok)
  59.120 -            throw new AssertionError("test failed");
  59.121 -    }
  59.122 -
  59.123 -    static boolean verify(Tree.Kind k, Class<?> c, boolean b) {
  59.124 -        if (!b)
  59.125 -            System.err.println("error: " + k + " " + c);
  59.126 -        return b;
  59.127 -    }
  59.128 -}
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/test/tools/javac/T6458749.java	Tue Sep 07 15:49:48 2010 -0700
    60.3 @@ -0,0 +1,62 @@
    60.4 +/*
    60.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    60.7 + *
    60.8 + * This code is free software; you can redistribute it and/or modify it
    60.9 + * under the terms of the GNU General Public License version 2 only, as
   60.10 + * published by the Free Software Foundation.
   60.11 + *
   60.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   60.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   60.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   60.15 + * version 2 for more details (a copy is included in the LICENSE file that
   60.16 + * accompanied this code).
   60.17 + *
   60.18 + * You should have received a copy of the GNU General Public License version
   60.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   60.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   60.21 + *
   60.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   60.23 + * or visit www.oracle.com if you need additional information or have any
   60.24 + * questions.
   60.25 + */
   60.26 +
   60.27 +/*
   60.28 + * @test
   60.29 + * @bug 6458749
   60.30 + * @summary  TypeParameterElement.getEnclosedElements() throws NPE within javac
   60.31 + * @build T6458749
   60.32 + * @compile -processor T6458749 -proc:only T6458749.java
   60.33 + */
   60.34 +
   60.35 +import java.util.Set;
   60.36 +import javax.annotation.processing.*;
   60.37 +import javax.lang.model.element.*;
   60.38 +import javax.lang.model.util.ElementFilter;
   60.39 +import javax.lang.model.SourceVersion;
   60.40 +
   60.41 +@SupportedAnnotationTypes("*")
   60.42 +public class T6458749<T> extends AbstractProcessor {
   60.43 +    public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
   60.44 +        if (!renv.processingOver()) {
   60.45 +            for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
   60.46 +                System.out.printf("Element %s:%n", e.toString());
   60.47 +                try {
   60.48 +                    for (TypeParameterElement tp : e.getTypeParameters()) {
   60.49 +                        System.out.printf("Type param %s", tp.toString());
   60.50 +                        if (! tp.getEnclosedElements().isEmpty()) {
   60.51 +                            throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
   60.52 +                        }
   60.53 +                    }
   60.54 +                } catch (NullPointerException npe) {
   60.55 +                    throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
   60.56 +                }
   60.57 +            }
   60.58 +        }
   60.59 +        return true;
   60.60 +    }
   60.61 +
   60.62 +    public SourceVersion getSupportedSourceVersion() {
   60.63 +        return SourceVersion.latest();
   60.64 +    }
   60.65 +}
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/test/tools/javac/T6458823/MyProcessor.java	Tue Sep 07 15:49:48 2010 -0700
    61.3 @@ -0,0 +1,55 @@
    61.4 + /*
    61.5 +  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    61.6 +  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    61.7 +  *
    61.8 +  * This code is free software; you can redistribute it and/or modify it
    61.9 +  * under the terms of the GNU General Public License version 2 only, as
   61.10 +  * published by the Free Software Foundation.
   61.11 +  *
   61.12 +  * This code is distributed in the hope that it will be useful, but WITHOUT
   61.13 +  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   61.14 +  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   61.15 +  * version 2 for more details (a copy is included in the LICENSE file that
   61.16 +  * accompanied this code).
   61.17 +  *
   61.18 +  * You should have received a copy of the GNU General Public License version
   61.19 +  * 2 along with this work; if not, write to the Free Software Foundation,
   61.20 +  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   61.21 +  *
   61.22 +  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   61.23 +  * or visit www.oracle.com if you need additional information or have any
   61.24 +  * questions.
   61.25 +  */
   61.26 +
   61.27 +import java.util.Set;
   61.28 +import javax.annotation.processing.*;
   61.29 +import javax.lang.model.element.*;
   61.30 +import javax.lang.model.util.ElementFilter;
   61.31 +import javax.lang.model.SourceVersion;
   61.32 +import static javax.tools.Diagnostic.Kind.*;
   61.33 +
   61.34 +@SupportedAnnotationTypes("*")
   61.35 +public class MyProcessor extends AbstractProcessor {
   61.36 +    private Messager messager;
   61.37 +    public void init(ProcessingEnvironment processingEnv) {
   61.38 +        this.messager = processingEnv.getMessager();
   61.39 +    }
   61.40 +
   61.41 +    public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
   61.42 +        if (!renv.processingOver()) {
   61.43 +            for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
   61.44 +                for (TypeParameterElement tp : e.getTypeParameters()) {
   61.45 +                    if (tp.getSimpleName().toString().length() > 1) {
   61.46 +                        messager.printMessage(WARNING,
   61.47 +                            "Type param names should be of length 1", tp);
   61.48 +                    }
   61.49 +                }
   61.50 +            }
   61.51 +        }
   61.52 +        return true;
   61.53 +    }
   61.54 +
   61.55 +    public SourceVersion getSupportedSourceVersion() {
   61.56 +        return SourceVersion.latest();
   61.57 +    }
   61.58 +}
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/test/tools/javac/T6458823/T6458823.java	Tue Sep 07 15:49:48 2010 -0700
    62.3 @@ -0,0 +1,87 @@
    62.4 +/*
    62.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    62.7 + *
    62.8 + * This code is free software; you can redistribute it and/or modify it
    62.9 + * under the terms of the GNU General Public License version 2 only, as
   62.10 + * published by the Free Software Foundation.
   62.11 + *
   62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   62.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   62.15 + * version 2 for more details (a copy is included in the LICENSE file that
   62.16 + * accompanied this code).
   62.17 + *
   62.18 + * You should have received a copy of the GNU General Public License version
   62.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   62.21 + *
   62.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   62.23 + * or visit www.oracle.com if you need additional information or have any
   62.24 + * questions.
   62.25 + */
   62.26 +
   62.27 +/*
   62.28 + * @test
   62.29 + * @bug 6458823
   62.30 + * @summary Messager messages on TypeParamterElements to not include position information.
   62.31 + *
   62.32 + * @compile MyProcessor.java T6458823.java
   62.33 + * @run main T6458823
   62.34 + */
   62.35 +
   62.36 +import java.io.File;
   62.37 +import java.io.IOException;
   62.38 +import java.io.Writer;
   62.39 +import java.net.URISyntaxException;
   62.40 +import java.util.ArrayList;
   62.41 +import java.util.HashMap;
   62.42 +import java.util.List;
   62.43 +import java.util.Map;
   62.44 +import java.util.Set;
   62.45 +import javax.tools.Diagnostic;
   62.46 +import javax.tools.DiagnosticCollector;
   62.47 +import javax.tools.JavaCompiler;
   62.48 +import javax.tools.JavaCompiler.CompilationTask;
   62.49 +import javax.tools.JavaFileObject;
   62.50 +import javax.tools.StandardJavaFileManager;
   62.51 +import javax.tools.ToolProvider;
   62.52 +
   62.53 +public class T6458823 {
   62.54 +    public static void main(String[] args) throws Exception {
   62.55 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
   62.56 +        if (compiler == null) {
   62.57 +            throw new RuntimeException("can't get javax.tools.JavaCompiler!");
   62.58 +        }
   62.59 +        DiagnosticCollector<JavaFileObject> diagColl =
   62.60 +            new DiagnosticCollector<JavaFileObject>();
   62.61 +        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
   62.62 +        List<String> options = new ArrayList<String>();
   62.63 +        options.add("-processor");
   62.64 +        options.add("MyProcessor");
   62.65 +        options.add("-proc:only");
   62.66 +        List<File> files = new ArrayList<File>();
   62.67 +        files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
   62.68 +        final CompilationTask task = compiler.getTask(null, fm, diagColl,
   62.69 +            options, null, fm.getJavaFileObjectsFromFiles(files));
   62.70 +        task.call();
   62.71 +        int diagCount = 0;
   62.72 +        for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
   62.73 +            if (diag.getKind() != Diagnostic.Kind.WARNING) {
   62.74 +                throw new AssertionError("Only warnings expected");
   62.75 +            }
   62.76 +            System.out.println(diag);
   62.77 +            if (diag.getPosition() == Diagnostic.NOPOS) {
   62.78 +                throw new AssertionError("No position info in message");
   62.79 +            }
   62.80 +            if (diag.getSource() == null) {
   62.81 +                throw new AssertionError("No source info in message");
   62.82 +            }
   62.83 +            diagCount++;
   62.84 +        }
   62.85 +        if (diagCount != 2) {
   62.86 +            throw new AssertionError("unexpected number of warnings: " +
   62.87 +                diagCount + ", expected: 2");
   62.88 +        }
   62.89 +    }
   62.90 +}
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/test/tools/javac/T6458823/TestClass.java	Tue Sep 07 15:49:48 2010 -0700
    63.3 @@ -0,0 +1,25 @@
    63.4 +/*
    63.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    63.7 + *
    63.8 + * This code is free software; you can redistribute it and/or modify it
    63.9 + * under the terms of the GNU General Public License version 2 only, as
   63.10 + * published by the Free Software Foundation.
   63.11 + *
   63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   63.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   63.15 + * version 2 for more details (a copy is included in the LICENSE file that
   63.16 + * accompanied this code).
   63.17 + *
   63.18 + * You should have received a copy of the GNU General Public License version
   63.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   63.21 + *
   63.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   63.23 + * or visit www.oracle.com if you need additional information or have any
   63.24 + * questions.
   63.25 + */
   63.26 +
   63.27 +class TestClass<XYZ, ABC> {
   63.28 +}
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/test/tools/javac/T6956462/T6956462.java	Tue Sep 07 15:49:48 2010 -0700
    64.3 @@ -0,0 +1,126 @@
    64.4 +/*
    64.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    64.7 + *
    64.8 + * This code is free software; you can redistribute it and/or modify it
    64.9 + * under the terms of the GNU General Public License version 2 only, as
   64.10 + * published by the Free Software Foundation.
   64.11 + *
   64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   64.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   64.15 + * version 2 for more details (a copy is included in the LICENSE file that
   64.16 + * accompanied this code).
   64.17 + *
   64.18 + * You should have received a copy of the GNU General Public License version
   64.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   64.21 + *
   64.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   64.23 + * or visit www.oracle.com if you need additional information or have any
   64.24 + * questions.
   64.25 + */
   64.26 +
   64.27 +/*
   64.28 + * @test
   64.29 + * @bug 6956462
   64.30 + * @summary AssertionError exception throws in the Compiler Tree API in JDK 7.
   64.31 + *
   64.32 + * @build TestClass T6956462
   64.33 + * @run main T6956462
   64.34 + */
   64.35 +
   64.36 +import java.io.*;
   64.37 +import java.net.URISyntaxException;
   64.38 +import java.util.*;
   64.39 +import javax.tools.*;
   64.40 +import javax.tools.JavaCompiler.CompilationTask;
   64.41 +import com.sun.source.tree.*;
   64.42 +import com.sun.source.util.*;
   64.43 +
   64.44 +public class T6956462 {
   64.45 +    public static void main(String[] args) throws Exception {
   64.46 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
   64.47 +        if (compiler == null) {
   64.48 +            throw new RuntimeException("can't get javax.tools.JavaCompiler!");
   64.49 +        }
   64.50 +        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
   64.51 +        List<File> files = new ArrayList<File>();
   64.52 +        files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
   64.53 +        final CompilationTask task = compiler.getTask(null, fm, null,
   64.54 +            null, null, fm.getJavaFileObjectsFromFiles(files));
   64.55 +        JavacTask javacTask = (JavacTask) task;
   64.56 +        for (CompilationUnitTree cu : javacTask.parse()) {
   64.57 +            cu.accept(new MyVisitor(javacTask), null);
   64.58 +        }
   64.59 +    }
   64.60 +
   64.61 +    private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> {
   64.62 +        private final Trees trees;
   64.63 +        private CompilationUnitTree file;
   64.64 +
   64.65 +        private MyVisitor(JavacTask javac) {
   64.66 +            this.trees = Trees.instance(javac);
   64.67 +        }
   64.68 +
   64.69 +        @Override
   64.70 +        public Tree visitCompilationUnit(CompilationUnitTree file, Void v) {
   64.71 +            this.file = file;
   64.72 +            for (Tree typeDecl : file.getTypeDecls()) {
   64.73 +                typeDecl.accept(this, v);
   64.74 +            }
   64.75 +            return null;
   64.76 +        }
   64.77 +
   64.78 +        @Override
   64.79 +        public Tree visitImport(ImportTree imp, Void v) {
   64.80 +            return null;
   64.81 +        }
   64.82 +
   64.83 +        @Override
   64.84 +        public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) {
   64.85 +            invoke.getMethodSelect().accept(this, v);
   64.86 +            return null;
   64.87 +        }
   64.88 +
   64.89 +        @Override
   64.90 +        public Tree visitBlock(BlockTree block, Void v) {
   64.91 +            for (StatementTree stat : block.getStatements()) {
   64.92 +                stat.accept(this, v);
   64.93 +            }
   64.94 +            return null;
   64.95 +        }
   64.96 +
   64.97 +        @Override
   64.98 +        public Tree visitClass(ClassTree clazz, Void v) {
   64.99 +            for (Tree member : clazz.getMembers()) {
  64.100 +                member.accept(this, v);
  64.101 +            }
  64.102 +            return null;
  64.103 +        }
  64.104 +
  64.105 +        @Override
  64.106 +        public Tree visitIdentifier(IdentifierTree ident, Void v) {
  64.107 +            trees.getScope(trees.getPath(file, ident));
  64.108 +            return null;
  64.109 +        }
  64.110 +
  64.111 +        @Override
  64.112 +        public Tree visitMethod(MethodTree method, Void v) {
  64.113 +            method.getBody().accept(this, v);
  64.114 +            return null;
  64.115 +        }
  64.116 +
  64.117 +        @Override
  64.118 +        public Tree visitMemberSelect(MemberSelectTree select, Void v) {
  64.119 +            select.getExpression().accept(this, v);
  64.120 +            return null;
  64.121 +        }
  64.122 +
  64.123 +        @Override
  64.124 +        public Tree visitVariable(VariableTree var, Void v) {
  64.125 +            var.getInitializer().accept(this, v);
  64.126 +            return null;
  64.127 +        }
  64.128 +    }
  64.129 +}
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/test/tools/javac/T6956462/TestClass.java	Tue Sep 07 15:49:48 2010 -0700
    65.3 @@ -0,0 +1,30 @@
    65.4 +/*
    65.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    65.7 + *
    65.8 + * This code is free software; you can redistribute it and/or modify it
    65.9 + * under the terms of the GNU General Public License version 2 only, as
   65.10 + * published by the Free Software Foundation.
   65.11 + *
   65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   65.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   65.15 + * version 2 for more details (a copy is included in the LICENSE file that
   65.16 + * accompanied this code).
   65.17 + *
   65.18 + * You should have received a copy of the GNU General Public License version
   65.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   65.21 + *
   65.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   65.23 + * or visit www.oracle.com if you need additional information or have any
   65.24 + * questions.
   65.25 + */
   65.26 +
   65.27 +import java.io.PrintStream;
   65.28 +
   65.29 +abstract class TestClass {
   65.30 +    private void test() {
   65.31 +        final PrintStream out = System.out;
   65.32 +    }
   65.33 +}
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/test/tools/javac/TestPkgInfo.java	Tue Sep 07 15:49:48 2010 -0700
    66.3 @@ -0,0 +1,174 @@
    66.4 +/*
    66.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    66.7 + *
    66.8 + * This code is free software; you can redistribute it and/or modify it
    66.9 + * under the terms of the GNU General Public License version 2 only, as
   66.10 + * published by the Free Software Foundation.
   66.11 + *
   66.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   66.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   66.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   66.15 + * version 2 for more details (a copy is included in the LICENSE file that
   66.16 + * accompanied this code).
   66.17 + *
   66.18 + * You should have received a copy of the GNU General Public License version
   66.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   66.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   66.21 + *
   66.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   66.23 + * or visit www.oracle.com if you need additional information or have any
   66.24 + * questions.
   66.25 + */
   66.26 +
   66.27 +/*
   66.28 + * @test
   66.29 + * @bug 6960424
   66.30 + * @summary new option -Xpkginfo for better control of when package-info.class is generated
   66.31 + */
   66.32 +
   66.33 +import java.io.*;
   66.34 +import java.util.*;
   66.35 +
   66.36 +public class TestPkgInfo {
   66.37 +    enum OptKind {
   66.38 +        NONE(null),
   66.39 +        ALWAYS("-Xpkginfo:always"),
   66.40 +        NONEMPTY("-Xpkginfo:nonempty"),
   66.41 +        LEGACY("-Xpkginfo:legacy");
   66.42 +        OptKind(String opt) { this.opt = opt; }
   66.43 +        final String opt;
   66.44 +    };
   66.45 +
   66.46 +    public static void main(String... args) throws Exception {
   66.47 +        new TestPkgInfo().run(args);
   66.48 +    }
   66.49 +
   66.50 +    public void run(String... args) throws Exception {
   66.51 +        boolean[] booleanValues = { false, true };
   66.52 +        for (OptKind ok: OptKind.values()) {
   66.53 +            for (boolean sr: booleanValues) {
   66.54 +                for (boolean cr: booleanValues) {
   66.55 +                    for (boolean rr: booleanValues) {
   66.56 +                        try {
   66.57 +                            test(ok, sr, cr, rr);
   66.58 +                        } catch (Exception e) {
   66.59 +                            error("Exception: " + e);
   66.60 +                        }
   66.61 +                        if (errors > 0) throw new AssertionError();
   66.62 +                    }
   66.63 +                }
   66.64 +            }
   66.65 +        }
   66.66 +
   66.67 +        if (errors > 0)
   66.68 +            throw new Exception(errors + " errors occurred");
   66.69 +    }
   66.70 +
   66.71 +    void test(OptKind ok, boolean sr, boolean cr, boolean rr) throws Exception {
   66.72 +        count++;
   66.73 +        System.err.println("Test " + count + ": ok:" + ok + " sr:" + sr + " cr:" + cr + " rr:" + rr);
   66.74 +
   66.75 +        StringBuilder sb = new StringBuilder();
   66.76 +
   66.77 +        // create annotated package statement with all combinations of retention policy
   66.78 +        if (sr) sb.append("@SR\n");
   66.79 +        if (cr) sb.append("@CR\n");
   66.80 +        if (rr) sb.append("@RR\n");
   66.81 +        sb.append("package p;\n");
   66.82 +        sb.append("\n");
   66.83 +
   66.84 +        sb.append("import java.lang.annotation.*;\n");
   66.85 +        sb.append("@Retention(RetentionPolicy.SOURCE)  @interface SR { }\n");
   66.86 +        sb.append("@Retention(RetentionPolicy.CLASS)   @interface CR { }\n");
   66.87 +        sb.append("@Retention(RetentionPolicy.RUNTIME) @interface RR { }\n");
   66.88 +
   66.89 +        // test specific tmp directory
   66.90 +        File tmpDir = new File("tmp.test" + count);
   66.91 +        File classesDir = new File(tmpDir, "classes");
   66.92 +        classesDir.mkdirs();
   66.93 +        File pkginfo_java = new File(new File(tmpDir, "src"), "package-info.java");
   66.94 +        writeFile(pkginfo_java, sb.toString());
   66.95 +
   66.96 +        // build up list of options and files to be compiled
   66.97 +        List<String> opts = new ArrayList<String>();
   66.98 +        List<File> files = new ArrayList<File>();
   66.99 +
  66.100 +        opts.add("-d");
  66.101 +        opts.add(classesDir.getPath());
  66.102 +        if (ok.opt != null)
  66.103 +            opts.add(ok.opt);
  66.104 +        //opts.add("-verbose");
  66.105 +        files.add(pkginfo_java);
  66.106 +
  66.107 +        compile(opts, files);
  66.108 +
  66.109 +        File pkginfo_class = new File(new File(classesDir, "p"), "package-info.class");
  66.110 +        boolean exists = pkginfo_class.exists();
  66.111 +
  66.112 +        boolean expected;
  66.113 +        switch (ok) {
  66.114 +            case ALWAYS:
  66.115 +                expected = true;
  66.116 +                break;
  66.117 +
  66.118 +            case LEGACY:
  66.119 +            case NONE:
  66.120 +                expected = (sr || cr || rr ); // any annotation
  66.121 +                break;
  66.122 +
  66.123 +            case NONEMPTY:
  66.124 +                expected = (cr || rr ); // any annotation in class file
  66.125 +                break;
  66.126 +
  66.127 +            default:
  66.128 +                throw new IllegalStateException();
  66.129 +        }
  66.130 +
  66.131 +        if (exists && !expected)
  66.132 +            error("package-info.class found but not expected");
  66.133 +        if (!exists && expected)
  66.134 +            error("package-info.class expected but not found");
  66.135 +    }
  66.136 +
  66.137 +    /** Compile files with options provided. */
  66.138 +    void compile(List<String> opts, List<File> files) throws Exception {
  66.139 +        System.err.println("javac: " + opts + " " + files);
  66.140 +        List<String> args = new ArrayList<String>();
  66.141 +        args.addAll(opts);
  66.142 +        for (File f: files)
  66.143 +            args.add(f.getPath());
  66.144 +        StringWriter sw = new StringWriter();
  66.145 +        PrintWriter pw = new PrintWriter(sw);
  66.146 +        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
  66.147 +        pw.flush();
  66.148 +        if (sw.getBuffer().length() > 0)
  66.149 +            System.err.println(sw.toString());
  66.150 +        if (rc != 0)
  66.151 +            throw new Exception("compilation failed: rc=" + rc);
  66.152 +    }
  66.153 +
  66.154 +    /** Write a file with a given body. */
  66.155 +    void writeFile(File f, String body) throws Exception {
  66.156 +        if (f.getParentFile() != null)
  66.157 +            f.getParentFile().mkdirs();
  66.158 +        Writer out = new FileWriter(f);
  66.159 +        try {
  66.160 +            out.write(body);
  66.161 +        } finally {
  66.162 +            out.close();
  66.163 +        }
  66.164 +    }
  66.165 +
  66.166 +    /** Report an error. */
  66.167 +    void error(String msg) {
  66.168 +        System.err.println("Error: " + msg);
  66.169 +        errors++;
  66.170 +    }
  66.171 +
  66.172 +    /** Test case counter. */
  66.173 +    int count;
  66.174 +
  66.175 +    /** Number of errors found. */
  66.176 +    int errors;
  66.177 +}
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/test/tools/javac/api/TestContainTypes.java	Tue Sep 07 15:49:48 2010 -0700
    67.3 @@ -0,0 +1,216 @@
    67.4 +/*
    67.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    67.7 + *
    67.8 + * This code is free software; you can redistribute it and/or modify it
    67.9 + * under the terms of the GNU General Public License version 2 only, as
   67.10 + * published by the Free Software Foundation.
   67.11 + *
   67.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   67.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   67.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   67.15 + * version 2 for more details (a copy is included in the LICENSE file that
   67.16 + * accompanied this code).
   67.17 + *
   67.18 + * You should have received a copy of the GNU General Public License version
   67.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   67.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   67.21 + *
   67.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   67.23 + * or visit www.oracle.com if you need additional information or have any
   67.24 + * questions.
   67.25 + */
   67.26 +
   67.27 +/*
   67.28 + * @test
   67.29 + * @bug 6981185
   67.30 + * @summary  com.sun.tools.model.JavacTypes.contains() calls Type.contains instead of Types.containsType
   67.31 + * @run main TestContainTypes
   67.32 + */
   67.33 +
   67.34 +import java.net.URI;
   67.35 +import java.util.Arrays;
   67.36 +import java.util.HashSet;
   67.37 +import java.util.Set;
   67.38 +import javax.annotation.processing.AbstractProcessor;
   67.39 +import javax.annotation.processing.RoundEnvironment;
   67.40 +import javax.lang.model.element.Element;
   67.41 +import javax.lang.model.element.TypeElement;
   67.42 +import javax.lang.model.element.ExecutableElement;
   67.43 +import javax.lang.model.type.TypeMirror;
   67.44 +import javax.lang.model.type.DeclaredType;
   67.45 +import javax.tools.JavaCompiler;
   67.46 +import javax.tools.JavaFileObject;
   67.47 +import javax.tools.SimpleJavaFileObject;
   67.48 +import javax.tools.ToolProvider;
   67.49 +
   67.50 +import com.sun.source.util.JavacTask;
   67.51 +import javax.annotation.processing.SupportedSourceVersion;
   67.52 +import javax.lang.model.SourceVersion;
   67.53 +
   67.54 +public class TestContainTypes {
   67.55 +
   67.56 +    enum ClassType {
   67.57 +        OBJECT("Object"),
   67.58 +        NUMBER("Number"),
   67.59 +        INTEGER("Integer"),
   67.60 +        STRING("String");
   67.61 +
   67.62 +        String classStub;
   67.63 +
   67.64 +        ClassType(String classStub) {
   67.65 +            this.classStub = classStub;
   67.66 +        }
   67.67 +
   67.68 +        boolean subtypeOf(ClassType that) {
   67.69 +            switch (that) {
   67.70 +                case OBJECT: return true;
   67.71 +                case NUMBER: return this == NUMBER || this == INTEGER;
   67.72 +                case INTEGER: return this == INTEGER;
   67.73 +                case STRING: return this == STRING;
   67.74 +                default: throw new AssertionError("Bad type kind in subtyping test");
   67.75 +            }
   67.76 +        }
   67.77 +    }
   67.78 +
   67.79 +    enum ParameterType {
   67.80 +        INVARIANT("List<#1>"),
   67.81 +        COVARIANT("List<? extends #1>"),
   67.82 +        CONTRAVARIANT("List<? super #1>"),
   67.83 +        BIVARIANT("List<?>");
   67.84 +
   67.85 +        String paramTypeStub;
   67.86 +
   67.87 +        ParameterType(String paramTypeStub) {
   67.88 +            this.paramTypeStub = paramTypeStub;
   67.89 +        }
   67.90 +
   67.91 +        String instantiate(ClassType ct) {
   67.92 +            return paramTypeStub.replace("#1", ct.classStub);
   67.93 +        }
   67.94 +
   67.95 +        static boolean contains(ParameterType pt1, ClassType ct1,
   67.96 +                ParameterType pt2, ClassType ct2) {
   67.97 +            switch (pt1) {
   67.98 +                case INVARIANT: return (pt2 == INVARIANT && ct1 == ct2) ||
   67.99 +                                           (pt2 == CONTRAVARIANT && ct1 == ct2 && ct1 == ClassType.OBJECT);
  67.100 +                case COVARIANT: return ((pt2 == INVARIANT || pt2 == COVARIANT) &&
  67.101 +                                            ct2.subtypeOf(ct1)) ||
  67.102 +                                            (ct1 == ClassType.OBJECT);
  67.103 +                case CONTRAVARIANT: return (pt2 == INVARIANT || pt2 == CONTRAVARIANT) &&
  67.104 +                                            ct1.subtypeOf(ct2);
  67.105 +                case BIVARIANT: return true;
  67.106 +                default: throw new AssertionError("Bad type kind in containment test");
  67.107 +            }
  67.108 +        }
  67.109 +    }
  67.110 +
  67.111 +    static class JavaSource extends SimpleJavaFileObject {
  67.112 +
  67.113 +        final static String sourceStub =
  67.114 +                        "import java.util.List;\n" +
  67.115 +                        "@interface ToCheck {}\n" +
  67.116 +                        "class Test {\n" +
  67.117 +                        "   @ToCheck void test(#A a, #B b) {}\n" +
  67.118 +                        "}\n";
  67.119 +
  67.120 +        String source;
  67.121 +
  67.122 +        public JavaSource(String typeA, String typeB) {
  67.123 +            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
  67.124 +            source = sourceStub.replace("#A", typeA).replace("#B", typeB);
  67.125 +        }
  67.126 +
  67.127 +        @Override
  67.128 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
  67.129 +            return source;
  67.130 +        }
  67.131 +    }
  67.132 +
  67.133 +    public static void main(String... args) throws Exception {
  67.134 +        for (ClassType ctA : ClassType.values()) {
  67.135 +            for (ParameterType ptA : ParameterType.values()) {
  67.136 +                for (ClassType ctB : ClassType.values()) {
  67.137 +                    for (ParameterType ptB : ParameterType.values()) {
  67.138 +                        compileAndCheck(ptA, ctA, ptB, ctB);
  67.139 +                    }
  67.140 +                }
  67.141 +            }
  67.142 +        }
  67.143 +    }
  67.144 +
  67.145 +    static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception {
  67.146 +        JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB));
  67.147 +        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  67.148 +        JavacTask ct = (JavacTask)tool.getTask(null, null, null,
  67.149 +                null, null, Arrays.asList(source));
  67.150 +        ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source)));
  67.151 +        System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA));
  67.152 +        System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB));
  67.153 +        System.err.println("Source = " + source.source);
  67.154 +        ct.analyze();
  67.155 +    }
  67.156 +
  67.157 +    @SupportedSourceVersion(SourceVersion.RELEASE_7)
  67.158 +    static class ContainTypesTester extends AbstractProcessor {
  67.159 +
  67.160 +        boolean expected;
  67.161 +        JavaSource source;
  67.162 +
  67.163 +        ContainTypesTester(boolean expected, JavaSource source) {
  67.164 +            this.expected = expected;
  67.165 +            this.source = source;
  67.166 +        }
  67.167 +
  67.168 +        @Override
  67.169 +        public Set<String> getSupportedAnnotationTypes() {
  67.170 +            Set<String> supportedAnnos = new HashSet();
  67.171 +            supportedAnnos.add("*");
  67.172 +            return supportedAnnos;
  67.173 +        }
  67.174 +
  67.175 +        private void error(String msg) {
  67.176 +            System.err.println(source.source);
  67.177 +            throw new AssertionError(msg);
  67.178 +        }
  67.179 +
  67.180 +        @Override
  67.181 +        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  67.182 +            if (roundEnv.getRootElements().size() == 0) {
  67.183 +                return true;
  67.184 +            }
  67.185 +            if (annotations.isEmpty() || annotations.size() > 1) {
  67.186 +                error("no anno found/wrong number of annotations found: " + annotations.size());
  67.187 +            }
  67.188 +            TypeElement anno = (TypeElement)annotations.toArray()[0];
  67.189 +            Set<? extends Element> annoElems = roundEnv.getElementsAnnotatedWith(anno);
  67.190 +            if (annoElems.isEmpty() || annoElems.size() > 1) {
  67.191 +                error("no annotated element found/wrong number of annotated elements found: " + annoElems.size());
  67.192 +            }
  67.193 +            Element annoElement = (Element)annoElems.toArray()[0];
  67.194 +            if (!(annoElement instanceof ExecutableElement)) {
  67.195 +                error("annotated element must be a method");
  67.196 +            }
  67.197 +            ExecutableElement method = (ExecutableElement)annoElement;
  67.198 +            if (method.getParameters().size() != 2) {
  67.199 +                error("annotated method must have 2 arguments");
  67.200 +            }
  67.201 +            DeclaredType d1 = (DeclaredType)method.getParameters().get(0).asType();
  67.202 +            DeclaredType d2 = (DeclaredType)method.getParameters().get(1).asType();
  67.203 +            if (d1.getTypeArguments().size() != 1 ||
  67.204 +                    d1.getTypeArguments().size() != 1) {
  67.205 +                error("parameter type must be generic in one type-variable");
  67.206 +            }
  67.207 +            TypeMirror t1 = d1.getTypeArguments().get(0);
  67.208 +            TypeMirror t2 = d2.getTypeArguments().get(0);
  67.209 +
  67.210 +            if (processingEnv.getTypeUtils().contains(t1, t2) != expected) {
  67.211 +                error("bad type containment result\n" +
  67.212 +                        "t1 : " + t1 +"\n" +
  67.213 +                        "t2 : " + t2 +"\n" +
  67.214 +                        "expected answer : " + expected +"\n");
  67.215 +            }
  67.216 +            return true;
  67.217 +        }
  67.218 +    }
  67.219 +}
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/test/tools/javac/api/TestGetElement.java	Tue Sep 07 15:49:48 2010 -0700
    68.3 @@ -0,0 +1,235 @@
    68.4 +/*
    68.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    68.7 + *
    68.8 + * This code is free software; you can redistribute it and/or modify it
    68.9 + * under the terms of the GNU General Public License version 2 only, as
   68.10 + * published by the Free Software Foundation.
   68.11 + *
   68.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   68.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   68.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   68.15 + * version 2 for more details (a copy is included in the LICENSE file that
   68.16 + * accompanied this code).
   68.17 + *
   68.18 + * You should have received a copy of the GNU General Public License version
   68.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   68.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   68.21 + *
   68.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   68.23 + * or visit www.oracle.com if you need additional information or have any
   68.24 + * questions.
   68.25 + */
   68.26 +
   68.27 +/*
   68.28 + * @test
   68.29 + * @bug 6930507
   68.30 + * @summary Symbols for anonymous and local classes made too late for use by java tree API
   68.31 + */
   68.32 +
   68.33 +import java.io.*;
   68.34 +import java.util.*;
   68.35 +import javax.annotation.processing.*;
   68.36 +import javax.lang.model.SourceVersion;
   68.37 +import javax.lang.model.element.*;
   68.38 +import javax.tools.Diagnostic;
   68.39 +import static javax.lang.model.util.ElementFilter.*;
   68.40 +
   68.41 +import com.sun.source.tree.*;
   68.42 +import com.sun.source.util.*;
   68.43 +
   68.44 +@SupportedOptions({"test", "last"})
   68.45 +@SupportedAnnotationTypes("*")
   68.46 +public class TestGetElement extends AbstractProcessor {
   68.47 +    public static void main(String... args) throws Exception {
   68.48 +        new TestGetElement().run();
   68.49 +    }
   68.50 +
   68.51 +    public TestGetElement() { }
   68.52 +
   68.53 +    public void run() throws Exception {
   68.54 +        final String testSrc = System.getProperty("test.src");
   68.55 +        final String testClasses = System.getProperty("test.classes");
   68.56 +        final String myClassName = getClass().getName();
   68.57 +        final String mySrc = new File(testSrc, myClassName + ".java").getPath();
   68.58 +
   68.59 +        final int NUM_TESTS = 90; // #decls in this source file
   68.60 +        for (int i = 1; i <= NUM_TESTS; i++) {
   68.61 +            System.err.println("test " + i);
   68.62 +            File testDir = new File("test" + i);
   68.63 +            File classesDir = new File(testDir, "classes");
   68.64 +            classesDir.mkdirs();
   68.65 +            String[] args = {
   68.66 +                "-d", classesDir.getPath(),
   68.67 +                "-processorpath", testClasses,
   68.68 +                "-processor", myClassName,
   68.69 +                "-proc:only",
   68.70 +                "-Atest=" + i,
   68.71 +                "-Alast=" + (i == NUM_TESTS),
   68.72 +                mySrc
   68.73 +            };
   68.74 +
   68.75 +//            System.err.println("compile: " + Arrays.asList(args));
   68.76 +
   68.77 +            StringWriter sw = new StringWriter();
   68.78 +            PrintWriter pw = new PrintWriter(sw);
   68.79 +            int rc = com.sun.tools.javac.Main.compile(args, pw);
   68.80 +            pw.close();
   68.81 +            String out = sw.toString();
   68.82 +            if (out != null)
   68.83 +                System.err.println(out);
   68.84 +            if (rc != 0) {
   68.85 +                System.err.println("compilation failed: rc=" + rc);
   68.86 +                errors++;
   68.87 +            }
   68.88 +        }
   68.89 +
   68.90 +        if (errors > 0)
   68.91 +            throw new Exception(errors + " errors occurred");
   68.92 +    }
   68.93 +
   68.94 +
   68.95 +    int errors;
   68.96 +
   68.97 +    public boolean process(Set<? extends TypeElement> annotations,
   68.98 +                           RoundEnvironment roundEnvironment)
   68.99 +    {
  68.100 +        if (roundEnvironment.processingOver())
  68.101 +            return true;
  68.102 +
  68.103 +        Map<String,String> options = processingEnv.getOptions();
  68.104 +        int test = Integer.parseInt(options.get("test"));
  68.105 +        boolean _last = Boolean.parseBoolean(options.get("last"));
  68.106 +
  68.107 +        Trees trees = Trees.instance(processingEnv);
  68.108 +        Scanner scanner = new Scanner(trees, _last);
  68.109 +        int nelems = 0;
  68.110 +        for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
  68.111 +            nelems += scanner.scan(trees.getPath(e), test);
  68.112 +        }
  68.113 +
  68.114 +        Messager m = processingEnv.getMessager();
  68.115 +        int EXPECT = 1;
  68.116 +        if (nelems != EXPECT) {
  68.117 +            m.printMessage(Diagnostic.Kind.ERROR,
  68.118 +                    "Unexpected number of elements found: " + nelems + " expected: " + EXPECT);
  68.119 +        }
  68.120 +        return true;
  68.121 +    }
  68.122 +
  68.123 +    @Override
  68.124 +    public SourceVersion getSupportedSourceVersion() {
  68.125 +        return SourceVersion.latest();
  68.126 +    }
  68.127 +
  68.128 +    class Scanner extends TreePathScanner<Integer,Integer> {
  68.129 +        final Trees trees;
  68.130 +        final boolean last;
  68.131 +        int count;
  68.132 +
  68.133 +        Scanner(Trees trees, boolean last) {
  68.134 +            this.trees = trees;
  68.135 +            this.last = last;
  68.136 +        }
  68.137 +
  68.138 +        @Override
  68.139 +        public Integer visitClass(ClassTree tree, Integer test) {
  68.140 +            return reduce(check(test), super.visitClass(tree, test));
  68.141 +        }
  68.142 +
  68.143 +        @Override
  68.144 +        public Integer visitMethod(MethodTree tree, Integer test) {
  68.145 +            return reduce(check(test), super.visitMethod(tree, test));
  68.146 +        }
  68.147 +
  68.148 +        @Override
  68.149 +        public Integer visitVariable(VariableTree tree, Integer test) {
  68.150 +            return reduce(check(test), super.visitVariable(tree, test));
  68.151 +        }
  68.152 +
  68.153 +        @Override
  68.154 +        public Integer reduce(Integer i1, Integer i2) {
  68.155 +            if (i1 == null || i1.intValue() == 0)
  68.156 +                return i2;
  68.157 +            if (i2 == null || i2.intValue() == 0)
  68.158 +                return i1;
  68.159 +            return (i1 + i2);
  68.160 +        }
  68.161 +
  68.162 +        int check(int test) {
  68.163 +            count++;
  68.164 +
  68.165 +            if (count != test)
  68.166 +                return 0;
  68.167 +
  68.168 +            TreePath p = getCurrentPath();
  68.169 +            Element e = trees.getElement(p);
  68.170 +
  68.171 +            String text = p.getLeaf().toString().replaceAll("\\s+", " ").trim();
  68.172 +            int MAXLEN = 40;
  68.173 +            if (text.length() > MAXLEN)
  68.174 +                text = text.substring(0, MAXLEN - 3) + "...";
  68.175 +
  68.176 +            System.err.println(String.format("%3d: %-" + MAXLEN + "s -- %s",
  68.177 +                    count, text,
  68.178 +                    (e == null ? "null" : e.getKind() + " " + e)));
  68.179 +
  68.180 +            Messager m = processingEnv.getMessager();
  68.181 +            if (e == null) {
  68.182 +                m.printMessage(Diagnostic.Kind.ERROR, "Null element found for " + text);
  68.183 +                return 0;
  68.184 +            }
  68.185 +
  68.186 +            if (last && !e.getSimpleName().contentEquals("last")) {
  68.187 +                m.printMessage(Diagnostic.Kind.ERROR, "Unexpected name in last test: "
  68.188 +                        + e.getSimpleName() + ", expected: last");
  68.189 +            }
  68.190 +
  68.191 +            return 1;
  68.192 +        }
  68.193 +    }
  68.194 +
  68.195 +    // following are all fodder for the test
  68.196 +
  68.197 +    class MemberClass {
  68.198 +        class NestedMemberClass { }
  68.199 +    }
  68.200 +
  68.201 +    {
  68.202 +        class InnerClassInInit { }
  68.203 +        Object o = new Object() { };
  68.204 +    }
  68.205 +
  68.206 +    TestGetElement(TestGetElement unused) {
  68.207 +        class InnerClassInConstr { }
  68.208 +        Object o = new Object() { };
  68.209 +    }
  68.210 +
  68.211 +    void m() {
  68.212 +        class InnerClassInMethod { }
  68.213 +        Object o = new Object() { };
  68.214 +
  68.215 +        class C {
  68.216 +            class MemberClass {
  68.217 +                class NestedMemberClass { }
  68.218 +            }
  68.219 +
  68.220 +            {
  68.221 +                class InnerClassInInit { }
  68.222 +                Object o = new Object() { };
  68.223 +            }
  68.224 +
  68.225 +            C(Object unused) {
  68.226 +                class InnerClassInConstr { }
  68.227 +                Object o = new Object() { };
  68.228 +            }
  68.229 +
  68.230 +            void m() {
  68.231 +                class InnerClassInMethod { }
  68.232 +                Object o = new Object() { };
  68.233 +            }
  68.234 +        }
  68.235 +    }
  68.236 +
  68.237 +    int last; // this name is verified by the test to make sure that all decls are checked
  68.238 +}
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/test/tools/javac/api/ToolProvider/HelloWorldTest.java	Tue Sep 07 15:49:48 2010 -0700
    69.3 @@ -0,0 +1,83 @@
    69.4 +/*
    69.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    69.7 + *
    69.8 + * This code is free software; you can redistribute it and/or modify it
    69.9 + * under the terms of the GNU General Public License version 2 only, as
   69.10 + * published by the Free Software Foundation.
   69.11 + *
   69.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   69.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   69.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   69.15 + * version 2 for more details (a copy is included in the LICENSE file that
   69.16 + * accompanied this code).
   69.17 + *
   69.18 + * You should have received a copy of the GNU General Public License version
   69.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   69.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   69.21 + *
   69.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   69.23 + * or visit www.oracle.com if you need additional information or have any
   69.24 + * questions.
   69.25 + */
   69.26 +
   69.27 +/*
   69.28 + * @test
   69.29 + * @bug 6604599
   69.30 + * @summary ToolProvider should be less compiler-specific
   69.31 + */
   69.32 +
   69.33 +import java.io.*;
   69.34 +import java.util.*;
   69.35 +
   69.36 +// verify that running a simple program, such as this one, does not trigger
   69.37 +// the loading of ToolProvider or any com.sun.tools.javac class
   69.38 +public class HelloWorldTest {
   69.39 +    public static void main(String... args) throws Exception {
   69.40 +        if (args.length > 0) {
   69.41 +            System.err.println(Arrays.asList(args));
   69.42 +            return;
   69.43 +        }
   69.44 +
   69.45 +        new HelloWorldTest().run();
   69.46 +    }
   69.47 +
   69.48 +    void run() throws Exception {
   69.49 +        File javaHome = new File(System.getProperty("java.home"));
   69.50 +        if (javaHome.getName().equals("jre"))
   69.51 +            javaHome = javaHome.getParentFile();
   69.52 +        File javaExe = new File(new File(javaHome, "bin"), "java");
   69.53 +        String classpath = System.getProperty("java.class.path");
   69.54 +
   69.55 +        String[] cmd = {
   69.56 +            javaExe.getPath(),
   69.57 +            "-verbose:class",
   69.58 +            "-classpath", classpath,
   69.59 +            HelloWorldTest.class.getName(),
   69.60 +            "Hello", "World"
   69.61 +        };
   69.62 +
   69.63 +        ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
   69.64 +        Process p = pb.start();
   69.65 +        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
   69.66 +        String line;
   69.67 +        while ((line = r.readLine()) != null) {
   69.68 +            System.err.println(line);
   69.69 +            if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac."))
   69.70 +                error(">>> " + line);
   69.71 +        }
   69.72 +        int rc = p.waitFor();
   69.73 +        if (rc != 0)
   69.74 +            error("Unexpected exit code: " + rc);
   69.75 +
   69.76 +        if (errors > 0)
   69.77 +            throw new Exception(errors + " errors occurred");
   69.78 +    }
   69.79 +
   69.80 +    void error(String msg) {
   69.81 +        System.err.println(msg);
   69.82 +        errors++;
   69.83 +    }
   69.84 +
   69.85 +    int errors;
   69.86 +}
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/test/tools/javac/api/ToolProvider/ToolProviderTest1.java	Tue Sep 07 15:49:48 2010 -0700
    70.3 @@ -0,0 +1,82 @@
    70.4 +/*
    70.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    70.7 + *
    70.8 + * This code is free software; you can redistribute it and/or modify it
    70.9 + * under the terms of the GNU General Public License version 2 only, as
   70.10 + * published by the Free Software Foundation.
   70.11 + *
   70.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   70.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   70.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   70.15 + * version 2 for more details (a copy is included in the LICENSE file that
   70.16 + * accompanied this code).
   70.17 + *
   70.18 + * You should have received a copy of the GNU General Public License version
   70.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   70.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   70.21 + *
   70.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   70.23 + * or visit www.oracle.com if you need additional information or have any
   70.24 + * questions.
   70.25 + */
   70.26 +
   70.27 +/*
   70.28 + * @test
   70.29 + * @bug 6604599
   70.30 + * @summary ToolProvider should be less compiler-specific
   70.31 + */
   70.32 +
   70.33 +import java.io.*;
   70.34 +
   70.35 +// verify that running accessing ToolProvider by itself does not
   70.36 +// trigger loading com.sun.tools.javac.*
   70.37 +public class ToolProviderTest1 {
   70.38 +    public static void main(String... args) throws Exception {
   70.39 +        if (args.length > 0) {
   70.40 +            System.err.println(Class.forName(args[0], true, null));
   70.41 +            return;
   70.42 +        }
   70.43 +
   70.44 +        new ToolProviderTest1().run();
   70.45 +    }
   70.46 +
   70.47 +    void run() throws Exception {
   70.48 +        File javaHome = new File(System.getProperty("java.home"));
   70.49 +        if (javaHome.getName().equals("jre"))
   70.50 +            javaHome = javaHome.getParentFile();
   70.51 +        File javaExe = new File(new File(javaHome, "bin"), "java");
   70.52 +        String classpath = System.getProperty("java.class.path");
   70.53 +
   70.54 +        String[] cmd = {
   70.55 +            javaExe.getPath(),
   70.56 +            "-verbose:class",
   70.57 +            "-classpath", classpath,
   70.58 +            ToolProviderTest1.class.getName(),
   70.59 +            "javax.tools.ToolProvider"
   70.60 +        };
   70.61 +
   70.62 +        ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
   70.63 +        Process p = pb.start();
   70.64 +        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
   70.65 +        String line;
   70.66 +        while ((line = r.readLine()) != null) {
   70.67 +            System.err.println(line);
   70.68 +            if (line.contains("com.sun.tools.javac."))
   70.69 +                error(">>> " + line);
   70.70 +        }
   70.71 +        int rc = p.waitFor();
   70.72 +        if (rc != 0)
   70.73 +            error("Unexpected exit code: " + rc);
   70.74 +
   70.75 +        if (errors > 0)
   70.76 +            throw new Exception(errors + " errors occurred");
   70.77 +    }
   70.78 +
   70.79 +    void error(String msg) {
   70.80 +        System.err.println(msg);
   70.81 +        errors++;
   70.82 +    }
   70.83 +
   70.84 +    int errors;
   70.85 +}
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/test/tools/javac/api/ToolProvider/ToolProviderTest2.java	Tue Sep 07 15:49:48 2010 -0700
    71.3 @@ -0,0 +1,87 @@
    71.4 +/*
    71.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    71.7 + *
    71.8 + * This code is free software; you can redistribute it and/or modify it
    71.9 + * under the terms of the GNU General Public License version 2 only, as
   71.10 + * published by the Free Software Foundation.
   71.11 + *
   71.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   71.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   71.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   71.15 + * version 2 for more details (a copy is included in the LICENSE file that
   71.16 + * accompanied this code).
   71.17 + *
   71.18 + * You should have received a copy of the GNU General Public License version
   71.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   71.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   71.21 + *
   71.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   71.23 + * or visit www.oracle.com if you need additional information or have any
   71.24 + * questions.
   71.25 + */
   71.26 +
   71.27 +/*
   71.28 + * @test
   71.29 + * @bug 6604599
   71.30 + * @summary ToolProvider should be less compiler-specific
   71.31 + */
   71.32 +
   71.33 +import java.io.*;
   71.34 +import javax.tools.*;
   71.35 +
   71.36 +// control for ToolProviderTest1 -- verify that using ToolProvider to
   71.37 +// access the compiler does trigger loading com.sun.tools.javac.*
   71.38 +public class ToolProviderTest2 {
   71.39 +    public static void main(String... args) throws Exception {
   71.40 +        if (args.length > 0) {
   71.41 +            System.err.println(ToolProvider.getSystemJavaCompiler());
   71.42 +            return;
   71.43 +        }
   71.44 +
   71.45 +        new ToolProviderTest2().run();
   71.46 +    }
   71.47 +
   71.48 +    void run() throws Exception {
   71.49 +        File javaHome = new File(System.getProperty("java.home"));
   71.50 +        if (javaHome.getName().equals("jre"))
   71.51 +            javaHome = javaHome.getParentFile();
   71.52 +        File javaExe = new File(new File(javaHome, "bin"), "java");
   71.53 +        String classpath = System.getProperty("java.class.path");
   71.54 +
   71.55 +        String[] cmd = {
   71.56 +            javaExe.getPath(),
   71.57 +            "-verbose:class",
   71.58 +            "-classpath", classpath,
   71.59 +            ToolProviderTest2.class.getName(),
   71.60 +            "javax.tools.ToolProvider"
   71.61 +        };
   71.62 +
   71.63 +        ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
   71.64 +        Process p = pb.start();
   71.65 +        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
   71.66 +        String line;
   71.67 +        boolean found = false;
   71.68 +        while ((line = r.readLine()) != null) {
   71.69 +            System.err.println(line);
   71.70 +            if (line.contains("com.sun.tools.javac."))
   71.71 +                found = true;
   71.72 +        }
   71.73 +        int rc = p.waitFor();
   71.74 +        if (rc != 0)
   71.75 +            error("Unexpected exit code: " + rc);
   71.76 +
   71.77 +        if (!found)
   71.78 +            System.err.println("expected class name not found");
   71.79 +
   71.80 +        if (errors > 0)
   71.81 +            throw new Exception(errors + " errors occurred");
   71.82 +    }
   71.83 +
   71.84 +    void error(String msg) {
   71.85 +        System.err.println(msg);
   71.86 +        errors++;
   71.87 +    }
   71.88 +
   71.89 +    int errors;
   71.90 +}
    72.1 --- a/test/tools/javac/diags/examples.not-yet.txt	Tue Sep 07 15:14:49 2010 -0700
    72.2 +++ b/test/tools/javac/diags/examples.not-yet.txt	Tue Sep 07 15:49:48 2010 -0700
    72.3 @@ -62,6 +62,7 @@
    72.4  compiler.misc.fatal.err.cant.locate.ctor                # Resolve, from Lower
    72.5  compiler.misc.fatal.err.cant.locate.field               # Resolve, from Lower
    72.6  compiler.misc.fatal.err.cant.locate.meth                # Resolve, from Lower
    72.7 +compiler.misc.fatal.err.cant.close.loader               # JavacProcessingEnvironment
    72.8  compiler.misc.file.does.not.contain.package
    72.9  compiler.misc.illegal.start.of.class.file
   72.10  compiler.misc.inferred.do.not.conform.to.params         # UNUSED (hard to see if very complex inference scenario might require this though, so leaving it in, as per JLS3)
   72.11 @@ -113,3 +114,4 @@
   72.12  compiler.warn.unchecked.assign                          # DEAD, replaced by compiler.misc.unchecked.assign
   72.13  compiler.warn.unchecked.cast.to.type                    # DEAD, replaced by compiler.misc.unchecked.cast.to.type
   72.14  compiler.warn.unexpected.archive.file                   # Paths: zip file with unknown extn
   72.15 +compiler.warn.wrong.target.for.polymorphic.signature.definition     # Transitional 292
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/test/tools/javac/diags/examples/TypeParameterOnPolymorphicSignature.java	Tue Sep 07 15:49:48 2010 -0700
    73.3 @@ -0,0 +1,31 @@
    73.4 +/*
    73.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    73.7 + *
    73.8 + * This code is free software; you can redistribute it and/or modify it
    73.9 + * under the terms of the GNU General Public License version 2 only, as
   73.10 + * published by the Free Software Foundation.
   73.11 + *
   73.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   73.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   73.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   73.15 + * version 2 for more details (a copy is included in the LICENSE file that
   73.16 + * accompanied this code).
   73.17 + *
   73.18 + * You should have received a copy of the GNU General Public License version
   73.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   73.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   73.21 + *
   73.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   73.23 + * or visit www.oracle.com if you need additional information or have any
   73.24 + * questions.
   73.25 + */
   73.26 +
   73.27 +// key: compiler.warn.type.parameter.on.polymorphic.signature
   73.28 +// key: compiler.err.unreported.exception.need.to.catch.or.throw
   73.29 +
   73.30 +import java.dyn.InvokeDynamic;
   73.31 +
   73.32 +class TypeParameterOnPolymorphicSignature {
   73.33 +    { InvokeDynamic.<void>call("",123); }
   73.34 +}
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/test/tools/javac/diags/examples/UnsupportedExoticID.java	Tue Sep 07 15:49:48 2010 -0700
    74.3 @@ -0,0 +1,31 @@
    74.4 +/*
    74.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    74.7 + *
    74.8 + * This code is free software; you can redistribute it and/or modify it
    74.9 + * under the terms of the GNU General Public License version 2 only, as
   74.10 + * published by the Free Software Foundation.
   74.11 + *
   74.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   74.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   74.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   74.15 + * version 2 for more details (a copy is included in the LICENSE file that
   74.16 + * accompanied this code).
   74.17 + *
   74.18 + * You should have received a copy of the GNU General Public License version
   74.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   74.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   74.21 + *
   74.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   74.23 + * or visit www.oracle.com if you need additional information or have any
   74.24 + * questions.
   74.25 + */
   74.26 +
   74.27 +// key: compiler.err.unsupported.exotic.id
   74.28 +// options: -source 6
   74.29 +
   74.30 +class UnsupportedExoticID {
   74.31 +    void m() {
   74.32 +        Object #"Hello!" = null;
   74.33 +    }
   74.34 +}
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/test/tools/javac/failover/CheckAttributedTree.java	Tue Sep 07 15:49:48 2010 -0700
    75.3 @@ -0,0 +1,775 @@
    75.4 +/*
    75.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    75.7 + *
    75.8 + * This code is free software; you can redistribute it and/or modify it
    75.9 + * under the terms of the GNU General Public License version 2 only, as
   75.10 + * published by the Free Software Foundation.
   75.11 + *
   75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   75.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   75.15 + * version 2 for more details (a copy is included in the LICENSE file that
   75.16 + * accompanied this code).
   75.17 + *
   75.18 + * You should have received a copy of the GNU General Public License version
   75.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   75.21 + *
   75.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   75.23 + * or visit www.oracle.com if you need additional information or have any
   75.24 + * questions.
   75.25 + */
   75.26 +
   75.27 +import com.sun.source.util.TaskEvent;
   75.28 +import java.awt.BorderLayout;
   75.29 +import java.awt.Color;
   75.30 +import java.awt.Dimension;
   75.31 +import java.awt.EventQueue;
   75.32 +import java.awt.Font;
   75.33 +import java.awt.GridBagConstraints;
   75.34 +import java.awt.GridBagLayout;
   75.35 +import java.awt.Rectangle;
   75.36 +import java.awt.event.ActionEvent;
   75.37 +import java.awt.event.ActionListener;
   75.38 +import java.awt.event.MouseAdapter;
   75.39 +import java.awt.event.MouseEvent;
   75.40 +import javax.swing.DefaultComboBoxModel;
   75.41 +import javax.swing.JComboBox;
   75.42 +import javax.swing.JComponent;
   75.43 +import javax.swing.JFrame;
   75.44 +import javax.swing.JLabel;
   75.45 +import javax.swing.JPanel;
   75.46 +import javax.swing.JScrollPane;
   75.47 +import javax.swing.JTextArea;
   75.48 +import javax.swing.JTextField;
   75.49 +import javax.swing.SwingUtilities;
   75.50 +import javax.swing.event.CaretEvent;
   75.51 +import javax.swing.event.CaretListener;
   75.52 +import javax.swing.text.BadLocationException;
   75.53 +import javax.swing.text.DefaultHighlighter;
   75.54 +import javax.swing.text.Highlighter;
   75.55 +import java.io.File;
   75.56 +import java.io.IOException;
   75.57 +import java.io.PrintStream;
   75.58 +import java.io.PrintWriter;
   75.59 +import java.io.StringWriter;
   75.60 +import java.lang.reflect.Field;
   75.61 +import java.lang.reflect.Modifier;
   75.62 +import java.nio.charset.Charset;
   75.63 +import java.util.ArrayList;
   75.64 +import java.util.HashMap;
   75.65 +import java.util.List;
   75.66 +import java.util.Map;
   75.67 +import javax.tools.Diagnostic;
   75.68 +import javax.tools.DiagnosticListener;
   75.69 +import javax.tools.JavaFileObject;
   75.70 +import javax.tools.StandardJavaFileManager;
   75.71 +
   75.72 +import com.sun.source.tree.CompilationUnitTree;
   75.73 +import com.sun.source.util.JavacTask;
   75.74 +import com.sun.source.util.TaskListener;
   75.75 +import com.sun.tools.javac.api.JavacTool;
   75.76 +import com.sun.tools.javac.code.Symbol;
   75.77 +import com.sun.tools.javac.code.Type;
   75.78 +import com.sun.tools.javac.tree.JCTree;
   75.79 +import com.sun.tools.javac.tree.JCTree.JCClassDecl;
   75.80 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
   75.81 +import com.sun.tools.javac.tree.JCTree.JCImport;
   75.82 +import com.sun.tools.javac.tree.TreeInfo;
   75.83 +import com.sun.tools.javac.tree.TreeScanner;
   75.84 +import com.sun.tools.javac.util.Pair;
   75.85 +
   75.86 +import java.util.Arrays;
   75.87 +import java.util.HashSet;
   75.88 +import java.util.Set;
   75.89 +import javax.lang.model.element.Element;
   75.90 +
   75.91 +/**
   75.92 + * Utility and test program to check validity of tree positions for tree nodes.
   75.93 + * The program can be run standalone, or as a jtreg test.  In standalone mode,
   75.94 + * errors can be displayed in a gui viewer. For info on command line args,
   75.95 + * run program with no args.
   75.96 + *
   75.97 + * <p>
   75.98 + * jtreg: Note that by using the -r switch in the test description below, this test
   75.99 + * will process all java files in the langtools/test directory, thus implicitly
  75.100 + * covering any new language features that may be tested in this test suite.
  75.101 + */
  75.102 +
  75.103 +/*
  75.104 + * @test
  75.105 + * @bug 6970584
  75.106 + * @summary assorted position errors in compiler syntax trees
  75.107 + * @run main CheckAttributedTree -q -r -et ERRONEOUS .
  75.108 + */
  75.109 +public class CheckAttributedTree {
  75.110 +    /**
  75.111 +     * Main entry point.
  75.112 +     * If test.src is set, program runs in jtreg mode, and will throw an Error
  75.113 +     * if any errors arise, otherwise System.exit will be used, unless the gui
  75.114 +     * viewer is being used. In jtreg mode, the default base directory for file
  75.115 +     * args is the value of ${test.src}. In jtreg mode, the -r option can be
  75.116 +     * given to change the default base directory to the root test directory.
  75.117 +     */
  75.118 +    public static void main(String... args) {
  75.119 +        String testSrc = System.getProperty("test.src");
  75.120 +        File baseDir = (testSrc == null) ? null : new File(testSrc);
  75.121 +        boolean ok = new CheckAttributedTree().run(baseDir, args);
  75.122 +        if (!ok) {
  75.123 +            if (testSrc != null)  // jtreg mode
  75.124 +                throw new Error("failed");
  75.125 +            else
  75.126 +                System.exit(1);
  75.127 +        }
  75.128 +    }
  75.129 +
  75.130 +    /**
  75.131 +     * Run the program. A base directory can be provided for file arguments.
  75.132 +     * In jtreg mode, the -r option can be given to change the default base
  75.133 +     * directory to the test root directory. For other options, see usage().
  75.134 +     * @param baseDir base directory for any file arguments.
  75.135 +     * @param args command line args
  75.136 +     * @return true if successful or in gui mode
  75.137 +     */
  75.138 +    boolean run(File baseDir, String... args) {
  75.139 +        if (args.length == 0) {
  75.140 +            usage(System.out);
  75.141 +            return true;
  75.142 +        }
  75.143 +
  75.144 +        List<File> files = new ArrayList<File>();
  75.145 +        for (int i = 0; i < args.length; i++) {
  75.146 +            String arg = args[i];
  75.147 +            if (arg.equals("-encoding") && i + 1 < args.length)
  75.148 +                encoding = args[++i];
  75.149 +            else if (arg.equals("-gui"))
  75.150 +                gui = true;
  75.151 +            else if (arg.equals("-q"))
  75.152 +                quiet = true;
  75.153 +            else if (arg.equals("-v"))
  75.154 +                verbose = true;
  75.155 +            else if (arg.equals("-t") && i + 1 < args.length)
  75.156 +                tags.add(args[++i]);
  75.157 +            else if (arg.equals("-ef") && i + 1 < args.length)
  75.158 +                excludeFiles.add(new File(baseDir, args[++i]));
  75.159 +            else if (arg.equals("-et") && i + 1 < args.length)
  75.160 +                excludeTags.add(args[++i]);
  75.161 +            else if (arg.equals("-r")) {
  75.162 +                if (excludeFiles.size() > 0)
  75.163 +                    throw new Error("-r must be used before -ef");
  75.164 +                File d = baseDir;
  75.165 +                while (!new File(d, "TEST.ROOT").exists()) {
  75.166 +                    if (d == null)
  75.167 +                        throw new Error("cannot find TEST.ROOT");
  75.168 +                    d = d.getParentFile();
  75.169 +                }
  75.170 +                baseDir = d;
  75.171 +            }
  75.172 +            else if (arg.startsWith("-"))
  75.173 +                throw new Error("unknown option: " + arg);
  75.174 +            else {
  75.175 +                while (i < args.length)
  75.176 +                    files.add(new File(baseDir, args[i++]));
  75.177 +            }
  75.178 +        }
  75.179 +
  75.180 +        for (File file: files) {
  75.181 +            if (file.exists())
  75.182 +                test(file);
  75.183 +            else
  75.184 +                error("File not found: " + file);
  75.185 +        }
  75.186 +
  75.187 +        if (fileCount != 1)
  75.188 +            System.err.println(fileCount + " files read");
  75.189 +        if (errors > 0)
  75.190 +            System.err.println(errors + " errors");
  75.191 +
  75.192 +        return (gui || errors == 0);
  75.193 +    }
  75.194 +
  75.195 +    /**
  75.196 +     * Print command line help.
  75.197 +     * @param out output stream
  75.198 +     */
  75.199 +    void usage(PrintStream out) {
  75.200 +        out.println("Usage:");
  75.201 +        out.println("  java CheckAttributedTree options... files...");
  75.202 +        out.println("");
  75.203 +        out.println("where options include:");
  75.204 +        out.println("-q        Quiet: don't report on inapplicable files");
  75.205 +        out.println("-gui      Display returns in a GUI viewer");
  75.206 +        out.println("-v        Verbose: report on files as they are being read");
  75.207 +        out.println("-t tag    Limit checks to tree nodes with this tag");
  75.208 +        out.println("          Can be repeated if desired");
  75.209 +        out.println("-ef file  Exclude file or directory");
  75.210 +        out.println("-et tag   Exclude tree nodes with given tag name");
  75.211 +        out.println("");
  75.212 +        out.println("files may be directories or files");
  75.213 +        out.println("directories will be scanned recursively");
  75.214 +        out.println("non java files, or java files which cannot be parsed, will be ignored");
  75.215 +        out.println("");
  75.216 +    }
  75.217 +
  75.218 +    /**
  75.219 +     * Test a file. If the file is a directory, it will be recursively scanned
  75.220 +     * for java files.
  75.221 +     * @param file the file or directory to test
  75.222 +     */
  75.223 +    void test(File file) {
  75.224 +        if (excludeFiles.contains(file)) {
  75.225 +            if (!quiet)
  75.226 +                error("File " + file + " excluded");
  75.227 +            return;
  75.228 +        }
  75.229 +
  75.230 +        if (file.isDirectory()) {
  75.231 +            for (File f: file.listFiles()) {
  75.232 +                test(f);
  75.233 +            }
  75.234 +            return;
  75.235 +        }
  75.236 +
  75.237 +        if (file.isFile() && file.getName().endsWith(".java")) {
  75.238 +            try {
  75.239 +                if (verbose)
  75.240 +                    System.err.println(file);
  75.241 +                fileCount++;
  75.242 +                NPETester p = new NPETester();
  75.243 +                p.test(read(file));
  75.244 +            } catch (AttributionException e) {
  75.245 +                if (!quiet) {
  75.246 +                    error("Error attributing " + file + "\n" + e.getMessage());
  75.247 +                }
  75.248 +            } catch (IOException e) {
  75.249 +                error("Error reading " + file + ": " + e);
  75.250 +            }
  75.251 +            return;
  75.252 +        }
  75.253 +
  75.254 +        if (!quiet)
  75.255 +            error("File " + file + " ignored");
  75.256 +    }
  75.257 +
  75.258 +    /**
  75.259 +     * Read a file.
  75.260 +     * @param file the file to be read
  75.261 +     * @return the tree for the content of the file
  75.262 +     * @throws IOException if any IO errors occur
  75.263 +     * @throws TreePosTest.ParseException if any errors occur while parsing the file
  75.264 +     */
  75.265 +    List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
  75.266 +        StringWriter sw = new StringWriter();
  75.267 +        PrintWriter pw = new PrintWriter(sw);
  75.268 +        Reporter r = new Reporter(pw);
  75.269 +        JavacTool tool = JavacTool.create();
  75.270 +        Charset cs = (encoding == null ? null : Charset.forName(encoding));
  75.271 +        StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
  75.272 +        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
  75.273 +        String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
  75.274 +        JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
  75.275 +        final List<Element> analyzedElems = new ArrayList<>();
  75.276 +        task.setTaskListener(new TaskListener() {
  75.277 +            public void started(TaskEvent e) {
  75.278 +                if (e.getKind() == TaskEvent.Kind.ANALYZE)
  75.279 +                        analyzedElems.add(e.getTypeElement());
  75.280 +            }
  75.281 +            public void finished(TaskEvent e) { }
  75.282 +        });
  75.283 +
  75.284 +        try {
  75.285 +            Iterable<? extends CompilationUnitTree> trees = task.parse();
  75.286 +            task.analyze();
  75.287 +            List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>();
  75.288 +            System.out.println("Try to add pairs. Elems are " + analyzedElems);
  75.289 +            for (CompilationUnitTree t : trees) {
  75.290 +               JCCompilationUnit cu = (JCCompilationUnit)t;
  75.291 +               for (JCTree def : cu.defs) {
  75.292 +                   if (def.getTag() == JCTree.CLASSDEF &&
  75.293 +                           analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) {
  75.294 +                       System.out.println("Adding pair...");
  75.295 +                       res.add(new Pair<>(cu, def));
  75.296 +                   }
  75.297 +               }
  75.298 +            }
  75.299 +            return res;
  75.300 +        }
  75.301 +        catch (Throwable t) {
  75.302 +            throw new AttributionException("Exception while attributing file: " + file);
  75.303 +        }
  75.304 +    }
  75.305 +
  75.306 +    /**
  75.307 +     * Report an error. When the program is complete, the program will either
  75.308 +     * exit or throw an Error if any errors have been reported.
  75.309 +     * @param msg the error message
  75.310 +     */
  75.311 +    void error(String msg) {
  75.312 +        System.err.println(msg);
  75.313 +        errors++;
  75.314 +    }
  75.315 +
  75.316 +    /** Number of files that have been analyzed. */
  75.317 +    int fileCount;
  75.318 +    /** Number of errors reported. */
  75.319 +    int errors;
  75.320 +    /** Flag: don't report irrelevant files. */
  75.321 +    boolean quiet;
  75.322 +    /** Flag: show errors in GUI viewer. */
  75.323 +    boolean gui;
  75.324 +    /** The GUI viewer for errors. */
  75.325 +    Viewer viewer;
  75.326 +    /** Flag: report files as they are processed. */
  75.327 +    boolean verbose;
  75.328 +    /** Option: encoding for test files. */
  75.329 +    String encoding;
  75.330 +    /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes
  75.331 +     * are analyzed. */
  75.332 +    Set<String> tags = new HashSet<String>();
  75.333 +    /** Set of files and directories to be excluded from analysis. */
  75.334 +    Set<File> excludeFiles = new HashSet<File>();
  75.335 +    /** Set of tag names to be excluded from analysis. */
  75.336 +    Set<String> excludeTags = new HashSet<String>();
  75.337 +    /** Utility class for trees */
  75.338 +    TreeUtil treeUtil = new TreeUtil();
  75.339 +
  75.340 +    /**
  75.341 +     * Main class for testing assertions concerning types/symbol
  75.342 +     * left uninitialized after attribution
  75.343 +     */
  75.344 +    private class NPETester extends TreeScanner {
  75.345 +        void test(List<Pair<JCCompilationUnit, JCTree>> trees) {
  75.346 +            for (Pair<JCCompilationUnit, JCTree> p : trees) {
  75.347 +                sourcefile = p.fst.sourcefile;
  75.348 +                endPosTable = p.fst.endPositions;
  75.349 +                encl = new Info(p.snd, endPosTable);
  75.350 +                p.snd.accept(this);
  75.351 +            }
  75.352 +        }
  75.353 +
  75.354 +        @Override
  75.355 +        public void scan(JCTree tree) {
  75.356 +            if (tree == null ||
  75.357 +                    excludeTags.contains(treeUtil.nameFromTag(tree.getTag()))) {
  75.358 +                return;
  75.359 +            }
  75.360 +
  75.361 +            Info self = new Info(tree, endPosTable);
  75.362 +            check(!mandatoryType(tree) ||
  75.363 +                    (tree.type != null &&
  75.364 +                    checkFields(tree)),
  75.365 +                    "'null' found in tree ",
  75.366 +                    self);
  75.367 +
  75.368 +            Info prevEncl = encl;
  75.369 +            encl = self;
  75.370 +            tree.accept(this);
  75.371 +            encl = prevEncl;
  75.372 +        }
  75.373 +
  75.374 +        private boolean mandatoryType(JCTree that) {
  75.375 +            return that instanceof JCTree.JCExpression ||
  75.376 +                    that.getTag() == JCTree.VARDEF ||
  75.377 +                    that.getTag() == JCTree.METHODDEF ||
  75.378 +                    that.getTag() == JCTree.CLASSDEF;
  75.379 +        }
  75.380 +
  75.381 +        private final List<String> excludedFields = Arrays.asList("varargsElement");
  75.382 +
  75.383 +        void check(boolean ok, String label, Info self) {
  75.384 +            if (!ok) {
  75.385 +                if (gui) {
  75.386 +                    if (viewer == null)
  75.387 +                        viewer = new Viewer();
  75.388 +                    viewer.addEntry(sourcefile, label, encl, self);
  75.389 +                }
  75.390 +                error(label + self.toString() + " encl: " + encl.toString() + " in file: " + sourcefile + "  " + self.tree);
  75.391 +            }
  75.392 +        }
  75.393 +
  75.394 +        boolean checkFields(JCTree t) {
  75.395 +            List<Field> fieldsToCheck = treeUtil.getFieldsOfType(t,
  75.396 +                    excludedFields,
  75.397 +                    Symbol.class,
  75.398 +                    Type.class);
  75.399 +            for (Field f : fieldsToCheck) {
  75.400 +                try {
  75.401 +                    if (f.get(t) == null) {
  75.402 +                        return false;
  75.403 +                    }
  75.404 +                }
  75.405 +                catch (IllegalAccessException e) {
  75.406 +                    System.err.println("Cannot read field: " + f);
  75.407 +                    //swallow it
  75.408 +                }
  75.409 +            }
  75.410 +            return true;
  75.411 +        }
  75.412 +
  75.413 +        @Override
  75.414 +        public void visitImport(JCImport tree) { }
  75.415 +
  75.416 +        @Override
  75.417 +        public void visitTopLevel(JCCompilationUnit tree) {
  75.418 +            scan(tree.defs);
  75.419 +        }
  75.420 +
  75.421 +        JavaFileObject sourcefile;
  75.422 +        Map<JCTree, Integer> endPosTable;
  75.423 +        Info encl;
  75.424 +    }
  75.425 +
  75.426 +    /**
  75.427 +     * Utility class providing easy access to position and other info for a tree node.
  75.428 +     */
  75.429 +    private class Info {
  75.430 +        Info() {
  75.431 +            tree = null;
  75.432 +            tag = JCTree.ERRONEOUS;
  75.433 +            start = 0;
  75.434 +            pos = 0;
  75.435 +            end = Integer.MAX_VALUE;
  75.436 +        }
  75.437 +
  75.438 +        Info(JCTree tree, Map<JCTree, Integer> endPosTable) {
  75.439 +            this.tree = tree;
  75.440 +            tag = tree.getTag();
  75.441 +            start = TreeInfo.getStartPos(tree);
  75.442 +            pos = tree.pos;
  75.443 +            end = TreeInfo.getEndPos(tree, endPosTable);
  75.444 +        }
  75.445 +
  75.446 +        @Override
  75.447 +        public String toString() {
  75.448 +            return treeUtil.nameFromTag(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]";
  75.449 +        }
  75.450 +
  75.451 +        final JCTree tree;
  75.452 +        final int tag;
  75.453 +        final int start;
  75.454 +        final int pos;
  75.455 +        final int end;
  75.456 +    }
  75.457 +
  75.458 +    /**
  75.459 +     * Names for tree tags.
  75.460 +     * javac does not provide an API to convert tag values to strings, so this class uses
  75.461 +     * reflection to determine names of public static final int values in JCTree.
  75.462 +     */
  75.463 +    private static class TreeUtil {
  75.464 +        String nameFromTag(int tag) {
  75.465 +            if (names == null) {
  75.466 +                names = new HashMap<Integer, String>();
  75.467 +                Class c = JCTree.class;
  75.468 +                for (Field f : c.getDeclaredFields()) {
  75.469 +                    if (f.getType().equals(int.class)) {
  75.470 +                        int mods = f.getModifiers();
  75.471 +                        if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) {
  75.472 +                            try {
  75.473 +                                names.put(f.getInt(null), f.getName());
  75.474 +                            } catch (IllegalAccessException e) {
  75.475 +                            }
  75.476 +                        }
  75.477 +                    }
  75.478 +                }
  75.479 +            }
  75.480 +            String name = names.get(tag);
  75.481 +            return (name == null) ? "??" : name;
  75.482 +        }
  75.483 +
  75.484 +        List<Field> getFieldsOfType(JCTree t, List<String> excludeNames, Class<?>... types) {
  75.485 +            List<Field> buf = new ArrayList<Field>();
  75.486 +            for (Field f : t.getClass().getDeclaredFields()) {
  75.487 +                if (!excludeNames.contains(f.getName())) {
  75.488 +                    for (Class<?> type : types) {
  75.489 +                        if (type.isAssignableFrom(f.getType())) {
  75.490 +                            f.setAccessible(true);
  75.491 +                            buf.add(f);
  75.492 +                            break;
  75.493 +                        }
  75.494 +                    }
  75.495 +                }
  75.496 +            }
  75.497 +            return buf;
  75.498 +        }
  75.499 +
  75.500 +        private Map<Integer, String> names;
  75.501 +    }
  75.502 +
  75.503 +    /**
  75.504 +     * Thrown when errors are found parsing a java file.
  75.505 +     */
  75.506 +    private static class ParseException extends Exception {
  75.507 +        ParseException(String msg) {
  75.508 +            super(msg);
  75.509 +        }
  75.510 +    }
  75.511 +
  75.512 +    private static class AttributionException extends Exception {
  75.513 +        AttributionException(String msg) {
  75.514 +            super(msg);
  75.515 +        }
  75.516 +    }
  75.517 +
  75.518 +    /**
  75.519 +     * DiagnosticListener to report diagnostics and count any errors that occur.
  75.520 +     */
  75.521 +    private static class Reporter implements DiagnosticListener<JavaFileObject> {
  75.522 +        Reporter(PrintWriter out) {
  75.523 +            this.out = out;
  75.524 +        }
  75.525 +
  75.526 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  75.527 +            out.println(diagnostic);
  75.528 +            switch (diagnostic.getKind()) {
  75.529 +                case ERROR:
  75.530 +                    errors++;
  75.531 +            }
  75.532 +        }
  75.533 +        int errors;
  75.534 +        PrintWriter out;
  75.535 +    }
  75.536 +
  75.537 +    /**
  75.538 +     * GUI viewer for issues found by TreePosTester. The viewer provides a drop
  75.539 +     * down list for selecting error conditions, a header area providing details
  75.540 +     * about an error, and a text area with the ranges of text highlighted as
  75.541 +     * appropriate.
  75.542 +     */
  75.543 +    private class Viewer extends JFrame {
  75.544 +        /**
  75.545 +         * Create a viewer.
  75.546 +         */
  75.547 +        Viewer() {
  75.548 +            initGUI();
  75.549 +        }
  75.550 +
  75.551 +        /**
  75.552 +         * Add another entry to the list of errors.
  75.553 +         * @param file The file containing the error
  75.554 +         * @param check The condition that was being tested, and which failed
  75.555 +         * @param encl the enclosing tree node
  75.556 +         * @param self the tree node containing the error
  75.557 +         */
  75.558 +        void addEntry(JavaFileObject file, String check, Info encl, Info self) {
  75.559 +            Entry e = new Entry(file, check, encl, self);
  75.560 +            DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
  75.561 +            m.addElement(e);
  75.562 +            if (m.getSize() == 1)
  75.563 +                entries.setSelectedItem(e);
  75.564 +        }
  75.565 +
  75.566 +        /**
  75.567 +         * Initialize the GUI window.
  75.568 +         */
  75.569 +        private void initGUI() {
  75.570 +            JPanel head = new JPanel(new GridBagLayout());
  75.571 +            GridBagConstraints lc = new GridBagConstraints();
  75.572 +            GridBagConstraints fc = new GridBagConstraints();
  75.573 +            fc.anchor = GridBagConstraints.WEST;
  75.574 +            fc.fill = GridBagConstraints.HORIZONTAL;
  75.575 +            fc.gridwidth = GridBagConstraints.REMAINDER;
  75.576 +
  75.577 +            entries = new JComboBox();
  75.578 +            entries.addActionListener(new ActionListener() {
  75.579 +                public void actionPerformed(ActionEvent e) {
  75.580 +                    showEntry((Entry) entries.getSelectedItem());
  75.581 +                }
  75.582 +            });
  75.583 +            fc.insets.bottom = 10;
  75.584 +            head.add(entries, fc);
  75.585 +            fc.insets.bottom = 0;
  75.586 +            head.add(new JLabel("check:"), lc);
  75.587 +            head.add(checkField = createTextField(80), fc);
  75.588 +            fc.fill = GridBagConstraints.NONE;
  75.589 +            head.add(setBackground(new JLabel("encl:"), enclColor), lc);
  75.590 +            head.add(enclPanel = new InfoPanel(), fc);
  75.591 +            head.add(setBackground(new JLabel("self:"), selfColor), lc);
  75.592 +            head.add(selfPanel = new InfoPanel(), fc);
  75.593 +            add(head, BorderLayout.NORTH);
  75.594 +
  75.595 +            body = new JTextArea();
  75.596 +            body.setFont(Font.decode(Font.MONOSPACED));
  75.597 +            body.addCaretListener(new CaretListener() {
  75.598 +                public void caretUpdate(CaretEvent e) {
  75.599 +                    int dot = e.getDot();
  75.600 +                    int mark = e.getMark();
  75.601 +                    if (dot == mark)
  75.602 +                        statusText.setText("dot: " + dot);
  75.603 +                    else
  75.604 +                        statusText.setText("dot: " + dot + ", mark:" + mark);
  75.605 +                }
  75.606 +            });
  75.607 +            JScrollPane p = new JScrollPane(body,
  75.608 +                    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  75.609 +                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  75.610 +            p.setPreferredSize(new Dimension(640, 480));
  75.611 +            add(p, BorderLayout.CENTER);
  75.612 +
  75.613 +            statusText = createTextField(80);
  75.614 +            add(statusText, BorderLayout.SOUTH);
  75.615 +
  75.616 +            pack();
  75.617 +            setLocationRelativeTo(null); // centered on screen
  75.618 +            setVisible(true);
  75.619 +            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  75.620 +        }
  75.621 +
  75.622 +        /** Show an entry that has been selected. */
  75.623 +        private void showEntry(Entry e) {
  75.624 +            try {
  75.625 +                // update simple fields
  75.626 +                setTitle(e.file.getName());
  75.627 +                checkField.setText(e.check);
  75.628 +                enclPanel.setInfo(e.encl);
  75.629 +                selfPanel.setInfo(e.self);
  75.630 +                // show file text with highlights
  75.631 +                body.setText(e.file.getCharContent(true).toString());
  75.632 +                Highlighter highlighter = body.getHighlighter();
  75.633 +                highlighter.removeAllHighlights();
  75.634 +                addHighlight(highlighter, e.encl, enclColor);
  75.635 +                addHighlight(highlighter, e.self, selfColor);
  75.636 +                scroll(body, getMinPos(enclPanel.info, selfPanel.info));
  75.637 +            } catch (IOException ex) {
  75.638 +                body.setText("Cannot read " + e.file.getName() + ": " + e);
  75.639 +            }
  75.640 +        }
  75.641 +
  75.642 +        /** Create a test field. */
  75.643 +        private JTextField createTextField(int width) {
  75.644 +            JTextField f = new JTextField(width);
  75.645 +            f.setEditable(false);
  75.646 +            f.setBorder(null);
  75.647 +            return f;
  75.648 +        }
  75.649 +
  75.650 +        /** Add a highlighted region based on the positions in an Info object. */
  75.651 +        private void addHighlight(Highlighter h, Info info, Color c) {
  75.652 +            int start = info.start;
  75.653 +            int end = info.end;
  75.654 +            if (start == -1 && end == -1)
  75.655 +                return;
  75.656 +            if (start == -1)
  75.657 +                start = end;
  75.658 +            if (end == -1)
  75.659 +                end = start;
  75.660 +            try {
  75.661 +                h.addHighlight(info.start, info.end,
  75.662 +                        new DefaultHighlighter.DefaultHighlightPainter(c));
  75.663 +                if (info.pos != -1) {
  75.664 +                    Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
  75.665 +                    h.addHighlight(info.pos, info.pos + 1,
  75.666 +                        new DefaultHighlighter.DefaultHighlightPainter(c2));
  75.667 +                }
  75.668 +            } catch (BadLocationException e) {
  75.669 +                e.printStackTrace();
  75.670 +            }
  75.671 +        }
  75.672 +
  75.673 +        /** Get the minimum valid position in a set of info objects. */
  75.674 +        private int getMinPos(Info... values) {
  75.675 +            int i = Integer.MAX_VALUE;
  75.676 +            for (Info info: values) {
  75.677 +                if (info.start >= 0) i = Math.min(i, info.start);
  75.678 +                if (info.pos   >= 0) i = Math.min(i, info.pos);
  75.679 +                if (info.end   >= 0) i = Math.min(i, info.end);
  75.680 +            }
  75.681 +            return (i == Integer.MAX_VALUE) ? 0 : i;
  75.682 +        }
  75.683 +
  75.684 +        /** Set the background on a component. */
  75.685 +        private JComponent setBackground(JComponent comp, Color c) {
  75.686 +            comp.setOpaque(true);
  75.687 +            comp.setBackground(c);
  75.688 +            return comp;
  75.689 +        }
  75.690 +
  75.691 +        /** Scroll a text area to display a given position near the middle of the visible area. */
  75.692 +        private void scroll(final JTextArea t, final int pos) {
  75.693 +            // Using invokeLater appears to give text a chance to sort itself out
  75.694 +            // before the scroll happens; otherwise scrollRectToVisible doesn't work.
  75.695 +            // Maybe there's a better way to sync with the text...
  75.696 +            EventQueue.invokeLater(new Runnable() {
  75.697 +                public void run() {
  75.698 +                    try {
  75.699 +                        Rectangle r = t.modelToView(pos);
  75.700 +                        JScrollPane p = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, t);
  75.701 +                        r.y = Math.max(0, r.y - p.getHeight() * 2 / 5);
  75.702 +                        r.height += p.getHeight() * 4 / 5;
  75.703 +                        t.scrollRectToVisible(r);
  75.704 +                    } catch (BadLocationException ignore) {
  75.705 +                    }
  75.706 +                }
  75.707 +            });
  75.708 +        }
  75.709 +
  75.710 +        private JComboBox entries;
  75.711 +        private JTextField checkField;
  75.712 +        private InfoPanel enclPanel;
  75.713 +        private InfoPanel selfPanel;
  75.714 +        private JTextArea body;
  75.715 +        private JTextField statusText;
  75.716 +
  75.717 +        private Color selfColor = new Color(0.f, 1.f, 0.f, 0.2f); // 20% green
  75.718 +        private Color enclColor = new Color(1.f, 0.f, 0.f, 0.2f); // 20% red
  75.719 +
  75.720 +        /** Panel to display an Info object. */
  75.721 +        private class InfoPanel extends JPanel {
  75.722 +            InfoPanel() {
  75.723 +                add(tagName = createTextField(20));
  75.724 +                add(new JLabel("start:"));
  75.725 +                add(addListener(start = createTextField(6)));
  75.726 +                add(new JLabel("pos:"));
  75.727 +                add(addListener(pos = createTextField(6)));
  75.728 +                add(new JLabel("end:"));
  75.729 +                add(addListener(end = createTextField(6)));
  75.730 +            }
  75.731 +
  75.732 +            void setInfo(Info info) {
  75.733 +                this.info = info;
  75.734 +                tagName.setText(treeUtil.nameFromTag(info.tag));
  75.735 +                start.setText(String.valueOf(info.start));
  75.736 +                pos.setText(String.valueOf(info.pos));
  75.737 +                end.setText(String.valueOf(info.end));
  75.738 +            }
  75.739 +
  75.740 +            JTextField addListener(final JTextField f) {
  75.741 +                f.addMouseListener(new MouseAdapter() {
  75.742 +                    @Override
  75.743 +                    public void mouseClicked(MouseEvent e) {
  75.744 +                        body.setCaretPosition(Integer.valueOf(f.getText()));
  75.745 +                        body.getCaret().setVisible(true);
  75.746 +                    }
  75.747 +                });
  75.748 +                return f;
  75.749 +            }
  75.750 +
  75.751 +            Info info;
  75.752 +            JTextField tagName;
  75.753 +            JTextField start;
  75.754 +            JTextField pos;
  75.755 +            JTextField end;
  75.756 +        }
  75.757 +
  75.758 +        /** Object to record information about an error to be displayed. */
  75.759 +        private class Entry {
  75.760 +            Entry(JavaFileObject file, String check, Info encl, Info self) {
  75.761 +                this.file = file;
  75.762 +                this.check = check;
  75.763 +                this.encl = encl;
  75.764 +                this.self= self;
  75.765 +            }
  75.766 +
  75.767 +            @Override
  75.768 +            public String toString() {
  75.769 +                return file.getName() + " " + check + " " + getMinPos(encl, self);
  75.770 +            }
  75.771 +
  75.772 +            final JavaFileObject file;
  75.773 +            final String check;
  75.774 +            final Info encl;
  75.775 +            final Info self;
  75.776 +        }
  75.777 +    }
  75.778 +}
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/test/tools/javac/failover/FailOver01.java	Tue Sep 07 15:49:48 2010 -0700
    76.3 @@ -0,0 +1,10 @@
    76.4 +/*
    76.5 +  * @test /nodynamiccopyright/
    76.6 + * @bug 6970584
    76.7 + * @summary Flow.java should be more error-friendly
    76.8 + * @author mcimadamore
    76.9 + *
   76.10 + * @compile/fail/ref=FailOver01.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver01.java
   76.11 + */
   76.12 +
   76.13 +class Test { { x = "" } }
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/test/tools/javac/failover/FailOver01.out	Tue Sep 07 15:49:48 2010 -0700
    77.3 @@ -0,0 +1,3 @@
    77.4 +FailOver01.java:10:22: compiler.err.expected: ';'
    77.5 +FailOver01.java:10:16: compiler.err.cant.resolve.location: kindname.variable, x, , , kindname.class, Test
    77.6 +2 errors
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/test/tools/javac/failover/FailOver02.java	Tue Sep 07 15:49:48 2010 -0700
    78.3 @@ -0,0 +1,14 @@
    78.4 +/*
    78.5 + * @test /nodynamiccopyright/
    78.6 + * @bug 6970584
    78.7 + * @summary Flow.java should be more error-friendly
    78.8 + * @author mcimadamore
    78.9 + *
   78.10 + * @compile/fail/ref=FailOver02.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver02.java
   78.11 + */
   78.12 +
   78.13 +class Test implements AutoCloseable {
   78.14 +    void test() {
   78.15 +        try(Test t = null) {}
   78.16 +    }
   78.17 +}
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/test/tools/javac/failover/FailOver02.out	Tue Sep 07 15:49:48 2010 -0700
    79.3 @@ -0,0 +1,3 @@
    79.4 +FailOver02.java:10:1: compiler.err.does.not.override.abstract: Test, close(), java.lang.AutoCloseable
    79.5 +FailOver02.java:12:9: compiler.err.cant.resolve.location.args: kindname.method, close, , , kindname.class, Test
    79.6 +2 errors
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/test/tools/javac/failover/FailOver03.java	Tue Sep 07 15:49:48 2010 -0700
    80.3 @@ -0,0 +1,12 @@
    80.4 +/*
    80.5 + * @test /nodynamiccopyright/
    80.6 + * @bug 6970584
    80.7 + * @summary Flow.java should be more error-friendly
    80.8 + * @author mcimadamore
    80.9 + *
   80.10 + * @compile/fail/ref=FailOver03.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver03.java
   80.11 + */
   80.12 +
   80.13 +class Test extends Test {
   80.14 +   Test i;
   80.15 +}
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/test/tools/javac/failover/FailOver03.out	Tue Sep 07 15:49:48 2010 -0700
    81.3 @@ -0,0 +1,2 @@
    81.4 +FailOver03.java:10:1: compiler.err.cyclic.inheritance: Test
    81.5 +1 error
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/test/tools/javac/failover/FailOver04.java	Tue Sep 07 15:49:48 2010 -0700
    82.3 @@ -0,0 +1,12 @@
    82.4 +/*
    82.5 + * @test /nodynamiccopyright/
    82.6 + * @bug 6970584
    82.7 + * @summary Flow.java should be more error-friendly
    82.8 + * @author mcimadamore
    82.9 + *
   82.10 + * @compile/fail/ref=FailOver04.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver04.java
   82.11 + */
   82.12 +
   82.13 +class Test {
   82.14 +   { new Unknown() {}; }
   82.15 +}
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/test/tools/javac/failover/FailOver04.out	Tue Sep 07 15:49:48 2010 -0700
    83.3 @@ -0,0 +1,2 @@
    83.4 +FailOver04.java:11:10: compiler.err.cant.resolve.location: kindname.class, Unknown, , , kindname.class, Test
    83.5 +1 error
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/test/tools/javac/failover/FailOver05.java	Tue Sep 07 15:49:48 2010 -0700
    84.3 @@ -0,0 +1,12 @@
    84.4 +/*
    84.5 + * @test /nodynamiccopyright/
    84.6 + * @bug 6970584
    84.7 + * @summary Flow.java should be more error-friendly
    84.8 + * @author mcimadamore
    84.9 + *
   84.10 + * @compile/fail/ref=FailOver05.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver05.java
   84.11 + */
   84.12 +
   84.13 +class Test extends Test {
   84.14 +   { for ( Integer x : null) {} }
   84.15 +}
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/test/tools/javac/failover/FailOver05.out	Tue Sep 07 15:49:48 2010 -0700
    85.3 @@ -0,0 +1,2 @@
    85.4 +FailOver05.java:10:1: compiler.err.cyclic.inheritance: Test
    85.5 +1 error
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/test/tools/javac/failover/FailOver06.java	Tue Sep 07 15:49:48 2010 -0700
    86.3 @@ -0,0 +1,13 @@
    86.4 +/*
    86.5 + * @test /nodynamiccopyright/
    86.6 + * @bug 6970584
    86.7 + * @summary Flow.java should be more error-friendly
    86.8 + * @author mcimadamore
    86.9 + *
   86.10 + * @compile/fail/ref=FailOver06.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver06.java
   86.11 + */
   86.12 +
   86.13 +class Test extends Test {
   86.14 +    Inference x = 1;
   86.15 +    { if (x == 1) { } else { } }
   86.16 +}
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/test/tools/javac/failover/FailOver06.out	Tue Sep 07 15:49:48 2010 -0700
    87.3 @@ -0,0 +1,2 @@
    87.4 +FailOver06.java:10:1: compiler.err.cyclic.inheritance: Test
    87.5 +1 error
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/test/tools/javac/failover/FailOver07.java	Tue Sep 07 15:49:48 2010 -0700
    88.3 @@ -0,0 +1,13 @@
    88.4 +/*
    88.5 + * @test /nodynamiccopyright/
    88.6 + * @bug 6970584
    88.7 + * @summary Flow.java should be more error-friendly
    88.8 + * @author mcimadamore
    88.9 + *
   88.10 + * @compile/fail/ref=FailOver07.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver07.java
   88.11 + */
   88.12 +
   88.13 +class Test extends Test {
   88.14 +    Integer x = 1;
   88.15 +    { do {} while (x); }
   88.16 +}
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/test/tools/javac/failover/FailOver07.out	Tue Sep 07 15:49:48 2010 -0700
    89.3 @@ -0,0 +1,2 @@
    89.4 +FailOver07.java:10:1: compiler.err.cyclic.inheritance: Test
    89.5 +1 error
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/test/tools/javac/failover/FailOver08.java	Tue Sep 07 15:49:48 2010 -0700
    90.3 @@ -0,0 +1,13 @@
    90.4 +/*
    90.5 + * @test /nodynamiccopyright/
    90.6 + * @bug 6970584
    90.7 + * @summary Flow.java should be more error-friendly
    90.8 + * @author mcimadamore
    90.9 + *
   90.10 + * @compile/fail/ref=FailOver08.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver08.java
   90.11 + */
   90.12 +
   90.13 +class Test extends Test {
   90.14 +    Integer x = 1;
   90.15 +    { while (x) {}; }
   90.16 +}
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/test/tools/javac/failover/FailOver08.out	Tue Sep 07 15:49:48 2010 -0700
    91.3 @@ -0,0 +1,2 @@
    91.4 +FailOver08.java:10:1: compiler.err.cyclic.inheritance: Test
    91.5 +1 error
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/test/tools/javac/failover/FailOver09.java	Tue Sep 07 15:49:48 2010 -0700
    92.3 @@ -0,0 +1,13 @@
    92.4 +/*
    92.5 + * @test /nodynamiccopyright/
    92.6 + * @bug 6970584
    92.7 + * @summary Flow.java should be more error-friendly
    92.8 + * @author mcimadamore
    92.9 + *
   92.10 + * @compile/fail/ref=FailOver09.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver09.java
   92.11 + */
   92.12 +
   92.13 +class Test extends Test {
   92.14 +    Integer x = 1;
   92.15 +    { for (x = 0 ; x ; x++) {}; }
   92.16 +}
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/test/tools/javac/failover/FailOver09.out	Tue Sep 07 15:49:48 2010 -0700
    93.3 @@ -0,0 +1,2 @@
    93.4 +FailOver09.java:10:1: compiler.err.cyclic.inheritance: Test
    93.5 +1 error
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/test/tools/javac/failover/FailOver10.java	Tue Sep 07 15:49:48 2010 -0700
    94.3 @@ -0,0 +1,15 @@
    94.4 +/*
    94.5 + * @test /nodynamiccopyright/
    94.6 + * @bug 6970584
    94.7 + * @summary Flow.java should be more error-friendly
    94.8 + * @author mcimadamore
    94.9 + *
   94.10 + * @compile/fail/ref=FailOver10.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver10.java
   94.11 + */
   94.12 +
   94.13 +class Test extends Test {
   94.14 +
   94.15 +    boolean cond;
   94.16 +
   94.17 +    { Object o = null; }
   94.18 +}
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/test/tools/javac/failover/FailOver10.out	Tue Sep 07 15:49:48 2010 -0700
    95.3 @@ -0,0 +1,2 @@
    95.4 +FailOver10.java:10:1: compiler.err.cyclic.inheritance: Test
    95.5 +1 error
    96.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.2 +++ b/test/tools/javac/failover/FailOver11.java	Tue Sep 07 15:49:48 2010 -0700
    96.3 @@ -0,0 +1,17 @@
    96.4 +/*
    96.5 + * @test /nodynamiccopyright/
    96.6 + * @bug 6970584
    96.7 + * @summary Flow.java should be more error-friendly
    96.8 + * @author mcimadamore
    96.9 + *
   96.10 + * @compile/fail/ref=FailOver11.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver11.java
   96.11 + */
   96.12 +
   96.13 +class Test extends Test {
   96.14 +
   96.15 +    boolean cond;
   96.16 +
   96.17 +    void m(Object o) {}
   96.18 +
   96.19 +    { m(cond ? null : null); }
   96.20 +}
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/test/tools/javac/failover/FailOver11.out	Tue Sep 07 15:49:48 2010 -0700
    97.3 @@ -0,0 +1,2 @@
    97.4 +FailOver11.java:10:1: compiler.err.cyclic.inheritance: Test
    97.5 +1 error
    98.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.2 +++ b/test/tools/javac/failover/FailOver12.java	Tue Sep 07 15:49:48 2010 -0700
    98.3 @@ -0,0 +1,15 @@
    98.4 +/*
    98.5 + * @test /nodynamiccopyright/
    98.6 + * @bug 6970584
    98.7 + * @summary Flow.java should be more error-friendly
    98.8 + * @author mcimadamore
    98.9 + *
   98.10 + * @compile/fail/ref=FailOver12.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver12.java
   98.11 + */
   98.12 +
   98.13 +class Test extends Test {
   98.14 +
   98.15 +    Integer x = 1;
   98.16 +
   98.17 +    { try {} catch (Exception e) {} }
   98.18 +}
    99.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.2 +++ b/test/tools/javac/failover/FailOver12.out	Tue Sep 07 15:49:48 2010 -0700
    99.3 @@ -0,0 +1,2 @@
    99.4 +FailOver12.java:10:1: compiler.err.cyclic.inheritance: Test
    99.5 +1 error
   100.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.2 +++ b/test/tools/javac/failover/FailOver13.java	Tue Sep 07 15:49:48 2010 -0700
   100.3 @@ -0,0 +1,15 @@
   100.4 +/*
   100.5 + * @test /nodynamiccopyright/
   100.6 + * @bug 6970584
   100.7 + * @summary Flow.java should be more error-friendly
   100.8 + * @author mcimadamore
   100.9 + *
  100.10 + * @compile/fail/ref=FailOver13.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver13.java
  100.11 + */
  100.12 +
  100.13 +class Test extends Test {
  100.14 +
  100.15 +    Integer x = 1;
  100.16 +
  100.17 +    { x = (Object)o; }
  100.18 +}
   101.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.2 +++ b/test/tools/javac/failover/FailOver13.out	Tue Sep 07 15:49:48 2010 -0700
   101.3 @@ -0,0 +1,2 @@
   101.4 +FailOver13.java:10:1: compiler.err.cyclic.inheritance: Test
   101.5 +1 error
   102.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.2 +++ b/test/tools/javac/failover/FailOver14.java	Tue Sep 07 15:49:48 2010 -0700
   102.3 @@ -0,0 +1,14 @@
   102.4 +/*
   102.5 + * @test /nodynamiccopyright/
   102.6 + * @bug 6970584
   102.7 + * @summary Flow.java should be more error-friendly
   102.8 + * @author mcimadamore
   102.9 + *
  102.10 + * @compile/fail/ref=FailOver14.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver14.java
  102.11 + */
  102.12 +
  102.13 +class Test extends Test  {
  102.14 +
  102.15 +   { for (Integer x : !x) { } }
  102.16 +
  102.17 +}
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/test/tools/javac/failover/FailOver14.out	Tue Sep 07 15:49:48 2010 -0700
   103.3 @@ -0,0 +1,2 @@
   103.4 +FailOver14.java:10:1: compiler.err.cyclic.inheritance: Test
   103.5 +1 error
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/test/tools/javac/generics/OverrideBridge.java	Tue Sep 07 15:49:48 2010 -0700
   104.3 @@ -0,0 +1,163 @@
   104.4 +/*
   104.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   104.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   104.7 + *
   104.8 + * This code is free software; you can redistribute it and/or modify it
   104.9 + * under the terms of the GNU General Public License version 2 only, as
  104.10 + * published by the Free Software Foundation.
  104.11 + *
  104.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  104.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  104.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  104.15 + * version 2 for more details (a copy is included in the LICENSE file that
  104.16 + * accompanied this code).
  104.17 + *
  104.18 + * You should have received a copy of the GNU General Public License version
  104.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  104.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  104.21 + *
  104.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  104.23 + * or visit www.oracle.com if you need additional information or have any
  104.24 + * questions.
  104.25 + */
  104.26 +
  104.27 +/*
  104.28 + * @test
  104.29 + * @bug 6337171
  104.30 + * @summary  javac should create bridge methods when type variable bounds restricted
  104.31 + * @run main OverrideBridge
  104.32 + */
  104.33 +
  104.34 +import java.io.*;
  104.35 +import java.net.URI;
  104.36 +import java.util.ArrayList;
  104.37 +import java.util.Arrays;
  104.38 +import java.util.List;
  104.39 +import java.util.Map;
  104.40 +import java.util.HashMap;
  104.41 +import javax.tools.JavaCompiler;
  104.42 +import javax.tools.JavaFileObject;
  104.43 +import javax.tools.SimpleJavaFileObject;
  104.44 +import javax.tools.ToolProvider;
  104.45 +
  104.46 +import com.sun.source.util.JavacTask;
  104.47 +import com.sun.tools.classfile.ClassFile;
  104.48 +import com.sun.tools.classfile.ConstantPoolException;
  104.49 +import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
  104.50 +import com.sun.tools.classfile.Method;
  104.51 +
  104.52 +public class OverrideBridge {
  104.53 +
  104.54 +    enum Implementation {
  104.55 +        IMPLICIT(""),
  104.56 +        EXPLICIT("@Override public abstract X m(X x);");
  104.57 +
  104.58 +        String impl;
  104.59 +
  104.60 +        Implementation(String impl) {
  104.61 +            this.impl = impl;
  104.62 +        }
  104.63 +    }
  104.64 +
  104.65 +    static class JavaSource extends SimpleJavaFileObject {
  104.66 +
  104.67 +        final static String sourceStub =
  104.68 +                        "abstract class A<X> {\n" +
  104.69 +                        "   public abstract X m(X x);\n" +
  104.70 +                        "}\n" +
  104.71 +                        "interface I<X> {\n" +
  104.72 +                        "X m(X x);\n" +
  104.73 +                        "}\n" +
  104.74 +                        "abstract class B<X extends B<X>> extends A<X> implements I<X> { #B }\n" +
  104.75 +                        "abstract class C<X extends C<X>> extends B<X>  { #C }\n" +
  104.76 +                        "abstract class D<X extends D<X>> extends C<X>  { #D }\n";
  104.77 +
  104.78 +        String source;
  104.79 +
  104.80 +        public JavaSource(Implementation implB, Implementation implC, Implementation implD) {
  104.81 +            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
  104.82 +            source = sourceStub.replace("#B", implB.impl).replace("#C", implC.impl).replace("#D", implD.impl);
  104.83 +        }
  104.84 +
  104.85 +        @Override
  104.86 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
  104.87 +            return source;
  104.88 +        }
  104.89 +    }
  104.90 +
  104.91 +    public static void main(String... args) throws Exception {
  104.92 +        Map<ClassFile, List<Method>> refMembers =
  104.93 +                compile(Implementation.EXPLICIT, Implementation.EXPLICIT, Implementation.EXPLICIT, "ref");
  104.94 +        int i = 0;
  104.95 +        for (Implementation implB : Implementation.values()) {
  104.96 +            for (Implementation implC : Implementation.values()) {
  104.97 +                for (Implementation implD : Implementation.values()) {
  104.98 +                    Map<ClassFile, List<Method>> membersToCheck = compile(implB, implC, implD, "out_" + i++);
  104.99 +                    check(refMembers, membersToCheck);
 104.100 +                }
 104.101 +            }
 104.102 +        }
 104.103 +    }
 104.104 +
 104.105 +    static String workDir = System.getProperty("user.dir");
 104.106 +
 104.107 +    static Map<ClassFile, List<Method>> compile(Implementation implB, Implementation implC, Implementation implD, String destPath) throws Exception {
 104.108 +        File destDir = new File(workDir, destPath); destDir.mkdir();
 104.109 +        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
 104.110 +        JavaSource source = new JavaSource(implB, implC, implD);
 104.111 +        JavacTask ct = (JavacTask)tool.getTask(null, null, null,
 104.112 +                Arrays.asList("-d", destPath), null, Arrays.asList(source));
 104.113 +        ct.generate();
 104.114 +        Map<ClassFile, List<Method>> members = new HashMap<>();
 104.115 +        addMembers(destDir, members);
 104.116 +        return members;
 104.117 +    }
 104.118 +
 104.119 +    static void addMembers(File destDir, Map<ClassFile, List<Method>> members) {
 104.120 +        String[] names = { "B.class", "C.class", "D.class" };
 104.121 +        try {
 104.122 +            for (String name : names) {
 104.123 +                File f = new File(destDir, name);
 104.124 +                ClassFile cf = ClassFile.read(f);
 104.125 +                members.put(cf, readMethod(cf, "m"));
 104.126 +            }
 104.127 +        } catch (Exception e) {
 104.128 +            e.printStackTrace();
 104.129 +            throw new Error("error reading classes");
 104.130 +        }
 104.131 +    }
 104.132 +
 104.133 +    static List<Method> readMethod(ClassFile cf, String name) throws ConstantPoolException {
 104.134 +        List<Method> buf = new ArrayList<>();
 104.135 +        for (Method m : cf.methods) {
 104.136 +            if (m.getName(cf.constant_pool).equals(name)) {
 104.137 +                buf.add(m);
 104.138 +            }
 104.139 +        }
 104.140 +        return buf;
 104.141 +    }
 104.142 +
 104.143 +    static void check(Map<ClassFile, List<Method>> refMembers, Map<ClassFile, List<Method>> membersToCheck) throws ConstantPoolException, InvalidDescriptor {
 104.144 +        for (Map.Entry<ClassFile, List<Method>> ref : refMembers.entrySet()) {
 104.145 +            ClassFile cRef = ref.getKey();
 104.146 +            for (Method mRef : ref.getValue()) {
 104.147 +                boolean ok = false;
 104.148 +                for (Map.Entry<ClassFile, List<Method>> toCheck : membersToCheck.entrySet()) {
 104.149 +                    ClassFile cToCheck = toCheck.getKey();
 104.150 +                    for (Method mToCheck : toCheck.getValue()) {
 104.151 +                        if (cRef.getName().equals(cToCheck.getName()) &&
 104.152 +                                mRef.descriptor.getReturnType(cRef.constant_pool).equals(
 104.153 +                                mToCheck.descriptor.getReturnType(cToCheck.constant_pool)) &&
 104.154 +                                mRef.descriptor.getParameterTypes(cRef.constant_pool).equals(
 104.155 +                                mToCheck.descriptor.getParameterTypes(cToCheck.constant_pool))) {
 104.156 +                            ok = true;
 104.157 +                        }
 104.158 +                    }
 104.159 +                }
 104.160 +                if (!ok) {
 104.161 +                    throw new AssertionError("Matching method descriptor for " + mRef.descriptor.getParameterTypes(cRef.constant_pool) + "not found");
 104.162 +                }
 104.163 +            }
 104.164 +        }
 104.165 +    }
 104.166 +}
   105.1 --- a/test/tools/javac/meth/InvokeDyn.java	Tue Sep 07 15:14:49 2010 -0700
   105.2 +++ b/test/tools/javac/meth/InvokeDyn.java	Tue Sep 07 15:49:48 2010 -0700
   105.3 @@ -1,5 +1,5 @@
   105.4  /*
   105.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
   105.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
   105.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   105.8   *
   105.9   * This code is free software; you can redistribute it and/or modify it
  105.10 @@ -23,12 +23,12 @@
  105.11  
  105.12  /*
  105.13   * @test
  105.14 - * @bug 6754038
  105.15 + * @bug 6754038 6979327
  105.16   * @summary Generate call sites for method handle
  105.17   * @author jrose
  105.18   *
  105.19   * @library ..
  105.20 - * @compile -source 7 -target 7 InvokeDyn.java
  105.21 + * @compile -source 7 -target 7 -XDinvokedynamic -XDallowTransitionalJSR292=no InvokeDyn.java
  105.22   */
  105.23  //No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn
  105.24  
  105.25 @@ -44,16 +44,21 @@
  105.26  
  105.27  package meth;
  105.28  
  105.29 -import java.dyn.InvokeDynamic;
  105.30 +import java.dyn.*;
  105.31  
  105.32  public class InvokeDyn {
  105.33 +    class CS extends CallSite {
  105.34 +        CS(Object x, Object y, Object z) { throw new RuntimeException(); }
  105.35 +    }
  105.36 +    //@BootstrapMethod(CS.class)  //note: requires 6964498
  105.37      void test() throws Throwable {
  105.38          Object x = "hello";
  105.39 -        InvokeDynamic.greet(x, "world", 123);
  105.40 -        InvokeDynamic.greet(x, "mundus", 456);
  105.41 -        InvokeDynamic.greet(x, "kosmos", 789);
  105.42 -        InvokeDynamic.<String>cogitate(10.11121, 3.14);
  105.43 -        InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
  105.44 -        InvokeDynamic.<int>invoke("goodbye");
  105.45 +        Object ojunk; int ijunk;
  105.46 +        ojunk = InvokeDynamic.greet(x, "world", 123);
  105.47 +        ojunk = InvokeDynamic.greet(x, "mundus", 456);
  105.48 +        ojunk = InvokeDynamic.greet(x, "kosmos", 789);
  105.49 +        ojunk = (String) InvokeDynamic.cogitate(10.11121, 3.14);
  105.50 +        InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
  105.51 +        ijunk = (int) InvokeDynamic.invoke("goodbye");
  105.52      }
  105.53  }
   106.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.2 +++ b/test/tools/javac/meth/InvokeDynTrans.java	Tue Sep 07 15:49:48 2010 -0700
   106.3 @@ -0,0 +1,59 @@
   106.4 +/*
   106.5 + * Copyright (c) 2008-2010, Oracle and/or its affiliates. All rights reserved.
   106.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   106.7 + *
   106.8 + * This code is free software; you can redistribute it and/or modify it
   106.9 + * under the terms of the GNU General Public License version 2 only, as
  106.10 + * published by the Free Software Foundation.
  106.11 + *
  106.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  106.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  106.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  106.15 + * version 2 for more details (a copy is included in the LICENSE file that
  106.16 + * accompanied this code).
  106.17 + *
  106.18 + * You should have received a copy of the GNU General Public License version
  106.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  106.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  106.21 + *
  106.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  106.23 + * or visit www.oracle.com if you need additional information or have any
  106.24 + * questions.
  106.25 + */
  106.26 +
  106.27 +/*
  106.28 + * @test
  106.29 + * @bug 6754038 6979327
  106.30 + * @summary Generate call sites for method handle
  106.31 + * @author jrose
  106.32 + *
  106.33 + * @library ..
  106.34 + * @compile/fail/ref=InvokeDynTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeDynTrans.java
  106.35 + */
  106.36 +//No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn
  106.37 +
  106.38 +/*
  106.39 + * Standalone testing:
  106.40 + * <code>
  106.41 + * $ cd $MY_REPO_DIR/langtools
  106.42 + * $ (cd make; make)
  106.43 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeDyn.java
  106.44 + * $ javap -c -classpath dist meth.InvokeDyn
  106.45 + * </code>
  106.46 + */
  106.47 +
  106.48 +package meth;
  106.49 +
  106.50 +import java.dyn.InvokeDynamic;
  106.51 +
  106.52 +public class InvokeDynTrans {
  106.53 +    void test() throws Throwable {
  106.54 +        Object x = "hello";
  106.55 +        InvokeDynamic.greet(x, "world", 123);
  106.56 +        InvokeDynamic.greet(x, "mundus", 456);
  106.57 +        InvokeDynamic.greet(x, "kosmos", 789);
  106.58 +        InvokeDynamic.<String>cogitate(10.11121, 3.14);
  106.59 +        InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
  106.60 +        InvokeDynamic.<int>invoke("goodbye");
  106.61 +    }
  106.62 +}
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/test/tools/javac/meth/InvokeDynTrans.out	Tue Sep 07 15:49:48 2010 -0700
   107.3 @@ -0,0 +1,6 @@
   107.4 +InvokeDynTrans.java:55:39: compiler.warn.type.parameter.on.polymorphic.signature
   107.5 +InvokeDynTrans.java:56:91: compiler.warn.type.parameter.on.polymorphic.signature
   107.6 +InvokeDynTrans.java:57:34: compiler.warn.type.parameter.on.polymorphic.signature
   107.7 +- compiler.err.warnings.and.werror
   107.8 +1 error
   107.9 +3 warnings
   108.1 --- a/test/tools/javac/meth/InvokeMH.java	Tue Sep 07 15:14:49 2010 -0700
   108.2 +++ b/test/tools/javac/meth/InvokeMH.java	Tue Sep 07 15:49:48 2010 -0700
   108.3 @@ -1,5 +1,5 @@
   108.4  /*
   108.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
   108.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
   108.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   108.8   *
   108.9   * This code is free software; you can redistribute it and/or modify it
  108.10 @@ -23,11 +23,11 @@
  108.11  
  108.12  /*
  108.13   * @test
  108.14 - * @bug 6754038
  108.15 + * @bug 6754038 6979327
  108.16   * @summary Generate call sites for method handle
  108.17   * @author jrose
  108.18   *
  108.19 - * @compile -source 7 -target 7 InvokeMH.java
  108.20 + * @compile -source 7 -target 7 -XDallowTransitionalJSR292=no InvokeMH.java
  108.21   */
  108.22  
  108.23  /*
  108.24 @@ -57,20 +57,17 @@
  108.25          Object k = "kosmos";
  108.26          mh_SiO.invokeExact((String)k, 789);
  108.27          o = mh_SiO.invokeExact((String)null, 000);
  108.28 -        o = mh_SiO.<Object>invokeExact("arda", -123);
  108.29 +        o = (Object) mh_SiO.invokeExact("arda", -123);
  108.30  
  108.31          // sig = ()String
  108.32 -        s = mh_vS.<String>invokeExact();
  108.33 +        s = (String) mh_vS.invokeExact();
  108.34  
  108.35          // sig = ()int
  108.36 -        i = mh_vi.<int>invokeExact();
  108.37 -        o = mh_vi.<int>invokeExact();
  108.38 -        //s = mh_vi.<int>invokeExact(); //BAD
  108.39 -        mh_vi.<int>invokeExact();
  108.40 +        i = (int) mh_vi.invokeExact();
  108.41 +        o = (int) mh_vi.invokeExact();
  108.42  
  108.43          // sig = ()void
  108.44 -        //o = mh_vv.<void>invokeExact(); //BAD
  108.45 -        mh_vv.<void>invokeExact();
  108.46 +        mh_vv.invokeExact();
  108.47      }
  108.48  
  108.49      void testGen(MethodHandle mh_SiO,
  108.50 @@ -80,24 +77,23 @@
  108.51          Object o; String s; int i;  // for return type testing
  108.52  
  108.53          // next five must have sig = (*,*)*
  108.54 -        mh_SiO.invokeGeneric((Object)"world", (Object)123);
  108.55 -        mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456);
  108.56 +        o = mh_SiO.invokeGeneric((Object)"world", (Object)123);
  108.57 +        mh_SiO.invokeGeneric((Object)"mundus", (Object)456);
  108.58          Object k = "kosmos";
  108.59 -        mh_SiO.invokeGeneric(k, 789);
  108.60 +        o = mh_SiO.invokeGeneric(k, 789);
  108.61          o = mh_SiO.invokeGeneric(null, 000);
  108.62 -        o = mh_SiO.<Object>invokeGeneric("arda", -123);
  108.63 +        o = mh_SiO.invokeGeneric("arda", -123);
  108.64  
  108.65          // sig = ()String
  108.66          o = mh_vS.invokeGeneric();
  108.67  
  108.68          // sig = ()int
  108.69 -        i = mh_vi.<int>invokeGeneric();
  108.70 -        o = mh_vi.invokeGeneric();
  108.71 -        //s = mh_vi.<int>invokeGeneric(); //BAD
  108.72 -        mh_vi.<void>invokeGeneric();
  108.73 +        i = (int) mh_vi.invokeGeneric();
  108.74 +        o = (int) mh_vi.invokeGeneric();
  108.75 +        mh_vi.invokeGeneric();
  108.76  
  108.77          // sig = ()void
  108.78 -        //o = mh_vv.<void>invokeGeneric(); //BAD
  108.79 +        mh_vv.invokeGeneric();
  108.80          o = mh_vv.invokeGeneric();
  108.81      }
  108.82  }
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/test/tools/javac/meth/InvokeMHTrans.java	Tue Sep 07 15:49:48 2010 -0700
   109.3 @@ -0,0 +1,102 @@
   109.4 +/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
   109.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   109.6 + *
   109.7 + * This code is free software; you can redistribute it and/or modify it
   109.8 + * under the terms of the GNU General Public License version 2 only, as
   109.9 + * published by the Free Software Foundation.
  109.10 + *
  109.11 + * This code is distributed in the hope that it will be useful, but WITHOUT
  109.12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  109.13 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  109.14 + * version 2 for more details (a copy is included in the LICENSE file that
  109.15 + * accompanied this code).
  109.16 + *
  109.17 + * You should have received a copy of the GNU General Public License version
  109.18 + * 2 along with this work; if not, write to the Free Software Foundation,
  109.19 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  109.20 + *
  109.21 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  109.22 + * or visit www.oracle.com if you need additional information or have any
  109.23 + * questions.
  109.24 + */
  109.25 +
  109.26 +/*
  109.27 + * @test
  109.28 + * @bug 6754038 6979327
  109.29 + * @summary Generate call sites for method handle
  109.30 + * @author jrose
  109.31 + *
  109.32 + * @compile/fail/ref=InvokeMHTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeMHTrans.java
  109.33 + */
  109.34 +
  109.35 +/*
  109.36 + * Standalone testing:
  109.37 + * <code>
  109.38 + * $ cd $MY_REPO_DIR/langtools
  109.39 + * $ (cd make; make)
  109.40 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java
  109.41 + * $ javap -c -classpath dist meth.InvokeMH
  109.42 + * </code>
  109.43 + */
  109.44 +
  109.45 +package meth;
  109.46 +
  109.47 +import java.dyn.MethodHandle;
  109.48 +
  109.49 +public class InvokeMHTrans {
  109.50 +    void test(MethodHandle mh_SiO,
  109.51 +              MethodHandle mh_vS,
  109.52 +              MethodHandle mh_vi,
  109.53 +              MethodHandle mh_vv) throws Throwable {
  109.54 +        Object o; String s; int i;  // for return type testing
  109.55 +
  109.56 +        // next five must have sig = (String,int)Object
  109.57 +        mh_SiO.invokeExact("world", 123);
  109.58 +        mh_SiO.invokeExact("mundus", 456);
  109.59 +        Object k = "kosmos";
  109.60 +        mh_SiO.invokeExact((String)k, 789);
  109.61 +        o = mh_SiO.invokeExact((String)null, 000);
  109.62 +        o = mh_SiO.<Object>invokeExact("arda", -123);
  109.63 +
  109.64 +        // sig = ()String
  109.65 +        s = mh_vS.<String>invokeExact();
  109.66 +
  109.67 +        // sig = ()int
  109.68 +        i = mh_vi.<int>invokeExact();
  109.69 +        o = mh_vi.<int>invokeExact();
  109.70 +        //s = mh_vi.<int>invokeExact(); //BAD
  109.71 +        mh_vi.<int>invokeExact();
  109.72 +
  109.73 +        // sig = ()void
  109.74 +        //o = mh_vv.<void>invokeExact(); //BAD
  109.75 +        mh_vv.<void>invokeExact();
  109.76 +    }
  109.77 +
  109.78 +    void testGen(MethodHandle mh_SiO,
  109.79 +                 MethodHandle mh_vS,
  109.80 +                 MethodHandle mh_vi,
  109.81 +                 MethodHandle mh_vv) throws Throwable {
  109.82 +        Object o; String s; int i;  // for return type testing
  109.83 +
  109.84 +        // next five must have sig = (*,*)*
  109.85 +        mh_SiO.invokeGeneric((Object)"world", (Object)123);
  109.86 +        mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456);
  109.87 +        Object k = "kosmos";
  109.88 +        mh_SiO.invokeGeneric(k, 789);
  109.89 +        o = mh_SiO.invokeGeneric(null, 000);
  109.90 +        o = mh_SiO.<Object>invokeGeneric("arda", -123);
  109.91 +
  109.92 +        // sig = ()String
  109.93 +        o = mh_vS.invokeGeneric();
  109.94 +
  109.95 +        // sig = ()int
  109.96 +        i = mh_vi.<int>invokeGeneric();
  109.97 +        o = mh_vi.invokeGeneric();
  109.98 +        //s = mh_vi.<int>invokeGeneric(); //BAD
  109.99 +        mh_vi.<void>invokeGeneric();
 109.100 +
 109.101 +        // sig = ()void
 109.102 +        //o = mh_vv.<void>invokeGeneric(); //BAD
 109.103 +        o = mh_vv.invokeGeneric();
 109.104 +    }
 109.105 +}
   110.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.2 +++ b/test/tools/javac/meth/InvokeMHTrans.out	Tue Sep 07 15:49:48 2010 -0700
   110.3 @@ -0,0 +1,13 @@
   110.4 +InvokeMHTrans.java:59:39: compiler.warn.type.parameter.on.polymorphic.signature
   110.5 +InvokeMHTrans.java:62:38: compiler.warn.type.parameter.on.polymorphic.signature
   110.6 +InvokeMHTrans.java:65:35: compiler.warn.type.parameter.on.polymorphic.signature
   110.7 +InvokeMHTrans.java:66:35: compiler.warn.type.parameter.on.polymorphic.signature
   110.8 +InvokeMHTrans.java:68:31: compiler.warn.type.parameter.on.polymorphic.signature
   110.9 +InvokeMHTrans.java:72:32: compiler.warn.type.parameter.on.polymorphic.signature
  110.10 +InvokeMHTrans.java:83:35: compiler.warn.type.parameter.on.polymorphic.signature
  110.11 +InvokeMHTrans.java:87:41: compiler.warn.type.parameter.on.polymorphic.signature
  110.12 +InvokeMHTrans.java:93:37: compiler.warn.type.parameter.on.polymorphic.signature
  110.13 +InvokeMHTrans.java:96:34: compiler.warn.type.parameter.on.polymorphic.signature
  110.14 +- compiler.err.warnings.and.werror
  110.15 +1 error
  110.16 +10 warnings
   111.1 --- a/test/tools/javac/meth/MakeNegTests.sh	Tue Sep 07 15:14:49 2010 -0700
   111.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.3 @@ -1,98 +0,0 @@
   111.4 -#!/bin/sh
   111.5 -
   111.6 -#
   111.7 -# Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
   111.8 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   111.9 -#
  111.10 -# This code is free software; you can redistribute it and/or modify it
  111.11 -# under the terms of the GNU General Public License version 2 only, as
  111.12 -# published by the Free Software Foundation.
  111.13 -#
  111.14 -# This code is distributed in the hope that it will be useful, but WITHOUT
  111.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  111.16 -# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  111.17 -# version 2 for more details (a copy is included in the LICENSE file that
  111.18 -# accompanied this code).
  111.19 -#
  111.20 -# You should have received a copy of the GNU General Public License version
  111.21 -# 2 along with this work; if not, write to the Free Software Foundation,
  111.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  111.23 -#
  111.24 -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  111.25 -# or visit www.oracle.com if you need additional information or have any
  111.26 -# questions.
  111.27 -#
  111.28 -
  111.29 -# @test
  111.30 -# @bug 6754038
  111.31 -# @summary Verify correct rejection of strongly typed return values
  111.32 -# @run shell MakeNegTests.sh
  111.33 -
  111.34 -default_template=InvokeMH.java
  111.35 -javacflags='-source 7 -target 7'
  111.36 -# the rest of this file is a generic "//BAD"-line tester
  111.37 -
  111.38 -: ${TESTSRC=.} ${TESTCLASSES=.}
  111.39 -javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
  111.40 -
  111.41 -verbose=false quiet=false
  111.42 -
  111.43 -main() {
  111.44 -  case "${@-}" in
  111.45 -  *.java*)
  111.46 -    for template in "$@"; do
  111.47 -      expand_and_test "$template"
  111.48 -    done;;
  111.49 -  *) expand_and_test "${TESTSRC}/$default_template";;
  111.50 -  esac
  111.51 -}
  111.52 -
  111.53 -expand_and_test() {
  111.54 -  template=$1
  111.55 -  expand "$@"
  111.56 -  testneg "$@"
  111.57 -}
  111.58 -
  111.59 -expand() {
  111.60 -  template=$1
  111.61 -  badlines=` grep -n < "$template" '//BAD' `
  111.62 -  badcount=` echo "$badlines" | wc -l `
  111.63 -  [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; }
  111.64 -  $quiet || echo "Expanding $badcount negative test cases from $template:"
  111.65 -  $quiet || echo "$badlines"
  111.66 -  badnums=` echo "$badlines" | sed 's/:.*//' `
  111.67 -  casestem=` getcasestem "$template" `
  111.68 -  tclassname=` basename "$template" .java `
  111.69 -  rm -f "$casestem"*.java
  111.70 -  for badnum in $badnums; do
  111.71 -    casefile="$casestem"${badnum}.java
  111.72 -    cclassname=` basename "$casefile" .java `
  111.73 -    sed < "$template" > "$casefile" "
  111.74 -      s|@compile|@compile/fail|
  111.75 -      / @[a-z]/s|@|##|
  111.76 -      ${badnum}s:^ *[/*]*:    :
  111.77 -      s/${tclassname}/${cclassname}/g
  111.78 -    "
  111.79 -    $verbose && diff -u "$template" "$casefile"
  111.80 -  done
  111.81 -}
  111.82 -
  111.83 -getcasestem() {
  111.84 -  echo `basename $1` | sed 's/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/'
  111.85 -}
  111.86 -
  111.87 -testneg() {
  111.88 -  template=$1
  111.89 -  for casefile in ` getcasestem "$template" `*.java; do
  111.90 -    $quiet || echo -------- $javac $javacflags "$casefile"
  111.91 -    $javac $javacflags "$casefile" > "$casefile".errlog 2>&1 && {
  111.92 -      echo "*** Compilation unexpectedly succeeded:  $casefile"
  111.93 -      exit 1
  111.94 -    }
  111.95 -    $quiet || echo "Compilation failed as expected"
  111.96 -    $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog
  111.97 -    rm "$casefile".errlog
  111.98 -  done
  111.99 -}
 111.100 -
 111.101 -main "$@"
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/test/tools/javac/parser/ExtraSemiTest.java	Tue Sep 07 15:49:48 2010 -0700
   112.3 @@ -0,0 +1,100 @@
   112.4 +/*
   112.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   112.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   112.7 + *
   112.8 + * This code is free software; you can redistribute it and/or modify it
   112.9 + * under the terms of the GNU General Public License version 2 only, as
  112.10 + * published by the Free Software Foundation.
  112.11 + *
  112.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  112.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  112.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  112.15 + * version 2 for more details (a copy is included in the LICENSE file that
  112.16 + * accompanied this code).
  112.17 + *
  112.18 + * You should have received a copy of the GNU General Public License version
  112.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  112.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  112.21 + *
  112.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  112.23 + * or visit www.oracle.com if you need additional information or have any
  112.24 + * questions.
  112.25 + */
  112.26 +
  112.27 +/*
  112.28 + * @test
  112.29 + * @bug 6921495
  112.30 + * @summary spurious semicolons in class def cause empty NOPOS blocks
  112.31 + */
  112.32 +
  112.33 +import java.io.*;
  112.34 +import java.net.*;
  112.35 +import java.util.*;
  112.36 +import javax.tools.*;
  112.37 +import com.sun.source.util.*;
  112.38 +
  112.39 +public class ExtraSemiTest {
  112.40 +
  112.41 +    static class JavaSource extends SimpleJavaFileObject {
  112.42 +
  112.43 +        final static String source =
  112.44 +                        "class C {\n" +
  112.45 +                        "    int x;;\n" +
  112.46 +                        "    class X { int i;; };\n" +
  112.47 +                        "}";
  112.48 +
  112.49 +        JavaSource() {
  112.50 +            super(URI.create("myfo:/C.java"), JavaFileObject.Kind.SOURCE);
  112.51 +        }
  112.52 +
  112.53 +        @Override
  112.54 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
  112.55 +            return source;
  112.56 +        }
  112.57 +    }
  112.58 +
  112.59 +    public static void main(String... args) throws IOException {
  112.60 +        new ExtraSemiTest().run();
  112.61 +    }
  112.62 +
  112.63 +    void run() throws IOException {
  112.64 +        File destDir = new File("classes"); destDir.mkdir();
  112.65 +        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  112.66 +        JavaSource source = new JavaSource();
  112.67 +        JavacTask ct = (JavacTask)tool.getTask(null, null, null,
  112.68 +                Arrays.asList("-d", destDir.getPath(), "-XD-printsource"),
  112.69 +                null,
  112.70 +                Arrays.asList(source));
  112.71 +        Boolean ok = ct.call();
  112.72 +        if (!ok) throw new AssertionError("compilation failed");
  112.73 +
  112.74 +        String text = readFile(new File(destDir, "C.java"));
  112.75 +        System.out.println(text);
  112.76 +
  112.77 +        // compress/canonicalize all whitespace
  112.78 +        String canon = text.replaceAll("\\s+", " ");
  112.79 +        System.out.println("canon: " + canon);
  112.80 +
  112.81 +        // There are no empty blocks in the original text.
  112.82 +        // C will be given a default constructor "C() { super(); }" which
  112.83 +        // does not have any empty blocks.
  112.84 +        // The bug is that spurious semicolons in the class defn are parsed
  112.85 +        // into redundant empty blocks in the tree, so verify there are
  112.86 +        // no empty blocks in the -printsource output
  112.87 +
  112.88 +        if (canon.contains("{ }"))
  112.89 +            throw new AssertionError("unexpected empty block found");
  112.90 +    }
  112.91 +
  112.92 +    String readFile(File f) throws IOException {
  112.93 +        int len = (int) f.length();
  112.94 +        byte[] data = new byte[len];
  112.95 +        DataInputStream in = new DataInputStream(new FileInputStream(f));
  112.96 +        try {
  112.97 +            in.readFully(data);
  112.98 +            return new String(data);
  112.99 +        } finally {
 112.100 +            in.close();
 112.101 +        }
 112.102 +    }
 112.103 +}
   113.1 --- a/test/tools/javac/processing/6430209/b6341534.java	Tue Sep 07 15:14:49 2010 -0700
   113.2 +++ b/test/tools/javac/processing/6430209/b6341534.java	Tue Sep 07 15:49:48 2010 -0700
   113.3 @@ -51,7 +51,8 @@
   113.4              try {
   113.5                  PackageElement PE = E.getPackageElement("dir1");
   113.6                  List<? extends Element> LEE = PE.getEnclosedElements();    /* <=This line elicits the error message.  */
   113.7 -                for(Element e : LEE)    System.out.println("found " + e.toString() + " in dir1.");
   113.8 +                for(Element e : LEE)
   113.9 +                    System.out.println("found " + e.toString() + " in dir1.");
  113.10              }
  113.11              catch(NullPointerException npe) {
  113.12                  msgr.printMessage(ERROR,npe.toString());
  113.13 @@ -59,7 +60,11 @@
  113.14                  return false;
  113.15              }
  113.16          }
  113.17 -        if( renv.errorRaised() ) {      msgr.printMessage(ERROR, "FAILED");}
  113.18 +        // on round 1, expect errorRaised == false && processingOver == false
  113.19 +        // on round 2, expect errorRaised == true && processingOver == true
  113.20 +        if( renv.errorRaised() != renv.processingOver()) {
  113.21 +            msgr.printMessage(ERROR, "FAILED");
  113.22 +        }
  113.23          return true;
  113.24      }
  113.25  
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/test/tools/javac/processing/errors/TestSuppression.java	Tue Sep 07 15:49:48 2010 -0700
   114.3 @@ -0,0 +1,232 @@
   114.4 +/*
   114.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   114.7 + *
   114.8 + * This code is free software; you can redistribute it and/or modify it
   114.9 + * under the terms of the GNU General Public License version 2 only, as
  114.10 + * published by the Free Software Foundation.
  114.11 + *
  114.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  114.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  114.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  114.15 + * version 2 for more details (a copy is included in the LICENSE file that
  114.16 + * accompanied this code).
  114.17 + *
  114.18 + * You should have received a copy of the GNU General Public License version
  114.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  114.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  114.21 + *
  114.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  114.23 + * or visit www.oracle.com if you need additional information or have any
  114.24 + * questions.
  114.25 + */
  114.26 +
  114.27 +/*
  114.28 + * @test
  114.29 + * @bug 6403465
  114.30 + * @summary javac should defer diagnostics until it can be determined they are persistent
  114.31 + */
  114.32 +
  114.33 +import java.io.*;
  114.34 +import java.util.*;
  114.35 +import javax.annotation.processing.*;
  114.36 +import javax.lang.model.*;
  114.37 +import javax.lang.model.element.TypeElement;
  114.38 +import javax.tools.*;
  114.39 +
  114.40 +import com.sun.source.util.JavacTask;
  114.41 +import com.sun.tools.javac.api.JavacTool;
  114.42 +import com.sun.tools.javac.util.JCDiagnostic;
  114.43 +
  114.44 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
  114.45 +
  114.46 +
  114.47 +public class TestSuppression {
  114.48 +    public static void main(String... args) throws Exception {
  114.49 +        new TestSuppression().run(args);
  114.50 +    }
  114.51 +
  114.52 +    enum WarningKind { NO, YES };
  114.53 +
  114.54 +    String[] cases = {
  114.55 +        // missing class C
  114.56 +        "class X { C c; }",
  114.57 +        "class X { C foo() { return null; } }",
  114.58 +        "class X { void foo(C c) { } }",
  114.59 +        "class X extends C { }",
  114.60 +        "class X<T extends C> { }",
  114.61 +        // missing interface I
  114.62 +        "class X implements I { }",
  114.63 +        "interface X extends I { }",
  114.64 +        // missing exception E
  114.65 +        "class X { void m() throws E { } }",
  114.66 +        // missing method m
  114.67 +        "class X extends C { int i = m(); }",
  114.68 +        // missing field f
  114.69 +        "class X extends C { int i = f; }"
  114.70 +    };
  114.71 +
  114.72 +    void run(String... args) throws Exception {
  114.73 +        for (String c: cases) {
  114.74 +            for (WarningKind wk: WarningKind.values()) {
  114.75 +                for (int g = 1; g <= 3; g++) {
  114.76 +                    try {
  114.77 +                        test(c, wk, g);
  114.78 +                    } catch (Throwable t) {
  114.79 +                        error("caught: " + t);
  114.80 +                    }
  114.81 +                    if (errors > 0) throw new AssertionError();
  114.82 +                }
  114.83 +            }
  114.84 +        }
  114.85 +
  114.86 +        System.err.println(count + " test cases");
  114.87 +
  114.88 +        if (errors > 0)
  114.89 +            throw new Exception(errors + " errors occurred");
  114.90 +    }
  114.91 +
  114.92 +    void test(String src, WarningKind wk, int gen) throws Exception {
  114.93 +        count++;
  114.94 +        System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src);
  114.95 +
  114.96 +        File testDir = new File("test" + count);
  114.97 +        File srcDir = createDir(testDir, "src");
  114.98 +        File gensrcDir = createDir(testDir, "gensrc");
  114.99 +        File classesDir = createDir(testDir, "classes");
 114.100 +
 114.101 +        File x = writeFile(new File(srcDir, "X.java"), src);
 114.102 +
 114.103 +        DiagListener dl = new DiagListener();
 114.104 +        JavacTool tool = JavacTool.create();
 114.105 +        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
 114.106 +        fm.setLocation(StandardLocation.CLASS_PATH,
 114.107 +                Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
 114.108 +        fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
 114.109 +        fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
 114.110 +        List<String> args = new ArrayList<String>();
 114.111 +//        args.add("-XprintProcessorInfo");
 114.112 +        args.add("-XprintRounds");
 114.113 +        args.add("-Agen=" + gen);
 114.114 +        if (wk == WarningKind.YES)
 114.115 +            args.add("-Xlint:serial");
 114.116 +        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
 114.117 +
 114.118 +        StringWriter sw = new StringWriter();
 114.119 +        PrintWriter pw = new PrintWriter(sw);
 114.120 +        JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
 114.121 +        task.setProcessors(Arrays.asList(new AnnoProc()));
 114.122 +        boolean ok = task.call();
 114.123 +        pw.close();
 114.124 +
 114.125 +        System.err.println("ok:" + ok + " diags:" + dl.counts);
 114.126 +        if (sw.toString().length() > 0) {
 114.127 +            System.err.println("output:\n" + sw.toString());
 114.128 +        }
 114.129 +
 114.130 +        for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
 114.131 +            Integer v = dl.counts.get(dk);
 114.132 +            int found = (v == null) ? 0 : v;
 114.133 +            int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
 114.134 +            if (found != expect) {
 114.135 +                error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
 114.136 +            }
 114.137 +        }
 114.138 +
 114.139 +        System.err.println();
 114.140 +    }
 114.141 +
 114.142 +    File createDir(File parent, String name) {
 114.143 +        File dir = new File(parent, name);
 114.144 +        dir.mkdirs();
 114.145 +        return dir;
 114.146 +    }
 114.147 +
 114.148 +    File writeFile(File f, String content) throws IOException {
 114.149 +        FileWriter out = new FileWriter(f);
 114.150 +        try {
 114.151 +            out.write(content);
 114.152 +        } finally {
 114.153 +            out.close();
 114.154 +        }
 114.155 +        return f;
 114.156 +    }
 114.157 +
 114.158 +    <T> void add(List<T> list, T... values) {
 114.159 +        for (T v: values)
 114.160 +            list.add(v);
 114.161 +    }
 114.162 +
 114.163 +    void error(String msg) {
 114.164 +        System.err.println("Error: " + msg);
 114.165 +        errors++;
 114.166 +    }
 114.167 +
 114.168 +    int count;
 114.169 +    int errors;
 114.170 +
 114.171 +    static class DiagListener implements DiagnosticListener<JavaFileObject> {
 114.172 +        int total;
 114.173 +        Map<Diagnostic.Kind,Integer> counts = new TreeMap<Diagnostic.Kind,Integer>();
 114.174 +
 114.175 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
 114.176 +            System.err.println((++total) + ": "
 114.177 +                    + "resolveError:" + isResolveError((JCDiagnostic) diagnostic) + "\n"
 114.178 +                    + diagnostic);
 114.179 +            Diagnostic.Kind dk = diagnostic.getKind();
 114.180 +            Integer c = counts.get(dk);
 114.181 +            counts.put(dk, (c == null ? 1 : c + 1));
 114.182 +        }
 114.183 +
 114.184 +        private static boolean isResolveError(JCDiagnostic d) {
 114.185 +            return d.isFlagSet(RESOLVE_ERROR);
 114.186 +        }
 114.187 +    }
 114.188 +
 114.189 +    @SupportedAnnotationTypes("*")
 114.190 +    @SupportedOptions("gen")
 114.191 +    public static class AnnoProc extends AbstractProcessor {
 114.192 +        Filer f;
 114.193 +        Messager m;
 114.194 +        int gen;
 114.195 +
 114.196 +        @Override
 114.197 +        public void init(ProcessingEnvironment processingEnv) {
 114.198 +            f = processingEnv.getFiler();
 114.199 +            m = processingEnv.getMessager();
 114.200 +            Map<String,String> options = processingEnv.getOptions();
 114.201 +            gen = Integer.parseInt(options.get("gen"));
 114.202 +        }
 114.203 +
 114.204 +        @Override
 114.205 +        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
 114.206 +            round++;
 114.207 +            if (round < gen)
 114.208 +                writeSource("Dummy" + round, "class Dummy" + round + " extends java.util.ArrayList{ }");
 114.209 +            else if (round == gen) {
 114.210 +                writeSource("C", "class C { int f; int m() { return 0; } }");
 114.211 +                writeSource("I", "interface I { }");
 114.212 +                writeSource("E", "class E extends Exception { }");
 114.213 +            }
 114.214 +            return true;
 114.215 +        }
 114.216 +
 114.217 +        @Override
 114.218 +        public SourceVersion getSupportedSourceVersion() {
 114.219 +            return SourceVersion.latest();
 114.220 +        }
 114.221 +
 114.222 +        private void writeSource(String name, String text) {
 114.223 +            try {
 114.224 +                JavaFileObject fo = f.createSourceFile(name);
 114.225 +                Writer out = fo.openWriter();
 114.226 +                out.write(text);
 114.227 +                out.close();
 114.228 +            } catch (IOException e) {
 114.229 +                m.printMessage(Diagnostic.Kind.ERROR, e.toString());
 114.230 +            }
 114.231 +        }
 114.232 +
 114.233 +        int round = 0;
 114.234 +    }
 114.235 +}
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/test/tools/javac/processing/filer/TestGetResource2.java	Tue Sep 07 15:49:48 2010 -0700
   115.3 @@ -0,0 +1,172 @@
   115.4 +/*
   115.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
   115.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   115.7 + *
   115.8 + * This code is free software; you can redistribute it and/or modify it
   115.9 + * under the terms of the GNU General Public License version 2 only, as
  115.10 + * published by the Free Software Foundation.
  115.11 + *
  115.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  115.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  115.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  115.15 + * version 2 for more details (a copy is included in the LICENSE file that
  115.16 + * accompanied this code).
  115.17 + *
  115.18 + * You should have received a copy of the GNU General Public License version
  115.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  115.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  115.21 + *
  115.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  115.23 + * or visit www.oracle.com if you need additional information or have any
  115.24 + * questions.
  115.25 + */
  115.26 +
  115.27 +/* @test
  115.28 + * @bug 6929404
  115.29 + * @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
  115.30 + */
  115.31 +
  115.32 +import java.io.*;
  115.33 +import java.security.*;
  115.34 +import java.util.*;
  115.35 +import javax.annotation.processing.*;
  115.36 +import javax.lang.model.*;
  115.37 +import javax.lang.model.element.*;
  115.38 +import javax.tools.*;
  115.39 +import javax.tools.Diagnostic.Kind;
  115.40 +import javax.tools.JavaCompiler.CompilationTask;
  115.41 +
  115.42 +public class TestGetResource2 {
  115.43 +
  115.44 +    public static void main(String[] args) throws Exception {
  115.45 +        new TestGetResource2().run();
  115.46 +    }
  115.47 +
  115.48 +    void run() throws Exception {
  115.49 +        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
  115.50 +        CodeSource cs = javac.getClass().getProtectionDomain().getCodeSource();
  115.51 +        if (cs == null) {
  115.52 +            System.err.println("got compiler from " +
  115.53 +                ClassLoader.getSystemResource(javac.getClass().getName().replace(".", "/")+".class"));
  115.54 +        } else {
  115.55 +            System.err.println("got compiler from " + cs.getLocation());
  115.56 +        }
  115.57 +
  115.58 +        testSingleSourceDir(javac);
  115.59 +        testCompositeSourcePath(javac);
  115.60 +        testMissingResource(javac);
  115.61 +    }
  115.62 +
  115.63 +    private void testSingleSourceDir(JavaCompiler javac) throws Exception {
  115.64 +        System.err.println("testSingleSourceDir");
  115.65 +        File tmpdir = new File("testSingleSourceDir");
  115.66 +        File srcdir = new File(tmpdir, "src");
  115.67 +        File destdir = new File(tmpdir, "dest");
  115.68 +        write(srcdir, "pkg/X.java", "package pkg; class X {}");
  115.69 +        write(srcdir, "resources/file.txt", "hello");
  115.70 +        destdir.mkdirs();
  115.71 +
  115.72 +        CompilationTask task = javac.getTask(null, null, null,
  115.73 +                Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
  115.74 +                Collections.singleton("pkg.X"), null);
  115.75 +        task.setProcessors(Collections.singleton(new AnnoProc()));
  115.76 +        boolean result = task.call();
  115.77 +        System.err.println("javac result with single source dir: " + result);
  115.78 +        expect(result, true);
  115.79 +    }
  115.80 +
  115.81 +    private void testCompositeSourcePath(JavaCompiler javac) throws Exception {
  115.82 +        System.err.println("testCompositeSearchPath");
  115.83 +        File tmpdir = new File("testCompositeSourcePath");
  115.84 +        File srcdir = new File(tmpdir, "src");
  115.85 +        File rsrcdir = new File(tmpdir, "rsrc");
  115.86 +        File destdir = new File(tmpdir, "dest");
  115.87 +        write(srcdir, "pkg/X.java", "package pkg; class X {}");
  115.88 +        write(rsrcdir, "resources/file.txt", "hello");
  115.89 +        destdir.mkdirs();
  115.90 +
  115.91 +        CompilationTask task = javac.getTask(null, null, null,
  115.92 +                Arrays.asList("-sourcepath", srcdir + File.pathSeparator + rsrcdir, "-d", destdir.toString()),
  115.93 +                Collections.singleton("pkg.X"), null);
  115.94 +        task.setProcessors(Collections.singleton(new AnnoProc()));
  115.95 +        boolean result = task.call();
  115.96 +        System.err.println("javac result with composite source path: " + result);
  115.97 +        expect(result, true);
  115.98 +    }
  115.99 +
 115.100 +    private void testMissingResource(JavaCompiler javac) throws Exception {
 115.101 +        System.err.println("testMissingResource");
 115.102 +        File tmpdir = new File("testMissingResource");
 115.103 +        File srcdir = new File(tmpdir, "src");
 115.104 +        File destdir = new File(tmpdir, "dest");
 115.105 +        write(srcdir, "pkg/X.java", "package pkg; class X {}");
 115.106 +        destdir.mkdirs();
 115.107 +
 115.108 +        CompilationTask task = javac.getTask(null, null, null,
 115.109 +                Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
 115.110 +                Collections.singleton("pkg.X"), null);
 115.111 +        task.setProcessors(Collections.singleton(new AnnoProc()));
 115.112 +        boolean result = task.call();
 115.113 +        System.err.println("javac result when missing resource: " + result);
 115.114 +        expect(result, false);
 115.115 +
 115.116 +        if (errors > 0)
 115.117 +            throw new Exception(errors + " errors occurred");
 115.118 +    }
 115.119 +
 115.120 +    @SupportedAnnotationTypes("*")
 115.121 +    static class AnnoProc extends AbstractProcessor {
 115.122 +
 115.123 +        public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
 115.124 +            if (roundEnv.processingOver()) {
 115.125 +                return false;
 115.126 +            }
 115.127 +
 115.128 +            try {
 115.129 +                FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt");
 115.130 +                try {
 115.131 +                    resource.openInputStream().close();
 115.132 +                    processingEnv.getMessager().printMessage(Kind.NOTE, "found: " + resource.toUri());
 115.133 +                    return true;
 115.134 +                } catch (IOException x) {
 115.135 +                    processingEnv.getMessager().printMessage(Kind.ERROR, "could not read: " + resource.toUri());
 115.136 +                    x.printStackTrace();
 115.137 +                }
 115.138 +            } catch (IOException x) {
 115.139 +                processingEnv.getMessager().printMessage(Kind.ERROR, "did not find resource");
 115.140 +                x.printStackTrace();
 115.141 +            }
 115.142 +
 115.143 +            return false;
 115.144 +        }
 115.145 +
 115.146 +        @Override
 115.147 +        public SourceVersion getSupportedSourceVersion() {
 115.148 +            return SourceVersion.latest();
 115.149 +        }
 115.150 +    }
 115.151 +
 115.152 +    private File write(File dir, String path, String contents) throws IOException {
 115.153 +        File f = new File(dir, path);
 115.154 +        f.getParentFile().mkdirs();
 115.155 +        Writer w = new FileWriter(f);
 115.156 +        try {
 115.157 +            w.write(contents);
 115.158 +        } finally {
 115.159 +            w.close();
 115.160 +        }
 115.161 +        return f;
 115.162 +    }
 115.163 +
 115.164 +    void expect(boolean val, boolean expect) {
 115.165 +        if (val != expect)
 115.166 +            error("Unexpected value: " + val + "; expected: " + expect);
 115.167 +    }
 115.168 +
 115.169 +    void error(String msg) {
 115.170 +        System.err.println(msg);
 115.171 +        errors++;
 115.172 +    }
 115.173 +
 115.174 +    int errors = 0;
 115.175 +}
   116.1 --- a/test/tools/javac/processing/model/element/TestAnonClassNames.java	Tue Sep 07 15:14:49 2010 -0700
   116.2 +++ b/test/tools/javac/processing/model/element/TestAnonClassNames.java	Tue Sep 07 15:49:48 2010 -0700
   116.3 @@ -27,8 +27,7 @@
   116.4   * @summary Test that reported names of anonymous classes are non-null.
   116.5   * @author  Joseph D. Darcy
   116.6   * @build TestAnonSourceNames
   116.7 - * @compile/fail -processor TestAnonSourceNames TestAnonClassNames.java
   116.8 - * @build TestAnonClassNames
   116.9 + * @compile -processor TestAnonSourceNames TestAnonClassNames.java
  116.10   * @run main TestAnonClassNames
  116.11   */
  116.12  
  116.13 @@ -40,10 +39,6 @@
  116.14   *
  116.15   * Source files will be tested by the @compile line which runs
  116.16   * TestAnonSourceNames as an annotation processor over this file.
  116.17 - * This compile line is expected to fail until 6930507 is fixed.  Once
  116.18 - * bug 6930507 is fixed, the "@compile/fail -processor ..." and
  116.19 - * following "@build..." steps can be replaced with a single "@compile
  116.20 - * -processor ..." directive.
  116.21   *
  116.22   * Class files are tested by the @run command on this type.  This
  116.23   * class gets the names of classes with different nesting kinds,
   117.1 --- a/test/tools/javac/processing/model/element/TestAnonSourceNames.java	Tue Sep 07 15:14:49 2010 -0700
   117.2 +++ b/test/tools/javac/processing/model/element/TestAnonSourceNames.java	Tue Sep 07 15:49:48 2010 -0700
   117.3 @@ -67,7 +67,7 @@
   117.4                       Element element = trees.getElement(trees.getPath(cu, node));
   117.5             if (element == null) {
   117.6                 processingEnv.getMessager().printMessage(ERROR,
   117.7 -                                                        "No element retreived for node named ''" +
   117.8 +                                                        "No element retrieved for node named ''" +
   117.9                                                          node.getSimpleName() + "''.");
  117.10             } else {
  117.11  
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/test/tools/javac/processing/options/TestImplicitNone.java	Tue Sep 07 15:49:48 2010 -0700
   118.3 @@ -0,0 +1,109 @@
   118.4 +/*
   118.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   118.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   118.7 + *
   118.8 + * This code is free software; you can redistribute it and/or modify it
   118.9 + * under the terms of the GNU General Public License version 2 only, as
  118.10 + * published by the Free Software Foundation.
  118.11 + *
  118.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  118.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  118.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  118.15 + * version 2 for more details (a copy is included in the LICENSE file that
  118.16 + * accompanied this code).
  118.17 + *
  118.18 + * You should have received a copy of the GNU General Public License version
  118.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  118.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  118.21 + *
  118.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  118.23 + * or visit www.oracle.com if you need additional information or have any
  118.24 + * questions.
  118.25 + */
  118.26 +
  118.27 +/*
  118.28 + * @test
  118.29 + * @bug 6935638
  118.30 + * @summary -implicit:none prevents compilation with annotation processing
  118.31 + */
  118.32 +
  118.33 +import java.io.*;
  118.34 +import java.util.*;
  118.35 +import javax.annotation.processing.*;
  118.36 +import javax.lang.model.*;
  118.37 +import javax.lang.model.element.*;
  118.38 +
  118.39 +
  118.40 +@SupportedAnnotationTypes("*")
  118.41 +public class TestImplicitNone extends AbstractProcessor {
  118.42 +    public static void main(String... args) throws Exception {
  118.43 +        new TestImplicitNone().run();
  118.44 +    }
  118.45 +
  118.46 +    void run() throws Exception {
  118.47 +        File classesDir = new File("tmp", "classes");
  118.48 +        classesDir.mkdirs();
  118.49 +        File test_java = new File(new File("tmp", "src"), "Test.java");
  118.50 +        writeFile(test_java, "class Test { }");
  118.51 +
  118.52 +        // build up list of options and files to be compiled
  118.53 +        List<String> opts = new ArrayList<String>();
  118.54 +        List<File> files = new ArrayList<File>();
  118.55 +
  118.56 +        opts.add("-d");
  118.57 +        opts.add(classesDir.getPath());
  118.58 +        opts.add("-processorpath");
  118.59 +        opts.add(System.getProperty("test.classes"));
  118.60 +        opts.add("-implicit:none");
  118.61 +        opts.add("-processor");
  118.62 +        opts.add(TestImplicitNone.class.getName());
  118.63 +        files.add(test_java);
  118.64 +
  118.65 +        compile(opts, files);
  118.66 +
  118.67 +        File test_class = new File(classesDir, "Test.class");
  118.68 +        if (!test_class.exists())
  118.69 +            throw new Exception("Test.class not generated");
  118.70 +    }
  118.71 +
  118.72 +    /** Compile files with options provided. */
  118.73 +    void compile(List<String> opts, List<File> files) throws Exception {
  118.74 +        System.err.println("javac: " + opts + " " + files);
  118.75 +        List<String> args = new ArrayList<String>();
  118.76 +        args.addAll(opts);
  118.77 +        for (File f: files)
  118.78 +            args.add(f.getPath());
  118.79 +        StringWriter sw = new StringWriter();
  118.80 +        PrintWriter pw = new PrintWriter(sw);
  118.81 +        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
  118.82 +        pw.flush();
  118.83 +        if (sw.getBuffer().length() > 0)
  118.84 +            System.err.println(sw.toString());
  118.85 +        if (rc != 0)
  118.86 +            throw new Exception("compilation failed: rc=" + rc);
  118.87 +    }
  118.88 +
  118.89 +    /** Write a file with a given body. */
  118.90 +    void writeFile(File f, String body) throws Exception {
  118.91 +        if (f.getParentFile() != null)
  118.92 +            f.getParentFile().mkdirs();
  118.93 +        Writer out = new FileWriter(f);
  118.94 +        try {
  118.95 +            out.write(body);
  118.96 +        } finally {
  118.97 +            out.close();
  118.98 +        }
  118.99 +    }
 118.100 +
 118.101 +    //----- annotation processor methods -----
 118.102 +
 118.103 +    public boolean process(Set<? extends TypeElement> annotations,
 118.104 +                         RoundEnvironment roundEnv) {
 118.105 +        return true;
 118.106 +    }
 118.107 +
 118.108 +    @Override
 118.109 +    public SourceVersion getSupportedSourceVersion() {
 118.110 +        return SourceVersion.latest();
 118.111 +    }
 118.112 +}
   119.1 --- a/test/tools/javac/quid/MakeNegTests.sh	Tue Sep 07 15:14:49 2010 -0700
   119.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   119.3 @@ -1,97 +0,0 @@
   119.4 -#!/bin/sh
   119.5 -
   119.6 -#
   119.7 -# Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
   119.8 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   119.9 -#
  119.10 -# This code is free software; you can redistribute it and/or modify it
  119.11 -# under the terms of the GNU General Public License version 2 only, as
  119.12 -# published by the Free Software Foundation.
  119.13 -#
  119.14 -# This code is distributed in the hope that it will be useful, but WITHOUT
  119.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  119.16 -# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  119.17 -# version 2 for more details (a copy is included in the LICENSE file that
  119.18 -# accompanied this code).
  119.19 -#
  119.20 -# You should have received a copy of the GNU General Public License version
  119.21 -# 2 along with this work; if not, write to the Free Software Foundation,
  119.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  119.23 -#
  119.24 -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  119.25 -# or visit www.oracle.com if you need additional information or have any
  119.26 -# questions.
  119.27 -#
  119.28 -
  119.29 -# @test
  119.30 -# @bug 6746458
  119.31 -# @summary Verify correct rejection of illegal quoted identifiers.
  119.32 -# @run shell MakeNegTests.sh
  119.33 -
  119.34 -default_template=QuotedIdent.java
  119.35 -# the rest of this file is a generic "//BAD"-line tester
  119.36 -
  119.37 -: ${TESTSRC=.} ${TESTCLASSES=.}
  119.38 -javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
  119.39 -
  119.40 -verbose=false quiet=false
  119.41 -
  119.42 -main() {
  119.43 -  case "${@-}" in
  119.44 -  *.java*)
  119.45 -    for template in "$@"; do
  119.46 -      expand_and_test "$template"
  119.47 -    done;;
  119.48 -  *) expand_and_test "${TESTSRC}/$default_template";;
  119.49 -  esac
  119.50 -}
  119.51 -
  119.52 -expand_and_test() {
  119.53 -  template=$1
  119.54 -  expand "$@"
  119.55 -  testneg "$@"
  119.56 -}
  119.57 -
  119.58 -expand() {
  119.59 -  template=$1
  119.60 -  badlines=` grep -n < "$template" '//BAD' `
  119.61 -  badcount=` echo "$badlines" | wc -l `
  119.62 -  [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; }
  119.63 -  $quiet || echo "Expanding $badcount negative test cases from $template:"
  119.64 -  $quiet || echo "$badlines"
  119.65 -  badnums=` echo "$badlines" | sed 's/:.*//' `
  119.66 -  casestem=` getcasestem "$template" `
  119.67 -  tclassname=` basename "$template" .java `
  119.68 -  rm "$casestem"*.java
  119.69 -  for badnum in $badnums; do
  119.70 -    casefile="$casestem"${badnum}.java
  119.71 -    cclassname=` basename "$casefile" .java `
  119.72 -    sed < "$template" > "$casefile" "
  119.73 -      s|@compile|@compile/fail|
  119.74 -      / @[a-z]/s|@|##|
  119.75 -      ${badnum}s:^ *[/*]*:    :
  119.76 -      s/${tclassname}/${cclassname}/g
  119.77 -    "
  119.78 -    $verbose && diff -u "$template" "$casefile"
  119.79 -  done
  119.80 -}
  119.81 -
  119.82 -getcasestem() {
  119.83 -  echo `basename $1` | sed 's/.*\///;s/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/'
  119.84 -}
  119.85 -
  119.86 -testneg() {
  119.87 -  template=$1
  119.88 -  for casefile in ` getcasestem "$template" `*.java; do
  119.89 -    $quiet || echo -------- $javac "$casefile"
  119.90 -    $javac "$casefile" > "$casefile".errlog 2>&1 && {
  119.91 -      echo "*** Compilation unexpectedly succeeded:  $casefile"
  119.92 -      exit 1
  119.93 -    }
  119.94 -    $quiet || echo "Compilation failed as expected"
  119.95 -    $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog
  119.96 -    rm "$casefile".errlog
  119.97 -  done
  119.98 -}
  119.99 -
 119.100 -main "$@"
   120.1 --- a/test/tools/javac/quid/QuotedIdent.java	Tue Sep 07 15:14:49 2010 -0700
   120.2 +++ b/test/tools/javac/quid/QuotedIdent.java	Tue Sep 07 15:49:48 2010 -0700
   120.3 @@ -1,5 +1,5 @@
   120.4  /*
   120.5 - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
   120.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
   120.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   120.8   *
   120.9   * This code is free software; you can redistribute it and/or modify it
  120.10 @@ -31,6 +31,7 @@
  120.11   *      (The filename, directory name, or volume label syntax is incorrect)
  120.12   *
  120.13   * @library ..
  120.14 + * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
  120.15   * @run main quid.QuotedIdent
  120.16   */
  120.17  
  120.18 @@ -119,7 +120,7 @@
  120.19          s = #"int".class.getName();
  120.20          check(31, s, QuotedIdent.class.getName()+"$int");
  120.21  
  120.22 -        Class x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
  120.23 +        Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
  120.24          if (x86 != #"*86".class)
  120.25              check(32, "reflected "+x86, "static "+#"*86".class);
  120.26  
   121.1 --- a/test/tools/javac/quid/QuotedIdent2.java	Tue Sep 07 15:14:49 2010 -0700
   121.2 +++ b/test/tools/javac/quid/QuotedIdent2.java	Tue Sep 07 15:49:48 2010 -0700
   121.3 @@ -1,5 +1,5 @@
   121.4  /*
   121.5 - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
   121.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
   121.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   121.8   *
   121.9   * This code is free software; you can redistribute it and/or modify it
  121.10 @@ -31,6 +31,7 @@
  121.11   *      (The filename, directory name, or volume label syntax is incorrect)
  121.12   *
  121.13   * @library ..
  121.14 + * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
  121.15   * @run main quid.QuotedIdent2
  121.16   */
  121.17  /*
  121.18 @@ -72,7 +73,7 @@
  121.19          s = QuotedIdent.#"int".class.getName();
  121.20          check(31, s, QuotedIdent.class.getName()+"$int");
  121.21  
  121.22 -        Class x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
  121.23 +        Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
  121.24          if (x86 != #"*86".class)
  121.25              check(32, "reflected "+x86, "static "+#"*86".class);
  121.26  
   122.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   122.2 +++ b/test/tools/javac/tree/ClassTreeTest.java	Tue Sep 07 15:49:48 2010 -0700
   122.3 @@ -0,0 +1,102 @@
   122.4 +/*
   122.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   122.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   122.7 + *
   122.8 + * This code is free software; you can redistribute it and/or modify it
   122.9 + * under the terms of the GNU General Public License version 2 only, as
  122.10 + * published by the Free Software Foundation.
  122.11 + *
  122.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  122.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  122.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  122.15 + * version 2 for more details (a copy is included in the LICENSE file that
  122.16 + * accompanied this code).
  122.17 + *
  122.18 + * You should have received a copy of the GNU General Public License version
  122.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  122.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  122.21 + *
  122.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  122.23 + * or visit www.oracle.com if you need additional information or have any
  122.24 + * questions.
  122.25 + */
  122.26 +
  122.27 +/*
  122.28 + * @test
  122.29 + * @bug 6570730
  122.30 + * @summary com.sun.source.tree.ModifiersTree.getFlags() should return class type
  122.31 + */
  122.32 +
  122.33 +import java.io.*;
  122.34 +import java.util.*;
  122.35 +import javax.tools.*;
  122.36 +import com.sun.source.tree.*;
  122.37 +import com.sun.source.util.*;
  122.38 +import com.sun.tools.javac.api.*;
  122.39 +
  122.40 +public class ClassTreeTest {
  122.41 +    public static void main(String... args) throws Exception {
  122.42 +        new ClassTreeTest().run();
  122.43 +    }
  122.44 +
  122.45 +    void run() throws Exception {
  122.46 +        JavacTool tool = JavacTool.create();
  122.47 +        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
  122.48 +        List<String> opts = Collections.<String>emptyList();
  122.49 +        File testSrc = new File(System.getProperty("test.src"));
  122.50 +        File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java");
  122.51 +        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
  122.52 +        JavacTask task = tool.getTask(null, fm, null, opts, null, fos);
  122.53 +        for (CompilationUnitTree cu: task.parse()) {
  122.54 +            check(cu, "CLASS", Tree.Kind.CLASS);
  122.55 +            check(cu, "INTERFACE", Tree.Kind.INTERFACE);
  122.56 +            check(cu, "ENUM", Tree.Kind.ENUM);
  122.57 +            check(cu, "ANNOTATION_TYPE", Tree.Kind.ANNOTATION_TYPE);
  122.58 +        }
  122.59 +
  122.60 +        int expected = 4;
  122.61 +        if (checks != expected)
  122.62 +            error("Unexpected number of checks performed; expected: " + expected + ", found: " + checks);
  122.63 +
  122.64 +        if (errors > 0)
  122.65 +            throw new Exception(errors + " errors found");
  122.66 +    }
  122.67 +
  122.68 +    void check(CompilationUnitTree cu, String name, Tree.Kind k) {
  122.69 +        checks++;
  122.70 +
  122.71 +        TreeScanner<ClassTree,String> s = new TreeScanner<ClassTree,String>() {
  122.72 +            @Override
  122.73 +            public ClassTree visitClass(ClassTree c, String name) {
  122.74 +                if (c.getSimpleName().toString().equals(name))
  122.75 +                    return c;
  122.76 +                else
  122.77 +                    return super.visitClass(c, name);
  122.78 +            }
  122.79 +
  122.80 +            @Override
  122.81 +            public ClassTree reduce(ClassTree t1, ClassTree t2) {
  122.82 +                return (t1 != null ? t1 : t2);
  122.83 +            }
  122.84 +        };
  122.85 +
  122.86 +        ClassTree c = s.scan(cu, name);
  122.87 +        if (c == null)
  122.88 +            error("Can't find node named " + name);
  122.89 +        else if (c.getKind() != k)
  122.90 +            error("Unexpected kind for node named " + name + ": expected: " + k + ", found: " + c.getKind());
  122.91 +    }
  122.92 +
  122.93 +    void error(String msg) {
  122.94 +        System.err.println("Error: " + msg);
  122.95 +        errors++;
  122.96 +    }
  122.97 +
  122.98 +    int checks;
  122.99 +    int errors;
 122.100 +
 122.101 +    class CLASS { }
 122.102 +    interface INTERFACE { }
 122.103 +    enum ENUM { }
 122.104 +    @interface ANNOTATION_TYPE { }
 122.105 +}
   123.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   123.2 +++ b/test/tools/javac/tree/TreeKindTest.java	Tue Sep 07 15:49:48 2010 -0700
   123.3 @@ -0,0 +1,132 @@
   123.4 +/*
   123.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
   123.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   123.7 + *
   123.8 + * This code is free software; you can redistribute it and/or modify it
   123.9 + * under the terms of the GNU General Public License version 2 only, as
  123.10 + * published by the Free Software Foundation.
  123.11 + *
  123.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  123.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  123.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  123.15 + * version 2 for more details (a copy is included in the LICENSE file that
  123.16 + * accompanied this code).
  123.17 + *
  123.18 + * You should have received a copy of the GNU General Public License version
  123.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  123.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  123.21 + *
  123.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  123.23 + * or visit www.oracle.com if you need additional information or have any
  123.24 + * questions.
  123.25 + */
  123.26 +
  123.27 +/*
  123.28 + * @test
  123.29 + * @bug 6341023
  123.30 + * @summary Tree API: Tree.Kind should have mapping to interface
  123.31 + */
  123.32 +
  123.33 +import com.sun.source.tree.*;
  123.34 +
  123.35 +public class TreeKindTest{
  123.36 +    public static void main(String... args) {
  123.37 +        boolean ok = true;
  123.38 +
  123.39 +        for (Tree.Kind k: Tree.Kind.values()) {
  123.40 +            //System.err.println(k + " " + k.asInterface());
  123.41 +            Class<? extends Tree> i = k.asInterface();
  123.42 +            switch (k) {
  123.43 +            case POSTFIX_INCREMENT:
  123.44 +            case POSTFIX_DECREMENT:
  123.45 +            case PREFIX_INCREMENT:
  123.46 +            case PREFIX_DECREMENT:
  123.47 +            case UNARY_PLUS:
  123.48 +            case UNARY_MINUS:
  123.49 +            case BITWISE_COMPLEMENT:
  123.50 +            case LOGICAL_COMPLEMENT:
  123.51 +                ok = ok & verify(k, i, i == UnaryTree.class);
  123.52 +                break;
  123.53 +
  123.54 +            case MULTIPLY:
  123.55 +            case DIVIDE:
  123.56 +            case REMAINDER:
  123.57 +            case PLUS:
  123.58 +            case MINUS:
  123.59 +            case LEFT_SHIFT:
  123.60 +            case RIGHT_SHIFT:
  123.61 +            case UNSIGNED_RIGHT_SHIFT:
  123.62 +            case LESS_THAN:
  123.63 +            case GREATER_THAN:
  123.64 +            case LESS_THAN_EQUAL:
  123.65 +            case GREATER_THAN_EQUAL:
  123.66 +            case EQUAL_TO:
  123.67 +            case NOT_EQUAL_TO:
  123.68 +            case AND:
  123.69 +            case XOR:
  123.70 +            case OR:
  123.71 +            case CONDITIONAL_AND:
  123.72 +            case CONDITIONAL_OR:
  123.73 +                ok = ok & verify(k, i, i == BinaryTree.class);
  123.74 +                break;
  123.75 +
  123.76 +            case MULTIPLY_ASSIGNMENT:
  123.77 +            case DIVIDE_ASSIGNMENT:
  123.78 +            case REMAINDER_ASSIGNMENT:
  123.79 +            case PLUS_ASSIGNMENT:
  123.80 +            case MINUS_ASSIGNMENT:
  123.81 +            case LEFT_SHIFT_ASSIGNMENT:
  123.82 +            case RIGHT_SHIFT_ASSIGNMENT:
  123.83 +            case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
  123.84 +            case AND_ASSIGNMENT:
  123.85 +            case XOR_ASSIGNMENT:
  123.86 +            case OR_ASSIGNMENT:
  123.87 +                ok = ok & verify(k, i, i == CompoundAssignmentTree.class);
  123.88 +                break;
  123.89 +
  123.90 +            case INT_LITERAL:
  123.91 +            case LONG_LITERAL:
  123.92 +            case FLOAT_LITERAL:
  123.93 +            case DOUBLE_LITERAL:
  123.94 +            case BOOLEAN_LITERAL:
  123.95 +            case CHAR_LITERAL:
  123.96 +            case STRING_LITERAL:
  123.97 +            case NULL_LITERAL:
  123.98 +                ok = ok & verify(k, i, i == LiteralTree.class);
  123.99 +                break;
 123.100 +
 123.101 +            case UNBOUNDED_WILDCARD:
 123.102 +            case EXTENDS_WILDCARD:
 123.103 +            case SUPER_WILDCARD:
 123.104 +                ok = ok & verify(k, i, i == WildcardTree.class);
 123.105 +                break;
 123.106 +
 123.107 +            case INTERFACE:
 123.108 +            case ANNOTATION_TYPE:
 123.109 +            case ENUM:
 123.110 +            case CLASS:
 123.111 +                ok = ok & verify(k, i, i == ClassTree.class);
 123.112 +                break;
 123.113 +
 123.114 +            case OTHER:
 123.115 +                ok = ok & verify(k, i, i == null);
 123.116 +                break;
 123.117 +
 123.118 +            default:
 123.119 +                String ks = k.toString().replace("_", "") + "tree";
 123.120 +                String iName = i.getName();
 123.121 +                String is = iName.substring(iName.lastIndexOf(".") + 1);
 123.122 +                ok = ok & verify(k, i, ks.equalsIgnoreCase(is));
 123.123 +            }
 123.124 +        }
 123.125 +
 123.126 +        if (!ok)
 123.127 +            throw new AssertionError("test failed");
 123.128 +    }
 123.129 +
 123.130 +    static boolean verify(Tree.Kind k, Class<?> c, boolean b) {
 123.131 +        if (!b)
 123.132 +            System.err.println("error: " + k + " " + c);
 123.133 +        return b;
 123.134 +    }
 123.135 +}
   124.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.2 +++ b/test/tools/javap/T6980017.java	Tue Sep 07 15:49:48 2010 -0700
   124.3 @@ -0,0 +1,78 @@
   124.4 +/*
   124.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   124.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   124.7 + *
   124.8 + * This code is free software; you can redistribute it and/or modify it
   124.9 + * under the terms of the GNU General Public License version 2 only, as
  124.10 + * published by the Free Software Foundation.
  124.11 + *
  124.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  124.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  124.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  124.15 + * version 2 for more details (a copy is included in the LICENSE file that
  124.16 + * accompanied this code).
  124.17 + *
  124.18 + * You should have received a copy of the GNU General Public License version
  124.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  124.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  124.21 + *
  124.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  124.23 + * or visit www.oracle.com if you need additional information or have any
  124.24 + * questions.
  124.25 + */
  124.26 +
  124.27 +/*
  124.28 + * @test
  124.29 + * @bug 6980017
  124.30 + * @summary javap -XDdetail:source behaves badly if source not available.
  124.31 + */
  124.32 +
  124.33 +import java.io.*;
  124.34 +
  124.35 +public class T6980017 {
  124.36 +    public static void main(String... args) throws Exception {
  124.37 +        new T6980017().run();
  124.38 +    }
  124.39 +
  124.40 +    void run() throws Exception {
  124.41 +
  124.42 +        String[] args = {
  124.43 +            "-v",
  124.44 +            "-XDdetails:source",
  124.45 +            "java.lang.String"
  124.46 +        };
  124.47 +
  124.48 +        StringWriter sw = new StringWriter();
  124.49 +        PrintWriter pw = new PrintWriter(sw);
  124.50 +        int rc = com.sun.tools.javap.Main.run(args, pw);
  124.51 +        pw.close();
  124.52 +        if (rc != 0)
  124.53 +            error("Unexpected exit code: " + rc);
  124.54 +
  124.55 +        boolean foundBlankSourceLine = false;
  124.56 +        boolean foundNoSourceLine = false;
  124.57 +        for (String line: sw.toString().split("[\r\n]+")) {
  124.58 +            System.err.println(line);
  124.59 +            if (line.contains("Source code not available"))
  124.60 +                foundNoSourceLine = true;
  124.61 +            if (line.matches("\\s*\\( *[0-9]+\\)\\s*"))
  124.62 +                foundBlankSourceLine = true;
  124.63 +        }
  124.64 +
  124.65 +        if (foundBlankSourceLine)
  124.66 +            error("found blank source lines");
  124.67 +
  124.68 +        if (!foundNoSourceLine)
  124.69 +            error("did not find \"Source code not available\" message");
  124.70 +
  124.71 +        if (errors > 0)
  124.72 +            throw new Exception(errors + " errors occurred");
  124.73 +    }
  124.74 +
  124.75 +    void error(String msg) {
  124.76 +        System.err.println(msg);
  124.77 +        errors++;
  124.78 +    }
  124.79 +
  124.80 +    int errors;
  124.81 +}

mercurial