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.
16 package com
.intellij
.refactoring
;
18 import com
.intellij
.psi
.JavaPsiFacade
;
19 import com
.intellij
.psi
.PsiDirectory
;
20 import com
.intellij
.psi
.PsiManager
;
21 import com
.intellij
.psi
.PsiPackage
;
22 import org
.jetbrains
.annotations
.NotNull
;
25 * Represents a package.
28 public class PackageWrapper
{
29 private final PsiManager myManager
;
30 @NotNull private final String myQualifiedName
;
32 public PackageWrapper(PsiManager manager
, @NotNull String qualifiedName
) {
34 myQualifiedName
= qualifiedName
;
37 public PackageWrapper(PsiPackage aPackage
) {
38 myManager
= aPackage
.getManager();
39 myQualifiedName
= aPackage
.getQualifiedName();
42 public PsiManager
getManager() { return myManager
; }
44 public PsiDirectory
[] getDirectories() {
45 final PsiPackage aPackage
= JavaPsiFacade
.getInstance(myManager
.getProject()).findPackage(myQualifiedName
);
46 if (aPackage
!= null) {
47 return aPackage
.getDirectories();
49 return PsiDirectory
.EMPTY_ARRAY
;
53 public boolean exists() {
54 return JavaPsiFacade
.getInstance(myManager
.getProject()).findPackage(myQualifiedName
) != null;
58 public String
getQualifiedName() {
59 return myQualifiedName
;
62 public boolean equalToPackage(PsiPackage aPackage
) {
63 return aPackage
!= null && myQualifiedName
.equals(aPackage
.getQualifiedName());
66 public static PackageWrapper
create(PsiPackage aPackage
) {
67 return new PackageWrapper(aPackage
);