本文整理汇总了Java中com.intellij.codeInsight.navigation.actions.GotoDeclarationAction类的典型用法代码示例。如果您正苦于以下问题:Java GotoDeclarationAction类的具体用法?Java GotoDeclarationAction怎么用?Java GotoDeclarationAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GotoDeclarationAction类属于com.intellij.codeInsight.navigation.actions包,在下文中一共展示了GotoDeclarationAction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: chooseAmbiguousTargetAndPerform
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project,
final Editor editor,
@NotNull PsiElementProcessor<PsiElement> processor) {
if (editor == null) {
Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(),
Messages.getErrorIcon());
}
else {
int offset = editor.getCaretModel().getOffset();
boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
if (!chosen) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
}
}, project.getDisposed());
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:FindUsagesAction.java
示例2: 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);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DomIncludesTest.java
示例3: doJavaFileNavigationTest
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
private void doJavaFileNavigationTest(String srcPath, String destPath, int expectedTargets, boolean expectedEnabled,
boolean testGotoDeclaration, Class<? extends PsiElement> targetElementClass) throws IOException {
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + srcPath, destPath);
myFixture.configureFromExistingVirtualFile(file);
// test Ctrl+B
if (testGotoDeclaration) {
PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(expectedTargets, targets.length);
for (PsiElement target : targets) {
assertInstanceOf(LazyValueResourceElementWrapper.computeLazyElement(target), targetElementClass);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AndroidResourcesLineMarkerTest.java
示例4: testNavigationInPlatformXml1
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testNavigationInPlatformXml1() throws Exception {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(
getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml");
myFixture.configureFromExistingVirtualFile(file);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(16, 43));
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag)targetAttrValue.getParent().getParent()).getName());
assertEquals(file, targetElement.getContainingFile().getVirtualFile());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AndroidValueResourcesTest.java
示例5: testNavigationInPlatformXml2
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testNavigationInPlatformXml2() throws Exception {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(
getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml");
myFixture.configureFromExistingVirtualFile(file);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(19, 17));
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag)targetAttrValue.getParent().getParent()).getName());
assertEquals(file, targetElement.getContainingFile().getVirtualFile());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AndroidValueResourcesTest.java
示例6: testNavigationInPlatformXml3
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testNavigationInPlatformXml3() throws Exception {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(
getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml");
myFixture.configureFromExistingVirtualFile(file);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 44));
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement;
assertEquals("my_white", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName());
assertEquals("color", ((XmlTag)targetAttrValue.getParent().getParent()).getName());
assertEquals(file, targetElement.getContainingFile().getVirtualFile());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AndroidValueResourcesTest.java
示例7: 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()));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:AndroidSdkSourcesBrowsingTest.java
示例8: doTestNavigationToResource
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
private void doTestNavigationToResource(LogicalPosition position, int expectedCount, Class<?> aClass) {
myFixture.allowTreeAccessForAllFiles();
final String sdkSourcesPath = configureMockSdk();
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(sdkSourcesPath + "/android/app/Activity.java");
myFixture.configureFromExistingVirtualFile(file);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(position);
PsiElement[] elements = GotoDeclarationAction.findAllTargetElements(
myFixture.getProject(), myFixture.getEditor(),
myFixture.getEditor().getCaretModel().getOffset());
assertEquals(expectedCount, elements.length);
for (PsiElement element : elements) {
assertInstanceOf(LazyValueResourceElementWrapper.computeLazyElement(element), aClass);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AndroidSdkSourcesBrowsingTest.java
示例9: testFindUsagesWorksFromNameString
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
@Test
public void testFindUsagesWorksFromNameString() {
BuildFile targetFile =
createBuildFile(
new WorkspacePath("java/com/google/foo/BUILD"),
"java_library(name = \"tar<caret>get\")");
BuildFile refFile =
createBuildFile(
new WorkspacePath("java/com/google/bar/BUILD"),
"java_library(name = \"ref\", exports = [\"//java/com/google/foo:target\"])");
testFixture.configureFromExistingVirtualFile(targetFile.getVirtualFile());
PsiElement targetElement =
GotoDeclarationAction.findElementToShowUsagesOf(
testFixture.getEditor(), testFixture.getEditor().getCaretModel().getOffset());
PsiReference[] references = FindUsages.findAllReferences(targetElement);
assertThat(references).hasLength(1);
PsiElement ref = references[0].getElement();
assertThat(ref).isInstanceOf(StringLiteral.class);
assertThat(ref.getContainingFile()).isEqualTo(refFile);
}
开发者ID:bazelbuild,项目名称:intellij,代码行数:26,代码来源:FindRuleUsagesTest.java
示例10: chooseAmbiguousTargetAndPerform
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project, final Editor editor,
@NotNull PsiElementProcessor<PsiElement> processor) {
if (editor == null) {
Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"),
CommonBundle.getErrorTitle(), Messages.getErrorIcon());
} else {
int offset = editor.getCaretModel().getOffset();
boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor,
FindBundle.message("find.usages.ambiguous.title", "crap"), null);
if (!chosen) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
HintManager.getInstance()
.showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
}
}, project.getDisposed());
}
}
}
开发者ID:square,项目名称:dagger-intellij-plugin,代码行数:22,代码来源:ShowUsagesAction.java
示例11: chooseAmbiguousTargetAndPerform
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
static void chooseAmbiguousTargetAndPerform(@Nonnull final Project project, final Editor editor, @Nonnull PsiElementProcessor<PsiElement> processor) {
if (editor == null) {
Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
}
else {
int offset = editor.getCaretModel().getOffset();
boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
if (!chosen) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
}
}, project.getDisposed());
}
}
}
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:FindUsagesAction.java
示例12: chooseAmbiguousTargetAndPerform
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project,
final Editor editor,
@NotNull PsiElementProcessor<PsiElement> processor) {
if (editor == null) {
Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"),
CommonBundle.getErrorTitle(), Messages.getErrorIcon());
}
else {
int offset = editor.getCaretModel().getOffset();
boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor,
FindBundle.message("find.usages.ambiguous.title", "crap"), null);
if (!chosen) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
}
}, project.getDisposed());
}
}
}
开发者ID:square,项目名称:otto-intellij-plugin,代码行数:23,代码来源:ShowUsagesAction.java
示例13: 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();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:GotoDeclarationTest.java
示例14: testMultipleConstructors
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testMultipleConstructors() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/gotoDeclaration/" + name + ".java");
final int offset = getEditor().getCaretModel().getOffset();
final PsiElement[] elements =
GotoDeclarationAction.findAllTargetElements(getProject(), getEditor(), offset);
assertEquals(Arrays.asList(elements).toString(), 0, elements.length);
final TargetElementUtil elementUtilBase = TargetElementUtil.getInstance();
final PsiReference reference = getFile().findReferenceAt(offset);
assertNotNull(reference);
final Collection<PsiElement> candidates = elementUtilBase.getTargetCandidates(reference);
assertEquals(candidates.toString(), 2, candidates.size());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:GotoDeclarationTest.java
示例15: 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));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:JavaFoldingGotoTest.java
示例16: testDeclareStyleableNameNavigation1
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testDeclareStyleableNameNavigation1() throws Exception {
copyFileToProject("LabelView.java", "src/p1/p2/LabelView.java");
final VirtualFile file = copyFileToProject("attrs4.xml");
myFixture.configureFromExistingVirtualFile(file);
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = targets[0];
assertInstanceOf(targetElement, PsiClass.class);
assertEquals("android.widget.TextView", ((PsiClass)targetElement).getQualifiedName());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:AndroidValueResourcesTest.java
示例17: testDeclareStyleableNameNavigation2
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testDeclareStyleableNameNavigation2() throws Exception {
copyFileToProject("LabelView.java", "src/p1/p2/LabelView.java");
final VirtualFile file = copyFileToProject("attrs5.xml");
myFixture.configureFromExistingVirtualFile(file);
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = targets[0];
assertInstanceOf(targetElement, PsiClass.class);
assertEquals("p1.p2.LabelView", ((PsiClass)targetElement).getQualifiedName());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:AndroidValueResourcesTest.java
示例18: testJavaNavigation
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
public void testJavaNavigation() throws Exception {
createInitialStructure();
myFixture.copyFileToProject("R.java", "app/src/p1/p2/R.java");
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + getTestName(false) + ".java", "/app/src/p1/p2/Java.java");
myFixture.configureFromExistingVirtualFile(file);
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = targets[0];
assertInstanceOf(targetElement, PsiFile.class);
assertEquals("main.xml", ((PsiFile)targetElement).getName());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:AndroidLibraryProjectTest.java
示例19: getDeclarationsFrom
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; //导入依赖的package包/类
@Nullable
private PsiElement[] getDeclarationsFrom(VirtualFile file) {
myFixture.configureFromExistingVirtualFile(file);
// AndroidGotoDeclarationHandler only handles .java files. We also want to check .xml files, so
// we use GotoDeclarationAction instead of creating AndroidGotoDeclarationHandler and invoking getGotoDeclarationTargets
// on it directly.
return GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:AndroidGotoDeclarationHandlerTest.java
示例20: 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());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:IdeaDecompilerTest.java
注:本文中的com.intellij.codeInsight.navigation.actions.GotoDeclarationAction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论