Converter.elementToKotlin added
This commit is contained in:
@@ -66,6 +66,31 @@ public class Converter {
|
||||
ourClassIdentifiers.clear();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static 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 "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File fileToFile(@NotNull PsiJavaFile javaFile) {
|
||||
return fileToFile(javaFile, Collections.<String>emptyList());
|
||||
@@ -326,6 +351,11 @@ public class Converter {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Function methodToFunction(@NotNull PsiMethod method) {
|
||||
return methodToFunction(method, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Function methodToFunction(@NotNull PsiMethod method, boolean notEmpty) {
|
||||
if (isOverrideObjectDirect(method))
|
||||
|
||||
@@ -101,7 +101,7 @@ public class StandaloneJavaToKotlinConverterTest extends TestCase {
|
||||
private static String generateKotlinCode(@Nullable PsiFile file) {
|
||||
if (file != null && file instanceof PsiJavaFile) {
|
||||
JavaToKotlinTranslator.setClassIdentifiers(file);
|
||||
return prettify(Converter.fileToFile((PsiJavaFile) file).toKotlin());
|
||||
return prettify(Converter.elementToKotlin(file));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user