List of usage examples for java.lang.reflect Modifier isProtected
public static boolean isProtected(int mod)
From source file:gaffer.rest.service.SimpleGraphConfigurationService.java
private static void keepPublicConcreteClasses(final Collection<Class> classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); while (itr.hasNext()) { final Class clazz = itr.next(); if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();// w ww . j a v a 2s . co m } } } } }
From source file:com.gu.management.spring.ManagementUrlDiscoveryService.java
private boolean isRequestableMethod(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); boolean isPublic = Modifier.isPublic(method.getModifiers()); boolean isProtected = Modifier.isProtected(method.getModifiers()); boolean returnsModelAndView = method.getReturnType().equals(ModelAndView.class); boolean takesRequestAndResponse = parameterTypes.length >= 2 && HttpServletRequest.class.isAssignableFrom(parameterTypes[0]) && HttpServletResponse.class.isAssignableFrom(parameterTypes[1]); return (isPublic || isProtected) && (returnsModelAndView || takesRequestAndResponse); }
From source file:objenome.util.bytecode.SgUtils.java
/** * Checks if the modifiers are valid for a method. If any of the modifiers * is not valid an <code>IllegalArgumentException</code> is thrown. * /*from ww w . j a v a 2 s.c o m*/ * @param modifiers * Modifiers. */ // CHECKSTYLE:OFF Cyclomatic complexity is OK public static void checkMethodModifiers(int modifiers) { // Base check checkModifiers(METHOD, modifiers); // Check overlapping modifiers if (Modifier.isPrivate(modifiers)) { if (Modifier.isProtected(modifiers) || Modifier.isPublic(modifiers)) { throw new IllegalArgumentException( METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']'); } } if (Modifier.isProtected(modifiers)) { if (Modifier.isPrivate(modifiers) || Modifier.isPublic(modifiers)) { throw new IllegalArgumentException( METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']'); } } if (Modifier.isPublic(modifiers)) { if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { throw new IllegalArgumentException( METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']'); } } // Check illegal abstract modifiers if (Modifier.isAbstract(modifiers)) { if (Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers) || Modifier.isNative(modifiers) || Modifier.isStrict(modifiers) || Modifier.isSynchronized(modifiers)) { throw new IllegalArgumentException( METHOD_ILLEGAL_ABSTRACT_MODIFIERS_ERROR + " [" + Modifier.toString(modifiers) + ']'); } } // Check native and strictfp if (Modifier.isNative(modifiers) && Modifier.isStrict(modifiers)) { throw new IllegalArgumentException( METHOD_NATIVE_STRICTFP_ERROR + " [" + Modifier.toString(modifiers) + ']'); } }
From source file:org.testng.spring.test.AbstractDependencyInjectionSpringContextTests.java
private boolean isProtectedInstanceField(Field field) { int modifiers = field.getModifiers(); return !Modifier.isStatic(modifiers) && Modifier.isProtected(modifiers); }
From source file:org.alfresco.module.org_alfresco_module_rm.api.PublicAPITestUtil.java
/** * Check if the supplied {@link Executable#getModifiers() modifiers} indicate that an extension can access the * element. Here we assume that an extension can see public and protected items, but not package protected (or * private).//from w ww.j av a2 s . c o m * * @param modifiers The java language modifiers. * @return {@code true} if the item is visible to an extension. */ private static boolean isVisibleToExtender(int modifiers) { return Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers); }
From source file:org.evosuite.testcase.statements.FunctionalMockStatementTest.java
@Test public void testConfirmPackageLevel() throws Exception { Method m = AClassWithPLMethod.class.getDeclaredMethod("foo"); assertFalse(Modifier.isPrivate(m.getModifiers())); assertFalse(Modifier.isPublic(m.getModifiers())); assertFalse(Modifier.isProtected(m.getModifiers())); }
From source file:org.lmn.fc.common.utilities.pending.Utilities.java
/*********************************************************************************************** * Show the Member Modifiers./*w w w .j a v a2 s .c o m*/ * * @param member * * @return String */ public static String showModifiers(final Member member) { final int modifiers; final StringBuffer buffer; buffer = new StringBuffer(); if (member != null) { modifiers = member.getModifiers(); if (Modifier.isAbstract(modifiers)) { buffer.append("Abstract "); } if (Modifier.isFinal(modifiers)) { buffer.append("Final "); } if (Modifier.isInterface(modifiers)) { buffer.append("Interface "); } if (Modifier.isNative(modifiers)) { buffer.append("Native "); } if (Modifier.isPrivate(modifiers)) { buffer.append("Private "); } if (Modifier.isProtected(modifiers)) { buffer.append("Protected "); } if (Modifier.isPublic(modifiers)) { buffer.append("Public "); } if (Modifier.isStatic(modifiers)) { buffer.append("Static "); } if (Modifier.isStrict(modifiers)) { buffer.append("Strict "); } if (Modifier.isSynchronized(modifiers)) { buffer.append("Synchronized "); } if (Modifier.isTransient(modifiers)) { buffer.append("Transient "); } if (Modifier.isVolatile(modifiers)) { buffer.append("Volatile "); } } return (buffer.toString().trim()); }
From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java
public static boolean canBeFunctionalMocked(Type type) { Class<?> rawClass = new GenericClass(type).getRawClass(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (Properties.hasTargetClassBeenLoaded() && (rawClass.equals(targetClass))) { return false; }//ww w. ja v a2s . c o m if (EvoSuiteMock.class.isAssignableFrom(rawClass) || MockList.isAMockClass(rawClass.getName()) || rawClass.equals(Class.class) || rawClass.isArray() || rawClass.isPrimitive() || rawClass.isAnonymousClass() || rawClass.isEnum() || //note: Mockito can handle package-level classes, but we get all kinds of weird exceptions with instrumentation :( !Modifier.isPublic(rawClass.getModifiers())) { return false; } if (!InstrumentedClass.class.isAssignableFrom(rawClass) && Modifier.isFinal(rawClass.getModifiers())) { /* if a class has not been instrumented (eg because belonging to javax.*), then if it is final we cannot mock it :( recall that instrumentation does remove the final modifiers */ return false; } //FIXME: tmp fix to avoid mocking any class with package access methods try { for (Method m : rawClass.getDeclaredMethods()) { /* Unfortunately, it does not seem there is a "isPackageLevel" method, so we have to go by exclusion */ if (!Modifier.isPublic(m.getModifiers()) && !Modifier.isProtected(m.getModifiers()) && !Modifier.isPrivate(m.getModifiers()) && !m.isBridge() && !m.isSynthetic() && !m.getName().equals(ClassResetter.STATIC_RESET)) { return false; } } } catch (NoClassDefFoundError | Exception e) { //this could happen if we failed to load the class AtMostOnceLogger.warn(logger, "Failed to check if can mock class " + rawClass.getName() + ": " + e.getMessage()); return false; } //avoid cases of infinite recursions boolean onlySelfReturns = true; for (Method m : rawClass.getDeclaredMethods()) { if (!rawClass.equals(m.getReturnType())) { onlySelfReturns = false; break; } } if (onlySelfReturns && rawClass.getDeclaredMethods().length > 0) { //avoid weird cases like java.lang.Appendable return false; } //ad-hoc list of classes we should not really mock List<Class<?>> avoid = Arrays.asList( //add here if needed ); if (avoid.contains(rawClass)) { return false; } return true; }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void publicMethods() { memberCriteria.membersOfType(Method.class); memberCriteria.withAccess(AccessType.PUBLIC); 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 method", member instanceof Method); int modifiers = member.getModifiers(); assertTrue(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); }/* w w w. jav a2 s .c o m*/ }
From source file:org.eclipse.buildship.docs.source.SourceMetaDataVisitor.java
private int extractModifiers(GroovySourceAST t, AbstractLanguageElement metaData) { final int modifiers = extractModifiers(t); metaData.setAbstract(Modifier.isAbstract(modifiers)); if (groovy) { metaData.setPublic(!Modifier.isProtected(modifiers) && !Modifier.isPrivate(modifiers)); } else {//from w ww .jav a 2 s . com metaData.setPublic(Modifier.isPublic(modifiers) || (metaData instanceof MethodMetaData && ((MethodMetaData) metaData).getOwnerClass().isInterface())); } return modifiers; }