### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java,v retrieving revision 1.122.2.1 diff -u -r1.122.2.1 ASTConverterTestAST3_2.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 13 Aug 2007 18:53:06 -0000 1.122.2.1 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 27 Aug 2007 13:57:59 -0000 @@ -9144,65 +9144,53 @@ * http://dev.eclipse.org/bugs/show_bug.cgi?id=180905 */ public void test0676() throws JavaModelException { - ICompilationUnit workingCopy = null; - try { - String contents = - "package p;\n" + - "public class X {\n" + - " B foo() {\n" + - " }\n" + - "}"; - workingCopy = getWorkingCopy("/Converter/src/p/X.java", true/*resolve*/); - workingCopy.getBuffer().setContents(contents); - ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true); - assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); - CompilationUnit unit = (CompilationUnit) node; - assertTrue("no binding recovery", unit.getAST().hasBindingsRecovery()); - assertTrue("no statement recovery", unit.getAST().hasStatementsRecovery()); - assertTrue("no binding resolution", unit.getAST().hasResolvedBindings()); - String expectedError = "B cannot be resolved to a type"; - assertProblemsSize(unit, 1, expectedError); - assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery()); - node = getASTNode(unit, 0, 0); - assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); - MethodDeclaration methodDeclaration = (MethodDeclaration) node; - Type type = methodDeclaration.getReturnType2(); - assertNotNull("No type", type); - ITypeBinding typeBinding = type.resolveBinding(); - assertNotNull("No type binding", typeBinding); - assertTrue("Not a recovered binding", typeBinding.isRecovered()); - IJavaElement javaElement = typeBinding.getJavaElement(); - assertNotNull("No java element", javaElement); - assertTrue("Javalement exists", !javaElement.exists()); - IPackageBinding packageBinding = typeBinding.getPackage(); - assertNotNull("No package", packageBinding); - assertEquals("Not the package p", "p", packageBinding.getName()); - ITypeBinding arrayBinding = typeBinding.createArrayType(2); - assertNotNull("No array binding", arrayBinding); - assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions()); - ITypeBinding elementType = arrayBinding.getElementType(); - assertNotNull("No element type", elementType); - assertNotNull("No key", typeBinding.getKey()); - assertTrue("Not equals", elementType.isEqualTo(typeBinding)); - - node = getASTNode(unit, 0); - assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); - TypeDeclaration typeDeclaration = (TypeDeclaration) node; - ITypeBinding typeBinding2 = typeDeclaration.resolveBinding(); - ITypeBinding javaLangObject = typeBinding2.getSuperclass(); - assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName()); - assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(javaLangObject)); - assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(elementType)); + ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0676", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true, true); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit unit = (CompilationUnit) node; + assertTrue("no binding recovery", unit.getAST().hasBindingsRecovery()); + assertTrue("no statement recovery", unit.getAST().hasStatementsRecovery()); + assertTrue("no binding resolution", unit.getAST().hasResolvedBindings()); + String expectedError = "B cannot be resolved to a type"; + assertProblemsSize(unit, 1, expectedError); + assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery()); + node = getASTNode(unit, 0, 0); + assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); + MethodDeclaration methodDeclaration = (MethodDeclaration) node; + Type type = methodDeclaration.getReturnType2(); + assertNotNull("No type", type); + ITypeBinding typeBinding = type.resolveBinding(); + assertNotNull("No type binding", typeBinding); + assertTrue("Not a recovered binding", typeBinding.isRecovered()); + IJavaElement javaElement = typeBinding.getJavaElement(); + assertNotNull("No java element", javaElement); + assertTrue("Java element exists", !javaElement.exists()); + IPackageBinding packageBinding = typeBinding.getPackage(); + assertNotNull("No package", packageBinding); + assertNotNull("No java element for package", packageBinding.getJavaElement()); + assertEquals("Not the package test0676", "test0676", packageBinding.getName()); + ITypeBinding arrayBinding = typeBinding.createArrayType(2); + assertNotNull("No array binding", arrayBinding); + assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions()); + ITypeBinding elementType = arrayBinding.getElementType(); + assertNotNull("No element type", elementType); + assertNotNull("No key", typeBinding.getKey()); + assertTrue("Not equals", elementType.isEqualTo(typeBinding)); + + node = getASTNode(unit, 0); + assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); + TypeDeclaration typeDeclaration = (TypeDeclaration) node; + ITypeBinding typeBinding2 = typeDeclaration.resolveBinding(); + ITypeBinding javaLangObject = typeBinding2.getSuperclass(); + assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName()); + assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(javaLangObject)); + assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(elementType)); - assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(javaLangObject)); - assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(elementType)); + assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(javaLangObject)); + assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(elementType)); - assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(javaLangObject)); - assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(elementType)); - } finally { - if (workingCopy != null) - workingCopy.discardWorkingCopy(); - } + assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(javaLangObject)); + assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(elementType)); } /** Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v retrieving revision 1.247.2.4 diff -u -r1.247.2.4 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 24 Aug 2007 02:14:04 -0000 1.247.2.4 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 27 Aug 2007 13:57:59 -0000 @@ -9344,4 +9344,56 @@ IAnnotationBinding[] annotations = typeBinding.getAnnotations(); assertEquals("wrong size", 1, annotations.length); } + + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=201104 + public void test0282() throws JavaModelException { + String contents = + "public class X {\n" + + " public @interface Moo {\n" + + " Class value();\n" + + " }\n" + + " @Moo(Bar2.Baz.class)\n" + + " public static class Bar {\n" + + " public static class Baz {\n" + + " }\n" + + " }\n" + + "}"; + workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); + workingCopy.getBuffer().setContents(contents); + ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit unit = (CompilationUnit) node; + assertProblemsSize(unit, 1, "Bar2 cannot be resolved to a type"); + node = getASTNode(unit, 0, 1); + assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); + TypeDeclaration typeDeclaration = (TypeDeclaration) node; + final List modifiers = typeDeclaration.modifiers(); + assertEquals("Wrong size", 3, modifiers.size()); + IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0); + assertTrue("Not an annotation", extendedModifier instanceof SingleMemberAnnotation); + SingleMemberAnnotation annotation = (SingleMemberAnnotation) extendedModifier; + final Expression value = annotation.getValue(); + assertEquals("Not a type literal", ASTNode.TYPE_LITERAL, value.getNodeType()); + TypeLiteral typeLiteral = (TypeLiteral) value; + final Type type = typeLiteral.getType(); + assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType()); + SimpleType simpleType = (SimpleType) type; + final Name name = simpleType.getName(); + assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType()); + QualifiedName qualifiedName = (QualifiedName) name; + final IBinding binding = qualifiedName.resolveBinding(); + assertNotNull("No binding", binding); + assertEquals("Wrong value", "Bar2.Baz", qualifiedName.getFullyQualifiedName()); + final Name qualifier = qualifiedName.getQualifier(); + assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, qualifier.getNodeType()); + SimpleName simpleName2 = (SimpleName) qualifier; + final IBinding binding3 = simpleName2.resolveBinding(); + assertNotNull("No binding3", binding3); + assertTrue("Not a recovered binding", binding3.isRecovered()); + final IJavaElement javaElement = binding3.getJavaElement(); + assertNotNull("No java element", javaElement); + assertEquals("Not a compilation unit", IJavaElement.COMPILATION_UNIT, javaElement.getElementType()); + assertNotNull("No parent", javaElement.getParent()); + } } Index: workspace/Converter/src/test0676/X.java =================================================================== RCS file: workspace/Converter/src/test0676/X.java diff -N workspace/Converter/src/test0676/X.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Converter/src/test0676/X.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ +package test0676; +public class X { + B foo() { + } +} #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java,v retrieving revision 1.5 diff -u -r1.5 RecoveredTypeBinding.java --- dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java 27 Apr 2007 15:05:39 -0000 1.5 +++ dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java 27 Aug 2007 13:58:00 -0000 @@ -19,6 +19,7 @@ import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.jdt.internal.core.CompilationUnit; +import org.eclipse.jdt.internal.core.PackageFragment; /** * This class represents the recovered binding for a type @@ -495,7 +496,13 @@ */ public IJavaElement getJavaElement() { try { - return new CompilationUnit(null, this.getInternalName(), this.resolver.getWorkingCopyOwner()).getWorkingCopy(this.resolver.getWorkingCopyOwner(), null); + IPackageBinding packageBinding = getPackage(); + if (packageBinding != null) { + final IJavaElement javaElement = packageBinding.getJavaElement(); + if (javaElement!= null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { + return new CompilationUnit((PackageFragment) javaElement, this.getInternalName(), this.resolver.getWorkingCopyOwner()).getWorkingCopy(this.resolver.getWorkingCopyOwner(), null); + } + } } catch (JavaModelException e) { //ignore }