use of com.intellij.psi.impl.java.stubs.PsiJavaFileStub 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.PsiJavaFileStub in project intellij-community by JetBrains.
the class GroovyTraitMethodsFileIndex method read.
@Override
public PsiJavaFileStub read(@NotNull DataInput in) throws IOException {
try {
byte[] buffer = new byte[in.readInt()];
in.readFully(buffer);
return (PsiJavaFileStub) SerializationManagerEx.getInstanceEx().deserialize(new ByteArrayInputStream(buffer));
} catch (SerializerNotFoundException e) {
throw new IOException(e);
}
}
use of com.intellij.psi.impl.java.stubs.PsiJavaFileStub in project intellij-community by JetBrains.
the class PsiJavaFileBaseImpl method getPackageName.
@Override
@NotNull
public String getPackageName() {
PsiJavaFileStub stub = (PsiJavaFileStub) getGreenStub();
if (stub != null) {
return stub.getPackageName();
}
String name = myPackageName;
if (name == null) {
PsiPackageStatement statement = getPackageStatement();
myPackageName = name = statement == null ? "" : statement.getPackageName();
}
return name;
}
use of com.intellij.psi.impl.java.stubs.PsiJavaFileStub 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);
}
}
use of com.intellij.psi.impl.java.stubs.PsiJavaFileStub in project intellij-community by JetBrains.
the class GroovyTraitMethodsFileIndex method index.
private static PsiJavaFileStub index(VirtualFile file, byte[] content) {
try {
PsiJavaFileStub root = new PsiJavaFileStubImpl("", true);
new ClassReader(content).accept(new GrTraitMethodVisitor(file, root), EMPTY_ATTRIBUTES, ClassReader.SKIP_CODE);
return root;
} catch (Exception e) {
LOG.info(file.getPath(), e);
return null;
}
}
Aggregations