Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2014-02-04 14:02:08 +0000
committerMarkus Keller2014-02-04 14:06:01 +0000
commit055cf2299e246e07310e3c00069174f749475bd4 (patch)
tree038d417a9de3b733235ca1bef7306dbf1657209e
parentcafb00c9a05a5f3d6c3b24a32fe9b4ce9e8ba449 (diff)
downloadeclipse.jdt.core-055cf2299e246e07310e3c00069174f749475bd4.tar.gz
eclipse.jdt.core-055cf2299e246e07310e3c00069174f749475bd4.tar.xz
eclipse.jdt.core-055cf2299e246e07310e3c00069174f749475bd4.zip
Bug 427362: [1.8][dom ast] ASTRewriteFormatter uses wrong "Insert new
line after annotation" option for SingleVariableDeclaration
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java22
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java8
2 files changed, 25 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
index 8b8ee0f4ca..325755cbdc 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -3095,12 +3095,28 @@ public class ASTRewritingMethodDeclTest extends ASTRewritingTest {
rewrite.replace((ASTNode) decl.modifiers().get(0), markerAnnotation, null);
}
+ {
+ SingleVariableDeclaration decl= ast.newSingleVariableDeclaration();
+
+ MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("X"));
+ decl.modifiers().add(markerAnnotation);
+
+ Type type= ast.newPrimitiveType(PrimitiveType.INT);
+ decl.setType(type);
+
+ decl.setName(ast.newSimpleName("e"));
+
+ ListRewrite listRewrite= rewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
+ listRewrite.insertLast(decl, null);
+ }
+
String preview= evaluateRewrite(cu, rewrite);
buf= new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
- buf.append(" public void foo(@X @A int a, @B2 int b, @X int c, @X int d) {\n");
+ buf.append(" public void foo(@X @A int a, @B2 int b, @X int c, @X int d, @X int e) {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
@@ -3112,7 +3128,7 @@ public class ASTRewritingMethodDeclTest extends ASTRewritingTest {
buf= new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
- buf.append(" public void foo(@X\n @A int a, @B2 int b, @X\n int c, @X int d) {\n");
+ buf.append(" public void foo(@X\n @A int a, @B2 int b, @X\n int c, @X int d, @X\n int e) {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java
index 981546cdf5..f5c14e45a0 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -298,10 +298,14 @@ public final class ASTRewriteFormatter {
code= CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
- case ASTNode.SINGLE_VARIABLE_DECLARATION:
suffix= ";"; //$NON-NLS-1$
code= CodeFormatter.K_STATEMENTS;
break;
+ case ASTNode.SINGLE_VARIABLE_DECLARATION:
+ prefix= "void m("; //$NON-NLS-1$
+ suffix= ");"; //$NON-NLS-1$
+ code= CodeFormatter.K_CLASS_BODY_DECLARATIONS;
+ break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
prefix= "A "; //$NON-NLS-1$
suffix= ";"; //$NON-NLS-1$

Back to the top