org.eclipse.xtext.xbase.XBooleanLiteral Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.XBooleanLiteral.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RichStringEvaluationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void acceptElseIfCondition(/* @NonNull */ XExpression condition) { if (!internalIgnore()) { if (printElse.peek()) { XBooleanLiteral literal = (XBooleanLiteral) condition; boolean conditionResult = literal.isIsTrue(); if (conditionResult) { printElse.pop(); printElse.push(Boolean.FALSE); } printNext.pop(); printNext.push(conditionResult); } else { printNext.pop(); printNext.push(Boolean.FALSE); } } }
Example #2
Source File: SARLExpressionHelper.java From sarl with Apache License 2.0 | 6 votes |
/** Convert the boolean constant to the object equivalent if possible. * * @param expression the expression to convert. * @return one of the boolean constants {@link Boolean#TRUE} or {@link Boolean#FALSE}, * or {@code null} if the expression is not a constant boolean expression. */ @SuppressWarnings("static-method") public Boolean toBooleanPrimitiveWrapperConstant(XExpression expression) { if (expression instanceof XBooleanLiteral) { return ((XBooleanLiteral) expression).isIsTrue() ? Boolean.TRUE : Boolean.FALSE; } if (expression instanceof XMemberFeatureCall) { final XMemberFeatureCall call = (XMemberFeatureCall) expression; final XExpression receiver = call.getMemberCallTarget(); if (receiver instanceof XFeatureCall) { final XFeatureCall call2 = (XFeatureCall) receiver; final String call2Identifier = call2.getConcreteSyntaxFeatureName(); if (Boolean.class.getSimpleName().equals(call2Identifier) || Boolean.class.getName().equals(call2Identifier)) { final String callIdentifier = call.getConcreteSyntaxFeatureName(); if ("TRUE".equals(callIdentifier)) { //$NON-NLS-1$ return Boolean.TRUE; } else if ("FALSE".equals(callIdentifier)) { //$NON-NLS-1$ return Boolean.FALSE; } } } } return null; }
Example #3
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testRichStringIF_00() throws Exception { XtendFunction function = function("def foo() ''' foo �IF true� wurst �ELSEIF null==3� brot �ELSE� machine �ENDIF� bar '''"); final RichString richString = (RichString) function.getExpression(); assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral); final RichStringIf rsIf = (RichStringIf) richString.getExpressions().get(1); assertTrue(rsIf.getIf() instanceof XBooleanLiteral); assertTrue(rsIf.getThen() instanceof RichString); assertEquals(1,rsIf.getElseIfs().size()); RichStringElseIf elseIf = rsIf.getElseIfs().get(0); assertTrue(elseIf.getIf() instanceof XBinaryOperation); assertTrue(elseIf.getThen() instanceof RichString); assertTrue(rsIf.getElse() instanceof RichString); assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral); }
Example #4
Source File: LiteralsCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) { if (obj instanceof XStringLiteral) { _toJavaExpression((XStringLiteral) obj, appendable); } else if (obj instanceof XNumberLiteral) { _toJavaExpression((XNumberLiteral) obj, appendable); } else if (obj instanceof XNullLiteral) { _toJavaExpression((XNullLiteral) obj, appendable); } else if (obj instanceof XBooleanLiteral) { _toJavaExpression((XBooleanLiteral) obj, appendable); } else if (obj instanceof XTypeLiteral) { _toJavaExpression((XTypeLiteral) obj, appendable); } else { super.internalToConvertedExpression(obj, appendable); } }
Example #5
Source File: LiteralsCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) { if (obj instanceof XStringLiteral) { _toJavaStatement((XStringLiteral) obj, appendable, isReferenced); } else if (obj instanceof XNumberLiteral) { _toJavaStatement((XNumberLiteral) obj, appendable, isReferenced); } else if (obj instanceof XNullLiteral) { _toJavaStatement((XNullLiteral) obj, appendable, isReferenced); } else if (obj instanceof XBooleanLiteral) { _toJavaStatement((XBooleanLiteral) obj, appendable, isReferenced); } else if (obj instanceof XTypeLiteral) { _toJavaStatement((XTypeLiteral) obj, appendable, isReferenced); } else { super.doInternalToJavaStatement(obj, appendable, isReferenced); } }
Example #6
Source File: ParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testRichStringIF_01() throws Exception { XtendFunction function = function("def foo() ''' foo �IF true� wurst �IF false� brot �ELSE� machine �ENDIF� bar �ENDIF�'''"); final RichString richString = (RichString) function.getExpression(); assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral); final RichStringIf rsIf = (RichStringIf) richString.getExpressions().get(1); assertTrue(rsIf.getIf() instanceof XBooleanLiteral); final RichString then = (RichString) rsIf.getThen(); assertEquals(3,then.getExpressions().size()); RichStringIf innerIf = (RichStringIf) then.getExpressions().get(1); assertTrue(innerIf.getIf() instanceof XBooleanLiteral); assertTrue(innerIf.getElse() instanceof RichString); assertTrue(rsIf.getElse()==null); assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral); }
Example #7
Source File: AbstractConstantExpressionsInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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()); } }
Example #8
Source File: ConstantExpressionValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public boolean isConstant(final XExpression expression) { if (expression instanceof XAbstractFeatureCall) { return _isConstant((XAbstractFeatureCall)expression); } else if (expression instanceof XBooleanLiteral) { return _isConstant((XBooleanLiteral)expression); } else if (expression instanceof XCastedExpression) { return _isConstant((XCastedExpression)expression); } else if (expression instanceof XNumberLiteral) { return _isConstant((XNumberLiteral)expression); } else if (expression instanceof XStringLiteral) { return _isConstant((XStringLiteral)expression); } else if (expression instanceof XTypeLiteral) { return _isConstant((XTypeLiteral)expression); } else if (expression != null) { return _isConstant(expression); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression).toString()); } }
Example #9
Source File: ShouldExtensions.java From sarl with Apache License 2.0 | 6 votes |
/** Ensure that the given boolean literal is equal to the given value. * * @param actual the boolean literal to test. * @param expected the expected value. * @return the validation status */ public static boolean shouldBe(XBooleanLiteral actual, Object expected) { if (actual == null) { return false; } final Boolean b; if (expected instanceof Boolean) { b = (Boolean) expected; } else { try { b = new Boolean(expected.toString()); } catch (Throwable exception) { return false; } } return b.booleanValue() == actual.isIsTrue(); }
Example #10
Source File: LiteralsCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) { if (expr instanceof XBooleanLiteral || expr instanceof XStringLiteral || expr instanceof XNumberLiteral || expr instanceof XTypeLiteral || expr instanceof XClosure || expr instanceof XNullLiteral) return false; return super.isVariableDeclarationRequired(expr,b, recursive); }
Example #11
Source File: SwitchConstantExpressionsInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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()); } }
Example #12
Source File: ConstantConditionsInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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()); } }
Example #13
Source File: ConstantExpressionsInterpreter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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()); } }
Example #14
Source File: RichStringEvaluationTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptIfCondition(/* @NonNull */ XExpression condition) { if (ignore()) { ignoreStack.push(Boolean.TRUE); } else { printElse.push(Boolean.TRUE); XBooleanLiteral literal = (XBooleanLiteral) condition; boolean conditionResult = literal.isIsTrue(); if (conditionResult) { printElse.pop(); printElse.push(Boolean.FALSE); } printNext.push(conditionResult); } }
Example #15
Source File: JvmAnnotationReferencePrinter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String internalToString(Object obj) { if (obj instanceof XBinaryOperation) { return _internalToString((XBinaryOperation) obj); } else if (obj instanceof XFeatureCall) { return _internalToString((XFeatureCall) obj); } else if (obj instanceof XListLiteral) { return _internalToString((XListLiteral) obj); } else if (obj instanceof XMemberFeatureCall) { return _internalToString((XMemberFeatureCall) obj); } else if (obj instanceof XBooleanLiteral) { return _internalToString((XBooleanLiteral) obj); } else if (obj instanceof XNumberLiteral) { return _internalToString((XNumberLiteral) obj); } else if (obj instanceof XStringLiteral) { return _internalToString((XStringLiteral) obj); } else if (obj instanceof XTypeLiteral) { return _internalToString((XTypeLiteral) obj); } else if (obj instanceof XAnnotation) { return _internalToString((XAnnotation) obj); } else if (obj instanceof JvmAnnotationReference) { return _internalToString((JvmAnnotationReference) obj); } else if (obj instanceof JvmAnnotationValue) { return _internalToString((JvmAnnotationValue) obj); } else { return _internalToString(obj); } }
Example #16
Source File: FeatureCallCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private static boolean isConstantExpression(JvmAnnotationReference reference) { for (final JvmAnnotationValue annotationValue: reference.getValues()) { if ("constantExpression".equals(annotationValue.getValueName())) { if (annotationValue instanceof JvmBooleanAnnotationValue) { return ((JvmBooleanAnnotationValue) annotationValue).getValues().get(0).booleanValue(); } else if (annotationValue instanceof JvmCustomAnnotationValue) { final EObject value = ((JvmCustomAnnotationValue) annotationValue).getValues().get(0); if (value instanceof XBooleanLiteral) { return ((XBooleanLiteral) value).isIsTrue(); } } } } return false; }
Example #17
Source File: XExpressionHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * @return whether the expression itself (not its children) possibly causes a side-effect */ public boolean hasSideEffects(XExpression expr) { if (expr instanceof XClosure || expr instanceof XStringLiteral || expr instanceof XTypeLiteral || expr instanceof XBooleanLiteral || expr instanceof XNumberLiteral || expr instanceof XNullLiteral || expr instanceof XAnnotation ) return false; if(expr instanceof XCollectionLiteral) { for(XExpression element: ((XCollectionLiteral)expr).getElements()) { if(hasSideEffects(element)) return true; } return false; } if (expr instanceof XAbstractFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr; return hasSideEffects(featureCall, true); } if (expr instanceof XConstructorCall) { XConstructorCall constrCall = (XConstructorCall) expr; return findPureAnnotation(constrCall.getConstructor()) == null; } return true; }
Example #18
Source File: XbaseParserTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void testDoWhileExpression() throws Exception { XDoWhileExpression expression = (XDoWhileExpression) expression("do foo while (true)"); assertTrue(expression.getPredicate() instanceof XBooleanLiteral); assertFeatureCall("foo",expression.getBody()); }
Example #19
Source File: JvmAnnotationReferencePrinter.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected String _internalToString(XBooleanLiteral booleanLiteral) { return Boolean.toString(booleanLiteral.isIsTrue()); }
Example #20
Source File: XbaseParserTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void doTestInstanceOf(XInstanceOfExpression expression) { assertEquals("java.lang.Boolean",expression.getType().getIdentifier()); assertTrue(expression.getExpression() instanceof XBooleanLiteral); }
Example #21
Source File: AbstractXbaseSemanticSequencer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Deprecated protected void sequence_XBooleanLiteral(EObject context, XBooleanLiteral semanticObject) { sequence_XBooleanLiteral(createContext(context, semanticObject), semanticObject); }
Example #22
Source File: XtendImplicitReturnFinder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) { if (expression instanceof AnonymousClass) { _findImplicitReturns((AnonymousClass)expression, acceptor); return; } else if (expression instanceof RichString) { _findImplicitReturns((RichString)expression, acceptor); return; } else if (expression instanceof XAbstractFeatureCall) { _findImplicitReturns((XAbstractFeatureCall)expression, acceptor); return; } else if (expression instanceof XBlockExpression) { _findImplicitReturns((XBlockExpression)expression, acceptor); return; } else if (expression instanceof XBooleanLiteral) { _findImplicitReturns((XBooleanLiteral)expression, acceptor); return; } else if (expression instanceof XCastedExpression) { _findImplicitReturns((XCastedExpression)expression, acceptor); return; } else if (expression instanceof XClosure) { _findImplicitReturns((XClosure)expression, acceptor); return; } else if (expression instanceof XCollectionLiteral) { _findImplicitReturns((XCollectionLiteral)expression, acceptor); return; } else if (expression instanceof XConstructorCall) { _findImplicitReturns((XConstructorCall)expression, acceptor); return; } else if (expression instanceof XIfExpression) { _findImplicitReturns((XIfExpression)expression, acceptor); return; } else if (expression instanceof XInstanceOfExpression) { _findImplicitReturns((XInstanceOfExpression)expression, acceptor); return; } else if (expression instanceof XNullLiteral) { _findImplicitReturns((XNullLiteral)expression, acceptor); return; } else if (expression instanceof XNumberLiteral) { _findImplicitReturns((XNumberLiteral)expression, acceptor); return; } else if (expression instanceof XStringLiteral) { _findImplicitReturns((XStringLiteral)expression, acceptor); return; } else if (expression instanceof XSwitchExpression) { _findImplicitReturns((XSwitchExpression)expression, acceptor); return; } else if (expression instanceof XSynchronizedExpression) { _findImplicitReturns((XSynchronizedExpression)expression, acceptor); return; } else if (expression instanceof XTryCatchFinallyExpression) { _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor); return; } else if (expression instanceof XTypeLiteral) { _findImplicitReturns((XTypeLiteral)expression, acceptor); return; } else if (expression != null) { _findImplicitReturns(expression, acceptor); return; } else if (expression == null) { _findImplicitReturns((Void)null, acceptor); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression, acceptor).toString()); } }
Example #23
Source File: ShouldExtensions.java From sarl with Apache License 2.0 | 4 votes |
/** Ensure that the given type literal is equal to the given type. * * @param actual the type literal to test. * @param expected the name of the expected type. * @return the validation status */ @SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity"}) public static boolean shouldBeLiteral(XExpression actual, Object expected) { if (actual instanceof XNumberLiteral) { return shouldBe((XNumberLiteral) actual, expected); } if (actual instanceof XBooleanLiteral) { return shouldBe((XBooleanLiteral) actual, expected); } if (actual instanceof XStringLiteral) { return shouldBe((XStringLiteral) actual, expected); } if (actual instanceof XTypeLiteral) { return shouldBe((XTypeLiteral) actual, expected); } if (actual instanceof XNullLiteral) { return Objects.equals("null", expected); //$NON-NLS-1$ } if (actual instanceof XCollectionLiteral) { return shouldBe((XCollectionLiteral) actual, expected); } if (actual instanceof XBinaryOperation) { final XBinaryOperation op = (XBinaryOperation) actual; if ("operator_mappedTo".equals(op.getFeature().getSimpleName())) { //$NON-NLS-1$ final Object key; final Object value; if (expected instanceof Pair<?, ?>) { key = ((Pair<?, ?>) expected).getKey(); value = ((Pair<?, ?>) expected).getValue(); } else if (expected instanceof Entry<?, ?>) { key = ((Entry<?, ?>) expected).getKey(); value = ((Entry<?, ?>) expected).getValue(); } else { return false; } return shouldBeLiteral(op.getLeftOperand(), key) && shouldBeLiteral(op.getRightOperand(), value); } } return false; }
Example #24
Source File: ExpressionBuilderImpl.java From sarl with Apache License 2.0 | 4 votes |
/** Replies the XExpression for the default value associated to the given type. * @param type the type for which the default value should be determined. * @return the default value. */ @Pure public XExpression getDefaultXExpressionForType(String type) { //TODO: Check if a similar function exists in the Xbase library. XExpression expr = null; if (type != null && !"void".equals(type) && !Void.class.getName().equals(type)) { switch (type) { case "boolean": case "java.lang.Boolean": XBooleanLiteral booleanLiteral = XbaseFactory.eINSTANCE.createXBooleanLiteral(); booleanLiteral.setIsTrue(false); expr = booleanLiteral; break; case "float": case "java.lang.Float": XNumberLiteral numberLiteral = XbaseFactory.eINSTANCE.createXNumberLiteral(); numberLiteral.setValue("0.0f"); expr = numberLiteral; break; case "double": case "java.lang.Double": case "java.lang.BigDecimal": numberLiteral = XbaseFactory.eINSTANCE.createXNumberLiteral(); numberLiteral.setValue("0.0"); expr = numberLiteral; break; case "int": case "long": case "java.lang.Integer": case "java.lang.Long": case "java.lang.BigInteger": numberLiteral = XbaseFactory.eINSTANCE.createXNumberLiteral(); numberLiteral.setValue("0"); expr = numberLiteral; break; case "byte": case "short": case "char": case "java.lang.Byte": case "java.lang.Short": case "java.lang.Character": numberLiteral = XbaseFactory.eINSTANCE.createXNumberLiteral(); numberLiteral.setValue("0"); XCastedExpression castExpression = XbaseFactory.eINSTANCE.createXCastedExpression(); castExpression.setTarget(numberLiteral); castExpression.setType(newTypeRef(this.context, type)); expr = numberLiteral; break; default: expr = XbaseFactory.eINSTANCE.createXNullLiteral(); break; } } return expr; }
Example #25
Source File: SARLValidator.java From sarl with Apache License 2.0 | 4 votes |
/** Check the type of the behavior unit's guard. * * @param behaviorUnit the behavior unit. */ @Check(CheckType.FAST) public void checkBehaviorUnitGuardType(SarlBehaviorUnit behaviorUnit) { final XExpression guard = behaviorUnit.getGuard(); if (guard != null) { if (this.operationHelper.hasSideEffects(null, guard)) { error(Messages.SARLValidator_53, guard, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INNER_EXPRESSION); return; } if (guard instanceof XBooleanLiteral) { final XBooleanLiteral booleanLiteral = (XBooleanLiteral) guard; if (booleanLiteral.isIsTrue()) { if (!isIgnored(DISCOURAGED_BOOLEAN_EXPRESSION)) { addIssue(Messages.SARLValidator_54, booleanLiteral, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, DISCOURAGED_BOOLEAN_EXPRESSION); } } else if (!isIgnored(UNREACHABLE_BEHAVIOR_UNIT)) { addIssue(Messages.SARLValidator_55, behaviorUnit, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, UNREACHABLE_BEHAVIOR_UNIT, behaviorUnit.getName().getSimpleName()); } return; } final LightweightTypeReference fromType = getActualType(guard); if (!fromType.isAssignableFrom(Boolean.TYPE)) { error(MessageFormat.format( Messages.SARLValidator_38, getNameOfTypes(fromType), boolean.class.getName()), guard, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES); } } }
Example #26
Source File: SarlCompiler.java From sarl with Apache License 2.0 | 4 votes |
@SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"}) private static String getAnnotationStringValue(JvmAnnotationValue value) { if (value instanceof JvmAnnotationAnnotationValue) { return ((JvmAnnotationAnnotationValue) value).getValues().get(0).getAnnotation().getIdentifier(); } if (value instanceof JvmBooleanAnnotationValue) { return ((JvmBooleanAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmByteAnnotationValue) { return ((JvmByteAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmCharAnnotationValue) { return ((JvmCharAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmCustomAnnotationValue) { final EObject evalue = ((JvmCustomAnnotationValue) value).getValues().get(0); if (evalue instanceof XStringLiteral) { return ((XStringLiteral) evalue).getValue(); } if (evalue instanceof XNumberLiteral) { return ((XNumberLiteral) evalue).getValue(); } if (evalue instanceof XBooleanLiteral) { return ((XNumberLiteral) evalue).getValue(); } if (evalue instanceof XTypeLiteral) { return ((XTypeLiteral) evalue).getType().getIdentifier(); } } if (value instanceof JvmDoubleAnnotationValue) { return ((JvmDoubleAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmEnumAnnotationValue) { return ((JvmEnumAnnotationValue) value).getValues().get(0).getSimpleName(); } if (value instanceof JvmFloatAnnotationValue) { return ((JvmFloatAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmIntAnnotationValue) { return ((JvmIntAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmLongAnnotationValue) { return ((JvmLongAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmShortAnnotationValue) { return ((JvmShortAnnotationValue) value).getValues().get(0).toString(); } if (value instanceof JvmStringAnnotationValue) { return ((JvmStringAnnotationValue) value).getValues().get(0); } if (value instanceof JvmTypeAnnotationValue) { return ((JvmTypeAnnotationValue) value).getValues().get(0).getIdentifier(); } return null; }
Example #27
Source File: SarlCompiler.java From sarl with Apache License 2.0 | 4 votes |
private static boolean isLiteral(XExpression expr) { return expr instanceof XBooleanLiteral || expr instanceof XStringLiteral || expr instanceof XNumberLiteral || expr instanceof XCollectionLiteral || expr instanceof XSetLiteral || expr instanceof XNullLiteral || expr instanceof XTypeLiteral; }
Example #28
Source File: XbaseParserTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void testIf_1() throws Exception { XIfExpression ie = (XIfExpression) expression("if (true) false else bar"); assertTrue(((XBooleanLiteral) ie.getIf()).isIsTrue()); assertFalse(((XBooleanLiteral) ie.getThen()).isIsTrue()); assertTrue(ie.getElse() instanceof XFeatureCall); }
Example #29
Source File: XbaseTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public void computeTypes(XExpression expression, ITypeComputationState state) { if (expression instanceof XAssignment) { _computeTypes((XAssignment)expression, state); } else if (expression instanceof XAbstractFeatureCall) { _computeTypes((XAbstractFeatureCall)expression, state); } else if (expression instanceof XDoWhileExpression) { _computeTypes((XDoWhileExpression)expression, state); } else if (expression instanceof XWhileExpression) { _computeTypes((XWhileExpression)expression, state); } else if (expression instanceof XBlockExpression) { _computeTypes((XBlockExpression)expression, state); } else if (expression instanceof XBooleanLiteral) { _computeTypes((XBooleanLiteral)expression, state); } else if (expression instanceof XCastedExpression) { _computeTypes((XCastedExpression)expression, state); } else if (expression instanceof XClosure) { _computeTypes((XClosure)expression, state); } else if (expression instanceof XConstructorCall) { _computeTypes((XConstructorCall)expression, state); } else if (expression instanceof XForLoopExpression) { _computeTypes((XForLoopExpression)expression, state); } else if (expression instanceof XBasicForLoopExpression) { _computeTypes((XBasicForLoopExpression)expression, state); } else if (expression instanceof XIfExpression) { _computeTypes((XIfExpression)expression, state); } else if (expression instanceof XInstanceOfExpression) { _computeTypes((XInstanceOfExpression)expression, state); } else if (expression instanceof XNumberLiteral) { _computeTypes((XNumberLiteral)expression, state); } else if (expression instanceof XNullLiteral) { _computeTypes((XNullLiteral)expression, state); } else if (expression instanceof XReturnExpression) { _computeTypes((XReturnExpression)expression, state); } else if (expression instanceof XStringLiteral) { _computeTypes((XStringLiteral)expression, state); } else if (expression instanceof XSwitchExpression) { _computeTypes((XSwitchExpression)expression, state); } else if (expression instanceof XThrowExpression) { _computeTypes((XThrowExpression)expression, state); } else if (expression instanceof XTryCatchFinallyExpression) { _computeTypes((XTryCatchFinallyExpression)expression, state); } else if (expression instanceof XTypeLiteral) { _computeTypes((XTypeLiteral)expression, state); } else if (expression instanceof XVariableDeclaration) { _computeTypes((XVariableDeclaration)expression, state); } else if (expression instanceof XListLiteral) { _computeTypes((XListLiteral)expression, state); } else if (expression instanceof XSetLiteral) { _computeTypes((XSetLiteral)expression, state); } else if (expression instanceof XSynchronizedExpression) { _computeTypes((XSynchronizedExpression)expression, state); } else { throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state); } }
Example #30
Source File: XbaseTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @param object used for dispatching */ protected void _computeTypes(XBooleanLiteral object, ITypeComputationState state) { LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state); state.acceptActualType(bool); }