com.intellij.psi.util.PsiUtil#resolveClassInType ( )源码实例Demo

下面列出了com.intellij.psi.util.PsiUtil#resolveClassInType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public boolean process(@NotNull PsiReference reference, @NotNull JavaCallHierarchyData jchdata) {
  if (!(jchdata instanceof CallData)) {
    String msg = "Internal error, unexpected call data type passed in.";
    LOG.error(msg);
    throw new UnsupportedOperationException(msg);
  }
  CallData data = (CallData)jchdata;

  PsiClass originalClass = data.getOriginalClass();
  PsiMethod method = data.getMethod();
  Set<PsiMethod> methodsToFind = data.getMethodsToFind();
  PsiMethod methodToFind = data.getMethodToFind();
  PsiClassType originalType = data.getOriginalType();
  Map<PsiMember, NodeDescriptor> methodToDescriptorMap = data.getResultMap();
  Project myProject = data.getProject();
  HaxeHierarchyTimeoutHandler timeoutHandler = data.getTimeoutHandler();

  // All done, if we time out.
  if (timeoutHandler.checkAndCancelIfNecessary()) {
    return false;
  }

  if (reference instanceof HaxeReferenceExpression) {
    final PsiElement qualifierElement = ((HaxeReferenceExpression)reference).getQualifier();
    final HaxeReferenceExpression qualifier = (HaxeReferenceExpression) qualifierElement;
    if (qualifier instanceof HaxeSuperExpression) { // filter super.foo() call inside foo() and similar cases (bug 8411)
      final PsiClass superClass = PsiUtil.resolveClassInType(qualifier.getPsiType());
      if (superClass == null || originalClass.isInheritor(superClass, true)) {
        return true;
      }
    }
    if (qualifier != null && !methodToFind.hasModifierProperty(PsiModifier.STATIC)) {
      final PsiType qualifierType = qualifier.getPsiType();
      if (qualifierType instanceof PsiClassType &&
          !TypeConversionUtil.isAssignable(qualifierType, originalType) &&
          methodToFind != method) {
        final PsiClass psiClass = ((PsiClassType)qualifierType).resolve();
        if (psiClass != null) {
          final PsiMethod callee = psiClass.findMethodBySignature(methodToFind, true);
          if (callee != null && !methodsToFind.contains(callee)) {
            // skip sibling methods
            return true;
          }
        }
      }
    }
  }
  else {
    if (!(reference instanceof PsiElement)) {
      return true;
    }

    final PsiElement parent = ((PsiElement)reference).getParent();
    // If the parent is a 'new x' expression, but the reference isn't the primary
    // expression, then keep looking.
    if (parent instanceof HaxeNewExpression) {
      if (((HaxeNewExpression)parent).getType().getReferenceExpression() != reference) {
        return true;
      }
    }
    // If the reference isn't the primary expression of an anonymous class, then keep looking?
    else if (parent instanceof PsiAnonymousClass) {
      // XXX: This appears to be an optimization, knowing that an anonymous class can't be
      //      referenced from outside of itself, there's no need to load the class by
      //      calling for the base reference (the first child of the class).  The haxe
      //      PSI doesn't appear to be built in that fashion any way...
      // if (((PsiAnonymousClass)parent).getBaseClassReference() != reference) {
      //   return true;
      // }

      // let it be processed.
    }
    else {
      return true;
    }
  }

  final PsiElement element = reference.getElement();
  final PsiMember key = CallHierarchyNodeDescriptor.getEnclosingElement(element);

  synchronized (methodToDescriptorMap) {
    CallHierarchyNodeDescriptor d = (CallHierarchyNodeDescriptor)methodToDescriptorMap.get(key);
    if (d == null) {
      d = new CallHierarchyNodeDescriptor(myProject, (CallHierarchyNodeDescriptor)data.getNodeDescriptor(), element, false, true);
      methodToDescriptorMap.put(key, d);
    }
    else if (!d.hasReference(reference)) {
      d.incrementUsageCount();
    }
    d.addReference(reference);
  }
  return false;
}
 
源代码2 项目: lombok-intellij-plugin   文件: PsiTypeUtil.java
@Nullable
public static String getQualifiedName(@NotNull PsiType psiType) {
  final PsiClass psiFieldClass = PsiUtil.resolveClassInType(psiType);
  return psiFieldClass != null ? psiFieldClass.getQualifiedName() : null;
}