Search in sources :

Example 6 with AnnotatedElement

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));
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 7 with AnnotatedElement

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());
        }
    }
}
Also used : org.hibernate.mapping(org.hibernate.mapping) AnnotatedElement(java.lang.reflect.AnnotatedElement) EntityType(com.querydsl.codegen.EntityType) Type(com.mysema.codegen.model.Type) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.mysema.codegen.model.SimpleType) Property(com.querydsl.codegen.Property)

Example 8 with AnnotatedElement

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);
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) Type(com.mysema.codegen.model.Type) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.mysema.codegen.model.SimpleType) AnnotatedElement(java.lang.reflect.AnnotatedElement) Property(com.querydsl.codegen.Property) MappingException(org.hibernate.MappingException)

Example 9 with AnnotatedElement

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();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) ArrayList(java.util.ArrayList) AnnotatedElement(java.lang.reflect.AnnotatedElement) ThreadLeakGroup(com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) StoppedByUserException(org.junit.runner.notification.StoppedByUserException) MultipleFailureException(org.junit.runners.model.MultipleFailureException) UncaughtException(com.carrotsearch.randomizedtesting.RandomizedRunner.UncaughtException) Failure(org.junit.runner.notification.Failure)

Example 10 with AnnotatedElement

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);
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) Test(org.junit.Test)

Aggregations

AnnotatedElement (java.lang.reflect.AnnotatedElement)29 Test (org.junit.Test)7 Method (java.lang.reflect.Method)5 HashMap (java.util.HashMap)4 SimpleType (com.mysema.codegen.model.SimpleType)3 Type (com.mysema.codegen.model.Type)3 EntityType (com.querydsl.codegen.EntityType)3 Property (com.querydsl.codegen.Property)3 Annotation (java.lang.annotation.Annotation)3 Type (java.lang.reflect.Type)3 ArrayList (java.util.ArrayList)3 UncaughtException (com.carrotsearch.randomizedtesting.RandomizedRunner.UncaughtException)2 QueryEntity (com.querydsl.core.annotations.QueryEntity)2 Constructor (java.lang.reflect.Constructor)2 Nullable (javax.annotation.Nullable)2 MappingException (org.hibernate.MappingException)2 org.hibernate.mapping (org.hibernate.mapping)2 Nullable (org.jetbrains.annotations.Nullable)2 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)2 StoppedByUserException (org.junit.runner.notification.StoppedByUserException)2