Search in sources :

Example 1 with PsiElementUsageTarget

use of com.intellij.usages.PsiElementUsageTarget in project smali by JesusFreke.

the class FindUsagesTest method doTest.

protected void doTest() {
    PsiReference reference = null;
    PsiElement targetElement = null;
    for (TestFile testFile : testFiles) {
        int refIndex = testFile.getRefIndex();
        if (refIndex != -1) {
            PsiElement element = testFile.psiFile.findElementAt(refIndex);
            UsageTarget[] targets = UsageTargetUtil.findUsageTargets(element);
            if (targets != null) {
                for (UsageTarget target : targets) {
                    if (target instanceof PsiElementUsageTarget) {
                        targetElement = ((PsiElementUsageTarget) target).getElement();
                        break;
                    }
                }
            }
            if (targetElement == null) {
                reference = testFile.psiFile.findReferenceAt(refIndex);
                if (reference != null) {
                    targetElement = reference.resolve();
                } else {
                    targetElement = TargetElementUtilBase.getInstance().getNamedElement(testFile.psiFile.findElementAt(refIndex), 0);
                }
            }
            break;
        }
    }
    Assert.assertNotNull(targetElement);
    Collection<UsageInfo> usages = findUsages(targetElement);
    for (TestFile testFile : testFiles) {
        assertUsages(testFile, usages);
    }
}
Also used : PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

Example 2 with PsiElementUsageTarget

use of com.intellij.usages.PsiElementUsageTarget in project android by JetBrains.

the class AndroidFindUsagesTest method findUsages.

private static Collection<UsageInfo> findUsages(String fileName, final JavaCodeInsightTestFixture fixture, String newFilePath) throws Throwable {
    VirtualFile file = fixture.copyFileToProject(BASE_PATH + fileName, newFilePath);
    fixture.configureFromExistingVirtualFile(file);
    final UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return ((EditorEx) fixture.getEditor()).getDataContext().getData(dataId);
        }
    });
    assert targets != null && targets.length > 0 && targets[0] instanceof PsiElementUsageTarget;
    return fixture.findUsages(((PsiElementUsageTarget) targets[0]).getElement());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataProvider(com.intellij.openapi.actionSystem.DataProvider) EditorEx(com.intellij.openapi.editor.ex.EditorEx) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

Example 3 with PsiElementUsageTarget

use of com.intellij.usages.PsiElementUsageTarget in project intellij-community by JetBrains.

the class FindUsagesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    UsageTarget[] usageTargets = e.getData(UsageView.USAGE_TARGETS_KEY);
    if (usageTargets == null) {
        final Editor editor = e.getData(CommonDataKeys.EDITOR);
        chooseAmbiguousTargetAndPerform(project, editor, element -> {
            startFindUsages(element);
            return false;
        });
    } else {
        UsageTarget target = usageTargets[0];
        if (target instanceof PsiElementUsageTarget) {
            PsiElement element = ((PsiElementUsageTarget) target).getElement();
            if (element != null) {
                startFindUsages(element);
            }
        } else {
            target.findUsages();
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

Aggregations

PsiElementUsageTarget (com.intellij.usages.PsiElementUsageTarget)3 UsageTarget (com.intellij.usages.UsageTarget)3 PsiElement (com.intellij.psi.PsiElement)2 DataProvider (com.intellij.openapi.actionSystem.DataProvider)1 Editor (com.intellij.openapi.editor.Editor)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiReference (com.intellij.psi.PsiReference)1 UsageInfo (com.intellij.usageView.UsageInfo)1