コード例 #1
0
 private static PsiElement[] getParameterElementsToSearch(final PsiParameter parameter) {
   final PsiMethod method = (PsiMethod) parameter.getDeclarationScope();
   PsiMethod[] overrides =
       OverridingMethodsSearch.search(method, true).toArray(PsiMethod.EMPTY_ARRAY);
   for (int i = 0; i < overrides.length; i++) {
     overrides[i] = (PsiMethod) overrides[i].getNavigationElement();
   }
   List<PsiElement> elementsToSearch = new ArrayList<PsiElement>(overrides.length + 1);
   elementsToSearch.add(parameter);
   int idx = method.getParameterList().getParameterIndex(parameter);
   for (PsiMethod override : overrides) {
     final PsiParameter[] parameters = override.getParameterList().getParameters();
     if (idx < parameters.length) {
       elementsToSearch.add(parameters[idx]);
     }
   }
   return elementsToSearch.toArray(new PsiElement[elementsToSearch.size()]);
 }
コード例 #2
0
  private static List<PsiElement> getTopLevelRegExpChars(String regExpText, Project project) {
    @SuppressWarnings("deprecation")
    PsiFile file = PsiFileFactory.getInstance(project).createFileFromText("A.regexp", regExpText);
    List<PsiElement> result = null;
    final PsiElement[] children = file.getChildren();

    for (PsiElement child : children) {
      PsiElement[] grandChildren = child.getChildren();
      if (grandChildren.length != 1)
        return Collections
            .emptyList(); // a | b, more than one branch, can not predict in current way

      for (PsiElement grandGrandChild : grandChildren[0].getChildren()) {
        if (result == null) result = new ArrayList<>();
        result.add(grandGrandChild);
      }
    }
    return result != null ? result : Collections.<PsiElement>emptyList();
  }