use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertCompilationUnit.
public static CompilationUnit convertCompilationUnit(Options options, JavacEnvironment env, CompilationUnitTree javacUnit) {
String sourceFilePath = getPath(javacUnit.getSourceFile());
try {
TreeConverter converter = new TreeConverter(javacUnit, env);
JavaFileObject sourceFile = javacUnit.getSourceFile();
String source = sourceFile.getCharContent(false).toString();
String mainTypeName = FileUtil.getMainTypeName(sourceFile);
TranslationEnvironment translationEnv = new TranslationEnvironment(options, env);
converter.newUnit = new CompilationUnit(translationEnv, sourceFilePath, mainTypeName, source);
TreePath path = new TreePath(javacUnit);
converter.newUnit.setPackage(converter.convertPackage(path));
for (Tree type : javacUnit.getTypeDecls()) {
if (type.getKind() == Kind.IMPORT) {
continue;
}
TreeNode newNode = converter.convert(type, path);
if (newNode.getKind() != TreeNode.Kind.EMPTY_STATEMENT) {
converter.newUnit.addType((AbstractTypeDeclaration) newNode);
}
}
addOcniComments(converter.newUnit, options.jsniWarnings());
return converter.newUnit;
} catch (Throwable e) {
ErrorUtil.fatalError(e, sourceFilePath);
return null;
}
}
use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertBinary.
private TreeNode convertBinary(BinaryTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
InfixExpression newNode = new InfixExpression();
newNode.setTypeMirror(getTypeMirror(path)).setOperator(InfixExpression.Operator.from(node.getKind()));
// Flatten this tree to avoid stack overflow with very deep trees. This
// code traverses the subtree non-recursively and merges all children
// that have the same operator into this node.
List<StackState> stack = Lists.newArrayList();
stack.add(new StackState(node));
while (!stack.isEmpty()) {
StackState currentState = stack.get(stack.size() - 1);
ExpressionTree child = currentState.nextChild();
if (child == null) {
stack.remove(stack.size() - 1);
continue;
}
if (child instanceof BinaryTree) {
BinaryTree infixChild = (BinaryTree) child;
if (infixChild.getKind() == node.getKind()) {
stack.add(new StackState(infixChild));
continue;
}
}
newNode.addOperand((Expression) convert(child, path));
}
return newNode;
}
use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertVariableExpression.
private VariableDeclarationExpression convertVariableExpression(VariableTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
VariableElement element = (VariableElement) getElement(path);
boolean isVarargs = (((JCVariableDecl) node).sym.flags() & Flags.VARARGS) > 0;
Type newType = convertType(getTypeMirror(path), getPosition(node), isVarargs);
VariableDeclarationFragment fragment = new VariableDeclarationFragment();
fragment.setVariableElement(element).setInitializer((Expression) convert(node.getInitializer(), path));
return new VariableDeclarationExpression().setType(newType).addFragment(fragment);
}
use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertSynchronized.
private TreeNode convertSynchronized(SynchronizedTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
Expression expr = convertWithoutParens(node.getExpression(), path);
expr.setPosition(getPosition(node));
return new SynchronizedStatement().setExpression(expr).setBody((Block) convert(node.getBlock(), path));
}
use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertTry.
private TreeNode convertTry(TryTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
TryStatement newNode = new TryStatement();
for (Tree obj : node.getResources()) {
if (obj.getKind() == Kind.VARIABLE) {
newNode.addResource(convertVariableExpression((VariableTree) obj, path));
} else {
newNode.addResource(convertInner(obj, path));
}
}
for (CatchTree obj : node.getCatches()) {
newNode.addCatchClause((CatchClause) convert(obj, path));
}
return newNode.setBody((Block) convert(node.getBlock(), path)).setFinally((Block) convert(node.getFinallyBlock(), path));
}
Aggregations