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);
}
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);
}
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();
}
}
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);
}
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);
}
Aggregations