update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / resolve / reference / impl / providers / PackageReferenceSet.java
blob4290343542f1487d56846969c8442d887ffbb0f0
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.psi.impl.source.resolve.reference.impl.providers;
19 import com.intellij.openapi.util.Comparing;
20 import com.intellij.openapi.util.TextRange;
21 import com.intellij.psi.PsiElement;
22 import com.intellij.psi.PsiPackage;
23 import com.intellij.psi.ResolveResult;
24 import com.intellij.psi.util.ReferenceSetBase;
25 import com.intellij.util.NullableFunction;
26 import com.intellij.util.containers.ContainerUtil;
27 import org.jetbrains.annotations.NotNull;
29 import java.util.Collection;
30 import java.util.Collections;
32 /**
33 * @author Dmitry Avdeev
35 public class PackageReferenceSet extends ReferenceSetBase<PsiPackageReference> {
37 public PackageReferenceSet(@NotNull final String str, @NotNull final PsiElement element, final int startInElement) {
38 super(str, element, startInElement, DOT_SEPARATOR);
41 @NotNull
42 protected PsiPackageReference createReference(final TextRange range, final int index) {
43 return new PsiPackageReference(this, range, index);
46 public Collection<PsiPackage> resolvePackageName(PsiPackage context, String packageName) {
47 for (PsiPackage aPackage : context.getSubPackages()) {
48 if (Comparing.equal(aPackage.getName(), packageName)) {
49 return Collections.singleton(aPackage);
52 return Collections.emptyList();
55 public Collection<PsiPackage> resolvePackage() {
56 final PsiPackageReference packageReference = getLastReference();
57 if (packageReference == null) {
58 return Collections.emptyList();
60 return ContainerUtil.map2List(packageReference.multiResolve(false), new NullableFunction<ResolveResult, PsiPackage>() {
61 public PsiPackage fun(final ResolveResult resolveResult) {
62 return (PsiPackage)resolveResult.getElement();
64 });