Fix async virtual methods

This commit is contained in:
konsoletyper 2015-02-07 15:21:46 +04:00
parent ce2c625f53
commit 268b66e523
3 changed files with 39 additions and 2 deletions

View File

@ -446,11 +446,12 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
debugEmitter.emitMethod(method.getReference().getDescriptor()); debugEmitter.emitMethod(method.getReference().getDescriptor());
MethodReference ref = method.getReference(); MethodReference ref = method.getReference();
writer.append(",").newLine(); writer.append(",").newLine();
String methodName = method.isAsync() ? naming.getNameForAsync(ref) : naming.getNameFor(ref);
if (method.isOriginalNamePreserved()) { if (method.isOriginalNamePreserved()) {
writer.append("[\"").appendMethod(ref).append("\",").ws().append("\"").append(ref.getName()) writer.append("[\"").append(methodName).append("\",").ws().append("\"").append(ref.getName())
.append("\"]"); .append("\"]");
} else { } else {
writer.append("\"").appendMethod(ref).append("\""); writer.append("\"").append(methodName).append("\"");
} }
writer.append(",").ws().append("function("); writer.append(",").ws().append("function(");
for (int i = 1; i <= ref.parameterCount(); ++i) { for (int i = 1; i <= ref.parameterCount(); ++i) {

View File

@ -227,5 +227,8 @@ class UnusedVariableEliminator implements ExprVisitor, StatementVisitor {
@Override @Override
public void visit(RestoreAsyncStatement statement) { public void visit(RestoreAsyncStatement statement) {
if (statement.getReceiver() != null) {
statement.setReceiver(renumber(statement.getReceiver()));
}
} }
} }

View File

@ -85,5 +85,38 @@ public class AsyncMethodFinder {
for (CallSite callSite : node.getCallerCallSites()) { for (CallSite callSite : node.getCallerCallSites()) {
add(callSite.getCaller().getMethod()); add(callSite.getCaller().getMethod());
} }
Set<MethodReference> visited = new HashSet<>();
Set<MethodReference> overriden = new HashSet<>();
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
findOverridenMethods(new MethodReference(cls.getParent(), methodRef.getDescriptor()), overriden, visited);
}
for (String iface : cls.getInterfaces()) {
findOverridenMethods(new MethodReference(iface, methodRef.getDescriptor()), overriden, visited);
}
for (MethodReference overridenMethod : overriden) {
add(overridenMethod);
}
}
private void findOverridenMethods(MethodReference methodRef, Set<MethodReference> result,
Set<MethodReference> visited) {
if (!visited.add(methodRef)) {
return;
}
ClassReader cls = classSource.get(methodRef.getClassName());
if (cls == null) {
return;
}
MethodReader method = cls.getMethod(methodRef.getDescriptor());
if (method != null) {
result.add(methodRef);
} else {
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
findOverridenMethods(new MethodReference(cls.getParent(), methodRef.getDescriptor()), result, visited);
}
for (String iface : cls.getInterfaces()) {
findOverridenMethods(new MethodReference(iface, methodRef.getDescriptor()), result, visited);
}
}
} }
} }