refactoring JavaDescriptorResolver and Java*Scope
This commit is contained in:
+9
-2
@@ -5,11 +5,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.lang.Configuration;
|
import org.jetbrains.jet.lang.Configuration;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.Importer;
|
import org.jetbrains.jet.lang.resolve.Importer;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
@@ -29,11 +32,15 @@ public class JavaBridgeConfiguration implements Configuration {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDefaultImports(@NotNull BindingTrace trace, @NotNull WritableScope rootScope, @NotNull Importer importer) {
|
public void addDefaultImports(@NotNull BindingTrace trace, @NotNull WritableScope rootScope, @NotNull Importer importer) {
|
||||||
rootScope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
rootScope.importScope(new JavaPackageScope("", createNamespaceDescriptor(JavaDescriptorResolver.JAVA_ROOT, ""), javaSemanticServices));
|
||||||
importer.addScopeImport(new JavaPackageScope("java.lang", null, javaSemanticServices));
|
importer.addScopeImport(new JavaPackageScope("java.lang", createNamespaceDescriptor("lang", "java.lang"), javaSemanticServices));
|
||||||
delegateConfiguration.addDefaultImports(trace, rootScope, importer);
|
delegateConfiguration.addDefaultImports(trace, rootScope, importer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JavaNamespaceDescriptor createNamespaceDescriptor(String name, String qualifiedName) {
|
||||||
|
return new JavaNamespaceDescriptor(null, Collections.<AnnotationDescriptor>emptyList(), name, qualifiedName, true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||||
namespaceMemberScope.importScope(new JavaPackageScope(DescriptorUtils.getFQName(namespaceDescriptor), namespaceDescriptor, javaSemanticServices));
|
namespaceMemberScope.importScope(new JavaPackageScope(DescriptorUtils.getFQName(namespaceDescriptor), namespaceDescriptor, javaSemanticServices));
|
||||||
|
|||||||
+22
-58
@@ -2,9 +2,7 @@ package org.jetbrains.jet.lang.resolve.java;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.psi.HierarchicalMethodSignature;
|
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiMethod;
|
|
||||||
import com.intellij.psi.PsiModifier;
|
import com.intellij.psi.PsiModifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -12,9 +10,6 @@ import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
|
|
||||||
@@ -26,25 +21,30 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class JavaClassMembersScope implements JetScope {
|
public class JavaClassMembersScope extends JavaClassOrPackageScope {
|
||||||
private final PsiClass psiClass;
|
private final PsiClassWrapper psiClass;
|
||||||
private final JavaSemanticServices semanticServices;
|
|
||||||
private final boolean staticMembers;
|
private final boolean staticMembers;
|
||||||
private final DeclarationDescriptor containingDeclaration;
|
|
||||||
private final Map<String, ClassifierDescriptor> classifiers = Maps.newHashMap();
|
private final Map<String, ClassifierDescriptor> classifiers = Maps.newHashMap();
|
||||||
private Collection<DeclarationDescriptor> allDescriptors;
|
private Collection<DeclarationDescriptor> allDescriptors;
|
||||||
|
|
||||||
public JavaClassMembersScope(@NotNull DeclarationDescriptor classOrNamespaceDescriptor, PsiClass psiClass, JavaSemanticServices semanticServices, boolean staticMembers) {
|
public JavaClassMembersScope(
|
||||||
this.containingDeclaration = classOrNamespaceDescriptor;
|
@NotNull DeclarationDescriptor classOrNamespaceDescriptor,
|
||||||
this.psiClass = psiClass;
|
@NotNull PsiClass psiClass,
|
||||||
this.semanticServices = semanticServices;
|
@NotNull JavaSemanticServices semanticServices,
|
||||||
|
boolean staticMembers) {
|
||||||
|
super(classOrNamespaceDescriptor, semanticServices);
|
||||||
|
this.psiClass = new PsiClassWrapper(psiClass);
|
||||||
this.staticMembers = staticMembers;
|
this.staticMembers = staticMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public DeclarationDescriptor getContainingDeclaration() {
|
protected PsiClassWrapper psiClass() {
|
||||||
return containingDeclaration;
|
return psiClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean staticMembers() {
|
||||||
|
return staticMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -53,11 +53,6 @@ public class JavaClassMembersScope implements JetScope {
|
|||||||
throw new UnsupportedOperationException(); // TODO
|
throw new UnsupportedOperationException(); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||||
ClassifierDescriptor classifierDescriptor = classifiers.get(name);
|
ClassifierDescriptor classifierDescriptor = classifiers.get(name);
|
||||||
@@ -80,28 +75,19 @@ public class JavaClassMembersScope implements JetScope {
|
|||||||
allDescriptors = Sets.newHashSet();
|
allDescriptors = Sets.newHashSet();
|
||||||
TypeSubstitutor substitutorForGenericSupertypes = getTypeSubstitutorForSupertypes();
|
TypeSubstitutor substitutorForGenericSupertypes = getTypeSubstitutorForSupertypes();
|
||||||
|
|
||||||
for (HierarchicalMethodSignature signature : psiClass.getVisibleSignatures()) {
|
allDescriptors.addAll(semanticServices.getDescriptorResolver().resolveMethods(psiClass.getPsiClass(), descriptor, staticMembers, substitutorForGenericSupertypes));
|
||||||
PsiMethod method = signature.getMethod();
|
|
||||||
if (method.hasModifierProperty(PsiModifier.STATIC) != staticMembers) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
FunctionDescriptor functionDescriptor = semanticServices.getDescriptorResolver().resolveMethodToFunctionDescriptor(containingDeclaration, psiClass, substitutorForGenericSupertypes, new PsiMethodWrapper(method));
|
|
||||||
if (functionDescriptor != null) {
|
|
||||||
allDescriptors.add(functionDescriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allDescriptors.addAll(semanticServices.getDescriptorResolver().resolveFieldGroup(containingDeclaration, psiClass, staticMembers));
|
allDescriptors.addAll(semanticServices.getDescriptorResolver().resolveFieldGroup(descriptor, psiClass.getPsiClass(), staticMembers));
|
||||||
|
|
||||||
allDescriptors.addAll(semanticServices.getDescriptorResolver().resolveInnerClasses(containingDeclaration, psiClass, staticMembers));
|
allDescriptors.addAll(semanticServices.getDescriptorResolver().resolveInnerClasses(descriptor, psiClass.getPsiClass(), staticMembers));
|
||||||
}
|
}
|
||||||
return allDescriptors;
|
return allDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeSubstitutor getTypeSubstitutorForSupertypes() {
|
private TypeSubstitutor getTypeSubstitutorForSupertypes() {
|
||||||
TypeSubstitutor substitutorForGenericSupertypes;
|
TypeSubstitutor substitutorForGenericSupertypes;
|
||||||
if (containingDeclaration instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
substitutorForGenericSupertypes = semanticServices.getDescriptorResolver().createSubstitutorForGenericSupertypes((ClassDescriptor) containingDeclaration);
|
substitutorForGenericSupertypes = semanticServices.getDescriptorResolver().createSubstitutorForGenericSupertypes((ClassDescriptor) descriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
substitutorForGenericSupertypes = TypeSubstitutor.EMPTY;
|
substitutorForGenericSupertypes = TypeSubstitutor.EMPTY;
|
||||||
@@ -111,7 +97,7 @@ public class JavaClassMembersScope implements JetScope {
|
|||||||
|
|
||||||
private ClassifierDescriptor doGetClassifierDescriptor(String name) {
|
private ClassifierDescriptor doGetClassifierDescriptor(String name) {
|
||||||
// TODO : suboptimal, walk the list only once
|
// TODO : suboptimal, walk the list only once
|
||||||
for (PsiClass innerClass : psiClass.getAllInnerClasses()) {
|
for (PsiClass innerClass : psiClass.getPsiClass().getAllInnerClasses()) {
|
||||||
if (name.equals(innerClass.getName())) {
|
if (name.equals(innerClass.getName())) {
|
||||||
if (innerClass.hasModifierProperty(PsiModifier.STATIC) != staticMembers) return null;
|
if (innerClass.hasModifierProperty(PsiModifier.STATIC) != staticMembers) return null;
|
||||||
ClassDescriptor classDescriptor = semanticServices.getDescriptorResolver().resolveClass(innerClass);
|
ClassDescriptor classDescriptor = semanticServices.getDescriptorResolver().resolveClass(innerClass);
|
||||||
@@ -123,28 +109,6 @@ public class JavaClassMembersScope implements JetScope {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<VariableDescriptor> getProperties(@NotNull String name) {
|
|
||||||
return semanticServices.getDescriptorResolver().resolveFieldGroupByName(containingDeclaration, psiClass, name, staticMembers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VariableDescriptor getLocalVariable(@NotNull String name) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
|
||||||
return semanticServices.getDescriptorResolver().resolveFunctionGroup(
|
|
||||||
containingDeclaration,
|
|
||||||
psiClass,
|
|
||||||
staticMembers ? null : (ClassDescriptor) containingDeclaration,
|
|
||||||
name,
|
|
||||||
staticMembers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
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.scopes.JetScopeImpl;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*/
|
||||||
|
public abstract class JavaClassOrPackageScope extends JetScopeImpl {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected final DeclarationDescriptor descriptor;
|
||||||
|
protected final JavaSemanticServices semanticServices;
|
||||||
|
|
||||||
|
protected JavaClassOrPackageScope(@NotNull DeclarationDescriptor descriptor, @NotNull JavaSemanticServices semanticServices) {
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.semanticServices = semanticServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DeclarationDescriptor getContainingDeclaration() {
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected abstract PsiClassWrapper psiClass();
|
||||||
|
|
||||||
|
protected abstract boolean staticMembers();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<VariableDescriptor> getProperties(@NotNull String name) {
|
||||||
|
PsiClassWrapper psiClass = psiClass();
|
||||||
|
|
||||||
|
if (psiClass == null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: cache
|
||||||
|
return semanticServices.getDescriptorResolver().resolveFieldGroupByName(
|
||||||
|
descriptor, psiClass.getPsiClass(), name, staticMembers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||||
|
PsiClassWrapper psiClassForPackage = psiClass();
|
||||||
|
|
||||||
|
if (psiClassForPackage == null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
return semanticServices.getDescriptorResolver().resolveFunctionGroup(descriptor, psiClassForPackage.getPsiClass(), name, staticMembers());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+26
-6
@@ -1056,9 +1056,9 @@ public class JavaDescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<FunctionDescriptor> resolveFunctionGroup(@NotNull DeclarationDescriptor owner, @NotNull PsiClass psiClass, @Nullable ClassDescriptor classDescriptor, @NotNull String methodName, boolean staticMembers) {
|
public Set<FunctionDescriptor> resolveFunctionGroup(@NotNull DeclarationDescriptor descriptor, @NotNull PsiClass psiClass, @NotNull String methodName, boolean staticMembers) {
|
||||||
|
|
||||||
ResolverScopeData resolverScopeData = getResolverScopeData(owner, new PsiClassWrapper(psiClass));
|
ResolverScopeData resolverScopeData = getResolverScopeData(descriptor, new PsiClassWrapper(psiClass));
|
||||||
|
|
||||||
Map<String, NamedMembers> namedMembersMap = resolverScopeData.namedMembersMap;
|
Map<String, NamedMembers> namedMembersMap = resolverScopeData.namedMembersMap;
|
||||||
|
|
||||||
@@ -1067,13 +1067,18 @@ public class JavaDescriptorResolver {
|
|||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeSubstitutor typeSubstitutor = createSubstitutorForGenericSupertypes(classDescriptor);
|
TypeSubstitutor typeSubstitutor;
|
||||||
resolveNamedGroupFunctions(owner, psiClass, typeSubstitutor, staticMembers, namedMembers, methodName);
|
if (descriptor instanceof ClassDescriptor && !staticMembers) {
|
||||||
|
typeSubstitutor = createSubstitutorForGenericSupertypes((ClassDescriptor) descriptor);
|
||||||
|
} else {
|
||||||
|
typeSubstitutor = TypeSubstitutor.EMPTY;
|
||||||
|
}
|
||||||
|
resolveNamedGroupFunctions(descriptor, psiClass, typeSubstitutor, staticMembers, namedMembers, methodName);
|
||||||
|
|
||||||
return namedMembers.functionDescriptors;
|
return namedMembers.functionDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeSubstitutor createSubstitutorForGenericSupertypes(ClassDescriptor classDescriptor) {
|
public TypeSubstitutor createSubstitutorForGenericSupertypes(@Nullable ClassDescriptor classDescriptor) {
|
||||||
TypeSubstitutor typeSubstitutor;
|
TypeSubstitutor typeSubstitutor;
|
||||||
if (classDescriptor != null) {
|
if (classDescriptor != null) {
|
||||||
typeSubstitutor = TypeUtils.buildDeepSubstitutor(classDescriptor.getDefaultType());
|
typeSubstitutor = TypeUtils.buildDeepSubstitutor(classDescriptor.getDefaultType());
|
||||||
@@ -1105,7 +1110,7 @@ public class JavaDescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethodWrapper method) {
|
private FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethodWrapper method) {
|
||||||
|
|
||||||
PsiType returnType = method.getReturnType();
|
PsiType returnType = method.getReturnType();
|
||||||
if (returnType == null) {
|
if (returnType == null) {
|
||||||
@@ -1224,6 +1229,21 @@ public class JavaDescriptorResolver {
|
|||||||
}
|
}
|
||||||
return substitutedFunctionDescriptor;
|
return substitutedFunctionDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FunctionDescriptor> resolveMethods(PsiClass psiClass, DeclarationDescriptor containingDeclaration, boolean staticMembers, TypeSubstitutor substitutorForGenericSupertypes) {
|
||||||
|
List<FunctionDescriptor> functions = new ArrayList<FunctionDescriptor>();
|
||||||
|
for (HierarchicalMethodSignature signature : psiClass.getVisibleSignatures()) {
|
||||||
|
PsiMethod method = signature.getMethod();
|
||||||
|
if (method.hasModifierProperty(PsiModifier.STATIC) != staticMembers) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FunctionDescriptor functionDescriptor = semanticServices.getDescriptorResolver().resolveMethodToFunctionDescriptor(containingDeclaration, psiClass, substitutorForGenericSupertypes, new PsiMethodWrapper(method));
|
||||||
|
if (functionDescriptor != null) {
|
||||||
|
functions.add(functionDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return functions;
|
||||||
|
}
|
||||||
|
|
||||||
private List<TypeParameterDescriptor> resolveMethodTypeParameters(
|
private List<TypeParameterDescriptor> resolveMethodTypeParameters(
|
||||||
@NotNull PsiMethodWrapper method,
|
@NotNull PsiMethodWrapper method,
|
||||||
|
|||||||
+18
-44
@@ -2,12 +2,14 @@ package org.jetbrains.jet.lang.resolve.java;
|
|||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiField;
|
|
||||||
import com.intellij.psi.PsiModifier;
|
import com.intellij.psi.PsiModifier;
|
||||||
import com.intellij.psi.PsiPackage;
|
import com.intellij.psi.PsiPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -16,17 +18,17 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class JavaPackageScope extends JetScopeImpl {
|
public class JavaPackageScope extends JavaClassOrPackageScope {
|
||||||
private final JavaSemanticServices semanticServices;
|
|
||||||
private final DeclarationDescriptor containingDescriptor;
|
|
||||||
private final String packageFQN;
|
private final String packageFQN;
|
||||||
|
|
||||||
private Collection<DeclarationDescriptor> allDescriptors;
|
private Collection<DeclarationDescriptor> allDescriptors;
|
||||||
|
|
||||||
public JavaPackageScope(@NotNull String packageFQN, DeclarationDescriptor containingDescriptor, JavaSemanticServices semanticServices) {
|
public JavaPackageScope(
|
||||||
this.semanticServices = semanticServices;
|
@NotNull String packageFQN,
|
||||||
|
@NotNull DeclarationDescriptor containingDescriptor,
|
||||||
|
@NotNull JavaSemanticServices semanticServices) {
|
||||||
|
super(containingDescriptor, semanticServices);
|
||||||
this.packageFQN = packageFQN;
|
this.packageFQN = packageFQN;
|
||||||
this.containingDescriptor = containingDescriptor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,6 +38,7 @@ public class JavaPackageScope extends JetScopeImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassDescriptor getObjectDescriptor(@NotNull String name) {
|
public ClassDescriptor getObjectDescriptor(@NotNull String name) {
|
||||||
|
// TODO
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +46,9 @@ public class JavaPackageScope extends JetScopeImpl {
|
|||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
return semanticServices.getDescriptorResolver().resolveNamespace(getQualifiedName(name));
|
return semanticServices.getDescriptorResolver().resolveNamespace(getQualifiedName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PsiClass getPsiClassForPackage() {
|
@Override
|
||||||
|
protected PsiClassWrapper psiClass() {
|
||||||
// If this package is actually a Kotlin namespace, then we access it through a namespace descriptor, and
|
// If this package is actually a Kotlin namespace, then we access it through a namespace descriptor, and
|
||||||
// Kotlin functions are already there
|
// Kotlin functions are already there
|
||||||
NamespaceDescriptor kotlinNamespaceDescriptor = semanticServices.getKotlinNamespaceDescriptor(packageFQN);
|
NamespaceDescriptor kotlinNamespaceDescriptor = semanticServices.getKotlinNamespaceDescriptor(packageFQN);
|
||||||
@@ -58,42 +62,12 @@ public class JavaPackageScope extends JetScopeImpl {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containingDescriptor == null) {
|
return new PsiClassWrapper(psiClass);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return psiClass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
protected boolean staticMembers() {
|
||||||
PsiClass psiClassForPackage = getPsiClassForPackage();
|
return true;
|
||||||
|
|
||||||
if (psiClassForPackage == null) {
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
return semanticServices.getDescriptorResolver().resolveFunctionGroup(containingDescriptor, psiClassForPackage, null, name, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<VariableDescriptor> getProperties(@NotNull String name) {
|
|
||||||
PsiClass psiClassForPackage = getPsiClassForPackage();
|
|
||||||
|
|
||||||
if (psiClassForPackage == null) {
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: cache
|
|
||||||
return semanticServices.getDescriptorResolver().resolveFieldGroupByName(containingDescriptor, psiClassForPackage, name, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public DeclarationDescriptor getContainingDeclaration() {
|
|
||||||
return containingDescriptor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaPackageScope;
|
import org.jetbrains.jet.lang.resolve.java.JavaPackageScope;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||||
@@ -543,8 +545,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING);
|
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING);
|
||||||
writableScope.importScope(library.getLibraryScope());
|
writableScope.importScope(library.getLibraryScope());
|
||||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
|
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
|
||||||
writableScope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
writableScope.importScope(new JavaPackageScope("", JavaBridgeConfiguration.createNamespaceDescriptor(JavaDescriptorResolver.JAVA_ROOT, ""), javaSemanticServices));
|
||||||
writableScope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices));
|
writableScope.importScope(new JavaPackageScope("java.lang", JavaBridgeConfiguration.createNamespaceDescriptor("lang", "java.lang"), javaSemanticServices));
|
||||||
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
return writableScope;
|
return writableScope;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user