Example #1
0
  @NotNull
  public String elementToKotlin(@NotNull PsiElement element) {
    if (element instanceof PsiJavaFile) {
      return fileToFile((PsiJavaFile) element).toKotlin();
    }

    if (element instanceof PsiClass) {
      return classToClass((PsiClass) element).toKotlin();
    }

    if (element instanceof PsiMethod) {
      return methodToFunction((PsiMethod) element).toKotlin();
    }

    if (element instanceof PsiField) {
      PsiField field = (PsiField) element;
      return fieldToField(field, field.getContainingClass()).toKotlin();
    }

    if (element instanceof PsiStatement) {
      return statementToStatement((PsiStatement) element).toKotlin();
    }

    if (element instanceof PsiExpression) {
      return expressionToExpression((PsiExpression) element).toKotlin();
    }

    return "";
  }
Example #2
0
 @NotNull
 private Field fieldToField(@NotNull PsiField field, PsiClass psiClass) {
   Set<String> modifiers = modifiersListToModifiersSet(field.getModifierList());
   if (field instanceof PsiEnumConstant) // TODO: remove instanceof
   {
     return new EnumConstant(
         new IdentifierImpl(field.getName()), // TODO
         modifiers,
         typeToType(field.getType()),
         elementToElement(((PsiEnumConstant) field).getArgumentList()));
   }
   return new Field(
       new IdentifierImpl(field.getName()), // TODO
       modifiers,
       typeToType(field.getType(), ConverterUtil.isAnnotatedAsNotNull(field.getModifierList())),
       createSureCallOnlyForChain(field.getInitializer(), field.getType()), // TODO: add modifiers
       countWritingAccesses(field, psiClass));
 }