Lines 9144-9208
Link Here
|
9144 |
* http://dev.eclipse.org/bugs/show_bug.cgi?id=180905 |
9144 |
* http://dev.eclipse.org/bugs/show_bug.cgi?id=180905 |
9145 |
*/ |
9145 |
*/ |
9146 |
public void test0676() throws JavaModelException { |
9146 |
public void test0676() throws JavaModelException { |
9147 |
ICompilationUnit workingCopy = null; |
9147 |
ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0676", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
9148 |
try { |
9148 |
ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true, true); |
9149 |
String contents = |
9149 |
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); |
9150 |
"package p;\n" + |
9150 |
CompilationUnit unit = (CompilationUnit) node; |
9151 |
"public class X {\n" + |
9151 |
assertTrue("no binding recovery", unit.getAST().hasBindingsRecovery()); |
9152 |
" B foo() {\n" + |
9152 |
assertTrue("no statement recovery", unit.getAST().hasStatementsRecovery()); |
9153 |
" }\n" + |
9153 |
assertTrue("no binding resolution", unit.getAST().hasResolvedBindings()); |
9154 |
"}"; |
9154 |
String expectedError = "B cannot be resolved to a type"; |
9155 |
workingCopy = getWorkingCopy("/Converter/src/p/X.java", true/*resolve*/); |
9155 |
assertProblemsSize(unit, 1, expectedError); |
9156 |
workingCopy.getBuffer().setContents(contents); |
9156 |
assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery()); |
9157 |
ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true); |
9157 |
node = getASTNode(unit, 0, 0); |
9158 |
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); |
9158 |
assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
9159 |
CompilationUnit unit = (CompilationUnit) node; |
9159 |
MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
9160 |
assertTrue("no binding recovery", unit.getAST().hasBindingsRecovery()); |
9160 |
Type type = methodDeclaration.getReturnType2(); |
9161 |
assertTrue("no statement recovery", unit.getAST().hasStatementsRecovery()); |
9161 |
assertNotNull("No type", type); |
9162 |
assertTrue("no binding resolution", unit.getAST().hasResolvedBindings()); |
9162 |
ITypeBinding typeBinding = type.resolveBinding(); |
9163 |
String expectedError = "B cannot be resolved to a type"; |
9163 |
assertNotNull("No type binding", typeBinding); |
9164 |
assertProblemsSize(unit, 1, expectedError); |
9164 |
assertTrue("Not a recovered binding", typeBinding.isRecovered()); |
9165 |
assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery()); |
9165 |
IJavaElement javaElement = typeBinding.getJavaElement(); |
9166 |
node = getASTNode(unit, 0, 0); |
9166 |
assertNotNull("No java element", javaElement); |
9167 |
assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
9167 |
assertTrue("Java element exists", !javaElement.exists()); |
9168 |
MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
9168 |
IPackageBinding packageBinding = typeBinding.getPackage(); |
9169 |
Type type = methodDeclaration.getReturnType2(); |
9169 |
assertNotNull("No package", packageBinding); |
9170 |
assertNotNull("No type", type); |
9170 |
assertNotNull("No java element for package", packageBinding.getJavaElement()); |
9171 |
ITypeBinding typeBinding = type.resolveBinding(); |
9171 |
assertEquals("Not the package test0676", "test0676", packageBinding.getName()); |
9172 |
assertNotNull("No type binding", typeBinding); |
9172 |
ITypeBinding arrayBinding = typeBinding.createArrayType(2); |
9173 |
assertTrue("Not a recovered binding", typeBinding.isRecovered()); |
9173 |
assertNotNull("No array binding", arrayBinding); |
9174 |
IJavaElement javaElement = typeBinding.getJavaElement(); |
9174 |
assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions()); |
9175 |
assertNotNull("No java element", javaElement); |
9175 |
ITypeBinding elementType = arrayBinding.getElementType(); |
9176 |
assertTrue("Javalement exists", !javaElement.exists()); |
9176 |
assertNotNull("No element type", elementType); |
9177 |
IPackageBinding packageBinding = typeBinding.getPackage(); |
9177 |
assertNotNull("No key", typeBinding.getKey()); |
9178 |
assertNotNull("No package", packageBinding); |
9178 |
assertTrue("Not equals", elementType.isEqualTo(typeBinding)); |
9179 |
assertEquals("Not the package p", "p", packageBinding.getName()); |
9179 |
|
9180 |
ITypeBinding arrayBinding = typeBinding.createArrayType(2); |
9180 |
node = getASTNode(unit, 0); |
9181 |
assertNotNull("No array binding", arrayBinding); |
9181 |
assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); |
9182 |
assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions()); |
9182 |
TypeDeclaration typeDeclaration = (TypeDeclaration) node; |
9183 |
ITypeBinding elementType = arrayBinding.getElementType(); |
9183 |
ITypeBinding typeBinding2 = typeDeclaration.resolveBinding(); |
9184 |
assertNotNull("No element type", elementType); |
9184 |
ITypeBinding javaLangObject = typeBinding2.getSuperclass(); |
9185 |
assertNotNull("No key", typeBinding.getKey()); |
9185 |
assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName()); |
9186 |
assertTrue("Not equals", elementType.isEqualTo(typeBinding)); |
9186 |
assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(javaLangObject)); |
9187 |
|
9187 |
assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(elementType)); |
9188 |
node = getASTNode(unit, 0); |
|
|
9189 |
assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); |
9190 |
TypeDeclaration typeDeclaration = (TypeDeclaration) node; |
9191 |
ITypeBinding typeBinding2 = typeDeclaration.resolveBinding(); |
9192 |
ITypeBinding javaLangObject = typeBinding2.getSuperclass(); |
9193 |
assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName()); |
9194 |
assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(javaLangObject)); |
9195 |
assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(elementType)); |
9196 |
|
9188 |
|
9197 |
assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(javaLangObject)); |
9189 |
assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(javaLangObject)); |
9198 |
assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(elementType)); |
9190 |
assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(elementType)); |
9199 |
|
9191 |
|
9200 |
assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(javaLangObject)); |
9192 |
assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(javaLangObject)); |
9201 |
assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(elementType)); |
9193 |
assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(elementType)); |
9202 |
} finally { |
|
|
9203 |
if (workingCopy != null) |
9204 |
workingCopy.discardWorkingCopy(); |
9205 |
} |
9206 |
} |
9194 |
} |
9207 |
|
9195 |
|
9208 |
/** |
9196 |
/** |