private boolean containsEmptyMaskedMediaRule(CSSMediaRule mediaRule, IndexedRegion mediaRuleRegion) { for (String rule : EMPTY_MASKED_MEDIA_RULES) { try { if (structuredDocument.getLength() < rule.length()) { continue; } if (!rule.equalsIgnoreCase(structuredDocument.get( mediaRuleRegion.getStartOffset(), rule.length()))) { continue; } if (mediaRule.getMedia().getLength() > 0) { continue; } return true; } catch (BadLocationException e1) { // Shouldn't happen, continue on } } return false; }
private void fixPotentialEmptyMaskedMediaRule(ICSSNode node) { CSSMediaRule mediaRule = (CSSMediaRule) node; IndexedRegion mediaRuleRegion = (IndexedRegion) mediaRule; if (!containsEmptyMaskedMediaRule(mediaRule, mediaRuleRegion)) { return; } // Set the range to a valid value (it won't be proper since we don't have // any additional words that can be categorized as CSS_MEDIUM.) MediaList mediaList = mediaRule.getMedia(); IStructuredDocumentRegion[] structuredDocumentRegions = structuredDocument.getStructuredDocumentRegions( mediaRuleRegion.getStartOffset(), mediaRuleRegion.getLength()); // The value we set is a 0-length region starting where the next word would // have been ITextRegion textRegion = new ContextRegion(CSSRegionContexts.CSS_MEDIUM, structuredDocumentRegions[0].getEndOffset() - structuredDocumentRegions[0].getStartOffset(), 0, 0); try { callSetRangeRegion(mediaList, structuredDocumentRegions, textRegion); } catch (Throwable e) { GWTPluginLog.logError(e, "Could not clean up the @else in the CSS model."); } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof CSSMediaRule)) { return false; } final CSSMediaRule cmr = (CSSMediaRule) obj; return super.equals(obj) && LangUtils.equals(getMedia(), cmr.getMedia()) && LangUtils.equals(getCssRules(), cmr.getCssRules()); }