-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 1st version of a simple kotlinAST -> SLangAST mapper #10
Conversation
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use assertj, please!
TreeVisitor<TreeContext> visitor = new TreeVisitor<>(); | ||
visitor.register(Tree.class, (ctx, tree) -> System.out.println(formatTree(tree))); | ||
visitor.scan(new TreeContext(), ASTMapper.fromString("fun function1() = 2 >= 1")); | ||
assertThat(true, is(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this assertion supposed to do?
} | ||
|
||
private static PsiFile compile(String content) { | ||
PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(createKotlinCoreEnvironment()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may keep this psiFileFactory as a field if it's an expensive operation.
|
||
import static java.nio.file.Files.readAllBytes; | ||
|
||
public class ASTMapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not naming this class KotlinParser
?
return BinaryExpressionTree.Operator.CONDITIONAL_OR; | ||
} else if (KtTokens.ANDAND.equals(operationTokenType)) { | ||
return BinaryExpressionTree.Operator.CONDITIONAL_AND; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now have other operators: see BinaryExpressionTree.Operator.
} | ||
|
||
private static BinaryExpressionTree.Operator mapBinaryExpression(IElementType operationTokenType) { | ||
if (KtTokens.EQEQ.equals(operationTokenType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not have a map instead of this big if statement?
No description provided.