update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / ide / navigationToolbar / JavaNavBarExtension.java
blobee727388dac525066db291a69e97ab66bfebb509
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.
18 * User: anna
19 * Date: 04-Feb-2008
21 package com.intellij.ide.navigationToolbar;
23 import com.intellij.analysis.AnalysisScopeBundle;
24 import com.intellij.lang.StdLanguages;
25 import com.intellij.psi.*;
26 import com.intellij.psi.presentation.java.ClassPresentationUtil;
27 import com.intellij.openapi.roots.ProjectFileIndex;
28 import com.intellij.openapi.roots.ProjectRootManager;
29 import com.intellij.openapi.vfs.VirtualFile;
30 import org.jetbrains.annotations.Nullable;
32 public class JavaNavBarExtension implements NavBarModelExtension{
33 public String getPresentableText(final Object object) {
34 if (object instanceof PsiClass) {
35 return ClassPresentationUtil.getNameForClass((PsiClass)object, false);
37 else if (object instanceof PsiPackage) {
38 final String name = ((PsiPackage)object).getName();
39 return name != null ? name : AnalysisScopeBundle.message("dependencies.tree.node.default.package.abbreviation");
41 return null;
44 public PsiElement getParent(final PsiElement psiElement) {
45 if (psiElement instanceof PsiPackage) {
46 final PsiPackage parentPackage = ((PsiPackage)psiElement).getParentPackage();
47 if (parentPackage != null && parentPackage.getQualifiedName().length() > 0) {
48 return parentPackage;
51 return null;
55 @Nullable
56 public PsiElement adjustElement(final PsiElement psiElement) {
57 final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
58 final PsiFile containingFile = psiElement.getContainingFile();
59 if (containingFile != null) {
60 final VirtualFile file = containingFile.getVirtualFile();
61 if (file != null && (index.isInSourceContent(file) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
62 if (psiElement instanceof PsiJavaFile) {
63 final PsiJavaFile psiJavaFile = (PsiJavaFile)psiElement;
64 if (psiJavaFile.getViewProvider().getBaseLanguage() == StdLanguages.JAVA) {
65 final PsiClass[] psiClasses = psiJavaFile.getClasses();
66 if (psiClasses.length == 1) {
67 return psiClasses[0];
71 if (psiElement instanceof PsiClass) return psiElement;
73 return containingFile;
75 return psiElement.isPhysical() ? psiElement : null;