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

Collapse All | Expand All

(-)buildnotes_jdt-core.html (+33 lines)
Lines 49-54 Link Here
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A36">cvs</a>).
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A36">cvs</a>).
50
<h2>What's new in this drop</h2>
50
<h2>What's new in this drop</h2>
51
<ul>
51
<ul>
52
<li>
53
Added a new formatter preferences to align annotation arguments (ie. element-value pairs).
54
<p>
55
This new preference is controlled with the option:</p>
56
<code>DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION</code>
57
<pre>
58
/**
59
 * FORMATTER / Option for alignment of arguments in annotation
60
 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation"
61
 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
62
 *     - default:           createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
63
 * 
64
 * @see #createAlignmentValue(boolean, int, int)
65
 * @since 3.6
66
 */
67
</pre>
68
<p>For example, the following snippet:</p>
69
<pre>
70
@MyAnnot(value1 = "this is an example", value2 = "of an annotation", value3 = "with several arguments", value4 = "which may need to be wrapped")
71
public class Test {
72
}
73
</pre>
74
formatted with this preference activated, will produce the following output
75
while using the <code>Eclipse [built-in]</code> profile:
76
<pre>
77
@MyAnnot(value1 = "this is an example", value2 = "of an annotation",
78
		value3 = "with several arguments",
79
		value4 = "which may need to be wrapped")
80
public class Test {
81
}
82
</pre>
83
See bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=282030">282030</a> for more details.
84
</li>
52
<li>In order to get bindings outside of the Eclipse environment, the following method has been added on the ASTParser class.
85
<li>In order to get bindings outside of the Eclipse environment, the following method has been added on the ASTParser class.
53
<br>See bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391">206391</a> for details.<br>
86
<br>See bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391">206391</a> for details.<br>
54
<pre>
87
<pre>
(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (+11 lines)
Lines 87-92 Link Here
87
	public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_enum_constant";	 //$NON-NLS-1$
87
	public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_enum_constant";	 //$NON-NLS-1$
88
	/**
88
	/**
89
	 * <pre>
89
	 * <pre>
90
	 * FORMATTER / Option for alignment of arguments in annotation
91
	 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation"
92
	 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
93
	 *     - default:           createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
94
	 * </pre>
95
	 * @see #createAlignmentValue(boolean, int, int)
96
	 * @since 3.6
97
	 */
98
	public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_annotation";	 //$NON-NLS-1$
99
	/**
100
	 * <pre>
90
	 * FORMATTER / Option for alignment of arguments in explicit constructor call
101
	 * FORMATTER / Option for alignment of arguments in explicit constructor call
91
	 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call"
102
	 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call"
92
	 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
103
	 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-7 / +25 lines)
Lines 4262-4275 Link Here
4262
		MemberValuePair[] memberValuePairs = annotation.memberValuePairs;
4262
		MemberValuePair[] memberValuePairs = annotation.memberValuePairs;
4263
		if (memberValuePairs != null) {
4263
		if (memberValuePairs != null) {
4264
			int length = memberValuePairs.length;
4264
			int length = memberValuePairs.length;
4265
			for (int i = 0; i < length - 1; i++) {
4265
			Alignment annotationAlignment = this.scribe.createAlignment(
4266
				memberValuePairs[i].traverse(this, scope);
4266
					"annotationMemberValuePairs",//$NON-NLS-1$
4267
				this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_annotation);
4267
					this.preferences.alignment_for_arguments_in_annotation,
4268
				if (this.preferences.insert_space_after_comma_in_annotation) {
4268
					length,
4269
					this.scribe.space();
4269
					this.scribe.scanner.currentPosition);
4270
			this.scribe.enterAlignment(annotationAlignment);
4271
			boolean ok = false;
4272
			do {
4273
				try {
4274
					for (int i = 0; i < length; i++) {
4275
						if (i > 0) {
4276
							this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_annotation);
4277
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
4278
						}
4279
						this.scribe.alignFragment(annotationAlignment, i);
4280
						if (i > 0 && this.preferences.insert_space_after_comma_in_annotation) {
4281
							this.scribe.space();
4282
						}
4283
						memberValuePairs[i].traverse(this, scope);
4284
					}
4285
					ok = true;
4286
				} catch (AlignmentException e) {
4287
					this.scribe.redoAlignment(e);
4270
				}
4288
				}
4271
			}
4289
			} while (!ok);
4272
			memberValuePairs[length - 1].traverse(this, scope);
4290
			this.scribe.exitAlignment(annotationAlignment, true);
4273
		}
4291
		}
4274
		this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_annotation);
4292
		this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_annotation);
4275
		return false;
4293
		return false;
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (+14 lines)
Lines 47-52 Link Here
47
	}
47
	}
48
48
49
	public int alignment_for_arguments_in_allocation_expression;
49
	public int alignment_for_arguments_in_allocation_expression;
50
	public int alignment_for_arguments_in_annotation;
50
	public int alignment_for_arguments_in_enum_constant;
51
	public int alignment_for_arguments_in_enum_constant;
51
	public int alignment_for_arguments_in_explicit_constructor_call;
52
	public int alignment_for_arguments_in_explicit_constructor_call;
52
	public int alignment_for_arguments_in_method_invocation;
53
	public int alignment_for_arguments_in_method_invocation;
Lines 336-341 Link Here
336
	public Map getMap() {
337
	public Map getMap() {
337
		Map options = new HashMap();
338
		Map options = new HashMap();
338
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression));
339
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression));
340
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION, getAlignment(this.alignment_for_arguments_in_annotation));
339
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT, getAlignment(this.alignment_for_arguments_in_enum_constant));
341
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT, getAlignment(this.alignment_for_arguments_in_enum_constant));
340
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, getAlignment(this.alignment_for_arguments_in_explicit_constructor_call));
342
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, getAlignment(this.alignment_for_arguments_in_explicit_constructor_call));
341
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation));
343
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation));
Lines 620-625 Link Here
620
				this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
622
				this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
621
			}
623
			}
622
		}
624
		}
625
		final Object alignmentForArgumentsInAnnotationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION);
626
		if (alignmentForArgumentsInAnnotationOption != null) {
627
			try {
628
				this.alignment_for_arguments_in_annotation = Integer.parseInt((String) alignmentForArgumentsInAnnotationOption);
629
			} catch (NumberFormatException e) {
630
				this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
631
			} catch (ClassCastException e) {
632
				this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
633
			}
634
		}
623
		final Object alignmentForArgumentsInEnumConstantOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT);
635
		final Object alignmentForArgumentsInEnumConstantOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT);
624
		if (alignmentForArgumentsInEnumConstantOption != null) {
636
		if (alignmentForArgumentsInEnumConstantOption != null) {
625
			try {
637
			try {
Lines 1968-1973 Link Here
1968
1980
1969
	public void setDefaultSettings() {
1981
	public void setDefaultSettings() {
1970
		this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
1982
		this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
1983
		this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
1971
		this.alignment_for_arguments_in_enum_constant = Alignment.M_COMPACT_SPLIT;
1984
		this.alignment_for_arguments_in_enum_constant = Alignment.M_COMPACT_SPLIT;
1972
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
1985
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
1973
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
1986
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
Lines 2234-2239 Link Here
2234
2247
2235
	public void setJavaConventionsSettings() {
2248
	public void setJavaConventionsSettings() {
2236
		this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
2249
		this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
2250
		this.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
2237
		this.alignment_for_arguments_in_enum_constant = Alignment.M_COMPACT_SPLIT;
2251
		this.alignment_for_arguments_in_enum_constant = Alignment.M_COMPACT_SPLIT;
2238
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
2252
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
2239
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
2253
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+354 lines)
Lines 582-587 Link Here
582
}
582
}
583
583
584
/**
584
/**
585
 * @bug 281655: [formatter] "Never join lines" does not work for annotations.
586
 * @test Verify that "Never join lines" now works for annotations and also that
587
 * 		element-value pairs are well wrapped using the new formatter option
588
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281655"
589
 */
590
public void testBug281655() throws JavaModelException {
591
	this.formatterPrefs.join_wrapped_lines = false;
592
	String source =
593
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
594
		"        activationConfig = { \n" + 
595
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
596
		"propertyValue = \"0/10 * * * * ?\") \n" + 
597
		"        })\n" + 
598
		"@RunAs(\"admin\")\n" + 
599
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
600
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
601
		"public class X {\n" + 
602
		"}\n";
603
	formatSource(source,
604
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + 
605
		"		activationConfig = {\n" + 
606
		"			@ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
607
		"					propertyValue = \"0/10 * * * * ?\")\n" + 
608
		"		})\n" + 
609
		"@RunAs(\"admin\")\n" + 
610
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
611
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
612
		"public class X {\n" + 
613
		"}\n"
614
	);
615
}
616
public void testBug281655a() throws JavaModelException {
617
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT;
618
	String source =
619
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
620
		"        activationConfig = { \n" + 
621
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
622
		"propertyValue = \"0/10 * * * * ?\") \n" + 
623
		"        })\n" + 
624
		"@RunAs(\"admin\")\n" + 
625
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
626
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
627
		"public class X {\n" + 
628
		"}\n";
629
	formatSource(source,
630
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", activationConfig = { @ActivationConfigProperty(propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" + 
631
		"@RunAs(\"admin\")\n" + 
632
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
633
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
634
		"public class X {\n" + 
635
		"}\n"
636
	);
637
}
638
public void testBug281655b() throws JavaModelException {
639
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
640
	String source =
641
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
642
		"        activationConfig = { \n" + 
643
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
644
		"propertyValue = \"0/10 * * * * ?\") \n" + 
645
		"        })\n" + 
646
		"@RunAs(\"admin\")\n" + 
647
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
648
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
649
		"public class X {\n" + 
650
		"}\n";
651
	formatSource(source,
652
		"@MessageDriven(\n" + 
653
		"		mappedName = \"filiality/SchedulerMQService\",\n" + 
654
		"		activationConfig = { @ActivationConfigProperty(\n" + 
655
		"				propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" + 
656
		"@RunAs(\"admin\")\n" + 
657
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
658
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
659
		"public class X {\n" + 
660
		"}\n"
661
	);
662
}
663
public void testBug281655c() throws JavaModelException {
664
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
665
	String source =
666
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
667
		"        activationConfig = { \n" + 
668
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
669
		"propertyValue = \"0/10 * * * * ?\") \n" + 
670
		"        })\n" + 
671
		"@RunAs(\"admin\")\n" + 
672
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
673
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
674
		"public class X {\n" + 
675
		"}\n";
676
	formatSource(source,
677
		"@MessageDriven(\n" + 
678
		"		mappedName = \"filiality/SchedulerMQService\",\n" + 
679
		"		activationConfig = { @ActivationConfigProperty(\n" + 
680
		"				propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" + 
681
		"@RunAs(\"admin\")\n" + 
682
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
683
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
684
		"public class X {\n" + 
685
		"}\n"
686
	);
687
}
688
public void testBug281655d() throws JavaModelException {
689
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
690
	String source =
691
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
692
		"        activationConfig = { \n" + 
693
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
694
		"propertyValue = \"0/10 * * * * ?\") \n" + 
695
		"        })\n" + 
696
		"@RunAs(\"admin\")\n" + 
697
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
698
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
699
		"public class X {\n" + 
700
		"}\n";
701
	formatSource(source,
702
		"@MessageDriven(\n" + 
703
		"		mappedName = \"filiality/SchedulerMQService\",\n" + 
704
		"		activationConfig = { @ActivationConfigProperty(\n" + 
705
		"				propertyName = \"cronTrigger\",\n" + 
706
		"				propertyValue = \"0/10 * * * * ?\") })\n" + 
707
		"@RunAs(\"admin\")\n" + 
708
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
709
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
710
		"public class X {\n" + 
711
		"}\n"
712
	);
713
}
714
public void testBug281655e() throws JavaModelException {
715
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_SHIFTED_SPLIT;
716
	String source =
717
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
718
		"        activationConfig = { \n" + 
719
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
720
		"propertyValue = \"0/10 * * * * ?\") \n" + 
721
		"        })\n" + 
722
		"@RunAs(\"admin\")\n" + 
723
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
724
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
725
		"public class X {\n" + 
726
		"}\n";
727
	formatSource(source,
728
		"@MessageDriven(\n" + 
729
		"		mappedName = \"filiality/SchedulerMQService\",\n" + 
730
		"			activationConfig = { @ActivationConfigProperty(\n" + 
731
		"					propertyName = \"cronTrigger\",\n" + 
732
		"						propertyValue = \"0/10 * * * * ?\") })\n" + 
733
		"@RunAs(\"admin\")\n" + 
734
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
735
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
736
		"public class X {\n" + 
737
		"}\n"
738
	);
739
}
740
public void testBug281655f() throws JavaModelException {
741
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_PER_LINE_SPLIT;
742
	String source =
743
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" + 
744
		"        activationConfig = { \n" + 
745
		"            @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
746
		"propertyValue = \"0/10 * * * * ?\") \n" + 
747
		"        })\n" + 
748
		"@RunAs(\"admin\")\n" + 
749
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
750
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
751
		"public class X {\n" + 
752
		"}\n";
753
	formatSource(source,
754
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + 
755
		"		activationConfig = { @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
756
		"				propertyValue = \"0/10 * * * * ?\") })\n" + 
757
		"@RunAs(\"admin\")\n" + 
758
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
759
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
760
		"public class X {\n" + 
761
		"}\n"
762
	);
763
}
764
765
/**
766
 * @bug 282030: [formatter] Java annotation formatting
767
 * @test Verify that element-value pairs are well wrapped using the new formatter option
768
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=282030"
769
 */
770
public void testBug282030() throws JavaModelException {
771
	String source =
772
		"@DeclareParents(value =\n" + 
773
		"\"com.apress.springrecipes.calculator.ArithmeticCalculatorImpl\", defaultImpl =\n" + 
774
		"MaxCalculatorImpl.class) \n" + 
775
		"public class X {\n" + 
776
		"}\n";
777
	formatSource(source,
778
		"@DeclareParents(\n" + 
779
		"		value = \"com.apress.springrecipes.calculator.ArithmeticCalculatorImpl\",\n" + 
780
		"		defaultImpl = MaxCalculatorImpl.class)\n" + 
781
		"public class X {\n" + 
782
		"}\n"
783
	);
784
}
785
public void testBug282030a() throws JavaModelException {
786
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT;
787
	String source =
788
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
789
		"public class Test {\n" + 
790
		"}\n";
791
	formatSource(source,
792
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
793
		"public class Test {\n" + 
794
		"}\n"
795
	);
796
}
797
public void testBug282030b() throws JavaModelException {
798
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
799
	String source =
800
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
801
		"public class Test {\n" + 
802
		"}\n";
803
	formatSource(source,
804
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\",\n" + 
805
		"		value3 = \"with several arguments\",\n" + 
806
		"		value4 = \"which may need to be wrapped\")\n" + 
807
		"public class Test {\n" + 
808
		"}\n"
809
	);
810
}
811
public void testBug282030c() throws JavaModelException {
812
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
813
	String source =
814
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
815
		"public class Test {\n" + 
816
		"}\n";
817
	formatSource(source,
818
		"@MyAnnot(\n" + 
819
		"		value1 = \"this is an example\", value2 = \"of an annotation\",\n" + 
820
		"		value3 = \"with several arguments\",\n" + 
821
		"		value4 = \"which may need to be wrapped\")\n" + 
822
		"public class Test {\n" + 
823
		"}\n"
824
	);
825
}
826
public void testBug282030d() throws JavaModelException {
827
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
828
	String source =
829
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
830
		"public class Test {\n" + 
831
		"}\n";
832
	formatSource(source,
833
		"@MyAnnot(\n" + 
834
		"		value1 = \"this is an example\",\n" + 
835
		"		value2 = \"of an annotation\",\n" + 
836
		"		value3 = \"with several arguments\",\n" + 
837
		"		value4 = \"which may need to be wrapped\")\n" + 
838
		"public class Test {\n" + 
839
		"}\n"
840
	);
841
}
842
public void testBug282030e() throws JavaModelException {
843
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_SHIFTED_SPLIT;
844
	String source =
845
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
846
		"public class Test {\n" + 
847
		"}\n";
848
	formatSource(source,
849
		"@MyAnnot(\n" + 
850
		"		value1 = \"this is an example\",\n" + 
851
		"			value2 = \"of an annotation\",\n" + 
852
		"			value3 = \"with several arguments\",\n" + 
853
		"			value4 = \"which may need to be wrapped\")\n" + 
854
		"public class Test {\n" + 
855
		"}\n"
856
	);
857
}
858
public void testBug282030f() throws JavaModelException {
859
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_PER_LINE_SPLIT;
860
	String source =
861
		"@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" + 
862
		"public class Test {\n" + 
863
		"}\n";
864
	formatSource(source,
865
		"@MyAnnot(value1 = \"this is an example\",\n" + 
866
		"		value2 = \"of an annotation\",\n" + 
867
		"		value3 = \"with several arguments\",\n" + 
868
		"		value4 = \"which may need to be wrapped\")\n" + 
869
		"public class Test {\n" + 
870
		"}\n"
871
	);
872
}
873
public void testBug282030g1() throws JavaModelException {
874
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
875
	String source =
876
		"@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" + 
877
		"public class X {\n" + 
878
		"}\n";
879
	formatSource(source,
880
		"@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" + 
881
		"public class X {\n" + 
882
		"}\n"
883
	);
884
}
885
public void testBug282030g2() throws JavaModelException {
886
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE;
887
	String source =
888
		"@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" + 
889
		"public class X {\n" + 
890
		"}\n";
891
	formatSource(source,
892
		"@MyAnnot1(\n" +
893
		"		member1 = \"sample1\",\n" +
894
		"		member2 = \"sample2\")\n" + 
895
		"public class X {\n" + 
896
		"}\n"
897
	);
898
}
899
public void testBug282030h1() throws JavaModelException {
900
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
901
	String source =
902
		"@MyAnnot1(name = \"sample1\", \n" + 
903
		"                value = { \n" + 
904
		"                        @MyAnnot2(name = \"sample2\",\n" + 
905
		"value = \"demo\") \n" + 
906
		"                })\n" + 
907
		"public class X {\n" + 
908
		"}\n";
909
	formatSource(source,
910
		"@MyAnnot1(name = \"sample1\", value = { @MyAnnot2(\n" + 
911
		"		name = \"sample2\",\n" + 
912
		"		value = \"demo\") })\n" + 
913
		"public class X {\n" + 
914
		"}\n"
915
	);
916
}
917
public void testBug282030h2() throws JavaModelException {
918
	this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE;
919
	String source =
920
		"@MyAnnot1(name = \"sample1\", \n" + 
921
		"                value = { \n" + 
922
		"                        @MyAnnot2(name = \"sample2\",\n" + 
923
		"value = \"demo\") \n" + 
924
		"                })\n" + 
925
		"public class X {\n" + 
926
		"}\n";
927
	formatSource(source,
928
		"@MyAnnot1(\n" +
929
		"		name = \"sample1\",\n" +
930
		"		value = { @MyAnnot2(\n" +
931
		"				name = \"sample2\",\n" + 
932
		"				value = \"demo\") })\n" + 
933
		"public class X {\n" + 
934
		"}\n"
935
	);
936
}
937
938
/**
585
 * @bug 283467: [formatter] wrong indentation with 'Never join lines' selected
939
 * @bug 283467: [formatter] wrong indentation with 'Never join lines' selected
586
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=283467"
940
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=283467"
587
 */
941
 */
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (+25 lines)
Lines 41-46 Link Here
41
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
41
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
42
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
42
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
43
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
43
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
44
import org.eclipse.jdt.internal.formatter.align.Alignment;
44
import org.eclipse.jface.text.IRegion;
45
import org.eclipse.jface.text.IRegion;
45
import org.eclipse.jface.text.Region;
46
import org.eclipse.jface.text.Region;
46
import org.eclipse.text.edits.TextEdit;
47
import org.eclipse.text.edits.TextEdit;
Lines 7297-7302 Link Here
7297
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
7298
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
7298
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
7299
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
7299
        preferences.tab_size = 4;
7300
        preferences.tab_size = 4;
7301
		preferences.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT;
7300
		Hashtable javaCoreOptions = JavaCore.getOptions();
7302
		Hashtable javaCoreOptions = JavaCore.getOptions();
7301
		try {
7303
		try {
7302
			Hashtable newJavaCoreOptions = JavaCore.getOptions();
7304
			Hashtable newJavaCoreOptions = JavaCore.getOptions();
Lines 7315-7320 Link Here
7315
			JavaCore.setOptions(javaCoreOptions);
7317
			JavaCore.setOptions(javaCoreOptions);
7316
		}
7318
		}
7317
	}
7319
	}
7320
	public void test527b() {
7321
		Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
7322
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
7323
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
7324
        preferences.tab_size = 4;
7325
		Hashtable javaCoreOptions = JavaCore.getOptions();
7326
		try {
7327
			Hashtable newJavaCoreOptions = JavaCore.getOptions();
7328
			newJavaCoreOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
7329
			newJavaCoreOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
7330
			newJavaCoreOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
7331
			JavaCore.setOptions(newJavaCoreOptions);
7332
7333
			Map compilerOptions = new HashMap();
7334
			compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
7335
			compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
7336
			compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
7337
			DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
7338
			runTest(codeFormatter, "test527b", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
7339
		} finally {
7340
			JavaCore.setOptions(javaCoreOptions);
7341
		}
7342
	}
7318
7343
7319
	/**
7344
	/**
7320
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=79779
7345
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=79779
(-)workspace/Formatter/test527b/A_in.java (+9 lines)
Added Link Here
1
package test527b;
2
3
@Jpf.Controller(
4
	    catches={
5
	       @Jpf.Catch(type=java.lang.Exception.class, method="handleException"),
6
	       @Jpf.Catch(type=PageFlowException.class, method="handlePageFlowException")
7
	    }
8
	)
9
	public class A {}
(-)workspace/Formatter/test527b/A_out.java (+10 lines)
Added Link Here
1
package test527b;
2
3
@Jpf.Controller(
4
		catches = {
5
				@Jpf.Catch(type = java.lang.Exception.class,
6
						method = "handleException"),
7
				@Jpf.Catch(type = PageFlowException.class,
8
						method = "handlePageFlowException") })
9
public class A {
10
}

Return to bug 282030