Search in sources :

Example 66 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project motech by motech.

the class RestIgnoreProcessor method getElementsToProcess.

@Override
protected Set<? extends AnnotatedElement> getElementsToProcess() {
    List<Member> members = ReflectionsUtil.getFilteredMembers(clazz, restIgnore());
    Set<AnnotatedElement> elements = new LinkedHashSet<>(members.size());
    for (Member member : members) {
        if (member instanceof AnnotatedElement) {
            elements.add((AnnotatedElement) member);
        }
    }
    return elements;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotatedElement(java.lang.reflect.AnnotatedElement) Member(java.lang.reflect.Member)

Example 67 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project motech by motech.

the class FieldProcessorTest method shouldNotProcessIgnoredSettersAndGetters.

@Test
public void shouldNotProcessIgnoredSettersAndGetters() {
    Method setIgnoredField = getAccessibleMethod(Sample.class, "setIgnoredPrivate", String.class);
    Method getIgnoredField = getAccessibleMethod(Sample.class, "getIgnoredPrivate", new Class[0]);
    processor.process(setIgnoredField);
    processor.process(getIgnoredField);
    verify(schemaHolder, times(2)).getType(String.class);
    Collection<FieldDto> setterFields = processor.getElements();
    assertEquals(1, setterFields.size());
    List<AnnotatedElement> actual = new ArrayList<>();
    actual.addAll(processor.getElementsToProcess());
    assertEquals(Sample.FIELD_COUNT, actual.size());
    assertFalse(actual.contains(getIgnoredField));
    assertFalse(actual.contains(setIgnoredField));
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MethodUtils.getAccessibleMethod(org.apache.commons.lang.reflect.MethodUtils.getAccessibleMethod) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 68 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project motech by motech.

the class AbstractProcessor method execute.

/**
 * {@inheritDoc}
 * <p/>
 * Developer have to specify what actions have to be done before and after processing each
 * found element.
 */
@Override
public void execute(Bundle bundle, SchemaHolder schemaHolder) {
    this.bundle = bundle;
    this.schemaHolder = schemaHolder;
    Class<A> annotation = getAnnotationType();
    Set<? extends AnnotatedElement> elements = getElementsToProcess();
    beforeExecution();
    for (AnnotatedElement element : elements) {
        LOGGER.debug("Processing: Annotation: {} Object: {}", annotation.getName(), element);
        try {
            process(element);
        } catch (RuntimeException e) {
            LOGGER.error("An error occurred while processing annotated element in Bundle: {}, in Element: {} because of:", bundle.getSymbolicName(), element, e);
        }
        LOGGER.debug("Processed: Annotation: {} Object: {}", annotation.getName(), element);
    }
    afterExecution();
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement)

Example 69 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project motech by motech.

the class NonEditableProcessor method getElementsToProcess.

@Override
protected Set<? extends AnnotatedElement> getElementsToProcess() {
    List<Member> members = ReflectionsUtil.getFilteredMembers(clazz, nonEditable());
    Set<AnnotatedElement> elements = new LinkedHashSet<>(members.size());
    for (Member member : members) {
        if (member instanceof AnnotatedElement) {
            elements.add((AnnotatedElement) member);
        }
    }
    return elements;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotatedElement(java.lang.reflect.AnnotatedElement) Member(java.lang.reflect.Member)

Example 70 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project motech by motech.

the class UIDisplayableProcessor method getElementsToProcess.

@Override
protected Set<? extends AnnotatedElement> getElementsToProcess() {
    List<Member> members = ReflectionsUtil.getFilteredMembers(clazz, uiDisplayable());
    Set<AnnotatedElement> elements = new LinkedHashSet<>(members.size());
    for (Member member : members) {
        if (member instanceof AnnotatedElement) {
            elements.add((AnnotatedElement) member);
        }
    }
    return elements;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotatedElement(java.lang.reflect.AnnotatedElement) Member(java.lang.reflect.Member)

Aggregations

AnnotatedElement (java.lang.reflect.AnnotatedElement)106 Method (java.lang.reflect.Method)23 Annotation (java.lang.annotation.Annotation)17 Field (java.lang.reflect.Field)17 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 Test (org.junit.jupiter.api.Test)8 Member (java.lang.reflect.Member)7 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 Constructor (java.lang.reflect.Constructor)6 Type (java.lang.reflect.Type)6 Map (java.util.Map)6 HashSet (java.util.HashSet)5 By (org.openqa.selenium.By)5 Statement (org.junit.runners.model.Statement)4 FindBy (org.openqa.selenium.support.FindBy)4 EntityType (com.querydsl.codegen.EntityType)3 Collection (java.util.Collection)3