Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 193951 Details for
Bug 339478
[1.7][compiler] support for diamond case
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Revised Implementation v0.98
patch.txt (text/plain), 34.12 KB, created by
Srikanth Sankaran
on 2011-04-23 03:50:16 EDT
(
hide
)
Description:
Revised Implementation v0.98
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-04-23 03:50:16 EDT
Size:
34.12 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java,v >retrieving revision 1.84.2.6 >diff -u -r1.84.2.6 AllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 23 Apr 2011 07:21:32 -0000 1.84.2.6 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 23 Apr 2011 07:47:39 -0000 >@@ -17,12 +17,14 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.ast; > >+import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.internal.compiler.ASTVisitor; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.codegen.*; > import org.eclipse.jdt.internal.compiler.flow.*; > import org.eclipse.jdt.internal.compiler.impl.Constant; > import org.eclipse.jdt.internal.compiler.lookup.*; >+import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; > > public class AllocationExpression extends Expression implements InvocationSite { > >@@ -33,6 +35,7 @@ > public TypeReference[] typeArguments; > public TypeBinding[] genericTypeArguments; > public FieldDeclaration enumConstant; // for enum constant initializations >+ private TypeBinding expectedTypeForInference; // for <> inference > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { > // check captured variables are initialized in current context (26134) >@@ -359,6 +362,11 @@ > scope.problemReporter().cannotInstantiate(this.type, this.resolvedType); > return this.resolvedType; > } >+ if (this.type != null && this.resolvedType != null && (this.type.bits & ASTNode.IsDiamond) != 0) { >+ TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), argumentTypes, scope); >+ this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType()); >+ // TODO(Srikanth) : inject inferred arguments ?? >+ } > ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType; > if (!(this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) { > if (this.binding.declaringClass == null) { >@@ -384,6 +392,149 @@ > return allocationType; > } > >+public TypeBinding[] inferElidedTypes(ReferenceBinding allocationType, TypeBinding[] argumentTypes, final BlockScope scope) { >+ MethodBinding factory = getStaticFactory(allocationType, argumentTypes, scope); >+ if (factory instanceof ParameterizedGenericMethodBinding) { >+ return ((ParameterizedTypeBinding)factory.returnType).arguments; >+ } >+ int arity = allocationType.typeVariables().length; >+ TypeBinding [] inferredTypes = new TypeBinding[arity]; >+ for (int i = 0; i < arity; i++) { >+ inferredTypes[i] = new ProblemReferenceBinding(CharOperation.NO_CHAR_CHAR, null, ProblemReasons.InferenceFailed); >+ } >+ return inferredTypes; >+} >+ >+private MethodBinding getStaticFactory (ReferenceBinding allocationType, TypeBinding[] argumentTypes, final BlockScope scope) { >+ TypeVariableBinding[] classTypeVariables = allocationType.typeVariables(); >+ int classTypeVariablesArity = classTypeVariables.length; >+ MethodBinding[] methods = allocationType.getMethods(TypeConstants.INIT, argumentTypes.length); >+ MethodBinding [] staticFactories = new MethodBinding[methods.length]; >+ int sfi = 0; >+ for (int i = 0, length = methods.length; i < length; i++) { >+ MethodBinding method = methods[i]; >+ >+ TypeVariableBinding[] methodTypeVariables = method.typeVariables(); >+ int methodTypeVariablesArity = methodTypeVariables.length; >+ >+ if (this.genericTypeArguments != null && this.genericTypeArguments.length < methodTypeVariablesArity) >+ continue; // wrong tree, don't bark. >+ MethodBinding staticFactory = new MethodBinding(method.modifiers | ClassFileConstants.AccStatic, TypeConstants.SYNTHETIC_STATIC_FACTORY, >+ null, null, null, method.declaringClass); >+ staticFactory.typeVariables = new TypeVariableBinding[classTypeVariablesArity + (this.genericTypeArguments == null ? methodTypeVariablesArity : 0)]; >+ final SimpleLookupTable map = new SimpleLookupTable(classTypeVariablesArity + methodTypeVariablesArity); >+ // Rename each type variable T of the type to T' >+ for (int j = 0; j < classTypeVariablesArity; j++) { >+ map.put(classTypeVariables[j], staticFactory.typeVariables[j] = new TypeVariableBinding(CharOperation.concat(classTypeVariables[j].sourceName, "'".toCharArray()), //$NON-NLS-1$ >+ staticFactory, j, scope.environment())); >+ } >+ // Rename each type variable U of method U to U'' if not explicitly parameterized. Otherwise use the parameterizing type. >+ for (int j = classTypeVariablesArity, max = classTypeVariablesArity + methodTypeVariablesArity; j < max; j++) { >+ map.put(methodTypeVariables[j - classTypeVariablesArity], >+ this.genericTypeArguments != null ? this.genericTypeArguments[j - classTypeVariablesArity] : >+ (staticFactory.typeVariables[j] = new TypeVariableBinding(CharOperation.concat(methodTypeVariables[j - classTypeVariablesArity].sourceName, "''".toCharArray()), //$NON-NLS-1$ >+ staticFactory, j, scope.environment()))); >+ } >+ >+ Substitution substitution = new Substitution() { >+ public LookupEnvironment environment() { >+ return scope.environment(); >+ } >+ public boolean isRawSubstitution() { >+ return false; >+ } >+ public TypeBinding substitute(TypeVariableBinding typeVariable) { >+ return (TypeBinding) map.get(typeVariable); >+ } >+ }; >+ >+ staticFactory.parameters = Scope.substitute(substitution, method.parameters); >+ >+ // initialize new variable bounds >+ for (int j = 0, max = classTypeVariablesArity + methodTypeVariablesArity; j < max; j++) { >+ TypeVariableBinding originalVariable = j < classTypeVariablesArity ? classTypeVariables[j] : methodTypeVariables[j - classTypeVariablesArity]; >+ TypeBinding substitutedType = (TypeBinding) map.get(originalVariable); >+ if (substitutedType instanceof TypeVariableBinding) { >+ TypeVariableBinding substitutedVariable = (TypeVariableBinding) substitutedType; >+ TypeBinding substitutedSuperclass = Scope.substitute(substitution, originalVariable.superclass); >+ ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitution, originalVariable.superInterfaces); >+ if (originalVariable.firstBound != null) { >+ substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass >+ ? substitutedSuperclass // could be array type or interface >+ : substitutedInterfaces[0]; >+ } >+ switch (substitutedSuperclass.kind()) { >+ case Binding.ARRAY_TYPE : >+ substitutedVariable.superclass = scope.environment().getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); >+ substitutedVariable.superInterfaces = substitutedInterfaces; >+ break; >+ default: >+ if (substitutedSuperclass.isInterface()) { >+ substitutedVariable.superclass = scope.environment().getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); >+ int interfaceCount = substitutedInterfaces.length; >+ System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount+1], 1, interfaceCount); >+ substitutedInterfaces[0] = (ReferenceBinding) substitutedSuperclass; >+ substitutedVariable.superInterfaces = substitutedInterfaces; >+ } else { >+ substitutedVariable.superclass = (ReferenceBinding) substitutedSuperclass; // typeVar was extending other typeVar which got substituted with interface >+ substitutedVariable.superInterfaces = substitutedInterfaces; >+ } >+ } >+ } >+ } >+ TypeVariableBinding[] returnTypeParameters = new TypeVariableBinding[classTypeVariablesArity]; >+ for (int j = 0; j < classTypeVariablesArity; j++) { >+ returnTypeParameters[j] = (TypeVariableBinding) map.get(classTypeVariables[j]); >+ } >+ staticFactory.returnType = scope.environment().createParameterizedType(allocationType, returnTypeParameters, allocationType.enclosingType()); >+ staticFactory.thrownExceptions = Scope.substitute(substitution, method.thrownExceptions); >+ if (staticFactory.thrownExceptions == null) { >+ staticFactory.thrownExceptions = Binding.NO_EXCEPTIONS; >+ } >+ staticFactories[sfi++] = new ParameterizedMethodBinding((ParameterizedTypeBinding) scope.environment().convertToParameterizedType(staticFactory.declaringClass), >+ staticFactory); >+ } >+ if (sfi != methods.length) { >+ System.arraycopy(staticFactories, 0, staticFactories = new MethodBinding[sfi], 0, sfi); >+ } >+ final InvocationSite allocationSite = this; >+ InvocationSite site = new InvocationSite() { // Alternate site to not expose the generic type arguments as they have already been substituted. >+ public int sourceStart() { return allocationSite.sourceStart(); } >+ public int sourceEnd() { return allocationSite.sourceEnd(); } >+ public void setFieldIndex(int depth) { allocationSite.setFieldIndex(depth); } >+ public void setDepth(int depth) { allocationSite.setDepth(depth);} >+ public void setActualReceiverType(ReferenceBinding receiverType) { allocationSite.setActualReceiverType(receiverType);} >+ public boolean isTypeAccess() { return allocationSite.isTypeAccess(); } >+ public boolean isSuperAccess() { return allocationSite.isSuperAccess(); } >+ public TypeBinding[] genericTypeArguments() { return null; } >+ public TypeBinding expectedType() { return allocationSite.expectedType(); } >+ }; >+ MethodBinding[] compatible = new MethodBinding[sfi]; >+ int compatibleIndex = 0; >+ for (int i = 0; i < sfi; i++) { >+ MethodBinding compatibleMethod = scope.computeCompatibleMethod(staticFactories[i], argumentTypes, site); >+ if (compatibleMethod != null) { >+ if (compatibleMethod.isValidBinding()) >+ compatible[compatibleIndex++] = compatibleMethod; >+ } >+ } >+ >+ if (compatibleIndex == 0) { >+ return null; >+ } >+ MethodBinding[] visible = new MethodBinding[compatibleIndex]; >+ int visibleIndex = 0; >+ for (int i = 0; i < compatibleIndex; i++) { >+ MethodBinding method = compatible[i]; >+ if (method.canBeSeenBy(this, scope)) >+ visible[visibleIndex++] = method; >+ } >+ if (visibleIndex == 0) { >+ return null; >+ } >+ return visibleIndex == 1 ? visible[0] : scope.mostSpecificMethodBinding(visible, visibleIndex, argumentTypes, this, allocationType); >+} >+ > public void setActualReceiverType(ReferenceBinding receiverType) { > // ignored > } >@@ -413,4 +564,17 @@ > } > visitor.endVisit(this, scope); > } >+/** >+ * @see org.eclipse.jdt.internal.compiler.ast.Expression#setExpectedType(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) >+ */ >+public void setExpectedType(TypeBinding expectedType) { >+ this.expectedTypeForInference = expectedType; >+} >+/** >+ * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#expectedType() >+ */ >+public TypeBinding expectedType() { >+ return this.expectedTypeForInference; >+} >+ > } >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java,v >retrieving revision 1.63.2.6 >diff -u -r1.63.2.6 ParameterizedQualifiedTypeReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java 19 Apr 2011 21:36:37 -0000 1.63.2.6 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java 23 Apr 2011 07:47:40 -0000 >@@ -268,7 +268,7 @@ > // check argument type compatibility > if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution > parameterizedType.boundCheck(scope, args); >- else >+ else if (!isDiamond) > scope.deferBoundCheck(this); > qualifyingType = parameterizedType; > } else { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java,v >retrieving revision 1.54.2.6 >diff -u -r1.54.2.6 ParameterizedSingleTypeReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java 19 Apr 2011 21:36:37 -0000 1.54.2.6 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java 23 Apr 2011 07:47:40 -0000 >@@ -245,7 +245,7 @@ > // check argument type compatibility > if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution > parameterizedType.boundCheck(scope, this.typeArguments); >- else >+ else if ((this.bits & ASTNode.IsDiamond) == 0) > scope.deferBoundCheck(this); > if (isTypeUseDeprecated(parameterizedType, scope)) > reportDeprecatedType(parameterizedType, scope); >Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java,v >retrieving revision 1.101.2.5 >diff -u -r1.101.2.5 QualifiedAllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 23 Apr 2011 07:21:32 -0000 1.101.2.5 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 23 Apr 2011 07:47:40 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; > import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; >+import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding; > import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; > import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding; >@@ -385,6 +386,10 @@ > scope.problemReporter().cannotInstantiate(this.type, receiverType); > return this.resolvedType = receiverType; > } >+ if (this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0) { >+ TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), argumentTypes, scope); >+ receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType()); >+ } > ReferenceBinding allocationType = (ReferenceBinding) receiverType; > if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) { > if (isMethodUseDeprecated(this.binding, scope, true)) { >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java,v >retrieving revision 1.14.28.1 >diff -u -r1.14.28.1 ProblemReasons.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java 2 Mar 2011 11:56:58 -0000 1.14.28.1 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java 23 Apr 2011 07:47:40 -0000 >@@ -31,4 +31,5 @@ > final int TypeArgumentsForRawGenericMethod = 13; // for generic method > final int InvalidTypeForStaticImport = 14; > final int InvalidTypeForAutoManagedResource = 15; >+ final int InferenceFailed = 16; > } >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v >retrieving revision 1.380.2.3 >diff -u -r1.380.2.3 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 15 Feb 2011 05:43:47 -0000 1.380.2.3 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 23 Apr 2011 07:47:43 -0000 >@@ -511,7 +511,7 @@ > * Will answer a substituted method in case the method was generic and type inference got triggered; > * in case the method was originally compatible, then simply answer it back. > */ >- protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) { >+ public final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) { > TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments(); > TypeBinding[] parameters = method.parameters; > TypeVariableBinding[] typeVariables = method.typeVariables; >@@ -3686,7 +3686,7 @@ > } > > // caveat: this is not a direct implementation of JLS >- protected final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, int visibleSize, TypeBinding[] argumentTypes, final InvocationSite invocationSite, ReferenceBinding receiverType) { >+ public final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, int visibleSize, TypeBinding[] argumentTypes, final InvocationSite invocationSite, ReferenceBinding receiverType) { > int[] compatibilityLevels = new int[visibleSize]; > for (int i = 0; i < visibleSize; i++) > compatibilityLevels[i] = parameterCompatibilityLevel(visible[i], argumentTypes); >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java,v >retrieving revision 1.51.2.4 >diff -u -r1.51.2.4 TypeConstants.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java 19 Apr 2011 13:09:09 -0000 1.51.2.4 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java 23 Apr 2011 07:47:43 -0000 >@@ -170,6 +170,7 @@ > char[] SYNTHETIC_ENCLOSING_INSTANCE_PREFIX = "this$".toCharArray(); //$NON-NLS-1$ > char[] SYNTHETIC_ACCESS_METHOD_PREFIX = "access$".toCharArray(); //$NON-NLS-1$ > char[] SYNTHETIC_ENUM_CONSTANT_INITIALIZATION_METHOD_PREFIX = " enum constant initialization$".toCharArray(); //$NON-NLS-1$ >+ char[] SYNTHETIC_STATIC_FACTORY = "<factory>".toCharArray(); //$NON-NLS-1$ > > // synthetic package-info name > public static final char[] PACKAGE_INFO_NAME = "package-info".toCharArray(); //$NON-NLS-1$ >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Attic/GenericsRegressionTest_1_7.java,v >retrieving revision 1.1.2.6 >diff -u -r1.1.2.6 GenericsRegressionTest_1_7.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java 19 Apr 2011 12:10:01 -0000 1.1.2.6 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java 23 Apr 2011 07:47:47 -0000 >@@ -18,7 +18,7 @@ > public class GenericsRegressionTest_1_7 extends AbstractRegressionTest { > > static { >-// TESTS_NAMES = new String[] { "test0014" }; >+// TESTS_NAMES = new String[] { "test0025" }; > // TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; > // TESTS_RANGE = new int[] { 11, -1 }; > } >@@ -28,7 +28,7 @@ > public static Test suite() { > return buildMinimalComplianceTestSuite(testClass(), F_1_7); > } >-public void _test001() { >+public void test001() { > this.runConformTest( > new String[] { > "X.java", >@@ -44,7 +44,7 @@ > }, > "SUCCESS"); > } >-public void _test001a() { >+public void test001a() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -65,7 +65,7 @@ > "The method testFunction(String) in the type X<String> is not applicable for the arguments (int)\n" + > "----------\n"); > } >-public void _test001b() { >+public void test001b() { > this.runConformTest( > new String[] { > "X.java", >@@ -80,7 +80,7 @@ > "SUCCESS"); > } > // fields >-public void _test001b_1() { >+public void test001b_1() { > this.runConformTest( > new String[] { > "X.java", >@@ -94,7 +94,7 @@ > }, > "SUCCESS"); > } >-public void _test001c() { >+public void test001c() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -114,7 +114,7 @@ > "----------\n"); > } > // fields >-public void _test001c_1() { >+public void test001c_1() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -133,7 +133,7 @@ > "The method add(int, String) in the type ArrayList<String> is not applicable for the arguments (int)\n" + > "----------\n"); > } >-public void _test001d() { >+public void test001d() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -155,7 +155,7 @@ > "The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + > "----------\n"); > } >-public void _test001e() { >+public void test001e() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -177,8 +177,8 @@ > "The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + > "----------\n"); > } >-public void _test001f() { >- this.runConformTest( >+public void test001f() { >+ this.runNegativeTest( > new String[] { > "X.java", > "public class X<T> {\n" + >@@ -193,7 +193,17 @@ > " }\n" + > "}", > }, >- "SUCCESS"); >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " class X2<T>{\n" + >+ " ^\n" + >+ "The type parameter T is hiding the type T\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 8)\n" + >+ " X<String>.X2<String> x = new X<>().new X2<>();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X<Object>.X2<String> to X<String>.X2<String>\n" + >+ "----------\n"); > } > // fields > public void test001f_1() { >@@ -216,8 +226,8 @@ > }, > "SUCCESS"); > } >-public void _test001g() { >- this.runConformTest( >+public void test001g() { >+ this.runNegativeTest( > new String[] { > "X.java", > "public class X<T> {\n" + >@@ -233,7 +243,12 @@ > " }\n" + > "}", > }, >- "SUCCESS\n1"); >+ "----------\n" + >+ "1. ERROR in X.java (at line 9)\n" + >+ " X<String>.X2<Integer> x = new X<>().new X2<>();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X<Object>.X2<Integer> to X<String>.X2<Integer>\n" + >+ "----------\n"); > } > public void test001g_1() { > this.runConformTest( >@@ -256,7 +271,7 @@ > }, > "SUCCESS\n1"); > } >-public void _test001h() { >+public void test001h() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -278,13 +293,18 @@ > " ^\n" + > "The type parameter T is hiding the type T\n" + > "----------\n" + >- "2. ERROR in X.java (at line 9)\n" + >+ "2. ERROR in X.java (at line 8)\n" + >+ " X<String>.X2<String> x = new X<>().new X2<>();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X<Object>.X2<String> to X<String>.X2<String>\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 9)\n" + > " x.methodx(1);\n" + > " ^^^^^^^\n" + > "The method methodx(String) in the type X<String>.X2<String> is not applicable for the arguments (int)\n" + > "----------\n"); > } >-public void _test001h_1() { >+public void test001h_1() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -329,11 +349,31 @@ > "Type safety: The method methodx(Object) belongs to the raw type X.X2. References to generic type X<T>.X2<T> should be parameterized\n" + > "----------\n"); > } >-public void _test001i() { >+public void test001h_2() { > this.runConformTest( > new String[] { > "X.java", > "public class X<T> {\n" + >+ " class X2<T>{\n" + >+ " void methodx(T param){\n" + >+ " System.out.println(param);\n" + >+ " }\n" + >+ " }\n" + >+ " X<String>.X2<String> x;\n" + >+ " public static void main(String[] args) {\n" + >+ " X test = new X();\n" + >+ " test.x = new X<>().new X2<>();\n" + >+ " test.x.methodx(1);\n" + >+ " }\n" + >+ "}", >+ }, >+ "1"); >+} >+public void test001i() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + > " class X2<K>{\n" + > " class X22<I>{\n" + > " void methodx(T param, K param2, I param3){\n" + >@@ -348,7 +388,12 @@ > " }\n" + > "}", > }, >- "SUCCESS"); >+ "----------\n" + >+ "1. ERROR in X.java (at line 10)\n" + >+ " X<String> test = new X<>(); X<String>.X2<Integer>.X22<X<String>> x = new X<>().new X2<>().new X22<>();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X<Object>.X2<Object>.X22<X<String>> to X<String>.X2<Integer>.X22<X<String>>\n" + >+ "----------\n"); > } > public void test002() { > this.runNegativeTest( >@@ -376,7 +421,7 @@ > "Type safety: The method testFunction(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + > "----------\n"); > } >-public void _test003() { >+public void test003() { > this.runConformTest( > new String[] { > "X.java", >@@ -392,7 +437,7 @@ > "SUCCESS"); > } > >-public void _test004b() { >+public void test004b() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -437,7 +482,7 @@ > "1"); > } > >-public void _test006() { >+public void test006() { > this.runConformTest( > new String[] { > "X.java", >@@ -460,7 +505,7 @@ > "SUCCESS"); > } > // shows the difference between using <> and the raw type - different semantics >-public void _test007() { >+public void test007() { > this.runConformTest( > new String[] { > "X.java", >@@ -487,7 +532,7 @@ > "1\n" + > "2"); > } >-public void _test007a() { >+public void test007a() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -529,12 +574,12 @@ > "----------\n"); > } > //shows the difference between using <> and the raw type - different semantics >-public void _test008() { >- this.runConformTest( >+public void test008() { >+ this.runNegativeTest( > new String[] { > "X.java", > "public class X<T> {\n" + >- " T field1;" + >+ " T field1;\n" + > " public X(T param){\n" + > " field1 = param;\n" + > " }\n" + >@@ -547,10 +592,30 @@ > " }\n" + > "}", > }, >- ""); >+ "----------\n" + >+ "1. WARNING in X.java (at line 7)\n" + >+ " X<?> x1 = new X(1).get(\"\");\n" + >+ " ^^^^^^^^\n" + >+ "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " X<?> x1 = new X(1).get(\"\");\n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method get(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 7)\n" + >+ " X<?> x1 = new X(1).get(\"\");\n" + >+ " ^\n" + >+ "X is a raw type. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 8)\n" + >+ " X<?> x2 = new X<>(1).get(\"\");\n" + >+ " ^^^\n" + >+ "The method get(Integer) in the type X<Integer> is not applicable for the arguments (String)\n" + >+ "----------\n"); > } > >-public void _test0014() { >+public void test0014() { > this.runConformTest( > new String[] { > "X.java", >@@ -568,7 +633,7 @@ > "SUCCESS\n" + > "123"); > } >-public void _test0014a() { >+public void test0014a() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -590,7 +655,7 @@ > "The method testFunction(String, Integer) in the type X<String,Integer> is not applicable for the arguments (int, String)\n" + > "----------\n"); > } >-public void _test0015() { >+public void test0015() { > this.runConformTest( > new String[] { > "X.java", >@@ -611,8 +676,8 @@ > } > // To verify that a parameterized invocation of a generic constructor works even if <> is used > // to elide class type parameters. >-public void _test0016() { >- this.runConformTest( >+public void test0016() { >+ this.runConformTest( // javac fails to compile this, looks buggy > new String[] { > "X.java", > "public class X<T> {\n" + >@@ -632,8 +697,8 @@ > } > // To verify that a parameterized invocation of a generic constructor works even if <> is used > // to elide class type parameters. This test handles fields >-public void _test0016b() { >- this.runConformTest( >+public void test0016b() { >+ this.runConformTest( // javac fails to compile this, looks buggy > new String[] { > "X.java", > "public class X<T> {\n" + >@@ -657,8 +722,8 @@ > // To verify that a parameterized invocation of a non-generic constructor works even if <> is used > // to elide class type parameters. > // This was not allowed in java 1.6 and 1.5 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230) >-public void _test0017() { >- this.runConformTest( >+public void test0017() { >+ this.runConformTest( // javac fails to compile this, looks buggy > new String[] { > "X.java", > "public class X<T> {\n" + >@@ -679,7 +744,7 @@ > "const.1\nconst.1\nconst.2"); > } > // To verify that the correct constructor is found by parameter substitution in the diamond case >-public void _test0018() { >+public void test0018() { > this.runConformTest( > new String[] { > "X.java", >@@ -700,7 +765,7 @@ > } > // To verify that the correct constructor is found by parameter substitution > // in the diamond case -- fields >-public void _test0018b() { >+public void test0018b() { > this.runConformTest( > new String[] { > "X.java", >@@ -738,7 +803,7 @@ > "----------\n"); > } > // check inference at method argument position. >-public void _test0020() { >+public void test0020() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -757,7 +822,7 @@ > "----------\n"); > } > //check inference at method argument position. >-public void _test0021() { >+public void test0021() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -776,7 +841,104 @@ > "The method f(List<String>) in the type X<T> is not applicable for the arguments (ArrayList<Object>)\n" + > "----------\n"); > } >- >+public void test0022() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "import java.util.HashMap;\n" + >+ "import java.util.Map;\n" + >+ "\n" + >+ "class StringKeyHashMap<V> extends HashMap<String, V> { \n" + >+ "}\n" + >+ "\n" + >+ "class IntegerValueHashMap<K> extends HashMap<K, Integer> { \n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " Map<String, Integer> m1 = new StringKeyHashMap<>();\n" + >+ " Map<String, Integer> m2 = new IntegerValueHashMap<>();\n" + >+ "}\n" >+ }, >+ ""); >+} >+public void test0023() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.HashMap;\n" + >+ "import java.util.Map;\n" + >+ "\n" + >+ "class StringKeyHashMap<V> extends HashMap<String, V> { \n" + >+ "}\n" + >+ "\n" + >+ "class IntegerValueHashMap<K> extends HashMap<K, Integer> { \n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + >+ " Map<String, Integer> m2 = new IntegerValueHashMap<>();\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 4)\n" + >+ " class StringKeyHashMap<V> extends HashMap<String, V> { \n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "The serializable class StringKeyHashMap does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " class IntegerValueHashMap<K> extends HashMap<K, Integer> { \n" + >+ " ^^^^^^^^^^^^^^^^^^^\n" + >+ "The serializable class IntegerValueHashMap does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 11)\n" + >+ " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "The constructor StringKeyHashMap<>(int) is undefined\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 11)\n" + >+ " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from StringKeyHashMap<> to Map<String,Integer>\n" + >+ "----------\n"); >+} >+// check inference at return expression. >+public void test0024() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "import java.util.ArrayList;\n" + >+ "class X<T> {\n" + >+ " public X() {}\n" + >+ " X<String> f(List<String> p) {return new X<>();}\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " import java.util.ArrayList;\n" + >+ " ^^^^^^^^^^^^^^^^^^^\n" + >+ "The import java.util.ArrayList is never used\n" + >+ "----------\n"); >+} >+// check inference at cast expression. >+public void test0025() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "import java.util.ArrayList;\n" + >+ "class X<T> {\n" + >+ " public X() {}\n" + >+ " void f(List<String> p) { Object o = (X<String>) new X<>();}\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " void f(List<String> p) { Object o = (X<String>) new X<>();}\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot cast from X<Object> to X<String>\n" + >+ "----------\n"); >+} > public static Class testClass() { > return GenericsRegressionTest_1_7.class; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 339478
:
190845
|
191332
|
191458
|
191707
|
191785
|
191891
|
191902
|
191946
|
191947
|
191984
|
192058
|
193887
|
193901
|
193918
|
193951
|
193962
|
193963