当前位置: 首页>>代码示例>>Java>>正文


Java JavaResolveUtil.resolveWithContainingFile方法代码示例

本文整理汇总了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;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:HighlightVisitorImpl.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:HighlightVisitorImpl.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:79,代码来源:HighlightUtil.java

示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:74,代码来源:HighlightUtil.java


注:本文中的com.intellij.psi.impl.source.resolve.JavaResolveUtil.resolveWithContainingFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。