本文整理汇总了Java中com.intellij.psi.impl.source.resolve.JavaResolveUtil.resolveWithContainingFile方法的典型用法代码示例。如果您正苦于以下问题:Java JavaResolveUtil.resolveWithContainingFile方法的具体用法?Java JavaResolveUtil.resolveWithContainingFile怎么用?Java JavaResolveUtil.resolveWithContainingFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.resolve.JavaResolveUtil
的用法示例。
在下文中一共展示了JavaResolveUtil.resolveWithContainingFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveOptimised
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
@Nullable
private JavaResolveResult resolveOptimised(@NotNull PsiJavaCodeReferenceElement ref)
{
try
{
if(ref instanceof PsiReferenceExpressionImpl)
{
PsiReferenceExpressionImpl.OurGenericsResolver resolver = PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE;
JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(ref, resolver, true, true, myFile);
return results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
}
else
{
return ref.advancedResolve(true);
}
}
catch(IndexNotReadyException e)
{
return null;
}
}
示例2: resolveOptimised
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
@NotNull
private JavaResolveResult resolveOptimised(@NotNull PsiJavaCodeReferenceElement ref) {
JavaResolveResult result;
if (ref instanceof PsiReferenceExpressionImpl) {
JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(ref,
PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE,
true, true,
myFile);
result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
}
else {
result = ref.advancedResolve(true);
}
return result;
}
示例3: checkReferenceToOurInstanceInsideThisOrSuper
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
@Nullable
private static HighlightInfo checkReferenceToOurInstanceInsideThisOrSuper(@NotNull final PsiElement expression,
@NotNull PsiClass referencedClass,
final String resolvedName,
@NotNull PsiFile containingFile) {
if (PsiTreeUtil.getParentOfType(expression, PsiReferenceParameterList.class) != null) return null;
PsiElement element = expression.getParent();
while (element != null) {
// check if expression inside super()/this() call
if (RefactoringChangeUtil.isSuperOrThisMethodCall(element)) {
PsiElement parentClass = new PsiMatcherImpl(element)
.parent(PsiMatchers.hasClass(PsiExpressionStatement.class))
.parent(PsiMatchers.hasClass(PsiCodeBlock.class))
.parent(PsiMatchers.hasClass(PsiMethod.class))
.dot(JavaMatchers.isConstructor(true))
.parent(PsiMatchers.hasClass(PsiClass.class))
.getElement();
if (parentClass == null) {
return null;
}
// only this class/superclasses instance methods are not allowed to call
PsiClass aClass = (PsiClass)parentClass;
if (PsiUtil.isInnerClass(aClass) && referencedClass == aClass.getContainingClass()) return null;
// field or method should be declared in this class or super
if (!InheritanceUtil.isInheritorOrSelf(aClass, referencedClass, true)) return null;
// and point to our instance
if (expression instanceof PsiReferenceExpression &&
!thisOrSuperReference(((PsiReferenceExpression)expression).getQualifierExpression(), aClass)) {
return null;
}
if (expression instanceof PsiJavaCodeReferenceElement &&
!aClass.equals(PsiTreeUtil.getParentOfType(expression, PsiClass.class)) &&
PsiTreeUtil.getParentOfType(expression, PsiTypeElement.class) != null) {
return null;
}
if (expression instanceof PsiJavaCodeReferenceElement &&
PsiTreeUtil.getParentOfType(expression, PsiClassObjectAccessExpression.class) != null) {
return null;
}
final HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange());
if (expression instanceof PsiReferenceExpression && PsiUtil.isInnerClass(aClass)) {
final String referenceName = ((PsiReferenceExpression)expression).getReferenceName();
final PsiClass containingClass = aClass.getContainingClass();
LOG.assertTrue(containingClass != null);
final PsiField fieldInContainingClass = containingClass.findFieldByName(referenceName, true);
if (fieldInContainingClass != null && ((PsiReferenceExpression)expression).getQualifierExpression() == null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new QualifyWithThisFix(containingClass, expression));
}
}
return highlightInfo;
}
if (element instanceof PsiReferenceExpression) {
final PsiElement resolve;
if (element instanceof PsiReferenceExpressionImpl) {
PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)element;
JavaResolveResult[] results = JavaResolveUtil
.resolveWithContainingFile(referenceExpression, PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, true, false, containingFile);
resolve = results.length == 1 ? results[0].getElement() : null;
}
else {
resolve = ((PsiReferenceExpression)element).resolve();
}
if (resolve instanceof PsiField && ((PsiField)resolve).hasModifierProperty(PsiModifier.STATIC)) {
return null;
}
}
element = element.getParent();
if (element instanceof PsiClass && InheritanceUtil.isInheritorOrSelf((PsiClass)element, referencedClass, true)) return null;
}
return null;
}
示例4: checkReferenceToOurInstanceInsideThisOrSuper
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
@Nullable
private static HighlightInfo checkReferenceToOurInstanceInsideThisOrSuper(@NotNull final PsiElement expression,
@NotNull PsiClass referencedClass,
final String resolvedName,
@NotNull PsiFile containingFile) {
if (PsiTreeUtil.getParentOfType(expression, PsiReferenceParameterList.class) != null) return null;
PsiElement element = expression.getParent();
while (element != null) {
// check if expression inside super()/this() call
if (RefactoringChangeUtil.isSuperOrThisMethodCall(element)) {
PsiElement parentClass = new PsiMatcherImpl(element)
.parent(PsiMatchers.hasClass(PsiExpressionStatement.class))
.parent(PsiMatchers.hasClass(PsiCodeBlock.class))
.parent(PsiMatchers.hasClass(PsiMethod.class))
.dot(JavaMatchers.isConstructor(true))
.parent(PsiMatchers.hasClass(PsiClass.class))
.getElement();
if (parentClass == null) {
return null;
}
// only this class/superclasses instance methods are not allowed to call
PsiClass aClass = (PsiClass)parentClass;
if (PsiUtil.isInnerClass(aClass) && referencedClass == aClass.getContainingClass()) return null;
// field or method should be declared in this class or super
if (!InheritanceUtil.isInheritorOrSelf(aClass, referencedClass, true)) return null;
// and point to our instance
if (expression instanceof PsiReferenceExpression &&
!thisOrSuperReference(((PsiReferenceExpression)expression).getQualifierExpression(), aClass)) {
return null;
}
if (expression instanceof PsiJavaCodeReferenceElement &&
!aClass.equals(PsiTreeUtil.getParentOfType(expression, PsiClass.class)) &&
PsiTreeUtil.getParentOfType(expression, PsiTypeElement.class) != null) {
return null;
}
final HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange());
if (expression instanceof PsiReferenceExpression && PsiUtil.isInnerClass(aClass)) {
final String referenceName = ((PsiReferenceExpression)expression).getReferenceName();
final PsiClass containingClass = aClass.getContainingClass();
LOG.assertTrue(containingClass != null);
final PsiField fieldInContainingClass = containingClass.findFieldByName(referenceName, true);
if (fieldInContainingClass != null && ((PsiReferenceExpression)expression).getQualifierExpression() == null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new QualifyWithThisFix(containingClass, expression));
}
}
return highlightInfo;
}
if (element instanceof PsiReferenceExpression) {
final PsiElement resolve;
if (element instanceof PsiReferenceExpressionImpl) {
PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)element;
JavaResolveResult[] results = JavaResolveUtil
.resolveWithContainingFile(referenceExpression, PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, true, false, containingFile);
resolve = results.length == 1 ? results[0].getElement() : null;
}
else {
resolve = ((PsiReferenceExpression)element).resolve();
}
if (resolve instanceof PsiField && ((PsiField)resolve).hasModifierProperty(PsiModifier.STATIC)) {
return null;
}
}
element = element.getParent();
if (element instanceof PsiClass && InheritanceUtil.isInheritorOrSelf((PsiClass)element, referencedClass, true)) return null;
}
return null;
}