use of com.intellij.compiler.instrumentation.FailSafeClassReader 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