List of usage examples for java.lang.reflect Modifier ABSTRACT
int ABSTRACT
To view the source code for java.lang.reflect Modifier ABSTRACT.
Click Source Link
From source file:org.eclipse.skalli.testutil.PropertyTestUtil.java
private static Object assertExistsConstructor(Class<?> clazz, Map<Class<?>, String[]> requiredProperties, Map<String, Object> values) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException { Object instance = null;/* w ww . j a va 2 s . co m*/ String[] params = requiredProperties.get(clazz); if (params == null) { try { instance = clazz.newInstance(); } catch (InstantiationException ex) { Assert.assertTrue(clazz.getName() + ": class without constructor must be abstract", (clazz.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT); } } else { Class<?>[] paramTypes = new Class<?>[params.length]; Object[] args = new Object[params.length]; for (int i = 0; i < params.length; ++i) { Object arg = values.get(params[i]); Assert.assertNotNull(arg); args[i] = arg; paramTypes[i] = arg.getClass(); } Constructor<?> c; try { c = clazz.getConstructor(paramTypes); instance = c.newInstance(args); } catch (NoSuchMethodException e) { Assert.fail(clazz.getName() + ": must have constructor " + clazz.getName() + "(" + Arrays.toString(paramTypes) + ")"); } catch (InstantiationException e) { Assert.assertTrue(clazz.getName() + ": class is not instantiable", (clazz.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT); } } return instance; }
From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java
/** * Validates methods of the class.// ww w . jav a2s.c om * * @param validator * a validator * @return a map containing the snippet methods by their name */ private Map<String, Method> validateMethods(final AbstractValidator<?> validator) { // check: only "[public|private] static" or synthetic methods Map<String, Method> snippetMethods = new HashMap<String, Method>(); for (Method method : javaClass.getDeclaredMethods()) { if (method.isSynthetic()) { // skip synthetic methods continue; } MethodValidator v = new MethodValidator(method); if (snippetMethods.get(method.getName()) != null) { v.addException("The method must have a unique name"); } int methodModifiers = method.getModifiers(); if (!Modifier.isPublic(methodModifiers) && !Modifier.isPrivate(methodModifiers)) { v.addException("The method must be public or private"); } v.withModifiers(Modifier.STATIC); v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED); AnnotationMap methodAnns = SetteAnnotationUtils.getSetteAnnotations(method); if (Modifier.isPublic(methodModifiers)) { if (methodAnns.get(SetteNotSnippet.class) == null) { // should be snippet, validated by Snippet class and added // later snippetMethods.put(method.getName(), method); } else { // not snippet snippetMethods.put(method.getName(), null); if (methodAnns.size() != 1) { v.addException("The method must not have " + "any other SETTE annotations " + "if it is not a snippet."); } } } else { // method is private if (methodAnns.size() != 0) { v.addException("The method must not have " + "any SETTE annotations"); } } validator.addChildIfInvalid(v); } return snippetMethods; }
From source file:com.github.geequery.codegen.ast.JavaUnit.java
public void setAbstract(boolean isAbstract) { if (isAbstract != isAbstract()) { this.modifiers ^= Modifier.ABSTRACT; } }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteria.java
/** * Set the criterion that selects only {@link Member}s that exactly have the * specified modifiers. The access modifiers are set separately. Use * {@link #withAccess(AccessType...)} to set access modifiers. * * @param modifiers/*from w w w. j a va2 s . com*/ * @since 1.0.0.0 */ public void withModifiers(int modifiers) { if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)) { throw new IllegalArgumentException( "access modifiers are not allowed as argument. Use withAccess() instead."); } int allowedModifiers = Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE; if ((modifiers & allowedModifiers) == 0) { throw new IllegalArgumentException( "modifiers must be one of [" + Modifier.toString(allowedModifiers) + "]"); } this.modifiers = modifiers; }
From source file:cn.teamlab.wg.framework.struts2.json.PackageBasedActionConfigBuilder.java
/** * Interfaces, enums, annotations, and abstract classes cannot be * instantiated./*from ww w.ja v a 2 s . c o m*/ * * @param actionClass * class to check * @return returns true if the class cannot be instantiated or should be * ignored */ protected boolean cannotInstantiate(Class<?> actionClass) { return actionClass.isAnnotation() || actionClass.isInterface() || actionClass.isEnum() || (actionClass.getModifiers() & Modifier.ABSTRACT) != 0 || actionClass.isAnonymousClass(); }
From source file:org.tynamo.model.elasticsearch.util.ReflectionUtil.java
/** * Checks if is abstract./*from ww w. ja v a 2 s . com*/ * * @param clazz * the clazz * @return true, if is abstract */ public static boolean isAbstract(Class<?> clazz) { int modifiers = clazz.getModifiers(); return (modifiers & Modifier.ABSTRACT) > 0; }
From source file:org.eclipse.buildship.docs.source.SourceMetaDataVisitor.java
private int extractModifiers(GroovySourceAST ast) { GroovySourceAST modifiers = ast.childOfType(MODIFIERS); if (modifiers == null) { return 0; }/*from w w w. j a v a2 s. c o m*/ int modifierFlags = 0; for (GroovySourceAST child = (GroovySourceAST) modifiers .getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) { switch (child.getType()) { case LITERAL_private: modifierFlags |= Modifier.PRIVATE; break; case LITERAL_protected: modifierFlags |= Modifier.PROTECTED; break; case LITERAL_public: modifierFlags |= Modifier.PUBLIC; break; case FINAL: modifierFlags |= Modifier.FINAL; break; case LITERAL_static: modifierFlags |= Modifier.STATIC; break; case ABSTRACT: modifierFlags |= Modifier.ABSTRACT; break; } } return modifierFlags; }
From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java
/** * Learn whether this BasicTypeConverter can create a collection of the specified type. * @param type prospective destination class * @return boolean//from w ww .jav a 2 s . c o m */ protected boolean canCreateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { type.getConstructor(new Class[0]); return true; } catch (Exception e) { return false; } } return type == List.class || type == Collection.class || type == Set.class; }
From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java
/** * Create a collection of a given type./*from www .j a v a 2 s . com*/ * @param type destination class * @return Collection */ protected Collection allocateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { return (Collection) type.newInstance(); } catch (Exception ex) { throw new JXPathInvalidAccessException("Cannot create collection of type: " + type, ex); } } if (type == List.class || type == Collection.class) { return new ArrayList(); } if (type == Set.class) { return new HashSet(); } throw new JXPathInvalidAccessException("Cannot create collection of type: " + type); }