Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.Expression


      for (Annotation a : annotations) {
        if (SuppressWarnings.class.getName().equals(
            CharOperation.toString(((ReferenceBinding) a.resolvedType).compoundName))) {
          for (MemberValuePair pair : a.memberValuePairs()) {
            if (String.valueOf(pair.name).equals("value")) {
              Expression valueExpr = pair.value;
              if (valueExpr instanceof StringLiteral) {
                // @SuppressWarnings("Foo")
                return Sets.create(((StringLiteral) valueExpr).constant.stringValue().toLowerCase(
                    Locale.ENGLISH));
              } else if (valueExpr instanceof ArrayInitializer) {
View Full Code Here


            CharOperation.toString(((ReferenceBinding) a.resolvedType).compoundName))) {
          continue;
        }

        // Sometimes it's a SingleMemberAnnotation, other times it's not
        Expression value = null;
        if (a instanceof SingleMemberAnnotation) {
          value = ((SingleMemberAnnotation) a).memberValue;
        } else {
          for (MemberValuePair pair : a.memberValuePairs()) {
            if ("value".equals(String.valueOf(pair.name))) {
              value = pair.value;
              break;
            }
          }
        }

        assert value != null;
        if (value instanceof ArrayInitializer) {
          for (Expression e : ((ArrayInitializer) value).expressions) {
            processArtificialRescue((Annotation) e);
          }
        } else if (value instanceof Annotation) {
          processArtificialRescue((Annotation) value);
        } else {
          throw new InternalCompilerException(
              "Unable to process annotation with value of type "
                  + value.getClass().getName());
        }

        return;
      }
    }
View Full Code Here

    return this.newCodeFormatter.format(source, compilationUnitDeclaration);
  }

  private TextEdit formatExpression(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
    Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);

    if (expression == null) {
      // a problem occurred while parsing the source
      return null;
    }
View Full Code Here

      // ignore
    }
    PROBING_SCANNER.setSource((char[]) null);

    // probe for expression
    Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);
    if (expression != null) {
      return internalFormatExpression(source, indentationLevel, lineSeparator, expression, regions, includeComments);
    }

    // probe for body declarations (fields, methods, constructors)
View Full Code Here

   * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ThrowStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
   */
  public boolean visit(ThrowStatement throwStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNamethrow);
    Expression expression = throwStatement.exception;
    final int numberOfParens = (expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
    if ((numberOfParens > 0 && this.preferences.insert_space_before_parenthesized_expression_in_throw)
        || numberOfParens == 0) {
      this.scribe.space();
    }
    expression.traverse(this, scope);
    /*
     * Print the semi-colon
     */
    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(operator, this.preferences.insert_space_before_unary_operator);
    if (this.preferences.insert_space_after_unary_operator) {
      this.scribe.space();
    }
    Expression expression = unaryExpression.expression;

    if (expression instanceof PrefixExpression) {
      PrefixExpression prefixExpression = (PrefixExpression) expression;
      final int numberOfParensForExpression = (prefixExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
      if (numberOfParensForExpression == 0) {
        switch(operatorValue) {
          case OperatorIds.PLUS:
            if (prefixExpression.operator == OperatorIds.PLUS) {
              this.scribe.space();
            }
            break;
          case OperatorIds.MINUS:
            if (prefixExpression.operator == OperatorIds.MINUS) {
              this.scribe.space();
            }
            break;
        }
      }
    } else if (expression instanceof UnaryExpression) {
      UnaryExpression unaryExpression2 = (UnaryExpression) expression;
      final int numberOfParensForExpression = (unaryExpression2.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
      if (numberOfParensForExpression == 0) {
        int operatorValue2 = (unaryExpression2.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT;
        switch(operatorValue) {
          case OperatorIds.PLUS:
            if (operatorValue2 == OperatorIds.PLUS) {
              this.scribe.space();
            }
            break;
          case OperatorIds.MINUS:
            if (operatorValue2 == OperatorIds.MINUS) {
              this.scribe.space();
            }
            break;
        }
      }
    }
    expression.traverse(this, scope);

    if (numberOfParens > 0) {
      manageClosingParenthesizedExpression(unaryExpression, numberOfParens);
    }
    return false;
View Full Code Here

    }

    /*
     * 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);
      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);
View Full Code Here

          }

          /*
           * Field initialization
           */
          final Expression initialization = fieldDeclaration.initialization;
          if (initialization != null) {
            if (i == 0) {
              this.scribe.alignFragment(fieldAlignment, 1);
            }
            this.scribe.printNextToken(TerminalTokens.TokenNameEQUAL, this.preferences.insert_space_before_assignment_operator);
            if (this.preferences.insert_space_after_assignment_operator) {
              this.scribe.space();
            }
            initialization.traverse(this, scope);
          }

          if (i != length - 1) {
            this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_multiple_field_declarations);
            this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
View Full Code Here

  }

  private void formatCascadingMessageSends(CascadingMethodInvocationFragmentBuilder builder, BlockScope scope) {
    int size = builder.size();
    MessageSend[] fragments = builder.fragments();
    Expression fragment = fragments[0].receiver;
    int startingPositionInCascade = 1;
    if (!fragment.isImplicitThis()) {
      fragment.traverse(this, scope);
    } else {
      MessageSend currentMessageSend = fragments[1];
      final int numberOfParens = (currentMessageSend.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
      if (numberOfParens > 0) {
        manageOpeningParenthesizedExpression(currentMessageSend, numberOfParens);
View Full Code Here

         this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET);
         this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET);
       }
    }

    final Expression initialization = localDeclaration.initialization;
    if (initialization != null) {
      /*
       * Print the method name
       */
      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);
      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);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.Expression

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.