instanceof supported, is operator added
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ignatov
|
||||||
|
*/
|
||||||
|
public class IsOperator extends Expression {
|
||||||
|
private Expression myExpression;
|
||||||
|
private Element myTypeElement;
|
||||||
|
|
||||||
|
public IsOperator(Expression expression, Element typeElement) {
|
||||||
|
myExpression = expression;
|
||||||
|
myTypeElement = typeElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String toKotlin() {
|
||||||
|
return "(" + myExpression.toKotlin() + SPACE + "is" + SPACE + myTypeElement.toKotlin() + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ignatov
|
||||||
|
*/
|
||||||
|
public class TypeElement extends Element {
|
||||||
|
private Type myType;
|
||||||
|
|
||||||
|
public TypeElement(Type type) {
|
||||||
|
myType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String toKotlin() {
|
||||||
|
return myType.toKotlin();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,12 @@ public class ElementVisitor extends JavaElementVisitor implements Visitor {
|
|||||||
myResult = new IdentifierImpl(reference.getQualifiedName()); // TODO
|
myResult = new IdentifierImpl(reference.getQualifiedName()); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitTypeElement(PsiTypeElement type) {
|
||||||
|
super.visitTypeElement(type);
|
||||||
|
myResult = new TypeElement(typeToType(type.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitTypeParameter(PsiTypeParameter classParameter) {
|
public void visitTypeParameter(PsiTypeParameter classParameter) {
|
||||||
super.visitTypeParameter(classParameter);
|
super.visitTypeParameter(classParameter);
|
||||||
|
|||||||
@@ -140,6 +140,9 @@ public class ExpressionVisitor extends StatementVisitor implements Visitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visitInstanceOfExpression(PsiInstanceOfExpression expression) {
|
public void visitInstanceOfExpression(PsiInstanceOfExpression expression) {
|
||||||
super.visitInstanceOfExpression(expression);
|
super.visitInstanceOfExpression(expression);
|
||||||
|
myResult = new IsOperator(
|
||||||
|
expressionToExpression(expression.getOperand()),
|
||||||
|
elementToElement(expression.getCheckType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ignatov
|
||||||
|
*/
|
||||||
|
public class IsOperatorTest extends JetTestCaseBase {
|
||||||
|
public void testSimpleReference() throws Exception {
|
||||||
|
Assert.assertEquals(
|
||||||
|
expressionToKotlin("a instanceof String"),
|
||||||
|
"(a is String?)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testComplicatedExpression() throws Exception {
|
||||||
|
Assert.assertEquals(
|
||||||
|
expressionToKotlin("c.getType().getName() instanceof String"),
|
||||||
|
"(c.getType().getName() is String?)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user