Example #1
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);
  }
Example #2
0
 @NotNull
 private static List<Import> importsToImportList(@NotNull PsiImportStatementBase[] imports) {
   List<Import> result = new LinkedList<Import>();
   for (PsiImportStatementBase i : imports) {
     Import anImport = importToImport(i);
     String name = anImport.getName();
     if (!name.isEmpty() && !NOT_NULL_ANNOTATIONS.contains(name)) {
       result.add(anImport);
     }
   }
   return result;
 }
Example #3
0
 @NotNull
 public static Set<String> modifiersListToModifiersSet(@Nullable PsiModifierList modifierList) {
   Set<String> modifiersSet = new HashSet<String>();
   if (modifierList != null) {
     if (modifierList.hasExplicitModifier(PsiModifier.ABSTRACT))
       modifiersSet.add(Modifier.ABSTRACT);
     if (modifierList.hasModifierProperty(PsiModifier.FINAL)) modifiersSet.add(Modifier.FINAL);
     if (modifierList.hasModifierProperty(PsiModifier.STATIC)) modifiersSet.add(Modifier.STATIC);
     if (modifierList.hasExplicitModifier(PsiModifier.PUBLIC)) modifiersSet.add(Modifier.PUBLIC);
     if (modifierList.hasExplicitModifier(PsiModifier.PROTECTED))
       modifiersSet.add(Modifier.PROTECTED);
     if (modifierList.hasExplicitModifier(PsiModifier.PACKAGE_LOCAL))
       modifiersSet.add(Modifier.INTERNAL);
     if (modifierList.hasExplicitModifier(PsiModifier.PRIVATE)) modifiersSet.add(Modifier.PRIVATE);
   }
   return modifiersSet;
 }
Example #4
0
 public void clearClassIdentifiers() {
   classIdentifiers.clear();
 }
Example #5
0
 public boolean hasFlag(@NotNull J2KConverterFlags flag) {
   return flags.contains(flag);
 }
Example #6
0
 public boolean addFlag(@NotNull J2KConverterFlags flag) {
   return flags.add(flag);
 }