use of com.intellij.psi.impl.compiled.StubBuildingVisitor 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);
}
Aggregations