private void addMethodToObjectExternsUsingExportAnnotation(
      PolymerClassDefinition cls, MemberDefinition method) {
    Node getprop =
        NodeUtil.newQName(
            compiler, cls.target.getQualifiedName() + ".prototype." + method.name.getString());
    JSDocInfoBuilder info =
        new JSDocInfoBuilder(
            /** parseDocumentation */
            true);
    if (method.info != null) {
      // We need to preserve visibility, but other JSDoc doesn't matter (and can cause
      // re-declaration errors).
      info.recordVisibility(method.info.getVisibility());
    }
    info.recordExport();
    getprop.setJSDocInfo(info.build());
    Node expression = IR.exprResult(getprop).useSourceInfoIfMissingFromForTree(method.name);
    // Walk up until we find a statement we can insert after.
    Node insertAfter = cls.definition;
    while (!NodeUtil.isStatementBlock(insertAfter.getParent())) {
      insertAfter = insertAfter.getParent();
    }
    insertAfter.getParent().addChildAfter(expression, insertAfter);
    compiler.reportChangeToEnclosingScope(expression);
  }
private void addMethodToObjectExternsUsingExportAnnotation ( PolymerClassDefinition cls , MemberDefinition method ) { Node getprop = NodeUtil . newQName ( compiler , cls . target . getQualifiedName ( ) + ".prototype." + method . name . getString ( ) ) ; JSDocInfoBuilder info = new JSDocInfoBuilder ( true ) ; if ( method . info != null ) { info . recordVisibility ( method . info . getVisibility ( ) ) ; } info . recordExport ( ) ; getprop . setJSDocInfo ( info . build ( ) ) ; Node expression = IR . exprResult ( getprop ) . useSourceInfoIfMissingFromForTree ( method . name ) ; Node insertAfter = cls . definition ; while ( ! NodeUtil . isStatementBlock ( insertAfter . getParent ( ) ) ) { insertAfter = insertAfter . getParent ( ) ; } insertAfter . getParent ( ) . addChildAfter ( expression , insertAfter ) ; compiler . reportChangeToEnclosingScope ( expression ) ; }
Add a method to {@code Object.prototype} in the externs by inserting a {@code GETPROP}
expression with an {@code @export} annotation into the program.

<p>This relies on the {@code --generate_exports} and {@code export_local_property_definitions}
flags to enable the {@link GenerateExports} pass, which will add properties exported in this
way to {@code Object.prototype} in the externs, thus preventing renaming and dead code removal.
Note that {@link GenerateExports} runs after type checking, so extending {@code
Object.prototype} does not cause unwanted type checking effects.