Minor, move ABI version error reporting

AbiVersionUtil will be used in descriptors.loader.java, so it cannot depend on
BindingTrace
This commit is contained in:
Alexander Udalov
2013-08-21 15:47:23 +04:00
parent a2e4029bb5
commit a17328f9d3
3 changed files with 33 additions and 39 deletions
@@ -35,9 +35,9 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
import org.jetbrains.jet.lang.resolve.java.JavaBindingContext;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedErrorReporter;
import java.util.Collection;
import java.util.List;
@@ -143,9 +143,10 @@ public final class AnalyzerWithCompilerReport {
assert analyzeExhaust != null;
BindingContext bindingContext = analyzeExhaust.getBindingContext();
Collection<AbiVersionUtil.AbiVersionErrorLocation> errorLocations = bindingContext.getKeys(AbiVersionUtil.ABI_VERSION_ERRORS);
for (AbiVersionUtil.AbiVersionErrorLocation abiVersionErrorLocation : errorLocations) {
Integer abiVersion = bindingContext.get(AbiVersionUtil.ABI_VERSION_ERRORS, abiVersionErrorLocation);
Collection<TraceBasedErrorReporter.AbiVersionErrorLocation> errorLocations =
bindingContext.getKeys(TraceBasedErrorReporter.ABI_VERSION_ERRORS);
for (TraceBasedErrorReporter.AbiVersionErrorLocation abiVersionErrorLocation : errorLocations) {
Integer abiVersion = bindingContext.get(TraceBasedErrorReporter.ABI_VERSION_ERRORS, abiVersionErrorLocation);
messageCollectorWrapper.report(CompilerMessageSeverity.ERROR,
"Class '" + abiVersionErrorLocation.getClassFqName().asString() +
"' was compiled with an incompatible version of Kotlin. " +
@@ -16,46 +16,13 @@
package org.jetbrains.jet.lang.resolve.java;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.java.resolver.ErrorReporter;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
import org.jetbrains.jet.util.slicedmap.Slices;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
public final class AbiVersionUtil {
public static final WritableSlice<AbiVersionErrorLocation, Integer> ABI_VERSION_ERRORS =
new BasicWritableSlice<AbiVersionErrorLocation, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
public static final int INVALID_VERSION = -1;
public static boolean isAbiVersionCompatible(int abiVersion) {
return abiVersion == JvmAbi.VERSION;
}
public static final class AbiVersionErrorLocation {
@NotNull
private final FqName classFqName;
@NotNull
private final VirtualFile file;
public AbiVersionErrorLocation(@NotNull FqName name, @NotNull VirtualFile file) {
this.classFqName = name;
this.file = file;
}
@NotNull
public FqName getClassFqName() {
return classFqName;
}
@NotNull
public String getPath() {
return file.getPath();
}
}
private AbiVersionUtil() {
}
}
@@ -19,12 +19,16 @@ package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
import org.jetbrains.jet.util.slicedmap.Slices;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import javax.inject.Inject;
public class TraceBasedErrorReporter implements ErrorReporter {
public static final WritableSlice<AbiVersionErrorLocation, Integer> ABI_VERSION_ERRORS =
new BasicWritableSlice<AbiVersionErrorLocation, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
private BindingTrace trace;
@Inject
@@ -34,6 +38,28 @@ public class TraceBasedErrorReporter implements ErrorReporter {
@Override
public void reportIncompatibleAbiVersion(@NotNull FqName fqName, @NotNull VirtualFile file, int actualVersion) {
trace.record(AbiVersionUtil.ABI_VERSION_ERRORS, new AbiVersionUtil.AbiVersionErrorLocation(fqName, file), actualVersion);
trace.record(ABI_VERSION_ERRORS, new AbiVersionErrorLocation(fqName, file), actualVersion);
}
public static final class AbiVersionErrorLocation {
@NotNull
private final FqName classFqName;
@NotNull
private final VirtualFile file;
public AbiVersionErrorLocation(@NotNull FqName name, @NotNull VirtualFile file) {
this.classFqName = name;
this.file = file;
}
@NotNull
public FqName getClassFqName() {
return classFqName;
}
@NotNull
public String getPath() {
return file.getPath();
}
}
}