Skip to content

Commit

Permalink
Fixes outer resolution of SuperMethodInvocation nodes for default met…
Browse files Browse the repository at this point in the history
…hods.

	Change on 2016/09/02 by kstanger <kstanger@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132072622
  • Loading branch information
kstanger authored and tomball committed Sep 8, 2016
1 parent b096da1 commit 56784d9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Expand Up @@ -16,6 +16,7 @@

import com.google.common.base.Predicate;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.devtools.j2objc.jdt.BindingConverter;
Expand Down Expand Up @@ -300,10 +301,22 @@ public static IMethodBinding getMethodBinding(Expression node) {
}
}

private static final List<Class<? extends TreeNode>> TYPE_NODE_BASE_CLASSES =
ImmutableList.of(AbstractTypeDeclaration.class, AnonymousClassDeclaration.class);

public static TreeNode getEnclosingType(TreeNode node) {
return TreeUtil.getNearestAncestorWithTypeOneOf(TYPE_NODE_BASE_CLASSES, node);
}

public static ITypeBinding getEnclosingTypeBinding(TreeNode node) {
TypeDeclaration enclosingType = TreeUtil.getNearestAncestorWithType(TypeDeclaration.class,
node);
return enclosingType == null ? null : enclosingType.getTypeBinding();
TreeNode enclosingType = getEnclosingType(node);
if (enclosingType instanceof AbstractTypeDeclaration) {
return ((AbstractTypeDeclaration) enclosingType).getTypeBinding();
} else if (enclosingType instanceof AnonymousClassDeclaration) {
return ((AnonymousClassDeclaration) enclosingType).getTypeBinding();
} else {
return null;
}
}

public static IMethodBinding getEnclosingMethodBinding(TreeNode node) {
Expand Down
Expand Up @@ -315,14 +315,6 @@ private void addInternalCapturing() {
nameTable.getObjCType(outerField.asType())
+ " " + outerField.getSimpleName().toString() + "_ = captures__->"
+ outerField.getSimpleName().toString() + ";"));
// TODO(user): This self should be unnecessary, but SuperMethodInvocationRewriter
// adds a ThisExpression node after the OuterReferenceResolver has already run, so it
// doesn't get the right path using the lambda and instead just becomes self.
funcImplStatements.add(
2,
new NativeStatement(
nameTable.getObjCType(outerField.asType())
+ " self = captures__->" + outerField.getSimpleName().toString() + ";"));

funcGet.addParameter(new SingleVariableDeclaration(outerField));

Expand Down
Expand Up @@ -123,10 +123,6 @@ public boolean visit(MethodInvocation node) {

@Override
public void endVisit(SuperMethodInvocation node) {
// Ignore default methods, they do not have outer paths.
if (ElementUtil.isDefault(node.getExecutableElement())) {
return;
}
List<VariableElement> path = outerResolver.getPath(node);
if (path != null) {
// We substitute the qualifying type name with the outer variable name.
Expand Down
Expand Up @@ -107,9 +107,6 @@ private String getSuperFunctionName(SuperMethodBindingPair superMethod) {
@Override
public void endVisit(SuperMethodInvocation node) {
Name qualifier = node.getQualifier();
if (qualifier == null) {
return;
}
IMethodBinding method = node.getMethodBinding();
TypeMirror exprType = node.getTypeMirror();

Expand All @@ -121,13 +118,20 @@ public void endVisit(SuperMethodInvocation node) {
binding.addParameters(method.getParameterTypes());
FunctionInvocation invocation = new FunctionInvocation(binding, exprType);
List<Expression> args = invocation.getArguments();
ITypeBinding thisClass = TreeUtil.getOwningType(node).getTypeBinding();
args.add(new ThisExpression(thisClass));
if (qualifier == null) {
args.add(new ThisExpression(TreeUtil.getEnclosingTypeBinding(node)));
} else {
// OuterReferenceFixer has provided an outer path.
args.add(TreeUtil.remove(qualifier));
}
TreeUtil.copyList(node.getArguments(), args);
node.replaceWith(invocation);
return;
}

if (qualifier == null) {
return;
}
IVariableBinding var = TreeUtil.getVariableBinding(qualifier);
assert var != null : "Expected qualifier to be a variable";
TypeMirror qualifierType = BindingConverter.getType(var.getType());
Expand Down

0 comments on commit 56784d9

Please sign in to comment.