Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1c2c10202dee378ce0b069cfecbd8c812f3af904 (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
/*******************************************************************************
 * Copyright (c) 2007 Remy Suen 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:
 *    Remy Suen <remy.suen@gmail.com> - initial API and implementation
 ******************************************************************************/
package org.eclipse.ecf.internal.presence.bot.kosmos;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.osgi.util.NLS;

class JavadocAnalyzer {

	private final Map javadocs = new HashMap();

	JavadocAnalyzer() {
		try {
			initialize();
		} catch (IOException e) {
			// ignored
			e.printStackTrace(System.err);
		} catch (RuntimeException e) {
			e.printStackTrace(System.err);
			System.exit(0);
		}
	}

	private void initialize() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				JavadocAnalyzer.class.getResourceAsStream("javadoc.txt")));
		String input = reader.readLine();
		while (input != null) {
			String className = input.substring(input.lastIndexOf('.') + 1);
			Object o = javadocs.get(className);
			Javadoc doc = new Javadoc(javadocs, input);
			if (o != null) {
				if (o instanceof Javadoc) {
					Javadoc[] docs = new Javadoc[2];
					docs[0] = (Javadoc) o;
					docs[1] = doc;
					javadocs.put(className, docs);
				} else {
					Javadoc[] docs = (Javadoc[]) o;
					Javadoc[] copy = new Javadoc[docs.length + 1];
					System.arraycopy(docs, 0, copy, 0, docs.length);
					copy[docs.length] = doc;
					javadocs.put(className, copy);
				}
			} else {
				javadocs.put(className, doc);
			}
			javadocs.put(input, doc);
			input = reader.readLine();
		}
		reader.close();
	}

	String getJavadocs(String className) {
		Object docs = javadocs.get(className);
		if (docs == null) {
			return NLS.bind(CustomMessages
					.getString(CustomMessages.Javadoc_NotFound), className);
		} else if (docs instanceof Javadoc) {
			return ((Javadoc) docs).getDefault();
		} else {
			Javadoc[] array = (Javadoc[]) docs;
			String reply = ""; //$NON-NLS-1$
			for (int i = 0; i < array.length; i++) {
				reply += array[i].getDefault() + " "; //$NON-NLS-1$
			}
			reply = reply.substring(0, reply.length() - 1);
			return reply;
		}
	}

	String getJavadocs(String className, String field) {
		Object docs = javadocs.get(className);
		if (docs == null) {
			return NLS.bind(CustomMessages
					.getString(CustomMessages.Javadoc_NotFound), className);
		} else if (docs instanceof Javadoc) {
			return ((Javadoc) docs).getField(field);
		} else {
			Javadoc[] array = (Javadoc[]) docs;
			String reply = ""; //$NON-NLS-1$
			for (int i = 0; i < array.length; i++) {
				reply += array[i].getField(field) + " "; //$NON-NLS-1$
			}
			reply = reply.substring(0, reply.length() - 1);
			return reply;
		}
	}

	String getJavadocs(String className, String methodName, String[] parameters) {
		Object docs = javadocs.get(className);
		if (docs == null) {
			return NLS.bind(CustomMessages
					.getString(CustomMessages.Javadoc_NotFound), className);
		} else if (docs instanceof Javadoc) {
			String javadocs = ((Javadoc) docs)
					.getMethod(methodName, parameters);
			if (javadocs == null) {
				return CustomMessages.getString(CustomMessages.Javadoc_ResultsUnknown);
			} else {
				return javadocs;
			}
		} else {
			Javadoc[] array = (Javadoc[]) docs;
			String reply = ""; //$NON-NLS-1$
			for (int i = 0; i < array.length; i++) {
				String ret = array[i].getMethod(methodName, parameters);
				if (ret != null) {
					reply = reply + ret + " "; //$NON-NLS-1$
				}
			}
			reply = reply.substring(0, reply.length() - 1);
			return reply;
		}
	}
}

Back to the top