Search in sources :

Example 6 with XMLFormattingPreferences

use of org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences in project webtools.sourceediting by eclipse.

the class TestPartitionFormatterXML method testFormatDocumentLevelComment.

public void testFormatDocumentLevelComment() throws UnsupportedEncodingException, IOException, CoreException {
    XMLFormattingPreferences prefs = new XMLFormattingPreferences();
    prefs.setJoinCommentLines(false);
    formatAndAssertEquals("testfiles/xml/xml-format-document-level-comment.xml", "testfiles/xml/xml-format-document-level-comment-fmt.xml", prefs);
}
Also used : XMLFormattingPreferences(org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences)

Example 7 with XMLFormattingPreferences

use of org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences in project webtools.sourceediting by eclipse.

the class TestPartitionFormatterXML method testSpaceBeforeEmptyCloseTag.

public void testSpaceBeforeEmptyCloseTag() throws UnsupportedEncodingException, IOException, CoreException {
    // Bug 195264
    XMLFormattingPreferences prefs = new XMLFormattingPreferences();
    prefs.setSpaceBeforeEmptyCloseTag(false);
    formatAndAssertEquals("testfiles/xml/xml-empty-tag-space.xml", "testfiles/xml/xml-empty-tag-space-none-newfmt.xml", prefs);
    prefs.setSpaceBeforeEmptyCloseTag(true);
    formatAndAssertEquals("testfiles/xml/xml-empty-tag-space.xml", "testfiles/xml/xml-empty-tag-space-newfmt.xml", prefs);
}
Also used : XMLFormattingPreferences(org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences)

Example 8 with XMLFormattingPreferences

use of org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences in project webtools.sourceediting by eclipse.

the class TestPartitionFormatterXML method formatAndAssertEquals.

private void formatAndAssertEquals(String beforePath, String afterPath, XMLFormattingPreferences prefs) throws UnsupportedEncodingException, IOException, CoreException {
    IStructuredModel beforeModel = null, afterModel = null;
    try {
        beforeModel = getModelForEdit(beforePath);
        assertNotNull("could not retrieve structured model for : " + beforePath, beforeModel);
        afterModel = getModelForEdit(afterPath);
        assertNotNull("could not retrieve structured model for : " + afterPath, afterModel);
        IStructuredDocument document = beforeModel.getStructuredDocument();
        String normalizedContents = document.get();
        normalizedContents = StringUtils.replace(normalizedContents, "\r\n", "\n");
        normalizedContents = StringUtils.replace(normalizedContents, "\r", "\n");
        document.set(normalizedContents);
        if (prefs == null)
            prefs = new XMLFormattingPreferences();
        TextEdit edit = partitionFormatter.format(beforeModel, 0, document.getLength(), prefs);
        try {
            edit.apply(document);
        } catch (MalformedTreeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ByteArrayOutputStream formattedBytes = new ByteArrayOutputStream();
        // "beforeModel" should now be
        beforeModel.save(formattedBytes);
        // after the formatter
        ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
        afterModel.save(afterBytes);
        String expectedContents = new String(afterBytes.toByteArray(), UTF_8);
        String actualContents = new String(formattedBytes.toByteArray(), UTF_8);
        /* Make some adjustments to ignore cross platform line delimiter issues */
        expectedContents = StringUtils.replace(expectedContents, "\r\n", "\n");
        expectedContents = StringUtils.replace(expectedContents, "\r", "\n");
        actualContents = StringUtils.replace(actualContents, "\r\n", "\n");
        actualContents = StringUtils.replace(actualContents, "\r", "\n");
        if (!fStringCompareUtil.equalsIgnoreLineSeperator(expectedContents, actualContents)) {
            assertEquals("Formatted document differs from the expected.", expectedContents, actualContents);
        }
    } finally {
        if (beforeModel != null)
            beforeModel.releaseFromEdit();
        if (afterModel != null)
            afterModel.releaseFromEdit();
    }
}
Also used : TextEdit(org.eclipse.text.edits.TextEdit) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) XMLFormattingPreferences(org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 9 with XMLFormattingPreferences

use of org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences in project webtools.sourceediting by eclipse.

the class TestPartitionFormatterXML method testAlignEndBracketFormat.

public void testAlignEndBracketFormat() throws UnsupportedEncodingException, IOException, CoreException {
    // results are different than old formatter
    // BUG113584
    XMLFormattingPreferences prefs = new XMLFormattingPreferences();
    prefs.setIndentMultipleAttributes(false);
    prefs.setAlignFinalBracket(true);
    formatAndAssertEquals("testfiles/xml/multiattributes.xml", "testfiles/xml/multiattributes-nosplit-yesalign-newfmt.xml", prefs);
    // results are different than old formatter
    prefs.setIndentMultipleAttributes(true);
    prefs.setAlignFinalBracket(true);
    formatAndAssertEquals("testfiles/xml/multiattributes.xml", "testfiles/xml/multiattributes-yessplit-yesalign-newfmt.xml", prefs);
}
Also used : XMLFormattingPreferences(org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences)

Example 10 with XMLFormattingPreferences

use of org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences in project webtools.sourceediting by eclipse.

the class TestPartitionFormatterXML method testEntityFormat.

public void testEntityFormat() throws UnsupportedEncodingException, IOException, CoreException {
    // results are different than old formatter
    // BUG102076
    XMLFormattingPreferences prefs = new XMLFormattingPreferences();
    prefs.setClearAllBlankLines(true);
    formatAndAssertEquals("testfiles/xml/entities.xml", "testfiles/xml/entities-newfmt.xml", prefs);
}
Also used : XMLFormattingPreferences(org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences)

Aggregations

XMLFormattingPreferences (org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)1 TextEdit (org.eclipse.text.edits.TextEdit)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1