Skip to content

Commit

Permalink
Work around a change to InstanceOfTree in JDK 14
Browse files Browse the repository at this point in the history
It has a new getter for instanceof patterns, for now we proxy it to handle the
new getter (and the new PatterTree AST node type that it returns) and
unconditionally return `null`. This will require more work to actually support
refaster matches on instanceof patterns.

#1106

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=313270135
  • Loading branch information
cushon authored and kevinb9n committed May 27, 2020
1 parent 16308d3 commit d1b47a0
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions core/src/main/java/com/google/errorprone/refaster/UInstanceOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.sun.source.tree.InstanceOfTree;
import com.sun.source.tree.TreeVisitor;
import com.sun.tools.javac.tree.JCTree.JCInstanceOf;
import java.lang.reflect.Proxy;
import javax.annotation.Nullable;

/**
Expand All @@ -30,20 +31,40 @@
* @author lowasser@google.com (Louis Wasserman)
*/
@AutoValue
abstract class UInstanceOf extends UExpression implements InstanceOfTree {
abstract class UInstanceOf extends UExpression {
public static UInstanceOf create(UExpression expression, UTree<?> type) {
return new AutoValue_UInstanceOf(expression, type);
}

@Override
public abstract UExpression getExpression();

@Override
public abstract UTree<?> getType();

@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
return visitor.visitInstanceOf(this, data);
InstanceOfTree proxy =
(InstanceOfTree)
Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class<?>[] {InstanceOfTree.class},
(unused, method, args) -> {
switch (method.getName()) {
case "getPattern":
// TOOD(cushon): support refaster template matching on instanceof patterns
return null;
case "getExpression":
return getExpression();
case "getType":
return getType();
default:
try {
return method.invoke(UInstanceOf.this, args);
} catch (IllegalArgumentException e) {
throw new LinkageError(method.getName(), e);
}
}
});
return visitor.visitInstanceOf(proxy, data);
}

@Override
Expand Down

0 comments on commit d1b47a0

Please sign in to comment.