Java Code Examples for com.intellij.util.ReflectionUtil#getField()

The following examples show how to use com.intellij.util.ReflectionUtil#getField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalTool.java    From EasyCode with MIT License 5 votes vote down vote up
/**
 * 获取字段,私有属性一样强制访问
 *
 * @param obj       对象
 * @param fieldName 字段名
 * @return 字段值
 */
public Object getField(Object obj, String fieldName) {
    if (obj == null) {
        return null;
    }
    Class<?> cls = obj.getClass();
    return ReflectionUtil.getField(cls, obj, Object.class, fieldName);
}
 
Example 2
Source File: IntellijTestSetupRule.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void cleanupSwingDataStructures() throws Exception {
  Object manager =
      ReflectionUtil.getDeclaredMethod(
              Class.forName("javax.swing.KeyboardManager"), "getCurrentManager")
          .invoke(null);
  Map<?, ?> componentKeyStrokeMap =
      ReflectionUtil.getField(
          manager.getClass(), manager, Hashtable.class, "componentKeyStrokeMap");
  componentKeyStrokeMap.clear();
  Map<?, ?> containerMap =
      ReflectionUtil.getField(manager.getClass(), manager, Hashtable.class, "containerMap");
  containerMap.clear();
}
 
Example 3
Source File: UsageViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void clearRendererCache() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (myExpandingCollapsing) return; // to avoid quadratic row enumeration
  // clear renderer cache of node preferred size
  TreeUI ui = myTree.getUI();
  if (ui instanceof BasicTreeUI) {
    AbstractLayoutCache treeState = ReflectionUtil.getField(BasicTreeUI.class, ui, AbstractLayoutCache.class, "treeState");
    Rectangle visibleRect = myTree.getVisibleRect();
    int rowForLocation = myTree.getClosestRowForLocation(0, visibleRect.y);
    int visibleRowCount = getVisibleRowCount();
    List<Node> toUpdate = new ArrayList<>();
    for (int i = rowForLocation + visibleRowCount + 1; i >= rowForLocation; i--) {
      final TreePath eachPath = myTree.getPathForRow(i);
      if (eachPath == null) continue;

      treeState.invalidatePathBounds(eachPath);
      Object node = eachPath.getLastPathComponent();
      if (node instanceof UsageNode) {
        toUpdate.add((Node)node);
      }
    }
    queueUpdateBulk(toUpdate, () -> {
      if (!isDisposed()) {
        myTree.repaint(visibleRect);
      }
    });
  }
  else {
    myTree.setCellRenderer(myUsageViewTreeCellRenderer);
  }
}
 
Example 4
Source File: PopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public AwtPopupWrapper(Popup popup, JBPopup jbPopup) {
  myPopup = popup;
  myJBPopup = jbPopup;

  if (SystemInfo.isMac && UIUtil.isUnderAquaLookAndFeel()) {
    final Component c = (Component)ReflectionUtil.getField(Popup.class, myPopup, Component.class, "component");
    c.setBackground(UIUtil.getPanelBackground());
  }
}
 
Example 5
Source File: UiInspectorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void appendFieldValue(@Nonnull MoreObjects.ToStringHelper h,
                                     @Nonnull GridBagConstraints constraints,
                                     @Nonnull String field) {
  Object value = ReflectionUtil.getField(GridBagConstraints.class, constraints, null, field);
  Object defaultValue = ReflectionUtil.getField(GridBagConstraints.class, new GridBagConstraints(), null, field);
  if (!Comparing.equal(value, defaultValue)) h.add(field, value);
}
 
Example 6
Source File: PopupUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isComboPopupKeyEvent(@Nonnull ComponentEvent event, @Nonnull JComboBox comboBox) {
  final Component component = event.getComponent();
  if(!comboBox.isPopupVisible() || component == null) return false;
  ComboPopup popup = ReflectionUtil.getField(comboBox.getUI().getClass(), comboBox.getUI(), ComboPopup.class, "popup");
  return popup != null && SwingUtilities.isDescendingFrom(popup.getList(), component);
}
 
Example 7
Source File: PopupComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Window getWindow() {
  final Component c = (Component)ReflectionUtil.getField(Popup.class, myPopup, Component.class, "component");
  return c instanceof JWindow ? (JWindow)c : null;
}
 
Example 8
Source File: RunAnythingSearchListModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected RunAnythingSearchListModel() {
  super();
  myDelegate = ReflectionUtil.getField(DefaultListModel.class, this, Vector.class, "delegate");
  clearIndexes();
}