Lines 12-17
Link Here
|
12 |
package org.eclipse.jdt.core.tests.dom; |
12 |
package org.eclipse.jdt.core.tests.dom; |
13 |
|
13 |
|
14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
|
|
15 |
import java.util.ArrayList; |
15 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
16 |
import java.util.List; |
17 |
import java.util.List; |
17 |
import java.util.Map; |
18 |
import java.util.Map; |
Lines 6962-6965
Link Here
|
6962 |
CompilationUnit unit = (CompilationUnit) node; |
6963 |
CompilationUnit unit = (CompilationUnit) node; |
6963 |
assertProblemsSize(unit, 0); |
6964 |
assertProblemsSize(unit, 0); |
6964 |
} |
6965 |
} |
|
|
6966 |
|
6967 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=155115 |
6968 |
public void test0227() throws JavaModelException { |
6969 |
this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); |
6970 |
String contents = |
6971 |
"import anno.Anno;\n" + |
6972 |
"import binary.B;\n" + |
6973 |
"import intf.IFoo;\n" + |
6974 |
"\n" + |
6975 |
"public class X extends B {\n" + |
6976 |
" @Anno(clz=IFoo.IBar.class)\n" + |
6977 |
// the annotation we chase up is not this one, but the one |
6978 |
// carried by B#f |
6979 |
" public void f() {}\n" + |
6980 |
" IFoo.IBar m;\n" + |
6981 |
"}"; |
6982 |
class TestASTRequestor extends ASTRequestor { |
6983 |
public ArrayList asts = new ArrayList(); |
6984 |
public void acceptAST(ICompilationUnit source, CompilationUnit compilationUnit) { |
6985 |
this.asts.add(compilationUnit); |
6986 |
} |
6987 |
public void acceptBinding(String bindingKey, IBinding binding) { |
6988 |
} |
6989 |
} |
6990 |
this.workingCopy.getBuffer().setContents(contents); |
6991 |
this.workingCopy.save(null, true); |
6992 |
TestASTRequestor requestor = new TestASTRequestor(); |
6993 |
resolveASTs(new ICompilationUnit[] { this.workingCopy } , new String[0], requestor, this.getJavaProject("Converter15"), null); |
6994 |
ArrayList asts = requestor.asts; |
6995 |
assertEquals("Wrong size", 1, asts.size()); |
6996 |
CompilationUnit compilationUnit = (CompilationUnit) asts.get(0); |
6997 |
assertNotNull("No compilation unit", compilationUnit); |
6998 |
List types = compilationUnit.types(); |
6999 |
assertEquals("Wrong size", 1, types.size()); |
7000 |
AbstractTypeDeclaration abstractTypeDeclaration = (AbstractTypeDeclaration) types.get(0); |
7001 |
assertEquals("Wrong type", ASTNode.TYPE_DECLARATION, abstractTypeDeclaration.getNodeType()); |
7002 |
TypeDeclaration declaration = (TypeDeclaration) abstractTypeDeclaration; |
7003 |
Type superclass = declaration.getSuperclassType(); |
7004 |
assertNotNull("No superclass", superclass); |
7005 |
ITypeBinding typeBinding = superclass.resolveBinding(); |
7006 |
assertNotNull("No binding", typeBinding); |
7007 |
IMethodBinding[] methods = typeBinding.getDeclaredMethods(); |
7008 |
assertNotNull("No methods", methods); |
7009 |
assertEquals("Wrong size", 2, methods.length); |
7010 |
IMethodBinding methodBinding = null; |
7011 |
for(int i = 0; i < 2; i++) { |
7012 |
methodBinding = methods[i]; |
7013 |
if (methodBinding.getName().equals("f")) { |
7014 |
break; |
7015 |
} |
7016 |
} |
7017 |
assertEquals("Wrong name", "f", methodBinding.getName()); |
7018 |
IAnnotationBinding[] annotationBindings = methodBinding.getAnnotations(); |
7019 |
assertNotNull("No annotations", annotationBindings); |
7020 |
assertEquals("Wrong size", 1, annotationBindings.length); |
7021 |
IAnnotationBinding annotationBinding = annotationBindings[0]; |
7022 |
IMemberValuePairBinding[] pairs = annotationBinding.getAllMemberValuePairs(); |
7023 |
assertNotNull("no pairs", pairs); |
7024 |
assertEquals("Wrong size", 1, pairs.length); |
7025 |
IMemberValuePairBinding memberValuePairBinding = pairs[0]; |
7026 |
assertEquals("Wrong kind", IBinding.MEMBER_VALUE_PAIR, memberValuePairBinding.getKind()); |
7027 |
Object value = memberValuePairBinding.getValue(); |
7028 |
assertNotNull("No value", value); |
7029 |
assertTrue("Not a type binding", value instanceof ITypeBinding); |
7030 |
assertEquals("Wrong qualified name", "intf.IFoo.IBar", |
7031 |
((ITypeBinding) value).getQualifiedName()); |
7032 |
IVariableBinding[] fields = |
7033 |
declaration.resolveBinding().getDeclaredFields(); |
7034 |
assertTrue("Bad field definition", fields != null && fields.length == 1); |
7035 |
assertEquals("Type binding mismatch", value, fields[0].getType()); |
7036 |
} |
6965 |
} |
7037 |
} |