类com.intellij.psi.util.InheritanceUtil源码实例Demo

下面列出了怎么用com.intellij.psi.util.InheritanceUtil的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: intellij-haxe   文件: HaxePullUpHelper.java
@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);
  }
}
 
源代码2 项目: intellij-haxe   文件: ExtractSuperBaseProcessor.java
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;
}
 
源代码3 项目: lombok-intellij-plugin   文件: PsiElementUtil.java
/**
 * @param method              the method to compare to.
 * @param containingClassName the name of the class which contiains the
 *                            method.
 * @param returnType          the return type, specify null if any type matches
 * @param methodName          the name the method should have
 * @param parameterTypes      the type of the parameters of the method, specify
 *                            null if any number and type of parameters match or an empty array
 *                            to match zero parameters.
 * @return true, if the specified method matches the specified constraints,
 * false otherwise
 */
public static boolean methodMatches(
  @NotNull PsiMethod method,
  @NonNls @Nullable String containingClassName,
  @Nullable PsiType returnType,
  @NonNls @Nullable String methodName,
  @Nullable List<PsiType> parameterTypes) {
  final String name = method.getName();
  if (methodName != null && !methodName.equals(name)) {
    return false;
  }
  if (parameterTypes != null) {
    final PsiParameterList parameterList = method.getParameterList();
    if (parameterList.getParametersCount() != parameterTypes.size()) {
      return false;
    }
    final PsiParameter[] parameters = parameterList.getParameters();
    for (int i = 0; i < parameters.length; i++) {
      final PsiType type = parameters[i].getType();
      final PsiType parameterType = parameterTypes.get(i);
      if (PsiType.NULL.equals(parameterType)) {
        continue;
      }
      if (parameterType != null && !typesAreEquivalent(type, parameterType)) {
        return false;
      }
    }
  }
  if (returnType != null) {
    final PsiType methodReturnType = method.getReturnType();
    if (!typesAreEquivalent(returnType, methodReturnType)) {
      return false;
    }
  }
  if (containingClassName != null) {
    final PsiClass containingClass = method.getContainingClass();
    return InheritanceUtil.isInheritor(containingClass, containingClassName);
  }
  return true;
}
 
源代码4 项目: HakunaMatataIntelliJPlugin   文件: CommonUtils.java
@Contract("null -> false")
public static boolean isIterable(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_ITERABLE);
}
 
@Override
public boolean value(PsiElement element) {
    return element instanceof PsiExpression
            && InheritanceUtil.isInheritor(((PsiExpression) element).getType(), CommonClassNames.JAVA_UTIL_MAP);
}
 
@Contract("null -> false")
public static boolean isCollection(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION);
}
 
@Contract("null -> false")
public static boolean isIterator(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_ITERATOR);
}
 
@Contract("null -> false")
public static boolean isCharSequence(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, JAVA_LANG_CHAR_SEQUENCE);
}
 
@Override
public boolean value(PsiElement element) {
    return element instanceof PsiExpression
            && InheritanceUtil.isInheritor(((PsiExpression) element).getType(), CommonClassNames.JAVA_UTIL_MAP);
}
 
@Override
public boolean value(PsiElement element) {
    return element instanceof PsiExpression
            && InheritanceUtil.isInheritor(((PsiExpression) element).getType(), AndroidClassName.VIEW.getClassName());
}
 
@Contract("null -> false")
public static boolean isCollection(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION);
}
 
@Contract("null -> false")
public static boolean isIterator(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_ITERATOR);
}
 
@Contract("null -> false")
public static boolean isCharSequence(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, JAVA_LANG_CHAR_SEQUENCE);
}
 
@Override
public boolean value(PsiElement element) {
    return InheritanceUtil.isInheritor(((PsiExpression) element).getType(), "java.lang.CharSequence") && !AndroidPostfixTemplatesUtils.isAnnotatedNullable(element);
}
 
源代码15 项目: intellij-haxe   文件: PushDownConflicts.java
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);

}
 
 类所在包
 同包方法