Java Code Examples for com.intellij.psi.util.InheritanceUtil#isInheritorOrSelf()

The following examples show how to use com.intellij.psi.util.InheritanceUtil#isInheritorOrSelf() . 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: HaxePullUpHelper.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override public void visitReferenceElement(PsiJavaCodeReferenceElement referenceElement) {
  if (!myIsMovable) return;
  final PsiExpression qualifier;
  if (referenceElement instanceof PsiReferenceExpression) {
    qualifier = ((PsiReferenceExpression) referenceElement).getQualifierExpression();
  } else {
    qualifier = null;
  }
  if (qualifier == null || qualifier instanceof PsiThisExpression || qualifier instanceof PsiSuperExpression) {
    final PsiElement resolved = referenceElement.resolve();
    if (!(resolved instanceof PsiParameter)) {
      if (resolved instanceof PsiClass && (((PsiClass) resolved).hasModifierProperty(PsiModifier.STATIC) || ((PsiClass)resolved).getContainingClass() == null)) {
        return;
      }
      PsiClass containingClass = null;
      if (resolved instanceof PsiMember && !((PsiMember)resolved).hasModifierProperty(PsiModifier.STATIC)) {
        containingClass = ((PsiMember) resolved).getContainingClass();
      }
      myIsMovable = containingClass != null && InheritanceUtil.isInheritorOrSelf(myTargetSuperClass, containingClass, true);
    }
  } else {
    qualifier.accept(this);
  }
}
 
Example 2
Source File: ExtractSuperBaseProcessor.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
protected boolean doesAnyExtractedInterfaceExtends(PsiClass aClass) {
  for (final MemberInfo memberInfo : myMemberInfos) {
    final PsiElement member = memberInfo.getMember();
    if (member instanceof PsiClass && memberInfo.getOverrides() != null) {
      if (InheritanceUtil.isInheritorOrSelf((PsiClass)member, aClass, true)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 3
Source File: PushDownConflicts.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public void checkTargetClassConflicts(final PsiClass targetClass, final boolean checkStatic, final PsiElement context) {
  if (targetClass != null) {
    for (final PsiMember movedMember : myMovedMembers) {
      checkMemberPlacementInTargetClassConflict(targetClass, movedMember);
      movedMember.accept(new JavaRecursiveElementWalkingVisitor() {
        @Override
        public void visitMethodCallExpression(PsiMethodCallExpression expression) {
          super.visitMethodCallExpression(expression);
          if (expression.getMethodExpression().getQualifierExpression() instanceof PsiSuperExpression) {
            final PsiMethod resolvedMethod = expression.resolveMethod();
            if (resolvedMethod != null) {
              final PsiClass resolvedClass = resolvedMethod.getContainingClass();
              if (resolvedClass != null) {
                if (myClass.isInheritor(resolvedClass, true)) {
                  final PsiMethod methodBySignature = myClass.findMethodBySignature(resolvedMethod, false);
                  if (methodBySignature != null && !myMovedMembers.contains(methodBySignature)) {
                    myConflicts.putValue(expression, "Super method call will resolve to another method");
                  }
                }
              }
            }
          }
        }
      });
    }
  }
  Members:
  for (PsiMember member : myMovedMembers) {
    for (PsiReference ref : ReferencesSearch.search(member, member.getResolveScope(), false)) {
      final PsiElement element = ref.getElement();
      if (element instanceof PsiReferenceExpression) {
        final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)element;
        final PsiExpression qualifier = referenceExpression.getQualifierExpression();
        if (qualifier != null) {
          final PsiType qualifierType = qualifier.getType();
          PsiClass aClass = null;
          if (qualifierType instanceof PsiClassType) {
            aClass = ((PsiClassType)qualifierType).resolve();
          }
          else {
            if (!checkStatic) continue;
            if (qualifier instanceof PsiReferenceExpression) {
              final PsiElement resolved = ((PsiReferenceExpression)qualifier).resolve();
              if (resolved instanceof PsiClass) {
                aClass = (PsiClass)resolved;
              }
            }
          }

          if (!InheritanceUtil.isInheritorOrSelf(aClass, targetClass, true)) {
            myConflicts.putValue(referenceExpression, RefactoringBundle.message("pushed.members.will.not.be.visible.from.certain.call.sites"));
            break Members;
          }
        }
      }
    }
  }
  //RefactoringConflictsUtil.analyzeAccessibilityConflicts(myMovedMembers, targetClass, myConflicts, null, context, myAbstractMembers);

}