use of org.jetbrains.jps.incremental.BinaryContent in project intellij-community by JetBrains.
the class NotNullInstrumentingBuilder method instrument.
// todo: probably instrument other NotNull-like annotations defined in project settings?
@Override
@Nullable
protected BinaryContent instrument(CompileContext context, CompiledClass compiledClass, ClassReader reader, ClassWriter writer, InstrumentationClassFinder finder) {
try {
final ProjectDescriptor pd = context.getProjectDescriptor();
final List<String> notNulls = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(pd.getProject()).getNotNullAnnotations();
if (NotNullVerifyingInstrumenter.processClassFile((FailSafeClassReader) reader, writer, ArrayUtil.toStringArray(notNulls))) {
return new BinaryContent(writer.toByteArray());
}
} catch (Throwable e) {
LOG.error(e);
final Collection<File> sourceFiles = compiledClass.getSourceFiles();
String msg = "Cannot instrument " + ContainerUtil.map(sourceFiles, file -> file.getName()) + ": " + e.getMessage();
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, msg, ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
}
return null;
}
use of org.jetbrains.jps.incremental.BinaryContent in project intellij-community by JetBrains.
the class JavacProtoUtil method createOutputObjectResponse.
public static JavacRemoteProto.Message.Response createOutputObjectResponse(OutputFileObject fileObject) {
final JavacRemoteProto.Message.Response.OutputObject.Builder msgBuilder = JavacRemoteProto.Message.Response.OutputObject.newBuilder();
msgBuilder.setKind(convertKind(fileObject.getKind()));
msgBuilder.setFilePath(FileUtilRt.toSystemIndependentName(fileObject.getFile().getPath()));
final BinaryContent content = fileObject.getContent();
if (content != null) {
msgBuilder.setContent(ByteString.copyFrom(content.getBuffer(), content.getOffset(), content.getLength()));
}
final String className = fileObject.getClassName();
if (className != null) {
msgBuilder.setClassName(className);
}
final File outputRoot = fileObject.getOutputRoot();
if (outputRoot != null) {
msgBuilder.setOutputRoot(FileUtilRt.toSystemIndependentName(outputRoot.getPath()));
}
final String relativePath = fileObject.getRelativePath();
if (relativePath != null) {
msgBuilder.setRelativePath(relativePath);
}
final URI srcUri = fileObject.getSourceUri();
if (srcUri != null) {
msgBuilder.setSourceUri(srcUri.toString());
}
final JavacRemoteProto.Message.Response.Builder builder = JavacRemoteProto.Message.Response.newBuilder();
builder.setResponseType(JavacRemoteProto.Message.Response.Type.OUTPUT_OBJECT).setOutputObject(msgBuilder.build());
return builder.build();
}
Aggregations