Esempio n. 1
0
 @NotNull
 public Expression expressionToExpression(@Nullable PsiExpression e) {
   if (e == null) return Expression.EMPTY_EXPRESSION;
   ExpressionVisitor expressionVisitor = dispatcher.getExpressionVisitor();
   e.accept(expressionVisitor);
   return expressionVisitor.getResult();
 }
Esempio n. 2
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);
  }