Forced resolution of all contents enhanced
This commit is contained in:
committed by
Nikolay Krasko
parent
7c26271500
commit
783258d91a
@@ -16,30 +16,49 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ForceResolveUtil {
|
||||
private static final Logger LOG = Logger.getInstance(ForceResolveUtil.class);
|
||||
|
||||
private ForceResolveUtil() {}
|
||||
|
||||
public static void forceResolveAllContents(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof LazyEntity) {
|
||||
LazyEntity lazyEntity = (LazyEntity) descriptor;
|
||||
lazyEntity.forceResolveAllContents();
|
||||
}
|
||||
LOG.debug("descriptor: " + descriptor);
|
||||
doForceResolveAllContents(descriptor);
|
||||
LOG.debug("<<< " + descriptor);
|
||||
}
|
||||
|
||||
public static void forceResolveAllContents(@NotNull JetScope scope) {
|
||||
for (DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
|
||||
forceResolveAllContents(scope.getAllDescriptors());
|
||||
}
|
||||
|
||||
public static void forceResolveAllContents(@NotNull Iterable<? extends DeclarationDescriptor> descriptors) {
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
forceResolveAllContents(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public static void forceResolveAllContents(@NotNull Collection<JetType> types) {
|
||||
for (JetType type : types) {
|
||||
forceResolveAllContents(type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void forceResolveAllContents(@NotNull TypeConstructor typeConstructor) {
|
||||
LOG.debug("descriptor: " + typeConstructor);
|
||||
doForceResolveAllContents(typeConstructor);
|
||||
LOG.debug("<<< " + typeConstructor);
|
||||
}
|
||||
|
||||
public static void forceResolveAllContents(@NotNull Annotations annotations) {
|
||||
@@ -48,8 +67,17 @@ public class ForceResolveUtil {
|
||||
|
||||
private static void doForceResolveAllContents(Object object) {
|
||||
if (object instanceof LazyEntity) {
|
||||
LazyEntity lazyConstructor = (LazyEntity) object;
|
||||
lazyConstructor.forceResolveAllContents();
|
||||
LazyEntity lazyEntity = (LazyEntity) object;
|
||||
lazyEntity.forceResolveAllContents();
|
||||
}
|
||||
}
|
||||
|
||||
public static void forceResolveAllContents(@Nullable JetType type) {
|
||||
if (type == null) return;
|
||||
|
||||
forceResolveAllContents(type.getConstructor());
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
forceResolveAllContents(projection.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-5
@@ -84,6 +84,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
private final NotNullLazyValue<JetScope> scopeForMemberDeclarationResolution;
|
||||
private final NotNullLazyValue<JetScope> scopeForPropertyInitializerResolution;
|
||||
|
||||
private final NullableLazyValue<Void> forceResolveAllContents;
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -151,6 +153,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
return computeScopeForPropertyInitializerResolution();
|
||||
}
|
||||
});
|
||||
this.forceResolveAllContents = storageManager.createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
@Override
|
||||
public Void invoke() {
|
||||
doForceResolveAllContents();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -340,10 +349,19 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
|
||||
@Override
|
||||
public void forceResolveAllContents() {
|
||||
forceResolveAllContents.invoke();
|
||||
}
|
||||
|
||||
private void doForceResolveAllContents() {
|
||||
ForceResolveUtil.forceResolveAllContents(getAnnotations());
|
||||
getClassObjectDescriptor();
|
||||
|
||||
ClassDescriptor classObjectDescriptor = getClassObjectDescriptor();
|
||||
if (classObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(classObjectDescriptor);
|
||||
}
|
||||
|
||||
getClassObjectType();
|
||||
getConstructors();
|
||||
ForceResolveUtil.forceResolveAllContents(getConstructors());
|
||||
getContainingDeclaration();
|
||||
getThisAsReceiverParameter();
|
||||
getKind();
|
||||
@@ -401,7 +419,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
findAndDisconnectLoopsInTypeHierarchy(supertypes);
|
||||
return Unit.VALUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = resolveSession.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
@@ -418,6 +437,15 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
}
|
||||
});
|
||||
|
||||
private final NullableLazyValue<Void> forceResolveAllContents =
|
||||
resolveSession.getStorageManager().createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
@Override
|
||||
public Void invoke() {
|
||||
doForceResolveAllContents();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
@@ -481,9 +509,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
|
||||
@Override
|
||||
public void forceResolveAllContents() {
|
||||
forceResolveAllContents.invoke();
|
||||
}
|
||||
|
||||
private void doForceResolveAllContents() {
|
||||
ForceResolveUtil.forceResolveAllContents(getAnnotations());
|
||||
getSupertypes();
|
||||
getParameters();
|
||||
ForceResolveUtil.forceResolveAllContents(getSupertypes());
|
||||
ForceResolveUtil.forceResolveAllContents(getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -115,14 +115,14 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
@Override
|
||||
public void forceResolveAllContents() {
|
||||
ForceResolveUtil.forceResolveAllContents(getAnnotations());
|
||||
getClassObjectType();
|
||||
ForceResolveUtil.forceResolveAllContents(getClassObjectType());
|
||||
getContainingDeclaration();
|
||||
getDefaultType();
|
||||
getIndex();
|
||||
getLowerBounds();
|
||||
getLowerBoundsAsType();
|
||||
getOriginal();
|
||||
getTypeConstructor();
|
||||
ForceResolveUtil.forceResolveAllContents(getTypeConstructor());
|
||||
getUpperBounds();
|
||||
getUpperBoundsAsType();
|
||||
getVariance();
|
||||
|
||||
+11
-7
@@ -32,10 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.asJava.KotlinLightClassForExplicitDeclaration;
|
||||
import org.jetbrains.jet.asJava.LightClassConstructionContext;
|
||||
import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
@@ -132,14 +129,14 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
ClassDescriptor descriptor = session.getClassDescriptor((JetClassOrObject) declaration);
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor);
|
||||
forceResolveAllContents(descriptor);
|
||||
}
|
||||
else if (declaration instanceof JetFunction) {
|
||||
JetFunction jetFunction = (JetFunction) declaration;
|
||||
Name name = jetFunction.getNameAsSafeName();
|
||||
Collection<FunctionDescriptor> functions = packageDescriptor.getMemberScope().getFunctions(name);
|
||||
for (FunctionDescriptor descriptor : functions) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor);
|
||||
forceResolveAllContents(descriptor);
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof JetProperty) {
|
||||
@@ -147,7 +144,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
Name name = jetProperty.getNameAsSafeName();
|
||||
Collection<VariableDescriptor> properties = packageDescriptor.getMemberScope().getProperties(name);
|
||||
for (VariableDescriptor descriptor : properties) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor);
|
||||
forceResolveAllContents(descriptor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -157,6 +154,13 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
}
|
||||
}
|
||||
|
||||
private static void forceResolveAllContents(DeclarationDescriptor descriptor) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("done: " + descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LightClassConstructionContext analyzeRelevantCode(@NotNull JetClassOrObject classOrObject) {
|
||||
|
||||
Reference in New Issue
Block a user