Example usage for java.lang Class isSynthetic

List of usage examples for java.lang Class isSynthetic

Introduction

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

Prototype

public boolean isSynthetic() 

Source Link

Document

Returns true if this class is a synthetic class; returns false otherwise.

Usage

From source file:Main.java

public static void main(String[] args) {

    Main c = new Main();
    Class cls = c.getClass();

    // returns true if this class is a synthetic class, else false
    boolean retval = cls.isSynthetic();
    System.out.println(retval);/* w  w w .j  av  a  2  s.c om*/
}

From source file:org.lunarray.model.descriptor.creational.util.CreationalScanUtil.java

/**
 * Find a no-args public constructor.//from  w  ww.  j  ava2  s  . c o m
 * 
 * @param source
 *            The source class. May not be null.
 * @return The constructor, or null.
 * @param <E>
 *            The entity type.
 */
@SuppressWarnings("unchecked")
public static <E> Constructor<E> findConstructor(final Class<E> source) {
    Validate.notNull(source, "Source may not be null.");
    Constructor<E> result = null;
    if (!Modifier.isAbstract(source.getModifiers()) && !source.isSynthetic()) {
        for (final Constructor<E> constructor : (Constructor<E>[]) source.getConstructors()) {
            if (!constructor.isSynthetic() && (constructor.getParameterTypes().length == 0)) {
                result = constructor;
            }
        }
    }
    return result;
}

From source file:com.edmunds.autotest.ClassUtil.java

public static boolean isStandardClass(Class cls) {
    return !(((cls.getModifiers() & Modifier.ABSTRACT) > 0) || cls.isInterface() || cls.isMemberClass()
            || cls.isLocalClass() || cls.isSynthetic());
}

From source file:net.jodah.typetools.TypeResolver.java

/**
 * Returns an array of raw classes representing arguments for the {@code genericType} using type variable information
 * from the {@code subType}. Arguments for {@code genericType} that cannot be resolved are returned as
 * {@code Unknown.class}. If no arguments can be resolved then {@code null} is returned.
 *
 * @param genericType to resolve arguments for
 * @param subType to extract type variable information from
 * @return array of raw classes representing arguments for the {@code genericType} else {@code null} if no type
 *         arguments are declared/*from  w  ww . j  a  v  a  2  s  . c  o m*/
 */
public static Class<?>[] resolveRawArguments(Type genericType, Class<?> subType) {
    Class<?>[] result = null;
    Class<?> functionalInterface = null;

    // Handle lambdas
    if (SUPPORTS_LAMBDAS && subType.isSynthetic()) {
        Class<?> fi = genericType instanceof ParameterizedType
                && ((ParameterizedType) genericType).getRawType() instanceof Class
                        ? (Class<?>) ((ParameterizedType) genericType).getRawType()
                        : genericType instanceof Class ? (Class<?>) genericType : null;
        if (fi != null && fi.isInterface())
            functionalInterface = fi;
    }

    if (genericType instanceof ParameterizedType) {
        ParameterizedType paramType = (ParameterizedType) genericType;
        Type[] arguments = paramType.getActualTypeArguments();
        result = new Class[arguments.length];
        for (int i = 0; i < arguments.length; i++)
            result[i] = resolveRawClass(arguments[i], subType, functionalInterface);
    } else if (genericType instanceof TypeVariable) {
        result = new Class[1];
        result[0] = resolveRawClass(genericType, subType, functionalInterface);
    } else if (genericType instanceof Class) {
        TypeVariable<?>[] typeParams = ((Class<?>) genericType).getTypeParameters();
        result = new Class[typeParams.length];
        for (int i = 0; i < typeParams.length; i++)
            result[i] = resolveRawClass(typeParams[i], subType, functionalInterface);
    }

    return result;
}

From source file:hu.bme.mit.sette.common.validator.reflection.ClassValidator.java

/**
 * Sets whether the Java class should be synthetic or not.
 *
 * @param isSynthetic//from   www. j a  v a2  s.  c  o m
 *            true if the Java class should be synthetic, false if it should
 *            not be
 * @return this object
 */
public ClassValidator synthetic(final boolean isSynthetic) {
    if (getSubject() != null) {
        Class<?> javaClass = getSubject();

        if (isSynthetic ^ javaClass.isSynthetic()) {
            String must;

            if (isSynthetic) {
                must = "must";
            } else {
                must = "must not";
            }

            this.addException(String.format("The Java class %s be synthetic", must));
        }
    }

    return this;
}

From source file:name.ikysil.beanpathdsl.codegen.Context.java

private boolean isExcluded(Class<?> clazz) {
    if (clazz.isPrimitive() || clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isInterface()
            || clazz.isSynthetic() || clazz.isEnum() || !Modifier.isPublic(clazz.getModifiers())
            || (clazz.getPackage() == null)) {
        return true;
    }//from w  w  w  .ja  va  2  s  . c  o m
    IncludedClass includedConfig = includedClasses.get(clazz);
    if (includedConfig != null) {
        return false;
    }
    ExcludedClass excludedConfig = excludedClasses.get(clazz);
    if (excludedConfig != null) {
        return true;
    }
    for (ExcludedPackage excludedPackage : excludedPackages) {
        if (excludedPackage.match(clazz.getPackage())) {
            return true;
        }
    }
    return false;
}

From source file:com.feilong.core.lang.ClassUtilTest.java

/**
 *  class info map for LOGGER./*from  w w w  .  j  a va 2 s. c  o  m*/
 *
 * @param klass
 *            the klass
 * @return  <code>klass</code> nullempty, {@link Collections#emptyMap()}<br>
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {
    if (isNullOrEmpty(klass)) {
        return Collections.emptyMap();
    }

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getName()", klass.getName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern"

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?"". ,voidboolean?byte?char?short?int?long?float  double?.
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ?"".,.
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ?"?".?,?,?"""??".
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class?"??".java??false,?true.,JVM???,java??"??"?
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true.
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
}

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

/**
 * Gets the {@link ClassType} from the given class.
 *
 * @param clazz/*from www  .  java2s . c om*/
 *            The class.
 * @return the {@link ClassType} from the given class.
 */
public static ClassType getClassType(final Class<?> clazz) {
    if (clazz.isArray()) {
        return ClassType.ARRAY;
    }
    if (isCollection(clazz)) {
        return ClassType.COLLECTION;
    }
    if (isMap(clazz)) {
        return ClassType.MAP;
    }
    if (clazz.isLocalClass()) {
        return ClassType.LOCAL;
    }
    if (clazz.isMemberClass()) {
        return ClassType.MEMBER;
    }
    if (clazz.isPrimitive()) {
        return ClassType.PRIMITIVE;
    }
    if (clazz.isAnnotation()) {
        return ClassType.ANNOTATION;
    }
    if (clazz.isEnum()) {
        return ClassType.ENUM;
    }
    if (clazz.isInterface()) {
        return ClassType.INTERFACE;
    }
    if (clazz.isSynthetic()) {
        return ClassType.SYNTHETIC;
    }
    if (clazz.isAnonymousClass()) {
        return ClassType.ANONYMOUS;
    }
    return ClassType.DEFAULT;
}

From source file:com.discovery.darchrow.lang.ClassUtil.java

/**
 *  class info map for LOGGER.//from  w w  w  .ja  v a 2 s.co m
 *
 * @param klass
 *            the clz
 * @return the map for log
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {
    if (Validator.isNullOrEmpty(klass)) {
        return null;
    }

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getName()", klass.getName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern"

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?? voidboolean?byte?char?short?int?long?float  double?
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ??,
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ????,??????
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class????java??false?trueJVM???java??????
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
}

From source file:com.sunchenbin.store.feilong.core.lang.ClassUtil.java

/**
 *  class info map for LOGGER.// w w  w  .  j av a2 s .  c o  m
 *
 * @param klass
 *            the clz
 * @return the map for log
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {
    if (Validator.isNullOrEmpty(klass)) {
        return Collections.emptyMap();
    }

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.sunchenbin.store.feilong.core.date.DatePattern"
    map.put("clz.getName()", klass.getName());//"com.sunchenbin.store.feilong.core.date.DatePattern"
    map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern"

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?? ,voidboolean?byte?char?short?int?long?float  double?
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ??,
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ????,?,?????
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class????java??false,?true,JVM???,java??????
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
}