001 /*
002 * Copyright 2010-2014 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.lazy.descriptors;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.jet.lang.descriptors.*;
022 import org.jetbrains.jet.lang.psi.JetDeclaration;
023 import org.jetbrains.jet.lang.psi.JetFile;
024 import org.jetbrains.jet.lang.resolve.DescriptorUtils;
025 import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
026 import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
027 import org.jetbrains.jet.lang.resolve.name.Name;
028 import org.jetbrains.jet.lang.resolve.scopes.JetScope;
029
030 import java.util.Collection;
031 import java.util.Collections;
032 import java.util.Set;
033
034 public class LazyPackageMemberScope extends AbstractLazyMemberScope<PackageFragmentDescriptor, PackageMemberDeclarationProvider> {
035
036 public LazyPackageMemberScope(@NotNull ResolveSession resolveSession,
037 @NotNull PackageMemberDeclarationProvider declarationProvider,
038 @NotNull PackageFragmentDescriptor thisPackage) {
039 super(resolveSession, declarationProvider, thisPackage);
040 }
041
042 @Nullable
043 @Override
044 public PackageViewDescriptor getPackage(@NotNull Name name) {
045 return null;
046 }
047
048 @Override
049 public ClassifierDescriptor getClassifier(@NotNull Name name) {
050 // TODO: creating an FqName every time may be a performance problem
051 Name actualName = resolveSession.resolveClassifierAlias(DescriptorUtils.getFqNameSafe(thisDescriptor), name);
052 return super.getClassifier(actualName);
053 }
054
055 @NotNull
056 @Override
057 protected JetScope getScopeForMemberDeclarationResolution(JetDeclaration declaration) {
058 return resolveSession.getScopeProvider().getFileScope((JetFile) declaration.getContainingFile());
059 }
060
061 @Override
062 protected ReceiverParameterDescriptor getImplicitReceiver() {
063 return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
064 }
065
066 @Override
067 protected void getNonDeclaredFunctions(@NotNull Name name, @NotNull Set<FunctionDescriptor> result) {
068 // No extra functions
069 }
070
071 @Override
072 protected void getNonDeclaredProperties(@NotNull Name name, @NotNull Set<VariableDescriptor> result) {
073 // No extra properties
074 }
075
076 @NotNull
077 @Override
078 protected Collection<DeclarationDescriptor> computeExtraDescriptors() {
079 return Collections.emptyList();
080 }
081
082 @Override
083 public String toString() {
084 // Do not add details here, they may compromise the laziness during debugging
085 return "lazy scope for package " + thisDescriptor.getName();
086 }
087 }