Search in sources :

Example 66 with JvmConstructor

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

the class AbstractTypeProviderTest method testAnnotatedParameter_03.

@Test
public void testAnnotatedParameter_03() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String,java.lang.String)");
    JvmAnnotationTarget target = constructor.getParameters().get(2);
    assertEquals(1, target.getAnnotations().size());
    JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
    assertSame(annotationType, annotationReference.getAnnotation());
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmAnnotationTarget(org.eclipse.xtext.common.types.JvmAnnotationTarget) TestAnnotation(org.eclipse.xtext.common.types.testSetups.TestAnnotation) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) Test(org.junit.Test)

Example 67 with JvmConstructor

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

the class AbstractTypeProviderTest method testAnnotatedConstructor_01.

@Test
public void testAnnotatedConstructor_01() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated()");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("constructor", s);
}
Also used : TestAnnotation(org.eclipse.xtext.common.types.testSetups.TestAnnotation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) Test(org.junit.Test)

Example 68 with JvmConstructor

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

the class SourceBasedJdtTypeProviderTest method getConstructorFromType.

@Override
protected JvmConstructor getConstructorFromType(EObject context, Class<?> type, String constructor) {
    JvmConstructor result = super.getConstructorFromType(context, type, constructor);
    if (result != null) {
        IJavaElement found = elementFinder.findElementFor(result);
        assertEquals(IJavaElement.METHOD, found.getElementType());
        assertEquals(result.getSimpleName(), found.getElementName());
        IMethod foundMethod = (IMethod) found;
        assertEquals(result.getParameters().size(), foundMethod.getNumberOfParameters());
    }
    return result;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IMethod(org.eclipse.jdt.core.IMethod)

Example 69 with JvmConstructor

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

the class AbstractConstructorScopeTest method testGetElementByInstance_01.

@Test
public void testGetElementByInstance_01() {
    JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
    JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType();
    type.setPackageName("java.lang");
    type.setSimpleName("Object");
    constructor.setSimpleName("Object");
    type.getMembers().add(constructor);
    IEObjectDescription element = getConstructorScope().getSingleElement(constructor);
    assertNotNull(element);
    assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getName());
    assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getQualifiedName());
}
Also used : JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 70 with JvmConstructor

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

the class AbstractTypeProviderTest method testEnum_04.

@Test
public void testEnum_04() throws Exception {
    String typeName = TestEnum.class.getName();
    JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    boolean constructorFound = false;
    for (JvmMember member : members) {
        if (member instanceof JvmConstructor) {
            assertFalse(constructorFound);
            constructorFound = true;
            List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
            // synthetic parameters are not returned
            assertEquals(1, parameters.size());
        }
    }
    assertTrue(constructorFound);
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) 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