final Set<JsniClassLiteral> newClassRefs = Sets.newLinkedHashSet();
// Replace all arrays JSNI class literals with the its construction via the leaf type class
// literal.
JsModVisitor replaceJsniClassLiteralVisitor = new JsModVisitor() {
@Override
public void endVisit(JsNameRef x, JsContext ctx) {
if (!x.isJsniReference()) {
return;
}
JsniClassLiteral jsniClassLiteral = jsniClassLiteralsByJsniReference.get(
x.getIdent());
if (jsniClassLiteral == null) {
return;
}
if (jsniClassLiteral.getRefType() instanceof JArrayType) {
// Replace the array class literal by an expression that retrieves it from
// that of the leaf type.
JArrayType arrayType = (JArrayType) jsniClassLiteral.getRefType();
JType leafType = arrayType.getLeafType();
jsniClassLiteral = new JsniClassLiteral(jsniClassLiteral.getSourceInfo(), leafType);
// Array.getClassLiteralForArray(leafType.class, dimensions)
SourceInfo info = x.getSourceInfo();
JsNameRef getArrayClassLiteralMethodNameRef =
new JsNameRef(info, getClassLiteralForArrayMethodIdent);
JsInvocation invocation = new JsInvocation(info, getArrayClassLiteralMethodNameRef,
new JsNameRef(info, jsniClassLiteral.getIdent()),
new JsNumberLiteral(info, arrayType.getDims()));
// Finally resolve the class literal.
resolveClassLiteral(jsniClassLiteral);
ctx.replaceMe(invocation);
}
newClassRefs.add(jsniClassLiteral);
}
};
replaceJsniClassLiteralVisitor.accept(jsniMethodBody.getFunc());
if (!replaceJsniClassLiteralVisitor.didChange()) {
// Nothing was changed, no need to replace JsniMethodBody.
return;
}
JsniMethodBody newBody = new JsniMethodBody(jsniMethodBody.getSourceInfo(), jsniMethodBody.getFunc(),