@Check public void checkDelegateConstructorIsFirst(XFeatureCall featureCall) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) { JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(featureCall); if (container != null) { if (container instanceof JvmConstructor) { XExpression body = logicalContainerProvider.getAssociatedExpression(container); if (body == featureCall) return; if (body instanceof XBlockExpression) { List<XExpression> expressions = ((XBlockExpression) body).getExpressions(); if (expressions.isEmpty() || expressions.get(0) != featureCall) { error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION); } } } else { error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION); } } } }
@Check public void checkNoJavaStyleTypeCasting(XBlockExpression blockExpression) { if(isIgnored(JAVA_STYLE_TYPE_CAST)) { return; } if (blockExpression.getExpressions().size() <= 1) { return; } ICompositeNode node = NodeModelUtils.getNode(blockExpression); if (node == null) { return; } INode expressionNode = null; for (INode child : node.getChildren()) { if (isSemicolon(child)) { expressionNode = null; } else if (isXExpressionInsideBlock(child)) { if (expressionNode != null) { checkNoJavaStyleTypeCasting(expressionNode); } expressionNode = child; } } }
/** * Syntax: '('* */ @Override protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) { Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0(); if (nodes == null) { if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) { EObject cnt = semanticObject.eContainer(); if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression) && !(cnt instanceof XForLoopExpression)) acceptUnassignedKeyword(kw, kw.getValue(), null); } if (semanticObject instanceof XConstructorCall) { XConstructorCall call = (XConstructorCall) semanticObject; if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) { acceptUnassignedKeyword(kw, kw.getValue(), null); } } } acceptNodes(transition, nodes); }
/** * On Java-level the any-type is represented as java.lang.Object as there is no subtype of everything (i.e. type for null). * So, when the values are used we need to manually cast them to whatever is expected. * * This method tells us whether such a cast is needed. */ private boolean isToBeCastedAnyType(LightweightTypeReference actualType, XExpression obj, ITreeAppendable appendable) { if (actualType instanceof AnyTypeReference) { if (getReferenceName(obj, appendable) != null) return true; else if (obj instanceof XBlockExpression) { XBlockExpression blockExpression = (XBlockExpression) obj; EList<XExpression> expressions = blockExpression.getExpressions(); if (expressions.isEmpty()) return false; if (expressions.size() > 1) return true; XExpression last = expressions.get(0); return isToBeCastedAnyType(actualType, last, appendable); } } return false; }
@Test public void testXVariableDeclarationCall() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("val foo = 1"); _builder.newLine(); _builder.append("\t"); _builder.append("val bar = foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); XExpression _expression = this.expression(_builder); final XBlockExpression blockExpression = ((XBlockExpression) _expression); XExpression _get = blockExpression.getExpressions().get(1); final XVariableDeclaration variableDeclaration = ((XVariableDeclaration) _get); this.evaluatesTo(variableDeclaration, Integer.valueOf(1)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected void compileWithJvmConstructorCall(XBlockExpression obj, ITreeAppendable apendable) { EList<XExpression> expressions = obj.getExpressions(); internalToJavaStatement(expressions.get(0), apendable.trace(obj, false), false); if (expressions.size() == 1) { return; } apendable.newLine().append("try {").increaseIndentation(); ITreeAppendable b = apendable.trace(obj, false); for (int i = 1; i < expressions.size(); i++) { XExpression ex = expressions.get(i); internalToJavaStatement(ex, b, false); } generateCheckedExceptionHandling(apendable); }
/** * checks whether the given lambda should be formatted as a block. * That includes newlines after and before the brackets, and a fresh line for each expression. */ protected boolean isMultilineLambda(final XClosure closure) { final ILeafNode closingBracket = this._nodeModelAccess.nodeForKeyword(closure, "]"); HiddenLeafs _hiddenLeafsBefore = null; if (closingBracket!=null) { _hiddenLeafsBefore=this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket); } boolean _tripleNotEquals = (_hiddenLeafsBefore != null); if (_tripleNotEquals) { int _newLines = this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket).getNewLines(); return (_newLines > 0); } boolean _switchResult = false; XExpression _expression = closure.getExpression(); final XExpression block = _expression; boolean _matched = false; if (block instanceof XBlockExpression) { _matched=true; _switchResult = ((((XBlockExpression)block).getExpressions().size() > 1) && this.isEachExpressionInOwnLine(((XBlockExpression)block).getExpressions())); } if (!_matched) { _switchResult = false; } return _switchResult; }
@Test public void testReassignedType_01() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{ var it = new Object() if (it instanceof String) {} }"); XExpression _expression = this.expression(_builder, false); XExpression _last = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions()); final XIfExpression ifExpr = ((XIfExpression) _last); XExpression _then = ifExpr.getThen(); final XBlockExpression block = ((XBlockExpression) _then); final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(block).getExpressionScope(block, IExpressionScope.Anchor.BEFORE); this.contains(expressionScope, "charAt"); this.contains(expressionScope, "it"); this.contains(expressionScope, "operator_lessThan"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * {@inheritDoc} */ @Override public boolean createEObjectDescriptions(final EObject eObject, final IAcceptor<IEObjectDescription> acceptor) { if (eObject instanceof XBlockExpression || isXbaseLocalVariableName(eObject)) { return false; } boolean indexObject = false; boolean indexDefault = false; String objectFingerprint = null; if (fingerprintComputer != null && eObject.eContainer() instanceof FormatConfiguration && NodeModelUtils.getNode(eObject) != null) { objectFingerprint = fingerprintComputer.computeFingerprint(eObject); } if (objectFingerprint != null && !"".equals(objectFingerprint) && eObject.eContainer() instanceof FormatConfiguration) { acceptor.accept(EObjectDescription.create(objectFingerprint, eObject)); indexObject = true; } indexDefault = createDescriptionsForNonXbaseFormalParameters(eObject, acceptor); return indexDefault || indexObject; }
@Test public void testReassignedType_02() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{ var it = new Object() if (it instanceof String) { it = new Object() } }"); XExpression _expression = this.expression(_builder, false); XExpression _last = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions()); final XIfExpression ifExpr = ((XIfExpression) _last); XExpression _then = ifExpr.getThen(); final XBlockExpression block = ((XBlockExpression) _then); final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(block).getExpressionScope(block, IExpressionScope.Anchor.BEFORE); this.contains(expressionScope, "charAt"); this.contains(expressionScope, "it"); this.contains(expressionScope, "operator_lessThan"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testMemberOnIt_05() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{ var (int)=>int it = null }"); XExpression _expression = this.expression(_builder, false); XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions()); final XExpression varInit = ((XVariableDeclaration) _head).getRight(); final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(varInit).getExpressionScope(varInit, IExpressionScope.Anchor.BEFORE); this.containsNot(expressionScope, "it"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testFeatureCall_2() throws Exception { XBlockExpression block = (XBlockExpression) expression("{" + " val this = new testdata.FieldAccessSub();" + " privateField;" + " privateField();" + "}"); XFeatureCall call1 = (XFeatureCall) block.getExpressions().get(1); XFeatureCall call2 = (XFeatureCall) block.getExpressions().get(2); assertEquals("testdata.FieldAccessSub.privateField()",((JvmOperation)call1.getFeature()).getIdentifier()); assertSame(call1.getFeature(), call2.getFeature()); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetBlock(XBlockExpression newBlock, NotificationChain msgs) { XBlockExpression oldBlock = block; block = newBlock; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, PureXbasePackage.MODEL__BLOCK, oldBlock, newBlock); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; }
@Test public void testSynchronized() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("synchronized (this) {1}"); XExpression _expression = this.expression(_builder); final XSynchronizedExpression block = ((XSynchronizedExpression) _expression); XExpression _expression_1 = block.getExpression(); this.hasImplicitReturns(block, IterableExtensions.<XExpression>head(((XBlockExpression) _expression_1).getExpressions())); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case PureXbasePackage.MODEL__IMPORT_SECTION: setImportSection((XImportSection)newValue); return; case PureXbasePackage.MODEL__BLOCK: setBlock((XBlockExpression)newValue); return; } super.eSet(featureID, newValue); }
@Test public void testAppendForEachSafely_3() { XExpression _validatedExpression = this.validatedExpression("{ error }"); final XBlockExpression e = ((XBlockExpression) _validatedExpression); final TreeAppendable app = this.createTreeAppendable(e); Assert.assertTrue(this._errorSafeExtensions.hasErrors(e.getExpressions().get(0))); final Procedure2<XExpression, ITreeAppendable> _function = (XExpression it, ITreeAppendable app2) -> { app2.append(this.getText(it)); }; this._errorSafeExtensions.<XExpression>forEachSafely(app, e.getExpressions(), this.getLoopInitializer(), _function); Assert.assertEquals("/* (error) */", app.getContent()); }
@Test public void testLocalVarAssignment_1() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ var x = ''; x = '' }"); XAssignment assignment = (XAssignment) block.getExpressions().get(1); assertNull(assignment.getAssignable()); assertTrue(String.valueOf(assignment.getFeature()), assignment.getFeature() instanceof XVariableDeclaration); assertSame(block.getExpressions().get(0), assignment.getFeature()); }
@Test public void testOverloadedMethods_03() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<String> strings = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded(strings, strings)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded(java.util.List,java.util.List)", overloaded.getIdentifier()); }
@Test public void testShadowing_4() throws Exception { XBlockExpression bop = (XBlockExpression) expression( "{" + " val size = 23;" + " {" + " val this = new java.util.ArrayList<String>(); " + " size();" + " };" + "}"); XBlockExpression innerBlock = (XBlockExpression)bop.getExpressions().get(1); assertEquals("java.util.ArrayList.size()",((XFeatureCall)innerBlock.getExpressions().get(1)).getFeature().getIdentifier()); }
@Check public void checkDeadCode(XBlockExpression block) { List<XExpression> expressions = block.getExpressions(); for(int i = 0, size = expressions.size(); i < size - 1; i++) { XExpression expression = expressions.get(i); if (earlyExitComputer.isEarlyExit(expression)) { if (!(expression instanceof XAbstractFeatureCall)) { // XAbstractFeatureCall does already a decent job for its argument lists // no additional error necessary markAsDeadCode(expressions.get(i + 1)); } return; } } }
@Test public void testAppendForEachSafely_4() { XExpression _validatedExpression = this.validatedExpression("{ error1 error2 }"); final XBlockExpression e = ((XBlockExpression) _validatedExpression); final TreeAppendable app = this.createTreeAppendable(e); Assert.assertTrue(this._errorSafeExtensions.hasErrors(e.getExpressions().get(0))); Assert.assertTrue(this._errorSafeExtensions.hasErrors(e.getExpressions().get(1))); final Procedure2<XExpression, ITreeAppendable> _function = (XExpression it, ITreeAppendable app2) -> { app2.append(this.getText(it)); }; this._errorSafeExtensions.<XExpression>forEachSafely(app, e.getExpressions(), this.getLoopInitializer(), _function); Assert.assertEquals("/* (error1:error2) */", app.getContent()); }
@Test public void testShadowing_6() throws Exception { XBlockExpression bop = (XBlockExpression) expression( "{" + " val size = 23;" + " [String x|size];" + "}"); XClosure closure = (XClosure)bop.getExpressions().get(1); assertSame(bop.getExpressions().get(0), ((XFeatureCall)((XBlockExpression)closure.getExpression()).getExpressions().get(0)).getFeature()); }
@Test public void testOverloadedMethods_09() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? extends Object> objects = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded2(objects, objects)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded2(java.lang.Iterable,java.lang.Iterable)", overloaded.getIdentifier()); }
@Test public void testParameterizedInnerTypes_01() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ val nested.ParameterizedInnerTypes<String>.Inner x = null }", true); XVariableDeclaration variableDecl = (XVariableDeclaration) block.getExpressions().get(0); JvmType type = variableDecl.getType().getType(); assertEquals("nested.ParameterizedInnerTypes$Inner", type.getIdentifier()); assertEquals("nested.ParameterizedInnerTypes<java.lang.String>$Inner", variableDecl.getType().getIdentifier()); }
@Override protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) { if (obj instanceof XBlockExpression) { _toJavaExpression((XBlockExpression) obj, appendable); } else if (obj instanceof XCastedExpression) { _toJavaExpression((XCastedExpression) obj, appendable); } else if (obj instanceof XClosure) { _toJavaExpression((XClosure) obj, appendable); } else if (obj instanceof XAnnotation) { _toJavaExpression((XAnnotation) obj, appendable); } else if (obj instanceof XConstructorCall) { _toJavaExpression((XConstructorCall) obj, appendable); } else if (obj instanceof XIfExpression) { _toJavaExpression((XIfExpression) obj, appendable); } else if (obj instanceof XInstanceOfExpression) { _toJavaExpression((XInstanceOfExpression) obj, appendable); } else if (obj instanceof XSwitchExpression) { _toJavaExpression((XSwitchExpression) obj, appendable); } else if (obj instanceof XTryCatchFinallyExpression) { _toJavaExpression((XTryCatchFinallyExpression) obj, appendable); } else if (obj instanceof XListLiteral) { _toJavaExpression((XListLiteral) obj, appendable); } else if (obj instanceof XSetLiteral) { _toJavaExpression((XSetLiteral) obj, appendable); } else if (obj instanceof XSynchronizedExpression) { _toJavaExpression((XSynchronizedExpression) obj, appendable); } else if (obj instanceof XReturnExpression) { _toJavaExpression((XReturnExpression) obj, appendable); } else if (obj instanceof XThrowExpression) { _toJavaExpression((XThrowExpression) obj, appendable); } else { super.internalToConvertedExpression(obj, appendable); } }
@Test public void testGetExpressionScope_03() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{ var x = 1 }"); XExpression _expression = this.expression(_builder, false); final XExpression varDecl = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions()); final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl, IExpressionScope.Anchor.AFTER); this.contains(expressionScope, "x"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected void _toJavaStatement(XBlockExpression expr, ITreeAppendable b, boolean isReferenced) { b = b.trace(expr, false); if (expr.getExpressions().isEmpty()) return; if (expr.getExpressions().size()==1) { internalToJavaStatement(expr.getExpressions().get(0), b, isReferenced); return; } if (isReferenced) declareSyntheticVariable(expr, b); boolean needsBraces = isReferenced || !bracesAreAddedByOuterStructure(expr); if (needsBraces) { b.newLine().append("{").increaseIndentation(); b.openPseudoScope(); } final EList<XExpression> expressions = expr.getExpressions(); for (int i = 0; i < expressions.size(); i++) { XExpression ex = expressions.get(i); if (i < expressions.size() - 1) { internalToJavaStatement(ex, b, false); } else { internalToJavaStatement(ex, b, isReferenced); if (isReferenced) { b.newLine().append(getVarName(expr, b)).append(" = "); internalToConvertedExpression(ex, b, getLightweightType(expr)); b.append(";"); } } } if (needsBraces) { b.closeScope(); b.decreaseIndentation().newLine().append("}"); } }
@Test public void testGetExpressionScope_04() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{ var x = 1 }"); XExpression _expression = this.expression(_builder, false); final XExpression varDecl = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions()); final IExpressionScope expressionScope = this._iBatchTypeResolver.resolveTypes(varDecl).getExpressionScope(varDecl, IExpressionScope.Anchor.BEFORE); this.containsNot(expressionScope, "x"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testImplicitReceiver() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("val it = \'\'"); _builder.newLine(); _builder.append("\t"); _builder.append("toString"); _builder.newLine(); _builder.append("}"); _builder.newLine(); XExpression _parse = this._parseHelper.parse(_builder); final XBlockExpression block = ((XBlockExpression) _parse); Resource _eResource = block.eResource(); final BatchLinkableResource resource = ((BatchLinkableResource) _eResource); XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions()); final XFeatureCall toString = ((XFeatureCall) _last); XExpression _implicitReceiver = toString.getImplicitReceiver(); final XFeatureCall implicitReceiver = ((XFeatureCall) _implicitReceiver); Assert.assertEquals("it", implicitReceiver.getFeature().getSimpleName()); resource.update(0, 0, ""); Assert.assertNull(this._reflectExtensions.<Object>get(toString, "implicitReceiver")); Assert.assertNotNull(toString.getImplicitReceiver()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testOverloadedMethods_07() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<CharSequence> chars = null\n" + " var java.util.List<String> strings = null\n" + " var testdata.OverloadedMethods<CharSequence> receiver = null\n" + " receiver.overloaded2(strings, chars)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(3); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded2(java.lang.Iterable,java.util.Collection)", overloaded.getIdentifier()); }
@Test public void testBlock01() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{1}"); XExpression _expression = this.expression(_builder); final XBlockExpression block = ((XBlockExpression) _expression); this.hasImplicitReturns(block, IterableExtensions.<XExpression>head(block.getExpressions())); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testOverloadedConstructors_04() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<CharSequence> chars = null\n" + " new testdata.OverloadedMethods<CharSequence>(chars, chars)\n" + "}"); XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1); JvmConstructor constructor = constructorCall.getConstructor(); assertNotNull(constructor); assertFalse(constructor.eIsProxy()); assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.util.List,java.util.List)", constructor.getIdentifier()); }
@Test public void testBinaryOperation_9() throws Exception { XBlockExpression block = (XBlockExpression) expression("{\n" + " val java.util.List<CharSequence> list = null" + " list += null as Iterable<? extends CharSequence>" + "}", true); XBinaryOperation operation = (XBinaryOperation) block.getExpressions().get(1); assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.operator_add(java.util.Collection,java.lang.Iterable)", operation.getFeature().getIdentifier()); }
@Test public void testFeatureCall_3() throws Exception { XBlockExpression block = (XBlockExpression) expression("{" + " val this = new testdata.MethodOverrides1();" + " m1('String');" + " m1('CharSequence' as CharSequence);" + "}"); XFeatureCall call1 = (XFeatureCall) block.getExpressions().get(1); XFeatureCall call2 = (XFeatureCall) block.getExpressions().get(2); assertEquals("testdata.MethodOverrides1.m1(java.lang.String)",((JvmOperation)call1.getFeature()).getIdentifier()); assertEquals("testdata.MethodOverrides1.m1(java.lang.CharSequence)",((JvmOperation)call2.getFeature()).getIdentifier()); }
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XBlockExpression expression) { EList<XExpression> _expressions = expression.getExpressions(); for (final XExpression child : _expressions) { { Collection<IEarlyExitComputer.ExitPoint> exitPoints = this.getExitPoints(child); boolean _isNotEmpty = this.isNotEmpty(exitPoints); if (_isNotEmpty) { return exitPoints; } } } return Collections.<IEarlyExitComputer.ExitPoint>emptyList(); }
@Test public void testFeatureCall_1() throws Exception { XBlockExpression block = (XBlockExpression) expression("{" + " val this = new testdata.FieldAccessSub();" + " stringField;" + " stringField();" + "}"); XFeatureCall call1 = (XFeatureCall) block.getExpressions().get(1); XFeatureCall call2 = (XFeatureCall) block.getExpressions().get(2); assertEquals("testdata.FieldAccessSub.stringField",call1.getFeature().getIdentifier()); assertEquals("testdata.FieldAccessSub.stringField()",((JvmOperation)call2.getFeature()).getIdentifier()); }
@Test public void testAppendForEachSafely_0() { XExpression _validatedExpression = this.validatedExpression("{ error val x=42 val y=42 }"); final XBlockExpression e = ((XBlockExpression) _validatedExpression); final TreeAppendable app = this.createTreeAppendable(e); Assert.assertTrue(this._errorSafeExtensions.hasErrors(e.getExpressions().get(0))); Assert.assertFalse(this._errorSafeExtensions.hasErrors(e.getExpressions().get(1))); Assert.assertFalse(this._errorSafeExtensions.hasErrors(e.getExpressions().get(2))); final Procedure2<XExpression, ITreeAppendable> _function = (XExpression it, ITreeAppendable app2) -> { app2.append(this.getText(it)); }; this._errorSafeExtensions.<XExpression>forEachSafely(app, e.getExpressions(), this.getLoopInitializer(), _function); Assert.assertEquals("(/* error */val x=42:val y=42)", app.getContent()); }
@Test public void testRecursiveClosure_02() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ val (int)=>int fun = [ self.apply(it) ] }"); XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0); XClosure closure = (XClosure) variable.getRight(); XBlockExpression body = (XBlockExpression) closure.getExpression(); XMemberFeatureCall member = (XMemberFeatureCall) body.getExpressions().get(0); XFeatureCall recursive = (XFeatureCall) member.getMemberCallTarget(); assertEquals(Functions.Function1.class.getName(), recursive.getFeature().getQualifiedName('$')); }
@Test public void testClosure_03() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? super String> list = null;\n" + " list.map(e|e)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(1); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); LightweightTypeReference typeRef = getType(closure); assertEquals("(java.lang.Object)=>java.lang.Object", toString(typeRef)); }
@Test public void testOverloadedConstructors_05() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<String> strings = null\n" + " new testdata.OverloadedMethods<String>(strings, strings)\n" + "}"); XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1); JvmConstructor constructor = constructorCall.getConstructor(); assertNotNull(constructor); assertFalse(constructor.eIsProxy()); assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.util.List,java.util.List)", constructor.getIdentifier()); }