Esempio n. 1
0
 private static boolean isNotOpenMethod(@NotNull PsiMethod method) {
   if (method.getParent() instanceof PsiClass) {
     PsiModifierList parentModifierList = ((PsiClass) method.getParent()).getModifierList();
     if ((parentModifierList != null && parentModifierList.hasExplicitModifier(Modifier.FINAL))
         || ((PsiClass) method.getParent()).isEnum()) {
       return true;
     }
   }
   return false;
 }
Esempio n. 2
0
 public static boolean isConstructorPrimary(@NotNull PsiMethod constructor) {
   if (constructor.getParent() instanceof PsiClass) {
     PsiClass parent = (PsiClass) constructor.getParent();
     if (parent.getConstructors().length == 1) {
       return true;
     } else {
       PsiMethod c =
           getPrimaryConstructorForThisCase(parent); // TODO: move up to classToClass() method
       if (c != null && c.hashCode() == constructor.hashCode()) {
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 3
0
  @NotNull
  private Function methodToFunction(@NotNull PsiMethod method, boolean notEmpty) {
    if (isOverrideObjectDirect(method)) {
      dispatcher.setExpressionVisitor(new ExpressionVisitorForDirectObjectInheritors(this));
    } else {
      dispatcher.setExpressionVisitor(new ExpressionVisitor(this));
    }

    methodReturnType = method.getReturnType();

    IdentifierImpl identifier = new IdentifierImpl(method.getName());
    Type returnType =
        typeToType(
            method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList()));
    Block body =
        hasFlag(J2KConverterFlags.SKIP_BODIES)
            ? Block.EMPTY_BLOCK
            : blockToBlock(method.getBody(), notEmpty); // #TODO
    Element params = createFunctionParameters(method);
    List<Element> typeParameters = elementsToElementList(method.getTypeParameters());

    Set<String> modifiers = modifiersListToModifiersSet(method.getModifierList());
    if (isOverrideAnyMethodExceptMethodsFromObject(method)) {
      modifiers.add(Modifier.OVERRIDE);
    }
    if (method.getParent() instanceof PsiClass && ((PsiClass) method.getParent()).isInterface()) {
      modifiers.remove(Modifier.ABSTRACT);
    }
    if (isNotOpenMethod(method)) {
      modifiers.add(Modifier.NOT_OPEN);
    }

    if (method.isConstructor()) { // TODO: simplify
      boolean isPrimary = isConstructorPrimary(method);
      return new Constructor(
          identifier,
          modifiers,
          returnType,
          typeParameters,
          params,
          new Block(removeEmpty(body.getStatements()), false),
          isPrimary);
    }
    return new Function(identifier, modifiers, returnType, typeParameters, params, body);
  }