use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method transferEmbeddedRegions.
/**
* The purpose of this method is to "reuse" the old container region, when
* found to be same (so same instance doesn't change). The goal is to
* "transform" the old region, so its equivelent to the newly parsed one.
*/
private void transferEmbeddedRegions(IStructuredDocumentRegion oldNode, ITextRegionContainer oldRegion, ITextRegionContainer newRegion) {
// the oldRegion should already have the right parent, since
// we got here because all's equivelent except the region
// postions have changed.
// oldRegion.setParent(newRegion.getParent());
// but we should check if there's "nested" embedded regions, and if
// so, we can just move them over. setting their parent as this old
// region.
ITextRegionList newRegionsToTransfer = newRegion.getRegions();
oldRegion.setRegions(newRegionsToTransfer);
Iterator newRegionsInOldOne = newRegionsToTransfer.iterator();
while (newRegionsInOldOne.hasNext()) {
ITextRegion newOne = (ITextRegion) newRegionsInOldOne.next();
if (isCollectionRegion(newOne)) {
// ||
// hasContainerRegions(newOne)) {
// ((ITextRegionContainer) newOne).setParent(oldRegion);
oldRegion.setRegions(newRegion.getRegions());
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class BasicStructuredDocumentRegion method getType.
/**
* Provides the type of IStructuredDocumentRegion ... not to be confused
* with type of XML node! This is subclassed, if something other than type
* of first region is desired.
*/
public String getType() {
String result = UNDEFINED;
ITextRegionList subregions = getRegions();
if (subregions != null && subregions.size() > 0) {
ITextRegion firstRegion = subregions.get(0);
if (firstRegion != null) {
result = firstRegion.getType();
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class BasicStructuredDocumentRegion method getRegionAtCharacterOffset.
/**
* The parameter offset refers to the overall offset in the document.
*/
public ITextRegion getRegionAtCharacterOffset(int offset) {
if (_getRegions() != 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 (Debug.debugStructuredDocument) {
// $NON-NLS-1$
System.out.println("region(s) in IStructuredDocumentRegion::getRegionAtCharacterOffset: " + region);
// $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;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class StructuredDocumentRegionUtil method getFirstRegionType.
/**
* Returns the type of the first region.
*/
static String getFirstRegionType(IStructuredDocumentRegion flatNode) {
if (flatNode instanceof StructuredDocumentRegionProxy) {
flatNode = ((StructuredDocumentRegionProxy) flatNode).getStructuredDocumentRegion();
}
if (flatNode == null)
return JSONRegionContexts.UNDEFINED;
ITextRegionList regions = flatNode.getRegions();
if (regions == null || regions.size() == 0)
return JSONRegionContexts.UNDEFINED;
ITextRegion region = regions.get(0);
return region.getType();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPValidator method getAttributeValueRegion.
/**
* @param sdr
* @param attrName
* @return the ITextRegion for the attribute value of the given attribute
* name, case sensitive, null if no matching attribute is found
*/
protected ITextRegion getAttributeValueRegion(ITextRegionCollection sdr, String attrName) {
ITextRegion valueRegion = null;
ITextRegionList subRegions = sdr.getRegions();
for (int i = 0; i < subRegions.size(); i++) {
ITextRegion subRegion = subRegions.get(i);
if (subRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME && sdr.getText(subRegion).equals(attrName)) {
for (int j = i; j < subRegions.size(); j++) {
subRegion = subRegions.get(j);
if (subRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
valueRegion = subRegion;
break;
}
}
break;
}
}
return valueRegion;
}
Aggregations