Search in sources :

Example 76 with JvmConstructor

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

the class AbstractTypeProviderTest method test_nestedInterface_Outer_02.

@Test
public void test_nestedInterface_Outer_02() {
    String typeName = NestedInterfaces.class.getName() + "$Outer";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(0, constructors.size());
    assertEquals(JvmVisibility.DEFAULT, type.getVisibility());
    assertTrue(type.isStatic());
    assertTrue(type.isAbstract());
}
Also used : NestedInterfaces(org.eclipse.xtext.common.types.testSetups.NestedInterfaces) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 77 with JvmConstructor

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

the class AbstractTypeProviderTest method test_staticNestedTypes_constructor.

@Test
public void test_staticNestedTypes_constructor() {
    String typeName = Bug347739.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    for (JvmMember member : members) {
        if (member instanceof JvmGenericType) {
            if ("StackItem".equals(member.getSimpleName())) {
                JvmGenericType stackItem = (JvmGenericType) member;
                Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors();
                for (JvmConstructor constructor : constructors) {
                    assertEquals(2, constructor.getParameters().size());
                }
                return;
            }
        }
    }
    fail("could not find inner class");
}
Also used : 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 78 with JvmConstructor

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

the class AbstractTypeProviderTest method testAnnotatedConstructor_02.

@Test
public void testAnnotatedConstructor_02() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String)");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("secondConstructor", 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 79 with JvmConstructor

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

the class AbstractTypeProviderTest method doTestInnerType_WrappedIterator_03.

protected void doTestInnerType_WrappedIterator_03(JvmGenericType wrappedIterator) {
    assertEquals(3, Iterables.size(wrappedIterator.getDeclaredConstructors()));
    JvmConstructor constructor = (JvmConstructor) Iterables.find(wrappedIterator.getMembers(), new Predicate<JvmMember>() {

        @Override
        public boolean apply(JvmMember input) {
            return (input instanceof JvmConstructor) && input.getSimpleName().equals("WrappedIterator") && ((JvmConstructor) input).getParameters().size() == 4;
        }
    });
    assertNotNull(constructor);
    JvmFormalParameter firstParameter = constructor.getParameters().get(0);
    assertEquals(0, firstParameter.getAnnotations().size());
    assertEquals("int", firstParameter.getParameterType().getIdentifier());
    JvmFormalParameter secondParameter = constructor.getParameters().get(1);
    assertEquals(1, secondParameter.getAnnotations().size());
    assertEquals("java.lang.String", secondParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotationWithDefaults.class.getName(), secondParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
    JvmFormalParameter thirdParameter = constructor.getParameters().get(2);
    assertEquals(0, thirdParameter.getAnnotations().size());
    assertEquals("int", thirdParameter.getParameterType().getIdentifier());
    JvmFormalParameter forthParameter = constructor.getParameters().get(3);
    assertEquals(1, forthParameter.getAnnotations().size());
    assertEquals("java.lang.String", forthParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotation.NestedAnnotation.class.getName(), forthParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
}
Also used : TestAnnotationWithDefaults(org.eclipse.xtext.common.types.testSetups.TestAnnotationWithDefaults) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) Predicate(com.google.common.base.Predicate)

Example 80 with JvmConstructor

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

the class AbstractTypeProviderTest method testAnnotatedParameter_01.

@Test
public void testAnnotatedParameter_01() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.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(0);
    assertEquals(2, target.getAnnotations().size());
    JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
    assertSame(annotationType, annotationReference.getAnnotation());
    annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
    annotationReference = target.getAnnotations().get(1);
    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)

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