001    /*
002     * Copyright 2010-2013 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.jet.lang.resolve.scopes;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.TestOnly;
021    import org.jetbrains.jet.lang.descriptors.*;
022    import org.jetbrains.jet.lang.resolve.name.LabelName;
023    import org.jetbrains.jet.lang.resolve.name.Name;
024    import org.jetbrains.jet.utils.Printer;
025    
026    import java.util.Collection;
027    import java.util.List;
028    
029    /**
030     * Introduces a simple wrapper for internal scope.
031     */
032    public abstract class AbstractScopeAdapter implements JetScope {
033        @NotNull
034        protected abstract JetScope getWorkerScope();
035    
036        @NotNull
037        @Override
038        public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
039            return getWorkerScope().getImplicitReceiversHierarchy();
040        }
041    
042        @NotNull
043        @Override
044        public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
045            return getWorkerScope().getFunctions(name);
046        }
047    
048        @Override
049        public PackageViewDescriptor getPackage(@NotNull Name name) {
050            return getWorkerScope().getPackage(name);
051        }
052    
053        @Override
054        public ClassifierDescriptor getClassifier(@NotNull Name name) {
055            return getWorkerScope().getClassifier(name);
056        }
057    
058        @NotNull
059        @Override
060        public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
061            return getWorkerScope().getProperties(name);
062        }
063    
064        @Override
065        public VariableDescriptor getLocalVariable(@NotNull Name name) {
066            return getWorkerScope().getLocalVariable(name);
067        }
068    
069        @NotNull
070        @Override
071        public DeclarationDescriptor getContainingDeclaration() {
072            return getWorkerScope().getContainingDeclaration();
073        }
074    
075        @NotNull
076        @Override
077        public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
078            return getWorkerScope().getDeclarationsByLabel(labelName);
079        }
080    
081        @NotNull
082        @Override
083        public Collection<DeclarationDescriptor> getAllDescriptors() {
084            return getWorkerScope().getAllDescriptors();
085        }
086    
087        @NotNull
088        @Override
089        public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
090            return getWorkerScope().getOwnDeclaredDescriptors();
091        }
092    
093        @TestOnly
094        @Override
095        public void printScopeStructure(@NotNull Printer p) {
096            p.println(getClass().getSimpleName(), " {");
097            p.pushIndent();
098    
099            p.print("worker =");
100            getWorkerScope().printScopeStructure(p.withholdIndentOnce());
101    
102            p.popIndent();
103            p.println("}");
104        }
105    }