List of usage examples for java.lang.reflect Modifier isPrivate
public static boolean isPrivate(int mod)
From source file:org.apache.hawq.pxf.plugins.hdfs.WritableResolver.java
/** * Sets customWritable fields and creates a OneRow object. *///from w ww. java 2 s . c o m @Override public OneRow setFields(List<OneField> record) throws Exception { Writable key = null; int colIdx = 0; for (Field field : fields) { /* * extract recordkey based on the column descriptor type * and add to OneRow.key */ if (colIdx == recordkeyIndex) { key = recordkeyAdapter.convertKeyValue(record.get(colIdx).val); colIdx++; } if (Modifier.isPrivate(field.getModifiers())) { continue; } String javaType = field.getType().getName(); convertJavaToGPDBType(javaType); if (isArray(javaType)) { Object value = field.get(userObject); int length = Array.getLength(value); for (int j = 0; j < length; j++, colIdx++) { Array.set(value, j, record.get(colIdx).val); } } else { field.set(userObject, record.get(colIdx).val); colIdx++; } } return new OneRow(key, userObject); }
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 w w w . j a v a2 s .c om*/ * @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:lucee.transformer.bytecode.reflection.ASMProxyFactory.java
public static ASMClass getClass(ExtendableClassLoader pcl, Resource classRoot, Class clazz) throws IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException { Type type = Type.getType(clazz); // Fields// w w w . ja va 2 s . com Field[] fields = clazz.getFields(); for (int i = 0; i < fields.length; i++) { if (Modifier.isPrivate(fields[i].getModifiers())) continue; createField(type, fields[i]); } // Methods Method[] methods = clazz.getMethods(); Map<String, ASMMethod> amethods = new HashMap<String, ASMMethod>(); for (int i = 0; i < methods.length; i++) { if (Modifier.isPrivate(methods[i].getModifiers())) continue; amethods.put(methods[i].getName(), getMethod(pcl, classRoot, type, clazz, methods[i])); } return new ASMClass(clazz.getName(), amethods); }
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:com.sunchenbin.store.feilong.core.lang.reflect.FieldUtil.java
/** * ?field?list.//from www . ja va 2 s . c o m * * <h3>??:</h3> * * <blockquote> * <ol> * <li>{@code if isNullOrEmpty(fields) return emptyList}</li> * <li>(?,) {@link #getAllFields(Object)}</li> * <li> <code>excludeFieldNames</code></li> * <li> {@link Modifier#isPrivate(int)} and {@link Modifier#isStatic(int)}</li> * </ol> * </blockquote> * * @param obj * the obj * @param excludeFieldNames * ?field names,?nullOrEmpty ? * @return the field value map * @see #getAllFields(Object) * @since 1.4.0 */ public static List<Field> getAllFieldList(Object obj, String[] excludeFieldNames) { // (?,) Field[] fields = getAllFields(obj); if (Validator.isNullOrEmpty(fields)) { return Collections.emptyList(); } List<Field> fieldList = new ArrayList<Field>(); for (Field field : fields) { String fieldName = field.getName(); if (Validator.isNotNullOrEmpty(excludeFieldNames) && ArrayUtils.contains(excludeFieldNames, fieldName)) { continue; } int modifiers = field.getModifiers(); // ??? log boolean isPrivateAndStatic = Modifier.isPrivate(modifiers) && Modifier.isStatic(modifiers); LOGGER.debug("field name:[{}],modifiers:[{}],isPrivateAndStatic:[{}]", fieldName, modifiers, isPrivateAndStatic); if (!isPrivateAndStatic) { fieldList.add(field); } } return fieldList; }
From source file:org.openehealth.ipf.commons.lbs.utils.NiceClass.java
/** * Ensures that a utility class (i.e. a class with only static methods) cannot be * instantiated/*from w w w . j a v a 2s . c om*/ * @param utilityClass * the class to test * @throws Exception * any unexpected exception that occurred */ public static void checkUtilityClass(Class<?> utilityClass) throws Exception { Constructor<?>[] constructors = utilityClass.getDeclaredConstructors(); assertEquals(1, constructors.length); assertTrue(Modifier.isPrivate(constructors[0].getModifiers())); constructors[0].setAccessible(true); try { constructors[0].newInstance(new Object[] {}); fail("Expected Exception: " + InvocationTargetException.class.getSimpleName()); } catch (InvocationTargetException e) { // That's expected } }
From source file:net.orfjackal.retrolambda.test.LambdaTest.java
/** * We could make private lambda implementation methods package-private, * so that the lambda class may call them, but we should not make any * more methods non-private than is absolutely necessary. *///from ww w . java 2s.c o m @Test public void will_not_change_the_visibility_of_unrelated_methods() throws Exception { assertThat(unrelatedPrivateMethod(), is("foo")); Method method = getClass().getDeclaredMethod("unrelatedPrivateMethod"); int modifiers = method.getModifiers(); assertTrue("expected " + method.getName() + " to be private, but modifiers were: " + Modifier.toString(modifiers), Modifier.isPrivate(modifiers)); }
From source file:org.lmn.fc.common.utilities.pending.Utilities.java
/*********************************************************************************************** * Show the Member Modifiers./*from ww w .j a v a2s . 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:com.github.juanmf.java2plant.Parser.java
protected static void addUses(Set<Relation> relations, Class<?> fromType) { Method[] methods = fromType.getDeclaredMethods(); for (Method m : methods) { if (!Modifier.isPrivate(m.getModifiers())) { addMethodUses(relations, fromType, m); }/*from ww w .j ava2s.c om*/ } Constructor<?>[] constructors = fromType.getDeclaredConstructors(); for (Constructor<?> c : constructors) { if (!Modifier.isPrivate(c.getModifiers())) { addConstructorUses(relations, fromType, c); } } }
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 a 2 s. c om*/ 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; }