本文整理汇总了Java中com.intellij.codeInsight.navigation.actions.GotoDeclarationAction.findTargetElement方法的典型用法代码示例。如果您正苦于以下问题:Java GotoDeclarationAction.findTargetElement方法的具体用法?Java GotoDeclarationAction.findTargetElement怎么用?Java GotoDeclarationAction.findTargetElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
的用法示例。
在下文中一共展示了GotoDeclarationAction.findTargetElement方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNavigationToIncluded
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
public void testNavigationToIncluded() throws Throwable {
final MyElement rootElement = createDomFile("a.xml", "<root xmlns:xi=\"http://www.w3.org/2001/XInclude\">" +
"<xi:include href=\"b.xml\" xpointer=\"xpointer(/xxx/*)\"/>" +
"<child ref=\"b\"/>" +
"</root>");
final XmlFile includedFile = (XmlFile) createFile("b.xml", "<xxx><child xxx=\"b\"/></xxx>");
final List<Child> children = rootElement.getChildren();
final MyElement domTarget = children.get(0);
final GenericAttributeValue<Child> ref = children.get(1).getRef();
final MyElement value = ref.getValue();
assertEquals(domTarget, value);
myFixture.configureFromTempProjectFile("a.xml");
final int offset = ref.getXmlAttributeValue().getTextRange().getStartOffset() + 1;
myFixture.getEditor().getCaretModel().moveToOffset(offset);
final PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), myFixture.getEditor(), offset);
PsiElement element = ((DomTarget)((PomTargetPsiElement)target).getTarget()).getNavigationElement();
// assertSame(PomService.convertToPsi(DomTarget.getTarget(domTarget)), target);
assertSame(includedFile.getDocument().getRootTag().getSubTags()[0].getAttributes()[0].getValueElement(), element);
}
示例2: testNavigationToSources
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
public void testNavigationToSources() throws Exception {
final String sdkSourcesPath = configureAndroidSdkWithSources(SDK_SOURCES_PATH_PREFIX + "2");
final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + "MyActivity2.java", MODULE_DIR + "/src/p1/p2/MyActivity.java");
myFixture.configureFromExistingVirtualFile(f);
PsiElement element = GotoDeclarationAction.findTargetElement(
myFixture.getProject(), myFixture.getEditor(),
myFixture.getEditor().getCaretModel().getOffset());
assertNotNull(element);
element = element.getNavigationElement();
assertNotNull(element);
final PsiFile activityPsiFile = element.getContainingFile();
assertNotNull(activityPsiFile);
final VirtualFile activityVFile = activityPsiFile.getVirtualFile();
assertNotNull(activityVFile);
final String expectedActivityFilePath = FileUtil.toSystemIndependentName(sdkSourcesPath + "/android/app/Activity.java");
assertTrue("Expected: " + expectedActivityFilePath + "\nActual: " + activityVFile.getPath(),
FileUtil.pathsEqual(expectedActivityFilePath, activityVFile.getPath()));
}
示例3: performAction
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
private static void performAction() {
PsiElement element = GotoDeclarationAction.findTargetElement(getProject(), getEditor(), getEditor().getCaretModel().getOffset());
assertEquals(getFile(), element.getContainingFile());
getEditor().getCaretModel().moveToOffset(element.getTextOffset());
getEditor().getScrollingModel().scrollToCaret(ScrollType.CENTER);
getEditor().getSelectionModel().removeSelection();
}
示例4: testIDEA127145
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
public void testIDEA127145() {
PsiFile file = myFixture.addFileToProject("Program.java",
"import java.io.InputStream;\n" +
"import java.util.HashMap;\n" +
"import java.util.Map;\n" +
"\n" +
"class Program {\n" +
" private static InputStream getFile(String name, Map<String, Object> args) {\n" +
" return Program.class.getResourceAsStream(name);\n" +
" }\n" +
"\n" +
" public static void main(String[] args) {\n" +
" // Ctrl + B or Ctrl + Left Mouse Button work correctly for following string:\n" +
" final String name = \"file.sql\";\n" +
" // But it jumps only to folder in following case:\n" +
" final InputStream inputStream = getFile(\"dir/fil<caret>e.sql\", new HashMap<String, Object>());\n" +
" }\n" +
"}");
PsiFile fileSql = myFixture.addFileToProject("dir/file.sql", "select 1;");
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
Editor editor = myFixture.getEditor();
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(editor);
FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel();
foldingModel.rebuild();
myFixture.doHighlighting();
PsiElement element = GotoDeclarationAction.findTargetElement(getProject(), editor, editor.getCaretModel().getOffset());
assertTrue("Should navigate to: file.sql instead of " + element, element != null && element.equals(fileSql));
}
示例5: doTestNavigation
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
private void doTestNavigation(int line, int column, int expectedLine, int expectedColumn) {
PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), myFixture.getEditor(), offset(line, column));
assertTrue(String.valueOf(target), target instanceof Navigatable);
((Navigatable)target).navigate(true);
int expected = offset(expectedLine, expectedColumn);
assertEquals(expected, myFixture.getCaretOffset());
}
示例6: testGotoDirectory
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
public void testGotoDirectory() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/gotoDeclaration/" + name + ".java");
PsiDirectory element = (PsiDirectory)GotoDeclarationAction.findTargetElement(getProject(), getEditor(), getEditor().getCaretModel().getOffset());
assertEquals("java.lang", JavaDirectoryService.getInstance().getPackage(element).getQualifiedName());
}
示例7: checkNavigatesTo
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入方法依赖的package包/类
private void checkNavigatesTo(String expected) {
final int offset = myEditor.getCaretModel().getOffset();
final PsiElement targetElement = GotoDeclarationAction.findTargetElement(myProject, myEditor, offset);
assertEquals(expected, ((PsiFile)targetElement).getName());
}