1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.query.xwql.internal; |
21 |
|
|
22 |
|
import org.apache.commons.lang3.StringUtils; |
23 |
|
import org.xwiki.query.jpql.analysis.DepthFirstAdapter; |
24 |
|
import org.xwiki.query.jpql.node.AAbstractSchemaName; |
25 |
|
import org.xwiki.query.jpql.node.APath; |
26 |
|
import org.xwiki.query.jpql.node.ARangeVariableDeclaration; |
27 |
|
import org.xwiki.query.jpql.node.ASelectStatement; |
28 |
|
import org.xwiki.query.jpql.node.AXObjectDecl; |
29 |
|
import org.xwiki.query.jpql.node.AXPath; |
30 |
|
|
31 |
|
|
32 |
|
@version |
33 |
|
@since |
34 |
|
|
|
|
| 92% |
Uncovered Elements: 4 (50) |
Complexity: 18 |
Complexity Density: 0.6 |
|
35 |
|
public class QueryAnalyzer extends DepthFirstAdapter |
36 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
1032 |
public QueryAnalyzer(QueryContext context)... |
38 |
|
{ |
39 |
1032 |
this.context = context; |
40 |
|
} |
41 |
|
|
42 |
|
QueryContext context; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
44 |
1032 |
@Override... |
45 |
|
public void outASelectStatement(ASelectStatement node) |
46 |
|
{ |
47 |
|
|
48 |
1032 |
node.getSelectClause().apply(this); |
49 |
1032 |
super.outASelectStatement(node); |
50 |
|
} |
51 |
|
|
52 |
|
String documentFromName = "Document"; |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
54 |
1077 |
@Override... |
55 |
|
public void caseAAbstractSchemaName(AAbstractSchemaName node) |
56 |
|
{ |
57 |
1077 |
String from = node.toString().trim(); |
58 |
1077 |
String alias = ((ARangeVariableDeclaration) node.parent()).getVariable().toString().trim(); |
59 |
1077 |
if (documentFromName.equals(from)) { |
60 |
419 |
context.addDocument(alias); |
61 |
|
} |
62 |
|
} |
63 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
64 |
397 |
@Override... |
65 |
|
public void caseAXObjectDecl(AXObjectDecl node) |
66 |
|
{ |
67 |
397 |
String path[] = splitPath(node.getId().toString()); |
68 |
397 |
if (path.length != 2) { |
69 |
0 |
throw new InvalidQueryException("docalias.object('classname') expected, but got:" + node.toString()); |
70 |
|
} |
71 |
397 |
String docalias = path[0]; |
72 |
397 |
String method = path[1]; |
73 |
397 |
String className = unquote(node.getXClassName().toString().trim()); |
74 |
|
|
75 |
397 |
String alias = node.parent().parent() instanceof ARangeVariableDeclaration |
76 |
|
|
77 |
|
? ((ARangeVariableDeclaration) node.parent().parent()).getVariable().toString().trim() |
78 |
|
|
79 |
|
: null; |
80 |
|
|
81 |
397 |
if ("object".equals(method)) { |
82 |
397 |
context.addObject(docalias, className, alias, node); |
83 |
|
} else { |
84 |
0 |
throw new InvalidQueryException("document's method + [" + method + "] is unsupported"); |
85 |
|
} |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
88 |
5135 |
@Override... |
89 |
|
public void caseAPath(APath node) |
90 |
|
{ |
91 |
5135 |
String path[] = splitPath(node.toString()); |
92 |
5135 |
QueryContext.ObjectInfo obj = context.getObject(path[0]); |
93 |
5135 |
if (path.length >= 2 && obj != null) { |
94 |
169 |
obj.addProperty(path[1], node); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
98 |
3 |
@Override... |
99 |
|
public void outAXPath(AXPath node) |
100 |
|
{ |
101 |
3 |
QueryContext.ObjectInfo obj = context.getObject(node.getXObjectDecl()); |
102 |
3 |
String path[] = splitPath(node.getProperty().toString()); |
103 |
3 |
obj.addProperty(path[0], node); |
104 |
3 |
super.outAXPath(node); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
5535 |
public static String[] splitPath(String str)... |
108 |
|
{ |
109 |
5535 |
return StringUtils.split(str.trim(), "."); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 5 |
Complexity Density: 1.25 |
|
112 |
397 |
public static String unquote(String str)... |
113 |
|
{ |
114 |
397 |
str = str.trim(); |
115 |
397 |
if (str.startsWith("'") && str.endsWith("'") |
116 |
|
|| str.startsWith("\"") && str.endsWith("\"")) |
117 |
|
{ |
118 |
9 |
str = str.substring(1, str.length() - 1); |
119 |
|
} |
120 |
397 |
return str; |
121 |
|
} |
122 |
|
} |