Lazy values unified in the project
This commit is contained in:
+6
-5
@@ -23,8 +23,6 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
@@ -32,7 +30,9 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValueImpl;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -198,9 +198,10 @@ public abstract class AbstractLazyTypeParameterDescriptor implements TypeParamet
|
||||
|
||||
@NotNull
|
||||
private JetType createDefaultType() {
|
||||
return new JetTypeImpl(getTypeConstructor(), new LazyScopeAdapter(new RecursionIntolerantLazyValue<JetScope>() {
|
||||
return new JetTypeImpl(getTypeConstructor(), new LazyScopeAdapter(new NotNullLazyValueImpl<JetScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope compute() {
|
||||
protected JetScope doCompute() {
|
||||
return getUpperBoundsAsType().getMemberScope();
|
||||
}
|
||||
}));
|
||||
|
||||
+4
-3
@@ -30,7 +30,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValueImpl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -222,9 +222,10 @@ public class TypeParameterDescriptorImpl extends DeclarationDescriptorNonRootImp
|
||||
getTypeConstructor(),
|
||||
TypeUtils.hasNullableLowerBound(this),
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
new LazyScopeAdapter(new RecursionIntolerantLazyValue<JetScope>() {
|
||||
new LazyScopeAdapter(new NotNullLazyValueImpl<JetScope>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope compute() {
|
||||
protected JetScope doCompute() {
|
||||
return getUpperBoundsAsType().getMemberScope();
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -17,19 +17,19 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
|
||||
public class LazyScopeAdapter extends AbstractScopeAdapter {
|
||||
|
||||
private final RecursionIntolerantLazyValue<JetScope> scope;
|
||||
private final NotNullLazyValue<JetScope> scope;
|
||||
|
||||
public LazyScopeAdapter(RecursionIntolerantLazyValue<JetScope> scope) {
|
||||
public LazyScopeAdapter(NotNullLazyValue<JetScope> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getWorkerScope() {
|
||||
return scope.get();
|
||||
return scope.compute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.utils;
|
||||
|
||||
public abstract class RecursionIntolerantLazyValue<T> {
|
||||
|
||||
private enum State {
|
||||
NOT_COMPUTED,
|
||||
BEING_COMPUTED,
|
||||
COMPUTED,
|
||||
ERROR
|
||||
}
|
||||
|
||||
private State state = State.NOT_COMPUTED;
|
||||
private T value;
|
||||
|
||||
protected abstract T compute();
|
||||
|
||||
protected T getValueOnErrorReentry() {
|
||||
throw new ReenteringLazyValueComputationException();
|
||||
}
|
||||
|
||||
public boolean isComputed() {
|
||||
return state == State.ERROR || state == State.COMPUTED;
|
||||
}
|
||||
|
||||
public final T get() {
|
||||
switch (state) {
|
||||
case NOT_COMPUTED:
|
||||
state = State.BEING_COMPUTED;
|
||||
value = compute();
|
||||
state = State.COMPUTED;
|
||||
return value;
|
||||
case BEING_COMPUTED:
|
||||
state = State.ERROR;
|
||||
throw new ReenteringLazyValueComputationException();
|
||||
case COMPUTED:
|
||||
return value;
|
||||
case ERROR:
|
||||
return getValueOnErrorReentry();
|
||||
}
|
||||
throw new IllegalStateException("Unreachable");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user