use of java.lang.reflect.AnnotatedElement in project querydsl by querydsl.
the class ReflectionUtilsTest method getAnnotatedElement.
@Test
public void getAnnotatedElement() {
AnnotatedElement annotatedElement = ReflectionUtils.getAnnotatedElement(ReflectionUtilsTest.class, "property", String.class);
assertNotNull(annotatedElement.getAnnotation(Nullable.class));
}
use of java.lang.reflect.AnnotatedElement in project querydsl by querydsl.
the class HibernateDomainExporter method collectTypes.
@Override
protected void collectTypes() throws IOException, XMLStreamException, ClassNotFoundException, NoSuchMethodException {
// super classes
Iterator<?> superClassMappings = configuration.getMappedSuperclassMappings();
while (superClassMappings.hasNext()) {
MappedSuperclass msc = (MappedSuperclass) superClassMappings.next();
EntityType entityType = createSuperType(msc.getMappedClass());
if (msc.getDeclaredIdentifierProperty() != null) {
handleProperty(entityType, msc.getMappedClass(), msc.getDeclaredIdentifierProperty());
}
Iterator<?> properties = msc.getDeclaredPropertyIterator();
while (properties.hasNext()) {
handleProperty(entityType, msc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
}
}
// entity classes
Iterator<?> classMappings = configuration.getClassMappings();
while (classMappings.hasNext()) {
PersistentClass pc = (PersistentClass) classMappings.next();
EntityType entityType = createEntityType(pc.getMappedClass());
if (pc.getDeclaredIdentifierProperty() != null) {
handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty());
} else if (!pc.isInherited() && pc.hasIdentifierProperty()) {
logger.info(entityType.toString() + pc.getIdentifierProperty());
handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty());
} else if (pc.getIdentifier() != null) {
KeyValue identifier = pc.getIdentifier();
if (identifier instanceof Component) {
Component component = (Component) identifier;
Iterator<?> properties = component.getPropertyIterator();
if (component.isEmbedded()) {
while (properties.hasNext()) {
handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
}
} else {
String name = component.getNodeName();
Class<?> clazz = component.getType().getReturnedClass();
Type propertyType = getType(pc.getMappedClass(), clazz, name);
AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name);
Property property = createProperty(entityType, name, propertyType, annotated);
entityType.addProperty(property);
// handle component properties
EntityType embeddedType = createEmbeddableType(propertyType);
while (properties.hasNext()) {
handleProperty(embeddedType, clazz, (org.hibernate.mapping.Property) properties.next());
}
}
}
// TODO handle other KeyValue subclasses such as Any, DependentValue and ToOne
}
Iterator<?> properties = pc.getDeclaredPropertyIterator();
while (properties.hasNext()) {
handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
}
}
}
use of java.lang.reflect.AnnotatedElement in project querydsl by querydsl.
the class JPADomainExporter method handleProperty.
private void handleProperty(EntityType entityType, Class<?> cl, Attribute<?, ?> p) throws NoSuchMethodException, ClassNotFoundException {
Class<?> clazz = Object.class;
try {
clazz = p.getJavaType();
} catch (MappingException e) {
// ignore
}
Type propertyType = getType(cl, clazz, p.getName());
AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
propertyType = getTypeOverride(propertyType, annotated);
if (propertyType == null) {
return;
}
if (p.isCollection()) {
if (p instanceof MapAttribute) {
MapAttribute<?, ?, ?> map = (MapAttribute<?, ?, ?>) p;
Type keyType = typeFactory.get(map.getKeyJavaType());
Type valueType = typeFactory.get(map.getElementType().getJavaType());
valueType = getPropertyType(p, valueType);
propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType));
} else {
Type valueType = typeFactory.get(((PluralAttribute<?, ?, ?>) p).getElementType().getJavaType());
valueType = getPropertyType(p, valueType);
propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), valueType));
}
} else {
propertyType = getPropertyType(p, propertyType);
}
Property property = createProperty(entityType, p.getName(), propertyType, annotated);
entityType.addProperty(property);
}
use of java.lang.reflect.AnnotatedElement in project randomizedtesting by randomizedtesting.
the class ThreadLeakControl method forSuite.
/**
* A {@link Statement} for wrapping suite-level execution.
*/
Statement forSuite(final Statement s, final Description suiteDescription) {
final Class<?> suiteClass = RandomizedContext.current().getTargetClass();
final int timeout = determineTimeout(suiteClass);
return new Statement() {
@Override
public void evaluate() throws Throwable {
checkZombies();
threadLeakGroup = firstAnnotated(ThreadLeakGroup.class, suiteClass, DefaultAnnotationValues.class);
final List<Throwable> errors = new ArrayList<Throwable>();
suiteFilters = instantiateFilters(errors, suiteClass);
MultipleFailureException.assertEmpty(errors);
final StatementRunner sr = new StatementRunner(s);
final boolean timedOut = forkTimeoutingTask(sr, timeout, errors);
synchronized (notifierLock) {
if (timedOut) {
// Mark as timed out so that we don't do any checks in any currently running test
suiteTimedOut.set(true);
// Flush streams so that we don't get warning outputs before sysout buffers.
flushStreams();
// Emit a warning.
LOGGER.warning("Suite execution timed out: " + suiteDescription + formatThreadStacksFull());
// mark subNotifier as dead (no longer passing events).
subNotifier.pleaseStop();
}
}
if (timedOut) {
// complete subNotifier state in case in the middle of a test.
if (subNotifier.testInProgress != null) {
targetNotifier.fireTestFailure(new Failure(subNotifier.testInProgress, RandomizedRunner.augmentStackTrace(emptyStack(new Exception("Test abandoned because suite timeout was reached.")))));
targetNotifier.fireTestFinished(subNotifier.testInProgress);
}
// throw suite failure (timeout).
errors.add(RandomizedRunner.augmentStackTrace(emptyStack(new Exception("Suite timeout exceeded (>= " + timeout + " msec)."))));
}
final AnnotatedElement[] chain = { suiteClass, DefaultAnnotationValues.class };
List<Throwable> threadLeakErrors = timedOut ? new ArrayList<Throwable>() : errors;
checkThreadLeaks(refilter(expectedSuiteState, suiteFilters), threadLeakErrors, LifecycleScope.SUITE, suiteDescription, chain);
processUncaught(errors, runner.handler.getUncaughtAndClear());
MultipleFailureException.assertEmpty(errors);
}
@SuppressForbidden("Legitimate use of syserr.")
private void flushStreams() {
System.out.flush();
System.err.flush();
}
};
}
use of java.lang.reflect.AnnotatedElement in project spring-framework by spring-projects.
the class MultipleComposedAnnotationsOnSingleAnnotatedElementTests method getMultipleComposedAnnotationsOnMethod.
@Test
public void getMultipleComposedAnnotationsOnMethod() throws Exception {
AnnotatedElement element = getClass().getDeclaredMethod("multipleComposedCachesMethod");
assertGetAllMergedAnnotationsBehavior(element);
}
Aggregations