Search in sources :

Example 1 with UsageTarget

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

the class MavenDomTestCase method search.

protected List<PsiElement> search(VirtualFile file) throws IOException {
    final MapDataContext context = createDataContext(file);
    UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return context.getData(dataId);
        }
    });
    PsiElement target = ((PsiElement2UsageTargetAdapter) targets[0]).getElement();
    List<PsiReference> result = new ArrayList<>(ReferencesSearch.search(target).findAll());
    return ContainerUtil.map(result, psiReference -> psiReference.getElement());
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) MapDataContext(com.intellij.testFramework.MapDataContext) ArrayList(java.util.ArrayList) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 2 with UsageTarget

use of com.intellij.usages.UsageTarget 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 3 with UsageTarget

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

the class UsageViewTreeModelBuilder method addTargetNodes.

private void addTargetNodes() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myTargets.length == 0)
        return;
    myTargetNodes = new UsageTargetNode[myTargets.length];
    myTargetsNode.removeAllChildren();
    for (int i = 0; i < myTargets.length; i++) {
        UsageTarget target = myTargets[i];
        UsageTargetNode targetNode = new UsageTargetNode(target);
        myTargetsNode.add(targetNode);
        myTargetNodes[i] = targetNode;
    }
    myRootNode.addTargetsNode(myTargetsNode, this);
    reload(myTargetsNode);
}
Also used : UsageTarget(com.intellij.usages.UsageTarget)

Example 4 with UsageTarget

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

the class JavaUsageTypeProviderTest method assertUsageType.

private void assertUsageType(UsageType expected, PsiClass target) {
    UsageTarget[] targets = { new PsiElement2UsageTargetAdapter(target) };
    PsiElement element = myFixture.getReferenceAtCaretPositionWithAssertion().getElement();
    UsageType usageType = new JavaUsageTypeProvider().getUsageType(element, targets);
    assertEquals(expected, usageType);
}
Also used : JavaUsageTypeProvider(com.intellij.usages.impl.rules.JavaUsageTypeProvider) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) UsageType(com.intellij.usages.impl.rules.UsageType) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 5 with UsageTarget

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

the class UsageViewManagerTest method testScopeCreatedForFindInDirectory.

public void testScopeCreatedForFindInDirectory() {
    VirtualFile dir = getProject().getBaseDir();
    FindModel findModel = new FindModel();
    findModel.setDirectoryName(dir.getPath());
    findModel.setWithSubdirectories(true);
    findModel.setProjectScope(false);
    UsageTarget target = new FindInProjectUtil.StringUsageTarget(getProject(), findModel);
    UsageViewManagerImpl manager = (UsageViewManagerImpl) UsageViewManager.getInstance(getProject());
    SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[] { target });
    assertEquals(scope, GlobalSearchScopesCore.directoryScope(getProject(), dir, true));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FindModel(com.intellij.find.FindModel) SearchScope(com.intellij.psi.search.SearchScope) UsageTarget(com.intellij.usages.UsageTarget)

Aggregations

UsageTarget (com.intellij.usages.UsageTarget)14 PsiElement (com.intellij.psi.PsiElement)7 Project (com.intellij.openapi.project.Project)5 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)3 Editor (com.intellij.openapi.editor.Editor)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 PsiElementUsageTarget (com.intellij.usages.PsiElementUsageTarget)3 FindModel (com.intellij.find.FindModel)2 DataProvider (com.intellij.openapi.actionSystem.DataProvider)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 PsiReference (com.intellij.psi.PsiReference)2 SearchScope (com.intellij.psi.search.SearchScope)2 ArrayList (java.util.ArrayList)2 CopyProvider (com.intellij.ide.CopyProvider)1 DeleteProvider (com.intellij.ide.DeleteProvider)1 ContextHelpAction (com.intellij.ide.actions.ContextHelpAction)1 Language (com.intellij.lang.Language)1 EmptyFindUsagesProvider (com.intellij.lang.findUsages.EmptyFindUsagesProvider)1 IProperty (com.intellij.lang.properties.IProperty)1