use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLFormatter method canInsertBreakBefore.
/**
*/
protected boolean canInsertBreakBefore(Node node) {
if (node == null)
return false;
Node parent = node.getParentNode();
if (parent == null)
return false;
Node prev = node.getPreviousSibling();
// special exception if this node is a non-HTML tag (like JSP
// elements)
// BUG188093 - only preserve whitespace for jsp (not custom) tags
String prefix = node.getPrefix();
if (prefix != null && JSP.equals(prefix)) {
boolean canInsertBreakBefore = false;
// if a whitespace does not exist before it, do not add one
if (prev != null && prev.getNodeType() == Node.TEXT_NODE) {
String theText = ((Text) prev).getData();
if (theText != null && theText.length() > 0) {
char theChar = theText.charAt(theText.length() - 1);
canInsertBreakBefore = Character.isWhitespace(theChar);
}
}
// continue processing)
if (!canInsertBreakBefore)
return false;
}
// BUG188093 - only preserve whitespace for jsp (not custom) tags
if (prev != null) {
prefix = prev.getPrefix();
if (prefix != null && JSP.equals(prefix)) {
boolean canInsertBreakBeforeNext = false;
// if a whitespace does not exist after it, do not add one
if (node.getNodeType() == Node.TEXT_NODE) {
String theText = ((Text) node).getData();
if (theText != null && theText.length() > 0) {
char theChar = theText.charAt(0);
canInsertBreakBeforeNext = Character.isWhitespace(theChar);
}
}
// continue processing)
if (!canInsertBreakBeforeNext)
return false;
}
}
if (parent.getNodeType() == Node.DOCUMENT_NODE) {
if (prev == null)
return false;
return true;
} else if (parent.getNodeType() == Node.ELEMENT_NODE) {
IDOMElement element = (IDOMElement) parent;
// do not insert break after missing start tag
if (prev == null && element.getStartStructuredDocumentRegion() == null)
return false;
// elements
if (element.getPrefix() != null)
return true;
CMElementDeclaration decl = getElementDeclaration(element);
if (decl != null) {
return allowNewlineBefore(node, element, decl);
}
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
return true;
}
if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) {
CMElementDeclaration decl = getElementDeclaration((Element) prev);
if (canInsertBreakAfter(decl)) {
// spcial for BR
return canFormatChild(parent);
}
}
return false;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method insertEndTag.
private IDOMNode insertEndTag(IDOMNode node) {
IDOMNode newNode = node;
IDOMElement element = (IDOMElement) node;
if (element.isCommentTag())
// do nothing
return node;
int startTagStartOffset = node.getStartOffset();
IDOMModel structuredModel = node.getModel();
if (isEmptyElement(element)) {
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
ITextRegionList regions = startStructuredDocumentRegion.getRegions();
ITextRegion lastRegion = regions.get(regions.size() - 1);
structuredDocument.replaceText(structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), lastRegion.getLength(), EMPTY_TAG_CLOSE);
if (regions.size() > 1) {
ITextRegion regionBeforeTagClose = regions.get(regions.size() - 1 - 1);
// region does not have extra spaces
if (regionBeforeTagClose.getTextLength() == regionBeforeTagClose.getLength())
// $NON-NLS-1$
structuredDocument.replaceText(structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), 0, " ");
}
} else {
String tagName = node.getNodeName();
String endTag = END_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);
IDOMNode lastChild = (IDOMNode) node.getLastChild();
int endTagStartOffset = 0;
if (lastChild != null)
// if this node has children, insert the end tag after the
// last child
endTagStartOffset = lastChild.getEndOffset();
else
// if this node does not has children, insert the end tag
// after the start tag
endTagStartOffset = node.getEndOffset();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
structuredDocument.replaceText(structuredDocument, endTagStartOffset, 0, endTag);
}
// save
newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
return newNode;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class XMLComponentRenameParticipant method createChange.
// private RefactoringStatus createRenameChanges(final IProgressMonitor monitor) throws CoreException {
// Assert.isNotNull(monitor);
// final RefactoringStatus status= new RefactoringStatus();
// try {
// monitor.beginTask("RefactoringMessages.RenameComponentRefactoring_searching", 1);
// createRenameChanges(new SubProgressMonitor(monitor, 1));
// //updateChangeManager(new SubProgressMonitor(monitor, 1), status);
// } finally {
// monitor.done();
// }
// return status;
// }
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
for (Iterator iter = matches.iterator(); iter.hasNext(); ) {
SearchMatch match = (SearchMatch) iter.next();
TextChange textChange = getChangeManager().get(match.getFile());
String newName = getArguments().getNewName();
String qualifier = "";
if (getArguments() instanceof ComponentRenameArguments) {
qualifier = ((ComponentRenameArguments) getArguments()).getQualifier();
}
if (match.getObject() instanceof Node) {
Node node = (Node) match.getObject();
if (node instanceof IDOMAttr) {
IDOMAttr attr = (IDOMAttr) node;
IDOMElement element = (IDOMElement) attr.getOwnerElement();
newName = getNewQName(element, qualifier, newName);
}
newName = RenameComponentProcessor.quoteString(newName);
}
ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName);
String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference");
TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit);
}
// don't create any change now, all the changes are in changeManger variable and will be combined in RenameComponentProcessor.postCreateChange method
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project liferay-ide by liferay.
the class LayoutTplUtil method getChildElementsByTagName.
public static List<Element> getChildElementsByTagName(IDOMElement parentElement, String childElementTag) {
NodeList childNodes = ((Node) parentElement).getChildNodes();
List<Element> childElements = new ArrayList<>();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if ((childNode.getNodeType() == 1) && (childElementTag != null)) {
Element element = (Element) childNode;
if (element.getTagName().equals(childElementTag)) {
childElements.add(element);
}
}
}
return childElements;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project liferay-ide by liferay.
the class LayoutTplUtil method findMainContentElement.
public static IDOMElement findMainContentElement(IDOMDocument rootDocument) {
if ((rootDocument == null) || !(rootDocument.hasChildNodes())) {
return null;
}
IDOMElement mainContentElement = null;
mainContentElement = (IDOMElement) rootDocument.getElementById("main-content");
return mainContentElement;
}
Aggregations