List of usage examples for java.lang.reflect Modifier isFinal
public static boolean isFinal(int mod)
From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java
/** * Creates a serializable copy of a given object */// w ww .j a v a 2 s . c om protected Object createClone(Object source) { try { Object target = source.getClass().newInstance(); List<Field> fieldList = new ArrayList<Field>(); getAllFields(source.getClass(), fieldList); for (Field field : fieldList) { Object obj = field.get(source); if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character || obj instanceof Long || obj instanceof Boolean || obj instanceof String) { if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) { field.setAccessible(true); field.set(target, obj); } } } return target; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:$.Reflections.java
/** * ?private/protected???public?????JDKSecurityManager */// ww w .j ava2 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:net.radai.beanz.util.ReflectionUtil.java
public static boolean isFinal(Field field) { return Modifier.isFinal(field.getModifiers()); }
From source file:org.sonatype.nexus.mock.SeleniumTest.java
private void cleanFields() throws IllegalArgumentException, IllegalAccessException { List<Field> fields = getFields(getClass()); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) { continue; }//from w w w .jav a 2 s . c o m field.setAccessible(true); if (field.getDeclaringClass().isPrimitive()) { field.set(this, 0); } else { field.set(this, null); } } }
From source file:org.rasea.core.configuration.ConfigurationLoader.java
private void setProperty(final Object pojo, final Field field, final Object fieldValue) throws IllegalAccessException, InvocationTargetException, ConfigurationException, NoSuchMethodException {//from w ww.j a v a 2 s. c o m if (Modifier.isFinal(field.getModifiers())) { final String message = "Failed to set property: " + pojo.getClass().getName() + "." + field.getType().getName() + " is final"; this.log(message, field.getType().isLocalClass()); } else { Object newValue = fieldValue; if (field.getType().isEnum()) { newValue = this.getEnumProperty(pojo, field, fieldValue); } if (field.getType().equals(Boolean.class) || this.getProperty(pojo, field) instanceof Boolean) { newValue = this.getBooleanProperty(fieldValue); } if (newValue == null || !newValue.equals(fieldValue)) { BeanUtilsBean.getInstance().getPropertyUtils().setSimpleProperty(pojo, field.getName(), newValue); } else { BeanUtils.setProperty(pojo, field.getName(), newValue); } } }
From source file:org.springframework.batch.core.jsr.configuration.support.BatchPropertyBeanPostProcessor.java
private boolean isValidFieldModifier(Field field) { return !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers()); }
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 www. jav 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:py.una.pol.karaku.dao.entity.interceptors.InterceptorHandler.java
/** * Verifica si un field puede ser asignable. Se define un fiel asignable * como aquel que no es estatico, final. * /*from w w w . j a va 2 s . c o m*/ * Como nota general tener en cuenta que un campo que no es String es * inmediatamente no asignable * * @param field * a ser evaluado * @return <code>true</code> si es asignable, <code>false</code> en caso * contrario */ private boolean isAssignable(Field field) { int modifier = field.getModifiers(); if (Modifier.isFinal(modifier)) { return false; } if (Modifier.isStatic(modifier)) { return false; } if (Modifier.isTransient(modifier)) { return false; } return field.getAnnotation(Transient.class) == null; }
From source file:org.apache.openjpa.enhance.PCSubclassValidator.java
private void checkMethodIsSubclassable(Method meth, FieldMetaData fmd) { String className = fmd.getDefiningMetaData().getDescribedType().getName(); if (!(Modifier.isProtected(meth.getModifiers()) || Modifier.isPublic(meth.getModifiers()))) addError(loc.get("subclasser-private-accessors-unsupported", className, meth.getName()), fmd); if (Modifier.isFinal(meth.getModifiers())) addError(loc.get("subclasser-final-methods-not-allowed", className, meth.getName()), fmd); if (Modifier.isNative(meth.getModifiers())) addContractViolation(loc.get("subclasser-native-methods-not-allowed", className, meth.getName()), fmd); if (Modifier.isStatic(meth.getModifiers())) addError(loc.get("subclasser-static-methods-not-supported", className, meth.getName()), fmd); }
From source file:org.gradle.build.docs.dsl.SourceMetaDataVisitor.java
private void maybeAddPropertyFromField(GroovySourceAST t) { GroovySourceAST parentNode = getParentNode(); boolean isField = parentNode != null && parentNode.getType() == OBJBLOCK; if (!isField) { return;// w ww. ja v a 2s. c om } int modifiers = extractModifiers(t); boolean isConst = getCurrentClass().isInterface() || (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)); if (isConst) { visitConst(t); return; } boolean isProp = groovy && !Modifier.isStatic(modifiers) && !Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isPrivate(modifiers); if (!isProp) { return; } ASTIterator children = new ASTIterator(t); children.skip(MODIFIERS); String propertyName = extractIdent(t); TypeMetaData propertyType = extractTypeName(children.current); ClassMetaData currentClass = getCurrentClass(); MethodMetaData getterMethod = currentClass .addMethod(String.format("get%s", StringUtils.capitalize(propertyName)), propertyType, ""); currentClass.addReadableProperty(propertyName, propertyType, getJavaDocCommentsBeforeNode(t), getterMethod); if (!Modifier.isFinal(modifiers)) { MethodMetaData setterMethod = currentClass .addMethod(String.format("set%s", StringUtils.capitalize(propertyName)), TypeMetaData.VOID, ""); setterMethod.addParameter(propertyName, propertyType); currentClass.addWriteableProperty(propertyName, propertyType, getJavaDocCommentsBeforeNode(t), setterMethod); } }