@Override public List<SuggestedFix> processMatch(Match match) { SuggestedFix.Builder fix = new SuggestedFix.Builder(); Node newNode = transformNode( matchedTemplate.afterTemplate.getLastChild(), matchedTemplate.matcher.getTemplateNodeToMatchMap()); Node nodeToReplace = match.getNode(); fix.setOriginalMatchedNode(nodeToReplace); fix.replace(nodeToReplace, newNode, match.getMetadata().getCompiler()); // If the template is a multiline template, make sure to delete the same number of sibling nodes // as the template has. Node n = match.getNode().getNext(); for (int i = 1; i < matchedTemplate.beforeTemplate.getLastChild().getChildCount(); i++) { Preconditions.checkNotNull( n, "Found mismatched sibling count between before template and matched node.\n" + "Template: %s\nMatch: %s", matchedTemplate.beforeTemplate.getLastChild(), match.getNode()); fix.delete(n); n = n.getNext(); } // Add/remove any goog.requires for (String require : matchedTemplate.getGoogRequiresToAdd()) { fix.addGoogRequire(match, require); } for (String require : matchedTemplate.getGoogRequiresToRemove()) { fix.removeGoogRequire(match, require); } return ImmutableList.of(fix.build()); }
private static SuggestedFix removeNode(JSError error) { return new SuggestedFix.Builder() .setOriginalMatchedNode(error.node) .delete(error.node).build(); }
/** * Deletes a node and its contents from the source file. */ public Builder deleteWithoutRemovingWhitespaceBefore(Node n) { return delete(n, false); }
/** * Deletes a node and its contents from the source file. If the node is a child of a * block or top level statement, this will also delete the whitespace before the node. */ public Builder delete(Node n) { return delete(n, true); }