Checking redundant projections in jdk annotations.

This commit is contained in:
Evgeny Gerashchenko
2013-02-01 14:29:25 +04:00
parent 4be1e7d8d8
commit 25dc5b5991
2 changed files with 27 additions and 3 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
@@ -39,7 +40,9 @@ import java.util.*;
import static org.jetbrains.jet.lang.resolve.java.TypeUsage.TYPE_ARGUMENT;
import static org.jetbrains.jet.lang.types.Variance.INVARIANT;
class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
private static boolean strictMode = false;
private final JetType originalType;
private final Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters;
@@ -179,7 +182,10 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
}
if (altProjectionKind != INVARIANT && parameter.getVariance() != INVARIANT) {
if (altProjectionKind == parameter.getVariance()) {
// TODO report redundant if in strict mode
if (strictMode) {
throw new AlternativeSignatureMismatchException("Projection kind '%s' is redundant",
altProjectionKind, DescriptorUtils.getFQName(typeConstructor.getDeclarationDescriptor()));
}
}
else {
throw new AlternativeSignatureMismatchException("Projection kind '%s' is conflicting with variance of %s",
@@ -232,4 +238,9 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
private static boolean isSameName(String qualifiedName, String fullyQualifiedName) {
return fullyQualifiedName.equals(qualifiedName) || fullyQualifiedName.endsWith("." + qualifiedName);
}
@TestOnly
public static void setStrictMode(boolean strictMode) {
TypeTransformingVisitor.strictMode = strictMode;
}
}
@@ -42,6 +42,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap;
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.TypeTransformingVisitor;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.renderer.DescriptorRenderer;
@@ -65,10 +66,22 @@ public class JdkAnnotationsValidityTest extends UsefulTestCase {
return new JetCoreEnvironment(parentDisposable, configuration);
}
@Override
protected void setUp() throws Exception {
super.setUp();
TypeTransformingVisitor.setStrictMode(true);
}
@Override
protected void tearDown() throws Exception {
TypeTransformingVisitor.setStrictMode(false);
super.tearDown();
}
public void testNoErrorsInAlternativeSignatures() {
List<FqName> affectedClasses = getAffectedClasses("file://jdk-annotations");
final Map<String, List<String>> errors = Maps.newHashMap();
final Map<String, List<String>> errors = Maps.newLinkedHashMap();
for (int chunkIndex = 0; chunkIndex < affectedClasses.size() / CLASSES_IN_CHUNK + 1; chunkIndex++) {
Disposable parentDisposable = CompileEnvironmentUtil.createMockDisposable();