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);
}
});
}
}
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()]);
}
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;
}
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;
}
Aggregations