Java Code Examples for com.intellij.psi.PsiNamedElement#getName()

The following examples show how to use com.intellij.psi.PsiNamedElement#getName() . 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: NASMReferenceProvider.java    From JetBrains-NASM-Language with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
                                             @NotNull ProcessingContext context) {
    if (element instanceof PsiNamedElement) {
        PsiNamedElement namedElement = (PsiNamedElement) element;
        String value = namedElement.getName();
        if (value != null) {
            int valueIndex = namedElement.getText().indexOf(value);
            if (valueIndex >= 0) {
                return new PsiReference[]{new NASMReference(element, new TextRange(valueIndex, valueIndex + value.length()))};
            }
        }
    }

    return PsiReference.EMPTY_ARRAY;
}
 
Example 2
Source File: SoyPsiElementPresentationFactory.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
static ItemPresentation getItemPresentation(PsiNamedElement element) {
  return new ItemPresentation() {

    @Nullable
    @Override
    public String getPresentableText() {
      return element.getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      return null;
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return element.getIcon(Iconable.ICON_FLAG_READ_STATUS);
    }
  };
}
 
Example 3
Source File: CompletionResultsProcessor.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(BuildElement buildElement) {
  if (buildElement == originalElement) {
    return true;
  }
  if (buildElement instanceof LoadedSymbol) {
    LoadedSymbol loadedSymbol = (LoadedSymbol) buildElement;
    String string = loadedSymbol.getSymbolString();
    results.put(string, new LoadedSymbolReferenceLookupElement(loadedSymbol, string, quoteType));
  } else if (buildElement instanceof PsiNamedElement) {
    PsiNamedElement namedElement = (PsiNamedElement) buildElement;
    String name = namedElement.getName();
    if (!allowPrivateSymbols && name != null && name.startsWith("_")) {
      return true;
    }
    results.put(name, new NamedBuildLookupElement((PsiNamedElement) buildElement, quoteType));
  }
  return true;
}
 
Example 4
Source File: SymtabUtils.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Return the root of a def subtree chosen from among the
 *  matches from xpathToIDNodes that matches namedElement's text.
 *  Assumption: ID nodes are direct children of def subtree roots.
 */
public static PsiElement resolve(ScopeNode scope,
                                 Language language,
                                 PsiNamedElement namedElement,
                                 String xpathToIDNodes)
{
	Collection<? extends PsiElement> defIDNodes =
		XPath.findAll(language, scope, xpathToIDNodes);
	String id = namedElement.getName();
	PsiElement idNode = Trees.toMap(defIDNodes).get(id); // Find identifier node of variable definition
	if ( idNode!=null ) {
		return idNode.getParent(); // return the def subtree root
	}

	// If not found, ask the enclosing scope/context to resolve.
	// That might lead back to this method, but probably with a
	// different xpathToIDNodes (which is why I don't call this method
	// directly).
	ScopeNode context = scope.getContext();
	if ( context!=null ) {
		return context.resolve(namedElement);
	}
	// must be top scope; no resolution for element
	return null;
}
 
Example 5
Source File: HaskellLineMarkerProvider.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element,
                        Collection<? super RelatedItemLineMarkerInfo> result) {
    if (false && element instanceof PsiNamedElement) {
        PsiNamedElement namedElement = (PsiNamedElement) element;
        String value = namedElement.getName();
        if (value != null) {
            Project project = element.getProject();
            final List<HaskellUtil.FoundDefinition> found =
                    HaskellUtil.findDefinitionNode(project, value, namedElement);
            final List<PsiNamedElement> namedNodes = ContainerUtil.newArrayList();
            for (HaskellUtil.FoundDefinition fd : found) {
                namedNodes.add(fd.element);
            }

            if (namedNodes.size() > 0) {
                NavigationGutterIconBuilder<PsiElement> builder =
                        NavigationGutterIconBuilder.create(HaskellIcons.FILE).
                                setTargets(namedNodes).
                                setTooltipText("Navigate to element definition");
                result.add(builder.createLineMarkerInfo(element));
            }
        }
    }
}
 
Example 6
Source File: CSharpElementTreeNode.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
public static String getPresentableText(PsiNamedElement value)
{
	if(value instanceof DotNetLikeMethodDeclaration)
	{
		return CSharpElementPresentationUtil.formatMethod((DotNetLikeMethodDeclaration) value, CSharpElementPresentationUtil.METHOD_SCALA_LIKE_FULL);
	}
	else if(value instanceof DotNetFieldDeclaration)
	{
		return CSharpElementPresentationUtil.formatField((DotNetFieldDeclaration) value);
	}
	else if(value instanceof DotNetNamespaceDeclaration)
	{
		return ((DotNetNamespaceDeclaration) value).getPresentableQName();
	}
	else if(value instanceof DotNetTypeDeclaration)
	{
		return DotNetElementPresentationUtil.formatTypeWithGenericParameters((DotNetTypeDeclaration) value);
	}
	else
	{
		return value.getName();
	}
}
 
Example 7
Source File: PathFinder.java    From intellij-swagger with MIT License 5 votes vote down vote up
private PsiNamedElement getNextNamedParent(final PsiElement psiElement) {
  if (psiElement == null) {
    return null;
  }

  if (psiElement instanceof PsiNamedElement) {
    final PsiNamedElement namedElement = (PsiNamedElement) psiElement;

    if (namedElement.getName() != null && !namedElement.getName().contains(DUMMY_IDENTIFIER)) {
      return namedElement;
    }
  }

  return getNextNamedParent(psiElement.getParent());
}
 
Example 8
Source File: PresentationUtil.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns presentation name for given element.
 */
@Nullable
public static String getNameForElement(PsiElement element) {
    if (element instanceof DataType) {
        DataType type = (DataType) element;
        return type.getFullName();
    }
    if (element instanceof ProtoRootNode) {
        ProtoRootNode rootNode = (ProtoRootNode) element;
        String packageName = rootNode.getPackageName();
        if (packageName.isEmpty()) {
            return null;
        }
        return packageName;
    }
    if (element instanceof MessageField) {
        MessageField field = (MessageField) element;
        String fieldName = field.getFieldName();
        DataTypeContainer container = PsiTreeUtil.getParentOfType(element, DataTypeContainer.class);
        String conteinerName = getNameForElement(container);
        if (conteinerName != null) {
            return ProtostuffBundle.message("element.context.display", fieldName, conteinerName);
        } else {
            return fieldName;
        }
    }
    if (element instanceof PsiNamedElement) {
        PsiNamedElement namedElement = (PsiNamedElement) element;
        return namedElement.getName();
    }
    return null;
}
 
Example 9
Source File: CSharpNamedTreeElement.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredUIAccess
public String getPresentableText()
{
	PsiNamedElement value = getValue();
	if(value instanceof DotNetLikeMethodDeclaration)
	{
		return CSharpElementPresentationUtil.formatMethod((DotNetLikeMethodDeclaration) value, CSharpElementPresentationUtil.METHOD_SCALA_LIKE_FULL);
	}
	else if(value instanceof DotNetTypeDeclaration)
	{
		return DotNetElementPresentationUtil.formatTypeWithGenericParameters((DotNetTypeDeclaration)value);
	}
	else if(value instanceof DotNetFieldDeclaration)
	{
		return CSharpElementPresentationUtil.formatField((DotNetFieldDeclaration) value);
	}
	else if(value instanceof DotNetPropertyDeclaration)
	{
		return CSharpElementPresentationUtil.formatProperty((DotNetPropertyDeclaration) value, CSharpElementPresentationUtil.PROPERTY_SCALA_LIKE_FULL);
	}
	else if(value instanceof DotNetNamespaceDeclaration)
	{
		return ((DotNetNamespaceDeclaration) value).getPresentableQName();
	}
	else
	{
		return value.getName();
	}
}
 
Example 10
Source File: AutomaticRenamer.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void suggestAllNames(final String oldClassName, String newClassName) {
  final NameSuggester suggester = new NameSuggester(oldClassName, newClassName);
  for (int varIndex = myElements.size() - 1; varIndex >= 0; varIndex--) {
    final PsiNamedElement element = myElements.get(varIndex);
    final String name = element.getName();
    if (!myRenames.containsKey(element)) {
      String newName;
      if (oldClassName.equals(name)) {
        newName = newClassName;
      } else {
        String canonicalName = nameToCanonicalName(name, element);
        final String newCanonicalName = suggester.suggestName(canonicalName);
        if (newCanonicalName.length() == 0) {
          LOG.error("oldClassName = " + oldClassName + ", newClassName = " + newClassName + ", name = " + name + ", canonicalName = " +
                    canonicalName + ", newCanonicalName = " + newCanonicalName);
        }
        newName = canonicalNameToName(newCanonicalName, element);
      }
      if (!newName.equals(name)) {
        myRenames.put(element, newName);
      }
      else {
        myRenames.put(element, null);
      }
    }
    if (myRenames.get(element) == null) {
      myElements.remove(varIndex);
    }
  }
}
 
Example 11
Source File: LSPInplaceRenamer.java    From lsp4intellij with Apache License 2.0 4 votes vote down vote up
LSPInplaceRenamer(@NotNull PsiNamedElement elementToRename, PsiElement substituted, Editor editor) {
    super(elementToRename, substituted, editor, elementToRename.getName(), elementToRename.getName());
    this.editor = editor;
}
 
Example 12
Source File: NamedBuildLookupElement.java    From intellij with Apache License 2.0 4 votes vote down vote up
public NamedBuildLookupElement(PsiNamedElement element, QuoteType quoteType) {
  super(element.getName(), quoteType);
  this.element = element;
}