com.intellij.psi.PsiNamedElement#getName ( )源码实例Demo

下面列出了com.intellij.psi.PsiNamedElement#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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;
}
 
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);
    }
  };
}
 
源代码3 项目: intellij   文件: CompletionResultsProcessor.java
@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;
}
 
源代码4 项目: antlr4-intellij-adaptor   文件: SymtabUtils.java
/** 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;
}
 
@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));
            }
        }
    }
}
 
源代码6 项目: consulo-csharp   文件: CSharpElementTreeNode.java
@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();
	}
}
 
源代码7 项目: intellij-swagger   文件: PathFinder.java
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());
}
 
/**
 * 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;
}
 
源代码9 项目: consulo-csharp   文件: CSharpNamedTreeElement.java
@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();
	}
}
 
源代码10 项目: consulo   文件: AutomaticRenamer.java
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);
    }
  }
}
 
源代码11 项目: lsp4intellij   文件: LSPInplaceRenamer.java
LSPInplaceRenamer(@NotNull PsiNamedElement elementToRename, PsiElement substituted, Editor editor) {
    super(elementToRename, substituted, editor, elementToRename.getName(), elementToRename.getName());
    this.editor = editor;
}
 
源代码12 项目: intellij   文件: NamedBuildLookupElement.java
public NamedBuildLookupElement(PsiNamedElement element, QuoteType quoteType) {
  super(element.getName(), quoteType);
  this.element = element;
}
 
 同类方法