本文整理匯總了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;
}
示例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;
}
示例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");
}
示例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 "";
}
示例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;
}
示例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
) {}
);
}
}
}
}
}
示例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);
}
});
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}