コード例 #1
0
 @NotNull
 private static JBIterable<PsiElement> getSiblings(PsiElement element, boolean fwd) {
   SyntaxTraverser.ApiEx<PsiElement> api =
       fwd ? SyntaxTraverser.psiApi() : SyntaxTraverser.psiApiReversed();
   JBIterable<PsiElement> flatSiblings = JBIterable.generate(element, api::next).skip(1);
   return SyntaxTraverser.syntaxTraverser(api)
       .withRoots(flatSiblings)
       .expandAndSkip(e -> api.typeOf(e) == GeneratedParserUtilBase.DUMMY_BLOCK)
       .traverse();
 }
コード例 #2
0
  private static boolean canCallMethodsInConstructors(PsiClass aClass, boolean virtual) {
    for (PsiMethod constructor : aClass.getConstructors()) {
      if (!constructor.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return true;

      PsiCodeBlock body = constructor.getBody();
      if (body == null) continue;

      for (PsiMethodCallExpression call :
          SyntaxTraverser.psiTraverser().withRoot(body).filter(PsiMethodCallExpression.class)) {
        PsiReferenceExpression methodExpression = call.getMethodExpression();
        if (methodExpression instanceof PsiThisExpression
            || methodExpression instanceof PsiSuperExpression) continue;
        if (!virtual) return true;

        PsiMethod target = call.resolveMethod();
        if (target != null && PsiUtil.canBeOverriden(target)) return true;
      }
    }

    return false;
  }