Search in sources :

Example 1 with Annotation

use of org.freud.analysed.javasource.Annotation in project freud by LMAX-Exchange.

the class JavaSourceJdom method parseAnnotations.

//////////////////////////////////////////////////////////////////////////////////////////////////
public static List<Annotation> parseAnnotations(final Element element) {
    final List<Annotation> annotations;
    JXPathContext context = JXPathContext.newContext(element);
    List annotationList = context.selectNodes("/" + JavaSourceTokenType.MODIFIER_LIST.getName() + "/" + JavaSourceTokenType.AT.getName());
    annotations = new ArrayList<Annotation>(annotationList.size());
    for (Object annotationElement : annotationList) {
        annotations.add(new AnnotationJdom((Element) annotationElement));
    }
    return annotations;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List) Annotation(org.freud.analysed.javasource.Annotation)

Example 2 with Annotation

use of org.freud.analysed.javasource.Annotation in project freud by LMAX-Exchange.

the class AnnotatedElementDeclarationMatchers method hasDeclaredAnnotation.

public FreudExtendedMatcher<T> hasDeclaredAnnotation(final String annotationName, final Matcher<String> defaultValueMatcher) {
    return new FreudExtendedMatcher<T>() {

        @Override
        protected boolean matchesSafely(final AnnotatedElementDeclaration toBeAnalysed) {
            for (Annotation declaredAnnotation : toBeAnalysed.getDeclaredAnnotations()) {
                if (annotationName.equals(declaredAnnotation.getName())) {
                    return defaultValueMatcher.matches(declaredAnnotation.getDefaultParameter());
                }
            }
            return false;
        }

        @Override
        public String toString() {
            Description description = new StringDescription();
            description.appendText("HasDeclaredAnnotation(").appendText(annotationName);
            defaultValueMatcher.describeTo(description);
            description.appendText(")");
            return description.toString();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(toString());
        }
    };
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) AnnotatedElementDeclaration(org.freud.analysed.javasource.AnnotatedElementDeclaration) StringDescription(org.hamcrest.StringDescription) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) Annotation(org.freud.analysed.javasource.Annotation)

Aggregations

Annotation (org.freud.analysed.javasource.Annotation)2 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 AnnotatedElementDeclaration (org.freud.analysed.javasource.AnnotatedElementDeclaration)1 FreudExtendedMatcher (org.freud.java.matcher.FreudExtendedMatcher)1 Description (org.hamcrest.Description)1 StringDescription (org.hamcrest.StringDescription)1 Element (org.jdom.Element)1