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