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 com.google.common.base.Predicate;
020    import com.google.common.base.Predicates;
021    import com.google.common.collect.Collections2;
022    import org.jetbrains.annotations.NotNull;
023    import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
024    import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
025    import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
026    import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
027    import org.jetbrains.jet.lang.resolve.name.Name;
028    
029    import java.util.Collection;
030    import java.util.Collections;
031    import java.util.List;
032    
033    public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
034        private static final Predicate<Object> IS_CLASS = Predicates.instanceOf(ClassDescriptor.class);
035    
036        private final JetScope actualScope;
037    
038        public InnerClassesScopeWrapper(@NotNull JetScope actualScope) {
039            this.actualScope = actualScope;
040        }
041    
042        @NotNull
043        @Override
044        protected JetScope getWorkerScope() {
045            return actualScope;
046        }
047    
048        @Override
049        public ClassifierDescriptor getClassifier(@NotNull Name name) {
050            ClassifierDescriptor classifier = actualScope.getClassifier(name);
051            return IS_CLASS.apply(classifier) ? classifier : null;
052        }
053    
054        @NotNull
055        @Override
056        public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
057            return Collections2.filter(actualScope.getDeclarationsByLabel(labelName), IS_CLASS);
058        }
059    
060        @NotNull
061        @Override
062        public Collection<DeclarationDescriptor> getAllDescriptors() {
063            return Collections2.filter(actualScope.getAllDescriptors(), IS_CLASS);
064        }
065    
066        @NotNull
067        @Override
068        public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
069            return Collections.emptyList();
070        }
071    
072        @Override
073        public String toString() {
074            return "Classes from " + actualScope;
075        }
076    }