List of usage examples for java.lang.reflect Modifier isPrivate
public static boolean isPrivate(int mod)
From source file:org.gradle.api.internal.AbstractClassGenerator.java
private <T> Class<? extends T> generateUnderLock(Class<T> type) { Map<Class<?>, Class<?>> cache = GENERATED_CLASSES.get(getClass()); if (cache == null) { // WeakHashMap won't work here. It keeps a strong reference to the mapping value, which is the generated class in this case // However, the generated class has a strong reference to the source class (by extending it), so the keys will always be // strongly reachable while this Class is strongly reachable. Use weak references for both key and value of the mapping instead. cache = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK); GENERATED_CLASSES.put(getClass(), cache); }/* w w w .j ava2 s .c o m*/ Class<?> generatedClass = cache.get(type); if (generatedClass != null) { return generatedClass.asSubclass(type); } if (Modifier.isPrivate(type.getModifiers())) { throw new GradleException( String.format("Cannot create a proxy class for private class '%s'.", type.getSimpleName())); } if (Modifier.isAbstract(type.getModifiers())) { throw new GradleException( String.format("Cannot create a proxy class for abstract class '%s'.", type.getSimpleName())); } Class<? extends T> subclass; try { ClassMetaData classMetaData = inspectType(type); ClassBuilder<T> builder = start(type, classMetaData); builder.startClass(); if (!DynamicObjectAware.class.isAssignableFrom(type)) { if (ExtensionAware.class.isAssignableFrom(type)) { throw new UnsupportedOperationException( "A type that implements ExtensionAware must currently also implement DynamicObjectAware."); } builder.mixInDynamicAware(); } if (!GroovyObject.class.isAssignableFrom(type)) { builder.mixInGroovyObject(); } builder.addDynamicMethods(); if (classMetaData.conventionAware && !IConventionAware.class.isAssignableFrom(type)) { builder.mixInConventionAware(); } Class noMappingClass = Object.class; for (Class<?> c = type; c != null && noMappingClass == Object.class; c = c.getSuperclass()) { if (c.getAnnotation(NoConventionMapping.class) != null) { noMappingClass = c; } } Set<PropertyMetaData> conventionProperties = new HashSet<PropertyMetaData>(); for (PropertyMetaData property : classMetaData.properties.values()) { if (SKIP_PROPERTIES.contains(property.name)) { continue; } if (property.injector) { builder.addInjectorProperty(property); for (Method getter : property.getters) { builder.applyServiceInjectionToGetter(property, getter); } for (Method setter : property.setters) { builder.applyServiceInjectionToSetter(property, setter); } continue; } boolean needsConventionMapping = false; if (classMetaData.isExtensible()) { for (Method getter : property.getters) { if (!Modifier.isFinal(getter.getModifiers()) && !getter.getDeclaringClass().isAssignableFrom(noMappingClass)) { needsConventionMapping = true; break; } } } if (needsConventionMapping) { conventionProperties.add(property); builder.addConventionProperty(property); for (Method getter : property.getters) { builder.applyConventionMappingToGetter(property, getter); } } if (needsConventionMapping) { for (Method setter : property.setters) { if (!Modifier.isFinal(setter.getModifiers())) { builder.applyConventionMappingToSetter(property, setter); } } } } Set<Method> actionMethods = classMetaData.missingOverloads; for (Method method : actionMethods) { builder.addActionMethod(method); } // Adds a set method for each mutable property for (PropertyMetaData property : classMetaData.properties.values()) { if (property.setters.isEmpty()) { continue; } if (Iterable.class.isAssignableFrom(property.getType())) { // Currently not supported continue; } if (property.setMethods.isEmpty()) { for (Method setter : property.setters) { builder.addSetMethod(property, setter); } } else if (conventionProperties.contains(property)) { for (Method setMethod : property.setMethods) { builder.applyConventionMappingToSetMethod(property, setMethod); } } } for (Constructor<?> constructor : type.getConstructors()) { if (Modifier.isPublic(constructor.getModifiers())) { builder.addConstructor(constructor); } } subclass = builder.generate(); } catch (Throwable e) { throw new GradleException( String.format("Could not generate a proxy class for class %s.", type.getName()), e); } cache.put(type, subclass); cache.put(subclass, subclass); return subclass; }
From source file:org.evosuite.setup.TestUsageChecker.java
public static boolean canUse(Class<?> c) { //if (Throwable.class.isAssignableFrom(c)) // return false; if (Modifier.isPrivate(c.getModifiers())) return false; if (!Properties.USE_DEPRECATED && c.isAnnotationPresent(Deprecated.class)) { final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (Properties.hasTargetClassBeenLoaded() && !c.equals(targetClass)) { logger.debug("Skipping deprecated class " + c.getName()); return false; }/*from w ww . j av a 2 s . c om*/ } if (c.isAnonymousClass()) { return false; } if (c.getName().startsWith("junit")) return false; if (TestClusterUtils.isEvoSuiteClass(c) && !MockList.isAMockClass(c.getCanonicalName())) { return false; } if (c.getEnclosingClass() != null) { if (!canUse(c.getEnclosingClass())) return false; } if (c.getDeclaringClass() != null) { if (!canUse(c.getDeclaringClass())) return false; } // If the SUT is not in the default package, then // we cannot import classes that are in the default // package if (!c.isArray() && !c.isPrimitive() && !Properties.CLASS_PREFIX.isEmpty() && !c.getName().contains(".")) { return false; } if (c.getName().contains("EnhancerByMockito")) { return false; } // TODO: This should be unnecessary if Java reflection works... // This is inefficient if (TestClusterUtils.isAnonymousClass(c.getName())) { String message = c + " looks like an anonymous class, ignoring it (although reflection says " + c.isAnonymousClass() + ") " + c.getSimpleName(); LoggingUtils.logWarnAtMostOnce(logger, message); return false; } if (Modifier.isPublic(c.getModifiers())) { return true; } // If default access rights, then check if this class is in the same package as the target class if (!Modifier.isPrivate(c.getModifiers())) { // && !Modifier.isProtected(c.getModifiers())) { String packageName = ClassUtils.getPackageName(c); if (packageName.equals(Properties.CLASS_PREFIX)) { return true; } } logger.debug("Not public"); return false; }
From source file:uk.gov.gchq.gaffer.example.gettingstarted.walkthrough.WalkthroughRunner.java
private static void keepPublicConcreteClasses(final List classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); for (Class clazz = null; itr.hasNext(); 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();//from ww w.ja v a2s . c o m } } } } }
From source file:org.apache.hawq.pxf.plugins.hdfs.WritableResolver.java
@Override public List<OneField> getFields(OneRow onerow) throws Exception { userObject = onerow.getData();/*from www . j a va 2 s .c o m*/ List<OneField> record = new LinkedList<OneField>(); int currentIdx = 0; for (Field field : fields) { if (currentIdx == recordkeyIndex) { currentIdx += recordkeyAdapter.appendRecordkeyField(record, inputData, onerow); } if (Modifier.isPrivate(field.getModifiers())) { continue; } currentIdx += populateRecord(record, field); } return record; }
From source file:org.apromore.test.heuristic.JavaBeanHeuristic.java
private Object tryToInstantiate(Class clazz) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { Constructor constructor = clazz.getDeclaredConstructor(); // Default constructor must not be private. It can be protected or package-private though. if (!Modifier.isPrivate(constructor.getModifiers())) { constructor.setAccessible(true); }//from w w w . ja va 2 s.com return constructor.newInstance(); }
From source file:org.obsidian.test.TestAbstract.java
public <T> void appendDynamicImports(Class<T> classToImport) { boolean shouldBeIgnored = false; //Make sure: not already in dynamic imports for (String s : getDynamicImports()) { if (s.compareToIgnoreCase(classToImport.getName().replaceAll("\\$", ".")) == 0) { shouldBeIgnored = true;//from w w w .j a va 2 s .c o m } } if (!classToImport.isPrimitive() && !classToImport.isArray()) { //make sure: not in imports from constants for (String s : Content.IMPORTS) { if (s.compareToIgnoreCase(classToImport.getName()) == 0) { shouldBeIgnored = true; } } //make sure: not in same package if (classToImport.getPackage().toString() .compareToIgnoreCase(classTested.getPackage().toString()) == 0) { //#### Patch Submitted by Michael Cole (micole.3@gmail.com) 2/13/13 if (!(classToImport.isMemberClass() || classToImport.isEnum() || classToImport.isLocalClass())) { shouldBeIgnored = true; } } //make sure not private if (Modifier.isPrivate(classToImport.getModifiers())) { shouldBeIgnored = true; } //make sure: not importing from java.lang unless at least 3 deep //ex)java.lang.reflect String[] packageStructure = classToImport.getPackage().getName().split("\\."); int packageDepth = packageStructure.length; //if dataInputStream java.lang if (packageStructure[0].compareToIgnoreCase("java") == 0 && packageStructure[1].compareToIgnoreCase("lang") == 0) { //and less than three deep if (packageDepth < 3) { shouldBeIgnored = true; classToImport.getName(); } } } else { shouldBeIgnored = true; if (classToImport.isArray() && !classToImport.getComponentType().isPrimitive()) { appendDynamicImports(classToImport.getComponentType()); } } //if: not already in imports and not in same package if (!shouldBeIgnored) { //add to dynamic imports String importName = classToImport.getName(); importName = importName.replaceAll("\\$", "."); getDynamicImports().add(importName); } }
From source file:xutils.view.ViewInjectorImpl.java
@SuppressWarnings("ConstantConditions") private static void injectObject(Object handler, Class<?> handlerType, ViewFinder finder) { if (handlerType == null || IGNORED.contains(handlerType)) { return;//from ww w . j a v a2 s . c o m } // inject view Field[] fields = handlerType.getDeclaredFields(); if (fields != null && fields.length > 0) { for (Field field : fields) { Class<?> fieldType = field.getType(); if ( /* ??? */ Modifier.isStatic(field.getModifiers()) || /* ?final */ Modifier.isFinal(field.getModifiers()) || /* ? */ fieldType.isPrimitive() || /* ? */ fieldType.isArray()) { continue; } ViewInject viewInject = field.getAnnotation(ViewInject.class); if (viewInject != null) { try { View view = finder.findViewById(viewInject.value(), viewInject.parentId()); if (view != null) { field.setAccessible(true); field.set(handler, view); } else { throw new RuntimeException("Invalid @ViewInject for " + handlerType.getSimpleName() + "." + field.getName()); } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } } } } // inject event Method[] methods = handlerType.getDeclaredMethods(); if (methods != null && methods.length > 0) { for (Method method : methods) { if (Modifier.isStatic(method.getModifiers()) || !Modifier.isPrivate(method.getModifiers())) { continue; } //??event Event event = method.getAnnotation(Event.class); if (event != null) { try { // id? int[] values = event.value(); int[] parentIds = event.parentId(); int parentIdsLen = parentIds == null ? 0 : parentIds.length; //id?ViewInfo??? for (int i = 0; i < values.length; i++) { int value = values[i]; if (value > 0) { ViewInfo info = new ViewInfo(); info.value = value; info.parentId = parentIdsLen > i ? parentIds[i] : 0; method.setAccessible(true); EventListenerManager.addEventMethod(finder, info, event, handler, method); } } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } } } } injectObject(handler, handlerType.getSuperclass(), finder); }
From source file:com.xutils.view.ViewInjectorImpl.java
@SuppressWarnings("ConstantConditions") private static void injectObject(Object handler, Class<?> handlerType, ViewFinder finder) { if (handlerType == null || IGNORED.contains(handlerType)) { return;/*from ww w. ja va 2s .c om*/ } // inject view Field[] fields = handlerType.getDeclaredFields(); if (fields != null && fields.length > 0) { for (Field field : fields) { Class<?> fieldType = field.getType(); if ( /* ??? */ Modifier.isStatic(field.getModifiers()) || /* ?final */ Modifier.isFinal(field.getModifiers()) || /* ? */ fieldType.isPrimitive() || /* ? */ fieldType.isArray()) { continue; } ViewInject viewInject = field.getAnnotation(ViewInject.class); if (viewInject != null) { try { View view = finder.findViewById(viewInject.value(), viewInject.parentId()); if (view != null) { field.setAccessible(true); field.set(handler, view); } else { throw new RuntimeException("Invalid id(" + viewInject.value() + ") for @ViewInject!" + handlerType.getSimpleName()); } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } } } } // inject event Method[] methods = handlerType.getDeclaredMethods(); if (methods != null && methods.length > 0) { for (Method method : methods) { if (Modifier.isStatic(method.getModifiers()) || !Modifier.isPrivate(method.getModifiers())) { continue; } //??event Event event = method.getAnnotation(Event.class); if (event != null) { try { // id? int[] values = event.value(); int[] parentIds = event.parentId(); int parentIdsLen = parentIds == null ? 0 : parentIds.length; //id?ViewInfo??? for (int i = 0; i < values.length; i++) { int value = values[i]; if (value > 0) { ViewInfo info = new ViewInfo(); info.value = value; info.parentId = parentIdsLen > i ? parentIds[i] : 0; method.setAccessible(true); EventListenerManager.addEventMethod(finder, info, event, handler, method); } } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } } } } injectObject(handler, handlerType.getSuperclass(), finder); }
From source file:com.medallia.spider.api.StRenderer.java
/** @return the action method of the given class; throws AssertionError if no such method exists */ private static Method findActionMethod(Class<?> clazz) { Method am = ACTION_METHOD_MAP.get(clazz); if (am != null) return am; for (Method m : CollUtils.concat(Arrays.asList(clazz.getMethods()), Arrays.asList(clazz.getDeclaredMethods()))) { if (m.getName().equals("action")) { int modifiers = m.getModifiers(); if (Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers)) continue; m.setAccessible(true);//from w ww . java 2s. co m ACTION_METHOD_MAP.put(clazz, m); return m; } } throw new AssertionError("No action method found in " + clazz); }
From source file:com.example.basedemo.view.ViewInjectorImpl.java
@SuppressWarnings("ConstantConditions") private static void injectObject(Object handler, Class<?> handlerType, ViewFinder finder) { if (handlerType == null || IGNORED.contains(handlerType)) { return;/* www. j ava 2 s. c o m*/ } // ? injectObject(handler, handlerType.getSuperclass(), finder); // inject view Field[] fields = handlerType.getDeclaredFields(); if (fields != null && fields.length > 0) { for (Field field : fields) { Class<?> fieldType = field.getType(); if ( /* ??? */ Modifier.isStatic(field.getModifiers()) || /* ?final */ Modifier.isFinal(field.getModifiers()) || /* ? */ fieldType.isPrimitive() || /* ? */ fieldType.isArray()) { continue; } ViewInject viewInject = field.getAnnotation(ViewInject.class); if (viewInject != null) { try { View view = finder.findViewById(viewInject.value(), viewInject.parentId()); if (view != null) { field.setAccessible(true); field.set(handler, view); } else { throw new RuntimeException("Invalid @ViewInject for " + handlerType.getSimpleName() + "." + field.getName()); } } catch (Throwable ex) { Log.e(ex.getMessage(), ex.toString()); } } } } // end inject view // inject event Method[] methods = handlerType.getDeclaredMethods(); if (methods != null && methods.length > 0) { for (Method method : methods) { if (Modifier.isStatic(method.getModifiers()) || !Modifier.isPrivate(method.getModifiers())) { continue; } //??event Event event = method.getAnnotation(Event.class); if (event != null) { try { // id? int[] values = event.value(); int[] parentIds = event.parentId(); int parentIdsLen = parentIds == null ? 0 : parentIds.length; //id?ViewInfo??? for (int i = 0; i < values.length; i++) { int value = values[i]; if (value > 0) { ViewInfo info = new ViewInfo(); info.value = value; info.parentId = parentIdsLen > i ? parentIds[i] : 0; method.setAccessible(true); EventListenerManager.addEventMethod(finder, info, event, handler, method); } } } catch (Throwable ex) { Log.e(ex.getMessage(), ex.toString()); } } } } // end inject event }