List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.apache.usergrid.services.DBServiceManager.java
@SuppressWarnings("unchecked") private static Class<Service> findClass(String classname) { Class<Service> cls; try {//from w w w . j av a2 s. co m if (logger.isTraceEnabled()) { logger.trace("Attempting to instantiate service class {}", classname); } cls = (Class<Service>) Class.forName(classname); if (cls.isInterface()) { cls = (Class<Service>) Class.forName(classname.concat(IMPL)); } if ((cls != null) && !Modifier.isAbstract(cls.getModifiers())) { return cls; } } catch (ClassNotFoundException e1) { if (logger.isTraceEnabled()) { logger.trace("Could not find class", e1); } } return null; }
From source file:adalid.core.XS1.java
static Class<?> getConcreteSuperclass(Class<?> c) { if (c == null) { return null; }/*from w w w. j a v a 2s . co 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.lanternpowered.server.data.manipulator.gen.DataManipulatorGenerator.java
private static List<Method> findValueMethods(Class<?>... targetClasses) { final Set<Method> methods = new HashSet<>(); for (Class<?> targetClass : targetClasses) { for (Method method : targetClass.getMethods()) { if (!Modifier.isAbstract(method.getModifiers())) { continue; }/*w w w . ja va2s. co m*/ if (BaseValue.class.isAssignableFrom(method.getReturnType()) && method.getParameterTypes().length == 0) { boolean add = true; for (Class<?> clazz : targetClasses) { if (clazz != targetClass) { try { final Method method1 = clazz.getMethod(method.getName(), method.getParameterTypes()); if (!Modifier.isAbstract(method1.getModifiers())) { add = false; break; } } catch (NoSuchMethodException ignored) { } } } if (add) { methods.add(method); } } } } return new ArrayList<>(methods); }
From source file:org.lightjason.agentspeak.common.CCommon.java
/** * reads all methods by the action-annotations * for building agent-actions/*w ww . j a v a 2s . c om*/ * * @param p_class class * @param p_root root class * @return stream of all methods with inheritance */ private static Stream<Method> methods(final Class<?> p_class, final Class<?> p_root) { final Pair<Boolean, IAgentAction.EAccess> l_classannotation = CCommon.isActionClass(p_class); if (!l_classannotation.getLeft()) return p_class.getSuperclass() == null ? Stream.of() : methods(p_class.getSuperclass(), p_root); final Predicate<Method> l_filter = IAgentAction.EAccess.WHITELIST.equals(l_classannotation.getRight()) ? i -> !CCommon.isActionFiltered(i, p_root) : i -> CCommon.isActionFiltered(i, p_root); return Stream.concat(Arrays.stream(p_class.getDeclaredMethods()).parallel().map(i -> { i.setAccessible(true); return i; }).filter(i -> !Modifier.isAbstract(i.getModifiers())).filter(i -> !Modifier.isInterface(i.getModifiers())) .filter(i -> !Modifier.isNative(i.getModifiers())).filter(i -> !Modifier.isStatic(i.getModifiers())) .filter(l_filter), methods(p_class.getSuperclass(), p_root)); }
From source file:com.twinsoft.convertigo.beans.CheckBeans.java
private static void analyzeJavaClass(String javaClassName) { try {/*from w w w.j av a 2 s .com*/ Class<?> javaClass = Class.forName(javaClassName); String javaClassSimpleName = javaClass.getSimpleName(); if (!DatabaseObject.class.isAssignableFrom(javaClass)) { //Error.NON_DATABASE_OBJECT.add(javaClassName); return; } nBeanClass++; String dboBeanInfoClassName = javaClassName + "BeanInfo"; MySimpleBeanInfo dboBeanInfo = null; try { dboBeanInfo = (MySimpleBeanInfo) (Class.forName(dboBeanInfoClassName)).newInstance(); } catch (ClassNotFoundException e) { if (!Modifier.isAbstract(javaClass.getModifiers())) { Error.MISSING_BEAN_INFO .add(javaClassName + " (expected bean info: " + dboBeanInfoClassName + ")"); } return; } catch (Exception e) { e.printStackTrace(); return; } BeanDescriptor beanDescriptor = dboBeanInfo.getBeanDescriptor(); // Check abstract class if (Modifier.isAbstract(javaClass.getModifiers())) { // Check icon (16x16) String declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_16x16); if (declaredIconName != null) { Error.ABSTRACT_CLASS_WITH_ICON.add(javaClassName); } // Check icon (32x32) declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_32x32); if (declaredIconName != null) { Error.ABSTRACT_CLASS_WITH_ICON.add(javaClassName); } // Check display name if (!beanDescriptor.getDisplayName().equals("?")) { Error.ABSTRACT_CLASS_WITH_DISPLAY_NAME.add(javaClassName); } // Check description if (!beanDescriptor.getShortDescription().equals("?")) { Error.ABSTRACT_CLASS_WITH_DESCRIPTION.add(javaClassName); } } else { nBeanClassNotAbstract++; // Check bean declaration in database_objects.xml if (!dboXmlDeclaredDatabaseObjects.contains(javaClassName)) { Error.BEAN_DEFINED_BUT_NOT_USED.add(javaClassName); } // Check icon name policy (16x16) String declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_16x16); String expectedIconName = javaClassName.replace(javaClassSimpleName, "images/" + javaClassSimpleName); expectedIconName = "/" + expectedIconName.replace('.', '/') + "_color_16x16"; expectedIconName = expectedIconName.toLowerCase() + ".png"; if (declaredIconName != null) { if (!declaredIconName.equals(expectedIconName)) { Error.BEAN_ICON_NAMING_POLICY.add(javaClassName + "\n" + " Declared: " + declaredIconName + "\n" + " Expected: " + expectedIconName); } } // Check icon file (16x16) File iconFile = new File(srcBase + declaredIconName); if (!iconFile.exists()) { Error.BEAN_MISSING_ICON.add(javaClassName + " - icon missing: " + declaredIconName); } else { icons.remove(declaredIconName); } // Check icon name policy (32x32) declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_32x32); expectedIconName = javaClassName.replace(javaClassSimpleName, "images/" + javaClassSimpleName); expectedIconName = "/" + expectedIconName.replace('.', '/') + "_color_32x32"; expectedIconName = expectedIconName.toLowerCase() + ".png"; if (declaredIconName != null) { if (!declaredIconName.equals(expectedIconName)) { Error.BEAN_ICON_NAMING_POLICY.add(javaClassName + "\n" + " Declared: " + declaredIconName + "\n" + " Expected: " + expectedIconName); } } // Check icon file (32x32) iconFile = new File(srcBase + declaredIconName); if (!iconFile.exists()) { Error.BEAN_MISSING_ICON.add(javaClassName + " - icon missing: " + declaredIconName); } else { icons.remove(declaredIconName); } // Check display name if (beanDescriptor.getDisplayName().equals("?")) { Error.BEAN_MISSING_DISPLAY_NAME.add(javaClassName); } // Check description if (beanDescriptor.getShortDescription().equals("?")) { Error.BEAN_MISSING_DESCRIPTION.add(javaClassName); } } // Check declared bean properties PropertyDescriptor[] propertyDescriptors = dboBeanInfo.getLocalPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); try { javaClass.getDeclaredField(propertyName); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { try { // Try to find it in the upper classes javaClass.getField(propertyName); } catch (SecurityException e1) { // printStackTrace(); } catch (NoSuchFieldException e1) { Error.PROPERTY_DECLARED_BUT_NOT_FOUND.add(javaClassName + ": " + propertyName); } } } Method[] methods = javaClass.getDeclaredMethods(); List<Method> listMethods = Arrays.asList(methods); List<String> listMethodNames = new ArrayList<String>(); for (Method method : listMethods) { listMethodNames.add(method.getName()); } Field[] fields = javaClass.getDeclaredFields(); for (Field field : fields) { int fieldModifiers = field.getModifiers(); // Ignore static fields (constants) if (Modifier.isStatic(fieldModifiers)) continue; String fieldName = field.getName(); String errorMessage = javaClassName + ": " + field.getName(); // Check bean info PropertyDescriptor propertyDescriptor = isBeanProperty(fieldName, dboBeanInfo); if (propertyDescriptor != null) { // Check bean property name policy if (!propertyDescriptor.getName().equals(fieldName)) { Error.PROPERTY_NAMING_POLICY.add(errorMessage); } String declaredGetter = propertyDescriptor.getReadMethod().getName(); String declaredSetter = propertyDescriptor.getWriteMethod().getName(); String formattedFieldName = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); String expectedGetter = "get" + formattedFieldName; String expectedSetter = "set" + formattedFieldName; // Check getter name policy if (!declaredGetter.equals(expectedGetter)) { Error.GETTER_SETTER_DECLARED_EXPECTED_NAMES_MISMATCH .add(errorMessage + "\n" + " Declared getter: " + declaredGetter + "\n" + " Expected getter: " + expectedGetter); } // Check setter name policy if (!declaredSetter.equals(expectedSetter)) { Error.GETTER_SETTER_DECLARED_EXPECTED_NAMES_MISMATCH .add(errorMessage + "\n" + " Declared setter: " + declaredSetter + "\n" + " Expected setter: " + expectedSetter); } // Check required private modifiers for bean property if (!Modifier.isPrivate(fieldModifiers)) { Error.PROPERTY_NOT_PRIVATE.add(errorMessage); } // Check getter if (!listMethodNames.contains(declaredGetter)) { Error.GETTER_SETTER_DECLARED_BUT_NOT_FOUND .add(errorMessage + " - Declared getter not found: " + declaredGetter); } // Check setter if (!listMethodNames.contains(declaredSetter)) { Error.GETTER_SETTER_DECLARED_BUT_NOT_FOUND .add(errorMessage + " - Declared setter not found: " + declaredGetter); } // Check non transient modifier if (Modifier.isTransient(fieldModifiers)) { Error.PROPERTY_TRANSIENT.add(errorMessage); } } else if (!Modifier.isTransient(fieldModifiers)) { Error.FIELD_NOT_TRANSIENT.add(errorMessage); } } } catch (ClassNotFoundException e) { System.out.println("ERROR on " + javaClassName); e.printStackTrace(); } }
From source file:edu.cornell.med.icb.goby.modes.GenericToolsDriver.java
/** * Load the list of concrete modes./*from ww w .j av a 2 s. c om*/ */ private void loadModeMap() { final Map<String, Class> modeMap = MODES_MAP; final Map<String, Class> shortModeMap = SHORT_MODES_MAP; final Map<Class, String> shortModeReverseMap = SHORT_MODES_REVERSE_MAP; final Set<String> allShortModes = new HashSet<String>(); for (final String modeClassName : modesClassNamesList()) { try { LOG.debug("About to process modeClassName: " + modeClassName); final Class modeClass = Class.forName(modeClassName); if (Modifier.isAbstract(modeClass.getModifiers())) { // Ignore abstract classes continue; } // Since we're not abstract, we can make an instance final Object modeInstance = modeClass.newInstance(); if (modeInstance instanceof AbstractCommandLineMode) { final String modeName = ((AbstractCommandLineMode) modeInstance).getModeName(); final String shortModeName = ((AbstractCommandLineMode) modeInstance).getShortModeName(); // Make sure the class has a static field "MODE_NAME" if (modeName != null) { modeMap.put(modeName, modeClass); if (shortModeName != null) { if (!allShortModes.contains(shortModeName)) { shortModeMap.put(shortModeName, modeClass); shortModeReverseMap.put(modeClass, shortModeName); allShortModes.add(shortModeName); } else { // Do not offer short versions for which there are duplicates. One needs // to hand write versions of getShortModeName() for these classes. shortModeReverseMap.remove(shortModeMap.get(shortModeName)); shortModeMap.remove(shortModeName); } } } } } catch (ClassNotFoundException e) { System.err.println( "Could find a class for " + modeClassName + " ClassNotFoundException: " + e.getMessage()); } catch (IllegalAccessException e) { System.err.println("Could not find MODE_NAME for class " + modeClassName + " IllegalAccessException: " + e.getMessage()); } catch (InstantiationException e) { System.err.println("Could not find MODE_NAME for class " + modeClassName + " InstantiationException: " + e.getMessage()); } } }
From source file:org.gvnix.flex.FlexOperationsImpl.java
public void generateAll(JavaPackage javaPackage) { Set<ClassOrInterfaceTypeDetails> cids = typeLocationService .findClassesOrInterfaceDetailsWithAnnotation(new JavaType(RooJpaActiveRecord.class.getName())); for (ClassOrInterfaceTypeDetails cid : cids) { if (Modifier.isAbstract(cid.getModifier())) { continue; }/* ww w. j a va2s .com*/ JavaType javaType = cid.getName(); LogicalPath path = PhysicalTypeIdentifier.getPath(cid.getDeclaredByMetadataId()); JpaActiveRecordMetadata entityMetadata = (JpaActiveRecordMetadata) metadataService .get(JpaActiveRecordMetadata.createIdentifier(javaType, path)); if (entityMetadata == null || (!entityMetadata.isValid())) { continue; } // Check to see if this entity metadata has a flex scaffold metadata // listening to it String dwnstrmFlexScaffMDataId = FlexScaffoldMetadata.createIdentifier(javaType, path); if (dependencyRegistry.getDownstream(entityMetadata.getId()).contains(dwnstrmFlexScaffMDataId)) { // There is already Flex scaffolding this entity continue; } // to get here, there is no listening service, so add one JavaType service = new JavaType( javaPackage.getFullyQualifiedPackageName() + "." + javaType.getSimpleTypeName() + "Service"); createRemotingDestination(service, javaType); } }
From source file:lineage2.gameserver.scripts.Scripts.java
/** * Method load.//from ww w. j a v a2 s . c om * @param classes List<Class<?>> * @param target String * @return boolean */ private boolean load(List<Class<?>> classes, String target) { Collection<File> scriptFiles = Collections.emptyList(); File file = new File(Config.DATAPACK_ROOT, "data/scripts/" + target.replace(".", "/") + ".java"); if (file.isFile()) { scriptFiles = new ArrayList<>(1); scriptFiles.add(file); } else { file = new File(Config.DATAPACK_ROOT, "data/scripts/" + target); if (file.isDirectory()) { scriptFiles = FileUtils.listFiles(file, FileFilterUtils.suffixFileFilter(".java"), FileFilterUtils.directoryFileFilter()); } } if (scriptFiles.isEmpty()) { return false; } Class<?> clazz; boolean success = compiler.compile(scriptFiles); if (success) { MemoryClassLoader classLoader = compiler.getClassLoader(); for (String name : classLoader.getLoadedClasses()) { if (name.contains(ClassUtils.INNER_CLASS_SEPARATOR)) { continue; } try { clazz = classLoader.loadClass(name); if (Modifier.isAbstract(clazz.getModifiers())) { continue; } classes.add(clazz); } catch (ClassNotFoundException e) { success = false; _log.error("Scripts: Can't load script class: " + name, e); } } classLoader.clear(); } return success; }
From source file:ClassFinder.java
/** * //from www. ja v a2s .c o m * @param parentClasses * list of classes to check for * @param strClassName * name of class to be checked * @param contextClassLoader * the classloader to use * @return */ private static boolean isChildOf(Class[] parentClasses, String strClassName, ClassLoader contextClassLoader) { // might throw an exception, assume this is ignorable try { Class c = Class.forName(strClassName, false, contextClassLoader); if (!c.isInterface() && !Modifier.isAbstract(c.getModifiers())) { for (Class parentClass : parentClasses) { if (parentClass.isAssignableFrom(c)) { return true; } } } } catch (Throwable ignored) { } return false; }
From source file:org.grouplens.grapht.util.Types.java
/** * <p>/*ww w .j ava 2s . co m*/ * Return true if the type is not abstract and not an interface. This will * return true essentially when the class "should" have a default * constructor or a constructor annotated with {@link Inject @Inject} to be * used properly. * <p> * As another special rule, if the input type is {@link Void}, false is * returned because for most intents and purposes, it is not instantiable. * * @param type The type to test * @return True if it should be instantiable */ public static boolean shouldBeInstantiable(Class<?> type) { return !Modifier.isAbstract(type.getModifiers()) && !type.isInterface() && !Void.class.equals(type); }