AnonymousClasses supported
This commit is contained in:
@@ -39,10 +39,19 @@ public class Converter {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class classToClass(PsiClass psiClass) {
|
public static AnonymousClass anonymousClassToAnonymousClass(PsiAnonymousClass anonymousClass) { // TODO: replace by Block,
|
||||||
final List<Function> methods = methodsToFunctionList(psiClass.getMethods(), true);
|
// use class.getChild() method
|
||||||
|
return new AnonymousClass(
|
||||||
|
classesToClassList(anonymousClass.getAllInnerClasses()),
|
||||||
|
methodsToFunctionList(anonymousClass.getMethods(), true),
|
||||||
|
fieldsToFieldList(anonymousClass.getAllFields())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class classToClass(PsiClass psiClass) {
|
||||||
final Set<String> modifiers = modifiersListToModifiersSet(psiClass.getModifierList());
|
final Set<String> modifiers = modifiersListToModifiersSet(psiClass.getModifierList());
|
||||||
final List<Class> innerClasses = classesToClassList(psiClass.getAllInnerClasses());
|
final List<Class> innerClasses = classesToClassList(psiClass.getAllInnerClasses());
|
||||||
|
final List<Function> methods = methodsToFunctionList(psiClass.getMethods(), true);
|
||||||
final List<Field> fields = fieldsToFieldList(psiClass.getAllFields());
|
final List<Field> fields = fieldsToFieldList(psiClass.getAllFields());
|
||||||
final List<Element> typeParameters = elementsToElementList(psiClass.getTypeParameters());
|
final List<Element> typeParameters = elementsToElementList(psiClass.getTypeParameters());
|
||||||
final List<Type> implementsTypes = typesToNotNullableTypeList(psiClass.getImplementsListTypes());
|
final List<Type> implementsTypes = typesToNotNullableTypeList(psiClass.getImplementsListTypes());
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ignatov
|
||||||
|
*/
|
||||||
|
public class AnonymousClass extends Class {
|
||||||
|
public AnonymousClass(List<Class> innerClasses, List<Function> methods, List<Field> fields) {
|
||||||
|
super(new IdentifierImpl("anonClass"),
|
||||||
|
new HashSet<String>(),
|
||||||
|
new LinkedList<Element>(),
|
||||||
|
new LinkedList<Type>(),
|
||||||
|
new LinkedList<Type>(),
|
||||||
|
innerClasses,
|
||||||
|
methods,
|
||||||
|
fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String toKotlin() {
|
||||||
|
return bodyToKotlin();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,10 +99,11 @@ public class Class extends Member {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String bodyToKotlin() {
|
String bodyToKotlin() {
|
||||||
return classObjectToKotlin() + N +
|
return "{" + N + classObjectToKotlin() + N +
|
||||||
AstUtil.joinNodes(getNonStatic(myFields), N) + N +
|
AstUtil.joinNodes(getNonStatic(myFields), N) + N +
|
||||||
AstUtil.joinNodes(getNonStatic(methodsExceptConstructors()), N) + N +
|
AstUtil.joinNodes(getNonStatic(methodsExceptConstructors()), N) + N +
|
||||||
AstUtil.joinNodes(getNonStatic(myInnerClasses), N) + N;
|
AstUtil.joinNodes(getNonStatic(myInnerClasses), N) + N +
|
||||||
|
"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Member> getStatic(List<? extends Member> members) {
|
private List<Member> getStatic(List<? extends Member> members) {
|
||||||
@@ -141,8 +142,6 @@ public class Class extends Member {
|
|||||||
return modifiersToKotlin() + TYPE + SPACE + myName.toKotlin() + typeParametersToKotlin() +
|
return modifiersToKotlin() + TYPE + SPACE + myName.toKotlin() + typeParametersToKotlin() +
|
||||||
implementTypesToKotlin() +
|
implementTypesToKotlin() +
|
||||||
typeParameterWhereToKotlin() +
|
typeParameterWhereToKotlin() +
|
||||||
SPACE + "{" + N +
|
SPACE + bodyToKotlin();
|
||||||
bodyToKotlin() +
|
|
||||||
"}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ignatov
|
* @author ignatov
|
||||||
@@ -8,15 +9,23 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class NewClassExpression extends Expression {
|
public class NewClassExpression extends Expression {
|
||||||
private final Element myName;
|
private final Element myName;
|
||||||
private final Element myArguments;
|
private final Element myArguments;
|
||||||
|
private AnonymousClass myAnonymousClass = null;
|
||||||
|
|
||||||
public NewClassExpression(Element name, Element arguments) {
|
public NewClassExpression(Element name, Element arguments) {
|
||||||
myName = name;
|
myName = name;
|
||||||
myArguments = arguments;
|
myArguments = arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NewClassExpression(Element name, Element arguments, @Nullable AnonymousClass anonymousClass) {
|
||||||
|
this(name, arguments);
|
||||||
|
myAnonymousClass = anonymousClass;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String toKotlin() {
|
public String toKotlin() {
|
||||||
return myName.toKotlin() + "(" + myArguments.toKotlin() + ")";
|
return myAnonymousClass != null ?
|
||||||
|
myName.toKotlin() + "(" + myArguments.toKotlin() + ")" + SPACE + myAnonymousClass.toKotlin() :
|
||||||
|
myName.toKotlin() + "(" + myArguments.toKotlin() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
|
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -192,7 +193,10 @@ public class ExpressionVisitor extends StatementVisitor implements Visitor {
|
|||||||
} else {
|
} else {
|
||||||
myResult = new NewClassExpression(
|
myResult = new NewClassExpression(
|
||||||
elementToElement(expression.getClassOrAnonymousClassReference()),
|
elementToElement(expression.getClassOrAnonymousClassReference()),
|
||||||
elementToElement(expression.getArgumentList())
|
elementToElement(expression.getArgumentList()),
|
||||||
|
expression.getAnonymousClass() != null?
|
||||||
|
anonymousClassToAnonymousClass(expression.getAnonymousClass()) :
|
||||||
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("Run");
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
java.lang.Runnable() {
|
||||||
|
override public fun run() : Unit {
|
||||||
|
System.`out`?.println("Run")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user