use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class BasicStructuredDocumentRegion method updateDownStreamRegions.
private void updateDownStreamRegions(ITextRegion changedRegion, int lengthDifference) {
int listLength = _getRegions().size();
int startIndex = 0;
// first, loop through to find index of where to start
for (int i = 0; i < listLength; i++) {
ITextRegion region = _getRegions().get(i);
if (region == changedRegion) {
startIndex = i;
break;
}
}
// now, beginning one past the one that was changed, loop
// through to end of list, adjusting the start postions.
startIndex++;
for (int j = startIndex; j < listLength; j++) {
ITextRegion region = _getRegions().get(j);
region.adjustStart(lengthDifference);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion 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.ITextRegion 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.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPIncludeRegionHelper method getRegionName.
// different btwn XML-JSP and JSP tags
protected String getRegionName(IStructuredDocumentRegion sdRegion) {
ITextRegion nameRegion = null;
// $NON-NLS-1$
String nameStr = "";
int size = sdRegion.getRegions().size();
if (size > 1) {
// presumably XML-JSP <jsp:scriptlet> | <jsp:expression> | <jsp:declaration>
nameRegion = sdRegion.getRegions().get(1);
} else if (size == 1) {
// presumably JSP open <% | <%= | <%!
nameRegion = sdRegion.getRegions().get(0);
}
if (nameRegion != null)
nameStr = fTextToParse.substring(sdRegion.getStartOffset(nameRegion), sdRegion.getTextEndOffset(nameRegion));
return nameStr.trim();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSONModelImpl method regionChanged.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.core.internal.provisional.events.
* IStructuredDocumentListener
* #regionChanged(org.eclipse.wst.sse.core.internal
* .provisional.events.RegionChangedEvent)
*/
@Override
public void regionChanged(RegionChangedEvent event) {
if (event == null)
return;
IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
if (flatNode == null)
return;
ITextRegion region = event.getRegion();
if (region == null)
return;
JSONModelUpdater updater = getActiveUpdater();
if (updater != null) {
// being updated
try {
updater.changeRegion(event, flatNode, region);
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
}
// checkForReinit();
return;
}
JSONModelNotifier notifier = getModelNotifier();
boolean isChanging = notifier.isChanging();
if (!isChanging)
notifier.beginChanging();
JSONModelParser parser = getModelParser();
setActive(parser);
try {
parser.changeRegion(event, flatNode, region);
/* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=486860 */
// this.refresh = true;
// handleRefresh();
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
if (!isChanging) {
notifier.endChanging();
handleRefresh();
}
}
// checkForReinit();
}
Aggregations