use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class RefreshStructureJob method contains.
/**
* Simple hierarchical containment relationship. Note, this method returns
* "false" if the two nodes are equal!
*
* @param root
* @param possible
* @return if the root is parent of possible, return true, otherwise
* return false
*/
private boolean contains(ICSSNode root, ICSSNode possible) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("==============================================================================================================");
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("recursive call w/ root: " + root + " and possible: " + possible);
// $NON-NLS-1$
System.out.println("--------------------------------------------------------------------------------------------------------------");
}
// can't contain the child if it's null
if (root == null) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning false: root is null");
}
return false;
}
// nothing can be parent of Document node
if (possible instanceof ICSSDocument) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning false: possible is Document node");
}
return false;
}
// document contains everything
if (root instanceof ICSSDocument) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning true: root is Document node");
}
return true;
}
// check parentage
ICSSNode current = possible;
// loop parents
while ((current != null) && (current.getNodeType() != ICSSNode.STYLESHEET_NODE || current.getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
// found it
if (root.equals(current)) {
if (DEBUG) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println(" !!! found: " + possible + " in subelement of: " + root);
}
return true;
}
current = current.getParentNode();
}
// never found it
return false;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class RefreshStructureJob method addRefreshRequest.
private synchronized void addRefreshRequest(ICSSNode newNodeRequest) {
/*
* note: the caller must NOT pass in null node request (which, since
* private method, we do not need to gaurd against here, as long as we
* gaurd against it in calling method.
*/
int size = fRefreshes.size();
for (int i = 0; i < size; i++) {
ICSSNode existingNodeRequest = (ICSSNode) fRefreshes.get(i);
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=157427 If we
* already have a request which equals the new request, discard
* the new request
*/
if (existingNodeRequest.equals(newNodeRequest)) {
return;
}
/*
* If we already have a request which contains the new request,
* discard the new request
*/
if (contains(existingNodeRequest, newNodeRequest)) {
return;
}
/*
* If new request contains any existing requests, replace it with
* new request. ISSUE: technically, we should replace ALL
* contained, existing requests (such as if many siblings already
* que'd up when their common parent is then requested, but, I'm
* not sure if that occurs much, in practice, or if there's an
* algorithm to quickly find them all. Actually, I guess we could
* just go through the _rest_ of the list (i+1 to size) and remove
* any that are contained by new request ... in future :) .
*/
if (contains(newNodeRequest, existingNodeRequest)) {
fRefreshes.set(i, newNodeRequest);
return;
}
}
/*
* If we get to here, either from existing request list being zero
* length, or no exisitng requests "matched" new request, then add the
* new request.
*/
fRefreshes.add(newNodeRequest);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class StructuredSelectNextHandler 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.getNextSibling();
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(currentOffset, newIndexedRegion.getEndOffset() - currentOffset);
}
}
} else
newRegion = cursorNodeRegion;
}
return newRegion;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSHyperlinkDetector method detectHyperlinks.
/* (non-Javadoc)
* @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
*/
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (textViewer != null && region != null) {
final IDocument document = textViewer.getDocument();
final ICSSNode node = getNode(document, region);
if (node == null) {
return null;
}
String href = null;
switch(node.getNodeType()) {
case ICSSNode.PRIMITIVEVALUE_NODE:
if (((CSSPrimitiveValue) node).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
href = ((CSSPrimitiveValue) node).getStringValue();
}
break;
case ICSSNode.IMPORTRULE_NODE:
href = ((CSSImportRule) node).getHref();
break;
}
if (href != null) {
final IHyperlink hyperlink = getHyperlink(node, href);
if (hyperlink != null) {
return new IHyperlink[] { hyperlink };
}
}
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSContentAssistContext method initializeTargetNode.
/**
*/
private void initializeTargetNode() {
if (fCursorPos == 0) {
fTargetNode = fModel.getDocument();
return;
}
// find edge of tree node
ICSSNode cursorNode = getNodeAt(fCursorPos);
if (cursorNode == null) {
// end of document
cursorNode = fModel.getDocument();
}
ICSSNode node = null;
IStructuredDocumentRegion flatNode = fStructuredDocument.getRegionAtCharacterOffset(fCursorPos - 1);
while (flatNode != null && (node = getNodeAt(flatNode.getStartOffset())) == cursorNode && ((IndexedRegion) node).getStartOffset() != flatNode.getStartOffset()) {
flatNode = flatNode.getPrevious();
}
if (flatNode == null) {
// top of document
fTargetNode = (node == null) ? fModel.getDocument() : node;
return;
}
// BBBBBBBBBB cursorNode:A , node:B -> target is A
if (cursorNode != null) {
for (ICSSNode parent = cursorNode.getParentNode(); parent != null; parent = parent.getParentNode()) {
if (parent == cursorNode) {
fTargetNode = cursorNode;
return;
}
}
}
// v<--|
// AAA
// BBBBBBBBBB cursorNode:B , node:A -> depend on A's node type
short nodeType = node.getNodeType();
if (nodeType == ICSSNode.STYLEDECLITEM_NODE || nodeType == ICSSNode.CHARSETRULE_NODE || nodeType == ICSSNode.IMPORTRULE_NODE) {
String type = CSSUtil.getStructuredDocumentRegionType(flatNode);
if (type == CSSRegionContexts.CSS_DELIMITER || type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
fTargetNode = node.getParentNode();
} else {
fTargetNode = node;
}
// fTargetNode = (bOverSemiColon) ? node.getParentNode() : node;
} else if (CSSUtil.getStructuredDocumentRegionType(flatNode) == CSSRegionContexts.CSS_RBRACE) {
fTargetNode = node.getParentNode();
} else {
fTargetNode = node;
}
return;
}
Aggregations