本文整理汇总了Java中com.intellij.psi.PsiPolyVariantReference.resolve方法的典型用法代码示例。如果您正苦于以下问题:Java PsiPolyVariantReference.resolve方法的具体用法?Java PsiPolyVariantReference.resolve怎么用?Java PsiPolyVariantReference.resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiPolyVariantReference
的用法示例。
在下文中一共展示了PsiPolyVariantReference.resolve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}
}
}
}
}
}
}
}
示例4: visitPyReferenceExpression
import com.intellij.psi.PsiPolyVariantReference; //导入方法依赖的package包/类
@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
final PyExceptPart exceptPart = PsiTreeUtil.getParentOfType(node, PyExceptPart.class);
if (exceptPart != null) {
final PyExpression exceptClass = exceptPart.getExceptClass();
if (exceptClass != null && "ImportError".equals(exceptClass.getText())) return;
}
final PsiPolyVariantReference reference = node.getReference(getResolveContext());
if (reference == null) return;
final PsiElement resolveResult = reference.resolve();
final PyFromImportStatement importStatement = PsiTreeUtil.getParentOfType(node, PyFromImportStatement.class);
if (importStatement != null) {
final PsiElement element = importStatement.resolveImportSource();
if (resolveResult != null && element != resolveResult.getContainingFile()) return;
}
String deprecationMessage = null;
if (resolveResult instanceof PyFunction) {
deprecationMessage = ((PyFunction) resolveResult).getDeprecationMessage();
}
else if (resolveResult instanceof PyFile) {
deprecationMessage = ((PyFile)resolveResult).getDeprecationMessage();
}
if (deprecationMessage != null) {
ASTNode nameElement = node.getNameElement();
registerProblem(nameElement == null ? node : nameElement.getPsi(), deprecationMessage, ProblemHighlightType.LIKE_DEPRECATED);
}
}
示例5: visitPyRaiseStatement
import com.intellij.psi.PsiPolyVariantReference; //导入方法依赖的package包/类
@Override
public void visitPyRaiseStatement(PyRaiseStatement node) {
PyExpression[] expressions = node.getExpressions();
if (expressions.length == 0) {
return;
}
PyExpression expression = expressions[0];
if (expression instanceof PyCallExpression) {
PyExpression callee = ((PyCallExpression)expression).getCallee();
if (callee instanceof PyReferenceExpression) {
final PsiPolyVariantReference reference = ((PyReferenceExpression)callee).getReference(getResolveContext());
if (reference == null) return;
PsiElement psiElement = reference.resolve();
if (psiElement instanceof PyClass) {
PyClass aClass = (PyClass) psiElement;
for (PyClassLikeType type : aClass.getAncestorTypes(myTypeEvalContext)) {
if (type == null) {
return;
}
final String name = type.getName();
if (name == null || "BaseException".equals(name) || "Exception".equals(name)) {
return;
}
}
registerProblem(expression, "Exception doesn't inherit from base \'Exception\' class", new PyAddExceptionSuperClassQuickFix());
}
}
}
}
示例6: visitPyReferenceExpression
import com.intellij.psi.PsiPolyVariantReference; //导入方法依赖的package包/类
@Override
public void visitPyReferenceExpression(final PyReferenceExpression node) {
final PsiPolyVariantReference reference = node.getReference();
if (reference.isReferenceTo(myElementToFind)) {
myDependencyFound = true;
return;
}
// TODO: This step is member-type specific. Move to MemberManagers?
if (myElementToFind instanceof PyAssignmentStatement) {
final PyExpression[] targets = ((PyAssignmentStatement)myElementToFind).getTargets();
if (targets.length != 1) {
return;
}
final PyExpression expression = targets[0];
if (reference.isReferenceTo(expression)) {
myDependencyFound = true;
return;
}
if (node.getText().equals(expression.getText())) { // Check by name also
myDependencyFound = true;
}
return;
}
final PsiElement declaration = reference.resolve();
myDependencyFound = PsiTreeUtil.findFirstParent(declaration, new PsiElementCondition()) != null;
}