Disabled error checking for if super/sub method has raw types in signature.

This commit is contained in:
Evgeny Gerashchenko
2012-12-10 17:19:31 +04:00
parent c8aa3d9290
commit 1dc928b5db
5 changed files with 182 additions and 8 deletions
@@ -18,9 +18,7 @@ package org.jetbrains.jet.lang.resolve.java.resolver;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiFormatUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -193,11 +191,13 @@ public final class JavaFunctionResolver {
throw new IllegalStateException("non-static method in subclass");
}
if (signatureErrors.isEmpty()) {
checkFunctionsOverrideCorrectly(method, superFunctions, functionDescriptorImpl);
}
else {
trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, functionDescriptorImpl, signatureErrors);
if (!RawTypesCheck.hasRawTypesInHierarchicalSignature(psiMethod)) {
if (signatureErrors.isEmpty()) {
checkFunctionsOverrideCorrectly(method, superFunctions, functionDescriptorImpl);
}
else {
trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, functionDescriptorImpl, signatureErrors);
}
}
return functionDescriptorImpl;
@@ -0,0 +1,108 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class RawTypesCheck {
private static boolean isPartiallyRawType(@NotNull PsiType type) {
return type.accept(new PsiTypeVisitor<Boolean>() {
@Nullable
@Override
public Boolean visitPrimitiveType(PsiPrimitiveType primitiveType) {
return false;
}
@Nullable
@Override
public Boolean visitClassType(PsiClassType classType) {
if (classType.isRaw()) {
return true;
}
for (PsiType argument : classType.getParameters()) {
if (argument.accept(this)) {
return true;
}
}
return false;
}
@Nullable
@Override
public Boolean visitArrayType(PsiArrayType arrayType) {
return arrayType.getComponentType().accept(this);
}
@Nullable
@Override
public Boolean visitWildcardType(PsiWildcardType wildcardType) {
PsiType bound = wildcardType.getBound();
return bound == null ? false : bound.accept(this);
}
@Nullable
@Override
public Boolean visitType(PsiType type) {
throw new IllegalStateException(type.getClass().getSimpleName() + " is unexpected");
}
});
}
private static boolean hasRawTypesInSignature(@NotNull PsiMethod method) {
PsiType returnType = method.getReturnType();
if (returnType != null && isPartiallyRawType(returnType)) {
return true;
}
for (PsiParameter parameter : method.getParameterList().getParameters()) {
if (isPartiallyRawType(parameter.getType())) {
return true;
}
}
for (PsiTypeParameter typeParameter : method.getTypeParameters()) {
for (PsiClassType upperBound : typeParameter.getExtendsList().getReferencedTypes()) {
if (isPartiallyRawType(upperBound)) {
return true;
}
}
}
return false;
}
static boolean hasRawTypesInHierarchicalSignature(@NotNull PsiMethod method) {
if (hasRawTypesInSignature(method)) {
return true;
}
for (HierarchicalMethodSignature superSignature : method.getHierarchicalMethodSignature().getSuperSignatures()) {
if (hasRawTypesInSignature(superSignature.getMethod())) {
return true;
}
}
return false;
}
private RawTypesCheck() {
}
}
@@ -0,0 +1,36 @@
package test;
import java.io.Serializable;
import java.lang.Comparable;
import java.lang.Runnable;
import java.util.List;
public interface SubclassWithRawType {
interface Super {
List simple1();
List simple2();
List<String> simple3();
List<? extends List> boundWildcard1();
List<? super List<String>> boundWildcard2();
List<?> wildcard();
List[] array1();
List<String>[] array2();
}
interface Sub extends Super {
List<String> simple1();
List<List<String>> simple2();
List simple3();
List<? extends List<String>> boundWildcard1();
List<? super List> boundWildcard2();
List wildcard();
List<String>[] array1();
List[] array2();
}
}
@@ -0,0 +1,24 @@
namespace test
public abstract trait test.SubclassWithRawType : java.lang.Object {
public abstract trait test.SubclassWithRawType.Sub : test.SubclassWithRawType.Super {
public abstract override /*1*/ fun array1(): jet.Array<jet.List<jet.String?>?>?
public abstract override /*1*/ fun array2(): jet.Array<jet.List<jet.Any?>?>?
public abstract override /*1*/ fun boundWildcard1(): jet.MutableList<out jet.List<jet.String?>?>?
public abstract override /*1*/ fun boundWildcard2(): jet.MutableList<in jet.List<jet.Any?>?>?
public abstract override /*1*/ fun simple1(): jet.MutableList<out jet.String?>?
public abstract override /*1*/ fun simple2(): jet.MutableList<out jet.List<jet.String?>?>?
public abstract override /*1*/ fun simple3(): jet.MutableList<out jet.Any?>?
public abstract override /*1*/ fun wildcard(): jet.MutableList<out jet.Any?>?
}
public abstract trait test.SubclassWithRawType.Super : java.lang.Object {
public abstract fun array1(): jet.Array<jet.List<jet.Any?>?>?
public abstract fun array2(): jet.Array<jet.List<jet.String?>?>?
public abstract fun boundWildcard1(): jet.MutableList<out jet.List<jet.Any?>?>?
public abstract fun boundWildcard2(): jet.MutableList<in jet.List<jet.String?>?>?
public abstract fun simple1(): jet.MutableList<out jet.Any?>?
public abstract fun simple2(): jet.MutableList<out jet.Any?>?
public abstract fun simple3(): jet.MutableList<jet.String?>?
public abstract fun wildcard(): jet.MutableList<out jet.Any?>?
}
}
@@ -135,6 +135,12 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
dir + "RawSuperType.java");
}
public void testSubclassWithRawType() throws Exception {
String dir = PATH + "/subclassWithRawType/";
doTest(dir + "SubclassWithRawType.txt",
dir + "SubclassWithRawType.java");
}
public static class SubclassingKotlinInJavaTest extends KotlinTestWithEnvironment {
@Override
protected JetCoreEnvironment createEnvironment() {