use of com.google.devtools.j2objc.ast.Name in project j2objc by google.
the class OuterReferenceResolver method getPathForLocalVar.
private Expression getPathForLocalVar(VariableElement var) {
Name path = null;
Scope scope = peekScope();
if (scope.declaredVars.contains(var)) {
// Var is declared in current scope, return empty path.
return path;
}
if (var.getConstantValue() != null) {
// Var has constant value, return a literal.
return TreeUtil.newLiteral(var.getConstantValue(), typeUtil);
}
Scope lastScope = scope;
while (!(scope = scope.outer).declaredVars.contains(var)) {
// Except for the top scope, only include CLASS scopes when generating the path.
if (scope == lastScope.outerClass) {
path = Name.newName(path, getOrCreateOuterVar(lastScope));
lastScope = scope;
}
}
return Name.newName(path, getOrCreateCaptureVar(var, lastScope));
}
use of com.google.devtools.j2objc.ast.Name in project j2objc by google.
the class OuterReferenceResolver method visit.
@Override
public boolean visit(SuperFieldAccess node) {
VariableElement var = node.getVariableElement();
Name path = getPathForField(var, node.getTypeMirror());
if (path != null) {
node.replaceWith(path);
}
return false;
}
use of com.google.devtools.j2objc.ast.Name in project j2objc by google.
the class TreeConverter method convertExpressionMethodReference.
private static TreeNode convertExpressionMethodReference(org.eclipse.jdt.core.dom.ExpressionMethodReference node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
ExpressionMethodReference newNode = new ExpressionMethodReference();
Expression expression = (Expression) convert(node.getExpression());
boolean consumesFirstParam = !BindingUtil.isStatic(methodBinding) && expression instanceof Name && !ElementUtil.isVariable(((Name) expression).getElement());
convertMethodReference(node, newNode, methodBinding, consumesFirstParam);
return newNode.setName((SimpleName) TreeConverter.convert(node.getName())).setExpression(expression);
}
use of com.google.devtools.j2objc.ast.Name in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(QualifiedName node) {
Element element = node.getElement();
if (ElementUtil.isVariable(element)) {
VariableElement var = (VariableElement) element;
if (ElementUtil.isGlobalVar(var)) {
buffer.append(nameTable.getVariableQualifiedName(var));
return false;
}
}
if (ElementUtil.isTypeElement(element)) {
buffer.append(nameTable.getFullName((TypeElement) element));
return false;
}
Name qualifier = node.getQualifier();
qualifier.accept(this);
buffer.append("->");
node.getName().accept(this);
return false;
}
use of com.google.devtools.j2objc.ast.Name in project j2objc by google.
the class TreeConverter method convertSuperMethodInvocation.
private static TreeNode convertSuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation node) {
SuperMethodInvocation newNode = new SuperMethodInvocation();
convertExpression(node, newNode);
for (Object argument : node.arguments()) {
newNode.addArgument((Expression) TreeConverter.convert(argument));
}
IMethodBinding methodBinding = node.resolveMethodBinding();
return newNode.setExecutablePair(new ExecutablePair(BindingConverter.getExecutableElement(methodBinding), BindingConverter.getType(methodBinding))).setVarargsType(getVarargsType(methodBinding, node.arguments())).setQualifier((Name) TreeConverter.convert(node.getQualifier())).setName((SimpleName) TreeConverter.convert(node.getName()));
}
Aggregations