### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java,v retrieving revision 1.162 diff -u -r1.162 TypeDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 25 Nov 2009 04:56:02 -0000 1.162 +++ compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 17 May 2010 13:40:49 -0000 @@ -1187,6 +1187,28 @@ ReferenceBinding existingType = (ReferenceBinding) existing; if (existingType instanceof TypeVariableBinding) { blockScope.problemReporter().typeHiding(this, (TypeVariableBinding) existingType); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989, check for collision with enclosing type. + Scope outerScope = blockScope.parent; +checkOuterScope:while (outerScope != null) { + Binding existing2 = outerScope.getType(this.name); + if (existing2 instanceof TypeVariableBinding && existing2.isValidBinding()) { + TypeVariableBinding tvb = (TypeVariableBinding) existingType; + Binding declaringElement = tvb.declaringElement; + if (declaringElement instanceof ReferenceBinding + && CharOperation.equals(((ReferenceBinding) declaringElement).sourceName(), this.name)) { + blockScope.problemReporter().typeCollidesWithEnclosingType(this); + break checkOuterScope; + } + } else if (existing2 instanceof ReferenceBinding + && existing2.isValidBinding() + && outerScope.isDefinedInType((ReferenceBinding) existing2)) { + blockScope.problemReporter().typeCollidesWithEnclosingType(this); + break checkOuterScope; + } else if (existing2 == null) { + break checkOuterScope; + } + outerScope = outerScope.parent; + } } else if (existingType instanceof LocalTypeBinding && ((LocalTypeBinding) existingType).scope.methodScope() == blockScope.methodScope()) { // dup in same method #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java =================================================================== RCS file: src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java diff -N src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class InnerClass15Test extends AbstractRegressionTest { +public InnerClass15Test(String name) { + super(name); +} +static { +// TESTS_NUMBERS = new int[] { 2 }; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); +} +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; +} +public void test001() { + this.runNegativeTest(new String[] { + "X.java", + "class X {\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo() {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X is hiding the type parameter X of the generic method foo() of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X cannot hide an enclosing type\n" + + "----------\n"); +} +public void test002() { + this.runNegativeTest(new String[] { + "X.java", + "class X {\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X is hiding the type parameter X of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X cannot hide an enclosing type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989 +// note javac reports an error for this test, but that is +// incorrect, compare and contrast javac behavior with +// test004. +public void test003() { + this.runNegativeTest(new String[] { + "Y.java", + "class Y {\n" + + "class X {}\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " void foo() {\n" + + " ^\n" + + "The type parameter X is hiding the type Y.X\n" + + "----------\n" + + "2. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X is hiding the type parameter X of the generic method foo() of type Y\n" + + "----------\n" + + "3. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The type X is never used locally\n" + + "----------\n"); +} +public void test004() { + this.runNegativeTest(new String[] { + "Y.java", + "class Y {\n" + + "class X {}\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The type X is hiding the type Y.X\n" + + "----------\n" + + "2. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The type X is never used locally\n" + + "----------\n"); +} +public static Class testClass() { + return InnerClass15Test.class; +} +} Index: src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java,v retrieving revision 1.85 diff -u -r1.85 TestAll.java --- src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java 11 May 2010 18:53:50 -0000 1.85 +++ src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java 17 May 2010 13:40:59 -0000 @@ -94,6 +94,7 @@ since_1_5.add(Deprecated15Test.class); since_1_5.add(InnerEmulationTest_1_5.class); since_1_5.add(AssignmentTest_1_5.class); + since_1_5.add(InnerClass15Test.class); // Tests to run when compliance is greater than 1.5 ArrayList since_1_6 = new ArrayList();