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 164574 Details for
Bug 308754
CompilationUnit.rewrite messes up .class-literal in annotation instead of changing class to interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression tests
patch_308754.txt (text/plain), 8.80 KB, created by
Olivier Thomann
on 2010-04-12 11:38:30 EDT
(
hide
)
Description:
Proposed fix + regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-04-12 11:38:30 EDT
Size:
8.80 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java,v >retrieving revision 1.72 >diff -u -r1.72 ASTRewriteAnalyzer.java >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java 18 Mar 2010 15:58:49 -0000 1.72 >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java 12 Apr 2010 15:37:58 -0000 >@@ -1503,7 +1503,16 @@ > if (invertType) { > try { > int typeToken= isInterface ? TerminalTokens.TokenNameinterface : TerminalTokens.TokenNameclass; >- getScanner().readToToken(typeToken, node.getStartPosition()); >+ int startPosition = node.getStartPosition(); >+ if (apiLevel >= AST.JLS3) { >+ List modifiers = node.modifiers(); >+ final int size = modifiers.size(); >+ if (size != 0) { >+ ASTNode modifierNode = (ASTNode) modifiers.get(size - 1); >+ startPosition = modifierNode.getStartPosition() + modifierNode.getLength(); >+ } >+ } >+ getScanner().readToToken(typeToken, startPosition); > > String str= isInterface ? "class" : "interface"; //$NON-NLS-1$ //$NON-NLS-2$ > int start= getScanner().getCurrentStartOffset(); >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java,v >retrieving revision 1.25 >diff -u -r1.25 ASTRewritingTypeDeclTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java 28 Apr 2009 17:46:13 -0000 1.25 >+++ src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java 12 Apr 2010 15:37:58 -0000 >@@ -153,7 +153,56 @@ > assertEqualString(preview, buf.toString()); > > } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754 >+ public void testTypeDeclarationChange() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class C {}"); >+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createAST(cu); >+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); >+ { >+ // change to interface >+ TypeDeclaration type= findTypeDeclaration(astRoot, "C"); >+ >+ astRoot.recordModifications(); >+ // change to interface >+ rewrite.set(type, TypeDeclaration.INTERFACE_PROPERTY, Boolean.TRUE, null); >+ } >+ String preview= evaluateRewrite(cu, rewrite); > >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public interface C {}"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754 >+ public void testTypeDeclarationChange2() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("@A(X.class) public class C {}"); >+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createAST3(cu); >+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); >+ { >+ // change to interface >+ TypeDeclaration type= findTypeDeclaration(astRoot, "C"); >+ >+ astRoot.recordModifications(); >+ // change to interface >+ rewrite.set(type, TypeDeclaration.INTERFACE_PROPERTY, Boolean.TRUE, null); >+ } >+ String preview= evaluateRewrite(cu, rewrite); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("@A(X.class) public interface C {}"); >+ assertEqualString(preview, buf.toString()); >+ } > public void testTypeDeclChanges2() throws Exception { > IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer(); >Index: src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java,v >retrieving revision 1.11 >diff -u -r1.11 ASTRewritingModifyingOtherTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java 28 Apr 2009 17:49:27 -0000 1.11 >+++ src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java 12 Apr 2010 15:37:58 -0000 >@@ -16,8 +16,12 @@ > > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IPackageFragment; >- >-import org.eclipse.jdt.core.dom.*; >+import org.eclipse.jdt.core.dom.AST; >+import org.eclipse.jdt.core.dom.ASTVisitor; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.dom.ImportDeclaration; >+import org.eclipse.jdt.core.dom.Name; >+import org.eclipse.jdt.core.dom.TypeDeclaration; > > public class ASTRewritingModifyingOtherTest extends ASTRewritingModifyingTest { > private static final Class THIS = ASTRewritingModifyingOtherTest.class; >@@ -186,49 +190,56 @@ > buf.append("}\n"); > assertEqualString(preview, buf.toString()); > } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754 >+ public void test0005() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0005", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0005;\n"); >+ buf.append("@A(X.class) public class C {}"); >+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, true, AST.JLS3); >+ astRoot.recordModifications(); >+ { >+ // change to interface >+ astRoot.accept(new ASTVisitor() { >+ public boolean visit(TypeDeclaration node) { >+ node.setInterface(true); >+ return false; >+ } >+ }); >+ } >+ String preview= evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0005;\n"); >+ buf.append("@A(X.class) public interface C {}"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754 >+ public void test0006() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0006", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0006;\n"); >+ buf.append("public @A(X.class) class C {}"); >+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, true, AST.JLS3); >+ astRoot.recordModifications(); >+ { >+ // change to interface >+ astRoot.accept(new ASTVisitor() { >+ public boolean visit(TypeDeclaration node) { >+ node.setInterface(true); >+ return false; >+ } >+ }); >+ } >+ String preview= evaluateRewrite(cu, astRoot); > >-// public void _test000X() throws Exception { >-// IPackageFragment pack1= fSourceFolder.createPackageFragment("test0004", false, null); >-// StringBuffer buf= new StringBuffer(); >-// buf.append("package test0004;\n"); >-// buf.append("\n"); >-// buf.append("public class X {\n"); >-// buf.append(" void foo(){\n"); >-// buf.append(" //rien\n"); >-// buf.append(" \n"); >-// buf.append(" \n"); >-// buf.append(" \n"); >-// buf.append(" \n"); >-// buf.append(" }\n"); >-// buf.append("}\n"); >-// ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >-// >-// CompilationUnit astRoot= parseCompilationUnit(cu, false); >-// >-// astRoot.recordModifications(); >-// >-// AST a = astRoot.getAST(); >-// >-// Comment[] comments = astRoot.getCommentTable(); >-// Comment comment1 = comments[0]; >-// Comment comment2 = a.newBlockComment(); >-// comment2.setSourceRange(comment1.getStartPosition(), comment1.getLength() - 2); >-// comments[0] = comment2; >-// >-// String preview = evaluateRewrite(cu, astRoot); >-// >-// buf= new StringBuffer(); >-// buf.append("package test0004;\n"); >-// buf.append("\n"); >-// buf.append("public class X {\n"); >-// buf.append("\n"); >-// buf.append("}\n"); >-// buf.append("class Y {\n"); >-// buf.append("\n"); >-// buf.append("}\n"); >-// buf.append("class Z {\n"); >-// buf.append("\n"); >-// buf.append("}\n"); >-// assertEqualString(preview, buf.toString()); >-// } >+ buf= new StringBuffer(); >+ buf.append("package test0006;\n"); >+ buf.append("public @A(X.class) interface C {}"); >+ assertEqualString(preview, buf.toString()); >+ } > }
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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 308754
: 164574