Source:
<code>public JsonRpcResult getMatchedStylesForNode(JsonRpcPeer peer, JSONObject params) { final GetMatchedStylesForNodeRequest request = mObjectMapper.convertValue( params, GetMatchedStylesForNodeRequest.class); final GetMatchedStylesForNodeResult result = new GetMatchedStylesForNodeResult(); result.matchedCSSRules = new ArrayList<>(); result.inherited = Collections.emptyList(); result.pseudoElements = Collections.emptyList(); mDocument.postAndWait(new Runnable() { @Override public void run() { final Object elementForNodeId = mDocument.getElementForNodeId(request.nodeId); if (elementForNodeId == null) { LogUtil.w("Failed to get style of an element that does not exist, nodeid=" + request.nodeId); return; } mDocument.getElementStyleRules(elementForNodeId, new StyleRuleAccumulator() { @Override public void store(String ruleName, boolean editable) { final ArrayList<CSSProperty> properties = new ArrayList<>(); final RuleMatch match = new RuleMatch(); match.matchingSelectors = ListUtil.newImmutableList(0); final Selector selector = new Selector(); selector.value = ruleName; final CSSRule rule = new CSSRule(); rule.origin = Origin.REGULAR; rule.selectorList = new SelectorList(); rule.selectorList.selectors = ListUtil.newImmutableList(selector); rule.style = new CSSStyle(); rule.style.cssProperties = properties; rule.style.shorthandEntries = Collections.emptyList(); if (editable) { <START> rule.style.styleSheetId = String.format("%d.%s", request.nodeId, selector.value); <END> } mDocument.getElementStyles(elementForNodeId, ruleName, new StyleAccumulator() { @Override public void store(String name, String value, boolean isDefault) { final CSSProperty property = new CSSProperty(); property.name = name; property.value = value; properties.add(property); } }); match.rule = rule; result.matchedCSSRules.add(match); } }); } }); return result; }</code><technical_language>in order save int->Object boxing allocation, relieve some GC pressure, prefer this pattern: rule.style.styleSheetId = String.format("%s.%s", Integer.toString(request.nodeId), selector.value);</technical_language>

Target:
public JsonRpcResult getMatchedStylesForNode(JsonRpcPeer peer, JSONObject params) { final GetMatchedStylesForNodeRequest request = mObjectMapper.convertValue( params, GetMatchedStylesForNodeRequest.class); final GetMatchedStylesForNodeResult result = new GetMatchedStylesForNodeResult(); result.matchedCSSRules = new ArrayList<>(); result.inherited = Collections.emptyList(); result.pseudoElements = Collections.emptyList(); mDocument.postAndWait(new Runnable() { @Override public void run() { final Object elementForNodeId = mDocument.getElementForNodeId(request.nodeId); if (elementForNodeId == null) { LogUtil.w("Failed to get style of an element that does not exist, nodeid=" + request.nodeId); return; } mDocument.getElementStyleRuleNames(elementForNodeId, new StyleRuleNameAccumulator() { @Override public void store(String ruleName, boolean editable) { final ArrayList<CSSProperty> properties = new ArrayList<>(); final RuleMatch match = new RuleMatch(); match.matchingSelectors = ListUtil.newImmutableList(0); final Selector selector = new Selector(); selector.value = ruleName; final CSSRule rule = new CSSRule(); rule.origin = Origin.REGULAR; rule.selectorList = new SelectorList(); rule.selectorList.selectors = ListUtil.newImmutableList(selector); rule.style = new CSSStyle(); rule.style.cssProperties = properties; rule.style.shorthandEntries = Collections.emptyList(); if (editable) { rule.style.styleSheetId = String.format( "%s.%s", Integer.toString(request.nodeId), selector.value); } mDocument.getElementStyles(elementForNodeId, ruleName, new StyleAccumulator() { @Override public void store(String name, String value, boolean isDefault) { final CSSProperty property = new CSSProperty(); property.name = name; property.value = value; properties.add(property); } }); match.rule = rule; result.matchedCSSRules.add(match); } }); } }); return result; }