Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fd3ab9eed9c1131f15d93bc949ff4af567ac1654 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved.   This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* 
* Contributors:
*   IBM - Initial API and implementation
*   Jens Lukowski/Innoopract - initial renaming/restructuring
* 
*/
package org.eclipse.wst.sse.core.internal.text;



import java.util.Vector;

import org.eclipse.wst.sse.core.text.IStructuredDocument;
import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.text.IStructuredDocumentRegionList;
import org.eclipse.wst.sse.core.util.Assert;


public class StructuredDocumentRegionIterator {

	/**
	 * 
	 */
	private StructuredDocumentRegionIterator() {
	}

	public final static IStructuredDocumentRegion adjustStart(IStructuredDocumentRegion headNode, int adjustment) {
		IStructuredDocumentRegion aNode = headNode;
		while (aNode != null) {
			aNode.adjustStart(adjustment);
			aNode = aNode.getNext();
		}
		return headNode;
	}

	public final static int countRegions(IStructuredDocumentRegionList flatNodes) {
		int result = 0;
		if (flatNodes != null) {
			int length = flatNodes.getLength();
			for (int i = 0; i < length; i++) {
				IStructuredDocumentRegion node = flatNodes.item(i);
				// don't know why, but we're getting null pointer exceptions in this method
				if (node != null) {
					result = result + node.getNumberOfRegions();
				}
			}
		}
		return result;
	}

	public final static String getText(CoreNodeList flatNodes) {
		String result = null;
		if (flatNodes == null) {
			result = ""; //$NON-NLS-1$
		}
		else {
			StringBuffer buff = new StringBuffer();
			//IStructuredDocumentRegion aNode = null;
			int length = flatNodes.getLength();
			for (int i = 0; i < length; i++) {
				buff.append(flatNodes.item(i).getText());
			}
			result = buff.toString();
		}
		return result;
	}

	//	public final static IStructuredDocumentRegion setStructuredDocument(IStructuredDocumentRegion headNode, BasicStructuredDocument structuredDocument) {
	//		IStructuredDocumentRegion aNode = headNode;
	//		while (aNode != null) {
	//			aNode.setParentDocument(structuredDocument);
	//			aNode = (IStructuredDocumentRegion) aNode.getNext();
	//		}
	//		return headNode;
	//	}
	public final static IStructuredDocumentRegion setParentDocument(IStructuredDocumentRegion headNode, IStructuredDocument document) {
		IStructuredDocumentRegion aNode = headNode;
		while (aNode != null) {
			aNode.setParentDocument(document);
			aNode = aNode.getNext();
		}
		return headNode;
	}

	public final static CoreNodeList setParentDocument(CoreNodeList nodelist, IStructuredDocument textStore) {
		Assert.isNotNull(nodelist, "nodelist was null in CoreNodeList::setTextStore(CoreNodeList, StructuredTextStore)"); //$NON-NLS-1$
		int len = nodelist.getLength();
		for (int i = 0; i < len; i++) {
			IStructuredDocumentRegion node = nodelist.item(i);
			//Assert.isNotNull(node, "who's putting null in the node list? in CoreNodeList::setTextStore(CoreNodeList, StructuredTextStore)"); //$NON-NLS-1$
			node.setParentDocument(textStore);
		}
		return nodelist;
	}

	public final static Vector toVector(IStructuredDocumentRegion headNode) {
		IStructuredDocumentRegion aNode = headNode;
		Vector v = new Vector();
		while (aNode != null) {
			v.addElement(aNode);
			aNode = aNode.getNext();
		}
		return v;
	}
}

Back to the top