use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project liferay-ide by liferay.
the class AlloyStructuredTextPartitionerForJSP method _isAUIScriptRegion.
private boolean _isAUIScriptRegion(IStructuredDocumentRegion sdRegion) {
/*
* TODO can this handle content with other regions like
* <aui:script> function foo() {}; <portletTag/> function bar(){}</aui:script>
*/
IStructuredDocumentRegion previousRegion = sdRegion.getPrevious();
if (previousRegion == null) {
return false;
}
String info = previousRegion.toString();
if ((sdRegion != null) && (sdRegion.getPrevious() != null) && info.contains("aui:script")) {
return true;
}
return false;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project liferay-ide by liferay.
the class AlloyStructuredTextPartitionerForJSP method getPartitionType.
@Override
public String getPartitionType(ITextRegion region, int offset) {
String retval = super.getPartitionType(region, offset);
IStructuredDocumentRegion sdRegion = this.fStructuredDocument.getRegionAtCharacterOffset(offset);
if (_isAUIScriptRegion(sdRegion)) {
retval = IHTMLPartitions.SCRIPT;
} else if (_isAUIEventHandlerAttrValue(sdRegion, sdRegion.getRegionAtCharacterOffset(offset))) {
retval = IHTMLPartitions.SCRIPT_EVENTHANDLER;
}
return retval;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class StyledTextColorPicker method getNamedStyleAtOffset.
protected String getNamedStyleAtOffset(int offset) {
// ensure the offset is clean
if (offset >= fInput.length())
return getNamedStyleAtOffset(fInput.length() - 1);
else if (offset < 0)
return getNamedStyleAtOffset(0);
// find the ITextRegion at this offset
if (fNodes == null)
return null;
IStructuredDocumentRegion aNode = fNodes;
while (aNode != null && !aNode.containsOffset(offset)) aNode = aNode.getNext();
if (aNode != null) {
// find the ITextRegion's Context at this offset
ITextRegion interest = aNode.getRegionAtCharacterOffset(offset);
if (interest == null)
return null;
if (offset > aNode.getTextEndOffset(interest))
return null;
String regionContext = interest.getType();
if (regionContext == null)
return null;
// find the named style (internal/selectable name) for that
// context
String namedStyle = (String) getContextStyleMap().get(regionContext);
if (namedStyle != null) {
return namedStyle;
}
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class StyledTextColorPicker method applyStyles.
protected void applyStyles() {
if (fText == null || fText.isDisposed() || fInput == null || fInput.length() == 0)
return;
// List regions = fParser.getRegions();
IStructuredDocumentRegion node = fNodes;
while (node != null) {
ITextRegionList regions = node.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) getContextStyleMap().get(currentRegion.getType());
if (namedStyle == null)
continue;
TextAttribute attribute = getAttribute(namedStyle);
if (attribute == null)
continue;
StyleRange style = new StyleRange(node.getStartOffset(currentRegion), currentRegion.getLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
fText.setStyleRange(style);
}
node = node.getNext();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class AbstractJSONCompletionProposalComputer method computeCompletionProposals.
@Override
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
ITextViewer textViewer = context.getViewer();
int documentPosition = context.getInvocationOffset();
setErrorMessage(null);
fTextViewer = textViewer;
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition <= 0 ? 0 : documentPosition - 1);
IJSONNode node = (IJSONNode) treeNode;
while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
node = node.getParentNode();
}
ContentAssistRequest contentAssistRequest = null;
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
// Fix completion region in case of JSON_OBJECT_CLOSE
if (completionRegion != null && completionRegion.getType() == JSONRegionContexts.JSON_OBJECT_CLOSE && documentPosition > 0) {
completionRegion = getCompletionRegion(documentPosition, node);
}
String matchString = EMPTY;
if (completionRegion != null) {
if (isPairValue(context, node)) {
try {
String nodeText = getNodeText(node);
int colonIndex = nodeText.indexOf(COLON);
int offset = documentPosition - node.getStartOffset();
if (colonIndex >= 0 && offset >= 0) {
String str = nodeText.substring(colonIndex + 1, offset);
// $NON-NLS-1$
str = str.replaceAll(",", BLANK);
matchString = str;
}
} catch (BadLocationException e) {
// ignore
}
} else {
matchString = getMatchString(sdRegion, completionRegion, documentPosition);
}
}
// compute normal proposals
contentAssistRequest = computeCompletionProposals(matchString, completionRegion, (IJSONNode) treeNode, node != null ? node.getParentNode() : null, context);
if (contentAssistRequest == null) {
contentAssistRequest = new ContentAssistRequest((IJSONNode) treeNode, node != null ? node.getParentNode() : null, sdRegion, completionRegion, documentPosition, 0, EMPTY);
setErrorMessage(JSONUIMessages.Content_Assist_not_availab_UI_);
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892 Only set this
* error message if nothing else was already set
*/
if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) {
setErrorMessage(JSONUIMessages.Content_Assist_not_availab_UI_);
}
ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
Aggregations