List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.apache.tapestry.enhance.ComponentClassFactory.java
protected void scanForAbstractClass() { if (Modifier.isAbstract(_componentClass.getModifiers())) getEnhancedClass().addEnhancer(new NoOpEnhancer()); }
From source file:org.apache.struts2.config.ClasspathPackageProvider.java
/** * Scan a list of packages for Action classes. * * This method loads classes that implement the Action interface * or have a class name that ends with the letters "Action". * * @param pkgs A list of packages to load * @see #processActionClass/*from w ww .ja v a2 s . c om*/ */ protected void loadPackages(String[] pkgs) { packageLoader = new PackageLoader(); ResolverUtil<Class> resolver = new ResolverUtil<Class>(); resolver.find(createActionClassTest(), pkgs); Set<? extends Class<? extends Class>> actionClasses = resolver.getClasses(); for (Object obj : actionClasses) { Class cls = (Class) obj; if (!Modifier.isAbstract(cls.getModifiers())) { processActionClass(cls, pkgs); } } for (PackageConfig config : packageLoader.createPackageConfigs()) { configuration.addPackageConfig(config.getName(), config); } }
From source file:com.clarkparsia.empire.annotation.RdfGenerator.java
/** * Create an instance of the specified class and instantiate it's data from the given data source using the RDF * instance specified by the given URI/*from w w w . jav a 2 s . co m*/ * @param theClass the class to create * @param theId the id of the RDF individual containing the data for the new instance * @param theSource the KB to get the RDF data from * @param <T> the type of the instance to create * @return a new instance * @throws InvalidRdfException thrown if the class does not support RDF JPA operations, or does not provide sufficient access to its fields/data. * @throws DataSourceException thrown if there is an error while retrieving data from the graph */ public static <T> T fromRdf(Class<T> theClass, SupportsRdfId.RdfKey theId, DataSource theSource) throws InvalidRdfException, DataSourceException { T aObj; long start = System.currentTimeMillis(), start1 = System.currentTimeMillis(); try { aObj = Empire.get().instance(theClass); } catch (ConfigurationException ex) { aObj = null; } catch (ProvisionException ex) { aObj = null; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Tried to get instance of class in {} ms ", (System.currentTimeMillis() - start)); } start = System.currentTimeMillis(); if (aObj == null) { // this means Guice construction failed, which is not surprising since that's not going to be the default. // so we'll try our own reflect based creation or create bytecode for an interface. try { long istart = System.currentTimeMillis(); if (theClass.isInterface() || Modifier.isAbstract(theClass.getModifiers())) { aObj = com.clarkparsia.empire.codegen.InstanceGenerator.generateInstanceClass(theClass) .newInstance(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("CodeGenerated instance in {} ms. ", (System.currentTimeMillis() - istart)); } } else { aObj = theClass.newInstance(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("CodeGenerated instance in {} ms. ", (System.currentTimeMillis() - istart)); } } } catch (InstantiationException e) { throw new InvalidRdfException("Cannot create instance of bean, should have a default constructor.", e); } catch (IllegalAccessException e) { throw new InvalidRdfException("Could not access default constructor for class: " + theClass, e); } catch (Exception e) { throw new InvalidRdfException("Cannot create an instance of bean", e); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Got reflect instance of class {} ms ", (System.currentTimeMillis() - start1)); } start = System.currentTimeMillis(); } asSupportsRdfId(aObj).setRdfId(theId); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Has rdfId {} ms", (System.currentTimeMillis() - start1)); } start = System.currentTimeMillis(); Class<T> aNewClass = determineClass(theClass, aObj, theSource); if (!aNewClass.equals(aObj.getClass())) { try { aObj = aNewClass.newInstance(); } catch (InstantiationException e) { throw new InvalidRdfException("Cannot create instance of bean, should have a default constructor.", e); } catch (IllegalAccessException e) { throw new InvalidRdfException("Could not access default constructor for class: " + theClass, e); } catch (Exception e) { throw new InvalidRdfException("Cannot create an instance of bean", e); } asSupportsRdfId(aObj).setRdfId(theId); } T fromRdf = fromRdf(aObj, theSource); return fromRdf; }
From source file:org.seedstack.seed.core.utils.BaseClassSpecifications.java
/** * Checks if the class is abstract.//w w w . ja v a2 s .co m * * @return the specification */ public static Specification<Class<?>> classIsAbstract() { return new AbstractSpecification<Class<?>>() { @Override public boolean isSatisfiedBy(Class<?> candidate) { return candidate != null && Modifier.isAbstract(candidate.getModifiers()); } }; }
From source file:edu.cmu.tetrad.util.TetradSerializableUtils.java
/** * Finds all classes inside the stated scope that implement * TetradSerializable and serializes them out to the getCurrentDirectory() * directory. Abstract methods and interfaces are skipped over. For all * other classes C, it is assumed that C has a static constructor of the * following form:// www. j av a 2s . c o m * <pre> * public static C serializableInstance() { * // Returns an instance of C. May be a mind-numbingly simple * // instance, no need to get fancy. * } * </pre> * The instance returned may be mind-numbingly simple; there is no need to * get fancy. It may change over time. The point is to make sure that * instances serialized out with earlier versions load with the * currentDirectory version. * * @throws RuntimeException if clazz cannot be serialized. This exception * has an informative message and wraps the * originally thrown exception as root cause. */ public void serializeCurrentDirectory() throws RuntimeException { clearCurrentDirectory(); @SuppressWarnings("Convert2Diamond") Map<String, List<String>> classFields = new TreeMap<>(); // Get the classes that implement SerializationCanonicalizer. List classes = getAssignableClasses(new File(getSerializableScope()), TetradSerializable.class); System.out.println( "Serializing exemplars of instantiable TetradSerializable " + "in " + getSerializableScope() + "."); System.out.println("Writing serialized examplars to " + getCurrentDirectory()); int index = -1; for (Object aClass : classes) { Class clazz = (Class) aClass; if (TetradSerializableExcluded.class.isAssignableFrom(clazz)) { continue; } if (Modifier.isAbstract(clazz.getModifiers())) { continue; } if (Modifier.isInterface(clazz.getModifiers())) { continue; } int numFields = getNumNonSerialVersionUIDFields(clazz); if (numFields > 0 && serializableInstanceMethod(clazz) == null) { throw new RuntimeException("Class " + clazz + " does not " + "\nhave a public static serializableInstance constructor."); } if (++index % 50 == 0) { System.out.println(index); } System.out.print("."); serializeClass(clazz, classFields); } try { File file = new File(getCurrentDirectory(), "class_fields.ser"); FileOutputStream out = new FileOutputStream(file); ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(classFields); out.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("\nFinished serializing exemplars."); }
From source file:at.tuwien.ifs.somtoolbox.apps.SOMToolboxMain.java
/** * @param screenWidth the with of the screen * @param runnables {@link ArrayList} of available runnables. *//* w w w . j a v a 2 s .c om*/ private static void printAvailableRunnables(int screenWidth, ArrayList<Class<? extends SOMToolboxApp>> runnables) { Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR); ArrayList<Class<? extends SOMToolboxApp>> runnableClassList = new ArrayList<Class<? extends SOMToolboxApp>>(); ArrayList<String> runnableNamesList = new ArrayList<String>(); ArrayList<String> runnableDeskrList = new ArrayList<String>(); for (Class<? extends SOMToolboxApp> c : runnables) { try { // Ignore abstract classes and interfaces if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) { continue; } runnableClassList.add(c); runnableNamesList.add(c.getSimpleName()); String desk = null; try { Field f = c.getDeclaredField("DESCRIPTION"); desk = (String) f.get(null); } catch (Exception e) { } if (desk != null) { runnableDeskrList.add(desk); } else { runnableDeskrList.add(""); } } catch (SecurityException e) { // Should not happen - no Security } catch (IllegalArgumentException e) { e.printStackTrace(); } } StringBuilder sb = new StringBuilder(); String lineSep = System.getProperty("line.separator", "\n"); int maxLen = StringUtils.getLongestStringLength(runnableNamesList); sb.append("Runnable classes:").append(lineSep); for (int i = 0; i < runnableNamesList.size(); i++) { final Type cType = Type.getType(runnableClassList.get(i)); if (i == 0 || !cType.equals(Type.getType(runnableClassList.get(i - 1)))) { sb.append(String.format("-- %s %s%s", cType.toString(), StringUtils.repeatString(screenWidth - (8 + cType.toString().length()), "-"), lineSep)); } sb.append(" "); sb.append(runnableNamesList.get(i)); sb.append(StringUtils.getSpaces(4 + maxLen - runnableNamesList.get(i).length())).append("- "); sb.append(runnableDeskrList.get(i)); sb.append(lineSep); } System.out.println(StringUtils.wrap(sb.toString(), screenWidth, StringUtils.getSpaces(maxLen + 10), true)); }
From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java
public static boolean isAddableMethod(MethodNode declaredMethod) { ClassNode groovyMethods = GROOVY_OBJECT_CLASS_NODE; String methodName = declaredMethod.getName(); return !declaredMethod.isSynthetic() && !methodName.contains("$") && Modifier.isPublic(declaredMethod.getModifiers()) && !Modifier.isAbstract(declaredMethod.getModifiers()) && !groovyMethods.hasMethod(declaredMethod.getName(), declaredMethod.getParameters()); }
From source file:alluxio.shell.AlluxioShellUtilsTest.java
@Test public void loadCommands() { Map<String, ShellCommand> map = new HashMap<>(); AlluxioShellUtils.loadCommands(mFileSystem, map); String pkgName = ShellCommand.class.getPackage().getName(); Reflections reflections = new Reflections(pkgName); Set<Class<? extends ShellCommand>> cmdSet = reflections.getSubTypesOf(ShellCommand.class); for (Map.Entry<String, ShellCommand> entry : map.entrySet()) { Assert.assertEquals(entry.getValue().getCommandName(), entry.getKey()); Assert.assertEquals(cmdSet.contains(entry.getValue().getClass()), true); }/*from w w w. j av a 2 s . c o m*/ int expectSize = 0; for (Class<? extends ShellCommand> cls : cmdSet) { if (!Modifier.isAbstract(cls.getModifiers())) { expectSize++; } } Assert.assertEquals(expectSize, map.size()); }
From source file:nl.knaw.huygens.timbuctoo.config.TypeRegistry.java
@SuppressWarnings("unchecked") public static Class<? extends Entity> getBaseClass(Class<? extends Entity> type) { Class<? extends Entity> lastType = type; while (type != null && !Modifier.isAbstract(type.getModifiers())) { lastType = type;// w w w. ja v a 2 s.com type = (Class<? extends Entity>) type.getSuperclass(); } return lastType; }
From source file:com.evolveum.midpoint.prism.PrismContainerValue.java
public C asContainerable() { PrismContainerable parent = getParent(); if (parent == null) { throw new IllegalStateException( "Cannot represent container value without a parent as containerable; value: " + this); }/*from w w w .ja v a 2 s . c o m*/ Class<C> clazz = null; if (concreteType != null) { clazz = resolveConcreteClass(parent); } if (clazz == null) { clazz = parent.getCompileTimeClass(); } if (clazz == null) { throw new SystemException("Unknown compile time class of container '" + parent.getElementName() + "'."); } if (Modifier.isAbstract(clazz.getModifiers())) { throw new SystemException( "Can't create instance of class '" + clazz.getSimpleName() + "', it's abstract."); } return asContainerableInternal(clazz); }