use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class ContextRegionContainer method getRegionAtCharacterOffset.
/**
* The parameter offset refers to the overall offset in the document.
*/
public ITextRegion getRegionAtCharacterOffset(int offset) {
ITextRegion result = null;
if (regions != null) {
int thisStartOffset = getStartOffset();
if (offset < thisStartOffset)
return null;
int thisEndOffset = getStartOffset() + getLength();
if (offset > thisEndOffset)
return null;
// transform the requested offset to the "scale" that
// regions are stored in, which are all relative to the
// start point.
// int transformedOffset = offset - getStartOffset();
//
ITextRegionList regions = getRegions();
int length = regions.size();
int low = 0;
int high = length;
int mid = 0;
// Binary search for the region
while (low < high) {
mid = low + ((high - low) >> 1);
ITextRegion region = regions.get(mid);
if (org.eclipse.wst.sse.core.internal.util.Debug.debugStructuredDocument) {
// $NON-NLS-1$
System.out.println("region(s) in IStructuredDocumentRegion::getRegionAtCharacterOffset: " + region);
// $NON-NLS-1$
System.out.println(" midpoint of search:" + mid);
// $NON-NLS-1$
System.out.println(" requested offset: " + offset);
// System.out.println(" transformedOffset: " +
// transformedOffset); //$NON-NLS-1$
// $NON-NLS-1$
System.out.println(" region start: " + region.getStart());
// $NON-NLS-1$
System.out.println(" region end: " + region.getEnd());
// $NON-NLS-1$
System.out.println(" region type: " + region.getType());
// $NON-NLS-1$
System.out.println(" region class: " + region.getClass());
}
// Region is before this one
if (offset < region.getStart() + thisStartOffset)
high = mid;
else if (offset > (region.getEnd() + thisStartOffset - 1))
low = mid + 1;
else
return region;
}
return null;
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class XMLSyntaxColoringPage method applyStyles.
/**
* Color the text in the sample area according to the current preferences
*/
void applyStyles() {
if (fText == null || fText.isDisposed())
return;
IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
while (documentRegion != null) {
ITextRegionList regions = documentRegion.getRegions();
for (int i = 0; i < regions.size(); i++) {
ITextRegion currentRegion = regions.get(i);
// lookup the local coloring type and apply it
String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType());
if (namedStyle == null)
continue;
TextAttribute attribute = getAttributeFor(namedStyle);
if (attribute == null)
continue;
StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0;
fText.setStyleRange(style);
}
documentRegion = documentRegion.getNext();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPActionValidator method getStartTagName.
private String getStartTagName(IStructuredDocumentRegion sdr) {
String name = new String();
ITextRegionList subRegions = sdr.getRegions();
if (subRegions.size() > 2) {
ITextRegion subRegion = subRegions.get(0);
if (subRegion.getType() == DOMRegionContext.XML_TAG_OPEN) {
subRegion = subRegions.get(1);
if (subRegion.getType() == DOMRegionContext.XML_TAG_NAME) {
name = sdr.getText(subRegion);
}
}
}
return name;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPActionValidator method hasJSPRegion.
private boolean hasJSPRegion(ITextRegion container) {
if (!(container instanceof ITextRegionContainer))
return false;
ITextRegionList regions = ((ITextRegionContainer) container).getRegions();
if (regions == null)
return false;
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_OPEN || (isNestedTagName(regionType)))
return true;
}
return false;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPValidator method getDirectiveName.
/**
* @param collection
* @return the jsp directive name
*/
protected String getDirectiveName(ITextRegionCollection collection) {
// $NON-NLS-1$
String name = "";
ITextRegionList subRegions = collection.getRegions();
for (int j = 0; j < subRegions.size(); j++) {
ITextRegion subRegion = subRegions.get(j);
if (subRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
name = collection.getText(subRegion);
break;
}
}
return name;
}
Aggregations