use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class Debug method printChildRegions.
private static void printChildRegions(ITextRegionCollection region, int depth) {
if (region != null) {
// ==> // ITextRegionCollection regionCollection = region;
System.out.println(region);
ITextRegionList regionList = region.getRegions();
for (int i = 0; i < regionList.size(); i++) {
ITextRegion r = regionList.get(i);
if (r instanceof ITextRegionCollection) {
ITextRegionCollection rc = (ITextRegionCollection) r;
printChildRegions(rc, depth++);
} else {
System.out.println(space(depth) + r);
depth--;
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkStartEndTagPairs.
private void checkStartEndTagPairs(IStructuredDocumentRegion sdRegion, IReporter reporter) {
if (sdRegion.isDeleted()) {
return;
}
// check start/end tag pairs
IDOMNode xmlNode = getXMLNode(sdRegion);
if (xmlNode == null) {
return;
}
boolean selfClosed = false;
String tagName = null;
/**
* For tags that aren't meant to be EMPTY, make sure it's empty or has an end tag
*/
if (xmlNode.isContainer()) {
IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
if (endRegion == null) {
IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
if (startRegion != null && !startRegion.isDeleted() && DOMRegionContext.XML_TAG_OPEN.equals(startRegion.getFirstRegion().getType())) {
// analyze the tag (check self closing)
ITextRegionList regions = startRegion.getRegions();
ITextRegion r = null;
int start = sdRegion.getStart();
int length = sdRegion.getTextLength();
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
tagName = sdRegion.getText(r);
start = sdRegion.getStartOffset(r);
length = r.getTextLength();
} else if (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
selfClosed = true;
}
}
if (!selfClosed && (tagName != null)) {
Object[] args = { tagName };
String messageText = NLS.bind(XMLCoreMessages.Missing_end_tag_, args);
int lineNumber = getLineNumber(start);
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_END_TAG), messageText);
message.setOffset(start);
message.setLength(length);
message.setLineNo(lineNumber);
Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
getAnnotationMsg(reporter, ProblemIDsXML.MissingEndTag, message, additionalFixInfo, length);
}
}
} else {
IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
if (startRegion == null || startRegion.isDeleted()) {
// analyze the tag (check self closing)
ITextRegionList regions = endRegion.getRegions();
ITextRegion r = null;
int start = sdRegion.getStart();
int length = sdRegion.getTextLength();
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
tagName = sdRegion.getText(r);
start = sdRegion.getStartOffset(r);
length = r.getTextLength();
}
}
if (tagName != null) {
Object[] args = { tagName };
String messageText = NLS.bind(XMLCoreMessages.Missing_start_tag_, args);
int lineNumber = getLineNumber(start);
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_START_TAG), messageText);
message.setOffset(start);
message.setLength(length);
message.setLineNo(lineNumber);
Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
getAnnotationMsg(reporter, ProblemIDsXML.MissingStartTag, message, additionalFixInfo, length);
}
}
}
} else /*
* Check for an end tag that has no start tag
*/
{
IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
if (startRegion == null) {
IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
if (!endRegion.isDeleted()) {
// get name
ITextRegionList regions = endRegion.getRegions();
ITextRegion r = null;
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
tagName = sdRegion.getText(r);
}
}
if (!selfClosed && (tagName != null)) {
String messageText = XMLCoreMessages.Indicate_no_grammar_specified_severities_error;
int start = sdRegion.getStart();
int lineNumber = getLineNumber(start);
// SEVERITY_STRUCTURE == IMessage.HIGH_SEVERITY
IMessage message = new LocalizedMessage(IMessage.HIGH_SEVERITY, messageText);
message.setOffset(start);
message.setLength(sdRegion.getTextLength());
message.setLineNo(lineNumber);
reporter.addMessage(this, message);
}
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkForAttributeValue.
private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
if (structuredDocumentRegion.isDeleted()) {
return;
}
// check for attributes without a value
// track the attribute/equals/value sequence using a state of 0, 1 ,2
// representing the name, =, and value, respectively
int attrState = 0;
ITextRegionList textRegions = structuredDocumentRegion.getRegions();
// ReconcileAnnotationKey key = createKey(structuredDocumentRegion,
// getScope());
int errorCount = 0;
for (int i = 0; (i < textRegions.size()) && (errorCount < ELEMENT_ERROR_LIMIT); i++) {
ITextRegion textRegion = textRegions.get(i);
if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) {
// dangling name and '='
if ((attrState == 2) && (i >= 2)) {
// create annotation
ITextRegion nameRegion = textRegions.get(i - 2);
if (!(nameRegion instanceof ITextRegionContainer)) {
Object[] args = { structuredDocumentRegion.getText(nameRegion) };
String messageText = NLS.bind(XMLCoreMessages.Attribute__is_missing_a_value, args);
int start = structuredDocumentRegion.getStartOffset(nameRegion);
int end = structuredDocumentRegion.getEndOffset();
int lineNo = getLineNumber(start);
int textLength = structuredDocumentRegion.getText(nameRegion).trim().length();
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
message.setOffset(start);
message.setLength(textLength);
message.setLineNo(lineNo);
// quick fix info
ITextRegion equalsRegion = textRegions.get(i - 2 + 1);
int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end;
Object[] additionalFixInfo = { structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset) };
getAnnotationMsg(reporter, ProblemIDsXML.MissingAttrValue, message, additionalFixInfo, textLength);
errorCount++;
}
} else // name but no '=' (XML only)
if ((attrState == 1) && (i >= 1)) {
// create annotation
ITextRegion previousRegion = textRegions.get(i - 1);
if (!(previousRegion instanceof ITextRegionContainer)) {
Object[] args = { structuredDocumentRegion.getText(previousRegion) };
String messageText = NLS.bind(XMLCoreMessages.Attribute__has_no_value, args);
int start = structuredDocumentRegion.getStartOffset(previousRegion);
int textLength = structuredDocumentRegion.getText(previousRegion).trim().length();
int lineNo = getLineNumber(start);
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
message.setOffset(start);
message.setLength(textLength);
message.setLineNo(lineNo);
getAnnotationMsg(reporter, ProblemIDsXML.NoAttrValue, message, structuredDocumentRegion.getText(previousRegion), textLength);
errorCount++;
}
}
attrState = 1;
} else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
attrState = 2;
} else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
attrState = 0;
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class XMLModelParser method insertDecl.
/**
* insertDecl method
*/
private void insertDecl(IStructuredDocumentRegion flatNode) {
ITextRegionList regions = flatNode.getRegions();
if (regions == null)
return;
boolean isDocType = false;
String name = null;
String publicId = null;
String systemId = null;
Iterator e = regions.iterator();
while (e.hasNext()) {
ITextRegion region = (ITextRegion) e.next();
String regionType = region.getType();
if (regionType == DOMRegionContext.XML_DOCTYPE_DECLARATION) {
isDocType = true;
} else if (regionType == DOMRegionContext.XML_DOCTYPE_NAME) {
if (name == null)
name = flatNode.getText(region);
} else if (regionType == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF) {
if (publicId == null)
publicId = StructuredDocumentRegionUtil.getAttrValue(flatNode, region);
} else if (regionType == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF) {
if (systemId == null)
systemId = StructuredDocumentRegionUtil.getAttrValue(flatNode, region);
}
}
// invalid declaration
if (!isDocType) {
insertInvalidDecl(flatNode);
return;
}
DocumentTypeImpl docType = (DocumentTypeImpl) this.model.getDocument().createDoctype(name);
if (docType == null)
return;
if (publicId != null)
docType.setPublicId(publicId);
if (systemId != null)
docType.setSystemId(systemId);
docType.setStructuredDocumentRegion(flatNode);
insertNode(docType);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class XMLModelParser method insertEndTag.
/**
* insertEndTag method
*/
private void insertEndTag(IStructuredDocumentRegion flatNode) {
ITextRegionList regions = flatNode.getRegions();
if (regions == null)
return;
String tagName = null;
Iterator e = regions.iterator();
while (e.hasNext()) {
ITextRegion region = (ITextRegion) e.next();
String regionType = region.getType();
if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
if (tagName == null)
tagName = flatNode.getText(region);
}
}
if (tagName == null) {
// invalid end tag
// regard as invalid text
insertText(flatNode);
return;
}
String rootName = getFindRootName(tagName);
ElementImpl start = (ElementImpl) this.context.findStartTag(tagName, rootName);
if (start != null) {
// start tag found
insertEndTag(start);
start.setEndStructuredDocumentRegion(flatNode);
return;
}
// invalid end tag
ElementImpl end = null;
try {
end = (ElementImpl) this.model.getDocument().createElement(tagName);
} catch (DOMException ex) {
}
if (end == null) {
// invalid end tag
// regard as invalid text
insertText(flatNode);
return;
}
end.setEndStructuredDocumentRegion(flatNode);
insertNode(end);
}
Aggregations