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


Java PsiNameIdentifierOwner.getName方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiNameIdentifierOwner.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiNameIdentifierOwner.getName方法的具體用法?Java PsiNameIdentifierOwner.getName怎麽用?Java PsiNameIdentifierOwner.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiNameIdentifierOwner的用法示例。


在下文中一共展示了PsiNameIdentifierOwner.getName方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: initOccurrencesNumber

import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
protected static int initOccurrencesNumber(PsiNameIdentifierOwner nameIdentifierOwner) {
  final ProgressManager progressManager = ProgressManager.getInstance();
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(nameIdentifierOwner.getProject());
  final GlobalSearchScope scope = GlobalSearchScope.projectScope(nameIdentifierOwner.getProject());
  final String name = nameIdentifierOwner.getName();
  final boolean isCheapToSearch =
   name != null && searchHelper.isCheapEnoughToSearch(name, scope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
  return isCheapToSearch ? ReferencesSearch.search(nameIdentifierOwner).findAll().size() : - 1;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:10,代碼來源:InlineOptionsDialog.java

示例3: 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

示例4: perform

import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
public void perform() {
  final PsiNameIdentifierOwner element = getNamedElement();
  if (element != null) {
    final String name = element.getName();
    ApplicationManager.getApplication().runWriteAction(() -> {
      element.setName(myOldName);
    });
    new RenameProcessor(element.getProject(), element, name, false, false).run();
  }
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:11,代碼來源:RenameChangeInfo.java

示例5: processElement

import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
private void processElement(@NotNull final PsiNameIdentifierOwner element) {
  if (isConditional(element)) {
    return;
  }
  final String name = element.getName();
  final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
  if (owner != null && name != null) {
    final Instruction[] instructions = ControlFlowCache.getControlFlow(owner).getInstructions();
    PsiElement elementInControlFlow = element;
    if (element instanceof PyTargetExpression) {
      final PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class);
      if (importStatement != null) {
        elementInControlFlow = importStatement;
      }
    }
    final int startInstruction = ControlFlowUtil.findInstructionNumberByElement(instructions, elementInControlFlow);
    if (startInstruction < 0) {
      return;
    }
    final Ref<PsiElement> readElementRef = Ref.create(null);
    final Ref<PsiElement> writeElementRef = Ref.create(null);
    ControlFlowUtil.iteratePrev(startInstruction, instructions, new Function<Instruction, ControlFlowUtil.Operation>() {
      @Override
      public ControlFlowUtil.Operation fun(Instruction instruction) {
        if (instruction instanceof ReadWriteInstruction && instruction.num() != startInstruction) {
          final ReadWriteInstruction rwInstruction = (ReadWriteInstruction)instruction;
          if (name.equals(rwInstruction.getName())) {
            final PsiElement originalElement = rwInstruction.getElement();
            if (originalElement != null) {
              if (rwInstruction.getAccess().isReadAccess()) {
                readElementRef.set(originalElement);
              }
              if (rwInstruction.getAccess().isWriteAccess()) {
                if (originalElement != element) {
                  writeElementRef.set(originalElement);
                }
              }
            }
            return ControlFlowUtil.Operation.CONTINUE;
          }
        }
        return ControlFlowUtil.Operation.NEXT;
      }
    });
    final PsiElement writeElement = writeElementRef.get();
    if (writeElement != null && readElementRef.get() == null) {
      final List<LocalQuickFix> quickFixes = new ArrayList<LocalQuickFix>();
      if (suggestRename(element, writeElement)) {
        quickFixes.add(new PyRenameElementQuickFix());
      }
      final PsiElement identifier = element.getNameIdentifier();
      registerProblem(identifier != null ? identifier : element,
                      PyBundle.message("INSP.redeclared.name", name),
                      ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                      null,
                      quickFixes.toArray(new LocalQuickFix[quickFixes.size()]));
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:60,代碼來源:PyRedeclarationInspection.java

示例6: processElement

import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
private void processElement(@NotNull final PsiNameIdentifierOwner element, @NotNull final String elementType) {
    if (isConditional(element)) {
        return;
    }
    final String name = element.getName();
    final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
    if (owner != null && name != null) {
        final Instruction[] instructions = ControlFlowCache.getControlFlow(owner).getInstructions();
        PsiElement elementInControlFlow = element;
        if (element instanceof PyTargetExpression) {
            final PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class);
            if (importStatement != null) {
                elementInControlFlow = importStatement;
            }
        }
        final int startInstruction = ControlFlowUtil.findInstructionNumberByElement(instructions, elementInControlFlow);
        if (startInstruction < 0) {
            return;
        }
        final Ref<PsiElement> readElementRef = Ref.create(null);
        final Ref<PsiElement> writeElementRef = Ref.create(null);
        ControlFlowUtil.iteratePrev(startInstruction, instructions, instruction -> {
            if (instruction instanceof ReadWriteInstruction && instruction.num() != startInstruction) {
                final ReadWriteInstruction rwInstruction = (ReadWriteInstruction) instruction;
                if (name.equals(rwInstruction.getName())) {
                    final PsiElement originalElement = rwInstruction.getElement();
                    if (originalElement != null) {
                        if (rwInstruction.getAccess().isReadAccess()) {
                            readElementRef.set(originalElement);
                        }
                        if (rwInstruction.getAccess().isWriteAccess()) {
                            if (originalElement != element) {
                                writeElementRef.set(originalElement);
                            }
                        }
                    }
                    return ControlFlowUtil.Operation.CONTINUE;
                }
            }
            return ControlFlowUtil.Operation.NEXT;
        });
        final PsiElement writeElement = writeElementRef.get();
        if (writeElement != null && readElementRef.get() == null) {
            final List<LocalQuickFix> quickFixes = new ArrayList<LocalQuickFix>();
            if (suggestRename(element, writeElement)) {
                quickFixes.add(new PyRenameElementQuickFix());
            }
            final PsiElement identifier = element.getNameIdentifier();
            registerProblem(identifier != null ? identifier : element,
                    String.format("Redeclared decorated %s ''%s'' defined above", elementType, name),
                    ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                    null,
                    quickFixes.toArray(new LocalQuickFix[quickFixes.size()]));
        }
    }
}
 
開發者ID:KarlGong,項目名稱:ptest-pycharm-plugin,代碼行數:57,代碼來源:PTestRedeclarationInspection.java

示例7: RenameChangeInfo

import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
public RenameChangeInfo(final PsiNameIdentifierOwner namedElement, final ChangeInfo oldInfo) {
  myOldName = oldInfo instanceof RenameChangeInfo ? ((RenameChangeInfo)oldInfo).getOldName() : namedElement.getName();
  myFile = namedElement.getContainingFile();
  myOffset = namedElement.getTextOffset();
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:6,代碼來源:RenameChangeInfo.java

示例8: getNewName

import com.intellij.psi.PsiNameIdentifierOwner; //導入方法依賴的package包/類
@Override
public String getNewName() {
  final PsiNameIdentifierOwner nameOwner = getNamedElement();
  return nameOwner != null ? nameOwner.getName() : null;
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:6,代碼來源:RenameChangeInfo.java


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