List of usage examples for java.lang.reflect Modifier FINAL
int FINAL
To view the source code for java.lang.reflect Modifier FINAL.
Click Source Link
From source file:org.jenkinsci.plugins.ghprb.GhprbTestUtil.java
public static List<String> checkClassForGetters(Class<?> clazz) { Field[] fields = clazz.getDeclaredFields(); List<Field> xmlFields = new ArrayList<Field>(); List<String> errors = new ArrayList<String>(); for (Field field : fields) { int modifiers = field.getModifiers(); if (modifiers == (Modifier.PRIVATE) || modifiers == (Modifier.PRIVATE | Modifier.FINAL)) { xmlFields.add(field);// w w w . j a va 2s. c o m } } for (Field field : xmlFields) { String getter = "get" + StringUtils.capitalize(field.getName()); try { Method method = clazz.getDeclaredMethod(getter); int modifier = method.getModifiers(); if (!Modifier.isPublic(modifier)) { errors.add(getter + " is not a public method"); } } catch (Exception e) { String wrongGetter = "is" + StringUtils.capitalize(field.getName()); try { clazz.getDeclaredMethod(wrongGetter); errors.add("Setter is using the wrong name, is " + wrongGetter + " and should be " + getter); } catch (Exception err) { errors.add("Missing " + getter); } } } return errors; }
From source file:org.wso2.carbon.identity.oauth.endpoint.util.EndpointUtilTest.java
private void setMockedLog(boolean isDebugEnabled) throws Exception { Constructor<EndpointUtil> constructor = EndpointUtil.class.getDeclaredConstructor(new Class[0]); constructor.setAccessible(true);/*from w ww .j a va 2s . c o m*/ Object claimUtilObject = constructor.newInstance(new Object[0]); Field logField = claimUtilObject.getClass().getDeclaredField("log"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(logField, logField.getModifiers() & ~Modifier.FINAL); logField.setAccessible(true); logField.set(claimUtilObject, mockedLog); when(mockedLog.isDebugEnabled()).thenReturn(isDebugEnabled); }
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
protected FieldMetadataBuilder getGvNIXPatternField() { return new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("PATTERN_PARAM_NAME"), JavaType.STRING, "\"" + GVNIXPATTERN + "\""); }
From source file:com.google.dexmaker.ProxyBuilder.java
private static <T, G extends T> void generateConstructorsAndFields(DexMaker dexMaker, TypeId<G> generatedType, TypeId<T> superType, Class<T> superClass) { TypeId<InvocationHandler> handlerType = TypeId.get(InvocationHandler.class); TypeId<Method[]> methodArrayType = TypeId.get(Method[].class); FieldId<G, InvocationHandler> handlerField = generatedType.getField(handlerType, FIELD_NAME_HANDLER); dexMaker.declare(handlerField, PRIVATE, null); FieldId<G, Method[]> allMethods = generatedType.getField(methodArrayType, FIELD_NAME_METHODS); dexMaker.declare(allMethods, PRIVATE | STATIC, null); for (Constructor<T> constructor : getConstructorsToOverwrite(superClass)) { if (constructor.getModifiers() == Modifier.FINAL) { continue; }//from ww w .j a v a2 s.c om TypeId<?>[] types = classArrayToTypeArray(constructor.getParameterTypes()); MethodId<?, ?> method = generatedType.getConstructor(types); Code constructorCode = dexMaker.declare(method, PUBLIC); Local<G> thisRef = constructorCode.getThis(generatedType); Local<?>[] params = new Local[types.length]; for (int i = 0; i < params.length; ++i) { params[i] = constructorCode.getParameter(i, types[i]); } MethodId<T, ?> superConstructor = superType.getConstructor(types); constructorCode.invokeDirect(superConstructor, null, thisRef, params); constructorCode.returnVoid(); } }
From source file:jef.tools.security.EncrypterUtil.java
/** * ???/*from w w w . j a v a2 s .com*/ * @return */ public static boolean removeCryptographyRestrictions() { if (!isRestrictedCryptography()) { return false; } try { /* * Do the following, but with reflection to bypass access checks: * * JceSecurity.isRestricted = false; * JceSecurity.defaultPolicy.perms.clear(); * JceSecurity.defaultPolicy.add(CryptoAllPermission.INSTANCE); */ final Class<?> jceSecurity = Class.forName("javax.crypto.JceSecurity"); final Class<?> cryptoPermissions = Class.forName("javax.crypto.CryptoPermissions"); final Class<?> cryptoAllPermission = Class.forName("javax.crypto.CryptoAllPermission"); final Field isRestrictedField = jceSecurity.getDeclaredField("isRestricted"); isRestrictedField.setAccessible(true); final Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(isRestrictedField, isRestrictedField.getModifiers() & ~Modifier.FINAL); isRestrictedField.set(null, false); final Field defaultPolicyField = jceSecurity.getDeclaredField("defaultPolicy"); defaultPolicyField.setAccessible(true); final PermissionCollection defaultPolicy = (PermissionCollection) defaultPolicyField.get(null); final Field perms = cryptoPermissions.getDeclaredField("perms"); perms.setAccessible(true); ((Map<?, ?>) perms.get(defaultPolicy)).clear(); final Field instance = cryptoAllPermission.getDeclaredField("INSTANCE"); instance.setAccessible(true); defaultPolicy.add((Permission) instance.get(null)); return true; } catch (final Exception e) { LogUtil.error("Failed to remove cryptography restrictions", e); return false; } }
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
protected FieldMetadata getDefinedPatternField() { String definedPatternIds = ""; for (String definedPattern : patterns) { if (definedPatternIds.length() > 0) { definedPatternIds = definedPatternIds.concat(", "); }//from w ww. j ava 2 s .co m definedPatternIds = definedPatternIds.concat("\"").concat(definedPattern.split("=")[0]).concat("\""); } FieldMetadataBuilder fmb = null; JavaSymbolName fieldName = new JavaSymbolName("definedPatterns"); JavaType stringArray = new JavaType(JavaType.STRING.getFullyQualifiedTypeName(), 1, DataType.TYPE, null, null); FieldMetadata field = fieldExists(fieldName, stringArray); if (field != null) { String initializer = field.getFieldInitializer(); initializer = initializer.replace("{", "").replace("}", "").replace(" ", "").replace("\"", ""); for (String pattern : initializer.split(",")) { if (!definedPatternIds.contains(pattern)) { if (definedPatternIds.length() > 0) { definedPatternIds = definedPatternIds.concat(", "); } definedPatternIds = definedPatternIds.concat("\"").concat(pattern).concat("\""); } } fmb = new FieldMetadataBuilder(field); fmb.setFieldInitializer("{ ".concat(definedPatternIds).concat(" }")); } if (fmb == null) { fmb = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, fieldName, stringArray, "{ ".concat(definedPatternIds).concat(" }")); } field = fmb.build(); controllerFields.add(field); return field; }
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
protected void addStaticFields() { FieldMetadataBuilder field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("INDEX_PARAM_NAME"), JavaType.STRING, "\"index\""); builder.addField(field);//w w w . j av a 2s . c o m field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("FORM_PARAM_NAME"), JavaType.STRING, "\"gvnixform\""); builder.addField(field); field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("REFERER_PARAM_NAME"), JavaType.STRING, "\"Referer\""); builder.addField(field); }
From source file:org.wso2.carbon.identity.openidconnect.SAMLAssertionClaimsCallbackTest.java
private void setStaticField(Class classname, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { Field declaredField = classname.getDeclaredField(fieldName); declaredField.setAccessible(true);/*from w ww. j a v a2 s.c o m*/ Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(declaredField, declaredField.getModifiers() & ~Modifier.FINAL); declaredField.set(null, value); }
From source file:org.apache.cassandra.db.ScrubTest.java
/** The SecondaryIndex class is used for custom indexes so to avoid * making a public final field into a private field with getters * and setters, we resort to this hack in order to test it properly * since it can have two values which influence the scrubbing behavior. * @param comparator - the key comparator we want to test *///from ww w.j av a 2 s .c om private void setKeyComparator(AbstractType<?> comparator) { try { Field keyComparator = SecondaryIndex.class.getDeclaredField("keyComparator"); keyComparator.setAccessible(true); int modifiers = keyComparator.getModifiers(); Field modifierField = keyComparator.getClass().getDeclaredField("modifiers"); modifiers = modifiers & ~Modifier.FINAL; modifierField.setAccessible(true); modifierField.setInt(keyComparator, modifiers); keyComparator.set(null, comparator); } catch (Exception ex) { fail("Failed to change key comparator in secondary index : " + ex.getMessage()); ex.printStackTrace(); } }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
@Rpc(description = "Get list of constants (static final fields) for a class") public Bundle getConstants( @RpcParameter(name = "classname", description = "Class to get constants from") String classname) throws Exception { Bundle result = new Bundle(); int flags = Modifier.FINAL | Modifier.PUBLIC | Modifier.STATIC; Class<?> clazz = Class.forName(classname); for (Field field : clazz.getFields()) { if ((field.getModifiers() & flags) == flags) { Class<?> type = field.getType(); String name = field.getName(); if (type == int.class) { result.putInt(name, field.getInt(null)); } else if (type == long.class) { result.putLong(name, field.getLong(null)); } else if (type == double.class) { result.putDouble(name, field.getDouble(null)); } else if (type == char.class) { result.putChar(name, field.getChar(null)); } else if (type instanceof Object) { result.putString(name, field.get(null).toString()); }/*from ww w. ja v a 2 s . c om*/ } } return result; }