List of usage examples for java.lang.reflect Modifier isFinal
public static boolean isFinal(int mod)
From source file:com.happyblueduck.lembas.datastore.LembasEntity.java
/** * copies values from lembasEntity to this entity. skip objectKey from that. * @param that/*from w w w . j a v a 2s .c o m*/ */ public void copy(LembasEntity that) { ArrayList<Field> fields = Lists.newArrayList(that.getClass().getFields()); for (Field f : fields) { try { int modifiers = f.getModifiers(); if (Modifier.isPrivate(modifiers)) continue; if (Modifier.isStatic(modifiers)) continue; if (Modifier.isTransient(modifiers)) continue; if (Modifier.isFinal(modifiers)) continue; if (Modifier.isVolatile(modifiers)) continue; if (f.getName().equalsIgnoreCase(LembasUtil.objectKey)) continue; Object value = f.get(that); if (value != null) this.setField(f, value); } catch (IllegalAccessException exception) { exception.printStackTrace(); } } }
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;/* www . ja v a 2 s. com*/ } // 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 w w w .ja v a2 s . co 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 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:org.ngrinder.model.BaseEntity.java
/** * Clone current entity./*from w w w . j a v a2 s . c o m*/ * * Only not null value is merged. * * @param toInstance instance to which the value is copied. * @return cloned entity */ public M cloneTo(M toInstance) { Field forDisplay = null; try { Field[] fields = getClass().getDeclaredFields(); // Iterate over all the attributes for (Field each : fields) { if (each.isSynthetic()) { continue; } final int modifiers = each.getModifiers(); if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers)) { continue; } forDisplay = each; final Cloneable annotation = each.getAnnotation(Cloneable.class); if (annotation == null) { continue; } if (!each.isAccessible()) { each.setAccessible(true); } each.set(toInstance, each.get(this)); } return toInstance; } catch (Exception e) { String displayName = (forDisplay == null) ? "Empty" : forDisplay.getName(); throw processException(displayName + " - Exception occurred while cloning an entity from " + this + " to " + toInstance, e); } }
From source file:com.taobao.diamond.common.Constants.java
/** ?-D > env > diamond.properties */ public static void init() { File diamondFile = new File(System.getProperty("user.home"), "diamond/ServerAddress"); if (!diamondFile.exists()) { diamondFile.getParentFile().mkdirs(); try (OutputStream out = new FileOutputStream(diamondFile)) { out.write("localhost".getBytes()); } catch (IOException e) { throw new IllegalStateException(diamondFile.toString(), e); }//from w w w . j a v a2 s .c om } List<Field> fields = new ArrayList<>(); for (Field field : Constants.class.getDeclaredFields()) { if (Modifier.isPublic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) { fields.add(field); } } Properties props = new Properties(); { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) cl = Constants.class.getClassLoader(); try (InputStream in = cl.getResourceAsStream("diamond.properties")) { if (in != null) props.load(in); } catch (IOException e) { log.warn("load diamond.properties", e); } } props.putAll(System.getenv()); props.putAll(System.getProperties()); Map<String, Object> old = new HashMap<>(); try { for (Field field : fields) { if (!props.containsKey(field.getName())) continue; old.put(field.getName(), field.get(Constants.class)); String value = props.getProperty(field.getName()); Class<?> clazz = field.getType(); if (String.class.equals(clazz)) { field.set(Constraints.class, value); } else if (int.class.equals(clazz)) { if (value != null) { field.set(Constraints.class, Integer.parseInt(value)); } } else { throw new IllegalArgumentException(field + " " + value + " ?"); } } } catch (IllegalAccessException e) { throw new IllegalStateException(e); } setValue(old, "CONFIG_HTTP_URI_FILE", "HTTP_URI_FILE"); setValue(old, "HTTP_URI_LOGIN", "HTTP_URI_FILE"); setValue(old, "DAILY_DOMAINNAME", "DEFAULT_DOMAINNAME"); }
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;//from ww w . j a va 2s . com } // ? 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 }
From source file:org.springframework.test.context.support.AnnotationConfigContextLoaderUtils.java
private static boolean isStaticNonPrivateAndNonFinal(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); int modifiers = clazz.getModifiers(); return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)); }
From source file:org.apache.openjpa.enhance.PCSubclassValidator.java
public void assertCanSubclass() { Class superclass = meta.getDescribedType(); String name = superclass.getName(); if (superclass.isInterface()) addError(loc.get("subclasser-no-ifaces", name), meta); if (Modifier.isFinal(superclass.getModifiers())) addError(loc.get("subclasser-no-final-classes", name), meta); if (Modifier.isPrivate(superclass.getModifiers())) addError(loc.get("subclasser-no-private-classes", name), meta); if (PersistenceCapable.class.isAssignableFrom(superclass)) addError(loc.get("subclasser-super-already-pc", name), meta); try {/*from w w w . jav a2 s.c om*/ Constructor c = superclass.getDeclaredConstructor(new Class[0]); if (!(Modifier.isProtected(c.getModifiers()) || Modifier.isPublic(c.getModifiers()))) addError(loc.get("subclasser-private-ctor", name), meta); } catch (NoSuchMethodException e) { addError(loc.get("subclasser-no-void-ctor", name), meta); } // if the BCClass we loaded is already pc and the superclass is not, // then we should never get here, so let's make sure that the // calling context is caching correctly by throwing an exception. if (pc.isInstanceOf(PersistenceCapable.class) && !PersistenceCapable.class.isAssignableFrom(superclass)) throw new InternalException(loc.get("subclasser-class-already-pc", name)); if (AccessCode.isProperty(meta.getAccessType())) checkPropertiesAreInterceptable(); if (errors != null && !errors.isEmpty()) throw new UserException(errors.toString()); else if (contractViolations != null && !contractViolations.isEmpty() && log.isWarnEnabled()) log.warn(contractViolations.toString()); }
From source file:com.asuka.android.asukaandroid.view.ViewInjectorImpl.java
@SuppressWarnings("ConstantConditions") private static void injectObject(Object handler, Class<?> handlerType, ViewFinder finder) { if (handlerType == null || IGNORED.contains(handlerType)) { return;//from www .j av a 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) { LogUtil.e(ex.getMessage(), ex); } } } } // 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) { LogUtil.e(ex.getMessage(), ex); } } } } // end inject event }
From source file:edu.usu.sdl.openstorefront.util.ReflectionUtil.java
/** * This gets all declared field of the whole object hierarchy * * @param typeClass//from w w w . ja v a 2 s . com * @return */ public static List<Field> getAllFields(Class typeClass) { Objects.requireNonNull(typeClass, "Class is required"); List<Field> fields = new ArrayList<>(); if (typeClass.getSuperclass() != null) { fields.addAll(getAllFields(typeClass.getSuperclass())); } for (Field field : typeClass.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) == false && Modifier.isFinal(field.getModifiers()) == false) { fields.add(field); } } return fields; }