protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) { if (node != null) formatChildren(node, formatContraints); } }
public void format(Node node) { IStructuredFormatContraints formatContraints = getFormatContraints(); format(node, formatContraints); }
protected IStructuredFormatProcessor getFormatProcessor() { return new FormatProcessorXML(); }
switch (nodeType) { case Node.ELEMENT_NODE : { formatter = new ElementNodeFormatter(); break; formatter = new TextNodeFormatter(); break; formatter = new NoMoveFormatter(); break; formatter = new CommentNodeFormatter(); break; formatter = new NoMoveFormatter(); break; formatter = new DocumentNodeFormatter(); break; formatter = new NoMoveFormatter(); break; formatter = new NodeFormatter(); formatter.setFormatPreferences(getFormatPreferences()); formatter.setProgressMonitor(fProgressMonitor);
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; }
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; }
switch (nodeType) { case Node.ELEMENT_NODE : { formatter = new ElementNodeFormatter(); break; formatter = new TextNodeFormatter(); break; formatter = new NoMoveFormatter(); break; formatter = new CommentNodeFormatter(); break; formatter = new NoMoveFormatter(); break; formatter = new DocumentNodeFormatter(); break; formatter = new NoMoveFormatter(); break; formatter = new NodeFormatter(); formatter.setFormatPreferences(getFormatPreferences()); formatter.setProgressMonitor(fProgressMonitor);
private boolean noSiblingsAndNoFollowingComment(IDOMNode node) { IDOMNode nextSibling = (IDOMNode) node.getNextSibling(); return !nodeHasSiblings(node) || (noLineDelimiter(node) && isComment(nextSibling) && noLineDelimiter(nextSibling)); }
protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) { if (node != null && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) { // format indentation before node formatIndentationBeforeNode(node, formatContraints); // format indentation after node formatIndentationAfterNode(node, formatContraints); } }
public void format(Node node, IStructuredFormatContraints formatContraints) { if (formatContraints.getFormatWithSiblingIndent()) formatContraints.setCurrentIndent(getSiblingIndent(node)); if (node instanceof IDOMNode) formatNode((IDOMNode) node, formatContraints); }
protected IDOMNode getDeepestChildNode(IDOMNode node) { IDOMNode result = null; IDOMNode lastChild = (IDOMNode) node.getLastChild(); if (lastChild == null) result = node; else { result = getDeepestChildNode(lastChild); if ((result.getNodeType() == Node.TEXT_NODE || result.getNodeType() == Node.COMMENT_NODE) && !isEndTagMissing(node)) result = node; } return result; }
protected void insertBeforeNode(IDOMNode node, String string) { IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); replace(structuredDocument, node.getStartOffset(), 0, string); }
protected String getNodeText(IDOMNode node) { String text = null; if ((node instanceof CharacterDataImpl) && !(node instanceof CommentImpl) && !(node instanceof CDATASectionImpl) && !isJSPTag(node)) text = ((CharacterDataImpl) node).getSource(); else text = node.getFirstStructuredDocumentRegion().getText(); return text; }
public IStructuredFormatContraints getFormatContraints() { if (fFormatContraints == null) { fFormatContraints = new StructuredFormatContraints(); fFormatContraints.setClearAllBlankLines(getFormatPreferences().getClearAllBlankLines()); } return fFormatContraints; }
protected IDOMNode getParentIndentNode(IDOMNode node) { IDOMNode result = null; IDOMNode parentNode = (IDOMNode) node.getParentNode(); if (parentNode.getNodeType() == Node.DOCUMENT_NODE) result = parentNode; else { ITextRegion region = parentNode.getLastStructuredDocumentRegion().getFirstRegion(); if (region.getType() == DOMRegionContext.XML_END_TAG_OPEN) result = parentNode; else result = getParentIndentNode(parentNode); } return result; }
private int computeAvailableLineWidth(IStructuredDocument doc, int nodeOffset, int lineWidth) { // compute current available line width int currentAvailableLineWidth = 0; try { int lineOffset = doc.getLineInformationOfOffset(nodeOffset).getOffset(); String text = doc.get(lineOffset, nodeOffset - lineOffset); int usedWidth = getIndentationLength(text); currentAvailableLineWidth = lineWidth - usedWidth; } catch (BadLocationException e) { // log for now, unless we find reason not to Logger.log(Logger.INFO, e.getMessage()); } return currentAvailableLineWidth; }
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { final MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IXMLPartitions.XML_DEFAULT); formatter.setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorXML())); return formatter; }
protected void insertAfterNode(IDOMNode node, String string) { IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); int offset = node.getEndOffset(); int length = 0; // 261968 - formatting tag without closing bracket: <t1><t1 if (node.getEndStructuredDocumentRegion() != null) { offset = node.getEndStructuredDocumentRegion().getTextEndOffset(); length = node.getEndOffset() - offset; } replace(structuredDocument, offset, length, string); }
public void reformat(Node newElement, boolean deep) { try { // tell the model that we are about to make a big model change fModel.aboutToChangeModel(); // format selected node IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); formatProcessor.formatNode(newElement); } finally { // tell the model that we are done with the big model change fModel.changedModel(); } }
protected void removeRegionSpaces(IDOMNode node, IStructuredDocumentRegion flatNode, ITextRegion region) { if ((region != null) && (region instanceof ContextRegion || region instanceof TagNameRegion) && (flatNode.getEndOffset(region) > flatNode.getTextEndOffset(region))) { IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); replace(structuredDocument, flatNode.getTextEndOffset(region), flatNode.getEndOffset(region) - flatNode.getTextEndOffset(region), EMPTY_STRING); } }