Java源码示例:org.eclipse.xtext.xbase.XUnaryOperation
示例1
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;
}
示例2
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();
}
示例3
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());
}
}
示例4
/**
* 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
}
}
}
}
}
示例5
/** Generate the given object.
*
* @param operation the unary operation.
* @param it the target for the generated content.
* @param context the context.
* @return the operation.
*/
protected XExpression _generate(XUnaryOperation operation, IAppendable it, IExtraLanguageGeneratorContext context) {
appendReturnIfExpectedReturnedExpression(it, context);
final String operator = getOperatorSymbol(operation);
if (operator != null) {
it.append("("); //$NON-NLS-1$
switch (operator) {
case "+": //$NON-NLS-1$
generate(operation.getOperand(), it, context);
break;
case "-": //$NON-NLS-1$
it.append("-"); //$NON-NLS-1$
generate(operation.getOperand(), it, context);
break;
default:
throw new IllegalArgumentException(MessageFormat.format(Messages.PyExpressionGenerator_0, operator));
}
it.append(")"); //$NON-NLS-1$
}
return operation;
}
示例6
@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";
}
}
示例7
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;
}
示例8
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());
}
}
示例9
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());
}
}
示例10
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;
}
示例11
@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());
}
示例12
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;
}
示例13
public Object internalEvaluate(final XExpression it, final Context ctx) {
if (it instanceof XBinaryOperation) {
return _internalEvaluate((XBinaryOperation)it, ctx);
} else if (it instanceof XFeatureCall) {
return _internalEvaluate((XFeatureCall)it, ctx);
} else if (it instanceof XListLiteral) {
return _internalEvaluate((XListLiteral)it, ctx);
} else if (it instanceof XMemberFeatureCall) {
return _internalEvaluate((XMemberFeatureCall)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 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());
}
}
示例14
/**
* Contexts:
* XConstantUnaryOperation returns XUnaryOperation
* XFormalParameterDefaultValueLiteral returns XUnaryOperation
*
* Constraint:
* (feature=[JvmIdentifiableElement|OpUnary] operand=XConstantUnaryOperation)
*/
protected void sequence_XConstantUnaryOperation(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.getXConstantUnaryOperationAccess().getFeatureJvmIdentifiableElementOpUnaryParserRuleCall_0_1_0_1(), semanticObject.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, false));
feeder.accept(grammarAccess.getXConstantUnaryOperationAccess().getOperandXConstantUnaryOperationParserRuleCall_0_2_0(), semanticObject.getOperand());
feeder.finish();
}
示例15
/**
* Contexts:
* XConstantUnaryOperation returns XUnaryOperation
* XFormalParameterDefaultValueLiteral returns XUnaryOperation
*
* Constraint:
* (feature=[JvmIdentifiableElement|OpUnary] operand=XConstantUnaryOperation)
*/
protected void sequence_XConstantUnaryOperation(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.getXConstantUnaryOperationAccess().getFeatureJvmIdentifiableElementOpUnaryParserRuleCall_0_1_0_1(), semanticObject.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, false));
feeder.accept(grammarAccess.getXConstantUnaryOperationAccess().getOperandXConstantUnaryOperationParserRuleCall_0_2_0(), semanticObject.getOperand());
feeder.finish();
}
示例16
/** Test if the given expression has side effects.
*
* @param expression the expression.
* @param context the list of context expressions.
* @return {@code true} if the expression has side effects.
*/
protected Boolean _hasSideEffects(XUnaryOperation expression, ISideEffectContext context) {
if (expression.isTypeLiteral() || expression.isPackageFragment()) {
return Boolean.FALSE;
}
if (hasSideEffects(expression.getOperand(), context)) {
return true;
}
return false;
}
示例17
@Deprecated
protected void sequence_XUnaryOperation(EObject context, XUnaryOperation semanticObject) {
sequence_XUnaryOperation(createContext(context, semanticObject), semanticObject);
}
示例18
@Test public void testUnaryOperation() throws Exception {
XUnaryOperation call = (XUnaryOperation) expression("-(Foo)");
assertNotNull(call);
}
示例19
@Test public void testUnaryOperation_2() throws Exception {
XUnaryOperation call = (XUnaryOperation) expression("-foo");
assertNotNull(call);
}
示例20
@SuppressWarnings("deprecation")
@Test public void testUnaryOperation() throws Exception {
assertEquals(1, ((XUnaryOperation) expression("- bar")).getExplicitArguments().size());
}
示例21
@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
}
示例22
/**
* 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();
}
示例23
/**
* Contexts:
* XCastedExpression returns XUnaryOperation
* XCastedExpression.SarlCastedExpression_1_0_0_0 returns XUnaryOperation
* XPrimaryExpression returns XUnaryOperation
* XMultiplicativeExpression returns XUnaryOperation
* XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
* XExponentExpression returns XUnaryOperation
* XExponentExpression.XBinaryOperation_1_0_0_0 returns XUnaryOperation
* XUnaryOperation returns XUnaryOperation
* XAssignment returns XUnaryOperation
* XAssignment.XBinaryOperation_1_1_0_0_0 returns XUnaryOperation
* XConditionalExpression returns XUnaryOperation
* XConditionalExpression.XIfExpression_1_0_0_0 returns XUnaryOperation
* XExpressionOrSimpleConstructorCall returns XUnaryOperation
* RichStringPart returns XUnaryOperation
* XAnnotationElementValueOrCommaList returns XUnaryOperation
* XAnnotationElementValueOrCommaList.XListLiteral_1_1_0 returns XUnaryOperation
* XAnnotationElementValue returns XUnaryOperation
* XAnnotationOrExpression returns XUnaryOperation
* XExpression 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
* 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
* 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();
}