Skip to content
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

Merged
merged 2 commits into from
May 31, 2018

Conversation

christophe-zurn-sonarsource
Copy link
Contributor

No description provided.

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
Copy link
Contributor

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));
Copy link
Contributor

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());
Copy link
Contributor

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 {
Copy link
Contributor

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;
}
Copy link
Contributor

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)) {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants