Skip to main content
summaryrefslogtreecommitdiffstats
blob: cba5fe4be61af3d23bb9c45da3a698729957f326 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*******************************************************************************
 * Copyright (c) 2005, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.jsdt.jsdoc;

import java.io.IOException;
import java.util.ArrayList;

/**
 *
 */
/**
 * @author childsb
 *
 */
public class ElementInfo {

	public static final int CLASS = 1;
	public static final int METHOD = 2;
	public static final int PROPERTY = 3;

	public static final int EVENT = 4;
	public static final int COLLECTION = 5;

	protected String name;
	protected String baseUrl;
	protected  ElementInfo parent;
	protected  ElementInfo[] children;
	protected int type=-5;
	protected static ArrayList nodes;
	protected boolean visited=false;
	protected static int instances = 0;
	protected static boolean DEBUG=false;
	protected static boolean useCache;
	protected static boolean keepCache;

	public boolean shouldUseCache() {
		return useCache;
	}

	public boolean shouldKeepCache() {
		return keepCache;
	}
	public static void setUseCache(boolean shouldUseCache) {
		useCache=shouldUseCache;
	}

	public static void setKeepCache(boolean shouldKeepCache) {
		keepCache = shouldKeepCache;
	}

	public boolean visit() {
		boolean ov = visited;
		visited = true;
		return ov;

	}

	public boolean equals(Object o) {

			try {
				ElementInfo other = (ElementInfo)o;
				boolean equal = other.getUrl().trim().equalsIgnoreCase(this.getUrl().trim());
//				boolean equal =  other.getName().equals(this.getName()) &&
//								 other.getType()==this.getType() &&
//								 (
//								 other.getParent().getName().equals(this.getParent().getName()) &&
//							     other.getParent().getType()== (this.getParent().getType()) ||
//							     other.getParent()==null && this.getParent()==null
//							     );
				return equal;
			} catch (Exception ex) {}

		return false;
	}

	public static void freeObject(ElementInfo element) {
		for(int i = 0;i<nodes.size();i++) {
			ElementInfo temp = (ElementInfo)nodes.get(i);
			if(temp.getUrl().equalsIgnoreCase(element.getUrl())) {
				nodes.remove(i);
				break;
			}
		}
	}

	public ElementInfo[] getFoundObjects() {
		ArrayList found = new ArrayList();
		ElementInfo[] children = getChildren();

		//found.add(this);
		for(int i = 0;i<children.length;i++) {

			if(children[i].getType() == COLLECTION || children[i].getType()==EVENT) {
				children[i].clearVisit();
				found.add(children[i]);
			}
		}

		return (ElementInfo[])found.toArray(new ElementInfo[found.size()]);
	}
	public void clearVisit() {
		visited=false;
	}

	{
		nodes = new ArrayList();
	}

	public ElementInfo(String baseUrl,ElementInfo parent) {
		this.baseUrl = baseUrl;
		this.parent = parent;
		//addNode(this);
		if(DEBUG) {
			System.out.println("Creating new instance for total of : " + ++instances);
		}

	}

	public void finalize() {
		if(DEBUG) {
			System.out.println("Destroying instance for total of : " + --instances);
		}
	}

	public void addNode(ElementInfo element) {

			nodes.add(element);
	}

	public static ElementInfo findChild(String baseUrl) {
		for(int i = 0;i<nodes.size();i++) {
			ElementInfo temp = (ElementInfo)nodes.get(i);
			if(temp.getUrl().equalsIgnoreCase(baseUrl)) return temp;
		}
		return null;
	}

	public boolean isDefined(String baseUrl) {
		return findChild(baseUrl)!=null;
	}

	public ElementInfo getParent() {
		return this.parent;
	}

	public ElementInfo[] getChildren() {
		return this.children;
	}

	public boolean hasChildren() { return this.children!=null && this.children.length>0;}

	public String getName() { return name;}

	public String getUrl() { return baseUrl;}



	public String getJsDoc(String parentName) { return null; }

	public String getJsStructure() { return null;}

	public String getTypeName() {
		switch(getType()) {
			case ElementInfo.PROPERTY:
				return "Property";
			case ElementInfo.METHOD:
				return "Method";
			case ElementInfo.CLASS:
				return "Class";


		}
		return "Unknown Type";
	}

	public int getType() {
		return -1;
	}

	public String toString() {
		StringBuffer buff = new StringBuffer();
		buff.append("name : " + getName() + Util.NEW_LINE);
		buff.append("Type : " + getTypeName() + "Util.NEW_LINE");
		if(getParent()!=null) {
			buff.append("\tParent Name : " + getParent().getName() + Util.NEW_LINE);
			buff.append("\tParent Type : " + getParent().getTypeName() + Util.NEW_LINE);
		}else {
			buff.append("No Parent" + Util.NEW_LINE);
		}
		buff.append("baseUrl : " + baseUrl + Util.NEW_LINE);
		//buff.append("translation : " + translation + "\n");
		buff.append("----------------Children--------------" + Util.NEW_LINE + "Name\t\t\t\tType"+ Util.NEW_LINE);
		if(hasChildren()) {

			ElementInfo[] children = getChildren();
			for(int i = 0;i<children.length;i++) {
				buff.append(children[i].getName() + "\t\t\t" + children[i].getTypeName() + Util.NEW_LINE);
			}
		}else {
			buff.append(Util.NEW_LINE + "No Children" + Util.NEW_LINE);
		}
		buff.append("--------------------------------------");
		return buff.toString();
	}

	protected String getPageText() {
		try {
			return Util.retrieveFromUrl(getUrl(), shouldUseCache(), !shouldKeepCache());
		} catch (IOException ex) {

		}
		return null;
//		if(pageText!=null) return pageText;
//		try {
//			pageText =  Util.retrieveFromUrl(getUrl());
//		} catch (IOException ex) {
//			// TODO Auto-generated catch block
//			//ex.printStackTrace();
//		}
//		return pageText;
	}

	public String getBaseUrl() {
		return Util.getBaseUrl(getUrl());
	}

	public String getDeclarationString() {
		return null;
	}
	public String getJsStructure(String parent) {
		return "NOT DEFINED " + parent;
	}

	public boolean isStatic() { return false; }
}

Back to the top