diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java index 9c19d8ec9dd..106db7a7fff 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java @@ -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; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/RawTypesCheck.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/RawTypesCheck.java new file mode 100644 index 00000000000..a97b238718c --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/RawTypesCheck.java @@ -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() { + @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() { + } +} diff --git a/compiler/testData/loadJavaCustom/subclassWithRawType/SubclassWithRawType.java b/compiler/testData/loadJavaCustom/subclassWithRawType/SubclassWithRawType.java new file mode 100644 index 00000000000..47a2b948d40 --- /dev/null +++ b/compiler/testData/loadJavaCustom/subclassWithRawType/SubclassWithRawType.java @@ -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 simple3(); + + List boundWildcard1(); + List> boundWildcard2(); + + List wildcard(); + + List[] array1(); + List[] array2(); + } + + interface Sub extends Super { + List simple1(); + List> simple2(); + List simple3(); + + List> boundWildcard1(); + List boundWildcard2(); + + List wildcard(); + + List[] array1(); + List[] array2(); + } +} diff --git a/compiler/testData/loadJavaCustom/subclassWithRawType/SubclassWithRawType.txt b/compiler/testData/loadJavaCustom/subclassWithRawType/SubclassWithRawType.txt new file mode 100644 index 00000000000..d8e2d55881a --- /dev/null +++ b/compiler/testData/loadJavaCustom/subclassWithRawType/SubclassWithRawType.txt @@ -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?>? + public abstract override /*1*/ fun array2(): jet.Array?>? + public abstract override /*1*/ fun boundWildcard1(): jet.MutableList?>? + public abstract override /*1*/ fun boundWildcard2(): jet.MutableList?>? + public abstract override /*1*/ fun simple1(): jet.MutableList? + public abstract override /*1*/ fun simple2(): jet.MutableList?>? + public abstract override /*1*/ fun simple3(): jet.MutableList? + public abstract override /*1*/ fun wildcard(): jet.MutableList? + } + public abstract trait test.SubclassWithRawType.Super : java.lang.Object { + public abstract fun array1(): jet.Array?>? + public abstract fun array2(): jet.Array?>? + public abstract fun boundWildcard1(): jet.MutableList?>? + public abstract fun boundWildcard2(): jet.MutableList?>? + public abstract fun simple1(): jet.MutableList? + public abstract fun simple2(): jet.MutableList? + public abstract fun simple3(): jet.MutableList? + public abstract fun wildcard(): jet.MutableList? + } +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaCustomTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaCustomTest.java index bf3ee22ffc7..233ed327c02 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaCustomTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaCustomTest.java @@ -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() {