Example usage for java.lang Class getDeclaredClasses

List of usage examples for java.lang Class getDeclaredClasses

Introduction

In this page you can find the example usage for java.lang Class getDeclaredClasses.

Prototype

@CallerSensitive
public Class<?>[] getDeclaredClasses() throws SecurityException 

Source Link

Document

Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object.

Usage

From source file:com.medallia.spider.api.StRenderer.java

/** @return the interface declared within the given class which is also annotated with the given annotation */
private static <X extends Annotation> Class<X> findInterfaceWithAnnotation(Map<Class<?>, Class<?>> methodMap,
        Class<?> clazz, Class<? extends Annotation> annotation) {
    Class<?> annotatedInterface = methodMap.get(clazz);
    if (annotatedInterface == null) {
        for (Class<?> c : CollUtils.concat(Arrays.asList(clazz.getClasses()),
                Arrays.asList(clazz.getDeclaredClasses()))) {
            Annotation i = c.getAnnotation(annotation);
            if (i != null) {
                annotatedInterface = c;/*from w w w  .j  av  a 2s .  c o m*/
                methodMap.put(clazz, annotatedInterface);
                break;
            }
        }
    }
    @SuppressWarnings("unchecked")
    Class<X> x = (Class<X>) annotatedInterface;
    return x;
}

From source file:org.esa.snap.core.gpf.ui.OperatorMenu.java

private static OperatorDescriptor getOperatorDescriptor(Class<? extends Operator> opType) {
    String operatorAlias = OperatorSpi.getOperatorAlias(opType);

    OperatorDescriptor operatorDescriptor;
    OperatorSpiRegistry spiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry();
    operatorDescriptor = spiRegistry.getOperatorSpi(operatorAlias).getOperatorDescriptor();
    if (operatorDescriptor == null) {
        Class<?>[] declaredClasses = opType.getDeclaredClasses();
        for (Class<?> declaredClass : declaredClasses) {
            if (OperatorSpi.class.isAssignableFrom(declaredClass)) {
                operatorDescriptor = spiRegistry.getOperatorSpi(declaredClass.getName())
                        .getOperatorDescriptor();
            }/*from w  w w.  j av  a  2s. c  o m*/
        }
    }
    if (operatorDescriptor == null) {
        throw new IllegalStateException("Not able to find SPI for operator class '" + opType.getName() + "'");
    }
    return operatorDescriptor;
}

From source file:therian.module.SelfContainedTherianModule.java

private Operator<?>[] getSelfContainedOperators() {
    final List<Operator<?>> result = new ArrayList<>();

    for (Class<?> c : ClassUtils.hierarchy(getClass(), interfacesPolicy)) {
        for (Class<?> inner : c.getDeclaredClasses()) {
            if (Operator.class.isAssignableFrom(inner)) {
                final Operator<?> operator = newInstance(inner.asSubclass(Operator.class));
                if (operator != null) {
                    result.add(operator);
                }/*from w  ww  . j a va2 s. c  o  m*/
            }
        }
    }
    return result.toArray(new Operator[result.size()]);
}

From source file:org.thelq.stackexchange.api.model.types.EntryFormatTest.java

@DataProvider
public Object[][] noExtraEnumMethods() throws IOException {
    List<Class<?>> enumClasses = new ArrayList<Class<?>>();
    for (Class<?> curClass : TestUtils.loadClasses(PostEntry.class, null)) {
        if (curClass.isEnum())
            enumClasses.add(curClass);//w  w  w. j  av  a2s .  com
        //Load subtypes
        for (Class<?> curSubClass : curClass.getDeclaredClasses())
            if (curSubClass.isEnum())
                enumClasses.add(curSubClass);
    }
    return TestUtils.toTestParameters(enumClasses);
}

From source file:org.alfresco.module.org_alfresco_module_rm.api.PublicAPITestUtil.java

/**
 * Get all the classes referenced by the given class, which might be used by an extension. We consider visible
 * methods, constructors, fields and inner classes, as well as superclasses and interfaces extended by the class.
 *
 * @param initialClass The class to analyse.
 * @param consideredClasses Classes that have already been considered, and which should not be considered again. If
 *            the given class has already been considered then an empty set will be returned. This set will be
 *            updated with the given class.
 * @return The set of classes that might be accessible by an extension of this class.
 *///  w  w w  .  j  a  v  a 2s  .co m
private static Set<Class<?>> getReferencedClassesFromClass(Class<?> initialClass,
        Set<Class<?>> consideredClasses) {
    Set<Class<?>> referencedClasses = new HashSet<>();

    if (consideredClasses.add(initialClass)) {
        for (Method method : initialClass.getDeclaredMethods()) {
            if (isVisibleToExtender(method.getModifiers())) {
                referencedClasses.addAll(getClassesFromMethod(method));
            }
        }
        for (Constructor<?> constructor : initialClass.getDeclaredConstructors()) {
            if (isVisibleToExtender(constructor.getModifiers())) {
                referencedClasses.addAll(getClassesFromConstructor(constructor));
            }
        }
        for (Field field : initialClass.getDeclaredFields()) {
            if (isVisibleToExtender(field.getModifiers())) {
                referencedClasses.addAll(getClassesFromField(field));
            }
        }
        for (Class<?> clazz : initialClass.getDeclaredClasses()) {
            if (isVisibleToExtender(clazz.getModifiers())) {
                referencedClasses.addAll(getReferencedClassesFromClass(clazz, consideredClasses));
            }
        }
        if (initialClass.getSuperclass() != null) {
            referencedClasses
                    .addAll(getReferencedClassesFromClass(initialClass.getSuperclass(), consideredClasses));
        }
        for (Class<?> clazz : initialClass.getInterfaces()) {
            referencedClasses.addAll(getReferencedClassesFromClass(clazz, consideredClasses));
        }
    }
    return referencedClasses;
}

From source file:org.eclipse.wb.android.internal.model.widgets.ViewGroupInfo.java

private Class<?> findLayoutParamsClass(Class<?> componentClass) {
    Class<?>[] classes = componentClass.getDeclaredClasses();
    for (Class<?> clazz : classes) {
        if (ReflectionUtils.isSuccessorOf(clazz, "android.view.ViewGroup$LayoutParams")) {
            return clazz;
        }/*from w  w w.jav a 2s.c o m*/
    }
    return null;
}

From source file:edu.wustl.bulkoperator.action.BulkHandler.java

/**
 * This method will be called to get fileItem.
 * @param fileItem fileItem/*from   w  w  w .jav  a 2 s.  c om*/
 * @return FormFile FormFile
 * @throws BulkOperationException BulkOperationException
 */
public FormFile getFormFile(FileItem fileItem) throws BulkOperationException {
    try {
        Class parentClass = Class.forName("org.apache.struts.upload.CommonsMultipartRequestHandler");

        Class childClass = parentClass.getDeclaredClasses()[0];
        Constructor constructor = childClass.getConstructors()[0];
        constructor.setAccessible(true);
        return (FormFile) constructor.newInstance(new Object[] { fileItem });
    } catch (Exception exp) {
        ErrorKey errorkey = ErrorKey.getErrorKey("bulk.operation.request.param.error");
        throw new BulkOperationException(errorkey, exp, "");
    }
}

From source file:dk.statsbiblioteket.util.qa.PackageScanner.java

/**
 * <b>Beware:</b> This class may throw exotic exceptions since it deals with
 * binary class data.// www.  j a  v  a  2s . c o  m
 *
 * @param classTarget The class to analyze.
 * @param filename    The file containing the class.
 * @return An array of ReportElements extracted from the members of the
 *         class and the class it self.
 */
@SuppressWarnings({ "unchecked" })
public final ReportElement[] analyzeClass(Class classTarget, String filename) {
    //FIXME: Filenames for internal classes does not refer to correct .java
    //file (it uses Foo$Bar.java)
    Class[] classes = classTarget.getDeclaredClasses();
    Constructor[] constructors = classTarget.getDeclaredConstructors();
    Method[] methods = classTarget.getDeclaredMethods();
    Field[] fields = classTarget.getDeclaredFields();

    List<ReportElement> elements = new ArrayList<ReportElement>();

    // Add the top level class
    ReportElement topLevel = new ReportElement(ReportElement.ElementType.CLASS, classTarget.getName(), null,
            baseSource.toString(), filename, (QAInfo) classTarget.getAnnotation(QAInfo.class));
    elements.add(topLevel);

    for (Class c : classes) {
        ReportElement classInfo = new ReportElement(ReportElement.ElementType.CLASS, c.getName(),
                classTarget.getName(), baseSource.toString(), filename, (QAInfo) c.getAnnotation(QAInfo.class));
        elements.add(classInfo);
    }

    for (Constructor c : constructors) {
        ReportElement conInfo = new ReportElement(ReportElement.ElementType.METHOD,
                c.getName().substring(c.getName().lastIndexOf(".") + 1), classTarget.getName(),
                baseSource.toString(), filename, (QAInfo) c.getAnnotation(QAInfo.class));
        elements.add(conInfo);
    }

    for (Method m : methods) {
        ReportElement metInfo = new ReportElement(ReportElement.ElementType.METHOD, m.getName(),
                classTarget.getName(), baseSource.toString(), filename, (QAInfo) m.getAnnotation(QAInfo.class));
        elements.add(metInfo);
    }

    for (Field f : fields) {
        ReportElement fInfo = new ReportElement(ReportElement.ElementType.FIELD, f.getName(),
                classTarget.getName(), baseSource.toString(), filename, (QAInfo) f.getAnnotation(QAInfo.class));
        elements.add(fInfo);
    }
    return elements.toArray(new ReportElement[elements.size()]);
}

From source file:com.geodevv.testing.irmina.IrminaContextLoader.java

/**
 * Detect the default configuration classes for the supplied test class.
 * <p>The returned class array will contain all static inner classes of
 * the supplied class that meet the requirements for {@code @Configuration}
 * class implementations as specified in the documentation for
 * {@link Configuration @Configuration}.
 * <p>The implementation of this method adheres to the contract defined in the
 * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}
 * SPI. Specifically, this method uses introspection to detect default
 * configuration classes that comply with the constraints required of
 * {@code @Configuration} class implementations. If a potential candidate
 * configuration class does meet these requirements, this method will log a
 * warning, and the potential candidate class will be ignored.
 *
 * @param declaringClass the test class that declared {@code @ContextConfiguration}
 * @return an array of default configuration classes, potentially empty but
 *         never <code>null</code>
 *//*from  w w  w .  j  a  v  a  2  s .  c o m*/
protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass) {
    Assert.notNull(declaringClass, "Declaring class must not be null");

    List<Class<?>> configClasses = new ArrayList<Class<?>>();

    for (Class<?> candidate : declaringClass.getDeclaredClasses()) {
        if (isDefaultConfigurationClassCandidate(candidate)) {
            configClasses.add(candidate);
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(String.format(
                        "Ignoring class [%s]; it must be static, non-private, non-final, and annotated "
                                + "with @Configuration to be considered a default configuration class.",
                        candidate.getName()));
            }
        }
    }

    if (configClasses.isEmpty()) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format(
                    "Could not detect default configuration classes for test class [%s]: "
                            + "%s does not declare any static, non-private, non-final, inner classes "
                            + "annotated with @Configuration.",
                    declaringClass.getName(), declaringClass.getSimpleName()));
        }
    }

    return configClasses.toArray(new Class<?>[configClasses.size()]);
}

From source file:org.opentestsystem.delivery.testreg.upload.FileUploadUtils.java

public TestRegistrationBase getDomainObject(final FormatType formatType, final Object[] cellData) {
    final Class<? extends TestRegistrationBase> sb11EntityClass = this.parentEntityClassFinder
            .getParentClass(formatType.name());

    final Class<?>[] cArray = sb11EntityClass.getDeclaredClasses();
    for (final Class<?> clazz : cArray) {
        if (isInnerClass(clazz) && isAssignable(clazz, TestRegistrationBuilder.class)) {// Builders as Static Inner class
            try {
                return (TestRegistrationBase) TestRegistrationBuilder.class
                        .cast(invokeConstructor(clazz, new Object[] { cellData })).build();
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
                    | InstantiationException e) {
                throw createInvalidTypeException(formatType.toString());
            }/*from  w w  w .ja  v  a  2s .  co m*/
        }
    }
    throw createInvalidTypeException(formatType.toString());
}