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 49480 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
test case
SnippedBug156352.java (text/plain), 3.50 KB, created by
Martin Aeschlimann
on 2006-09-06 09:39:58 EDT
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
Martin Aeschlimann
Created:
2006-09-06 09:39:58 EDT
Size:
3.50 KB
patch
obsolete
>package a; > >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.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.IAnnotationBinding; >import org.eclipse.jdt.core.dom.IBinding; >import org.eclipse.jdt.core.dom.ITypeBinding; > >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) { > IAnnotationBinding[] annotations= binding.getAnnotations(); // NPE here on 'Test1' > binding= binding.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