本文整理汇总了Java中com.intellij.psi.PsiPolyVariantReference类的典型用法代码示例。如果您正苦于以下问题:Java PsiPolyVariantReference类的具体用法?Java PsiPolyVariantReference怎么用?Java PsiPolyVariantReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiPolyVariantReference类属于com.intellij.psi包,在下文中一共展示了PsiPolyVariantReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResolvedProperty
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
@Nullable
private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) {
return CachedValuesManager.getCachedValue(codeValue, KEY, () -> {
List<IProperty> allProperties = new SmartList<>();
for (PsiReference nextRef : codeValue.getReferences()) {
if (nextRef instanceof PsiPolyVariantReference) {
Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false))
.filter(ResolveResult::isValidResult)
.map(ResolveResult::getElement)
.map(o -> ObjectUtils.tryCast(o, IProperty.class))
.filter(Objects::nonNull)
.forEach(allProperties::add);
} else {
Optional.ofNullable(nextRef.resolve())
.map(o -> ObjectUtils.tryCast(o, IProperty.class))
.ifPresent(allProperties::add);
}
}
IProperty theChosenOne = chooseForLocale(allProperties);
return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT);
});
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:24,代码来源:JspPropertyFoldingBuilder.java
示例2: findUsages
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
@Nullable
@Override
public List<UsageInfo> findUsages( PsiFile psiFile, PsiDirectory newParent, boolean searchInComments, boolean searchInNonJavaFiles )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( psiFile );
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( psiFile );
if( psiClass == null )
{
return Collections.emptyList();
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), psiClass,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
return usages;
}
示例3: findUsages
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
private static List<UsageInfo> findUsages( PsiElement element, PsiElement ctx )
{
// Module mod = ModuleUtilCore.findModuleForPsiElement( element );
// if( mod == null )
// {
// return Collections.emptyList();
// }
Query<PsiReference> search = ReferencesSearch.search( element, GlobalSearchScope.moduleScope( ModuleUtilCore.findModuleForPsiElement( ctx ) ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref : search.findAll() )
{
MoveRenameUsageInfo usageInfo = new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) );
usages.add( usageInfo );
}
return usages;
}
示例4: doAddLocalImport
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
/**
* Add local import statement
*
* @param name reference name in corresponding import element
* @param qualifier if not {@code null} form {@code from qualifier import name} will be used, otherwise {@code import name}
*/
private void doAddLocalImport(@NotNull final String name, @Nullable final String qualifier) {
myFixture.configureByFile(getTestName(true) + ".py");
WriteCommandAction.runWriteCommandAction(myFixture.getProject(), new Runnable() {
@Override
public void run() {
final PsiPolyVariantReference reference = PyResolveTestCase.findReferenceByMarker(myFixture.getFile());
if (qualifier != null) {
AddImportHelper.addLocalFromImportStatement(reference.getElement(), qualifier, name);
}
else {
AddImportHelper.addLocalImportStatement(reference.getElement(), name);
}
}
});
myFixture.checkResultByFile(getTestName(true) + ".after.py");
}
示例5: checkReferences
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
private void checkReferences(PsiReference[] references) {
for (PsiReference reference : references) {
if (!reference.isSoft()) {
if (reference.resolve() == null) {
if (reference instanceof PsiPolyVariantReference) {
final PsiPolyVariantReference pvr = (PsiPolyVariantReference)reference;
if (pvr.multiResolve(false).length == 0) {
addError(reference);
}
} else {
addError(reference);
}
}
}
}
}
示例6: testResolveIncludedRef2
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
public void testResolveIncludedRef2() throws Throwable {
myTestFixture.copyFileToProject("include.rng");
final PsiReference ref = myTestFixture.getReferenceAtCaretPositionWithAssertion("resolve-include-ref-2.rng");
assertTrue("PolyVariantRef", ref instanceof PsiPolyVariantReference);
final PsiElement element = ref.resolve();
assertNull(element);
final ResolveResult[] results = ((PsiPolyVariantReference)ref).multiResolve(false);
assertEquals(2, results.length);
for (ResolveResult result : results) {
PsiElement e = result.getElement();
assertTrue(e instanceof XmlTag);
final int contentLength = ((XmlTag)e).getSubTags().length;
if (e.getContainingFile() == ref.getElement().getContainingFile()) {
assertEquals(1, contentLength);
} else {
assertEquals(0, contentLength);
}
}
}
示例7: resolveXsltReference
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
@Nullable
private static PsiElement resolveXsltReference(PsiReference reference) {
final PsiElement element = reference.resolve();
if (element != null) {
return element;
}
if (reference instanceof PsiPolyVariantReference) {
final ResolveResult[] results = ((PsiPolyVariantReference)reference).multiResolve(false);
for (ResolveResult result : results) {
if (result.isValidResult() && result.getElement() instanceof XsltElement) {
return result.getElement();
}
}
}
return null;
}
示例8: getMultiResolvedMethod
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
/**
* Single resolve doesnt work if we have non unique class names in project context,
* so try a multiResolve and use first matched method
*/
@Nullable
public static Method getMultiResolvedMethod(PsiReference psiReference) {
// class be unique in normal case, so try this first
PsiElement resolvedReference = psiReference.resolve();
if (resolvedReference instanceof Method) {
return (Method) resolvedReference;
}
// try multiResolve if class exists twice in project
if(psiReference instanceof PsiPolyVariantReference) {
for(ResolveResult resolveResult : ((PsiPolyVariantReference) psiReference).multiResolve(false)) {
PsiElement element = resolveResult.getElement();
if(element instanceof Method) {
return (Method) element;
}
}
}
return null;
}
示例9: resolveTargetByName
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
public static List<PsiElement> resolveTargetByName(@Nls String name, @NotNull Project project, GlobalSearchScope scope) {
final PsiManager psiManager = PsiManager.getInstance(project);
final ArrayList<PsiElement> result = new ArrayList<>();
final Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance().getContainingFiles(NAME, name, scope);
for (VirtualFile virtualFile : containingFiles) {
final PsiFile psiFile = psiManager.findFile(virtualFile);
if (psiFile instanceof PyFile) {
final PyReferenceExpression referenceExpression = PantsPsiUtil.findTargetDefinitions((PyFile)psiFile).get(name);
final PsiPolyVariantReference reference = referenceExpression != null ? referenceExpression.getReference() : null;
final PsiElement definition = reference != null ? reference.resolve() : null;
if (definition != null) {
result.add(definition);
} else if (referenceExpression != null) {
// at least something
result.add(referenceExpression);
}
}
}
return result;
}
示例10: doTest
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
private void doTest(@NotNull String beforeText, String... expectedResolve) {
myFixture.configureByText(GitFileType.INSTANCE, beforeText);
PsiPolyVariantReference reference = ((PsiPolyVariantReference) myFixture.getReferenceAtCaretPosition());
assertNotNull(reference);
final VirtualFile rootFile = myFixture.getFile().getContainingDirectory().getVirtualFile();
ResolveResult[] resolveResults = reference.multiResolve(true);
List<String> actualResolve = ContainerUtil.map(resolveResults, new Function<ResolveResult, String>() {
@Override
public String fun(ResolveResult resolveResult) {
PsiElement resolveResultElement = resolveResult.getElement();
assertNotNull(resolveResultElement);
assertInstanceOf(resolveResultElement, PsiFileSystemItem.class);
PsiFileSystemItem fileSystemItem = (PsiFileSystemItem) resolveResultElement;
return VfsUtilCore.getRelativePath(fileSystemItem.getVirtualFile(), rootFile, '/');
}
});
assertContainsElements(actualResolve, expectedResolve);
}
示例11: storeTypeManifoldReferences
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
private void storeTypeManifoldReferences( @NotNull PsiElement element )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( element );
if( mod == null )
{
return;
}
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( (PsiFileSystemItem)element, module );
if( psiClass == null )
{
return;
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.projectScope( mod.getProject() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
_usages = usages;
if( psiClass instanceof ManifoldPsiClass )
{
PsiElement fakeElement = ManGotoDeclarationHandler.find( psiClass, (ManifoldPsiClass)psiClass );
if( fakeElement instanceof PsiNamedElement && isTopLevelClassDeclaration( fakeElement ) )
{
_classDeclElement = (PsiNamedElement)fakeElement;
}
}
}
示例12: tryResolving
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
@NotNull
private static PsiElement tryResolving(@NotNull PyExpression expression, @NotNull TypeEvalContext context) {
if (expression instanceof PyReferenceExpression) {
final PyReferenceExpression referenceExpr = (PyReferenceExpression)expression;
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
final PsiPolyVariantReference reference = referenceExpr.getReference(resolveContext);
final PsiElement element = reference.resolve();
if (element instanceof PyFunction) {
final PyFunction function = (PyFunction)element;
if (PyUtil.isInit(function)) {
final PyClass cls = function.getContainingClass();
if (cls != null) {
return cls;
}
}
}
else if (element instanceof PyTargetExpression) {
final PyTargetExpression targetExpr = (PyTargetExpression)element;
// XXX: Requires switching from stub to AST
final PyExpression assignedValue = targetExpr.findAssignedValue();
if (assignedValue != null) {
return assignedValue;
}
}
if (element != null) {
return element;
}
}
return expression;
}
示例13: getLanguagesToInject
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
final PsiElement contextParent = context.getParent();
if (PyInjectionUtil.getLargestStringLiteral(context) == context && contextParent instanceof PyArgumentList) {
final PyExpression[] args = ((PyArgumentList)contextParent).getArguments();
int index = ArrayUtil.indexOf(args, context);
PyCallExpression call = PsiTreeUtil.getParentOfType(context, PyCallExpression.class);
if (call != null) {
final PyExpression callee = call.getCallee();
if (callee instanceof PyReferenceExpression && canBeRegexpCall(callee)) {
final PsiPolyVariantReference ref = ((PyReferenceExpression)callee).getReference(PyResolveContext.noImplicits());
if (ref != null) {
final PsiElement element = ref.resolve();
if (element != null && ScopeUtil.getScopeOwner(element) instanceof PyFile &&
element.getContainingFile().getName().equals("re.py") && isRegexpMethod(element, index)) {
final Language language = isVerbose(call) ? PythonVerboseRegexpLanguage.INSTANCE : PythonRegexpLanguage.INSTANCE;
registrar.startInjecting(language);
final PyInjectionUtil.InjectionResult result = PyInjectionUtil.registerStringLiteralInjection(context, registrar);
if (result.isInjected()) {
registrar.doneInjecting();
if (!result.isStrict()) {
final PsiFile file = getInjectedFile(registrar);
if (file != null) {
file.putUserData(InjectedLanguageUtil.FRANKENSTEIN_INJECTION, Boolean.TRUE);
}
}
}
}
}
}
}
}
}
示例14: getReference
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
@NotNull
@Override
public PsiPolyVariantReference getReference(PyResolveContext context) {
if (isQualified()) {
return new PyQualifiedReference(this, context);
}
final PsiElement importParent = PsiTreeUtil.getParentOfType(this, PyImportElement.class, PyFromImportStatement.class);
if (importParent != null) {
return PyImportReference.forElement(this, importParent, context);
}
return new PyDocReference(this, context);
}
示例15: referencesTarget
import com.intellij.psi.PsiPolyVariantReference; //导入依赖的package包/类
private static boolean referencesTarget(@NotNull final PyExpression expression, @NotNull final PsiElement target) {
final List<PsiElement> refs = new ArrayList<PsiElement>();
expression.accept(new PyRecursiveElementVisitor() {
@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
super.visitPyReferenceExpression(node);
final PsiPolyVariantReference ref = node.getReference();
if (ref.isReferenceTo(target)) {
refs.add(node);
}
}
});
return !refs.isEmpty();
}