Search in sources :

Example 46 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class ImportRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
    if (end > 0) {
        // format source
        CSSCleanupStrategy stgy = getCleanupStrategy(node);
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            String str = regions[i].getText();
            if (regions[i].getType() == CSSRegionContexts.CSS_IMPORT)
                str = decoratedIdentRegion(regions[i], stgy);
            else
                str = decoratedPropValueRegion(regions[i], stgy);
            if (i != 0)
                appendSpaceBefore(node, regions[i], source);
            source.append(str);
        }
    } else {
        // generate source
        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
        String str = IMPORT;
        if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
            str = IMPORT.toUpperCase();
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        source.append(str);
        // $NON-NLS-1$
        str = "url(";
        if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
            str = str.toUpperCase();
        String href = ((ICSSImportRule) node).getHref();
        quote = CSSUtil.detectQuote(href, quote);
        // $NON-NLS-1$
        str = str + quote + href + quote + ")";
        appendSpaceBefore(node, str, source);
        source.append(str);
    }
    ICSSNode child = node.getFirstChild();
    if (child != null && (child instanceof org.w3c.dom.stylesheets.MediaList) && ((org.w3c.dom.stylesheets.MediaList) child).getLength() > 0) {
        // $NON-NLS-1$
        appendSpaceBefore(node, "", source);
    }
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)

Example 47 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class ImportRuleFormatter method formatPost.

/**
 */
protected void formatPost(ICSSNode node, IRegion region, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
    CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
    for (int i = 0; i < regions.length; i++) {
        if ((i != 0 || needS(outside[0])) && !regions[i].getType().equals(CSSRegionContexts.CSS_DELIMITER))
            appendDelimBefore(node, regions[i], source);
        source.append(decoratedRegion(regions[i], 0, stgy));
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 48 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class MediaRuleFormatter method formatPost.

/**
 */
protected void formatPost(ICSSNode node, StringBuffer source) {
    int end = ((IndexedRegion) node).getEndOffset();
    int start = (node.getLastChild() != null && ((IndexedRegion) node.getLastChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getLastChild()).getEndOffset() : getChildInsertPos(node);
    if (end > 0 && start < end) {
        // source formatting
        CSSCleanupStrategy stgy = getCleanupStrategy(node);
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        if (node.getLastChild() == null || node.getLastChild().getNodeType() != ICSSNode.MEDIALIST_NODE) {
            for (int i = 0; i < regions.length; i++) {
                appendDelimBefore(node, regions[i], source);
                source.append(decoratedRegion(regions[i], 0, stgy));
            }
        } else {
            boolean bInCurlyBrace = false;
            for (int i = 0; i < regions.length; i++) {
                if (!bInCurlyBrace)
                    appendSpaceBefore(node, regions[i], source);
                else
                    appendDelimBefore(node, regions[i], source);
                source.append(decoratedRegion(regions[i], 0, stgy));
                if (regions[i].getType() == CSSRegionContexts.CSS_LBRACE)
                    bInCurlyBrace = true;
            }
        }
    } else {
        // source generation
        String delim = getLineDelimiter(node);
        if (node.getLastChild() != null && node.getLastChild().getNodeType() == ICSSNode.MEDIALIST_NODE) {
            // $NON-NLS-1$
            appendSpaceBefore(node, "{", source);
            // $NON-NLS-1$
            source.append("{");
        }
        source.append(delim);
        source.append(getIndent(node));
        // $NON-NLS-1$
        source.append("}");
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 49 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class TestCleanupProcessorCSS method testBUG166909urlCaseCleanup.

public void testBUG166909urlCaseCleanup() throws UnsupportedEncodingException, IOException, CoreException {
    // set up cleanup preferences for this test
    CSSCleanupStrategy currentStrategy = CSSCleanupStrategyImpl.getInstance();
    short oldCaseIdentifier = currentStrategy.getIdentCase();
    short oldCasePropertyName = currentStrategy.getPropNameCase();
    short oldCasePropertyValue = currentStrategy.getPropValueCase();
    short oldCaseSelector = currentStrategy.getSelectorTagCase();
    boolean oldFormatSource = currentStrategy.isFormatSource();
    boolean oldFormatQuote = currentStrategy.isQuoteValues();
    currentStrategy.setIdentCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setPropNameCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setPropValueCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setSelectorTagCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setFormatSource(true);
    currentStrategy.setQuoteValues(false);
    cleanupAndAssertEquals("testfiles/bug166909-urlcase.css", "testfiles/bug166909-urlcase-cleaned.css");
    currentStrategy.setIdentCase(oldCaseIdentifier);
    currentStrategy.setPropNameCase(oldCasePropertyName);
    currentStrategy.setPropValueCase(oldCasePropertyValue);
    currentStrategy.setSelectorTagCase(oldCaseSelector);
    currentStrategy.setFormatSource(oldFormatSource);
    currentStrategy.setQuoteValues(oldFormatQuote);
}
Also used : CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 50 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class TestCleanupProcessorCSS method testBug218993NoFormatCleanup.

public void testBug218993NoFormatCleanup() throws UnsupportedEncodingException, IOException, CoreException {
    // set up cleanup preferences for this test
    CSSCleanupStrategy currentStrategy = CSSCleanupStrategyImpl.getInstance();
    short oldCaseIdentifier = currentStrategy.getIdentCase();
    short oldCasePropertyName = currentStrategy.getPropNameCase();
    short oldCasePropertyValue = currentStrategy.getPropValueCase();
    short oldCaseSelector = currentStrategy.getSelectorTagCase();
    boolean oldFormatSource = currentStrategy.isFormatSource();
    boolean oldFormatQuote = currentStrategy.isQuoteValues();
    currentStrategy.setIdentCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setPropNameCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setPropValueCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setSelectorTagCase(CSSCleanupStrategy.LOWER);
    currentStrategy.setFormatSource(false);
    currentStrategy.setQuoteValues(false);
    cleanupAndAssertEquals("testfiles/bug218993-noformat.css", "testfiles/bug218993-noformat-cleaned.css");
    currentStrategy.setIdentCase(oldCaseIdentifier);
    currentStrategy.setPropNameCase(oldCasePropertyName);
    currentStrategy.setPropValueCase(oldCasePropertyValue);
    currentStrategy.setSelectorTagCase(oldCaseSelector);
    currentStrategy.setFormatSource(oldFormatSource);
    currentStrategy.setQuoteValues(oldFormatQuote);
}
Also used : CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Aggregations

CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)50 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)44 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 Preferences (org.eclipse.core.runtime.Preferences)6 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)5 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 MediaList (org.w3c.dom.stylesheets.MediaList)3 ICSSAttr (org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr)2 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 CSSCleanupStrategyImpl (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategyImpl)1 CSSRegionContainer (org.eclipse.wst.css.core.internal.document.CSSRegionContainer)1 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)1 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 ICounter (org.eclipse.wst.css.core.internal.provisional.document.ICounter)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 CSSUnknownRule (org.w3c.dom.css.CSSUnknownRule)1