Report ABI errors on KotlinClass, not VirtualFile

This commit is contained in:
Alexander Udalov
2013-10-01 22:58:40 +04:00
parent 1afd0504fa
commit f68a702e8f
6 changed files with 17 additions and 43 deletions
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
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 org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass;
import java.util.Collection;
import java.util.List;
@@ -139,15 +140,16 @@ public final class AnalyzerWithCompilerReport {
assert analyzeExhaust != null;
BindingContext bindingContext = analyzeExhaust.getBindingContext();
Collection<TraceBasedErrorReporter.AbiVersionErrorLocation> errorLocations =
bindingContext.getKeys(TraceBasedErrorReporter.ABI_VERSION_ERRORS);
for (TraceBasedErrorReporter.AbiVersionErrorLocation abiVersionErrorLocation : errorLocations) {
Integer abiVersion = bindingContext.get(TraceBasedErrorReporter.ABI_VERSION_ERRORS, abiVersionErrorLocation);
Collection<VirtualFileKotlinClass> errorClasses = bindingContext.getKeys(TraceBasedErrorReporter.ABI_VERSION_ERRORS);
for (VirtualFileKotlinClass kotlinClass : errorClasses) {
Integer abiVersion = bindingContext.get(TraceBasedErrorReporter.ABI_VERSION_ERRORS, kotlinClass);
String fqName = kotlinClass.getClassName().getFqName().asString();
String path = toSystemDependentName(kotlinClass.getFile().getPath());
messageCollectorWrapper.report(CompilerMessageSeverity.ERROR,
"Class '" + abiVersionErrorLocation.getClassFqName().asString() +
"Class '" + fqName +
"' was compiled with an incompatible version of Kotlin. " +
"Its ABI version is " + abiVersion + ", expected ABI version is " + JvmAbi.VERSION,
CompilerMessageLocation.create(toSystemDependentName(abiVersionErrorLocation.getPath()), 0, 0));
CompilerMessageLocation.create(path, 0, 0));
}
}
@@ -16,14 +16,14 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass;
import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
import org.jetbrains.jet.util.slicedmap.Slices;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
@@ -33,8 +33,8 @@ import javax.inject.Inject;
import static org.jetbrains.jet.lang.diagnostics.Errors.CANNOT_INFER_VISIBILITY;
public class TraceBasedErrorReporter implements ErrorReporter {
public static final WritableSlice<AbiVersionErrorLocation, Integer> ABI_VERSION_ERRORS =
new BasicWritableSlice<AbiVersionErrorLocation, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
public static final WritableSlice<VirtualFileKotlinClass, Integer> ABI_VERSION_ERRORS =
new BasicWritableSlice<VirtualFileKotlinClass, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
private BindingTrace trace;
@Inject
@@ -43,8 +43,8 @@ public class TraceBasedErrorReporter implements ErrorReporter {
}
@Override
public void reportIncompatibleAbiVersion(@NotNull FqName fqName, @NotNull VirtualFile file, int actualVersion) {
trace.record(ABI_VERSION_ERRORS, new AbiVersionErrorLocation(fqName, file), actualVersion);
public void reportIncompatibleAbiVersion(@NotNull KotlinJvmBinaryClass kotlinClass, int actualVersion) {
trace.record(ABI_VERSION_ERRORS, (VirtualFileKotlinClass) kotlinClass, actualVersion);
}
@Override
@@ -54,26 +54,4 @@ public class TraceBasedErrorReporter implements ErrorReporter {
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
}
}
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();
}
}
}
@@ -41,7 +41,6 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
}
@NotNull
@Override
public VirtualFile getFile() {
return file;
}
@@ -16,13 +16,12 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
public interface ErrorReporter {
void reportIncompatibleAbiVersion(@NotNull FqName fqName, @NotNull VirtualFile file, int actualVersion);
void reportIncompatibleAbiVersion(@NotNull KotlinJvmBinaryClass kotlinClass, int actualVersion);
void reportCannotInferVisibility(@NotNull CallableMemberDescriptor descriptor);
}
@@ -116,7 +116,7 @@ public final class DeserializedDescriptorResolver {
}
if (header != null) {
errorReporter.reportIncompatibleAbiVersion(kotlinClass.getClassName().getFqName(), kotlinClass.getFile(), header.getVersion());
errorReporter.reportIncompatibleAbiVersion(kotlinClass, header.getVersion());
}
return null;
@@ -16,16 +16,12 @@
package org.jetbrains.jet.lang.resolve.kotlin;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.Name;
public interface KotlinJvmBinaryClass {
@NotNull
VirtualFile getFile();
@NotNull
JvmClassName getClassName();