use of com.google.devtools.j2objc.ast.TreeVisitor in project j2objc by google.
the class Functionizer method determineFunctionizableMethods.
/**
* Determines the set of methods to functionize. In addition to a method being
* final we must also find an invocation for that method. Static methods, though,
* are always functionized since there are no dynamic dispatch issues.
*/
private Set<ExecutableElement> determineFunctionizableMethods(final CompilationUnit unit) {
final Set<ExecutableElement> functionizableDeclarations = Sets.newHashSet();
final Set<ExecutableElement> invocations = Sets.newHashSet();
unit.accept(new TreeVisitor() {
@Override
public void endVisit(MethodDeclaration node) {
if (canFunctionize(node)) {
functionizableDeclarations.add(node.getExecutableElement());
}
}
@Override
public void endVisit(MethodInvocation node) {
invocations.add(node.getExecutableElement());
}
});
return Sets.intersection(functionizableDeclarations, invocations);
}
use of com.google.devtools.j2objc.ast.TreeVisitor in project j2objc by google.
the class NameTableTest method testTypeVariableWithTypeVariableBounds.
public void testTypeVariableWithTypeVariableBounds() {
String source = "class A<T> { <E extends T> void foo(E e) {} }";
CompilationUnit unit = translateType("A", source);
NameTable nameTable = unit.getEnv().nameTable();
final ExecutableElement[] methodElement = new ExecutableElement[1];
unit.accept(new TreeVisitor() {
@Override
public void endVisit(MethodDeclaration node) {
ExecutableElement element = node.getExecutableElement();
if (ElementUtil.getName(element).equals("foo")) {
methodElement[0] = element;
}
}
});
assertNotNull(methodElement[0]);
TypeMirror paramType = methodElement[0].getParameters().get(0).asType();
assertEquals("id", nameTable.getObjCType(paramType));
}
use of com.google.devtools.j2objc.ast.TreeVisitor in project j2objc by google.
the class GenerationTest method translateStatements.
/**
* Translate a string of Java statement(s) into a list of
* JDT DOM Statements. Although JDT has support for statement
* parsing, it doesn't resolve them. The statements are therefore
* wrapped in a type declaration so they having bindings.
*/
protected List<Statement> translateStatements(String stmts) {
// Wrap statements in test class, so type resolution works.
String source = "public class Test { void test() { " + stmts + "}}";
CompilationUnit unit = translateType("Test", source);
final List<Statement> statements = Lists.newArrayList();
unit.accept(new TreeVisitor() {
@Override
public boolean visit(MethodDeclaration node) {
if (ElementUtil.getName(node.getExecutableElement()).equals("test")) {
statements.addAll(node.getBody().getStatements());
}
return false;
}
});
return statements;
}
use of com.google.devtools.j2objc.ast.TreeVisitor in project j2objc by google.
the class StatementGenerator method needsParenthesesForMacro.
private boolean needsParenthesesForMacro(Expression expr) {
boolean[] hasComma = { false };
expr.accept(new TreeVisitor() {
@Override
public boolean visit(ArrayInitializer node) {
hasComma[0] = true;
return false;
}
@Override
public boolean visit(CommaExpression node) {
// Adds parentheses around children.
return false;
}
@Override
public boolean visit(FunctionInvocation node) {
// Adds parentheses around children.
return false;
}
@Override
public boolean visit(StringLiteral node) {
if (!UnicodeUtils.hasValidCppCharacters(node.getLiteralValue())) {
// LiteralGenerator will emit the string using [NSString stringWithCharacters:].
hasComma[0] = true;
return false;
}
return true;
}
});
return hasComma[0];
}
use of com.google.devtools.j2objc.ast.TreeVisitor in project j2objc by google.
the class Functionizer method hasSuperMethodInvocation.
private static boolean hasSuperMethodInvocation(MethodDeclaration node) {
final boolean[] result = new boolean[1];
result[0] = false;
node.accept(new TreeVisitor() {
@Override
public void endVisit(SuperMethodInvocation node) {
result[0] = true;
}
});
return result[0];
}
Aggregations