Search in sources :

Example 1 with InnerClassSourceStrategy

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

the class ClsMirrorBuildingTest method testStrayInnersFiltering.

public void testStrayInnersFiltering() throws IOException {
    String path = JavaTestUtil.getJavaTestDataPath() + "/../../mockJDK-1.8/jre/lib/rt.jar!/java/lang/Class.class";
    VirtualFile file = StandardFileSystems.jar().findFileByPath(path);
    assertNotNull(path, file);
    InnerClassSourceStrategy<VirtualFile> strategy = new InnerClassSourceStrategy<VirtualFile>() {

        @Override
        public VirtualFile findInnerClass(String innerName, VirtualFile outerClass) {
            String baseName = outerClass.getNameWithoutExtension();
            VirtualFile child = outerClass.getParent().findChild(baseName + "$" + innerName + ".class");
            // stray inner classes should be filtered out
            assert child != null : innerName + " is not an inner class of " + outerClass;
            return child;
        }

        @Override
        public void accept(VirtualFile innerClass, StubBuildingVisitor<VirtualFile> visitor) {
            try {
                byte[] bytes = innerClass.contentsToByteArray();
                new ClassReader(bytes).accept(visitor, ClassReader.SKIP_FRAMES);
            } catch (IOException ignored) {
            }
        }
    };
    PsiJavaFileStubImpl stub = new PsiJavaFileStubImpl("java.lang", true);
    StubBuildingVisitor<VirtualFile> visitor = new StubBuildingVisitor<>(file, strategy, stub, 0, null);
    new ClassReader(file.contentsToByteArray()).accept(visitor, ClassReader.SKIP_FRAMES);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiJavaFileStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) InnerClassSourceStrategy(com.intellij.psi.impl.compiled.InnerClassSourceStrategy) IOException(java.io.IOException) StubBuildingVisitor(com.intellij.psi.impl.compiled.StubBuildingVisitor)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 InnerClassSourceStrategy (com.intellij.psi.impl.compiled.InnerClassSourceStrategy)1 StubBuildingVisitor (com.intellij.psi.impl.compiled.StubBuildingVisitor)1 PsiJavaFileStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl)1 IOException (java.io.IOException)1 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)1