update copyrights
[fedora-idea.git] / platform / lang-impl / src / com / intellij / psi / impl / PomTargetPsiElementImpl.java
blob987cfed9dd861318cf7d609dece467d0a4ec5688
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.
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;
29 import javax.swing.*;
31 /**
32 * @author peter
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) {
43 super(null);
44 myProject = project;
45 myTarget = target;
48 @NotNull
49 public PomTarget getTarget() {
50 return myTarget;
53 @Override
54 public String getName() {
55 if (myTarget instanceof PomNamedTarget) {
56 return ((PomNamedTarget)myTarget).getName();
58 return null;
61 @Override
62 public boolean isWritable() {
63 if (myTarget instanceof PomRenameableTarget) {
64 return ((PomRenameableTarget)myTarget).isWritable();
66 return false;
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);
77 if (icon != null) {
78 return icon;
83 if (myTarget instanceof PsiTarget) {
84 return ((PsiTarget)myTarget).getNavigationElement().getIcon(0);
86 return null;
89 @Override
90 public boolean isValid() {
91 if (myTarget instanceof PsiTarget) {
92 return ((PsiTarget)myTarget).getNavigationElement().isValid();
95 return myTarget.isValid();
98 @Override
99 public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
100 if (myTarget instanceof PomRenameableTarget) {
101 ((PomRenameableTarget)myTarget).setName(name);
102 return this;
104 throw new UnsupportedOperationException("Cannot rename " + myTarget);
107 @Override
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;
116 return true;
119 @Override
120 public int hashCode() {
121 return myTarget.hashCode();
124 @Override
125 public boolean isEquivalentTo(PsiElement another) {
126 return equals(another);
129 @Override
130 public PsiElement getContext() {
131 if (myTarget instanceof PsiTarget) {
132 return ((PsiTarget)myTarget).getNavigationElement();
134 return null;
137 @Nullable
138 public PsiElement getParent() {
139 return null;
142 @Override
143 public void navigate(boolean requestFocus) {
144 myTarget.navigate(requestFocus);
147 @Override
148 public boolean canNavigate() {
149 return myTarget.canNavigate();
152 @Override
153 public boolean canNavigateToSource() {
154 return myTarget.canNavigateToSource();
157 @Override
158 @Nullable
159 public PsiFile getContainingFile() {
160 if (myTarget instanceof PsiTarget) {
161 return ((PsiTarget)myTarget).getNavigationElement().getContainingFile();
163 return null;
166 @NotNull
167 @Override
168 public Project getProject() {
169 return myProject;