本文整理汇总了Java中com.intellij.codeInsight.navigation.NavigationUtil类的典型用法代码示例。如果您正苦于以下问题:Java NavigationUtil类的具体用法?Java NavigationUtil怎么用?Java NavigationUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NavigationUtil类属于com.intellij.codeInsight.navigation包,在下文中一共展示了NavigationUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
DumbService.getInstance(project).setAlternativeResolveEnabled(true);
try {
int offset = editor.getCaretModel().getOffset();
PsiElement[] symbolTypes = findSymbolTypes(editor, offset);
if (symbolTypes == null || symbolTypes.length == 0) return;
if (symbolTypes.length == 1) {
navigate(project, symbolTypes[0]);
}
else {
NavigationUtil.getPsiElementPopup(symbolTypes, CodeInsightBundle.message("choose.type.popup.title")).showInBestPositionFor(editor);
}
}
catch (IndexNotReadyException e) {
DumbService.getInstance(project).showDumbModeNotification("Navigation is not available here during index update");
}
finally {
DumbService.getInstance(project).setAlternativeResolveEnabled(false);
}
}
示例2: handleLink
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public boolean handleLink(@NotNull String refSuffix, @NotNull Editor editor) {
Project project = editor.getProject();
if (project == null) return false;
PsiElement aClass = JavaPsiFacade.getInstance(project).findClass(refSuffix, GlobalSearchScope.allScope(project));
if (aClass == null) return false;
NavigationUtil.activateFileWithPsiElement(aClass);
return true;
}
示例3: testGotoClass
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
public void testGotoClass() throws Exception {
PsiJavaFile file = (PsiJavaFile)myFixture.configureByText("Foo.java", "public class Foo {\n" +
"}\n" +
"\n" +
"class Bar {}\n");
VirtualFile virtualFile = file.getVirtualFile();
assertNotNull(virtualFile);
myManager.openFile(virtualFile, true);
assertEquals(0, getOffset(virtualFile));
myManager.closeAllFiles();
PsiClass psiClass = file.getClasses()[1];
int identifierOffset = psiClass.getNameIdentifier().getTextOffset();
NavigationUtil.activateFileWithPsiElement(psiClass);
assertEquals(identifierOffset, getOffset(virtualFile));
getEditor(virtualFile).getCaretModel().moveToOffset(identifierOffset + 3); // it's still inside the class, so keep it
myManager.closeAllFiles();
NavigationUtil.activateFileWithPsiElement(psiClass);
assertEquals(identifierOffset + 3, getOffset(virtualFile));
getEditor(virtualFile).getCaretModel().moveToOffset(0);
NavigationUtil.activateFileWithPsiElement(psiClass);
assertEquals(identifierOffset, getOffset(virtualFile));
myManager.closeAllFiles();
NavigationUtil.activateFileWithPsiElement(file); // GoTo file should keep offset
assertEquals(identifierOffset, getOffset(virtualFile));
}
示例4: testSelectFileOnNavigation
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
public void testSelectFileOnNavigation() throws Exception {
VirtualFile file1 = getFile("/src/1.txt");
myManager.openFile(file1, true);
VirtualFile file2 = getFile("/src/2.txt");
myManager.openFile(file2, true);
NavigationUtil.activateFileWithPsiElement(PsiManager.getInstance(getProject()).findFile(file1));
VirtualFile[] files = myManager.getSelectedFiles();
assertEquals(1, files.length);
assertEquals("1.txt", files[0].getName());
}
示例5: invokeHint
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
public void invokeHint(Runnable hideRunnable) {
myHideRunnable = hideRunnable;
if (!canShowHint()) {
hideHint();
return;
}
if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);
myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(),
HighlighterLayer.SELECTION + 1, attributes,
HighlighterTargetArea.EXACT_RANGE);
Component internalComponent = myEditor.getContentComponent();
myStoredCursor = internalComponent.getCursor();
internalComponent.addKeyListener(myEditorKeyListener);
internalComponent.setCursor(hintCursor());
if (LOG.isDebugEnabled()) {
LOG.debug("internalComponent.setCursor(hintCursor())");
}
}
else {
evaluateAndShowHint();
}
}
示例6: navigateToElement
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
protected void navigateToElement(Navigatable element) {
if (element instanceof PsiElement) {
NavigationUtil.activateFileWithPsiElement((PsiElement)element, true);
}
else {
element.navigate(true);
}
}
示例7: actionPerformed
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
PsiElement element = getContextElement(e.getDataContext());
if (element == null) return;
List<GotoRelatedItem> items = NavigationUtil.collectRelatedItems(element, e.getDataContext());
if (items.isEmpty()) return;
if (items.size() == 1 && items.get(0).getElement() != null) {
items.get(0).navigate();
return;
}
NavigationUtil.getRelatedItemsPopup(items, "Choose Target").showInBestPositionFor(e.getDataContext());
}
示例8: navigate
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public void navigate(boolean requestFocus, boolean preserveState) {
if (canNavigate()) {
if (requestFocus || preserveState) {
NavigationUtil.openFileWithPsiElement(extractPsiFromValue(), requestFocus, requestFocus);
}
else {
getNavigationItem().navigate(requestFocus);
}
}
}
示例9: navigateOrChoose
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
private static void navigateOrChoose(Editor editor, Collection<? extends NavigatablePsiElement> superElements, final String title) {
if (!superElements.isEmpty()) {
NavigatablePsiElement[] superElementArray = superElements.toArray(new NavigatablePsiElement[superElements.size()]);
if (superElementArray.length == 1) {
superElementArray[0].navigate(true);
}
else {
NavigationUtil.getPsiElementPopup(superElementArray, title).showInBestPositionFor(editor);
}
}
}
示例10: doClickAction
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
static void doClickAction(AnActionEvent e, Collection<Define> set, String title) {
if (set.size() == 1) {
final Navigatable n = (Navigatable)set.iterator().next().getPsiElement();
OpenSourceUtil.navigate(true, n);
} else {
final Define[] array = set.toArray(new Define[set.size()]);
NavigationUtil.getPsiElementPopup(ContainerUtil.map(array, new Function<Define, PsiElement>() {
@Override
public PsiElement fun(Define define) {
return define.getPsiElement();
}
}, PsiElement.EMPTY_ARRAY), title).show(new RelativePoint((MouseEvent)e.getInputEvent()));
}
}
示例11: navigate
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public void navigate(MouseEvent e, PsiElement elt) {
final List<GotoRelatedItem> items = doComputeItems();
if (items.size() == 1) {
items.get(0).navigate();
}
else {
NavigationUtil.getRelatedItemsPopup(items, "Go to Related Files").show(new RelativePoint(e));
}
}
示例12: showScopeChooser
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
protected void showScopeChooser(PsiClass[] scopes, final Pass<PsiClass> callback, Editor editor) {
PsiElementProcessor<PsiClass> processor = new PsiElementProcessor<PsiClass>() {
@Override
public boolean execute(@NotNull PsiClass element) {
callback.pass(element);
return false;
}
};
NavigationUtil.getPsiElementPopup(scopes, new PsiClassListCellRenderer(), "Choose class to introduce field", processor).showInBestPositionFor(editor);
}
示例13: navigate
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public void navigate(MouseEvent e, PsiField field) {
final ArrayList<PsiElement> relatedItems = new ArrayList<PsiElement>();
collectTargets(field, relatedItems, Function.ID, false);
if (relatedItems.size() == 1) {
NavigationUtil.activateFileWithPsiElement(relatedItems.get(0));
return;
}
final JBPopup popup = NavigationUtil
.getPsiElementPopup(relatedItems.toArray(new PsiElement[relatedItems.size()]), "<html>Choose component with fx:id <b>" + field.getName() + "<b></html>");
popup.show(new RelativePoint(e));
}
示例14: navigate
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
@Override
public void navigate(boolean requestFocus) {
if (canNavigate()) {
final PsiNamedElement value = (PsiNamedElement)getValue();
if (requestFocus) {
NavigationUtil.activateFileWithPsiElement(value, true);
}
else if (value instanceof NavigationItem) {
((NavigationItem)value).navigate(requestFocus);
}
}
}
示例15: navigate
import com.intellij.codeInsight.navigation.NavigationUtil; //导入依赖的package包/类
public void navigate(MouseEvent e, PsiElement elt) {
Collection<GotoRelatedItem> items = this.items;
if (items.size() == 1) {
items.iterator().next().navigate();
} else {
NavigationUtil.getRelatedItemsPopup(new ArrayList<>(items), "Go to Related Files").show(new RelativePoint(e));
}
}