revert compiler-message to receive only one file
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Tue, 30 Aug 2016 15:41:41 +0000 (18:41 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Tue, 30 Aug 2016 15:42:05 +0000 (18:42 +0300)
jps/jps-builders/src/org/jetbrains/jps/incremental/CompiledClass.java
jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/BaseInstrumentingBuilder.java
jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/NotNullInstrumentingBuilder.java
jps/jps-builders/src/org/jetbrains/jps/incremental/messages/CompilerMessage.java

index 6a57e2707ac7b3d4bee520790783054b93eb2315..5dacdb596078845b66abf943a4a777cb16f52943 100644 (file)
@@ -28,6 +28,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * In-memory representation of JVM *.class file produced by a compiler.
@@ -84,7 +85,7 @@ public class CompiledClass extends UserDataHolderBase{
   }
 
   @NotNull
-  public Collection<String> getSourceFilesPaths() {
+  public List<String> getSourceFilesPaths() {
     return ContainerUtil.map(mySourceFiles, new Function<File, String>() {
       @Override
       public String fun(File file) {
index fffa64cb6ccbb5903a8c0bb48e3d1708efada2df..f8c46abf3e5711c7a94b354ae34094a468a87db4 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.compiler.instrumentation.InstrumentationClassFinder;
 import com.intellij.compiler.instrumentation.InstrumenterClassWriter;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.Key;
+import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.jps.ModuleChunk;
 import org.jetbrains.jps.incremental.*;
@@ -72,7 +73,7 @@ public abstract class BaseInstrumentingBuilder extends ClassProcessingBuilder {
         LOG.info(e);
         final String message = e.getMessage();
         if (message != null) {
-          context.processMessage(new CompilerMessage(getPresentableName(), message, compiledClass.getSourceFilesPaths(), BuildMessage.Kind.ERROR));
+          context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message, ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
         }
         else {
           context.processMessage(new CompilerMessage(getPresentableName(), e));
index 5ae766ce0e59300ec85287662c6fd14310cc6874..a4e7873b373b0bf78caf9ee10b522272e91d30da 100644 (file)
@@ -93,9 +93,9 @@ public class NotNullInstrumentingBuilder extends BaseInstrumentingBuilder{
         }
       }) + ": " + e.getMessage();
       context.processMessage(new CompilerMessage(getPresentableName(),
+                                                 BuildMessage.Kind.ERROR,
                                                  msg,
-                                                 compiledClass.getSourceFilesPaths(),
-                                                 BuildMessage.Kind.ERROR));
+                                                 ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
     }
     return null;
   }
index c627ab7df75a09c9fc4f318465a2e954d91e3a7b..a594a9bef12d11a993563c1a573706b187184068 100644 (file)
 package org.jetbrains.jps.incremental.messages;
 
 import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.PrintStream;
-import java.util.Collection;
-import java.util.Collections;
 
 /**
  * @author Eugene Zhuravlev
@@ -37,28 +33,24 @@ public class CompilerMessage extends BuildMessage {
   private final long myProblemBeginOffset;
   private final long myProblemEndOffset;
   private final long myProblemLocationOffset;
-  private final Collection<String> mySourcePaths;
+  private final String mySourcePath;
   private final long myLine;
   private final long myColumn;
 
   public CompilerMessage(@NotNull String compilerName, @NotNull Throwable internalError) {
-    this(compilerName, Kind.ERROR, getTextFromThrowable(internalError));
+    this(compilerName, Kind.ERROR, getTextFromThrowable(internalError), null, -1L, -1L, -1L, -1L, -1L);
   }
 
   public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText) {
-    this(compilerName, kind, messageText, (String)null, -1L, -1L, -1L, -1L, -1L);
-  }
-
-  public CompilerMessage(@NotNull String compilerName, String messageText, Collection<String> sourcePaths, Kind kind) {
-    this(compilerName, kind, messageText, sourcePaths, -1L, -1L, -1L, -1L, -1L);
+    this(compilerName, kind, messageText, null, -1L, -1L, -1L, -1L, -1L);
   }
 
   public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText, String sourcePath) {
-    this(compilerName, messageText, sourcePath == null ? Collections.<String>emptyList() : Collections.singleton(sourcePath), kind);
+    this(compilerName, kind, messageText, sourcePath, -1L, -1L, -1L, -1L, -1L);
   }
 
   public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText,
-                         @NotNull Collection<String> sourcePaths,
+                         @Nullable String sourcePath,
                          long problemBeginOffset,
                          long problemEndOffset,
                          long problemLocationOffset,
@@ -69,34 +61,11 @@ public class CompilerMessage extends BuildMessage {
     myProblemBeginOffset = problemBeginOffset;
     myProblemEndOffset = problemEndOffset;
     myProblemLocationOffset = problemLocationOffset;
-    mySourcePaths = ContainerUtil.map(sourcePaths, new Function<String, String>() {
-      @Override
-      public String fun(String s) {
-        return s.replace(File.separatorChar, '/');
-      }
-    });
+    mySourcePath = sourcePath != null && !sourcePath.isEmpty()? sourcePath.replace(File.separatorChar, '/') : null;
     myLine = locationLine;
     myColumn = locationColumn;
   }
 
-  public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText,
-                         @Nullable String sourcePath,
-                         long problemBeginOffset,
-                         long problemEndOffset,
-                         long problemLocationOffset,
-                         long locationLine,
-                         long locationColumn) {
-    this(compilerName,
-         kind,
-         messageText,
-         sourcePath == null ? Collections.<String>emptyList() : Collections.singleton(sourcePath),
-         problemBeginOffset,
-         problemEndOffset,
-         problemLocationOffset,
-         locationLine,
-         locationColumn);
-  }
-
   @NotNull
   public String getCompilerName() {
     return myCompilerName;
@@ -104,7 +73,7 @@ public class CompilerMessage extends BuildMessage {
 
   @Nullable
   public String getSourcePath() {
-    return mySourcePaths.size() == 1 ? ContainerUtil.getFirstItem(mySourcePaths) : null;
+    return mySourcePath;
   }
 
   public long getLine() {
@@ -130,16 +99,7 @@ public class CompilerMessage extends BuildMessage {
   public String toString() {
     final StringBuilder builder = new StringBuilder();
     builder.append(getCompilerName()).append(":").append(getKind().name()).append(":").append(super.toString());
-    String result;
-    if (mySourcePaths.isEmpty()) {
-      result = null;
-    }
-    else if (mySourcePaths.size() == 1) {
-      result = ContainerUtil.getFirstItem(mySourcePaths);
-    } else {
-      result = mySourcePaths.toString();
-    }
-    final String path = result;
+    final String path = getSourcePath();
     if (path != null) {
       builder.append("; file: ").append(path);
       final long line = getLine();