Move descriptors cache from NamedMembers to JavaBaseScope
2 tests failing
This commit is contained in:
-10
@@ -131,11 +131,6 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
||||
return propertiesResolver.resolveFieldGroupByName(name, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<VariableDescriptor> resolveFieldGroup(ResolverScopeData data) {
|
||||
return propertiesResolver.resolveFieldGroup(data);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ClassDescriptor resolveClass(@NotNull FqName name, @NotNull DescriptorSearchRule searchRule, @NotNull PostponedTasks tasks) {
|
||||
return classResolver.resolveClass(name, searchRule, tasks);
|
||||
@@ -166,11 +161,6 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
||||
return functionResolver.resolveFunctionGroup(methodName, scopeData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<FunctionDescriptor> resolveMethods(@NotNull ResolverScopeData scopeData) {
|
||||
return functionResolver.resolveMethods(scopeData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ClassDescriptor> resolveInnerClasses(DeclarationDescriptor owner, PsiClass psiClass, boolean staticMembers) {
|
||||
return innerClassResolver.resolveInnerClasses(owner, psiClass, staticMembers);
|
||||
|
||||
@@ -18,19 +18,12 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class NamedMembers {
|
||||
public final class NamedMembers {
|
||||
|
||||
public NamedMembers(@NotNull Name name) {
|
||||
this.name = name;
|
||||
@@ -45,11 +38,6 @@ public class NamedMembers {
|
||||
@NotNull
|
||||
private final List<PropertyAccessorData> propertyAccessors = Lists.newArrayList();
|
||||
|
||||
private Set<VariableDescriptor> propertyDescriptors;
|
||||
|
||||
/** Including from supertypes */
|
||||
private Set<FunctionDescriptor> functionDescriptors;
|
||||
|
||||
void addMethod(@NotNull PsiMethodWrapper method) {
|
||||
methods.add(method);
|
||||
}
|
||||
@@ -72,22 +60,4 @@ public class NamedMembers {
|
||||
public List<PropertyAccessorData> getPropertyAccessors() {
|
||||
return propertyAccessors;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<VariableDescriptor> getPropertyDescriptors() {
|
||||
return propertyDescriptors;
|
||||
}
|
||||
|
||||
public void setPropertyDescriptors(@NotNull Set<VariableDescriptor> propertyDescriptors) {
|
||||
this.propertyDescriptors = propertyDescriptors;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<FunctionDescriptor> getFunctionDescriptors() {
|
||||
return functionDescriptors;
|
||||
}
|
||||
|
||||
public void setFunctionDescriptors(@NotNull Set<FunctionDescriptor> functionDescriptors) {
|
||||
this.functionDescriptors = functionDescriptors;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-33
@@ -37,7 +37,10 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class JavaFunctionResolver {
|
||||
|
||||
@@ -165,14 +168,11 @@ public final class JavaFunctionResolver {
|
||||
return functionDescriptorImpl;
|
||||
}
|
||||
|
||||
private void resolveNamedGroupFunctions(
|
||||
@NotNull
|
||||
private Set<FunctionDescriptor> resolveNamedGroupFunctions(
|
||||
@NotNull ClassOrNamespaceDescriptor owner, @NotNull PsiClass psiClass,
|
||||
NamedMembers namedMembers, Name methodName, ResolverScopeData scopeData
|
||||
) {
|
||||
if (namedMembers.getFunctionDescriptors() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Set<FunctionDescriptor> functions = new HashSet<FunctionDescriptor>();
|
||||
|
||||
Set<SimpleFunctionDescriptor> functionsFromCurrent = Sets.newHashSet();
|
||||
@@ -216,7 +216,7 @@ public final class JavaFunctionResolver {
|
||||
}
|
||||
}
|
||||
|
||||
namedMembers.setFunctionDescriptors(functions);
|
||||
return functions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -224,22 +224,15 @@ public final class JavaFunctionResolver {
|
||||
MembersByNameCache namedMembersMap = scopeData.getMembersCache();
|
||||
|
||||
NamedMembers namedMembers = namedMembersMap.get(methodName);
|
||||
if (namedMembers != null) {
|
||||
|
||||
PsiClass psiClass = scopeData.getPsiClass();
|
||||
assert psiClass != null;
|
||||
resolveNamedGroupFunctions(scopeData.getClassOrNamespaceDescriptor(), psiClass, namedMembers,
|
||||
methodName, scopeData);
|
||||
|
||||
Set<FunctionDescriptor> result = namedMembers.getFunctionDescriptors();
|
||||
assert result != null;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
if (namedMembers == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
PsiClass psiClass = scopeData.getPsiClass();
|
||||
assert psiClass != null;
|
||||
return resolveNamedGroupFunctions(scopeData.getClassOrNamespaceDescriptor(), psiClass, namedMembers, methodName, scopeData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetType makeReturnType(
|
||||
PsiType returnType, PsiMethodWrapper method,
|
||||
@NotNull TypeVariableResolver typeVariableResolver
|
||||
@@ -265,6 +258,7 @@ public final class JavaFunctionResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<SimpleFunctionDescriptor> getFunctionsFromSupertypes(
|
||||
ResolverScopeData scopeData,
|
||||
Name methodName
|
||||
@@ -278,20 +272,6 @@ public final class JavaFunctionResolver {
|
||||
return r;
|
||||
}
|
||||
|
||||
public List<FunctionDescriptor> resolveMethods(@NotNull ResolverScopeData scopeData) {
|
||||
List<FunctionDescriptor> functions = new ArrayList<FunctionDescriptor>();
|
||||
|
||||
for (NamedMembers member : scopeData.getMembersCache().allMembers()) {
|
||||
PsiClass psiClass = scopeData.getPsiClass();
|
||||
assert psiClass != null;
|
||||
resolveNamedGroupFunctions(scopeData.getClassOrNamespaceDescriptor(), psiClass,
|
||||
member, member.getName(), scopeData);
|
||||
functions.addAll(member.getFunctionDescriptors());
|
||||
}
|
||||
|
||||
return functions;
|
||||
}
|
||||
|
||||
private static boolean isEnumSpecialMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
String methodName = functionDescriptor.getName().getName();
|
||||
|
||||
+5
-27
@@ -79,6 +79,7 @@ public final class JavaPropertiesResolver {
|
||||
this.classResolver = classResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<VariableDescriptor> resolveFieldGroupByName(
|
||||
@NotNull Name fieldName,
|
||||
@NotNull ResolverScopeData scopeData
|
||||
@@ -93,30 +94,10 @@ public final class JavaPropertiesResolver {
|
||||
|
||||
//noinspection ConstantConditions
|
||||
String qualifiedName = psiClass == null ? scopeData.getPsiPackage().getQualifiedName() : psiClass.getQualifiedName();
|
||||
resolveNamedGroupProperties(scopeData.getClassOrNamespaceDescriptor(), scopeData, namedMembers, fieldName,
|
||||
return resolveNamedGroupProperties(scopeData.getClassOrNamespaceDescriptor(), scopeData, namedMembers, fieldName,
|
||||
"class or namespace " + qualifiedName);
|
||||
|
||||
Set<VariableDescriptor> result = namedMembers.getPropertyDescriptors();
|
||||
assert result != null;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<VariableDescriptor> resolveFieldGroup(@NotNull ResolverScopeData scopeData) {
|
||||
final PsiClass psiClass = scopeData.getPsiClass();
|
||||
assert psiClass != null;
|
||||
|
||||
Set<VariableDescriptor> descriptors = Sets.newHashSet();
|
||||
MembersByNameCache membersForProperties = scopeData.getMembersCache();
|
||||
for (NamedMembers members : membersForProperties.allMembers()) {
|
||||
resolveNamedGroupProperties(
|
||||
scopeData.getClassOrNamespaceDescriptor(), scopeData, members, members.getName(),
|
||||
"class or namespace " + psiClass.getQualifiedName());
|
||||
descriptors.addAll(members.getPropertyDescriptors());
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
private static class GroupingValue {
|
||||
PropertyAccessorData getter;
|
||||
PropertyAccessorData setter;
|
||||
@@ -124,17 +105,14 @@ public final class JavaPropertiesResolver {
|
||||
boolean ext;
|
||||
}
|
||||
|
||||
private void resolveNamedGroupProperties(
|
||||
@NotNull
|
||||
private Set<VariableDescriptor> resolveNamedGroupProperties(
|
||||
@NotNull ClassOrNamespaceDescriptor owner,
|
||||
@NotNull ResolverScopeData scopeData,
|
||||
@NotNull NamedMembers namedMembers,
|
||||
@NotNull Name propertyName,
|
||||
@NotNull String context
|
||||
) {
|
||||
if (namedMembers.getPropertyDescriptors() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, GroupingValue> map = collectGroupingValuesFromAccessors(namedMembers.getPropertyAccessors());
|
||||
|
||||
Set<PropertyDescriptor> propertiesFromCurrent = new HashSet<PropertyDescriptor>(1);
|
||||
@@ -315,7 +293,7 @@ public final class JavaPropertiesResolver {
|
||||
OverrideResolver.resolveUnknownVisibilities(properties, trace);
|
||||
properties.addAll(propertiesFromCurrent);
|
||||
|
||||
namedMembers.setPropertyDescriptors(Sets.<VariableDescriptor>newHashSet(properties));
|
||||
return Sets.<VariableDescriptor>newHashSet(properties);
|
||||
}
|
||||
|
||||
private List<TypeParameterDescriptor> resolvePropertyTypeParameters(
|
||||
|
||||
+75
-5
@@ -16,20 +16,28 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.scope;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.java.NamedMembers;
|
||||
import org.jetbrains.jet.lang.resolve.java.data.ResolverScopeData;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaNamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.scope.ScopeUtils.computeAllClassDeclarations;
|
||||
import static org.jetbrains.jet.lang.resolve.java.scope.ScopeUtils.computeAllPackageDeclarations;
|
||||
|
||||
public abstract class JavaBaseScope extends JetScopeImpl {
|
||||
@@ -39,6 +47,12 @@ public abstract class JavaBaseScope extends JetScopeImpl {
|
||||
@NotNull
|
||||
protected final ResolverScopeData resolverScopeData;
|
||||
|
||||
@NotNull
|
||||
private final Map<Name, Set<FunctionDescriptor>> functionDescriptors = Maps.newHashMap();
|
||||
@NotNull
|
||||
private final Map<Name, Set<VariableDescriptor>> propertyDescriptors = Maps.newHashMap();
|
||||
|
||||
|
||||
@Nullable
|
||||
private Collection<DeclarationDescriptor> allDescriptors = null;
|
||||
|
||||
@@ -59,19 +73,47 @@ public abstract class JavaBaseScope extends JetScopeImpl {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
Set<VariableDescriptor> cached = propertyDescriptors.get(name);
|
||||
if (cached != null) return cached;
|
||||
|
||||
if (allDescriptorsComputed()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<VariableDescriptor> computedDescriptors = computePropertyDescriptors(name);
|
||||
propertyDescriptors.put(name, computedDescriptors);
|
||||
return computedDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Set<VariableDescriptor> computePropertyDescriptors(@NotNull Name name) {
|
||||
return semanticServices.getDescriptorResolver().resolveFieldGroupByName(name, resolverScopeData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||
Set<FunctionDescriptor> cached = functionDescriptors.get(name);
|
||||
if (cached != null) return cached;
|
||||
|
||||
if (allDescriptorsComputed()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<FunctionDescriptor> computedDescriptors = computeFunctionDescriptor(name);
|
||||
functionDescriptors.put(name, computedDescriptors);
|
||||
return computedDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Set<FunctionDescriptor> computeFunctionDescriptor(@NotNull Name name) {
|
||||
return semanticServices.getDescriptorResolver().resolveFunctionGroup(name, resolverScopeData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors != null) {
|
||||
if (allDescriptorsComputed()) {
|
||||
return allDescriptors;
|
||||
}
|
||||
|
||||
@@ -80,12 +122,17 @@ public abstract class JavaBaseScope extends JetScopeImpl {
|
||||
return allDescriptors;
|
||||
}
|
||||
|
||||
private boolean allDescriptorsComputed() {
|
||||
return allDescriptors != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<DeclarationDescriptor> computeAllDescriptors() {
|
||||
Collection<DeclarationDescriptor> result = Sets.newHashSet();
|
||||
PsiClass psiClass = resolverScopeData.getPsiClass();
|
||||
if (psiClass != null) {
|
||||
result.addAll(computeAllClassDeclarations(psiClass, semanticServices, resolverScopeData, getContainingDeclaration()));
|
||||
computeFieldAndFunctionDescriptors(result);
|
||||
computeInnerClasses(psiClass, result);
|
||||
}
|
||||
|
||||
PsiPackage psiPackage = resolverScopeData.getPsiPackage();
|
||||
@@ -94,4 +141,27 @@ public abstract class JavaBaseScope extends JetScopeImpl {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void computeFieldAndFunctionDescriptors(Collection<DeclarationDescriptor> result) {
|
||||
for (NamedMembers members : resolverScopeData.getMembersCache().allMembers()) {
|
||||
Name name = members.getName();
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
result.addAll(getFunctions(name));
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
result.addAll(getProperties(name));
|
||||
}
|
||||
}
|
||||
|
||||
private void computeInnerClasses(@NotNull PsiClass psiClass, @NotNull Collection<DeclarationDescriptor> result) {
|
||||
// TODO: Trying to hack the situation when we produce namespace descriptor for java class and still want to see inner classes
|
||||
if (getContainingDeclaration() instanceof JavaNamespaceDescriptor) {
|
||||
result.addAll(semanticServices.getDescriptorResolver().resolveInnerClasses(
|
||||
resolverScopeData.getClassOrNamespaceDescriptor(), psiClass, false));
|
||||
}
|
||||
else {
|
||||
result.addAll(semanticServices.getDescriptorResolver().resolveInnerClasses(
|
||||
resolverScopeData.getClassOrNamespaceDescriptor(), psiClass,
|
||||
resolverScopeData.isStaticMembers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.data.ResolverScopeData;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaNamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -79,31 +77,4 @@ public final class ScopeUtils {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<DeclarationDescriptor> computeAllClassDeclarations(
|
||||
@NotNull PsiClass psiClass,
|
||||
@NotNull JavaSemanticServices javaSemanticServices,
|
||||
@NotNull ResolverScopeData scopeData,
|
||||
@NotNull DeclarationDescriptor containingDeclaration
|
||||
) {
|
||||
Collection<DeclarationDescriptor> result = Sets.newHashSet();
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
result.addAll(javaSemanticServices.getDescriptorResolver().resolveMethods(scopeData));
|
||||
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
result.addAll(javaSemanticServices.getDescriptorResolver().resolveFieldGroup(scopeData));
|
||||
|
||||
// TODO: Trying to hack the situation when we produce namespace descriptor for java class and still want to see inner classes
|
||||
if (containingDeclaration instanceof JavaNamespaceDescriptor) {
|
||||
result.addAll(javaSemanticServices.getDescriptorResolver().resolveInnerClasses(
|
||||
scopeData.getClassOrNamespaceDescriptor(), psiClass, false));
|
||||
}
|
||||
else {
|
||||
result.addAll(javaSemanticServices.getDescriptorResolver().resolveInnerClasses(
|
||||
scopeData.getClassOrNamespaceDescriptor(), psiClass,
|
||||
scopeData.isStaticMembers()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user