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