use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method replaceStructuredDocumentRegions.
/**
* Preparation of applying changes from CSS sub-model to HTML model
*/
private void replaceStructuredDocumentRegions(IStructuredDocumentRegionList newStructuredDocumentRegions, IStructuredDocumentRegionList oldStructuredDocumentRegions) {
int offset = 0;
int length = 0;
if (oldStructuredDocumentRegions != null) {
int count = oldStructuredDocumentRegions.getLength();
if (count > 0) {
IStructuredDocumentRegion first = oldStructuredDocumentRegions.item(0);
if (first != null)
offset = first.getStart();
IStructuredDocumentRegion last = oldStructuredDocumentRegions.item(count - 1);
if (last != null)
length = last.getEnd() - offset;
}
}
String data = null;
if (newStructuredDocumentRegions != null) {
int count = newStructuredDocumentRegions.getLength();
if (count > 0) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < count; i++) {
IStructuredDocumentRegion flatNode = newStructuredDocumentRegions.item(i);
if (flatNode == null)
continue;
buffer.append(flatNode.getText());
if (i == 0)
offset = flatNode.getStart();
}
data = buffer.toString();
}
}
replaceData(offset, length, data);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method regionsReplaced.
/**
* Implementing IStructuredDocumentListener's method
* Event from CSS Flat Model
*/
public void regionsReplaced(RegionsReplacedEvent event) {
if (event == null)
return;
if (event.getOriginalRequester() == getRequesterH2C())
return;
IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
if (flatNode == null)
return;
changeStructuredDocumentRegion(flatNode);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class HTMLElementFormatter method formatEndTag.
/**
*/
private void formatEndTag(IDOMElement element, HTMLFormatContraints contraints) {
Node lastChild = element.getLastChild();
if (lastChild != null && lastChild instanceof IDOMElement && lastChild.getNodeName().equals("jsp:scriptlet")) {
// $NON-NLS-1$
insertBreakAfter((IDOMElement) lastChild, contraints);
return;
}
IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion == null)
return;
if (element.isJSPTag() || element.isCommentTag()) {
String endTag = endStructuredDocumentRegion.getText();
if (endTag != null && endTag.length() > 0) {
setWidth(contraints, endTag);
}
return;
}
ITextRegion prevRegion = null;
ITextRegionList regions = endStructuredDocumentRegion.getRegions();
Iterator e = regions.iterator();
while (e.hasNext()) {
ITextRegion region = (ITextRegion) e.next();
if (region == null)
continue;
String regionType = region.getType();
if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTag(regionType)) {
if (prevRegion != null && prevRegion.getType() == DOMRegionContext.XML_END_TAG_OPEN) {
removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
}
} else if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
if (prevRegion != null && (prevRegion.getType() == DOMRegionContext.XML_TAG_NAME || isNestedRootTag(prevRegion.getType()))) {
removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
}
}
prevRegion = region;
}
if (prevRegion != null && (prevRegion.getType() == DOMRegionContext.XML_TAG_NAME || isNestedRootTag(prevRegion.getType()))) {
removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
}
// BUG123890 (end tag length was already prefactored into
// formatStartTag so no need to do it here)
// String newEndTag = endStructuredDocumentRegion.getText();
// if (newEndTag != null && newEndTag.length() > 0) {
// setWidth(contraints, newEndTag);
// }
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class HTMLTextFormatter method canFormatText.
/**
*/
private boolean canFormatText(IDOMText text) {
if (text == null)
return false;
IStructuredDocumentRegion flatNode = text.getFirstStructuredDocumentRegion();
if (flatNode != null) {
String type = flatNode.getType();
if (isUnparsedRegion(type))
return false;
}
Node parent = text.getParentNode();
if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
IDOMElement element = (IDOMElement) parent;
if (!element.isGlobalTag() && !text.isElementContentWhitespace())
return false;
}
return canFormatChild(parent);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class TEIValidation method testCustomTagInAttribute.
public void testCustomTagInAttribute() throws Exception {
// $NON-NLS-1$
final String path = "/" + PROJECT_NAME + "/WebContent/test.jsp";
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
try {
assertTrue("Not an IDOMModel", model instanceof IDOMModel);
NodeList divs = ((IDOMModel) model).getDocument().getElementsByTagName("div");
assertTrue("Missing a div", divs.getLength() > 0);
IDOMNode node = (IDOMNode) divs.item(0);
IStructuredDocumentRegion region = node.getStartStructuredDocumentRegion();
ITextRegionList regions = region.getRegions();
assertTrue(regions.size() > 2);
/* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
/* JSPJavaTranslatorCoreTest.waitForBuildAndValidation(getProject()); */
final TaglibHelper helper = new TaglibHelper(getProject());
final List problems = new ArrayList();
final IStructuredDocument document = model.getStructuredDocument();
ITextRegion embedded = regions.get(2);
assertTrue("Not a container region", embedded instanceof ITextRegionContainer);
helper.getCustomTag("test:foo", document, (ITextRegionContainer) embedded, problems);
/* assertEquals("No problems should be generated", 0, problems.size()); */
} finally {
if (model != null)
model.releaseFromRead();
}
}
Aggregations