List of usage examples for java.lang.reflect Modifier isFinal
public static boolean isFinal(int mod)
From source file:com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter.java
/** * ?pipeline?// w w w. j a va 2s .c o m */ public void merge(PipelineParameter pipelineParameter) { try { Field[] fields = this.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; // Skip static and final fields. if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) { continue; } ReflectionUtils.makeAccessible(field); Object srcValue = field.get(pipelineParameter); if (srcValue != null) { // null field.set(this, srcValue); } } } catch (Exception e) { // ignore } }
From source file:uk.ac.liverpool.thumbnails.PDFService.java
public static void printModel(PrintStream ps, Object o) { Field[] fi = o.getClass().getDeclaredFields(); for (Field f : fi) { if (!Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers())) ps.print(f.getName() + " = "); try {// w ww . j a v a 2 s . c o m ps.println(f.get(o)); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ps.println(); }
From source file:objenome.util.bytecode.SgUtils.java
/** * Checks if the modifiers are valid for a field. If any of the modifiers is * not valid an <code>IllegalArgumentException</code> is thrown. * /*from w w w . j a va 2 s.c om*/ * @param modifiers * Modifiers. */ public static void checkFieldModifiers(int modifiers) { // Basic checks checkModifiers(FIELD, modifiers); // Check final and volatile if (Modifier.isFinal(modifiers) && Modifier.isVolatile(modifiers)) { throw new IllegalArgumentException( FIELD_FINAL_VOLATILE_ERROR + " [" + Modifier.toString(modifiers) + ']'); } }
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); }/*from w ww . j av a 2 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:com.kangyonggan.cms.util.Reflections.java
/** * ?private/protected???public?????JDKSecurityManager *//*from w w w . java 2 s .co m*/ public static void makeAccessible(Field field) { boolean temp = (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier.isFinal(field.getModifiers())) && !field.isAccessible(); if (temp) { field.setAccessible(true); } }
From source file:org.evosuite.setup.TestClusterUtils.java
/** * Get the set of fields defined in this class and its superclasses * * @param clazz//from ww w.ja va2s . c o m * @return */ public static Set<Field> getAccessibleFields(Class<?> clazz) { if (accessibleFieldCache.containsKey(clazz)) { return accessibleFieldCache.get(clazz); } Set<Field> fields = new LinkedHashSet<>(); for (Field f : Reflection.getFields(clazz)) { if (TestUsageChecker.canUse(f) && !Modifier.isFinal(f.getModifiers())) { fields.add(f); } } accessibleFieldCache.put(clazz, fields); return fields; }
From source file:com.cnksi.core.tools.utils.Reflections.java
/** * ?private/protected???public?????JDKSecurityManager */// w ww. jav a 2 s.c om public static void makeAccessible(Field field) { if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { field.setAccessible(true); } }
From source file:org.apache.bval.cdi.BValExtension.java
public <A> void processAnnotatedType(final @Observes ProcessAnnotatedType<A> pat) { if (!isExecutableValidationEnabled) { return;// w w w . ja va2 s . c om } final AnnotatedType<A> annotatedType = pat.getAnnotatedType(); if (!annotatedTypeFilter.accept(annotatedType)) { return; } final Class<A> javaClass = annotatedType.getJavaClass(); final int modifiers = javaClass.getModifiers(); if (!javaClass.isInterface() && !Modifier.isFinal(modifiers) && !Modifier.isAbstract(modifiers)) { try { ensureFactoryValidator(); try { final BeanDescriptor classConstraints = validator.getConstraintsForClass(javaClass); if (annotatedType.isAnnotationPresent(ValidateOnExecution.class) || hasValidationAnnotation(annotatedType.getMethods()) || hasValidationAnnotation(annotatedType.getConstructors()) || classConstraints != null && (validBean && classConstraints.isBeanConstrained() || validConstructors && !classConstraints.getConstrainedConstructors().isEmpty() || validBusinessMethods && !classConstraints .getConstrainedMethods(MethodType.NON_GETTER).isEmpty() || validGetterMethods && !classConstraints .getConstrainedMethods(MethodType.GETTER).isEmpty())) { final BValAnnotatedType<A> bValAnnotatedType = new BValAnnotatedType<A>(annotatedType); pat.setAnnotatedType(bValAnnotatedType); } } catch (final NoClassDefFoundError ncdfe) { // skip } } catch (final ValidationException ve) { LOGGER.log(Level.FINEST, ve.getMessage(), ve); } catch (final Exception e) { // just info LOGGER.log(Level.INFO, e.getMessage()); } } }
From source file:com.rosenvold.spring.SpringContextAnalyzer.java
private boolean isFinal(Field field) { return Modifier.isFinal(field.getModifiers()); }
From source file:org.jboss.arquillian.spring.integration.javaconfig.utils.DefaultConfigurationClassesProcessor.java
private void throwExceptionIfConfigurationClassDeclaredFinal(Class<?> configurationCandidate) { if (Modifier.isFinal(configurationCandidate.getModifiers())) { throw new RuntimeException(buildValidationMessage(configurationCandidate, VALIDATION_MESSAGE_SUFFIX_INNER_CONFIGURATION_CLASS_DECLARED_FINAL)); }// w w w . j a v a2 s . c o m }