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