cleanup in JavaDescriptorResolver
This commit is contained in:
@@ -178,20 +178,20 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
private String jvmClassNameForNamespace(NamespaceDescriptor namespace) {
|
private String jvmClassNameForNamespace(NamespaceDescriptor namespace) {
|
||||||
FqName fqName = DescriptorUtils.getFQName(namespace).toSafe();
|
FqName fqName = DescriptorUtils.getFQName(namespace).toSafe();
|
||||||
Boolean javaClassStatics = bindingContext.get(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, namespace);
|
JavaNamespaceKind javaNamespaceKind = bindingContext.get(JavaBindingContext.JAVA_NAMESPACE_KIND, namespace);
|
||||||
Boolean src = bindingContext.get(BindingContext.NAMESPACE_IS_SRC, namespace);
|
Boolean src = bindingContext.get(BindingContext.NAMESPACE_IS_SRC, namespace);
|
||||||
|
|
||||||
if (javaClassStatics == null && src == null) {
|
if (javaNamespaceKind == null && src == null) {
|
||||||
throw new IllegalStateException("unknown namespace origin: " + fqName);
|
throw new IllegalStateException("unknown namespace origin: " + fqName);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean classStatics;
|
boolean classStatics;
|
||||||
if (javaClassStatics != null) {
|
if (javaNamespaceKind != null) {
|
||||||
if (javaClassStatics.booleanValue() && src != null) {
|
if (javaNamespaceKind == JavaNamespaceKind.CLASS_STATICS && src != null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"conflicting namespace " + fqName + ": it is both java statics and from src");
|
"conflicting namespace " + fqName + ": it is both java statics and from src");
|
||||||
}
|
}
|
||||||
classStatics = javaClassStatics.booleanValue();
|
classStatics = javaNamespaceKind == JavaNamespaceKind.CLASS_STATICS;
|
||||||
} else {
|
} else {
|
||||||
classStatics = false;
|
classStatics = false;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ public class JavaBindingContext {
|
|||||||
/**
|
/**
|
||||||
* @see BindingContext#NAMESPACE_IS_SRC
|
* @see BindingContext#NAMESPACE_IS_SRC
|
||||||
*/
|
*/
|
||||||
public static final WritableSlice<NamespaceDescriptor, Boolean> NAMESPACE_IS_CLASS_STATICS =
|
public static final WritableSlice<NamespaceDescriptor, JavaNamespaceKind> JAVA_NAMESPACE_KIND =
|
||||||
Slices.createSimpleSlice();
|
Slices.createSimpleSlice();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-81
@@ -28,6 +28,7 @@ import com.intellij.psi.PsiAnnotationParameterList;
|
|||||||
import com.intellij.psi.PsiArrayType;
|
import com.intellij.psi.PsiArrayType;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiClassType;
|
import com.intellij.psi.PsiClassType;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiEllipsisType;
|
import com.intellij.psi.PsiEllipsisType;
|
||||||
import com.intellij.psi.PsiLiteralExpression;
|
import com.intellij.psi.PsiLiteralExpression;
|
||||||
import com.intellij.psi.PsiMethod;
|
import com.intellij.psi.PsiMethod;
|
||||||
@@ -232,6 +233,16 @@ public class JavaDescriptorResolver {
|
|||||||
classOrNamespaceDescriptor = descriptor;
|
classOrNamespaceDescriptor = descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public PsiElement getPsiPackageOrPsiClass() {
|
||||||
|
if (psiPackage != null) {
|
||||||
|
return psiPackage;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return psiClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, NamedMembers> namedMembersMap;
|
private Map<String, NamedMembers> namedMembersMap;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -872,78 +883,69 @@ public class JavaDescriptorResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiPackage psiPackage = psiClassFinder.findPsiPackage(qualifiedName);
|
ResolverNamespaceData namespaceData = namespaceDescriptorCacheByFqn.get(qualifiedName);
|
||||||
if (psiPackage == null) {
|
if (namespaceData != null) {
|
||||||
PsiClass psiClass = psiClassFinder.findPsiClass(qualifiedName);
|
return namespaceData.namespaceDescriptor;
|
||||||
if (psiClass == null) return null;
|
|
||||||
return resolveNamespace(psiClass);
|
|
||||||
}
|
}
|
||||||
return resolveNamespace(psiPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private NamespaceDescriptor resolveNamespace(@NotNull PsiPackage psiPackage) {
|
NamespaceDescriptorParent parentNs = resolveParentNamespace(qualifiedName);
|
||||||
FqName fqName = new FqName(psiPackage.getQualifiedName());
|
if (parentNs == null) {
|
||||||
ResolverNamespaceData namespaceData = namespaceDescriptorCacheByFqn.get(fqName);
|
return null;
|
||||||
if (namespaceData == null) {
|
|
||||||
return createJavaNamespaceDescriptor(psiPackage);
|
|
||||||
}
|
}
|
||||||
return namespaceData.namespaceDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NamespaceDescriptor resolveNamespace(@NotNull PsiClass psiClass) {
|
JavaNamespaceDescriptor ns = new JavaNamespaceDescriptor(
|
||||||
FqName fqName = new FqName(psiClass.getQualifiedName());
|
parentNs,
|
||||||
ResolverNamespaceData namespaceData = namespaceDescriptorCacheByFqn.get(fqName);
|
|
||||||
if (namespaceData == null) {
|
|
||||||
namespaceData = createJavaNamespaceDescriptor(psiClass);
|
|
||||||
namespaceDescriptorCacheByFqn.put(fqName, namespaceData);
|
|
||||||
}
|
|
||||||
return namespaceData.namespaceDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JavaNamespaceDescriptor createJavaNamespaceDescriptor(@NotNull PsiPackage psiPackage) {
|
|
||||||
FqName fqName = new FqName(psiPackage.getQualifiedName());
|
|
||||||
String name = psiPackage.getName();
|
|
||||||
JavaNamespaceDescriptor namespaceDescriptor = new JavaNamespaceDescriptor(
|
|
||||||
(NamespaceDescriptorParent) resolveParentDescriptor(psiPackage),
|
|
||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||||
name == null ? JAVA_ROOT : name,
|
qualifiedName.isRoot() ? "<root>" : qualifiedName.shortName(),
|
||||||
fqName
|
qualifiedName
|
||||||
);
|
);
|
||||||
trace.record(BindingContext.NAMESPACE, psiPackage, namespaceDescriptor);
|
|
||||||
|
|
||||||
ResolverNamespaceData scopeData = createNamespaceResolverScopeData(fqName, namespaceDescriptor);
|
ResolverNamespaceData scopeData = createNamespaceResolverScopeData(qualifiedName, ns);
|
||||||
namespaceDescriptor.setMemberScope(scopeData.memberScope);
|
if (scopeData == null) {
|
||||||
return namespaceDescriptor;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
trace.record(BindingContext.NAMESPACE, scopeData.getPsiPackageOrPsiClass(), ns);
|
||||||
|
|
||||||
|
ns.setMemberScope(scopeData.memberScope);
|
||||||
|
|
||||||
|
return scopeData.namespaceDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NamespaceDescriptorParent resolveParentNamespace(FqName fqName) {
|
||||||
|
if (fqName.isRoot()) {
|
||||||
|
return FAKE_ROOT_MODULE;
|
||||||
|
} else {
|
||||||
|
return resolveNamespace(fqName.parent(), DescriptorSearchRule.INCLUDE_KOTLIN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ResolverNamespaceData createNamespaceResolverScopeData(@NotNull FqName fqName, @NotNull NamespaceDescriptor ns) {
|
private ResolverNamespaceData createNamespaceResolverScopeData(@NotNull FqName fqName, @NotNull NamespaceDescriptor ns) {
|
||||||
PsiPackage psiPackage;
|
PsiPackage psiPackage;
|
||||||
psiPackage = semanticServices.getPsiClassFinder().findPsiPackage(fqName);
|
|
||||||
PsiClass psiClass;
|
PsiClass psiClass;
|
||||||
|
|
||||||
lookingForPsi:
|
lookingForPsi:
|
||||||
{
|
{
|
||||||
psiClass = getPsiClassForJavaPackageScope(fqName);
|
psiClass = getPsiClassForJavaPackageScope(fqName);
|
||||||
|
psiPackage = semanticServices.getPsiClassFinder().findPsiPackage(fqName);
|
||||||
if (psiClass != null || psiPackage != null) {
|
if (psiClass != null || psiPackage != null) {
|
||||||
|
trace.record(JavaBindingContext.JAVA_NAMESPACE_KIND, ns, JavaNamespaceKind.PROPER);
|
||||||
break lookingForPsi;
|
break lookingForPsi;
|
||||||
}
|
}
|
||||||
|
|
||||||
psiClass = psiClassFinder.findPsiClass(fqName);
|
psiClass = psiClassFinder.findPsiClass(fqName);
|
||||||
if (psiClass == null) {
|
if (psiClass != null) {
|
||||||
return null;
|
trace.record(JavaBindingContext.JAVA_NAMESPACE_KIND, ns, JavaNamespaceKind.CLASS_STATICS);
|
||||||
|
break lookingForPsi;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (psiPackage != null) {
|
return null;
|
||||||
trace.record(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, ns, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolverNamespaceData namespaceData = new ResolverNamespaceData(psiClass, psiPackage, fqName, ns);
|
ResolverNamespaceData namespaceData = new ResolverNamespaceData(psiClass, psiPackage, fqName, ns);
|
||||||
|
|
||||||
JavaPackageScope scope = new JavaPackageScope(fqName, semanticServices, namespaceData);
|
namespaceData.memberScope = new JavaPackageScope(fqName, semanticServices, namespaceData);
|
||||||
|
|
||||||
namespaceData.memberScope = scope;
|
|
||||||
|
|
||||||
ResolverNamespaceData oldValue = namespaceDescriptorCacheByFqn.put(fqName, namespaceData);
|
ResolverNamespaceData oldValue = namespaceDescriptorCacheByFqn.put(fqName, namespaceData);
|
||||||
if (oldValue != null) {
|
if (oldValue != null) {
|
||||||
@@ -974,43 +976,6 @@ public class JavaDescriptorResolver {
|
|||||||
return psiClassFinder.findPsiClass(packageFQN.child(JvmAbi.PACKAGE_CLASS));
|
return psiClassFinder.findPsiClass(packageFQN.child(JvmAbi.PACKAGE_CLASS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private DeclarationDescriptor resolveParentDescriptor(@NotNull PsiPackage psiPackage) {
|
|
||||||
PsiPackage parentPackage = psiPackage.getParentPackage();
|
|
||||||
if (parentPackage == null) {
|
|
||||||
return FAKE_ROOT_MODULE;
|
|
||||||
}
|
|
||||||
return resolveNamespace(parentPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
* @see #createClassObjectDescriptor(org.jetbrains.jet.lang.descriptors.ClassDescriptor, com.intellij.psi.PsiClass)
|
|
||||||
*/
|
|
||||||
private ResolverNamespaceData createJavaNamespaceDescriptor(@NotNull final PsiClass psiClass) {
|
|
||||||
|
|
||||||
checkPsiClassIsNotJet(psiClass);
|
|
||||||
|
|
||||||
FqName fqName = new FqName(psiClass.getQualifiedName());
|
|
||||||
JavaNamespaceDescriptor ns = new JavaNamespaceDescriptor(
|
|
||||||
resolveNamespace(fqName.parent(), DescriptorSearchRule.INCLUDE_KOTLIN),
|
|
||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
|
||||||
psiClass.getName(),
|
|
||||||
fqName
|
|
||||||
);
|
|
||||||
|
|
||||||
ResolverNamespaceData scopeData = createNamespaceResolverScopeData(fqName, ns);
|
|
||||||
if (scopeData == null) {
|
|
||||||
throw new IllegalStateException("we have class: " + fqName);
|
|
||||||
}
|
|
||||||
|
|
||||||
ns.setMemberScope(scopeData.memberScope);
|
|
||||||
trace.record(BindingContext.NAMESPACE, psiClass, ns);
|
|
||||||
trace.record(JavaBindingContext.NAMESPACE_IS_CLASS_STATICS, ns, true);
|
|
||||||
|
|
||||||
return scopeData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ValueParameterDescriptors {
|
private static class ValueParameterDescriptors {
|
||||||
private final JetType receiverType;
|
private final JetType receiverType;
|
||||||
private final List<ValueParameterDescriptor> descriptors;
|
private final List<ValueParameterDescriptor> descriptors;
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.lang.resolve.java;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*/
|
||||||
|
public enum JavaNamespaceKind {
|
||||||
|
PROPER,
|
||||||
|
CLASS_STATICS,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user