DelegatingType extracted

This commit is contained in:
Andrey Breslav
2014-02-26 15:08:49 +04:00
parent a3075f90db
commit 131d6ddd3d
6 changed files with 85 additions and 57 deletions
@@ -653,7 +653,7 @@ public class BodyResolver {
if (type instanceof DeferredType) { if (type instanceof DeferredType) {
DeferredType deferredType = (DeferredType) type; DeferredType deferredType = (DeferredType) type;
if (!deferredType.isComputed()) { if (!deferredType.isComputed()) {
deferredType.getActualType(); deferredType.getDelegate();
} }
} }
} }
@@ -676,7 +676,7 @@ public class BodyResolver {
DeferredType deferredType = queue.pullFirst(); DeferredType deferredType = queue.pullFirst();
if (!deferredType.isComputed()) { if (!deferredType.isComputed()) {
try { try {
deferredType.getActualType(); // to compute deferredType.getDelegate(); // to compute
} }
catch (ReenteringLazyValueComputationException e) { catch (ReenteringLazyValueComputationException e) {
// A problem should be reported while computing the type // A problem should be reported while computing the type
@@ -198,7 +198,7 @@ public class DeclarationsChecker {
if (propertyDescriptor.getModality() == Modality.ABSTRACT) { if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
JetType returnType = propertyDescriptor.getReturnType(); JetType returnType = propertyDescriptor.getReturnType();
if (returnType instanceof DeferredType) { if (returnType instanceof DeferredType) {
returnType = ((DeferredType) returnType).getActualType(); returnType = ((DeferredType) returnType).getDelegate();
} }
JetExpression initializer = property.getInitializer(); JetExpression initializer = property.getInitializer();
@@ -19,19 +19,15 @@ package org.jetbrains.jet.lang.types;
import kotlin.Function0; import kotlin.Function0;
import kotlin.Function1; import kotlin.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.storage.NotNullLazyValue; import org.jetbrains.jet.storage.NotNullLazyValue;
import org.jetbrains.jet.storage.StorageManager; import org.jetbrains.jet.storage.StorageManager;
import org.jetbrains.jet.util.Box; import org.jetbrains.jet.util.Box;
import org.jetbrains.jet.util.ReenteringLazyValueComputationException; import org.jetbrains.jet.util.ReenteringLazyValueComputationException;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE; import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE;
public class DeferredType implements LazyType { public class DeferredType extends DelegatingType implements LazyType {
private static final Function1 EMPTY_CONSUMER = new Function1<Object, Void>() { private static final Function1 EMPTY_CONSUMER = new Function1<Object, Void>() {
@Override @Override
@@ -85,50 +81,16 @@ public class DeferredType implements LazyType {
return lazyValue.isComputed(); return lazyValue.isComputed();
} }
@NotNull @Override
public JetType getActualType() { public JetType getDelegate() {
return lazyValue.invoke(); return lazyValue.invoke();
} }
@Override
@NotNull
public JetScope getMemberScope() {
return getActualType().getMemberScope();
}
@Override
public boolean isError() {
return getActualType().isError();
}
@Override
@NotNull
public TypeConstructor getConstructor() {
return getActualType().getConstructor();
}
@Override
@NotNull
public List<TypeProjection> getArguments() {
return getActualType().getArguments();
}
@Override
public boolean isNullable() {
return getActualType().isNullable();
}
@NotNull
@Override
public Annotations getAnnotations() {
return getActualType().getAnnotations();
}
@Override @Override
public String toString() { public String toString() {
try { try {
if (lazyValue.isComputed()) { if (lazyValue.isComputed()) {
return getActualType().toString(); return getDelegate().toString();
} }
else { else {
return "<Not computed yet>"; return "<Not computed yet>";
@@ -138,14 +100,4 @@ public class DeferredType implements LazyType {
return "<Failed to compute this type>"; return "<Failed to compute this type>";
} }
} }
@Override
public boolean equals(Object obj) {
return getActualType().equals(obj);
}
@Override
public int hashCode() {
return getActualType().hashCode();
}
} }
@@ -131,7 +131,7 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
} }
if (result.getType() instanceof DeferredType) { if (result.getType() instanceof DeferredType) {
result = JetTypeInfo.create(((DeferredType) result.getType()).getActualType(), result.getDataFlowInfo()); result = JetTypeInfo.create(((DeferredType) result.getType()).getDelegate(), result.getDataFlowInfo());
} }
if (result.getType() != null) { if (result.getType() != null) {
context.trace.record(BindingContext.EXPRESSION_TYPE, expression, result.getType()); context.trace.record(BindingContext.EXPRESSION_TYPE, expression, result.getType());
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2014 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.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import java.util.List;
public abstract class DelegatingType implements JetType {
protected abstract JetType getDelegate();
@NotNull
@Override
public TypeConstructor getConstructor() {
return getDelegate().getConstructor();
}
@NotNull
@Override
public List<TypeProjection> getArguments() {
return getDelegate().getArguments();
}
@Override
public boolean isNullable() {
return getDelegate().isNullable();
}
@NotNull
@Override
public JetScope getMemberScope() {
return getDelegate().getMemberScope();
}
@Override
public boolean isError() {
return getDelegate().isError();
}
@NotNull
@Override
public Annotations getAnnotations() {
return getDelegate().getAnnotations();
}
@Override
public int hashCode() {
return getDelegate().hashCode();
}
@Override
public boolean equals(Object obj) {
return getDelegate().equals(obj);
}
@Override
public String toString() {
return getDelegate().toString();
}
}
@@ -64,7 +64,7 @@ public class QuickFixUtil {
if (!(descriptor instanceof CallableDescriptor)) return null; if (!(descriptor instanceof CallableDescriptor)) return null;
JetType type = ((CallableDescriptor) descriptor).getReturnType(); JetType type = ((CallableDescriptor) descriptor).getReturnType();
if (type instanceof DeferredType) { if (type instanceof DeferredType) {
type = ((DeferredType) type).getActualType(); type = ((DeferredType) type).getDelegate();
} }
return type; return type;
} }