Search in sources :

Example 66 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testInferredJvmConstructor.

@Test
public void testInferredJvmConstructor() throws Exception {
    XtendFile xtendFile = file("class Foo { }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    assertEquals(1, inferredType.getMembers().size());
    JvmMember inferredFirstMember = inferredType.getMembers().get(0);
    assertTrue(inferredFirstMember instanceof JvmConstructor);
    assertEquals(JvmVisibility.PUBLIC, inferredFirstMember.getVisibility());
    assertEquals(associations.getInferredConstructor(xtendClass), inferredFirstMember);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 67 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class LinkingErrorTest method testNoExceptionInValidator_03.

@Test
public void testNoExceptionInValidator_03() throws Exception {
    XtendClass clazz = clazz("package pack class Case_4 {\n" + "	richStrings_01() {\n" + "		'''foobar'''\n" + "	}\n" + "	richStrings_02() {\n" + "		'''�'start'�\n" + "		  first line\n'''" + "");
    assertNoExceptions(clazz);
    XtextResource resource = (XtextResource) clazz.eResource();
    validateWithoutException(resource);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 68 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class LinkingTest method testOverloadedWithLambdaArgument_01.

@Test
public void testOverloadedWithLambdaArgument_01() throws Exception {
    XtendFile file = file("import static extension com.google.common.collect.Iterables.*" + "abstract class C {\n" + "	def void m(Iterable<String> iter) {\n" + "		iter.filter [ it != null ]\n" + "	}\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("com.google.common.collect.Iterables.filter(java.lang.Iterable,com.google.common.base.Predicate)", 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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 69 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class LinkingTest method testQualifiedSuper.

@Test
public void testQualifiedSuper() throws Exception {
    XtendFile file = file("class B<T> { def T m1() {} }\n" + "class C extends B<String> {\n" + "  def void m2() { C.super.m1.subSequence(1, 1) } \n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(1);
    XtendFunction n = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) n.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) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 70 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class LinkingTest method testExtensionMethodCall_04.

@Test
public void testExtensionMethodCall_04() throws Exception {
    XtendClass clazz = clazz("" + "abstract class MyIterable implements Iterable<String> {" + "  def doSomething() {\n" + "    this.filter [ s.toUpperCase != null ]\n" + "  }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    final XAbstractFeatureCall call = (XAbstractFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.filter(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", call.getFeature().getIdentifier());
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    assertEquals("Iterable<String>", operation.getReturnType().getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1017 Test (org.junit.Test)988 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)249 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)229 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)169 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)129 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)104 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)101 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)74 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)73 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)63 XExpression (org.eclipse.xtext.xbase.XExpression)62 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)62 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)37 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)35 XAssignment (org.eclipse.xtext.xbase.XAssignment)19 EObject (org.eclipse.emf.ecore.EObject)18 RichString (org.eclipse.xtend.core.xtend.RichString)17