com.intellij.psi.SmartPointerManager Java Examples

The following examples show how to use com.intellij.psi.SmartPointerManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UsageHolder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public UsageHolder(PsiElement element, UsageInfo[] usageInfos) {
  Project project = element.getProject();
  myElementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(element);

  GeneratedSourcesFilter[] filters = GeneratedSourcesFilter.EP_NAME.getExtensions();
  for (UsageInfo usageInfo : usageInfos) {
    if (!(usageInfo instanceof SafeDeleteReferenceUsageInfo)) continue;
    final SafeDeleteReferenceUsageInfo usage = (SafeDeleteReferenceUsageInfo)usageInfo;
    if (usage.getReferencedElement() != element) continue;

    if (!usage.isSafeDelete()) {
      myUnsafeUsages++;
      if (usage.isNonCodeUsage || isInGeneratedCode(usage, project, filters)) {
        myNonCodeUnsafeUsages++;
      }
    }
  }
}
 
Example #2
Source File: LocalQuickFixOnPsiElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
public LocalQuickFixOnPsiElement(PsiElement startElement, PsiElement endElement) {
  if (startElement == null || endElement == null) {
    myStartElement = myEndElement = null;
    return;
  }
  LOG.assertTrue(startElement.isValid());
  PsiFile startContainingFile = startElement.getContainingFile();
  PsiFile endContainingFile = startElement == endElement ? startContainingFile : endElement.getContainingFile();
  if (startElement != endElement) {
    LOG.assertTrue(endElement.isValid());
    LOG.assertTrue(startContainingFile == endContainingFile, "Both elements must be from the same file");
  }
  Project project = startContainingFile == null ? startElement.getProject() : startContainingFile.getProject(); // containingFile can be null for a directory
  myStartElement = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(startElement, startContainingFile);
  myEndElement = endElement == startElement ? null : SmartPointerManager.getInstance(project).createSmartPsiElementPointer(endElement, endContainingFile);
}
 
Example #3
Source File: LineMarkerInfo.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a line marker info for the element.
 *
 * @param element         the element for which the line marker is created.
 * @param range           the range (relative to beginning of file) with which the marker is associated
 * @param icon            the icon to show in the gutter for the line marker
 * @param updatePass      the ID of the daemon pass during which the marker should be recalculated
 * @param tooltipProvider the callback to calculate the tooltip for the gutter icon
 * @param navHandler      the handler executed when the gutter icon is clicked
 */
public LineMarkerInfo(@Nonnull T element,
                      @Nonnull TextRange range,
                      Image icon,
                      int updatePass,
                      @Nullable Function<? super T, String> tooltipProvider,
                      @Nullable GutterIconNavigationHandler<T> navHandler,
                      @Nonnull GutterIconRenderer.Alignment alignment) {
  myIcon = icon;
  myTooltipProvider = tooltipProvider;
  myIconAlignment = alignment;
  elementRef = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
  myNavigationHandler = navHandler;
  startOffset = range.getStartOffset();
  endOffset = range.getEndOffset();
  this.updatePass = 11; //Pass.LINE_MARKERS;
}
 
Example #4
Source File: ElementCreator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public PsiElement[] tryCreate(@Nonnull 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);
}
 
Example #5
Source File: InplaceVariableIntroducer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public MyIntroduceLookupExpression(final String initialName,
                                   final LinkedHashSet<String> names,
                                   final PsiNamedElement elementToRename,
                                   final boolean shouldSelectAll,
                                   final String advertisementText) {
  super(initialName, names, elementToRename, elementToRename, shouldSelectAll, advertisementText);
  myPointer = SmartPointerManager.getInstance(elementToRename.getProject()).createSmartPsiElementPointer(elementToRename);
}
 
Example #6
Source File: ReplaceTypeQuickFix.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public ReplaceTypeQuickFix(@Nonnull DotNetType type, @Nonnull DotNetTypeRef typeRef)
{
	myPointer = SmartPointerManager.getInstance(type.getProject()).createSmartPsiElementPointer(type);

	myTypeText = CSharpTypeRefPresentationUtil.buildShortText(typeRef, type);
	setText("Replace '" + type.getText() + "' by '" + myTypeText + "'");
}
 
Example #7
Source File: PsiElementUsageGroupBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public PsiElementUsageGroupBase(@Nonnull T element, Image icon) {
  String myName = element.getName();
  if (myName == null) myName = "<anonymous>";
  this.myName = myName;
  myElementPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);

  myIcon = icon;
}
 
Example #8
Source File: UsageInfoToUsageConverter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<SmartPsiElementPointer<PsiElement>> convertToSmartPointers(@Nonnull PsiElement[] primaryElements) {
  if (primaryElements.length == 0) return Collections.emptyList();

  final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(primaryElements[0].getProject());
  return ContainerUtil.mapNotNull(primaryElements, new Function<PsiElement, SmartPsiElementPointer<PsiElement>>() {
    @Override
    public SmartPsiElementPointer<PsiElement> fun(final PsiElement s) {
      return smartPointerManager.createSmartPsiElementPointer(s);
    }
  });
}
 
Example #9
Source File: QueryToXMLConverter.java    From dbunit-extractor with MIT License 5 votes vote down vote up
@Nullable
private SmartPsiElementPointer<SqlSelectStatement> getStatementPointer(final @NotNull Project project,
                                                                       final @NotNull PsiElement psiElement) {
    final SqlSelectStatement sqlSelectStatement =
            PsiTreeUtil.getParentOfType(psiElement.getContainingFile().findElementAt(psiElement.getTextOffset()),
                                        SqlSelectStatement.class);
    SmartPsiElementPointer<SqlSelectStatement> pointer = null;
    if (sqlSelectStatement != null) {
        pointer = SmartPointerManager.getInstance(project)
                                     .createSmartPsiElementPointer(sqlSelectStatement);
    }
    return pointer;
}
 
Example #10
Source File: BasePsiNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
public BasePsiNode(final T element) {
  super(element.getProject());
  if (element.isValid()) {
    myPsiElementPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(element);
  }
  else {
    myPsiElementPointer = null;
  }
}
 
Example #11
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setData(@Nullable PsiElement element, @Nonnull String text, @Nullable String effectiveExternalUrl, @Nullable String ref, @Nullable DocumentationProvider provider) {
  pushHistory();
  myExternalUrl = effectiveExternalUrl;
  myProvider = provider;

  SmartPsiElementPointer<PsiElement> pointer = null;
  if (element != null && element.isValid()) {
    pointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
  }
  setDataInternal(pointer, text, new Rectangle(0, 0), ref);
}
 
Example #12
Source File: PsiTreeAnchorizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Object createAnchor(@Nonnull Object element) {
  if (element instanceof PsiElement) {
    PsiElement psi = (PsiElement)element;
    return ReadAction.compute(() -> {
      if (!psi.isValid()) return psi;
      return SmartPointerManager.getInstance(psi.getProject()).createSmartPsiElementPointer(psi);
    });
  }
  return super.createAnchor(element);
}
 
Example #13
Source File: PsiTreeAnchorizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void freeAnchor(final Object element) {
  if (element instanceof SmartPsiElementPointer) {
    ApplicationManager.getApplication().runReadAction(() -> {
      SmartPsiElementPointer pointer = (SmartPsiElementPointer)element;
      Project project = pointer.getProject();
      if (!project.isDisposed()) {
        SmartPointerManager.getInstance(project).removePointer(pointer);
      }
    });
  }
}
 
Example #14
Source File: NavigationGutterIconBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private MyNavigationGutterIconRenderer createGutterIconRenderer(@Nonnull Project project) {
  checkBuilt();
  final SmartPointerManager manager = SmartPointerManager.getInstance(project);

  NotNullLazyValue<List<SmartPsiElementPointer>> pointers = new NotNullLazyValue<List<SmartPsiElementPointer>>() {
    @Override
    @Nonnull
    public List<SmartPsiElementPointer> compute() {
      Set<PsiElement> elements = new THashSet<PsiElement>();
      Collection<? extends T> targets = myTargets.getValue();
      final List<SmartPsiElementPointer> list = new ArrayList<SmartPsiElementPointer>(targets.size());
      for (final T target : targets) {
        for (final PsiElement psiElement : myConverter.fun(target)) {
          if (elements.add(psiElement) && psiElement.isValid()) {
            list.add(manager.createSmartPsiElementPointer(psiElement));
          }
        }
      }
      return list;
    }
  };

  final boolean empty = isEmpty();

  if (myTooltipText == null && !myLazy) {
    final SortedSet<String> names = new TreeSet<String>();
    for (T t : myTargets.getValue()) {
      final String text = myNamer.fun(t);
      if (text != null) {
        names.add(MessageFormat.format(PATTERN, text));
      }
    }
    @NonNls StringBuilder sb = new StringBuilder("<html><body>");
    if (myTooltipTitle != null) {
      sb.append(myTooltipTitle).append("<br>");
    }
    for (String name : names) {
      sb.append(name).append("<br>");
    }
    sb.append("</body></html>");
    myTooltipText = sb.toString();
  }

  Computable<PsiElementListCellRenderer> renderer =
    myCellRenderer == null ? new Computable<PsiElementListCellRenderer>() {
      @Override
      public PsiElementListCellRenderer compute() {
        return new DefaultPsiElementCellRenderer();
      }
    } : myCellRenderer;
  return new MyNavigationGutterIconRenderer(this, myAlignment, myIcon, myTooltipText, pointers, renderer, empty);
}
 
Example #15
Source File: UpdateFoldRegionsOperation.java    From consulo with Apache License 2.0 4 votes vote down vote up
private List<FoldRegion> addNewRegions(@Nonnull EditorFoldingInfo info,
                                       @Nonnull FoldingModelEx foldingModel,
                                       @Nonnull Map<TextRange, Boolean> rangeToExpandStatusMap,
                                       @Nonnull Map<FoldRegion, Boolean> shouldExpand,
                                       @Nonnull Map<FoldingGroup, Boolean> groupExpand) {
  List<FoldRegion> newRegions = new ArrayList<>();
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  for (FoldingUpdate.RegionInfo regionInfo : myRegionInfos) {
    ProgressManager.checkCanceled();
    FoldingDescriptor descriptor = regionInfo.descriptor;
    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;

    if (descriptor.isNonExpandable()) region.putUserData(FoldingModelImpl.SELECT_REGION_ON_CARET_NEARBY, Boolean.TRUE);

    PsiElement psi = descriptor.getElement().getPsi();

    if (psi == null || !psi.isValid() || !myFile.isValid()) {
      region.dispose();
      continue;
    }

    region.setGutterMarkEnabledForSingleLine(descriptor.isGutterMarkEnabledForSingleLine());

    if (descriptor.canBeRemovedWhenCollapsed()) region.putUserData(CAN_BE_REMOVED_WHEN_COLLAPSED, Boolean.TRUE);
    region.putUserData(COLLAPSED_BY_DEFAULT, regionInfo.collapsedByDefault);
    region.putUserData(SIGNATURE, ObjectUtils.chooseNotNull(regionInfo.signature, NO_SIGNATURE));

    info.addRegion(region, smartPointerManager.createSmartPsiElementPointer(psi));
    newRegions.add(region);

    boolean expandStatus = !descriptor.isNonExpandable() && shouldExpandNewRegion(range, rangeToExpandStatusMap, regionInfo.collapsedByDefault);
    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;
}
 
Example #16
Source File: LookupElementBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static LookupElementBuilder createWithSmartPointer(@Nonnull String lookupString, @Nonnull PsiElement element) {
  PsiUtilCore.ensureValid(element);
  return new LookupElementBuilder(lookupString, SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element));
}
 
Example #17
Source File: IconDescriptorUpdaters.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ElementIconRequest(PsiElement element, @Iconable.IconFlags int flags) {
  myPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
  myFlags = flags;
}
 
Example #18
Source File: RefElementImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected RefElementImpl(@Nonnull String name, @Nonnull PsiElement element, @Nonnull RefManager manager) {
  super(name, manager);
  myID = SmartPointerManager.getInstance(manager.getProject()).createSmartPsiElementPointer(element);
  myFlags = 0;
}
 
Example #19
Source File: DefaultChooseByNameItemProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DefaultChooseByNameItemProvider(@Nullable PsiElement context) {
  myContext = context == null ? null : SmartPointerManager.getInstance(context.getProject()).createSmartPsiElementPointer(context);
}
 
Example #20
Source File: LiteFixture.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void setContext(final PsiFile psiFile, final PsiElement context) {
  if (context != null) {
    psiFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, SmartPointerManager.getInstance(context.getProject()).createSmartPsiElementPointer(context));
  }
}
 
Example #21
Source File: CS0453.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public DeleteQuestMarkQuickFix(CSharpNullableType nullableType)
{
	myPointer = SmartPointerManager.getInstance(nullableType.getProject()).createSmartPsiElementPointer(nullableType);
	setText("Remove '?'");
}
 
Example #22
Source File: CreateMethodQuickFix.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public CreateMethodQuickFix(@NotNull PhpClass phpClass, @NotNull String functionName, @NotNull InsertStringInterface stringInterface) {
    this.smartPhpClass = SmartPointerManager.getInstance(phpClass.getProject()).createSmartPsiElementPointer(phpClass);
    this.functionName = functionName;
    this.stringInterface = stringInterface;
}
 
Example #23
Source File: RenameQuickFix.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public RenameQuickFix(@Nonnull String newName, @Nonnull PsiNamedElement namedElement)
{
	myNewName = newName;
	myPointer = SmartPointerManager.getInstance(namedElement.getProject()).createSmartPsiElementPointer(namedElement);
	setText("Rename '" + namedElement.getName() + "' to '" + myNewName + "'");
}
 
Example #24
Source File: SmartElementDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public SmartElementDescriptor(@Nonnull Project project, NodeDescriptor parentDescriptor, @Nonnull PsiElement element) {
  super(project, parentDescriptor);
  mySmartPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(element);
}
 
Example #25
Source File: CastExpressionToTypeRef.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CastExpressionToTypeRef(@Nonnull DotNetExpression expression, @Nonnull DotNetTypeRef expectedTypeRef)
{
	myExpressionPointer = SmartPointerManager.getInstance(expression.getProject()).createSmartPsiElementPointer(expression);
	myExpectedTypeRef = expectedTypeRef;
}
 
Example #26
Source File: CommandCamelCaseInspection.java    From arma-intellij-plugin with MIT License 4 votes vote down vote up
public CamelCaseFixAction(@NotNull SQFPsiCommand command) {
	this.commandPointer = SmartPointerManager.getInstance(command.getProject()).createSmartPsiElementPointer(command);
}
 
Example #27
Source File: CommandCamelCaseInspection.java    From arma-intellij-plugin with MIT License 4 votes vote down vote up
public CamelCaseFixAction(@NotNull SQFPsiCommand command) {
	this.commandPointer = SmartPointerManager.getInstance(command.getProject()).createSmartPsiElementPointer(command);
}
 
Example #28
Source File: RegisterShebangCommandQuickfix.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
public RegisterShebangCommandQuickfix(FixShebangInspection fixShebangInspection, BashShebang shebang) {
    this.inspection = fixShebangInspection;

    Project project = shebang.getProject();
    this.shebang = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(shebang);
}
 
Example #29
Source File: ReferenceDiagramDataModel.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
public ReferenceDiagramDataModel(Project project, DiagramProvider<PsiElement> provider) {
    super(project, provider);
    this.spManager = SmartPointerManager.getInstance(getProject());
}
 
Example #30
Source File: ConvertNamedToSimpleArgumentFix.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public ConvertNamedToSimpleArgumentFix(CSharpNamedCallArgument element)
{
	setText("Convert to simple argument");
	myPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
}