public int get() { try { return this.field.getInt(null); } catch (Exception e) { return 0; } }
public final int getIntValue(Object obj) throws IllegalAccessException { if (!isAndroid && memOffset >= 0) { return FSTUtil.unFlaggedUnsafe.getInt(obj, memOffset); } return field.getInt(obj); }
private void addDefaultValue(JadxCLIArgs args, Field f, StringBuilder opt) { Class<?> fieldType = f.getType(); if (fieldType == int.class) { try { int val = f.getInt(args); opt.append(" (default: ").append(val).append(")"); } catch (Exception e) { // ignore } } }
private void readAndroidRStyleClass() { try { Class<?> rStyleCls = Class.forName(ANDROID_R_STYLE_CLS); for (Field f : rStyleCls.getFields()) { styleMap.put(f.getInt(f.getType()), f.getName()); } } catch (Exception th) { LOG.error("Android R class loading failed", th); } }
@Override void serialize(AbstractHessianOutput out, Object obj, Field field) throws IOException { int value = 0; try { value = field.getInt(obj); } catch (IllegalAccessException e) { log.log(Level.FINE, e.toString(), e); } out.writeInt(value); } }
public static int getResId(String resName, Class<?> c) { try { Field idField = c.getDeclaredField(resName); return idField.getInt(idField); } catch (Exception e) { e.printStackTrace(); return -1; } }
public static int getNativeConfig(Bitmap.Config config) { try { if (nativeIntField == null) { return 0; } return nativeIntField.getInt(config); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return 0; }
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Field mDragger = mDrawerLayout.getClass().getDeclaredField( "mLeftDragger");//mRightDragger for right obviously mDragger.setAccessible(true); ViewDragHelper draggerObj = (ViewDragHelper) mDragger .get(mDrawerLayout); Field mEdgeSize = draggerObj.getClass().getDeclaredField( "mEdgeSize"); mEdgeSize.setAccessible(true); int edge = mEdgeSize.getInt(draggerObj); mEdgeSize.setInt(draggerObj, edge * 5); //optimal value as for me, you may set any constant in dp
public static int pid(@Nonnull Process proc) { try { if (JAVA8_PID_FIELD != null) { return JAVA8_PID_FIELD.getInt(proc); } else { long pid = (long)JAVA9_PID_METHOD.invoke(proc); if (pid > Integer.MAX_VALUE) { throw new IllegalAccessError("Java 9+ support error (JENKINS-53799). PID is out of Jenkins API bounds: " + pid); } return (int)pid; } } catch (IllegalAccessException | InvocationTargetException e) { // impossible IllegalAccessError x = new IllegalAccessError(); x.initCause(e); throw x; } } }
/** * Get system file descriptor (int) from FileDescriptor object. * @param descriptor - FileDescriptor object to get fd from * @return file descriptor, -1 or error */ public static int getfd(FileDescriptor descriptor) { try { return field.getInt(descriptor); } catch (IllegalArgumentException | IllegalAccessException e) { log.warn("Unable to read fd field from java.io.FileDescriptor"); } return -1; }
Field f = R.class.getField("_1st"); Class<?> t = f.getType(); if(t == int.class){ System.out.println(f.getInt(null)); }else if(t == double.class){ System.out.println(f.getDouble(null)); }...
/** * Handy method for fetching hidden integer constant value in system classes. * * @param clazz * @param fieldName * @return */ public static int getValueOfStaticIntField(Class<?> clazz, String fieldName, int defVal) { try { final Field field = findField(clazz, fieldName); return field.getInt(null); } catch (Throwable thr) { return defVal; } } }
public static void setStaticFinalField( Field field, Object value) throws NoSuchFieldException, IllegalAccessException { // 获得 public 权限 field.setAccessible(true); // 将modifiers域设为非final,这样就可以修改了 Field modifiersField = Field.class.getDeclaredField(MODIFIERS_FIELD); modifiersField.setAccessible(true); int modifiers = modifiersField.getInt(field); // 去掉 final 标志位 modifiers &= ~Modifier.FINAL; modifiersField.setInt(field, modifiers); FieldAccessor fa = reflection.newFieldAccessor( field, false ); fa.set(null, value); } }
@Implementation(minSdk = LOLLIPOP) @HiddenApi protected static int nativeAxisFromString(String label) { // The native code just mirrors the AXIS_* constants defined in MotionEvent.java. Look up // the field value by reflection try { Field constantField = MotionEvent.class.getDeclaredField("AXIS_" + label); return constantField.getInt(null); } catch (NoSuchFieldException | IllegalAccessException e) { return 0; } }
private int extractOracleCursorTypeValue() { try { return locateOracleTypesClass().getField( "CURSOR" ).getInt( null ); } catch ( Exception se ) { throw new HibernateException( "Unable to access OracleTypes.CURSOR value", se ); } }
@Test public void testRuleOffsetValue() throws Exception { final Field ruleTypesOffset = JavadocTokenTypes.class.getDeclaredField("RULE_TYPES_OFFSET"); ruleTypesOffset.setAccessible(true); assertEquals("Please ensure that the field `RULE_TYPES_OFFSET` in" + " `JavadocTokenTypes.java` has a value of 10000", 10000, ruleTypesOffset.getInt(null)); }
private void assertLoadUnloadInvocationCount(Class<?> testExtensionClass, int invocationCount) throws Exception { String simpleNameOfTestExtensionClass = testExtensionClass.getSimpleName(); setupClassesInBundle(simpleNameOfTestExtensionClass + ".class"); when(bundle.loadClass(contains(simpleNameOfTestExtensionClass))).thenReturn((Class) testExtensionClass); activator.start(context); assertThat(testExtensionClass.getField("loadInvoked").getInt(null), is(invocationCount)); activator.stop(context); assertThat(testExtensionClass.getField("unLoadInvoked").getInt(null), is(invocationCount)); }
@Test public void testTokenValueCorrect() throws IllegalAccessException { final Field[] fields = TokenTypes.class.getDeclaredFields(); for (final Field field : fields) { // Only process the int declarations. if (field.getType() != Integer.TYPE) { continue; } final String name = field.getName(); final int id = field.getInt(name); assertEquals("Invalid token name", name, TokenUtil.getTokenName(id)); } }
@Test public void intArgSetsCapacityIfNoPropertySpecified() throws Exception { final SortedArrayStringMap actual = (SortedArrayStringMap) ContextDataFactory.createContextData(2); final Field thresholdField = SortedArrayStringMap.class.getDeclaredField("threshold"); thresholdField.setAccessible(true); assertEquals(2, thresholdField.getInt(actual)); } }
@Test public void intArgReturnsSortedArrayStringMapIfPropertySpecifiedButMissingIntConstructor() throws Exception { System.setProperty("log4j2.ContextData", FactoryTestStringMapWithoutIntConstructor.class.getName()); assertTrue(ContextDataFactory.createContextData(2) instanceof SortedArrayStringMap); final SortedArrayStringMap actual = (SortedArrayStringMap) ContextDataFactory.createContextData(2); final Field thresholdField = SortedArrayStringMap.class.getDeclaredField("threshold"); thresholdField.setAccessible(true); assertEquals(2, thresholdField.getInt(actual)); System.clearProperty("log4j2.ContextData"); } }