Example usage for java.lang Class isAnonymousClass

List of usage examples for java.lang Class isAnonymousClass

Introduction

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

Prototype

public boolean isAnonymousClass() 

Source Link

Document

Returns true if and only if the underlying class is an anonymous class.

Usage

From source file:org.assertj.assertions.generator.util.ClassUtil.java

/**
 * @param loadedClass/*from  w  ww . j  a  v a2  s.  com*/
 * @return
 */
private static boolean isClassCandidateToAssertionsGeneration(Class<?> loadedClass) {
    return loadedClass != null && isPublic(loadedClass.getModifiers()) && !loadedClass.isAnonymousClass()
            && !loadedClass.isLocalClass();
}

From source file:de.alpharogroup.lang.ClassExtensions.java

/**
 * Returns the name of the given class or null if the given class is null. If the given flag
 * 'simple' is true the simple name (without the package) will be returned.
 *
 * @param clazz//from  w ww .  j a v  a2s.co m
 *            The class
 * @param simple
 *            The flag if the simple name should be returned.
 *
 * @return The name of the given class or if the given flag 'simple' is true the simple name
 *         (without the package) will be returned.
 */
public static String getName(Class<?> clazz, final boolean simple) {
    String name = null;
    if (clazz != null) {
        while (clazz.isAnonymousClass()) {
            clazz = clazz.getSuperclass();
        }
        if (simple) {
            name = clazz.getSimpleName();
        } else {
            name = clazz.getName();
        }
    }
    return name;
}

From source file:adalid.core.XS1.java

static Class<?> getNamedClass(Class<?> clazz) {
    assert clazz != null;
    return clazz.isAnonymousClass() ? clazz.getSuperclass() : clazz;
}

From source file:xiaofei.library.hermes.util.TypeUtils.java

public static void validateClass(Class<?> clazz) {
    if (clazz == null) {
        throw new IllegalArgumentException("Class object is null.");
    }/*from   w  ww .ja  va 2 s.co m*/
    if (clazz.isPrimitive() || clazz.isInterface()) {
        return;
    }
    if (clazz.isAnnotationPresent(WithinProcess.class)) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Class with a WithinProcess annotation presented on it cannot be accessed"
                + " from outside the process.");
    }

    if (clazz.isAnonymousClass()) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Anonymous class cannot be accessed from outside the process.");
    }
    if (clazz.isLocalClass()) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Local class cannot be accessed from outside the process.");
    }
    if (Context.class.isAssignableFrom(clazz)) {
        return;
    }
    if (Modifier.isAbstract(clazz.getModifiers())) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Abstract class cannot be accessed from outside the process.");
    }
}

From source file:adalid.core.XS1.java

static Class<?> getConcreteSuperclass(Class<?> c) {
    if (c == null) {
        return null;
    }//from w ww.  j a  v a  2s .c  o m
    Class<?> s = c.getSuperclass();
    if (s == null) {
        return null;
    }
    if (c.isAnonymousClass()) {
        return getConcreteSuperclass(s);
    }
    int modifiers = s.getModifiers();
    if (Modifier.isAbstract(modifiers)) {
        return null;
    }
    if (s.getSimpleName().equals(c.getSimpleName())) {
        return getConcreteSuperclass(s);
    }
    return s;
}

From source file:org.evosuite.setup.TestUsageChecker.java

public static boolean canUse(Class<?> c) {
    //if (Throwable.class.isAssignableFrom(c))
    //   return false;
    if (Modifier.isPrivate(c.getModifiers()))
        return false;

    if (!Properties.USE_DEPRECATED && c.isAnnotationPresent(Deprecated.class)) {
        final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();

        if (Properties.hasTargetClassBeenLoaded() && !c.equals(targetClass)) {
            logger.debug("Skipping deprecated class " + c.getName());
            return false;
        }/*from   ww w .j a  v  a2s.c om*/
    }

    if (c.isAnonymousClass()) {
        return false;
    }

    if (c.getName().startsWith("junit"))
        return false;

    if (TestClusterUtils.isEvoSuiteClass(c) && !MockList.isAMockClass(c.getCanonicalName())) {
        return false;
    }

    if (c.getEnclosingClass() != null) {
        if (!canUse(c.getEnclosingClass()))
            return false;
    }

    if (c.getDeclaringClass() != null) {
        if (!canUse(c.getDeclaringClass()))
            return false;
    }

    // If the SUT is not in the default package, then
    // we cannot import classes that are in the default
    // package
    if (!c.isArray() && !c.isPrimitive() && !Properties.CLASS_PREFIX.isEmpty() && !c.getName().contains(".")) {
        return false;
    }

    if (c.getName().contains("EnhancerByMockito")) {
        return false;
    }

    // TODO: This should be unnecessary if Java reflection works...
    // This is inefficient
    if (TestClusterUtils.isAnonymousClass(c.getName())) {
        String message = c + " looks like an anonymous class, ignoring it (although reflection says "
                + c.isAnonymousClass() + ") " + c.getSimpleName();
        LoggingUtils.logWarnAtMostOnce(logger, message);
        return false;
    }

    if (Modifier.isPublic(c.getModifiers())) {
        return true;
    }

    // If default access rights, then check if this class is in the same package as the target class
    if (!Modifier.isPrivate(c.getModifiers())) {
        //              && !Modifier.isProtected(c.getModifiers())) {
        String packageName = ClassUtils.getPackageName(c);
        if (packageName.equals(Properties.CLASS_PREFIX)) {
            return true;
        }
    }

    logger.debug("Not public");
    return false;
}

From source file:adalid.core.XS1.java

private static boolean isRestrictedFieldType(Class<?> fieldType) {
    int modifiers = fieldType.getModifiers();
    boolean b = fieldType.isPrimitive();
    b |= Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers);
    b |= fieldType.isAnnotation();// ww  w . j  a v a  2 s .  c  o m
    b |= fieldType.isAnonymousClass();
    b |= fieldType.isArray();
    b |= fieldType.isEnum();
    b |= fieldType.isLocalClass();
    b |= fieldType.isInterface();
    return b;
}

From source file:gobblin.instrumented.Instrumented.java

/**
 * Get a {@link gobblin.metrics.MetricContext} to be used by an object needing instrumentation.
 *
 * <p>//from   ww w. j  a  v a2s  . co m
 * This method will read the property "metrics.context.name" from the input State, and will attempt
 * to find a MetricContext with that name in the global instance of {@link gobblin.metrics.GobblinMetricsRegistry}.
 * If it succeeds, the generated MetricContext will be a child of the retrieved Context, otherwise it will
 * be a parent-less context.
 * </p>
 * <p>
 * The method will automatically add two tags to the context:
 * <ul>
 *  <li> construct will contain the name of the {@link gobblin.Constructs} that klazz represents. </li>
 *  <li> class will contain the canonical name of the input class. </li>
 * </ul>
 * </p>
 *
 * @param state {@link gobblin.configuration.State} used to find the parent MetricContext.
 * @param klazz Class of the object needing instrumentation.
 * @param tags Additional tags to add to the returned context.
 * @return A {@link gobblin.metrics.MetricContext} with the appropriate tags and parent.
 */
public static MetricContext getMetricContext(State state, Class<?> klazz, List<Tag<?>> tags) {
    int randomId = RAND.nextInt(Integer.MAX_VALUE);

    List<Tag<?>> generatedTags = Lists.newArrayList();
    Constructs construct = null;
    if (Converter.class.isAssignableFrom(klazz)) {
        construct = Constructs.CONVERTER;
    } else if (ForkOperator.class.isAssignableFrom(klazz)) {
        construct = Constructs.FORK_OPERATOR;
    } else if (RowLevelPolicy.class.isAssignableFrom(klazz)) {
        construct = Constructs.ROW_QUALITY_CHECKER;
    } else if (Extractor.class.isAssignableFrom(klazz)) {
        construct = Constructs.EXTRACTOR;
    } else if (DataWriter.class.isAssignableFrom(klazz)) {
        construct = Constructs.WRITER;
    }

    if (construct != null) {
        generatedTags.add(new Tag<>(GobblinMetricsKeys.CONSTRUCT_META, construct.toString()));
    }
    if (!klazz.isAnonymousClass()) {
        generatedTags.add(new Tag<>(GobblinMetricsKeys.CLASS_META, klazz.getCanonicalName()));
    }

    Optional<GobblinMetrics> gobblinMetrics = state.contains(METRIC_CONTEXT_NAME_KEY)
            ? GobblinMetricsRegistry.getInstance().get(state.getProp(METRIC_CONTEXT_NAME_KEY))
            : Optional.<GobblinMetrics>absent();

    MetricContext.Builder builder = gobblinMetrics.isPresent()
            ? gobblinMetrics.get().getMetricContext().childBuilder(klazz.getCanonicalName() + "." + randomId)
            : MetricContext.builder(klazz.getCanonicalName() + "." + randomId);
    return builder.addTags(generatedTags).addTags(tags).build();
}

From source file:edu.northwestern.bioinformatics.studycalendar.domain.delta.DeltaNodeTypeTest.java

public void testThereIsOneDeltaNodeTypePerDeltaClass() throws Exception {
    List<String> errors = new ArrayList<String>();
    for (Class<? extends Delta> deltaClass : domainReflections.getSubTypesOf(Delta.class)) {
        if (Modifier.isAbstract(deltaClass.getModifiers()) || deltaClass.isAnonymousClass())
            continue;
        try {//www.  j av  a 2 s  .c  o  m
            DeltaNodeType.valueForDeltaClass(deltaClass);
        } catch (IllegalArgumentException iae) {
            errors.add(iae.getMessage());
        }
    }

    if (!errors.isEmpty()) {
        fail("* " + StringUtils.join(errors.iterator(), "\n* "));
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.domain.delta.DeltaNodeTypeTest.java

public void testThereIsOneDeltaNodeTypePerChangeableClass() throws Exception {
    List<String> errors = new ArrayList<String>();
    for (Class<? extends Changeable> cClass : domainReflections.getSubTypesOf(Changeable.class)) {
        if (Modifier.isAbstract(cClass.getModifiers()) || cClass.isAnonymousClass())
            continue;
        try {/*from  w  ww .  j  a v  a  2s  . co m*/
            DeltaNodeType.valueForNodeClass(cClass);
        } catch (IllegalArgumentException iae) {
            errors.add(iae.getMessage());
        }
    }

    if (!errors.isEmpty()) {
        fail("* " + StringUtils.join(errors.iterator(), "\n* "));
    }
}