Search in sources :

Example 36 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.

the class UTF8ParserErrorTest method testInvalidReference_01.

@Test
public void testInvalidReference_01() throws Exception {
    XtendFunction func = function("def m() { \\u0020invalidStart }");
    XBlockExpression block = (XBlockExpression) func.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
    String featureName = featureCall.getConcreteSyntaxFeatureName();
    assertEquals("\\u0020invalidStart", featureName);
    assertTrue(featureCall.getFeature().eIsProxy());
    List<Diagnostic> errorList = func.eResource().getErrors();
    assertEquals(2, errorList.size());
    XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
    assertTrue(diagnostic.getMessage().contains("invalidStart"));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 37 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.

the class LinkingShadowingTest method getFeatureCall.

protected XAbstractFeatureCall getFeatureCall(XtendClass clazz, int expressionInFunction) {
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall result = (XAbstractFeatureCall) body.getExpressions().get(expressionInFunction);
    return result;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 38 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.

the class LinkingTest method testQualifiedSuperOuter.

@Test
public void testQualifiedSuperOuter() throws Exception {
    XtendFile file = file("class B<T> { def T m1() {} }\n" + "class C extends B<String> {\n" + "  def void m2() { new Object { def m3() { C.super.m1.subSequence(1, 1) } } }\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(1);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression outer = (XBlockExpression) m.getExpression();
    AnonymousClass anonymousClass = (AnonymousClass) outer.getExpressions().get(0);
    XtendFunction m3 = (XtendFunction) anonymousClass.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m3.getExpression();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("java.lang.String.subSequence(int,int)", feature.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 39 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.

the class LinkingTest method testOverloadedMethods_13.

@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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 40 with XBlockExpression

use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.

the class LinkingTest method testExtensionMethodCall_05.

@Test
public void testExtensionMethodCall_05() throws Exception {
    XtendClass clazz = clazz("" + "class C {" + "  def m() {\n" + "    ''.m\n" + "  }\n" + "  def void m(String... s) {" + "  }" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XMemberFeatureCall call = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    assertFalse(call.getFeature().getIdentifier(), call.getFeature().eIsProxy());
    assertEquals("C.m(java.lang.String[])", call.getFeature().getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Aggregations

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)229 Test (org.junit.Test)209 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)198 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)82 XExpression (org.eclipse.xtext.xbase.XExpression)80 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)67 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)58 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)54 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)29 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)8 JvmType (org.eclipse.xtext.common.types.JvmType)7