Cleanup (formatting; unneeded assertions)

This commit is contained in:
Roman Shevchenko
2015-01-19 18:05:51 +01:00
parent 4fb1124d2d
commit 028e1bd18c
5 changed files with 56 additions and 50 deletions
@@ -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.
@@ -175,7 +175,6 @@ public final class NavigationUtil {
return false;
}
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) {
if (!elt.isValid()) return false;
elt = elt.getNavigationElement();
@@ -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.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.actions;
import com.intellij.codeInsight.navigation.NavigationUtil;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.structureView.StructureView;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.StructureViewTreeElement;
@@ -29,7 +29,6 @@ import com.intellij.lang.LanguageStructureViewBuilder;
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.navigation.AnonymousElementProvider;
import com.intellij.navigation.ChooseByNameRegistry;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.AccessToken;
@@ -53,34 +52,38 @@ import com.intellij.psi.util.PsiUtilCore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.awt.event.InputEvent;
import java.util.ArrayList;
import java.util.List;
public class GotoClassAction extends GotoActionBase implements DumbAware {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null) return;
if (!DumbService.getInstance(project).isDumb()) {
super.actionPerformed(e);
}
else {
DumbService.getInstance(project)
.showDumbModeNotification("Goto Class action is not available until indices are built, using Goto File instead");
ActionManager.getInstance()
.tryToExecute(ActionManager.getInstance().getAction(GotoFileAction.ID), ActionCommand.getInputEvent(GotoFileAction.ID),
e.getData(PlatformDataKeys.CONTEXT_COMPONENT), e.getPlace(), true);
DumbService.getInstance(project).showDumbModeNotification(IdeBundle.message("go.to.class.dumb.mode.message"));
AnAction action = ActionManager.getInstance().getAction(GotoFileAction.ID);
InputEvent event = ActionCommand.getInputEvent(GotoFileAction.ID);
Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
ActionManager.getInstance().tryToExecute(action, event, component, e.getPlace(), true);
}
}
@Override
public void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
public void gotoActionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null) return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class");
PsiDocumentManager.getInstance(project).commitAllDocuments();
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class");
final GotoClassModel2 model = new GotoClassModel2(project);
showNavigationPopup(e, model, new GotoActionCallback<Language>() {
@Override
@@ -95,14 +98,16 @@ public class GotoClassAction extends GotoActionBase implements DumbAware {
if (element instanceof PsiElement) {
final PsiElement psiElement = getElement(((PsiElement)element), popup);
final VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);
if (popup.getLinePosition() != -1 && file != null) {
Navigatable n = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition()).setUseCurrentWindow(
popup.isOpenInCurrentWindowRequested());
if (file != null && popup.getLinePosition() != -1) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
if (n.canNavigate()) {
n.navigate(true);
return;
}
}
if (psiElement != null && file != null && popup.getMemberPattern() != null) {
NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
Navigatable member = findMember(popup.getMemberPattern(), psiElement, file);
@@ -121,10 +126,11 @@ public class GotoClassAction extends GotoActionBase implements DumbAware {
token.finish();
}
}
}, "Classes matching pattern", true);
}, IdeBundle.message("go.to.class.toolwindow.title"), true);
}
@Nullable private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
@@ -144,8 +150,7 @@ public class GotoClassAction extends GotoActionBase implements DumbAware {
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
final ItemPresentation presentation = treeElement.getPresentation();
String presentableText = presentation == null ? null : presentation.getPresentableText();
String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
@@ -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,11 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.actions;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.ide.util.gotoByName.*;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.util.gotoByName.ChooseByNameFilter;
import com.intellij.ide.util.gotoByName.ChooseByNamePopup;
import com.intellij.ide.util.gotoByName.GotoFileConfiguration;
import com.intellij.ide.util.gotoByName.GotoFileModel;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.application.ApplicationManager;
@@ -30,7 +33,6 @@ import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -52,8 +54,11 @@ public class GotoFileAction extends GotoActionBase implements DumbAware {
@Override
public void gotoActionPerformed(AnActionEvent e) {
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
final GotoFileModel gotoFileModel = new GotoFileModel(project);
GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() {
@Override
@@ -71,9 +76,10 @@ public class GotoFileAction extends GotoActionBase implements DumbAware {
//this is for better cursor position
if (element instanceof PsiFile) {
VirtualFile vfile = ((PsiFile)element).getVirtualFile();
if (vfile == null) return;
n = new OpenFileDescriptor(project, vfile, popup.getLinePosition(), popup.getColumnPosition()).setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
VirtualFile file = ((PsiFile)element).getVirtualFile();
if (file == null) return;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
}
if (!n.canNavigate()) return;
@@ -82,8 +88,8 @@ public class GotoFileAction extends GotoActionBase implements DumbAware {
}, ModalityState.NON_MODAL);
}
};
PsiElement context = getPsiContext(e);
showNavigationPopup(e, gotoFileModel, callback, "Files matching pattern", true, true, new GotoFileItemProvider(project, context));
GotoFileItemProvider provider = new GotoFileItemProvider(project, getPsiContext(e));
showNavigationPopup(e, gotoFileModel, callback, IdeBundle.message("go.to.file.toolwindow.title"), true, true, provider);
}
protected static class GotoFileFilter extends ChooseByNameFilter<FileType> {
@@ -148,5 +154,4 @@ public class GotoFileAction extends GotoActionBase implements DumbAware {
return o1.getName().compareToIgnoreCase(o2.getName());
}
}
}
@@ -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.
@@ -36,21 +36,17 @@ import java.util.List;
public class OpenFileDescriptor implements Navigatable {
/**
* Tells descriptor to navigate in specific editor rather than file editor
* in main IDEA window.
* For example if you want to navigate in editor embedded into modal dialog,
* you should provide this data.
* Tells descriptor to navigate in specific editor rather than file editor in main IDEA window.
* For example if you want to navigate in editor embedded into modal dialog, you should provide this data.
*/
public static final DataKey<Editor> NAVIGATE_IN_EDITOR = DataKey.create("NAVIGATE_IN_EDITOR");
@NotNull
private final Project myProject;
private final VirtualFile myFile;
private final int myOffset;
private final int myLogicalLine;
private final int myLogicalColumn;
private final int myOffset;
private final RangeMarker myRangeMarker;
@NotNull
private final Project myProject;
private boolean myUseCurrentWindow = false;
@@ -62,8 +58,7 @@ public class OpenFileDescriptor implements Navigatable {
this(project, file, logicalLine, logicalColumn, -1, false);
}
public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file,
int logicalLine, int logicalColumn, boolean persistent) {
public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int logicalLine, int logicalColumn, boolean persistent) {
this(project, file, logicalLine, logicalColumn, -1, persistent);
}
@@ -71,10 +66,8 @@ public class OpenFileDescriptor implements Navigatable {
this(project, file, -1, -1, -1, false);
}
private OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file,
int logicalLine, int logicalColumn, int offset, boolean persistent) {
private OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int logicalLine, int logicalColumn, int offset, boolean persistent) {
myProject = project;
myFile = file;
myLogicalLine = logicalLine;
myLogicalColumn = logicalColumn;
@@ -139,7 +132,7 @@ public class OpenFileDescriptor implements Navigatable {
}
private boolean navigateInRequestedEditor() {
DataContext ctx = DataManager.getInstance().getDataContext();
@SuppressWarnings("deprecation") DataContext ctx = DataManager.getInstance().getDataContext();
Editor e = NAVIGATE_IN_EDITOR.getData(ctx);
if (e == null) return false;
if (!Comparing.equal(FileDocumentManager.getInstance().getFile(e.getDocument()), myFile)) return false;
@@ -1166,3 +1166,7 @@ new.dir.project.chooser.title=Select Location for Project Directory
new.dir.project.default.generator=Empty project
new.dir.project.error.empty=Project name can't be empty
new.dir.project.error.buck=Project directory name must not contain the ''$'' character
go.to.file.toolwindow.title=Files matching pattern
go.to.class.toolwindow.title=Classes matching pattern
go.to.class.dumb.mode.message=Go To Class action is not available until indices are built, using Go To File instead