View | Details | Raw Unified | Return to bug 71766
Collapse All | Expand All

(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (+11 lines)
Lines 115-120 Link Here
115
	public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_qualified_allocation_expression";	 //$NON-NLS-1$
115
	public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_qualified_allocation_expression";	 //$NON-NLS-1$
116
	/**
116
	/**
117
	 * <pre>
117
	 * <pre>
118
	 * FORMATTER / Option for alignment of assignment
119
	 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_assignment"
120
	 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
121
	 *     - default:           createAlignmentValue(false, M_NO_ALIGNMENT, INDENT_DEFAULT)
122
	 * </pre>
123
	 * @see #createAlignmentValue(boolean, int, int)
124
	 * @since 3.0
125
	 */
126
	public static final String FORMATTER_ALIGNMENT_FOR_ASSIGNMENT  = JavaCore.PLUGIN_ID + ".formatter.alignment_for_assignment";	 //$NON-NLS-1$
127
	/**
128
	 * <pre>
118
	 * FORMATTER / Option for alignment of binary expression
129
	 * FORMATTER / Option for alignment of binary expression
119
	 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_binary_expression"
130
	 *     - option id:         "org.eclipse.jdt.core.formatter.alignment_for_binary_expression"
120
	 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
131
	 *     - possible values:   values returned by <code>createAlignmentValue(boolean, int, int)</code> call
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-12 / +45 lines)
Lines 588-594 Link Here
588
			if (this.preferences.insert_space_after_assignment_operator) {
588
			if (this.preferences.insert_space_after_assignment_operator) {
589
				this.scribe.space();
589
				this.scribe.space();
590
			}
590
			}
591
			initialization.traverse(this, scope);
591
			Alignment assignmentAlignment = this.scribe.createAlignment("fieldDeclarationAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
592
			this.scribe.enterAlignment(assignmentAlignment);
593
			boolean ok = false;
594
			do {
595
				try {
596
					this.scribe.alignFragment(assignmentAlignment, 0);
597
					initialization.traverse(this, scope);
598
					ok = true;
599
				} catch(AlignmentException e){
600
					this.scribe.redoAlignment(e);
601
				}
602
			} while (!ok);		
603
			this.scribe.exitAlignment(assignmentAlignment, true);			
592
		}
604
		}
593
		
605
		
594
		this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
606
		this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
Lines 1105-1112 Link Here
1105
		}
1117
		}
1106
1118
1107
		formatTypeMembers(typeDeclaration);
1119
		formatTypeMembers(typeDeclaration);
1108
1109
		this.scribe.printComment();
1110
		
1120
		
1111
		if (indent_body_declarations_compare_to_header) {
1121
		if (indent_body_declarations_compare_to_header) {
1112
			this.scribe.unIndent();
1122
			this.scribe.unIndent();
Lines 1174-1181 Link Here
1174
		this.scribe.indent();
1184
		this.scribe.indent();
1175
1185
1176
		formatTypeMembers(typeDeclaration);
1186
		formatTypeMembers(typeDeclaration);
1177
		
1187
1178
		this.scribe.printComment();
1179
		this.scribe.unIndent();
1188
		this.scribe.unIndent();
1180
		if (this.preferences.insert_new_line_in_empty_anonymous_type_declaration) {
1189
		if (this.preferences.insert_new_line_in_empty_anonymous_type_declaration) {
1181
			this.scribe.printNewLine();
1190
			this.scribe.printNewLine();
Lines 1552-1558 Link Here
1552
			if (this.preferences.insert_space_after_assignment_operator) {
1561
			if (this.preferences.insert_space_after_assignment_operator) {
1553
				this.scribe.space();
1562
				this.scribe.space();
1554
			}
1563
			}
1555
			initialization.traverse(this, scope);
1564
			Alignment assignmentAlignment = this.scribe.createAlignment("localDeclarationAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
1565
			this.scribe.enterAlignment(assignmentAlignment);
1566
			boolean ok = false;
1567
			do {
1568
				try {
1569
					this.scribe.alignFragment(assignmentAlignment, 0);
1570
					initialization.traverse(this, scope);
1571
					ok = true;
1572
				} catch(AlignmentException e){
1573
					this.scribe.redoAlignment(e);
1574
				}
1575
			} while (!ok);		
1576
			this.scribe.exitAlignment(assignmentAlignment, true);			
1556
		}
1577
		}
1557
1578
1558
		if (isPartOfMultipleLocalDeclaration()) {
1579
		if (isPartOfMultipleLocalDeclaration()) {
Lines 1947-1953 Link Here
1947
				startIndex = memberAlignment.chunkStartIndex;
1968
				startIndex = memberAlignment.chunkStartIndex;
1948
				this.scribe.redoMemberAlignment(e);
1969
				this.scribe.redoMemberAlignment(e);
1949
			}
1970
			}
1950
		} while (!ok);		
1971
		} while (!ok);
1972
		this.scribe.printComment();
1951
		this.scribe.exitMemberAlignment(memberAlignment);
1973
		this.scribe.exitMemberAlignment(memberAlignment);
1952
	}
1974
	}
1953
1975
Lines 2659-2666 Link Here
2659
		if (this.preferences.insert_space_after_assignment_operator) {
2681
		if (this.preferences.insert_space_after_assignment_operator) {
2660
			this.scribe.space();
2682
			this.scribe.space();
2661
		}
2683
		}
2662
		assignment.expression.traverse(this, scope);
2684
2663
		
2685
		Alignment assignmentAlignment = this.scribe.createAlignment("assignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
2686
		this.scribe.enterAlignment(assignmentAlignment);
2687
		boolean ok = false;
2688
		do {
2689
			try {
2690
				this.scribe.alignFragment(assignmentAlignment, 0);
2691
				assignment.expression.traverse(this, scope);
2692
				ok = true;
2693
			} catch(AlignmentException e){
2694
				this.scribe.redoAlignment(e);
2695
			}
2696
		} while (!ok);		
2697
		this.scribe.exitAlignment(assignmentAlignment, true);
2698
2664
		if (numberOfParens > 0) {
2699
		if (numberOfParens > 0) {
2665
			manageClosingParenthesizedExpression(assignment, numberOfParens);
2700
			manageClosingParenthesizedExpression(assignment, numberOfParens);
2666
		}
2701
		}
Lines 3286-3294 Link Here
3286
			if (fieldsCount != 0 || methodsCount != 0 || membersCount != 0) {
3321
			if (fieldsCount != 0 || methodsCount != 0 || membersCount != 0) {
3287
				formatTypeMembers(typeDeclaration);
3322
				formatTypeMembers(typeDeclaration);
3288
			}
3323
			}
3289
	
3324
3290
			this.scribe.printComment();
3291
			
3292
			if (this.preferences.indent_body_declarations_compare_to_enum_constant_header) {
3325
			if (this.preferences.indent_body_declarations_compare_to_enum_constant_header) {
3293
				this.scribe.unIndent();
3326
				this.scribe.unIndent();
3294
			}
3327
			}
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (+14 lines)
Lines 50-55 Link Here
50
	public int alignment_for_arguments_in_explicit_constructor_call;
50
	public int alignment_for_arguments_in_explicit_constructor_call;
51
	public int alignment_for_arguments_in_method_invocation;
51
	public int alignment_for_arguments_in_method_invocation;
52
	public int alignment_for_arguments_in_qualified_allocation_expression;
52
	public int alignment_for_arguments_in_qualified_allocation_expression;
53
	public int alignment_for_assignment;
53
	public int alignment_for_binary_expression;
54
	public int alignment_for_binary_expression;
54
	public int alignment_for_compact_if;
55
	public int alignment_for_compact_if;
55
	public int alignment_for_conditional_expression;
56
	public int alignment_for_conditional_expression;
Lines 320-325 Link Here
320
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, getAlignment(this.alignment_for_arguments_in_explicit_constructor_call));
321
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, getAlignment(this.alignment_for_arguments_in_explicit_constructor_call));
321
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation));
322
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation));
322
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_qualified_allocation_expression));
323
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_qualified_allocation_expression));
324
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, getAlignment(this.alignment_for_assignment));
323
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression));
325
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression));
324
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if));
326
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if));
325
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression));
327
		options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression));
Lines 621-626 Link Here
621
				this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
623
				this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
622
			}
624
			}
623
		}
625
		}
626
		final Object alignmentForAssignmentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT);
627
		if (alignmentForAssignmentOption != null) {
628
			try {
629
				this.alignment_for_assignment = Integer.parseInt((String) alignmentForAssignmentOption);
630
			} catch (NumberFormatException e) {
631
				this.alignment_for_assignment =  Alignment.M_ONE_PER_LINE_SPLIT;
632
			} catch (ClassCastException e) {
633
				this.alignment_for_assignment =  Alignment.M_ONE_PER_LINE_SPLIT;
634
			}
635
		}
624
		final Object alignmentForBinaryExpressionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION);
636
		final Object alignmentForBinaryExpressionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION);
625
		if (alignmentForBinaryExpressionOption != null) {
637
		if (alignmentForBinaryExpressionOption != null) {
626
			try {
638
			try {
Lines 1819-1824 Link Here
1819
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
1831
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
1820
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
1832
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
1821
		this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
1833
		this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
1834
		this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
1822
		this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
1835
		this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
1823
		this.alignment_for_compact_if = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_INDENT_BY_ONE;
1836
		this.alignment_for_compact_if = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_INDENT_BY_ONE;
1824
		this.alignment_for_conditional_expression = Alignment.M_ONE_PER_LINE_SPLIT;
1837
		this.alignment_for_conditional_expression = Alignment.M_ONE_PER_LINE_SPLIT;
Lines 2069-2074 Link Here
2069
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
2082
		this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
2070
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
2083
		this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
2071
		this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
2084
		this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
2085
		this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
2072
		this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
2086
		this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
2073
		this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT;
2087
		this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT;
2074
		this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT;
2088
		this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT;
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-3 / +5 lines)
Lines 1009-1020 Link Here
1009
			if (this.memberAlignment != null) {
1009
			if (this.memberAlignment != null) {
1010
				// select the last alignment
1010
				// select the last alignment
1011
				if (this.currentAlignment.location.inputOffset > this.memberAlignment.location.inputOffset) {
1011
				if (this.currentAlignment.location.inputOffset > this.memberAlignment.location.inputOffset) {
1012
					this.indentationLevel = Math.max(this.indentationLevel, this.currentAlignment.breakIndentationLevel);
1012
					if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) {
1013
						this.currentAlignment.performFragmentEffect();
1014
					}
1013
				} else {
1015
				} else {
1014
					this.indentationLevel = Math.max(this.indentationLevel, this.memberAlignment.breakIndentationLevel);
1016
					this.indentationLevel = Math.max(this.indentationLevel, this.memberAlignment.breakIndentationLevel);
1015
				}
1017
				}
1016
			} else {
1018
			} else if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) {
1017
				this.indentationLevel = Math.max(this.indentationLevel, this.currentAlignment.breakIndentationLevel);
1019
				this.currentAlignment.performFragmentEffect();
1018
			}
1020
			}
1019
		}
1021
		}
1020
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
1022
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
(-)formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java (+9 lines)
Lines 405-408 Link Here
405
		    }
405
		    }
406
		}
406
		}
407
	}
407
	}
408
409
	public boolean isWrapped() {
410
		for (int i = 0, max = this.fragmentCount; i < max; i++) {
411
			if (this.fragmentBreaks[i] == BREAK) {
412
				return true;
413
			}
414
		}
415
		return false;
416
	}
408
}
417
}

Return to bug 71766