use of com.laytonsmith.PureUtilities.ClassLoading.ClassMirror.MethodMirror in project CommandHelper by EngineHub.
the class ClassDiscovery method getMethodsWithAnnotation.
/**
* Returns all methods, including constructors, with the specified annotations
*
* @param annotation
* @return
*/
public Set<MethodMirror> getMethodsWithAnnotation(Class<? extends Annotation> annotation) {
if (methodAnnotationCache.containsKey(annotation)) {
return new HashSet<>(methodAnnotationCache.get(annotation));
}
doDiscovery();
Set<MethodMirror> mirrors = new HashSet<>();
for (ClassMirror<?> m : getKnownClasses()) {
for (MethodMirror mm : m.getMethods()) {
if (mm.hasAnnotation(annotation)) {
mirrors.add(mm);
}
}
}
methodAnnotationCache.put(annotation, mirrors);
return mirrors;
}
use of com.laytonsmith.PureUtilities.ClassLoading.ClassMirror.MethodMirror in project CommandHelper by EngineHub.
the class GeneralTest method testAnnotationValue.
@Test
public void testAnnotationValue() throws Exception {
ClassMirror<?> c1 = ClassDiscovery.getDefaultInstance().forName(GeneralTest.class.getName());
ClassMirror<GeneralTest> c2 = new ClassMirror<>(GeneralTest.class);
FieldMirror f1 = c1.getField("field");
FieldMirror f2 = c1.getField("field");
MethodMirror m1 = c1.getMethod("method", new Class[] {});
MethodMirror m2 = c2.getMethod("method", new Class[] {});
assertEquals(c1.loadAnnotation(TestAnnotation.class).value(), "value");
assertEquals(c2.loadAnnotation(TestAnnotation.class).value(), "value");
assertEquals(f1.loadAnnotation(TestAnnotation.class).value(), "field");
assertEquals(f2.loadAnnotation(TestAnnotation.class).value(), "field");
assertEquals(m1.loadAnnotation(TestAnnotation.class).value(), "method");
assertEquals(m2.loadAnnotation(TestAnnotation.class).value(), "method");
}
Aggregations