### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: buildnotes_jdt-core.html =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v retrieving revision 1.7316 diff -u -r1.7316 buildnotes_jdt-core.html --- buildnotes_jdt-core.html 22 Feb 2010 15:44:32 -0000 1.7316 +++ buildnotes_jdt-core.html 22 Feb 2010 16:43:11 -0000 @@ -49,6 +49,39 @@ (cvs).
+This new preference is controlled with the option:
+DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION
+
+/**
+ * FORMATTER / Option for alignment of arguments in annotation
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation"
+ * - possible values: values returned by createAlignmentValue(boolean, int, int)
call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ *
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.6
+ */
+
+For example, the following snippet:
++@MyAnnot(value1 = "this is an example", value2 = "of an annotation", value3 = "with several arguments", value4 = "which may need to be wrapped") +public class Test { +} ++formatted with this preference activated, will produce the following output +while using the
Eclipse [built-in]
profile:
++@MyAnnot(value1 = "this is an example", value2 = "of an annotation", + value3 = "with several arguments", + value4 = "which may need to be wrapped") +public class Test { +} ++See bug 282030 for more details. +
Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v retrieving revision 1.101 diff -u -r1.101 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 22 Feb 2010 14:51:59 -0000 1.101 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 22 Feb 2010 16:43:12 -0000 @@ -87,6 +87,17 @@ public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_enum_constant"; //$NON-NLS-1$ /** *+ * FORMATTER / Option for alignment of arguments in annotation + * - option id: "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" + * - possible values: values returned by+ * @see #createAlignmentValue(boolean, int, int) + * @since 3.6 + */ + public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_annotation"; //$NON-NLS-1$ + /** + *createAlignmentValue(boolean, int, int)
call + * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT) + ** FORMATTER / Option for alignment of arguments in explicit constructor call * - option id: "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" * - possible values: values returned bycreateAlignmentValue(boolean, int, int)
call Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v retrieving revision 1.227 diff -u -r1.227 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 22 Feb 2010 11:01:45 -0000 1.227 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 22 Feb 2010 16:43:13 -0000 @@ -4262,14 +4262,32 @@ MemberValuePair[] memberValuePairs = annotation.memberValuePairs; if (memberValuePairs != null) { int length = memberValuePairs.length; - for (int i = 0; i < length - 1; i++) { - memberValuePairs[i].traverse(this, scope); - this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_annotation); - if (this.preferences.insert_space_after_comma_in_annotation) { - this.scribe.space(); + Alignment annotationAlignment = this.scribe.createAlignment( + "annotationMemberValuePairs",//$NON-NLS-1$ + this.preferences.alignment_for_arguments_in_annotation, + length, + this.scribe.scanner.currentPosition); + this.scribe.enterAlignment(annotationAlignment); + boolean ok = false; + do { + try { + for (int i = 0; i < length; i++) { + if (i > 0) { + this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_annotation); + this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + } + this.scribe.alignFragment(annotationAlignment, i); + if (i > 0 && this.preferences.insert_space_after_comma_in_annotation) { + this.scribe.space(); + } + memberValuePairs[i].traverse(this, scope); + } + ok = true; + } catch (AlignmentException e) { + this.scribe.redoAlignment(e); } - } - memberValuePairs[length - 1].traverse(this, scope); + } while (!ok); + this.scribe.exitAlignment(annotationAlignment, true); } this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_annotation); return false; Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v retrieving revision 1.97 diff -u -r1.97 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 22 Feb 2010 14:52:00 -0000 1.97 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 22 Feb 2010 16:43:14 -0000 @@ -47,6 +47,7 @@ } public int alignment_for_arguments_in_allocation_expression; + public int alignment_for_arguments_in_annotation; public int alignment_for_arguments_in_enum_constant; public int alignment_for_arguments_in_explicit_constructor_call; public int alignment_for_arguments_in_method_invocation; @@ -336,6 +337,7 @@ public Map getMap() { Map options = new HashMap(); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression)); + options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION, getAlignment(this.alignment_for_arguments_in_annotation)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT, getAlignment(this.alignment_for_arguments_in_enum_constant)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, getAlignment(this.alignment_for_arguments_in_explicit_constructor_call)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation)); @@ -620,6 +622,16 @@ this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT; } } + final Object alignmentForArgumentsInAnnotationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION); + if (alignmentForArgumentsInAnnotationOption != null) { + try { + this.alignment_for_arguments_in_annotation = Integer.parseInt((String) alignmentForArgumentsInAnnotationOption); + } catch (NumberFormatException e) { + this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT; + } catch (ClassCastException e) { + this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT; + } + } final Object alignmentForArgumentsInEnumConstantOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT); if (alignmentForArgumentsInEnumConstantOption != null) { try { @@ -1968,6 +1980,7 @@ public void setDefaultSettings() { this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT; + this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_enum_constant = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT; @@ -2234,6 +2247,7 @@ public void setJavaConventionsSettings() { this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT; + this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_enum_constant = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v retrieving revision 1.20 diff -u -r1.20 FormatterBugsTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 16 Feb 2010 14:56:46 -0000 1.20 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 22 Feb 2010 16:43:16 -0000 @@ -582,6 +582,360 @@ } /** + * @bug 281655: [formatter] "Never join lines" does not work for annotations. + * @test Verify that "Never join lines" now works for annotations and also that + * element-value pairs are well wrapped using the new formatter option + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281655" + */ +public void testBug281655() throws JavaModelException { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + + " activationConfig = {\n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + " propertyValue = \"0/10 * * * * ?\")\n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug281655a() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", activationConfig = { @ActivationConfigProperty(propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug281655b() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(\n" + + " mappedName = \"filiality/SchedulerMQService\",\n" + + " activationConfig = { @ActivationConfigProperty(\n" + + " propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug281655c() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(\n" + + " mappedName = \"filiality/SchedulerMQService\",\n" + + " activationConfig = { @ActivationConfigProperty(\n" + + " propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug281655d() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(\n" + + " mappedName = \"filiality/SchedulerMQService\",\n" + + " activationConfig = { @ActivationConfigProperty(\n" + + " propertyName = \"cronTrigger\",\n" + + " propertyValue = \"0/10 * * * * ?\") })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug281655e() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_SHIFTED_SPLIT; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(\n" + + " mappedName = \"filiality/SchedulerMQService\",\n" + + " activationConfig = { @ActivationConfigProperty(\n" + + " propertyName = \"cronTrigger\",\n" + + " propertyValue = \"0/10 * * * * ?\") })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug281655f() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_PER_LINE_SPLIT; + String source = + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + + " activationConfig = { \n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + "propertyValue = \"0/10 * * * * ?\") \n" + + " })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + + " activationConfig = { @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + " propertyValue = \"0/10 * * * * ?\") })\n" + + "@RunAs(\"admin\")\n" + + "@ResourceAdapter(\"quartz-ra.rar\")\n" + + "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + + "public class X {\n" + + "}\n" + ); +} + +/** + * @bug 282030: [formatter] Java annotation formatting + * @test Verify that element-value pairs are well wrapped using the new formatter option + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=282030" + */ +public void testBug282030() throws JavaModelException { + String source = + "@DeclareParents(value =\n" + + "\"com.apress.springrecipes.calculator.ArithmeticCalculatorImpl\", defaultImpl =\n" + + "MaxCalculatorImpl.class) \n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@DeclareParents(\n" + + " value = \"com.apress.springrecipes.calculator.ArithmeticCalculatorImpl\",\n" + + " defaultImpl = MaxCalculatorImpl.class)\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug282030a() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT; + String source = + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n"; + formatSource(source, + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n" + ); +} +public void testBug282030b() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT; + String source = + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n"; + formatSource(source, + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\",\n" + + " value3 = \"with several arguments\",\n" + + " value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n" + ); +} +public void testBug282030c() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT; + String source = + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n"; + formatSource(source, + "@MyAnnot(\n" + + " value1 = \"this is an example\", value2 = \"of an annotation\",\n" + + " value3 = \"with several arguments\",\n" + + " value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n" + ); +} +public void testBug282030d() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT; + String source = + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n"; + formatSource(source, + "@MyAnnot(\n" + + " value1 = \"this is an example\",\n" + + " value2 = \"of an annotation\",\n" + + " value3 = \"with several arguments\",\n" + + " value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n" + ); +} +public void testBug282030e() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_SHIFTED_SPLIT; + String source = + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n"; + formatSource(source, + "@MyAnnot(\n" + + " value1 = \"this is an example\",\n" + + " value2 = \"of an annotation\",\n" + + " value3 = \"with several arguments\",\n" + + " value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n" + ); +} +public void testBug282030f() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_PER_LINE_SPLIT; + String source = + "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n"; + formatSource(source, + "@MyAnnot(value1 = \"this is an example\",\n" + + " value2 = \"of an annotation\",\n" + + " value3 = \"with several arguments\",\n" + + " value4 = \"which may need to be wrapped\")\n" + + "public class Test {\n" + + "}\n" + ); +} +public void testBug282030g1() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT; + String source = + "@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug282030g2() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE; + String source = + "@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MyAnnot1(\n" + + " member1 = \"sample1\",\n" + + " member2 = \"sample2\")\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug282030h1() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT; + String source = + "@MyAnnot1(name = \"sample1\", \n" + + " value = { \n" + + " @MyAnnot2(name = \"sample2\",\n" + + "value = \"demo\") \n" + + " })\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MyAnnot1(name = \"sample1\", value = { @MyAnnot2(\n" + + " name = \"sample2\",\n" + + " value = \"demo\") })\n" + + "public class X {\n" + + "}\n" + ); +} +public void testBug282030h2() throws JavaModelException { + this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE; + String source = + "@MyAnnot1(name = \"sample1\", \n" + + " value = { \n" + + " @MyAnnot2(name = \"sample2\",\n" + + "value = \"demo\") \n" + + " })\n" + + "public class X {\n" + + "}\n"; + formatSource(source, + "@MyAnnot1(\n" + + " name = \"sample1\",\n" + + " value = { @MyAnnot2(\n" + + " name = \"sample2\",\n" + + " value = \"demo\") })\n" + + "public class X {\n" + + "}\n" + ); +} + +/** * @bug 283467: [formatter] wrong indentation with 'Never join lines' selected * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=283467" */ Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v retrieving revision 1.256 diff -u -r1.256 FormatterRegressionTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 22 Feb 2010 11:01:35 -0000 1.256 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 22 Feb 2010 16:43:19 -0000 @@ -41,6 +41,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; +import org.eclipse.jdt.internal.formatter.align.Alignment; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; import org.eclipse.text.edits.TextEdit; @@ -7297,6 +7298,7 @@ DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); preferences.tab_char = DefaultCodeFormatterOptions.TAB; preferences.tab_size = 4; + preferences.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT; Hashtable javaCoreOptions = JavaCore.getOptions(); try { Hashtable newJavaCoreOptions = JavaCore.getOptions(); @@ -7315,6 +7317,29 @@ JavaCore.setOptions(javaCoreOptions); } } + public void test527b() { + Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings(); + DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); + preferences.tab_char = DefaultCodeFormatterOptions.TAB; + preferences.tab_size = 4; + Hashtable javaCoreOptions = JavaCore.getOptions(); + try { + Hashtable newJavaCoreOptions = JavaCore.getOptions(); + newJavaCoreOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + newJavaCoreOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + newJavaCoreOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + JavaCore.setOptions(newJavaCoreOptions); + + Map compilerOptions = new HashMap(); + compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions); + runTest(codeFormatter, "test527b", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$ + } finally { + JavaCore.setOptions(javaCoreOptions); + } + } /** * https://bugs.eclipse.org/bugs/show_bug.cgi?id=79779 Index: workspace/Formatter/test527b/A_in.java =================================================================== RCS file: workspace/Formatter/test527b/A_in.java diff -N workspace/Formatter/test527b/A_in.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/test527b/A_in.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,9 @@ +package test527b; + +@Jpf.Controller( + catches={ + @Jpf.Catch(type=java.lang.Exception.class, method="handleException"), + @Jpf.Catch(type=PageFlowException.class, method="handlePageFlowException") + } + ) + public class A {} Index: workspace/Formatter/test527b/A_out.java =================================================================== RCS file: workspace/Formatter/test527b/A_out.java diff -N workspace/Formatter/test527b/A_out.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/test527b/A_out.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,10 @@ +package test527b; + +@Jpf.Controller( + catches = { + @Jpf.Catch(type = java.lang.Exception.class, + method = "handleException"), + @Jpf.Catch(type = PageFlowException.class, + method = "handlePageFlowException") }) +public class A { +}