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

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


    }
    return alignment;
  }

  public Alignment createMemberAlignment(int kind, int mode, int count, int sourceRestart) {
    Alignment mAlignment = createAlignment(kind, mode, Alignment.R_INNERMOST, count, sourceRestart);
    mAlignment.breakIndentationLevel = this.indentationLevel;
    return mAlignment;
  }
View Full Code Here


    alignment.location.lastLocalDeclarationSourceStart = this.formatter.lastLocalDeclarationSourceStart;
    this.memberAlignment = alignment;
  }

  public void exitAlignment(Alignment alignment, boolean discardAlignment){
    Alignment current = this.currentAlignment;
    while (current != null){
      if (current == alignment) break;
      current = current.enclosing;
    }
    if (current == null) {
View Full Code Here

      }
    }
  }

  public void exitMemberAlignment(Alignment alignment){
    Alignment current = this.memberAlignment;
    while (current != null){
      if (current == alignment) break;
      current = current.enclosing;
    }
    if (current == null) {
View Full Code Here

            useAlignmentBreakIndentation = true;
            break;
        }

        // If there's an alignment try to align on its break indentation level
        Alignment alignment = this.currentAlignment;
        if (alignment == null) {
          if (useLastBinaryExpressionAlignmentBreakIndentation) {
            if (this.indentationLevel < this.formatter.lastBinaryExpressionAlignmentBreakIndentation) {
              this.indentationLevel = this.formatter.lastBinaryExpressionAlignmentBreakIndentation;
            }
View Full Code Here

      return;
    }
    // search for closest breakable alignment, using tiebreak rules
    // look for outermost breakable one
    int relativeDepth = 0, outerMostDepth = -1;
    Alignment targetAlignment = this.currentAlignment;
    while (targetAlignment != null){
      if (targetAlignment.tieBreakRule == Alignment.R_OUTERMOST && targetAlignment.couldBreak()){
        outerMostDepth = relativeDepth;
      }
      targetAlignment = targetAlignment.enclosing;
      relativeDepth++;
    }
    if (outerMostDepth >= 0) {
      throw new AlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth);
    }
    // look for innermost breakable one
    relativeDepth = 0;
    targetAlignment = this.currentAlignment;
    while (targetAlignment != null){
      if (targetAlignment.couldBreak()){
        throw new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
      }
      targetAlignment = targetAlignment.enclosing;
      relativeDepth++;
    }
View Full Code Here

  private void handleLineTooLongSmartly() {
    // search for closest breakable alignment, using tiebreak rules
    // look for outermost breakable one
    int relativeDepth = 0, outerMostDepth = -1;
    Alignment targetAlignment = this.currentAlignment;
    int previousKind = -1;
    int insideMessage = 0;
    boolean insideStringConcat = false;
    while (targetAlignment != null){
      boolean couldBreak = targetAlignment.tieBreakRule == Alignment.R_OUTERMOST ||
        (!insideStringConcat &&
            insideMessage > 0 && targetAlignment.kind == Alignment.MESSAGE_ARGUMENTS &&
            (!targetAlignment.wasReset() || previousKind != Alignment.MESSAGE_SEND));
      if (couldBreak && targetAlignment.couldBreak()){
        outerMostDepth = relativeDepth;
      }
      switch (targetAlignment.kind) {
        case Alignment.MESSAGE_ARGUMENTS:
        case Alignment.MESSAGE_SEND:
          insideMessage++;
          break;
        case Alignment.STRING_CONCATENATION:
          insideStringConcat = true;
          break;
      }
      previousKind = targetAlignment.kind;
      targetAlignment = targetAlignment.enclosing;
      relativeDepth++;
    }
    if (outerMostDepth >= 0) {
      throw new AlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth);
    }
    // look for innermost breakable one
    relativeDepth = 0;
    targetAlignment = this.currentAlignment;
    AlignmentException alignmentException = null;
    int msgArgsDepth = -1;
    while (targetAlignment != null) {
      if (targetAlignment.kind == Alignment.MESSAGE_ARGUMENTS) {
        msgArgsDepth = relativeDepth;
      }
      if (alignmentException == null) {
        if (targetAlignment.couldBreak()) {
          // do not throw the exception immediately to have a chance to reset
          // previously broken alignments (see bug 203588)
          alignmentException = new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
          if (insideStringConcat) throw alignmentException;
        }
      } else if (targetAlignment.wasSplit) {
        // reset the nearest already broken outermost alignment.
        // Note that it's not done twice to avoid infinite loop while raising
        // the exception on an innermost alignment...
        if (!targetAlignment.wasReset()) {
          targetAlignment.reset();
          if (msgArgsDepth > alignmentException.relativeDepth) {
            alignmentException.relativeDepth = msgArgsDepth;
          }
          throw alignmentException;
        }
View Full Code Here

    try {
      this.lastBinaryExpressionAlignmentBreakIndentation = 0;
      if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) {
        int scribeLine = this.scribe.line;
        this.scribe.printComment();
        Alignment binaryExpressionAlignment = this.scribe.createAlignment(
            Alignment.BINARY_EXPRESSION,
            this.preferences.alignment_for_binary_expression,
            Alignment.R_OUTERMOST,
            fragmentsSize,
            this.scribe.scanner.currentPosition);
View Full Code Here

      final int newLinesBeforeField = this.preferences.blank_lines_before_field;
      if (newLinesBeforeField > 0) {
        this.scribe.printEmptyLines(newLinesBeforeField);
      }
    }
    Alignment memberAlignment = this.scribe.getMemberAlignment();

        this.scribe.printComment();
    this.scribe.printModifiers(fieldDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_FIELD);
    this.scribe.space();
    /*
     * Field type
     */
    fieldDeclaration.type.traverse(this, scope);

    /*
     * Field name
     */
    this.scribe.alignFragment(memberAlignment, 0);

    this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true);

    /*
     * Check for extra dimensions
     */
    int extraDimensions = getDimensions();
    if (extraDimensions != 0) {
       for (int i = 0; i < extraDimensions; i++) {
         this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET);
         this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET);
       }
    }

    /*
     * Field initialization
     */
    final Expression initialization = fieldDeclaration.initialization;
    if (initialization != null) {
      this.scribe.alignFragment(memberAlignment, 1);
      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.FIELD_DECLARATION_ASSIGNMENT,
          this.preferences.alignment_for_assignment,
          Alignment.R_INNERMOST,
          1,
          this.scribe.scanner.currentPosition);
View Full Code Here

      final int newLinesBeforeField = this.preferences.blank_lines_before_field;
      if (newLinesBeforeField > 0) {
        this.scribe.printEmptyLines(newLinesBeforeField);
      }
    }
    Alignment fieldAlignment = this.scribe.getMemberAlignment();

        this.scribe.printComment();
    this.scribe.printModifiers(multiFieldDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_FIELD);
    this.scribe.space();

    multiFieldDeclaration.declarations[0].type.traverse(this, scope);

    final int multipleFieldDeclarationsLength = multiFieldDeclaration.declarations.length;

    Alignment multiFieldDeclarationsAlignment =this.scribe.createAlignment(
        Alignment.MULTIPLE_FIELD,
        this.preferences.alignment_for_multiple_fields,
        multipleFieldDeclarationsLength - 1,
        this.scribe.scanner.currentPosition);
    this.scribe.enterAlignment(multiFieldDeclarationsAlignment);
View Full Code Here

    /*
     * Superclass
     */
    final TypeReference superclass = typeDeclaration.superclass;
    if (superclass != null) {
      Alignment superclassAlignment =this.scribe.createAlignment(
          Alignment.SUPER_CLASS,
          this.preferences.alignment_for_superclass_in_type_declaration,
          2,
          this.scribe.scanner.currentPosition);
      this.scribe.enterAlignment(superclassAlignment);
      boolean ok = false;
      do {
        try {
          this.scribe.alignFragment(superclassAlignment, 0);
          this.scribe.printNextToken(TerminalTokens.TokenNameextends, true);
          this.scribe.alignFragment(superclassAlignment, 1);
          this.scribe.space();
          superclass.traverse(this, typeDeclaration.scope);
          ok = true;
        } catch (AlignmentException e) {
          this.scribe.redoAlignment(e);
        }
      } while (!ok);
      this.scribe.exitAlignment(superclassAlignment, true);
    }

    /*
     * Super Interfaces
     */
    final TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
    if (superInterfaces != null) {
      int alignment_for_superinterfaces;
      int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
      switch(kind) {
        case TypeDeclaration.ENUM_DECL :
          alignment_for_superinterfaces = this.preferences.alignment_for_superinterfaces_in_enum_declaration;
          break;
        default:
          alignment_for_superinterfaces = this.preferences.alignment_for_superinterfaces_in_type_declaration;
          break;
      }
      int superInterfaceLength = superInterfaces.length;
      Alignment interfaceAlignment =this.scribe.createAlignment(
          Alignment.SUPER_INTERFACES,
          alignment_for_superinterfaces,
          superInterfaceLength+1// implements token is first fragment
          this.scribe.scanner.currentPosition);
      this.scribe.enterAlignment(interfaceAlignment);
      boolean ok = false;
      do {
        try {
          this.scribe.alignFragment(interfaceAlignment, 0);
          if (kind == TypeDeclaration.INTERFACE_DECL) {
            this.scribe.printNextToken(TerminalTokens.TokenNameextends, true);
          } else  {
            this.scribe.printNextToken(TerminalTokens.TokenNameimplements, true);
          }
          for (int i = 0; i < superInterfaceLength; i++) {
            if (i > 0) {
              this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_superinterfaces);
              this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
              this.scribe.alignFragment(interfaceAlignment, i+1);
              if (this.preferences.insert_space_after_comma_in_superinterfaces) {
                this.scribe.space();
              }
              superInterfaces[i].traverse(this, typeDeclaration.scope);
            } else {
              this.scribe.alignFragment(interfaceAlignment, i+1);
              this.scribe.space();
              superInterfaces[i].traverse(this, typeDeclaration.scope);
            }
          }
          ok = true;
        } catch (AlignmentException e) {
          this.scribe.redoAlignment(e);
        }
      } while (!ok);
      this.scribe.exitAlignment(interfaceAlignment, true);
    }

    /*
     * Type body
     */
    String class_declaration_brace;
    boolean space_before_opening_brace;
    int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
    switch(kind) {
      case TypeDeclaration.ENUM_DECL :
        class_declaration_brace = this.preferences.brace_position_for_enum_declaration;
        space_before_opening_brace = this.preferences.insert_space_before_opening_brace_in_enum_declaration;
        break;
      case TypeDeclaration.ANNOTATION_TYPE_DECL :
        class_declaration_brace = this.preferences.brace_position_for_annotation_type_declaration;
        space_before_opening_brace =  this.preferences.insert_space_before_opening_brace_in_annotation_type_declaration;
        break;
      default:
        class_declaration_brace = this.preferences.brace_position_for_type_declaration;
        space_before_opening_brace = this.preferences.insert_space_before_opening_brace_in_type_declaration;
        break;
    }
    formatLeftCurlyBrace(line, class_declaration_brace);
    formatTypeOpeningBrace(class_declaration_brace, space_before_opening_brace, typeDeclaration);

    boolean indent_body_declarations_compare_to_header;
    switch(kind) {
      case TypeDeclaration.ENUM_DECL :
        indent_body_declarations_compare_to_header = this.preferences.indent_body_declarations_compare_to_enum_declaration_header;
        break;
      case TypeDeclaration.ANNOTATION_TYPE_DECL :
        indent_body_declarations_compare_to_header = this.preferences.indent_body_declarations_compare_to_annotation_declaration_header;
        break;
      default:
        indent_body_declarations_compare_to_header = this.preferences.indent_body_declarations_compare_to_type_header;
        break;
    }
    if (indent_body_declarations_compare_to_header) {
      this.scribe.indent();
    }

    if (kind == TypeDeclaration.ENUM_DECL) {
      FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
      boolean hasConstants = false;
      int length = fieldDeclarations != null ? fieldDeclarations.length : 0;
      int enumConstantsLength = 0;
      if (fieldDeclarations != null) {
        for (int i = 0; i < length; i++) {
          FieldDeclaration fieldDeclaration = fieldDeclarations[i];
          if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
            enumConstantsLength++;
          } else {
            break;
          }
        }
        hasConstants = enumConstantsLength != 0;
        if (enumConstantsLength > 1) {
          Alignment enumConstantsAlignment = this.scribe.createAlignment(
              Alignment.ENUM_CONSTANTS,
              this.preferences.alignment_for_enum_constants,
              enumConstantsLength,
              this.scribe.scanner.currentPosition,
              0, // we don't want to indent enum constants when splitting to a new line
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.