blob: bc99da857133a1970e0dff179b210c2d10c6e814 (
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
|
/*******************************************************************************
* Copyright (c) 2009, 2018 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EZchip Semiconductor - adding support for Doxygen XML files as input
* Red Hat Incorporated - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.internal.cdt.libhover.utils;
import org.eclipse.linuxtools.cdt.libhover.FunctionInfo;
import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class CXmlLibhoverGen extends LibhoverInfoGenerator{
public CXmlLibhoverGen(Document document){
this.document = document;
}
private FunctionInfo getFunctionInfoFromNode(String name, Node functionNode, Document document) {
FunctionInfo f = new FunctionInfo(name);
NamedNodeMap functionNodeMap = functionNode.getAttributes();
Node functionNodeReturntypeNode = functionNodeMap.item(0);
String functionNodeRtName = functionNodeReturntypeNode.getNodeName();
if (functionNodeRtName.equals("returntype")) { //$NON-NLS-1$
// return type
String functionNodeRtValue = functionNodeReturntypeNode.getNodeValue();
f.setReturnType(functionNodeRtValue);
} // returntype
NodeList kids = functionNode.getChildNodes();
for (int fnk = 0; fnk < kids.getLength(); fnk++) {
Node kid = kids.item(fnk);
String kidName = kid.getNodeName();
if (kidName.equals("prototype")) { //$NON-NLS-1$
// prototype
String prototype = null;
NodeList parms = kid.getChildNodes();
for (int fnp = 0; fnp < parms.getLength(); fnp++) {
Node parm = parms.item(fnp);
String parmName = parm.getNodeName();
if (parmName.equals("parameter")) { //$NON-NLS-1$
NamedNodeMap parmMap = parm.getAttributes();
Node parmNode = parmMap.item(0);
String parameter = parmNode.getNodeValue();
prototype = (null == prototype) ? parameter : prototype
+ ", " + parameter; //$NON-NLS-1$
}
}
f.setPrototype(prototype);
} // prototype
else if (kidName.equals("headers")) { //$NON-NLS-1$
// headers
NodeList headers = kid.getChildNodes();
for (int fnh = 0; fnh < headers.getLength(); fnh++) {
Node header = headers.item(fnh);
String headerName = header.getNodeName();
if (headerName.equals("header")) { //$NON-NLS-1$
NamedNodeMap headerMap = header.getAttributes();
Node headerNode = headerMap.item(0);
f.addHeader(headerNode.getNodeValue());
}
}
} // headers
else if (kidName.equals("groupsynopsis")) { //$NON-NLS-1$
// group synopsis
NamedNodeMap attr = kid.getAttributes();
Node idnode = attr.getNamedItem("id"); //$NON-NLS-1$
String id = idnode.getNodeValue();
if (id != null) {
Element elem2 = document.getElementById(id);
if (null != elem2) {
NodeList synopsisNode = elem2.getElementsByTagName("synopsis"); //$NON-NLS-1$
if (null != synopsisNode && synopsisNode.getLength() > 0) {
Node synopsis = synopsisNode.item(0);
Node textNode = synopsis.getLastChild();
f.setDescription(textNode.getNodeValue());
}
}
}
} else if (kidName.equals("synopsis")) { //$NON-NLS-1$
// synopsis
Node textNode = kid.getLastChild();
f.setDescription(textNode.getNodeValue());
}
}
return f;
}
@Override
protected LibHoverInfo doGenerate() {
LibHoverInfo hoverInfo = new LibHoverInfo();
NodeList nl = document.getElementsByTagName("construct"); //$NON-NLS-1$
for (int i = 0; i < nl.getLength(); ++i) {
Node n = nl.item(i);
NamedNodeMap m = n.getAttributes();
Node id = m.getNamedItem("id"); //$NON-NLS-1$
if (id != null && id.getNodeValue().startsWith("function-")) { //$NON-NLS-1$
String name = id.getNodeValue().substring(9);
NodeList nl2 = n.getChildNodes();
for (int j = 0; j < nl2.getLength(); ++j) {
Node n2 = nl2.item(j);
if (n2.getNodeName().equals("function")) { //$NON-NLS-1$
FunctionInfo f = getFunctionInfoFromNode(name, n2, document);
hoverInfo.functions.put(name, f);
}
}
}
}
return hoverInfo;
}
}
|