Search in sources :

Example 21 with IStructuredFormatPreferences

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences in project webtools.sourceediting by eclipse.

the class FormatTester method testFormatTags.

public void testFormatTags() {
    // get model
    IStructuredModel structuredModel = getModel("tags.xml");
    // init FormatPreferences
    IStructuredFormatPreferences formatPreferences = fFormatProcessor.getFormatPreferences();
    ((StructuredFormatPreferencesXML) formatPreferences).setSplitMultiAttrs(false);
    formatPreferences.setLineWidth(999);
    formatPreferences.setIndent("\t");
    formatPreferences.setClearAllBlankLines(false);
    // format
    ((AbstractStructuredFormatProcessor) fFormatProcessor).refreshFormatPreferences = false;
    fFormatProcessor.formatModel(structuredModel);
    ((AbstractStructuredFormatProcessor) fFormatProcessor).refreshFormatPreferences = true;
    // compare
    String formatted = structuredModel.getStructuredDocument().get();
    String expectedFileName = "tags.afterDefaultFormat.xml";
    String expected = getFile(expectedFileName);
    compare(expectedFileName, expected, formatted);
    // release model
    structuredModel.releaseFromRead();
}
Also used : StructuredFormatPreferencesXML(org.eclipse.wst.xml.core.internal.provisional.format.StructuredFormatPreferencesXML) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredFormatPreferences(org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)

Example 22 with IStructuredFormatPreferences

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences in project webtools.sourceediting by eclipse.

the class FormatTester method testFormatTagOpen.

public void testFormatTagOpen() {
    // get model
    IStructuredModel structuredModel = getModel("tagOpen.xml");
    // init FormatPreferences
    IStructuredFormatPreferences formatPreferences = fFormatProcessor.getFormatPreferences();
    ((StructuredFormatPreferencesXML) formatPreferences).setSplitMultiAttrs(false);
    formatPreferences.setLineWidth(999);
    formatPreferences.setIndent("\t");
    formatPreferences.setClearAllBlankLines(false);
    // format
    ((AbstractStructuredFormatProcessor) fFormatProcessor).refreshFormatPreferences = false;
    fFormatProcessor.formatModel(structuredModel);
    ((AbstractStructuredFormatProcessor) fFormatProcessor).refreshFormatPreferences = true;
    // compare
    String formatted = structuredModel.getStructuredDocument().get();
    String expectedFileName = "tagOpen.xml";
    String expected = getFile(expectedFileName);
    compare(expectedFileName, expected, formatted);
    // release model
    structuredModel.releaseFromRead();
}
Also used : StructuredFormatPreferencesXML(org.eclipse.wst.xml.core.internal.provisional.format.StructuredFormatPreferencesXML) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredFormatPreferences(org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)

Example 23 with IStructuredFormatPreferences

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences in project webtools.sourceediting by eclipse.

the class FormatTester method testFormatSplitLinesSplitMultiAttrs.

public void testFormatSplitLinesSplitMultiAttrs() {
    // get model
    IStructuredModel structuredModel = getModel("small.xml");
    // init FormatPreferences
    IStructuredFormatPreferences formatPreferences = fFormatProcessor.getFormatPreferences();
    ((StructuredFormatPreferencesXML) formatPreferences).setSplitMultiAttrs(true);
    formatPreferences.setLineWidth(72);
    formatPreferences.setIndent("\t");
    formatPreferences.setClearAllBlankLines(false);
    // format
    ((AbstractStructuredFormatProcessor) fFormatProcessor).refreshFormatPreferences = false;
    fFormatProcessor.formatModel(structuredModel);
    ((AbstractStructuredFormatProcessor) fFormatProcessor).refreshFormatPreferences = true;
    // compare
    String formatted = structuredModel.getStructuredDocument().get();
    String expectedFileName = "small.afterSplitLinesSplitMultiAttrsFormat.xml";
    String expected = getFile(expectedFileName);
    compare(expectedFileName, expected, formatted);
    // release model
    structuredModel.releaseFromRead();
}
Also used : StructuredFormatPreferencesXML(org.eclipse.wst.xml.core.internal.provisional.format.StructuredFormatPreferencesXML) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredFormatPreferences(org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)

Example 24 with IStructuredFormatPreferences

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences in project webtools.sourceediting by eclipse.

the class FormatProcessorXML method getFormatPreferences.

public IStructuredFormatPreferences getFormatPreferences() {
    if (fFormatPreferences == null) {
        fFormatPreferences = new StructuredFormatPreferencesXML();
        Preferences preferences = getModelPreferences();
        if (preferences != null) {
            fFormatPreferences.setLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
            ((StructuredFormatPreferencesXML) fFormatPreferences).setSplitMultiAttrs(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
            ((StructuredFormatPreferencesXML) fFormatPreferences).setAlignEndBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
            ((StructuredFormatPreferencesXML) fFormatPreferences).setPreservePCDATAContent(preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
            fFormatPreferences.setClearAllBlankLines(preferences.getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
            char indentChar = ' ';
            String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR);
            if (XMLCorePreferenceNames.TAB.equals(indentCharPref)) {
                indentChar = '\t';
            }
            int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
            StringBuffer indent = new StringBuffer();
            for (int i = 0; i < indentationWidth; i++) {
                indent.append(indentChar);
            }
            fFormatPreferences.setIndent(indent.toString());
        }
    }
    return fFormatPreferences;
}
Also used : IStructuredFormatPreferences(org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences) Preferences(org.eclipse.core.runtime.Preferences)

Example 25 with IStructuredFormatPreferences

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences in project webtools.sourceediting by eclipse.

the class TestFormatProcessorXML method testPreservePCDATAFormat.

public void testPreservePCDATAFormat() throws UnsupportedEncodingException, IOException, CoreException {
    // BUG84688
    IStructuredFormatPreferences formatPreferences = formatProcessor.getFormatPreferences();
    ((StructuredFormatPreferencesXML) formatPreferences).setPreservePCDATAContent(true);
    formatAndAssertEquals("testfiles/xml/xml-preservepcdata.xml", "testfiles/xml/xml-preservepcdata-yes-fmt.xml", false);
    ((StructuredFormatPreferencesXML) formatPreferences).setPreservePCDATAContent(false);
    formatAndAssertEquals("testfiles/xml/xml-preservepcdata.xml", "testfiles/xml/xml-preservepcdata-no-fmt.xml", false);
}
Also used : StructuredFormatPreferencesXML(org.eclipse.wst.xml.core.internal.provisional.format.StructuredFormatPreferencesXML) IStructuredFormatPreferences(org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)

Aggregations

IStructuredFormatPreferences (org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)28 StructuredFormatPreferencesXML (org.eclipse.wst.xml.core.internal.provisional.format.StructuredFormatPreferencesXML)26 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)17 Preferences (org.eclipse.core.runtime.Preferences)4