Example usage for java.lang.reflect Modifier isPublic

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

Introduction

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

Prototype

public static boolean isPublic(int mod) 

Source Link

Document

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

Usage

From source file:com.espertech.esper.epl.core.EngineImportServiceImpl.java

public Method resolveMethod(String className, String methodName) throws EngineImportException {
    Class clazz;/*from ww  w .  ja v  a2s .co  m*/
    try {
        clazz = resolveClassInternal(className, false);
    } catch (ClassNotFoundException e) {
        throw new EngineImportException(
                "Could not load class by name '" + className + "', please check imports", e);
    }

    Method methods[] = clazz.getMethods();
    Method methodByName = null;

    // check each method by name
    for (Method method : methods) {
        if (method.getName().equals(methodName)) {
            if (methodByName != null) {
                throw new EngineImportException("Ambiguous method name: method by name '" + methodName
                        + "' is overloaded in class '" + className + "'");
            }
            int modifiers = method.getModifiers();
            if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)) {
                methodByName = method;
            }
        }
    }

    if (methodByName == null) {
        throw new EngineImportException(
                "Could not find static method named '" + methodName + "' in class '" + className + "'");
    }
    return methodByName;
}

From source file:org.gridgain.grid.spi.deployment.uri.GridUriDeploymentFileProcessor.java

/**
 * Check that class may be instantiated as {@link GridComputeTask} and used
 * in deployment./*from   w w w  .j  a  va  2  s .  c  om*/
 *
 * Loaded task class must implement interface {@link GridComputeTask}.
 * Only non-abstract, non-interfaces and public classes allowed.
 * Inner static classes also allowed for loading.
 *
 * @param cls Class to check
 * @return {@code true} if class allowed for deployment.
 */
private static boolean isAllowedTaskClass(Class<?> cls) {
    if (!GridComputeTask.class.isAssignableFrom(cls))
        return false;

    int modifiers = cls.getModifiers();

    return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers)
            && (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers);
}

From source file:net.abhinavsarkar.spelhelper.SpelHelper.java

private static List<Method> filterFunctions(final Class<?> clazz) {
    List<Method> allowedMethods = new ArrayList<Method>();
    for (Method method : clazz.getMethods()) {
        int modifiers = method.getModifiers();
        if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)
                && !method.getReturnType().equals(Void.TYPE)) {
            allowedMethods.add(method);/* w  ww . ja v  a  2 s .  com*/
        }
    }
    return allowedMethods;
}

From source file:com.datos.vfs.util.DelegatingFileSystemOptionsBuilder.java

/**
 * create the list of all set*() methods for the given scheme
 *//*  www . j  av  a2 s.c o m*/
private Map<String, List<Method>> createSchemeMethods(final String scheme) throws FileSystemException {
    final FileSystemConfigBuilder fscb = getManager().getFileSystemConfigBuilder(scheme);
    if (fscb == null) {
        throw new FileSystemException("vfs.provider/no-config-builder.error", scheme);
    }

    final Map<String, List<Method>> schemeMethods = new TreeMap<>();

    final Method[] methods = fscb.getClass().getMethods();
    for (final Method method : methods) {
        if (!Modifier.isPublic(method.getModifiers())) {
            continue;
        }

        final String methodName = method.getName();
        if (!methodName.startsWith("set")) {
            // not a setter
            continue;
        }

        final String key = methodName.substring(3).toLowerCase();

        List<Method> configSetter = schemeMethods.get(key);
        if (configSetter == null) {
            configSetter = new ArrayList<>(2);
            schemeMethods.put(key, configSetter);
        }
        configSetter.add(method);
    }

    return schemeMethods;
}

From source file:org.guicerecipes.spring.support.AutowiredMemberProvider.java

/**
 * Returns a new instance of the given class if its a public non abstract class which has a public zero argument constructor otherwise returns null
 *///from  ww w  .  j av a 2 s.  com
protected Object tryCreateInstance(Class<?> type) {
    Object answer = null;
    int modifiers = type.getModifiers();
    if (!Modifier.isAbstract(modifiers) && Modifier.isPublic(modifiers) && !type.isInterface()) {
        // if its a concrete class with no args make one
        Constructor<?> constructor = null;
        try {
            constructor = type.getConstructor();
        } catch (NoSuchMethodException e) {
            // ignore
        }
        if (constructor != null) {
            if (Modifier.isPublic(constructor.getModifiers())) {
                try {
                    answer = constructor.newInstance();
                } catch (InstantiationException e) {
                    throw new ProvisionException("Failed to instantiate " + constructor, e);
                } catch (IllegalAccessException e) {
                    throw new ProvisionException("Failed to instantiate " + constructor, e);
                } catch (InvocationTargetException ie) {
                    Throwable e = ie.getTargetException();
                    throw new ProvisionException("Failed to instantiate " + constructor, e);
                }
            }
        }
    }
    return answer;
}

From source file:org.apache.ignite.spi.deployment.uri.GridUriDeploymentFileProcessor.java

/**
 * Check that class may be instantiated as {@link org.apache.ignite.compute.ComputeTask} and used
 * in deployment.//from w  w w .j  a v a2  s .  c  o  m
 *
 * Loaded task class must implement interface {@link org.apache.ignite.compute.ComputeTask}.
 * Only non-abstract, non-interfaces and public classes allowed.
 * Inner static classes also allowed for loading.
 *
 * @param cls Class to check
 * @return {@code true} if class allowed for deployment.
 */
private static boolean isAllowedTaskClass(Class<?> cls) {
    if (!ComputeTask.class.isAssignableFrom(cls))
        return false;

    int modifiers = cls.getModifiers();

    return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers)
            && (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers);
}

From source file:com.espertech.esper.util.MethodResolver.java

public static Constructor resolveCtor(Class declaringClass, Class[] paramTypes)
        throws EngineNoSuchCtorException {
    // Get all the methods for this class
    Constructor[] ctors = declaringClass.getConstructors();

    Constructor bestMatch = null;
    int bestConversionCount = -1;

    // Examine each method, checking if the signature is compatible
    Constructor conversionFailedCtor = null;
    for (Constructor ctor : ctors) {
        // Check the modifiers: we only want public
        if (!Modifier.isPublic(ctor.getModifiers())) {
            continue;
        }//w  w w  .ja v a  2 s  .  c  om

        // Check the parameter list
        int conversionCount = compareParameterTypesNoContext(ctor.getParameterTypes(), paramTypes, null, null,
                ctor.getGenericParameterTypes());

        // Parameters don't match
        if (conversionCount == -1) {
            conversionFailedCtor = ctor;
            continue;
        }

        // Parameters match exactly
        if (conversionCount == 0) {
            bestMatch = ctor;
            break;
        }

        // No previous match
        if (bestMatch == null) {
            bestMatch = ctor;
            bestConversionCount = conversionCount;
        } else {
            // Current match is better
            if (conversionCount < bestConversionCount) {
                bestMatch = ctor;
                bestConversionCount = conversionCount;
            }
        }

    }

    if (bestMatch != null) {
        return bestMatch;
    } else {
        StringBuilder parameters = new StringBuilder();
        String message = "Constructor not found for " + declaringClass.getSimpleName() + " taking ";
        if (paramTypes != null && paramTypes.length != 0) {
            String appendString = "";
            for (Object param : paramTypes) {
                parameters.append(appendString);
                if (param == null) {
                    parameters.append("(null)");
                } else {
                    parameters.append(param.toString());
                }
                appendString = ", ";
            }
            message += "('" + parameters + "')'";
        } else {
            message += "no parameters";
        }
        throw new EngineNoSuchCtorException(message, conversionFailedCtor);
    }
}

From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java

@Override
public void runTest() throws Throwable {
    Method runMethod = null;// ww  w  .j  a v  a  2 s.  c  o m
    try {
        runMethod = this.getClass().getMethod(getMethodName(), (Class[]) null);
    } catch (NoSuchMethodException e) {
        fail("Method \"" + getMethodName() + "\" not found");
    }
    if (!Modifier.isPublic(runMethod.getModifiers())) {
        fail("Method \"" + getMethodName() + "\" should be public");
    }

    try {
        runMethod.invoke(this, (Object[]) new Class[0]);
    } catch (InvocationTargetException e) {
        e.fillInStackTrace();
        throw e.getTargetException();
    } catch (IllegalAccessException e) {
        e.fillInStackTrace();
        throw e;
    }
}

From source file:com.github.venkateshamurthy.designpatterns.builders.FluentBuilders.java

private Set<Method> getWritableNormalMethods(final Class<?> thisPojoClass) throws NotFoundException {
    final CtClass ctClass = ctPool.get(thisPojoClass.getName());
    final Set<CtMethod> ctMethodSet = new LinkedHashSet<>(); // Gets
                                                             // collected
    final Set<Method> methodSet = new LinkedHashSet<>(); // Gets collected

    final Set<Class<?>> propTypes = getPropertyClassTypes(thisPojoClass, ctClass, ctMethodSet);

    for (Method method : thisPojoClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            LOGGER.warning(method.getName() + " is synthetically added, so ignoring");
            continue;
        }//  ww  w .j a v a 2 s .  c o m
        if (Modifier.isPublic(method.getModifiers())
                && setMethodNamePattern.matcher(method.getName()).matches()) {
            methodSet.add(method);
        }
        final CtMethod ctMethod = ctClass.getDeclaredMethod(method.getName());
        if (Modifier.isPublic(method.getModifiers()) && setMethodNamePattern.matcher(method.getName()).matches()
                && !ctMethodSet.contains(ctMethod)) {

            // Make sure the types u get from method is really is of a field
            // type
            boolean isAdded = propTypes.containsAll(Arrays.asList(method.getParameterTypes()))
                    && ctMethodSet.add(ctMethod);
            if (!isAdded) {
                LOGGER.warning(method.getName() + " is not added");
            }
        }
    }
    return methodSet;
}

From source file:org.assertj.assertions.generator.util.ClassUtil.java

private static boolean isNotStaticPublicField(Field field) {
    final int modifiers = field.getModifiers();
    return !Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers);
}