use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkNoNamespaceInPI.
private void checkNoNamespaceInPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
if (structuredDocumentRegion.isDeleted()) {
return;
}
// navigate to name
ITextRegionList regions = structuredDocumentRegion.getRegions();
ITextRegion r = null;
int errorCount = 0;
for (int i = 0; (i < regions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
String piText = structuredDocumentRegion.getText(r);
// $NON-NLS-1$
int index = piText.indexOf(":");
if (index != -1) {
String messageText = XMLUIMessages.ReconcileStepForMarkup_4;
int start = structuredDocumentRegion.getStartOffset(r) + index;
int length = piText.trim().length() - index;
LocalizedMessage message = new LocalizedMessage(SEVERITY_NAMESPACE_IN_PI_TARGET, messageText);
message.setOffset(start);
message.setLength(length);
message.setLineNo(getLineNumber(start));
if (reporter instanceof IncrementalReporter) {
MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
processor.setProblemId(ProblemIDsXML.NamespaceInPI);
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
reporter.addMessage(this, message);
}
errorCount++;
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkAttributesInEndTag.
private void checkAttributesInEndTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
if (structuredDocumentRegion.isDeleted()) {
return;
}
ITextRegionList textRegions = structuredDocumentRegion.getRegions();
int errorCount = 0;
int start = structuredDocumentRegion.getEndOffset();
int end = structuredDocumentRegion.getEndOffset();
for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) {
ITextRegion textRegion = textRegions.get(i);
if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) {
if (start > structuredDocumentRegion.getStartOffset(textRegion)) {
start = structuredDocumentRegion.getStartOffset(textRegion);
}
end = structuredDocumentRegion.getEndOffset(textRegion);
errorCount++;
}
}
// create one error for all attributes in the end tag
if (errorCount > 0) {
// Position p = new Position(start, end - start);
String messageText = XMLUIMessages.End_tag_has_attributes;
LocalizedMessage message = new LocalizedMessage(SEVERITY_END_TAG_WITH_ATTRIBUTES, messageText);
message.setOffset(start);
message.setLength(end - start);
message.setLineNo(getLineNumber(start));
if (reporter instanceof IncrementalReporter) {
MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
processor.setProblemId(ProblemIDsXML.AttrsInEndTag);
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
reporter.addMessage(this, message);
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class DOMModelImpl method regionsReplaced.
/**
* regionsReplaced method
*
* @param event
*/
public void regionsReplaced(RegionsReplacedEvent event) {
if (event == null)
return;
IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
if (flatNode == null)
return;
ITextRegionList oldRegions = event.getOldRegions();
ITextRegionList newRegions = event.getNewRegions();
if (oldRegions == null && newRegions == null)
return;
XMLModelUpdater updater = getActiveUpdater();
if (updater != null) {
// being updated
try {
updater.replaceRegions(flatNode, newRegions, oldRegions);
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
}
// checkForReinit();
return;
}
XMLModelNotifier notifier = getModelNotifier();
boolean isChanging = notifier.isChanging();
if (!isChanging)
notifier.beginChanging();
XMLModelParser parser = getModelParser();
setActive(parser);
try {
parser.replaceRegions(flatNode, newRegions, oldRegions);
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
if (!isChanging) {
notifier.endChanging();
handleRefresh();
}
}
// checkForReinit();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method compressEmptyElementTag.
private IDOMNode compressEmptyElementTag(IDOMNode node) {
boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags();
IDOMNode newNode = node;
IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion();
IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion();
if (compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && startTagStructuredDocumentRegion != null) {
ITextRegionList regions = startTagStructuredDocumentRegion.getRegions();
ITextRegion lastRegion = regions.get(regions.size() - 1);
// format children and end tag if not empty element tag
if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
NodeList childNodes = newNode.getChildNodes();
if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) {
IDOMModel structuredModel = newNode.getModel();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
int startTagStartOffset = newNode.getStartOffset();
int offset = endTagStructuredDocumentRegion.getStart();
int length = endTagStructuredDocumentRegion.getLength();
// $NON-NLS-1$
structuredDocument.replaceText(structuredDocument, offset, length, "");
// save
newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart();
// $NON-NLS-1$
structuredDocument.replaceText(structuredDocument, offset, 0, "/");
// save
newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
}
}
}
return newNode;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class XMLModelParser method insertComment.
/**
* insertComment method
*/
private void insertComment(IStructuredDocumentRegion flatNode) {
ITextRegionList regions = flatNode.getRegions();
if (regions == null)
return;
StringBuffer data = null;
boolean isJSPTag = false;
Iterator e = regions.iterator();
while (e.hasNext()) {
ITextRegion region = (ITextRegion) e.next();
String regionType = region.getType();
if (isNestedCommentOpen(regionType)) {
isJSPTag = true;
} else if (regionType == DOMRegionContext.XML_COMMENT_TEXT || isNestedCommentText(regionType)) {
if (data == null) {
data = new StringBuffer(flatNode.getText(region));
} else {
data.append(flatNode.getText(region));
}
}
}
if (data != null) {
ElementImpl element = (ElementImpl) createCommentElement(data.toString(), isJSPTag);
if (element != null) {
if (!isEndTag(element)) {
element.setStartStructuredDocumentRegion(flatNode);
insertStartTag(element);
return;
}
// end tag
element.setEndStructuredDocumentRegion(flatNode);
String tagName = element.getTagName();
String rootName = getFindRootName(tagName);
ElementImpl start = (ElementImpl) this.context.findStartTag(tagName, rootName);
if (start != null) {
// start tag found
insertEndTag(start);
start.addEndTag(element);
return;
}
// invalid end tag
insertNode(element);
return;
}
}
CommentImpl comment = (CommentImpl) this.model.getDocument().createComment(null);
if (comment == null)
return;
if (isJSPTag)
comment.setJSPTag(true);
comment.setStructuredDocumentRegion(flatNode);
insertNode(comment);
}
Aggregations