use of org.eclipse.wst.sse.core.internal.text.IRegionComparible 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.text.IRegionComparible in project webtools.sourceediting by eclipse.
the class StructuredTextPartitionerForHTML method isAttributeNameForValueInArray.
/**
* <p>determines if the attribute name associated with the given attribute region
* is in the given array of attribute names</p>
*
* @param attributeNames determine if the attribute name associated with the given offset
* is in this array of attribute names
* @param attrValueRegion {@link ITextRegion} of the attribute region containing the given offset
* @param offset offset in an attribute region to determine if it is in the list of given attribute names
* @return <code>true</code> if the attribute name associated with the given offset is in the given
* list of attribute names, <code>false</code> otherwise
*/
private boolean isAttributeNameForValueInArray(String[] attributeNames, ITextRegion attrValueRegion, int offset) {
IStructuredDocumentRegion node = fStructuredDocument.getRegionAtCharacterOffset(offset);
ITextRegionList regionList = node.getRegions();
int currentIndex = regionList.indexOf(attrValueRegion);
/*
* 4 is the minimum index allowing for the tag's open, name, attribute
* name and equals character to appear first
*/
if (currentIndex < 4)
return false;
ITextRegion tagAttrNameRegion = regionList.get(currentIndex - 2);
boolean foundAttributeName = false;
if (fStructuredDocument instanceof IRegionComparible) {
int start = node.getStartOffset(tagAttrNameRegion);
for (int i = 0; !foundAttributeName && i < attributeNames.length; i++) {
foundAttributeName = ((IRegionComparible) fStructuredDocument).regionMatchesIgnoreCase(start, tagAttrNameRegion.getTextLength(), attributeNames[i]);
}
} else {
String tagAttrName = node.getText(tagAttrNameRegion);
foundAttributeName = StringUtils.contains(attributeNames, tagAttrName, false);
}
return foundAttributeName;
}
Aggregations