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