| Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/formatter/CodeFormatterVisitor.java
|
| ===================================================================
|
| --- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/formatter/CodeFormatterVisitor.java (revision 12271)
|
| +++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/formatter/CodeFormatterVisitor.java (working copy)
|
| @@ -13,6 +13,7 @@
|
| */
|
| package com.google.dart.tools.core.internal.formatter;
|
|
|
| +import com.google.dart.compiler.ast.ASTNodes;
|
| import com.google.dart.compiler.ast.ASTVisitor;
|
| import com.google.dart.compiler.ast.DartArrayAccess;
|
| import com.google.dart.compiler.ast.DartArrayLiteral;
|
| @@ -97,7 +98,6 @@
|
| import com.google.dart.tools.core.formatter.DefaultCodeFormatterConstants;
|
| import com.google.dart.tools.core.internal.formatter.align.Alignment;
|
| import com.google.dart.tools.core.internal.formatter.align.AlignmentException;
|
| -import com.google.dart.tools.core.utilities.ast.DartAstUtilities;
|
|
|
| import org.eclipse.jface.text.IRegion;
|
| import org.eclipse.text.edits.TextEdit;
|
| @@ -418,8 +418,7 @@
|
| false,
|
| Scribe.PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER
|
| + (arrayInitializerIndentationLevel << 16));
|
| - if (array_initializer_brace_position.equals(
|
| - DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
|
| + if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
|
| scribe.unIndent();
|
| }
|
| } else {
|
| @@ -451,8 +450,7 @@
|
| scribe.printNextToken(
|
| Token.RBRACK,
|
| preferences.insert_space_between_empty_braces_in_array_initializer);
|
| - if (array_initializer_brace_position.equals(
|
| - DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
|
| + if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
|
| scribe.unIndent();
|
| }
|
| }
|
| @@ -507,13 +505,9 @@
|
| }
|
| if (preferences.wrap_before_binary_operator) {
|
| scribe.alignFragment(binaryExpressionAlignment, i);
|
| - scribe.printNextToken(
|
| - operators[i],
|
| - preferences.insert_space_before_binary_operator);
|
| + scribe.printNextToken(operators[i], preferences.insert_space_before_binary_operator);
|
| } else {
|
| - scribe.printNextToken(
|
| - operators[i],
|
| - preferences.insert_space_before_binary_operator);
|
| + scribe.printNextToken(operators[i], preferences.insert_space_before_binary_operator);
|
| scribe.alignFragment(binaryExpressionAlignment, i);
|
| }
|
| if (operators[i] == Token.SUB && isNextToken(Token.SUB)) {
|
| @@ -1404,7 +1398,7 @@
|
|
|
| @Override
|
| public DartNode visitMethodDefinition(DartMethodDefinition node) {
|
| - if (DartAstUtilities.isConstructor(node)) {
|
| + if (ASTNodes.isConstructor(node)) {
|
| // TODO update for new constructor syntax
|
| visitConstructorDefinition(node);
|
| return null;
|
| @@ -2024,10 +2018,10 @@
|
| // Set header end position
|
| final List<DartDirective> directives = compilationUnitDeclaration.getDirectives();
|
| final List<DartNode> types = compilationUnitDeclaration.getTopLevelNodes();
|
| - int headerEndPosition = types == null || types.isEmpty() ?
|
| - compilationUnitDeclaration.getSourceInfo().getOffset()
|
| - + compilationUnitDeclaration.getSourceInfo().getLength() : types.get(0)
|
| - .getSourceInfo().getOffset();
|
| + int headerEndPosition = types == null || types.isEmpty()
|
| + ? compilationUnitDeclaration.getSourceInfo().getOffset()
|
| + + compilationUnitDeclaration.getSourceInfo().getLength()
|
| + : types.get(0).getSourceInfo().getOffset();
|
| scribe.setHeaderComment(headerEndPosition);
|
| scribe.printComment();
|
|
|
| @@ -2306,9 +2300,7 @@
|
| int length = typeParameters.size();
|
| for (int i = 0; i < length - 1; i++) {
|
| typeParameters.get(i).accept(this);
|
| - scribe.printNextToken(
|
| - Token.COMMA,
|
| - preferences.insert_space_before_comma_in_type_parameters);
|
| + scribe.printNextToken(Token.COMMA, preferences.insert_space_before_comma_in_type_parameters);
|
| if (preferences.insert_space_after_comma_in_type_parameters) {
|
| scribe.space();
|
| }
|
| @@ -2532,9 +2524,7 @@
|
| if (i == 0) {
|
| scribe.alignFragment(fieldAlignment, 1);
|
| }
|
| - scribe.printNextToken(
|
| - Token.ASSIGN,
|
| - preferences.insert_space_before_assignment_operator);
|
| + scribe.printNextToken(Token.ASSIGN, preferences.insert_space_before_assignment_operator);
|
| if (preferences.insert_space_after_assignment_operator) {
|
| scribe.space();
|
| }
|
| @@ -2588,8 +2578,8 @@
|
| methodDeclaration.accept(this);
|
| }
|
|
|
| - private void formatBlock(
|
| - DartBlock block, String block_brace_position, boolean insertSpaceBeforeOpeningBrace) {
|
| + private void formatBlock(DartBlock block, String block_brace_position,
|
| + boolean insertSpaceBeforeOpeningBrace) {
|
| formatOpeningBrace(block_brace_position, insertSpaceBeforeOpeningBrace);
|
| final List<DartStatement> statements = block.getStatements();
|
| if (!statements.isEmpty()) {
|
| @@ -2836,8 +2826,8 @@
|
| DartNode[] mergedNodes = nodes;// computeMergedMemberDeclarations(nodes);
|
| Alignment memberAlignment = scribe.createMemberAlignment(
|
| Alignment.TYPE_MEMBERS,
|
| - preferences.align_type_members_on_columns
|
| - ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT,
|
| + preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN
|
| + : Alignment.M_NO_ALIGNMENT,
|
| 4,
|
| scribe.scanner.currentPosition);
|
| scribe.enterMemberAlignment(memberAlignment);
|
| @@ -2849,10 +2839,7 @@
|
| for (int i = startIndex, max = mergedNodes.length; i < max; i++) {
|
| DartNode member = mergedNodes[i];
|
| if (member instanceof DartFieldDefinition) {
|
| - isChunkStart = memberAlignment.checkChunkStart(
|
| - FIELD,
|
| - i,
|
| - scribe.scanner.currentPosition);
|
| + isChunkStart = memberAlignment.checkChunkStart(FIELD, i, scribe.scanner.currentPosition);
|
| format((DartFieldDefinition) member, this, isChunkStart, i == 0);
|
| } else if (member instanceof DartMethodDefinition) {
|
| isChunkStart = memberAlignment.checkChunkStart(
|
| @@ -3207,8 +3194,7 @@
|
| formatOpeningGroup(Token.LBRACK, bracePosition, insertSpaceBeforeBracket);
|
| }
|
|
|
| - private void formatOpeningGroup(
|
| - Token token, String bracePosition, boolean insertSpaceBeforeBrace) {
|
| + private void formatOpeningGroup(Token token, String bracePosition, boolean insertSpaceBeforeBrace) {
|
| if (DefaultCodeFormatterConstants.NEXT_LINE.equals(bracePosition)) {
|
| scribe.printNewLine();
|
| } else if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(bracePosition)) {
|
| @@ -3222,8 +3208,8 @@
|
| scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.UNMODIFIABLE_TRAILING_COMMENT);
|
| }
|
|
|
| - private void formatStatements(
|
| - final List<DartStatement> statements, boolean insertNewLineAfterLastStatement) {
|
| + private void formatStatements(final List<DartStatement> statements,
|
| + boolean insertNewLineAfterLastStatement) {
|
| int statementsLength = statements.size();
|
| for (int i = 0; i < statementsLength; i++) {
|
| final DartStatement statement = statements.get(i);
|
| @@ -3290,8 +3276,8 @@
|
| private void formatTypeMembers(DartClass typeDeclaration) {
|
| Alignment memberAlignment = scribe.createMemberAlignment(
|
| Alignment.TYPE_MEMBERS,
|
| - preferences.align_type_members_on_columns
|
| - ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT,
|
| + preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN
|
| + : Alignment.M_NO_ALIGNMENT,
|
| 3,
|
| scribe.scanner.currentPosition);
|
| scribe.enterMemberAlignment(memberAlignment);
|
| @@ -3350,10 +3336,10 @@
|
| scribe.exitMemberAlignment(memberAlignment);
|
| }
|
|
|
| - private void formatTypeOpeningBrace(
|
| - String bracePosition, boolean insertSpaceBeforeBrace, DartClass typeDeclaration) {
|
| - final int memberLength = typeDeclaration.getMembers() == null
|
| - ? 0 : typeDeclaration.getMembers().size();
|
| + private void formatTypeOpeningBrace(String bracePosition, boolean insertSpaceBeforeBrace,
|
| + DartClass typeDeclaration) {
|
| + final int memberLength = typeDeclaration.getMembers() == null ? 0
|
| + : typeDeclaration.getMembers().size();
|
|
|
| boolean insertNewLine = memberLength > 0;
|
|
|
| @@ -3448,15 +3434,12 @@
|
| }
|
|
|
| private boolean isGuardClause(DartBlock block) {
|
| - return !commentStartsBlock(
|
| - block.getSourceInfo().getOffset(),
|
| - block.getSourceInfo().getLength() + block.getSourceInfo().getOffset()) &&
|
| - block.getStatements() != null && block.getStatements().size() == 1
|
| - && (
|
| - block.getStatements().get(0) instanceof DartReturnStatement || (
|
| - block.getStatements().get(0) instanceof DartExprStmt
|
| - && (((DartExprStmt) block.getStatements().get(0))
|
| - .getExpression() instanceof DartThrowExpression)));
|
| + return !commentStartsBlock(block.getSourceInfo().getOffset(), block.getSourceInfo().getLength()
|
| + + block.getSourceInfo().getOffset())
|
| + && block.getStatements() != null
|
| + && block.getStatements().size() == 1
|
| + && (block.getStatements().get(0) instanceof DartReturnStatement || (block.getStatements().get(
|
| + 0) instanceof DartExprStmt && (((DartExprStmt) block.getStatements().get(0)).getExpression() instanceof DartThrowExpression)));
|
| }
|
|
|
| private boolean isMultipleLocalDeclaration(DartVariableStatement localDeclaration) {
|
|
|