Java 类com.intellij.psi.impl.compiled.ClsElementImpl 实例源码

项目:intellij-ce-playground    文件:JavaPsiImplementationHelperImpl.java   
@Override
public PsiClass getOriginalClass(PsiClass psiClass) {
  PsiCompiledElement cls = psiClass.getUserData(ClsElementImpl.COMPILED_ELEMENT);
  if (cls != null && cls.isValid()) return (PsiClass)cls;

  if (DumbService.isDumb(myProject)) return psiClass;

  VirtualFile vFile = psiClass.getContainingFile().getVirtualFile();
  final ProjectFileIndex idx = ProjectRootManager.getInstance(myProject).getFileIndex();
  if (vFile == null || !idx.isInLibrarySource(vFile)) return psiClass;

  String fqn = psiClass.getQualifiedName();
  if (fqn == null) return psiClass;

  final Set<OrderEntry> orderEntries = ContainerUtil.newHashSet(idx.getOrderEntriesForFile(vFile));
  GlobalSearchScope librariesScope = LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope();
  for (PsiClass original : JavaPsiFacade.getInstance(myProject).findClasses(fqn, librariesScope)) {
    PsiFile psiFile = original.getContainingFile();
    if (psiFile != null) {
      VirtualFile candidateFile = psiFile.getVirtualFile();
      if (candidateFile != null) {
        // order for file and vFile has non empty intersection.
        List<OrderEntry> entries = idx.getOrderEntriesForFile(candidateFile);
        //noinspection ForLoopReplaceableByForEach
        for (int i = 0; i < entries.size(); i++) {
          if (orderEntries.contains(entries.get(i))) return original;
        }
      }
    }
  }

  return psiClass;
}
项目:intellij-ce-playground    文件:ClsMirrorBuildingTest.java   
public void testElementAt() {
  String path = getTestDataDir() + "/pkg/SimpleEnum.class";
  VirtualFile vFile = StandardFileSystems.local().findFileByPath(path);
  assertNotNull(path, vFile);
  PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(vFile);
  assertNotNull(path, psiFile);
  for (int i = 0; i < psiFile.getTextLength(); i++) {
    PsiElement element = psiFile.findElementAt(i);
    assertTrue(i + ":" + element, element == null || element instanceof ClsElementImpl && !(element instanceof PsiFile));
  }
}
项目:consulo-java    文件:JavaPsiImplementationHelperImpl.java   
@Override
public PsiClass getOriginalClass(PsiClass psiClass)
{
    PsiCompiledElement cls = psiClass.getUserData(ClsElementImpl.COMPILED_ELEMENT);
    if(cls != null && cls.isValid())
    {
        return (PsiClass) cls;
    }

    if(DumbService.isDumb(myProject))
    {
        return psiClass;
    }

    VirtualFile vFile = psiClass.getContainingFile().getVirtualFile();
    final ProjectFileIndex idx = ProjectRootManager.getInstance(myProject).getFileIndex();
    if(vFile == null || !idx.isInLibrarySource(vFile))
    {
        return psiClass;
    }

    String fqn = psiClass.getQualifiedName();
    if(fqn == null)
    {
        return psiClass;
    }

    final Set<OrderEntry> orderEntries = ContainerUtil.newHashSet(idx.getOrderEntriesForFile(vFile));
    GlobalSearchScope librariesScope = LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope();
    for(PsiClass original : JavaPsiFacade.getInstance(myProject).findClasses(fqn, librariesScope))
    {
        PsiFile psiFile = original.getContainingFile();
        if(psiFile != null)
        {
            VirtualFile candidateFile = psiFile.getVirtualFile();
            if(candidateFile != null)
            {
                // order for file and vFile has non empty intersection.
                List<OrderEntry> entries = idx.getOrderEntriesForFile(candidateFile);
                //noinspection ForLoopReplaceableByForEach
                for(int i = 0; i < entries.size(); i++)
                {
                    if(orderEntries.contains(entries.get(i)))
                    {
                        return original;
                    }
                }
            }
        }
    }

    return psiClass;
}