List of usage examples for java.lang.reflect Modifier isProtected
public static boolean isProtected(int mod)
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void protecedConstructors() { memberCriteria.membersOfType(Constructor.class); memberCriteria.withAccess(AccessType.PROTECTED); 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 constructor", member instanceof Constructor<?>); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertTrue(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); }// w w w . ja v a2 s . c om }
From source file:org.apache.felix.webconsole.AbstractWebConsolePlugin.java
/** * Returns a method which is called on the * {@link #getResourceProvider() resource provider} class to return an URL * to a resource which may be spooled when requested. The method has the * following signature:/*from w ww. j a va 2s . c o m*/ * <pre> * [modifier] URL getResource(String path); * </pre> * Where the <i>[modifier]</i> may be <code>public</code>, <code>protected</code> * or <code>private</code> (if the method is declared in the class of the * resource provider). It is suggested to use the <code>private</code> * modifier if the method is declared in the resource provider class or * the <code>protected</code> modifier if the method is declared in a * base class of the resource provider. * * @return The <code>getResource(String)</code> method or <code>null</code> * if the {@link #getResourceProvider() resource provider} is * <code>null</code> or does not provide such a method. */ private final Method getGetResourceMethod() { // return what we know of the getResourceMethod, if we already checked if (getResourceMethodChecked) { return getResourceMethod; } Method tmpGetResourceMethod = null; Object resourceProvider = getResourceProvider(); if (resourceProvider != null) { try { Class cl = resourceProvider.getClass(); while (tmpGetResourceMethod == null && cl != Object.class) { Method[] methods = cl.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; if (GET_RESOURCE_METHOD_NAME.equals(m.getName()) && m.getParameterTypes().length == 1 && m.getParameterTypes()[0] == String.class && m.getReturnType() == URL.class) { // ensure modifier is protected or public or the private // method is defined in the plugin class itself int mod = m.getModifiers(); if (Modifier.isProtected(mod) || Modifier.isPublic(mod) || (Modifier.isPrivate(mod) && cl == resourceProvider.getClass())) { m.setAccessible(true); tmpGetResourceMethod = m; break; } } } cl = cl.getSuperclass(); } } catch (Throwable t) { tmpGetResourceMethod = null; } } // set what we have found and prevent future lookups getResourceMethod = tmpGetResourceMethod; getResourceMethodChecked = true; // now also return the method return getResourceMethod; }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteria.java
/** * Set the criterion that selects only {@link Member}s that exactly have the * specified modifiers. The access modifiers are set separately. Use * {@link #withAccess(AccessType...)} to set access modifiers. * * @param modifiers/*from w ww . j a va2 s .com*/ * @since 1.0.0.0 */ public void withModifiers(int modifiers) { if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)) { throw new IllegalArgumentException( "access modifiers are not allowed as argument. Use withAccess() instead."); } int allowedModifiers = Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE; if ((modifiers & allowedModifiers) == 0) { throw new IllegalArgumentException( "modifiers must be one of [" + Modifier.toString(allowedModifiers) + "]"); } this.modifiers = modifiers; }
From source file:com.judoscript.jamaica.parser.JamaicaDumpVisitor.java
static void printAccessFlags(int flags) { if (Modifier.isPublic(flags)) out.print("public "); else if (Modifier.isProtected(flags)) out.print("protected "); else if (Modifier.isPrivate(flags)) out.print("private "); if (Modifier.isAbstract(flags)) out.print("abstract "); if (Modifier.isFinal(flags)) out.print("final "); if (Modifier.isNative(flags)) out.print("native "); if (Modifier.isStatic(flags)) out.print("static "); if (Modifier.isStrict(flags)) out.print("strict "); if (Modifier.isSynchronized(flags)) out.print("synchronized "); if (Modifier.isTransient(flags)) out.print("transient "); if (Modifier.isVolatile(flags)) out.print("volative "); }
From source file:name.yumaa.ChromeLogger4J.java
/** * Converts an object to a better format for logging * @param object variable to conver//from w w w . j a v a2 s . co m * @param depth recursion depth * @return converted object, ready to put to JSON */ private Object convert(Object object, int depth) { // *** return simple types as is *** if (object == null || object instanceof String || object instanceof Number || object instanceof Boolean) return object; // *** other simple types *** if (object instanceof Character || object instanceof StringBuffer || object instanceof StringBuilder || object instanceof Currency || object instanceof Date || object instanceof Locale) return object.toString(); if (object instanceof Calendar) return ((Calendar) object).getTime().toString(); if (object instanceof SimpleDateFormat) return ((SimpleDateFormat) object).toPattern(); // check recursion depth if (depth > this.depth) return "d>" + this.depth; // mark this object as processed so we don't convert it twice and it // also avoid recursion when objects refer to each other processed.add(object); // *** not so simple types, but we can foreach it *** if (object instanceof Map) { JSONObject jobject = new JSONObject(); for (Object key : ((Map<Object, Object>) object).keySet()) { Object value = ((Map<Object, Object>) object).get(key); addValue(jobject, key.toString(), value, depth); } return jobject; } if (object instanceof Collection) { JSONArray jobject = new JSONArray(); for (Object value : (Collection<Object>) object) addValue(jobject, value, depth); return jobject; } if (object instanceof Iterable) { JSONArray jobject = new JSONArray(); for (Object value : (Iterable<Object>) object) addValue(jobject, value, depth); return jobject; } if (object instanceof Object[]) { JSONArray jobject = new JSONArray(); for (Object value : (Object[]) object) addValue(jobject, value, depth); return jobject; } // *** object of unknown type *** JSONObject jobject = new JSONObject(); Class<?> cls = object.getClass(); jobject.put("___class_name", cls.getName()); // add the class name jobject.put("___toString()", object.toString()); // and to string representation if (!this.reflect) return jobject; // get all properties using reflection if (this.reflectfields) { try { for (Field field : cls.getDeclaredFields()) { Boolean access = field.isAccessible(); field.setAccessible(true); int mod = field.getModifiers(); String key = getKey(mod, field.getName()); Object value; try { value = field.get(object); } catch (Exception e) { value = e.toString(); } field.setAccessible(access); if (!this.reflectprivate && (Modifier.isPrivate(mod) || Modifier.isProtected(mod))) continue; if (!this.reflectstatic && Modifier.isStatic(mod)) continue; addValue(jobject, key, value, depth); } } catch (SecurityException e) { } } // get all methods using reflection if (this.reflectmethods) { try { JSONObject methods = new JSONObject(); for (Method method : cls.getDeclaredMethods()) { Boolean access = method.isAccessible(); method.setAccessible(true); Class<?>[] params = method.getParameterTypes(); StringBuilder parameters = new StringBuilder(""); for (int i = 0, j = params.length; i < j; i++) { parameters.append(params[i].getName()); if (i + 1 < j) parameters.append(", "); } int mod = method.getModifiers(); String key = getKey(mod, method.getName() + "(" + parameters.toString() + ")"); String value = method.getReturnType().getName(); method.setAccessible(access); if (!this.reflectprivate && (Modifier.isPrivate(mod) || Modifier.isProtected(mod))) continue; if (!this.reflectstatic && Modifier.isStatic(mod)) continue; methods.put(key, value); } jobject.put("___methods", methods); } catch (SecurityException e) { } } return jobject; }
From source file:name.yumaa.ChromeLogger4J.java
/** * Returns a nicely formatted key of the field or method name * @param mod .getModifiers()// w w w . j a va2 s. co m * @param end key ending * @return class member keys, converted to string */ private String getKey(int mod, String end) { StringBuilder key = new StringBuilder(""); if (Modifier.isPublic(mod)) key.append("public "); if (Modifier.isPrivate(mod)) key.append("private "); if (Modifier.isProtected(mod)) key.append("protected "); if (Modifier.isStatic(mod)) key.append("static "); if (Modifier.isTransient(mod)) key.append("transient "); if (Modifier.isVolatile(mod)) key.append("volatile "); if (Modifier.isFinal(mod)) key.append("final "); if (Modifier.isSynchronized(mod)) key.append("synchronized "); return key.append(end).toString(); }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
private void ensureNoProtectedOrPrivateMethods(ModelSchemaExtractionContext<?> extractionContext, Class<?> typeClass) { Class<?> superClass = typeClass.getSuperclass(); if (superClass != null && !superClass.equals(Object.class)) { ensureNoProtectedOrPrivateMethods(extractionContext, superClass); }/*from w ww .java 2 s .c o m*/ Iterable<Method> protectedAndPrivateMethods = Iterables .filter(Arrays.asList(typeClass.getDeclaredMethods()), new Predicate<Method>() { @Override public boolean apply(Method method) { int modifiers = method.getModifiers(); return !method.isSynthetic() && (Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)); } }); if (!Iterables.isEmpty(protectedAndPrivateMethods)) { throw invalidMethods(extractionContext, "protected and private methods are not allowed", protectedAndPrivateMethods); } }
From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java
protected boolean doSkip(Field field) { return Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()) || Modifier.isProtected(field.getModifiers()) || Modifier.isPrivate(field.getModifiers()); }
From source file:com.lucidtechnics.blackboard.TargetConstructor.java
private final static List findProtectedMethods(Class _class) { List methodList = new ArrayList(); Enhancer.getMethods(_class, null, methodList); Predicate mutatorPredicate = new Predicate() { public boolean evaluate(Object _object) { Method method = (Method) _object; boolean isProtected = (Modifier.isProtected(method.getModifiers()) == true); return isProtected; }/*from www . java2s . c o m*/ }; CollectionUtils.filter(methodList, mutatorPredicate); return methodList; }
From source file:com.parse.ParseObject.java
private static boolean isAccessible(Member m) { return Modifier.isPublic(m.getModifiers()) || (m.getDeclaringClass().getPackage().getName().equals("com.parse") && !Modifier.isPrivate(m.getModifiers()) && !Modifier.isProtected(m.getModifiers())); }