當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。