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 162312 Details for
Bug 192233
[AST] CompilationUnit.rewrite() removes whitespace between return type and method name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression tests
patch_192233.txt (text/plain), 14.22 KB, created by
Olivier Thomann
on 2010-03-17 12:15:13 EDT
(
hide
)
Description:
Proposed fix + regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-03-17 12:15:13 EDT
Size:
14.22 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.69 >diff -u -r1.69 ASTRewriteAnalyzer.java >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java 4 Mar 2010 16:44:19 -0000 1.69 >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java 17 Mar 2010 16:09:05 -0000 >@@ -1588,6 +1588,7 @@ > boolean returnTypeExists= originalReturnType != null && originalReturnType.getStartPosition() != -1; > if (!isConstructorChange && returnTypeExists) { > rewriteRequiredNode(node, property); >+ ensureSpaceAfterReplace(node, property); > return; > } > // difficult cases: return type insert or remove >@@ -2158,6 +2159,7 @@ > } > > pos= rewriteRequiredNode(node, FieldDeclaration.TYPE_PROPERTY); >+ ensureSpaceAfterReplace(node, FieldDeclaration.TYPE_PROPERTY); > rewriteNodeList(node, FieldDeclaration.FRAGMENTS_PROPERTY, pos, "", ", "); //$NON-NLS-1$ //$NON-NLS-2$ > return false; > } >@@ -2639,6 +2641,9 @@ > } > } > } >+ if (!node.isVarargs()) { >+ ensureSpaceAfterReplace(node, SingleVariableDeclaration.TYPE_PROPERTY); >+ } > > pos= rewriteRequiredNode(node, SingleVariableDeclaration.NAME_PROPERTY); > int extraDims= rewriteExtraDimensions(node, SingleVariableDeclaration.EXTRA_DIMENSIONS_PROPERTY, pos); >Index: dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java,v >retrieving revision 1.27 >diff -u -r1.27 ASTRewriteFormatter.java >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java 29 Sep 2009 15:46:40 -0000 1.27 >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java 17 Mar 2010 16:09:05 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -546,8 +546,8 @@ > > public final BlockContext IF_BLOCK_WITH_ELSE= new BlockFormattingPrefixSuffix("if (true)", "else{}", 8); //$NON-NLS-1$ //$NON-NLS-2$ > public final BlockContext IF_BLOCK_NO_ELSE= new BlockFormattingPrefix("if (true)", 8); //$NON-NLS-1$ >- public final BlockContext ELSE_AFTER_STATEMENT= new BlockFormattingPrefix("if (true) foo(); else ", 15); //$NON-NLS-1$ >- public final BlockContext ELSE_AFTER_BLOCK= new BlockFormattingPrefix("if (true) {} else ", 11); //$NON-NLS-1$ >+ public final BlockContext ELSE_AFTER_STATEMENT= new BlockFormattingPrefix("if (true) foo();else ", 15); //$NON-NLS-1$ >+ public final BlockContext ELSE_AFTER_BLOCK= new BlockFormattingPrefix("if (true) {}else ", 11); //$NON-NLS-1$ > > public final BlockContext FOR_BLOCK= new BlockFormattingPrefix("for (;;) ", 7); //$NON-NLS-1$ > public final BlockContext WHILE_BLOCK= new BlockFormattingPrefix("while (true)", 11); //$NON-NLS-1$ >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java,v >retrieving revision 1.10 >diff -u -r1.10 ASTRewritingModifyingReplaceTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java 28 Apr 2009 17:49:27 -0000 1.10 >+++ src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java 17 Mar 2010 16:09:05 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -236,4 +236,230 @@ > buf.append("}\n"); > assertEqualString(preview, buf.toString()); > } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0007() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0007", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0007;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" List/**/getUsers() {}\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0); >+ >+ methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0007;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers() {}\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0008() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0008", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0008;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" List /**/getUsers() {}\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0); >+ >+ methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0008;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers() {}\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0009() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0009", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0009;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" List/**/ getUsers() {}\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0); >+ >+ methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0009;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers() {}\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0010() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0010", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0010;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers(List/**/list) {}\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0); >+ List parameters = methodDecl.parameters(); >+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0); >+ variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0010;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers(int list) {}\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0011() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0011", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0011;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers(int i, List/**/list) {}\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0); >+ List parameters = methodDecl.parameters(); >+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(1); >+ variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0011;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers(int i, int list) {}\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0012() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0012", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0012;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers(int i, List.../**/list) {}\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0); >+ List parameters = methodDecl.parameters(); >+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(1); >+ variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0012;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" void getUsers(int i, int.../**/list) {}\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233 >+ public void test0013() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0013", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test0013;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" List/**/list;\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3); >+ >+ astRoot.recordModifications(); >+ >+ AST ast = astRoot.getAST(); >+ >+ List types = astRoot.types(); >+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations(); >+ FieldDeclaration fieldDeclaration= (FieldDeclaration) list.get(0); >+ fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT)); >+ >+ String preview = evaluateRewrite(cu, astRoot); >+ >+ buf= new StringBuffer(); >+ buf.append("package test0013;\n"); >+ buf.append("public class X {\n"); >+ buf.append(" int list;\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } > } >Index: src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java,v >retrieving revision 1.14 >diff -u -r1.14 ASTRewritingModifyingTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java 28 Apr 2009 17:49:27 -0000 1.14 >+++ src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java 17 Mar 2010 16:09:05 -0000 >@@ -82,10 +82,11 @@ > } > public CompilationUnit createCU( > ICompilationUnit unit, >- boolean resolveBindings) { >+ boolean resolveBindings, >+ int astLevel) { > > try { >- ASTParser c = ASTParser.newParser(AST_INTERNAL_JLS2); >+ ASTParser c = ASTParser.newParser(astLevel); > c.setSource(unit); > c.setResolveBindings(resolveBindings); > ASTNode result = c.createAST(null); >@@ -96,6 +97,12 @@ > } > } > >+ public CompilationUnit createCU( >+ ICompilationUnit unit, >+ boolean resolveBindings) { >+ return createCU(unit, resolveBindings, AST_INTERNAL_JLS2); >+ } >+ > public CompilationUnit createCU(char[] source) { > if (source == null) { > throw new IllegalArgumentException();
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 192233
: 162312