Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6a995749ae6c9df538fb09c60c0f58b6de24ac7e (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
/*******************************************************************************
 * Copyright (c) 2007, 2008 Intel 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:
 *     Intel Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.ui.help;

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import org.eclipse.cdt.ui.FunctionPrototypeSummary;
import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IRequiredInclude;

public class CFunctionSummary implements IFunctionSummary {
	private static final String ATTR_STD = "standard"; //$NON-NLS-1$
	private static final String NODE_NAME = "name"; //$NON-NLS-1$
	private static final String NODE_DESC = "description"; //$NON-NLS-1$
	private static final String NODE_INCL = "include"; //$NON-NLS-1$
	private static final String NODE_TYPE = "returnType"; //$NON-NLS-1$
	private static final String NODE_ARGS = "arguments"; //$NON-NLS-1$

	private static final String SP = " "; //$NON-NLS-1$
	private static final String LB = "("; //$NON-NLS-1$
	private static final String RB = ")"; //$NON-NLS-1$
	
	private String name = null;
	private String desc = null;
	private IRequiredInclude[] incs = null;
	IFunctionPrototypeSummary fps = null;
	
	public CFunctionSummary(Element e, String defName) {
		name = defName; // if there's no "name" tag, keyword used instead
		String args = null;
		String type = null;
		NodeList list = e.getChildNodes();
		ArrayList<IRequiredInclude> incList = new ArrayList<IRequiredInclude>();
		for(int j = 0; j < list.getLength(); j++){
			Node node = list.item(j);
			if(node.getNodeType() != Node.ELEMENT_NODE)	
				continue;
			String s = node.getNodeName().trim();
			String t = node.getFirstChild().getNodeValue().trim();
			if(NODE_NAME.equals(s)){
				name = t;
			} else if(NODE_DESC.equals(s)){
				desc = t;
			} else if(NODE_ARGS.equals(s)){
				args = t;
			} else if(NODE_TYPE.equals(s)){
				type = t;
			} else if(NODE_INCL.equals(s)){
				boolean std = true;
				if (((Element)node).hasAttribute(ATTR_STD)) {
					String st = ((Element)node).getAttribute(ATTR_STD);
					std = (st == null  || st.equalsIgnoreCase("true") //$NON-NLS-1$
							|| st.equalsIgnoreCase("yes"));           //$NON-NLS-1$
				}
				incList.add(new RequiredInclude(t, std));
			}
		}
		if (incList.size() > 0) 
			incs = incList.toArray(new IRequiredInclude[incList.size()]);
		fps = new FunctionPrototypeSummary(type + SP + name + LB + args + RB);	
	}
	
	public String getDescription() {
		return desc;
	}
	public IRequiredInclude[] getIncludes() { 
		return incs; 
	}
	public String getName() {
		return name;
	}
	public String getNamespace() {
		return null;
	}
	public IFunctionPrototypeSummary getPrototype() {
		return fps;
	}
	
	/**
	 * This class implements IRequiredInclude interface 
	 */
	private class RequiredInclude implements IRequiredInclude {
		private String iname;
		private boolean std;
		
		private RequiredInclude(String s, boolean b) {
			iname = s;
			std = b;
		}
		public String getIncludeName() {
			return iname;
		}
		public boolean isStandard() {
			return std;
		}
		public String toString() {
			if (std) 
				return "#include <" + iname + ">";   //$NON-NLS-1$ //$NON-NLS-2$
			else
				return "#include \"" + iname + "\""; //$NON-NLS-1$ //$NON-NLS-2$
		}		
	}
	public String toString() {
		return "<functionSummary> : " + getPrototype().getPrototypeString(false); //$NON-NLS-1$
	}

}

Back to the top