View | Details | Raw Unified | Return to bug 262517 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java (+51 lines)
Lines 16-25 Link Here
16
16
17
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.IPackageFragment;
18
import org.eclipse.jdt.core.IPackageFragment;
19
import org.eclipse.jdt.core.JavaCore;
19
20
20
import org.eclipse.jdt.core.dom.*;
21
import org.eclipse.jdt.core.dom.*;
21
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
22
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
22
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
23
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
24
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
23
25
24
public class ASTRewritingTypeDeclTest extends ASTRewritingTest {
26
public class ASTRewritingTypeDeclTest extends ASTRewritingTest {
25
27
Lines 873-878 Link Here
873
		assertEqualString(preview, buf.toString());
875
		assertEqualString(preview, buf.toString());
874
876
875
	}
877
	}
878
	
879
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262517
880
	public void testSingleMemberAnnotation1() throws Exception {
881
		String previousValue = null;
882
		try {
883
			previousValue = this.project1.getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_ANNOTATION, false);
884
			
885
			this.project1.setOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_ANNOTATION, JavaCore.INSERT);
886
			
887
			IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
888
			StringBuffer buf= new StringBuffer();
889
			buf.append("package test1;\n");
890
			buf.append("public class E {\n");
891
			buf.append("}\n");
892
			ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
893
	
894
			CompilationUnit astRoot= createAST3(cu);
895
			ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
896
			AST ast= astRoot.getAST();
897
	
898
			{
899
				TypeDeclaration type= findTypeDeclaration(astRoot, "E");
900
	
901
				SingleMemberAnnotation newAnnot= ast.newSingleMemberAnnotation();
902
				
903
				newAnnot.setTypeName(ast.newName("SuppressWarnings"));
904
				
905
				StringLiteral newStringLiteral= ast.newStringLiteral();
906
				newStringLiteral.setLiteralValue("deprecation");
907
				newAnnot.setValue(newStringLiteral);
908
	
909
				ListRewrite modifiers= rewrite.getListRewrite(type, TypeDeclaration.MODIFIERS2_PROPERTY);
910
				modifiers.insertFirst(newAnnot, null);
911
			}
912
	
913
			String preview= evaluateRewrite(cu, rewrite);
914
	
915
			buf= new StringBuffer();
916
			buf.append("package test1;\n");
917
			buf.append("@SuppressWarnings (\"deprecation\")\n");
918
			buf.append("public class E {\n");
919
			buf.append("}\n");
920
			assertEqualString(preview, buf.toString());
921
		} finally {
922
			if (previousValue != null) {
923
				this.project1.setOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_ANNOTATION, previousValue);
924
			}
925
		}
926
	}
876
927
877
	public void testSingleVariableDeclaration() throws Exception {
928
	public void testSingleVariableDeclaration() throws Exception {
878
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
929
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
(-)dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java (-1 / +7 lines)
Lines 18-23 Link Here
18
import org.eclipse.jdt.core.JavaCore;
18
import org.eclipse.jdt.core.JavaCore;
19
import org.eclipse.jdt.core.ToolFactory;
19
import org.eclipse.jdt.core.ToolFactory;
20
import org.eclipse.jdt.core.dom.ASTNode;
20
import org.eclipse.jdt.core.dom.ASTNode;
21
import org.eclipse.jdt.core.dom.Annotation;
21
import org.eclipse.jdt.core.dom.Block;
22
import org.eclipse.jdt.core.dom.Block;
22
import org.eclipse.jdt.core.dom.BodyDeclaration;
23
import org.eclipse.jdt.core.dom.BodyDeclaration;
23
import org.eclipse.jdt.core.dom.Expression;
24
import org.eclipse.jdt.core.dom.Expression;
Lines 264-270 Link Here
264
				code= CodeFormatter.K_STATEMENTS;
265
				code= CodeFormatter.K_STATEMENTS;
265
			}
266
			}
266
		} else if (node instanceof Expression && node.getNodeType() != ASTNode.VARIABLE_DECLARATION_EXPRESSION) {
267
		} else if (node instanceof Expression && node.getNodeType() != ASTNode.VARIABLE_DECLARATION_EXPRESSION) {
267
			code= CodeFormatter.K_EXPRESSION;
268
			if (node instanceof Annotation) {
269
				suffix= "\nclass A {}"; //$NON-NLS-1$
270
				code= CodeFormatter.K_COMPILATION_UNIT;
271
			} else {
272
				code= CodeFormatter.K_EXPRESSION;
273
			}
268
		} else if (node instanceof BodyDeclaration) {
274
		} else if (node instanceof BodyDeclaration) {
269
			code= CodeFormatter.K_CLASS_BODY_DECLARATIONS;
275
			code= CodeFormatter.K_CLASS_BODY_DECLARATIONS;
270
		} else {
276
		} else {

Return to bug 262517