public void testChainedConstructor() throws Exception { Class cls = loadAndPatchClass("TestChainedConstructor.form", "ChainedConstructorTest"); Field scrollPaneField = cls.getField("myScrollPane"); Object instance = cls.newInstance(); JScrollPane scrollPane = (JScrollPane) scrollPaneField.get(instance); assertNotNull(scrollPane.getViewport().getView()); }
private JComponent getInstrumentedRootComponent(final String formFileName, final String className) throws Exception { Class cls = loadAndPatchClass(formFileName, className); Field rootComponentField = cls.getField("myRootComponent"); rootComponentField.setAccessible(true); Object instance = cls.newInstance(); return (JComponent) rootComponentField.get(instance); }
@Nullable private static Icon getReflectiveIcon(@NotNull String path, ClassLoader classLoader) { try { @NonNls String pckg = path.startsWith("AllIcons.") ? "com.intellij.icons." : "icons."; Class cur = Class.forName( pckg + path.substring(0, path.lastIndexOf('.')).replace('.', '$'), true, classLoader); Field field = cur.getField(path.substring(path.lastIndexOf('.') + 1)); return (Icon) field.get(null); } catch (Exception e) { return null; } }
public Option( @Nullable Class<? extends CustomCodeStyleSettings> clazz, @NotNull String fieldName, @NotNull String title, @Nullable String groupName, @Nullable OptionAnchor anchor, @Nullable String anchorFiledName) { super(fieldName, anchor, anchorFiledName); this.clazz = clazz; this.title = title; this.groupName = groupName; try { Class styleSettingsClass = clazz == null ? CommonCodeStyleSettings.class : clazz; this.field = styleSettingsClass.getField(fieldName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } }
static { // compute primitives/primitiveMap/primitiveToWrapper for (Class<?> c : primitiveWrappers) { try { Field f = c.getField("TYPE"); Class<?> p = (Class<?>) f.get(null); primitives.add(p); primitiveMap.put(p.getName(), p); primitiveToWrapper.put(p.getName(), c); } catch (Exception e) { throw new AssertionError(e); } } // compute editableTypes for (Class<?> c : primitives) { editableTypes.add(c.getName()); } for (Class<?> c : primitiveWrappers) { editableTypes.add(c.getName()); } for (Class<?> c : extraEditableClasses) { editableTypes.add(c.getName()); } // compute numericalTypes for (Class<?> c : primitives) { String name = c.getName(); if (!name.equals(Boolean.TYPE.getName())) { numericalTypes.add(name); } } for (Class<?> c : primitiveWrappers) { String name = c.getName(); if (!name.equals(Boolean.class.getName())) { numericalTypes.add(name); } } }
private static Object getFieldValue(Class type, String name) throws IllegalAccessException, NoSuchFieldException { return type.getField(name).get(null); }