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 20487 Details for
Bug 93208
[dom] CompilationUnit.rewrite throws AssertionFailedException with legal AST (bug in recoding ast modifications)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
JUnit testcase for the bug
AstRewriteBug.java (text/plain), 2.46 KB, created by
Rodrigo Kumpera
on 2005-04-28 21:27:33 EDT
(
hide
)
Description:
JUnit testcase for the bug
Filename:
MIME Type:
Creator:
Rodrigo Kumpera
Created:
2005-04-28 21:27:33 EDT
Size:
2.46 KB
patch
obsolete
>/* > * Created on Apr 28, 2005 > */ >package jdt.tests; > >import junit.framework.TestCase; > >import org.eclipse.jdt.core.dom.AST; >import org.eclipse.jdt.core.dom.ASTNode; >import org.eclipse.jdt.core.dom.ASTParser; >import org.eclipse.jdt.core.dom.Block; >import org.eclipse.jdt.core.dom.CompilationUnit; >import org.eclipse.jdt.core.dom.ExpressionStatement; >import org.eclipse.jdt.core.dom.FieldAccess; >import org.eclipse.jdt.core.dom.MethodDeclaration; >import org.eclipse.jdt.core.dom.MethodInvocation; >import org.eclipse.jdt.core.dom.PrimitiveType; >import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; >import org.eclipse.jdt.core.dom.TypeDeclaration; >import org.eclipse.jface.text.Document; >import org.eclipse.text.edits.TextEdit; > >/** > * @author TEXP201 > * > */ >public class AstRewriteBug extends TestCase { > > > public void testAstRewriteBug() throws Exception { > Document sourceDoc = new Document("package test; public class Test { }"); > CompilationUnit unit = buildCU(sourceDoc); > unit.recordModifications(); > TypeDeclaration type = (TypeDeclaration) unit.types().get(0); > AST ast = type.getAST(); > > MethodDeclaration m = ast.newMethodDeclaration(); > type.bodyDeclarations().add(m); > > Block block = ast.newBlock(); > m.setName(ast.newSimpleName("foo")); > m.setReturnType(ast.newPrimitiveType(PrimitiveType.VOID)); > m.setBody(block); > > FieldAccess fa = ast.newFieldAccess(); > fa.setExpression(ast.newThisExpression()); > fa.setName(ast.newSimpleName("x")); > MethodInvocation mi = ast.newMethodInvocation(); > mi.setExpression(fa); > mi.setName(ast.newSimpleName("llall")); > > ExpressionStatement exp = ast.newExpressionStatement(mi); > block.statements().add(exp); > > StructuralPropertyDescriptor loc = mi.getLocationInParent(); > //This will cause the bug > ASTNode node = ASTNode.copySubtree(ast, fa); > exp.setStructuralProperty(loc, node); > > TextEdit edit = unit.rewrite(sourceDoc, null); > edit.apply(sourceDoc); > System.out.println(sourceDoc.get()); > } > > > > CompilationUnit buildCU(Document doc) { > ASTParser p = ASTParser.newParser(AST.JLS2); > p.setSource(doc.get().toCharArray()); > p.setUnitName("Test" + ".java"); > > return (CompilationUnit) p.createAST(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 93208
: 20487