From eab930dd855d85b36f247575ea082ef377c73e78 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 12 Nov 2015 21:08:36 +0100 Subject: [PATCH] Cleanup (I18N, warnings) --- .../impl/nodes/AbstractModuleNode.java | 56 +++++++-------- .../impl/nodes/NamedLibraryElementNode.java | 70 +++++++++++-------- .../impl/nodes/PsiDirectoryNode.java | 5 +- .../projectView/impl/nodes/PsiFileNode.java | 8 +-- .../packageDependencies/ui/ModuleNode.java | 12 ++-- .../src/messages/ActionsBundle.properties | 2 + 6 files changed, 81 insertions(+), 72 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java index 58591a139949..9e70d67bf289 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package com.intellij.ide.projectView.impl.nodes; import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.ProjectViewNode; import com.intellij.ide.projectView.ViewSettings; +import com.intellij.idea.ActionsBundle; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; @@ -32,6 +33,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; public abstract class AbstractModuleNode extends ProjectViewNode implements NavigatableWithText { protected AbstractModuleNode(Project project, Module module, ViewSettings viewSettings) { @@ -40,32 +42,31 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme @Override public void update(PresentationData presentation) { - if (getValue().isDisposed()) { + Module module = getValue(); + if (module == null || module.isDisposed()) { setValue(null); return; } - presentation.setPresentableText(getValue().getName()); + + presentation.setPresentableText(module.getName()); if (showModuleNameInBold()) { - presentation.addText(getValue().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); + presentation.addText(module.getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } - presentation.setIcon(ModuleType.get(getValue()).getIcon()); + presentation.setIcon(ModuleType.get(module).getIcon()); + + presentation.setTooltip(ModuleType.get(module).getName()); } protected boolean showModuleNameInBold() { return true; } - - @Override - public String getTestPresentation() { - return "Module"; - } - @NotNull @Override public Collection getRoots() { - return Arrays.asList(ModuleRootManager.getInstance(getValue()).getContentRoots()); + Module module = getValue(); + return module != null ? Arrays.asList(ModuleRootManager.getInstance(module).getContentRoots()) : Collections.emptyList(); } @Override @@ -73,24 +74,17 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme Module module = getValue(); if (module == null || module.isDisposed()) return false; - final VirtualFile testee; if (file.getFileSystem() instanceof JarFileSystem) { - testee = JarFileSystem.getInstance().getVirtualFileForJar(file); - if (testee == null) return false; + VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(file); + if (local == null) return false; + file = local; } - else { - testee = file; - } - for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { - if (VfsUtilCore.isAncestor(root, testee, false)) return true; - } - return false; - } - @Override - public String getToolTip() { - final Module module = getValue(); - return ModuleType.get(module).getName(); + for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { + if (VfsUtilCore.isAncestor(root, file, false)) return true; + } + + return false; } @Override @@ -103,11 +97,17 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme @Override public String getNavigateActionText(boolean focusEditor) { - return "Open Module Settings"; + return ActionsBundle.message("action.ModuleSettings.navigate"); } @Override public boolean canNavigate() { return ProjectSettingsService.getInstance(myProject).canOpenModuleSettings() && getValue() != null; } + + @SuppressWarnings("deprecation") + @Override + public String getTestPresentation() { + return "Module"; + } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/NamedLibraryElementNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/NamedLibraryElementNode.java index 001159faca81..2eef9d4e312f 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/NamedLibraryElementNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/NamedLibraryElementNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.projectView.impl.nodes; import com.intellij.icons.AllIcons; @@ -22,6 +21,7 @@ import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.ProjectViewNode; import com.intellij.ide.projectView.ViewSettings; import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.idea.ActionsBundle; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkType; @@ -47,16 +47,14 @@ public class NamedLibraryElementNode extends ProjectViewNode getChildren() { - final List children = new ArrayList(); - LibraryGroupNode.addLibraryChildren(getValue().getOrderEntry(), children, getProject(), this); + List children = new ArrayList(); + NamedLibraryElement libraryElement = getValue(); + if (libraryElement != null) { + LibraryGroupNode.addLibraryChildren(libraryElement.getOrderEntry(), children, getProject(), this); + } return children; } - @Override - public String getTestPresentation() { - return "Library: " + getValue().getName(); - } - private static Icon getJdkIcon(JdkOrderEntry entry) { final Sdk sdk = entry.getJdk(); if (sdk == null) { @@ -68,40 +66,39 @@ public class NamedLibraryElementNode extends ProjectViewNode implements Navig if (file != null && project != null) { if (ProjectRootsUtil.isModuleContentRoot(file, project) || ProjectRootsUtil.isModuleSourceRoot(file, project)) { - return "Open Module Settings"; + return ActionsBundle.message("action.ModuleSettings.navigate"); } if (ProjectRootsUtil.isLibraryRoot(file, project)) { - return "Open Library Settings"; + return ActionsBundle.message("action.LibrarySettings.navigate"); } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java index 068a97160c16..5f4d3a783638 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.ViewSettings; import com.intellij.ide.projectView.impl.ProjectRootsUtil; import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.idea.ActionsBundle; import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; @@ -134,10 +135,7 @@ public class PsiFileNode extends BasePsiNode implements NavigatableWith @Override public String getNavigateActionText(boolean focusEditor) { - if (isNavigatableLibraryRoot()) { - return "Open Library Settings"; - } - return null; + return isNavigatableLibraryRoot() ? ActionsBundle.message("action.LibrarySettings.navigate") : null; } @Override diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java index abfd133461a0..5d49f81da607 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.packageDependencies.ui; import com.intellij.analysis.AnalysisScopeBundle; +import com.intellij.idea.ActionsBundle; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; @@ -27,7 +27,7 @@ import com.intellij.psi.PsiFile; import javax.swing.*; import java.util.Set; -public class ModuleNode extends PackageDependenciesNode implements NavigatableWithText{ +public class ModuleNode extends PackageDependenciesNode implements NavigatableWithText { private final Module myModule; public ModuleNode(Module module) { @@ -65,6 +65,7 @@ public class ModuleNode extends PackageDependenciesNode implements NavigatableWi return myModule == null || myModule.isDisposed() ? super.getIcon() : ModuleType.get(myModule).getIcon(); } + @Override public String toString() { return myModule == null ? AnalysisScopeBundle.message("unknown.node.text") : myModule.getName(); } @@ -90,15 +91,14 @@ public class ModuleNode extends PackageDependenciesNode implements NavigatableWi if (!(o instanceof ModuleNode)) return false; final ModuleNode moduleNode = (ModuleNode)o; - return Comparing.equal(myModule, moduleNode.myModule); } + @Override public int hashCode() { return myModule == null ? 0 : myModule.hashCode(); } - @Override public boolean isValid() { return myModule != null && !myModule.isDisposed(); @@ -106,6 +106,6 @@ public class ModuleNode extends PackageDependenciesNode implements NavigatableWi @Override public String getNavigateActionText(boolean focusEditor) { - return "Open Module Settings"; + return ActionsBundle.message("action.ModuleSettings.navigate"); } } diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 883ca8331e24..09a1e69d0d6d 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -1491,3 +1491,5 @@ action.StructuralSearchPlugin.StructuralSearchAction.description=Structural Sear action.StructuralSearchPlugin.StructuralReplaceAction.text=Repla_ce Structurally... action.StructuralSearchPlugin.StructuralReplaceAction.description=Structural Replace +action.ModuleSettings.navigate=Open Module Settings +action.LibrarySettings.navigate=Open Library Settings \ No newline at end of file