Search in sources :

Example 46 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class LinkingTest method testOverloadedMethods_14.

@Test
public void testOverloadedMethods_14() 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.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 47 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class LinkingTest method testExplicitTypeOverSugar_02.

@Test
public void testExplicitTypeOverSugar_02() throws Exception {
    XtendFile file = file("import static extension org.eclipse.emf.ecore.util.EcoreUtil.*\n" + "import org.eclipse.emf.ecore.EObject\n" + "import org.eclipse.emf.common.util.URI\n" + "\n" + "class C {\n" + "  def m(EObject it) {\n" + "    URI.appendFragment(\"someString\")\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.common.util.URI.appendFragment(java.lang.String)", method.getIdentifier());
    assertFalse(featureCall.isStaticWithDeclaringType());
    XFeatureCall target = (XFeatureCall) featureCall.getMemberCallTarget();
    assertFalse(target.isTypeLiteral());
    assertEquals("org.eclipse.emf.ecore.util.EcoreUtil.getURI(org.eclipse.emf.ecore.EObject)", target.getFeature().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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 48 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class LinkingTest method testBug426788.

@Test
public void testBug426788() throws Exception {
    XtendFile file = file("class Bug {\n" + "  def <T extends Object> void m(T t) {}\n" + "  def void m(CharSequence t) {}\n" + "  def void n(Iterable<String> it) {\n" + "    m(it.head)           \n" + "    m(it.iterator.next)  \n" + "    m(\"\")              \n" + "  }\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction n = (XtendFunction) c.getMembers().get(2);
    XBlockExpression body = (XBlockExpression) n.getExpression();
    for (XExpression featureCall : body.getExpressions()) {
        XFeatureCall casted = (XFeatureCall) featureCall;
        JvmIdentifiableElement method = casted.getFeature();
        assertEquals("Bug.m(java.lang.CharSequence)", method.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) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 49 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class LinkingTest method testBug464264_01.

@Test
public void testBug464264_01() throws Exception {
    XtendFile file = file("import java.util.List\n" + "class C {\n" + "	def m(I i, List<CharSequence> list) {\n" + "		i.strings += list.map[it]\n" + "	}\n" + "	interface I {\n" + "		def List<String> getStrings()\n" + "	}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XBinaryOperation featureCall = (XBinaryOperation) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.operator_add(java.util.Collection,java.lang.Iterable)", feature.getIdentifier());
    assertNull(featureCall.getImplicitReceiver());
    assertNull(featureCall.getImplicitFirstArgument());
    List<Diagnostic> errors = c.eResource().getErrors();
    assertEquals(1, errors.size());
    assertEquals("Type mismatch: cannot convert from List<CharSequence> to Iterable<? extends String>", errors.get(0).getMessage());
}
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) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) Test(org.junit.Test)

Example 50 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class Bug409780Test method testConstraintsInfluenceFeatureScope_02.

@Test
public void testConstraintsInfluenceFeatureScope_02() throws Exception {
    XtendFile file = file("class C {\n" + "	def private a(Iterable<CharSequence> it) {\n" + "		map[ b.append('') ]\n" + "	}\n" + "	def private <T extends Appendable> T b(CharSequence 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("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
    assertTrue(featureCall.isStatic());
    assertTrue(featureCall.isExtension());
    assertFalse(featureCall.isTypeLiteral());
    LightweightTypeReference type = getType(featureCall);
    assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Aggregations

JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)112 Test (org.junit.Test)65 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)60 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)58 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)27 EObject (org.eclipse.emf.ecore.EObject)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)13 XExpression (org.eclipse.xtext.xbase.XExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 IJavaElement (org.eclipse.jdt.core.IJavaElement)10 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)8 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)6 JvmType (org.eclipse.xtext.common.types.JvmType)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 XtendField (org.eclipse.xtend.core.xtend.XtendField)5 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)5 JvmMember (org.eclipse.xtext.common.types.JvmMember)5