예제 #1
0
  @Nullable
  public static PsiElement getOriginalElement(PsiClass clazz, PsiFile containingFile) {
    VirtualFile vFile = containingFile.getVirtualFile();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(clazz.getProject());
    final ProjectFileIndex idx = ProjectRootManager.getInstance(facade.getProject()).getFileIndex();

    if (vFile == null || !idx.isInLibrarySource(vFile)) return clazz;
    final String qName = clazz.getQualifiedName();
    if (qName == null) return null;
    final List<OrderEntry> orderEntries = idx.getOrderEntriesForFile(vFile);
    PsiClass original =
        facade.findClass(
            qName,
            new GlobalSearchScope(facade.getProject()) {
              public int compare(VirtualFile file1, VirtualFile file2) {
                return 0;
              }

              public boolean contains(VirtualFile file) {
                // order for file and vFile has non empty intersection.
                List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
                //noinspection ForLoopReplaceableByForEach
                for (int i = 0; i < entries.size(); i++) {
                  final OrderEntry entry = entries.get(i);
                  if (orderEntries.contains(entry)) return true;
                }
                return false;
              }

              public boolean isSearchInModuleContent(@NotNull Module aModule) {
                return false;
              }

              public boolean isSearchInLibraries() {
                return true;
              }
            });

    return original != null ? original : clazz;
  }
  private void error(String descr) {
    PsiFile file = myScope.getContainingFile();
    String fileText = file != null ? file.getText() : null;

    LogMessageEx.error(LOG, descr, myScope.getText(), "\n------------------\n", fileText);
  }