use of com.sun.source.tree.VariableTree in project ceylon by eclipse.
the class T6654037 method main.
public static void main(String[] args) throws Exception {
// NOI18N
final String bootPath = System.getProperty("sun.boot.class.path");
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(0);
VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
BinaryTree cond = (BinaryTree) condSt.getInitializer();
JCTree condJC = (JCTree) cond;
if (condJC.pos != 93)
throw new IllegalStateException("Unexpected position=" + condJC.pos);
}
use of com.sun.source.tree.VariableTree in project ceylon-compiler by ceylon.
the class T6654037 method main.
public static void main(String[] args) throws Exception {
// NOI18N
final String bootPath = System.getProperty("sun.boot.class.path");
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(0);
VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
BinaryTree cond = (BinaryTree) condSt.getInitializer();
JCTree condJC = (JCTree) cond;
if (condJC.pos != 93)
throw new IllegalStateException("Unexpected position=" + condJC.pos);
}
use of com.sun.source.tree.VariableTree in project ceylon-compiler by ceylon.
the class T6993301 method testExceptionParameterCorrectKind.
public void testExceptionParameterCorrectKind() throws IOException {
final String bootPath = System.getProperty("sun.boot.class.path");
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
String code = "package test; public class Test { { try { } catch (NullPointerException ex) {} } }";
final JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ct.analyze();
new TreePathScanner<Void, Void>() {
@Override
public Void visitVariable(VariableTree node, Void p) {
Element el = Trees.instance(ct).getElement(getCurrentPath());
assertNotNull(el);
assertEquals(ElementKind.EXCEPTION_PARAMETER, el.getKind());
return super.visitVariable(node, p);
}
}.scan(cut, null);
}
use of com.sun.source.tree.VariableTree in project j2objc by google.
the class TreeConverter method convertLambda.
private TreeNode convertLambda(LambdaExpressionTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
LambdaExpression newNode = new LambdaExpression();
convertFunctionalExpression((JCFunctionalExpression) node, parent, newNode);
for (VariableTree param : node.getParameters()) {
newNode.addParameter((VariableDeclaration) convert(param, path));
}
return newNode.setBody(convert(node.getBody(), path));
}
use of com.sun.source.tree.VariableTree in project j2objc by google.
the class TreeConverter method convertForLoop.
private TreeNode convertForLoop(ForLoopTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
ForStatement newNode = new ForStatement().setExpression((Expression) convert(node.getCondition(), path)).setBody((Statement) convert(node.getStatement(), path));
VariableDeclarationExpression lastVar = null;
for (StatementTree initializer : node.getInitializer()) {
if (initializer.getKind() == Kind.VARIABLE) {
VariableTree var = (VariableTree) initializer;
VariableDeclarationExpression newVar = convertVariableExpression(var, path);
if (lastVar == null) {
newNode.addInitializer(newVar);
lastVar = newVar;
} else {
lastVar.addFragment(TreeUtil.remove(newVar.getFragment(0)));
}
} else {
assert initializer.getKind() == Kind.EXPRESSION_STATEMENT;
TreePath initializerPath = getTreePath(path, initializer);
TreeNode expr = convert(((ExpressionStatementTree) initializer).getExpression(), initializerPath);
newNode.addInitializer((Expression) expr);
}
}
for (ExpressionStatementTree updater : node.getUpdate()) {
newNode.addUpdater((Expression) convert(updater.getExpression(), getTreePath(path, updater)));
}
return newNode;
}
Aggregations