List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
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;/* w w w.j a v a 2 s. c om*/ // 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.jbpm.formModeler.core.model.PojoDataHolder.java
private Set<DataFieldHolder> calculatePropertyNames() throws Exception { Class clazz = getHolderClass(); if (clazz == null) { return null; }//from ww w . j a v a2s . c o m Set<DataFieldHolder> dataFieldHolders = new TreeSet<DataFieldHolder>(); for (Field field : clazz.getDeclaredFields()) { if (isValidType(field.getType().getName())) { String capitalizedName = capitalize(field.getName()); try { Method setter = clazz.getDeclaredMethod("set" + capitalizedName, field.getType()); if (!setter.getReturnType().getName().equals("void") && !Modifier.isPublic(setter.getModifiers())) continue; Method getter; if (field.getType().equals(boolean.class)) getter = clazz.getDeclaredMethod("is" + capitalizedName); else getter = clazz.getDeclaredMethod("get" + capitalizedName); if (!getter.getReturnType().equals(field.getType()) && !Modifier.isPublic(getter.getModifiers())) continue; Type type = field.getGenericType(); DataFieldHolder fieldHolder; if (type instanceof ParameterizedType) { ParameterizedType generictype = (ParameterizedType) type; Type[] arguments = generictype.getActualTypeArguments(); if (arguments == null || arguments.length > 1) fieldHolder = new DataFieldHolder(this, field.getName(), field.getType().getName()); else fieldHolder = new DataFieldHolder(this, field.getName(), field.getType().getName(), ((Class<?>) arguments[0]).getName()); } else { fieldHolder = new DataFieldHolder(this, field.getName(), field.getType().getName()); } dataFieldHolders.add(fieldHolder); } catch (Exception e) { getLogger().debug("Unable to generate field holder for '{}': {}", field.getName(), e); } } } return dataFieldHolders; }
From source file:com.developmentsprint.spring.breaker.annotations.AbstractFallbackCircuitBreakerAttributeSource.java
/** * Same signature as {@link #getCircuitBreakerAttribute}, but doesn't cache the result. {@link #getCircuitBreakerAttribute} is effectively a caching * decorator for this method.//from w w w.j a v a 2s . c o m * * @see #getCircuitBreakerAttribute(Method, Class) */ private CircuitBreakerAttribute computeCircuitBreakerAttribute(Method method, Class<?> targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; } // Ignore CGLIB subclasses - introspect the actual user class. Class<?> userClass = ClassUtils.getUserClass(targetClass); // The method may be on an interface, but we need attributes from the target class. // If the target class is null, the method will be unchanged. Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass); // If we are dealing with method with generic parameters, find the original method. specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); // First try is the method in the target class. CircuitBreakerAttribute cbAttribute = findCircuitBreakerAttribute(specificMethod); if (cbAttribute != null) { return cbAttribute; } // Second try is the circuit breaker attribute on the target class. cbAttribute = findCircuitBreakerAttribute(specificMethod.getDeclaringClass()); if (cbAttribute != null) { return cbAttribute; } if (specificMethod != method) { // Fallback is to look at the original method. cbAttribute = findCircuitBreakerAttribute(method); if (cbAttribute != null) { return cbAttribute; } // Last fallback is the class of the original method. return findCircuitBreakerAttribute(method.getDeclaringClass()); } return null; }
From source file:com.github.jknack.handlebars.internal.BaseTemplate.java
/** * Creates a new {@link TypeSafeTemplate}. * * @param rootType The target type./*w w w . j av a 2 s .c om*/ * @param template The target template. * @return A new {@link TypeSafeTemplate}. */ private static Object newTypeSafeTemplate(final Class<?> rootType, final Template template) { return Proxy.newProxyInstance(template.getClass().getClassLoader(), new Class[] { rootType }, new InvocationHandler() { private Map<String, Object> attributes = new HashMap<String, Object>(); @Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws IOException { String methodName = method.getName(); if ("apply".equals(methodName)) { Context context = Context.newBuilder(args[0]).combine(attributes).build(); attributes.clear(); if (args.length == 2) { template.apply(context, (Writer) args[1]); return null; } return template.apply(context); } if (Modifier.isPublic(method.getModifiers()) && methodName.startsWith("set")) { String attrName = StringUtils.uncapitalize(methodName.substring("set".length())); if (args != null && args.length == 1 && attrName.length() > 0) { attributes.put(attrName, args[0]); if (TypeSafeTemplate.class.isAssignableFrom(method.getReturnType())) { return proxy; } return null; } } String message = String.format( "No handler method for: '%s(%s)', expected method signature is: 'setXxx(value)'", methodName, args == null ? "" : join(args, ", ")); throw new UnsupportedOperationException(message); } }); }
From source file:org.evosuite.testcase.fm.MethodDescriptor.java
/** * For example, do not mock methods with no return value * * @return/*from w w w .j a v a2 s . co m*/ */ public boolean shouldBeMocked() { int modifiers = method.getMethod().getModifiers(); if (method.getReturnType().equals(Void.TYPE) || method.getName().equals("equals") || method.getName().equals("hashCode") || Modifier.isPrivate(modifiers)) { return false; } if (Properties.hasTargetClassBeenLoaded()) { //null can happen in some unit tests if (!Modifier.isPublic(modifiers)) { assert !Modifier.isPrivate(modifiers); //previous checks String sutName = Properties.TARGET_CLASS; int lastIndexMethod = className.lastIndexOf('.'); int lastIndexSUT = sutName.lastIndexOf('.'); boolean samePackage; if (lastIndexMethod != lastIndexSUT) { samePackage = false; } else if (lastIndexMethod < 0) { samePackage = true; //default package } else { samePackage = className.substring(0, lastIndexMethod) .equals(sutName.substring(0, lastIndexSUT)); } if (!samePackage) { return false; } } } else { logger.warn("The target class should be loaded before invoking this method"); } return true; }
From source file:de.contentreich.instrumentation.SpringBeansHelper.java
public List<String[]> getPublicMethodSignatures(String className) { logger.debug("Get public method signatures for class " + className); ArrayList<String[]> methodSignatures = new ArrayList<String[]>(); try {/*from ww w. ja va 2 s.c o m*/ Class clazz = Class.forName(className); List<Method> methods = (List<Method>) Arrays.asList(clazz.getMethods()); // Filtering - a pita in java for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) { Method method = iterator.next(); if (!method.getDeclaringClass().getName().startsWith("java") && Modifier.isPublic(method.getModifiers())) { methodSignatures.add(new String[] { method.toString(), method.getDeclaringClass().getName() }); } } Collections.sort(methodSignatures, new Comparator() { @Override public int compare(Object o1, Object o2) { String s1 = ((String[]) o1)[0]; String s2 = ((String[]) o2)[0]; return s1.compareTo(s2); } }); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return methodSignatures; }
From source file:org.apache.velocity.util.introspection.ClassMap.java
private void populateMethodCacheWith(MethodCache methodCache, Class classToReflect) { if (debugReflection && Logger.isDebugEnabled(this.getClass())) { Logger.debug(this, "Reflecting " + classToReflect); }/*ww w .j a va 2 s . c om*/ try { Method[] methods = classToReflect.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { int modifiers = methods[i].getModifiers(); if (Modifier.isPublic(modifiers)) { methodCache.put(methods[i]); } } } catch (SecurityException se) // Everybody feels better with... { if (Logger.isDebugEnabled(this.getClass())) { Logger.debug(this, "While accessing methods of " + classToReflect + ": ", se); } } }
From source file:com.kangyonggan.cms.util.Reflections.java
/** * ?private/protectedpublic?????JDKSecurityManager *//*w w w . j ava 2 s . c o m*/ public static void makeAccessible(Method method) { boolean temp = (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible(); if (temp) { method.setAccessible(true); } }
From source file:grails.plugin.cache.GrailsAnnotationCacheOperationSource.java
protected Collection<CacheOperation> computeCacheOperations(Method method, Class<?> targetClass) { // Don't allow no-public methods as required. if (publicMethodsOnly && !Modifier.isPublic(method.getModifiers())) { return null; }// w w w.ja v a2 s . co m // The method may be on an interface, but we need attributes from the target class. // If the target class is null, the method will be unchanged. Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass); // If we are dealing with method with generic parameters, find the original method. specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); // First try is the method in the target class. Collection<CacheOperation> opDef = findCacheOperations(specificMethod); if (opDef != null) { return opDef; } // Second try is the caching operation on the target class. opDef = findCacheOperations(specificMethod.getDeclaringClass()); if (opDef != null) { return opDef; } if (specificMethod != method) { // Fall back is to look at the original method. opDef = findCacheOperations(method); if (opDef != null) { return opDef; } // Last fall back is the class of the original method. return findCacheOperations(method.getDeclaringClass()); } return null; }
From source file:com.qcadoo.view.internal.CustomMethodHolder.java
private void checkMethodSignature() { if (!Modifier.isPublic(method.getModifiers())) { final String msg = String.format(WRONG_VISIBILITY_MSG, method.getDeclaringClass().getCanonicalName(), method.getName());//w ww. j a va 2 s . c om throw new IllegalStateException(msg); } if (!expectedReturnType.equals(method.getReturnType())) { final String msg = String.format(WRONG_RETURN_TYPE_MSG, method.getDeclaringClass().getCanonicalName(), method.getName(), expectedReturnType); throw new IllegalStateException(msg); } }