diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractNamespaceDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractNamespaceDescriptorImpl.java index ea495607b24..97aeafbb5b2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractNamespaceDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractNamespaceDescriptorImpl.java @@ -27,7 +27,7 @@ import java.util.List; /** * @author abreslav */ -public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorImpl implements NamespaceDescriptor { +public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorNonRootImpl implements NamespaceDescriptor { private NamespaceType namespaceType; public AbstractNamespaceDescriptorImpl( @@ -44,6 +44,7 @@ public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescrip } @Override + @NotNull public NamespaceDescriptorParent getContainingDeclaration() { return (NamespaceDescriptorParent) super.getContainingDeclaration(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java index 53100ad2694..eadb34b2156 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java @@ -28,7 +28,7 @@ import java.util.Set; /** * @author abreslav */ -public interface CallableDescriptor extends DeclarationDescriptorWithVisibility { +public interface CallableDescriptor extends DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot { @NotNull ReceiverDescriptor getReceiverParameter(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java index 23bf950930e..837d71f6bc7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java @@ -32,7 +32,7 @@ import java.util.*; /** * @author abreslav */ -public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements ClassDescriptorFromSource { +public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implements ClassDescriptorFromSource { private TypeConstructor typeConstructor; private JetScope memberDeclarations; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassOrNamespaceDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassOrNamespaceDescriptor.java index 2c3ed9b09ed..78d21a88f8f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassOrNamespaceDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassOrNamespaceDescriptor.java @@ -19,5 +19,5 @@ package org.jetbrains.jet.lang.descriptors; /** * @author Stepan Koltsov */ -public interface ClassOrNamespaceDescriptor extends DeclarationDescriptor { +public interface ClassOrNamespaceDescriptor extends DeclarationDescriptorNonRoot { } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassifierDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassifierDescriptor.java index f2b0db00f6b..519aaa4828d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassifierDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassifierDescriptor.java @@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.types.TypeConstructor; /** * @author abreslav */ -public interface ClassifierDescriptor extends DeclarationDescriptor { +public interface ClassifierDescriptor extends DeclarationDescriptorNonRoot { @NotNull TypeConstructor getTypeConstructor(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java index 189b140577f..fe049778a17 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.lang.descriptors; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.name.Name; @@ -26,19 +25,16 @@ import org.jetbrains.jet.resolve.DescriptorRenderer; import java.util.List; /** - * @author abreslav + * @author Stepan Koltsov */ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements Named, DeclarationDescriptor { @NotNull private final Name name; - private final DeclarationDescriptor containingDeclaration; - public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List annotations, @NotNull Name name) { + public DeclarationDescriptorImpl(@NotNull List annotations, @NotNull Name name) { super(annotations); - this.name = name; - this.containingDeclaration = containingDeclaration; } @NotNull @@ -53,11 +49,6 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements return this; } - @Override - public DeclarationDescriptor getContainingDeclaration() { - return containingDeclaration; - } - @Override public void acceptVoid(DeclarationDescriptorVisitor visitor) { accept(visitor, null); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRoot.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRoot.java new file mode 100644 index 00000000000..123019df146 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRoot.java @@ -0,0 +1,30 @@ +/* + * 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.descriptors; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Stepan Koltsov + */ +public interface DeclarationDescriptorNonRoot extends DeclarationDescriptor { + + @Override + @NotNull + DeclarationDescriptor getContainingDeclaration(); + +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRootImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRootImpl.java new file mode 100644 index 00000000000..480cd02958f --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRootImpl.java @@ -0,0 +1,51 @@ +/* + * 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.descriptors; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.name.Name; + +import java.util.List; + +/** + * @author abreslav + */ +public abstract class DeclarationDescriptorNonRootImpl + extends DeclarationDescriptorImpl + implements DeclarationDescriptorNonRoot { + + @NotNull + private final DeclarationDescriptor containingDeclaration; + + public DeclarationDescriptorNonRootImpl( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + @NotNull Name name) { + super(annotations, name); + + this.containingDeclaration = containingDeclaration; + } + + @Override + @NotNull + public DeclarationDescriptor getContainingDeclaration() { + return containingDeclaration; + } + +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java index f0df94e84be..a342dce8bcb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java @@ -39,7 +39,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor /** * @author abreslav */ -public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor { +public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRootImpl implements FunctionDescriptor { protected List typeParameters; protected List unsubstitutedValueParameters; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MemberDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MemberDescriptor.java index 76ceb86ca5e..6d694233955 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MemberDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MemberDescriptor.java @@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull; /** * @author abreslav */ -public interface MemberDescriptor extends DeclarationDescriptor, DeclarationDescriptorWithVisibility { +public interface MemberDescriptor extends DeclarationDescriptorNonRoot, DeclarationDescriptorWithVisibility { @NotNull Modality getModality(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ModuleDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ModuleDescriptor.java index d483071fc2b..f7e51290833 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ModuleDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ModuleDescriptor.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.lang.descriptors; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.TypeSubstitutor; @@ -29,8 +30,8 @@ import java.util.Collections; public class ModuleDescriptor extends DeclarationDescriptorImpl implements ClassOrNamespaceDescriptor, NamespaceDescriptorParent { private NamespaceDescriptor rootNamepsace; - public ModuleDescriptor(Name name) { - super(null, Collections.emptyList(), name); + public ModuleDescriptor(@NotNull Name name) { + super(Collections.emptyList(), name); if (!name.isSpecial()) { throw new IllegalArgumentException("module name must be special: " + name); } @@ -43,6 +44,12 @@ public class ModuleDescriptor extends DeclarationDescriptorImpl implements Class this.rootNamepsace = rootNs; } + @Override + @Nullable + public DeclarationDescriptor getContainingDeclaration() { + return null; + } + public NamespaceDescriptor getRootNamespace() { return rootNamepsace; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java index 844c47fbaa0..493ffbccaf4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java @@ -30,7 +30,7 @@ import java.util.Set; /** * @author abreslav */ -public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorImpl implements FunctionDescriptor, MemberDescriptor { +public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorNonRootImpl implements FunctionDescriptor, MemberDescriptor { private final boolean hasBody; private final boolean isDefault; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java index eb9ff460d60..bbc88078e17 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java @@ -31,7 +31,7 @@ import java.util.List; /** * @author Stepan Koltsov */ -public class ScriptDescriptor extends DeclarationDescriptorImpl { +public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl { private static final Name NAME = Name.special("