本文整理匯總了Java中com.intellij.psi.PsiNameIdentifierOwner.getNameIdentifier方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiNameIdentifierOwner.getNameIdentifier方法的具體用法?Java PsiNameIdentifierOwner.getNameIdentifier怎麽用?Java PsiNameIdentifierOwner.getNameIdentifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.PsiNameIdentifierOwner
的用法示例。
在下文中一共展示了PsiNameIdentifierOwner.getNameIdentifier方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: tokenize
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@Override
public void tokenize(@NotNull PsiNameIdentifierOwner element, TokenConsumer consumer) {
PsiElement identifier = element.getNameIdentifier();
if (identifier == null) {
return;
}
PsiElement parent = element;
final TextRange range = identifier.getTextRange();
if (range.isEmpty()) return;
int offset = range.getStartOffset() - parent.getTextRange().getStartOffset();
if(offset < 0 ) {
parent = PsiTreeUtil.findCommonParent(identifier, element);
offset = range.getStartOffset() - parent.getTextRange().getStartOffset();
}
String text = identifier.getText();
consumer.consumeToken(parent, text, true, offset, TextRange.allOf(text), IdentifierSplitter.getInstance());
}
示例2: processElement
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
private void processElement(@NotNull PsiNameIdentifierOwner element) {
final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
if (owner instanceof PyClass) {
return;
}
final String name = element.getName();
if (name != null && !myIgnoredNames.contains(name)) {
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(element);
final PsiElement builtin = builtinCache.getByName(name);
if (builtin != null && !PyUtil.inSameFile(builtin, element)) {
final PsiElement identifier = element.getNameIdentifier();
final PsiElement problemElement = identifier != null ? identifier : element;
registerProblem(problemElement, String.format("Shadows built-in name '%s'", name),
ProblemHighlightType.WEAK_WARNING, null, new PyRenameElementQuickFix(), new PyIgnoreBuiltinQuickFix(name));
}
}
}
示例3: getNameWithAt
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@Nullable
@RequiredReadAction
public static String getNameWithAt(@NotNull 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;
}
示例4: getNameIdentifier
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
/** returns name identifier, which is valid for reporting */
@Nullable
static public PsiElement getNameIdentifier(@Nullable PsiNameIdentifierOwner element) {
if (null != element) {
PsiElement id = element.getNameIdentifier();
boolean isIdReportable = null != id && id.getTextLength() > 0;
return isIdReportable ? id : null;
}
return null;
}
示例5: getReportableElement
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@Nullable
private static PsiElement getReportableElement(
@NotNull final PsiNameIdentifierOwner phpClass,
@NotNull final PhpClassMember fieldPrimaryKey
) {
if (Objects.equals(fieldPrimaryKey.getContainingClass(), phpClass)) {
return fieldPrimaryKey.getNameIdentifier();
}
return phpClass.getNameIdentifier();
}
示例6: moveCaretAfterNameIdentifier
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
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());
}
}
}
}
}
示例7: setName
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
/**
* 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);
}
示例8: moveCaretAfterNameIdentifier
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
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());
}
}
}
}
}
示例9: processElement
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
private void processElement(@NotNull PsiNameIdentifierOwner element) {
final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
if (owner instanceof PyClass) {
return;
}
final String name = element.getName();
if (name != null) {
final PsiElement identifier = element.getNameIdentifier();
final PsiElement problemElement = identifier != null ? identifier : element;
if ("_".equals(name)) {
return;
}
if (owner != null) {
final ScopeOwner nextOwner = ScopeUtil.getScopeOwner(owner);
if (nextOwner != null) {
final ResolveProcessor processor = new ResolveProcessor(name);
PyResolveUtil.scopeCrawlUp(processor, nextOwner, null, name, null, null);
final PsiElement resolved = processor.getResult();
if (resolved != null) {
final PyComprehensionElement comprehension = PsiTreeUtil.getParentOfType(resolved, PyComprehensionElement.class);
if (comprehension != null && PyUtil.isOwnScopeComprehension(comprehension)) {
return;
}
final Scope scope = ControlFlowCache.getScope(owner);
if (scope.isGlobal(name) || scope.isNonlocal(name)) {
return;
}
registerProblem(problemElement, String.format("Shadows name '%s' from outer scope", name),
ProblemHighlightType.WEAK_WARNING, null, new PyRenameElementQuickFix());
}
}
}
}
}
示例10: showRenameTemplate
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
public static void showRenameTemplate(PsiElement context,
PsiNameIdentifierOwner element,
PsiReference... references) {
context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(
context);
final Project project = context.getProject();
final FileEditorManager fileEditorManager =
FileEditorManager.getInstance(project);
final Editor editor = fileEditorManager.getSelectedTextEditor();
if (editor == null) {
return;
}
final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
final Expression macroCallNode = new MacroCallNode(
new SuggestVariableNameMacro());
final PsiElement identifier = element.getNameIdentifier();
builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
for (PsiReference reference : references) {
builder.replaceElement(reference, "PATTERN", "PATTERN",
false);
}
final Template template = builder.buildInlineTemplate();
final TextRange textRange = context.getTextRange();
final int startOffset = textRange.getStartOffset();
editor.getCaretModel().moveToOffset(startOffset);
final TemplateManager templateManager =
TemplateManager.getInstance(project);
templateManager.startTemplate(editor, template);
}
示例11: showRenameTemplate
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element) {
context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
final Query<PsiReference> query = ReferencesSearch.search(element, element.getUseScope());
final Collection<PsiReference> references = query.findAll();
final Project project = context.getProject();
final FileEditorManager fileEditorManager =
FileEditorManager.getInstance(project);
final Editor editor = fileEditorManager.getSelectedTextEditor();
if (editor == null) {
return;
}
final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
final Expression macroCallNode = new MacroCallNode(
new SuggestVariableNameMacro());
final PsiElement identifier = element.getNameIdentifier();
builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
for (PsiReference reference : references) {
builder.replaceElement(reference, "PATTERN", "PATTERN", false);
}
final Template template = builder.buildInlineTemplate();
final TextRange textRange = context.getTextRange();
final int startOffset = textRange.getStartOffset();
editor.getCaretModel().moveToOffset(startOffset);
final TemplateManager templateManager =
TemplateManager.getInstance(project);
templateManager.startTemplate(editor, template);
}
示例12: moveCaretAfterNameIdentifier
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
protected 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());
}
}
}
}
}
示例13: replaceNameIdentifier
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@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);
}
示例14: tokenize
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@Override
@RequiredReadAction
public void tokenize(@NotNull PsiNameIdentifierOwner owner, TokenConsumer tokenConsumer)
{
PsiElement identifier = owner.getNameIdentifier();
if(identifier == null)
{
return;
}
PsiElement parent = owner;
TextRange range = identifier.getTextRange();
if(range.isEmpty())
{
return;
}
String oldText = identifier.getText();
if(oldText.charAt(0) == '@')
{
range = new TextRange(range.getStartOffset() + 1, range.getEndOffset());
}
int offset = range.getStartOffset() - parent.getTextRange().getStartOffset();
if(offset < 0)
{
parent = PsiTreeUtil.findCommonParent(identifier, owner);
offset = range.getStartOffset() - parent.getTextRange().getStartOffset();
}
String text = CSharpPsiUtilImpl.getNameWithoutAt(oldText);
tokenConsumer.consumeToken(parent, text, true, offset, TextRange.allOf(text), IdentifierSplitter.getInstance());
}
示例15: getExpressionRangeAtOffset
import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@RequiredReadAction
@Nullable
public TextRange getExpressionRangeAtOffset(@NotNull PsiFile psiFile, int offset, boolean sideEffectsAllowed)
{
PsiElement elementAt = psiFile.findElementAt(offset);
if(elementAt == null)
{
return null;
}
PsiNameIdentifierOwner owner = PsiTreeUtil.getParentOfType(elementAt, PsiNameIdentifierOwner.class);
if(owner != null)
{
PsiElement nameIdentifier = owner.getNameIdentifier();
TextRange textRange = nameIdentifier == null ? null : nameIdentifier.getTextRange();
if(textRange != null && textRange.contains(offset))
{
return textRange;
}
}
DotNetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(elementAt, DotNetReferenceExpression.class);
if(referenceExpression != null)
{
// skip type references
if(PsiTreeUtil.getParentOfType(referenceExpression, DotNetType.class) != null)
{
return null;
}
return referenceExpression.getTextRange();
}
return null;
}