Search in sources :

Example 6 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException 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 7 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException in project intellij-community by JetBrains.

the class StubBuildingVisitor method parseClassSignature.

private ClassInfo parseClassSignature(String signature) throws ClsFormatException {
    ClassInfo result = new ClassInfo();
    CharacterIterator iterator = new StringCharacterIterator(signature);
    result.typeParameters = SignatureParsing.parseTypeParametersDeclaration(iterator, myMapping);
    result.superName = SignatureParsing.parseTopLevelClassRefSignature(iterator, myMapping);
    while (iterator.current() != CharacterIterator.DONE) {
        String name = SignatureParsing.parseTopLevelClassRefSignature(iterator, myMapping);
        if (name == null)
            throw new ClsFormatException();
        if (result.interfaceNames == null)
            result.interfaceNames = ContainerUtil.newSmartList();
        result.interfaceNames.add(name);
    }
    return result;
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator) ClsFormatException(com.intellij.util.cls.ClsFormatException)

Aggregations

ClsFormatException (com.intellij.util.cls.ClsFormatException)7 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)2 TypeInfo (com.intellij.psi.impl.cache.TypeInfo)2 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)2 IOException (java.io.IOException)2 CharacterIterator (java.text.CharacterIterator)2 StringCharacterIterator (java.text.StringCharacterIterator)2 NotNull (org.jetbrains.annotations.NotNull)2 PluginException (com.intellij.diagnostic.PluginException)1 Logger (com.intellij.openapi.diagnostic.Logger)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Pair (com.intellij.openapi.util.Pair)1 Pair.pair (com.intellij.openapi.util.Pair.pair)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 CommonClassNames (com.intellij.psi.CommonClassNames)1 PsiNameHelper (com.intellij.psi.PsiNameHelper)1 ClassFileDecompilers (com.intellij.psi.compiled.ClassFileDecompilers)1 Full (com.intellij.psi.compiled.ClassFileDecompilers.Full)1