@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); } }
@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); } }
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()); } }
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()); } }
@Test public void testSerialize_01() throws Exception { Resource resource = newResource("'foo' as String"); XCastedExpression casted = (XCastedExpression) resource.getContents().get(0); XbaseFactory factory = XbaseFactory.eINSTANCE; XClosure closure = factory.createXClosure(); XStringLiteral stringLiteral = factory.createXStringLiteral(); stringLiteral.setValue("value"); XBlockExpression blockExpression = factory.createXBlockExpression(); blockExpression.getExpressions().add(stringLiteral); closure.setExpression(blockExpression); closure.setExplicitSyntax(true); XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression(); instanceOfExpression.setExpression(closure); instanceOfExpression.setType(EcoreUtil.copy(casted.getType())); resource.getContents().clear(); resource.getContents().add(instanceOfExpression); ISerializer serializer = get(ISerializer.class); String string = serializer.serialize(instanceOfExpression); assertEquals("[|\"value\"] instanceof String", string); XInstanceOfExpression parsedExpression = parseHelper.parse(string); assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression)); }
@Test public void testSerialize_02() throws Exception { Resource resource = newResource("'foo' as String"); XCastedExpression casted = (XCastedExpression) resource.getContents().get(0); XbaseFactory factory = XbaseFactory.eINSTANCE; XIfExpression ifExpression = factory.createXIfExpression(); ifExpression.setIf(factory.createXBooleanLiteral()); XStringLiteral stringLiteral = factory.createXStringLiteral(); stringLiteral.setValue("value"); ifExpression.setThen(stringLiteral); XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression(); instanceOfExpression.setExpression(ifExpression); instanceOfExpression.setType(EcoreUtil.copy(casted.getType())); resource.getContents().clear(); resource.getContents().add(instanceOfExpression); ISerializer serializer = get(ISerializer.class); String string = serializer.serialize(instanceOfExpression); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=464846 assertEquals("( if(false) \"value\" ) instanceof String", string); XInstanceOfExpression parsedExpression = parseHelper.parse(string); assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression)); }
@Test public void testStringAnnotation() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, e); anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType)); anno.setValue(e); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()); EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues()); Assert.assertTrue((_head_1 instanceof XStringLiteral)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testAnnotationDefaultValue() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(Named.class, e); anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType)); anno.setValue(e); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()); EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues()); Assert.assertTrue((_head_1 instanceof XStringLiteral)); Assert.assertNull(IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()).getOperation()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * @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; }
/** * @since 2.4 */ protected void toJavaStatement(final XStringLiteral expr, ITreeAppendable b, boolean isReferenced, final boolean useUnicodeEscapes) { generateComment(new Later() { @Override public void exec(ITreeAppendable appendable) { // we have to escape closing comments in string literals String escapedClosingComments = expr.getValue().replace("*/", "* /"); String javaString = Strings.convertToJavaString(escapedClosingComments, useUnicodeEscapes); appendable.append("\"").append(javaString).append("\""); } }, b, isReferenced); }
@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); }
/** * @param context unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ protected Object _doEvaluate(XStringLiteral literal, IEvaluationContext context, CancelIndicator indicator) { LightweightTypeReference type = typeResolver.resolveTypes(literal).getActualType(literal); if (type != null && (type.isType(Character.TYPE) || type.isType(Character.class))) { return literal.getValue().charAt(0); } return literal.getValue(); }
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()); } }
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()); } }
@Test public void testClosure_2() throws Exception { XClosure closure = (XClosure) expression("[bar|'foo']"); assertEquals("foo", ((XStringLiteral) ((XBlockExpression)closure.getExpression()).getExpressions().get(0)) .getValue()); assertEquals("bar", closure.getFormalParameters().get(0).getName()); assertNull(closure.getFormalParameters().get(0).getParameterType()); }
@Test public void testClosure_3() throws Exception { XClosure closure = (XClosure) expression("[String bar|'foo']"); assertEquals("foo", ((XStringLiteral) ((XBlockExpression)closure.getExpression()).getExpressions().get(0)) .getValue()); assertEquals("bar", closure.getFormalParameters().get(0).getName()); assertEquals(1, closure.getFormalParameters().size()); assertNotNull(closure.getFormalParameters().get(0).getParameterType()); }
@Test public void testClosure_4() throws Exception { XClosure closure = (XClosure) expression("[foo, String bar|'foo']"); assertEquals("foo", ((XStringLiteral) ((XBlockExpression)closure.getExpression()).getExpressions().get(0)) .getValue()); assertEquals("foo", closure.getFormalParameters().get(0).getName()); assertEquals("bar", closure.getFormalParameters().get(1).getName()); assertEquals(2, closure.getFormalParameters().size()); assertNull(closure.getFormalParameters().get(0).getParameterType()); assertNotNull(closure.getFormalParameters().get(1).getParameterType()); }
@Test public void testFeatureCall_3() throws Exception { XMemberFeatureCall call = (XMemberFeatureCall) expression("'holla'.bar(4)"); assertNotNull(call); assertEquals(2, call.getExplicitArguments().size()); assertEquals("4", ((XNumberLiteral) call.getExplicitArguments().get(1)).getValue()); assertTrue(call.getExplicitArguments().get(0) instanceof XStringLiteral); }
@Test public void testSwitch_0() throws Exception { XSwitchExpression se = (XSwitchExpression) expression("switch true { case 1==0 : '1' }"); assertNull(se.getDefault()); assertEquals(1, se.getCases().size()); assertNotNull(se.getSwitch()); XCasePart casePart = se.getCases().get(0); assertTrue(casePart.getCase() instanceof XBinaryOperation); assertTrue(casePart.getThen() instanceof XStringLiteral); }
@Test public void testSwitch_1() throws Exception { XSwitchExpression se = (XSwitchExpression) expression("switch number{case 1:'1' case 2:'2' default:'3'}"); assertTrue(se.getDefault() instanceof XStringLiteral); assertEquals(2, se.getCases().size()); assertTrue(se.getSwitch() instanceof XFeatureCall); XCasePart case1 = se.getCases().get(0); assertEquals("1", ((XNumberLiteral) case1.getCase()).getValue()); assertTrue(case1.getThen() instanceof XStringLiteral); XCasePart case2 = se.getCases().get(1); assertEquals("2", ((XNumberLiteral) case2.getCase()).getValue()); assertTrue(case2.getThen() instanceof XStringLiteral); }
@Test public void testBlockExpression_withVariableDeclaration_4() throws Exception { XBlockExpression be = (XBlockExpression) expression("{ var Boolean x = 'bar' }"); assertEquals(1, be.getExpressions().size()); XVariableDeclaration vd = (XVariableDeclaration) be.getExpressions().get(0); assertEquals("x", vd.getName()); assertTrue(vd.getRight() instanceof XStringLiteral); assertNotNull(vd.getType()); }
public void resolvesStringLiteralsTo(final String expression, final String... types) { final String expressionWithQualifiedNames = expression.replace("$$", "org::eclipse::xtext::xbase::lib::"); final List<XStringLiteral> featureCalls = this.findLiterals(expressionWithQualifiedNames); Assert.assertFalse(featureCalls.isEmpty()); Assert.assertEquals(((List<String>)Conversions.doWrapArray(types)).size(), featureCalls.size()); final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XStringLiteral>head(featureCalls)); final Procedure2<XStringLiteral, Integer> _function = (XStringLiteral featureCall, Integer index) -> { final LightweightTypeReference type = resolvedTypes.getActualType(featureCall); StringConcatenation _builder = new StringConcatenation(); _builder.append("failed for literal at "); _builder.append(index); Assert.assertEquals(_builder.toString(), types[(index).intValue()], type.getSimpleName()); }; IterableExtensions.<XStringLiteral>forEach(featureCalls, _function); }
protected List<XStringLiteral> findLiterals(final CharSequence expression) { try { final XExpression xExpression = this.expression(expression, false); final List<XStringLiteral> featureCalls = IteratorExtensions.<XStringLiteral>toList(Iterators.<XStringLiteral>filter(EcoreUtil2.eAll(xExpression), XStringLiteral.class)); final Function1<XStringLiteral, Integer> _function = (XStringLiteral it) -> { return Integer.valueOf(NodeModelUtils.findActualNodeFor(it).getOffset()); }; return IterableExtensions.<XStringLiteral, Integer>sortBy(featureCalls, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * Constraint: * value=STRING */ protected void sequence_XStringLiteral(EObject context, XStringLiteral semanticObject) { if(errorAcceptor != null) { if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XSTRING_LITERAL__VALUE) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XSTRING_LITERAL__VALUE)); } INodesForEObjectProvider nodes = createNodeProvider(semanticObject); SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); feeder.accept(grammarAccess.getXStringLiteralAccess().getValueSTRINGTerminalRuleCall_1_0(), semanticObject.getValue()); feeder.finish(); }
@Deprecated protected void sequence_XStringLiteral(EObject context, XStringLiteral semanticObject) { sequence_XStringLiteral(createContext(context, semanticObject), semanticObject); }
@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); } }
public void _toJavaExpression(XStringLiteral expr, ITreeAppendable b) { toJavaExpression(expr, b, true); }
public void _toJavaStatement(final XStringLiteral expr, ITreeAppendable b, boolean isReferenced) { toJavaStatement(expr, b, isReferenced, true); }
/** * don't call this directly. Always call evaluate() internalEvaluate() */ protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) { if (expression instanceof XAssignment) { return _doEvaluate((XAssignment)expression, context, indicator); } else if (expression instanceof XDoWhileExpression) { return _doEvaluate((XDoWhileExpression)expression, context, indicator); } else if (expression instanceof XMemberFeatureCall) { return _doEvaluate((XMemberFeatureCall)expression, context, indicator); } else if (expression instanceof XWhileExpression) { return _doEvaluate((XWhileExpression)expression, context, indicator); } else if (expression instanceof XFeatureCall) { return _doEvaluate((XFeatureCall)expression, context, indicator); } else if (expression instanceof XAbstractFeatureCall) { return _doEvaluate((XAbstractFeatureCall)expression, context, indicator); } else if (expression instanceof XBlockExpression) { return _doEvaluate((XBlockExpression)expression, context, indicator); } else if (expression instanceof XSynchronizedExpression) { return _doEvaluate((XSynchronizedExpression)expression, context, indicator); } else if (expression instanceof XBooleanLiteral) { return _doEvaluate((XBooleanLiteral)expression, context, indicator); } else if (expression instanceof XCastedExpression) { return _doEvaluate((XCastedExpression)expression, context, indicator); } else if (expression instanceof XClosure) { return _doEvaluate((XClosure)expression, context, indicator); } else if (expression instanceof XConstructorCall) { return _doEvaluate((XConstructorCall)expression, context, indicator); } else if (expression instanceof XForLoopExpression) { return _doEvaluate((XForLoopExpression)expression, context, indicator); } else if (expression instanceof XBasicForLoopExpression) { return _doEvaluate((XBasicForLoopExpression)expression, context, indicator); } else if (expression instanceof XIfExpression) { return _doEvaluate((XIfExpression)expression, context, indicator); } else if (expression instanceof XInstanceOfExpression) { return _doEvaluate((XInstanceOfExpression)expression, context, indicator); } else if (expression instanceof XNullLiteral) { return _doEvaluate((XNullLiteral)expression, context, indicator); } else if (expression instanceof XNumberLiteral) { return _doEvaluate((XNumberLiteral)expression, context, indicator); } else if (expression instanceof XReturnExpression) { return _doEvaluate((XReturnExpression)expression, context, indicator); } else if (expression instanceof XStringLiteral) { return _doEvaluate((XStringLiteral)expression, context, indicator); } else if (expression instanceof XSwitchExpression) { return _doEvaluate((XSwitchExpression)expression, context, indicator); } else if (expression instanceof XThrowExpression) { return _doEvaluate((XThrowExpression)expression, context, indicator); } else if (expression instanceof XTryCatchFinallyExpression) { return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator); } else if (expression instanceof XTypeLiteral) { return _doEvaluate((XTypeLiteral)expression, context, indicator); } else if (expression instanceof XVariableDeclaration) { return _doEvaluate((XVariableDeclaration)expression, context, indicator); } else if (expression instanceof XListLiteral) { return _doEvaluate((XListLiteral)expression, context, indicator); } else if (expression instanceof XSetLiteral) { return _doEvaluate((XSetLiteral)expression, context, indicator); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression, context, indicator).toString()); } }
protected boolean _isConstant(final XStringLiteral expression) { return true; }
protected void _findImplicitReturns(final XStringLiteral expression, final ImplicitReturnFinder.Acceptor acceptor) { acceptor.accept(expression); }
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) { 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()); } }
protected EvaluationResult _internalEvaluate(final XStringLiteral it, final EvaluationContext context) { String _value = it.getValue(); return new EvaluationResult(_value, true); }
protected Object _internalEvaluate(final XStringLiteral it, final Context ctx) { return it.getValue(); }
@Test public void testAddition_2() throws Exception { XBinaryOperation operation = (XBinaryOperation) expression("foo + 'bar'"); assertEquals("foo", ((XFeatureCall) operation.getExplicitArguments().get(0)).getConcreteSyntaxFeatureName()); assertEquals("bar", ((XStringLiteral) operation.getExplicitArguments().get(1)).getValue()); }
@Test public void testStringLiteral() throws Exception { XStringLiteral literal = (XStringLiteral) expression("'bar'"); assertEquals("bar", literal.getValue()); }
@Test public void testClosure_1() throws Exception { XClosure closure = (XClosure) expression("[|'foo']"); assertEquals("foo", ((XStringLiteral) ((XBlockExpression)closure.getExpression()).getExpressions().get(0)) .getValue()); }
@Test public void testFeatureCall_2() throws Exception { XMemberFeatureCall call = (XMemberFeatureCall) expression("'holla'.bar()"); assertNotNull(call); assertEquals(1, call.getExplicitArguments().size()); assertTrue(call.getExplicitArguments().get(0) instanceof XStringLiteral); }
@Test public void testWhileExpression() throws Exception { XWhileExpression expression = (XWhileExpression) expression("while (true) 'foo'"); assertTrue(expression.getPredicate() instanceof XBooleanLiteral); assertTrue(expression.getBody() instanceof XStringLiteral); }