use of com.google.devtools.j2objc.ast.Expression 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.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class ComplexExpressionExtractor method handleNode.
private void handleNode(Expression node, Collection<Expression> children) {
if (node.getParent() instanceof Statement) {
return;
}
int depth = 0;
for (Expression child : children) {
Integer childDepth = depths.get(child);
depth = Math.max(depth, childDepth != null ? childDepth : 1);
}
if (depth >= maxDepth) {
VariableElement newVar = GeneratedVariableElement.newLocalVar("complex$" + count++, node.getTypeMirror(), currentMethod);
Statement newStmt = new VariableDeclarationStatement(newVar, node.copy());
assert currentStatement != null;
TreeUtil.insertBefore(currentStatement, newStmt);
node.replaceWith(new SimpleName(newVar));
} else {
depths.put(node, depth + 1);
}
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MetadataWriter method createAnnotations.
private Expression createAnnotations(List<Annotation> annotations) {
// Group repeated annotations.
LinkedHashMap<DeclaredType, List<Annotation>> groupedAnnotations = new LinkedHashMap<>();
for (Annotation annotation : annotations) {
DeclaredType type = annotation.getAnnotationMirror().getAnnotationType();
groupedAnnotations.computeIfAbsent(type, k -> new ArrayList<>()).add(annotation);
}
List<Expression> expressions = new ArrayList<>();
for (List<Annotation> group : groupedAnnotations.values()) {
if (group.size() == 1) {
expressions.add(translationUtil.createAnnotation(group.get(0).getAnnotationMirror()));
} else {
expressions.add(createContainerAnnotation(group));
}
}
return translationUtil.createObjectArray(expressions, annotationArray);
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class CastResolver method endVisit.
@Override
public void endVisit(CastExpression node) {
TypeMirror type = node.getType().getTypeMirror();
Expression expr = node.getExpression();
TypeMirror exprType = expr.getTypeMirror();
if (TypeUtil.isFloatingPoint(exprType)) {
// Java wouldn't allow a cast from primitive to non-primitive.
assert type.getKind().isPrimitive();
switch(type.getKind()) {
case LONG:
node.replaceWith(rewriteFloatToIntegralCast(type, expr, "JreFpToLong", type));
return;
case CHAR:
node.replaceWith(rewriteFloatToIntegralCast(type, expr, "JreFpToChar", type));
return;
case BYTE:
case SHORT:
case INT:
node.replaceWith(rewriteFloatToIntegralCast(type, expr, "JreFpToInt", typeUtil.getInt()));
return;
// Fall through.
default:
}
}
// Lean on Java's type-checking.
if (!type.getKind().isPrimitive() && typeUtil.isAssignable(exprType, typeUtil.erasure(type))) {
node.replaceWith(TreeUtil.remove(expr));
return;
}
FunctionInvocation castCheck = createCastCheck(type, expr);
if (castCheck != null) {
node.setExpression(castCheck);
}
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class CastResolver method visit.
@Override
public boolean visit(IfStatement node) {
// Adds a narrowed type to the narrowing map for a statement with
// an instanceof expression where the body would have a redundant
// cast check (since the instanceof test shows it's not necessary).
Expression expr = node.getExpression();
VariableElement var = getInstanceofVar(expr);
if (var != null) {
TypeMirror instanceofType = ((InstanceofExpression) expr).getRightOperand().getTypeMirror();
narrowingMap.put(var, instanceofType);
}
return true;
}
Aggregations