List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:ch.ifocusit.plantuml.classdiagram.ClassDiagramBuilder.java
public ClassMethod[] readMethods(Class aClass) { return Stream.of(aClass.getDeclaredMethods()) // only public and non static methods .filter(method -> !Modifier.isStatic(method.getModifiers()) && Modifier.isPublic(method.getModifiers())) .map(this::createClassMethod) // excludes specific fields .filter(filterMethods()).sorted().toArray(ClassMethod[]::new); }
From source file:com.espertech.esper.util.MethodResolver.java
private static boolean isPublicAndStatic(Method method, boolean allowInstance) { int modifiers = method.getModifiers(); if (allowInstance) { return Modifier.isPublic(modifiers); } else {/*from w w w .j av a2s .c o m*/ return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers); } }
From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java
private static ClassData analyzeClass(Class clazz) { log.info("analyzing " + clazz.getName()); Method methods[] = clazz.getMethods(); ClassData cd = new ClassData(); cd.clazz = clazz;//from ww w .jav a 2 s . co m // Create temporary method map HashMap staticMethodMap = new HashMap(); HashMap methodMap = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getDeclaringClass() == Object.class) continue; int mod = methods[i].getModifiers(); if (!Modifier.isPublic(mod)) continue; Class param[] = method.getParameterTypes(); // don't count locally resolved args int argCount = 0; synchronized (localArgResolverMap) { for (int n = 0; n < param.length; n++) { HashSet resolvers = (HashSet) localArgResolverMap.get(param[n]); if (resolvers != null) continue; argCount++; } } MethodKey mk = new MethodKey(method.getName(), argCount); ArrayList marr = (ArrayList) methodMap.get(mk); if (marr == null) { marr = new ArrayList(); methodMap.put(mk, marr); } marr.add(method); if (Modifier.isStatic(mod)) { marr = (ArrayList) staticMethodMap.get(mk); if (marr == null) { marr = new ArrayList(); staticMethodMap.put(mk, marr); } marr.add(method); } } cd.methodMap = new HashMap(); cd.staticMethodMap = new HashMap(); // Convert ArrayLists to arrays Iterator i = methodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.methodMap.put(mk, marr.get(0)); } else { cd.methodMap.put(mk, marr.toArray(new Method[0])); } } i = staticMethodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.staticMethodMap.put(mk, marr.get(0)); } else { cd.staticMethodMap.put(mk, marr.toArray(new Method[0])); } } return cd; }
From source file:org.apache.sling.scripting.sightly.impl.compiler.CompileTimeObjectModel.java
private static Method extractMethodInheritanceChain(Class type, Method m) { if (m == null || Modifier.isPublic(type.getModifiers())) { return m; }/*from w w w . j a v a 2 s . c om*/ Class[] iFaces = type.getInterfaces(); Method mp; for (Class<?> iFace : iFaces) { mp = getClassMethod(iFace, m); if (mp != null) { return mp; } } return getClassMethod(type.getSuperclass(), m); }
From source file:com.link_intersystems.lang.reflect.Member2.java
/** * @param referenceMember//w ww . ja v a 2 s.co m * @return true if the access modifier of this {@link Member2} are less * restrictive than the access modifier of the referenceInvokable. * <p> * Logic according to the java language specification: * * <pre> * The access modifier (6.6) of an overriding or hiding method must provide at least as much access as the overridden or hidden method, or a compile-time error occurs. In more detail: * <ul> * <li>If the overridden or hidden method is <code>public</code>, * then the overriding or hiding method must be <code>public</code>; * otherwise, a compile-time error occurs. <a name="39550"></a></li> * <li>If the overridden or hidden method is <code>protected</code>, * then the overriding or hiding method must be * <code>protected</code> or <code>public</code>; otherwise, a * compile-time error occurs. <a name="39551"></a></li> * <li>If the overridden or hidden method has default (package) * access, then the overriding or hiding method must not be * <code>private</code>; otherwise, a compile-time error occurs. * * </li> * </ul> * </pre> * * <pre> * +---------------------------------------------------------------------+ * | this | * +----------------+----------------+-------------------+---------------+ * | public | protected | package (default) | private | * +-----------+-------------------+----------------+----------------+-------------------+---------------+ * | | public | true | false | false | false | * | +-------------------+----------------+----------------+-------------------+---------------+ * | reference | protected | true | true | false | false | * | +-------------------+----------------+----------------+-------------------+---------------+ * | invokable | package (default) | true | true | true | false | * | +-------------------+----------------+----------------+-------------------+---------------+ * | | private | false | false | false | false | * +-----------+-------------------+----------------+----------------+-------------------+---------------+ * </pre> * * </p> * @since 1.0.0.0 */ protected boolean isAccessModifierOverriddingCompatible(Member2<?> referenceMember) { int referenceModifiers = referenceMember.getModifiers(); int invokableModifiers = getModifiers(); if (Modifier.isPrivate(referenceModifiers) || Modifier.isPrivate(invokableModifiers)) { return false; } if (Modifier.isPublic(referenceModifiers)) { return Modifier.isPublic(invokableModifiers); } if (Modifier.isProtected(referenceModifiers)) { return Modifier.isProtected(invokableModifiers) || Modifier.isPublic(invokableModifiers); } return true; }
From source file:ca.sqlpower.object.PersistedSPObjectTest.java
/** * All persistable {@link SPObject} implementations must define a static * final field which is a list defining the absolute ordering of that * class's child type classes. This method ensures that list is retrievable * by reflection from the object, that the field is public, static, and * final, and that it is nonempty for classes that allow children and empty * for classes that do not allow children. *//*from w w w .j a va 2 s. c o m*/ @SuppressWarnings("unchecked") public void testAllowedChildTypesField() throws Exception { Class<? extends SPObject> classUnderTest = getSPObjectUnderTest().getClass(); Field childOrderField; try { childOrderField = classUnderTest.getDeclaredField("allowedChildTypes"); } catch (NoSuchFieldException ex) { fail("Persistent " + classUnderTest + " must have a static final field called allowedChildTypes"); throw new AssertionError(); // NOTREACHED } assertEquals("The allowedChildTypes field must be final", true, Modifier.isFinal(childOrderField.getModifiers())); assertEquals("The allowedChildTypes field must be static", true, Modifier.isStatic(childOrderField.getModifiers())); // Note: in the future, we will change this to require that the field is private assertEquals("The allowedChildTypes field must be public", true, Modifier.isPublic(childOrderField.getModifiers())); List<Class<? extends SPObject>> allowedChildTypes = (List<Class<? extends SPObject>>) childOrderField .get(null); if (getSPObjectUnderTest().allowsChildren()) { assertFalse(allowedChildTypes.isEmpty()); } else { assertTrue(allowedChildTypes.isEmpty()); } }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void defaultAccessMethodsWithStaticNativeOnly() { memberCriteria.membersOfType(Method.class); memberCriteria.withAccess(AccessType.DEFAULT); memberCriteria.withModifiers(Modifier.STATIC | Modifier.NATIVE); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a method", member instanceof Method); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); assertTrue(Modifier.isStatic(modifiers)); assertTrue(Modifier.isNative(modifiers)); }/*from ww w . j a va2 s. c o m*/ }
From source file:HashNMap.java
/** * Returns a clone of the specified object, if it can be cloned, otherwise * throws a CloneNotSupportedException.// ww w. j a v a 2 s . co m * * @param object * the object to clone (<code>null</code> not permitted). * @return A clone of the specified object. * @throws CloneNotSupportedException * if the object cannot be cloned. */ public static Object clone(final Object object) throws CloneNotSupportedException { if (object == null) { throw new IllegalArgumentException("Null 'object' argument."); } else { try { final Method method = object.getClass().getMethod("clone", (Class[]) null); if (Modifier.isPublic(method.getModifiers())) { return method.invoke(object, (Object[]) null); } } catch (Exception e) { } } throw new CloneNotSupportedException("Failed to clone."); }
From source file:microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema.java
/** * Initialize schema property names.//from ww w. j ava 2s .c om */ public static void initializeSchemaPropertyNames() { synchronized (lockObject) { for (Class<?> type : ServiceObjectSchema.allSchemaTypes.getMember()) { Field[] fields = type.getDeclaredFields(); for (Field field : fields) { int modifier = field.getModifiers(); if (Modifier.isPublic(modifier) && Modifier.isStatic(modifier)) { Object o; try { o = field.get(null); if (o instanceof PropertyDefinition) { PropertyDefinition propertyDefinition = (PropertyDefinition) o; propertyDefinition.setName(field.getName()); } } catch (IllegalArgumentException e) { LOG.error(e); // Skip the field } catch (IllegalAccessException e) { LOG.error(e); // Skip the field } } } } } }