use of org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class SourceLineCounterUtil method collectNonCoveredClassInfo.
public static boolean collectNonCoveredClassInfo(final PackageAnnotator.ClassCoverageInfo classCoverageInfo, final PackageAnnotator.PackageCoverageInfo packageCoverageInfo, byte[] content, final boolean excludeLines, final PsiClass psiClass) {
if (content == null)
return false;
ClassReader reader = new ClassReader(content, 0, content.length);
SourceLineCounter counter = new SourceLineCounter(null, excludeLines, null);
reader.accept(counter, 0);
classCoverageInfo.totalLineCount += counter.getNSourceLines();
packageCoverageInfo.totalLineCount += counter.getNSourceLines();
for (Object nameAndSig : counter.getMethodsWithSourceCode()) {
if (!PackageAnnotator.isGeneratedDefaultConstructor(psiClass, (String) nameAndSig)) {
classCoverageInfo.totalMethodCount++;
packageCoverageInfo.totalMethodCount++;
}
}
if (!counter.isInterface()) {
packageCoverageInfo.totalClassCount++;
}
return !counter.isInterface();
}
use of org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class DefaultOutputConsumer method readClassName.
private static String readClassName(byte[] classBytes) throws IOException {
final Ref<String> nameRef = Ref.create(null);
new ClassReader(classBytes).accept(new ClassVisitor(Opcodes.API_VERSION) {
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
nameRef.set(name.replace('/', '.'));
}
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return nameRef.get();
}
use of org.jetbrains.org.objectweb.asm.ClassReader 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 org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class InstrumentationClassFinder method loadPseudoClass.
private PseudoClass loadPseudoClass(InputStream is) throws IOException {
final ClassReader reader = new ClassReader(is);
final V visitor = new V();
reader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return new PseudoClass(this, visitor.myName, visitor.mySuperclassName, visitor.myInterfaces, visitor.myModifiers, visitor.myMethods);
}
use of org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class BaseInstrumentingBuilder method performBuild.
@Override
protected final ExitCode performBuild(CompileContext context, ModuleChunk chunk, InstrumentationClassFinder finder, OutputConsumer outputConsumer) {
ExitCode exitCode = ExitCode.NOTHING_DONE;
for (CompiledClass compiledClass : outputConsumer.getCompiledClasses().values()) {
if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
LOG.info("checking " + compiledClass + " by " + getClass());
}
final BinaryContent originalContent = compiledClass.getContent();
final ClassReader reader = new FailSafeClassReader(originalContent.getBuffer(), originalContent.getOffset(), originalContent.getLength());
final int version = getClassFileVersion(reader);
if (IS_INSTRUMENTED_KEY.get(compiledClass, Boolean.FALSE) || !canInstrument(compiledClass, version)) {
// do not instrument the same content twice
continue;
}
final ClassWriter writer = new InstrumenterClassWriter(reader, getAsmClassWriterFlags(version), finder);
try {
if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
LOG.info("instrumenting " + compiledClass + " by " + getClass());
}
final BinaryContent instrumented = instrument(context, compiledClass, reader, writer, finder);
if (instrumented != null) {
compiledClass.setContent(instrumented);
finder.cleanCachedData(compiledClass.getClassName());
IS_INSTRUMENTED_KEY.set(compiledClass, Boolean.TRUE);
exitCode = ExitCode.OK;
}
} catch (Throwable e) {
LOG.info(e);
final String message = e.getMessage();
if (message != null) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message, ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
} else {
context.processMessage(new CompilerMessage(getPresentableName(), e));
}
}
}
return exitCode;
}
Aggregations