*/
package org.jetbrains.jps.incremental;
+import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.util.Function;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
/**
* @author Eugene Zhuravlev
* Date: 11/18/12
*/
public class CompiledClass extends UserDataHolderBase{
+ private final static Logger LOG = Logger.getInstance(CompiledClass.class);
+
@NotNull
private final File myOutputFile;
@NotNull
- private final File mySourceFile;
+ private final Collection<File> mySourceFiles;
@Nullable
private final String myClassName;
@NotNull
private boolean myIsDirty = false;
- public CompiledClass(@NotNull File outputFile, @NotNull File sourceFile, @Nullable String className, @NotNull BinaryContent content) {
+ public CompiledClass(@NotNull File outputFile, @NotNull Collection<File> sourceFiles, @Nullable String className, @NotNull BinaryContent content) {
myOutputFile = outputFile;
- mySourceFile = sourceFile;
+ mySourceFiles = sourceFiles;
myClassName = className;
myContent = content;
+ LOG.assertTrue(!mySourceFiles.isEmpty());
+ }
+
+ public CompiledClass(@NotNull File outputFile, @NotNull File sourceFile, @Nullable String className, @NotNull BinaryContent content) {
+ this(outputFile, Collections.singleton(sourceFile), className, content);
}
public void save() throws IOException {
return myOutputFile;
}
+ @NotNull
+ public Collection<File> getSourceFiles() {
+ return mySourceFiles;
+ }
+
+ @NotNull
+ public Collection<String> getSourceFilesPaths() {
+ return ContainerUtil.map(mySourceFiles, new Function<File, String>() {
+ @Override
+ public String fun(File file) {
+ return file.getPath();
+ }
+ });
+ }
+
+ /**
+ * @deprecated use {@link CompiledClass#getSourceFiles()} or {{@link CompiledClass#getSourceFilesPaths()}
+ */
+ @Deprecated
@NotNull
public File getSourceFile() {
- return mySourceFile;
+ //noinspection ConstantConditions
+ return ContainerUtil.getFirstItem(getSourceFiles());
}
@Nullable
public String toString() {
return "CompiledClass{" +
"myOutputFile=" + myOutputFile +
- ", mySourceFile=" + mySourceFile +
+ ", mySourceFiles=" + mySourceFiles +
", myIsDirty=" + myIsDirty +
'}';
}
import com.intellij.compiler.instrumentation.InstrumentationClassFinder;
import com.intellij.compiler.notNullVerification.NotNullVerifyingInstrumenter;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.util.Function;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.org.objectweb.asm.Opcodes;
import java.io.File;
+import java.util.Collection;
/**
* @author Eugene Zhuravlev
}
catch (Throwable e) {
LOG.error(e);
- final File sourceFile = compiledClass.getSourceFile();
- String msg = "Cannot instrument " + sourceFile.getName() + ": " + e.getMessage();
- context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, msg, sourceFile.getPath()));
+ final Collection<File> sourceFiles = compiledClass.getSourceFiles();
+ String msg = "Cannot instrument " + ContainerUtil.map(sourceFiles, new Function<File, String>() {
+ @Override
+ public String fun(File file) {
+ return file.getName();
+ }
+ }) + ": " + e.getMessage();
+ context.processMessage(new CompilerMessage(getPresentableName(),
+ msg,
+ compiledClass.getSourceFilesPaths(),
+ BuildMessage.Kind.ERROR));
}
return null;
}
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
private final long myProblemBeginOffset;
private final long myProblemEndOffset;
private final long myProblemLocationOffset;
- private final String mySourcePath;
+ private final Collection<String> mySourcePaths;
private final long myLine;
private final long myColumn;
public CompilerMessage(@NotNull String compilerName, @NotNull Throwable internalError) {
- this(compilerName, Kind.ERROR, getTextFromThrowable(internalError), null, -1L, -1L, -1L, -1L, -1L);
+ this(compilerName, Kind.ERROR, getTextFromThrowable(internalError));
}
public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText) {
- this(compilerName, kind, messageText, null, -1L, -1L, -1L, -1L, -1L);
+ 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);
}
public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText, String sourcePath) {
- this(compilerName, kind, messageText, sourcePath, -1L, -1L, -1L, -1L, -1L);
+ this(compilerName, messageText, Collections.singleton(sourcePath), kind);
}
public CompilerMessage(@NotNull String compilerName, Kind kind, String messageText,
- @Nullable String sourcePath,
+ @NotNull Collection<String> sourcePaths,
long problemBeginOffset,
long problemEndOffset,
long problemLocationOffset,
myProblemBeginOffset = problemBeginOffset;
myProblemEndOffset = problemEndOffset;
myProblemLocationOffset = problemLocationOffset;
- mySourcePath = sourcePath != null && !sourcePath.isEmpty()? sourcePath.replace(File.separatorChar, '/') : null;
+ mySourcePaths = ContainerUtil.map(sourcePaths, new Function<String, String>() {
+ @Override
+ public String fun(String s) {
+ return s.replace(File.separatorChar, '/');
+ }
+ });
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;
@Nullable
public String getSourcePath() {
- return mySourcePath;
+ if (mySourcePaths.isEmpty()) {
+ return null;
+ }
+ else if (mySourcePaths.size() == 1) {
+ return ContainerUtil.getFirstItem(mySourcePaths);
+ } else {
+ return mySourcePaths.toString();
+ }
}
public long getLine() {
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getCompilerName()).append(":").append(getKind().name()).append(":").append(super.toString());
- final String path = getSourcePath();
+ String result;
+ if (mySourcePaths.isEmpty()) {
+ result = null;
+ }
+ else if (mySourcePaths.size() == 1) {
+ result = ContainerUtil.getFirstItem(mySourcePaths);
+ } else {
+ result = mySourcePaths.toString();
+ }
+ final String path = result;
if (path != null) {
builder.append("; file: ").append(path);
final long line = getLine();