### Eclipse Workspace Patch 1.0 #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.23 diff -u -r1.23 ASTRewritingTypeDeclTest.java --- src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java 3 Dec 2008 14:36:39 -0000 1.23 +++ src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java 30 Jan 2009 10:42:43 -0000 @@ -16,10 +16,12 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.dom.*; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; public class ASTRewritingTypeDeclTest extends ASTRewritingTest { @@ -873,6 +875,55 @@ assertEqualString(preview, buf.toString()); } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=262517 + public void testSingleMemberAnnotation1() throws Exception { + String previousValue = null; + try { + previousValue = this.project1.getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_ANNOTATION, false); + + this.project1.setOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_ANNOTATION, JavaCore.INSERT); + + IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("public class E {\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); + + CompilationUnit astRoot= createAST3(cu); + ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); + AST ast= astRoot.getAST(); + + { + TypeDeclaration type= findTypeDeclaration(astRoot, "E"); + + SingleMemberAnnotation newAnnot= ast.newSingleMemberAnnotation(); + + newAnnot.setTypeName(ast.newName("SuppressWarnings")); + + StringLiteral newStringLiteral= ast.newStringLiteral(); + newStringLiteral.setLiteralValue("deprecation"); + newAnnot.setValue(newStringLiteral); + + ListRewrite modifiers= rewrite.getListRewrite(type, TypeDeclaration.MODIFIERS2_PROPERTY); + modifiers.insertFirst(newAnnot, null); + } + + String preview= evaluateRewrite(cu, rewrite); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@SuppressWarnings (\"deprecation\")\n"); + buf.append("public class E {\n"); + buf.append("}\n"); + assertEqualString(preview, buf.toString()); + } finally { + if (previousValue != null) { + this.project1.setOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_ANNOTATION, previousValue); + } + } + } public void testSingleVariableDeclaration() throws Exception { IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); #P org.eclipse.jdt.core 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.24 diff -u -r1.24 ASTRewriteFormatter.java --- dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java 27 Jun 2008 16:04:10 -0000 1.24 +++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java 30 Jan 2009 10:42:45 -0000 @@ -18,6 +18,7 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.Annotation; import org.eclipse.jdt.core.dom.Block; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.Expression; @@ -264,7 +265,12 @@ code= CodeFormatter.K_STATEMENTS; } } else if (node instanceof Expression && node.getNodeType() != ASTNode.VARIABLE_DECLARATION_EXPRESSION) { - code= CodeFormatter.K_EXPRESSION; + if (node instanceof Annotation) { + suffix= "\nclass A {}"; //$NON-NLS-1$ + code= CodeFormatter.K_COMPILATION_UNIT; + } else { + code= CodeFormatter.K_EXPRESSION; + } } else if (node instanceof BodyDeclaration) { code= CodeFormatter.K_CLASS_BODY_DECLARATIONS; } else {