use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatter in project webtools.sourceediting by eclipse.
the class HTMLFormatter method insertBreakAfter.
/**
*/
protected void insertBreakAfter(IDOMNode node, HTMLFormatContraints contraints) {
if (node == null)
return;
if (node.getNodeType() == Node.TEXT_NODE)
return;
// don't insert break if node is on the last line
int documentLength = node.getStructuredDocument().getLength();
if (documentLength < 1 || (node.getEndOffset() >= (documentLength - 1)))
return;
Node parent = node.getParentNode();
if (parent == null)
return;
Node next = node.getNextSibling();
String spaces = null;
if (next == null) {
// If the parent is inline and its content is not formatted don't insert
if (formattingUtil.isInline(parent) && !isContentFormatted(parent))
return;
// use parent indent for the end tag
spaces = getBreakSpaces(parent);
} else if (next.getNodeType() == Node.TEXT_NODE) {
if (contraints != null && contraints.getFormatWithSiblingIndent()) {
IDOMNode text = (IDOMNode) next;
IStructuredFormatter formatter = HTMLFormatterFactory.getInstance().createFormatter(text, getFormatPreferences());
if (formatter instanceof HTMLTextFormatter) {
HTMLTextFormatter textFormatter = (HTMLTextFormatter) formatter;
textFormatter.formatText(text, contraints, HTMLTextFormatter.FORMAT_HEAD);
}
}
return;
} else {
spaces = getBreakSpaces(node);
}
if (spaces == null || spaces.length() == 0)
return;
replaceSource(node.getModel(), node.getEndOffset(), 0, spaces);
setWidth(contraints, spaces);
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatter in project webtools.sourceediting by eclipse.
the class NodeFormatter method getFormatter.
protected IStructuredFormatter getFormatter(IDOMNode node) {
// 262135 - NPE during format of empty document
if (node == null)
return null;
short nodeType = ((Node) node).getNodeType();
IStructuredFormatter formatter = null;
switch(nodeType) {
case Node.ELEMENT_NODE:
{
formatter = new ElementNodeFormatter();
break;
}
case Node.TEXT_NODE:
{
formatter = new TextNodeFormatter();
break;
}
case Node.CDATA_SECTION_NODE:
{
formatter = new NoMoveFormatter();
break;
}
case Node.COMMENT_NODE:
{
formatter = new CommentNodeFormatter();
break;
}
case Node.PROCESSING_INSTRUCTION_NODE:
{
formatter = new NodeFormatter();
break;
}
case Node.DOCUMENT_NODE:
{
formatter = new DocumentNodeFormatter();
break;
}
case Node.ENTITY_REFERENCE_NODE:
{
formatter = new NoMoveFormatter();
break;
}
default:
{
formatter = new NodeFormatter();
}
}
// init fomatter
formatter.setFormatPreferences(getFormatPreferences());
formatter.setProgressMonitor(fProgressMonitor);
return formatter;
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatter in project webtools.sourceediting by eclipse.
the class DocumentNodeFormatter method formatChildren.
protected void formatChildren(IDOMNode node, IStructuredFormatContraints formatContraints) {
String singleIndent = getFormatPreferences().getIndent();
String lineIndent = formatContraints.getCurrentIndent();
if (node != null && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) {
// normalize node first to combine adjacent text nodes
node.normalize();
IDOMNode nextChild = (IDOMNode) node.getFirstChild();
while (nextChild != null) {
IDOMNode eachChildNode = nextChild;
nextChild = (IDOMNode) eachChildNode.getNextSibling();
IStructuredFormatter formatter = getFormatter(eachChildNode);
IStructuredFormatContraints childFormatContraints = formatter.getFormatContraints();
String childIndent = lineIndent + singleIndent;
childFormatContraints.setCurrentIndent(childIndent);
childFormatContraints.setClearAllBlankLines(formatContraints.getClearAllBlankLines());
childFormatContraints.setInPreserveSpaceElement(formatContraints.getInPreserveSpaceElement());
// format each child
formatter.format(eachChildNode, childFormatContraints);
if (nextChild != null && nextChild.getParentNode() == null)
// nextNode is deleted during format
nextChild = (IDOMNode) eachChildNode.getNextSibling();
}
}
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatter in project webtools.sourceediting by eclipse.
the class FormatProcessorXML method getFormatter.
protected IStructuredFormatter getFormatter(Node node) {
// 262135 - NPE during format of empty document
if (node == null)
return null;
short nodeType = node.getNodeType();
IStructuredFormatter formatter = null;
switch(nodeType) {
case Node.ELEMENT_NODE:
{
formatter = new ElementNodeFormatter();
break;
}
case Node.TEXT_NODE:
{
formatter = new TextNodeFormatter();
break;
}
case Node.CDATA_SECTION_NODE:
{
formatter = new NoMoveFormatter();
break;
}
case Node.COMMENT_NODE:
{
formatter = new CommentNodeFormatter();
break;
}
case Node.PROCESSING_INSTRUCTION_NODE:
{
formatter = new NodeFormatter();
break;
}
case Node.DOCUMENT_NODE:
{
formatter = new DocumentNodeFormatter();
break;
}
case Node.ENTITY_REFERENCE_NODE:
{
formatter = new NoMoveFormatter();
break;
}
default:
{
formatter = new NodeFormatter();
}
}
// init fomatter
formatter.setFormatPreferences(getFormatPreferences());
formatter.setProgressMonitor(fProgressMonitor);
return formatter;
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatter in project webtools.sourceediting by eclipse.
the class HTMLFormatterFactory method createFormatter.
protected IStructuredFormatter createFormatter(Node node, IStructuredFormatPreferences formatPreferences) {
IStructuredFormatter formatter = null;
switch(node.getNodeType()) {
case Node.ELEMENT_NODE:
formatter = new HTMLElementFormatter();
break;
case Node.TEXT_NODE:
if (isEmbeddedCSS(node)) {
formatter = new EmbeddedCSSFormatter();
} else {
formatter = new HTMLTextFormatter();
}
break;
default:
formatter = new HTMLFormatter();
break;
}
// init FormatPreferences
formatter.setFormatPreferences(formatPreferences);
return formatter;
}
Aggregations