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.Name;
023    import org.jetbrains.jet.utils.Printer;
024    
025    import java.util.Collection;
026    import java.util.List;
027    
028    /**
029     * Introduces a simple wrapper for internal scope.
030     */
031    public abstract class AbstractScopeAdapter implements JetScope {
032        @NotNull
033        protected abstract JetScope getWorkerScope();
034    
035        @NotNull
036        @Override
037        public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
038            return getWorkerScope().getImplicitReceiversHierarchy();
039        }
040    
041        @NotNull
042        @Override
043        public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
044            return getWorkerScope().getFunctions(name);
045        }
046    
047        @Override
048        public PackageViewDescriptor getPackage(@NotNull Name name) {
049            return getWorkerScope().getPackage(name);
050        }
051    
052        @Override
053        public ClassifierDescriptor getClassifier(@NotNull Name name) {
054            return getWorkerScope().getClassifier(name);
055        }
056    
057        @NotNull
058        @Override
059        public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
060            return getWorkerScope().getProperties(name);
061        }
062    
063        @Override
064        public VariableDescriptor getLocalVariable(@NotNull Name name) {
065            return getWorkerScope().getLocalVariable(name);
066        }
067    
068        @NotNull
069        @Override
070        public DeclarationDescriptor getContainingDeclaration() {
071            return getWorkerScope().getContainingDeclaration();
072        }
073    
074        @NotNull
075        @Override
076        public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
077            return getWorkerScope().getDeclarationsByLabel(labelName);
078        }
079    
080        @NotNull
081        @Override
082        public Collection<DeclarationDescriptor> getAllDescriptors() {
083            return getWorkerScope().getAllDescriptors();
084        }
085    
086        @NotNull
087        @Override
088        public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
089            return getWorkerScope().getOwnDeclaredDescriptors();
090        }
091    
092        @TestOnly
093        @Override
094        public void printScopeStructure(@NotNull Printer p) {
095            p.println(getClass().getSimpleName(), " {");
096            p.pushIndent();
097    
098            p.print("worker =");
099            getWorkerScope().printScopeStructure(p.withholdIndentOnce());
100    
101            p.popIndent();
102            p.println("}");
103        }
104    }