com.intellij.psi.PsiClass#isInheritor ( )源码实例Demo

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

源代码1 项目: Folivora   文件: InstalledBeforeSuperDetector.java
@Override
public void visitMethod(JavaContext context,
                        UCallExpression call,
                        PsiMethod method) {
  JavaEvaluator evaluator = context.getEvaluator();

  //check Folivora.installViewFactory() call
  String methodName = method.getName();
  if (!methodName.equals(INSTALL_METHOD) || !evaluator.isMemberInClass(method, TYPE_FOLIVORA))
    return;

  //check current class is decent of AppCompatActivity
  PsiClass legacyCompatActClass = evaluator.findClass(LEGACY_COMPAT_ACTIVITY);
  PsiClass compatActClass = evaluator.findClass(COMPAT_ACTIVITY);
  PsiClass c = UastUtils.getContainingClass(call);
  boolean isAppCompatActivity = false;
  if (c != null) {
    isAppCompatActivity = (legacyCompatActClass != null && c.isInheritor(legacyCompatActClass,
      true/*deep check*/))
      || compatActClass != null && c.isInheritor(compatActClass, true/*deep check*/);
  }
  if (!isAppCompatActivity) return;

  //check current method is onCreate
  @SuppressWarnings("unchecked")
  UMethod uMethod = UastUtils.getParentOfType(call, true, UMethod.class);
  if (uMethod == null || !"onCreate".equals(uMethod.getName())) return;

  SuperOnCreateFinder finder = new SuperOnCreateFinder(call);
  uMethod.accept(finder);
  if (!finder.isSuperOnCreateCalled()) {
    context.report(ISSUE, call, context.getLocation(call),
      "calling `Folivora.installViewFactory()` before super.onCreate can cause AppCompatViews unavailable");
  }
}
 
源代码2 项目: Folivora   文件: InternalFolivoraApiDetector.java
@Override
public void visitMethod(@NotNull JavaContext context,
                        @NotNull UCallExpression call,
                        @NotNull PsiMethod method) {
  JavaEvaluator evaluator = context.getEvaluator();

  //check Folivora.applyDrawableToView() call
  String methodName = method.getName();
  if (!methodName.equals(APPLY_METHOD) || !evaluator.isMemberInClass(method, FOLIVORA_CLASS)) return;

  PsiClass viewClass = evaluator.findClass(VIEW_CLASS);
  PsiClass currentClass = UastUtils.getContainingClass(call);
  if(currentClass == null || viewClass == null) return;
  if (!currentClass.isInheritor(viewClass, true/*deep check*/)) {
    report(context, call);
    return;
  }

  UMethod uMethod = UastUtils.getParentOfType(call, UMethod.class, false);
  if(uMethod == null) return;

  //check it is a view's constructor
  if (!uMethod.isConstructor()) {
    report(context, call);
    return;
  }

  MethodSignature signature = uMethod.getSignature(PsiSubstitutor.EMPTY);
  PsiType[] types = signature.getParameterTypes();
  if (types.length != 2) {
    report(context, call);
    return;
  }

  if (!types[0].equalsToText(CONTEXT_CLASS)
    || !types[1].equalsToText(ATTRS_CLASS)) {
    report(context, call);
  }
}
 
源代码3 项目: intellij   文件: ProducerUtils.java
private static boolean isTestCaseInheritor(PsiClass psiClass) {
  // unlike JUnitUtil#isTestCaseInheritor, works even if the class isn't in the project
  PsiClass testCaseClass =
      JavaPsiFacade.getInstance(psiClass.getProject())
          .findClass(
              JUnitUtil.TEST_CASE_CLASS, GlobalSearchScope.allScope(psiClass.getProject()));
  if (testCaseClass != null) {
    return psiClass.isInheritor(testCaseClass, true);
  }
  // TestCase isn't indexed, instead use heuristics to check
  return extendsTestCase(psiClass, new HashSet<>());
}
 
private boolean isImplementValidMixinType( PsiClass mixinClass, Set<PsiClass> validMixinsType )
{
    for( PsiClass validMixinTypeClass : validMixinsType )
    {
        if( mixinClass.isInheritor( validMixinTypeClass, true ) )
        {
            return true;
        }
    }

    return false;
}