当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionUtil类代码示例

本文整理汇总了Java中com.intellij.util.ReflectionUtil的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtil类的具体用法?Java ReflectionUtil怎么用?Java ReflectionUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReflectionUtil类属于com.intellij.util包,在下文中一共展示了ReflectionUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isTagValueGetter

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
public static boolean isTagValueGetter(final JavaMethod method) {
  if (!isGetter(method)) {
    return false;
  }
  if (hasTagValueAnnotation(method)) {
    return true;
  }
  if ("getValue".equals(method.getName())) {
    if (method.getAnnotation(SubTag.class) != null) return false;
    if (method.getAnnotation(SubTagList.class) != null) return false;
    if (method.getAnnotation(Convert.class) != null || method.getAnnotation(Resolve.class) != null) {
      return !ReflectionUtil.isAssignable(GenericDomValue.class, method.getReturnType());
    }
    if (ReflectionUtil.isAssignable(DomElement.class, method.getReturnType())) return false;
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:DomImplUtil.java

示例2: shouldBeShown

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
protected boolean shouldBeShown(final Type type) {
  final Map<Class, Boolean> hiders = DomUtil.getFile(getDomElement()).getUserData(TREE_NODES_HIDERS_KEY);
  if (type == null || hiders == null || hiders.size() == 0) return true;

  final Class aClass = ReflectionUtil.getRawType(type);

  List<Class> allParents = new ArrayList<Class>();
  for (Map.Entry<Class, Boolean> entry : hiders.entrySet()) {
    if (entry.getKey().isAssignableFrom(aClass)) {
      allParents.add(entry.getKey());
    }
  }
  if (allParents.size() == 0) return false;

  Collections.sort(allParents, INHERITORS_COMPARATOR);

  return hiders.get(allParents.get(0)).booleanValue();

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:AbstractDomElementNode.java

示例3: isLocationInExpandControl

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
private boolean isLocationInExpandControl(final TreePath path, final int x, final int y) {
  final TreeUI ui = getUI();
  if (!(ui instanceof BasicTreeUI)) return false;

  try {
    Class aClass = ui.getClass();
    while (BasicTreeUI.class.isAssignableFrom(aClass) && !BasicTreeUI.class.equals(aClass)) {
      aClass = aClass.getSuperclass();
    }
    final Method method = ReflectionUtil.getDeclaredMethod(aClass, "isLocationInExpandControl", TreePath.class, int.class, int.class);
    if (method != null) {
      return (Boolean)method.invoke(ui, path, x, y);
    }
  }
  catch (Throwable ignore) { }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:Tree.java

示例4: clearAntStaticCache

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
private static void clearAntStaticCache(final Class helperClass) {
  //if (++ourClearAttemptCount > 1000) { // allow not more than 1000 helpers cached inside ant
  //  ourClearAttemptCount = 0;
  //}
  //else {
  //  return;
  //}
  
  // for ant 1.7, there is a dedicated method for cache clearing
  try {
    final Method method = helperClass.getDeclaredMethod("clearCache");
    method.invoke(null);
  }
  catch (Throwable e) {
    try {
      // assume it is older version of ant
      Map helpersCollection = ReflectionUtil.getField(helperClass, null, null, "helpers");
      helpersCollection.clear();
    }
    catch (Throwable _e) {
      // ignore.
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AntIntrospector.java

示例5: isDumbAware

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
@Override
public boolean isDumbAware() {
  if (myDumbAware != null) {
    return myDumbAware;
  }

  boolean dumbAware = super.isDumbAware();
  if (dumbAware) {
    myDumbAware = Boolean.TRUE;
  } else {
    if (myDumbAware == null) {
      Class<?> declaringClass = ReflectionUtil.getMethodDeclaringClass(getClass(), "update", AnActionEvent.class);
      myDumbAware = AnAction.class.equals(declaringClass) || ActionGroup.class.equals(declaringClass);
    }
  }

  return myDumbAware;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ActionGroup.java

示例6: getPropertyValue

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
@Nullable
private static Object getPropertyValue(Object componentInstance, String propertyName) {
  final Class<? extends Object> componentInstanceClass = componentInstance.getClass();
  Object propertyValue = ReflectionUtil.getField(componentInstanceClass, componentInstance, null, propertyName);
  if (propertyValue == null) {
    Method method = ReflectionUtil.getMethod(componentInstanceClass, "get" + StringUtil.capitalize(propertyName));
    if (method == null) {
      method = ReflectionUtil.getMethod(componentInstanceClass, "is" + StringUtil.capitalize(propertyName));
    }
    if (method != null) {
      try {
        propertyValue = method.invoke(componentInstance);
      }
      catch (Exception ignored) {
      }
    }
  }
  return propertyValue;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:IdeSettingsStatisticsUtils.java

示例7: fillTable

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
void fillTable() {
  Class<?> clazz0 = myComponent.getClass();
  Class<?> clazz = clazz0.isAnonymousClass() ? clazz0.getSuperclass() : clazz0;
  myProperties.add(new PropertyBean("class", clazz.getName()));
  for (String name: PROPERTIES) {
    String propertyName = ObjectUtils.notNull(StringUtil.getPropertyName(name), name);
    Object propertyValue;
    try {
      try {
        //noinspection ConstantConditions
        propertyValue = ReflectionUtil.findMethod(Arrays.asList(clazz.getMethods()), name).invoke(myComponent);
      }
      catch (Exception e) {
        propertyValue = ReflectionUtil.findField(clazz, null, name).get(myComponent);
      }
      myProperties.add(new PropertyBean(propertyName, propertyValue));
    }
    catch (Exception ignored) {
    }
  }
  Object addedAt = myComponent instanceof JComponent ? ((JComponent)myComponent).getClientProperty("uiInspector.addedAt") : null;
  myProperties.add(new PropertyBean("added-at", addedAt));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:UiInspectorAction.java

示例8: fixGtkPopupStyle

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
private static void fixGtkPopupStyle() {
  if (!UIUtil.isUnderGTKLookAndFeel()) return;

  final SynthStyleFactory original = SynthLookAndFeel.getStyleFactory();

  SynthLookAndFeel.setStyleFactory(new SynthStyleFactory() {
    @Override
    public SynthStyle getStyle(final JComponent c, final Region id) {
      final SynthStyle style = original.getStyle(c, id);
      if (id == Region.POPUP_MENU) {
        final Integer x = ReflectionUtil.getField(style.getClass(), style, int.class, "xThickness");
        if (x != null && x == 0) {
          // workaround for Sun bug #6636964
          ReflectionUtil.setField(style.getClass(), style, int.class, "xThickness", 1);
          ReflectionUtil.setField(style.getClass(), style, int.class, "yThickness", 3);
        }
      }
      return style;
    }
  });

  new JBPopupMenu();  // invokes updateUI() -> updateStyle()

  SynthLookAndFeel.setStyleFactory(original);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LafManagerImpl.java

示例9: doConvert

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
private static void doConvert(Object object, String prefix, Map<String, String> result) throws IllegalAccessException {
  for (Field each : ReflectionUtil.collectFields(object.getClass())) {
    Class<?> type = each.getType();
    if (shouldSkip(type)) continue;

    each.setAccessible(true);
    Object value = each.get(object);

    if (value != null) {
      String name = prefix + each.getName();

      String sValue = String.valueOf(value);
      if (!isNativeToString(sValue, value)) {
        result.put(name, sValue);
      }

      Package pack = type.getPackage();
      if (pack != null && Model.class.getPackage().getName().equals(pack.getName())) {
        doConvert(value, name + ".", result);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:MavenModelConverter.java

示例10: fixStickyAlt

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
private static void fixStickyAlt(AWTEvent e) {
  if (Registry.is("actionSystem.win.suppressAlt.new")) {
    if (UIUtil.isUnderWindowsLookAndFeel() &&
        e instanceof InputEvent &&
        (((InputEvent)e).getModifiers() & (InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)) != 0 &&
        !(e instanceof KeyEvent && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_ALT)) {
      try {
        if (ourStickyAltField == null) {
          Class<?> aClass = Class.forName("com.sun.java.swing.plaf.windows.WindowsRootPaneUI$AltProcessor");
          ourStickyAltField = ReflectionUtil.getDeclaredField(aClass, "menuCanceledOnPress");
        }
        if (ourStickyAltField != null) {
          ourStickyAltField.set(null, true);
        }
      }
      catch (Exception exception) {
        LOG.error(exception);
      }
    }
  }
  else if (SystemInfo.isWindowsXP && e instanceof KeyEvent && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_ALT) {
    ((KeyEvent)e).consume();  // IDEA-17359
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:IdeEventQueue.java

示例11: removeAllCovariantMethods

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
private static void removeAllCovariantMethods(final List<Method> actualMethods, final Method method, final Map<Method, Method> covariantMethods) {
  if ((method.getModifiers() & Constants.ACC_SYNTHETIC) != 0) {
    return;
  }

  for (Iterator<Method> it = actualMethods.iterator(); it.hasNext();) {
    Method actualMethod = it.next();
    if (actualMethod.equals(method)) {
      continue;
    }

    if (!actualMethod.getName().equals(method.getName()) ||
        !Arrays.equals(actualMethod.getParameterTypes(), method.getParameterTypes())) {
      continue;
    }

    if (ReflectionUtil.isAssignable(actualMethod.getReturnType(), method.getReturnType())) {
      if ((actualMethod.getModifiers() & Constants.ACC_ABSTRACT) != 0 || (actualMethod.getModifiers() & Constants.ACC_SYNTHETIC) != 0) {
        covariantMethods.put(actualMethod, method); //generate bridge
      }
      else {
        it.remove();
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:AdvancedEnhancer.java

示例12: getProcessPid

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
/**
 * Returns {@code pid} for Windows process
 * @param process Windows process
 * @return pid of the {@code process}
 */
public static int getProcessPid(Process process) {
  if (process.getClass().getName().equals("java.lang.Win32Process") ||
      process.getClass().getName().equals("java.lang.ProcessImpl")) {
    try {
      long handle = ReflectionUtil.getField(process.getClass(), process, long.class, "handle");

      Kernel32 kernel = Kernel32.INSTANCE;
      WinNT.HANDLE winHandle = new WinNT.HANDLE();
      winHandle.setPointer(Pointer.createConstant(handle));
      return kernel.GetProcessId(winHandle);
    } catch (Throwable e) {
      throw new IllegalStateException(e);
    }
  } else {
    throw new IllegalStateException("Unknown Process implementation");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:WinProcessManager.java

示例13: testResetField

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
public void testResetField() throws Exception {
  final Reset reset = new Reset();

  ReflectionUtil.resetField(reset, String.class, "STRING");
  assertNull(reset.STRING);

  ReflectionUtil.resetField(reset, boolean.class, "BOOLEAN");
  assertFalse(reset.BOOLEAN);

  ReflectionUtil.resetField(reset, int.class, "INT");
  assertEquals(0, reset.INT);

  ReflectionUtil.resetField(reset, double.class, "DOUBLE");
  assertEquals(0d, reset.DOUBLE);

  ReflectionUtil.resetField(reset, float.class, "FLOAT");
  assertEquals(0f, reset.FLOAT);

  ReflectionUtil.resetField(Reset.class, String.class, "STATIC_STRING");
  assertNull(Reset.STATIC_STRING);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ReflectionUtilTest.java

示例14: filePathsDirty

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
@Override
public void filePathsDirty(@Nullable final Collection<FilePath> filesDirty, @Nullable final Collection<FilePath> dirsRecursivelyDirty) {
  try {
    final MultiMap<AbstractVcs, FilePath> filesConverted = groupByVcs(filesDirty);
    final MultiMap<AbstractVcs, FilePath> dirsConverted = groupByVcs(dirsRecursivelyDirty);
    if (filesConverted.isEmpty() && dirsConverted.isEmpty()) return;

    if (LOG.isDebugEnabled()) {
      LOG.debug("paths dirty: " + filesConverted + "; " + dirsConverted + "; " + ReflectionUtil.findCallerClass(3));
    }

    boolean hasSomethingDirty;
    synchronized (LOCK) {
      if (!myReady) return;
      markDirty(myDirtBuilder, filesConverted, false);
      markDirty(myDirtBuilder, dirsConverted, true);
      hasSomethingDirty = !myDirtBuilder.isEmpty();
    }

    if (hasSomethingDirty) {
      myChangeListManager.scheduleUpdate();
    }
  }
  catch (ProcessCanceledException ignore) {
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:VcsDirtyScopeManagerImpl.java

示例15: getChildIndex

import com.intellij.util.ReflectionUtil; //导入依赖的package包/类
protected static <T extends PsiNamedElement> int getChildIndex(T element, PsiElement parent, String name, Class<T> hisClass) {
  PsiElement[] children = parent.getChildren();
  int index = 0;

  for (PsiElement child : children) {
    if (ReflectionUtil.isAssignable(hisClass, child.getClass())) {
      T namedChild = hisClass.cast(child);
      final String childName = namedChild.getName();

      if (Comparing.equal(name, childName)) {
        if (namedChild.equals(element)) {
          return index;
        }
        index++;
      }
    }
  }

  return index;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AbstractElementSignatureProvider.java


注:本文中的com.intellij.util.ReflectionUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。