Big refactoring continued. Migrating to package views and fragments.
This commit is contained in:
-8
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaPackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -56,13 +55,6 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
||||
return classResolver.resolveClass(qualifiedName, IGNORE_KOTLIN_SOURCES);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public NamespaceDescriptor resolveNamespace(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule) {
|
||||
// TODO 1 remove this method
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JavaPackageFragmentProvider getPackageFragmentProvider() {
|
||||
return packageFragmentProvider;
|
||||
|
||||
+10
@@ -291,6 +291,16 @@ public final class JavaFunctionResolver {
|
||||
return findClassInPackage(parentPackage, fragment.getFqName().shortName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JavaPackageFragmentDescriptor getPackageForCorrespondingJavaClass(@NotNull JavaClassDescriptor javaClass) {
|
||||
PackageFragmentDescriptor packageFragment = DescriptorUtils.getParentOfType(javaClass, PackageFragmentDescriptor.class);
|
||||
assert packageFragment instanceof JavaPackageFragmentDescriptor :
|
||||
"java class " + javaClass + " is under non-java fragment: " + packageFragment;
|
||||
|
||||
JavaPackageFragmentProvider provider = ((JavaPackageFragmentDescriptor) packageFragment).getProvider();
|
||||
return provider.getOrCreatePackage(getFQName(javaClass).toSafe());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SamConstructorDescriptor resolveSamConstructor(@NotNull JavaPackageFragmentDescriptor owner, @NotNull NamedMembers namedMembers) {
|
||||
if (namedMembers.getSamInterface() != null) {
|
||||
|
||||
@@ -19,10 +19,8 @@ package org.jetbrains.jet.lang;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,8 +37,5 @@ public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equalsTo(KotlinBuiltIns.getInstance().getBuiltInsPackageFqName())) {
|
||||
namespaceMemberScope.importScope(KotlinBuiltIns.getInstance().getBuiltInsScope());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +51,6 @@ public interface WritableScope extends JetScope {
|
||||
|
||||
void addVariableAlias(@NotNull Name name, @NotNull VariableDescriptor variableDescriptor);
|
||||
|
||||
void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor);
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
NamespaceDescriptor getDeclaredNamespace(@NotNull Name name);
|
||||
|
||||
@NotNull Multimap<Name, DeclarationDescriptor> getDeclaredDescriptorsAccessibleBySimpleName();
|
||||
|
||||
void importScope(@NotNull JetScope imported);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
private SetMultimap<Name, FunctionDescriptor> functionGroups;
|
||||
|
||||
@Nullable
|
||||
private Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors;
|
||||
private Map<Name, DeclarationDescriptor> variableOrClassDescriptors;
|
||||
|
||||
@Nullable
|
||||
private SetMultimap<Name, VariableDescriptor> propertyGroups;
|
||||
@@ -180,11 +180,11 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<Name, DeclarationDescriptor> getVariableClassOrNamespaceDescriptors() {
|
||||
if (variableClassOrNamespaceDescriptors == null) {
|
||||
variableClassOrNamespaceDescriptors = Maps.newHashMap();
|
||||
private Map<Name, DeclarationDescriptor> getVariableOrClassDescriptors() {
|
||||
if (variableOrClassDescriptors == null) {
|
||||
variableOrClassDescriptors = Maps.newHashMap();
|
||||
}
|
||||
return variableClassOrNamespaceDescriptors;
|
||||
return variableOrClassDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -216,7 +216,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
if (variableDescriptor.getReceiverParameter() == null) {
|
||||
checkForRedeclaration(name, variableDescriptor);
|
||||
// TODO : Should this always happen?
|
||||
getVariableClassOrNamespaceDescriptors().put(name, variableDescriptor);
|
||||
getVariableOrClassDescriptors().put(name, variableDescriptor);
|
||||
}
|
||||
allDescriptors.add(variableDescriptor);
|
||||
addToDeclared(variableDescriptor);
|
||||
@@ -240,7 +240,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
public VariableDescriptor getLocalVariable(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableOrClassDescriptors();
|
||||
DeclarationDescriptor descriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||
if (descriptor instanceof VariableDescriptor && !getPropertyGroups().get(name).contains(descriptor)) {
|
||||
return (VariableDescriptor) descriptor;
|
||||
@@ -311,7 +311,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
checkMayWrite();
|
||||
|
||||
checkForRedeclaration(name, classifierDescriptor);
|
||||
getVariableClassOrNamespaceDescriptors().put(name, classifierDescriptor);
|
||||
getVariableOrClassDescriptors().put(name, classifierDescriptor);
|
||||
allDescriptors.add(classifierDescriptor);
|
||||
addToDeclared(classifierDescriptor);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
checkMayWrite();
|
||||
|
||||
checkForRedeclaration(name, variableDescriptor);
|
||||
getVariableClassOrNamespaceDescriptors().put(name, variableDescriptor);
|
||||
getVariableOrClassDescriptors().put(name, variableDescriptor);
|
||||
allDescriptors.add(variableDescriptor);
|
||||
addToDeclared(variableDescriptor);
|
||||
}
|
||||
@@ -358,7 +358,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
}
|
||||
|
||||
private void checkForRedeclaration(@NotNull Name name, DeclarationDescriptor classifierDescriptor) {
|
||||
DeclarationDescriptor originalDescriptor = getVariableClassOrNamespaceDescriptors().get(name);
|
||||
DeclarationDescriptor originalDescriptor = getVariableOrClassDescriptors().get(name);
|
||||
if (originalDescriptor != null) {
|
||||
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor);
|
||||
}
|
||||
@@ -368,7 +368,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableOrClassDescriptors();
|
||||
DeclarationDescriptor descriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||
if (descriptor instanceof ClassifierDescriptor) return (ClassifierDescriptor) descriptor;
|
||||
|
||||
@@ -378,37 +378,10 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
return super.getClassifier(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
DeclarationDescriptor oldValue = variableClassOrNamespaceDescriptors.put(namespaceDescriptor.getName(), namespaceDescriptor);
|
||||
if (oldValue != null) {
|
||||
redeclarationHandler.handleRedeclaration(oldValue, namespaceDescriptor);
|
||||
}
|
||||
allDescriptors.add(namespaceDescriptor);
|
||||
addToDeclared(namespaceDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getDeclaredNamespace(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
Map<Name, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
DeclarationDescriptor namespaceDescriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||
if (namespaceDescriptor instanceof NamespaceDescriptor) return (NamespaceDescriptor) namespaceDescriptor;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
checkMayRead();
|
||||
|
||||
// TODO 1
|
||||
//NamespaceDescriptor declaredNamespace = getDeclaredNamespace(name);
|
||||
//if (declaredNamespace != null) return declaredNamespace;
|
||||
|
||||
PackageViewDescriptor aliased = getPackageAliases().get(name);
|
||||
if (aliased != null) return aliased;
|
||||
|
||||
|
||||
@@ -682,11 +682,6 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
renderName(moduleOrScript, builder);
|
||||
}
|
||||
|
||||
private void renderNamespace(@NotNull NamespaceDescriptor namespace, @NotNull StringBuilder builder) {
|
||||
builder.append(renderKeyword("package")).append(" ");
|
||||
renderName(namespace, builder);
|
||||
}
|
||||
|
||||
private void renderPackageView(@NotNull PackageViewDescriptor packageView, @NotNull StringBuilder builder) {
|
||||
builder.append(renderKeyword("package")).append(" ");
|
||||
renderName(packageView, builder);
|
||||
@@ -751,7 +746,6 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
|
||||
@Override
|
||||
public Void visitNamespaceDescriptor(NamespaceDescriptor namespaceDescriptor, StringBuilder builder) {
|
||||
renderNamespace(namespaceDescriptor, builder);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user