Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v retrieving revision 1.64 diff -u -r1.64 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 30 Aug 2005 17:32:49 -0000 1.64 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 30 Aug 2005 20:51:57 -0000 @@ -115,6 +115,17 @@ 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$ /** *
+ * FORMATTER / Option for alignment of assignment
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_assignment"
+ * - possible values: values returned by createAlignmentValue(boolean, int, int)
call
+ * - default: createAlignmentValue(false, M_NO_ALIGNMENT, INDENT_DEFAULT)
+ *
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.0
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_ASSIGNMENT = JavaCore.PLUGIN_ID + ".formatter.alignment_for_assignment"; //$NON-NLS-1$
+ /**
+ *
* FORMATTER / Option for alignment of binary expression
* - option id: "org.eclipse.jdt.core.formatter.alignment_for_binary_expression"
* - possible values: values returned by createAlignmentValue(boolean, int, int)
call
Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v
retrieving revision 1.165
diff -u -r1.165 CodeFormatterVisitor.java
--- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 30 Aug 2005 17:57:38 -0000 1.165
+++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 30 Aug 2005 20:51:58 -0000
@@ -588,7 +588,19 @@
if (this.preferences.insert_space_after_assignment_operator) {
this.scribe.space();
}
- initialization.traverse(this, scope);
+ Alignment assignmentAlignment = this.scribe.createAlignment("fieldDeclarationAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
+ this.scribe.enterAlignment(assignmentAlignment);
+ boolean ok = false;
+ do {
+ try {
+ this.scribe.alignFragment(assignmentAlignment, 0);
+ initialization.traverse(this, scope);
+ ok = true;
+ } catch(AlignmentException e){
+ this.scribe.redoAlignment(e);
+ }
+ } while (!ok);
+ this.scribe.exitAlignment(assignmentAlignment, true);
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
@@ -1105,8 +1117,6 @@
}
formatTypeMembers(typeDeclaration);
-
- this.scribe.printComment();
if (indent_body_declarations_compare_to_header) {
this.scribe.unIndent();
@@ -1174,8 +1184,7 @@
this.scribe.indent();
formatTypeMembers(typeDeclaration);
-
- this.scribe.printComment();
+
this.scribe.unIndent();
if (this.preferences.insert_new_line_in_empty_anonymous_type_declaration) {
this.scribe.printNewLine();
@@ -1552,7 +1561,19 @@
if (this.preferences.insert_space_after_assignment_operator) {
this.scribe.space();
}
- initialization.traverse(this, scope);
+ Alignment assignmentAlignment = this.scribe.createAlignment("localDeclarationAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
+ this.scribe.enterAlignment(assignmentAlignment);
+ boolean ok = false;
+ do {
+ try {
+ this.scribe.alignFragment(assignmentAlignment, 0);
+ initialization.traverse(this, scope);
+ ok = true;
+ } catch(AlignmentException e){
+ this.scribe.redoAlignment(e);
+ }
+ } while (!ok);
+ this.scribe.exitAlignment(assignmentAlignment, true);
}
if (isPartOfMultipleLocalDeclaration()) {
@@ -1947,7 +1968,8 @@
startIndex = memberAlignment.chunkStartIndex;
this.scribe.redoMemberAlignment(e);
}
- } while (!ok);
+ } while (!ok);
+ this.scribe.printComment();
this.scribe.exitMemberAlignment(memberAlignment);
}
@@ -2659,8 +2681,21 @@
if (this.preferences.insert_space_after_assignment_operator) {
this.scribe.space();
}
- assignment.expression.traverse(this, scope);
-
+
+ Alignment assignmentAlignment = this.scribe.createAlignment("assignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
+ this.scribe.enterAlignment(assignmentAlignment);
+ boolean ok = false;
+ do {
+ try {
+ this.scribe.alignFragment(assignmentAlignment, 0);
+ assignment.expression.traverse(this, scope);
+ ok = true;
+ } catch(AlignmentException e){
+ this.scribe.redoAlignment(e);
+ }
+ } while (!ok);
+ this.scribe.exitAlignment(assignmentAlignment, true);
+
if (numberOfParens > 0) {
manageClosingParenthesizedExpression(assignment, numberOfParens);
}
@@ -3286,9 +3321,7 @@
if (fieldsCount != 0 || methodsCount != 0 || membersCount != 0) {
formatTypeMembers(typeDeclaration);
}
-
- this.scribe.printComment();
-
+
if (this.preferences.indent_body_declarations_compare_to_enum_constant_header) {
this.scribe.unIndent();
}
Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v
retrieving revision 1.68
diff -u -r1.68 DefaultCodeFormatterOptions.java
--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 30 Aug 2005 17:32:49 -0000 1.68
+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 30 Aug 2005 20:51:58 -0000
@@ -50,6 +50,7 @@
public int alignment_for_arguments_in_explicit_constructor_call;
public int alignment_for_arguments_in_method_invocation;
public int alignment_for_arguments_in_qualified_allocation_expression;
+ public int alignment_for_assignment;
public int alignment_for_binary_expression;
public int alignment_for_compact_if;
public int alignment_for_conditional_expression;
@@ -320,6 +321,7 @@
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));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_qualified_allocation_expression));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, getAlignment(this.alignment_for_assignment));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression));
@@ -621,6 +623,16 @@
this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
}
}
+ final Object alignmentForAssignmentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT);
+ if (alignmentForAssignmentOption != null) {
+ try {
+ this.alignment_for_assignment = Integer.parseInt((String) alignmentForAssignmentOption);
+ } catch (NumberFormatException e) {
+ this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT;
+ } catch (ClassCastException e) {
+ this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT;
+ }
+ }
final Object alignmentForBinaryExpressionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION);
if (alignmentForBinaryExpressionOption != null) {
try {
@@ -1819,6 +1831,7 @@
this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
this.alignment_for_compact_if = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_INDENT_BY_ONE;
this.alignment_for_conditional_expression = Alignment.M_ONE_PER_LINE_SPLIT;
@@ -2069,6 +2082,7 @@
this.alignment_for_arguments_in_explicit_constructor_call = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT;
this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT;
Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v
retrieving revision 1.91
diff -u -r1.91 Scribe.java
--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 30 Aug 2005 17:32:49 -0000 1.91
+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 30 Aug 2005 20:51:58 -0000
@@ -1009,12 +1009,14 @@
if (this.memberAlignment != null) {
// select the last alignment
if (this.currentAlignment.location.inputOffset > this.memberAlignment.location.inputOffset) {
- this.indentationLevel = Math.max(this.indentationLevel, this.currentAlignment.breakIndentationLevel);
+ if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) {
+ this.currentAlignment.performFragmentEffect();
+ }
} else {
this.indentationLevel = Math.max(this.indentationLevel, this.memberAlignment.breakIndentationLevel);
}
- } else {
- this.indentationLevel = Math.max(this.indentationLevel, this.currentAlignment.breakIndentationLevel);
+ } else if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) {
+ this.currentAlignment.performFragmentEffect();
}
}
this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
Index: formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java,v
retrieving revision 1.25
diff -u -r1.25 Alignment.java
--- formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java 20 Apr 2005 16:47:02 -0000 1.25
+++ formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java 30 Aug 2005 20:51:58 -0000
@@ -405,4 +405,13 @@
}
}
}
+
+ public boolean isWrapped() {
+ for (int i = 0, max = this.fragmentCount; i < max; i++) {
+ if (this.fragmentBreaks[i] == BREAK) {
+ return true;
+ }
+ }
+ return false;
+ }
}