Wed, 17 Jun 2015 23:29:40 -0700
Merge
.hgtags | file | annotate | diff | comparison | revisions | |
test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgtags Mon Jun 15 11:41:41 2015 -0700 1.2 +++ b/.hgtags Wed Jun 17 23:29:40 2015 -0700 1.3 @@ -442,6 +442,7 @@ 1.4 87dcdc1fd75bf827c8a4596b183de7ea73cb75e1 jdk8u60-b17 1.5 e7e42c79861ea1ab7495de5f238c01f98035a8a8 jdk8u60-b18 1.6 0366d7f1faa12ed35694571c151524e0847f05ff jdk8u60-b19 1.7 +976523f1d5626bdb6dd47883e2734614b64a5e61 jdk8u60-b20 1.8 779397f90251ea813cb44621dc27f780e5c20449 jdk8u52-b06 1.9 e0ce6be9142ed1e2f0ce3ee13090ec01c6c44721 jdk8u52-b07 1.10 779397f90251ea813cb44621dc27f780e5c20449 jdk8u65-b00
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java Mon Jun 15 11:41:41 2015 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java Wed Jun 17 23:29:40 2015 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -241,12 +241,16 @@ 2.11 listeners = listeners.prepend(sl); 2.12 } 2.13 2.14 - /** Remove symbol from this scope. Used when an inner class 2.15 - * attribute tells us that the class isn't a package member. 2.16 + /** Remove symbol from this scope. 2.17 */ 2.18 - public void remove(Symbol sym) { 2.19 + public void remove(final Symbol sym) { 2.20 Assert.check(shared == 0); 2.21 - Entry e = lookup(sym.name); 2.22 + Entry e = lookup(sym.name, new Filter<Symbol>() { 2.23 + @Override 2.24 + public boolean accepts(Symbol candidate) { 2.25 + return candidate == sym; 2.26 + } 2.27 + }); 2.28 if (e.scope == null) return; 2.29 2.30 // remove e from table and shadowed list;
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Mon Jun 15 11:41:41 2015 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jun 17 23:29:40 2015 -0700 3.3 @@ -2694,74 +2694,98 @@ 3.4 // </editor-fold> 3.5 3.6 // <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> 3.7 - class MembersClosureCache extends SimpleVisitor<CompoundScope, Boolean> { 3.8 - 3.9 - private WeakHashMap<TypeSymbol, Entry> _map = 3.10 - new WeakHashMap<TypeSymbol, Entry>(); 3.11 - 3.12 - class Entry { 3.13 - final boolean skipInterfaces; 3.14 - final CompoundScope compoundScope; 3.15 - 3.16 - public Entry(boolean skipInterfaces, CompoundScope compoundScope) { 3.17 - this.skipInterfaces = skipInterfaces; 3.18 - this.compoundScope = compoundScope; 3.19 + class MembersClosureCache extends SimpleVisitor<Scope.CompoundScope, Void> { 3.20 + 3.21 + private Map<TypeSymbol, CompoundScope> _map = new HashMap<>(); 3.22 + 3.23 + Set<TypeSymbol> seenTypes = new HashSet<>(); 3.24 + 3.25 + class MembersScope extends CompoundScope { 3.26 + 3.27 + CompoundScope scope; 3.28 + 3.29 + public MembersScope(CompoundScope scope) { 3.30 + super(scope.owner); 3.31 + this.scope = scope; 3.32 } 3.33 3.34 - boolean matches(boolean skipInterfaces) { 3.35 - return this.skipInterfaces == skipInterfaces; 3.36 + Filter<Symbol> combine(final Filter<Symbol> sf) { 3.37 + return new Filter<Symbol>() { 3.38 + @Override 3.39 + public boolean accepts(Symbol s) { 3.40 + return !s.owner.isInterface() && (sf == null || sf.accepts(s)); 3.41 + } 3.42 + }; 3.43 + } 3.44 + 3.45 + @Override 3.46 + public Iterable<Symbol> getElements(Filter<Symbol> sf) { 3.47 + return scope.getElements(combine(sf)); 3.48 + } 3.49 + 3.50 + @Override 3.51 + public Iterable<Symbol> getElementsByName(Name name, Filter<Symbol> sf) { 3.52 + return scope.getElementsByName(name, combine(sf)); 3.53 + } 3.54 + 3.55 + @Override 3.56 + public int getMark() { 3.57 + return scope.getMark(); 3.58 } 3.59 } 3.60 3.61 - List<TypeSymbol> seenTypes = List.nil(); 3.62 + CompoundScope nilScope; 3.63 3.64 /** members closure visitor methods **/ 3.65 3.66 - public CompoundScope visitType(Type t, Boolean skipInterface) { 3.67 - return null; 3.68 + public CompoundScope visitType(Type t, Void _unused) { 3.69 + if (nilScope == null) { 3.70 + nilScope = new CompoundScope(syms.noSymbol); 3.71 + } 3.72 + return nilScope; 3.73 } 3.74 3.75 @Override 3.76 - public CompoundScope visitClassType(ClassType t, Boolean skipInterface) { 3.77 - if (seenTypes.contains(t.tsym)) { 3.78 + public CompoundScope visitClassType(ClassType t, Void _unused) { 3.79 + if (!seenTypes.add(t.tsym)) { 3.80 //this is possible when an interface is implemented in multiple 3.81 - //superclasses, or when a classs hierarchy is circular - in such 3.82 + //superclasses, or when a class hierarchy is circular - in such 3.83 //cases we don't need to recurse (empty scope is returned) 3.84 return new CompoundScope(t.tsym); 3.85 } 3.86 try { 3.87 - seenTypes = seenTypes.prepend(t.tsym); 3.88 + seenTypes.add(t.tsym); 3.89 ClassSymbol csym = (ClassSymbol)t.tsym; 3.90 - Entry e = _map.get(csym); 3.91 - if (e == null || !e.matches(skipInterface)) { 3.92 - CompoundScope membersClosure = new CompoundScope(csym); 3.93 - if (!skipInterface) { 3.94 - for (Type i : interfaces(t)) { 3.95 - membersClosure.addSubScope(visit(i, skipInterface)); 3.96 - } 3.97 + CompoundScope membersClosure = _map.get(csym); 3.98 + if (membersClosure == null) { 3.99 + membersClosure = new CompoundScope(csym); 3.100 + for (Type i : interfaces(t)) { 3.101 + membersClosure.addSubScope(visit(i, null)); 3.102 } 3.103 - membersClosure.addSubScope(visit(supertype(t), skipInterface)); 3.104 + membersClosure.addSubScope(visit(supertype(t), null)); 3.105 membersClosure.addSubScope(csym.members()); 3.106 - e = new Entry(skipInterface, membersClosure); 3.107 - _map.put(csym, e); 3.108 + _map.put(csym, membersClosure); 3.109 } 3.110 - return e.compoundScope; 3.111 + return membersClosure; 3.112 } 3.113 finally { 3.114 - seenTypes = seenTypes.tail; 3.115 + seenTypes.remove(t.tsym); 3.116 } 3.117 } 3.118 3.119 @Override 3.120 - public CompoundScope visitTypeVar(TypeVar t, Boolean skipInterface) { 3.121 - return visit(t.getUpperBound(), skipInterface); 3.122 + public CompoundScope visitTypeVar(TypeVar t, Void _unused) { 3.123 + return visit(t.getUpperBound(), null); 3.124 } 3.125 } 3.126 3.127 private MembersClosureCache membersCache = new MembersClosureCache(); 3.128 3.129 public CompoundScope membersClosure(Type site, boolean skipInterface) { 3.130 - return membersCache.visit(site, skipInterface); 3.131 + CompoundScope cs = membersCache.visit(site, null); 3.132 + if (cs == null) 3.133 + Assert.error("type " + site); 3.134 + return skipInterface ? membersCache.new MembersScope(cs) : cs; 3.135 } 3.136 // </editor-fold> 3.137
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Jun 15 11:41:41 2015 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Jun 17 23:29:40 2015 -0700 4.3 @@ -825,9 +825,18 @@ 4.4 } 4.5 4.6 public void visitClassDef(JCClassDecl tree) { 4.7 - // Local classes have not been entered yet, so we need to do it now: 4.8 - if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) 4.9 + // Local and anonymous classes have not been entered yet, so we need to 4.10 + // do it now. 4.11 + if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) { 4.12 enter.classEnter(tree, env); 4.13 + } else { 4.14 + // If this class declaration is part of a class level annotation, 4.15 + // as in @MyAnno(new Object() {}) class MyClass {}, enter it in 4.16 + // order to simplify later steps and allow for sensible error 4.17 + // messages. 4.18 + if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree)) 4.19 + enter.classEnter(tree, env); 4.20 + } 4.21 4.22 ClassSymbol c = tree.sym; 4.23 if (c == null) {
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon Jun 15 11:41:41 2015 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Jun 17 23:29:40 2015 -0700 5.3 @@ -1256,6 +1256,9 @@ 5.4 return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); 5.5 case APPLY: 5.6 return true; 5.7 + case NEWCLASS: 5.8 + JCNewClass nc = (JCNewClass) rec; 5.9 + return nc.encl == null && nc.def == null && !TreeInfo.isDiamond(nc); 5.10 default: 5.11 return false; 5.12 } 5.13 @@ -1310,17 +1313,24 @@ 5.14 Type site; 5.15 5.16 if (rec != null) { 5.17 - if (rec.hasTag(APPLY)) { 5.18 - Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 5.19 - if (recSym == null) 5.20 - return null; 5.21 - Symbol resolvedReturnType = 5.22 - analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 5.23 - if (resolvedReturnType == null) 5.24 - return null; 5.25 - site = resolvedReturnType.type; 5.26 - } else { 5.27 - site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 5.28 + switch (rec.getTag()) { 5.29 + case APPLY: 5.30 + Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 5.31 + if (recSym == null) 5.32 + return null; 5.33 + Symbol resolvedReturnType = 5.34 + analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 5.35 + if (resolvedReturnType == null) 5.36 + return null; 5.37 + site = resolvedReturnType.type; 5.38 + break; 5.39 + case NEWCLASS: 5.40 + JCNewClass nc = (JCNewClass) rec; 5.41 + site = attribSpeculative(nc.clazz, env, attr.unknownTypeExprInfo).type; 5.42 + break; 5.43 + default: 5.44 + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 5.45 + break; 5.46 } 5.47 } else { 5.48 site = env.enclClass.sym.type;
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Jun 15 11:41:41 2015 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jun 17 23:29:40 2015 -0700 6.3 @@ -271,7 +271,7 @@ 6.4 * the one of its outer environment 6.5 */ 6.6 protected static boolean isStatic(Env<AttrContext> env) { 6.7 - return env.info.staticLevel > env.outer.info.staticLevel; 6.8 + return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel; 6.9 } 6.10 6.11 /** An environment is an "initializer" if it is a constructor or
7.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon Jun 15 11:41:41 2015 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jun 17 23:29:40 2015 -0700 7.3 @@ -514,6 +514,10 @@ 7.4 clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); 7.5 } else { 7.6 checkStringConstant(vdef.init.pos(), sym.getConstValue()); 7.7 + /* if the init contains a reference to an external class, add it to the 7.8 + * constant's pool 7.9 + */ 7.10 + vdef.init.accept(classReferenceVisitor); 7.11 } 7.12 } 7.13 break; 7.14 @@ -2431,9 +2435,12 @@ 7.15 && !allowGenerics // no Miranda methods available with generics 7.16 ) 7.17 implementInterfaceMethods(c); 7.18 - cdef.defs = normalizeDefs(cdef.defs, c); 7.19 c.pool = pool; 7.20 pool.reset(); 7.21 + /* method normalizeDefs() can add references to external classes into the constant pool 7.22 + * so it should be called after pool.reset() 7.23 + */ 7.24 + cdef.defs = normalizeDefs(cdef.defs, c); 7.25 generateReferencesToPrunedTree(c, pool); 7.26 Env<GenContext> localEnv = 7.27 new Env<GenContext>(cdef, new GenContext());
8.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties Mon Jun 15 11:41:41 2015 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties Wed Jun 17 23:29:40 2015 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 # 8.5 -# Copyright (c) 1999, 2014, 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=\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 8.13 8.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 8.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 8.16 8.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 8.18
9.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties Mon Jun 15 11:41:41 2015 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties Wed Jun 17 23:29:40 2015 -0700 9.3 @@ -1,5 +1,5 @@ 9.4 # 9.5 -# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 9.6 +# Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 9.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 # 9.9 # This code is free software; you can redistribute it and/or modify it 9.10 @@ -133,7 +133,7 @@ 9.11 9.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 9.13 9.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 9.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 9.16 9.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 9.18
10.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon Jun 15 11:41:41 2015 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Wed Jun 17 23:29:40 2015 -0700 10.3 @@ -28,6 +28,7 @@ 10.4 10.5 10.6 import com.sun.source.tree.Tree; 10.7 +import com.sun.source.util.TreePath; 10.8 import com.sun.tools.javac.code.*; 10.9 import com.sun.tools.javac.comp.AttrContext; 10.10 import com.sun.tools.javac.comp.Env; 10.11 @@ -351,6 +352,18 @@ 10.12 return (lit.typetag == BOT); 10.13 } 10.14 10.15 + /** Return true iff this tree is a child of some annotation. */ 10.16 + public static boolean isInAnnotation(Env<?> env, JCTree tree) { 10.17 + TreePath tp = TreePath.getPath(env.toplevel, tree); 10.18 + if (tp != null) { 10.19 + for (Tree t : tp) { 10.20 + if (t.getKind() == Tree.Kind.ANNOTATION) 10.21 + return true; 10.22 + } 10.23 + } 10.24 + return false; 10.25 + } 10.26 + 10.27 public static String getCommentText(Env<?> env, JCTree tree) { 10.28 DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) 10.29 ? ((JCCompilationUnit) tree).docComments
11.1 --- a/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Mon Jun 15 11:41:41 2015 -0700 11.2 +++ b/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Wed Jun 17 23:29:40 2015 -0700 11.3 @@ -1,5 +1,5 @@ 11.4 /* 11.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 11.6 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 11.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.8 * 11.9 * This code is free software; you can redistribute it and/or modify it 11.10 @@ -25,9 +25,9 @@ 11.11 11.12 /* 11.13 * @test 11.14 - * @bug 7153958 11.15 + * @bug 7153958 8073372 11.16 * @summary add constant pool reference to class containing inlined constants 11.17 - * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java 11.18 + * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java 11.19 * @run main CPoolRefClassContainingInlinedCts 11.20 */ 11.21 11.22 @@ -38,7 +38,8 @@ 11.23 import java.io.File; 11.24 import java.io.IOException; 11.25 11.26 -import static pkg.ClassToBeStaticallyImported.staticField; 11.27 +import static pkg.ClassToBeStaticallyImportedA.staticFieldA; 11.28 +import static pkg.ClassToBeStaticallyImportedB.staticFieldB; 11.29 11.30 public class CPoolRefClassContainingInlinedCts { 11.31 11.32 @@ -54,10 +55,14 @@ 11.33 11.34 void checkClassName(String className) { 11.35 switch (className) { 11.36 - case "SimpleAssignClass" : case "BinaryExpClass": 11.37 - case "UnaryExpClass" : case "CastClass": 11.38 - case "ParensClass" : case "CondClass": 11.39 - case "IfClass" : case "pkg/ClassToBeStaticallyImported": 11.40 + case "SimpleAssignClassA" : case "BinaryExpClassA": 11.41 + case "UnaryExpClassA" : case "CastClassA": 11.42 + case "ParensClassA" : case "CondClassA": 11.43 + case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA": 11.44 + case "SimpleAssignClassB" : case "BinaryExpClassB": 11.45 + case "UnaryExpClassB" : case "CastClassB": 11.46 + case "ParensClassB" : case "CondClassB": 11.47 + case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB": 11.48 numberOfReferencedClassesToBeChecked++; 11.49 } 11.50 } 11.51 @@ -76,59 +81,111 @@ 11.52 } 11.53 i += cpInfo.size(); 11.54 } 11.55 - if (numberOfReferencedClassesToBeChecked != 8) { 11.56 + if (numberOfReferencedClassesToBeChecked != 16) { 11.57 throw new AssertionError("Class reference missing in the constant pool"); 11.58 } 11.59 } 11.60 11.61 - private int assign = SimpleAssignClass.x; 11.62 - private int binary = BinaryExpClass.x + 1; 11.63 - private int unary = -UnaryExpClass.x; 11.64 - private int cast = (int)CastClass.x; 11.65 - private int parens = (ParensClass.x); 11.66 - private int cond = (CondClass.x == 1) ? 1 : 2; 11.67 - private static int ifConstant; 11.68 - private static int importStatic; 11.69 + private int assignA = SimpleAssignClassA.x; 11.70 + private int binaryA = BinaryExpClassA.x + 1; 11.71 + private int unaryA = -UnaryExpClassA.x; 11.72 + private int castA = (int)CastClassA.x; 11.73 + private int parensA = (ParensClassA.x); 11.74 + private int condA = (CondClassA.x == 1) ? 1 : 2; 11.75 + private static int ifConstantA; 11.76 + private static int importStaticA; 11.77 static { 11.78 - if (IfClass.x == 1) { 11.79 - ifConstant = 1; 11.80 + if (IfClassA.x == 1) { 11.81 + ifConstantA = 1; 11.82 } else { 11.83 - ifConstant = 2; 11.84 + ifConstantA = 2; 11.85 } 11.86 } 11.87 static { 11.88 - if (staticField == 1) { 11.89 - importStatic = 1; 11.90 + if (staticFieldA == 1) { 11.91 + importStaticA = 1; 11.92 } else { 11.93 - importStatic = 2; 11.94 + importStaticA = 2; 11.95 + } 11.96 + } 11.97 + 11.98 + // now as final constants 11.99 + private static final int assignB = SimpleAssignClassB.x; 11.100 + private static final int binaryB = BinaryExpClassB.x + 1; 11.101 + private static final int unaryB = -UnaryExpClassB.x; 11.102 + private static final int castB = (int)CastClassB.x; 11.103 + private static final int parensB = (ParensClassB.x); 11.104 + private static final int condB = (CondClassB.x == 1) ? 1 : 2; 11.105 + private static final int ifConstantB; 11.106 + private static final int importStaticB; 11.107 + static { 11.108 + if (IfClassB.x == 1) { 11.109 + ifConstantB = 1; 11.110 + } else { 11.111 + ifConstantB = 2; 11.112 + } 11.113 + } 11.114 + static { 11.115 + if (staticFieldB == 1) { 11.116 + importStaticB = 1; 11.117 + } else { 11.118 + importStaticB = 2; 11.119 } 11.120 } 11.121 } 11.122 11.123 -class SimpleAssignClass { 11.124 +class SimpleAssignClassA { 11.125 public static final int x = 1; 11.126 } 11.127 11.128 -class BinaryExpClass { 11.129 +class SimpleAssignClassB { 11.130 public static final int x = 1; 11.131 } 11.132 11.133 -class UnaryExpClass { 11.134 +class BinaryExpClassA { 11.135 public static final int x = 1; 11.136 } 11.137 11.138 -class CastClass { 11.139 +class BinaryExpClassB { 11.140 public static final int x = 1; 11.141 } 11.142 11.143 -class ParensClass { 11.144 +class UnaryExpClassA { 11.145 public static final int x = 1; 11.146 } 11.147 11.148 -class CondClass { 11.149 +class UnaryExpClassB { 11.150 public static final int x = 1; 11.151 } 11.152 11.153 -class IfClass { 11.154 +class CastClassA { 11.155 public static final int x = 1; 11.156 } 11.157 + 11.158 +class CastClassB { 11.159 + public static final int x = 1; 11.160 +} 11.161 + 11.162 +class ParensClassA { 11.163 + public static final int x = 1; 11.164 +} 11.165 + 11.166 +class ParensClassB { 11.167 + public static final int x = 1; 11.168 +} 11.169 + 11.170 +class CondClassA { 11.171 + public static final int x = 1; 11.172 +} 11.173 + 11.174 +class CondClassB { 11.175 + public static final int x = 1; 11.176 +} 11.177 + 11.178 +class IfClassA { 11.179 + public static final int x = 1; 11.180 +} 11.181 + 11.182 +class IfClassB { 11.183 + public static final int x = 1; 11.184 +}
12.1 --- a/test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java Mon Jun 15 11:41:41 2015 -0700 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,29 +0,0 @@ 12.4 -/* 12.5 - * Copyright (c) 2012, 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 ClassToBeStaticallyImported { 12.31 - public static final int staticField = 1; 12.32 -}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java Wed Jun 17 23:29:40 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 ClassToBeStaticallyImportedA { 13.31 + public static final int staticFieldA = 1; 13.32 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java Wed Jun 17 23:29:40 2015 -0700 14.3 @@ -0,0 +1,29 @@ 14.4 +/* 14.5 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. Oracle designates this 14.11 + * particular file as subject to the "Classpath" exception as provided 14.12 + * by Oracle in the LICENSE file that accompanied this code. 14.13 + * 14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.17 + * version 2 for more details (a copy is included in the LICENSE file that 14.18 + * accompanied this code). 14.19 + * 14.20 + * You should have received a copy of the GNU General Public License version 14.21 + * 2 along with this work; if not, write to the Free Software Foundation, 14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.23 + * 14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.25 + * or visit www.oracle.com if you need additional information or have any 14.26 + * questions. 14.27 + */ 14.28 +package pkg; 14.29 + 14.30 +public class ClassToBeStaticallyImportedB { 14.31 + public static final int staticFieldB = 1; 14.32 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/annotations/neg/AnonSubclass.java Wed Jun 17 23:29:40 2015 -0700 15.3 @@ -0,0 +1,13 @@ 15.4 +/* 15.5 + * @test /nodynamiccopyright/ 15.6 + * @bug 8028389 15.7 + * @summary javac should output a proper error message when given something 15.8 + * like new Object(){} as annotation argument. 15.9 + * 15.10 + * @compile/fail/ref=AnonSubclass.out -XDrawDiagnostics AnonSubclass.java 15.11 + */ 15.12 + 15.13 +@AnonSubclass(new Object(){}) 15.14 +@interface AnonSubclass { 15.15 + String value(); 15.16 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/annotations/neg/AnonSubclass.out Wed Jun 17 23:29:40 2015 -0700 16.3 @@ -0,0 +1,2 @@ 16.4 +AnonSubclass.java:10:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) 16.5 +1 error
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java Wed Jun 17 23:29:40 2015 -0700 17.3 @@ -0,0 +1,28 @@ 17.4 +/* 17.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +package pkg; 17.28 + 17.29 +@interface AnonSubclassOnPkg { 17.30 + String value(); 17.31 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/annotations/neg/pkg/package-info.java Wed Jun 17 23:29:40 2015 -0700 18.3 @@ -0,0 +1,12 @@ 18.4 +/* 18.5 + * @test /nodynamiccopyright/ 18.6 + * @bug 8028389 18.7 + * @summary javac should output a proper error message when given something 18.8 + * like new Object(){} as annotation argument. 18.9 + * 18.10 + * @compile AnonSubclassOnPkg.java 18.11 + * @compile/fail/ref=package-info.out -XDrawDiagnostics package-info.java 18.12 + */ 18.13 + 18.14 +@AnonSubclassOnPkg(new Object(){}) 18.15 +package pkg;
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/annotations/neg/pkg/package-info.out Wed Jun 17 23:29:40 2015 -0700 19.3 @@ -0,0 +1,2 @@ 19.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) 19.5 +1 error
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java Wed Jun 17 23:29:40 2015 -0700 20.3 @@ -0,0 +1,178 @@ 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 8079613 20.30 + * @summary Ensure that compiler ascertains a class of patently non-poly expressions as such 20.31 + * @run main/timeout=10 DeeplyChainedNonPolyExpressionTest 20.32 + */ 20.33 + 20.34 +public class DeeplyChainedNonPolyExpressionTest { 20.35 + static class JSO { 20.36 + 20.37 + JSO put(String s, Object y) { 20.38 + return null; 20.39 + } 20.40 + 20.41 + JSO put(java.lang.String x, java.util.Collection<String> y) { 20.42 + return null; 20.43 + } 20.44 + 20.45 + JSO put(java.lang.String x, int y) { 20.46 + return null; 20.47 + } 20.48 + 20.49 + JSO put(java.lang.String x, long y) { 20.50 + return null; 20.51 + } 20.52 + 20.53 + JSO put(java.lang.String x, double y) { 20.54 + return null; 20.55 + } 20.56 + 20.57 + JSO put(java.lang.String x, java.util.Map<String, String> y) { 20.58 + return null; 20.59 + } 20.60 + 20.61 + JSO put(java.lang.String x, boolean y) { 20.62 + return null; 20.63 + } 20.64 + } 20.65 + 20.66 + static class JSA { 20.67 + 20.68 + JSA put(Object o) { 20.69 + return null; 20.70 + } 20.71 + 20.72 + JSA put(int i, Object x) { 20.73 + return null; 20.74 + } 20.75 + 20.76 + JSA put(boolean x) { 20.77 + return null; 20.78 + } 20.79 + 20.80 + JSA put(int x) { 20.81 + return null; 20.82 + } 20.83 + 20.84 + JSA put(int i, int x) { 20.85 + return null; 20.86 + } 20.87 + 20.88 + JSA put(int x, boolean y) { 20.89 + return null; 20.90 + } 20.91 + 20.92 + JSA put(int i, long x) { 20.93 + return null; 20.94 + } 20.95 + 20.96 + JSA put(long x) { 20.97 + return null; 20.98 + } 20.99 + 20.100 + JSA put(java.util.Collection<String> x) { 20.101 + return null; 20.102 + } 20.103 + 20.104 + JSA put(int i, java.util.Collection<String> x) { 20.105 + return null; 20.106 + } 20.107 + 20.108 + JSA put(int i, java.util.Map<String, String> x) { 20.109 + return null; 20.110 + } 20.111 + 20.112 + JSA put(java.util.Map<String, String> x) { 20.113 + return null; 20.114 + } 20.115 + 20.116 + JSA put(int i, double x) { 20.117 + return null; 20.118 + } 20.119 + 20.120 + JSA put(double x) { 20.121 + return null; 20.122 + } 20.123 + } 20.124 + 20.125 + public static void main(String [] args) { 20.126 + } 20.127 + public static void foo() { 20.128 + new JSO() 20.129 + .put("s", new JSA()) 20.130 + .put("s", new JSA()) 20.131 + .put("s", new JSO() 20.132 + .put("s", new JSO() 20.133 + .put("s", new JSA().put("s")) 20.134 + .put("s", new JSA()) 20.135 + .put("s", new JSO() 20.136 + .put("s", new JSO() 20.137 + .put("s", new JSA().put("s").put("s")) 20.138 + .put("s", new JSA()) 20.139 + .put("s", new JSO() 20.140 + .put("s", new JSO() 20.141 + .put("s", new JSA().put("s").put("s").put("s") 20.142 + .put("s").put("s").put("s") 20.143 + .put("s").put("s")) 20.144 + .put("s", new JSA()) 20.145 + .put("s", new JSO() 20.146 + .put("s", new JSO() 20.147 + .put("s", new JSA().put("s")) 20.148 + .put("s", new JSA()) 20.149 + ) 20.150 + ) 20.151 + ) 20.152 + ) 20.153 + ) 20.154 + .put("s", new JSO() 20.155 + .put("s", new JSA().put("s")) 20.156 + .put("s", new JSA()) 20.157 + .put("s", new JSO() 20.158 + .put("s", new JSO() 20.159 + .put("s", new JSA().put("s").put("s")) 20.160 + .put("s", new JSA()) 20.161 + .put("s", new JSO() 20.162 + .put("s", new JSO() 20.163 + .put("s", new JSA().put("s").put("s").put("s") 20.164 + .put("s").put("s").put("s") 20.165 + .put("s").put("s")) 20.166 + .put("s", new JSA()) 20.167 + .put("s", new JSO() 20.168 + .put("s", new JSO() 20.169 + .put("s", new JSA().put("s")) 20.170 + .put("s", new JSA())) 20.171 + ) 20.172 + ) 20.173 + ) 20.174 + ) 20.175 + ) 20.176 + ) 20.177 + ) 20.178 + ) 20.179 + ); 20.180 + } 20.181 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/scope/RemoveSymbolTest.java Wed Jun 17 23:29:40 2015 -0700 21.3 @@ -0,0 +1,77 @@ 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 + * @run main RemoveSymbolTest 21.32 + */ 21.33 + 21.34 +import java.util.Iterator; 21.35 +import java.util.LinkedList; 21.36 + 21.37 +public class RemoveSymbolTest<W> implements Iterable<W> { 21.38 + static class Widget { 21.39 + private String name; 21.40 + Widget(String s) { name = s; } 21.41 + @Override public String toString() { return name; } 21.42 + } 21.43 + 21.44 + private LinkedList<W> data; 21.45 + // Instantiate an Iterable instance using a Lambda expression. 21.46 + // Causes ClassFormatError if a local variable of type Widget is named after one of the methods. 21.47 + private final Iterable<W> myIterator1 = () -> new Iterator<W>() { 21.48 + private W hasNext = null; 21.49 + private int index = 0; 21.50 + @Override public boolean hasNext() { return index < data.size(); } 21.51 + @Override public W next() { return data.get(index++); } 21.52 + }; 21.53 + 21.54 + // Instantiate an Iterable instance using an anonymous class. 21.55 + // Always works fine regardless of the name of the local variable. 21.56 + private final Iterable<W> myIterator2 = 21.57 + new Iterable<W>() { 21.58 + @Override 21.59 + public Iterator<W> iterator() { 21.60 + return new Iterator<W>() { 21.61 + private W hasNext = null; 21.62 + private int index = 0; 21.63 + @Override public boolean hasNext() { return index < data.size(); } 21.64 + @Override public W next() { return data.get(index++); } 21.65 + }; 21.66 + } 21.67 + }; 21.68 + public RemoveSymbolTest() { data = new LinkedList<>(); } 21.69 + public void add(W e) { data.add(e); } 21.70 + @Override public String toString() { return data.toString(); } 21.71 + @Override public Iterator<W> iterator() { return myIterator1.iterator(); } 21.72 + public static void main(String[] args) { 21.73 + RemoveSymbolTest<Widget> widgets = new RemoveSymbolTest<>(); 21.74 + widgets.add(new Widget("W1")); 21.75 + widgets.add(new Widget("W2")); 21.76 + widgets.add(new Widget("W3")); 21.77 + System.out.println(".foreach() call: "); 21.78 + widgets.forEach(w -> System.out.println(w + " ")); 21.79 + } 21.80 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/scope/RemoveSymbolUnitTest.java Wed Jun 17 23:29:40 2015 -0700 22.3 @@ -0,0 +1,95 @@ 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 8080842 22.30 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. 22.31 + */ 22.32 + 22.33 +import com.sun.tools.javac.util.*; 22.34 +import com.sun.tools.javac.code.*; 22.35 +import com.sun.tools.javac.code.Scope.*; 22.36 +import com.sun.tools.javac.code.Symbol.*; 22.37 +import com.sun.tools.javac.file.JavacFileManager; 22.38 + 22.39 +public class RemoveSymbolUnitTest { 22.40 + 22.41 + Context context; 22.42 + Names names; 22.43 + Symtab symtab; 22.44 + 22.45 + public static void main(String... args) throws Exception { 22.46 + new RemoveSymbolUnitTest().run(); 22.47 + } 22.48 + 22.49 + public void run() { 22.50 + context = new Context(); 22.51 + JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab 22.52 + names = Names.instance(context); 22.53 + symtab = Symtab.instance(context); 22.54 + 22.55 + Name hasNext = names.fromString("hasNext"); 22.56 + ClassSymbol clazz = new ClassSymbol(0, 22.57 + names.fromString("X"), 22.58 + Type.noType, 22.59 + symtab.unnamedPackage); 22.60 + 22.61 + VarSymbol v = new VarSymbol(0, hasNext, Type.noType, clazz); 22.62 + MethodSymbol m = new MethodSymbol(0, hasNext, Type.noType, clazz); 22.63 + 22.64 + // Try enter and remove in different shuffled combinations. 22.65 + // working with fresh scope each time. 22.66 + Scope cs = new Scope(clazz); 22.67 + cs.enter(v); 22.68 + cs.enter(m); 22.69 + cs.remove(v); 22.70 + Symbol s = cs.lookup(hasNext).sym; 22.71 + if (s != m) 22.72 + throw new AssertionError("Wrong symbol"); 22.73 + 22.74 + cs = new Scope(clazz); 22.75 + cs.enter(m); 22.76 + cs.enter(v); 22.77 + cs.remove(v); 22.78 + s = cs.lookup(hasNext).sym; 22.79 + if (s != m) 22.80 + throw new AssertionError("Wrong symbol"); 22.81 + 22.82 + cs = new Scope(clazz); 22.83 + cs.enter(v); 22.84 + cs.enter(m); 22.85 + cs.remove(m); 22.86 + s = cs.lookup(hasNext).sym; 22.87 + if (s != v) 22.88 + throw new AssertionError("Wrong symbol"); 22.89 + 22.90 + cs = new Scope(clazz); 22.91 + cs.enter(m); 22.92 + cs.enter(v); 22.93 + cs.remove(m); 22.94 + s = cs.lookup(hasNext).sym; 22.95 + if (s != v) 22.96 + throw new AssertionError("Wrong symbol"); 22.97 + } 22.98 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/types/ScopeListenerTest.java Wed Jun 17 23:29:40 2015 -0700 23.3 @@ -0,0 +1,82 @@ 23.4 +/* 23.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. 23.11 + * 23.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.15 + * version 2 for more details (a copy is included in the LICENSE file that 23.16 + * accompanied this code). 23.17 + * 23.18 + * You should have received a copy of the GNU General Public License version 23.19 + * 2 along with this work; if not, write to the Free Software Foundation, 23.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.21 + * 23.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.23 + * or visit www.oracle.com if you need additional information or have any 23.24 + * questions. 23.25 + */ 23.26 + 23.27 +/* 23.28 + * @test 23.29 + * @bug 8039262 23.30 + * @summary Ensure that using Types.membersClosure does not increase the number of listeners on the 23.31 + * class's members Scope. 23.32 + */ 23.33 + 23.34 +import com.sun.tools.javac.code.Scope; 23.35 +import com.sun.tools.javac.code.Symbol; 23.36 +import com.sun.tools.javac.code.Symtab; 23.37 +import com.sun.tools.javac.code.Types; 23.38 +import com.sun.tools.javac.file.JavacFileManager; 23.39 +import com.sun.tools.javac.util.Context; 23.40 +import com.sun.tools.javac.util.Names; 23.41 +import java.lang.reflect.Field; 23.42 +import java.util.Collection; 23.43 + 23.44 +public class ScopeListenerTest { 23.45 + 23.46 + public static void main(String[] args) throws Exception { 23.47 + new ScopeListenerTest().run(); 23.48 + } 23.49 + 23.50 + void run() throws Exception { 23.51 + Context context = new Context(); 23.52 + JavacFileManager.preRegister(context); 23.53 + Types types = Types.instance(context); 23.54 + Symtab syms = Symtab.instance(context); 23.55 + Names names = Names.instance(context); 23.56 + types.membersClosure(syms.stringType, true); 23.57 + types.membersClosure(syms.stringType, false); 23.58 + 23.59 + Field listenersField = Scope.class.getDeclaredField("listeners"); 23.60 + 23.61 + listenersField.setAccessible(true); 23.62 + 23.63 + int listenerCount = 23.64 + ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); 23.65 + 23.66 + for (int i = 0; i < 100; i++) { 23.67 + types.membersClosure(syms.stringType, true); 23.68 + types.membersClosure(syms.stringType, false); 23.69 + } 23.70 + 23.71 + int newListenerCount 23.72 + = ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); 23.73 + 23.74 + if (listenerCount != newListenerCount) { 23.75 + throw new AssertionError("Orig listener count: " + listenerCount + 23.76 + "; new listener count: " + newListenerCount); 23.77 + } 23.78 + 23.79 + for (Symbol s : types.membersClosure(syms.stringType, true).getElements()) 23.80 + ; 23.81 + for (Symbol s : types.membersClosure(syms.stringType, false).getElementsByName(names.fromString("substring"))) 23.82 + ; 23.83 + } 23.84 + 23.85 +}