diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaMethodImpl.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaMethodImpl.java index f3298b2e712..91927c71d3a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaMethodImpl.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaMethodImpl.java @@ -64,9 +64,10 @@ public class JavaMethodImpl extends JavaMemberImpl implements JavaMet } @Override - @Nullable + @NotNull public JavaType getReturnType() { PsiType psiType = getPsi().getReturnType(); - return psiType == null ? null : JavaTypeImpl.create(psiType); + assert psiType != null : "Method is not a constructor and has no return type: " + getName(); + return JavaTypeImpl.create(psiType); } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt index ff353cf30bf..0d915a9c960 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt @@ -31,14 +31,20 @@ import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext import org.jetbrains.kotlin.load.java.lazy.child import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations import org.jetbrains.kotlin.load.java.lazy.types.toAttributes -import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.load.java.structure.JavaArrayType +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaConstructor +import org.jetbrains.kotlin.load.java.structure.JavaMethod import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorFactory import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.TypeUtils -import org.jetbrains.kotlin.utils.* +import org.jetbrains.kotlin.utils.addIfNotNull +import org.jetbrains.kotlin.utils.emptyOrSingletonList +import org.jetbrains.kotlin.utils.ifEmpty +import org.jetbrains.kotlin.utils.valuesToMap import java.util.ArrayList import java.util.Collections import java.util.LinkedHashSet @@ -204,7 +210,7 @@ public class LazyJavaClassMemberScope( assert(methodsNamedValue.size() <= 1) { "There can't be more than one method named 'value' in annotation class: $jClass" } val methodNamedValue = methodsNamedValue.firstOrNull() if (methodNamedValue != null) { - val parameterNamedValueJavaType = methodNamedValue.getAnnotationMethodReturnJavaType() + val parameterNamedValueJavaType = methodNamedValue.getReturnType() val (parameterType, varargType) = if (parameterNamedValueJavaType is JavaArrayType) Pair(c.typeResolver.transformArrayType(parameterNamedValueJavaType, attr, isVararg = true), @@ -217,18 +223,13 @@ public class LazyJavaClassMemberScope( val startIndex = if (methodNamedValue != null) 1 else 0 for ((index, method) in otherMethods.withIndex()) { - val parameterType = c.typeResolver.transformJavaType(method.getAnnotationMethodReturnJavaType(), attr) + val parameterType = c.typeResolver.transformJavaType(method.getReturnType(), attr) result.addAnnotationValueParameter(constructor, index + startIndex, method, parameterType, null) } return result } - private fun JavaMethod.getAnnotationMethodReturnJavaType(): JavaType { - assert(getValueParameters().isEmpty()) { "Annotation method can't have parameters: $this" } - return getReturnType() ?: throw AssertionError("Annotation method has no return type: $this") - } - private fun MutableList.addAnnotationValueParameter( constructor: ConstructorDescriptor, index: Int, diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaMemberScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaMemberScope.kt index 556890a9074..536569cb0ae 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaMemberScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaMemberScope.kt @@ -153,9 +153,8 @@ public abstract class LazyJavaMemberScope( allowFlexible = !annotationMethod, isForAnnotationParameter = annotationMethod ) - val returnJavaType = method.getReturnType() ?: throw IllegalStateException("Constructor passed as method: $method") - // Annotation arguments are never null in Java - return c.typeResolver.transformJavaType(returnJavaType, returnTypeAttrs).let { + return c.typeResolver.transformJavaType(method.getReturnType(), returnTypeAttrs).let { + // Annotation arguments are never null in Java if (annotationMethod) TypeUtils.makeNotNullable(it) else it } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/JavaMethod.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/JavaMethod.java index 1511b7bbc2d..def254fe374 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/JavaMethod.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/structure/JavaMethod.java @@ -29,6 +29,6 @@ public interface JavaMethod extends JavaMember, JavaTypeParameterListOwner { boolean hasAnnotationParameterDefaultValue(); - @Nullable + @NotNull JavaType getReturnType(); }