use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList 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.ITextRegionList 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();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSModelImpl method regionsReplaced.
public void regionsReplaced(RegionsReplacedEvent structuredDocumentEvent) {
if (structuredDocumentEvent == null)
return;
IStructuredDocumentRegion flatNode = structuredDocumentEvent.getStructuredDocumentRegion();
if (flatNode == null)
return;
ITextRegionList oldRegions = structuredDocumentEvent.getOldRegions();
ITextRegionList newRegions = structuredDocumentEvent.getNewRegions();
if (oldRegions == null && newRegions == null)
return;
fStructuredDocumentUpdate = true;
CSSModelParser parser = getParser();
parser.setStructuredDocumentEvent(structuredDocumentEvent);
parser.replaceRegions(flatNode, newRegions, oldRegions);
fStructuredDocumentUpdate = false;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method createRgbValue.
/**
*/
private CSSPrimitiveValueImpl createRgbValue(ITextRegionList regions) {
String funcName = getFunctionName(regions);
if (funcName == null || !funcName.toLowerCase().equals("rgb")) {
// $NON-NLS-1$
return null;
}
String[] accepts = { CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER, CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE };
ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
if (valueRegions.size() != 3) {
return null;
}
RGBColorImpl value = getRGBColor();
if (value == null) {
return null;
}
for (int i = 0; i < 3; i++) {
ITextRegion region = valueRegions.get(i);
CSSPrimitiveValueImpl childValue = null;
switch(i) {
case 0:
childValue = (CSSPrimitiveValueImpl) value.getRed();
break;
case 1:
childValue = (CSSPrimitiveValueImpl) value.getGreen();
break;
case 2:
childValue = (CSSPrimitiveValueImpl) value.getBlue();
break;
default:
break;
}
if (childValue == null) {
return null;
}
setFloatValue(childValue, getText(region), region.getType());
if (!fTempStructuredDocument) {
childValue.setRangeRegion(fParentRegion, region, region);
}
}
return value;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method getPropertyName.
/**
*/
// private String getPropertyName(IStructuredDocumentRegion flatNode) {
// Vector nodeRegions = new Vector(flatNode.getRegions());
// return getPropertyName(nodeRegions);
// }
/**
*/
private String getPropertyName(ITextRegionList nodeRegions) {
ITextRegionList nameRegions = new TextRegionListImpl();
String name = null;
while (!nodeRegions.isEmpty()) {
ITextRegion region = nodeRegions.remove(0);
if (region == null) {
continue;
}
String type = region.getType();
if (type == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
CSSUtil.stripSurroundingSpace(nameRegions);
name = makeString(nameRegions);
break;
} else {
nameRegions.add(region);
}
}
return name;
}
Aggregations