TraceBasedErrorReporter converted to Kotlin and [data] added to AbiVersionErrorData

This commit is contained in:
Andrey Breslav
2015-03-06 18:42:09 +03:00
parent 3146b7e1b0
commit 704eea2eac
2 changed files with 36 additions and 63 deletions
@@ -153,9 +153,9 @@ public final class AnalyzerWithCompilerReport {
assert data != null; assert data != null;
String path = toSystemDependentName(kotlinClass); String path = toSystemDependentName(kotlinClass);
messageCollectorWrapper.report(CompilerMessageSeverity.ERROR, messageCollectorWrapper.report(CompilerMessageSeverity.ERROR,
"Class '" + JvmClassName.byClassId(data.classId) + "Class '" + JvmClassName.byClassId(data.getClassId()) +
"' was compiled with an incompatible version of Kotlin. " + "' was compiled with an incompatible version of Kotlin. " +
"Its ABI version is " + data.actualVersion + ", expected ABI version is " + JvmAbi.VERSION, "Its ABI version is " + data.getActualVersion() + ", expected ABI version is " + JvmAbi.VERSION,
CompilerMessageLocation.create(path, 0, 0)); CompilerMessageLocation.create(path, 0, 0));
} }
} }
@@ -14,83 +14,56 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.load.java.components; package org.jetbrains.kotlin.load.java.components
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor; import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.name.ClassId; import org.jetbrains.kotlin.resolve.OverrideResolver
import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
import org.jetbrains.kotlin.resolve.OverrideResolver; import org.jetbrains.kotlin.util.slicedMap.Slices
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter; import org.jetbrains.kotlin.util.slicedMap.WritableSlice
import org.jetbrains.kotlin.util.slicedMap.Slices;
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
import javax.inject.Inject; import javax.inject.Inject
import java.util.List;
public class TraceBasedErrorReporter implements ErrorReporter { public class TraceBasedErrorReporter : ErrorReporter {
private static final Logger LOG = Logger.getInstance(TraceBasedErrorReporter.class);
public static class AbiVersionErrorData { class object {
public final int actualVersion; private val LOG = Logger.getInstance(javaClass<TraceBasedErrorReporter>())
public final ClassId classId;
public AbiVersionErrorData(int actualVersion, @NotNull ClassId classId) { public val ABI_VERSION_ERRORS: WritableSlice<String, AbiVersionErrorData> = Slices.createCollectiveSlice()
this.actualVersion = actualVersion; // TODO: MutableList is a workaround for KT-5792 Covariant types in Kotlin translated to wildcard types in Java
this.classId = classId; public val INCOMPLETE_HIERARCHY: WritableSlice<ClassDescriptor, MutableList<String>> = Slices.createCollectiveSlice()
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbiVersionErrorData data = (AbiVersionErrorData) o;
if (actualVersion != data.actualVersion) return false;
if (!classId.equals(data.classId)) return false;
return true;
}
@Override
public int hashCode() {
int result = actualVersion;
result = 31 * result + classId.hashCode();
return result;
}
} }
public static final WritableSlice<String, AbiVersionErrorData> ABI_VERSION_ERRORS = Slices.createCollectiveSlice(); public data class AbiVersionErrorData(
public static final WritableSlice<ClassDescriptor, List<String>> INCOMPLETE_HIERARCHY = Slices.createCollectiveSlice(); public val actualVersion: Int,
public val classId: ClassId
)
private BindingTrace trace; private var trace: BindingTrace? = null
@Inject Inject
public void setTrace(BindingTrace trace) { public fun setTrace(trace: BindingTrace) {
this.trace = trace; this.trace = trace
} }
@Override override fun reportIncompatibleAbiVersion(classId: ClassId, filePath: String, actualVersion: Int) {
public void reportIncompatibleAbiVersion(@NotNull ClassId classId, @NotNull String filePath, int actualVersion) { trace!!.record(ABI_VERSION_ERRORS, filePath, AbiVersionErrorData(actualVersion, classId))
trace.record(ABI_VERSION_ERRORS, filePath, new AbiVersionErrorData(actualVersion, classId));
} }
@Override override fun reportIncompleteHierarchy(descriptor: ClassDescriptor, unresolvedSuperClasses: List<String>) {
public void reportIncompleteHierarchy(@NotNull ClassDescriptor descriptor, @NotNull List<String> unresolvedSuperClasses) { // TODO: MutableList is a workaround for KT-5792 Covariant types in Kotlin translated to wildcard types in Java
trace.record(INCOMPLETE_HIERARCHY, descriptor, unresolvedSuperClasses); trace!!.record(INCOMPLETE_HIERARCHY, descriptor, unresolvedSuperClasses as MutableList)
} }
@Override override fun reportCannotInferVisibility(descriptor: CallableMemberDescriptor) {
public void reportCannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) { OverrideResolver.createCannotInferVisibilityReporter(trace!!).invoke(descriptor)
OverrideResolver.createCannotInferVisibilityReporter(trace).invoke(descriptor);
} }
@Override override fun reportLoadingError(message: String, exception: Exception?) {
public void reportLoadingError(@NotNull String message, @Nullable Exception exception) { LOG.error(message, exception)
LOG.error(message, exception);
} }
} }