Mon, 10 Dec 2012 20:59:38 -0800
Merge
test/tools/javac/defaultMethodExecution/DefaultMethodRegressionTests.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/diags/examples/InvalidGenericDescInFunctionalInterface.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/lambda/LambdaConversionTest.java | file | annotate | diff | comparison | revisions |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/source/tree/IntersectionTypeTree.java Mon Dec 10 20:59:38 2012 -0800 1.3 @@ -0,0 +1,39 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.source.tree; 1.30 + 1.31 +import java.util.List; 1.32 + 1.33 +/** 1.34 + * A tree node for an intersection type in a cast expression. 1.35 + * 1.36 + * @author Maurizio Cimadamore 1.37 + * 1.38 + * @since 1.8 1.39 + */ 1.40 +public interface IntersectionTypeTree extends Tree { 1.41 + List<? extends Tree> getBounds(); 1.42 +}
2.1 --- a/src/share/classes/com/sun/source/tree/Tree.java Thu Dec 06 12:04:44 2012 -0800 2.2 +++ b/src/share/classes/com/sun/source/tree/Tree.java Mon Dec 10 20:59:38 2012 -0800 2.3 @@ -247,6 +247,11 @@ 2.4 UNION_TYPE(UnionTypeTree.class), 2.5 2.6 /** 2.7 + * Used for instances of {@link IntersectionTypeTree}. 2.8 + */ 2.9 + INTERSECTION_TYPE(IntersectionTypeTree.class), 2.10 + 2.11 + /** 2.12 * Used for instances of {@link TypeCastTree}. 2.13 */ 2.14 TYPE_CAST(TypeCastTree.class),
3.1 --- a/src/share/classes/com/sun/source/tree/TreeVisitor.java Thu Dec 06 12:04:44 2012 -0800 3.2 +++ b/src/share/classes/com/sun/source/tree/TreeVisitor.java Mon Dec 10 20:59:38 2012 -0800 3.3 @@ -98,6 +98,7 @@ 3.4 R visitTry(TryTree node, P p); 3.5 R visitParameterizedType(ParameterizedTypeTree node, P p); 3.6 R visitUnionType(UnionTypeTree node, P p); 3.7 + R visitIntersectionType(IntersectionTypeTree node, P p); 3.8 R visitArrayType(ArrayTypeTree node, P p); 3.9 R visitTypeCast(TypeCastTree node, P p); 3.10 R visitPrimitiveType(PrimitiveTypeTree node, P p);
4.1 --- a/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java Thu Dec 06 12:04:44 2012 -0800 4.2 +++ b/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java Mon Dec 10 20:59:38 2012 -0800 4.3 @@ -240,6 +240,10 @@ 4.4 return defaultAction(node, p); 4.5 } 4.6 4.7 + public R visitIntersectionType(IntersectionTypeTree node, P p) { 4.8 + return defaultAction(node, p); 4.9 + } 4.10 + 4.11 public R visitTypeParameter(TypeParameterTree node, P p) { 4.12 return defaultAction(node, p); 4.13 }
5.1 --- a/src/share/classes/com/sun/source/util/TreeScanner.java Thu Dec 06 12:04:44 2012 -0800 5.2 +++ b/src/share/classes/com/sun/source/util/TreeScanner.java Mon Dec 10 20:59:38 2012 -0800 5.3 @@ -371,6 +371,10 @@ 5.4 return scan(node.getTypeAlternatives(), p); 5.5 } 5.6 5.7 + public R visitIntersectionType(IntersectionTypeTree node, P p) { 5.8 + return scan(node.getBounds(), p); 5.9 + } 5.10 + 5.11 public R visitTypeParameter(TypeParameterTree node, P p) { 5.12 R r = scan(node.getBounds(), p); 5.13 return r;
6.1 --- a/src/share/classes/com/sun/tools/classfile/Instruction.java Thu Dec 06 12:04:44 2012 -0800 6.2 +++ b/src/share/classes/com/sun/tools/classfile/Instruction.java Mon Dec 10 20:59:38 2012 -0800 6.3 @@ -71,11 +71,16 @@ 6.4 SHORT(3), 6.5 /** Wide opcode is not followed by any operands. */ 6.6 WIDE_NO_OPERANDS(2), 6.7 + /** Wide opcode is followed by a 2-byte index into the local variables array. */ 6.8 + WIDE_LOCAL(4), 6.9 /** Wide opcode is followed by a 2-byte index into the constant pool. */ 6.10 WIDE_CPREF_W(4), 6.11 /** Wide opcode is followed by a 2-byte index into the constant pool, 6.12 * and a signed short value. */ 6.13 WIDE_CPREF_W_SHORT(6), 6.14 + /** Wide opcode is followed by a 2-byte reference to a local variable, 6.15 + * and a signed short value. */ 6.16 + WIDE_LOCAL_SHORT(6), 6.17 /** Opcode was not recognized. */ 6.18 UNKNOWN(1); 6.19 6.20 @@ -101,7 +106,7 @@ 6.21 R visitConstantPoolRef(Instruction instr, int index, P p); 6.22 /** See {@link Kind#CPREF_W_UBYTE}, {@link Kind#CPREF_W_UBYTE_ZERO}, {@link Kind#WIDE_CPREF_W_SHORT}. */ 6.23 R visitConstantPoolRefAndValue(Instruction instr, int index, int value, P p); 6.24 - /** See {@link Kind#LOCAL}. */ 6.25 + /** See {@link Kind#LOCAL}, {@link Kind#WIDE_LOCAL}. */ 6.26 R visitLocal(Instruction instr, int index, P p); 6.27 /** See {@link Kind#LOCAL_BYTE}. */ 6.28 R visitLocalAndValue(Instruction instr, int index, int value, P p); 6.29 @@ -315,6 +320,9 @@ 6.30 case WIDE_NO_OPERANDS: 6.31 return visitor.visitNoOperands(this, p); 6.32 6.33 + case WIDE_LOCAL: 6.34 + return visitor.visitLocal(this, getUnsignedShort(2), p); 6.35 + 6.36 case WIDE_CPREF_W: 6.37 return visitor.visitConstantPoolRef(this, getUnsignedShort(2), p); 6.38 6.39 @@ -322,6 +330,10 @@ 6.40 return visitor.visitConstantPoolRefAndValue( 6.41 this, getUnsignedShort(2), getUnsignedByte(4), p); 6.42 6.43 + case WIDE_LOCAL_SHORT: 6.44 + return visitor.visitLocalAndValue( 6.45 + this, getUnsignedShort(2), getShort(4), p); 6.46 + 6.47 case UNKNOWN: 6.48 return visitor.visitUnknown(this, p); 6.49
7.1 --- a/src/share/classes/com/sun/tools/classfile/Opcode.java Thu Dec 06 12:04:44 2012 -0800 7.2 +++ b/src/share/classes/com/sun/tools/classfile/Opcode.java Mon Dec 10 20:59:38 2012 -0800 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 2009, 2012, 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 @@ -246,18 +246,18 @@ 7.11 // impdep 0xff: Picojava priv 7.12 7.13 // wide opcodes 7.14 - ILOAD_W(0xc415, WIDE_CPREF_W), 7.15 - LLOAD_W(0xc416, WIDE_CPREF_W), 7.16 - FLOAD_W(0xc417, WIDE_CPREF_W), 7.17 - DLOAD_W(0xc418, WIDE_CPREF_W), 7.18 - ALOAD_W(0xc419, WIDE_CPREF_W), 7.19 - ISTORE_W(0xc436, WIDE_CPREF_W), 7.20 - LSTORE_W(0xc437, WIDE_CPREF_W), 7.21 - FSTORE_W(0xc438, WIDE_CPREF_W), 7.22 - DSTORE_W(0xc439, WIDE_CPREF_W), 7.23 - ASTORE_W(0xc43a, WIDE_CPREF_W), 7.24 - IINC_W(0xc484, WIDE_CPREF_W_SHORT), 7.25 - RET_W(0xc4a9, WIDE_CPREF_W), 7.26 + ILOAD_W(0xc415, WIDE_LOCAL), 7.27 + LLOAD_W(0xc416, WIDE_LOCAL), 7.28 + FLOAD_W(0xc417, WIDE_LOCAL), 7.29 + DLOAD_W(0xc418, WIDE_LOCAL), 7.30 + ALOAD_W(0xc419, WIDE_LOCAL), 7.31 + ISTORE_W(0xc436, WIDE_LOCAL), 7.32 + LSTORE_W(0xc437, WIDE_LOCAL), 7.33 + FSTORE_W(0xc438, WIDE_LOCAL), 7.34 + DSTORE_W(0xc439, WIDE_LOCAL), 7.35 + ASTORE_W(0xc43a, WIDE_LOCAL), 7.36 + IINC_W(0xc484, WIDE_LOCAL_SHORT), 7.37 + RET_W(0xc4a9, WIDE_LOCAL), 7.38 7.39 // PicoJava nonpriv instructions 7.40 LOAD_UBYTE(PICOJAVA, 0xfe00),
8.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Thu Dec 06 12:04:44 2012 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Mon Dec 10 20:59:38 2012 -0800 8.3 @@ -215,6 +215,9 @@ 8.4 public boolean allowRepeatedAnnotations() { 8.5 return compareTo(JDK1_8) >= 0; 8.6 } 8.7 + public boolean allowIntersectionTypesInCast() { 8.8 + return compareTo(JDK1_8) >= 0; 8.9 + } 8.10 public static SourceVersion toSourceVersion(Source source) { 8.11 switch(source) { 8.12 case JDK1_2:
9.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Thu Dec 06 12:04:44 2012 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Mon Dec 10 20:59:38 2012 -0800 9.3 @@ -839,6 +839,49 @@ 9.4 } 9.5 } 9.6 9.7 + // a clone of a ClassType that knows about the bounds of an intersection type. 9.8 + public static class IntersectionClassType extends ClassType implements IntersectionType { 9.9 + 9.10 + public boolean allInterfaces; 9.11 + 9.12 + public enum IntersectionKind { 9.13 + EXPLICIT, 9.14 + IMPLICT; 9.15 + } 9.16 + 9.17 + public IntersectionKind intersectionKind; 9.18 + 9.19 + public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) { 9.20 + super(Type.noType, List.<Type>nil(), csym); 9.21 + this.allInterfaces = allInterfaces; 9.22 + Assert.check((csym.flags() & COMPOUND) != 0); 9.23 + supertype_field = bounds.head; 9.24 + interfaces_field = bounds.tail; 9.25 + Assert.check(supertype_field.tsym.completer != null || 9.26 + !supertype_field.isInterface(), supertype_field); 9.27 + } 9.28 + 9.29 + public java.util.List<? extends TypeMirror> getBounds() { 9.30 + return Collections.unmodifiableList(getComponents()); 9.31 + } 9.32 + 9.33 + public List<Type> getComponents() { 9.34 + return interfaces_field.prepend(supertype_field); 9.35 + } 9.36 + 9.37 + @Override 9.38 + public TypeKind getKind() { 9.39 + return TypeKind.INTERSECTION; 9.40 + } 9.41 + 9.42 + @Override 9.43 + public <R, P> R accept(TypeVisitor<R, P> v, P p) { 9.44 + return intersectionKind == IntersectionKind.EXPLICIT ? 9.45 + v.visitIntersection(this, p) : 9.46 + v.visitDeclared(this, p); 9.47 + } 9.48 + } 9.49 + 9.50 public static class ArrayType extends Type 9.51 implements javax.lang.model.type.ArrayType { 9.52
10.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Dec 06 12:04:44 2012 -0800 10.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Dec 10 20:59:38 2012 -0800 10.3 @@ -26,7 +26,13 @@ 10.4 package com.sun.tools.javac.code; 10.5 10.6 import java.lang.ref.SoftReference; 10.7 -import java.util.*; 10.8 +import java.util.Comparator; 10.9 +import java.util.HashSet; 10.10 +import java.util.HashMap; 10.11 +import java.util.Locale; 10.12 +import java.util.Map; 10.13 +import java.util.Set; 10.14 +import java.util.WeakHashMap; 10.15 10.16 import com.sun.tools.javac.code.Attribute.RetentionPolicy; 10.17 import com.sun.tools.javac.code.Lint.LintCategory; 10.18 @@ -383,28 +389,6 @@ 10.19 } 10.20 10.21 /** 10.22 - * Scope filter used to skip methods that should be ignored during 10.23 - * function interface conversion (such as methods overridden by 10.24 - * j.l.Object) 10.25 - */ 10.26 - class DescriptorFilter implements Filter<Symbol> { 10.27 - 10.28 - TypeSymbol origin; 10.29 - 10.30 - DescriptorFilter(TypeSymbol origin) { 10.31 - this.origin = origin; 10.32 - } 10.33 - 10.34 - @Override 10.35 - public boolean accepts(Symbol sym) { 10.36 - return sym.kind == Kinds.MTH && 10.37 - (sym.flags() & (ABSTRACT | DEFAULT)) == ABSTRACT && 10.38 - !overridesObjectMethod(origin, sym) && 10.39 - (interfaceCandidates(origin.type, (MethodSymbol)sym).head.flags() & DEFAULT) == 0; 10.40 - } 10.41 - }; 10.42 - 10.43 - /** 10.44 * Compute the function descriptor associated with a given functional interface 10.45 */ 10.46 public FunctionDescriptor findDescriptorInternal(TypeSymbol origin, CompoundScope membersCache) throws FunctionDescriptorLookupError { 10.47 @@ -431,23 +415,8 @@ 10.48 throw failure("not.a.functional.intf.1", 10.49 diags.fragment("no.abstracts", Kinds.kindName(origin), origin)); 10.50 } else if (abstracts.size() == 1) { 10.51 - if (abstracts.first().type.tag == FORALL) { 10.52 - throw failure("invalid.generic.desc.in.functional.intf", 10.53 - abstracts.first(), 10.54 - Kinds.kindName(origin), 10.55 - origin); 10.56 - } else { 10.57 - return new FunctionDescriptor(abstracts.first()); 10.58 - } 10.59 + return new FunctionDescriptor(abstracts.first()); 10.60 } else { // size > 1 10.61 - for (Symbol msym : abstracts) { 10.62 - if (msym.type.tag == FORALL) { 10.63 - throw failure("invalid.generic.desc.in.functional.intf", 10.64 - abstracts.first(), 10.65 - Kinds.kindName(origin), 10.66 - origin); 10.67 - } 10.68 - } 10.69 FunctionDescriptor descRes = mergeDescriptors(origin, abstracts.toList()); 10.70 if (descRes == null) { 10.71 //we can get here if the functional interface is ill-formed 10.72 @@ -586,6 +555,85 @@ 10.73 } 10.74 // </editor-fold> 10.75 10.76 + /** 10.77 + * Scope filter used to skip methods that should be ignored (such as methods 10.78 + * overridden by j.l.Object) during function interface conversion/marker interface checks 10.79 + */ 10.80 + class DescriptorFilter implements Filter<Symbol> { 10.81 + 10.82 + TypeSymbol origin; 10.83 + 10.84 + DescriptorFilter(TypeSymbol origin) { 10.85 + this.origin = origin; 10.86 + } 10.87 + 10.88 + @Override 10.89 + public boolean accepts(Symbol sym) { 10.90 + return sym.kind == Kinds.MTH && 10.91 + (sym.flags() & (ABSTRACT | DEFAULT)) == ABSTRACT && 10.92 + !overridesObjectMethod(origin, sym) && 10.93 + (interfaceCandidates(origin.type, (MethodSymbol)sym).head.flags() & DEFAULT) == 0; 10.94 + } 10.95 + }; 10.96 + 10.97 + // <editor-fold defaultstate="collapsed" desc="isMarker"> 10.98 + 10.99 + /** 10.100 + * A cache that keeps track of marker interfaces 10.101 + */ 10.102 + class MarkerCache { 10.103 + 10.104 + private WeakHashMap<TypeSymbol, Entry> _map = new WeakHashMap<TypeSymbol, Entry>(); 10.105 + 10.106 + class Entry { 10.107 + final boolean isMarkerIntf; 10.108 + final int prevMark; 10.109 + 10.110 + public Entry(boolean isMarkerIntf, 10.111 + int prevMark) { 10.112 + this.isMarkerIntf = isMarkerIntf; 10.113 + this.prevMark = prevMark; 10.114 + } 10.115 + 10.116 + boolean matches(int mark) { 10.117 + return this.prevMark == mark; 10.118 + } 10.119 + } 10.120 + 10.121 + boolean get(TypeSymbol origin) throws FunctionDescriptorLookupError { 10.122 + Entry e = _map.get(origin); 10.123 + CompoundScope members = membersClosure(origin.type, false); 10.124 + if (e == null || 10.125 + !e.matches(members.getMark())) { 10.126 + boolean isMarkerIntf = isMarkerInterfaceInternal(origin, members); 10.127 + _map.put(origin, new Entry(isMarkerIntf, members.getMark())); 10.128 + return isMarkerIntf; 10.129 + } 10.130 + else { 10.131 + return e.isMarkerIntf; 10.132 + } 10.133 + } 10.134 + 10.135 + /** 10.136 + * Is given symbol a marker interface 10.137 + */ 10.138 + public boolean isMarkerInterfaceInternal(TypeSymbol origin, CompoundScope membersCache) throws FunctionDescriptorLookupError { 10.139 + return !origin.isInterface() ? 10.140 + false : 10.141 + !membersCache.getElements(new DescriptorFilter(origin)).iterator().hasNext(); 10.142 + } 10.143 + } 10.144 + 10.145 + private MarkerCache markerCache = new MarkerCache(); 10.146 + 10.147 + /** 10.148 + * Is given type a marker interface? 10.149 + */ 10.150 + public boolean isMarkerInterface(Type site) { 10.151 + return markerCache.get(site.tsym); 10.152 + } 10.153 + // </editor-fold> 10.154 + 10.155 // <editor-fold defaultstate="collapsed" desc="isSubtype"> 10.156 /** 10.157 * Is t an unchecked subtype of s? 10.158 @@ -1964,45 +2012,28 @@ 10.159 * @param supertype is objectType if all bounds are interfaces, 10.160 * null otherwise. 10.161 */ 10.162 - public Type makeCompoundType(List<Type> bounds, 10.163 - Type supertype) { 10.164 + public Type makeCompoundType(List<Type> bounds) { 10.165 + return makeCompoundType(bounds, bounds.head.tsym.isInterface()); 10.166 + } 10.167 + public Type makeCompoundType(List<Type> bounds, boolean allInterfaces) { 10.168 + Assert.check(bounds.nonEmpty()); 10.169 + Type firstExplicitBound = bounds.head; 10.170 + if (allInterfaces) { 10.171 + bounds = bounds.prepend(syms.objectType); 10.172 + } 10.173 ClassSymbol bc = 10.174 new ClassSymbol(ABSTRACT|PUBLIC|SYNTHETIC|COMPOUND|ACYCLIC, 10.175 Type.moreInfo 10.176 ? names.fromString(bounds.toString()) 10.177 : names.empty, 10.178 + null, 10.179 syms.noSymbol); 10.180 - if (bounds.head.tag == TYPEVAR) 10.181 - // error condition, recover 10.182 - bc.erasure_field = syms.objectType; 10.183 - else 10.184 - bc.erasure_field = erasure(bounds.head); 10.185 - bc.members_field = new Scope(bc); 10.186 - ClassType bt = (ClassType)bc.type; 10.187 - bt.allparams_field = List.nil(); 10.188 - if (supertype != null) { 10.189 - bt.supertype_field = supertype; 10.190 - bt.interfaces_field = bounds; 10.191 - } else { 10.192 - bt.supertype_field = bounds.head; 10.193 - bt.interfaces_field = bounds.tail; 10.194 - } 10.195 - Assert.check(bt.supertype_field.tsym.completer != null 10.196 - || !bt.supertype_field.isInterface(), 10.197 - bt.supertype_field); 10.198 - return bt; 10.199 - } 10.200 - 10.201 - /** 10.202 - * Same as {@link #makeCompoundType(List,Type)}, except that the 10.203 - * second parameter is computed directly. Note that this might 10.204 - * cause a symbol completion. Hence, this version of 10.205 - * makeCompoundType may not be called during a classfile read. 10.206 - */ 10.207 - public Type makeCompoundType(List<Type> bounds) { 10.208 - Type supertype = (bounds.head.tsym.flags() & INTERFACE) != 0 ? 10.209 - supertype(bounds.head) : null; 10.210 - return makeCompoundType(bounds, supertype); 10.211 + bc.type = new IntersectionClassType(bounds, bc, allInterfaces); 10.212 + bc.erasure_field = (bounds.head.tag == TYPEVAR) ? 10.213 + syms.objectType : // error condition, recover 10.214 + erasure(firstExplicitBound); 10.215 + bc.members_field = new Scope(bc); 10.216 + return bc.type; 10.217 } 10.218 10.219 /** 10.220 @@ -2192,12 +2223,8 @@ 10.221 * @param supertype is objectType if all bounds are interfaces, 10.222 * null otherwise. 10.223 */ 10.224 - public void setBounds(TypeVar t, List<Type> bounds, Type supertype) { 10.225 - if (bounds.tail.isEmpty()) 10.226 - t.bound = bounds.head; 10.227 - else 10.228 - t.bound = makeCompoundType(bounds, supertype); 10.229 - t.rank_field = -1; 10.230 + public void setBounds(TypeVar t, List<Type> bounds) { 10.231 + setBounds(t, bounds, bounds.head.tsym.isInterface()); 10.232 } 10.233 10.234 /** 10.235 @@ -2209,10 +2236,10 @@ 10.236 * Note that this check might cause a symbol completion. Hence, this version of 10.237 * setBounds may not be called during a classfile read. 10.238 */ 10.239 - public void setBounds(TypeVar t, List<Type> bounds) { 10.240 - Type supertype = (bounds.head.tsym.flags() & INTERFACE) != 0 ? 10.241 - syms.objectType : null; 10.242 - setBounds(t, bounds, supertype); 10.243 + public void setBounds(TypeVar t, List<Type> bounds, boolean allInterfaces) { 10.244 + t.bound = bounds.tail.isEmpty() ? 10.245 + bounds.head : 10.246 + makeCompoundType(bounds, allInterfaces); 10.247 t.rank_field = -1; 10.248 } 10.249 // </editor-fold> 10.250 @@ -2222,7 +2249,7 @@ 10.251 * Return list of bounds of the given type variable. 10.252 */ 10.253 public List<Type> getBounds(TypeVar t) { 10.254 - if (t.bound.hasTag(NONE)) 10.255 + if (t.bound.hasTag(NONE)) 10.256 return List.nil(); 10.257 else if (t.bound.isErroneous() || !t.bound.isCompound()) 10.258 return List.of(t.bound); 10.259 @@ -3321,8 +3348,7 @@ 10.260 if (arraySuperType == null) { 10.261 // JLS 10.8: all arrays implement Cloneable and Serializable. 10.262 arraySuperType = makeCompoundType(List.of(syms.serializableType, 10.263 - syms.cloneableType), 10.264 - syms.objectType); 10.265 + syms.cloneableType), true); 10.266 } 10.267 } 10.268 }
11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Dec 06 12:04:44 2012 -0800 11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 10 20:59:38 2012 -0800 11.3 @@ -716,21 +716,8 @@ 11.4 } 11.5 a.tsym.flags_field &= ~UNATTRIBUTED; 11.6 } 11.7 - for (JCTypeParameter tvar : typarams) 11.8 + for (JCTypeParameter tvar : typarams) { 11.9 chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type); 11.10 - attribStats(typarams, env); 11.11 - } 11.12 - 11.13 - void attribBounds(List<JCTypeParameter> typarams) { 11.14 - for (JCTypeParameter typaram : typarams) { 11.15 - Type bound = typaram.type.getUpperBound(); 11.16 - if (bound != null && bound.tsym instanceof ClassSymbol) { 11.17 - ClassSymbol c = (ClassSymbol)bound.tsym; 11.18 - if ((c.flags_field & COMPOUND) != 0) { 11.19 - Assert.check((c.flags_field & UNATTRIBUTED) != 0, c); 11.20 - attribClass(typaram.pos(), c); 11.21 - } 11.22 - } 11.23 } 11.24 } 11.25 11.26 @@ -892,7 +879,12 @@ 11.27 deferredLintHandler.flush(tree.pos()); 11.28 chk.checkDeprecatedAnnotation(tree.pos(), m); 11.29 11.30 - attribBounds(tree.typarams); 11.31 + // Create a new environment with local scope 11.32 + // for attributing the method. 11.33 + Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); 11.34 + localEnv.info.lint = lint; 11.35 + 11.36 + attribStats(tree.typarams, localEnv); 11.37 11.38 // If we override any other methods, check that we do so properly. 11.39 // JLS ??? 11.40 @@ -903,12 +895,6 @@ 11.41 } 11.42 chk.checkOverride(tree, m); 11.43 11.44 - // Create a new environment with local scope 11.45 - // for attributing the method. 11.46 - Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); 11.47 - 11.48 - localEnv.info.lint = lint; 11.49 - 11.50 if (isDefaultMethod && types.overridesObjectMethod(m.enclClass(), m)) { 11.51 log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location()); 11.52 } 11.53 @@ -2196,7 +2182,7 @@ 11.54 Type target; 11.55 Type lambdaType; 11.56 if (pt() != Type.recoveryType) { 11.57 - target = infer.instantiateFunctionalInterface(that, pt(), explicitParamTypes, resultInfo.checkContext); 11.58 + target = infer.instantiateFunctionalInterface(that, checkIntersectionTarget(that, resultInfo), explicitParamTypes, resultInfo.checkContext); 11.59 lambdaType = types.findDescriptorType(target); 11.60 chk.checkFunctionalInterface(that, target); 11.61 } else { 11.62 @@ -2204,6 +2190,14 @@ 11.63 lambdaType = fallbackDescriptorType(that); 11.64 } 11.65 11.66 + if (lambdaType.hasTag(FORALL)) { 11.67 + //lambda expression target desc cannot be a generic method 11.68 + resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target", 11.69 + lambdaType, kindName(target.tsym), target.tsym)); 11.70 + result = that.type = types.createErrorType(pt()); 11.71 + return; 11.72 + } 11.73 + 11.74 if (!TreeInfo.isExplicitLambda(that)) { 11.75 //add param type info in the AST 11.76 List<Type> actuals = lambdaType.getParameterTypes(); 11.77 @@ -2244,9 +2238,13 @@ 11.78 //with the target-type, it will be recovered anyway in Attr.checkId 11.79 needsRecovery = false; 11.80 11.81 + FunctionalReturnContext funcContext = that.getBodyKind() == JCLambda.BodyKind.EXPRESSION ? 11.82 + new ExpressionLambdaReturnContext((JCExpression)that.getBody(), resultInfo.checkContext) : 11.83 + new FunctionalReturnContext(resultInfo.checkContext); 11.84 + 11.85 ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ? 11.86 recoveryInfo : 11.87 - new ResultInfo(VAL, lambdaType.getReturnType(), new LambdaReturnContext(resultInfo.checkContext)); 11.88 + new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); 11.89 localEnv.info.returnResult = bodyResultInfo; 11.90 11.91 if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { 11.92 @@ -2282,6 +2280,26 @@ 11.93 } 11.94 } 11.95 } 11.96 + 11.97 + private Type checkIntersectionTarget(DiagnosticPosition pos, ResultInfo resultInfo) { 11.98 + Type pt = resultInfo.pt; 11.99 + if (pt != Type.recoveryType && pt.isCompound()) { 11.100 + IntersectionClassType ict = (IntersectionClassType)pt; 11.101 + List<Type> bounds = ict.allInterfaces ? 11.102 + ict.getComponents().tail : 11.103 + ict.getComponents(); 11.104 + types.findDescriptorType(bounds.head); //propagate exception outwards! 11.105 + for (Type bound : bounds.tail) { 11.106 + if (!types.isMarkerInterface(bound)) { 11.107 + resultInfo.checkContext.report(pos, diags.fragment("secondary.bound.must.be.marker.intf", bound)); 11.108 + } 11.109 + } 11.110 + //for now (translation doesn't support intersection types) 11.111 + return bounds.head; 11.112 + } else { 11.113 + return pt; 11.114 + } 11.115 + } 11.116 //where 11.117 private Type fallbackDescriptorType(JCExpression tree) { 11.118 switch (tree.getTag()) { 11.119 @@ -2327,8 +2345,9 @@ 11.120 * type according to both the inherited context and the assignment 11.121 * context. 11.122 */ 11.123 - class LambdaReturnContext extends Check.NestedCheckContext { 11.124 - public LambdaReturnContext(CheckContext enclosingContext) { 11.125 + class FunctionalReturnContext extends Check.NestedCheckContext { 11.126 + 11.127 + FunctionalReturnContext(CheckContext enclosingContext) { 11.128 super(enclosingContext); 11.129 } 11.130 11.131 @@ -2344,6 +2363,23 @@ 11.132 } 11.133 } 11.134 11.135 + class ExpressionLambdaReturnContext extends FunctionalReturnContext { 11.136 + 11.137 + JCExpression expr; 11.138 + 11.139 + ExpressionLambdaReturnContext(JCExpression expr, CheckContext enclosingContext) { 11.140 + super(enclosingContext); 11.141 + this.expr = expr; 11.142 + } 11.143 + 11.144 + @Override 11.145 + public boolean compatible(Type found, Type req, Warner warn) { 11.146 + //a void return is compatible with an expression statement lambda 11.147 + return TreeInfo.isExpressionStatement(expr) && req.hasTag(VOID) || 11.148 + super.compatible(found, req, warn); 11.149 + } 11.150 + } 11.151 + 11.152 /** 11.153 * Lambda compatibility. Check that given return types, thrown types, parameter types 11.154 * are compatible with the expected functional interface descriptor. This means that: 11.155 @@ -2428,7 +2464,7 @@ 11.156 } 11.157 11.158 //attrib type-arguments 11.159 - List<Type> typeargtypes = null; 11.160 + List<Type> typeargtypes = List.nil(); 11.161 if (that.typeargs != null) { 11.162 typeargtypes = attribTypes(that.typeargs, localEnv); 11.163 } 11.164 @@ -2436,7 +2472,7 @@ 11.165 Type target; 11.166 Type desc; 11.167 if (pt() != Type.recoveryType) { 11.168 - target = infer.instantiateFunctionalInterface(that, pt(), null, resultInfo.checkContext); 11.169 + target = infer.instantiateFunctionalInterface(that, checkIntersectionTarget(that, resultInfo), null, resultInfo.checkContext); 11.170 desc = types.findDescriptorType(target); 11.171 chk.checkFunctionalInterface(that, target); 11.172 } else { 11.173 @@ -2498,6 +2534,26 @@ 11.174 } 11.175 } 11.176 11.177 + if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { 11.178 + if (refSym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) && 11.179 + exprType.getTypeArguments().nonEmpty()) { 11.180 + //static ref with class type-args 11.181 + log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), 11.182 + diags.fragment("static.mref.with.targs")); 11.183 + result = that.type = types.createErrorType(target); 11.184 + return; 11.185 + } 11.186 + 11.187 + if (refSym.isStatic() && !TreeInfo.isStaticSelector(that.expr, names) && 11.188 + !lookupHelper.referenceKind(refSym).isUnbound()) { 11.189 + //no static bound mrefs 11.190 + log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), 11.191 + diags.fragment("static.bound.mref")); 11.192 + result = that.type = types.createErrorType(target); 11.193 + return; 11.194 + } 11.195 + } 11.196 + 11.197 if (desc.getReturnType() == Type.recoveryType) { 11.198 // stop here 11.199 result = that.type = target; 11.200 @@ -2560,7 +2616,7 @@ 11.201 11.202 if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) { 11.203 if (resType.isErroneous() || 11.204 - new LambdaReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) { 11.205 + new FunctionalReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) { 11.206 incompatibleReturnType = null; 11.207 } 11.208 } 11.209 @@ -3525,63 +3581,79 @@ 11.210 tree.type = result = t; 11.211 } 11.212 11.213 - public void visitTypeParameter(JCTypeParameter tree) { 11.214 - TypeVar a = (TypeVar)tree.type; 11.215 + public void visitTypeIntersection(JCTypeIntersection tree) { 11.216 + attribTypes(tree.bounds, env); 11.217 + tree.type = result = checkIntersection(tree, tree.bounds); 11.218 + } 11.219 + 11.220 + public void visitTypeParameter(JCTypeParameter tree) { 11.221 + TypeVar typeVar = (TypeVar)tree.type; 11.222 + if (!typeVar.bound.isErroneous()) { 11.223 + //fixup type-parameter bound computed in 'attribTypeVariables' 11.224 + typeVar.bound = checkIntersection(tree, tree.bounds); 11.225 + } 11.226 + } 11.227 + 11.228 + Type checkIntersection(JCTree tree, List<JCExpression> bounds) { 11.229 Set<Type> boundSet = new HashSet<Type>(); 11.230 - if (a.bound.isErroneous()) 11.231 - return; 11.232 - List<Type> bs = types.getBounds(a); 11.233 - if (tree.bounds.nonEmpty()) { 11.234 + if (bounds.nonEmpty()) { 11.235 // accept class or interface or typevar as first bound. 11.236 - Type b = checkBase(bs.head, tree.bounds.head, env, false, false, false); 11.237 - boundSet.add(types.erasure(b)); 11.238 - if (b.isErroneous()) { 11.239 - a.bound = b; 11.240 + bounds.head.type = checkBase(bounds.head.type, bounds.head, env, false, false, false); 11.241 + boundSet.add(types.erasure(bounds.head.type)); 11.242 + if (bounds.head.type.isErroneous()) { 11.243 + return bounds.head.type; 11.244 } 11.245 - else if (b.hasTag(TYPEVAR)) { 11.246 + else if (bounds.head.type.hasTag(TYPEVAR)) { 11.247 // if first bound was a typevar, do not accept further bounds. 11.248 - if (tree.bounds.tail.nonEmpty()) { 11.249 - log.error(tree.bounds.tail.head.pos(), 11.250 + if (bounds.tail.nonEmpty()) { 11.251 + log.error(bounds.tail.head.pos(), 11.252 "type.var.may.not.be.followed.by.other.bounds"); 11.253 - tree.bounds = List.of(tree.bounds.head); 11.254 - a.bound = bs.head; 11.255 + return bounds.head.type; 11.256 } 11.257 } else { 11.258 // if first bound was a class or interface, accept only interfaces 11.259 // as further bounds. 11.260 - for (JCExpression bound : tree.bounds.tail) { 11.261 - bs = bs.tail; 11.262 - Type i = checkBase(bs.head, bound, env, false, true, false); 11.263 - if (i.isErroneous()) 11.264 - a.bound = i; 11.265 - else if (i.hasTag(CLASS)) 11.266 - chk.checkNotRepeated(bound.pos(), types.erasure(i), boundSet); 11.267 + for (JCExpression bound : bounds.tail) { 11.268 + bound.type = checkBase(bound.type, bound, env, false, true, false); 11.269 + if (bound.type.isErroneous()) { 11.270 + bounds = List.of(bound); 11.271 + } 11.272 + else if (bound.type.hasTag(CLASS)) { 11.273 + chk.checkNotRepeated(bound.pos(), types.erasure(bound.type), boundSet); 11.274 + } 11.275 } 11.276 } 11.277 } 11.278 - bs = types.getBounds(a); 11.279 - 11.280 - // in case of multiple bounds ... 11.281 - if (bs.length() > 1) { 11.282 + 11.283 + if (bounds.length() == 0) { 11.284 + return syms.objectType; 11.285 + } else if (bounds.length() == 1) { 11.286 + return bounds.head.type; 11.287 + } else { 11.288 + Type owntype = types.makeCompoundType(TreeInfo.types(bounds)); 11.289 + if (tree.hasTag(TYPEINTERSECTION)) { 11.290 + ((IntersectionClassType)owntype).intersectionKind = 11.291 + IntersectionClassType.IntersectionKind.EXPLICIT; 11.292 + } 11.293 // ... the variable's bound is a class type flagged COMPOUND 11.294 // (see comment for TypeVar.bound). 11.295 // In this case, generate a class tree that represents the 11.296 // bound class, ... 11.297 JCExpression extending; 11.298 List<JCExpression> implementing; 11.299 - if ((bs.head.tsym.flags() & INTERFACE) == 0) { 11.300 - extending = tree.bounds.head; 11.301 - implementing = tree.bounds.tail; 11.302 + if (!bounds.head.type.isInterface()) { 11.303 + extending = bounds.head; 11.304 + implementing = bounds.tail; 11.305 } else { 11.306 extending = null; 11.307 - implementing = tree.bounds; 11.308 + implementing = bounds; 11.309 } 11.310 - JCClassDecl cd = make.at(tree.pos).ClassDef( 11.311 + JCClassDecl cd = make.at(tree).ClassDef( 11.312 make.Modifiers(PUBLIC | ABSTRACT), 11.313 - tree.name, List.<JCTypeParameter>nil(), 11.314 + names.empty, List.<JCTypeParameter>nil(), 11.315 extending, implementing, List.<JCTree>nil()); 11.316 11.317 - ClassSymbol c = (ClassSymbol)a.getUpperBound().tsym; 11.318 + ClassSymbol c = (ClassSymbol)owntype.tsym; 11.319 Assert.check((c.flags() & COMPOUND) != 0); 11.320 cd.sym = c; 11.321 c.sourcefile = env.toplevel.sourcefile; 11.322 @@ -3590,10 +3662,11 @@ 11.323 c.flags_field |= UNATTRIBUTED; 11.324 Env<AttrContext> cenv = enter.classEnv(cd, env); 11.325 enter.typeEnvs.put(c, cenv); 11.326 + attribClass(c); 11.327 + return owntype; 11.328 } 11.329 } 11.330 11.331 - 11.332 public void visitWildcard(JCWildcard tree) { 11.333 //- System.err.println("visitWildcard("+tree+");");//DEBUG 11.334 Type type = (tree.kind.kind == BoundKind.UNBOUND) 11.335 @@ -3747,7 +3820,7 @@ 11.336 chk.validateAnnotations(tree.mods.annotations, c); 11.337 11.338 // Validate type parameters, supertype and interfaces. 11.339 - attribBounds(tree.typarams); 11.340 + attribStats(tree.typarams, env); 11.341 if (!c.isAnonymous()) { 11.342 //already checked if anonymous 11.343 chk.validate(tree.typarams, env);
12.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Thu Dec 06 12:04:44 2012 -0800 12.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Mon Dec 10 20:59:38 2012 -0800 12.3 @@ -288,21 +288,20 @@ 12.4 JCExpression init; 12.5 switch(tree.kind) { 12.6 12.7 - case IMPLICIT_INNER: /** Inner # new */ 12.8 - case SUPER: /** super # instMethod */ 12.9 + case IMPLICIT_INNER: /** Inner :: new */ 12.10 + case SUPER: /** super :: instMethod */ 12.11 init = makeThis( 12.12 localContext.owner.owner.asType(), 12.13 localContext.owner); 12.14 break; 12.15 12.16 - case BOUND: /** Expr # instMethod */ 12.17 + case BOUND: /** Expr :: instMethod */ 12.18 init = tree.getQualifierExpression(); 12.19 break; 12.20 12.21 - case STATIC_EVAL: /** Expr # staticMethod */ 12.22 - case UNBOUND: /** Type # instMethod */ 12.23 - case STATIC: /** Type # staticMethod */ 12.24 - case TOPLEVEL: /** Top level # new */ 12.25 + case UNBOUND: /** Type :: instMethod */ 12.26 + case STATIC: /** Type :: staticMethod */ 12.27 + case TOPLEVEL: /** Top level :: new */ 12.28 init = null; 12.29 break; 12.30 12.31 @@ -315,14 +314,6 @@ 12.32 12.33 //build a sam instance using an indy call to the meta-factory 12.34 result = makeMetaFactoryIndyCall(tree, tree.targetType, localContext.referenceKind(), refSym, indy_args); 12.35 - 12.36 - //if we had a static reference with non-static qualifier, add a let 12.37 - //expression to force the evaluation of the qualifier expr 12.38 - if (tree.hasKind(ReferenceKind.STATIC_EVAL)) { 12.39 - VarSymbol rec = new VarSymbol(0, names.fromString("rec$"), tree.getQualifierExpression().type, localContext.owner); 12.40 - JCVariableDecl recDef = make.VarDef(rec, tree.getQualifierExpression()); 12.41 - result = make.LetExpr(recDef, result).setType(tree.type); 12.42 - } 12.43 } 12.44 12.45 /**
13.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Dec 06 12:04:44 2012 -0800 13.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon Dec 10 20:59:38 2012 -0800 13.3 @@ -138,6 +138,10 @@ 13.4 */ 13.5 Map<ClassSymbol, JCClassDecl> classdefs; 13.6 13.7 + /** A hash table mapping local classes to a list of pruned trees. 13.8 + */ 13.9 + public Map<ClassSymbol, List<JCTree>> prunedTree = new WeakHashMap<ClassSymbol, List<JCTree>>(); 13.10 + 13.11 /** A hash table mapping virtual accessed symbols in outer subclasses 13.12 * to the actually referred symbol in superclasses. 13.13 */ 13.14 @@ -1039,6 +1043,12 @@ 13.15 } 13.16 } 13.17 13.18 + private void addPrunedInfo(JCTree tree) { 13.19 + List<JCTree> infoList = prunedTree.get(currentClass); 13.20 + infoList = (infoList == null) ? List.of(tree) : infoList.prepend(tree); 13.21 + prunedTree.put(currentClass, infoList); 13.22 + } 13.23 + 13.24 /** Ensure that identifier is accessible, return tree accessing the identifier. 13.25 * @param sym The accessed symbol. 13.26 * @param tree The tree referring to the symbol. 13.27 @@ -1111,7 +1121,10 @@ 13.28 // Constants are replaced by their constant value. 13.29 if (sym.kind == VAR) { 13.30 Object cv = ((VarSymbol)sym).getConstValue(); 13.31 - if (cv != null) return makeLit(sym.type, cv); 13.32 + if (cv != null) { 13.33 + addPrunedInfo(tree); 13.34 + return makeLit(sym.type, cv); 13.35 + } 13.36 } 13.37 13.38 // Private variables and methods are replaced by calls 13.39 @@ -2746,12 +2759,15 @@ 13.40 13.41 /** Visitor method for conditional expressions. 13.42 */ 13.43 + @Override 13.44 public void visitConditional(JCConditional tree) { 13.45 JCTree cond = tree.cond = translate(tree.cond, syms.booleanType); 13.46 if (cond.type.isTrue()) { 13.47 result = convert(translate(tree.truepart, tree.type), tree.type); 13.48 + addPrunedInfo(cond); 13.49 } else if (cond.type.isFalse()) { 13.50 result = convert(translate(tree.falsepart, tree.type), tree.type); 13.51 + addPrunedInfo(cond); 13.52 } else { 13.53 // Condition is not a compile-time constant. 13.54 tree.truepart = translate(tree.truepart, tree.type); 13.55 @@ -2760,14 +2776,14 @@ 13.56 } 13.57 } 13.58 //where 13.59 - private JCTree convert(JCTree tree, Type pt) { 13.60 - if (tree.type == pt || tree.type.hasTag(BOT)) 13.61 - return tree; 13.62 - JCTree result = make_at(tree.pos()).TypeCast(make.Type(pt), (JCExpression)tree); 13.63 - result.type = (tree.type.constValue() != null) ? cfolder.coerce(tree.type, pt) 13.64 - : pt; 13.65 - return result; 13.66 - } 13.67 + private JCTree convert(JCTree tree, Type pt) { 13.68 + if (tree.type == pt || tree.type.hasTag(BOT)) 13.69 + return tree; 13.70 + JCTree result = make_at(tree.pos()).TypeCast(make.Type(pt), (JCExpression)tree); 13.71 + result.type = (tree.type.constValue() != null) ? cfolder.coerce(tree.type, pt) 13.72 + : pt; 13.73 + return result; 13.74 + } 13.75 13.76 /** Visitor method for if statements. 13.77 */ 13.78 @@ -2775,12 +2791,14 @@ 13.79 JCTree cond = tree.cond = translate(tree.cond, syms.booleanType); 13.80 if (cond.type.isTrue()) { 13.81 result = translate(tree.thenpart); 13.82 + addPrunedInfo(cond); 13.83 } else if (cond.type.isFalse()) { 13.84 if (tree.elsepart != null) { 13.85 result = translate(tree.elsepart); 13.86 } else { 13.87 result = make.Skip(); 13.88 } 13.89 + addPrunedInfo(cond); 13.90 } else { 13.91 // Condition is not a compile-time constant. 13.92 tree.thenpart = translate(tree.thenpart);
14.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Dec 06 12:04:44 2012 -0800 14.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Dec 10 20:59:38 2012 -0800 14.3 @@ -2617,8 +2617,7 @@ 14.4 @Override 14.5 ReferenceKind referenceKind(Symbol sym) { 14.6 if (sym.isStatic()) { 14.7 - return TreeInfo.isStaticSelector(referenceTree.expr, names) ? 14.8 - ReferenceKind.STATIC : ReferenceKind.STATIC_EVAL; 14.9 + return ReferenceKind.STATIC; 14.10 } else { 14.11 Name selName = TreeInfo.name(referenceTree.getQualifierExpression()); 14.12 return selName != null && selName == names._super ?
15.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Dec 06 12:04:44 2012 -0800 15.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Mon Dec 10 20:59:38 2012 -0800 15.3 @@ -551,6 +551,7 @@ 15.4 tree.body = translate(tree.body, null); 15.5 //save non-erased target 15.6 tree.targetType = tree.type; 15.7 + Assert.check(!tree.targetType.isCompound(), "Intersection-type targets not supported yet!"); 15.8 tree.type = erasure(tree.type); 15.9 result = tree; 15.10 } 15.11 @@ -786,6 +787,7 @@ 15.12 tree.expr = translate(tree.expr, null); 15.13 //save non-erased target 15.14 tree.targetType = tree.type; 15.15 + Assert.check(!tree.targetType.isCompound(), "Intersection-type targets not supported yet!"); 15.16 tree.type = erasure(tree.type); 15.17 result = tree; 15.18 } 15.19 @@ -803,6 +805,12 @@ 15.20 result = clazz; 15.21 } 15.22 15.23 + public void visitTypeIntersection(JCTypeIntersection tree) { 15.24 + tree.bounds = translate(tree.bounds, null); 15.25 + tree.type = erasure(tree.type); 15.26 + result = tree; 15.27 + } 15.28 + 15.29 /************************************************************************** 15.30 * utility methods 15.31 *************************************************************************/
16.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu Dec 06 12:04:44 2012 -0800 16.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Mon Dec 10 20:59:38 2012 -0800 16.3 @@ -846,17 +846,17 @@ 16.4 tvar = (TypeVar)findTypeVar(name); 16.5 } 16.6 List<Type> bounds = List.nil(); 16.7 - Type st = null; 16.8 + boolean allInterfaces = false; 16.9 if (signature[sigp] == ':' && signature[sigp+1] == ':') { 16.10 sigp++; 16.11 - st = syms.objectType; 16.12 + allInterfaces = true; 16.13 } 16.14 while (signature[sigp] == ':') { 16.15 sigp++; 16.16 bounds = bounds.prepend(sigToType()); 16.17 } 16.18 if (!sigEnterPhase) { 16.19 - types.setBounds(tvar, bounds.reverse(), st); 16.20 + types.setBounds(tvar, bounds.reverse(), allInterfaces); 16.21 } 16.22 return tvar; 16.23 }
17.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu Dec 06 12:04:44 2012 -0800 17.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon Dec 10 20:59:38 2012 -0800 17.3 @@ -71,6 +71,7 @@ 17.4 private final Map<Type,Symbol> stringBufferAppend; 17.5 private Name accessDollar; 17.6 private final Types types; 17.7 + private final Lower lower; 17.8 17.9 /** Switch: GJ mode? 17.10 */ 17.11 @@ -112,6 +113,7 @@ 17.12 stringBufferAppend = new HashMap<Type,Symbol>(); 17.13 accessDollar = names. 17.14 fromString("access" + target.syntheticNameChar()); 17.15 + lower = Lower.instance(context); 17.16 17.17 Options options = Options.instance(context); 17.18 lineDebugInfo = 17.19 @@ -816,6 +818,62 @@ 17.20 } 17.21 } 17.22 17.23 + /** Visitor class for expressions which might be constant expressions. 17.24 + * This class is a subset of TreeScanner. Intended to visit trees pruned by 17.25 + * Lower as long as constant expressions looking for references to any 17.26 + * ClassSymbol. Any such reference will be added to the constant pool so 17.27 + * automated tools can detect class dependencies better. 17.28 + */ 17.29 + class ClassReferenceVisitor extends JCTree.Visitor { 17.30 + 17.31 + @Override 17.32 + public void visitTree(JCTree tree) {} 17.33 + 17.34 + @Override 17.35 + public void visitBinary(JCBinary tree) { 17.36 + tree.lhs.accept(this); 17.37 + tree.rhs.accept(this); 17.38 + } 17.39 + 17.40 + @Override 17.41 + public void visitSelect(JCFieldAccess tree) { 17.42 + if (tree.selected.type.hasTag(CLASS)) { 17.43 + makeRef(tree.selected.pos(), tree.selected.type); 17.44 + } 17.45 + } 17.46 + 17.47 + @Override 17.48 + public void visitIdent(JCIdent tree) { 17.49 + if (tree.sym.owner instanceof ClassSymbol) { 17.50 + pool.put(tree.sym.owner); 17.51 + } 17.52 + } 17.53 + 17.54 + @Override 17.55 + public void visitConditional(JCConditional tree) { 17.56 + tree.cond.accept(this); 17.57 + tree.truepart.accept(this); 17.58 + tree.falsepart.accept(this); 17.59 + } 17.60 + 17.61 + @Override 17.62 + public void visitUnary(JCUnary tree) { 17.63 + tree.arg.accept(this); 17.64 + } 17.65 + 17.66 + @Override 17.67 + public void visitParens(JCParens tree) { 17.68 + tree.expr.accept(this); 17.69 + } 17.70 + 17.71 + @Override 17.72 + public void visitTypeCast(JCTypeCast tree) { 17.73 + tree.expr.accept(this); 17.74 + } 17.75 + } 17.76 + 17.77 + private ClassReferenceVisitor classReferenceVisitor = new ClassReferenceVisitor(); 17.78 + 17.79 /** Visitor method: generate code for an expression, catching and reporting 17.80 * any completion failures. 17.81 * @param tree The expression to be visited. 17.82 @@ -826,6 +884,7 @@ 17.83 try { 17.84 if (tree.type.constValue() != null) { 17.85 // Short circuit any expressions which are constants 17.86 + tree.accept(classReferenceVisitor); 17.87 checkStringConstant(tree.pos(), tree.type.constValue()); 17.88 result = items.makeImmediateItem(tree.type, tree.type.constValue()); 17.89 } else { 17.90 @@ -2205,6 +2264,15 @@ 17.91 code.endScopes(limit); 17.92 } 17.93 17.94 + private void generateReferencesToPrunedTree(ClassSymbol classSymbol, Pool pool) { 17.95 + List<JCTree> prunedInfo = lower.prunedTree.get(classSymbol); 17.96 + if (prunedInfo != null) { 17.97 + for (JCTree prunedTree: prunedInfo) { 17.98 + prunedTree.accept(classReferenceVisitor); 17.99 + } 17.100 + } 17.101 + } 17.102 + 17.103 /* ************************************************************************ 17.104 * main method 17.105 *************************************************************************/ 17.106 @@ -2232,6 +2300,7 @@ 17.107 cdef.defs = normalizeDefs(cdef.defs, c); 17.108 c.pool = pool; 17.109 pool.reset(); 17.110 + generateReferencesToPrunedTree(c, pool); 17.111 Env<GenContext> localEnv = 17.112 new Env<GenContext>(cdef, new GenContext()); 17.113 localEnv.toplevel = env.toplevel;
18.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Thu Dec 06 12:04:44 2012 -0800 18.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Mon Dec 10 20:59:38 2012 -0800 18.3 @@ -74,6 +74,7 @@ 18.4 public Element asElement(TypeMirror t) { 18.5 switch (t.getKind()) { 18.6 case DECLARED: 18.7 + case INTERSECTION: 18.8 case ERROR: 18.9 case TYPEVAR: 18.10 Type type = cast(Type.class, t);
19.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Thu Dec 06 12:04:44 2012 -0800 19.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Mon Dec 10 20:59:38 2012 -0800 19.3 @@ -348,8 +348,8 @@ 19.4 private void scanIdent() { 19.5 boolean isJavaIdentifierPart; 19.6 char high; 19.7 + reader.putChar(true); 19.8 do { 19.9 - reader.putChar(true); 19.10 switch (reader.ch) { 19.11 case 'A': case 'B': case 'C': case 'D': case 'E': 19.12 case 'F': case 'G': case 'H': case 'I': case 'J': 19.13 @@ -366,6 +366,7 @@ 19.14 case '$': case '_': 19.15 case '0': case '1': case '2': case '3': case '4': 19.16 case '5': case '6': case '7': case '8': case '9': 19.17 + break; 19.18 case '\u0000': case '\u0001': case '\u0002': case '\u0003': 19.19 case '\u0004': case '\u0005': case '\u0006': case '\u0007': 19.20 case '\u0008': case '\u000E': case '\u000F': case '\u0010': 19.21 @@ -373,26 +374,33 @@ 19.22 case '\u0015': case '\u0016': case '\u0017': 19.23 case '\u0018': case '\u0019': case '\u001B': 19.24 case '\u007F': 19.25 - break; 19.26 + reader.scanChar(); 19.27 + continue; 19.28 case '\u001A': // EOI is also a legal identifier part 19.29 if (reader.bp >= reader.buflen) { 19.30 name = reader.name(); 19.31 tk = tokens.lookupKind(name); 19.32 return; 19.33 } 19.34 - break; 19.35 + reader.scanChar(); 19.36 + continue; 19.37 default: 19.38 if (reader.ch < '\u0080') { 19.39 // all ASCII range chars already handled, above 19.40 isJavaIdentifierPart = false; 19.41 } else { 19.42 - high = reader.scanSurrogates(); 19.43 - if (high != 0) { 19.44 - reader.putChar(high); 19.45 - isJavaIdentifierPart = Character.isJavaIdentifierPart( 19.46 - Character.toCodePoint(high, reader.ch)); 19.47 + if (Character.isIdentifierIgnorable(reader.ch)) { 19.48 + reader.scanChar(); 19.49 + continue; 19.50 } else { 19.51 - isJavaIdentifierPart = Character.isJavaIdentifierPart(reader.ch); 19.52 + high = reader.scanSurrogates(); 19.53 + if (high != 0) { 19.54 + reader.putChar(high); 19.55 + isJavaIdentifierPart = Character.isJavaIdentifierPart( 19.56 + Character.toCodePoint(high, reader.ch)); 19.57 + } else { 19.58 + isJavaIdentifierPart = Character.isJavaIdentifierPart(reader.ch); 19.59 + } 19.60 } 19.61 } 19.62 if (!isJavaIdentifierPart) { 19.63 @@ -401,6 +409,7 @@ 19.64 return; 19.65 } 19.66 } 19.67 + reader.putChar(true); 19.68 } while (true); 19.69 } 19.70
20.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Dec 06 12:04:44 2012 -0800 20.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Dec 10 20:59:38 2012 -0800 20.3 @@ -124,6 +124,9 @@ 20.4 this.allowLambda = source.allowLambda(); 20.5 this.allowMethodReferences = source.allowMethodReferences(); 20.6 this.allowDefaultMethods = source.allowDefaultMethods(); 20.7 + this.allowIntersectionTypesInCast = 20.8 + source.allowIntersectionTypesInCast() && 20.9 + fac.options.isSet("allowIntersectionTypes"); 20.10 this.keepDocComments = keepDocComments; 20.11 docComments = newDocCommentTable(keepDocComments, fac); 20.12 this.keepLineMap = keepLineMap; 20.13 @@ -197,6 +200,10 @@ 20.14 */ 20.15 boolean allowDefaultMethods; 20.16 20.17 + /** Switch: should we allow intersection types in cast? 20.18 + */ 20.19 + boolean allowIntersectionTypesInCast; 20.20 + 20.21 /** Switch: should we keep docComments? 20.22 */ 20.23 boolean keepDocComments; 20.24 @@ -239,22 +246,38 @@ 20.25 } 20.26 20.27 protected boolean peekToken(TokenKind tk) { 20.28 - return S.token(1).kind == tk; 20.29 + return peekToken(0, tk); 20.30 + } 20.31 + 20.32 + protected boolean peekToken(int lookahead, TokenKind tk) { 20.33 + return S.token(lookahead + 1).kind == tk; 20.34 } 20.35 20.36 protected boolean peekToken(TokenKind tk1, TokenKind tk2) { 20.37 - return S.token(1).kind == tk1 && 20.38 - S.token(2).kind == tk2; 20.39 + return peekToken(0, tk1, tk2); 20.40 + } 20.41 + 20.42 + protected boolean peekToken(int lookahead, TokenKind tk1, TokenKind tk2) { 20.43 + return S.token(lookahead + 1).kind == tk1 && 20.44 + S.token(lookahead + 2).kind == tk2; 20.45 } 20.46 20.47 protected boolean peekToken(TokenKind tk1, TokenKind tk2, TokenKind tk3) { 20.48 - return S.token(1).kind == tk1 && 20.49 - S.token(2).kind == tk2 && 20.50 - S.token(3).kind == tk3; 20.51 + return peekToken(0, tk1, tk2, tk3); 20.52 + } 20.53 + 20.54 + protected boolean peekToken(int lookahead, TokenKind tk1, TokenKind tk2, TokenKind tk3) { 20.55 + return S.token(lookahead + 1).kind == tk1 && 20.56 + S.token(lookahead + 2).kind == tk2 && 20.57 + S.token(lookahead + 3).kind == tk3; 20.58 } 20.59 20.60 protected boolean peekToken(TokenKind... kinds) { 20.61 - for (int lookahead = 0 ; lookahead < kinds.length ; lookahead++) { 20.62 + return peekToken(0, kinds); 20.63 + } 20.64 + 20.65 + protected boolean peekToken(int lookahead, TokenKind... kinds) { 20.66 + for (; lookahead < kinds.length ; lookahead++) { 20.67 if (S.token(lookahead + 1).kind != kinds[lookahead]) { 20.68 return false; 20.69 } 20.70 @@ -966,102 +989,40 @@ 20.71 break; 20.72 case LPAREN: 20.73 if (typeArgs == null && (mode & EXPR) != 0) { 20.74 - if (peekToken(MONKEYS_AT) || 20.75 - peekToken(FINAL) || 20.76 - peekToken(RPAREN) || 20.77 - peekToken(IDENTIFIER, COMMA) || 20.78 - peekToken(IDENTIFIER, RPAREN, ARROW)) { 20.79 - //implicit n-ary lambda 20.80 - t = lambdaExpressionOrStatement(true, peekToken(MONKEYS_AT) || peekToken(FINAL), pos); 20.81 - break; 20.82 - } else { 20.83 - nextToken(); 20.84 - mode = EXPR | TYPE | NOPARAMS; 20.85 - t = term3(); 20.86 - if ((mode & TYPE) != 0 && token.kind == LT) { 20.87 - // Could be a cast to a parameterized type 20.88 - JCTree.Tag op = JCTree.Tag.LT; 20.89 - int pos1 = token.pos; 20.90 - nextToken(); 20.91 - mode &= (EXPR | TYPE); 20.92 - mode |= TYPEARG; 20.93 - JCExpression t1 = term3(); 20.94 - if ((mode & TYPE) != 0 && 20.95 - (token.kind == COMMA || token.kind == GT)) { 20.96 - mode = TYPE; 20.97 - ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); 20.98 - args.append(t1); 20.99 - while (token.kind == COMMA) { 20.100 - nextToken(); 20.101 - args.append(typeArgument()); 20.102 - } 20.103 - accept(GT); 20.104 - t = toP(F.at(pos1).TypeApply(t, args.toList())); 20.105 - checkGenerics(); 20.106 - mode = EXPR | TYPE; //could be a lambda or a method ref or a cast to a type 20.107 - t = term3Rest(t, typeArgs); 20.108 - if (token.kind == IDENTIFIER || token.kind == ELLIPSIS) { 20.109 - //explicit lambda (w/ generic type) 20.110 - mode = EXPR; 20.111 - JCModifiers mods = F.at(token.pos).Modifiers(Flags.PARAMETER); 20.112 - if (token.kind == ELLIPSIS) { 20.113 - mods.flags = Flags.VARARGS; 20.114 - t = to(F.at(token.pos).TypeArray(t)); 20.115 - nextToken(); 20.116 - } 20.117 - t = lambdaExpressionOrStatement(variableDeclaratorId(mods, t), pos); 20.118 - break; 20.119 - } 20.120 - } else if ((mode & EXPR) != 0) { 20.121 - mode = EXPR; 20.122 - JCExpression e = term2Rest(t1, TreeInfo.shiftPrec); 20.123 - t = F.at(pos1).Binary(op, t, e); 20.124 - t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec))); 20.125 - } else { 20.126 - accept(GT); 20.127 - } 20.128 - } else if ((mode & TYPE) != 0 && 20.129 - (token.kind == IDENTIFIER || token.kind == ELLIPSIS)) { 20.130 - //explicit lambda (w/ non-generic type) 20.131 + ParensResult pres = analyzeParens(); 20.132 + switch (pres) { 20.133 + case CAST: 20.134 + accept(LPAREN); 20.135 + mode = TYPE; 20.136 + int pos1 = pos; 20.137 + List<JCExpression> targets = List.of(t = term3()); 20.138 + while (token.kind == AMP) { 20.139 + checkIntersectionTypesInCast(); 20.140 + accept(AMP); 20.141 + targets = targets.prepend(term3()); 20.142 + } 20.143 + if (targets.length() > 1) { 20.144 + t = toP(F.at(pos1).TypeIntersection(targets.reverse())); 20.145 + } 20.146 + accept(RPAREN); 20.147 + mode = EXPR; 20.148 + JCExpression t1 = term3(); 20.149 + return F.at(pos).TypeCast(t, t1); 20.150 + case IMPLICIT_LAMBDA: 20.151 + case EXPLICIT_LAMBDA: 20.152 + t = lambdaExpressionOrStatement(true, pres == ParensResult.EXPLICIT_LAMBDA, pos); 20.153 + break; 20.154 + default: //PARENS 20.155 + accept(LPAREN); 20.156 mode = EXPR; 20.157 - JCModifiers mods = F.at(token.pos).Modifiers(Flags.PARAMETER); 20.158 - if (token.kind == ELLIPSIS) { 20.159 - mods.flags = Flags.VARARGS; 20.160 - t = to(F.at(token.pos).TypeArray(t)); 20.161 - nextToken(); 20.162 - } 20.163 - t = lambdaExpressionOrStatement(variableDeclaratorId(mods, t), pos); 20.164 + t = termRest(term1Rest(term2Rest(term3(), TreeInfo.orPrec))); 20.165 + accept(RPAREN); 20.166 + t = toP(F.at(pos).Parens(t)); 20.167 break; 20.168 - } else { 20.169 - t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec))); 20.170 - } 20.171 - } 20.172 - 20.173 - accept(RPAREN); 20.174 - lastmode = mode; 20.175 - mode = EXPR; 20.176 - if ((lastmode & EXPR) == 0) { 20.177 - JCExpression t1 = term3(); 20.178 - return F.at(pos).TypeCast(t, t1); 20.179 - } else if ((lastmode & TYPE) != 0) { 20.180 - switch (token.kind) { 20.181 - /*case PLUSPLUS: case SUBSUB: */ 20.182 - case BANG: case TILDE: 20.183 - case LPAREN: case THIS: case SUPER: 20.184 - case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: 20.185 - case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL: 20.186 - case TRUE: case FALSE: case NULL: 20.187 - case NEW: case IDENTIFIER: case ASSERT: case ENUM: 20.188 - case BYTE: case SHORT: case CHAR: case INT: 20.189 - case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID: 20.190 - JCExpression t1 = term3(); 20.191 - return F.at(pos).TypeCast(t, t1); 20.192 - } 20.193 } 20.194 } else { 20.195 return illegal(); 20.196 } 20.197 - t = toP(F.at(pos).Parens(t)); 20.198 break; 20.199 case THIS: 20.200 if ((mode & EXPR) != 0) { 20.201 @@ -1346,6 +1307,138 @@ 20.202 } 20.203 } 20.204 20.205 + /** 20.206 + * If we see an identifier followed by a '<' it could be an unbound 20.207 + * method reference or a binary expression. To disambiguate, look for a 20.208 + * matching '>' and see if the subsequent terminal is either '.' or '#'. 20.209 + */ 20.210 + @SuppressWarnings("fallthrough") 20.211 + ParensResult analyzeParens() { 20.212 + int depth = 0; 20.213 + boolean type = false; 20.214 + for (int lookahead = 0 ; ; lookahead++) { 20.215 + TokenKind tk = S.token(lookahead).kind; 20.216 + switch (tk) { 20.217 + case EXTENDS: case SUPER: case COMMA: 20.218 + type = true; 20.219 + case QUES: case DOT: case AMP: 20.220 + //skip 20.221 + break; 20.222 + case BYTE: case SHORT: case INT: case LONG: case FLOAT: 20.223 + case DOUBLE: case BOOLEAN: case CHAR: 20.224 + if (peekToken(lookahead, RPAREN)) { 20.225 + //Type, ')' -> cast 20.226 + return ParensResult.CAST; 20.227 + } else if (peekToken(lookahead, IDENTIFIER)) { 20.228 + //Type, 'Identifier -> explicit lambda 20.229 + return ParensResult.EXPLICIT_LAMBDA; 20.230 + } 20.231 + break; 20.232 + case LPAREN: 20.233 + if (lookahead != 0) { 20.234 + // '(' in a non-starting position -> parens 20.235 + return ParensResult.PARENS; 20.236 + } else if (peekToken(lookahead, RPAREN)) { 20.237 + // '(', ')' -> explicit lambda 20.238 + return ParensResult.EXPLICIT_LAMBDA; 20.239 + } 20.240 + break; 20.241 + case RPAREN: 20.242 + // if we have seen something that looks like a type, 20.243 + // then it's a cast expression 20.244 + if (type) return ParensResult.CAST; 20.245 + // otherwise, disambiguate cast vs. parenthesized expression 20.246 + // based on subsequent token. 20.247 + switch (S.token(lookahead + 1).kind) { 20.248 + /*case PLUSPLUS: case SUBSUB: */ 20.249 + case BANG: case TILDE: 20.250 + case LPAREN: case THIS: case SUPER: 20.251 + case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: 20.252 + case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL: 20.253 + case TRUE: case FALSE: case NULL: 20.254 + case NEW: case IDENTIFIER: case ASSERT: case ENUM: 20.255 + case BYTE: case SHORT: case CHAR: case INT: 20.256 + case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID: 20.257 + return ParensResult.CAST; 20.258 + default: 20.259 + return ParensResult.PARENS; 20.260 + } 20.261 + case IDENTIFIER: 20.262 + if (peekToken(lookahead, IDENTIFIER)) { 20.263 + // Identifier, Identifier -> explicit lambda 20.264 + return ParensResult.EXPLICIT_LAMBDA; 20.265 + } else if (peekToken(lookahead, RPAREN, ARROW)) { 20.266 + // Identifier, ')' '->' -> implicit lambda 20.267 + return ParensResult.IMPLICIT_LAMBDA; 20.268 + } 20.269 + break; 20.270 + case FINAL: 20.271 + case ELLIPSIS: 20.272 + case MONKEYS_AT: 20.273 + //those can only appear in explicit lambdas 20.274 + return ParensResult.EXPLICIT_LAMBDA; 20.275 + case LBRACKET: 20.276 + if (peekToken(lookahead, RBRACKET, IDENTIFIER)) { 20.277 + // '[', ']', Identifier -> explicit lambda 20.278 + return ParensResult.EXPLICIT_LAMBDA; 20.279 + } else if (peekToken(lookahead, RBRACKET, RPAREN) || 20.280 + peekToken(lookahead, RBRACKET, AMP)) { 20.281 + // '[', ']', ')' -> cast 20.282 + // '[', ']', '&' -> cast (intersection type) 20.283 + return ParensResult.CAST; 20.284 + } else if (peekToken(lookahead, RBRACKET)) { 20.285 + //consume the ']' and skip 20.286 + type = true; 20.287 + lookahead++; 20.288 + break; 20.289 + } else { 20.290 + return ParensResult.PARENS; 20.291 + } 20.292 + case LT: 20.293 + depth++; break; 20.294 + case GTGTGT: 20.295 + depth--; 20.296 + case GTGT: 20.297 + depth--; 20.298 + case GT: 20.299 + depth--; 20.300 + if (depth == 0) { 20.301 + if (peekToken(lookahead, RPAREN) || 20.302 + peekToken(lookahead, AMP)) { 20.303 + // '>', ')' -> cast 20.304 + // '>', '&' -> cast 20.305 + return ParensResult.CAST; 20.306 + } else if (peekToken(lookahead, IDENTIFIER, COMMA) || 20.307 + peekToken(lookahead, IDENTIFIER, RPAREN, ARROW) || 20.308 + peekToken(lookahead, ELLIPSIS)) { 20.309 + // '>', Identifier, ',' -> explicit lambda 20.310 + // '>', Identifier, ')', '->' -> explicit lambda 20.311 + // '>', '...' -> explicit lambda 20.312 + return ParensResult.EXPLICIT_LAMBDA; 20.313 + } 20.314 + //it looks a type, but could still be (i) a cast to generic type, 20.315 + //(ii) an unbound method reference or (iii) an explicit lambda 20.316 + type = true; 20.317 + break; 20.318 + } else if (depth < 0) { 20.319 + //unbalanced '<', '>' - not a generic type 20.320 + return ParensResult.PARENS; 20.321 + } 20.322 + break; 20.323 + default: 20.324 + //this includes EOF 20.325 + return ParensResult.PARENS; 20.326 + } 20.327 + } 20.328 + } 20.329 + 20.330 + enum ParensResult { 20.331 + CAST, 20.332 + EXPLICIT_LAMBDA, 20.333 + IMPLICIT_LAMBDA, 20.334 + PARENS; 20.335 + } 20.336 + 20.337 JCExpression lambdaExpressionOrStatement(JCVariableDecl firstParam, int pos) { 20.338 ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); 20.339 params.append(firstParam); 20.340 @@ -3171,21 +3264,12 @@ 20.341 /** Check that given tree is a legal expression statement. 20.342 */ 20.343 protected JCExpression checkExprStat(JCExpression t) { 20.344 - switch(t.getTag()) { 20.345 - case PREINC: case PREDEC: 20.346 - case POSTINC: case POSTDEC: 20.347 - case ASSIGN: 20.348 - case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG: 20.349 - case SL_ASG: case SR_ASG: case USR_ASG: 20.350 - case PLUS_ASG: case MINUS_ASG: 20.351 - case MUL_ASG: case DIV_ASG: case MOD_ASG: 20.352 - case APPLY: case NEWCLASS: 20.353 - case ERRONEOUS: 20.354 - return t; 20.355 - default: 20.356 + if (!TreeInfo.isExpressionStatement(t)) { 20.357 JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t)); 20.358 error(ret, "not.stmt"); 20.359 return ret; 20.360 + } else { 20.361 + return t; 20.362 } 20.363 } 20.364 20.365 @@ -3395,6 +3479,12 @@ 20.366 allowDefaultMethods = true; 20.367 } 20.368 } 20.369 + void checkIntersectionTypesInCast() { 20.370 + if (!allowIntersectionTypesInCast) { 20.371 + log.error(token.pos, "intersection.types.in.cast.not.supported.in.source", source.name); 20.372 + allowIntersectionTypesInCast = true; 20.373 + } 20.374 + } 20.375 20.376 /* 20.377 * a functional source tree and end position mappings
21.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Dec 06 12:04:44 2012 -0800 21.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon Dec 10 20:59:38 2012 -0800 21.3 @@ -187,8 +187,9 @@ 21.4 {0} 21.5 21.6 # 0: symbol, 1: symbol kind, 2: symbol 21.7 -compiler.misc.invalid.generic.desc.in.functional.intf=\ 21.8 - invalid functional descriptor: method {0} in {1} {2} is generic 21.9 +compiler.misc.invalid.generic.lambda.target=\ 21.10 + invalid functional descriptor for lambda expression\n\ 21.11 + method {0} in {1} {2} is generic 21.12 21.13 # 0: symbol kind, 1: symbol 21.14 compiler.misc.incompatible.descs.in.functional.intf=\ 21.15 @@ -206,6 +207,10 @@ 21.16 compiler.misc.no.suitable.functional.intf.inst=\ 21.17 cannot infer functional interface descriptor for {0} 21.18 21.19 +# 0: type 21.20 +compiler.misc.secondary.bound.must.be.marker.intf=\ 21.21 + secondary bound {0} must be a marker interface 21.22 + 21.23 # 0: symbol kind, 1: message segment 21.24 compiler.err.invalid.mref=\ 21.25 invalid {0} reference; {1} 21.26 @@ -214,6 +219,12 @@ 21.27 compiler.misc.invalid.mref=\ 21.28 invalid {0} reference; {1} 21.29 21.30 +compiler.misc.static.mref.with.targs=\ 21.31 + parameterized qualifier on static method reference 21.32 + 21.33 +compiler.misc.static.bound.mref=\ 21.34 + static bound method reference 21.35 + 21.36 # 0: symbol 21.37 compiler.err.cant.assign.val.to.final.var=\ 21.38 cannot assign a value to final variable {0} 21.39 @@ -2196,6 +2207,11 @@ 21.40 default methods are not supported in -source {0}\n\ 21.41 (use -source 8 or higher to enable default methods) 21.42 21.43 +# 0: string 21.44 +compiler.err.intersection.types.in.cast.not.supported.in.source=\ 21.45 + intersection types in cast are not supported in -source {0}\n\ 21.46 + (use -source 8 or higher to enable default methods) 21.47 + 21.48 ######################################## 21.49 # Diagnostics for verbose resolution 21.50 # used by Resolve (debug only)
22.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu Dec 06 12:04:44 2012 -0800 22.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Dec 10 20:59:38 2012 -0800 22.3 @@ -254,6 +254,10 @@ 22.4 */ 22.5 TYPEUNION, 22.6 22.7 + /** Intersection types, of type TypeIntersection 22.8 + */ 22.9 + TYPEINTERSECTION, 22.10 + 22.11 /** Formal type parameters, of type TypeParameter. 22.12 */ 22.13 TYPEPARAMETER, 22.14 @@ -1829,8 +1833,6 @@ 22.15 STATIC(ReferenceMode.INVOKE, false), 22.16 /** Expr # instMethod */ 22.17 BOUND(ReferenceMode.INVOKE, false), 22.18 - /** Expr # staticMethod */ 22.19 - STATIC_EVAL(ReferenceMode.INVOKE, false), 22.20 /** Inner # new */ 22.21 IMPLICIT_INNER(ReferenceMode.NEW, false), 22.22 /** Toplevel # new */ 22.23 @@ -2064,6 +2066,34 @@ 22.24 } 22.25 22.26 /** 22.27 + * An intersection type, T1 & T2 & ... Tn (used in cast expressions) 22.28 + */ 22.29 + public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree { 22.30 + 22.31 + public List<JCExpression> bounds; 22.32 + 22.33 + protected JCTypeIntersection(List<JCExpression> bounds) { 22.34 + this.bounds = bounds; 22.35 + } 22.36 + @Override 22.37 + public void accept(Visitor v) { v.visitTypeIntersection(this); } 22.38 + 22.39 + public Kind getKind() { return Kind.INTERSECTION_TYPE; } 22.40 + 22.41 + public List<JCExpression> getBounds() { 22.42 + return bounds; 22.43 + } 22.44 + @Override 22.45 + public <R,D> R accept(TreeVisitor<R,D> v, D d) { 22.46 + return v.visitIntersectionType(this, d); 22.47 + } 22.48 + @Override 22.49 + public Tag getTag() { 22.50 + return TYPEINTERSECTION; 22.51 + } 22.52 + } 22.53 + 22.54 + /** 22.55 * A formal class parameter. 22.56 */ 22.57 public static class JCTypeParameter extends JCTree implements TypeParameterTree { 22.58 @@ -2385,6 +2415,7 @@ 22.59 public void visitTypeArray(JCArrayTypeTree that) { visitTree(that); } 22.60 public void visitTypeApply(JCTypeApply that) { visitTree(that); } 22.61 public void visitTypeUnion(JCTypeUnion that) { visitTree(that); } 22.62 + public void visitTypeIntersection(JCTypeIntersection that) { visitTree(that); } 22.63 public void visitTypeParameter(JCTypeParameter that) { visitTree(that); } 22.64 public void visitWildcard(JCWildcard that) { visitTree(that); } 22.65 public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); }
23.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java Thu Dec 06 12:04:44 2012 -0800 23.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java Mon Dec 10 20:59:38 2012 -0800 23.3 @@ -1249,6 +1249,14 @@ 23.4 } 23.5 } 23.6 23.7 + public void visitTypeIntersection(JCTypeIntersection tree) { 23.8 + try { 23.9 + printExprs(tree.bounds, " & "); 23.10 + } catch (IOException e) { 23.11 + throw new UncheckedIOException(e); 23.12 + } 23.13 + } 23.14 + 23.15 public void visitTypeParameter(JCTypeParameter tree) { 23.16 try { 23.17 print(tree.name);
24.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java Thu Dec 06 12:04:44 2012 -0800 24.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java Mon Dec 10 20:59:38 2012 -0800 24.3 @@ -358,6 +358,12 @@ 24.4 return M.at(t.pos).TypeUnion(components); 24.5 } 24.6 24.7 + public JCTree visitIntersectionType(IntersectionTypeTree node, P p) { 24.8 + JCTypeIntersection t = (JCTypeIntersection) node; 24.9 + List<JCExpression> bounds = copy(t.bounds, p); 24.10 + return M.at(t.pos).TypeIntersection(bounds); 24.11 + } 24.12 + 24.13 public JCTree visitArrayType(ArrayTypeTree node, P p) { 24.14 JCArrayTypeTree t = (JCArrayTypeTree) node; 24.15 JCExpression elemtype = copy(t.elemtype, p);
25.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Dec 06 12:04:44 2012 -0800 25.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon Dec 10 20:59:38 2012 -0800 25.3 @@ -267,6 +267,25 @@ 25.4 return lambda.params.isEmpty() || 25.5 lambda.params.head.vartype != null; 25.6 } 25.7 + 25.8 + /** Return true if the tree corresponds to an expression statement */ 25.9 + public static boolean isExpressionStatement(JCExpression tree) { 25.10 + switch(tree.getTag()) { 25.11 + case PREINC: case PREDEC: 25.12 + case POSTINC: case POSTDEC: 25.13 + case ASSIGN: 25.14 + case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG: 25.15 + case SL_ASG: case SR_ASG: case USR_ASG: 25.16 + case PLUS_ASG: case MINUS_ASG: 25.17 + case MUL_ASG: case DIV_ASG: case MOD_ASG: 25.18 + case APPLY: case NEWCLASS: 25.19 + case ERRONEOUS: 25.20 + return true; 25.21 + default: 25.22 + return false; 25.23 + } 25.24 + } 25.25 + 25.26 /** 25.27 * Return true if the AST corresponds to a static select of the kind A.B 25.28 */
26.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Thu Dec 06 12:04:44 2012 -0800 26.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Mon Dec 10 20:59:38 2012 -0800 26.3 @@ -456,6 +456,12 @@ 26.4 return tree; 26.5 } 26.6 26.7 + public JCTypeIntersection TypeIntersection(List<JCExpression> components) { 26.8 + JCTypeIntersection tree = new JCTypeIntersection(components); 26.9 + tree.pos = pos; 26.10 + return tree; 26.11 + } 26.12 + 26.13 public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds) { 26.14 JCTypeParameter tree = new JCTypeParameter(name, bounds); 26.15 tree.pos = pos;
27.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java Thu Dec 06 12:04:44 2012 -0800 27.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java Mon Dec 10 20:59:38 2012 -0800 27.3 @@ -286,6 +286,10 @@ 27.4 scan(tree.alternatives); 27.5 } 27.6 27.7 + public void visitTypeIntersection(JCTypeIntersection tree) { 27.8 + scan(tree.bounds); 27.9 + } 27.10 + 27.11 public void visitTypeParameter(JCTypeParameter tree) { 27.12 scan(tree.bounds); 27.13 }
28.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java Thu Dec 06 12:04:44 2012 -0800 28.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java Mon Dec 10 20:59:38 2012 -0800 28.3 @@ -379,6 +379,11 @@ 28.4 result = tree; 28.5 } 28.6 28.7 + public void visitTypeIntersection(JCTypeIntersection tree) { 28.8 + tree.bounds = translate(tree.bounds); 28.9 + result = tree; 28.10 + } 28.11 + 28.12 public void visitTypeParameter(JCTypeParameter tree) { 28.13 tree.bounds = translate(tree.bounds); 28.14 result = tree;
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/src/share/classes/javax/lang/model/type/IntersectionType.java Mon Dec 10 20:59:38 2012 -0800 29.3 @@ -0,0 +1,47 @@ 29.4 +/* 29.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. Oracle designates this 29.11 + * particular file as subject to the "Classpath" exception as provided 29.12 + * by Oracle in the LICENSE file that accompanied this code. 29.13 + * 29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.17 + * version 2 for more details (a copy is included in the LICENSE file that 29.18 + * accompanied this code). 29.19 + * 29.20 + * You should have received a copy of the GNU General Public License version 29.21 + * 2 along with this work; if not, write to the Free Software Foundation, 29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.23 + * 29.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.25 + * or visit www.oracle.com if you need additional information or have any 29.26 + * questions. 29.27 + */ 29.28 + 29.29 +package javax.lang.model.type; 29.30 + 29.31 +import java.util.List; 29.32 + 29.33 +/** 29.34 + * Represents an intersection type. 29.35 + * 29.36 + * As of the {@link javax.lang.model.SourceVersion#RELEASE_8 29.37 + * RELEASE_8} source version, intersection types can appear as the target type 29.38 + * of a cast expression. 29.39 + * 29.40 + * @since 1.8 29.41 + */ 29.42 +public interface IntersectionType extends TypeMirror { 29.43 + 29.44 + /** 29.45 + * Return the bounds comprising this intersection type. 29.46 + * 29.47 + * @return the bounds of this intersection types. 29.48 + */ 29.49 + List<? extends TypeMirror> getBounds(); 29.50 +}
30.1 --- a/src/share/classes/javax/lang/model/type/TypeKind.java Thu Dec 06 12:04:44 2012 -0800 30.2 +++ b/src/share/classes/javax/lang/model/type/TypeKind.java Mon Dec 10 20:59:38 2012 -0800 30.3 @@ -144,7 +144,14 @@ 30.4 * 30.5 * @since 1.7 30.6 */ 30.7 - UNION; 30.8 + UNION, 30.9 + 30.10 + /** 30.11 + * An intersection type. 30.12 + * 30.13 + * @since 1.8 30.14 + */ 30.15 + INTERSECTION; 30.16 30.17 /** 30.18 * Returns {@code true} if this kind corresponds to a primitive
31.1 --- a/src/share/classes/javax/lang/model/type/TypeVisitor.java Thu Dec 06 12:04:44 2012 -0800 31.2 +++ b/src/share/classes/javax/lang/model/type/TypeVisitor.java Mon Dec 10 20:59:38 2012 -0800 31.3 @@ -172,4 +172,14 @@ 31.4 * @since 1.7 31.5 */ 31.6 R visitUnion(UnionType t, P p); 31.7 + 31.8 + /** 31.9 + * Visits an intersection type. 31.10 + * 31.11 + * @param t the type to visit 31.12 + * @param p a visitor-specified parameter 31.13 + * @return a visitor-specified result 31.14 + * @since 1.8 31.15 + */ 31.16 + R visitIntersection(IntersectionType t, P p); 31.17 }
32.1 --- a/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Thu Dec 06 12:04:44 2012 -0800 32.2 +++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Mon Dec 10 20:59:38 2012 -0800 32.3 @@ -111,6 +111,20 @@ 32.4 } 32.5 32.6 /** 32.7 + * Visits an {@code IntersectionType} element by calling {@code 32.8 + * visitUnknown}. 32.9 + 32.10 + * @param t {@inheritDoc} 32.11 + * @param p {@inheritDoc} 32.12 + * @return the result of {@code visitUnknown} 32.13 + * 32.14 + * @since 1.8 32.15 + */ 32.16 + public R visitIntersection(IntersectionType t, P p) { 32.17 + return visitUnknown(t, p); 32.18 + } 32.19 + 32.20 + /** 32.21 * {@inheritDoc} 32.22 * 32.23 * <p> The default implementation of this method in {@code
33.1 --- a/src/share/classes/javax/lang/model/util/AbstractTypeVisitor8.java Thu Dec 06 12:04:44 2012 -0800 33.2 +++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor8.java Mon Dec 10 20:59:38 2012 -0800 33.3 @@ -66,4 +66,13 @@ 33.4 protected AbstractTypeVisitor8() { 33.5 super(); 33.6 } 33.7 + 33.8 + /** 33.9 + * Visits an {@code IntersectionType} in a manner defined by a subclass. 33.10 + * 33.11 + * @param t {@inheritDoc} 33.12 + * @param p {@inheritDoc} 33.13 + * @return the result of the visit as defined by a subclass 33.14 + */ 33.15 + public abstract R visitIntersection(IntersectionType t, P p); 33.16 }
34.1 --- a/src/share/classes/javax/tools/JavaCompiler.java Thu Dec 06 12:04:44 2012 -0800 34.2 +++ b/src/share/classes/javax/tools/JavaCompiler.java Mon Dec 10 20:59:38 2012 -0800 34.3 @@ -108,8 +108,8 @@ 34.4 * example a recommended coding pattern: 34.5 * 34.6 * <pre> 34.7 - * Files[] files1 = ... ; // input for first compilation task 34.8 - * Files[] files2 = ... ; // input for second compilation task 34.9 + * File[] files1 = ... ; // input for first compilation task 34.10 + * File[] files2 = ... ; // input for second compilation task 34.11 * 34.12 * JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 34.13 * StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); 34.14 @@ -165,7 +165,7 @@ 34.15 * JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 34.16 * StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null); 34.17 * JavaFileManager fileManager = new ForwardingJavaFileManager(stdFileManager) { 34.18 - * public void flush() { 34.19 + * public void flush() throws IOException { 34.20 * logger.entering(StandardJavaFileManager.class.getName(), "flush"); 34.21 * super.flush(); 34.22 * logger.exiting(StandardJavaFileManager.class.getName(), "flush");
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/7144981/IgnoreIgnorableCharactersInInput.java Mon Dec 10 20:59:38 2012 -0800 35.3 @@ -0,0 +1,92 @@ 35.4 + 35.5 +/* 35.6 + * @test /nodynamiccopyright/ 35.7 + * @bug 7144981 35.8 + * @summary javac should ignore ignorable characters in input 35.9 + * @run main IgnoreIgnorableCharactersInInput 35.10 + */ 35.11 + 35.12 +import com.sun.source.util.JavacTask; 35.13 +import java.io.File; 35.14 +import java.net.URI; 35.15 +import java.util.Arrays; 35.16 +import java.util.Set; 35.17 +import java.util.TreeSet; 35.18 +import javax.tools.JavaCompiler; 35.19 +import javax.tools.JavaFileObject; 35.20 +import javax.tools.SimpleJavaFileObject; 35.21 +import javax.tools.ToolProvider; 35.22 + 35.23 +public class IgnoreIgnorableCharactersInInput { 35.24 + 35.25 + public static void main(String... args) throws Exception { 35.26 + new IgnoreIgnorableCharactersInInput().run(); 35.27 + } 35.28 + 35.29 + void run() throws Exception { 35.30 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 35.31 + File classesDir = new File(System.getProperty("user.dir"), "classes"); 35.32 + classesDir.mkdirs(); 35.33 + JavaSource[] sources = new JavaSource[]{ 35.34 + new JavaSource("TestOneIgnorableChar", "AA\\u0000BB"), 35.35 + new JavaSource("TestMultipleIgnorableChar", "AA\\u0000\\u0000\\u0000BB")}; 35.36 + JavacTask ct = (JavacTask)comp.getTask(null, null, null, 35.37 + Arrays.asList("-d", classesDir.getPath()), 35.38 + null, Arrays.asList(sources)); 35.39 + try { 35.40 + if (!ct.call()) { 35.41 + throw new AssertionError("Error thrown when compiling test cases"); 35.42 + } 35.43 + } catch (Throwable ex) { 35.44 + throw new AssertionError("Error thrown when compiling test cases"); 35.45 + } 35.46 + check(classesDir, 35.47 + "TestOneIgnorableChar.class", 35.48 + "TestOneIgnorableChar$AABB.class", 35.49 + "TestMultipleIgnorableChar.class", 35.50 + "TestMultipleIgnorableChar$AABB.class"); 35.51 + if (errors > 0) 35.52 + throw new AssertionError("There are some errors in the test check the error output"); 35.53 + } 35.54 + 35.55 + /** 35.56 + * Check that a directory contains the expected files. 35.57 + */ 35.58 + void check(File dir, String... paths) { 35.59 + Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); 35.60 + Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); 35.61 + if (found.equals(expect)) 35.62 + return; 35.63 + for (String f: found) { 35.64 + if (!expect.contains(f)) 35.65 + error("Unexpected file found: " + f); 35.66 + } 35.67 + for (String e: expect) { 35.68 + if (!found.contains(e)) 35.69 + error("Expected file not found: " + e); 35.70 + } 35.71 + } 35.72 + 35.73 + int errors; 35.74 + 35.75 + void error(String msg) { 35.76 + System.err.println(msg); 35.77 + errors++; 35.78 + } 35.79 + 35.80 + class JavaSource extends SimpleJavaFileObject { 35.81 + 35.82 + String internalSource = 35.83 + "public class #O {public class #I {} }"; 35.84 + public JavaSource(String outerClassName, String innerClassName) { 35.85 + super(URI.create(outerClassName + ".java"), JavaFileObject.Kind.SOURCE); 35.86 + internalSource = 35.87 + internalSource.replace("#O", outerClassName).replace("#I", innerClassName); 35.88 + } 35.89 + 35.90 + @Override 35.91 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 35.92 + return internalSource; 35.93 + } 35.94 + } 35.95 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Mon Dec 10 20:59:38 2012 -0800 36.3 @@ -0,0 +1,134 @@ 36.4 +/* 36.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. Oracle designates this 36.11 + * particular file as subject to the "Classpath" exception as provided 36.12 + * by Oracle in the LICENSE file that accompanied this code. 36.13 + * 36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.17 + * version 2 for more details (a copy is included in the LICENSE file that 36.18 + * accompanied this code). 36.19 + * 36.20 + * You should have received a copy of the GNU General Public License version 36.21 + * 2 along with this work; if not, write to the Free Software Foundation, 36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.23 + * 36.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 36.25 + * or visit www.oracle.com if you need additional information or have any 36.26 + * questions. 36.27 + */ 36.28 + 36.29 +/* 36.30 + * @test 36.31 + * @bug 7153958 36.32 + * @summary add constant pool reference to class containing inlined constants 36.33 + * @compile pkg/ClassToBeStaticallyImported.java 36.34 + * @run main CPoolRefClassContainingInlinedCts 36.35 + */ 36.36 + 36.37 +import com.sun.tools.classfile.ClassFile; 36.38 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; 36.39 +import com.sun.tools.classfile.ConstantPool.CPInfo; 36.40 +import com.sun.tools.classfile.ConstantPoolException; 36.41 +import java.io.File; 36.42 +import java.io.IOException; 36.43 + 36.44 +import static pkg.ClassToBeStaticallyImported.staticField; 36.45 + 36.46 +public class CPoolRefClassContainingInlinedCts { 36.47 + 36.48 + public static void main(String args[]) throws Exception { 36.49 + new CPoolRefClassContainingInlinedCts().run(); 36.50 + } 36.51 + 36.52 + void run() throws Exception { 36.53 + checkReferences(); 36.54 + } 36.55 + 36.56 + int numberOfReferencedClassesToBeChecked = 0; 36.57 + 36.58 + void checkClassName(String className) { 36.59 + switch (className) { 36.60 + case "SimpleAssignClass" : case "BinaryExpClass": 36.61 + case "UnaryExpClass" : case "CastClass": 36.62 + case "ParensClass" : case "CondClass": 36.63 + case "IfClass" : case "pkg/ClassToBeStaticallyImported": 36.64 + numberOfReferencedClassesToBeChecked++; 36.65 + } 36.66 + } 36.67 + 36.68 + void checkReferences() throws IOException, ConstantPoolException { 36.69 + File testClasses = new File(System.getProperty("test.classes")); 36.70 + File file = new File(testClasses, 36.71 + CPoolRefClassContainingInlinedCts.class.getName() + ".class"); 36.72 + ClassFile classFile = ClassFile.read(file); 36.73 + int i = 1; 36.74 + CPInfo cpInfo; 36.75 + while (i < classFile.constant_pool.size()) { 36.76 + cpInfo = classFile.constant_pool.get(i); 36.77 + if (cpInfo instanceof CONSTANT_Class_info) { 36.78 + checkClassName(((CONSTANT_Class_info)cpInfo).getName()); 36.79 + } 36.80 + i += cpInfo.size(); 36.81 + } 36.82 + if (numberOfReferencedClassesToBeChecked != 8) { 36.83 + throw new AssertionError("Class reference missing in the constant pool"); 36.84 + } 36.85 + } 36.86 + 36.87 + private int assign = SimpleAssignClass.x; 36.88 + private int binary = BinaryExpClass.x + 1; 36.89 + private int unary = -UnaryExpClass.x; 36.90 + private int cast = (int)CastClass.x; 36.91 + private int parens = (ParensClass.x); 36.92 + private int cond = (CondClass.x == 1) ? 1 : 2; 36.93 + private static int ifConstant; 36.94 + private static int importStatic; 36.95 + static { 36.96 + if (IfClass.x == 1) { 36.97 + ifConstant = 1; 36.98 + } else { 36.99 + ifConstant = 2; 36.100 + } 36.101 + } 36.102 + static { 36.103 + if (staticField == 1) { 36.104 + importStatic = 1; 36.105 + } else { 36.106 + importStatic = 2; 36.107 + } 36.108 + } 36.109 +} 36.110 + 36.111 +class SimpleAssignClass { 36.112 + public static final int x = 1; 36.113 +} 36.114 + 36.115 +class BinaryExpClass { 36.116 + public static final int x = 1; 36.117 +} 36.118 + 36.119 +class UnaryExpClass { 36.120 + public static final int x = 1; 36.121 +} 36.122 + 36.123 +class CastClass { 36.124 + public static final int x = 1; 36.125 +} 36.126 + 36.127 +class ParensClass { 36.128 + public static final int x = 1; 36.129 +} 36.130 + 36.131 +class CondClass { 36.132 + public static final int x = 1; 36.133 +} 36.134 + 36.135 +class IfClass { 36.136 + public static final int x = 1; 36.137 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java Mon Dec 10 20:59:38 2012 -0800 37.3 @@ -0,0 +1,29 @@ 37.4 +/* 37.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 + * 37.8 + * This code is free software; you can redistribute it and/or modify it 37.9 + * under the terms of the GNU General Public License version 2 only, as 37.10 + * published by the Free Software Foundation. Oracle designates this 37.11 + * particular file as subject to the "Classpath" exception as provided 37.12 + * by Oracle in the LICENSE file that accompanied this code. 37.13 + * 37.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 37.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.17 + * version 2 for more details (a copy is included in the LICENSE file that 37.18 + * accompanied this code). 37.19 + * 37.20 + * You should have received a copy of the GNU General Public License version 37.21 + * 2 along with this work; if not, write to the Free Software Foundation, 37.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.23 + * 37.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 37.25 + * or visit www.oracle.com if you need additional information or have any 37.26 + * questions. 37.27 + */ 37.28 +package pkg; 37.29 + 37.30 +public class ClassToBeStaticallyImported { 37.31 + public static final int staticField = 1; 37.32 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/tools/javac/cast/intersection/IntersectionTypeCastTest.java Mon Dec 10 20:59:38 2012 -0800 38.3 @@ -0,0 +1,330 @@ 38.4 +/* 38.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +/* 38.28 + * @test 38.29 + * @bug 8002099 38.30 + * @summary Add support for intersection types in cast expression 38.31 + */ 38.32 + 38.33 +import com.sun.source.util.JavacTask; 38.34 +import com.sun.tools.javac.util.List; 38.35 +import com.sun.tools.javac.util.ListBuffer; 38.36 +import java.net.URI; 38.37 +import java.util.Arrays; 38.38 +import javax.tools.Diagnostic; 38.39 +import javax.tools.JavaCompiler; 38.40 +import javax.tools.JavaFileObject; 38.41 +import javax.tools.SimpleJavaFileObject; 38.42 +import javax.tools.StandardJavaFileManager; 38.43 +import javax.tools.ToolProvider; 38.44 + 38.45 +public class IntersectionTypeCastTest { 38.46 + 38.47 + static int checkCount = 0; 38.48 + 38.49 + interface Type { 38.50 + boolean subtypeOf(Type that); 38.51 + String asString(); 38.52 + boolean isClass(); 38.53 + boolean isInterface(); 38.54 + } 38.55 + 38.56 + enum InterfaceKind implements Type { 38.57 + A("interface A { }\n", "A", null), 38.58 + B("interface B { }\n", "B", null), 38.59 + C("interface C extends A { }\n", "C", A); 38.60 + 38.61 + String declStr; 38.62 + String typeStr; 38.63 + InterfaceKind superInterface; 38.64 + 38.65 + InterfaceKind(String declStr, String typeStr, InterfaceKind superInterface) { 38.66 + this.declStr = declStr; 38.67 + this.typeStr = typeStr; 38.68 + this.superInterface = superInterface; 38.69 + } 38.70 + 38.71 + @Override 38.72 + public boolean subtypeOf(Type that) { 38.73 + return this == that || superInterface == that || that == ClassKind.OBJECT; 38.74 + } 38.75 + 38.76 + @Override 38.77 + public String asString() { 38.78 + return typeStr; 38.79 + } 38.80 + 38.81 + @Override 38.82 + public boolean isClass() { 38.83 + return false; 38.84 + } 38.85 + 38.86 + @Override 38.87 + public boolean isInterface() { 38.88 + return true; 38.89 + } 38.90 + } 38.91 + 38.92 + enum ClassKind implements Type { 38.93 + OBJECT(null, "Object"), 38.94 + CA("#M class CA implements A { }\n", "CA", InterfaceKind.A), 38.95 + CB("#M class CB implements B { }\n", "CB", InterfaceKind.B), 38.96 + CAB("#M class CAB implements A, B { }\n", "CAB", InterfaceKind.A, InterfaceKind.B), 38.97 + CC("#M class CC implements C { }\n", "CC", InterfaceKind.C, InterfaceKind.A), 38.98 + CCA("#M class CCA implements C, A { }\n", "CCA", InterfaceKind.C, InterfaceKind.A), 38.99 + CCB("#M class CCB implements C, B { }\n", "CCB", InterfaceKind.C, InterfaceKind.A, InterfaceKind.B), 38.100 + CCAB("#M class CCAB implements C, A, B { }\n", "CCAB", InterfaceKind.C, InterfaceKind.A, InterfaceKind.B); 38.101 + 38.102 + String declTemplate; 38.103 + String typeStr; 38.104 + List<InterfaceKind> superInterfaces; 38.105 + 38.106 + ClassKind(String declTemplate, String typeStr, InterfaceKind... superInterfaces) { 38.107 + this.declTemplate = declTemplate; 38.108 + this.typeStr = typeStr; 38.109 + this.superInterfaces = List.from(superInterfaces); 38.110 + } 38.111 + 38.112 + String getDecl(ModifierKind mod) { 38.113 + return declTemplate != null ? 38.114 + declTemplate.replaceAll("#M", mod.modStr) : 38.115 + ""; 38.116 + } 38.117 + 38.118 + @Override 38.119 + public boolean subtypeOf(Type that) { 38.120 + return this == that || superInterfaces.contains(that) || that == OBJECT; 38.121 + } 38.122 + 38.123 + @Override 38.124 + public String asString() { 38.125 + return typeStr; 38.126 + } 38.127 + 38.128 + @Override 38.129 + public boolean isClass() { 38.130 + return true; 38.131 + } 38.132 + 38.133 + @Override 38.134 + public boolean isInterface() { 38.135 + return false; 38.136 + } 38.137 + } 38.138 + 38.139 + enum ModifierKind { 38.140 + NONE(""), 38.141 + FINAL("final"); 38.142 + 38.143 + String modStr; 38.144 + 38.145 + ModifierKind(String modStr) { 38.146 + this.modStr = modStr; 38.147 + } 38.148 + } 38.149 + 38.150 + enum CastKind { 38.151 + CLASS("(#C)", 0), 38.152 + INTERFACE("(#I0)", 1), 38.153 + INTERSECTION2("(#C & #I0)", 1), 38.154 + INTERSECTION3("(#C & #I0 & #I1)", 2); 38.155 + //INTERSECTION4("(#C & #I0 & #I1 & #I2)", 3); 38.156 + 38.157 + String castTemplate; 38.158 + int interfaceBounds; 38.159 + 38.160 + CastKind(String castTemplate, int interfaceBounds) { 38.161 + this.castTemplate = castTemplate; 38.162 + this.interfaceBounds = interfaceBounds; 38.163 + } 38.164 + } 38.165 + 38.166 + static class CastInfo { 38.167 + CastKind kind; 38.168 + Type[] types; 38.169 + 38.170 + CastInfo(CastKind kind, Type... types) { 38.171 + this.kind = kind; 38.172 + this.types = types; 38.173 + } 38.174 + 38.175 + String getCast() { 38.176 + String temp = kind.castTemplate.replaceAll("#C", types[0].asString()); 38.177 + for (int i = 0; i < kind.interfaceBounds ; i++) { 38.178 + temp = temp.replace(String.format("#I%d", i), types[i + 1].asString()); 38.179 + } 38.180 + return temp; 38.181 + } 38.182 + 38.183 + boolean hasDuplicateTypes() { 38.184 + for (int i = 0 ; i < types.length ; i++) { 38.185 + for (int j = 0 ; j < types.length ; j++) { 38.186 + if (i != j && types[i] == types[j]) { 38.187 + return true; 38.188 + } 38.189 + } 38.190 + } 38.191 + return false; 38.192 + } 38.193 + 38.194 + boolean compatibleWith(ModifierKind mod, CastInfo that) { 38.195 + for (Type t1 : types) { 38.196 + for (Type t2 : that.types) { 38.197 + boolean compat = 38.198 + t1.subtypeOf(t2) || 38.199 + t2.subtypeOf(t1) || 38.200 + (t1.isInterface() && t2.isInterface()) || //side-cast (1) 38.201 + (mod == ModifierKind.NONE && (t1.isInterface() != t2.isInterface())); //side-cast (2) 38.202 + if (!compat) return false; 38.203 + } 38.204 + } 38.205 + return true; 38.206 + } 38.207 + } 38.208 + 38.209 + public static void main(String... args) throws Exception { 38.210 + //create default shared JavaCompiler - reused across multiple compilations 38.211 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 38.212 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 38.213 + 38.214 + for (ModifierKind mod : ModifierKind.values()) { 38.215 + for (CastInfo cast1 : allCastInfo()) { 38.216 + for (CastInfo cast2 : allCastInfo()) { 38.217 + new IntersectionTypeCastTest(mod, cast1, cast2).run(comp, fm); 38.218 + } 38.219 + } 38.220 + } 38.221 + System.out.println("Total check executed: " + checkCount); 38.222 + } 38.223 + 38.224 + static List<CastInfo> allCastInfo() { 38.225 + ListBuffer<CastInfo> buf = ListBuffer.lb(); 38.226 + for (CastKind kind : CastKind.values()) { 38.227 + for (ClassKind clazz : ClassKind.values()) { 38.228 + if (kind == CastKind.INTERFACE && clazz != ClassKind.OBJECT) { 38.229 + continue; 38.230 + } else if (kind.interfaceBounds == 0) { 38.231 + buf.append(new CastInfo(kind, clazz)); 38.232 + continue; 38.233 + } else { 38.234 + for (InterfaceKind intf1 : InterfaceKind.values()) { 38.235 + if (kind.interfaceBounds == 1) { 38.236 + buf.append(new CastInfo(kind, clazz, intf1)); 38.237 + continue; 38.238 + } else { 38.239 + for (InterfaceKind intf2 : InterfaceKind.values()) { 38.240 + if (kind.interfaceBounds == 2) { 38.241 + buf.append(new CastInfo(kind, clazz, intf1, intf2)); 38.242 + continue; 38.243 + } else { 38.244 + for (InterfaceKind intf3 : InterfaceKind.values()) { 38.245 + buf.append(new CastInfo(kind, clazz, intf1, intf2, intf3)); 38.246 + continue; 38.247 + } 38.248 + } 38.249 + } 38.250 + } 38.251 + } 38.252 + } 38.253 + } 38.254 + } 38.255 + return buf.toList(); 38.256 + } 38.257 + 38.258 + ModifierKind mod; 38.259 + CastInfo cast1, cast2; 38.260 + JavaSource source; 38.261 + DiagnosticChecker diagChecker; 38.262 + 38.263 + IntersectionTypeCastTest(ModifierKind mod, CastInfo cast1, CastInfo cast2) { 38.264 + this.mod = mod; 38.265 + this.cast1 = cast1; 38.266 + this.cast2 = cast2; 38.267 + this.source = new JavaSource(); 38.268 + this.diagChecker = new DiagnosticChecker(); 38.269 + } 38.270 + 38.271 + class JavaSource extends SimpleJavaFileObject { 38.272 + 38.273 + String bodyTemplate = "class Test {\n" + 38.274 + " void test() {\n" + 38.275 + " Object o = #C1#C2null;\n" + 38.276 + " } }"; 38.277 + 38.278 + String source = ""; 38.279 + 38.280 + public JavaSource() { 38.281 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 38.282 + for (ClassKind ck : ClassKind.values()) { 38.283 + source += ck.getDecl(mod); 38.284 + } 38.285 + for (InterfaceKind ik : InterfaceKind.values()) { 38.286 + source += ik.declStr; 38.287 + } 38.288 + source += bodyTemplate.replaceAll("#C1", cast1.getCast()).replaceAll("#C2", cast2.getCast()); 38.289 + } 38.290 + 38.291 + @Override 38.292 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 38.293 + return source; 38.294 + } 38.295 + } 38.296 + 38.297 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 38.298 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 38.299 + Arrays.asList("-XDallowIntersectionTypes"), null, Arrays.asList(source)); 38.300 + try { 38.301 + ct.analyze(); 38.302 + } catch (Throwable ex) { 38.303 + throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true)); 38.304 + } 38.305 + check(); 38.306 + } 38.307 + 38.308 + void check() { 38.309 + checkCount++; 38.310 + 38.311 + boolean errorExpected = cast1.hasDuplicateTypes() || cast2.hasDuplicateTypes(); 38.312 + 38.313 + errorExpected |= !cast2.compatibleWith(mod, cast1); 38.314 + 38.315 + if (errorExpected != diagChecker.errorFound) { 38.316 + throw new Error("invalid diagnostics for source:\n" + 38.317 + source.getCharContent(true) + 38.318 + "\nFound error: " + diagChecker.errorFound + 38.319 + "\nExpected error: " + errorExpected); 38.320 + } 38.321 + } 38.322 + 38.323 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 38.324 + 38.325 + boolean errorFound; 38.326 + 38.327 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 38.328 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 38.329 + errorFound = true; 38.330 + } 38.331 + } 38.332 + } 38.333 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javac/cast/intersection/IntersectionTypeParserTest.java Mon Dec 10 20:59:38 2012 -0800 39.3 @@ -0,0 +1,191 @@ 39.4 +/* 39.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. 39.11 + * 39.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.15 + * version 2 for more details (a copy is included in the LICENSE file that 39.16 + * accompanied this code). 39.17 + * 39.18 + * You should have received a copy of the GNU General Public License version 39.19 + * 2 along with this work; if not, write to the Free Software Foundation, 39.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.21 + * 39.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.23 + * or visit www.oracle.com if you need additional information or have any 39.24 + * questions. 39.25 + */ 39.26 + 39.27 +/* 39.28 + * @test 39.29 + * @bug 8002099 39.30 + * @summary Add support for intersection types in cast expression 39.31 + */ 39.32 + 39.33 +import com.sun.source.util.JavacTask; 39.34 +import java.net.URI; 39.35 +import java.util.Arrays; 39.36 +import javax.tools.Diagnostic; 39.37 +import javax.tools.JavaCompiler; 39.38 +import javax.tools.JavaFileObject; 39.39 +import javax.tools.SimpleJavaFileObject; 39.40 +import javax.tools.StandardJavaFileManager; 39.41 +import javax.tools.ToolProvider; 39.42 + 39.43 +public class IntersectionTypeParserTest { 39.44 + 39.45 + static int checkCount = 0; 39.46 + 39.47 + enum TypeKind { 39.48 + SIMPLE("A"), 39.49 + GENERIC("A<X>"), 39.50 + WILDCARD("A<? super X, ? extends Y>"); 39.51 + 39.52 + String typeStr; 39.53 + 39.54 + TypeKind(String typeStr) { 39.55 + this.typeStr = typeStr; 39.56 + } 39.57 + } 39.58 + 39.59 + enum ArrayKind { 39.60 + NONE(""), 39.61 + SINGLE("[]"), 39.62 + DOUBLE("[][]"); 39.63 + 39.64 + String arrStr; 39.65 + 39.66 + ArrayKind(String arrStr) { 39.67 + this.arrStr = arrStr; 39.68 + } 39.69 + } 39.70 + 39.71 + static class Type { 39.72 + TypeKind tk; 39.73 + ArrayKind ak; 39.74 + 39.75 + Type(TypeKind tk, ArrayKind ak) { 39.76 + this.tk = tk; 39.77 + this.ak = ak; 39.78 + } 39.79 + 39.80 + String asString() { 39.81 + return tk.typeStr + ak.arrStr; 39.82 + } 39.83 + } 39.84 + 39.85 + enum CastKind { 39.86 + ONE("(#T0)", 1), 39.87 + TWO("(#T0 & T1)", 2), 39.88 + THREE("(#T0 & #T1 & #T2)", 3); 39.89 + 39.90 + String castTemplate; 39.91 + int nBounds; 39.92 + 39.93 + CastKind(String castTemplate, int nBounds) { 39.94 + this.castTemplate = castTemplate; 39.95 + this.nBounds = nBounds; 39.96 + } 39.97 + 39.98 + String asString(Type... types) { 39.99 + String res = castTemplate; 39.100 + for (int i = 0; i < nBounds ; i++) { 39.101 + res = res.replaceAll(String.format("#T%d", i), types[i].asString()); 39.102 + } 39.103 + return res; 39.104 + } 39.105 + } 39.106 + 39.107 + public static void main(String... args) throws Exception { 39.108 + //create default shared JavaCompiler - reused across multiple compilations 39.109 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 39.110 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 39.111 + 39.112 + for (CastKind ck : CastKind.values()) { 39.113 + for (TypeKind t1 : TypeKind.values()) { 39.114 + for (ArrayKind ak1 : ArrayKind.values()) { 39.115 + Type typ1 = new Type(t1, ak1); 39.116 + if (ck.nBounds == 1) { 39.117 + new IntersectionTypeParserTest(ck, typ1).run(comp, fm); 39.118 + continue; 39.119 + } 39.120 + for (TypeKind t2 : TypeKind.values()) { 39.121 + for (ArrayKind ak2 : ArrayKind.values()) { 39.122 + Type typ2 = new Type(t2, ak2); 39.123 + if (ck.nBounds == 2) { 39.124 + new IntersectionTypeParserTest(ck, typ1, typ2).run(comp, fm); 39.125 + continue; 39.126 + } 39.127 + for (TypeKind t3 : TypeKind.values()) { 39.128 + for (ArrayKind ak3 : ArrayKind.values()) { 39.129 + Type typ3 = new Type(t3, ak3); 39.130 + new IntersectionTypeParserTest(ck, typ1, typ2, typ3).run(comp, fm); 39.131 + } 39.132 + } 39.133 + } 39.134 + } 39.135 + } 39.136 + } 39.137 + } 39.138 + System.out.println("Total check executed: " + checkCount); 39.139 + } 39.140 + 39.141 + CastKind ck; 39.142 + Type[] types; 39.143 + JavaSource source; 39.144 + DiagnosticChecker diagChecker; 39.145 + 39.146 + IntersectionTypeParserTest(CastKind ck, Type... types) { 39.147 + this.ck = ck; 39.148 + this.types = types; 39.149 + this.source = new JavaSource(); 39.150 + this.diagChecker = new DiagnosticChecker(); 39.151 + } 39.152 + 39.153 + class JavaSource extends SimpleJavaFileObject { 39.154 + 39.155 + String bodyTemplate = "class Test {\n" + 39.156 + " void test() {\n" + 39.157 + " Object o = #Cnull;\n" + 39.158 + " } }"; 39.159 + 39.160 + String source = ""; 39.161 + 39.162 + public JavaSource() { 39.163 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 39.164 + source += bodyTemplate.replaceAll("#C", ck.asString(types)); 39.165 + } 39.166 + 39.167 + @Override 39.168 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 39.169 + return source; 39.170 + } 39.171 + } 39.172 + 39.173 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 39.174 + checkCount++; 39.175 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 39.176 + Arrays.asList("-XDallowIntersectionTypes"), null, Arrays.asList(source)); 39.177 + ct.parse(); 39.178 + if (diagChecker.errorFound) { 39.179 + throw new Error("Unexpected parser error for source:\n" + 39.180 + source.getCharContent(true)); 39.181 + } 39.182 + } 39.183 + 39.184 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 39.185 + 39.186 + boolean errorFound; 39.187 + 39.188 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 39.189 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 39.190 + errorFound = true; 39.191 + } 39.192 + } 39.193 + } 39.194 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/tools/javac/cast/intersection/model/Check.java Mon Dec 10 20:59:38 2012 -0800 40.3 @@ -0,0 +1,27 @@ 40.4 +/* 40.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. 40.11 + * 40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.15 + * version 2 for more details (a copy is included in the LICENSE file that 40.16 + * accompanied this code). 40.17 + * 40.18 + * You should have received a copy of the GNU General Public License version 40.19 + * 2 along with this work; if not, write to the Free Software Foundation, 40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.21 + * 40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.23 + * or visit www.oracle.com if you need additional information or have any 40.24 + * questions. 40.25 + */ 40.26 + 40.27 +/** 40.28 + * Annotation used by ModelChecker to mark the class whose model is to be checked 40.29 + */ 40.30 +@interface Check {}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/tools/javac/cast/intersection/model/IntersectionTypeInfo.java Mon Dec 10 20:59:38 2012 -0800 41.3 @@ -0,0 +1,29 @@ 41.4 +/* 41.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. 41.11 + * 41.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.15 + * version 2 for more details (a copy is included in the LICENSE file that 41.16 + * accompanied this code). 41.17 + * 41.18 + * You should have received a copy of the GNU General Public License version 41.19 + * 2 along with this work; if not, write to the Free Software Foundation, 41.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.21 + * 41.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 41.23 + * or visit www.oracle.com if you need additional information or have any 41.24 + * questions. 41.25 + */ 41.26 + 41.27 +/** 41.28 + * Used by ModelChecker to validate the modeling information of a union type. 41.29 + */ 41.30 +@interface IntersectionTypeInfo { 41.31 + String[] value(); 41.32 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/tools/javac/cast/intersection/model/Member.java Mon Dec 10 20:59:38 2012 -0800 42.3 @@ -0,0 +1,31 @@ 42.4 +/* 42.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42.7 + * 42.8 + * This code is free software; you can redistribute it and/or modify it 42.9 + * under the terms of the GNU General Public License version 2 only, as 42.10 + * published by the Free Software Foundation. 42.11 + * 42.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 42.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 42.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 42.15 + * version 2 for more details (a copy is included in the LICENSE file that 42.16 + * accompanied this code). 42.17 + * 42.18 + * You should have received a copy of the GNU General Public License version 42.19 + * 2 along with this work; if not, write to the Free Software Foundation, 42.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 42.21 + * 42.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 42.23 + * or visit www.oracle.com if you need additional information or have any 42.24 + * questions. 42.25 + */ 42.26 + 42.27 +import javax.lang.model.element.ElementKind; 42.28 + 42.29 +/** 42.30 + * Annotation used by ModelChecker to mark a member that is to be checked 42.31 + */ 42.32 +@interface Member { 42.33 + ElementKind value(); 42.34 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/tools/javac/cast/intersection/model/Model01.java Mon Dec 10 20:59:38 2012 -0800 43.3 @@ -0,0 +1,52 @@ 43.4 +/* 43.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43.7 + * 43.8 + * This code is free software; you can redistribute it and/or modify it 43.9 + * under the terms of the GNU General Public License version 2 only, as 43.10 + * published by the Free Software Foundation. 43.11 + * 43.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 43.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 43.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 43.15 + * version 2 for more details (a copy is included in the LICENSE file that 43.16 + * accompanied this code). 43.17 + * 43.18 + * You should have received a copy of the GNU General Public License version 43.19 + * 2 along with this work; if not, write to the Free Software Foundation, 43.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 43.21 + * 43.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 43.23 + * or visit www.oracle.com if you need additional information or have any 43.24 + * questions. 43.25 + */ 43.26 + 43.27 +/* 43.28 + * @test 43.29 + * @bug 8002099 43.30 + * @summary Add support for intersection types in cast expression 43.31 + * @library ../../../lib 43.32 + * @build JavacTestingAbstractProcessor ModelChecker 43.33 + * @compile -XDallowIntersectionTypes -processor ModelChecker Model01.java 43.34 + */ 43.35 + 43.36 +import javax.lang.model.element.ElementKind; 43.37 + 43.38 +@Check 43.39 +class Test { 43.40 + 43.41 + interface A { 43.42 + @Member(ElementKind.METHOD) 43.43 + public void m1(); 43.44 + } 43.45 + 43.46 + interface B { 43.47 + @Member(ElementKind.METHOD) 43.48 + public void m2(); 43.49 + } 43.50 + 43.51 + void test(){ 43.52 + @IntersectionTypeInfo({"java.lang.Object", "Test.A", "Test.B"}) 43.53 + Object o = (A & B)null; 43.54 + } 43.55 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/tools/javac/cast/intersection/model/ModelChecker.java Mon Dec 10 20:59:38 2012 -0800 44.3 @@ -0,0 +1,153 @@ 44.4 +/* 44.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. 44.11 + * 44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.15 + * version 2 for more details (a copy is included in the LICENSE file that 44.16 + * accompanied this code). 44.17 + * 44.18 + * You should have received a copy of the GNU General Public License version 44.19 + * 2 along with this work; if not, write to the Free Software Foundation, 44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.21 + * 44.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 44.23 + * or visit www.oracle.com if you need additional information or have any 44.24 + * questions. 44.25 + */ 44.26 + 44.27 +import com.sun.source.tree.ExpressionTree; 44.28 +import com.sun.source.tree.Tree; 44.29 +import com.sun.source.tree.TypeCastTree; 44.30 +import com.sun.source.tree.VariableTree; 44.31 +import com.sun.source.util.TreePathScanner; 44.32 +import com.sun.source.util.Trees; 44.33 +import com.sun.source.util.TreePath; 44.34 +import com.sun.tools.javac.tree.JCTree.JCExpression; 44.35 + 44.36 +import java.util.Set; 44.37 + 44.38 +import javax.annotation.processing.RoundEnvironment; 44.39 +import javax.annotation.processing.SupportedAnnotationTypes; 44.40 +import javax.lang.model.element.Element; 44.41 +import javax.lang.model.element.TypeElement; 44.42 +import javax.lang.model.type.TypeMirror; 44.43 +import javax.lang.model.type.TypeKind; 44.44 +import javax.lang.model.type.IntersectionType; 44.45 +import javax.lang.model.type.UnknownTypeException; 44.46 +import javax.lang.model.util.SimpleTypeVisitor6; 44.47 +import javax.lang.model.util.SimpleTypeVisitor7; 44.48 + 44.49 +@SupportedAnnotationTypes("Check") 44.50 +public class ModelChecker extends JavacTestingAbstractProcessor { 44.51 + 44.52 + @Override 44.53 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 44.54 + if (roundEnv.processingOver()) 44.55 + return true; 44.56 + 44.57 + Trees trees = Trees.instance(processingEnv); 44.58 + 44.59 + TypeElement testAnno = elements.getTypeElement("Check"); 44.60 + for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) { 44.61 + TreePath p = trees.getPath(elem); 44.62 + new IntersectionCastTester(trees).scan(p, null); 44.63 + } 44.64 + return true; 44.65 + } 44.66 + 44.67 + class IntersectionCastTester extends TreePathScanner<Void, Void> { 44.68 + Trees trees; 44.69 + 44.70 + public IntersectionCastTester(Trees trees) { 44.71 + super(); 44.72 + this.trees = trees; 44.73 + } 44.74 + 44.75 + @Override 44.76 + public Void visitVariable(VariableTree node, Void p) { 44.77 + 44.78 + TreePath varPath = new TreePath(getCurrentPath(), node); 44.79 + Element v = trees.getElement(varPath); 44.80 + 44.81 + IntersectionTypeInfo it = v.getAnnotation(IntersectionTypeInfo.class); 44.82 + assertTrue(it != null, "IntersectionType annotation must be present"); 44.83 + 44.84 + ExpressionTree varInit = node.getInitializer(); 44.85 + assertTrue(varInit != null && varInit.getKind() == Tree.Kind.TYPE_CAST, 44.86 + "variable must have be initialized to an expression containing an intersection type cast"); 44.87 + 44.88 + TypeMirror t = ((JCExpression)((TypeCastTree)varInit).getType()).type; 44.89 + 44.90 + validateIntersectionTypeInfo(t, it); 44.91 + 44.92 + for (Element e2 : types.asElement(t).getEnclosedElements()) { 44.93 + assertTrue(false, "an intersection type has no declared members"); 44.94 + } 44.95 + 44.96 + for (Element e2 : elements.getAllMembers((TypeElement)types.asElement(t))) { 44.97 + Member m = e2.getAnnotation(Member.class); 44.98 + if (m != null) { 44.99 + assertTrue(e2.getKind() == m.value(), "Expected " + m.value() + " - found " + e2.getKind()); 44.100 + } 44.101 + } 44.102 + 44.103 + assertTrue(assertionCount == 10, "Expected 10 assertions - found " + assertionCount); 44.104 + return super.visitVariable(node, p); 44.105 + } 44.106 + } 44.107 + 44.108 + private void validateIntersectionTypeInfo(TypeMirror expectedIntersectionType, IntersectionTypeInfo it) { 44.109 + 44.110 + assertTrue(expectedIntersectionType.getKind() == TypeKind.INTERSECTION, "INTERSECTION kind expected"); 44.111 + 44.112 + try { 44.113 + new SimpleTypeVisitor6<Void, Void>(){}.visit(expectedIntersectionType); 44.114 + throw new RuntimeException("Expected UnknownTypeException not thrown."); 44.115 + } catch (UnknownTypeException ute) { 44.116 + ; // Expected 44.117 + } 44.118 + 44.119 + try { 44.120 + new SimpleTypeVisitor7<Void, Void>(){}.visit(expectedIntersectionType); 44.121 + throw new RuntimeException("Expected UnknownTypeException not thrown."); 44.122 + } catch (UnknownTypeException ute) { 44.123 + ; // Expected 44.124 + } 44.125 + 44.126 + IntersectionType intersectionType = new SimpleTypeVisitor<IntersectionType, Void>(){ 44.127 + @Override 44.128 + protected IntersectionType defaultAction(TypeMirror e, Void p) {return null;} 44.129 + 44.130 + @Override 44.131 + public IntersectionType visitIntersection(IntersectionType t, Void p) {return t;} 44.132 + }.visit(expectedIntersectionType); 44.133 + assertTrue(intersectionType != null, "Must get a non-null intersection type."); 44.134 + 44.135 + assertTrue(it.value().length == intersectionType.getBounds().size(), "Cardinalities do not match"); 44.136 + 44.137 + String[] typeNames = it.value(); 44.138 + for(int i = 0; i < typeNames.length; i++) { 44.139 + TypeMirror typeFromAnnotation = nameToType(typeNames[i]); 44.140 + assertTrue(types.isSameType(typeFromAnnotation, intersectionType.getBounds().get(i)), 44.141 + "Types were not equal."); 44.142 + } 44.143 + } 44.144 + 44.145 + private TypeMirror nameToType(String name) { 44.146 + return elements.getTypeElement(name).asType(); 44.147 + } 44.148 + 44.149 + private static void assertTrue(boolean cond, String msg) { 44.150 + assertionCount++; 44.151 + if (!cond) 44.152 + throw new AssertionError(msg); 44.153 + } 44.154 + 44.155 + static int assertionCount = 0; 44.156 +}
45.1 --- a/test/tools/javac/defaultMethodExecution/DefaultMethodRegressionTests.java Thu Dec 06 12:04:44 2012 -0800 45.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 45.3 @@ -1,137 +0,0 @@ 45.4 -/* 45.5 - * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 45.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 - * 45.8 - * This code is free software; you can redistribute it and/or modify it 45.9 - * under the terms of the GNU General Public License version 2 only, as 45.10 - * published by the Free Software Foundation. Oracle designates this 45.11 - * particular file as subject to the "Classpath" exception as provided 45.12 - * by Oracle in the LICENSE file that accompanied this code. 45.13 - * 45.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 45.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.17 - * version 2 for more details (a copy is included in the LICENSE file that 45.18 - * accompanied this code). 45.19 - * 45.20 - * You should have received a copy of the GNU General Public License version 45.21 - * 2 along with this work; if not, write to the Free Software Foundation, 45.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.23 - * 45.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.25 - * or visit www.oracle.com if you need additional information or have any 45.26 - * questions. 45.27 - */ 45.28 - 45.29 -/** 45.30 - * @test 45.31 - * @bug 8003639 45.32 - * @summary convert lambda testng tests to jtreg and add them 45.33 - * @run testng DefaultMethodRegressionTests 45.34 - */ 45.35 - 45.36 -import java.util.ArrayList; 45.37 -import java.util.Arrays; 45.38 -import java.util.List; 45.39 -import org.testng.annotations.Test; 45.40 - 45.41 -import static org.testng.Assert.*; 45.42 - 45.43 -/** 45.44 - * This set of classes/interfaces (K/I/C) is specially designed to expose a 45.45 - * bug in the JVM where it did not find some overloaded methods in some 45.46 - * specific situations. (fixed by hotspot changeset ffb9316fd9ed) 45.47 - */ 45.48 -interface K { 45.49 - int bbb(Long l); 45.50 -} 45.51 - 45.52 -interface I extends K { 45.53 - default void aaa() {} 45.54 - default void aab() {} 45.55 - default void aac() {} 45.56 - 45.57 - default int bbb(Integer i) { return 22; } 45.58 - default int bbb(Float f) { return 33; } 45.59 - default int bbb(Long l) { return 44; } 45.60 - default int bbb(Double d) { return 55; } 45.61 - default int bbb(String s) { return 66; } 45.62 - 45.63 - default void caa() {} 45.64 - default void cab() {} 45.65 - default void cac() {} 45.66 -} 45.67 - 45.68 -class C implements I {} 45.69 - 45.70 -public class DefaultMethodRegressionTests { 45.71 - 45.72 - @Test(groups = "vm") 45.73 - public void testLostOverloadedMethod() { 45.74 - C c = new C(); 45.75 - assertEquals(c.bbb(new Integer(1)), 22); 45.76 - assertEquals(c.bbb(new Float(1.1)), 33); 45.77 - assertEquals(c.bbb(new Long(1L)), 44); 45.78 - assertEquals(c.bbb(new Double(0.01)), 55); 45.79 - assertEquals(c.bbb(new String("")), 66); 45.80 - } 45.81 - 45.82 - // Test to ensure that the inference verifier accepts older classfiles 45.83 - // with classes that implement interfaces with defaults. 45.84 - @Test(groups = "vm") 45.85 - public void testInferenceVerifier() { 45.86 - // interface I { int m() default { return 99; } } 45.87 - byte I_bytes[] = { 45.88 - (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x33, 45.89 - 0x00, 0x08, 0x07, 0x00, 0x06, 0x07, 0x00, 0x07, 45.90 - 0x01, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x01, 0x00, 45.91 - 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x04, 0x43, 45.92 - 0x6f, 0x64, 0x65, 0x01, 0x00, 0x01, 0x49, 0x01, 45.93 - 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 45.94 - 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 45.95 - 0x63, 0x74, 0x06, 0x00, 0x00, 0x01, 0x00, 0x02, 45.96 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 45.97 - 0x00, 0x03, 0x00, 0x04, 0x00, 0x01, 0x00, 0x05, 45.98 - 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x01, 45.99 - 0x00, 0x00, 0x00, 0x03, 0x10, 0x63, (byte)0xac, 0x00, 45.100 - 0x00, 0x00, 0x00, 0x00, 0x00 45.101 - }; 45.102 - // public class C implements I {} /* -target 1.5 */ 45.103 - byte C_bytes[] = { 45.104 - (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x31, 45.105 - 0x00, 0x0c, 0x0a, 0x00, 0x03, 0x00, 0x08, 0x07, 45.106 - 0x00, 0x09, 0x07, 0x00, 0x0a, 0x07, 0x00, 0x0b, 45.107 - 0x01, 0x00, 0x06, 0x3c, 0x69, 0x6e, 0x69, 0x74, 45.108 - 0x3e, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01, 45.109 - 0x00, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x0c, 0x00, 45.110 - 0x05, 0x00, 0x06, 0x01, 0x00, 0x01, 0x43, 0x01, 45.111 - 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 45.112 - 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 45.113 - 0x63, 0x74, 0x01, 0x00, 0x01, 0x49, 0x00, 0x21, 45.114 - 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 45.115 - 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, 45.116 - 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 45.117 - 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 45.118 - 0x00, 0x05, 0x2a, (byte)0xb7, 0x00, 0x01, (byte)0xb1, 0x00, 45.119 - 0x00, 0x00, 0x00, 0x00, 0x00 45.120 - }; 45.121 - 45.122 - ClassLoader cl = new ClassLoader() { 45.123 - protected Class<?> findClass(String name) { 45.124 - if (name.equals("I")) { 45.125 - return defineClass("I", I_bytes, 0, I_bytes.length); 45.126 - } else if (name.equals("C")) { 45.127 - return defineClass("C", C_bytes, 0, C_bytes.length); 45.128 - } else { 45.129 - return null; 45.130 - } 45.131 - } 45.132 - }; 45.133 - try { 45.134 - Class.forName("C", true, cl); 45.135 - } catch (Exception e) { 45.136 - // unmodified verifier will throw VerifyError 45.137 - fail("No exception should be thrown"); 45.138 - } 45.139 - } 45.140 -}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/tools/javac/defaultMethods/defaultMethodExecution/DefaultMethodRegressionTests.java Mon Dec 10 20:59:38 2012 -0800 46.3 @@ -0,0 +1,138 @@ 46.4 +/* 46.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. Oracle designates this 46.11 + * particular file as subject to the "Classpath" exception as provided 46.12 + * by Oracle in the LICENSE file that accompanied this code. 46.13 + * 46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.17 + * version 2 for more details (a copy is included in the LICENSE file that 46.18 + * accompanied this code). 46.19 + * 46.20 + * You should have received a copy of the GNU General Public License version 46.21 + * 2 along with this work; if not, write to the Free Software Foundation, 46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.23 + * 46.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.25 + * or visit www.oracle.com if you need additional information or have any 46.26 + * questions. 46.27 + */ 46.28 + 46.29 +/** 46.30 + * @test 46.31 + * @ignore 8004360 46.32 + * @bug 8003639 46.33 + * @summary convert lambda testng tests to jtreg and add them 46.34 + * @run testng DefaultMethodRegressionTests 46.35 + */ 46.36 + 46.37 +import java.util.ArrayList; 46.38 +import java.util.Arrays; 46.39 +import java.util.List; 46.40 +import org.testng.annotations.Test; 46.41 + 46.42 +import static org.testng.Assert.*; 46.43 + 46.44 +/** 46.45 + * This set of classes/interfaces (K/I/C) is specially designed to expose a 46.46 + * bug in the JVM where it did not find some overloaded methods in some 46.47 + * specific situations. (fixed by hotspot changeset ffb9316fd9ed) 46.48 + */ 46.49 +interface K { 46.50 + int bbb(Long l); 46.51 +} 46.52 + 46.53 +interface I extends K { 46.54 + default void aaa() {} 46.55 + default void aab() {} 46.56 + default void aac() {} 46.57 + 46.58 + default int bbb(Integer i) { return 22; } 46.59 + default int bbb(Float f) { return 33; } 46.60 + default int bbb(Long l) { return 44; } 46.61 + default int bbb(Double d) { return 55; } 46.62 + default int bbb(String s) { return 66; } 46.63 + 46.64 + default void caa() {} 46.65 + default void cab() {} 46.66 + default void cac() {} 46.67 +} 46.68 + 46.69 +class C implements I {} 46.70 + 46.71 +public class DefaultMethodRegressionTests { 46.72 + 46.73 + @Test(groups = "vm") 46.74 + public void testLostOverloadedMethod() { 46.75 + C c = new C(); 46.76 + assertEquals(c.bbb(new Integer(1)), 22); 46.77 + assertEquals(c.bbb(new Float(1.1)), 33); 46.78 + assertEquals(c.bbb(new Long(1L)), 44); 46.79 + assertEquals(c.bbb(new Double(0.01)), 55); 46.80 + assertEquals(c.bbb(new String("")), 66); 46.81 + } 46.82 + 46.83 + // Test to ensure that the inference verifier accepts older classfiles 46.84 + // with classes that implement interfaces with defaults. 46.85 + @Test(groups = "vm") 46.86 + public void testInferenceVerifier() { 46.87 + // interface I { int m() default { return 99; } } 46.88 + byte I_bytes[] = { 46.89 + (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x33, 46.90 + 0x00, 0x08, 0x07, 0x00, 0x06, 0x07, 0x00, 0x07, 46.91 + 0x01, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x01, 0x00, 46.92 + 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x04, 0x43, 46.93 + 0x6f, 0x64, 0x65, 0x01, 0x00, 0x01, 0x49, 0x01, 46.94 + 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 46.95 + 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 46.96 + 0x63, 0x74, 0x06, 0x00, 0x00, 0x01, 0x00, 0x02, 46.97 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 46.98 + 0x00, 0x03, 0x00, 0x04, 0x00, 0x01, 0x00, 0x05, 46.99 + 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x01, 46.100 + 0x00, 0x00, 0x00, 0x03, 0x10, 0x63, (byte)0xac, 0x00, 46.101 + 0x00, 0x00, 0x00, 0x00, 0x00 46.102 + }; 46.103 + // public class C implements I {} /* -target 1.5 */ 46.104 + byte C_bytes[] = { 46.105 + (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x31, 46.106 + 0x00, 0x0c, 0x0a, 0x00, 0x03, 0x00, 0x08, 0x07, 46.107 + 0x00, 0x09, 0x07, 0x00, 0x0a, 0x07, 0x00, 0x0b, 46.108 + 0x01, 0x00, 0x06, 0x3c, 0x69, 0x6e, 0x69, 0x74, 46.109 + 0x3e, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01, 46.110 + 0x00, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x0c, 0x00, 46.111 + 0x05, 0x00, 0x06, 0x01, 0x00, 0x01, 0x43, 0x01, 46.112 + 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 46.113 + 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 46.114 + 0x63, 0x74, 0x01, 0x00, 0x01, 0x49, 0x00, 0x21, 46.115 + 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 46.116 + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, 46.117 + 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 46.118 + 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 46.119 + 0x00, 0x05, 0x2a, (byte)0xb7, 0x00, 0x01, (byte)0xb1, 0x00, 46.120 + 0x00, 0x00, 0x00, 0x00, 0x00 46.121 + }; 46.122 + 46.123 + ClassLoader cl = new ClassLoader() { 46.124 + protected Class<?> findClass(String name) { 46.125 + if (name.equals("I")) { 46.126 + return defineClass("I", I_bytes, 0, I_bytes.length); 46.127 + } else if (name.equals("C")) { 46.128 + return defineClass("C", C_bytes, 0, C_bytes.length); 46.129 + } else { 46.130 + return null; 46.131 + } 46.132 + } 46.133 + }; 46.134 + try { 46.135 + Class.forName("C", true, cl); 46.136 + } catch (Exception e) { 46.137 + // unmodified verifier will throw VerifyError 46.138 + fail("No exception should be thrown"); 46.139 + } 46.140 + } 46.141 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/tools/javac/diags/examples/IntersectionTypesInCastNotSupported.java Mon Dec 10 20:59:38 2012 -0800 47.3 @@ -0,0 +1,29 @@ 47.4 +/* 47.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. 47.11 + * 47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 + * version 2 for more details (a copy is included in the LICENSE file that 47.16 + * accompanied this code). 47.17 + * 47.18 + * You should have received a copy of the GNU General Public License version 47.19 + * 2 along with this work; if not, write to the Free Software Foundation, 47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 + * 47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 + * or visit www.oracle.com if you need additional information or have any 47.24 + * questions. 47.25 + */ 47.26 + 47.27 +// key: compiler.err.intersection.types.in.cast.not.supported.in.source 47.28 +// options: -source 7 -Xlint:-options 47.29 + 47.30 +interface IntersectionTypesInCastNotSupported { 47.31 + Object o = (A & B)null; 47.32 +}
48.1 --- a/test/tools/javac/diags/examples/InvalidGenericDescInFunctionalInterface.java Thu Dec 06 12:04:44 2012 -0800 48.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 48.3 @@ -1,34 +0,0 @@ 48.4 -/* 48.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 48.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 - * 48.8 - * This code is free software; you can redistribute it and/or modify it 48.9 - * under the terms of the GNU General Public License version 2 only, as 48.10 - * published by the Free Software Foundation. 48.11 - * 48.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 48.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.15 - * version 2 for more details (a copy is included in the LICENSE file that 48.16 - * accompanied this code). 48.17 - * 48.18 - * You should have received a copy of the GNU General Public License version 48.19 - * 2 along with this work; if not, write to the Free Software Foundation, 48.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.21 - * 48.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.23 - * or visit www.oracle.com if you need additional information or have any 48.24 - * questions. 48.25 - */ 48.26 - 48.27 -// key: compiler.err.prob.found.req 48.28 -// key: compiler.misc.invalid.generic.desc.in.functional.intf 48.29 - 48.30 -class InvalidGenericDescInFunctionalIntf { 48.31 - 48.32 - interface SAM { 48.33 - <Z> void m(); 48.34 - } 48.35 - 48.36 - SAM s = x-> { }; 48.37 -}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/diags/examples/InvalidGenericLambdaTarget.java Mon Dec 10 20:59:38 2012 -0800 49.3 @@ -0,0 +1,34 @@ 49.4 +/* 49.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +// key: compiler.err.prob.found.req 49.28 +// key: compiler.misc.invalid.generic.lambda.target 49.29 + 49.30 +class InvalidGenericLambdaTarget { 49.31 + 49.32 + interface SAM { 49.33 + <Z> void m(); 49.34 + } 49.35 + 49.36 + SAM s = x-> { }; 49.37 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/diags/examples/SecondaryBoundMustBeMarkerIntf.java Mon Dec 10 20:59:38 2012 -0800 50.3 @@ -0,0 +1,30 @@ 50.4 +/* 50.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. 50.11 + * 50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.15 + * version 2 for more details (a copy is included in the LICENSE file that 50.16 + * accompanied this code). 50.17 + * 50.18 + * You should have received a copy of the GNU General Public License version 50.19 + * 2 along with this work; if not, write to the Free Software Foundation, 50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.21 + * 50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.23 + * or visit www.oracle.com if you need additional information or have any 50.24 + * questions. 50.25 + */ 50.26 + 50.27 +// key: compiler.err.prob.found.req 50.28 +// key: compiler.misc.secondary.bound.must.be.marker.intf 50.29 +// options: -XDallowIntersectionTypes 50.30 + 50.31 +class SecondaryBoundMustBeMarkerInterface { 50.32 + Runnable r = (Runnable & Comparable<?>)()->{}; 50.33 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/diags/examples/StaticBoundMref.java Mon Dec 10 20:59:38 2012 -0800 51.3 @@ -0,0 +1,32 @@ 51.4 +/* 51.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. 51.11 + * 51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.15 + * version 2 for more details (a copy is included in the LICENSE file that 51.16 + * accompanied this code). 51.17 + * 51.18 + * You should have received a copy of the GNU General Public License version 51.19 + * 2 along with this work; if not, write to the Free Software Foundation, 51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.21 + * 51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.23 + * or visit www.oracle.com if you need additional information or have any 51.24 + * questions. 51.25 + */ 51.26 + 51.27 +// key: compiler.err.invalid.mref 51.28 +// key: compiler.misc.static.bound.mref 51.29 + 51.30 +class StaticBoundMref { 51.31 + 51.32 + Runnable r = new StaticBoundMref()::m; 51.33 + 51.34 + static void m() { } 51.35 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/tools/javac/diags/examples/StaticMrefWithTargs.java Mon Dec 10 20:59:38 2012 -0800 52.3 @@ -0,0 +1,32 @@ 52.4 +/* 52.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. 52.11 + * 52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.15 + * version 2 for more details (a copy is included in the LICENSE file that 52.16 + * accompanied this code). 52.17 + * 52.18 + * You should have received a copy of the GNU General Public License version 52.19 + * 2 along with this work; if not, write to the Free Software Foundation, 52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.21 + * 52.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.23 + * or visit www.oracle.com if you need additional information or have any 52.24 + * questions. 52.25 + */ 52.26 + 52.27 +// key: compiler.err.invalid.mref 52.28 +// key: compiler.misc.static.mref.with.targs 52.29 + 52.30 +class StaticMrefWithTargs<X> { 52.31 + 52.32 + Runnable r = StaticMrefWithTargs<String>::m; 52.33 + 52.34 + static void m() { } 52.35 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java Mon Dec 10 20:59:38 2012 -0800 53.3 @@ -0,0 +1,280 @@ 53.4 +/* 53.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. 53.11 + * 53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.15 + * version 2 for more details (a copy is included in the LICENSE file that 53.16 + * accompanied this code). 53.17 + * 53.18 + * You should have received a copy of the GNU General Public License version 53.19 + * 2 along with this work; if not, write to the Free Software Foundation, 53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.21 + * 53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.23 + * or visit www.oracle.com if you need additional information or have any 53.24 + * questions. 53.25 + */ 53.26 + 53.27 +/** 53.28 + * @test 53.29 + * @bug 8003280 8004102 53.30 + * @summary Add lambda tests 53.31 + * perform several automated checks in lambda conversion, esp. around accessibility 53.32 + * @author Maurizio Cimadamore 53.33 + * @run main FunctionalInterfaceConversionTest 53.34 + */ 53.35 + 53.36 +import com.sun.source.util.JavacTask; 53.37 +import java.net.URI; 53.38 +import java.util.Arrays; 53.39 +import javax.tools.Diagnostic; 53.40 +import javax.tools.JavaCompiler; 53.41 +import javax.tools.JavaFileObject; 53.42 +import javax.tools.SimpleJavaFileObject; 53.43 +import javax.tools.StandardJavaFileManager; 53.44 +import javax.tools.ToolProvider; 53.45 + 53.46 +public class FunctionalInterfaceConversionTest { 53.47 + 53.48 + enum PackageKind { 53.49 + NO_PKG(""), 53.50 + PKG_A("a"); 53.51 + 53.52 + String pkg; 53.53 + 53.54 + PackageKind(String pkg) { 53.55 + this.pkg = pkg; 53.56 + } 53.57 + 53.58 + String getPkgDecl() { 53.59 + return this == NO_PKG ? 53.60 + "" : 53.61 + "package " + pkg + ";"; 53.62 + } 53.63 + 53.64 + String getImportStat() { 53.65 + return this == NO_PKG ? 53.66 + "" : 53.67 + "import " + pkg + ".*;"; 53.68 + } 53.69 + } 53.70 + 53.71 + enum SamKind { 53.72 + CLASS("public class Sam { }"), 53.73 + ABSTACT_CLASS("public abstract class Sam { }"), 53.74 + ANNOTATION("public @interface Sam { }"), 53.75 + ENUM("public enum Sam { }"), 53.76 + INTERFACE("public interface Sam { \n #METH; \n }"); 53.77 + 53.78 + String sam_str; 53.79 + 53.80 + SamKind(String sam_str) { 53.81 + this.sam_str = sam_str; 53.82 + } 53.83 + 53.84 + String getSam(String methStr) { 53.85 + return sam_str.replaceAll("#METH", methStr); 53.86 + } 53.87 + } 53.88 + 53.89 + enum ModifierKind { 53.90 + PUBLIC("public"), 53.91 + PACKAGE(""); 53.92 + 53.93 + String modifier_str; 53.94 + 53.95 + ModifierKind(String modifier_str) { 53.96 + this.modifier_str = modifier_str; 53.97 + } 53.98 + 53.99 + boolean stricterThan(ModifierKind that) { 53.100 + return this.ordinal() > that.ordinal(); 53.101 + } 53.102 + } 53.103 + 53.104 + enum TypeKind { 53.105 + EXCEPTION("Exception"), 53.106 + PKG_CLASS("PackageClass"); 53.107 + 53.108 + String typeStr; 53.109 + 53.110 + private TypeKind(String typeStr) { 53.111 + this.typeStr = typeStr; 53.112 + } 53.113 + } 53.114 + 53.115 + enum ExprKind { 53.116 + LAMBDA("x -> null"), 53.117 + MREF("this::m"); 53.118 + 53.119 + String exprStr; 53.120 + 53.121 + private ExprKind(String exprStr) { 53.122 + this.exprStr = exprStr; 53.123 + } 53.124 + } 53.125 + 53.126 + enum MethodKind { 53.127 + NONE(""), 53.128 + NON_GENERIC("public abstract #R m(#ARG s) throws #T;"), 53.129 + GENERIC("public abstract <X> #R m(#ARG s) throws #T;"); 53.130 + 53.131 + String methodTemplate; 53.132 + 53.133 + private MethodKind(String methodTemplate) { 53.134 + this.methodTemplate = methodTemplate; 53.135 + } 53.136 + 53.137 + String getMethod(TypeKind retType, TypeKind argType, TypeKind thrownType) { 53.138 + return methodTemplate.replaceAll("#R", retType.typeStr). 53.139 + replaceAll("#ARG", argType.typeStr). 53.140 + replaceAll("#T", thrownType.typeStr); 53.141 + } 53.142 + } 53.143 + 53.144 + public static void main(String[] args) throws Exception { 53.145 + final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 53.146 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 53.147 + for (PackageKind samPkg : PackageKind.values()) { 53.148 + for (ModifierKind modKind : ModifierKind.values()) { 53.149 + for (SamKind samKind : SamKind.values()) { 53.150 + for (MethodKind samMeth : MethodKind.values()) { 53.151 + for (MethodKind clientMeth : MethodKind.values()) { 53.152 + for (TypeKind retType : TypeKind.values()) { 53.153 + for (TypeKind argType : TypeKind.values()) { 53.154 + for (TypeKind thrownType : TypeKind.values()) { 53.155 + for (ExprKind exprKind : ExprKind.values()) { 53.156 + new FunctionalInterfaceConversionTest(samPkg, modKind, samKind, 53.157 + samMeth, clientMeth, retType, argType, thrownType, exprKind).test(comp, fm); 53.158 + } 53.159 + } 53.160 + } 53.161 + } 53.162 + } 53.163 + } 53.164 + } 53.165 + } 53.166 + } 53.167 + } 53.168 + 53.169 + PackageKind samPkg; 53.170 + ModifierKind modKind; 53.171 + SamKind samKind; 53.172 + MethodKind samMeth; 53.173 + MethodKind clientMeth; 53.174 + TypeKind retType; 53.175 + TypeKind argType; 53.176 + TypeKind thrownType; 53.177 + ExprKind exprKind; 53.178 + DiagnosticChecker dc; 53.179 + 53.180 + SourceFile samSourceFile = new SourceFile("Sam.java", "#P \n #C") { 53.181 + public String toString() { 53.182 + return template.replaceAll("#P", samPkg.getPkgDecl()). 53.183 + replaceAll("#C", samKind.getSam(samMeth.getMethod(retType, argType, thrownType))); 53.184 + } 53.185 + }; 53.186 + 53.187 + SourceFile pkgClassSourceFile = new SourceFile("PackageClass.java", 53.188 + "#P\n #M class PackageClass extends Exception { }") { 53.189 + public String toString() { 53.190 + return template.replaceAll("#P", samPkg.getPkgDecl()). 53.191 + replaceAll("#M", modKind.modifier_str); 53.192 + } 53.193 + }; 53.194 + 53.195 + SourceFile clientSourceFile = new SourceFile("Client.java", 53.196 + "#I\n abstract class Client { \n" + 53.197 + " Sam s = #E;\n" + 53.198 + " #M \n }") { 53.199 + public String toString() { 53.200 + return template.replaceAll("#I", samPkg.getImportStat()) 53.201 + .replaceAll("#E", exprKind.exprStr) 53.202 + .replaceAll("#M", clientMeth.getMethod(retType, argType, thrownType)); 53.203 + } 53.204 + }; 53.205 + 53.206 + FunctionalInterfaceConversionTest(PackageKind samPkg, ModifierKind modKind, SamKind samKind, 53.207 + MethodKind samMeth, MethodKind clientMeth, TypeKind retType, TypeKind argType, 53.208 + TypeKind thrownType, ExprKind exprKind) { 53.209 + this.samPkg = samPkg; 53.210 + this.modKind = modKind; 53.211 + this.samKind = samKind; 53.212 + this.samMeth = samMeth; 53.213 + this.clientMeth = clientMeth; 53.214 + this.retType = retType; 53.215 + this.argType = argType; 53.216 + this.thrownType = thrownType; 53.217 + this.exprKind = exprKind; 53.218 + this.dc = new DiagnosticChecker(); 53.219 + } 53.220 + 53.221 + void test(JavaCompiler comp, StandardJavaFileManager fm) throws Exception { 53.222 + JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, 53.223 + null, null, Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile)); 53.224 + ct.analyze(); 53.225 + if (dc.errorFound == checkSamConversion()) { 53.226 + throw new AssertionError(samSourceFile + "\n\n" + pkgClassSourceFile + "\n\n" + clientSourceFile); 53.227 + } 53.228 + } 53.229 + 53.230 + boolean checkSamConversion() { 53.231 + if (samKind != SamKind.INTERFACE) { 53.232 + //sam type must be an interface 53.233 + return false; 53.234 + } else if (samMeth == MethodKind.NONE) { 53.235 + //interface must have at least a method 53.236 + return false; 53.237 + } else if (exprKind == ExprKind.LAMBDA && 53.238 + samMeth != MethodKind.NON_GENERIC) { 53.239 + //target method for lambda must be non-generic 53.240 + return false; 53.241 + } else if (exprKind == ExprKind.MREF && 53.242 + clientMeth == MethodKind.NONE) { 53.243 + return false; 53.244 + } else if (samPkg != PackageKind.NO_PKG && 53.245 + modKind != ModifierKind.PUBLIC && 53.246 + (retType == TypeKind.PKG_CLASS || 53.247 + argType == TypeKind.PKG_CLASS || 53.248 + thrownType == TypeKind.PKG_CLASS)) { 53.249 + //target must not contain inaccessible types 53.250 + return false; 53.251 + } else { 53.252 + return true; 53.253 + } 53.254 + } 53.255 + 53.256 + abstract class SourceFile extends SimpleJavaFileObject { 53.257 + 53.258 + protected String template; 53.259 + 53.260 + public SourceFile(String filename, String template) { 53.261 + super(URI.create("myfo:/" + filename), JavaFileObject.Kind.SOURCE); 53.262 + this.template = template; 53.263 + } 53.264 + 53.265 + @Override 53.266 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 53.267 + return toString(); 53.268 + } 53.269 + 53.270 + public abstract String toString(); 53.271 + } 53.272 + 53.273 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 53.274 + 53.275 + boolean errorFound = false; 53.276 + 53.277 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 53.278 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 53.279 + errorFound = true; 53.280 + } 53.281 + } 53.282 + } 53.283 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/tools/javac/lambda/Intersection01.java Mon Dec 10 20:59:38 2012 -0800 54.3 @@ -0,0 +1,42 @@ 54.4 +/* 54.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. 54.11 + * 54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.15 + * version 2 for more details (a copy is included in the LICENSE file that 54.16 + * accompanied this code). 54.17 + * 54.18 + * You should have received a copy of the GNU General Public License version 54.19 + * 2 along with this work; if not, write to the Free Software Foundation, 54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.21 + * 54.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.23 + * or visit www.oracle.com if you need additional information or have any 54.24 + * questions. 54.25 + */ 54.26 + 54.27 +/* 54.28 + * @test 54.29 + * @bug 8002099 54.30 + * @summary Add support for intersection types in cast expression 54.31 + * @compile/fail/ref=Intersection01.out -XDallowIntersectionTypes -XDrawDiagnostics Intersection01.java 54.32 + */ 54.33 +class Intersection01 { 54.34 + 54.35 + interface SAM { 54.36 + void m(); 54.37 + } 54.38 + 54.39 + Object o1 = (java.io.Serializable & SAM)()->{}; 54.40 + Object o2 = (SAM & java.io.Serializable)()->{}; 54.41 + Object o3 = (java.io.Serializable & SAM)Intersection01::m; 54.42 + Object o4 = (SAM & java.io.Serializable)Intersection01::m; 54.43 + 54.44 + static void m() { } 54.45 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/tools/javac/lambda/Intersection01.out Mon Dec 10 20:59:38 2012 -0800 55.3 @@ -0,0 +1,3 @@ 55.4 +Intersection01.java:36:45: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: (compiler.misc.no.abstracts: kindname.interface, java.io.Serializable)) 55.5 +Intersection01.java:38:45: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: (compiler.misc.no.abstracts: kindname.interface, java.io.Serializable)) 55.6 +2 errors
56.1 --- a/test/tools/javac/lambda/LambdaConv21.java Thu Dec 06 12:04:44 2012 -0800 56.2 +++ b/test/tools/javac/lambda/LambdaConv21.java Mon Dec 10 20:59:38 2012 -0800 56.3 @@ -23,7 +23,7 @@ 56.4 static void testExpressionLambda() { 56.5 SAM_void s1 = ()->m_void(); //ok 56.6 SAM_java_lang_Void s2 = ()->m_void(); //no - incompatible target 56.7 - SAM_void s3 = ()->m_java_lang_Void(); //no - incompatible target 56.8 + SAM_void s3 = ()->m_java_lang_Void(); //ok - expression statement lambda is compatible with void 56.9 SAM_java_lang_Void s4 = ()->m_java_lang_Void(); //ok 56.10 } 56.11
57.1 --- a/test/tools/javac/lambda/LambdaConv21.out Thu Dec 06 12:04:44 2012 -0800 57.2 +++ b/test/tools/javac/lambda/LambdaConv21.out Mon Dec 10 20:59:38 2012 -0800 57.3 @@ -1,6 +1,5 @@ 57.4 LambdaConv21.java:25:43: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: void, java.lang.Void)) 57.5 -LambdaConv21.java:26:43: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.Void, void)) 57.6 LambdaConv21.java:32:33: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.Void)) 57.7 LambdaConv21.java:33:53: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val)) 57.8 LambdaConv21.java:36:33: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.Void)) 57.9 -5 errors 57.10 +4 errors
58.1 --- a/test/tools/javac/lambda/LambdaConversionTest.java Thu Dec 06 12:04:44 2012 -0800 58.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 58.3 @@ -1,246 +0,0 @@ 58.4 -/* 58.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 58.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 58.7 - * 58.8 - * This code is free software; you can redistribute it and/or modify it 58.9 - * under the terms of the GNU General Public License version 2 only, as 58.10 - * published by the Free Software Foundation. 58.11 - * 58.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 58.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 58.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 58.15 - * version 2 for more details (a copy is included in the LICENSE file that 58.16 - * accompanied this code). 58.17 - * 58.18 - * You should have received a copy of the GNU General Public License version 58.19 - * 2 along with this work; if not, write to the Free Software Foundation, 58.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 58.21 - * 58.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 58.23 - * or visit www.oracle.com if you need additional information or have any 58.24 - * questions. 58.25 - */ 58.26 - 58.27 -/** 58.28 - * @test 58.29 - * @bug 8003280 58.30 - * @summary Add lambda tests 58.31 - * perform several automated checks in lambda conversion, esp. around accessibility 58.32 - * @author Maurizio Cimadamore 58.33 - * @run main LambdaConversionTest 58.34 - */ 58.35 - 58.36 -import com.sun.source.util.JavacTask; 58.37 -import java.net.URI; 58.38 -import java.util.Arrays; 58.39 -import javax.tools.Diagnostic; 58.40 -import javax.tools.JavaCompiler; 58.41 -import javax.tools.JavaFileObject; 58.42 -import javax.tools.SimpleJavaFileObject; 58.43 -import javax.tools.ToolProvider; 58.44 - 58.45 -public class LambdaConversionTest { 58.46 - 58.47 - enum PackageKind { 58.48 - NO_PKG(""), 58.49 - PKG_A("a"); 58.50 - 58.51 - String pkg; 58.52 - 58.53 - PackageKind(String pkg) { 58.54 - this.pkg = pkg; 58.55 - } 58.56 - 58.57 - String getPkgDecl() { 58.58 - return this == NO_PKG ? 58.59 - "" : 58.60 - "package " + pkg + ";"; 58.61 - } 58.62 - 58.63 - String getImportStat() { 58.64 - return this == NO_PKG ? 58.65 - "" : 58.66 - "import " + pkg + ".*;"; 58.67 - } 58.68 - } 58.69 - 58.70 - enum SamKind { 58.71 - CLASS("public class Sam { }"), 58.72 - ABSTACT_CLASS("public abstract class Sam { }"), 58.73 - ANNOTATION("public @interface Sam { }"), 58.74 - ENUM("public enum Sam { }"), 58.75 - INTERFACE("public interface Sam { \n #METH; \n }"); 58.76 - 58.77 - String sam_str; 58.78 - 58.79 - SamKind(String sam_str) { 58.80 - this.sam_str = sam_str; 58.81 - } 58.82 - 58.83 - String getSam(String methStr) { 58.84 - return sam_str.replaceAll("#METH", methStr); 58.85 - } 58.86 - } 58.87 - 58.88 - enum ModifierKind { 58.89 - PUBLIC("public"), 58.90 - PACKAGE(""); 58.91 - 58.92 - String modifier_str; 58.93 - 58.94 - ModifierKind(String modifier_str) { 58.95 - this.modifier_str = modifier_str; 58.96 - } 58.97 - 58.98 - boolean stricterThan(ModifierKind that) { 58.99 - return this.ordinal() > that.ordinal(); 58.100 - } 58.101 - } 58.102 - 58.103 - enum TypeKind { 58.104 - EXCEPTION("Exception"), 58.105 - PKG_CLASS("PackageClass"); 58.106 - 58.107 - String typeStr; 58.108 - 58.109 - private TypeKind(String typeStr) { 58.110 - this.typeStr = typeStr; 58.111 - } 58.112 - } 58.113 - 58.114 - enum MethodKind { 58.115 - NONE(""), 58.116 - NON_GENERIC("public #R m(#ARG s) throws #T;"), 58.117 - GENERIC("public <X> #R m(#ARG s) throws #T;"); 58.118 - 58.119 - String methodTemplate; 58.120 - 58.121 - private MethodKind(String methodTemplate) { 58.122 - this.methodTemplate = methodTemplate; 58.123 - } 58.124 - 58.125 - String getMethod(TypeKind retType, TypeKind argType, TypeKind thrownType) { 58.126 - return methodTemplate.replaceAll("#R", retType.typeStr). 58.127 - replaceAll("#ARG", argType.typeStr). 58.128 - replaceAll("#T", thrownType.typeStr); 58.129 - } 58.130 - } 58.131 - 58.132 - public static void main(String[] args) throws Exception { 58.133 - for (PackageKind samPkg : PackageKind.values()) { 58.134 - for (ModifierKind modKind : ModifierKind.values()) { 58.135 - for (SamKind samKind : SamKind.values()) { 58.136 - for (MethodKind meth : MethodKind.values()) { 58.137 - for (TypeKind retType : TypeKind.values()) { 58.138 - for (TypeKind argType : TypeKind.values()) { 58.139 - for (TypeKind thrownType : TypeKind.values()) { 58.140 - new LambdaConversionTest(samPkg, modKind, samKind, 58.141 - meth, retType, argType, thrownType).test(); 58.142 - } 58.143 - } 58.144 - } 58.145 - } 58.146 - } 58.147 - } 58.148 - } 58.149 - } 58.150 - 58.151 - PackageKind samPkg; 58.152 - ModifierKind modKind; 58.153 - SamKind samKind; 58.154 - MethodKind meth; 58.155 - TypeKind retType; 58.156 - TypeKind argType; 58.157 - TypeKind thrownType; 58.158 - 58.159 - SourceFile samSourceFile = new SourceFile("Sam.java", "#P \n #C") { 58.160 - public String toString() { 58.161 - return template.replaceAll("#P", samPkg.getPkgDecl()). 58.162 - replaceAll("#C", samKind.getSam(meth.getMethod(retType, argType, thrownType))); 58.163 - } 58.164 - }; 58.165 - 58.166 - SourceFile pkgClassSourceFile = new SourceFile("PackageClass.java", 58.167 - "#P\n #M class PackageClass extends Exception { }") { 58.168 - public String toString() { 58.169 - return template.replaceAll("#P", samPkg.getPkgDecl()). 58.170 - replaceAll("#M", modKind.modifier_str); 58.171 - } 58.172 - }; 58.173 - 58.174 - SourceFile clientSourceFile = new SourceFile("Client.java", 58.175 - "#I\n class Client { Sam s = x -> null; }") { 58.176 - public String toString() { 58.177 - return template.replaceAll("#I", samPkg.getImportStat()); 58.178 - } 58.179 - }; 58.180 - 58.181 - LambdaConversionTest(PackageKind samPkg, ModifierKind modKind, SamKind samKind, 58.182 - MethodKind meth, TypeKind retType, TypeKind argType, TypeKind thrownType) { 58.183 - this.samPkg = samPkg; 58.184 - this.modKind = modKind; 58.185 - this.samKind = samKind; 58.186 - this.meth = meth; 58.187 - this.retType = retType; 58.188 - this.argType = argType; 58.189 - this.thrownType = thrownType; 58.190 - } 58.191 - 58.192 - void test() throws Exception { 58.193 - final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 58.194 - DiagnosticChecker dc = new DiagnosticChecker(); 58.195 - JavacTask ct = (JavacTask)tool.getTask(null, null, dc, 58.196 - null, null, Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile)); 58.197 - ct.analyze(); 58.198 - if (dc.errorFound == checkSamConversion()) { 58.199 - throw new AssertionError(samSourceFile + "\n\n" + pkgClassSourceFile + "\n\n" + clientSourceFile); 58.200 - } 58.201 - } 58.202 - 58.203 - boolean checkSamConversion() { 58.204 - if (samKind != SamKind.INTERFACE) { 58.205 - //sam type must be an interface 58.206 - return false; 58.207 - } else if (meth != MethodKind.NON_GENERIC) { 58.208 - //target method must be non-generic 58.209 - return false; 58.210 - } else if (samPkg != PackageKind.NO_PKG && 58.211 - modKind != ModifierKind.PUBLIC && 58.212 - (retType == TypeKind.PKG_CLASS || 58.213 - argType == TypeKind.PKG_CLASS || 58.214 - thrownType == TypeKind.PKG_CLASS)) { 58.215 - //target must not contain inaccessible types 58.216 - return false; 58.217 - } else { 58.218 - return true; 58.219 - } 58.220 - } 58.221 - 58.222 - abstract class SourceFile extends SimpleJavaFileObject { 58.223 - 58.224 - protected String template; 58.225 - 58.226 - public SourceFile(String filename, String template) { 58.227 - super(URI.create("myfo:/" + filename), JavaFileObject.Kind.SOURCE); 58.228 - this.template = template; 58.229 - } 58.230 - 58.231 - @Override 58.232 - public CharSequence getCharContent(boolean ignoreEncodingErrors) { 58.233 - return toString(); 58.234 - } 58.235 - 58.236 - public abstract String toString(); 58.237 - } 58.238 - 58.239 - static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 58.240 - 58.241 - boolean errorFound = false; 58.242 - 58.243 - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 58.244 - if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 58.245 - errorFound = true; 58.246 - } 58.247 - } 58.248 - } 58.249 -}
59.1 --- a/test/tools/javac/lambda/LambdaParserTest.java Thu Dec 06 12:04:44 2012 -0800 59.2 +++ b/test/tools/javac/lambda/LambdaParserTest.java Mon Dec 10 20:59:38 2012 -0800 59.3 @@ -90,9 +90,14 @@ 59.4 enum LambdaParameterKind { 59.5 IMPLICIT(""), 59.6 EXPLIICT_SIMPLE("A"), 59.7 + EXPLIICT_SIMPLE_ARR1("A[]"), 59.8 + EXPLIICT_SIMPLE_ARR2("A[][]"), 59.9 EXPLICIT_VARARGS("A..."), 59.10 EXPLICIT_GENERIC1("A<X>"), 59.11 - EXPLICIT_GENERIC3("A<? extends X, ? super Y>"); 59.12 + EXPLICIT_GENERIC2("A<? extends X, ? super Y>"), 59.13 + EXPLICIT_GENERIC2_VARARGS("A<? extends X, ? super Y>..."), 59.14 + EXPLICIT_GENERIC2_ARR1("A<? extends X, ? super Y>[]"), 59.15 + EXPLICIT_GENERIC2_ARR2("A<? extends X, ? super Y>[][]"); 59.16 59.17 String parameterType; 59.18 59.19 @@ -103,6 +108,11 @@ 59.20 boolean explicit() { 59.21 return this != IMPLICIT; 59.22 } 59.23 + 59.24 + boolean isVarargs() { 59.25 + return this == EXPLICIT_VARARGS || 59.26 + this == EXPLICIT_GENERIC2_VARARGS; 59.27 + } 59.28 } 59.29 59.30 enum ModifierKind { 59.31 @@ -253,7 +263,7 @@ 59.32 59.33 if (lk.arity() == 2 && 59.34 (pk1.explicit() != pk2.explicit() || 59.35 - pk1 == LambdaParameterKind.EXPLICIT_VARARGS)) { 59.36 + pk1.isVarargs())) { 59.37 errorExpected = true; 59.38 } 59.39
60.1 --- a/test/tools/javac/lambda/MethodReference30.java Thu Dec 06 12:04:44 2012 -0800 60.2 +++ b/test/tools/javac/lambda/MethodReference30.java Mon Dec 10 20:59:38 2012 -0800 60.3 @@ -46,7 +46,7 @@ 60.4 assertTrue(true); 60.5 } 60.6 60.7 - static void m() { } 60.8 + void m() { } 60.9 60.10 public static void main(String[] args) { 60.11 SAM s = new MethodReference30()::m;
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 61.2 +++ b/test/tools/javac/lambda/MethodReference55.java Mon Dec 10 20:59:38 2012 -0800 61.3 @@ -0,0 +1,45 @@ 61.4 +/* 61.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 61.7 + * 61.8 + * This code is free software; you can redistribute it and/or modify it 61.9 + * under the terms of the GNU General Public License version 2 only, as 61.10 + * published by the Free Software Foundation. 61.11 + * 61.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 61.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 61.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 61.15 + * version 2 for more details (a copy is included in the LICENSE file that 61.16 + * accompanied this code). 61.17 + * 61.18 + * You should have received a copy of the GNU General Public License version 61.19 + * 2 along with this work; if not, write to the Free Software Foundation, 61.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 61.21 + * 61.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 61.23 + * or visit www.oracle.com if you need additional information or have any 61.24 + * questions. 61.25 + */ 61.26 + 61.27 +/* 61.28 + * @test 61.29 + * @bug 8004101 61.30 + * @summary Add checks for method reference well-formedness 61.31 + * @compile/fail/ref=MethodReference55.out -XDrawDiagnostics MethodReference55.java 61.32 + */ 61.33 +class MethodReference55<X> { 61.34 + 61.35 + interface V { 61.36 + void m(Object o); 61.37 + } 61.38 + 61.39 + V v = new MethodReference55<String>()::m; 61.40 + 61.41 + void test() { 61.42 + g(new MethodReference55<String>()::m); 61.43 + } 61.44 + 61.45 + void g(V v) { } 61.46 + 61.47 + static void m(Object o) { }; 61.48 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/test/tools/javac/lambda/MethodReference55.out Mon Dec 10 20:59:38 2012 -0800 62.3 @@ -0,0 +1,3 @@ 62.4 +MethodReference55.java:36:11: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.bound.mref) 62.5 +MethodReference55.java:39:11: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.bound.mref) 62.6 +2 errors
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/test/tools/javac/lambda/MethodReference56.java Mon Dec 10 20:59:38 2012 -0800 63.3 @@ -0,0 +1,45 @@ 63.4 +/* 63.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 63.7 + * 63.8 + * This code is free software; you can redistribute it and/or modify it 63.9 + * under the terms of the GNU General Public License version 2 only, as 63.10 + * published by the Free Software Foundation. 63.11 + * 63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 63.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 63.15 + * version 2 for more details (a copy is included in the LICENSE file that 63.16 + * accompanied this code). 63.17 + * 63.18 + * You should have received a copy of the GNU General Public License version 63.19 + * 2 along with this work; if not, write to the Free Software Foundation, 63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 63.21 + * 63.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 63.23 + * or visit www.oracle.com if you need additional information or have any 63.24 + * questions. 63.25 + */ 63.26 + 63.27 +/* 63.28 + * @test 63.29 + * @bug 8004101 63.30 + * @summary Add checks for method reference well-formedness 63.31 + * @compile/fail/ref=MethodReference56.out -XDrawDiagnostics MethodReference56.java 63.32 + */ 63.33 +class MethodReference56<X> { 63.34 + 63.35 + interface V { 63.36 + void m(Object o); 63.37 + } 63.38 + 63.39 + V v = MethodReference56<String>::m; 63.40 + 63.41 + void test() { 63.42 + g(MethodReference56<String>::m); 63.43 + } 63.44 + 63.45 + void g(V v) { } 63.46 + 63.47 + static void m(Object o) { }; 63.48 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/test/tools/javac/lambda/MethodReference56.out Mon Dec 10 20:59:38 2012 -0800 64.3 @@ -0,0 +1,3 @@ 64.4 +MethodReference56.java:36:28: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.mref.with.targs) 64.5 +MethodReference56.java:39:28: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.mref.with.targs) 64.6 +2 errors
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 65.2 +++ b/test/tools/javac/lambda/MethodReference57.java Mon Dec 10 20:59:38 2012 -0800 65.3 @@ -0,0 +1,41 @@ 65.4 +/* 65.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 65.7 + * 65.8 + * This code is free software; you can redistribute it and/or modify it 65.9 + * under the terms of the GNU General Public License version 2 only, as 65.10 + * published by the Free Software Foundation. 65.11 + * 65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 65.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 65.15 + * version 2 for more details (a copy is included in the LICENSE file that 65.16 + * accompanied this code). 65.17 + * 65.18 + * You should have received a copy of the GNU General Public License version 65.19 + * 2 along with this work; if not, write to the Free Software Foundation, 65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 65.21 + * 65.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 65.23 + * or visit www.oracle.com if you need additional information or have any 65.24 + * questions. 65.25 + */ 65.26 + 65.27 +/* 65.28 + * @test 65.29 + * @bug 8004102 65.30 + * @summary Add support for generic functional descriptors 65.31 + * @compile MethodReference57.java 65.32 + */ 65.33 +class MethodReference57 { 65.34 + 65.35 + interface F { 65.36 + <X> void m(); 65.37 + } 65.38 + 65.39 + void test() { 65.40 + F f = this::g; //ok 65.41 + } 65.42 + 65.43 + void g() { } 65.44 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 66.2 +++ b/test/tools/javac/lambda/MethodReference58.java Mon Dec 10 20:59:38 2012 -0800 66.3 @@ -0,0 +1,46 @@ 66.4 +/* 66.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 66.7 + * 66.8 + * This code is free software; you can redistribute it and/or modify it 66.9 + * under the terms of the GNU General Public License version 2 only, as 66.10 + * published by the Free Software Foundation. 66.11 + * 66.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 66.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 66.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 66.15 + * version 2 for more details (a copy is included in the LICENSE file that 66.16 + * accompanied this code). 66.17 + * 66.18 + * You should have received a copy of the GNU General Public License version 66.19 + * 2 along with this work; if not, write to the Free Software Foundation, 66.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 66.21 + * 66.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 66.23 + * or visit www.oracle.com if you need additional information or have any 66.24 + * questions. 66.25 + */ 66.26 + 66.27 +/* 66.28 + * @test 66.29 + * @bug 8004102 66.30 + * @summary Add support for generic functional descriptors 66.31 + * @compile/fail/ref=MethodReference58.out -XDrawDiagnostics MethodReference58.java 66.32 + */ 66.33 +class MethodReference58 { 66.34 + 66.35 + interface F_Object { 66.36 + <X> void m(X x); 66.37 + } 66.38 + 66.39 + interface F_Integer { 66.40 + <X extends Integer> void m(X x); 66.41 + } 66.42 + 66.43 + void test() { 66.44 + F_Object f1 = this::g; //incompatible bounds 66.45 + F_Integer f2 = this::g; //ok 66.46 + } 66.47 + 66.48 + <Z extends Number> void g(Z z) { } 66.49 +}
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 67.2 +++ b/test/tools/javac/lambda/MethodReference58.out Mon Dec 10 20:59:38 2012 -0800 67.3 @@ -0,0 +1,2 @@ 67.4 +MethodReference58.java:41:23: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, g, Z, X, kindname.class, MethodReference58, (compiler.misc.inferred.do.not.conform.to.upper.bounds: X, java.lang.Number))) 67.5 +1 error
68.1 --- a/test/tools/javac/lambda/VoidCompatibility.out Thu Dec 06 12:04:44 2012 -0800 68.2 +++ b/test/tools/javac/lambda/VoidCompatibility.out Mon Dec 10 20:59:38 2012 -0800 68.3 @@ -1,2 +1,3 @@ 68.4 +VoidCompatibility.java:17:9: compiler.err.ref.ambiguous: schedule, kindname.method, schedule(VoidCompatibility.Runnable), VoidCompatibility, kindname.method, schedule(VoidCompatibility.Thunk<?>), VoidCompatibility 68.5 VoidCompatibility.java:23:9: compiler.err.ref.ambiguous: schedule, kindname.method, schedule(VoidCompatibility.Runnable), VoidCompatibility, kindname.method, schedule(VoidCompatibility.Thunk<?>), VoidCompatibility 68.6 -1 error 68.7 +2 errors
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 69.2 +++ b/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Mon Dec 10 20:59:38 2012 -0800 69.3 @@ -0,0 +1,294 @@ 69.4 +/* 69.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 69.7 + * 69.8 + * This code is free software; you can redistribute it and/or modify it 69.9 + * under the terms of the GNU General Public License version 2 only, as 69.10 + * published by the Free Software Foundation. 69.11 + * 69.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 69.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 69.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 69.15 + * version 2 for more details (a copy is included in the LICENSE file that 69.16 + * accompanied this code). 69.17 + * 69.18 + * You should have received a copy of the GNU General Public License version 69.19 + * 2 along with this work; if not, write to the Free Software Foundation, 69.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 69.21 + * 69.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 69.23 + * or visit www.oracle.com if you need additional information or have any 69.24 + * questions. 69.25 + */ 69.26 + 69.27 +/* 69.28 + * @test 69.29 + * @bug 8002099 69.30 + * @summary Add support for intersection types in cast expression 69.31 + */ 69.32 + 69.33 +import com.sun.source.util.JavacTask; 69.34 +import com.sun.tools.javac.util.List; 69.35 +import com.sun.tools.javac.util.ListBuffer; 69.36 +import java.net.URI; 69.37 +import java.util.Arrays; 69.38 +import javax.tools.Diagnostic; 69.39 +import javax.tools.JavaCompiler; 69.40 +import javax.tools.JavaFileObject; 69.41 +import javax.tools.SimpleJavaFileObject; 69.42 +import javax.tools.StandardJavaFileManager; 69.43 +import javax.tools.ToolProvider; 69.44 + 69.45 +public class IntersectionTargetTypeTest { 69.46 + 69.47 + static int checkCount = 0; 69.48 + 69.49 + enum BoundKind { 69.50 + INTF, 69.51 + CLASS, 69.52 + SAM, 69.53 + ZAM; 69.54 + } 69.55 + 69.56 + enum MethodKind { 69.57 + NONE, 69.58 + ABSTRACT, 69.59 + DEFAULT; 69.60 + } 69.61 + 69.62 + enum TypeKind { 69.63 + A("interface A { }\n", "A", BoundKind.ZAM), 69.64 + B("interface B { default void m() { } }\n", "B", BoundKind.ZAM), 69.65 + C("interface C { void m(); }\n", "C", BoundKind.SAM), 69.66 + D("interface D extends B { }\n", "D", BoundKind.ZAM), 69.67 + E("interface E extends C { }\n", "E", BoundKind.SAM), 69.68 + F("interface F extends C { void g(); }\n", "F", BoundKind.INTF), 69.69 + G("interface G extends B { void g(); }\n", "G", BoundKind.SAM), 69.70 + H("interface H extends A { void g(); }\n", "H", BoundKind.SAM), 69.71 + OBJECT("", "Object", BoundKind.CLASS), 69.72 + STRING("", "String", BoundKind.CLASS); 69.73 + 69.74 + String declStr; 69.75 + String typeStr; 69.76 + BoundKind boundKind; 69.77 + 69.78 + private TypeKind(String declStr, String typeStr, BoundKind boundKind) { 69.79 + this.declStr = declStr; 69.80 + this.typeStr = typeStr; 69.81 + this.boundKind = boundKind; 69.82 + } 69.83 + 69.84 + boolean compatibleSupertype(TypeKind tk) { 69.85 + if (tk == this) return true; 69.86 + switch (tk) { 69.87 + case B: 69.88 + return this != C && this != E && this != F; 69.89 + case C: 69.90 + return this != B && this != C && this != D && this != G; 69.91 + case D: return compatibleSupertype(B); 69.92 + case E: 69.93 + case F: return compatibleSupertype(C); 69.94 + case G: return compatibleSupertype(B); 69.95 + case H: return compatibleSupertype(A); 69.96 + default: 69.97 + return true; 69.98 + } 69.99 + } 69.100 + } 69.101 + 69.102 + enum CastKind { 69.103 + ONE_ARY("(#B0)", 1), 69.104 + TWO_ARY("(#B0 & #B1)", 2), 69.105 + THREE_ARY("(#B0 & #B1 & #B2)", 3); 69.106 + 69.107 + String castTemplate; 69.108 + int nbounds; 69.109 + 69.110 + CastKind(String castTemplate, int nbounds) { 69.111 + this.castTemplate = castTemplate; 69.112 + this.nbounds = nbounds; 69.113 + } 69.114 + } 69.115 + 69.116 + enum ExpressionKind { 69.117 + LAMBDA("()->{}", true), 69.118 + MREF("this::m", true), 69.119 + //COND_LAMBDA("(true ? ()->{} : ()->{})", true), re-enable if spec allows this 69.120 + //COND_MREF("(true ? this::m : this::m)", true), 69.121 + STANDALONE("null", false); 69.122 + 69.123 + String exprString; 69.124 + boolean isFunctional; 69.125 + 69.126 + private ExpressionKind(String exprString, boolean isFunctional) { 69.127 + this.exprString = exprString; 69.128 + this.isFunctional = isFunctional; 69.129 + } 69.130 + } 69.131 + 69.132 + static class CastInfo { 69.133 + CastKind kind; 69.134 + TypeKind[] types; 69.135 + 69.136 + CastInfo(CastKind kind, TypeKind... types) { 69.137 + this.kind = kind; 69.138 + this.types = types; 69.139 + } 69.140 + 69.141 + String getCast() { 69.142 + String temp = kind.castTemplate; 69.143 + for (int i = 0; i < kind.nbounds ; i++) { 69.144 + temp = temp.replace(String.format("#B%d", i), types[i].typeStr); 69.145 + } 69.146 + return temp; 69.147 + } 69.148 + 69.149 + boolean wellFormed() { 69.150 + //check for duplicate types 69.151 + for (int i = 0 ; i < types.length ; i++) { 69.152 + for (int j = 0 ; j < types.length ; j++) { 69.153 + if (i != j && types[i] == types[j]) { 69.154 + return false; 69.155 + } 69.156 + } 69.157 + } 69.158 + //check that classes only appear as first bound 69.159 + boolean classOk = true; 69.160 + for (int i = 0 ; i < types.length ; i++) { 69.161 + if (types[i].boundKind == BoundKind.CLASS && 69.162 + !classOk) { 69.163 + return false; 69.164 + } 69.165 + classOk = false; 69.166 + } 69.167 + //check that supertypes are mutually compatible 69.168 + for (int i = 0 ; i < types.length ; i++) { 69.169 + for (int j = 0 ; j < types.length ; j++) { 69.170 + if (!types[i].compatibleSupertype(types[j]) && i != j) { 69.171 + return false; 69.172 + } 69.173 + } 69.174 + } 69.175 + return true; 69.176 + } 69.177 + } 69.178 + 69.179 + public static void main(String... args) throws Exception { 69.180 + //create default shared JavaCompiler - reused across multiple compilations 69.181 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 69.182 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 69.183 + 69.184 + for (CastInfo cInfo : allCastInfo()) { 69.185 + for (ExpressionKind ek : ExpressionKind.values()) { 69.186 + new IntersectionTargetTypeTest(cInfo, ek).run(comp, fm); 69.187 + } 69.188 + } 69.189 + System.out.println("Total check executed: " + checkCount); 69.190 + } 69.191 + 69.192 + static List<CastInfo> allCastInfo() { 69.193 + ListBuffer<CastInfo> buf = ListBuffer.lb(); 69.194 + for (CastKind kind : CastKind.values()) { 69.195 + for (TypeKind b1 : TypeKind.values()) { 69.196 + if (kind.nbounds == 1) { 69.197 + buf.append(new CastInfo(kind, b1)); 69.198 + continue; 69.199 + } else { 69.200 + for (TypeKind b2 : TypeKind.values()) { 69.201 + if (kind.nbounds == 2) { 69.202 + buf.append(new CastInfo(kind, b1, b2)); 69.203 + continue; 69.204 + } else { 69.205 + for (TypeKind b3 : TypeKind.values()) { 69.206 + buf.append(new CastInfo(kind, b1, b2, b3)); 69.207 + } 69.208 + } 69.209 + } 69.210 + } 69.211 + } 69.212 + } 69.213 + return buf.toList(); 69.214 + } 69.215 + 69.216 + CastInfo cInfo; 69.217 + ExpressionKind ek; 69.218 + JavaSource source; 69.219 + DiagnosticChecker diagChecker; 69.220 + 69.221 + IntersectionTargetTypeTest(CastInfo cInfo, ExpressionKind ek) { 69.222 + this.cInfo = cInfo; 69.223 + this.ek = ek; 69.224 + this.source = new JavaSource(); 69.225 + this.diagChecker = new DiagnosticChecker(); 69.226 + } 69.227 + 69.228 + class JavaSource extends SimpleJavaFileObject { 69.229 + 69.230 + String bodyTemplate = "class Test {\n" + 69.231 + " void m() { }\n" + 69.232 + " void test() {\n" + 69.233 + " Object o = #C#E;\n" + 69.234 + " } }"; 69.235 + 69.236 + String source = ""; 69.237 + 69.238 + public JavaSource() { 69.239 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 69.240 + for (TypeKind tk : TypeKind.values()) { 69.241 + source += tk.declStr; 69.242 + } 69.243 + source += bodyTemplate.replaceAll("#C", cInfo.getCast()).replaceAll("#E", ek.exprString); 69.244 + } 69.245 + 69.246 + @Override 69.247 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 69.248 + return source; 69.249 + } 69.250 + } 69.251 + 69.252 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 69.253 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 69.254 + Arrays.asList("-XDallowIntersectionTypes"), null, Arrays.asList(source)); 69.255 + try { 69.256 + ct.analyze(); 69.257 + } catch (Throwable ex) { 69.258 + throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true)); 69.259 + } 69.260 + check(); 69.261 + } 69.262 + 69.263 + void check() { 69.264 + checkCount++; 69.265 + 69.266 + boolean errorExpected = !cInfo.wellFormed(); 69.267 + 69.268 + if (ek.isFunctional) { 69.269 + //first bound must be a SAM 69.270 + errorExpected |= cInfo.types[0].boundKind != BoundKind.SAM; 69.271 + if (cInfo.types.length > 1) { 69.272 + //additional bounds must be ZAMs 69.273 + for (int i = 1; i < cInfo.types.length; i++) { 69.274 + errorExpected |= cInfo.types[i].boundKind != BoundKind.ZAM; 69.275 + } 69.276 + } 69.277 + } 69.278 + 69.279 + if (errorExpected != diagChecker.errorFound) { 69.280 + throw new Error("invalid diagnostics for source:\n" + 69.281 + source.getCharContent(true) + 69.282 + "\nFound error: " + diagChecker.errorFound + 69.283 + "\nExpected error: " + errorExpected); 69.284 + } 69.285 + } 69.286 + 69.287 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 69.288 + 69.289 + boolean errorFound; 69.290 + 69.291 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 69.292 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 69.293 + errorFound = true; 69.294 + } 69.295 + } 69.296 + } 69.297 +}
70.1 --- a/test/tools/javac/lambda/methodReference/MethodRef1.java Thu Dec 06 12:04:44 2012 -0800 70.2 +++ b/test/tools/javac/lambda/methodReference/MethodRef1.java Mon Dec 10 20:59:38 2012 -0800 70.3 @@ -70,9 +70,6 @@ 70.4 b = MethodRef1::foo; //static reference to foo(int) 70.5 b.m(1); 70.6 70.7 - b = new MethodRef1()::foo; //instance reference to static methods, supported for now 70.8 - b.m(1); 70.9 - 70.10 b = MethodRef1::bar; //static reference to bar(int) 70.11 b.m(2); 70.12
71.1 --- a/test/tools/javac/lambda/methodReference/SamConversion.java Thu Dec 06 12:04:44 2012 -0800 71.2 +++ b/test/tools/javac/lambda/methodReference/SamConversion.java Mon Dec 10 20:59:38 2012 -0800 71.3 @@ -133,15 +133,6 @@ 71.4 } catch (Exception e) { 71.5 assertTrue(false); 71.6 } 71.7 - 71.8 - bar = new A()::method6; 71.9 - try { 71.10 - bar.m(1); 71.11 - assertTrue(false); 71.12 - } catch (MyException e) { 71.13 - } catch (Exception e) { 71.14 - assertTrue(false); 71.15 - } 71.16 } 71.17 71.18 /**
72.1 --- a/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestKinds.java Thu Dec 06 12:04:44 2012 -0800 72.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestKinds.java Mon Dec 10 20:59:38 2012 -0800 72.3 @@ -119,20 +119,6 @@ 72.4 assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); 72.5 } 72.6 72.7 - public void testMRStaticEval() { 72.8 - MethodReferenceTestKinds evalCheck; 72.9 - S0 var = (evalCheck = inst("discard"))::staticMethod0; 72.10 - assertEquals(evalCheck.toString(), "MethodReferenceTestKinds(discard)"); 72.11 - assertEquals(var.get(), "SM:0"); 72.12 - } 72.13 - 72.14 - public void testMRStaticEvalArg() { 72.15 - MethodReferenceTestKinds evalCheck; 72.16 - S1 var = (evalCheck = inst("discard"))::staticMethod1; 72.17 - assertEquals(evalCheck.toString(), "MethodReferenceTestKinds(discard)"); 72.18 - assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); 72.19 - } 72.20 - 72.21 public void testMRTopLevel() { 72.22 SN0 var = MethodReferenceTestKindsBase::new; 72.23 assertEquals(var.make().toString(), "MethodReferenceTestKindsBase(blank)"); 72.24 @@ -142,17 +128,7 @@ 72.25 SN1 var = MethodReferenceTestKindsBase::new; 72.26 assertEquals(var.make("name").toString(), "MethodReferenceTestKindsBase(name)"); 72.27 } 72.28 -/* unbound inner case not supported anymore (dropped by EG) 72.29 - public void testMRUnboundInner() { 72.30 - SXN0 var = MethodReferenceTestKinds.In::new; 72.31 - assertEquals(var.make(inst("out")).toString(), "In(blank)"); 72.32 - } 72.33 72.34 - public void testMRUnboundInnerArg() { 72.35 - SXN1 var = MethodReferenceTestKinds.In::new; 72.36 - assertEquals(var.make(inst("out"), "name").toString(), "In(name)"); 72.37 - } 72.38 -*/ 72.39 public void testMRImplicitInner() { 72.40 SN0 var = MethodReferenceTestKinds.In::new; 72.41 assertEquals(var.make().toString(), "In(blank)");
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/test/tools/javap/T7190862.java Mon Dec 10 20:59:38 2012 -0800 73.3 @@ -0,0 +1,157 @@ 73.4 + 73.5 +/* 73.6 + * @test /nodynamiccopyright/ 73.7 + * @bug 7190862 7109747 73.8 + * @summary javap shows an incorrect type for operands if the 'wide' prefix is used 73.9 + */ 73.10 + 73.11 +import com.sun.source.util.JavacTask; 73.12 +import com.sun.tools.javap.JavapFileManager; 73.13 +import com.sun.tools.javap.JavapTask; 73.14 +import java.io.PrintWriter; 73.15 +import java.io.StringWriter; 73.16 +import java.net.URI; 73.17 +import java.util.Arrays; 73.18 +import java.util.List; 73.19 +import java.util.Locale; 73.20 +import javax.tools.Diagnostic; 73.21 +import javax.tools.DiagnosticCollector; 73.22 +import javax.tools.JavaCompiler; 73.23 +import javax.tools.JavaFileManager; 73.24 +import javax.tools.JavaFileObject; 73.25 +import javax.tools.SimpleJavaFileObject; 73.26 +import javax.tools.ToolProvider; 73.27 + 73.28 +public class T7190862 { 73.29 + 73.30 + enum TypeWideInstructionMap { 73.31 + INT("int", new String[]{"istore_w", "iload_w"}), 73.32 + LONG("long", new String[]{"lstore_w", "lload_w"}), 73.33 + FLOAT("float", new String[]{"fstore_w", "fload_w"}), 73.34 + DOUBLE("double", new String[]{"dstore_w", "dload_w"}), 73.35 + OBJECT("Object", new String[]{"astore_w", "aload_w"}); 73.36 + 73.37 + String type; 73.38 + String[] instructions; 73.39 + 73.40 + TypeWideInstructionMap(String type, String[] instructions) { 73.41 + this.type = type; 73.42 + this.instructions = instructions; 73.43 + } 73.44 + } 73.45 + 73.46 + JavaSource source; 73.47 + 73.48 + public static void main(String[] args) { 73.49 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 73.50 + new T7190862().run(comp); 73.51 + } 73.52 + 73.53 + private void run(JavaCompiler comp) { 73.54 + String code; 73.55 + for (TypeWideInstructionMap typeInstructionMap: TypeWideInstructionMap.values()) { 73.56 + if (typeInstructionMap != TypeWideInstructionMap.OBJECT) { 73.57 + code = createWideLocalSource(typeInstructionMap.type, 300); 73.58 + } else { 73.59 + code = createWideLocalSourceForObject(300); 73.60 + } 73.61 + source = new JavaSource(code); 73.62 + compile(comp); 73.63 + check(typeInstructionMap.instructions); 73.64 + } 73.65 + 73.66 + //an extra test for the iinc instruction 73.67 + code = createIincSource(); 73.68 + source = new JavaSource(code); 73.69 + compile(comp); 73.70 + check(new String[]{"iinc_w"}); 73.71 + } 73.72 + 73.73 + private void compile(JavaCompiler comp) { 73.74 + JavacTask ct = (JavacTask)comp.getTask(null, null, null, null, null, Arrays.asList(source)); 73.75 + try { 73.76 + if (!ct.call()) { 73.77 + throw new AssertionError("Error thrown when compiling the following source:\n" + source.getCharContent(true)); 73.78 + } 73.79 + } catch (Throwable ex) { 73.80 + throw new AssertionError("Error thrown when compiling the following source:\n" + source.getCharContent(true)); 73.81 + } 73.82 + } 73.83 + 73.84 + private void check(String[] instructions) { 73.85 + String out = javap(Arrays.asList("-c"), Arrays.asList("Test.class")); 73.86 + for (String line: out.split(System.getProperty("line.separator"))) { 73.87 + line = line.trim(); 73.88 + for (String instruction: instructions) { 73.89 + if (line.contains(instruction) && line.contains("#")) { 73.90 + throw new Error("incorrect type for operands for instruction " + instruction); 73.91 + } 73.92 + } 73.93 + } 73.94 + } 73.95 + 73.96 + private String javap(List<String> args, List<String> classes) { 73.97 + DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>(); 73.98 + StringWriter sw = new StringWriter(); 73.99 + PrintWriter pw = new PrintWriter(sw); 73.100 + JavaFileManager fm = JavapFileManager.create(dc, pw); 73.101 + JavapTask t = new JavapTask(pw, fm, dc, args, classes); 73.102 + boolean ok = t.run(); 73.103 + if (!ok) 73.104 + throw new Error("javap failed unexpectedly"); 73.105 + 73.106 + List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics(); 73.107 + for (Diagnostic<? extends JavaFileObject> d: diags) { 73.108 + if (d.getKind() == Diagnostic.Kind.ERROR) 73.109 + throw new Error(d.getMessage(Locale.ENGLISH)); 73.110 + } 73.111 + return sw.toString(); 73.112 + 73.113 + } 73.114 + 73.115 + private String createWideLocalSource(String type, int numberOfVars) { 73.116 + String result = " " + type + " x0 = 0;\n"; 73.117 + for (int i = 1; i < numberOfVars; i++) { 73.118 + result += " " + type + " x" + i + " = x" + (i - 1) + " + 1;\n"; 73.119 + } 73.120 + return result; 73.121 + } 73.122 + 73.123 + private String createWideLocalSourceForObject(int numberOfVars) { 73.124 + String result = " Object x0 = new Object();\n"; 73.125 + for (int i = 1; i < numberOfVars; i++) { 73.126 + result += " Object x" + i + " = x0;\n"; 73.127 + } 73.128 + return result; 73.129 + } 73.130 + 73.131 + private String createIincSource() { 73.132 + return " int i = 0;\n" 73.133 + + " i += 1;\n" 73.134 + + " i += 51;\n" 73.135 + + " i += 101;\n" 73.136 + + " i += 151;\n"; 73.137 + } 73.138 + 73.139 + class JavaSource extends SimpleJavaFileObject { 73.140 + 73.141 + String template = "class Test {\n" + 73.142 + " public static void main(String[] args)\n" + 73.143 + " {\n" + 73.144 + " #C" + 73.145 + " }\n" + 73.146 + "}"; 73.147 + 73.148 + String source; 73.149 + 73.150 + public JavaSource(String code) { 73.151 + super(URI.create("Test.java"), JavaFileObject.Kind.SOURCE); 73.152 + source = template.replaceAll("#C", code); 73.153 + } 73.154 + 73.155 + @Override 73.156 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 73.157 + return source; 73.158 + } 73.159 + } 73.160 +}