Search in sources :

Example 1 with FlexCssPropertyDescriptor

use of com.intellij.javascript.flex.css.FlexCssPropertyDescriptor in project intellij-plugins by JetBrains.

the class CssWriter method write.

@Nullable
private byte[] write(@NotNull StylesheetFile stylesheetFile, @NotNull Document document, @NotNull Module module) {
    CssStylesheet stylesheet = stylesheetFile.getStylesheet();
    if (stylesheet == null) {
        LOG.warn("Stylesheet is null for " + stylesheetFile.getName());
        return null;
    }
    rulesetVectorWriter.prepareIteration();
    DocumentWindow documentWindow = document instanceof DocumentWindow ? (DocumentWindow) document : null;
    for (CssRuleset ruleset : stylesheet.getRulesets()) {
        CssBlock block = ruleset.getBlock();
        if (block == null) {
            continue;
        }
        PrimitiveAmfOutputStream rulesetOut = rulesetVectorWriter.getOutputForIteration();
        int textOffset = ruleset.getTextOffset();
        if (documentWindow == null) {
            rulesetOut.writeUInt29(document.getLineNumber(textOffset) + 1);
        } else {
            rulesetOut.writeUInt29(documentWindow.injectedToHostLine(document.getLineNumber(textOffset)) + 1);
            textOffset = documentWindow.injectedToHost(textOffset);
        }
        rulesetOut.writeUInt29(textOffset);
        writeSelectors(ruleset, rulesetOut, module);
        declarationVectorWriter.prepareIteration();
        for (CssDeclaration declaration : block.getDeclarations()) {
            CssTermList value = declaration.getValue();
            if (value == null || PsiTreeUtil.getChildOfType(value, PsiErrorElement.class) != null) {
                continue;
            }
            propertyOut = declarationVectorWriter.getOutputForIteration();
            try {
                stringWriter.write(declaration.getPropertyName(), propertyOut);
                textOffset = declaration.getTextOffset();
                propertyOut.writeUInt29(documentWindow == null ? textOffset : documentWindow.injectedToHost(textOffset));
                CssPropertyDescriptor propertyDescriptor = ContainerUtil.getFirstItem(declaration.getDescriptors());
                writePropertyValue(value, propertyDescriptor != null && propertyDescriptor instanceof FlexCssPropertyDescriptor ? ((FlexCssPropertyDescriptor) propertyDescriptor).getStyleInfo() : null);
                continue;
            } catch (RuntimeException e) {
                problemsHolder.add(declaration, e, declaration.getPropertyName());
            } catch (Throwable e) {
                problemsHolder.add(e);
            }
            declarationVectorWriter.rollbackLastIteration();
        }
        // must be written in any case, IDEA-86219, ruleset without rules
        declarationVectorWriter.writeTo(rulesetOut);
    }
    PrimitiveAmfOutputStream outputForCustomData = rulesetVectorWriter.getOutputForCustomData();
    CssNamespace[] namespaces = stylesheet.getNamespaces();
    outputForCustomData.write(namespaces.length);
    if (namespaces.length > 0) {
        for (CssNamespace cssNamespace : namespaces) {
            stringWriter.writeNullable(cssNamespace.getPrefix(), outputForCustomData);
            stringWriter.writeNullable(cssNamespace.getUri(), outputForCustomData);
        }
    }
    return IOUtil.getBytes(rulesetVectorWriter);
}
Also used : FlexCssPropertyDescriptor(com.intellij.javascript.flex.css.FlexCssPropertyDescriptor) FlexCssPropertyDescriptor(com.intellij.javascript.flex.css.FlexCssPropertyDescriptor) DocumentWindow(com.intellij.injected.editor.DocumentWindow) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 FlexCssPropertyDescriptor (com.intellij.javascript.flex.css.FlexCssPropertyDescriptor)1 Nullable (org.jetbrains.annotations.Nullable)1