/** * */ static int getDepth(ICSSNode node) { int depth = -1; while (node != null) { depth++; node = node.getParentNode(); } return depth; }
ICSSNode getCommonAncestor(ICSSNode node) { if (node == null) return null; for (ICSSNode na = node; na != null; na = na.getParentNode()) { for (ICSSNode ta = this; ta != null; ta = ta.getParentNode()) { if (ta == na) return ta; } } return null; // not found }
private ICSSNode getCommonAncestor(ICSSNode nodeA, ICSSNode nodeB) { if (nodeA == null || nodeB == null) { return null; } for (ICSSNode na = nodeA; na != null; na = na.getParentNode()) { for (ICSSNode ta = nodeB; ta != null; ta = ta.getParentNode()) { if (ta == na) { return ta; } } } return null; // not found }
/** * */ static boolean isParentOf(ICSSNode parent, ICSSNode child) { if (parent == null || child == null) { return false; } for (ICSSNode node = child; node != null; node = node.getParentNode()) { if (parent == node) { return true; } } return false; } }
static ICSSNode findBraceContainer(ICSSNode node) { for (ICSSNode i = node; i != null; i = i.getParentNode()) { if (CSSModelUtil.canContainBrace(i)) { return i; } } return null; }
/** * The style sheet that contains this rule. */ public CSSStyleSheet getParentStyleSheet() { ICSSNode parent = getParentNode(); while (parent != null) { if (parent instanceof CSSStyleSheetImpl) return (CSSStyleSheet) parent; parent = parent.getParentNode(); } return null; }
CSSDocumentImpl getContainerDocument() { for (ICSSNode node = this; node != null; node = node.getParentNode()) { if (node instanceof CSSDocumentImpl) { CSSDocumentImpl doc = (CSSDocumentImpl) node; if (doc.isDocument()) return doc; } } return null; }
/** * Generate or format source between children('child' and its previous * sibling) and append to string buffer */ public final StringBuffer formatBefore(ICSSNode node, ICSSNode child, IRegion exceptFor) { Assert.isTrue(child == null || child.getParentNode() == node); StringBuffer buf = new StringBuffer(); formatBefore(node, child, /* (child != null) ? (child.getCssText()) : */"", buf, exceptFor);//$NON-NLS-1$ return buf; }
/** * */ protected String getIndent(ICSSNode node) { if (node == null) return "";//$NON-NLS-1$ ICSSNode parent = node.getParentNode(); if (node instanceof ICSSAttr) parent = ((ICSSAttr) node).getOwnerCSSNode(); if (parent == null) return "";//$NON-NLS-1$ if (node instanceof org.w3c.dom.css.CSSStyleDeclaration) parent = parent.getParentNode(); if (parent == null) return "";//$NON-NLS-1$ String parentIndent = getIndent(parent); if (parent instanceof org.w3c.dom.css.CSSRule) return parentIndent + getIndentString(); if (node.getParentNode() instanceof ICSSStyleDeclaration) return parentIndent + getIndentString(); return parentIndent; }
public CSSMMNode getMetaModelNodeFor(ICSSNode node) { if (node instanceof ICSSStyleDeclaration) { node = node.getParentNode(); ICSSNode parent = node.getParentNode(); if (parent != null) { parent = parent.getParentNode();
/** */ protected CSSSourceGenerator getParentFormatter(ICSSNode node) { ICSSNode parent = node.getParentNode(); if (parent != null) { CSSSourceGenerator formatter = (CSSSourceGenerator) ((INodeNotifier) parent).getAdapterFor(CSSSourceFormatter.class); if (formatter == null) { formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) parent); } return formatter; } return null; }
/** * Insert the method's description here. */ public int getChildInsertPos(ICSSNode node) { if (node == null) return -1; int pos = super.getChildInsertPos(node); if (pos < 0) { CSSSourceGenerator formatter = getParentFormatter(node); return (formatter != null) ? formatter.getChildInsertPos(node.getParentNode()) : -1; } return pos; }
traverseRoot = parentNode; while (traverseRoot instanceof CSSRegionContainer) { traverseRoot = traverseRoot.getParentNode(); fDeletionTargetParent = fDeletionTarget.getParentNode();
/** * * @return int * @param node * org.eclipse.wst.css.core.model.interfaces.ICSSNode * @param insertPos * int */ public int getLengthToReformatAfter(ICSSNode node, int insertPos) { if (node == null) return 0; IndexedRegion nnode = (IndexedRegion) node; if (insertPos < 0 || !nnode.contains(insertPos)) { if (node.getParentNode() != null && nnode.getEndOffset() <= 0) { CSSSourceGenerator pntFormatter = getParentFormatter(node); if (pntFormatter != null) return pntFormatter.getLengthToReformatAfter(node.getParentNode(), insertPos); } return 0; } return super.getLengthToReformatAfter(node, insertPos); }
/** * * @return int * @param node * org.eclipse.wst.css.core.model.interfaces.ICSSNode * @param insertPos * int */ public int getLengthToReformatBefore(ICSSNode node, int insertPos) { if (node == null) return 0; IndexedRegion nnode = (IndexedRegion) node; if (insertPos <= 0 || !nnode.contains(insertPos - 1)) { if (node.getParentNode() != null && nnode.getEndOffset() <= 0) { CSSSourceGenerator pntFormatter = getParentFormatter(node); if (pntFormatter != null) return pntFormatter.getLengthToReformatBefore(node.getParentNode(), insertPos); } return 0; } return super.getLengthToReformatBefore(node, insertPos); } }
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument(); CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy); boolean appendQuote = regions.length > 1 && node.getParentNode() instanceof ICSSStyleDeclItem && isCleanup() && getCleanupStrategy(node).isQuoteValues() && (((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT_FAMILY) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_VOICE_FAMILY)); String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
if (rule instanceof ICSSStyleRule) break; rule = rule.getParentNode();
if (rule instanceof ICSSStyleRule) break; rule = rule.getParentNode();
appendDelimBefore(node.getParentNode(), null, source); } else if (child != null && child.getNodeType() == ICSSNode.MEDIALIST_NODE) { // between appendDelimBefore(node, null, source); else appendDelimBefore(node.getParentNode(), null, source); } else { // normal case appendDelimBefore(node, null, source);
int limit = ((IndexedRegion) ((node.getParentNode() != null) ? node.getParentNode() : node)).getStartOffset(); while (it.hasPrev()) { ITextRegion curReg = it.prev(); int limit = ((IndexedRegion) ((node.getParentNode() != null) ? node.getParentNode() : node)).getEndOffset(); while (it.hasNext()) { ITextRegion curReg = it.next(); appendDelimBefore(node.getParentNode(), toAppendRegion, source);