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

The following examples show how to use com.intellij.psi.util.InheritanceUtil#isInheritor() . 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: PsiElementUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source File: CommonUtils.java    From HakunaMatataIntelliJPlugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isIterable(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_ITERABLE);
}
 
Example 3
Source File: AndroidPostfixUtil.java    From HakunaMatataIntelliJPlugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean value(PsiElement element) {
    return element instanceof PsiExpression
            && InheritanceUtil.isInheritor(((PsiExpression) element).getType(), CommonClassNames.JAVA_UTIL_MAP);
}
 
Example 4
Source File: AndroidPostfixUtil.java    From HakunaMatataIntelliJPlugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isCollection(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION);
}
 
Example 5
Source File: AndroidPostfixUtil.java    From HakunaMatataIntelliJPlugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isIterator(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_ITERATOR);
}
 
Example 6
Source File: AndroidPostfixUtil.java    From HakunaMatataIntelliJPlugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isCharSequence(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, JAVA_LANG_CHAR_SEQUENCE);
}
 
Example 7
Source File: AndroidPostfixTemplatesUtils.java    From android-postfix-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean value(PsiElement element) {
    return element instanceof PsiExpression
            && InheritanceUtil.isInheritor(((PsiExpression) element).getType(), CommonClassNames.JAVA_UTIL_MAP);
}
 
Example 8
Source File: AndroidPostfixTemplatesUtils.java    From android-postfix-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean value(PsiElement element) {
    return element instanceof PsiExpression
            && InheritanceUtil.isInheritor(((PsiExpression) element).getType(), AndroidClassName.VIEW.getClassName());
}
 
Example 9
Source File: AndroidPostfixTemplatesUtils.java    From android-postfix-plugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isCollection(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION);
}
 
Example 10
Source File: AndroidPostfixTemplatesUtils.java    From android-postfix-plugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isIterator(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_ITERATOR);
}
 
Example 11
Source File: AndroidPostfixTemplatesUtils.java    From android-postfix-plugin with Apache License 2.0 4 votes vote down vote up
@Contract("null -> false")
public static boolean isCharSequence(@Nullable PsiType type) {
    return type != null && InheritanceUtil.isInheritor(type, JAVA_LANG_CHAR_SEQUENCE);
}
 
Example 12
Source File: TextUtilsIsEmptyTemplate.java    From android-postfix-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean value(PsiElement element) {
    return InheritanceUtil.isInheritor(((PsiExpression) element).getType(), "java.lang.CharSequence") && !AndroidPostfixTemplatesUtils.isAnnotatedNullable(element);
}