Search in sources :

Example 1 with ClsFileImpl

use of com.intellij.psi.impl.compiled.ClsFileImpl in project intellij-community by JetBrains.

the class ClsPsiTest method getFile.

private static PsiJavaFile getFile(String name) {
    String path = PathManagerEx.getTestDataPath() + TEST_DATA_PATH + "/pack/" + name + ".class";
    VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    assertNotNull(path, file);
    PsiFile clsFile = PsiManager.getInstance(getProject()).findFile(file);
    assertTrue(String.valueOf(clsFile), clsFile instanceof ClsFileImpl);
    return (PsiJavaFile) clsFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ClsFileImpl(com.intellij.psi.impl.compiled.ClsFileImpl)

Example 2 with ClsFileImpl

use of com.intellij.psi.impl.compiled.ClsFileImpl in project intellij-community by JetBrains.

the class CoreJavaDirectoryService method getPsiClasses.

@NotNull
public static PsiClass[] getPsiClasses(@NotNull PsiDirectory dir, PsiFile[] psiFiles) {
    FileIndexFacade index = FileIndexFacade.getInstance(dir.getProject());
    VirtualFile virtualDir = dir.getVirtualFile();
    boolean onlyCompiled = index.isInLibraryClasses(virtualDir) && !index.isInSourceContent(virtualDir);
    List<PsiClass> classes = null;
    for (PsiFile file : psiFiles) {
        if (onlyCompiled && !(file instanceof ClsFileImpl)) {
            continue;
        }
        if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
            PsiClass[] psiClasses = ((PsiClassOwner) file).getClasses();
            if (psiClasses.length == 0)
                continue;
            if (classes == null)
                classes = new ArrayList<>();
            ContainerUtil.addAll(classes, psiClasses);
        }
    }
    return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ClsFileImpl(com.intellij.psi.impl.compiled.ClsFileImpl) ArrayList(java.util.ArrayList) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ClsFileImpl

use of com.intellij.psi.impl.compiled.ClsFileImpl in project intellij-community by JetBrains.

the class ClsMirrorBuildingTest method doTest.

private static void doTest(String clsPath, String txtPath) {
    VirtualFile file = (clsPath.contains("!/") ? StandardFileSystems.jar() : StandardFileSystems.local()).refreshAndFindFileByPath(clsPath);
    assertNotNull(clsPath, file);
    String expected;
    try {
        expected = StringUtil.trimTrailing(PlatformTestUtil.loadFileText(txtPath));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    assertEquals(expected, ClsFileImpl.decompile(file).toString());
    ((ClsFileImpl) getPsiManager().findFile(file)).getMirror();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ClsFileImpl(com.intellij.psi.impl.compiled.ClsFileImpl) IOException(java.io.IOException)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ClsFileImpl (com.intellij.psi.impl.compiled.ClsFileImpl)3 FileIndexFacade (com.intellij.openapi.roots.FileIndexFacade)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1