Search in sources :

Example 61 with JvmConstructor

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

the class EObjectLocationTests method testSignificantLocationInFile.

@Test
public void testSignificantLocationInFile() throws Exception {
    String model = "class Foo extends Object { def Foo foo() {this} }";
    XtendClass clazz = clazz(model);
    JvmGenericType inferredType = xtendjvmAssociations.getInferredType(clazz);
    assertEquals(locationInFileProvider.getSignificantTextRegion(clazz), locationInFileProvider.getSignificantTextRegion(inferredType));
    JvmConstructor inferredConstructor = xtendjvmAssociations.getInferredConstructor(clazz);
    assertEquals(locationInFileProvider.getSignificantTextRegion(clazz), locationInFileProvider.getSignificantTextRegion(inferredConstructor));
    XtendFunction xtendFunction = (XtendFunction) clazz.getMembers().get(0);
    JvmOperation inferredOperation = xtendjvmAssociations.getDirectlyInferredOperation(xtendFunction);
    assertEquals(locationInFileProvider.getSignificantTextRegion(xtendFunction), locationInFileProvider.getSignificantTextRegion(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 62 with JvmConstructor

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

the class InferredJvmModelTest method testInferredFunctionWithReturnType_01.

@Test
public void testInferredFunctionWithReturnType_01() throws Exception {
    XtendFile xtendFile = file("class Foo { def Boolean bar() { true } }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType());
    assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType());
}
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) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 63 with JvmConstructor

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

the class Case_14 method testInference.

@Test
public void testInference() {
    final Provider<IJvmModelInferrer> _function = () -> {
        final IJvmModelInferrer _function_1 = (EObject obj, IJvmDeclaredTypeAcceptor acceptor, boolean preIndexing) -> {
            final JvmGenericType firstType = this._jvmTypesBuilder.toClass(obj, "foo.Bar");
            final JvmGenericType secondType = this._jvmTypesBuilder.toClass(obj, "foo.Baz");
            Assert.assertNull(secondType.eResource());
            final Procedure1<JvmGenericType> _function_2 = (JvmGenericType it) -> {
                it.setAbstract(true);
                Assert.assertNotNull(firstType.eResource());
                Assert.assertNotNull(secondType.eResource());
            };
            acceptor.<JvmGenericType>accept(firstType, _function_2);
            final Procedure1<JvmGenericType> _function_3 = (JvmGenericType it) -> {
                it.setAbstract(true);
                Assert.assertNotNull(firstType.eResource());
            };
            acceptor.<JvmGenericType>accept(secondType, _function_3);
        };
        return _function_1;
    };
    this.assoc.setInferrerProvider(_function);
    this.resource.setDerivedStateComputer(null);
    this.resource.setURI(URI.createURI("foo.txt"));
    this.resourceSet.setClasspathURIContext(this.getClass());
    EList<Resource> _resources = this.resourceSet.getResources();
    this._jvmTypesBuilder.<DerivedStateAwareResource>operator_add(_resources, this.resource);
    EList<EObject> _contents = this.resource.getContents();
    EClass _createEClass = EcoreFactory.eINSTANCE.createEClass();
    this._jvmTypesBuilder.<EClass>operator_add(_contents, _createEClass);
    this.assoc.installDerivedState(this.resource, true);
    EObject _get = this.resource.getContents().get(1);
    Assert.assertFalse(((JvmDeclaredType) _get).isAbstract());
    this.resource.getContents().clear();
    EList<EObject> _contents_1 = this.resource.getContents();
    EClass _createEClass_1 = EcoreFactory.eINSTANCE.createEClass();
    this._jvmTypesBuilder.<EClass>operator_add(_contents_1, _createEClass_1);
    this.assoc.installDerivedState(this.resource, false);
    EObject _get_1 = this.resource.getContents().get(1);
    final JvmGenericType type = ((JvmGenericType) _get_1);
    Assert.assertTrue(type.isAbstract());
    Assert.assertEquals(1, IterableExtensions.size(Iterables.<JvmConstructor>filter(type.getMembers(), JvmConstructor.class)));
    JvmTypeReference _head = IterableExtensions.<JvmTypeReference>head(type.getSuperTypes());
    String _qualifiedName = null;
    if (_head != null) {
        _qualifiedName = _head.getQualifiedName();
    }
    Assert.assertEquals("java.lang.Object", _qualifiedName);
}
Also used : IJvmModelInferrer(org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) EClass(org.eclipse.emf.ecore.EClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IJvmDeclaredTypeAcceptor(org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor) Test(org.junit.Test)

Example 64 with JvmConstructor

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

the class AbstractTypeProviderTest method testInnerEnumType.

@Test
public void testInnerEnumType() throws Exception {
    JvmDeclaredType declaredType = (JvmDeclaredType) getTypeProvider().findTypeByName(TypeWithInnerEnum.class.getName());
    assertEquals(2, declaredType.getMembers().size());
    // default constructor
    assertTrue(Iterables.any(declaredType.getMembers(), new Predicate<JvmMember>() {

        @Override
        public boolean apply(JvmMember input) {
            return (input instanceof JvmConstructor) && input.getSimpleName().equals(TypeWithInnerEnum.class.getSimpleName());
        }
    }));
    // inner enum type
    assertTrue(Iterables.any(declaredType.getMembers(), new Predicate<JvmMember>() {

        @Override
        public boolean apply(JvmMember input) {
            return (input instanceof JvmEnumerationType) && input.getIdentifier().equals(TypeWithInnerEnum.MyEnum.class.getName()) && input.getVisibility() == JvmVisibility.PUBLIC;
        }
    }));
}
Also used : JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 65 with JvmConstructor

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

the class AbstractTypeProviderTest method testConstructorThrowsException.

@Test
public void testConstructorThrowsException() {
    String typeUnderTest = CallableThrowsExceptions.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeUnderTest);
    assertNotNull(type);
    Iterable<JvmConstructor> constructors = filter(type.getMembers(), JvmConstructor.class);
    assertEquals(3, size(constructors));
    assertTrue(hasExecutableWithException(constructors, UnsupportedOperationException.class.getName()));
    assertTrue(hasExecutableWithException(constructors, "E"));
    assertTrue(hasExecutableWithException(constructors, Exception.class.getName(), RuntimeException.class.getName()));
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Aggregations

JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)82 Test (org.junit.Test)42 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)33 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)18 JvmMember (org.eclipse.xtext.common.types.JvmMember)17 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)16 EObject (org.eclipse.emf.ecore.EObject)15 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)9 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 TestAnnotation (org.eclipse.xtext.common.types.testSetups.TestAnnotation)9 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 JvmField (org.eclipse.xtext.common.types.JvmField)6 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)6 Predicate (com.google.common.base.Predicate)5 JvmAnnotationTarget (org.eclipse.xtext.common.types.JvmAnnotationTarget)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)5