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);
      }
    }
Example #5
0
 private static Object getFieldValue(Class type, String name)
     throws IllegalAccessException, NoSuchFieldException {
   return type.getField(name).get(null);
 }