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


Java PsiNamedElement類代碼示例

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


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

示例1: findJavaUsages

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
static Map<Pair<FeaturePath, PsiElement>, List<UsageInfo>> findJavaUsages( PsiElement element, List<PsiElement> javaElems )
{
  if( !(element instanceof PsiNamedElement) || javaElems.isEmpty() )
  {
    return Collections.emptyMap();
  }

  Map<Pair<FeaturePath, PsiElement>, List<UsageInfo>> allUsages = new HashMap<>();
  for( PsiElement javaElem : javaElems )
  {
    if( javaElem == null )
    {
      continue;
    }

    List<UsageInfo> usages = findUsages( javaElem, element );
    if( !usages.isEmpty() )
    {
      FeaturePath path = javaElem.getUserData( KEY_FEATURE_PATH );
      allUsages.put( new Pair<>( path, javaElem ), usages );
    }
  }

  return allUsages;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:26,代碼來源:RenameResourceElementProcessor.java

示例2: getDependencyInfo

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Nullable
@Override
public DiagramRelationshipInfo getDependencyInfo(PsiNamedElement e1,
                                                 PsiNamedElement e2,
                                                 DiagramCategory diagramCategory) {
  if (e1 instanceof SchemaTypeDef && e2 instanceof SchemaTypeDef) {
    SchemaTypeDef td1 = (SchemaTypeDef) e1;
    SchemaTypeDef td2 = (SchemaTypeDef) e2;

    if (td2.extendsParents().contains(e1)) return EXTENDS;

    SchemaMetaDecl metaDecl = td1.getMetaDecl();
    if (metaDecl != null) {
      SchemaQnTypeRef typeRef = metaDecl.getQnTypeRef();
      if (typeRef != null) {
        SchemaTypeDef typeDef = typeRef.resolve();
        if (e2.equals(typeDef)) return META;
      }
    }
  }
  return null;
}
 
開發者ID:SumoLogic,項目名稱:epigraph,代碼行數:23,代碼來源:SchemaDiagramRelationshipManager.java

示例3: doTest

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
private void doTest() throws Exception {
  final String filename = getTestName(true) + ".xml";
  VirtualFile vfile = VirtualFileManager.getInstance().findFileByUrl("file://" + getTestDataPath() + filename);
  String text = FileDocumentManager.getInstance().getDocument(vfile).getText();
  final int off = text.indexOf("<ren>");
  text = text.replace("<ren>", "");
  configureFromFileText(filename, text);
  assertNotNull(myFile);
  PsiElement element = TargetElementUtil.getInstance().findTargetElement(
    getEditor(), 
    TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED,
    off);
  assertNotNull(element);
  assertTrue(element instanceof PsiNamedElement);
  final RenameRefactoring rename =
    RefactoringFactory.getInstance(getProject()).createRename(element, ((PsiNamedElement)element).getName() + "-after");
  rename.setSearchInComments(false);
  rename.setSearchInNonJavaFiles(false);
  rename.run();
  checkResultByFile(filename + "-after");
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:AntRenameTest.java

示例4: getDescriptiveName

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@NotNull
public String getDescriptiveName(@NotNull PsiElement element) {
  String literalString = tryFindMagicLiteralString(element, true);
  if (literalString != null) {
    return literalString;
  }

  if (element instanceof PsiNamedElement) {
    final String name = ((PsiNamedElement)element).getName();
    return name == null ? "<unnamed>" : name;
  }
  if (element instanceof PyReferenceExpression) {
    String referencedName = ((PyReferenceExpression)element).getReferencedName();
    if (referencedName == null) {
      return "<unnamed>";
    }
    return referencedName;
  }
  return "";
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:PythonFindUsagesProvider.java

示例5: getName

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Nullable
public static String getName(@NotNull PsiNamedElement element, boolean qualified) {
  if (element instanceof SchemaQnSegment) {
    SchemaQnSegment qnSegment = (SchemaQnSegment) element;
    return qnSegment.getQn().toString();
  }

  String shortName = element.getName();
  if (shortName == null) return null;

  if (qualified) {
    Qn namespace;
    if (element instanceof SchemaTypeDef) {
      SchemaTypeDef typeDef = (SchemaTypeDef) element;
      namespace = typeDef.getNamespace();
    } else namespace = NamespaceManager.getNamespace(element);
    return namespace == null ? shortName : namespace.append(shortName).toString();
  } else return shortName;
}
 
開發者ID:SumoLogic,項目名稱:epigraph,代碼行數:20,代碼來源:SchemaPresentationUtil.java

示例6: addMeta

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
private void addMeta(SchemaTypeDef typeDef,
                     final DiagramNode<PsiNamedElement> node,
                     Collection<PsiNamedElement> allElements) {
  SchemaMetaDecl metaDecl = typeDef.getMetaDecl();
  if (metaDecl != null) {
    SchemaQnTypeRef typeRef = metaDecl.getQnTypeRef();
    if (typeRef != null) {
      SchemaTypeDef metaType = typeRef.resolve();
      if (metaType != null) {
        DiagramNode<PsiNamedElement> node2 = getOrAddNode(metaType, allElements);

        if (node2 != null) {
          edges.add(
              new DiagramEdgeBase<PsiNamedElement>(
                  node, node2, SchemaDiagramRelationshipManager.META
              ) {}
          );
        }
      }
    }
  }
}
 
開發者ID:SumoLogic,項目名稱:epigraph,代碼行數:23,代碼來源:SchemaDiagramDataModel.java

示例7: collect

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Override
public void collect(final PsiNamedElement member) {
  if (member.getContainingFile() == myModule) {
    final PyResolveContext resolveContext = PyResolveContext.defaultContext();
    final PsiElement memberBody = PyMoveModuleMembersHelper.expandNamedElementBody(member);
    assert memberBody != null;
    memberBody.accept(new PyRecursiveElementVisitor() {
      @Override
      public void visitElement(PsiElement element) {
        for (PsiElement result : PyUtil.multiResolveTopPriority(element, resolveContext)) {
          if (result != null && isValidSameModuleDependency(result) && result != member) {
            myCollection.add((PsiNamedElement)result);
          }
        }
        super.visitElement(element);
      }
    });
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:PyDependentModuleMembersCollector.java

示例8: getTokenizer

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@NotNull
@Override
public Tokenizer getTokenizer(PsiElement element) {
  if (element instanceof PsiMethod) {
    return myMethodNameTokenizer;
  }
  if (element instanceof PsiDocComment) {
    return myDocCommentTokenizer;
  }
  if (element instanceof PsiLiteralExpression) {
    if (SuppressManager.isSuppressedInspectionName((PsiLiteralExpression)element)) {
      return EMPTY_TOKENIZER;
    }
    return myLiteralExpressionTokenizer;
  }
  if (element instanceof PsiNamedElement) {
    return myNamedElementTokenizer;
  }

  return super.getTokenizer(element);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:JavaSpellcheckingStrategy.java

示例9: doTest

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
private void doTest(final String... candidatesNames) {
  myFixture.configureByFile(getTestName(false) + ".java");
  final AddMethodQualifierFix addMethodQualifierFix = getQuickFix();
  if (candidatesNames.length == 0) {
    assertNull(addMethodQualifierFix);
    return;
  }
  assertNotNull(addMethodQualifierFix);
  final Set<String> actualCandidatesNames = new TreeSet<String>(ContainerUtil.map(addMethodQualifierFix.getCandidates(), new Function<PsiNamedElement, String>() {
    @Override
    public String fun(final PsiNamedElement psiNamedElement) {
      final String name = psiNamedElement.getName();
      assertNotNull(name);
      return name;
    }
  }));
  final Set<String> expectedCandidatesNames = new TreeSet<String>(ContainerUtil.list(candidatesNames));
  assertEquals(expectedCandidatesNames, actualCandidatesNames);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:AddMethodQualifierTest.java

示例10: getNameIdentifier

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Nullable
public static PsiElement getNameIdentifier(@NotNull PsiElement element) {
  if (element instanceof PsiNameIdentifierOwner) {
    return ((PsiNameIdentifierOwner)element).getNameIdentifier();
  }

  if (element.isPhysical() &&
      element instanceof PsiNamedElement &&
      element.getContainingFile() != null &&
      element.getTextRange() != null) {
    // Quite hacky way to get name identifier. Depends on getTextOffset overriden properly.
    final PsiElement potentialIdentifier = element.findElementAt(element.getTextOffset() - element.getTextRange().getStartOffset());
    if (potentialIdentifier != null && Comparing.equal(potentialIdentifier.getText(), ((PsiNamedElement)element).getName(), false)) {
      return potentialIdentifier;
    }
  }

  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:IdentifierUtil.java

示例11: resolveTopLevelMember

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Nullable
@Override
public <T extends PsiNamedElement> T resolveTopLevelMember(@NotNull final Class<T> aClass) {
  Preconditions.checkState(getModule() != null, "Module is not set");
  final String memberName = myQualifiedName.getLastComponent();
  if (memberName == null) {
    return null;
  }
  final PyFile file =
    new QualifiedNameResolverImpl(myQualifiedName.removeLastComponent()).fromModule(getModule()).firstResultOfType(PyFile.class);
  if (file == null) {
    return null;
  }
  for (final T element : PsiTreeUtil.getChildrenOfTypeAsList(file, aClass)) {
    if (memberName.equals(element.getName())) {
      return element;
    }
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:QualifiedNameResolverImpl.java

示例12: getNewName2PatternNameMap

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
public Map<String, String> getNewName2PatternNameMap() {
  Map<String, String> newNameToSearchPatternNameMap = new HashMap<String, String>(1);
  final Map<String, MatchResult> variableMap = replacementInfo.getVariableMap();

  if (variableMap != null) {
    for (String s : variableMap.keySet()) {
      final MatchResult matchResult = replacementInfo.getVariableMap().get(s);
      PsiElement match = matchResult.getMatchRef() != null ? matchResult.getMatch() : null;
      if (StructuralSearchUtil.isIdentifier(match)) match = match.getParent();

      if (match instanceof PsiNamedElement) {
        final String name = ((PsiNamedElement)match).getName();

        newNameToSearchPatternNameMap.put(name, s);
      }
    }
  }
  return newNameToSearchPatternNameMap;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:ReplacementContext.java

示例13: getDescriptiveName

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Override
@NotNull
public String getDescriptiveName(@NotNull PsiElement element) {
  if (element instanceof XmlTag) {
    return ((XmlTag)element).getName();
  }

  if (element instanceof XmlAttributeValue) {
    return ((XmlAttributeValue)element).getValue();
  }

  if (element instanceof PsiNamedElement) {
    return ((PsiNamedElement)element).getName();
  }
  return element.getText();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:XmlFindUsagesProvider.java

示例14: addTarget

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
public boolean addTarget(final PsiElement element) {
  if (ArrayUtil.find(targets, element) > -1) return false;
  targets = ArrayUtil.append(targets, element);
  renderers.put(element, createRenderer(this, element));
  if (!hasDifferentNames && element instanceof PsiNamedElement) {
    final String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
      @Override
      public String compute() {
        return ((PsiNamedElement)element).getName();
      }
    });
    myNames.add(name);
    hasDifferentNames = myNames.size() > 1;
  }
  return true;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:GotoTargetHandler.java

示例15: restoreElementInternal

import com.intellij.psi.PsiNamedElement; //導入依賴的package包/類
@Nullable
protected static <T extends PsiNamedElement> T restoreElementInternal(@NotNull PsiElement parent,
                                                                      String name,
                                                                      int index,
                                                                      @NotNull Class<T> hisClass)
{
  PsiElement[] children = parent.getChildren();

  for (PsiElement child : children) {
    if (ReflectionUtil.isAssignable(hisClass, child.getClass())) {
      T namedChild = hisClass.cast(child);
      final String childName = namedChild.getName();

      if (Comparing.equal(name, childName)) {
        if (index == 0) {
          return namedChild;
        }
        index--;
      }
    }
  }

  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:AbstractElementSignatureProvider.java


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