Search in sources :

Example 46 with JvmOperation

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

the class EObjectLocationTests method testFullLocationInFile.

@Test
public void testFullLocationInFile() throws Exception {
    String model = "class Foo extends Object { def Foo foo() {this }}";
    XtendClass clazz = clazz(model);
    JvmGenericType inferredType = xtendjvmAssociations.getInferredType(clazz);
    assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredType));
    JvmConstructor inferredConstructor = xtendjvmAssociations.getInferredConstructor(clazz);
    assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredConstructor));
    XtendFunction xtendFunction = (XtendFunction) clazz.getMembers().get(0);
    JvmOperation inferredOperation = xtendjvmAssociations.getDirectlyInferredOperation(xtendFunction);
    assertEquals(locationInFileProvider.getFullTextRegion(xtendFunction), locationInFileProvider.getFullTextRegion(inferredOperation));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 47 with JvmOperation

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

the class InferredJvmModelTest method testInferredFunction_05.

@Test
public void testInferredFunction_05() throws Exception {
    XtendFile xtendFile = file("class Foo { def Iterable<? extends CharSequence> create result: newArrayList(s) newList(String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    EList<JvmMember> jvmMembers = inferredType.getMembers();
    assertEquals(4, jvmMembers.size());
    JvmMember jvmMember = jvmMembers.get(1);
    assertTrue(jvmMember instanceof JvmOperation);
    XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
    assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
    assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
    assertEquals("java.lang.Iterable<? extends java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
    JvmField cacheVar = (JvmField) jvmMembers.get(2);
    assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
    assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
    JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
    assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
    assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 48 with JvmOperation

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

the class InferredJvmModelTest method testNameClashWithCreateExtension_00.

@Test
public void testNameClashWithCreateExtension_00() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } String _createCache_s }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField cacheVar = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_createCache_s_1", cacheVar.getSimpleName());
    JvmOperation initializer = (JvmOperation) inferredType.getMembers().get(3);
    assertEquals("_init_s", initializer.getSimpleName());
    JvmField field = (JvmField) inferredType.getMembers().get(4);
    assertEquals("_createCache_s", field.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 49 with JvmOperation

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

the class InferredJvmModelTest method testDispatchFunction_08.

@Test
public void testDispatchFunction_08() throws Exception {
    XtendFile xtendFile = file("class Z {\n" + "  def dispatch create newArrayList foo(Object x) {}\n" + "  def dispatch create newArrayList foo(String x) {}\n" + "}\n");
    Iterable<JvmOperation> operations = getInferredType(xtendFile).getDeclaredOperations();
    JvmOperation dispatcher = find(operations, new Predicate<JvmOperation>() {

        @Override
        public boolean apply(JvmOperation input) {
            return equal("foo", input.getSimpleName());
        }
    });
    String identifier = dispatcher.getReturnType().getIdentifier();
    assertEquals("java.util.ArrayList<java.lang.Object>", identifier);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Test(org.junit.Test)

Example 50 with JvmOperation

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

the class InferredJvmModelTest method testDispatchFunction_00.

@Test
public void testDispatchFunction_00() throws Exception {
    XtendFile xtendFile = file("class Foo { def dispatch foo(Object x) {null} def dispatch foo(String x) {null}}");
    JvmGenericType inferredType = getInferredType(xtendFile);
    // one main dispatch
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", Object.class);
    assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier());
    // two internal case methods
    findByNameAndFirstParameterType(operations, "_foo", Object.class);
    findByNameAndFirstParameterType(operations, "_foo", String.class);
    for (JvmMember member : inferredType.getMembers()) {
        if (member instanceof JvmExecutable) {
            if (member.getSimpleName().startsWith("_"))
                assertEquals(JvmVisibility.PROTECTED, member.getVisibility());
            else
                assertEquals(JvmVisibility.PUBLIC, member.getVisibility());
        } else {
            assertEquals(JvmVisibility.PRIVATE, member.getVisibility());
        }
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Aggregations

JvmOperation (org.eclipse.xtext.common.types.JvmOperation)202 Test (org.junit.Test)127 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)101 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)73 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)38 EObject (org.eclipse.emf.ecore.EObject)30 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)26 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)22 XExpression (org.eclipse.xtext.xbase.XExpression)20 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)20 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 JvmField (org.eclipse.xtext.common.types.JvmField)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)15 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)15 JvmMember (org.eclipse.xtext.common.types.JvmMember)15 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10