JavaDescriptorResolver: resolve constructors lazily
This speeds up analyze a bit (profiler shown about 10% of time spent in constructor resolver during completion in KDoc).
This commit is contained in:
+18
-2
@@ -38,6 +38,7 @@ import java.util.Set;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class MutableClassDescriptor extends MutableClassDescriptorLite implements ClassDescriptorFromSource {
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
|
||||
private final Set<CallableMemberDescriptor> declaredCallableMembers = Sets.newHashSet();
|
||||
@@ -72,9 +73,15 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Override
|
||||
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor, @NotNull BindingTrace trace) {
|
||||
super.addConstructor(constructorDescriptor, trace);
|
||||
if (constructorDescriptor.getContainingDeclaration() != this) {
|
||||
throw new IllegalStateException("invalid containing declaration of constructor");
|
||||
}
|
||||
constructors.add(constructorDescriptor);
|
||||
if (defaultType != null) {
|
||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
|
||||
if (constructorDescriptor.isPrimary()) {
|
||||
setUpScopeForInitializers(constructorDescriptor);
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : constructorDescriptor.getValueParameters()) {
|
||||
@@ -93,6 +100,12 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
addConstructor(constructorDescriptor, trace);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
@@ -141,6 +154,9 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
@Override
|
||||
public void createTypeConstructor() {
|
||||
super.createTypeConstructor();
|
||||
for (FunctionDescriptor functionDescriptor : getConstructors()) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
scopeForMemberResolution.setImplicitReceiver(new ClassReceiver(this));
|
||||
}
|
||||
|
||||
|
||||
+1
-19
@@ -36,9 +36,8 @@ import java.util.*;
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class MutableClassDescriptorLite extends ClassDescriptorBase
|
||||
public abstract class MutableClassDescriptorLite extends ClassDescriptorBase
|
||||
implements WithDeferredResolve {
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
|
||||
private List<AnnotationDescriptor> annotations = Lists.newArrayList();
|
||||
|
||||
@@ -134,9 +133,6 @@ public class MutableClassDescriptorLite extends ClassDescriptorBase
|
||||
getName().getName(),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
for (FunctionDescriptor functionDescriptor : constructors) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
}
|
||||
|
||||
private WritableScope getScopeForMemberLookupAsWritableScope() {
|
||||
@@ -145,12 +141,6 @@ public class MutableClassDescriptorLite extends ClassDescriptorBase
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberLookup() {
|
||||
return scopeForMemberLookup;
|
||||
@@ -205,14 +195,6 @@ public class MutableClassDescriptorLite extends ClassDescriptorBase
|
||||
}
|
||||
|
||||
|
||||
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor, @Nullable BindingTrace trace) {
|
||||
assert constructorDescriptor.getContainingDeclaration() == this;
|
||||
constructors.add(constructorDescriptor);
|
||||
if (defaultType != null) {
|
||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MutableClassDescriptorLite getClassObjectDescriptor() {
|
||||
|
||||
Reference in New Issue
Block a user