use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection in project webtools.sourceediting by eclipse.
the class JSPDirectiveValidator method performValidation.
protected void performValidation(IFile f, IReporter reporter, IStructuredDocument sDoc) {
loadPreferences(f);
setProject(f.getProject());
/*
* when validating an entire file need to clear dupes or else you're
* comparing between files
*/
fPrefixValueRegionToDocumentRegionMap.clear();
fTaglibPrefixesInUse.clear();
fAttributeNamesInUse.clear();
IRegionComparible comparer = null;
if (sDoc instanceof IRegionComparible)
comparer = (IRegionComparible) sDoc;
// iterate all document regions
IStructuredDocumentRegion region = sDoc.getFirstStructuredDocumentRegion();
while (region != null && !reporter.isCancelled()) {
// only checking directives
if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
processDirective(reporter, f, sDoc, region);
} else // To check directives inside script tag.
if (region.getType() == DOMRegionContext.BLOCK_TEXT) {
Iterator it = region.getRegions().iterator();
while (it.hasNext()) {
Object blockRegion = it.next();
if (blockRegion instanceof ITextRegionCollection) {
processDirective(reporter, f, sDoc, (ITextRegionCollection) blockRegion);
}
}
} else // requires tag name, attribute, equals, and value
if (comparer != null && region.getNumberOfRegions() > 4) {
ITextRegion nameRegion = region.getRegions().get(1);
if (comparer.regionMatches(region.getStartOffset(nameRegion), nameRegion.getTextLength(), "jsp:include")) {
// $NON-NLS-1$
processInclude(reporter, f, sDoc, region, JSP11Namespace.ATTR_NAME_PAGE);
} else // https://bugs.eclipse.org/bugs/show_bug.cgi?id=295950
if (comparer.regionMatches(region.getStartOffset(nameRegion), 14, "jsp:directive.")) {
// $NON-NLS-1$
processDirective(reporter, f, sDoc, region);
}
}
region = region.getNext();
}
if (!reporter.isCancelled()) {
reportTaglibDuplicatePrefixes(f, reporter, sDoc);
}
fPrefixValueRegionToDocumentRegionMap.clear();
fTaglibPrefixesInUse.clear();
fAttributeNamesInUse.clear();
setProject(null);
unloadPreferences();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection in project webtools.sourceediting by eclipse.
the class ScannerUnitTests method testDirectiveInTagBody.
public void testDirectiveInTagBody() {
String text = "<BODY <%@ include file=\"commonEventHandlers.jspf\" %> dir=\"ltr\"> ";
IStructuredDocumentRegionList documentRegionList = setUpJSP(text);
verifyLengths(0, documentRegionList, text);
checkSimpleRegionTypes(documentRegionList.item(0).getRegions(), new String[] { DOMRegionContext.XML_TAG_OPEN, DOMRegionContext.XML_TAG_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS, DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, DOMRegionContext.XML_TAG_CLOSE });
ITextRegionCollection coll = (ITextRegionCollection) documentRegionList.item(0).getRegions().get(2);
checkSimpleRegionTypes(coll.getRegions(), new String[] { DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN, DOMRegionContext.WHITE_SPACE, DOMJSPRegionContexts.JSP_DIRECTIVE_NAME, DOMRegionContext.WHITE_SPACE, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS, DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, DOMRegionContext.WHITE_SPACE, DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE });
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection in project webtools.sourceediting by eclipse.
the class AbstractLineStyleProvider method prepareTextRegions.
private boolean prepareTextRegions(IStructuredDocumentRegion structuredDocumentRegion, int partitionStartOffset, int partitionLength, Collection holdResults) {
boolean handled = false;
final int partitionEndOffset = partitionStartOffset + partitionLength - 1;
while (structuredDocumentRegion != null && structuredDocumentRegion.getStartOffset() <= partitionEndOffset) {
ITextRegion region = null;
ITextRegionList regions = structuredDocumentRegion.getRegions();
int nRegions = regions.size();
StyleRange styleRange = null;
for (int i = 0; i < nRegions; i++) {
region = regions.get(i);
TextAttribute attr = null;
TextAttribute previousAttr = null;
if (structuredDocumentRegion.getStartOffset(region) > partitionEndOffset)
break;
if (structuredDocumentRegion.getEndOffset(region) <= partitionStartOffset)
continue;
if (region instanceof ITextRegionCollection) {
boolean handledCollection = (prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults));
handled = (!handled) ? handledCollection : handled;
} else {
attr = getAttributeFor(structuredDocumentRegion, region);
if (attr != null) {
handled = true;
// regions correctly
if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) {
styleRange.length += region.getLength();
} else {
styleRange = createStyleRange(structuredDocumentRegion, region, attr, partitionStartOffset, partitionLength);
holdResults.add(styleRange);
// technically speaking, we don't need to update
// previousAttr
// in the other case, because the other case is
// when it hasn't changed
previousAttr = attr;
}
} else {
previousAttr = null;
}
}
if (Debug.syntaxHighlighting && !handled) {
// $NON-NLS-1$
System.out.println("not handled in prepareRegions");
}
}
structuredDocumentRegion = structuredDocumentRegion.getNext();
}
return handled;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection in project webtools.sourceediting by eclipse.
the class Debug method dump.
public static final void dump(IStructuredDocument structuredDocument, boolean verbose) {
ITextRegionCollection flatNode = null;
// $NON-NLS-1$
System.out.println("Dump of structuredDocument:");
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
Enumeration<?> structuredDocumentRegions = flatNodes.elements();
while (structuredDocumentRegions.hasMoreElements()) {
flatNode = (ITextRegionCollection) structuredDocumentRegions.nextElement();
if (!verbose) {
String outString = flatNode.toString();
outString = org.eclipse.wst.sse.core.utils.StringUtils.escape(outString);
System.out.println(outString);
} else {
dump(flatNode, verbose);
}
}
System.out.println();
// $NON-NLS-1$
System.out.println("= = = = = =");
System.out.println();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method checkAndAssignParent.
private void checkAndAssignParent(IStructuredDocumentRegion oldNode, ITextRegion region) {
if (region instanceof ITextRegionContainer) {
((ITextRegionContainer) region).setParent(oldNode);
return;
}
if (region instanceof ITextRegionCollection) {
ITextRegionCollection textRegionCollection = (ITextRegionCollection) region;
ITextRegionList regionList = textRegionCollection.getRegions();
for (int i = 0; i < regionList.size(); i++) {
ITextRegion innerRegion = regionList.get(i);
checkAndAssignParent(oldNode, innerRegion);
}
}
}
Aggregations