Search in sources :

Example 6 with BinaryContent

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;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) Collection(java.util.Collection) BinaryContent(org.jetbrains.jps.incremental.BinaryContent) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with BinaryContent

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();
}
Also used : ByteString(com.google.protobuf.ByteString) BinaryContent(org.jetbrains.jps.incremental.BinaryContent) File(java.io.File) URI(java.net.URI)

Aggregations

BinaryContent (org.jetbrains.jps.incremental.BinaryContent)7 File (java.io.File)4 URI (java.net.URI)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 ByteString (com.google.protobuf.ByteString)2 IOException (java.io.IOException)2 JavaFileObject (javax.tools.JavaFileObject)2 Nullable (org.jetbrains.annotations.Nullable)2 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 SmartList (com.intellij.util.SmartList)1 THashSet (gnu.trove.THashSet)1 Collection (java.util.Collection)1 JavacCompilerTool (org.jetbrains.jps.builders.impl.java.JavacCompilerTool)1 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)1 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)1 CompiledClass (org.jetbrains.jps.incremental.CompiledClass)1 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)1 InstrumentationException (org.jetbrains.jps.intellilang.model.InstrumentationException)1 JpsIntelliLangConfiguration (org.jetbrains.jps.intellilang.model.JpsIntelliLangConfiguration)1