use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StructuredSelectPreviousCSSActionDelegate method getNewSelectionRegion.
protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
Region newRegion = null;
if (indexedRegion instanceof ICSSNode) {
ICSSNode cursorNode = (ICSSNode) indexedRegion;
Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
int currentOffset = textSelection.getOffset();
int currentEndOffset = currentOffset + textSelection.getLength();
if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
ICSSNode newNode = cursorNode.getPreviousSibling();
if (newNode == null) {
newNode = cursorNode.getParentNode();
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
}
} else {
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), currentEndOffset - newIndexedRegion.getStartOffset());
}
}
} else
newRegion = cursorNodeRegion;
}
return newRegion;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class UnknownRuleFormatter method formatPre.
@Override
protected void formatPre(IJSONNode node, StringBuilder source) {
IJSONCleanupStrategy stgy = getCleanupStrategy(node);
int start = ((IndexedRegion) node).getStartOffset();
int end = ((IndexedRegion) node).getEndOffset();
if (end > 0) {
// format source
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
}
// else { // generate source
// JSONUnknownRule rule = (JSONUnknownRule) node;
// source.append(rule.getCssText());
// }
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class JSPActionValidator method processDirective.
private void processDirective(IReporter reporter, IFile file, IStructuredModel model, IStructuredDocumentRegion documentRegion) {
IndexedRegion ir = model.getIndexedRegion(documentRegion.getStartOffset());
if (ir instanceof IDOMElement) {
IDOMElement element = (IDOMElement) ir;
ModelQuery query = ModelQueryUtil.getModelQuery(model);
if (query != null) {
CMElementDeclaration cmElement = query.getCMElementDeclaration(element);
if (cmElement != null) {
CMNamedNodeMap cmAttributes = null;
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl();
List nodes = query.getAvailableContent(element, cmElement, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
cmAttributes = allAttributes;
boolean foundjspattribute = checkUnknownAttributes(element, cmElement, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
// missing required attributes
if (!foundjspattribute && fSeverityMissingRequiredAttribute != ValidationMessage.IGNORE)
checkRequiredAttributes(element, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
if (fSeverityNonEmptyInlineTag != ValidationMessage.IGNORE)
checkNonEmptyInlineTag(element, cmElement, reporter, file, model.getStructuredDocument());
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method getCurrentNode.
/**
* Returns the node the cursor is currently on in the document. null if no
* node is selected
*
* @param offset
* @return Node either element, doctype, text, or null
*/
private Node getCurrentNode(IDocument document, int offset) {
// get the current node at the offset (returns either: element,
// doctype, text)
IndexedRegion inode = null;
IStructuredModel sModel = null;
try {
sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
inode = sModel.getIndexedRegion(offset);
if (inode == null) {
inode = sModel.getIndexedRegion(offset - 1);
}
} finally {
if (sModel != null) {
sModel.releaseFromRead();
}
}
if (inode instanceof Node) {
return (Node) inode;
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class QuickOutlinePopupDialog method gotoSelectedElement.
private void gotoSelectedElement() {
Object element = getSelectedElement();
dispose();
if (element != null) {
ITextEditor editor = getActiveTextEditor();
if (editor != null) {
editor.selectAndReveal(((IndexedRegion) element).getStartOffset(), ((IndexedRegion) element).getEndOffset() - ((IndexedRegion) element).getStartOffset());
}
}
}
Aggregations