Java Code Examples for com.intellij.psi.util.PsiUtil#resolveClassInType()

The following examples show how to use com.intellij.psi.util.PsiUtil#resolveClassInType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaxeCallReferenceProcessor.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 2
Source File: PsiTypeUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
public static String getQualifiedName(@NotNull PsiType psiType) {
  final PsiClass psiFieldClass = PsiUtil.resolveClassInType(psiType);
  return psiFieldClass != null ? psiFieldClass.getQualifiedName() : null;
}