use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class AbstractJSONCompletionProposalComputer method getCompletionRegion.
/**
* Return the region whose content's require completion. This is something
* of a misnomer as sometimes the user wants to be prompted for contents of
* a non-existant ITextRegion, such as for enumerated attribute values
* following an '=' sign.
*/
private ITextRegion getCompletionRegion(int documentPosition, IJSONNode node) {
if (node == null) {
return null;
}
ITextRegion region = null;
int offset = documentPosition;
IStructuredDocumentRegion flatNode = null;
if (node.getNodeType() == IJSONNode.DOCUMENT_NODE) {
if (node.getStructuredDocument().getLength() == 0) {
return null;
}
ITextRegion result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
while (result == null) {
offset--;
result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
}
return result;
}
IStructuredDocumentRegion startTag = node.getStartStructuredDocumentRegion();
IStructuredDocumentRegion endTag = node.getEndStructuredDocumentRegion();
// somewhere within the Node's JSON content.
if ((startTag != null) && (startTag.getStartOffset() <= offset) && (offset < startTag.getStartOffset() + startTag.getLength())) {
flatNode = startTag;
} else if ((endTag != null) && (endTag.getStartOffset() <= offset) && (offset < endTag.getStartOffset() + endTag.getLength())) {
flatNode = endTag;
}
if (flatNode != null) {
// the offset is definitely within the start or end tag, continue
// on and find the region
region = getCompletionRegion(offset, flatNode);
} else {
// the docPosition is neither within the start nor the end, so it
// must be content
flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(offset);
// if (flatNode.contains(documentPosition)) {
if ((flatNode.getStartOffset() <= documentPosition) && (flatNode.getEndOffset() >= documentPosition)) {
// we're interesting in completing/extending the previous
// IStructuredDocumentRegion if the current
// IStructuredDocumentRegion isn't plain content or if it's
// preceded by an orphan '<'
/*
* if ((offset == flatNode.getStartOffset()) &&
* (flatNode.getPrevious() != null) && (((flatNode
* .getRegionAtCharacterOffset(documentPosition) != null)) ||
* (flatNode.getPrevious().getLastRegion() .getType() ==
* JSONRegionContext.JSON_TAG_OPEN) || (flatNode
* .getPrevious().getLastRegion().getType() ==
* JSONRegionContext.JSON_END_TAG_OPEN))) {
*
* // Is the region also the start of the node? If so, the //
* previous IStructuredDocumentRegion is // where to look for a
* useful region. region =
* flatNode.getPrevious().getLastRegion(); } else if
* (flatNode.getEndOffset() == documentPosition) { region =
* flatNode.getLastRegion(); } else { region =
* flatNode.getFirstRegion(); }
*/
region = flatNode.getFirstRegion();
} else {
// catch end of document positions where the docPosition isn't
// in a IStructuredDocumentRegion
region = flatNode.getLastRegion();
}
}
return region;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class AbstractJSONCompletionProposalComputer method computeCompletionProposals.
/**
* <p>
* This does all the magic of figuring out where in the JSON type document
* the content assist was invoked and then calling the corresponding method
* to add the correct proposals
* </p>
*
* <p>
* <b>NOTE: </b>if overriding be sure to make super call back to this method
* otherwise you will loose all of the proposals generated by this method
* </p>
*
* @param matchString
* @param completionRegion
* @param treeNode
* @param xmlnode
* @param context
*
* @return {@link ContentAssistRequest} that now has all the proposals in it
*/
protected ContentAssistRequest computeCompletionProposals(String matchString, ITextRegion completionRegion, IJSONNode treeNode, IJSONNode xmlnode, CompletionProposalInvocationContext context) {
int documentPosition = context.getInvocationOffset();
ContentAssistRequest contentAssistRequest = null;
String regionType = completionRegion != null ? completionRegion.getType() : EMPTY;
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
// Handle the most common and best supported cases
if (xmlnode != null) {
if (xmlnode.getNodeType() == IJSONNode.DOCUMENT_NODE || xmlnode.getNodeType() == IJSONNode.OBJECT_NODE) {
if (treeNode.getNodeType() == IJSONNode.OBJECT_NODE) {
if (regionType == JSONRegionContexts.JSON_OBJECT_OPEN || regionType == JSONRegionContexts.JSON_OBJECT_CLOSE || regionType == JSONRegionContexts.JSON_OBJECT_KEY || regionType == JSONRegionContexts.JSON_COMMA || regionType == JSONRegionContexts.JSON_UNKNOWN) {
contentAssistRequest = computeObjectKeyProposals(matchString, completionRegion, treeNode, xmlnode, context);
}
} else if ((treeNode.getNodeType() == IJSONNode.PAIR_NODE)) {
if (regionType == JSONRegionContexts.JSON_OBJECT_KEY || regionType == JSONRegionContexts.JSON_OBJECT_OPEN || regionType == JSONRegionContexts.JSON_OBJECT_CLOSE || regionType == JSONRegionContexts.JSON_ARRAY_OPEN || regionType == JSONRegionContexts.JSON_ARRAY_CLOSE || regionType == JSONRegionContexts.JSON_COMMA || regionType == JSONRegionContexts.JSON_VALUE_BOOLEAN || regionType == JSONRegionContexts.JSON_UNKNOWN || regionType == JSONRegionContexts.JSON_COLON || regionType == JSONRegionContexts.JSON_VALUE_STRING) {
contentAssistRequest = computeObjectKeyProposals(matchString, completionRegion, treeNode, xmlnode, context);
}
}
}
}
return contentAssistRequest;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class JSONUtil method findNextSignificantNode.
/**
*/
public static IStructuredDocumentRegion findNextSignificantNode(IStructuredDocumentRegion startNode) {
if (startNode == null) {
return null;
}
IStructuredDocumentRegion node = startNode.getNext();
while (node != null) {
String type = getStructuredDocumentRegionType(node);
/*
* if (type != JSONRegionContexts.JSON_S && type !=
* JSONRegionContexts.JSON_COMMENT && type !=
* JSONRegionContexts.JSON_CDO && type !=
* JSONRegionContexts.JSON_CDC) { return node; }
*/
node = node.getNext();
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSModelParser method getStructuredDocumentRegionList.
/**
*/
private IStructuredDocumentRegionList getStructuredDocumentRegionList(int start, int end) {
IStructuredDocumentRegionList nodeList = null;
if (0 <= start && start <= end) {
ICSSModel model = fDocument.getModel();
if (model instanceof CSSModelImpl) {
IStructuredDocument structuredDocument = ((CSSModelImpl) model).getStructuredDocument();
if (structuredDocument != null) {
IStructuredDocumentRegion startNode = structuredDocument.getRegionAtCharacterOffset(start);
IStructuredDocumentRegion endNode = structuredDocument.getRegionAtCharacterOffset(end - 1);
if (startNode != null && endNode != null) {
nodeList = new CoreNodeList(startNode, endNode);
}
}
}
}
return nodeList;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertBraceOpen.
/**
*/
private CSSNodeImpl insertBraceOpen(IStructuredDocumentRegion region) {
IStructuredDocumentRegion keyRegion = CSSUtil.findPreviousSignificantNode(region);
if (keyRegion == null) {
return null;
}
if (!fParseFloating) {
CSSNodeImpl node = getNodeAt(keyRegion.getStartOffset());
if (node != null && !(node instanceof ICSSRuleContainer)) {
return null;
}
}
String type = CSSUtil.getStructuredDocumentRegionType(keyRegion);
CSSNodeImpl inserted = null;
if (type == CSSRegionContexts.CSS_PAGE) {
inserted = insertPageRule(keyRegion, region);
} else if (type == CSSRegionContexts.CSS_MEDIA) {
inserted = insertMediaRule(keyRegion, region);
} else if (type == CSSRegionContexts.CSS_FONT_FACE) {
inserted = insertFontFaceRule(keyRegion, region);
} else if (CSSUtil.isSelectorText(keyRegion)) {
inserted = insertStyleRule(keyRegion, region);
}
if (inserted instanceof CSSStructuredDocumentRegionContainer) {
// CSSModelUtil.expandStructuredDocumentRegionContainer((CSSStructuredDocumentRegionContainer)inserted,
// flatNode);
IStructuredDocumentRegion braceClose = findBraceClose(CSSModelUtil.getDepth(inserted), region, (type == CSSRegionContexts.CSS_MEDIA));
if (braceClose != null) {
fCreationContext.setReparseStart(region.getEnd());
fCreationContext.setReparseEnd(braceClose.getEnd());
}
}
return inserted;
}
Aggregations