|
6 | 6 | */ |
7 | 7 | package com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.atoms; |
8 | 8 |
|
9 | | -import com.google.common.collect.Lists; |
10 | | -import com.intellij.codeInsight.lookup.LookupElement; |
11 | 9 | import com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.elements.CypherBuiltInFunctionElement; |
12 | 10 | import com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.elements.InvokableInformation; |
13 | 11 |
|
14 | | -import java.util.ArrayList; |
15 | 12 | import java.util.List; |
16 | 13 | import java.util.stream.Collectors; |
17 | 14 |
|
18 | 15 | public final class CypherBuiltInFunctions { |
19 | 16 |
|
20 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_PREDICATE = Lists.newArrayList( |
21 | | - element("all", "(variable IN list WHERE predicate :: ANY)", CypherSimpleType.BOOLEAN), |
22 | | - element("any", "(variable IN list WHERE predicate :: ANY)", CypherSimpleType.BOOLEAN), |
23 | | - element("none", "(variable in list WHERE predicate :: ANY)", CypherSimpleType.BOOLEAN), |
24 | | - element("single", "(variable in list WHERE predicate :: ANY)", CypherSimpleType.BOOLEAN), |
25 | | - element("exists", "(pattern :: ANY)", CypherSimpleType.BOOLEAN), |
26 | | - element("exists", "(property :: ANY)", CypherSimpleType.BOOLEAN) |
27 | | - ); |
28 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_SHORTEST_PATH = Lists.newArrayList( |
| 17 | + public static final List<CypherBuiltInFunctionElement> FUNCTIONS = List.of( |
29 | 18 | element("shortestPath", "(pattern :: PATH)", CypherSimpleType.PATH), |
30 | | - element("allShortestPaths", "(pattern :: PATH)", CypherList.of(CypherSimpleType.PATH)) |
31 | | - ); |
32 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_SCALAR = Lists.newArrayList( |
33 | | - element("size", "(list :: LIST OF ANY)", CypherSimpleType.INTEGER), |
34 | | - element("size", "(pattern :: PATH)", CypherSimpleType.INTEGER), |
35 | | - element("size", "(string :: STRING)", CypherSimpleType.INTEGER), |
36 | | - element("length", "(path :: ANY)", CypherSimpleType.INTEGER), |
37 | | - element("length", "(string :: STRING)", CypherSimpleType.INTEGER), |
38 | | - element("type", "(relationship :: RELATIONSHIP)", CypherSimpleType.STRING), |
39 | | - element("id", "(node :: NODE)", CypherSimpleType.INTEGER), |
40 | | - element("id", "(relationship :: RELATIONSHIP)", CypherSimpleType.INTEGER), |
41 | | - element("coalesce", "(expression... :: ANY)", CypherSimpleType.ANY), |
42 | | - element("head", "(expression :: LIST OF ANY)", CypherSimpleType.ANY), |
43 | | - element("last", "(expression :: LIST OF ANY)", CypherSimpleType.ANY), |
| 19 | + element("allShortestPaths", "(pattern :: PATH)", CypherList.of(CypherSimpleType.PATH)), |
44 | 20 | element("timestamp", "()", CypherSimpleType.INTEGER), |
45 | | - element("startNode", "(relationship :: RELATIONSHIP)", CypherSimpleType.NODE), |
46 | | - element("endNode", "(relationship :: RELATIONSHIP)", CypherSimpleType.NODE), |
47 | | - element("properties", "(node :: NODE)", CypherSimpleType.MAP), |
48 | | - element("properties", "(relationship :: RELATIONSHIP)", CypherSimpleType.MAP), |
49 | | - element("toInt", "(expression :: STRING)", CypherSimpleType.INTEGER), |
50 | | - element("toFloat", "(expression :: STRING)", CypherSimpleType.FLOAT) |
51 | | - ); |
52 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_LIST = Lists.newArrayList( |
53 | | - element("nodes", "(path :: PATH)", CypherList.of(CypherSimpleType.NODE)), |
54 | | - element("relationships", "(path :: PATH)", CypherList.of(CypherSimpleType.RELATIONSHIP)), |
55 | | - element("labels", "(node :: NODE)", CypherList.of(CypherSimpleType.STRING)), |
56 | | - element("keys", "(node :: NODE)", CypherList.of(CypherSimpleType.STRING)), |
57 | | - element("keys", "(relationship :: RELATIONSHIP)", CypherList.of(CypherSimpleType.STRING)), |
58 | | - element("extract", "(variable IN list | expression :: ANY)", CypherList.of(CypherSimpleType.ANY)), |
59 | | - element("filter", "(variable IN list WHERE predicate :: ANY)", CypherList.of(CypherSimpleType.ANY)), |
60 | | - element("tail", "(expression :: LIST OF ANY)", CypherList.of(CypherSimpleType.ANY)), |
61 | | - element("range", "(start :: INTEGER, end :: INTEGER, step = 1 :: INTEGER)", CypherList.of(CypherSimpleType.INTEGER)), |
62 | | - element("reduce", "(accumulator = initial :: ANY, variable IN list | expression :: ANY)", CypherSimpleType.ANY) |
63 | | - ); |
64 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_MATH_NUMERIC = Lists.newArrayList( |
65 | | - element("abs", "(expression :: NUMBER)", CypherSimpleType.INTEGER), |
66 | | - element("ceil", "(expression :: NUMBER)", CypherSimpleType.INTEGER), |
67 | | - element("floor", "(expression :: NUMBER)", CypherSimpleType.INTEGER), |
68 | | - element("round", "(expression :: NUMBER)", CypherSimpleType.INTEGER), |
69 | | - element("sign", "(expression :: NUMBER)", CypherSimpleType.INTEGER), |
70 | | - element("rand", "()", CypherSimpleType.FLOAT) |
71 | | - ); |
72 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_MATH_LOGARITHMIC = Lists.newArrayList( |
73 | | - element("log", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
74 | | - element("log10", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
75 | | - element("exp", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
76 | | - element("e", "()", CypherSimpleType.FLOAT), |
77 | | - element("sqrt", "(expression :: NUMBER)", CypherSimpleType.FLOAT) |
78 | | - ); |
79 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_MATH_TRIGONOMETRIC = Lists.newArrayList( |
80 | | - element("sin", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
81 | | - element("cos", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
82 | | - element("tan", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
83 | | - element("cot", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
84 | | - element("asin", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
85 | | - element("acos", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
86 | | - element("atan", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
87 | | - element("atan2", "(expression :: NUMBER, expression :: NUMBER)", CypherSimpleType.FLOAT), |
88 | | - element("pi", "()", CypherSimpleType.FLOAT), |
89 | | - element("degrees", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
90 | | - element("radians", "(expression :: NUMBER)", CypherSimpleType.FLOAT), |
91 | | - element("haversin", "(expression :: NUMBER)", CypherSimpleType.FLOAT) |
| 21 | + element("coalesce", "(expression... :: ANY)", CypherSimpleType.ANY) |
92 | 22 | ); |
93 | | - private static final List<CypherBuiltInFunctionElement> FUNCTIONS_STRING = Lists.newArrayList( |
94 | | - element("replace", "(original :: STRING, search :: STRING, replace :: STRING)", CypherSimpleType.STRING), |
95 | | - element("substring", "(original :: STRING, start :: INTEGER)", CypherSimpleType.STRING), |
96 | | - element("substring", "(original :: STRING, start :: INTEGER, length = length(original) :: INTEGER)", CypherSimpleType.STRING), |
97 | | - element("left", "(original :: STRING, length :: INTEGER)", CypherSimpleType.STRING), |
98 | | - element("right", "(original :: STRING, length :: INTEGER)", CypherSimpleType.STRING), |
99 | | - element("ltrim", "(original :: STRING)", CypherSimpleType.STRING), |
100 | | - element("rtrim", "(original :: STRING)", CypherSimpleType.STRING), |
101 | | - element("trim", "(original :: STRING)", CypherSimpleType.STRING), |
102 | | - element("lower", "(original :: STRING)", CypherSimpleType.STRING), |
103 | | - element("upper", "(original :: STRING)", CypherSimpleType.STRING), |
104 | | - element("split", "(original :: STRING, splitPattern :: STRING)", CypherList.of(CypherSimpleType.STRING)), |
105 | | - element("reverse", "(original :: STRING)", CypherSimpleType.STRING), |
106 | | - element("toString", "(expression :: STRING)", CypherSimpleType.STRING) |
107 | | - ); |
108 | | - |
109 | | - public static final List<CypherBuiltInFunctionElement> FUNCTIONS = new ArrayList<>() {{ |
110 | | - addAll(FUNCTIONS_PREDICATE); |
111 | | - addAll(FUNCTIONS_SHORTEST_PATH); |
112 | | - addAll(FUNCTIONS_SCALAR); |
113 | | - addAll(FUNCTIONS_LIST); |
114 | | - addAll(FUNCTIONS_MATH_NUMERIC); |
115 | | - addAll(FUNCTIONS_MATH_LOGARITHMIC); |
116 | | - addAll(FUNCTIONS_MATH_TRIGONOMETRIC); |
117 | | - addAll(FUNCTIONS_STRING); |
118 | | - }}; |
119 | | - |
120 | | - public static final List<LookupElement> FUNCTION_LOOKUP_ELEMENTS = FUNCTIONS.stream() |
121 | | - .map(CypherBuiltInFunctionElement::getLookupElement) |
122 | | - .collect(Collectors.toList()); |
123 | 23 |
|
124 | 24 | public static final List<String> FUNCTION_NAMES = FUNCTIONS.stream() |
125 | 25 | .map(CypherBuiltInFunctionElement::getInvokable) |
|
0 commit comments