Java 类org.eclipse.xtext.xbase.XUnaryOperation 实例源码

项目:xtext-extras    文件:FeatureLinkHelper.java   
public XExpression getSyntacticReceiver(XExpression expression) {
    if (expression instanceof XAbstractFeatureCall) {
        if (expression instanceof XFeatureCall) {
            return null;
        }
        if (expression instanceof XMemberFeatureCall) {
            return ((XMemberFeatureCall) expression).getMemberCallTarget();
        }
        if (expression instanceof XAssignment) {
            return ((XAssignment) expression).getAssignable();
        }
        if (expression instanceof XBinaryOperation) {
            return ((XBinaryOperation) expression).getLeftOperand();
        }
        if (expression instanceof XUnaryOperation) {
            return ((XUnaryOperation) expression).getOperand();
        }
        if (expression instanceof XPostfixOperation) {
            return ((XPostfixOperation) expression).getOperand();
        }
    }
    return null;
}
项目:xtext-extras    文件:FeatureLinkHelper.java   
public List<XExpression> getSyntacticArguments(XAbstractFeatureCall expression) {
    if (expression instanceof XFeatureCall) {
        return ((XFeatureCall) expression).getFeatureCallArguments();
    }
    if (expression instanceof XMemberFeatureCall) {
        return ((XMemberFeatureCall) expression).getMemberCallArguments();
    }
    if (expression instanceof XAssignment) {
        return Collections.singletonList(((XAssignment) expression).getValue());
    }
    if (expression instanceof XBinaryOperation) {
        return Collections.singletonList(((XBinaryOperation) expression).getRightOperand());
    }
    // explicit condition to make sure we thought about it
    if (expression instanceof XUnaryOperation) {
        return Collections.emptyList();
    }
    if (expression instanceof XPostfixOperation) {
        return Collections.emptyList();
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:AbstractConstantExpressionsInterpreter.java   
public Object internalEvaluate(final XExpression it, final Context ctx) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, ctx);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, ctx);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, ctx);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, ctx);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, ctx);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, ctx);
  } else if (it instanceof XAnnotation) {
    return _internalEvaluate((XAnnotation)it, ctx);
  } else if (it != null) {
    return _internalEvaluate(it, ctx);
  } else if (it == null) {
    return _internalEvaluate((Void)null, ctx);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, ctx).toString());
  }
}
项目:dsl-devkit    文件:FormalParameterCheckBase.java   
/**
 * Validates that all XNumberLiterals in this expression, which occurs on the right-hand side of a formal parameter
 * declaration/definition, have indeed integral values.
 * 
 * @param value
 *          to check
 * @param issueCode
 *          to issue if the validation fails
 */
protected void checkRightHandSideHasOnlyIntegralNumbers(final XExpression value, final String issueCode) {
  if (value != null) {
    List<XExpression> exprs = (value instanceof XListLiteral) ? ((XListLiteral) value).getElements() : Collections.singletonList(value);
    for (XExpression expr : exprs) {
      XExpression e = expr;
      while (e instanceof XUnaryOperation) {
        e = ((XUnaryOperation) e).getOperand();
      }
      if (e instanceof XNumberLiteral) {
        try {
          Integer.decode(((XNumberLiteral) e).getValue());
        } catch (NumberFormatException ex) {
          error("Only integral values as numbers are allowed in check parameters", expr, null, issueCode); // TODO: NLS
        }
      }
    }
  }
}
项目:xtext-extras    文件:AmbiguousFeatureLinkingCandidate.java   
@Override
protected String getSyntaxDescriptions() {
    XExpression expression = getExpression();
    if (expression instanceof XBinaryOperation) {
        return "binary operation";
    } else if (expression instanceof XUnaryOperation) {
        return "unary operation";
    } else if (expression instanceof XPostfixOperation) {
        return "postfix operation";
    } else {
        return "feature call";
    }
}
项目:xtext-extras    文件:XbaseSyntacticSequencer.java   
protected boolean startsWithUnaryOperator(EObject obj) {
    if(obj instanceof XUnaryOperation)
        return true;
    if(obj instanceof XBinaryOperation)
        return startsWithUnaryOperator(((XBinaryOperation)obj).getLeftOperand());
    if(obj instanceof XPostfixOperation) {
        return startsWithUnaryOperator(((XPostfixOperation)obj).getOperand());
    }
    return false;
}
项目:xtext-extras    文件:ConstantConditionsInterpreter.java   
public EvaluationResult internalEvaluate(final XExpression it, final EvaluationContext context) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, context);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, context);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, context);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, context);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, context);
  } else if (it instanceof XNullLiteral) {
    return _internalEvaluate((XNullLiteral)it, context);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, context);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, context);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, context);
  } else if (it != null) {
    return _internalEvaluate(it, context);
  } else if (it == null) {
    return _internalEvaluate((Void)null, context);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, context).toString());
  }
}
项目:xtext-extras    文件:SwitchConstantExpressionsInterpreter.java   
public Object internalEvaluate(final XExpression it, final Context ctx) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, ctx);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, ctx);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, ctx);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, ctx);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, ctx);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, ctx);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, ctx);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, ctx);
  } else if (it instanceof XAnnotation) {
    return _internalEvaluate((XAnnotation)it, ctx);
  } else if (it != null) {
    return _internalEvaluate(it, ctx);
  } else if (it == null) {
    return _internalEvaluate((Void)null, ctx);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, ctx).toString());
  }
}
项目:xtext-extras    文件:AbstractConstantExpressionsInterpreter.java   
protected Object _internalEvaluate(final XUnaryOperation it, final Context ctx) {
  Object _xblockexpression = null;
  {
    final Object value = this.evaluate(it.getOperand(), ctx);
    final String op = this.getOperator(it);
    Object _switchResult = null;
    boolean _matched = false;
    if (Objects.equal(op, "-")) {
      _matched=true;
      _switchResult = this.constantOperators.minus(value);
    }
    if (!_matched) {
      if ((Objects.equal(op, "!") && (value instanceof Boolean))) {
        _matched=true;
        _switchResult = Boolean.valueOf((!(((Boolean) value)).booleanValue()));
      }
    }
    if (!_matched) {
      if ((Objects.equal(op, "+") && (value instanceof Number))) {
        _matched=true;
        _switchResult = value;
      }
    }
    if (!_matched) {
      throw new ConstantExpressionEvaluationException(((("Couldn\'t evaluate unary operator \'" + op) + "\' on value ") + value));
    }
    _xblockexpression = _switchResult;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testUnaryOperation_3() throws Exception {
    XBinaryOperation call = (XBinaryOperation) expression("foo+-bar");
    assertEquals("+",call.getConcreteSyntaxFeatureName());
    assertEquals(2,call.getExplicitArguments().size());
    XUnaryOperation unary = (XUnaryOperation) call.getExplicitArguments().get(1);
    assertEquals("-", unary.getConcreteSyntaxFeatureName());
    assertEquals("bar", ((XFeatureCall)unary.getExplicitArguments().get(0)).getConcreteSyntaxFeatureName());
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
@Deprecated
protected void sequence_XUnaryOperation(EObject context, XUnaryOperation semanticObject) {
    sequence_XUnaryOperation(createContext(context, semanticObject), semanticObject);
}
项目:xtext-extras    文件:ConstantConditionsInterpreter.java   
protected EvaluationResult _internalEvaluate(final XUnaryOperation it, final EvaluationContext context) {
  EvaluationResult _xifexpression = null;
  boolean _isFromXbaseLibrary = this.isFromXbaseLibrary(it, context);
  if (_isFromXbaseLibrary) {
    EvaluationResult _xblockexpression = null;
    {
      final EvaluationResult arg = this.doEvaluate(it.getOperand(), context);
      final String op = it.getConcreteSyntaxFeatureName();
      EvaluationResult _switchResult = null;
      boolean _matched = false;
      if (Objects.equal(op, "-")) {
        _matched=true;
        try {
          final Object result = this.constantOperators.minus(arg.getRawValue());
          boolean _isCompileTimeConstant = arg.isCompileTimeConstant();
          return new EvaluationResult(result, _isCompileTimeConstant);
        } catch (final Throwable _t) {
          if (_t instanceof ConstantExpressionEvaluationException) {
            return EvaluationResult.NOT_A_CONSTANT;
          } else {
            throw Exceptions.sneakyThrow(_t);
          }
        }
      }
      if (!_matched) {
        if ((Objects.equal(op, "!") && (arg.getRawValue() instanceof Boolean))) {
          _matched=true;
          Object _rawValue = arg.getRawValue();
          boolean _not = (!(((Boolean) _rawValue)).booleanValue());
          boolean _isCompileTimeConstant_1 = arg.isCompileTimeConstant();
          _switchResult = new EvaluationResult(Boolean.valueOf(_not), _isCompileTimeConstant_1);
        }
      }
      if (!_matched) {
        if ((Objects.equal(op, "+") && (arg.getRawValue() instanceof Number))) {
          _matched=true;
          _switchResult = arg;
        }
      }
      if (!_matched) {
        _switchResult = EvaluationResult.NOT_A_CONSTANT;
      }
      _xblockexpression = _switchResult;
    }
    _xifexpression = _xblockexpression;
  } else {
    return EvaluationResult.NOT_A_CONSTANT;
  }
  return _xifexpression;
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testUnaryOperation() throws Exception {
    XUnaryOperation call = (XUnaryOperation) expression("-(Foo)");
    assertNotNull(call);
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testUnaryOperation_2() throws Exception {
    XUnaryOperation call = (XUnaryOperation) expression("-foo");
    assertNotNull(call);
}
项目:xtext-extras    文件:AbstractFeatureCallCustomImplTest.java   
@SuppressWarnings("deprecation")
@Test public void testUnaryOperation() throws Exception {
    assertEquals(1, ((XUnaryOperation) expression("- bar")).getExplicitArguments().size());
}
项目:xtext-extras    文件:CustomExpressionTest.java   
@Test public void testNullValuesShouldBeIgnored() throws Exception {
    //unary operations are not implemented yet
    String input = "!";
    XUnaryOperation expression = (XUnaryOperation) incompleteExpression(input);
    assertTrue(expression.getExplicitArguments().isEmpty()); // throws exception if null value is added to result list
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
/**
 * Contexts:
 *     XExpression returns XUnaryOperation
 *     XAssignment returns XUnaryOperation
 *     XAssignment.XBinaryOperation_1_1_0_0_0 returns XUnaryOperation
 *     XOrExpression returns XUnaryOperation
 *     XOrExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
 *     XAndExpression returns XUnaryOperation
 *     XAndExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
 *     XEqualityExpression returns XUnaryOperation
 *     XEqualityExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
 *     XRelationalExpression returns XUnaryOperation
 *     XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XUnaryOperation
 *     XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XUnaryOperation
 *     XOtherOperatorExpression returns XUnaryOperation
 *     XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
 *     XAdditiveExpression returns XUnaryOperation
 *     XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
 *     XMultiplicativeExpression returns XUnaryOperation
 *     XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
 *     XUnaryOperation returns XUnaryOperation
 *     XCastedExpression returns XUnaryOperation
 *     XCastedExpression.XCastedExpression_1_0_0_0 returns XUnaryOperation
 *     XPostfixOperation returns XUnaryOperation
 *     XPostfixOperation.XPostfixOperation_1_0_0 returns XUnaryOperation
 *     XMemberFeatureCall returns XUnaryOperation
 *     XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XUnaryOperation
 *     XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XUnaryOperation
 *     XPrimaryExpression returns XUnaryOperation
 *     XParenthesizedExpression returns XUnaryOperation
 *     XExpressionOrVarDeclaration returns XUnaryOperation
 *
 * Constraint:
 *     (feature=[JvmIdentifiableElement|OpUnary] operand=XUnaryOperation)
 */
protected void sequence_XUnaryOperation(ISerializationContext context, XUnaryOperation semanticObject) {
    if (errorAcceptor != null) {
        if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE));
        if (transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XUNARY_OPERATION__OPERAND) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XUNARY_OPERATION__OPERAND));
    }
    SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
    feeder.accept(grammarAccess.getXUnaryOperationAccess().getFeatureJvmIdentifiableElementOpUnaryParserRuleCall_0_1_0_1(), semanticObject.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, false));
    feeder.accept(grammarAccess.getXUnaryOperationAccess().getOperandXUnaryOperationParserRuleCall_0_2_0(), semanticObject.getOperand());
    feeder.finish();
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     (feature=[JvmIdentifiableElement|OpUnary] operand=XConstantUnaryOperation)
 */
protected void sequence_XConstantUnaryOperation(EObject context, XUnaryOperation semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     (feature=[JvmIdentifiableElement|OpUnary] operand=XUnaryOperation)
 */
protected void sequence_XUnaryOperation(EObject context, XUnaryOperation semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}
项目:dsl-devkit    文件:AbstractCheckCfgSemanticSequencer.java   
/**
 * Constraint:
 *     (feature=[JvmIdentifiableElement|OpUnary] operand=XConstantUnaryOperation)
 */
protected void sequence_XConstantUnaryOperation(EObject context, XUnaryOperation semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}
项目:dsl-devkit    文件:AbstractCheckCfgSemanticSequencer.java   
/**
 * Constraint:
 *     (feature=[JvmIdentifiableElement|OpUnary] operand=XUnaryOperation)
 */
protected void sequence_XUnaryOperation(EObject context, XUnaryOperation semanticObject) {
    genericSequencer.createSequence(context, semanticObject);
}