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:Main.java
public static void main(String... args) throws Exception { Class<?> c = Class.forName("java.lang.String"); Constructor[] allConstructors = c.getDeclaredConstructors(); for (Constructor ctor : allConstructors) { int searchMod = Modifier.FINAL; int mods = accessModifiers(ctor.getModifiers()); if (searchMod == mods) { System.out.println(ctor); }//from ww w . java 2 s .c om } }
From source file:Main.java
public static boolean fieldCanBeModify(Field field) { return field != null && ((field.getModifiers() & Modifier.FINAL) == 0); }
From source file:Main.java
private static int accessModifiers(int m) { return m & Modifier.FINAL; }
From source file:Main.java
/** * Stores the classes 'static final' field values as a map. * //from w w w . j a v a 2s. c om * @param clazz * The class containing static field values. * @return A map keyed by static field name to value. */ public static Map<String, Object> constantsAsMap(Class<?> clazz) { try { final Map<String, Object> constants = new HashMap<String, Object>(); final int staticFinalMods = Modifier.STATIC | Modifier.FINAL; for (Field field : clazz.getFields()) { if (staticFinalMods == (field.getModifiers() & staticFinalMods)) { // this is a constant! constants.put(field.getName(), field.get(null)); } } return constants; } catch (Exception e) { // wrap in general error throw new IllegalStateException("Unable to initialize class constants for: " + clazz); } }
From source file:me.hurel.hqlbuilder.internal.ProxyUtil.java
public static boolean isFinal(Class<?> objectClass) { return (Modifier.FINAL & objectClass.getModifiers()) == Modifier.FINAL; }
From source file:Main.java
/** * Key to lowercase String, extracts the effective key that was pressed * (without shift, control, alt)//from w w w. j ava 2s . c o m */ public static String getKeyText(KeyEvent e) { // special cases if (e.getKeyCode() == KeyEvent.VK_DELETE) { return "delete"; } // prio 1: get text of unresolved code (shift-1 --> '1') String s = "" + e.getKeyChar(); if (e.getKeyCode() > 0) { int flags = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; for (Field f : KeyEvent.class.getFields()) { if ((f.getModifiers() & flags) == flags) { try { if (f.getName().startsWith("VK_") && ((Integer) f.get(null)) == e.getKeyCode()) { s = f.getName().substring(3).toLowerCase(); break; } } catch (Throwable t) { // nop } } } } if (s.length() != 1) { // prio 2: check if the resolved char is valid (shift-1 --> '+') if (e.getKeyChar() >= 32 && e.getKeyChar() < 128) { s = "" + e.getKeyChar(); } } return s.toLowerCase(); }
From source file:ReflectionHelper.java
/** * Set the value of the field of the object to the given value. * //w ww . j av a2 s. c o m * @param original * object to modify * @param field * field to modify * @param value * new value for the given object and field * @throws NoSuchFieldException * @throws IllegalAccessException */ public static void setStaticFinalField(Object original, Field field, Object value) throws NoSuchFieldException, IllegalAccessException { // we mark the field to be public field.setAccessible(true); // next we change the modifier in the Field instance to // not be final anymore, thus tricking reflection into // letting us modify the static final field Field modifiersField = Field.class.getDeclaredField(MODIFIERS_FIELD); modifiersField.setAccessible(true); int modifiers = modifiersField.getInt(field); // blank out the final bit in the modifiers int modifiers &= ~Modifier.FINAL; modifiersField.setInt(field, modifiers); FieldAccessor fa = reflection.newFieldAccessor(field, false); fa.set(original, value); }
From source file:testinfrastructure.testutils.LogInjector.java
private static void setFinalStaticField(Field field, Object newValue) { try {//w w w . j a v a 2 s.c o m field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, newValue); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.lanternpowered.server.util.ReflectionHelper.java
public static void setField(Field field, @Nullable Object target, @Nullable Object object) throws Exception { final int modifiers = field.getModifiers(); if (Modifier.isFinal(modifiers)) { MODIFIERS_FIELD.set(field, modifiers & ~Modifier.FINAL); }// w ww . j a va2 s. c om field.setAccessible(true); field.set(target, object); }
From source file:org.apache.kylin.rest.DebugTomcat.java
public static void setupDebugEnv() { try {/*w ww . j a v a2 s . c om*/ System.setProperty("log4j.configuration", "file:../build/conf/kylin-tools-log4j.properties"); // test_case_data/sandbox/ contains HDP 2.2 site xmls which is dev sandbox KylinConfig.setSandboxEnvIfPossible(); overrideDevJobJarLocations(); System.setProperty("spring.profiles.active", "testing"); //avoid log permission issue if (System.getProperty("catalina.home") == null) System.setProperty("catalina.home", "."); if (StringUtils.isEmpty(System.getProperty("hdp.version"))) { System.err.println( "No hdp.version set; Please set hdp.version in your jvm option, for example: -Dhdp.version=2.4.0.0-169"); System.exit(1); } // workaround for job submission from win to linux -- https://issues.apache.org/jira/browse/MAPREDUCE-4052 if (Shell.WINDOWS) { { Field field = Shell.class.getDeclaredField("WINDOWS"); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, false); } { Field field = java.io.File.class.getDeclaredField("pathSeparator"); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, ":"); } } } catch (Exception ex) { ex.printStackTrace(); } }