first implementation for new classes creation
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ignatov
|
||||||
|
*/
|
||||||
|
public class NewClassExpression extends Expression {
|
||||||
|
private final Element myName;
|
||||||
|
private final Element myArguments;
|
||||||
|
|
||||||
|
public NewClassExpression(Element name, Element arguments) {
|
||||||
|
myName = name;
|
||||||
|
myArguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String toKotlin() {
|
||||||
|
return myName.toKotlin() + "(" + myArguments.toKotlin() + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
package org.jetbrains.jet.j2k.visitors;
|
package org.jetbrains.jet.j2k.visitors;
|
||||||
|
|
||||||
import com.intellij.psi.JavaElementVisitor;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.PsiExpressionList;
|
|
||||||
import com.intellij.psi.PsiLocalVariable;
|
|
||||||
import com.intellij.psi.PsiParameterList;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
@@ -41,6 +38,12 @@ public class ElementVisitor extends JavaElementVisitor implements Visitor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
|
||||||
|
super.visitReferenceElement(reference);
|
||||||
|
myResult = new IdentifierImpl(reference.getQualifiedName()); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitParameterList(PsiParameterList list) {
|
public void visitParameterList(PsiParameterList list) {
|
||||||
super.visitParameterList(list);
|
super.visitParameterList(list);
|
||||||
|
|||||||
@@ -169,8 +169,15 @@ public class ExpressionVisitor extends StatementVisitor implements Visitor {
|
|||||||
public void visitNewExpression(PsiNewExpression expression) {
|
public void visitNewExpression(PsiNewExpression expression) {
|
||||||
super.visitNewExpression(expression);
|
super.visitNewExpression(expression);
|
||||||
|
|
||||||
if (expression.getArrayInitializer() != null) // new Foo[] {}
|
if (expression.getArrayInitializer() != null) // new Foo[] {}
|
||||||
myResult = expressionToExpression(expression.getArrayInitializer());
|
myResult = expressionToExpression(expression.getArrayInitializer());
|
||||||
|
else {
|
||||||
|
myResult = new NewClassExpression(
|
||||||
|
elementToElement(expression.getClassOrAnonymousClassReference()),
|
||||||
|
elementToElement(expression.getArgumentList())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ignatov
|
||||||
|
*/
|
||||||
|
public class NewClassExpressionTest extends JetTestCaseBase {
|
||||||
|
public void testClassWithoutBody() throws Exception {
|
||||||
|
Assert.assertEquals(expressionToSingleLineKotlin("new Foo();"), "Foo()");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testClassWithoutBody2() throws Exception {
|
||||||
|
Assert.assertEquals(expressionToSingleLineKotlin("new myApp.Foo();"), "myApp.Foo()");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testClassWithParam() throws Exception {
|
||||||
|
Assert.assertEquals(expressionToSingleLineKotlin("new Foo(param);"), "Foo(param)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testClassWithParams() throws Exception {
|
||||||
|
Assert.assertEquals(expressionToSingleLineKotlin("new Foo(param1, param2);"), "Foo(param1, param2)");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user