use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class JSONModelImpl method getIndexedRegion.
@Override
public IndexedRegion getIndexedRegion(int offset) {
if (this.document == null)
return null;
// search in document children
IJSONNode parent = null;
int length = this.document.getEndOffset();
if (offset * 2 < length) {
// search from the first
IJSONNode child = (IJSONNode) this.document.getFirstChild();
while (child != null) {
if (child.getEndOffset() <= offset) {
child = (IJSONNode) child.getNextSibling();
continue;
}
if (child.getStartOffset() > offset) {
break;
}
IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null) {
if (startStructuredDocumentRegion.getEnd() > offset)
return child;
}
IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null) {
if (endStructuredDocumentRegion.getStart() <= offset) {
if (child instanceof IJSONPair) {
IJSONValue value = ((IJSONPair) child).getValue();
if (value instanceof IJSONObject || value instanceof IJSONArray) {
if (value.getStartOffset() < offset) {
child = value;
continue;
}
}
}
return child;
}
}
// dig more
parent = child;
if (parent != null && parent.getNodeType() == IJSONNode.PAIR_NODE) {
IJSONPair pair = (IJSONPair) parent;
child = pair.getValue();
} else {
child = (IJSONNode) parent.getFirstChild();
}
}
} else {
// search from the last
IJSONNode child = (IJSONNode) this.document.getLastChild();
while (child != null) {
if (child.getStartOffset() > offset) {
child = (IJSONNode) child.getPreviousSibling();
continue;
}
if (child.getEndOffset() <= offset) {
break;
}
IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null) {
if (startStructuredDocumentRegion.getEnd() > offset)
return child;
}
IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null) {
if (endStructuredDocumentRegion.getStart() <= offset) {
if (child instanceof IJSONPair) {
IJSONValue value = ((IJSONPair) child).getValue();
if (value instanceof IJSONObject || value instanceof IJSONArray) {
if (value.getStartOffset() < offset) {
child = value;
continue;
}
}
}
return child;
}
}
// dig more
parent = child;
if (parent != null && parent.getNodeType() == IJSONNode.PAIR_NODE) {
IJSONPair pair = (IJSONPair) parent;
child = pair.getValue();
} else {
child = (IJSONNode) parent.getLastChild();
}
}
}
return parent != null ? parent : document.getFirstChild();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion 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();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class JSPActionValidator method performValidation.
protected void performValidation(IFile f, IReporter reporter, IStructuredModel model, IRegion validateRegion) {
loadPreferences(f);
IStructuredDocument sDoc = model.getStructuredDocument();
fIsELIgnored = isElIgnored(f.getFullPath(), model);
// iterate all document regions
IStructuredDocumentRegion region = sDoc.getRegionAtCharacterOffset(validateRegion.getOffset());
while (region != null && !reporter.isCancelled() && (region.getStartOffset() <= (validateRegion.getOffset() + validateRegion.getLength()))) {
if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
// only checking directives
processDirective(reporter, f, model, region);
fTaglibPrefixes.clear();
} else if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
// and jsp tags
String tagName = getStartTagName(region);
int colonPosition = tagName.indexOf(':');
if (colonPosition > -1) {
// get tag's prefix and check if it's really a jsp action
// tag
String prefix = tagName.substring(0, colonPosition);
if (getTaglibPrefixes(sDoc).contains(prefix))
processDirective(reporter, f, model, region);
}
}
region = region.getNext();
}
unloadPreferences();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class JSPReParser method isBreakingWithNestedTag.
/**
* Verifies that the regions given, representing the regions touched by a
* text change have: 1) ...an insertion at the textEndOffset of an
* XML_TAG_OPEN that's in it's own IStructuredDocumentRegion and preceded
* by an unended IStructuredDocumentRegion 2) ...a deletion happening in
* an XML_EMPTY_TAG_CLOSE that ends a ITextRegionContainer 3) ...an
* insertion happening with a ' <' character somewhere in an XML attribute
* name or value 4) ...a deletion of a normal XML_TAG_CLOSE since
* subsequent tags become attribute values
*/
private boolean isBreakingWithNestedTag(boolean changesIncludeA_lt, boolean delsIncludeA_gt, IStructuredDocumentRegion parent, ITextRegion region) {
boolean result = false;
IStructuredDocumentRegion previous = parent.getPrevious();
// case 1 test
if (parent.getRegions().size() == 1 && region.getType() == DOMRegionContext.XML_TAG_OPEN && (previous == null || (!previous.isEnded() || previous.getType() == DOMRegionContext.XML_CONTENT))) {
result = true;
}
// case 2 test
if (region instanceof ITextRegionContainer) {
ITextRegionContainer container = (ITextRegionContainer) region;
ITextRegion internal = container.getRegions().get(container.getRegions().size() - 1);
if (internal.getType() == DOMRegionContext.WHITE_SPACE && container.getRegions().size() >= 2)
internal = container.getRegions().get(container.getRegions().size() - 2);
if (internal.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
result = true;
}
}
// case 3 test
if (changesIncludeA_lt && (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) {
result = true;
}
// case 4 test
if (delsIncludeA_gt && region.getType() == DOMRegionContext.XML_TAG_CLOSE) {
result = true;
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class JSPReParser method findDirtyEnd.
protected IStructuredDocumentRegion findDirtyEnd(int end) {
IStructuredDocumentRegion result = super.findDirtyEnd(end);
// check it first.
if (isJSPEmbeddedStartOrEnd(result)) {
result = fStructuredDocument.getLastStructuredDocumentRegion();
} else {
// flatnodes needlessly.
if (result != dirtyStart) {
IStructuredDocumentRegion searchNode = dirtyStart;
do {
if (isJSPEmbeddedStartOrEnd(searchNode)) {
result = fStructuredDocument.getLastStructuredDocumentRegion();
break;
} else {
searchNode = searchNode.getNext();
}
// if we get to the current dirty end, or end of
// flatnodes, without finding JSP region then we
// don't need to check further
} while ((searchNode != result) && (searchNode != null));
}
}
// from being changed to null
if (result != null)
fStructuredDocument.setCachedDocumentRegion(result);
dirtyEnd = result;
return dirtyEnd;
}
Aggregations