Example usage for java.lang.reflect Modifier ABSTRACT

List of usage examples for java.lang.reflect Modifier ABSTRACT

Introduction

In this page you can find the example usage for java.lang.reflect Modifier ABSTRACT.

Prototype

int ABSTRACT

To view the source code for java.lang.reflect Modifier ABSTRACT.

Click Source Link

Document

The int value representing the abstract modifier.

Usage

From source file:de.lmu.ifi.dbs.jfeaturelib.utils.PackageScanner.java

public List<Class<T>> scanForClass(Package thePackage, Class<T> needle)
        throws IOException, UnsupportedEncodingException, URISyntaxException {
    List<String> binaryNames = getNames(thePackage);
    List<Class<T>> list = new ArrayList<>();

    ClassLoader loader = ClassLoader.getSystemClassLoader();
    for (String binaryName : binaryNames) {
        if (binaryName.contains("$") && !includeInnerClasses) {
            log.debug("Skipped inner class: " + binaryName);
            continue;
        }/*from  w  w  w.j  a  v  a 2 s. c  om*/

        try {
            Class<?> clazz = loader.loadClass(binaryName);
            int modifiers = clazz.getModifiers();
            if ((modifiers & Modifier.INTERFACE) != 0 && !includeInterfaces) {
                log.debug("Skipped interface: " + binaryName);
                continue;
            }
            if ((modifiers & Modifier.ABSTRACT) != 0 && !includeAbstractClasses) {
                log.debug("Skipped abstract class: " + binaryName);
                continue;
            }
            if (needle.isAssignableFrom(clazz)) {
                log.debug("added class/interface/..: " + binaryName);
                list.add((Class<T>) clazz);
            }
        } catch (ClassNotFoundException e) {
            // This should never happen
            log.warn("couldn't find class (?!): " + binaryName, e);
        }
    }
    return list;
}

From source file:fr.imag.model2roo.addon.graph.GraphOperationsImpl.java

@Override
public void newEntity(final JavaType name, final JavaType superClass, final boolean isAbstract) {
    int modifier;
    String entityId;/*from w w w .j  a v  a 2s .  c  o  m*/
    GraphProvider graphProvider;
    FieldMetadataBuilder fieldBuilder;
    ClassOrInterfaceTypeDetails entityDetails;
    ClassOrInterfaceTypeDetails superClassDetails;
    ClassOrInterfaceTypeDetailsBuilder entityBuilder;

    // Class modifier
    modifier = Modifier.PUBLIC;
    if (isAbstract) {
        modifier = Modifier.ABSTRACT;
    }

    // Create entity class
    entityId = PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
    entityBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityId, modifier, name,
            PhysicalTypeCategory.CLASS);

    // Base class
    if (!superClass.equals(OBJECT)) {
        superClassDetails = typeLocationService.getTypeDetails(superClass);
        if (superClassDetails != null) {
            entityBuilder.setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(superClassDetails));
        }
    }
    entityBuilder.setExtendsTypes(Arrays.asList(superClass));

    // Associate appropriate annotations
    graphProvider = this.getCurrentGraphProvider();
    entityBuilder.setAnnotations(graphProvider.getClassAnnotations());
    entityBuilder.addAnnotation(ROO_JAVA_BEAN_BUILDER);
    entityBuilder.addAnnotation(ROO_TO_STRING_BUILDER);
    typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build());

    // Add id field
    entityDetails = typeLocationService.getTypeDetails(name);
    fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE,
            graphProvider.getIdAnnotations(), new JavaSymbolName("nodeId"), JavaType.LONG_OBJECT);
    typeManagementService.addField(fieldBuilder.build());
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java

/**
 * Validates the class and its annotations.
 *
 * @param validator/*from  www.ja  v a 2  s. com*/
 *            a validator
 * @return the {@link SetteSnippetContainer} annotation
 */
private SetteSnippetContainer validateClass(final AbstractValidator<?> validator) {
    // check: "public final class", no superclass, interface, declared
    // class, exactly one constructor
    ClassValidator v = new ClassValidator(javaClass);
    v.type(ClassType.REGULAR_CLASS);
    v.withModifiers(Modifier.PUBLIC | Modifier.FINAL);
    v.withoutModifiers(Modifier.ABSTRACT);
    v.synthetic(false);
    v.superclass(Object.class).interfaceCount(0).memberClassCount(0);
    v.declaredConstructorCount(1);

    // check: only @SetteSnippetContainer
    SetteSnippetContainer containerAnn = null;

    AnnotationMap classAnns = SetteAnnotationUtils.getSetteAnnotations(javaClass);

    containerAnn = (SetteSnippetContainer) classAnns.get(SetteSnippetContainer.class);

    if (containerAnn == null) {
        v.addException(
                "The Java class must have the annotation @" + SetteSnippetContainer.class.getSimpleName());
    } else {
        if (classAnns.size() != 1) {
            v.addException("The Java class must not have any " + "SETTE annotations other than @"
                    + SetteSnippetContainer.class.getSimpleName());
        }

        if (StringUtils.isBlank(containerAnn.category())) {
            v.addException(
                    "The category in @" + SetteSnippetContainer.class.getSimpleName() + " must not be blank");
        }

        if (StringUtils.isBlank(containerAnn.goal())) {
            v.addException(
                    "The goal in @" + SetteSnippetContainer.class.getSimpleName() + " must not be blank");
        }

        if (containerAnn.requiredJavaVersion() == null) {
            v.addException("The reqired Java version in @" + SetteSnippetContainer.class.getSimpleName()
                    + " must not be null");
        }
    }

    validator.addChildIfInvalid(v);

    return containerAnn;
}

From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java

private static boolean isDefault(Method method) {
    // Default methods are public non-abstract instance methods declared in an interface.
    return ((method.getModifiers()
            & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC)
            && method.getDeclaringClass().isInterface();
}

From source file:org.makersoft.mvc.builder.PackageBasedUrlPathBuilder.java

/**
 * Interfaces, enums, annotations, and abstract classes cannot be instantiated.
 * // w  w w .j a va  2 s.c o m
 * @param controllerClass
 *            class to check
 * @return returns true if the class cannot be instantiated or should be ignored
 */
protected boolean cannotInstantiate(Class<?> controllerClass) {
    return controllerClass.isAnnotation() || controllerClass.isInterface() || controllerClass.isEnum()
            || (controllerClass.getModifiers() & Modifier.ABSTRACT) != 0 || controllerClass.isAnonymousClass();
}

From source file:com.khs.sherpa.servlet.request.DefaultSherpaRequest.java

@SuppressWarnings("unchecked")
protected Object proccess() throws SherpaRuntimeException {
    if (!isRestful()) {
        requestProcessor = new DefaultRequestProcessor();
    } else {//  w w w  .  jav  a 2 s .  com
        requestProcessor = new RestfulRequestProcessor(applicationContext);
    }

    String endpoint = requestProcessor.getEndpoint(request);
    String action = requestProcessor.getAction(request);
    String httpMethod = request.getMethod();

    if (StringUtils.isEmpty(endpoint)) {
        if (action.equals(Constants.AUTHENTICATE_ACTION)) {
            return this.processAuthenication();
        } else if (action.equals(Constants.VALID)) {
            return this.processValid();
        }
    }

    Object target = null;
    Set<Method> methods = null;

    try {
        String userid = request.getHeader("userid");
        if (userid == null) {
            userid = request.getParameter("userid");
        }
        String token = request.getHeader("token");
        if (token == null) {
            token = request.getParameter("token");
        }

        this.hasPermission(applicationContext.getType(endpoint), userid, token);

        target = applicationContext.getManagedBean(endpoint);

        if (ApplicationContextAware.class.isAssignableFrom(target.getClass())) {
            ((ApplicationContextAware) target).setApplicationContext(applicationContext);
        }

        methods = Reflections.getAllMethods(applicationContext.getType(endpoint),
                Predicates.and(Predicates.not(SherpaPredicates.withAssignableFrom(Object.class)),
                        ReflectionUtils.withModifier(Modifier.PUBLIC),
                        Predicates.not(ReflectionUtils.withModifier(Modifier.ABSTRACT)),
                        Predicates.not(SherpaPredicates.withGeneric()),
                        Predicates.and(SherpaPredicates.withAssignableFrom(
                                Enhancer.isEnhanced(target.getClass()) ? target.getClass().getSuperclass()
                                        : target.getClass())),
                        Predicates.or(ReflectionUtils.withName(action),
                                Predicates.and(ReflectionUtils.withAnnotation(Action.class),
                                        SherpaPredicates.withActionAnnotationValueEqualTo(action)))));

        if (methods.size() == 0) {
            throw new SherpaActionNotFoundException(action);
        }

    } catch (NoSuchManagedBeanExcpetion e) {
        throw new SherpaRuntimeException(e);
    }

    return this.processEndpoint(target, methods.toArray(new Method[] {}), httpMethod);
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void hierarchyTraveral() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withModifiers(Modifier.ABSTRACT);
    memberCriteria.named(Pattern.compile("add.*"));
    Class<?> currentHierarchyClass = ArrayList.class;
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        if (!currentHierarchyClass.equals(member.getDeclaringClass())) {
            if (!member.getDeclaringClass().isInterface()) {
                assertTrue("members must be iterated " + "from subclass to superclass",
                        ((Class<?>) member.getDeclaringClass()).isAssignableFrom(currentHierarchyClass));
                // so the current declaring class is not the members
                // declaring
                // class which means we went up the hierarchy
                currentHierarchyClass = member.getDeclaringClass();
            }//from w w  w . jav a2  s. c  om
        }
    }
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java

/**
 * Validates methods of the class./*from  ww  w  .ja va 2 s  .  c  o  m*/
 *
 * @param validator
 *            a validator
 * @return a map containing the input factory methods by their name
 */
private Map<String, Method> validateMethods(final AbstractValidator<?> validator) {
    // check: only "public static" or synthetic methods
    Map<String, Method> factoryMethods = new HashMap<String, Method>();

    for (Method method : javaClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            // skip synthetic methods
            continue;
        }

        MethodValidator v = new MethodValidator(method);

        if (factoryMethods.get(method.getName()) != null) {
            v.addException("The method must have a unique name");
        }

        v.withModifiers(Modifier.PUBLIC | Modifier.STATIC);
        v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED);

        factoryMethods.put(method.getName(), method);

        validator.addChildIfInvalid(v);
    }

    return factoryMethods;
}

From source file:ClassTree.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    // get the user object
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    Class<?> c = (Class<?>) node.getUserObject();

    // the first time, derive italic font from plain font
    if (plainFont == null) {
        plainFont = getFont();//from   w w w. ja v a2  s. c o  m
        // the tree cell renderer is sometimes called with a label that has a null font
        if (plainFont != null)
            italicFont = plainFont.deriveFont(Font.ITALIC);
    }

    // set font to italic if the class is abstract, plain otherwise
    if ((c.getModifiers() & Modifier.ABSTRACT) == 0)
        setFont(plainFont);
    else
        setFont(italicFont);
    return this;
}

From source file:hd3gtv.mydmam.db.orm.CassandraOrm.java

private ArrayList<Field> getOrmobjectUsableFields() {
    ArrayList<Field> result = new ArrayList<Field>();

    Field[] fields = this.reference.getFields();
    Field field;//from  w  w  w. ja v a2s  . co  m
    int mod;
    for (int pos_df = 0; pos_df < fields.length; pos_df++) {
        field = fields[pos_df];
        if (field.isAnnotationPresent(Transient.class)) {
            /**
             * Is transient ?
             */
            continue;
        }
        if (field.getName().equals("key")) {
            /**
             * Not this (primary key)
             */
            continue;
        }
        mod = field.getModifiers();

        if ((mod & Modifier.PROTECTED) != 0)
            continue;
        if ((mod & Modifier.PRIVATE) != 0)
            continue;
        if ((mod & Modifier.ABSTRACT) != 0)
            continue;
        if ((mod & Modifier.STATIC) != 0)
            continue;
        if ((mod & Modifier.FINAL) != 0)
            continue;
        if ((mod & Modifier.TRANSIENT) != 0)
            continue;
        if ((mod & Modifier.INTERFACE) != 0)
            continue;

        try {
            result.add(field);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        }
    }

    return result;
}