Search in sources :

Example 1 with PsiJavaFileStubImpl

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

Example 2 with PsiJavaFileStubImpl

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

Example 3 with PsiJavaFileStubImpl

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);
}
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)

Example 4 with PsiJavaFileStubImpl

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)));
}
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 5 with PsiJavaFileStubImpl

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);
    }
}
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)

Aggregations

PsiJavaFileStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl)6 PsiJavaFileStub (com.intellij.psi.impl.java.stubs.PsiJavaFileStub)3 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)2 AnnotationUtil (com.intellij.codeInsight.AnnotationUtil)1 PluginException (com.intellij.diagnostic.PluginException)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 Logger (com.intellij.openapi.diagnostic.Logger)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Ref (com.intellij.openapi.util.Ref)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 com.intellij.psi (com.intellij.psi)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 ABSTRACT (com.intellij.psi.PsiModifier.ABSTRACT)1 ClsClassImpl (com.intellij.psi.impl.compiled.ClsClassImpl)1 InnerClassSourceStrategy (com.intellij.psi.impl.compiled.InnerClassSourceStrategy)1 StubBuildingVisitor (com.intellij.psi.impl.compiled.StubBuildingVisitor)1