NamespaceLikeBuilder instead of NamespaceLike

This commit is contained in:
Stepan Koltsov
2012-03-14 18:01:18 +04:00
parent 34c4808c76
commit 1127a23a1b
8 changed files with 37 additions and 66 deletions
@@ -48,15 +48,6 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
super(containingDeclaration, kind);
if (containingDeclaration instanceof ClassDescriptor
|| containingDeclaration instanceof NamespaceLike
|| containingDeclaration instanceof ModuleDescriptor
|| containingDeclaration instanceof FunctionDescriptor)
{
} else {
throw new IllegalStateException();
}
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup").changeLockLevel(WritableScope.LockLevel.BOTH));
@@ -79,6 +79,11 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
}
@NotNull
@Override
public DeclarationDescriptor getOwnerForChildren() {
return this;
}
@Override
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
@@ -38,6 +38,12 @@ public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl imp
this.memberScope = memberScope;
}
@NotNull
@Override
public DeclarationDescriptor getOwnerForChildren() {
return this;
}
@Override
@NotNull
public WritableScope getMemberScope() {
@@ -26,53 +26,10 @@ import java.util.List;
/**
* @author abreslav
*/
public interface NamespaceLike extends DeclarationDescriptor {
public interface NamespaceLike {
abstract class Adapter implements NamespaceLike {
private final DeclarationDescriptor descriptor;
public Adapter(DeclarationDescriptor descriptor) {
this.descriptor = descriptor;
}
@Override
@NotNull
public DeclarationDescriptor getOriginal() {
return descriptor.getOriginal();
}
@Override
@Nullable
public DeclarationDescriptor getContainingDeclaration() {
return descriptor.getContainingDeclaration();
}
@Override
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
return descriptor.substitute(substitutor);
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return descriptor.accept(visitor, data);
}
@Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
descriptor.acceptVoid(visitor);
}
@Override
public List<AnnotationDescriptor> getAnnotations() {
return descriptor.getAnnotations();
}
@Override
@NotNull
public String getName() {
return descriptor.getName();
}
}
@NotNull
DeclarationDescriptor getOwnerForChildren();
@Nullable
NamespaceDescriptorImpl getNamespace(String name);
@@ -102,7 +102,7 @@ public class AnalyzingUtils {
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
@NotNull BindingTraceContext bindingTraceContext) {
ModuleDescriptor owner = new ModuleDescriptor("<module>");
final ModuleDescriptor owner = new ModuleDescriptor("<module>");
final WritableScope scope = new WritableScopeImpl(
JetScope.EMPTY, owner,
@@ -136,7 +136,13 @@ public class AnalyzingUtils {
});
TopDownAnalyzer.process(project, bindingTraceContext, scope,
new NamespaceLike.Adapter(owner) {
new NamespaceLike() {
@NotNull
@Override
public DeclarationDescriptor getOwnerForChildren() {
return owner;
}
@Override
public NamespaceDescriptorImpl getNamespace(String name) {
@@ -144,7 +144,7 @@ public class DeclarationResolver {
declaration.accept(new JetVisitorVoid() {
@Override
public void visitNamedFunction(JetNamedFunction function) {
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function, context.getTrace());
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(namespaceLike.getOwnerForChildren(), scopeForFunctions, function, context.getTrace());
namespaceLike.addFunctionDescriptor(functionDescriptor);
context.getFunctions().put(function, functionDescriptor);
context.getDeclaringScopes().put(function, scopeForFunctions);
@@ -152,7 +152,7 @@ public class DeclarationResolver {
@Override
public void visitProperty(JetProperty property) {
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(namespaceLike, scopeForPropertyInitializers, property, context.getTrace());
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(namespaceLike.getOwnerForChildren(), scopeForPropertyInitializers, property, context.getTrace());
namespaceLike.addPropertyDescriptor(propertyDescriptor);
context.getProperties().put(property, propertyDescriptor);
context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
@@ -166,7 +166,7 @@ public class DeclarationResolver {
@Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration), context.getTrace());
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), context.getTrace());
namespaceLike.addPropertyDescriptor(propertyDescriptor);
}
@@ -169,9 +169,15 @@ public class TopDownAnalyzer {
@NotNull Project project,
@NotNull final BindingTrace trace,
@NotNull JetScope outerScope,
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull final DeclarationDescriptor containingDeclaration,
@NotNull JetObjectDeclaration object) {
process(project, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) {
process(project, trace, outerScope, new NamespaceLike() {
@NotNull
@Override
public DeclarationDescriptor getOwnerForChildren() {
return containingDeclaration;
}
@Override
public NamespaceDescriptorImpl getNamespace(String name) {
@@ -123,7 +123,7 @@ public class TypeHierarchyResolver {
@Override
public void visitClass(JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, outerScope, getClassKind(klass));
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner.getOwnerForChildren(), outerScope, getClassKind(klass));
context.getTrace().record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(klass), mutableClassDescriptor);
if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) {
@@ -166,7 +166,7 @@ public class TypeHierarchyResolver {
}
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner, JetScope scope, ClassKind classKind) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, scope, classKind) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner.getOwnerForChildren(), scope, classKind) {
@Override
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
return ClassObjectStatus.NOT_ALLOWED;
@@ -237,7 +237,7 @@ public class TypeHierarchyResolver {
currentOwner = namespaceDescriptor;
context.getTrace().record(REFERENCE_TARGET, nameExpression, currentOwner);
context.getTrace().record(REFERENCE_TARGET, nameExpression, currentOwner.getOwnerForChildren());
context.getTrace().record(RESOLUTION_SCOPE, nameExpression, outerScope);
outerScope = namespaceDescriptor.getMemberScope();
@@ -254,7 +254,7 @@ public class TypeHierarchyResolver {
NamespaceDescriptorImpl namespaceDescriptor = owner.getNamespace(name);
if (namespaceDescriptor == null) {
namespaceDescriptor = new NamespaceDescriptorImpl(
owner.getOriginal(),
owner.getOwnerForChildren(),
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
name
);