/** * Ensures that creating a DOM AST and computing the bindings takes the owner's working copies * into account. * * @deprecated using deprecated code */ public void testParseCompilationUnit3() throws CoreException { try { createJavaProject("P1", new String[] {"src"}, new String[] {"JCL_LIB", "lib"}, "bin"); // create X.class in lib folder /* Evaluate the following in a scrapbook: org.eclipse.jdt.core.tests.model.ModifyingResourceTests.generateClassFile( "X", "public class X {\n" + "}") */ byte[] bytes = new byte[] { -54, -2, -70, -66, 0, 3, 0, 45, 0, 13, 1, 0, 1, 88, 7, 0, 1, 1, 0, 16, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, 99, 116, 7, 0, 3, 1, 0, 6, 60, 105, 110, 105, 116, 62, 1, 0, 3, 40, 41, 86, 1, 0, 4, 67, 111, 100, 101, 12, 0, 5, 0, 6, 10, 0, 4, 0, 8, 1, 0, 15, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 84, 97, 98, 108, 101, 1, 0, 10, 83, 111, 117, 114, 99, 101, 70, 105, 108, 101, 1, 0, 6, 88, 46, 106, 97, 118, 97, 0, 33, 0, 2, 0, 4, 0, 0, 0, 0, 0, 1, 0, 1, 0, 5, 0, 6, 0, 1, 0, 7, 0, 0, 0, 29, 0, 1, 0, 1, 0, 0, 0, 5, 42, -73, 0, 9, -79, 0, 0, 0, 1, 0, 10, 0, 0, 0, 6, 0, 1, 0, 0, 0, 1, 0, 1, 0, 11, 0, 0, 0, 2, 0, 12, }; this.createFile("P1/lib/X.class", bytes); // create libsrc and attach source createFolder("P1/libsrc"); createFile("P1/libsrc/X.java", "public class X extends Y {\n" + "}"); IPackageFragmentRoot lib = getPackageFragmentRoot("P1/lib"); lib.attachSource(new Path("/P1/libsrc"), null, null); // create Y.java in src folder createFile("P1/src/Y.java", ""); // create working copy on Y.java TestWorkingCopyOwner owner = new TestWorkingCopyOwner(); this.workingCopy = getCompilationUnit("P1/src/Y.java").getWorkingCopy(owner, null); this.workingCopy.getBuffer().setContents("public class Y {\n" + "}"); this.workingCopy.makeConsistent(null); // parse and resolve class file IClassFile classFile = getClassFile("P1/lib/X.class"); ASTParser parser = ASTParser.newParser(AST.JLS2); parser.setSource(classFile); parser.setResolveBindings(true); parser.setWorkingCopyOwner(owner); CompilationUnit cu = (CompilationUnit) parser.createAST(null); List types = cu.types(); assertEquals("Unexpected number of types in AST", 1, types.size()); TypeDeclaration type = (TypeDeclaration) types.get(0); ITypeBinding typeBinding = type.resolveBinding(); ITypeBinding superType = typeBinding.getSuperclass(); assertEquals( "Unexpected super type", "Y", superType == null ? "<null>" : superType.getQualifiedName()); } finally { deleteProject("P1"); } }