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); |