Move ErrorUtils.ErrorTypeImpl to top level ErrorType and J2K

This commit is contained in:
Alexander Udalov
2017-04-24 18:34:13 +03:00
parent 38ea9986ab
commit f648f0235c
3 changed files with 44 additions and 78 deletions
@@ -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<TypeProjection> = 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)
}
@@ -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("<ERROR>", 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<TypeProjection> 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<TypeProjection> arguments;
private final boolean nullability;
private ErrorTypeImpl(
@NotNull TypeConstructor constructor,
@NotNull MemberScope memberScope,
@NotNull List<TypeProjection> 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.<TypeProjection>emptyList(), false);
}
@NotNull
@Override
public TypeConstructor getConstructor() {
return constructor;
}
@NotNull
@Override
public List<TypeProjection> 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;
@@ -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)
}