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:org.jenkinsci.plugins.workflow.structs.DescribableHelper.java

@SuppressWarnings("unchecked")
private static Object coerce(String context, Type type, @Nonnull Object o) throws Exception {
    if (type instanceof Class) {
        o = ReflectionCache.getCachedClass((Class) type).coerceArgument(o);
    }// w w  w.j  av a2  s  . c o m
    if (type instanceof Class && Primitives.wrap((Class) type).isInstance(o)) {
        return o;
    } else if (o instanceof Map) {
        Map<String, Object> m = new HashMap<String, Object>();
        for (Map.Entry<?, ?> entry : ((Map<?, ?>) o).entrySet()) {
            m.put((String) entry.getKey(), entry.getValue());
        }

        String clazzS = (String) m.remove(CLAZZ);
        Class<?> clazz;
        if (clazzS == null) {
            if (Modifier.isAbstract(((Class) type).getModifiers())) {
                throw new UnsupportedOperationException(
                        "must specify " + CLAZZ + " with an implementation of " + type);
            }
            clazz = (Class) type;
        } else if (clazzS.contains(".")) {
            Jenkins j = Jenkins.getInstance();
            ClassLoader loader = j != null ? j.getPluginManager().uberClassLoader
                    : DescribableHelper.class.getClassLoader();
            clazz = loader.loadClass(clazzS);
        } else if (type instanceof Class) {
            clazz = null;
            for (Class<?> c : findSubtypes((Class<?>) type)) {
                if (c.getSimpleName().equals(clazzS)) {
                    if (clazz != null) {
                        throw new UnsupportedOperationException(clazzS + " as a " + type + " could mean either "
                                + clazz.getName() + " or " + c.getName());
                    }
                    clazz = c;
                }
            }
            if (clazz == null) {
                throw new UnsupportedOperationException(
                        "no known implementation of " + type + " is named " + clazzS);
            }
        } else {
            throw new UnsupportedOperationException("JENKINS-26535: do not know how to handle " + type);
        }
        return instantiate(clazz.asSubclass((Class<?>) type), m);
    } else if (o instanceof String && type instanceof Class && ((Class) type).isEnum()) {
        return Enum.valueOf(((Class) type).asSubclass(Enum.class), (String) o);
    } else if (o instanceof String && type == URL.class) {
        return new URL((String) o);
    } else if (o instanceof String && (type == char.class || type == Character.class)
            && ((String) o).length() == 1) {
        return ((String) o).charAt(0);
    } else if (o instanceof List && type instanceof Class && ((Class) type).isArray()) {
        Class<?> componentType = ((Class) type).getComponentType();
        List<Object> list = mapList(context, componentType, (List) o);
        return list.toArray((Object[]) Array.newInstance(componentType, list.size()));
    } else if (o instanceof List && acceptsList(type)) {
        return mapList(context, ((ParameterizedType) type).getActualTypeArguments()[0], (List) o);
    } else {
        throw new ClassCastException(context + " expects " + type + " but received " + o.getClass());
    }
}

From source file:org.zanata.seam.SeamAutowire.java

private void registerInterfaces(Class<?> cls) {
    assert !Modifier.isAbstract(cls.getModifiers());
    // register all interfaces registered by this bean
    for (Class<?> iface : getAllInterfaces(cls)) {
        this.beanImpls.put(iface, cls);
    }/*  w  w w  .  j  a  v a 2 s.  c  o m*/
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

private boolean hasMatchingAnnotation(final Annotation expectedAnnotation, final Annotation[] annotations)
        throws UnableToCompleteException {
    // See spec section 2.2. Applying multiple constraints of the same type
    for (final Annotation annotation : annotations) {
        // annotations not annotated by @Constraint
        if (annotation.annotationType().getAnnotation(Constraint.class) == null) {
            try {
                // value element has a return type of an array of constraint
                // annotations
                final Method valueMethod = annotation.annotationType().getMethod("value");
                final Class<?> valueType = valueMethod.getReturnType();
                if (valueType.isArray() && Annotation.class.isAssignableFrom(valueType.getComponentType())) {
                    if (Modifier.isAbstract(valueMethod.getModifiers())) {
                        // handle edge case where interface is marked "abstract"
                        valueMethod.setAccessible(true);
                    }//from   w w  w  .  j av a  2  s. com
                    final Annotation[] valueAnnotions = (Annotation[]) valueMethod.invoke(annotation);
                    for (final Annotation annotation2 : valueAnnotions) {
                        if (expectedAnnotation.equals(annotation2)) {
                            return true;
                        }
                    }
                }
            } catch (final NoSuchMethodException ignore) { // NOPMD
                // Expected Case.
            } catch (final Exception e) {
                throw error(this.logger, e);
            }
        }
    }
    return false;
}

From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java

public static boolean isAbstract(Method method) {
    return Modifier.isAbstract(method.getModifiers());
}

From source file:org.latticesoft.util.common.StringUtil.java

/**
 * Print the properties of an object into a xml string.
 * This is useful in the object's toString method.
 * @param o the object to be converted/*from   w  w  w  . j a  va  2  s .c om*/
 * @param mode one of the above mode
 * @param displayAll display all attributes including those which are null.
 * @return the string-fied xml form of the object
 */
public static String formatObjectToXmlString(Object o, int mode, boolean displayAll) {
    if (o == null)
        return "<NullClass/>";

    StringBuffer sb = new StringBuffer();
    String s = o.getClass().getName();
    String p = o.getClass().getPackage().getName();
    String className = s.substring(p.length() + 1, s.length());

    if (mode == StringUtil.MODE_END_TAG) {
        sb.append("</");
        sb.append(className);
        sb.append(">");
        return sb.toString();
    }

    sb.append("<");
    sb.append(className);

    // list of attributes
    Field f[] = o.getClass().getDeclaredFields();
    WrapDynaBean dyn = null;
    try {
        dyn = new WrapDynaBean(o);
    } catch (Exception e) {
    }

    for (int i = 0; i < f.length; i++) {
        String name = f[i].getName();
        int modifier = f[i].getModifiers();
        if (Modifier.isFinal(modifier) || Modifier.isAbstract(modifier) || Modifier.isInterface(modifier)
                || Modifier.isStatic(modifier)) {
            continue;
        }

        Object value = null;
        try {
            value = dyn.get(name);
        } catch (Exception e) {
            //if (log.isErrorEnabled()) { log.error(e); }
        }
        if (name != null) {
            if ((value != null && !displayAll) || (displayAll)) {
                sb.append(" ");
                sb.append(name);
                sb.append("=\"");
                sb.append(value);
                sb.append("\"");
            }
        }
    }
    switch (mode) {
    default:
    case StringUtil.MODE_FULL_STANDARD:
        sb.append("/>");
        break;
    case StringUtil.MODE_FULL_LONG:
        sb.append("></");
        sb.append(className);
        sb.append(">");
        break;
    case StringUtil.MODE_START_TAG:
        sb.append(">");
        break;
    }
    return sb.toString();
}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadAnnotatedClass(String subpackage, Class<?> objectClass, Class<?> annotationClass,
        AnnotatedClassHandler handler) throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + "." + subpackage;

    for (Class<?> cls : MiscUtilities.findSubclasses(objectClass, ipack, getClassLoader())) {

        /*/*from   w  w  w . ja  va2 s.  co m*/
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        /*
         * find class with annotation and send back to plugin to process it
         */
        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation.annotationType().equals(annotationClass)) {
                handler.process(annotation, cls, this);
            }
        }
    }
}

From source file:org.romaframework.core.schema.reflection.SchemaClassReflection.java

@Override
public boolean isAbstract() {
    return javaClass != null ? Modifier.isAbstract(javaClass.getModifiers()) : false;
}

From source file:adalid.core.XS1.java

private static boolean isRestrictedFieldType(Class<?> fieldType) {
    int modifiers = fieldType.getModifiers();
    boolean b = fieldType.isPrimitive();
    b |= Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers);
    b |= fieldType.isAnnotation();//  ww  w .  ja v a 2s .c o m
    b |= fieldType.isAnonymousClass();
    b |= fieldType.isArray();
    b |= fieldType.isEnum();
    b |= fieldType.isLocalClass();
    b |= fieldType.isInterface();
    return b;
}

From source file:ca.sqlpower.object.annotation.SPAnnotationProcessor.java

/**
 * Generates the Java source file that is a helper of {@link SPPersisterHelper}.
 * These helpers are not true {@link SPPersisterHelper}s because they only do
 * part of a helper's job. They also do not implement the interface because nothing
 * outside of the {@link SPPersisterHelper}s should be using them directly.
 * /* w  w  w .j  a v a 2s  . c  o  m*/
 * @param visitedClass
 *            The {@link SPObject} class that is being visited by the
 *            annotation processor.
 * @param constructorImports
 *            The {@link Set} of imports that the generated persister helper
 *            requires for calling the {@link Constructor} annotated
 *            constructor.
 * @param constructorParameters
 *            The {@link List} of {@link ConstructorParameterObject}s that
 *            contain information about what the parameter should be used
 *            for.
 * @param propertiesToAccess
 *            The {@link Map} of getter method names of persistable
 *            properties to its property type.
 * @param accessorAdditionalInfo
 *            The {@link Multimap} of getter methods mapped to additional
 *            properties a session {@link SPPersister} requires to convert
 *            the getter's returned value from a complex to basic
 *            persistable type.
 * @param mutatorImports
 *            The {@link Multimap} of setter methods to imports that the
 *            generated persister helper requires for calling the
 *            {@link Mutator} annotated setters.
 * @param propertiesToMutate
 *            The {@link Map} of setter method names of persistable
 *            properties to its property type.
 * @param mutatorExtraParameters
 *            The {@link Multimap} of setter methods mapped to each of its
 *            extra parameters (second parameter and onwards).
 * @param mutatorThrownTypes
 *            The {@link Multimap} of {@link Exception}s thrown by each
 *            persistable property setter.
 * @param propertiesToPersistOnlyIfNonNull
 *            The {@link Set} of persistable properties that can only be
 *            persisted if its value is not null.
 */
private void generateAbstractPersisterHelperFile(Class<? extends SPObject> visitedClass,
        Set<String> constructorImports, Map<String, Class<?>> propertiesToAccess,
        Multimap<String, String> accessorAdditionalInfo, Multimap<String, String> mutatorImports,
        Map<String, Class<?>> propertiesToMutate,
        Multimap<String, MutatorParameterObject> mutatorExtraParameters,
        Multimap<String, Class<? extends Exception>> mutatorThrownTypes,
        Set<String> propertiesToPersistOnlyIfNonNull) {
    try {
        final String helperPackage = visitedClass.getPackage().getName() + "."
                + PersisterHelperFinder.GENERATED_PACKAGE_NAME;
        final String simpleClassName = visitedClass.getSimpleName() + "PersisterHelper";
        final Class<?> superclass = visitedClass.getSuperclass();
        int tabs = 0;

        Filer f = environment.getFiler();
        PrintWriter pw = new PrintWriter(
                f.createSourceFile(helperPackage + "." + simpleClassName).openOutputStream());
        tabs++;
        final String commitPropertyMethod = generateCommitPropertyMethod(visitedClass, propertiesToMutate,
                mutatorExtraParameters, mutatorThrownTypes, tabs);
        final String findPropertyMethod = generateFindPropertyMethod(visitedClass, propertiesToAccess,
                accessorAdditionalInfo, tabs);
        final String persistObjectMethodHelper = generatePersistObjectMethodHelper(visitedClass,
                propertiesToAccess, propertiesToMutate, propertiesToPersistOnlyIfNonNull, tabs);
        final String getPersistedPropertiesMethod = generateGetPersistedPropertyListMethod(visitedClass,
                propertiesToMutate, tabs);
        tabs--;

        if (superclass == Object.class) {
            importedClassNames.add(AbstractSPPersisterHelper.class.getName());
        } else {
            importedClassNames.add(PersisterHelperFinder.getPersisterHelperClassName(superclass.getName()));
        }
        final String generateImports = generateImports(visitedClass, constructorImports, mutatorImports);

        pw.print(generateWarning());
        pw.print("\n");
        pw.print(generateLicense());
        pw.print("\n");
        pw.print("package " + helperPackage + ";\n");
        pw.print("\n");
        pw.print(generateImports);
        pw.print("\n");

        if (superclass == Object.class) {
            pw.print(String.format("public abstract class %s<%s extends %s> extends %s<%s> {\n",
                    simpleClassName, TYPE_GENERIC_PARAMETER, visitedClass.getSimpleName(),
                    AbstractSPPersisterHelper.class.getSimpleName(), TYPE_GENERIC_PARAMETER));
        } else if (Modifier.isAbstract(superclass.getModifiers())) {
            pw.print(String.format("public abstract class %s<%s extends %s> extends %s<%s> {\n",
                    simpleClassName, TYPE_GENERIC_PARAMETER, visitedClass.getSimpleName(),
                    superclass.getSimpleName() + "PersisterHelper", TYPE_GENERIC_PARAMETER));
        } else {
            pw.print(String.format("public abstract class %s<%s extends %s> extends %s {\n", simpleClassName,
                    TYPE_GENERIC_PARAMETER, visitedClass.getSimpleName() + "PersisterHelper",
                    superclass.getName()));
        }

        pw.print("\n");
        pw.print(commitPropertyMethod);
        pw.print("\n");
        pw.print(findPropertyMethod);
        pw.print("\n");
        pw.print(persistObjectMethodHelper);
        pw.print("\n");
        pw.print(getPersistedPropertiesMethod);
        pw.print("\n");

        pw.print("}\n");
        pw.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.seasar.s2click.S2ClickConfigService.java

private String getPageClassName(String pagePath, String pagesPackage) {
    String packageName = pagesPackage + ".";
    String className = "";

    // Strip off .htm extension
    String path = pagePath.substring(0, pagePath.lastIndexOf("."));

    if (path.indexOf("/") != -1) {
        StringTokenizer tokenizer = new StringTokenizer(path, "/");
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (tokenizer.hasMoreTokens()) {
                packageName = packageName + token + ".";
            } else {
                className = token;//  ww  w . j ava2  s  .co  m
            }
        }
    } else {
        className = path;
    }

    StringTokenizer tokenizer = new StringTokenizer(className, "_-");
    className = "";
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        token = Character.toUpperCase(token.charAt(0)) + token.substring(1);
        className += token;
    }

    className = packageName + className;
    // if(!className.endsWith("Page")){
    // className = className + "Page";
    // }
    // return className;

    Class pageClass = loadClass(className);
    if (pageClass != null) {
        if (!Page.class.isAssignableFrom(pageClass)) {
            String msg = "Automapped page class " + className + " is not a subclass of net.sf.click.Page";
            throw new RuntimeException(msg);
        }
    } else {

        boolean classFound = false;

        if (!className.endsWith("Page")) {
            className = className + "Page";
            pageClass = loadClass(className);
            if (pageClass != null) {
                if (!Page.class.isAssignableFrom(pageClass)) {
                    String msg = "Automapped page class " + className
                            + " is not a subclass of net.sf.click.Page";
                    throw new RuntimeException(msg);
                }

                classFound = true;
            }
        }

        if (!classFound) {
            if (logService.isDebugEnabled()) {
                logService.debug(pagePath + " -> CLASS NOT FOUND");
            }
            if (logService.isTraceEnabled()) {
                logService.trace("class not found: " + className);
            }
            return null;
        }
    }

    // abstract????
    if (Modifier.isAbstract(pageClass.getModifiers())) {
        return null;
    }

    return className;
}