Search in sources :

Example 11 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class PsiTreeAnchorizer method freeAnchor.

@Override
public void freeAnchor(final Object element) {
    if (element instanceof SmartPointerWrapper) {
        ApplicationManager.getApplication().runReadAction(() -> {
            SmartPsiElementPointer pointer = ((SmartPointerWrapper) element).myPointer;
            Project project = pointer.getProject();
            if (!project.isDisposed()) {
                SmartPointerManager.getInstance(project).removePointer(pointer);
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer)

Example 12 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class InvertBooleanProcessor method findUsages.

@Override
@NotNull
protected UsageInfo[] findUsages() {
    final List<SmartPsiElementPointer> toInvert = new ArrayList<>();
    final LinkedHashSet<PsiElement> elementsToInvert = new LinkedHashSet<>();
    myDelegate.collectRefElements(myElement, myRenameProcessor, myNewName, elementsToInvert);
    for (PsiElement element : elementsToInvert) {
        toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(element));
    }
    final UsageInfo[] renameUsages = myRenameProcessor != null ? myRenameProcessor.findUsages() : UsageInfo.EMPTY_ARRAY;
    final SmartPsiElementPointer[] usagesToInvert = toInvert.toArray(new SmartPsiElementPointer[toInvert.size()]);
    //merge rename and invert usages
    Map<PsiElement, UsageInfo> expressionsToUsages = new HashMap<>();
    List<UsageInfo> result = new ArrayList<>();
    for (UsageInfo renameUsage : renameUsages) {
        expressionsToUsages.put(renameUsage.getElement(), renameUsage);
        result.add(renameUsage);
    }
    for (SmartPsiElementPointer pointer : usagesToInvert) {
        final PsiElement expression = pointer.getElement();
        if (!expressionsToUsages.containsKey(expression)) {
            final UsageInfo usageInfo = new UsageInfo(expression);
            expressionsToUsages.put(expression, usageInfo);
            //fake UsageInfo
            result.add(usageInfo);
            myToInvert.put(usageInfo, pointer);
        } else {
            myToInvert.put(expressionsToUsages.get(expression), pointer);
        }
    }
    return result.toArray(new UsageInfo[result.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(com.intellij.util.containers.HashMap) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class FavoritesTreeNodeDescriptor method getLocation.

public static String getLocation(final AbstractTreeNode element, @NotNull final Project project) {
    Object nodeElement = element.getValue();
    if (nodeElement instanceof SmartPsiElementPointer) {
        nodeElement = ((SmartPsiElementPointer) nodeElement).getElement();
    }
    if (nodeElement instanceof PsiElement) {
        if (nodeElement instanceof PsiDirectory) {
            return VfsUtilCore.getRelativeLocation(((PsiDirectory) nodeElement).getVirtualFile(), project.getBaseDir());
        }
        if (nodeElement instanceof PsiFile) {
            final PsiFile containingFile = (PsiFile) nodeElement;
            return VfsUtilCore.getRelativeLocation(containingFile.getVirtualFile(), project.getBaseDir());
        }
    }
    if (nodeElement instanceof LibraryGroupElement) {
        return ((LibraryGroupElement) nodeElement).getModule().getName();
    }
    if (nodeElement instanceof NamedLibraryElement) {
        final NamedLibraryElement namedLibraryElement = ((NamedLibraryElement) nodeElement);
        final Module module = namedLibraryElement.getModule();
        return (module != null ? module.getName() : "") + ":" + namedLibraryElement.getOrderEntry().getPresentableName();
    }
    if (nodeElement instanceof File) {
        return VfsUtilCore.getRelativeLocation(VfsUtil.findFileByIoFile((File) nodeElement, false), project.getBaseDir());
    }
    final FavoriteNodeProvider[] nodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project);
    for (FavoriteNodeProvider provider : nodeProviders) {
        String location = provider.getElementLocation(nodeElement);
        if (location != null)
            return location;
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) LibraryGroupElement(com.intellij.ide.projectView.impl.nodes.LibraryGroupElement)

Example 14 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class NavigationGutterIconBuilder method calcPsiTargets.

private static <T> List<SmartPsiElementPointer> calcPsiTargets(Project project, Collection<? extends T> targets, NotNullFunction<T, Collection<? extends PsiElement>> converter) {
    SmartPointerManager manager = SmartPointerManager.getInstance(project);
    Set<PsiElement> elements = new THashSet<PsiElement>();
    final List<SmartPsiElementPointer> list = new ArrayList<SmartPsiElementPointer>(targets.size());
    for (final T target : targets) {
        for (final PsiElement psiElement : converter.fun(target)) {
            if (elements.add(psiElement) && psiElement.isValid()) {
                list.add(manager.createSmartPsiElementPointer(psiElement));
            }
        }
    }
    return list;
}
Also used : SmartPointerManager(com.intellij.psi.SmartPointerManager) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Aggregations

SmartPsiElementPointer (com.intellij.psi.SmartPsiElementPointer)14 PsiElement (com.intellij.psi.PsiElement)7 Project (com.intellij.openapi.project.Project)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiFile (com.intellij.psi.PsiFile)2 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)2 UsageInfo (com.intellij.usageView.UsageInfo)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 File (java.io.File)2 List (java.util.List)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 RefElement (com.intellij.codeInspection.reference.RefElement)1 RefFile (com.intellij.codeInspection.reference.RefFile)1 DiagramNodeContainer (com.intellij.diagram.components.DiagramNodeContainer)1 DiagramExtras (com.intellij.diagram.extras.DiagramExtras)1