Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 49503 Details for
Bug 156352
NPE when accessing annotations from ITypeBinding
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
New test case
SnippedBug156352.java (text/plain), 6.42 KB, created by
Olivier Thomann
on 2006-09-06 11:39:53 EDT
(
hide
)
Description:
New test case
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2006-09-06 11:39:53 EDT
Size:
6.42 KB
patch
obsolete
>package a; > >import java.util.List; > >import junit.framework.TestCase; > >import org.eclipse.core.resources.IProject; >import org.eclipse.core.resources.IProjectDescription; >import org.eclipse.core.resources.ResourcesPlugin; > >import org.eclipse.jdt.core.IClasspathEntry; >import org.eclipse.jdt.core.ICompilationUnit; >import org.eclipse.jdt.core.IJavaElement; >import org.eclipse.jdt.core.IJavaProject; >import org.eclipse.jdt.core.IPackageFragment; >import org.eclipse.jdt.core.IPackageFragmentRoot; >import org.eclipse.jdt.core.IType; >import org.eclipse.jdt.core.JavaCore; >import org.eclipse.jdt.core.dom.AST; >import org.eclipse.jdt.core.dom.ASTParser; >import org.eclipse.jdt.core.dom.CompilationUnit; >import org.eclipse.jdt.core.dom.IBinding; >import org.eclipse.jdt.core.dom.ITypeBinding; >import org.eclipse.jdt.core.dom.TypeDeclaration; > >import org.eclipse.jdt.internal.junit.buildpath.JUnitContainerInitializer; > >import org.eclipse.jdt.launching.JavaRuntime; > >public class SnippedBug156352 extends TestCase { > > public void testNPE() throws Exception { > IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject("Test"); > project.create(null); > try { > project.open(null); > > IProjectDescription description = project.getDescription(); > description.setNatureIds(new String[] { JavaCore.NATURE_ID } ); > project.setDescription(description, null); > > IJavaProject javaProject= JavaCore.create(project); > > IClasspathEntry[] cpentry= new IClasspathEntry[] { > JavaCore.newSourceEntry(javaProject.getPath()), > JavaRuntime.getDefaultJREContainerEntry(), > JavaCore.newContainerEntry(JUnitContainerInitializer.JUNIT4_PATH) > }; > javaProject.setRawClasspath(cpentry, javaProject.getPath(), null); > > IPackageFragmentRoot root= javaProject.getPackageFragmentRoot(project); > > IPackageFragment p= root.createPackageFragment("p", true, null); > StringBuffer buf= new StringBuffer(); > buf.append("package p;\n"); > buf.append("\n"); > buf.append("import org.junit.Test;\n"); > buf.append("\n"); > buf.append("public class Test1 {\n"); > buf.append(" @Test public void testFoo() {\n"); > buf.append(" }\n"); > buf.append("}\n"); > p.createCompilationUnit("Test1.java", buf.toString(), false, null); > > buf= new StringBuffer(); > buf.append("package p;\n"); > buf.append("\n"); > buf.append("import org.junit.runner.RunWith;\n"); > buf.append("import org.junit.runners.Suite;\n"); > buf.append("import org.junit.runners.Suite.SuiteClasses;\n"); > buf.append("\n"); > buf.append("@RunWith(Suite.class)\n"); > buf.append("@SuiteClasses(Test1.class)\n"); > buf.append("public class Test2 {\n"); > buf.append(" \n"); > buf.append("}\n"); > p.createCompilationUnit("Test2.java", buf.toString(), false, null); > > buf= new StringBuffer(); > buf.append("package p;\n"); > buf.append("\n"); > buf.append("public class Test3 extends Test2 {\n"); > buf.append(" \n"); > buf.append("}\n"); > IType type= p.createCompilationUnit("Test3.java", buf.toString(), false, null).getType("Test3"); > > ASTParser parser= ASTParser.newParser(AST.JLS3); > parser.setProject(type.getJavaProject()); > IBinding[] bindings= parser.createBindings(new IJavaElement[] { type }, null); > if (bindings.length == 1 && bindings[0] instanceof ITypeBinding) { > ITypeBinding binding= (ITypeBinding) bindings[0]; > while (binding != null) { > binding.getAnnotations(); // NPE here on 'Test2' > binding= binding.getSuperclass(); > } > } > } finally { > project.delete(true, null); > } > } > public void testOK() throws Exception { > IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject("Test"); > project.create(null); > try { > project.open(null); > > IProjectDescription description = project.getDescription(); > description.setNatureIds(new String[] { JavaCore.NATURE_ID } ); > project.setDescription(description, null); > > IJavaProject javaProject= JavaCore.create(project); > > IClasspathEntry[] cpentry= new IClasspathEntry[] { > JavaCore.newSourceEntry(javaProject.getPath()), > JavaRuntime.getDefaultJREContainerEntry(), > JavaCore.newContainerEntry(JUnitContainerInitializer.JUNIT4_PATH) > }; > javaProject.setRawClasspath(cpentry, javaProject.getPath(), null); > > IPackageFragmentRoot root= javaProject.getPackageFragmentRoot(project); > > IPackageFragment p= root.createPackageFragment("p", true, null); > StringBuffer buf= new StringBuffer(); > buf.append("package p;\n"); > buf.append("\n"); > buf.append("import org.junit.Test;\n"); > buf.append("\n"); > buf.append("public class Test1 {\n"); > buf.append(" @Test public void testFoo() {\n"); > buf.append(" }\n"); > buf.append("}\n"); > p.createCompilationUnit("Test1.java", buf.toString(), false, null); > > buf= new StringBuffer(); > buf.append("package p;\n"); > buf.append("\n"); > buf.append("import org.junit.runner.RunWith;\n"); > buf.append("import org.junit.runners.Suite;\n"); > buf.append("import org.junit.runners.Suite.SuiteClasses;\n"); > buf.append("\n"); > buf.append("@RunWith(Suite.class)\n"); > buf.append("@SuiteClasses(Test1.class)\n"); > buf.append("public class Test2 {\n"); > buf.append(" \n"); > buf.append("}\n"); > p.createCompilationUnit("Test2.java", buf.toString(), false, null); > > buf= new StringBuffer(); > buf.append("package p;\n"); > buf.append("\n"); > buf.append("public class Test3 extends Test2 {\n"); > buf.append(" \n"); > buf.append("}\n"); >// IType type= p.createCompilationUnit("Test3.java", buf.toString(), false, null).getType("Test3"); > ICompilationUnit unit3 = p.createCompilationUnit("Test3.java", buf.toString(), false, null); > > ASTParser parser= ASTParser.newParser(AST.JLS3); > parser.setSource(unit3); > parser.setResolveBindings(true); > CompilationUnit unit = (CompilationUnit) parser.createAST(null); > List types = unit.types(); > TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0); > ITypeBinding typeBinding = typeDeclaration.resolveBinding(); > while (typeBinding != null) { > System.out.print(typeBinding.getQualifiedName()); > System.out.print(" has "); > System.out.print(typeBinding.getAnnotations().length); > System.out.println(" annotation(s)."); > typeBinding= typeBinding.getSuperclass(); > } > } finally { > project.delete(true, null); > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 156352
:
49480
| 49503 |
49504