Package org.eclipse.jdt.internal.formatter.align

Examples of org.eclipse.jdt.internal.formatter.align.Alignment


      if (arguments != null) {
        if (this.preferences.insert_space_after_opening_paren_in_method_invocation) {
          this.scribe.space();
        }
        int argumentLength = arguments.length;
        Alignment argumentsAlignment = this.scribe.createAlignment(
            Alignment.MESSAGE_ARGUMENTS,
            this.preferences.alignment_for_arguments_in_method_invocation,
            Alignment.R_OUTERMOST,
            argumentLength,
            this.scribe.scanner.currentPosition);
        this.scribe.enterAlignment(argumentsAlignment);
        boolean okForArguments = false;
        do {
          try {
            for (int j = 0; j < argumentLength; j++) {
              if (j > 0) {
                this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
                this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
              }
              this.scribe.alignFragment(argumentsAlignment, j);
              if (j > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
                this.scribe.space();
              }
              arguments[j].traverse(this, scope);
            }
            okForArguments = true;
          } catch (AlignmentException e) {
            this.scribe.redoAlignment(e);
          }
        } while (!okForArguments);
        this.scribe.exitAlignment(argumentsAlignment, true);
        this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_method_invocation);
      } else {
        this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_between_empty_parens_in_method_invocation);
      }
      if (numberOfParens > 0) {
        manageClosingParenthesizedExpression(currentMessageSend, numberOfParens);
      }
      startingPositionInCascade = 2;
    }
    int tieBreakRule = this.preferences.wrap_outer_expressions_when_nested && size-startingPositionInCascade > 2
      ? Alignment.R_OUTERMOST
      : Alignment.R_INNERMOST;
    Alignment cascadingMessageSendAlignment =
      this.scribe.createAlignment(
        Alignment.CASCADING_MESSAGE_SEND,
        this.preferences.alignment_for_selector_in_method_invocation,
        tieBreakRule,
        size,
        this.scribe.scanner.currentPosition);
    this.scribe.enterAlignment(cascadingMessageSendAlignment);
    boolean ok = false;
    boolean setStartingColumn = true;
    switch (this.preferences.alignment_for_arguments_in_method_invocation & Alignment.SPLIT_MASK) {
      case Alignment.M_COMPACT_FIRST_BREAK_SPLIT:
      case Alignment.M_NEXT_SHIFTED_SPLIT:
      case Alignment.M_ONE_PER_LINE_SPLIT:
        setStartingColumn = false;
        break;
    }
    do {
      if (setStartingColumn) {
        cascadingMessageSendAlignment.startingColumn = this.scribe.column;
      }
      try {
        this.scribe.alignFragment(cascadingMessageSendAlignment, 0);
        this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
        for (int i = startingPositionInCascade; i < size; i++) {
          MessageSend currentMessageSend = fragments[i];
          final int numberOfParens = (currentMessageSend.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
          if (numberOfParens > 0) {
            manageOpeningParenthesizedExpression(currentMessageSend, numberOfParens);
          }
          TypeReference[] typeArguments = currentMessageSend.typeArguments;
          if (typeArguments != null) {
              this.scribe.printNextToken(TerminalTokens.TokenNameLESS, this.preferences.insert_space_before_opening_angle_bracket_in_type_arguments);
              if (this.preferences.insert_space_after_opening_angle_bracket_in_type_arguments) {
                this.scribe.space();
              }
              int length = typeArguments.length;
              for (int j = 0; j < length - 1; j++) {
                typeArguments[j].traverse(this, scope);
                this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_type_arguments);
                if (this.preferences.insert_space_after_comma_in_type_arguments) {
                  this.scribe.space();
                }
              }
              typeArguments[length - 1].traverse(this, scope);
              if (isClosingGenericToken()) {
                this.scribe.printNextToken(CLOSING_GENERICS_EXPECTEDTOKENS, this.preferences.insert_space_before_closing_angle_bracket_in_type_arguments);
              }
              if (this.preferences.insert_space_after_closing_angle_bracket_in_type_arguments) {
                this.scribe.space();
              }
          }
          ASTNode[] arguments = currentMessageSend.arguments;
          this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); // selector
          this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_opening_paren_in_method_invocation);
          if (arguments != null) {
            if (this.preferences.insert_space_after_opening_paren_in_method_invocation) {
              this.scribe.space();
            }
            int argumentLength = arguments.length;
            int alignmentMode = this.preferences.alignment_for_arguments_in_method_invocation;
            Alignment argumentsAlignment = this.scribe.createAlignment(
                Alignment.MESSAGE_ARGUMENTS,
                alignmentMode,
                Alignment.R_OUTERMOST,
                argumentLength,
                this.scribe.scanner.currentPosition);
View Full Code Here


   */
  private void formatClassBodyDeclarations(ASTNode[] nodes) {
    final int FIELD = 1, METHOD = 2, TYPE = 3;
    this.scribe.lastNumberOfNewLines = 1;
    ASTNode[] mergedNodes = computeMergedMemberDeclarations(nodes);
    Alignment memberAlignment = this.scribe.createMemberAlignment(
        Alignment.TYPE_MEMBERS,
        this.preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT,
        4,
        this.scribe.scanner.currentPosition);
    this.scribe.enterMemberAlignment(memberAlignment);
    boolean isChunkStart = false;
    boolean ok = false;
    int startIndex = 0;
    do {
      try {
        for (int i = startIndex, max = mergedNodes.length; i < max; i++) {
          ASTNode member = mergedNodes[i];
          if (member instanceof FieldDeclaration) {
            isChunkStart = memberAlignment.checkChunkStart(FIELD, i, this.scribe.scanner.currentPosition);
            if (member instanceof MultiFieldDeclaration){
              MultiFieldDeclaration multiField = (MultiFieldDeclaration) member;
              format(multiField, this, null, isChunkStart, i == 0);
            } else if (member instanceof Initializer) {
              int newLineBeforeChunk = isChunkStart ? this.preferences.blank_lines_before_new_chunk : 0;
              if (newLineBeforeChunk > 0 && i != 0) {
                this.scribe.printEmptyLines(newLineBeforeChunk);
              } else if (i == 0) {
                int newLinesBeforeFirstClassBodyDeclaration = this.preferences.blank_lines_before_first_class_body_declaration;
                if (newLinesBeforeFirstClassBodyDeclaration > 0) {
                  this.scribe.printEmptyLines(newLinesBeforeFirstClassBodyDeclaration);
                }
              }
              Initializer initializer = (Initializer) member;
              initializer.traverse(this, null);
            } else {
              FieldDeclaration field = (FieldDeclaration) member;
              format(field, this, null, isChunkStart, i == 0);
            }
          } else if (member instanceof AbstractMethodDeclaration) {
            isChunkStart = memberAlignment.checkChunkStart(METHOD, i, this.scribe.scanner.currentPosition);
            format((AbstractMethodDeclaration) member, null, isChunkStart, i == 0);
          } else {
            isChunkStart = memberAlignment.checkChunkStart(TYPE, i, this.scribe.scanner.currentPosition);
            format((TypeDeclaration)member, null, isChunkStart, i == 0);
          }
          while (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
            this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
            this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
View Full Code Here

       */
      this.scribe.printNextToken(TerminalTokens.TokenNameEQUAL, this.preferences.insert_space_before_assignment_operator);
      if (this.preferences.insert_space_after_assignment_operator) {
        this.scribe.space();
      }
      Alignment assignmentAlignment = this.scribe.createAlignment(
          Alignment.LOCAL_DECLARATION_ASSIGNMENT,
          this.preferences.alignment_for_assignment,
          Alignment.R_OUTERMOST,
          1,
          this.scribe.scanner.currentPosition);
View Full Code Here

        this.scribe.space();
      }
      int argumentsLength = arguments.length;
      if (argumentsLength > 1) {
        int alignmentMode = this.preferences.alignment_for_arguments_in_method_invocation;
        Alignment argumentsAlignment = this.scribe.createAlignment(
            Alignment.MESSAGE_ARGUMENTS,
            alignmentMode,
            argumentsLength,
            this.scribe.scanner.currentPosition);
        this.scribe.enterAlignment(argumentsAlignment);
        boolean ok = false;
        do {
          switch (alignmentMode & Alignment.SPLIT_MASK) {
            case Alignment.M_COMPACT_SPLIT:
            case Alignment.M_NEXT_PER_LINE_SPLIT:
              argumentsAlignment.startingColumn = this.scribe.column;
              break;
          }
          try {
            for (int i = 0; i < argumentsLength; i++) {
              if (i > 0) {
                this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
                this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
                if (this.scribe.lastNumberOfNewLines == 1) {
                  // a new line has been inserted while printing the comment
                  // hence we need to use the break indentation level before printing next token...
                  this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel;
                }
              }
              this.scribe.alignFragment(argumentsAlignment, i);
              if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
                this.scribe.space();
              }
              int fragmentIndentation = 0;
              if (i == 0) {
                int wrappedIndex = argumentsAlignment.wrappedIndex();
                if (wrappedIndex >= 0) {
                  fragmentIndentation = argumentsAlignment.fragmentIndentations[wrappedIndex];
                  if ((argumentsAlignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0 && fragmentIndentation > 0) {
                    this.scribe.indentationLevel = fragmentIndentation;
                  }
View Full Code Here

    if (length > 0) {
      this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, spaceBeforeOpenParen);
      if (spaceBeforeFirstResource) {
        this.scribe.space();
      }
      Alignment resourcesAlignment = this.scribe.createAlignment(
          Alignment.TRY_RESOURCES,
          tryResourcesAligment,
          // make sure alignment options for try with resources takes precedence
          Alignment.R_OUTERMOST,
          length,
View Full Code Here

        this.scribe.space();
      }
      int receiverCount = receiver != null ? 1 : 0;
      int realArgumentLength =  arguments != null ? arguments.length : 0;
      int argumentLength = realArgumentLength + receiverCount;
      Alignment argumentsAlignment = this.scribe.createAlignment(
          Alignment.METHOD_ARGUMENTS,
          methodDeclarationParametersAlignment,
          argumentLength,
          this.scribe.scanner.currentPosition);
      this.scribe.enterAlignment(argumentsAlignment);
View Full Code Here

    this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, spaceBeforeOpenParen);
    final Expression[] arguments = ((AllocationExpression) enumConstant.initialization).arguments;
    if (arguments != null) {
      int argumentLength = arguments.length;
      Alignment argumentsAlignment = this.scribe.createAlignment(
          Alignment.ENUM_CONSTANTS_ARGUMENTS,
          methodDeclarationParametersAlignment,
          argumentLength,
          this.scribe.scanner.currentPosition);
      this.scribe.enterAlignment(argumentsAlignment);
View Full Code Here

    int alignmentForThrowsClause) {

    final TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
    if (thrownExceptions != null) {
      int thrownExceptionsLength = thrownExceptions.length;
      Alignment throwsAlignment = this.scribe.createAlignment(
          Alignment.THROWS,
          alignmentForThrowsClause,
          thrownExceptionsLength, // throws is the first token
          this.scribe.scanner.currentPosition);
View Full Code Here

  /*
   * Merged traversal of member (types, fields, methods)
   */
  private void formatTypeMembers(TypeDeclaration typeDeclaration) {
    Alignment memberAlignment = this.scribe.createMemberAlignment(
        Alignment.TYPE_MEMBERS,
        this.preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT,
        3,
        this.scribe.scanner.currentPosition);
    this.scribe.enterMemberAlignment(memberAlignment);
    ASTNode[] members = computeMergedMemberDeclarations(typeDeclaration);
    boolean isChunkStart = false;
    boolean ok = false;
    int membersLength = members.length;
    if (membersLength > 0) {
      int startIndex = 0;
      do {
        try {
          for (int i = startIndex, max = members.length; i < max; i++) {
            while (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
              this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
              this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
            }
            this.scribe.printNewLine();
            ASTNode member = members[i];
            if (member instanceof FieldDeclaration) {
              isChunkStart = memberAlignment.checkChunkStart(Alignment.CHUNK_FIELD, i, this.scribe.scanner.currentPosition);
              if (member instanceof MultiFieldDeclaration) {
                MultiFieldDeclaration multiField = (MultiFieldDeclaration) member;
 
                if (multiField.isStatic()) {
                  format(multiField, this, typeDeclaration.staticInitializerScope, isChunkStart, i == 0);
                } else {
                  format(multiField, this, typeDeclaration.initializerScope, isChunkStart, i == 0);
                }
              } else if (member instanceof Initializer) {
                int newLineBeforeChunk = isChunkStart ? this.preferences.blank_lines_before_new_chunk : 0;
                if (newLineBeforeChunk > 0 && i != 0) {
                  this.scribe.printEmptyLines(newLineBeforeChunk);
                } else if (i == 0) {
                  int newLinesBeforeFirstClassBodyDeclaration = this.preferences.blank_lines_before_first_class_body_declaration;
                  if (newLinesBeforeFirstClassBodyDeclaration > 0) {
                    this.scribe.printEmptyLines(newLinesBeforeFirstClassBodyDeclaration);
                  }
                }
                Initializer initializer = (Initializer) member;
                if (initializer.isStatic()) {
                  initializer.traverse(this, typeDeclaration.staticInitializerScope);
                } else {
                  initializer.traverse(this, typeDeclaration.initializerScope);
                }
              } else {
                FieldDeclaration field = (FieldDeclaration) member;
                if (field.isStatic()) {
                  format(field, this, typeDeclaration.staticInitializerScope, isChunkStart, i == 0);
                } else {
                  format(field, this, typeDeclaration.initializerScope, isChunkStart, i == 0);
                }
              }
            } else if (member instanceof AbstractMethodDeclaration) {
              isChunkStart = memberAlignment.checkChunkStart(Alignment.CHUNK_METHOD, i, this.scribe.scanner.currentPosition);
              format((AbstractMethodDeclaration) member, typeDeclaration.scope, isChunkStart, i == 0);
            } else if (member instanceof TypeDeclaration) {
              isChunkStart = memberAlignment.checkChunkStart(Alignment.CHUNK_TYPE, i, this.scribe.scanner.currentPosition);
              format((TypeDeclaration)member, typeDeclaration.scope, isChunkStart, i == 0);
            }
            while (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
              this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
              this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
View Full Code Here

    if (arguments != null) {
      if (this.preferences.insert_space_after_opening_paren_in_method_invocation) {
        this.scribe.space();
      }
      int argumentLength = arguments.length;
      Alignment argumentsAlignment =this.scribe.createAlignment(
          Alignment.ALLOCATION,
          this.preferences.alignment_for_arguments_in_allocation_expression,
          argumentLength,
          this.scribe.scanner.currentPosition);
      this.scribe.enterAlignment(argumentsAlignment);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.formatter.align.Alignment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.