use of com.intellij.psi.SmartPointerManager in project intellij-community by JetBrains.
the class PyiRelatedItemLineMarkerProvider method createLineMarkerInfo.
@NotNull
private static RelatedItemLineMarkerInfo<PsiElement> createLineMarkerInfo(@NotNull PsiElement element, @NotNull PsiElement relatedElement, @NotNull String itemTitle) {
final SmartPointerManager pointerManager = SmartPointerManager.getInstance(element.getProject());
final SmartPsiElementPointer<PsiElement> relatedElementPointer = pointerManager.createSmartPsiElementPointer(relatedElement);
final String stubFileName = relatedElement.getContainingFile().getName();
return new RelatedItemLineMarkerInfo<>(element, element.getTextRange(), ICON, Pass.LINE_MARKERS, element1 -> itemTitle + " in " + stubFileName, new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
final PsiElement restoredRelatedElement = relatedElementPointer.getElement();
if (restoredRelatedElement == null) {
return;
}
final int offset = restoredRelatedElement instanceof PsiFile ? -1 : restoredRelatedElement.getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(restoredRelatedElement);
if (virtualFile != null && virtualFile.isValid()) {
new OpenFileDescriptor(restoredRelatedElement.getProject(), virtualFile, offset).navigate(true);
}
}
}, GutterIconRenderer.Alignment.RIGHT, GotoRelatedItem.createItems(Collections.singletonList(relatedElement)));
}
use of com.intellij.psi.SmartPointerManager in project intellij-community by JetBrains.
the class UsageViewImpl method disposeSmartPointers.
private void disposeSmartPointers() {
SmartPointerManager pointerManager = SmartPointerManager.getInstance(getProject());
for (Usage usage : myUsageNodes.keySet()) {
if (usage instanceof UsageInfo2UsageAdapter) {
SmartPsiElementPointer<?> pointer = ((UsageInfo2UsageAdapter) usage).getUsageInfo().getSmartPointer();
pointerManager.removePointer(pointer);
}
}
}
use of com.intellij.psi.SmartPointerManager in project intellij-plugins by JetBrains.
the class AngularModulesProvider method getDependencies.
@Override
public List<Link> getDependencies(@NotNull PsiFile file) {
final Project project = file.getProject();
if (!AngularIndexUtil.hasAngularJS(project))
return null;
if (!(file instanceof JSFile))
return null;
final SmartPointerManager spm = SmartPointerManager.getInstance(project);
final List<Link> result = new ArrayList<>();
final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
final GlobalSearchScope fileScope = GlobalSearchScope.fileScope(file);
final int fileId = FileBasedIndex.getFileId(file.getVirtualFile());
StubIndex.getInstance().processAllKeys(AngularModuleIndex.KEY, processor, fileScope, new IdFilter() {
@Override
public boolean containsFileId(int id) {
return id == fileId;
}
});
for (String key : processor.getResults()) {
AngularIndexUtil.multiResolve(project, AngularModuleIndex.KEY, key, element -> {
if (!file.equals(element.getContainingFile()))
return true;
final JSCallExpression expression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
if (expression != null) {
final List<String> dependencies = AngularModuleIndex.findDependenciesInModuleDeclaration(expression);
if (dependencies != null) {
for (String dependency : dependencies) {
final JSImplicitElement resolve = AngularIndexUtil.resolve(project, AngularModuleIndex.KEY, dependency);
if (resolve != null) {
result.add(new Link(spm.createSmartPsiElementPointer(element.getNavigationElement()), spm.createSmartPsiElementPointer(resolve.getNavigationElement()), key, resolve.getName(), AngularJSIcons.AngularJS));
}
}
}
}
return true;
});
}
return result;
}
use of com.intellij.psi.SmartPointerManager in project intellij-community by JetBrains.
the class ElementCreator method tryCreate.
public PsiElement[] tryCreate(@NotNull final String inputString) {
if (inputString.length() == 0) {
Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
return PsiElement.EMPTY_ARRAY;
}
Ref<List<SmartPsiElementPointer>> createdElements = Ref.create();
Exception exception = executeCommand(getActionName(inputString), () -> {
PsiElement[] psiElements = create(inputString);
SmartPointerManager manager = SmartPointerManager.getInstance(myProject);
createdElements.set(ContainerUtil.map(psiElements, manager::createSmartPsiElementPointer));
});
if (exception != null) {
handleException(exception);
return PsiElement.EMPTY_ARRAY;
}
return ContainerUtil.mapNotNull(createdElements.get(), SmartPsiElementPointer::getElement).toArray(PsiElement.EMPTY_ARRAY);
}
use of com.intellij.psi.SmartPointerManager in project intellij-community by JetBrains.
the class UpdateFoldRegionsOperation method addNewRegions.
private List<FoldRegion> addNewRegions(@NotNull EditorFoldingInfo info, @NotNull FoldingModelEx foldingModel, FoldingUpdate.FoldingMap elementsToFold, @NotNull Map<TextRange, Boolean> rangeToExpandStatusMap, @NotNull Map<FoldRegion, Boolean> shouldExpand, @NotNull Map<FoldingGroup, Boolean> groupExpand) {
List<FoldRegion> newRegions = new ArrayList<>();
SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
for (PsiElement element : elementsToFold.keySet()) {
ProgressManager.checkCanceled();
final Collection<FoldingDescriptor> descriptors = elementsToFold.get(element);
for (FoldingDescriptor descriptor : descriptors) {
FoldingGroup group = descriptor.getGroup();
TextRange range = descriptor.getRange();
String placeholder = null;
try {
placeholder = descriptor.getPlaceholderText();
} catch (IndexNotReadyException ignore) {
}
if (range.getEndOffset() > myEditor.getDocument().getTextLength()) {
LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)", descriptor, myEditor.getDocument().getTextLength()));
continue;
}
FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(), placeholder == null ? "..." : placeholder, group, descriptor.isNonExpandable());
if (region == null)
continue;
PsiElement psi = descriptor.getElement().getPsi();
if (psi == null || !psi.isValid() || !foldingModel.addFoldRegion(region) || !myFile.isValid()) {
region.dispose();
continue;
}
if (descriptor.canBeRemovedWhenCollapsed())
region.putUserData(CAN_BE_REMOVED_WHEN_COLLAPSED, Boolean.TRUE);
info.addRegion(region, smartPointerManager.createSmartPsiElementPointer(psi));
newRegions.add(region);
boolean expandStatus = !descriptor.isNonExpandable() && shouldExpandNewRegion(element, range, rangeToExpandStatusMap);
if (group == null) {
shouldExpand.put(region, expandStatus);
} else {
final Boolean alreadyExpanded = groupExpand.get(group);
groupExpand.put(group, alreadyExpanded == null ? expandStatus : alreadyExpanded.booleanValue() || expandStatus);
}
}
}
return newRegions;
}
Aggregations