org.eclipse.xtext.xbase.XBlockExpression Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.XBlockExpression.
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: XtendSyntacticSequencer.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
/** * 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); }
Example #2
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOverloadedMethods_16() throws Exception { XtendFile file = file( "import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<? super T> collection, Iterable<T> elements) {\n" + " collection.addAll(elements.head)\n" + " }\n" + "}"); XtendClass clazz = (XtendClass) file.getXtendTypes().get(0); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0); JvmIdentifiableElement addAll = featureCall.getFeature(); assertNotNull(addAll); assertFalse(addAll.eIsProxy()); assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier()); }
Example #3
Source File: SARLOperationHelper.java From sarl with Apache License 2.0 | 6 votes |
/** 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(XBlockExpression expression, ISideEffectContext context) { final List<XExpression> exprs = expression.getExpressions(); if (exprs != null && !exprs.isEmpty()) { context.open(); try { for (final XExpression ex : exprs) { if (hasSideEffects(ex, context)) { return true; } } } finally { context.close(); } } return false; }
Example #4
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug403580_03() throws Exception { XtendFile file = file( "abstract class C {\n" + " def void m() {\n" + " overloaded [ String s | s ]\n" + " }\n" + " def void overloaded((String)=>String s)" + " def <T> void overloaded(Comparable<T> c)" + "}\n"); XtendClass c = (XtendClass) file.getXtendTypes().get(0); XtendFunction m = (XtendFunction) c.getMembers().get(0); XBlockExpression body = (XBlockExpression) m.getExpression(); XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0); JvmIdentifiableElement method = featureCall.getFeature(); assertEquals("C.overloaded(org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier()); }
Example #5
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testSugarOverTypeLiteral_02() throws Exception { XtendFile file = file( "import org.eclipse.emf.ecore.resource.Resource\n" + "import org.eclipse.emf.common.util.URI\n" + "class C {\n" + " def m(Resource Resource, URI unused) {\n" + " Resource.URI" + " }\n" + "}\n"); XtendClass c = (XtendClass) file.getXtendTypes().get(0); XtendFunction m = (XtendFunction) c.getMembers().get(0); XBlockExpression body = (XBlockExpression) m.getExpression(); XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0); JvmIdentifiableElement method = featureCall.getFeature(); assertEquals("org.eclipse.emf.ecore.resource.Resource.getURI()", method.getIdentifier()); }
Example #6
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOverloadedMethods_18() throws Exception { XtendFile file = file( "import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" + " collection.addAll(elements.head)\n" + " }\n" + "}"); XtendClass clazz = (XtendClass) file.getXtendTypes().get(0); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0); JvmIdentifiableElement addAll = featureCall.getFeature(); assertNotNull(addAll); assertFalse(addAll.eIsProxy()); assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier()); }
Example #7
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOverloadedMethods_19() throws Exception { XtendFile file = file( "import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<? super T> collection, Iterable<? extends T> elements) {\n" + " collection.<T>addAll(elements)\n" + " }\n" + "}"); XtendClass clazz = (XtendClass) file.getXtendTypes().get(0); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0); JvmIdentifiableElement addAll = featureCall.getFeature(); assertNotNull(addAll); assertFalse(addAll.eIsProxy()); assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier()); }
Example #8
Source File: TypeConvertingCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * 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; }
Example #9
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOverloadedMethods_07() throws Exception { XtendFile file = file( "import java.util.List\n" + "class X {\n" + " def foo() {\n" + " var List<String> strings = null\n" + " var testdata.OverloadedMethods<String> receiver = null\n" + " receiver.overloaded2(strings, strings)\n" + " }\n" + "}"); XtendClass clazz = (XtendClass) file.getXtendTypes().get(0); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded2(java.util.List,java.util.List)", overloaded.getIdentifier()); }
Example #10
Source File: TypeProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testExpectationRelevantExpressionType_03() throws Exception { String clazzString = "class C {\n" + " def m() {\n" + " typeof(C).getMethod('', newArrayList)\n" + " }\n" + "}"; XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0); XtendFunction function = (XtendFunction) clazz.getMembers().get(0); XBlockExpression body = (XBlockExpression) function.getExpression(); XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0); XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1); assertEquals("newArrayList", newArrayList.getFeature().getSimpleName()); assertEquals("Class<?>[]", getExpectedType(newArrayList).getSimpleName()); assertEquals("ArrayList<Class<?>>", getType(newArrayList).getSimpleName()); }
Example #11
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOverloadedMethods_13() throws Exception { XtendFile file = file( "import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<? super T> collection, Iterable<T> elements) {\n" + " collection.addAll(elements)\n" + " }\n" + "}"); XtendClass clazz = (XtendClass) file.getXtendTypes().get(0); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0); JvmIdentifiableElement addAll = featureCall.getFeature(); assertNotNull(addAll); assertFalse(addAll.eIsProxy()); assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,java.lang.Iterable)", addAll.getIdentifier()); }
Example #12
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOverloadedMethods_09() throws Exception { XtendFile file = file( "import java.util.List\n" + "class X {\n" + " def foo() {\n" + " var List<? extends CharSequence> chars = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded2(chars, chars)\n" + " }\n" + "}"); XtendClass clazz = (XtendClass) file.getXtendTypes().get(0); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded2(java.lang.Iterable,java.lang.Iterable)", overloaded.getIdentifier()); }
Example #13
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug345433_02() throws Exception { String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e0 | " + " !e0.isAssigned() && !e0.isEObjectRuleCall()" + " ).map(e1 | e1.rule)\n" + " }\n" + "}"; XtendClass clazz = clazz(classAsString); IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator(); List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl); assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty()); XtendFunction function = (XtendFunction) clazz.getMembers().get(1); XExpression body = function.getExpression(); LightweightTypeReference bodyType = getType(body); assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier()); XBlockExpression block = (XBlockExpression) body; XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); JvmFormalParameter e1 = closure.getFormalParameters().get(0); assertEquals("e1", e1.getSimpleName()); assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier()); }
Example #14
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testImplicitFirstArgument_07() throws Exception { XtendClass clazz = clazz( "import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " withCharSequence\n" + " }\n" + "}"); XtendFunction func= (XtendFunction) clazz.getMembers().get(0); XFeatureCall seventh = (XFeatureCall) ((XBlockExpression)func.getExpression()).getExpressions().get(0); JvmOperation seventhFeature = (JvmOperation) seventh.getFeature(); assertEquals("test.ImplicitFirstArgumentStatics.withCharSequence(java.lang.CharSequence)", seventhFeature.getIdentifier()); // static methods don't have receiver but an implicit argument assertNotNull(seventh.getImplicitFirstArgument()); assertNull(seventh.getImplicitReceiver()); assertNull(seventh.getInvalidFeatureIssueCode(), seventh.getInvalidFeatureIssueCode()); assertEquals("it", ((XAbstractFeatureCall) seventh.getImplicitFirstArgument()).getFeature().getSimpleName()); }
Example #15
Source File: TypeProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testExpectationRelevantExpressionType_06() throws Exception { String clazzString = "class C<T> {\n" + " def String m(String s, Class<? extends T>[] types) {\n" + " this.m('', newArrayList)\n" + " }\n" + "}"; XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0); XtendFunction function = (XtendFunction) clazz.getMembers().get(0); XBlockExpression body = (XBlockExpression) function.getExpression(); XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0); XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1); assertEquals("newArrayList", newArrayList.getFeature().getSimpleName()); assertEquals("Class<? extends T>[]", getExpectedType(newArrayList).getSimpleName()); assertEquals("ArrayList<Class<? extends T>>", getType(newArrayList).getSimpleName()); }
Example #16
Source File: XtendHoverSignatureProviderTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Ignore @Test public void testSignatureDelegateConstructorCall_02() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package testPackage"); _builder.newLine(); _builder.append("class Foo<S extends CharSequence> {"); _builder.newLine(); _builder.append("\t"); _builder.append("new(int i) {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("this(StringBuilder)"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); _builder.append("new<X>(Class<X> c) {}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet()); final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)); XtendMember _get = clazz.getMembers().get(0); final XtendConstructor xtendConstructor = ((XtendConstructor) _get); XExpression _expression = xtendConstructor.getExpression(); XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0); final XFeatureCall featureCall = ((XFeatureCall) _get_1); final String signature = this.signatureProvider.getSignature(featureCall); Assert.assertEquals("Foo<S>()", signature); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #17
Source File: ParserTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testParser() throws Exception { XBlockExpression expression = parseHelper.parse( "val x = 'hello' " + "val y = 'world!' " + "println(x+' '+y)").getBlock(); assertEquals(3, expression.getExpressions().size()); }
Example #18
Source File: AssignmentFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected AssignmentFeatureCallArguments toArguments(final String type, final String expression) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def void m("); _builder.append(type); _builder.append(") {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(expression, "\t"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); final String functionString = _builder.toString(); final XtendFunction function = this.function(functionString); XExpression _expression = function.getExpression(); final XBlockExpression body = ((XBlockExpression) _expression); final XExpression value = IterableExtensions.<XExpression>head(body.getExpressions()); JvmFormalParameter _head = IterableExtensions.<JvmFormalParameter>head(this._iXtendJvmAssociations.getDirectlyInferredOperation(function).getParameters()); JvmTypeReference _parameterType = null; if (_head!=null) { _parameterType=_head.getParameterType(); } final JvmTypeReference declaredType = _parameterType; if ((declaredType != null)) { LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(declaredType); return new AssignmentFeatureCallArguments(value, _lightweightTypeReference); } else { return new AssignmentFeatureCallArguments(value, null); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #19
Source File: StandardFeatureCallArgumentsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def void m("); _builder.append(signature); _builder.append(") {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("m("); _builder.append(invocation, "\t"); _builder.append(")"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); final String functionString = _builder.toString(); final XtendFunction function = this.function(functionString); XExpression _expression = function.getExpression(); final XBlockExpression body = ((XBlockExpression) _expression); XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions()); final XFeatureCall featureCall = ((XFeatureCall) _head); final EList<XExpression> arguments = featureCall.getFeatureCallArguments(); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); final IFeatureCallArguments result = this.factory.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner()); Class<? extends IFeatureCallArguments> _class = result.getClass(); boolean _equals = Objects.equal(_class, StandardFeatureCallArguments.class); Assert.assertTrue(_equals); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #20
Source File: FindReferencesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testFindReferencesTypeLiteral() throws Exception { XtendClass classFoo = (XtendClass) testHelper.xtendFile("Foo", "class Foo { def foo() { Foo } }").getXtendTypes().get(0); waitForBuild(); JvmGenericType inferredType = associations.getInferredType(classFoo); XtendFunction functionFoo = (XtendFunction) classFoo.getMembers().get(0); final MockAcceptor mockAcceptor = new MockAcceptor(); mockAcceptor.expect(((XBlockExpression) functionFoo.getExpression()).getExpressions().get(0), inferredType, XABSTRACT_FEATURE_CALL__FEATURE); findReferencesTester.checkFindReferences(inferredType, "Java References to Foo (/test.project/src/Foo.xtend)", mockAcceptor); }
Example #21
Source File: XtendUnsugaredHoverTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug380361() throws Exception { StringConcatenation _builder = new StringConcatenation(); _builder.append("package testpackage"); _builder.newLine(); _builder.append("import static extension testpackage.Extension.*"); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("def foo() { 42 }"); _builder.newLine(); _builder.append("\t"); _builder.append("def client() {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("foo //hover shows \'foo()\'"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile xtendFile = this.testHelper.xtendFile(XtendUnsugaredHoverTest.FILEPATH, _builder.toString()); IResourcesSetupUtil.waitForBuild(); XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(1); final XtendFunction function = ((XtendFunction) _get); XExpression _expression = function.getExpression(); final XBlockExpression block = ((XBlockExpression) _expression); final XExpression call = block.getExpressions().get(0); Assert.assertEquals("this.foo()", this.serializer.computeUnsugaredExpression(call)); }
Example #22
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testBinaryOperation_11() throws Exception { XBlockExpression block = (XBlockExpression) expression("{\n" + " val java.util.List list = null" + " list += null as Iterable<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()); }
Example #23
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testRecursiveClosure() throws Exception { XBlockExpression block = (XBlockExpression) expression("{ val (int)=>int fun = [ fun.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(); assertSame(variable, recursive.getFeature()); }
Example #24
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testOverloadedMethods_04() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? extends Object> objects = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded(objects, objects)\n" + "}"); XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(2); JvmIdentifiableElement overloaded = featureCall.getFeature(); assertNotNull(overloaded); assertFalse(overloaded.eIsProxy()); assertEquals("testdata.OverloadedMethods.overloaded(java.lang.Iterable,java.lang.Iterable)", overloaded.getIdentifier()); }
Example #25
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testExtensionMethodCall_08() throws Exception { XtendClass clazz = clazz("" + "class C {" + " def m() {\n" + " (null as String[]).m\n" + " }\n" + " def void m(String... s) {}\n" + " def void m(String s) {}\n" + "}"); XtendFunction func = (XtendFunction) clazz.getMembers().get(0); XMemberFeatureCall call = (XMemberFeatureCall)((XBlockExpression)func.getExpression()).getExpressions().get(0); assertFalse(call.getFeature().eIsProxy()); assertEquals("C.m(java.lang.String[])", call.getFeature().getIdentifier()); }
Example #26
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testOverloadedConstructors_07() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " var java.util.List<? extends Object> objects = null\n" + " new testdata.OverloadedMethods<Object>(objects, objects)\n" + "}"); XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1); JvmConstructor constructor = constructorCall.getConstructor(); assertNotNull(constructor); assertFalse(constructor.eIsProxy()); assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier()); }
Example #27
Source File: ErrorSafeExtensionsTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAppendForEachSafely_4() throws Exception { XBlockExpression e = (XBlockExpression) validatedExpression("{ error1 error2 }"); TreeAppendable app = createTreeAppendable(e); Assert.assertTrue(errorSafeExtensions.hasErrors(e.getExpressions().get(0))); Assert.assertTrue(errorSafeExtensions.hasErrors(e.getExpressions().get(1))); errorSafeExtensions.forEachSafely(app, e.getExpressions(), getLoopInitializer(), (XExpression it, ITreeAppendable app2) -> { app2.append(getText(it)); }); Assert.assertEquals("/* (error1:error2) */", app.getContent()); }
Example #28
Source File: XtendUnsugaredHoverTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnsuagaredVersionForXtendFunction() throws Exception { StringConcatenation _builder = new StringConcatenation(); _builder.append("package testpackage"); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("extension Extension"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("def baz(Integer it){"); _builder.newLine(); _builder.append("\t\t"); _builder.append("bar(42)\t"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile xtendFile = this.testHelper.xtendFile(XtendUnsugaredHoverTest.FILEPATH, _builder.toString()); IResourcesSetupUtil.waitForBuild(); XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(1); final XtendFunction function = ((XtendFunction) _get); XExpression _expression = function.getExpression(); final XBlockExpression block = ((XBlockExpression) _expression); final XExpression call = block.getExpressions().get(0); Assert.assertEquals("this._extension.bar(it, 42)", this.serializer.computeUnsugaredExpression(call)); }
Example #29
Source File: AnonymousClassTypeTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testOverriddenMethodTypeArgumentInference_2() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def <T> foo() {"); _builder.newLine(); _builder.append("\t"); _builder.append("new Iterable<T>() {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("override iterator() {}"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFunction function = this.function(_builder.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource()); Assert.assertEquals("Iterable<T>", resolvedTypes.getActualType(operation).toString()); XExpression _expression = function.getExpression(); XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions()); final AnonymousClass anonymousClass = ((AnonymousClass) _head); XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers()); final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last)); Assert.assertEquals("Iterator<T>", resolvedTypes.getActualType(overriding).toString()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #30
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testShadowing_1() throws Exception { XBlockExpression bop = (XBlockExpression) expression( "{ " + " val this = new java.util.List<String>(); " + " val size = 23;" + " size;" + "}", false); final JvmIdentifiableElement feature = ((XFeatureCall)bop.getExpressions().get(2)).getFeature(); assertTrue(feature.getClass().getName(), feature instanceof XVariableDeclaration); XConstructorCall xConstructorCall = (XConstructorCall)((XVariableDeclaration)bop.getExpressions().get(0)).getRight(); assertTrue(xConstructorCall.getConstructor().eIsProxy()); }