Search in sources :

Example 71 with JvmConstructor

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

the class AbstractTypeProviderTest method doTestInnerType_WrappedIterator_02.

protected void doTestInnerType_WrappedIterator_02(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() == 3;
        }
    });
    assertNotNull(constructor);
    JvmFormalParameter firstParameter = constructor.getParameters().get(0);
    assertEquals(1, firstParameter.getAnnotations().size());
    assertEquals("java.lang.String", firstParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotationWithDefaults.class.getName(), firstParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
    JvmFormalParameter secondParameter = constructor.getParameters().get(1);
    assertEquals(0, secondParameter.getAnnotations().size());
    assertEquals("int", secondParameter.getParameterType().getIdentifier());
    JvmFormalParameter thirdParameter = constructor.getParameters().get(2);
    assertEquals(1, thirdParameter.getAnnotations().size());
    assertEquals("java.util.Iterator<V>", thirdParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotation.NestedAnnotation.class.getName(), thirdParameter.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 72 with JvmConstructor

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

the class AbstractTypeProviderTest method testInnerAnnotationType.

@Test
public void testInnerAnnotationType() throws Exception {
    JvmDeclaredType declaredType = (JvmDeclaredType) getTypeProvider().findTypeByName(TypeWithInnerAnnotation.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(TypeWithInnerAnnotation.class.getSimpleName());
        }
    }));
    // inner annotation type
    assertTrue(Iterables.any(declaredType.getMembers(), new Predicate<JvmMember>() {

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

Example 73 with JvmConstructor

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

the class AbstractTypeProviderTest method test_nestedTypes_Outer_Inner_02.

@Test
public void test_nestedTypes_Outer_Inner_02() {
    String typeName = NestedTypes.Outer.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(1, constructors.size());
    JvmConstructor parameterlessConstructor = constructors.get(0);
    assertEquals(1, parameterlessConstructor.getParameters().size());
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 74 with JvmConstructor

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

the class AbstractTypeProviderTest method doTestInnerType_WrappedIterator_01.

private void doTestInnerType_WrappedIterator_01(JvmGenericType wrappedIterator) {
    assertEquals(2, Iterables.size(wrappedIterator.getDeclaredConstructors()));
    // default constructor
    assertTrue(Iterables.any(wrappedIterator.getMembers(), new Predicate<JvmMember>() {

        @Override
        public boolean apply(JvmMember input) {
            return (input instanceof JvmConstructor) && input.getSimpleName().equals("Iter") && ((JvmConstructor) input).getParameters().size() == 0;
        }
    }));
    // second constructor
    JvmConstructor secondConstructor = (JvmConstructor) Iterables.find(wrappedIterator.getMembers(), new Predicate<JvmMember>() {

        @Override
        public boolean apply(JvmMember input) {
            return (input instanceof JvmConstructor) && input.getSimpleName().equals("Iter") && ((JvmConstructor) input).getParameters().size() == 1;
        }
    });
    assertNotNull(secondConstructor);
    JvmFormalParameter firstParameter = secondConstructor.getParameters().get(0);
    assertEquals("java.util.Iterator<V>", firstParameter.getParameterType().getIdentifier());
}
Also used : 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 75 with JvmConstructor

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

the class AbstractTypeProviderTest method testAnnotatedConstructor_03.

@Test
public void testAnnotatedConstructor_03() 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,T)");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("parameterizedConstructor", 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)

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