use of com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl in project intellij-community by JetBrains.
the class JavaFileElementType method deserialize.
@NotNull
@Override
public PsiJavaFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
boolean compiled = dataStream.readBoolean();
int level = dataStream.readByte();
StringRef packageName = dataStream.readName();
return new PsiJavaFileStubImpl(null, StringRef.toString(packageName), level >= 0 ? LanguageLevel.values()[level] : null, compiled);
}
use of com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl in project intellij-community by JetBrains.
the class JavaLightStubBuilder method createStubForFile.
@NotNull
@Override
protected StubElement createStubForFile(@NotNull PsiFile file, @NotNull LighterAST tree) {
if (!(file instanceof PsiJavaFile)) {
return super.createStubForFile(file, tree);
}
String refText = "";
LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT);
if (pkg != null) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
if (ref != null) {
refText = JavaSourceUtil.getReferenceText(tree, ref);
}
}
return new PsiJavaFileStubImpl((PsiJavaFile) file, refText, null, false);
}
use of com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl 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);
}
use of com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl in project intellij-community by JetBrains.
the class GrTraitUtil method doCollectCompiledTraitMethods.
private static void doCollectCompiledTraitMethods(final ClsClassImpl trait, final Collection<PsiMethod> result) {
for (PsiMethod method : trait.getMethods()) {
if (AnnotationUtil.isAnnotated(method, GROOVY_TRAIT_IMPLEMENTED, false)) {
result.add(method);
}
}
VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
if (traitFile == null)
return;
VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitMethodsFileIndex.HELPER_SUFFIX);
if (helperFile == null)
return;
int key = FileBasedIndex.getFileId(helperFile);
List<PsiJavaFileStub> values = FileBasedIndex.getInstance().getValues(GroovyTraitMethodsFileIndex.INDEX_ID, key, trait.getResolveScope());
values.forEach(root -> ((PsiJavaFileStubImpl) root).setPsi((PsiJavaFile) trait.getContainingFile()));
values.stream().map(root -> root.getChildrenStubs().get(0).getChildrenStubs()).<StubElement>flatMap(Collection::stream).filter(stub -> stub instanceof PsiMethodStub).forEach(stub -> result.add(createTraitMethodFromCompiledHelperMethod(((PsiMethodStub) stub).getPsi(), trait)));
}
use of com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl in project intellij-community by JetBrains.
the class ClsFileImpl method buildFileStub.
@Nullable
public static PsiJavaFileStub buildFileStub(@NotNull VirtualFile file, @NotNull byte[] bytes) throws ClsFormatException {
try {
if (ClassFileViewProvider.isInnerClass(file, bytes)) {
return null;
}
ClassReader reader = new ClassReader(bytes);
String className = file.getNameWithoutExtension();
String internalName = reader.getClassName();
boolean module = internalName.equals("module-info") && BitUtil.isSet(reader.getAccess(), Opcodes.ACC_MODULE);
LanguageLevel level = ClsParsingUtil.getLanguageLevelByVersion(reader.readShort(6));
if (module) {
PsiJavaFileStub stub = new PsiJavaFileStubImpl(null, "", level, true);
ModuleStubBuildingVisitor visitor = new ModuleStubBuildingVisitor(stub);
reader.accept(visitor, EMPTY_ATTRIBUTES, ClassReader.SKIP_FRAMES);
if (visitor.getResult() != null)
return stub;
} else {
PsiJavaFileStub stub = new PsiJavaFileStubImpl(null, getPackageName(internalName), level, true);
try {
FileContentPair source = new FileContentPair(file, bytes);
StubBuildingVisitor<FileContentPair> visitor = new StubBuildingVisitor<>(source, STRATEGY, stub, 0, className);
reader.accept(visitor, EMPTY_ATTRIBUTES, ClassReader.SKIP_FRAMES);
if (visitor.getResult() != null)
return stub;
} catch (OutOfOrderInnerClassException ignored) {
}
}
return null;
} catch (Exception e) {
throw new ClsFormatException(file.getPath() + ": " + e.getMessage(), e);
}
}
Aggregations