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
.psi
.impl
;
18 import com
.intellij
.ide
.IconProvider
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.pom
.*;
21 import com
.intellij
.psi
.PsiElement
;
22 import com
.intellij
.psi
.PsiFile
;
23 import com
.intellij
.psi
.PsiTarget
;
24 import com
.intellij
.util
.IncorrectOperationException
;
25 import org
.jetbrains
.annotations
.NonNls
;
26 import org
.jetbrains
.annotations
.NotNull
;
27 import org
.jetbrains
.annotations
.Nullable
;
34 public class PomTargetPsiElementImpl
extends RenameableFakePsiElement
implements PomTargetPsiElement
{
35 private final PomTarget myTarget
;
36 private final Project myProject
;
38 public PomTargetPsiElementImpl(@NotNull PsiTarget target
) {
39 this(target
.getNavigationElement().getProject(), target
);
42 public PomTargetPsiElementImpl(@NotNull Project project
, @NotNull PomTarget target
) {
49 public PomTarget
getTarget() {
54 public String
getName() {
55 if (myTarget
instanceof PomNamedTarget
) {
56 return ((PomNamedTarget
)myTarget
).getName();
62 public boolean isWritable() {
63 if (myTarget
instanceof PomRenameableTarget
) {
64 return ((PomRenameableTarget
)myTarget
).isWritable();
69 public String
getTypeName() {
70 throw new UnsupportedOperationException("Method getTypeName is not yet implemented for " + myTarget
.getClass().getName() + "; see PomDescriptionProvider");
73 public Icon
getIcon() {
74 for (IconProvider iconProvider
: IconProvider
.EXTENSION_POINT_NAME
.getExtensions()) {
75 if (iconProvider
instanceof PomIconProvider
) {
76 final Icon icon
= ((PomIconProvider
)iconProvider
).getIcon(myTarget
, 0);
83 if (myTarget
instanceof PsiTarget
) {
84 return ((PsiTarget
)myTarget
).getNavigationElement().getIcon(0);
90 public boolean isValid() {
91 if (myTarget
instanceof PsiTarget
) {
92 return ((PsiTarget
)myTarget
).getNavigationElement().isValid();
95 return myTarget
.isValid();
99 public PsiElement
setName(@NonNls @NotNull String name
) throws IncorrectOperationException
{
100 if (myTarget
instanceof PomRenameableTarget
) {
101 ((PomRenameableTarget
)myTarget
).setName(name
);
104 throw new UnsupportedOperationException("Cannot rename " + myTarget
);
108 public boolean equals(Object o
) {
109 if (this == o
) return true;
110 if (o
== null || getClass() != o
.getClass()) return false;
112 PomTargetPsiElementImpl that
= (PomTargetPsiElementImpl
)o
;
114 if (!myTarget
.equals(that
.myTarget
)) return false;
120 public int hashCode() {
121 return myTarget
.hashCode();
125 public boolean isEquivalentTo(PsiElement another
) {
126 return equals(another
);
130 public PsiElement
getContext() {
131 if (myTarget
instanceof PsiTarget
) {
132 return ((PsiTarget
)myTarget
).getNavigationElement();
138 public PsiElement
getParent() {
143 public void navigate(boolean requestFocus
) {
144 myTarget
.navigate(requestFocus
);
148 public boolean canNavigate() {
149 return myTarget
.canNavigate();
153 public boolean canNavigateToSource() {
154 return myTarget
.canNavigateToSource();
159 public PsiFile
getContainingFile() {
160 if (myTarget
instanceof PsiTarget
) {
161 return ((PsiTarget
)myTarget
).getNavigationElement().getContainingFile();
168 public Project
getProject() {