Search in sources :

Example 11 with JvmConstructor

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

the class JvmModelTests method testAnonymousClass_03.

@Test
public void testAnonymousClass_03() {
    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 JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
        this.typeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals(1, operation.getLocalClasses().size());
        final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
        Assert.assertTrue(anonymous.isFinal());
        Assert.assertFalse(anonymous.isStatic());
        Assert.assertTrue(anonymous.isLocal());
        Assert.assertTrue(anonymous.isAnonymous());
        Assert.assertEquals(0, anonymous.getTypeParameters().size());
        Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
        Assert.assertEquals(2, anonymous.getSuperTypes().size());
        Assert.assertEquals("java.lang.Iterable<T>", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
        Assert.assertEquals(2, anonymous.getMembers().size());
        final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
        Assert.assertTrue((constructor instanceof JvmConstructor));
        Assert.assertEquals(0, ((JvmConstructor) constructor).getTypeParameters().size());
        final JvmMember overriding = IterableExtensions.<JvmMember>head(anonymous.getMembers());
        Assert.assertTrue((overriding instanceof JvmOperation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) 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 12 with JvmConstructor

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

the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_5.

@Test
public void testResolveAnonymousClassConstructorCall_5() throws Exception {
    String model = "class Foo { val bar = new Bar() {} } class Bar { new(String x) {} }";
    XtendFile file = file(model);
    XtextResource resource = (XtextResource) file.eResource();
    EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
    assertTrue(constructor instanceof JvmConstructor);
    assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
    assertEquals(1, ((JvmConstructor) constructor).getParameters().size());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 13 with JvmConstructor

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

the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_2.

@Test
public void testResolveAnonymousClassConstructorCall_2() throws Exception {
    String model = "class Foo { val bar = new Bar() {} } class Bar { new(String x) {} new() {} }";
    XtendFile file = file(model);
    XtextResource resource = (XtextResource) file.eResource();
    EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
    assertTrue(constructor instanceof JvmConstructor);
    assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
    assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 14 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor 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 15 with JvmConstructor

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

the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_1.

@Test
public void testResolveAnonymousClassConstructorCall_1() throws Exception {
    String model = "class Foo { val bar = new Bar() {} } class Bar {}";
    XtendFile file = file(model);
    XtextResource resource = (XtextResource) file.eResource();
    EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
    assertTrue(constructor instanceof JvmConstructor);
    assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)42 Test (org.junit.Test)21 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)16 EObject (org.eclipse.emf.ecore.EObject)13 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmMember (org.eclipse.xtext.common.types.JvmMember)8 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)6 XtextResource (org.eclipse.xtext.resource.XtextResource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)4 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 MockAcceptor (org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor)3 JvmField (org.eclipse.xtext.common.types.JvmField)3 URI (org.eclipse.emf.common.util.URI)2 JvmConstructorDeclarationImpl (org.eclipse.xtend.core.macro.declaration.JvmConstructorDeclarationImpl)2