Search in sources :

Example 1 with PsiJavaFileStub

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)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) ABSTRACT(com.intellij.psi.PsiModifier.ABSTRACT) ContainerUtil(com.intellij.util.containers.ContainerUtil) GrLightField(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) GrAnnotationUtil(org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil) Map(java.util.Map) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Logger(com.intellij.openapi.diagnostic.Logger) GROOVY_TRAIT(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_TRAIT) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) ClsClassImpl(com.intellij.psi.impl.compiled.ClsClassImpl) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiJavaFileStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl) GROOVY_TRAIT_IMPLEMENTED(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_TRAIT_IMPLEMENTED) Collection(java.util.Collection) TraitFieldDescriptor(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitFieldsFileIndex.TraitFieldDescriptor) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) GroovyTraitFieldsFileIndex(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitFieldsFileIndex) List(java.util.List) GroovyTraitMethodsFileIndex(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitMethodsFileIndex) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) com.intellij.psi(com.intellij.psi) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) GrModifierFlags(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierFlags) Ref(com.intellij.openapi.util.Ref) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) Collection(java.util.Collection) StubElement(com.intellij.psi.stubs.StubElement) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub)

Example 2 with PsiJavaFileStub

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializerNotFoundException(com.intellij.psi.stubs.SerializerNotFoundException) IOException(java.io.IOException) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub)

Example 3 with PsiJavaFileStub

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;
}
Also used : PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiJavaFileStub

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);
    }
}
Also used : PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ClsFormatException(com.intellij.util.cls.ClsFormatException) PluginException(com.intellij.diagnostic.PluginException) IOException(java.io.IOException) PsiJavaFileStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl) LanguageLevel(com.intellij.pom.java.LanguageLevel) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) ClsFormatException(com.intellij.util.cls.ClsFormatException) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PsiJavaFileStub

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;
    }
}
Also used : PsiJavaFileStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub) SerializerNotFoundException(com.intellij.psi.stubs.SerializerNotFoundException) IOException(java.io.IOException)

Aggregations

PsiJavaFileStub (com.intellij.psi.impl.java.stubs.PsiJavaFileStub)5 PsiJavaFileStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl)3 IOException (java.io.IOException)3 SerializerNotFoundException (com.intellij.psi.stubs.SerializerNotFoundException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AnnotationUtil (com.intellij.codeInsight.AnnotationUtil)1 PluginException (com.intellij.diagnostic.PluginException)1 Logger (com.intellij.openapi.diagnostic.Logger)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 com.intellij.psi (com.intellij.psi)1 ABSTRACT (com.intellij.psi.PsiModifier.ABSTRACT)1 ClsClassImpl (com.intellij.psi.impl.compiled.ClsClassImpl)1 PsiMethodStub (com.intellij.psi.impl.java.stubs.PsiMethodStub)1 StubElement (com.intellij.psi.stubs.StubElement)1 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)1 CachedValuesManager (com.intellij.psi.util.CachedValuesManager)1