Skip to content

Commit

Permalink
Convert ComplexExpressionExtractor to new type system.
Browse files Browse the repository at this point in the history
	Change on 2016/11/08 by kstanger <kstanger@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138551100
  • Loading branch information
kstanger authored and tomball committed Nov 8, 2016
1 parent c976cdc commit b1ed0ea
Showing 1 changed file with 9 additions and 13 deletions.
Expand Up @@ -34,16 +34,13 @@
import com.google.devtools.j2objc.ast.TreeVisitor;
import com.google.devtools.j2objc.ast.VariableDeclarationStatement;
import com.google.devtools.j2objc.ast.WhileStatement;
import com.google.devtools.j2objc.types.GeneratedVariableBinding;
import com.google.devtools.j2objc.util.BindingUtil;

import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;

import com.google.devtools.j2objc.types.GeneratedVariableElement;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;

/**
* Detects deep expression trees and extracts them into separate statements.
Expand All @@ -57,7 +54,7 @@ public class ComplexExpressionExtractor extends TreeVisitor {

private static int maxDepth = DEFAULT_MAX_DEPTH;
private Map<Expression, Integer> depths = Maps.newHashMap();
private IMethodBinding currentMethod;
private ExecutableElement currentMethod;
private Statement currentStatement;
private int count = 1;

Expand All @@ -81,9 +78,8 @@ private void handleNode(Expression node, Collection<Expression> children) {
depth = Math.max(depth, childDepth != null ? childDepth : 1);
}
if (depth >= maxDepth) {
ITypeBinding type = node.getTypeBinding();
IVariableBinding newVar = new GeneratedVariableBinding(
"complex$" + count++, 0, type, false, false, null, currentMethod);
VariableElement newVar = GeneratedVariableElement.newLocalVar(
"complex$" + count++, node.getTypeMirror(), currentMethod);
Statement newStmt = new VariableDeclarationStatement(newVar, node.copy());
assert currentStatement != null;
TreeUtil.insertBefore(currentStatement, newStmt);
Expand All @@ -104,7 +100,7 @@ public boolean preVisit(TreeNode node) {

@Override
public boolean visit(MethodDeclaration node) {
currentMethod = node.getMethodBinding();
currentMethod = node.getExecutableElement();
return true;
}

Expand Down Expand Up @@ -167,7 +163,7 @@ public void endVisit(PrefixExpression node) {

@Override
public void endVisit(Assignment node) {
if (BindingUtil.isBoolean(node.getTypeBinding())) {
if (node.getTypeMirror().getKind() == TypeKind.BOOLEAN) {
if (node.getRightHandSide() instanceof InfixExpression) {
// Avoid clang precedence warning by putting parentheses around expression.
ParenthesizedExpression.parenthesizeAndReplace(node.getRightHandSide());
Expand Down

0 comments on commit b1ed0ea

Please sign in to comment.