use of java.lang.reflect.AnnotatedElement in project antlr4 by tunnelvisionlabs.
the class RuleDependencyChecker method getDependencies.
public static List<Tuple2<RuleDependency, AnnotatedElement>> getDependencies(Class<?> clazz) {
List<Tuple2<RuleDependency, AnnotatedElement>> result = new ArrayList<Tuple2<RuleDependency, AnnotatedElement>>();
List<ElementType> supportedTarget = Arrays.asList(RuleDependency.class.getAnnotation(Target.class).value());
for (ElementType target : supportedTarget) {
switch(target) {
case TYPE:
if (!clazz.isAnnotation()) {
getElementDependencies(clazz, result);
}
break;
case ANNOTATION_TYPE:
if (!clazz.isAnnotation()) {
getElementDependencies(clazz, result);
}
break;
case CONSTRUCTOR:
for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
getElementDependencies(ctor, result);
}
break;
case FIELD:
for (Field field : clazz.getDeclaredFields()) {
getElementDependencies(field, result);
}
break;
case LOCAL_VARIABLE:
System.err.println("Runtime rule dependency checking is not supported for local variables.");
break;
case METHOD:
for (Method method : clazz.getDeclaredMethods()) {
getElementDependencies(method, result);
}
break;
case PACKAGE:
// package is not a subset of class, so nothing to do here
break;
case PARAMETER:
System.err.println("Runtime rule dependency checking is not supported for parameters.");
break;
}
}
return result;
}
use of java.lang.reflect.AnnotatedElement in project querydsl by querydsl.
the class PathTest method getAnnotatedElement.
@Test
public void getAnnotatedElement() {
Entity entity = Alias.alias(Entity.class);
AnnotatedElement element = $(entity).getAnnotatedElement();
// type
assertEquals(Entity.class, element);
}
use of java.lang.reflect.AnnotatedElement in project randomizedtesting by randomizedtesting.
the class ThreadLeakControl method forTest.
/**
* A {@link Statement} for wrapping test-level execution.
*/
Statement forTest(final Statement s, final TestCandidate c) {
final int timeout = determineTimeout(c);
return new Statement() {
@Override
public void evaluate() throws Throwable {
checkZombies();
final StatementRunner sr = new StatementRunner(s);
final List<Throwable> errors = new ArrayList<Throwable>();
final Set<Thread> beforeTestState = getThreads(suiteFilters);
final boolean timedOut = forkTimeoutingTask(sr, timeout, errors);
if (suiteTimedOut.get()) {
return;
}
if (timedOut) {
LOGGER.warning("Test execution timed out: " + c.description + formatThreadStacksFull());
}
if (timedOut) {
errors.add(RandomizedRunner.augmentStackTrace(emptyStack(new Exception("Test timeout exceeded (>= " + timeout + " msec)."))));
}
final AnnotatedElement[] chain = { c.method, c.getTestClass(), DefaultAnnotationValues.class };
List<Throwable> threadLeakErrors = timedOut ? new ArrayList<Throwable>() : errors;
checkThreadLeaks(beforeTestState, threadLeakErrors, LifecycleScope.TEST, c.description, chain);
processUncaught(errors, runner.handler.getUncaughtAndClear());
MultipleFailureException.assertEmpty(errors);
}
};
}
use of java.lang.reflect.AnnotatedElement in project randomizedtesting by randomizedtesting.
the class GroupEvaluator method getIgnoreReason.
/**
* @return Returns a non-null string with the reason why the annotated element (class, test or test-class pair)
* should be ignored in the execution. This is an expert-level method, typically tests
* shouldn't be concerned with this.
*/
public String getIgnoreReason(AnnotatedElement... elements) {
final Map<String, Annotation> annotations = new HashMap<String, Annotation>();
for (AnnotatedElement element : elements) {
for (Annotation ann : element.getAnnotations()) {
Class<? extends Annotation> annType = ann.annotationType();
if (annType.isAnnotationPresent(TestGroup.class)) {
if (!testGroups.containsKey(annType)) {
testGroups.put(annType, new TestGroupInfo(annType));
}
annotations.put(testGroups.get(annType).name, ann);
}
}
}
String defaultState = null;
for (Annotation ann : annotations.values()) {
TestGroupInfo g = testGroups.get(ann.annotationType());
if (!g.enabled) {
defaultState = "'" + g.name + "' test group is disabled (" + toString(ann) + ")";
break;
}
}
if (hasFilteringExpression()) {
final String defaultStateCopy = defaultState;
boolean enabled = filter.evaluate(new IContext() {
@Override
public boolean defaultValue() {
return defaultStateCopy == null;
}
@Override
public boolean hasGroup(String value) {
if (value.startsWith("@"))
value = value.substring(1);
for (Annotation ann : annotations.values()) {
if (value.equalsIgnoreCase(testGroups.get(ann.annotationType()).name)) {
return true;
}
}
return false;
}
});
return enabled ? null : "Test filter condition: " + filterExpression;
} else {
return defaultState;
}
}
use of java.lang.reflect.AnnotatedElement in project spring-framework by spring-projects.
the class ParameterResolutionDelegate method isAutowirable.
/**
* Determine if the supplied {@link Parameter} can <em>potentially</em> be
* autowired from an {@link AutowireCapableBeanFactory}.
* <p>Returns {@code true} if the supplied parameter is annotated or
* meta-annotated with {@link Autowired @Autowired},
* {@link Qualifier @Qualifier}, or {@link Value @Value}.
* <p>Note that {@link #resolveDependency} may still be able to resolve the
* dependency for the supplied parameter even if this method returns {@code false}.
* @param parameter the parameter whose dependency should be autowired
* (must not be {@code null})
* @param parameterIndex the index of the parameter in the constructor or method
* that declares the parameter
* @see #resolveDependency
*/
public static boolean isAutowirable(Parameter parameter, int parameterIndex) {
Assert.notNull(parameter, "Parameter must not be null");
AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex);
return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class));
}
Aggregations