IStructuredDocumentRegion getStructuredDocumentRegion(int index) { IStructuredDocumentRegion node = firstStructuredDocumentRegion; for (int i = index; i > 0; i--) { if (node == null) return null; node = node.getNext(); } return node; }
/** * @return int */ int getStructuredDocumentRegionCount() { if (firstStructuredDocumentRegion == null) return 0; IStructuredDocumentRegion node = firstStructuredDocumentRegion; int i = 0; for (; node != null; i++) node = node.getNext(); return i; }
/** * This is a simple utility to count nodes. Used only for debug * statements. */ private int _countNodes(IStructuredDocumentRegion nodes) { int result = 0; IStructuredDocumentRegion countNode = nodes; while (countNode != null) { result++; countNode = countNode.getNext(); } return result; }
/** * This is a simple utility to count nodes. Used only for debug * statements. */ protected int _countNodes(IStructuredDocumentRegion nodes) { int result = 0; IStructuredDocumentRegion countNode = nodes; while (countNode != null) { result++; countNode = countNode.getNext(); } return result; }
/** * */ public static IStructuredDocumentRegion findNextSignificantNode(IStructuredDocumentRegion startNode) { if (startNode == null) { return null; } IStructuredDocumentRegion node = startNode.getNext(); while (node != null) { String type = getStructuredDocumentRegionType(node); if (type != CSSRegionContexts.CSS_S && type != CSSRegionContexts.CSS_COMMENT && type != CSSRegionContexts.CSS_CDO && type != CSSRegionContexts.CSS_CDC) { return node; } node = node.getNext(); } return null; }
private boolean isBreakingWithNestedTag(IStructuredDocumentRegion start, IStructuredDocumentRegion end) { boolean result = false; boolean changesIncludeA_lt = fChanges != null && fChanges.indexOf('<') >= 0; boolean delsIncludeA_gt = fDeletedText != null && fDeletedText.indexOf('>') >= 0; // List regions = new ArrayList(); IStructuredDocumentRegion node = start; int endReplace = fStart + fLengthToReplace; while (end != null && node != end.getNext()) { Iterator i = node.getRegions().iterator(); while (i.hasNext()) { ITextRegion region = (ITextRegion) i.next(); if (intersects(node, region, fStart, endReplace)) { result = isBreakingWithNestedTag(changesIncludeA_lt, delsIncludeA_gt, node, region); if (result) break; } } node = node.getNext(); if (result) break; } return result; }
/** * Method getRegions. * * @param headNode * @return List */ protected List getRegions(IStructuredDocumentRegion headNode) { List allRegions = new ArrayList(); IStructuredDocumentRegion currentNode = headNode; while (currentNode != null) { ITextRegionList nodeRegions = currentNode.getRegions(); for (int i = 0; i < nodeRegions.size(); i++) { allRegions.add(nodeRegions.get(i)); } currentNode = currentNode.getNext(); } return allRegions; }
/** * Method getRegions. * * @param headNode * @return List */ protected List getRegions(IStructuredDocumentRegion headNode) { List allRegions = new ArrayList(); IStructuredDocumentRegion currentNode = headNode; while (currentNode != null) { ITextRegionList nodeRegions = currentNode.getRegions(); for (int i = 0; i < nodeRegions.size(); i++) { allRegions.add(nodeRegions.get(i)); } currentNode = currentNode.getNext(); } return allRegions; }
protected void performValidation(IFile f, IReporter reporter, IStructuredDocument sDoc) { /* * when validating an entire file need to clear dupes or else you're * comparing between files */ fPrefixValueRegionToDocumentRegionMap.clear(); fTaglibPrefixesInUse.clear(); // iterate all document regions IStructuredDocumentRegion region = sDoc.getFirstStructuredDocumentRegion(); while (region != null && !reporter.isCancelled()) { // only checking directives if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { processDirective(reporter, f, sDoc, region); } region = region.getNext(); } if (!reporter.isCancelled()) { reportTaglibDuplicatePrefixes(f, reporter, sDoc); } fPrefixValueRegionToDocumentRegionMap.clear(); fTaglibPrefixesInUse.clear(); }
/** * */ public static IStructuredDocumentRegion findNodeForward(IStructuredDocumentRegion startNode, IStructuredDocumentRegion endNode, String type) { IStructuredDocumentRegion node; for (node = startNode; node != null; node = node.getNext()) { if (endNode.getStartOffset() < node.getStartOffset()) { node = null; break; } else if (getStructuredDocumentRegionType(node) == type) { break; } } return node; }
/** * @return java.lang.String */ public String getCssText() { if (getFirstStructuredDocumentRegion() == null) return generateSource(); StringBuffer str = new StringBuffer(getFirstStructuredDocumentRegion().getText()); IStructuredDocumentRegion node = getFirstStructuredDocumentRegion(); while (node != getLastStructuredDocumentRegion()) { node = node.getNext(); str.append(node.getText()); } return str.toString(); }
/** * Old Nodes: --[O1]--[O2]--[O3]--- : / \ Current Nodes: * ---[C1]-----[C2]-----[C3]-----[C4]--- * * Input: O1 -> Output: O2 Input: O2 -> Output: O3 Input: O3 -> Output: C4 * Input: Cn -> Output: Cn+1 */ public IStructuredDocumentRegion getNextNode(IStructuredDocumentRegion node) { IStructuredDocumentRegion nextNode = null; if (node != null) { nextNode = node.getNext(); if (nextNode == null) { if (isOldNode(node)) { // this may be the end of old flatnodes int newStart = node.getEnd() - fLengthDifference; nextNode = fStructuredDocument.getRegionAtCharacterOffset(newStart); } } } return nextNode; }
private void advanceNextNode() { setCurrentNode(getCurrentNode().getNext()); if (getCurrentNode() != null) setSourceReferencePoint(); }
protected void performValidation(IFile file, IReporter reporter, IStructuredDocument structuredDoc) { IStructuredDocumentRegion curNode = structuredDoc.getFirstStructuredDocumentRegion(); while (null != curNode && !reporter.isCancelled()) { if (curNode.getType() != DOMRegionContext.XML_COMMENT_TEXT && curNode.getType() != DOMRegionContext.XML_CDATA_TEXT && curNode.getType() != DOMRegionContext.UNDEFINED) { validateRegionContainer(curNode, reporter, file); } curNode = curNode.getNext(); } }
/** * Old Nodes: --[O1]--[O2]--[O3]--- : / \ Current Nodes: * ---[C1]-----[C2]-----[C3]-----[C4]--- * * Input: O* -> Output: C4 Input: Cn -> Output: Cn+1 */ public IStructuredDocumentRegion getNextNodeInCurrent(IStructuredDocumentRegion node) { IStructuredDocumentRegion nextNode = null; if (isOldNode(node)) { IStructuredDocumentRegion oldEndNode = fOldStructuredDocumentRegionList.item(fOldStructuredDocumentRegionList.getLength() - 1); int newStart = oldEndNode.getEnd() - fLengthDifference; nextNode = fStructuredDocument.getRegionAtCharacterOffset(newStart); } else if (node != null) { nextNode = node.getNext(); } return nextNode; }
protected void performValidation(IFile f, IReporter reporter, IStructuredModel model, IRegion validateRegion) { IStructuredDocument sDoc = model.getStructuredDocument(); // iterate all document regions IStructuredDocumentRegion region = sDoc.getRegionAtCharacterOffset(validateRegion.getOffset()); while (region != null && !reporter.isCancelled() && (region.getStartOffset() <= (validateRegion.getOffset() + validateRegion.getLength()))) { if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { // only checking directives processDirective(reporter, f, model, region); fTaglibPrefixes.clear(); } else if (region.getType() == DOMRegionContext.XML_TAG_NAME) { // and jsp tags String tagName = getStartTagName(region); int colonPosition = tagName.indexOf(':'); if (colonPosition > -1) { // get tag's prefix and check if it's really a jsp action // tag String prefix = tagName.substring(0, colonPosition); if (getTaglibPrefixes(sDoc).contains(prefix)) processDirective(reporter, f, model, region); } } region = region.getNext(); } }
/** * */ public ITextRegion next() { if (documentRegion == null) return null; if (current < 0 || documentRegion.getRegions() == null || documentRegion.getRegions().size() <= current) return null; ITextRegion region = documentRegion.getRegions().get(current); curDocumentRegion = documentRegion; if (current >= documentRegion.getRegions().size() - 1) { documentRegion = documentRegion.getNext(); current = -1; } current++; return region; }
public boolean parse(String filePath) { getLocalParser().removeStructuredDocumentRegionHandler(this); // from outer class List blockMarkers = this.fTranslator.getBlockMarkers(); IStructuredDocument document = StructuredDocumentFactory.getNewStructuredDocumentInstance(getLocalParser()); String contents = getContents(filePath); if (contents == null) return false; // this adds the current markers from the outer class list // to this parser so parsing works correctly for (int i = 0; i < blockMarkers.size(); i++) { addBlockMarker((BlockMarker) blockMarkers.get(i)); } reset(contents); // forceParse(); document.set(contents); IStructuredDocumentRegion cursor = document.getFirstStructuredDocumentRegion(); while (cursor != null) { nodeParsed(cursor); cursor = cursor.getNext(); } getLocalParser().addStructuredDocumentRegionHandler(this); return true; }
/** * Color the text in the sample area according to the current preferences */ void applyStyles() { if (fText == null || fText.isDisposed()) return; IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); while (documentRegion != null) { ITextRegionList regions = documentRegion.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) fContextToStyleMap.get(currentRegion.getType()); if (namedStyle == null) continue; TextAttribute attribute = getAttributeFor(namedStyle); if (attribute == null) continue; StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle()); style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0; style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0; fText.setStyleRange(style); } documentRegion = documentRegion.getNext(); } }
private void setCssValueTextCore(String value) throws DOMException { // use temporary document synchronized (CSSStyleDeclarationImpl.class) { if (sharedStructuredDocument == null) { IDocumentLoader loader = new CSSDocumentLoader(); sharedStructuredDocument = (IStructuredDocument) loader.createNewStructuredDocument(); ((CSSSourceParser) sharedStructuredDocument.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE); } sharedStructuredDocument.set(value); IStructuredDocumentRegion node = sharedStructuredDocument.getFirstStructuredDocumentRegion(); if (node == null) { return; } if (node.getNext() != null) { throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "");//$NON-NLS-1$ } CSSDeclarationItemParser itemParser = new CSSDeclarationItemParser(getOwnerDocument()); itemParser.setStructuredDocumentTemporary(true); // make a copy of nodelist because setupValues will destroy list ITextRegionList nodeList = new TextRegionListImpl(node.getRegions()); itemParser.setupValues(this, node, nodeList); } }