當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiNameIdentifierOwner.getNameIdentifier方法代碼示例

本文整理匯總了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());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:PsiIdentifierOwnerTokenizer.java

示例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));
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:PyShadowingBuiltinsInspection.java

示例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;
}
 
開發者ID:consulo,項目名稱:consulo-csharp,代碼行數:24,代碼來源:CSharpPsiUtilImpl.java

示例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;
}
 
開發者ID:kalessil,項目名稱:yii2inspections,代碼行數:13,代碼來源:NamedElementUtil.java

示例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();
}
 
開發者ID:rentalhost,項目名稱:laravel-insight,代碼行數:12,代碼來源:ColumnWithoutAnnotationInspection.java

示例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());
                }
            }
        }
    }
}
 
開發者ID:PioBeat,項目名稱:GravSupport,代碼行數:16,代碼來源:CustomCreateFromTemplateAction.java

示例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);
}
 
開發者ID:protostuff,項目名稱:protobuf-jetbrains-plugin,代碼行數:14,代碼來源:GenericNameNode.java

示例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());
        }
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:CreateFromTemplateAction.java

示例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());
        }
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:35,代碼來源:PyShadowingNamesInspection.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:HighlightUtils.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:28,代碼來源:HighlightUtil.java

示例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());
        }
      }
    }
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:16,代碼來源:CreateFromTemplateAction.java

示例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);
}
 
開發者ID:consulo,項目名稱:consulo-csharp,代碼行數:14,代碼來源:CSharpRefactoringUtil.java

示例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());
}
 
開發者ID:consulo,項目名稱:consulo-csharp,代碼行數:34,代碼來源:CSharpSpellcheckingStrategy.java

示例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;
}
 
開發者ID:consulo,項目名稱:consulo-dotnet,代碼行數:34,代碼來源:DotNetDebuggerProvider.java


注:本文中的com.intellij.psi.PsiNameIdentifierOwner.getNameIdentifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。