List of usage examples for java.lang.reflect Modifier isFinal
public static boolean isFinal(int mod)
From source file:com.Da_Technomancer.crossroads.API.packets.Message.java
private static boolean acceptField(Field f, Class<?> type) { int mods = f.getModifiers(); if (Modifier.isFinal(mods) || Modifier.isStatic(mods) || Modifier.isTransient(mods)) return false; return handlers.containsKey(type); }
From source file:org.jiemamy.utils.reflect.FieldUtil.java
/** * ??????//from w ww. jav a 2 s. c o m * * @param field * @return ???{@code true}?????????{@code false} * @throws IllegalArgumentException ?{@code null}??? */ public static boolean isInstanceField(Field field) { Validate.notNull(field); int mod = field.getModifiers(); return !Modifier.isStatic(mod) && !Modifier.isFinal(mod); }
From source file:com.streamsets.datacollector.definition.ConfigDefinitionExtractor.java
private List<ErrorMessage> validate(String configPrefix, Class klass, List<String> stageGroups, boolean validateDependencies, boolean isBean, boolean isComplexField, Object contextMsg) { List<ErrorMessage> errors = new ArrayList<>(); boolean noConfigs = true; for (Field field : klass.getFields()) { if (field.getAnnotation(ConfigDef.class) != null && field.getAnnotation(ConfigDefBean.class) != null) { errors.add(new ErrorMessage(DefinitionError.DEF_152, contextMsg, field.getName())); } else {/*from w ww .j av a 2s .c o m*/ if (field.getAnnotation(ConfigDef.class) != null || field.getAnnotation(ConfigDefBean.class) != null) { if (Modifier.isStatic(field.getModifiers())) { errors.add(new ErrorMessage(DefinitionError.DEF_151, contextMsg, klass.getSimpleName(), field.getName())); } if (Modifier.isFinal(field.getModifiers())) { errors.add(new ErrorMessage(DefinitionError.DEF_154, contextMsg, klass.getSimpleName(), field.getName())); } } if (field.getAnnotation(ConfigDef.class) != null) { noConfigs = false; List<ErrorMessage> subErrors = validateConfigDef(configPrefix, stageGroups, field, isComplexField, Utils.formatL("{} Field='{}'", contextMsg, field.getName())); errors.addAll(subErrors); } else if (field.getAnnotation(ConfigDefBean.class) != null) { noConfigs = false; List<ErrorMessage> subErrors = validateConfigDefBean(configPrefix + field.getName() + ".", field, stageGroups, isComplexField, Utils.formatL("{} BeanField='{}'", contextMsg, field.getName())); errors.addAll(subErrors); } } } if (isBean && noConfigs) { errors.add(new ErrorMessage(DefinitionError.DEF_160, contextMsg)); } if (errors.isEmpty() & validateDependencies) { errors.addAll(validateDependencies(getConfigDefinitions(configPrefix, klass, stageGroups, contextMsg), contextMsg)); } return errors; }
From source file:org.moe.cli.utils.params.OptionsHandler.java
/** * Returns all registered options./* ww w . j ava 2 s . co m*/ * @return Well prepared {@link Options} object */ public static Options getAvalibleOptions() { Options avalibleOptions = new Options(); Field[] fields = OptionsHandler.class.getDeclaredFields(); for (Field field : fields) { int mod = field.getModifiers(); if (Modifier.isPublic(mod) && Modifier.isStatic(mod) && Modifier.isFinal(mod) //we check it to eliminate unnecessary field's handling if such exists && field.getType().equals(Option.class)) { Option opt = null; try { opt = (Option) field.get(null); } catch (IllegalArgumentException | IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } avalibleOptions.addOption(opt); } } return avalibleOptions; }
From source file:blue.lapis.pore.converter.wrapper.WrapperConverterTest.java
private Object create() { Class<?> base = interfaces.get(0); if (!base.isInterface() && Modifier.isFinal(base.getModifiers())) { if (base == Location.class) { return new Location(mock(Extent.class), 0, 0, 0); }/*from w w w . j av a 2s . c om*/ } Object mock; if (interfaces.size() == 1) { mock = mock(base); } else { mock = mock(base, withSettings().extraInterfaces( interfaces.subList(1, interfaces.size()).toArray(new Class<?>[interfaces.size() - 1]))); } // o.b.BlockState's subclasses break this test because of incongruencies between SpongeAPI and Bukkit // this code basically assures that a NullPointerException won't be thrown while converting if (base.getPackage().getName().startsWith("org.spongepowered.api.block.tileentity")) { Location loc = new Location(mock(Extent.class), 0, 0, 0); BlockState state = mock(BlockState.class); when(loc.getBlock()).thenReturn(state); when(((TileEntity) mock).getLocation()).thenReturn(loc); when(((TileEntity) mock).getBlock()).thenReturn(state); } return mock; }
From source file:org.openinfinity.core.aspect.ArgumentBuilder.java
private void doRecursiveFieldLookUpAndCallFieldCallback( final ArgumentGatheringFieldCallback<Field, Object> argumentGatheringCallback, final Object[] objects) { for (final Object object : objects) { try {/*from www . j av a2s . c o m*/ if (object != null) { ReflectionUtils.doWithFields(object.getClass(), new FieldCallback() { public void doWith(Field field) { try { if (!field.isAccessible()) { field.setAccessible(Boolean.TRUE); } if (!(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()))) { argumentGatheringCallback.onField(field, object); LOGGER.debug("Accessing field: " + field.getName()); } } catch (Throwable e) { LOGGER.error("Failure occurred while accessing object field.", e); } } }); } } catch (Throwable throwable) { throw new SystemException(throwable); } } }
From source file:objenome.util.bytecode.SgUtils.java
private static void checkModifiers(int type, int modifiers) { for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) { if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) { throwIllegalArgument(type, PRIVATE); }/*from ww w . j a va2 s . c om*/ if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) { throwIllegalArgument(type, PROTECTED); } if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) { throwIllegalArgument(type, PUBLIC); } if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) { throwIllegalArgument(type, STATIC); } if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) { throwIllegalArgument(type, ABSTRACT); } if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) { throwIllegalArgument(type, FINAL); } if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) { throwIllegalArgument(type, NATIVE); } if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) { throwIllegalArgument(type, SYNCHRONIZED); } if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) { throwIllegalArgument(type, TRANSIENT); } if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) { throwIllegalArgument(type, VOLATILE); } if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) { throwIllegalArgument(type, STRICTFP); } } }
From source file:org.jupyterkernel.json.messages.T_JSON.java
private static Object cloneObject(Object obj) { try {/*from w w w. j a v a 2 s . c o m*/ Object clone = obj.getClass().newInstance(); for (Field field : obj.getClass().getDeclaredFields()) { field.setAccessible(true); if (field.get(obj) == null || Modifier.isFinal(field.getModifiers())) { continue; } if (field.getType().isPrimitive() || field.getType().equals(String.class) || field.getType().getSuperclass().equals(Number.class) || field.getType().equals(Boolean.class)) { field.set(clone, field.get(obj)); } else { Object childObj = field.get(obj); if (childObj == obj) { field.set(clone, clone); } else { field.set(clone, cloneObject(field.get(obj))); } } } return clone; } catch (InstantiationException | IllegalAccessException | SecurityException | IllegalArgumentException e) { return null; } }
From source file:org.seasar.dao.spring.autoregister.AbstractBeanAutoRegister.java
private boolean isApplicableAspect(final Method method) { final int mod = method.getModifiers(); return !Modifier.isFinal(mod) && !Modifier.isStatic(mod); }
From source file:com.lexicalscope.fluentreflection.FluentMethodImpl.java
@Override public boolean isFinal() { return Modifier.isFinal(method.getModifiers()); }