Java Code Examples for com.intellij.psi.PsiNameIdentifierOwner#getNameIdentifier()

The following examples show how to use com.intellij.psi.PsiNameIdentifierOwner#getNameIdentifier() . 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: ORLineMarkerProvider.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private void extractRelatedExpressions(@Nullable PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo<?>> result,
                                       @NotNull FileBase containingFile) {
    if (element == null) {
        return;
    }

    FileBase psiRelatedFile = PsiFinder.getInstance(containingFile.getProject()).findRelatedFile(containingFile);
    if (psiRelatedFile != null) {
        Collection<PsiNameIdentifierOwner> expressions = psiRelatedFile.getExpressions(element.getText());
        if (expressions.size() == 1) {
            PsiNameIdentifierOwner relatedElement = expressions.iterator().next();
            PsiElement nameIdentifier = relatedElement.getNameIdentifier();
            if (nameIdentifier != null) {
                String tooltip = GutterIconTooltipHelper
                        .composeText(new PsiElement[]{psiRelatedFile}, "", "Implements method <b>" + nameIdentifier.getText() + "</b> in <b>{0}</b>");
                result.add(NavigationGutterIconBuilder.
                        create(containingFile.isInterface() ? ORIcons.IMPLEMENTED : ORIcons.IMPLEMENTING).
                        setTooltipText(tooltip).
                        setAlignment(GutterIconRenderer.Alignment.RIGHT).
                        setTargets(Collections.singleton(nameIdentifier instanceof PsiLowerSymbol ? nameIdentifier.getFirstChild() : nameIdentifier)).
                        createLineMarkerInfo(element));
            }
        }
    }
}
 
Example 2
Source File: CSharpPsiUtilImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
public static String getNameWithAt(@Nonnull PsiNameIdentifierOwner element)
{
	PsiElement nameIdentifier = element.getNameIdentifier();
	if(nameIdentifier == null)
	{
		return null;
	}

	if(!(nameIdentifier instanceof CSharpIdentifier))
	{
		LOGGER.error("NameIdentifier is not 'CSharpIdentifier' element. Owner: " + element.getClass().getName());
		return nameIdentifier.getText();
	}

	String value = ((CSharpIdentifier) nameIdentifier).getValue();
	if(value == null)
	{
		return null;
	}
	return value;
}
 
Example 3
Source File: GenericNameNode.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Set name for a given element if it implements {@link PsiNameIdentifierOwner} and
 * {@link PsiNameIdentifierOwner#getNameIdentifier()} resolves to an instance of
 * {@link GenericNameNode}.
 */
public static PsiElement setName(PsiNameIdentifierOwner element, String name) {
    PsiElement nameIdentifier = element.getNameIdentifier();
    if (nameIdentifier instanceof GenericNameNode) {
        GenericNameNode nameNode = (GenericNameNode) nameIdentifier;
        return nameNode.setName(name);
    }
    throw new IncorrectOperationException(OPERATION_NOT_SUPPORTED);
}
 
Example 4
Source File: CSharpRefactoringUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
public static void replaceNameIdentifier(PsiNameIdentifierOwner owner, String newName)
{
	PsiElement nameIdentifier = owner.getNameIdentifier();
	if(!(nameIdentifier instanceof CSharpIdentifier))
	{
		return;
	}

	CSharpIdentifier newIdentifier = CSharpFileFactory.createIdentifier(owner.getProject(), newName);

	nameIdentifier.replace(newIdentifier);
}
 
Example 5
Source File: CreateFromTemplateAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void moveCaretAfterNameIdentifier(PsiNameIdentifierOwner createdElement) {
  final Project project = createdElement.getProject();
  final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
  if (editor != null) {
    final VirtualFile virtualFile = createdElement.getContainingFile().getVirtualFile();
    if (virtualFile != null) {
      if (FileDocumentManager.getInstance().getDocument(virtualFile) == editor.getDocument()) {
        final PsiElement nameIdentifier = createdElement.getNameIdentifier();
        if (nameIdentifier != null) {
          editor.getCaretModel().moveToOffset(nameIdentifier.getTextRange().getEndOffset());
        }
      }
    }
  }
}
 
Example 6
Source File: ORUtil.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@NotNull
public static TextRange getTextRangeForReference(@NotNull PsiNameIdentifierOwner name) {
    PsiElement nameIdentifier = name.getNameIdentifier();
    return rangeInParent(name.getTextRange(), nameIdentifier == null ? TextRange.EMPTY_RANGE : name.getTextRange());
}
 
Example 7
Source File: CSharpPsiUtilImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
public static boolean isNullOrEmpty(@Nonnull PsiNameIdentifierOwner owner)
{
	PsiElement nameIdentifier = owner.getNameIdentifier();
	return nameIdentifier == null || nameIdentifier instanceof CSharpIdentifier && ((CSharpIdentifier) nameIdentifier).getValue() == null;
}
 
Example 8
Source File: RenameChangeInfo.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public PsiElement getNameIdentifier() {
  final PsiNameIdentifierOwner namedElement = getNamedElement();
  return namedElement != null ? namedElement.getNameIdentifier() : null;
}