Fri, 12 Jun 2015 18:44:36 -0700
Merge
test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java Wed Jun 10 18:15:56 2015 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java Fri Jun 12 18:44:36 2015 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -241,12 +241,16 @@ 1.11 listeners = listeners.prepend(sl); 1.12 } 1.13 1.14 - /** Remove symbol from this scope. Used when an inner class 1.15 - * attribute tells us that the class isn't a package member. 1.16 + /** Remove symbol from this scope. 1.17 */ 1.18 - public void remove(Symbol sym) { 1.19 + public void remove(final Symbol sym) { 1.20 Assert.check(shared == 0); 1.21 - Entry e = lookup(sym.name); 1.22 + Entry e = lookup(sym.name, new Filter<Symbol>() { 1.23 + @Override 1.24 + public boolean accepts(Symbol candidate) { 1.25 + return candidate == sym; 1.26 + } 1.27 + }); 1.28 if (e.scope == null) return; 1.29 1.30 // remove e from table and shadowed list;
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jun 10 18:15:56 2015 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Fri Jun 12 18:44:36 2015 -0700 2.3 @@ -2694,74 +2694,98 @@ 2.4 // </editor-fold> 2.5 2.6 // <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> 2.7 - class MembersClosureCache extends SimpleVisitor<CompoundScope, Boolean> { 2.8 - 2.9 - private WeakHashMap<TypeSymbol, Entry> _map = 2.10 - new WeakHashMap<TypeSymbol, Entry>(); 2.11 - 2.12 - class Entry { 2.13 - final boolean skipInterfaces; 2.14 - final CompoundScope compoundScope; 2.15 - 2.16 - public Entry(boolean skipInterfaces, CompoundScope compoundScope) { 2.17 - this.skipInterfaces = skipInterfaces; 2.18 - this.compoundScope = compoundScope; 2.19 + class MembersClosureCache extends SimpleVisitor<Scope.CompoundScope, Void> { 2.20 + 2.21 + private Map<TypeSymbol, CompoundScope> _map = new HashMap<>(); 2.22 + 2.23 + Set<TypeSymbol> seenTypes = new HashSet<>(); 2.24 + 2.25 + class MembersScope extends CompoundScope { 2.26 + 2.27 + CompoundScope scope; 2.28 + 2.29 + public MembersScope(CompoundScope scope) { 2.30 + super(scope.owner); 2.31 + this.scope = scope; 2.32 } 2.33 2.34 - boolean matches(boolean skipInterfaces) { 2.35 - return this.skipInterfaces == skipInterfaces; 2.36 + Filter<Symbol> combine(final Filter<Symbol> sf) { 2.37 + return new Filter<Symbol>() { 2.38 + @Override 2.39 + public boolean accepts(Symbol s) { 2.40 + return !s.owner.isInterface() && (sf == null || sf.accepts(s)); 2.41 + } 2.42 + }; 2.43 + } 2.44 + 2.45 + @Override 2.46 + public Iterable<Symbol> getElements(Filter<Symbol> sf) { 2.47 + return scope.getElements(combine(sf)); 2.48 + } 2.49 + 2.50 + @Override 2.51 + public Iterable<Symbol> getElementsByName(Name name, Filter<Symbol> sf) { 2.52 + return scope.getElementsByName(name, combine(sf)); 2.53 + } 2.54 + 2.55 + @Override 2.56 + public int getMark() { 2.57 + return scope.getMark(); 2.58 } 2.59 } 2.60 2.61 - List<TypeSymbol> seenTypes = List.nil(); 2.62 + CompoundScope nilScope; 2.63 2.64 /** members closure visitor methods **/ 2.65 2.66 - public CompoundScope visitType(Type t, Boolean skipInterface) { 2.67 - return null; 2.68 + public CompoundScope visitType(Type t, Void _unused) { 2.69 + if (nilScope == null) { 2.70 + nilScope = new CompoundScope(syms.noSymbol); 2.71 + } 2.72 + return nilScope; 2.73 } 2.74 2.75 @Override 2.76 - public CompoundScope visitClassType(ClassType t, Boolean skipInterface) { 2.77 - if (seenTypes.contains(t.tsym)) { 2.78 + public CompoundScope visitClassType(ClassType t, Void _unused) { 2.79 + if (!seenTypes.add(t.tsym)) { 2.80 //this is possible when an interface is implemented in multiple 2.81 - //superclasses, or when a classs hierarchy is circular - in such 2.82 + //superclasses, or when a class hierarchy is circular - in such 2.83 //cases we don't need to recurse (empty scope is returned) 2.84 return new CompoundScope(t.tsym); 2.85 } 2.86 try { 2.87 - seenTypes = seenTypes.prepend(t.tsym); 2.88 + seenTypes.add(t.tsym); 2.89 ClassSymbol csym = (ClassSymbol)t.tsym; 2.90 - Entry e = _map.get(csym); 2.91 - if (e == null || !e.matches(skipInterface)) { 2.92 - CompoundScope membersClosure = new CompoundScope(csym); 2.93 - if (!skipInterface) { 2.94 - for (Type i : interfaces(t)) { 2.95 - membersClosure.addSubScope(visit(i, skipInterface)); 2.96 - } 2.97 + CompoundScope membersClosure = _map.get(csym); 2.98 + if (membersClosure == null) { 2.99 + membersClosure = new CompoundScope(csym); 2.100 + for (Type i : interfaces(t)) { 2.101 + membersClosure.addSubScope(visit(i, null)); 2.102 } 2.103 - membersClosure.addSubScope(visit(supertype(t), skipInterface)); 2.104 + membersClosure.addSubScope(visit(supertype(t), null)); 2.105 membersClosure.addSubScope(csym.members()); 2.106 - e = new Entry(skipInterface, membersClosure); 2.107 - _map.put(csym, e); 2.108 + _map.put(csym, membersClosure); 2.109 } 2.110 - return e.compoundScope; 2.111 + return membersClosure; 2.112 } 2.113 finally { 2.114 - seenTypes = seenTypes.tail; 2.115 + seenTypes.remove(t.tsym); 2.116 } 2.117 } 2.118 2.119 @Override 2.120 - public CompoundScope visitTypeVar(TypeVar t, Boolean skipInterface) { 2.121 - return visit(t.getUpperBound(), skipInterface); 2.122 + public CompoundScope visitTypeVar(TypeVar t, Void _unused) { 2.123 + return visit(t.getUpperBound(), null); 2.124 } 2.125 } 2.126 2.127 private MembersClosureCache membersCache = new MembersClosureCache(); 2.128 2.129 public CompoundScope membersClosure(Type site, boolean skipInterface) { 2.130 - return membersCache.visit(site, skipInterface); 2.131 + CompoundScope cs = membersCache.visit(site, null); 2.132 + if (cs == null) 2.133 + Assert.error("type " + site); 2.134 + return skipInterface ? membersCache.new MembersScope(cs) : cs; 2.135 } 2.136 // </editor-fold> 2.137
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Jun 10 18:15:56 2015 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Jun 12 18:44:36 2015 -0700 3.3 @@ -825,9 +825,18 @@ 3.4 } 3.5 3.6 public void visitClassDef(JCClassDecl tree) { 3.7 - // Local classes have not been entered yet, so we need to do it now: 3.8 - if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) 3.9 + // Local and anonymous classes have not been entered yet, so we need to 3.10 + // do it now. 3.11 + if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) { 3.12 enter.classEnter(tree, env); 3.13 + } else { 3.14 + // If this class declaration is part of a class level annotation, 3.15 + // as in @MyAnno(new Object() {}) class MyClass {}, enter it in 3.16 + // order to simplify later steps and allow for sensible error 3.17 + // messages. 3.18 + if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree)) 3.19 + enter.classEnter(tree, env); 3.20 + } 3.21 3.22 ClassSymbol c = tree.sym; 3.23 if (c == null) {
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Jun 10 18:15:56 2015 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Fri Jun 12 18:44:36 2015 -0700 4.3 @@ -1256,6 +1256,9 @@ 4.4 return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); 4.5 case APPLY: 4.6 return true; 4.7 + case NEWCLASS: 4.8 + JCNewClass nc = (JCNewClass) rec; 4.9 + return nc.encl == null && nc.def == null && !TreeInfo.isDiamond(nc); 4.10 default: 4.11 return false; 4.12 } 4.13 @@ -1310,17 +1313,24 @@ 4.14 Type site; 4.15 4.16 if (rec != null) { 4.17 - if (rec.hasTag(APPLY)) { 4.18 - Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 4.19 - if (recSym == null) 4.20 - return null; 4.21 - Symbol resolvedReturnType = 4.22 - analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 4.23 - if (resolvedReturnType == null) 4.24 - return null; 4.25 - site = resolvedReturnType.type; 4.26 - } else { 4.27 - site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 4.28 + switch (rec.getTag()) { 4.29 + case APPLY: 4.30 + Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 4.31 + if (recSym == null) 4.32 + return null; 4.33 + Symbol resolvedReturnType = 4.34 + analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 4.35 + if (resolvedReturnType == null) 4.36 + return null; 4.37 + site = resolvedReturnType.type; 4.38 + break; 4.39 + case NEWCLASS: 4.40 + JCNewClass nc = (JCNewClass) rec; 4.41 + site = attribSpeculative(nc.clazz, env, attr.unknownTypeExprInfo).type; 4.42 + break; 4.43 + default: 4.44 + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 4.45 + break; 4.46 } 4.47 } else { 4.48 site = env.enclClass.sym.type;
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jun 10 18:15:56 2015 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jun 12 18:44:36 2015 -0700 5.3 @@ -271,7 +271,7 @@ 5.4 * the one of its outer environment 5.5 */ 5.6 protected static boolean isStatic(Env<AttrContext> env) { 5.7 - return env.info.staticLevel > env.outer.info.staticLevel; 5.8 + return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel; 5.9 } 5.10 5.11 /** An environment is an "initializer" if it is a constructor or
6.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jun 10 18:15:56 2015 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Fri Jun 12 18:44:36 2015 -0700 6.3 @@ -514,6 +514,10 @@ 6.4 clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); 6.5 } else { 6.6 checkStringConstant(vdef.init.pos(), sym.getConstValue()); 6.7 + /* if the init contains a reference to an external class, add it to the 6.8 + * constant's pool 6.9 + */ 6.10 + vdef.init.accept(classReferenceVisitor); 6.11 } 6.12 } 6.13 break; 6.14 @@ -2431,9 +2435,12 @@ 6.15 && !allowGenerics // no Miranda methods available with generics 6.16 ) 6.17 implementInterfaceMethods(c); 6.18 - cdef.defs = normalizeDefs(cdef.defs, c); 6.19 c.pool = pool; 6.20 pool.reset(); 6.21 + /* method normalizeDefs() can add references to external classes into the constant pool 6.22 + * so it should be called after pool.reset() 6.23 + */ 6.24 + cdef.defs = normalizeDefs(cdef.defs, c); 6.25 generateReferencesToPrunedTree(c, pool); 6.26 Env<GenContext> localEnv = 6.27 new Env<GenContext>(cdef, new GenContext());
7.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties Wed Jun 10 18:15:56 2015 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties Fri Jun 12 18:44:36 2015 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 # 7.5 -# Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 7.6 +# Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 7.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 # 7.9 # This code is free software; you can redistribute it and/or modify it 7.10 @@ -133,7 +133,7 @@ 7.11 7.12 javac.msg.usage.nonstandard.footer=\u3053\u308C\u3089\u306F\u975E\u6A19\u6E96\u30AA\u30D7\u30B7\u30E7\u30F3\u3067\u3042\u308A\u4E88\u544A\u306A\u3057\u306B\u5909\u66F4\u3055\u308C\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\u3002 7.13 7.14 -javac.msg.bug=\u30B3\u30F3\u30D1\u30A4\u30E9\u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F({0})\u3002Bug Parade\u3067\u91CD\u8907\u304C\u306A\u3044\u304B\u3092\u3054\u78BA\u8A8D\u306E\u3046\u3048\u3001Java Developer Connection (http://java.sun.com/webapps/bugreport)\u3067bug\u306E\u767B\u9332\u3092\u304A\u9858\u3044\u3044\u305F\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306B\u306F\u3001\u305D\u306E\u30D7\u30ED\u30B0\u30E9\u30E0\u3068\u4E0B\u8A18\u306E\u8A3A\u65AD\u5185\u5BB9\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u3054\u5354\u529B\u3042\u308A\u304C\u3068\u3046\u3054\u3056\u3044\u307E\u3059\u3002 7.15 +javac.msg.bug=\u30B3\u30F3\u30D1\u30A4\u30E9\u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F({0})\u3002\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3067\u91CD\u8907\u304C\u306A\u3044\u304B\u3092\u3054\u78BA\u8A8D\u306E\u3046\u3048\u3001Java Bug Database (http://bugreport.java.com/bugreport/)\u3067bug\u306E\u767B\u9332\u3092\u304A\u9858\u3044\u3044\u305F\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306B\u306F\u3001\u305D\u306E\u30D7\u30ED\u30B0\u30E9\u30E0\u3068\u4E0B\u8A18\u306E\u8A3A\u65AD\u5185\u5BB9\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u3054\u5354\u529B\u3042\u308A\u304C\u3068\u3046\u3054\u3056\u3044\u307E\u3059\u3002 7.16 7.17 javac.msg.io=\n\n\u5165\u51FA\u529B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\n\u8A73\u7D30\u306F\u6B21\u306E\u30B9\u30BF\u30C3\u30AF\u30FB\u30C8\u30EC\u30FC\u30B9\u3067\u8ABF\u67FB\u3057\u3066\u304F\u3060\u3055\u3044\u3002\n 7.18
8.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties Wed Jun 10 18:15:56 2015 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties Fri Jun 12 18:44:36 2015 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 # 8.5 -# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 8.6 +# Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 8.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 # 8.9 # This code is free software; you can redistribute it and/or modify it 8.10 @@ -133,7 +133,7 @@ 8.11 8.12 javac.msg.usage.nonstandard.footer=\u8FD9\u4E9B\u9009\u9879\u90FD\u662F\u975E\u6807\u51C6\u9009\u9879, \u5982\u6709\u66F4\u6539, \u6055\u4E0D\u53E6\u884C\u901A\u77E5\u3002 8.13 8.14 -javac.msg.bug=\u7F16\u8BD1\u5668 ({0}) \u4E2D\u51FA\u73B0\u5F02\u5E38\u9519\u8BEF\u3002 \u5982\u679C\u5728 Bug Parade \u4E2D\u6CA1\u6709\u627E\u5230\u8BE5\u9519\u8BEF, \u8BF7\u5728 Java Developer Connection (http://java.sun.com/webapps/bugreport) \u4E2D\u5EFA\u7ACB Bug\u3002\u8BF7\u5728\u62A5\u544A\u4E2D\u9644\u4E0A\u60A8\u7684\u7A0B\u5E8F\u548C\u4EE5\u4E0B\u8BCA\u65AD\u4FE1\u606F\u3002\u8C22\u8C22\u3002 8.15 +javac.msg.bug=\u7F16\u8BD1\u5668 ({0}) \u4E2D\u51FA\u73B0\u5F02\u5E38\u9519\u8BEF\u3002\u5982\u679C\u5728 Java Bug Database (http://bugreport.java.com/bugreport/) \u4E2D\u6CA1\u6709\u627E\u5230\u8BE5\u9519\u8BEF, \u8BF7\u5728\u8BE5\u6570\u636E\u5E93\u4E2D\u5EFA\u7ACB Bug\u3002\u8BF7\u5728\u62A5\u544A\u4E2D\u9644\u4E0A\u60A8\u7684\u7A0B\u5E8F\u548C\u4EE5\u4E0B\u8BCA\u65AD\u4FE1\u606F\u3002\u8C22\u8C22\u3002 8.16 8.17 javac.msg.io=\n\n\u53D1\u751F\u8F93\u5165/\u8F93\u51FA\u9519\u8BEF\u3002\n\u6709\u5173\u8BE6\u7EC6\u4FE1\u606F, \u8BF7\u53C2\u9605\u4EE5\u4E0B\u5806\u6808\u8DDF\u8E2A\u3002\n 8.18
9.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Wed Jun 10 18:15:56 2015 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Jun 12 18:44:36 2015 -0700 9.3 @@ -28,6 +28,7 @@ 9.4 9.5 9.6 import com.sun.source.tree.Tree; 9.7 +import com.sun.source.util.TreePath; 9.8 import com.sun.tools.javac.code.*; 9.9 import com.sun.tools.javac.comp.AttrContext; 9.10 import com.sun.tools.javac.comp.Env; 9.11 @@ -351,6 +352,18 @@ 9.12 return (lit.typetag == BOT); 9.13 } 9.14 9.15 + /** Return true iff this tree is a child of some annotation. */ 9.16 + public static boolean isInAnnotation(Env<?> env, JCTree tree) { 9.17 + TreePath tp = TreePath.getPath(env.toplevel, tree); 9.18 + if (tp != null) { 9.19 + for (Tree t : tp) { 9.20 + if (t.getKind() == Tree.Kind.ANNOTATION) 9.21 + return true; 9.22 + } 9.23 + } 9.24 + return false; 9.25 + } 9.26 + 9.27 public static String getCommentText(Env<?> env, JCTree tree) { 9.28 DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) 9.29 ? ((JCCompilationUnit) tree).docComments
10.1 --- a/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Wed Jun 10 18:15:56 2015 -0700 10.2 +++ b/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Fri Jun 12 18:44:36 2015 -0700 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -25,9 +25,9 @@ 10.11 10.12 /* 10.13 * @test 10.14 - * @bug 7153958 10.15 + * @bug 7153958 8073372 10.16 * @summary add constant pool reference to class containing inlined constants 10.17 - * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java 10.18 + * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java 10.19 * @run main CPoolRefClassContainingInlinedCts 10.20 */ 10.21 10.22 @@ -38,7 +38,8 @@ 10.23 import java.io.File; 10.24 import java.io.IOException; 10.25 10.26 -import static pkg.ClassToBeStaticallyImported.staticField; 10.27 +import static pkg.ClassToBeStaticallyImportedA.staticFieldA; 10.28 +import static pkg.ClassToBeStaticallyImportedB.staticFieldB; 10.29 10.30 public class CPoolRefClassContainingInlinedCts { 10.31 10.32 @@ -54,10 +55,14 @@ 10.33 10.34 void checkClassName(String className) { 10.35 switch (className) { 10.36 - case "SimpleAssignClass" : case "BinaryExpClass": 10.37 - case "UnaryExpClass" : case "CastClass": 10.38 - case "ParensClass" : case "CondClass": 10.39 - case "IfClass" : case "pkg/ClassToBeStaticallyImported": 10.40 + case "SimpleAssignClassA" : case "BinaryExpClassA": 10.41 + case "UnaryExpClassA" : case "CastClassA": 10.42 + case "ParensClassA" : case "CondClassA": 10.43 + case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA": 10.44 + case "SimpleAssignClassB" : case "BinaryExpClassB": 10.45 + case "UnaryExpClassB" : case "CastClassB": 10.46 + case "ParensClassB" : case "CondClassB": 10.47 + case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB": 10.48 numberOfReferencedClassesToBeChecked++; 10.49 } 10.50 } 10.51 @@ -76,59 +81,111 @@ 10.52 } 10.53 i += cpInfo.size(); 10.54 } 10.55 - if (numberOfReferencedClassesToBeChecked != 8) { 10.56 + if (numberOfReferencedClassesToBeChecked != 16) { 10.57 throw new AssertionError("Class reference missing in the constant pool"); 10.58 } 10.59 } 10.60 10.61 - private int assign = SimpleAssignClass.x; 10.62 - private int binary = BinaryExpClass.x + 1; 10.63 - private int unary = -UnaryExpClass.x; 10.64 - private int cast = (int)CastClass.x; 10.65 - private int parens = (ParensClass.x); 10.66 - private int cond = (CondClass.x == 1) ? 1 : 2; 10.67 - private static int ifConstant; 10.68 - private static int importStatic; 10.69 + private int assignA = SimpleAssignClassA.x; 10.70 + private int binaryA = BinaryExpClassA.x + 1; 10.71 + private int unaryA = -UnaryExpClassA.x; 10.72 + private int castA = (int)CastClassA.x; 10.73 + private int parensA = (ParensClassA.x); 10.74 + private int condA = (CondClassA.x == 1) ? 1 : 2; 10.75 + private static int ifConstantA; 10.76 + private static int importStaticA; 10.77 static { 10.78 - if (IfClass.x == 1) { 10.79 - ifConstant = 1; 10.80 + if (IfClassA.x == 1) { 10.81 + ifConstantA = 1; 10.82 } else { 10.83 - ifConstant = 2; 10.84 + ifConstantA = 2; 10.85 } 10.86 } 10.87 static { 10.88 - if (staticField == 1) { 10.89 - importStatic = 1; 10.90 + if (staticFieldA == 1) { 10.91 + importStaticA = 1; 10.92 } else { 10.93 - importStatic = 2; 10.94 + importStaticA = 2; 10.95 + } 10.96 + } 10.97 + 10.98 + // now as final constants 10.99 + private static final int assignB = SimpleAssignClassB.x; 10.100 + private static final int binaryB = BinaryExpClassB.x + 1; 10.101 + private static final int unaryB = -UnaryExpClassB.x; 10.102 + private static final int castB = (int)CastClassB.x; 10.103 + private static final int parensB = (ParensClassB.x); 10.104 + private static final int condB = (CondClassB.x == 1) ? 1 : 2; 10.105 + private static final int ifConstantB; 10.106 + private static final int importStaticB; 10.107 + static { 10.108 + if (IfClassB.x == 1) { 10.109 + ifConstantB = 1; 10.110 + } else { 10.111 + ifConstantB = 2; 10.112 + } 10.113 + } 10.114 + static { 10.115 + if (staticFieldB == 1) { 10.116 + importStaticB = 1; 10.117 + } else { 10.118 + importStaticB = 2; 10.119 } 10.120 } 10.121 } 10.122 10.123 -class SimpleAssignClass { 10.124 +class SimpleAssignClassA { 10.125 public static final int x = 1; 10.126 } 10.127 10.128 -class BinaryExpClass { 10.129 +class SimpleAssignClassB { 10.130 public static final int x = 1; 10.131 } 10.132 10.133 -class UnaryExpClass { 10.134 +class BinaryExpClassA { 10.135 public static final int x = 1; 10.136 } 10.137 10.138 -class CastClass { 10.139 +class BinaryExpClassB { 10.140 public static final int x = 1; 10.141 } 10.142 10.143 -class ParensClass { 10.144 +class UnaryExpClassA { 10.145 public static final int x = 1; 10.146 } 10.147 10.148 -class CondClass { 10.149 +class UnaryExpClassB { 10.150 public static final int x = 1; 10.151 } 10.152 10.153 -class IfClass { 10.154 +class CastClassA { 10.155 public static final int x = 1; 10.156 } 10.157 + 10.158 +class CastClassB { 10.159 + public static final int x = 1; 10.160 +} 10.161 + 10.162 +class ParensClassA { 10.163 + public static final int x = 1; 10.164 +} 10.165 + 10.166 +class ParensClassB { 10.167 + public static final int x = 1; 10.168 +} 10.169 + 10.170 +class CondClassA { 10.171 + public static final int x = 1; 10.172 +} 10.173 + 10.174 +class CondClassB { 10.175 + public static final int x = 1; 10.176 +} 10.177 + 10.178 +class IfClassA { 10.179 + public static final int x = 1; 10.180 +} 10.181 + 10.182 +class IfClassB { 10.183 + public static final int x = 1; 10.184 +}
11.1 --- a/test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java Wed Jun 10 18:15:56 2015 -0700 11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 11.3 @@ -1,29 +0,0 @@ 11.4 -/* 11.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 11.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 - * 11.8 - * This code is free software; you can redistribute it and/or modify it 11.9 - * under the terms of the GNU General Public License version 2 only, as 11.10 - * published by the Free Software Foundation. Oracle designates this 11.11 - * particular file as subject to the "Classpath" exception as provided 11.12 - * by Oracle in the LICENSE file that accompanied this code. 11.13 - * 11.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 11.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.17 - * version 2 for more details (a copy is included in the LICENSE file that 11.18 - * accompanied this code). 11.19 - * 11.20 - * You should have received a copy of the GNU General Public License version 11.21 - * 2 along with this work; if not, write to the Free Software Foundation, 11.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.23 - * 11.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.25 - * or visit www.oracle.com if you need additional information or have any 11.26 - * questions. 11.27 - */ 11.28 -package pkg; 11.29 - 11.30 -public class ClassToBeStaticallyImported { 11.31 - public static final int staticField = 1; 11.32 -}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java Fri Jun 12 18:44:36 2015 -0700 12.3 @@ -0,0 +1,29 @@ 12.4 +/* 12.5 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. Oracle designates this 12.11 + * particular file as subject to the "Classpath" exception as provided 12.12 + * by Oracle in the LICENSE file that accompanied this code. 12.13 + * 12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.17 + * version 2 for more details (a copy is included in the LICENSE file that 12.18 + * accompanied this code). 12.19 + * 12.20 + * You should have received a copy of the GNU General Public License version 12.21 + * 2 along with this work; if not, write to the Free Software Foundation, 12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.23 + * 12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.25 + * or visit www.oracle.com if you need additional information or have any 12.26 + * questions. 12.27 + */ 12.28 +package pkg; 12.29 + 12.30 +public class ClassToBeStaticallyImportedA { 12.31 + public static final int staticFieldA = 1; 12.32 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java Fri Jun 12 18:44:36 2015 -0700 13.3 @@ -0,0 +1,29 @@ 13.4 +/* 13.5 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. Oracle designates this 13.11 + * particular file as subject to the "Classpath" exception as provided 13.12 + * by Oracle in the LICENSE file that accompanied this code. 13.13 + * 13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.17 + * version 2 for more details (a copy is included in the LICENSE file that 13.18 + * accompanied this code). 13.19 + * 13.20 + * You should have received a copy of the GNU General Public License version 13.21 + * 2 along with this work; if not, write to the Free Software Foundation, 13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.23 + * 13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.25 + * or visit www.oracle.com if you need additional information or have any 13.26 + * questions. 13.27 + */ 13.28 +package pkg; 13.29 + 13.30 +public class ClassToBeStaticallyImportedB { 13.31 + public static final int staticFieldB = 1; 13.32 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/annotations/neg/AnonSubclass.java Fri Jun 12 18:44:36 2015 -0700 14.3 @@ -0,0 +1,13 @@ 14.4 +/* 14.5 + * @test /nodynamiccopyright/ 14.6 + * @bug 8028389 14.7 + * @summary javac should output a proper error message when given something 14.8 + * like new Object(){} as annotation argument. 14.9 + * 14.10 + * @compile/fail/ref=AnonSubclass.out -XDrawDiagnostics AnonSubclass.java 14.11 + */ 14.12 + 14.13 +@AnonSubclass(new Object(){}) 14.14 +@interface AnonSubclass { 14.15 + String value(); 14.16 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/annotations/neg/AnonSubclass.out Fri Jun 12 18:44:36 2015 -0700 15.3 @@ -0,0 +1,2 @@ 15.4 +AnonSubclass.java:10:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) 15.5 +1 error
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java Fri Jun 12 18:44:36 2015 -0700 16.3 @@ -0,0 +1,28 @@ 16.4 +/* 16.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +package pkg; 16.28 + 16.29 +@interface AnonSubclassOnPkg { 16.30 + String value(); 16.31 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/annotations/neg/pkg/package-info.java Fri Jun 12 18:44:36 2015 -0700 17.3 @@ -0,0 +1,12 @@ 17.4 +/* 17.5 + * @test /nodynamiccopyright/ 17.6 + * @bug 8028389 17.7 + * @summary javac should output a proper error message when given something 17.8 + * like new Object(){} as annotation argument. 17.9 + * 17.10 + * @compile AnonSubclassOnPkg.java 17.11 + * @compile/fail/ref=package-info.out -XDrawDiagnostics package-info.java 17.12 + */ 17.13 + 17.14 +@AnonSubclassOnPkg(new Object(){}) 17.15 +package pkg;
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/annotations/neg/pkg/package-info.out Fri Jun 12 18:44:36 2015 -0700 18.3 @@ -0,0 +1,2 @@ 18.4 +package-info.java:11:20: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) 18.5 +1 error
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java Fri Jun 12 18:44:36 2015 -0700 19.3 @@ -0,0 +1,178 @@ 19.4 +/* 19.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/* 19.28 + * @test 19.29 + * @bug 8079613 19.30 + * @summary Ensure that compiler ascertains a class of patently non-poly expressions as such 19.31 + * @run main/timeout=10 DeeplyChainedNonPolyExpressionTest 19.32 + */ 19.33 + 19.34 +public class DeeplyChainedNonPolyExpressionTest { 19.35 + static class JSO { 19.36 + 19.37 + JSO put(String s, Object y) { 19.38 + return null; 19.39 + } 19.40 + 19.41 + JSO put(java.lang.String x, java.util.Collection<String> y) { 19.42 + return null; 19.43 + } 19.44 + 19.45 + JSO put(java.lang.String x, int y) { 19.46 + return null; 19.47 + } 19.48 + 19.49 + JSO put(java.lang.String x, long y) { 19.50 + return null; 19.51 + } 19.52 + 19.53 + JSO put(java.lang.String x, double y) { 19.54 + return null; 19.55 + } 19.56 + 19.57 + JSO put(java.lang.String x, java.util.Map<String, String> y) { 19.58 + return null; 19.59 + } 19.60 + 19.61 + JSO put(java.lang.String x, boolean y) { 19.62 + return null; 19.63 + } 19.64 + } 19.65 + 19.66 + static class JSA { 19.67 + 19.68 + JSA put(Object o) { 19.69 + return null; 19.70 + } 19.71 + 19.72 + JSA put(int i, Object x) { 19.73 + return null; 19.74 + } 19.75 + 19.76 + JSA put(boolean x) { 19.77 + return null; 19.78 + } 19.79 + 19.80 + JSA put(int x) { 19.81 + return null; 19.82 + } 19.83 + 19.84 + JSA put(int i, int x) { 19.85 + return null; 19.86 + } 19.87 + 19.88 + JSA put(int x, boolean y) { 19.89 + return null; 19.90 + } 19.91 + 19.92 + JSA put(int i, long x) { 19.93 + return null; 19.94 + } 19.95 + 19.96 + JSA put(long x) { 19.97 + return null; 19.98 + } 19.99 + 19.100 + JSA put(java.util.Collection<String> x) { 19.101 + return null; 19.102 + } 19.103 + 19.104 + JSA put(int i, java.util.Collection<String> x) { 19.105 + return null; 19.106 + } 19.107 + 19.108 + JSA put(int i, java.util.Map<String, String> x) { 19.109 + return null; 19.110 + } 19.111 + 19.112 + JSA put(java.util.Map<String, String> x) { 19.113 + return null; 19.114 + } 19.115 + 19.116 + JSA put(int i, double x) { 19.117 + return null; 19.118 + } 19.119 + 19.120 + JSA put(double x) { 19.121 + return null; 19.122 + } 19.123 + } 19.124 + 19.125 + public static void main(String [] args) { 19.126 + } 19.127 + public static void foo() { 19.128 + new JSO() 19.129 + .put("s", new JSA()) 19.130 + .put("s", new JSA()) 19.131 + .put("s", new JSO() 19.132 + .put("s", new JSO() 19.133 + .put("s", new JSA().put("s")) 19.134 + .put("s", new JSA()) 19.135 + .put("s", new JSO() 19.136 + .put("s", new JSO() 19.137 + .put("s", new JSA().put("s").put("s")) 19.138 + .put("s", new JSA()) 19.139 + .put("s", new JSO() 19.140 + .put("s", new JSO() 19.141 + .put("s", new JSA().put("s").put("s").put("s") 19.142 + .put("s").put("s").put("s") 19.143 + .put("s").put("s")) 19.144 + .put("s", new JSA()) 19.145 + .put("s", new JSO() 19.146 + .put("s", new JSO() 19.147 + .put("s", new JSA().put("s")) 19.148 + .put("s", new JSA()) 19.149 + ) 19.150 + ) 19.151 + ) 19.152 + ) 19.153 + ) 19.154 + .put("s", new JSO() 19.155 + .put("s", new JSA().put("s")) 19.156 + .put("s", new JSA()) 19.157 + .put("s", new JSO() 19.158 + .put("s", new JSO() 19.159 + .put("s", new JSA().put("s").put("s")) 19.160 + .put("s", new JSA()) 19.161 + .put("s", new JSO() 19.162 + .put("s", new JSO() 19.163 + .put("s", new JSA().put("s").put("s").put("s") 19.164 + .put("s").put("s").put("s") 19.165 + .put("s").put("s")) 19.166 + .put("s", new JSA()) 19.167 + .put("s", new JSO() 19.168 + .put("s", new JSO() 19.169 + .put("s", new JSA().put("s")) 19.170 + .put("s", new JSA())) 19.171 + ) 19.172 + ) 19.173 + ) 19.174 + ) 19.175 + ) 19.176 + ) 19.177 + ) 19.178 + ) 19.179 + ); 19.180 + } 19.181 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/scope/RemoveSymbolTest.java Fri Jun 12 18:44:36 2015 -0700 20.3 @@ -0,0 +1,77 @@ 20.4 +/* 20.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +/* 20.28 + * @test 20.29 + * @bug 8080842 20.30 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. 20.31 + * @run main RemoveSymbolTest 20.32 + */ 20.33 + 20.34 +import java.util.Iterator; 20.35 +import java.util.LinkedList; 20.36 + 20.37 +public class RemoveSymbolTest<W> implements Iterable<W> { 20.38 + static class Widget { 20.39 + private String name; 20.40 + Widget(String s) { name = s; } 20.41 + @Override public String toString() { return name; } 20.42 + } 20.43 + 20.44 + private LinkedList<W> data; 20.45 + // Instantiate an Iterable instance using a Lambda expression. 20.46 + // Causes ClassFormatError if a local variable of type Widget is named after one of the methods. 20.47 + private final Iterable<W> myIterator1 = () -> new Iterator<W>() { 20.48 + private W hasNext = null; 20.49 + private int index = 0; 20.50 + @Override public boolean hasNext() { return index < data.size(); } 20.51 + @Override public W next() { return data.get(index++); } 20.52 + }; 20.53 + 20.54 + // Instantiate an Iterable instance using an anonymous class. 20.55 + // Always works fine regardless of the name of the local variable. 20.56 + private final Iterable<W> myIterator2 = 20.57 + new Iterable<W>() { 20.58 + @Override 20.59 + public Iterator<W> iterator() { 20.60 + return new Iterator<W>() { 20.61 + private W hasNext = null; 20.62 + private int index = 0; 20.63 + @Override public boolean hasNext() { return index < data.size(); } 20.64 + @Override public W next() { return data.get(index++); } 20.65 + }; 20.66 + } 20.67 + }; 20.68 + public RemoveSymbolTest() { data = new LinkedList<>(); } 20.69 + public void add(W e) { data.add(e); } 20.70 + @Override public String toString() { return data.toString(); } 20.71 + @Override public Iterator<W> iterator() { return myIterator1.iterator(); } 20.72 + public static void main(String[] args) { 20.73 + RemoveSymbolTest<Widget> widgets = new RemoveSymbolTest<>(); 20.74 + widgets.add(new Widget("W1")); 20.75 + widgets.add(new Widget("W2")); 20.76 + widgets.add(new Widget("W3")); 20.77 + System.out.println(".foreach() call: "); 20.78 + widgets.forEach(w -> System.out.println(w + " ")); 20.79 + } 20.80 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/scope/RemoveSymbolUnitTest.java Fri Jun 12 18:44:36 2015 -0700 21.3 @@ -0,0 +1,95 @@ 21.4 +/* 21.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.23 + * or visit www.oracle.com if you need additional information or have any 21.24 + * questions. 21.25 + */ 21.26 + 21.27 +/* 21.28 + * @test 21.29 + * @bug 8080842 21.30 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. 21.31 + */ 21.32 + 21.33 +import com.sun.tools.javac.util.*; 21.34 +import com.sun.tools.javac.code.*; 21.35 +import com.sun.tools.javac.code.Scope.*; 21.36 +import com.sun.tools.javac.code.Symbol.*; 21.37 +import com.sun.tools.javac.file.JavacFileManager; 21.38 + 21.39 +public class RemoveSymbolUnitTest { 21.40 + 21.41 + Context context; 21.42 + Names names; 21.43 + Symtab symtab; 21.44 + 21.45 + public static void main(String... args) throws Exception { 21.46 + new RemoveSymbolUnitTest().run(); 21.47 + } 21.48 + 21.49 + public void run() { 21.50 + context = new Context(); 21.51 + JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab 21.52 + names = Names.instance(context); 21.53 + symtab = Symtab.instance(context); 21.54 + 21.55 + Name hasNext = names.fromString("hasNext"); 21.56 + ClassSymbol clazz = new ClassSymbol(0, 21.57 + names.fromString("X"), 21.58 + Type.noType, 21.59 + symtab.unnamedPackage); 21.60 + 21.61 + VarSymbol v = new VarSymbol(0, hasNext, Type.noType, clazz); 21.62 + MethodSymbol m = new MethodSymbol(0, hasNext, Type.noType, clazz); 21.63 + 21.64 + // Try enter and remove in different shuffled combinations. 21.65 + // working with fresh scope each time. 21.66 + Scope cs = new Scope(clazz); 21.67 + cs.enter(v); 21.68 + cs.enter(m); 21.69 + cs.remove(v); 21.70 + Symbol s = cs.lookup(hasNext).sym; 21.71 + if (s != m) 21.72 + throw new AssertionError("Wrong symbol"); 21.73 + 21.74 + cs = new Scope(clazz); 21.75 + cs.enter(m); 21.76 + cs.enter(v); 21.77 + cs.remove(v); 21.78 + s = cs.lookup(hasNext).sym; 21.79 + if (s != m) 21.80 + throw new AssertionError("Wrong symbol"); 21.81 + 21.82 + cs = new Scope(clazz); 21.83 + cs.enter(v); 21.84 + cs.enter(m); 21.85 + cs.remove(m); 21.86 + s = cs.lookup(hasNext).sym; 21.87 + if (s != v) 21.88 + throw new AssertionError("Wrong symbol"); 21.89 + 21.90 + cs = new Scope(clazz); 21.91 + cs.enter(m); 21.92 + cs.enter(v); 21.93 + cs.remove(m); 21.94 + s = cs.lookup(hasNext).sym; 21.95 + if (s != v) 21.96 + throw new AssertionError("Wrong symbol"); 21.97 + } 21.98 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/types/ScopeListenerTest.java Fri Jun 12 18:44:36 2015 -0700 22.3 @@ -0,0 +1,82 @@ 22.4 +/* 22.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +/* 22.28 + * @test 22.29 + * @bug 8039262 22.30 + * @summary Ensure that using Types.membersClosure does not increase the number of listeners on the 22.31 + * class's members Scope. 22.32 + */ 22.33 + 22.34 +import com.sun.tools.javac.code.Scope; 22.35 +import com.sun.tools.javac.code.Symbol; 22.36 +import com.sun.tools.javac.code.Symtab; 22.37 +import com.sun.tools.javac.code.Types; 22.38 +import com.sun.tools.javac.file.JavacFileManager; 22.39 +import com.sun.tools.javac.util.Context; 22.40 +import com.sun.tools.javac.util.Names; 22.41 +import java.lang.reflect.Field; 22.42 +import java.util.Collection; 22.43 + 22.44 +public class ScopeListenerTest { 22.45 + 22.46 + public static void main(String[] args) throws Exception { 22.47 + new ScopeListenerTest().run(); 22.48 + } 22.49 + 22.50 + void run() throws Exception { 22.51 + Context context = new Context(); 22.52 + JavacFileManager.preRegister(context); 22.53 + Types types = Types.instance(context); 22.54 + Symtab syms = Symtab.instance(context); 22.55 + Names names = Names.instance(context); 22.56 + types.membersClosure(syms.stringType, true); 22.57 + types.membersClosure(syms.stringType, false); 22.58 + 22.59 + Field listenersField = Scope.class.getDeclaredField("listeners"); 22.60 + 22.61 + listenersField.setAccessible(true); 22.62 + 22.63 + int listenerCount = 22.64 + ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); 22.65 + 22.66 + for (int i = 0; i < 100; i++) { 22.67 + types.membersClosure(syms.stringType, true); 22.68 + types.membersClosure(syms.stringType, false); 22.69 + } 22.70 + 22.71 + int newListenerCount 22.72 + = ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); 22.73 + 22.74 + if (listenerCount != newListenerCount) { 22.75 + throw new AssertionError("Orig listener count: " + listenerCount + 22.76 + "; new listener count: " + newListenerCount); 22.77 + } 22.78 + 22.79 + for (Symbol s : types.membersClosure(syms.stringType, true).getElements()) 22.80 + ; 22.81 + for (Symbol s : types.membersClosure(syms.stringType, false).getElementsByName(names.fromString("substring"))) 22.82 + ; 22.83 + } 22.84 + 22.85 +}