List of usage examples for java.lang Class isMemberClass
public boolean isMemberClass()
From source file:io.github.pellse.decorator.util.reflection.ReflectionUtils.java
public static boolean isNestedClass(Class<?> clazz) { return clazz.isMemberClass() || clazz.isLocalClass() || clazz.isAnonymousClass(); }
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:io.coala.json.JsonUtil.java
/** * @param om the {@link ObjectMapper} used to parse/deserialize/unmarshal * @param tree the partially parsed JSON {@link TreeNode} * @param resultType the type of result {@link Object} * @param imports the {@link Properties} instances for default values, etc. * @return the parsed/deserialized/unmarshalled {@link Object} */// w w w . j a v a 2 s. c o m public static <T> T valueOf(final ObjectMapper om, final TreeNode tree, final Class<T> resultType, final Properties... imports) { if (tree == null) return null; // TODO add work-around for Wrapper sub-types? if (resultType.isMemberClass() && !Modifier.isStatic(resultType.getModifiers())) return Thrower.throwNew(IllegalArgumentException.class, "Unable to deserialize non-static member: {}", resultType); try { return (T) om.treeToValue(tree, checkRegistered(om, resultType, imports)); } catch (final Exception e) { return Thrower.rethrowUnchecked(e); } }
From source file:org.modelmapper.internal.util.TypeResolver.java
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType) { Reference<Map<TypeVariable<?>, Type>> ref = typeVariableCache.get(targetType); Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null; if (map == null) { map = new HashMap<TypeVariable<?>, Type>(); // Populate interfaces buildTypeVariableMap(targetType.getGenericInterfaces(), map); // Populate super classes and interfaces Type genericType = targetType.getGenericSuperclass(); Class<?> type = targetType.getSuperclass(); while (type != null && !Object.class.equals(type)) { if (genericType instanceof ParameterizedType) buildTypeVariableMap((ParameterizedType) genericType, map); buildTypeVariableMap(type.getGenericInterfaces(), map); genericType = type.getGenericSuperclass(); type = type.getSuperclass(); }// www . j a va2 s. com // Populate enclosing classes type = targetType; while (type.isMemberClass()) { genericType = type.getGenericSuperclass(); if (genericType instanceof ParameterizedType) buildTypeVariableMap((ParameterizedType) genericType, map); type = type.getEnclosingClass(); } typeVariableCache.put(targetType, new WeakReference<Map<TypeVariable<?>, Type>>(map)); } return map; }
From source file:antre.TypeResolver.java
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType) { Reference<Map<TypeVariable<?>, Type>> ref = typeVariableCache.get(targetType); Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null; if (map == null) { map = new HashMap<TypeVariable<?>, Type>(); // Populate interfaces buildTypeVariableMap(targetType.getGenericInterfaces(), map); // Populate super classes and interfaces Type genericType = targetType.getGenericSuperclass(); Class<?> type = targetType.getSuperclass(); while (type != null && !Object.class.equals(type)) { if (genericType instanceof ParameterizedType) buildTypeVariableMap((ParameterizedType) genericType, map); buildTypeVariableMap(type.getGenericInterfaces(), map); genericType = type.getGenericSuperclass(); type = type.getSuperclass(); }// ww w.java 2 s . com // Populate enclosing classes type = targetType; while (type.isMemberClass()) { genericType = type.getGenericSuperclass(); if (genericType instanceof ParameterizedType) buildTypeVariableMap((ParameterizedType) genericType, map); type = type.getEnclosingClass(); } if (cacheEnabled) typeVariableCache.put(targetType, new WeakReference<Map<TypeVariable<?>, Type>>(map)); } return map; }
From source file:io.werval.runtime.util.TypeResolver.java
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType) { Reference<Map<TypeVariable<?>, Type>> ref = CACHE.get(targetType); Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null; if (map == null) { map = new HashMap<>(); // Populate interfaces buildTypeVariableMap(targetType.getGenericInterfaces(), map); // Populate super classes and interfaces Type genericType = targetType.getGenericSuperclass(); Class<?> type = targetType.getSuperclass(); while (type != null && !Object.class.equals(type)) { if (genericType instanceof ParameterizedType) { buildTypeVariableMap((ParameterizedType) genericType, map); }// ww w .j a v a 2 s .c o m buildTypeVariableMap(type.getGenericInterfaces(), map); genericType = type.getGenericSuperclass(); type = type.getSuperclass(); } // Populate enclosing classes type = targetType; while (type.isMemberClass()) { genericType = type.getGenericSuperclass(); if (genericType instanceof ParameterizedType) { buildTypeVariableMap((ParameterizedType) genericType, map); } type = type.getEnclosingClass(); } if (cacheEnabled) { CACHE.put(targetType, new WeakReference<>(map)); } } return map; }
From source file:net.jodah.typetools.TypeResolver.java
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType, Class<?> functionalInterface) { Reference<Map<TypeVariable<?>, Type>> ref = typeVariableCache.get(targetType); Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null; if (map == null) { map = new HashMap<TypeVariable<?>, Type>(); // Populate lambdas if (functionalInterface != null) populateLambdaArgs(functionalInterface, targetType, map); // Populate interfaces populateSuperTypeArgs(targetType.getGenericInterfaces(), map, functionalInterface != null); // Populate super classes and interfaces Type genericType = targetType.getGenericSuperclass(); Class<?> type = targetType.getSuperclass(); while (type != null && !Object.class.equals(type)) { if (genericType instanceof ParameterizedType) populateTypeArgs((ParameterizedType) genericType, map, false); populateSuperTypeArgs(type.getGenericInterfaces(), map, false); genericType = type.getGenericSuperclass(); type = type.getSuperclass(); }/*from www .j a va 2 s.c o m*/ // Populate enclosing classes type = targetType; while (type.isMemberClass()) { genericType = type.getGenericSuperclass(); if (genericType instanceof ParameterizedType) populateTypeArgs((ParameterizedType) genericType, map, functionalInterface != null); type = type.getEnclosingClass(); } if (CACHE_ENABLED) typeVariableCache.put(targetType, new WeakReference<Map<TypeVariable<?>, Type>>(map)); } return map; }
From source file:de.alpharogroup.lang.ClassExtensions.java
/** * Gets the {@link ClassType} from the given class. * * @param clazz/*from w w w . j av a 2s .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.feilong.core.lang.ClassUtilTest.java
/** * class info map for LOGGER./*from ww w . j av a 2s. c om*/ * * @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:adalid.core.XS1.java
static Object initialiseField(Object declaringObject, Field declaringField) { if (declaringObject == null || declaringField == null) { return null; }//from w w w .j a va2s. c o m String declaringFieldName = declaringField.getName(); Class<?> declaringFieldType = declaringField.getType(); if (NamedValue.class.equals(declaringFieldType)) { return NamedValueCache.getInstance(declaringFieldName); } String fieldName = declaringFieldName; Class<?> fieldType = getFieldType(declaringFieldType); if (fieldType == null) { return null; } Object instance = null; Class<?> declaringClass = declaringObject.getClass(); Class<?> enclosingClass = fieldType.getEnclosingClass(); boolean memberClass = fieldType.isMemberClass(); Entity declaringEntity = declaringObject instanceof Entity ? (Entity) declaringObject : null; Artifact declaringArtifact = declaringObject instanceof Artifact ? (Artifact) declaringObject : null; boolean declaringArtifactIsParameter = false; if (declaringObject instanceof DataArtifact) { DataArtifact declaringDataArtifact = (DataArtifact) declaringObject; declaringArtifactIsParameter = declaringDataArtifact.isParameter(); } String errmsg = "failed to create a new instance of field " + declaringField + " at " + declaringObject; try { CastingField castingFieldAnnotation = getCastingFieldAnnotation(declaringField, fieldType); if (castingFieldAnnotation != null) { String name = castingFieldAnnotation.value(); Field field = getFieldToBeCasted(true, fieldName, name, declaringClass, fieldType); if (field != null) { errmsg = "failed to set casting field " + declaringField + " at " + declaringObject; instance = field.get(declaringObject); // if (instance == null) { // logFieldErrorMessage(fieldName, name, declaringClass, field, "field " + name + " is not allocated"); // } } } else if (memberClass && enclosingClass != null && enclosingClass.isAssignableFrom(declaringClass)) { if (Operation.class.isAssignableFrom(fieldType)) { if (declaringArtifact == null) { instance = fieldType.getConstructor(enclosingClass).newInstance(declaringObject); } else if (declaringEntity == null) { TLC.setDeclaringArtifact(declaringArtifact); instance = fieldType.getConstructor(enclosingClass).newInstance(declaringObject); TLC.removeDeclaringArtifact(); } else { String key = fieldType.getSimpleName(); Map<String, Class<?>> map = declaringEntity.getOperationClassesMap(); Class<?> fieldTypeX = map.containsKey(key) ? map.get(key) : fieldType; Class<?> enclosingClassX = fieldTypeX.getEnclosingClass(); TLC.setDeclaringArtifact(declaringArtifact); instance = fieldTypeX.getConstructor(enclosingClassX).newInstance(declaringObject); TLC.removeDeclaringArtifact(); } } else { instance = fieldType.getConstructor(enclosingClass).newInstance(declaringObject); } } else if (enclosingClass == null) { if (Entity.class.isAssignableFrom(fieldType)) { if (declaringArtifact == null) { instance = fieldType.newInstance(); } else { // Method method = fieldType.getMethod(GET_INSTANCE, new Class<?>[]{Artifact.class}); // instance = method.invoke(null, declaringObject); Class<?> type = getTrueType(fieldType); checkAbstractClassReference(declaringField, type); String path = declaringArtifact.getClassPath(); int depth = declaringArtifact.depth() + 1; int round = round(type, declaringArtifact); TLC.getProject().getParser().setMaxDepthReached(depth); TLC.getProject().getParser().setMaxRoundReached(round); FieldAllocationSettings settings = new FieldAllocationSettings(declaringField, declaringObject, depth, round); int maxDepth = settings.getMaxDepth(); int maxRound = settings.getMaxRound(); String method1 = "allocate(maxDepth={0}, maxRound={1})"; String method2 = MessageFormat.format(method1, maxDepth, maxRound); String remark1 = "maxDepth<" + depth; String remark2 = "maxRound<" + round; String pattern; String remarks; if (declaringArtifactIsParameter || declaringArtifact.depth() == 0 || (depth <= maxDepth && round <= maxRound)) { TLC.getProject().getParser().track(depth, round, path, type, fieldName, method2, null); instance = type.getConstructor(Artifact.class, Field.class).newInstance(declaringObject, declaringField); TLC.getProject().getParser().increaseEntityCount(); } else { pattern = "{1}, {0} not allocated"; if (depth > maxDepth) { remarks = MessageFormat.format(pattern, fieldName, remark1); TLC.getProject().getParser().alert(depth, round, path, type, fieldName, method2, remarks); } if (round > maxRound) { remarks = MessageFormat.format(pattern, fieldName, remark2); TLC.getProject().getParser().alert(depth, round, path, type, fieldName, method2, remarks); } } } } else { instance = fieldType.newInstance(); } } if (instance instanceof AbstractArtifact) { // do not declare here; it will be declared at the corresponding finalise method AbstractArtifact abstractArtifact = (AbstractArtifact) instance; abstractArtifact.setName(fieldName); abstractArtifact.setDeclaringArtifact(declaringArtifact); abstractArtifact.setDeclaringField(declaringField); if (instance instanceof VariantX) { VariantX variantX = (VariantX) instance; variantX.setDataType(declaringFieldType); } } } catch (IllegalArgumentException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException ex) { throw new InstantiationRuntimeException(errmsg, ex); } return instance; }