diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt new file mode 100644 index 00000000000..3aa8ecbea74 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorType.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2017 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.kotlin.types + +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.resolve.scopes.MemberScope + +class ErrorType @JvmOverloads internal constructor( + override val constructor: TypeConstructor, + override val memberScope: MemberScope, + override val arguments: List = emptyList(), + override val isMarkedNullable: Boolean = false +) : SimpleType() { + override val annotations: Annotations + get() = Annotations.EMPTY + + override fun toString(): String = + constructor.toString() + if (arguments.isEmpty()) "" else arguments.joinToString(", ", "<", ">", -1, "...", null) + + override fun replaceAnnotations(newAnnotations: Annotations): SimpleType = this + + override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = + ErrorType(constructor, memberScope, arguments, newNullability) +} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index 2884cce37f3..e69b38bcf43 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -43,7 +43,6 @@ import java.util.Set; import static java.util.Collections.emptySet; import static kotlin.collections.CollectionsKt.emptyList; -import static kotlin.collections.CollectionsKt.joinToString; public class ErrorUtils { private static final ModuleDescriptor ERROR_MODULE; @@ -296,7 +295,7 @@ public class ErrorUtils { Visibilities.INTERNAL); MemberScope memberScope = createErrorScope(getName().asString()); errorConstructor.setReturnType( - new ErrorTypeImpl( + new ErrorType( createErrorTypeConstructorWithCustomDebugName("", this), memberScope ) @@ -404,12 +403,12 @@ public class ErrorUtils { @NotNull public static SimpleType createErrorTypeWithCustomConstructor(@NotNull String debugName, @NotNull TypeConstructor typeConstructor) { - return new ErrorTypeImpl(typeConstructor, createErrorScope(debugName)); + return new ErrorType(typeConstructor, createErrorScope(debugName)); } @NotNull public static SimpleType createErrorTypeWithArguments(@NotNull String debugMessage, @NotNull List arguments) { - return new ErrorTypeImpl(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments, false); + return new ErrorType(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments, false); } @NotNull @@ -486,76 +485,6 @@ public class ErrorUtils { return candidate instanceof ErrorClassDescriptor; } - public static class ErrorTypeImpl extends SimpleType { - private final TypeConstructor constructor; - private final MemberScope memberScope; - private final List arguments; - private final boolean nullability; - - private ErrorTypeImpl( - @NotNull TypeConstructor constructor, - @NotNull MemberScope memberScope, - @NotNull List arguments, - boolean nullability - ) { - this.constructor = constructor; - this.memberScope = memberScope; - this.arguments = arguments; - this.nullability = nullability; - } - - private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull MemberScope memberScope) { - this(constructor, memberScope, Collections.emptyList(), false); - } - - @NotNull - @Override - public TypeConstructor getConstructor() { - return constructor; - } - - @NotNull - @Override - public List getArguments() { - return arguments; - } - - @Override - public boolean isMarkedNullable() { - return nullability; - } - - @NotNull - @Override - public MemberScope getMemberScope() { - return memberScope; - } - - @NotNull - @Override - public Annotations getAnnotations() { - return Annotations.Companion.getEMPTY(); - } - - @NotNull - @Override - public String toString() { - return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null)); - } - - @NotNull - @Override - public SimpleType replaceAnnotations(@NotNull Annotations newAnnotations) { - return this; - } - - @NotNull - @Override - public SimpleType makeNullableAsSpecified(boolean newNullability) { - return new ErrorTypeImpl(constructor, memberScope, arguments, newNullability); - } - } - @NotNull public static ModuleDescriptor getErrorModule() { return ERROR_MODULE; diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt index 80c24760e2a..3e3b1ebaddb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt @@ -159,8 +159,7 @@ abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleTy } val KotlinType.isError: Boolean - get() { - val unwrapped = unwrap() - return unwrapped is ErrorUtils.ErrorTypeImpl || - (unwrapped is FlexibleType && unwrapped.delegate is ErrorUtils.ErrorTypeImpl) + get() = unwrap().let { unwrapped -> + unwrapped is ErrorType || + (unwrapped is FlexibleType && unwrapped.delegate is ErrorType) }