Example usage for java.lang.reflect Modifier isAbstract

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

Introduction

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

Prototype

public static boolean isAbstract(int mod) 

Source Link

Document

Return true if the integer argument includes the abstract modifier, false otherwise.

Usage

From source file:com.github.dozermapper.core.classmap.ClassMappings.java

private static boolean isAbstract(Class<?> destClass) {
    return Modifier.isAbstract(destClass.getModifiers());
}

From source file:org.jgentleframework.configure.ConfigurationProxy.java

@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {

    if (Modifier.isAbstract(method.getModifiers())) {
        if (method.isAnnotationPresent(Block.class)) {
            Block anno = method.getAnnotation(Block.class);
            Class<?>[] clazzList = anno.value();
            ObjectBlock objBlock = new ObjectBlock(method, clazzList);
            this.objBlockList.add(objBlock);
        }/*from   w  w w. j  a v a 2s  .  c o m*/
        // thc thi hm getOptionsList trn ConfigModule interface
        if (method.getName().equals("getOptionsList") && method.getParameterTypes().length == 0) {
            checkBlock(method);
            return this.optionsList;
        } else if (method.getName().equals("getTargetClass") && method.getParameterTypes().length == 0) {
            checkBlock(method);
            return this.targetClass;
        } else if (method.getName().equals("getConfigInstance") && method.getParameterTypes().length == 1) {
            checkBlock(method);
            return this.configObjList.get(args[0]);
        } else {
            if (!this.objBlockList.isEmpty()) {
                ObjectBlock objb = this.objBlockList.get(this.configObjList.size() - 1);
                List<Class<?>> clazzList = null;
                clazzList = objb.getBlockList();
                for (Class<?> clazz : clazzList) {
                    Object objConfig = this.configObjList.get(clazz);
                    List<Method> methodList = Arrays.asList(objConfig.getClass().getMethods());
                    if (methodList.contains(method)) {
                        checkBlock(method);
                        return method.invoke(objConfig, args);
                    } else {
                        continue;
                    }
                }
            }
            // Nu khng c
            for (Class<?> clazz : this.configObjList.keySet()) {
                Object objConfig = this.configObjList.get(clazz);
                List<Method> methodList = Arrays.asList(ReflectUtils.getAllDeclaredMethods(clazz));
                if (methodList.contains(method)) {
                    checkBlock(method);
                    return method.invoke(objConfig, args);
                } else {
                    continue;
                }
            }
            throw new NoSuchMethodException("Could not found " + method + " method!");
        }
    } else {
        checkBlock(method);
        return proxy.invokeSuper(obj, args);
    }
}

From source file:com.dragome.compiler.parser.Parser.java

public TypeDeclaration parse() {
    DescendingVisitor classWalker = new DescendingVisitor(jc, new EmptyVisitor() {
        public void visitConstantClass(ConstantClass obj) {
            ConstantPool cp = jc.getConstantPool();
            String bytes = obj.getBytes(cp);
            fileUnit.addDependency(bytes.replace("/", "."));
        }//  w ww  .  ja  v  a  2 s.c  om
    });
    classWalker.visit();

    org.apache.bcel.classfile.Method[] bcelMethods = jc.getMethods();

    ObjectType type = new ObjectType(jc.getClassName());
    Map<String, String> annotationsValues = getAnnotationsValues(jc.getAttributes());
    TypeDeclaration typeDecl = new TypeDeclaration(type, jc.getAccessFlags(), annotationsValues);
    Project.singleton.addTypeAnnotations(typeDecl);

    fileUnit.isInterface = Modifier.isInterface(typeDecl.getAccess());
    fileUnit.isAbstract = Modifier.isAbstract(typeDecl.getAccess());

    fileUnit.setAnnotations(annotationsValues);

    if (!type.getClassName().equals("java.lang.Object")) {

        ObjectType superType = new ObjectType(jc.getSuperclassName());
        typeDecl.setSuperType(superType);
        ClassUnit superUnit = Project.getSingleton().getOrCreateClassUnit(superType.getClassName());
        fileUnit.setSuperUnit(superUnit);

        String[] interfaceNames = jc.getInterfaceNames();
        for (int i = 0; i < interfaceNames.length; i++) {
            ObjectType interfaceType = new ObjectType(interfaceNames[i]);
            ClassUnit interfaceUnit = Project.getSingleton().getOrCreateClassUnit(interfaceType.getClassName());
            fileUnit.addInterface(interfaceUnit);
        }
    }

    Field[] fields = jc.getFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        VariableDeclaration variableDecl = new VariableDeclaration(VariableDeclaration.NON_LOCAL);
        variableDecl.setName(field.getName());
        variableDecl.setModifiers(field.getModifiers());
        variableDecl.setType(field.getType());

        typeDecl.addField(variableDecl);
    }

    for (int i = 0; i < bcelMethods.length; i++) {
        Method method = bcelMethods[i];

        Attribute[] attributes = method.getAttributes();

        Map<String, String> methodAnnotationsValues = getAnnotationsValues(attributes);

        MethodBinding binding = MethodBinding.lookup(jc.getClassName(), method.getName(),
                method.getSignature());

        String genericSignature = method.getGenericSignature();
        if (genericSignature != null && !genericSignature.equals(method.getSignature())) {
            Signature signature = Project.getSingleton().getSignature(binding.toString()).relative();
            String normalizedSignature = DragomeJavaScriptGenerator.normalizeExpression(signature);
            String normalizedClassname = DragomeJavaScriptGenerator.normalizeExpression(type.getClassName());
            Project.getSingleton().addGenericSignature(
                    normalizedClassname + "|" + normalizedSignature + "|" + genericSignature);
            //      System.out.println(genericSignature);
        }

        if (DragomeJsCompiler.compiler.getSingleEntryPoint() != null) {
            Signature signature = Project.getSingleton().getSignature(binding.toString());
            String singleSignature = DragomeJsCompiler.compiler.getSingleEntryPoint();
            if (!signature.toString().equals(singleSignature))
                continue;
        }

        MethodDeclaration methodDecl = new MethodDeclaration(binding, method.getAccessFlags(), method.getCode(),
                methodAnnotationsValues);
        typeDecl.addMethod(methodDecl);

        parseMethod(typeDecl, methodDecl, method);
    }

    return typeDecl;
}

From source file:objenome.util.bytecode.SgUtils.java

/**
 * Checks if the modifiers are valid for a class. If any of the modifiers is
 * not valid an <code>IllegalArgumentException</code> is thrown.
 * //from   w  w w .j  a  va 2 s . c  o m
 * @param modifiers
 *            Modifiers.
 * @param isInterface
 *            Are the modifiers from an interface?
 * @param isInnerClass
 *            Is it an inner class?
 */
public static void checkClassModifiers(int modifiers, boolean isInterface, boolean isInnerClass) {

    // Basic checks
    int type;
    if (isInterface) {
        type = isInnerClass ? INNER_INTERFACE : OUTER_INTERFACE;
    } else {
        type = isInnerClass ? INNER_CLASS : OUTER_CLASS;
    }
    checkModifiers(type, modifiers);

    // Abstract and final check
    if (Modifier.isAbstract(modifiers) && Modifier.isFinal(modifiers)) {
        throw new IllegalArgumentException(
                CLASS_ABSTRACT_AND_FINAL_ERROR + " [" + Modifier.toString(modifiers) + ']');
    }

}

From source file:ome.services.graphs.AnnotationGraphSpec.java

/**
 * Performs sanity checks on the annotation entries found in {@link ExtendedMetadata}.
 * Primarily, this prevents new annotation types from not being properly specified
 * in spec.xml./*w  w  w . j  a  v  a 2 s.  c  o m*/
 */
@Override
public void setExtendedMetadata(ExtendedMetadata em) {
    super.setExtendedMetadata(em);

    // First calculate the number of unique top-level paths
    List<String> uniquePaths = new ArrayList<String>();
    for (GraphEntry entry : entries) {
        String topLevel = entry.path("")[0];
        if (!uniquePaths.contains(topLevel)) {
            uniquePaths.add(topLevel);
        }
    }

    // Now we check if this represents all the annotation types
    // in the system.
    Set<Class<Annotation>> types = em.getAnnotationTypes();
    if (types.size() != uniquePaths.size()) {
        throw new FatalBeanException("Mismatch between anntotations defined and those found: " + entries + "<> "
                + em.getAnnotationTypes());
    }

    TYPE: for (Class<Annotation> type : types) {
        String simpleName = type.getSimpleName();
        for (int i = 0; i < entries.size(); i++) {
            GraphEntry entry = entries.get(i);
            if (entry.path("").length > 1) {
                // This not an annotation, but some subpath
                // ignore it.
                continue;
            }
            if (simpleName.equals(entry.getName().substring(1))) {
                this.types[i] = type;
                if (Modifier.isAbstract(type.getModifiers())) {
                    this.isAbstract[i] = true;
                }
                continue TYPE;
            }
        }
        throw new FatalBeanException("Could not find entry: " + simpleName);
    }
}

From source file:com.github.geequery.codegen.ast.JavaUnit.java

/**
 * Equals//from w ww .j  a v a2 s  .  co m
 * @param idfields ?fields
 * @param overwirte ?
 * @param doSuperMethod ?
 * @return
 */
public boolean createHashCodeMethod(List<JavaField> idfields, boolean overwirte, String doSuperMethod) {
    JavaMethod hashCode = new JavaMethod("hashCode");
    hashCode.setCheckReturn(false);
    hashCode.setReturnType(int.class);
    if (methods.containsKey(hashCode.getKey())) {//?
        if (!overwirte) {
            return false;
        }
    }
    hashCode.addContent("return new HashCodeBuilder()");
    //
    for (int i = 0; i < idfields.size(); i++) {
        JavaField field = idfields.get(i);
        String name = field.getName();
        if (Modifier.isAbstract(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        hashCode.addContent(".append(" + name + ")");
    }
    if (StringUtils.isNotEmpty(doSuperMethod)) {
        hashCode.addContent(".append(super." + doSuperMethod + "())");
    }
    hashCode.addContent(".toHashCode();");
    addMethod(hashCode);
    addImport(HashCodeBuilder.class);
    return true;
}

From source file:org.batfish.common.plugin.PluginConsumer.java

private void loadPluginJar(Path path) {
    /*/*  www.j a v  a  2  s  .  c  om*/
     * Adapted from
     * http://stackoverflow.com/questions/11016092/how-to-load-classes-at-
     * runtime-from-a-folder-or-jar Retrieved: 2016-08-31 Original Authors:
     * Kevin Crain http://stackoverflow.com/users/2688755/kevin-crain
     * Apfelsaft http://stackoverflow.com/users/1447641/apfelsaft License:
     * https://creativecommons.org/licenses/by-sa/3.0/
     */
    String pathString = path.toString();
    if (pathString.endsWith(".jar")) {
        try {
            URL[] urls = { new URL("jar:file:" + pathString + "!/") };
            URLClassLoader cl = URLClassLoader.newInstance(urls, _currentClassLoader);
            _currentClassLoader = cl;
            Thread.currentThread().setContextClassLoader(cl);
            JarFile jar = new JarFile(path.toFile());
            Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                JarEntry element = entries.nextElement();
                String name = element.getName();
                if (element.isDirectory() || !name.endsWith(CLASS_EXTENSION)) {
                    continue;
                }
                String className = name.substring(0, name.length() - CLASS_EXTENSION.length()).replace("/",
                        ".");
                try {
                    cl.loadClass(className);
                    Class<?> pluginClass = Class.forName(className, true, cl);
                    if (!Plugin.class.isAssignableFrom(pluginClass)
                            || Modifier.isAbstract(pluginClass.getModifiers())) {
                        continue;
                    }
                    Constructor<?> pluginConstructor;
                    try {
                        pluginConstructor = pluginClass.getConstructor();
                    } catch (NoSuchMethodException | SecurityException e) {
                        throw new BatfishException(
                                "Could not find default constructor in plugin: '" + className + "'", e);
                    }
                    Object pluginObj;
                    try {
                        pluginObj = pluginConstructor.newInstance();
                    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
                            | InvocationTargetException e) {
                        throw new BatfishException(
                                "Could not instantiate plugin '" + className + "' from constructor", e);
                    }
                    Plugin plugin = (Plugin) pluginObj;
                    plugin.initialize(this);

                } catch (ClassNotFoundException e) {
                    jar.close();
                    throw new BatfishException("Unexpected error loading classes from jar", e);
                }
            }
            jar.close();
        } catch (IOException e) {
            throw new BatfishException("Error loading plugin jar: '" + path.toString() + "'", e);
        }
    }
}

From source file:org.gvnix.service.roo.addon.addon.ws.importt.WSImportOperationsImpl.java

/** {@inheritDoc} **/
public List<String> getServiceList() {
    List<String> classNames = new ArrayList<String>();
    Set<ClassOrInterfaceTypeDetails> cids = typeLocationService
            .findClassesOrInterfaceDetailsWithAnnotation(new JavaType(GvNIXWebServiceProxy.class.getName()));
    for (ClassOrInterfaceTypeDetails cid : cids) {
        if (Modifier.isAbstract(cid.getModifier())) {
            continue;
        }//w w  w  .  ja v a2  s  . c  om
        classNames.add(cid.getName().getFullyQualifiedTypeName());
    }
    return classNames;
}

From source file:org.eclipse.wb.internal.rcp.databinding.xwt.ui.contentproviders.ValidationUiContentProvider.java

private ClassInfo createInfo(String className) {
    ClassInfo info = new ClassInfo();
    info.className = className;//from w  w w  .j  ava 2 s. c  o m
    //
    if (className.length() == 0) {
        info.message = Messages.ValidationUiContentProvider_noClass;
    } else {
        if (className.startsWith("{") && className.endsWith("}")) {
            return info;
        }
        //
        try {
            // check load class
            Class<?> testClass = loadClass(className);
            // check permissions
            int modifiers = testClass.getModifiers();
            if (!Modifier.isPublic(modifiers)) {
                info.message = Messages.ValidationUiContentProvider_notPublicClass;
                return info;
            }
            if (Modifier.isAbstract(modifiers)) {
                info.message = Messages.ValidationUiContentProvider_abstractClass;
                return info;
            }
            // check constructor
            boolean noConstructor = true;
            try {
                testClass.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY);
                noConstructor = false;
            } catch (SecurityException e) {
            } catch (NoSuchMethodException e) {
            }
            // prepare error message for constructor
            if (noConstructor) {
                info.message = Messages.ValidationUiContentProvider_noPublicConstructor
                        + ClassUtils.getShortClassName(className) + "().";
            }
        } catch (ClassNotFoundException e) {
            info.message = Messages.ValidationUiContentProvider_notExistClass;
        }
    }
    return info;
}

From source file:org.syncope.core.rest.controller.ConfigurationController.java

@PreAuthorize("hasRole('CONFIGURATION_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/validators")
public ModelAndView getValidators() {
    CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();

    Set<String> validators = new HashSet<String>();
    try {//from w w  w.  j  ava 2 s.c o m
        for (Resource resource : resResolver
                .getResources("classpath:org/syncope/core/persistence/validation/" + "attrvalue/*.class")) {

            ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource)
                    .getClassMetadata();
            if (ArrayUtils.contains(metadata.getInterfaceNames(), Validator.class.getName())
                    || AbstractValidator.class.getName().equals(metadata.getSuperClassName())) {

                try {
                    Class jobClass = Class.forName(metadata.getClassName());
                    if (!Modifier.isAbstract(jobClass.getModifiers())) {
                        validators.add(jobClass.getName());
                    }
                } catch (ClassNotFoundException e) {
                    LOG.error("Could not load class {}", metadata.getClassName(), e);
                }
            }
        }
    } catch (IOException e) {
        LOG.error("While searching for class implementing {}", Validator.class.getName(), e);
    }

    return new ModelAndView().addObject(validators);
}