コード例 #1
0
  /* (non-Javadoc)
   * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.PrefixExpression)
   */
  public boolean visit(PrefixExpression node) {
    if (node.getOperand().getNodeType() == ASTNode.NUMBER_LITERAL) {
      // For number literals we see if it is a "+" or "-" prefix, and if it is, we simply
      // create a PTNumberLiteral with the operator already in it. It is a simplification.
      // Any other operator we've left alone since those won't be decoded simply by the
      // Number decoder.
      // If not a number literal, then leave alone since needs to be handled as a prefix
      // operation.
      PrefixExpression.Operator operator = node.getOperator();
      if (operator == PrefixExpression.Operator.PLUS
          || operator == PrefixExpression.Operator.MINUS) {
        PTNumberLiteral nm = InstantiationFactory.eINSTANCE.createPTNumberLiteral();
        nm.setToken(operator.toString() + ((NumberLiteral) node.getOperand()).getToken());
        expression = nm;
        return false;
      }
    }

    PTPrefixExpression pe = InstantiationFactory.eINSTANCE.createPTPrefixExpression();
    PTPrefixOperator ptoper = getParsePrefix(node.getOperator());
    if (ptoper == null) {
      // It is not one we can handle.
      throw new InvalidExpressionException(
          MessageFormat.format(
              WorkbenchUtilityMessages.ParseTreeCreationFromAST_OperatorTooComplicatedToHandle_EXC_,
              new Object[] {node.getOperator().toString()}));
    }
    pe.setOperator(ptoper);
    pe.setExpression(perform(node.getOperand()));
    expression = pe;
    return false;
  }
コード例 #2
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.NumberLiteral)
  */
 public boolean visit(NumberLiteral node) {
   PTNumberLiteral nl = InstantiationFactory.eINSTANCE.createPTNumberLiteral();
   nl.setToken(node.getToken());
   expression = nl;
   return false;
 }