List of usage examples for java.lang Class isAnonymousClass
public boolean isAnonymousClass()
From source file:Main.java
public static void main(String[] args) { Main c = new Main(); Class cls = c.getClass(); // returns the name of the class String name = cls.getName();/*from w w w .j a v a 2 s . c om*/ System.out.println("Class Name = " + name); // returns true if this class is an anonymous class boolean retval = cls.isAnonymousClass(); System.out.println(retval); }
From source file:Main.java
public static String getProcessName(Class<?> clazz) { if (clazz.isAnonymousClass()) { return getProcessName(clazz.getEnclosingClass()); }/*w w w. j a v a 2 s. co m*/ return clazz.getSimpleName(); }
From source file:Main.java
public static Class<?> messageClass(Object message) { final Class<?> messageClass = message.getClass(); if (messageClass.isAnonymousClass() || messageClass.getSimpleName().contains("-$Lambda$") // Jack || messageClass.getSimpleName().contains("$$Lambda$") // Retrolambda )//from w w w.jav a 2s . c o m return messageClass.getInterfaces()[0]; return messageClass; }
From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java
private static void addImmutableTypeTo(final Set<Class<?>> target, final Class<?> type) { if (target.contains(type)) { return;/* w w w . j ava 2 s . c o m*/ } Class<?> c = type; while (c.isAnonymousClass()) { c = c.getEnclosingClass(); } if (target.contains(c) && !target.equals(c) || StringUtils.startsWithAny(c.getSimpleName().toLowerCase(Locale.US), KNOWN_IMMUTABLE_PREFIXES)) { target.add(type); } }
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.anathema_roguelike.main.utilities.Utils.java
static String getProperty(Properties properties, Object obj, String defaultValue) { if (!(obj instanceof Class)) { if (obj instanceof String) { return (String) obj; }// w ww. j av a 2 s . c om obj = obj.getClass(); } Class<?> cls = (Class<?>) obj; while (cls.isAnonymousClass()) { cls = cls.getEnclosingClass(); } String property = properties.getProperty(cls.getSimpleName()); if (property != null) { return property; } else { return defaultValue; } }
From source file:com.anathema_roguelike.main.utilities.Utils.java
static Class<?> classify(Object obj) { Class<?> cls; if (obj instanceof Class) { cls = (Class<?>) obj; } else {/*from w ww . j a v a 2s . c o m*/ cls = obj.getClass(); } while (cls.isAnonymousClass()) { cls = cls.getEnclosingClass(); } return cls; }
From source file:com.github.dozermapper.core.util.MappingUtils.java
/** * Used to test if {@code srcFieldClass} is enum. * * @param srcFieldClass the source field to be tested. * @return {@code true} if and only if current running JRE is 1.5 or above, and * {@code srcFieldClass} is enum; otherwise return {@code false}. *///from ww w . ja va 2 s . c o m public static boolean isEnumType(Class<?> srcFieldClass) { if (srcFieldClass.isAnonymousClass()) { //If srcFieldClass is anonymous class, replace srcFieldClass with its enclosing class. //This is used to ensure Dozer can get correct Enum type. srcFieldClass = srcFieldClass.getEnclosingClass(); } return srcFieldClass.isEnum(); }
From source file:org.springframework.jdbc.core.JdbcOperationsUtils.java
public static final void validatePropertyValue(String id, String propName, Object propValue, ConversionService converter) {//from w w w .j a va2 s . co m if (StringUtils.isEmpty(propName)) { throw new IllegalStateException("validatePropertyValue(" + id + ") no property name"); } if (propValue == null) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "] no value"); } if (!(propValue instanceof Serializable)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "] not serializable"); } Class<?> propType = resolveEffectivePropertyType(propValue); if (Date.class.isAssignableFrom(propType) || Calendar.class.isAssignableFrom(propType)) { return; // Date(s) have a special handling } if (propType == Class.class) { Class<?> valueClass = (Class<?>) propValue; if (Proxy.isProxyClass(valueClass)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "] proxies N/A"); } if (valueClass.isAnonymousClass()) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " anonymous classes N/A: " + valueClass.getName()); } if (valueClass.isLocalClass()) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " local classes N/A: " + valueClass.getName()); } if (valueClass.isArray()) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " array classes N/A: " + valueClass.getName()); } int mods = valueClass.getModifiers(); if (!Modifier.isPublic(mods)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " non-public classes N/A: " + valueClass.getName()); } } if (!converter.canConvert(String.class, propType)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " cannot convert a string to a " + propType.getSimpleName()); } }
From source file:ma.glasnost.orika.test.perf.MultiThreadedTestCase.java
private static Set<Class<?>> getNonAnonymousClasses() { Set<Class<?>> classes = new HashSet<Class<?>>(); File classFolder;/*from w ww.j av a 2s .c om*/ try { classFolder = new File( URLDecoder.decode(MultiThreadedTestCase.class.getResource("/").getFile(), "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } List<Class<?>> allClasses = DynamicSuite.findTestCases(classFolder, ".*"); for (Class<?> aClass : allClasses) { if (!aClass.isAnonymousClass()) { classes.add(aClass); } } return classes; }