Skip to content

Commit 8fe2409

Browse files
Remove unneeded hardcoded functions (#55) (#58)
Remove hardcoded definitions of several functions
1 parent ba4c363 commit 8fe2409

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+45
-1132
lines changed

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/completion/metadata/CypherMetadataProviderService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,13 @@ public interface CypherMetadataProviderService {
3737

3838
Optional<CypherProcedureElement> findProcedure(String fullName);
3939

40-
Optional<CypherFunctionElement> findFunction(String fullName);
40+
/**
41+
* Find all functions that match the given name.
42+
* The result is a collection (instead of an Optional) because
43+
* there could be multiple functions that share the same name (i.e.
44+
* method overloading)
45+
* @param fullName the name of the function
46+
* @return known functions that match the given name
47+
*/
48+
List<CypherFunctionElement> findFunctions(String fullName);
4149
}

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/completion/metadata/CypherMetadataProviderServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ public Optional<CypherProcedureElement> findProcedure(String name) {
108108
}
109109

110110
@Override
111-
public Optional<CypherFunctionElement> findFunction(String name) {
111+
public List<CypherFunctionElement> findFunctions(String name) {
112112
return sourceData.values().stream()
113113
.flatMap(container -> container.getFunctions().stream())
114114
.filter(functionElement -> functionElement.getName().equals(name))
115-
.findFirst();
115+
.collect(Collectors.toList());
116116
}
117117
}

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/completion/metadata/atoms/CypherBuiltInFunctions.java

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -6,120 +6,20 @@
66
*/
77
package com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.atoms;
88

9-
import com.google.common.collect.Lists;
10-
import com.intellij.codeInsight.lookup.LookupElement;
119
import com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.elements.CypherBuiltInFunctionElement;
1210
import com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.elements.InvokableInformation;
1311

14-
import java.util.ArrayList;
1512
import java.util.List;
1613
import java.util.stream.Collectors;
1714

1815
public final class CypherBuiltInFunctions {
1916

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(
2918
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)),
4420
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)
9222
);
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());
12323

12424
public static final List<String> FUNCTION_NAMES = FUNCTIONS.stream()
12525
.map(CypherBuiltInFunctionElement::getInvokable)

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/documentation/CypherDocumentationProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ private Optional<String> storedProcedureDocumentation(PsiElement element) {
137137
private Optional<String> functionDocumentation(PsiElement element) {
138138
if (element instanceof CypherFunctionInvocation cypherFunctionInvocation) {
139139
return getMetadataService(element)
140-
.findFunction(cypherFunctionInvocation.getFullName())
140+
.findFunctions(cypherFunctionInvocation.getFullName())
141+
.stream()
142+
.filter(f -> f.getInvokableInformation().getArguments().size() == cypherFunctionInvocation.arguments().size())
143+
144+
.findFirst()
141145
.map(CypherFunctionElement::getDocumentation);
142146
}
143147
return Optional.empty();

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/references/CypherInvocation.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package com.albertoventurini.graphdbplugin.language.cypher.references;
88

9-
109
import com.albertoventurini.graphdbplugin.language.cypher.psi.CypherFunctionArguments;
1110
import com.albertoventurini.graphdbplugin.language.cypher.psi.CypherFunctionInvocation;
1211
import com.albertoventurini.graphdbplugin.language.cypher.psi.CypherProcedureInvocation;
@@ -24,7 +23,6 @@
2423
import java.util.*;
2524

2625
import static com.albertoventurini.graphdbplugin.language.cypher.completion.metadata.atoms.CypherSimpleType.ANY;
27-
import static java.util.stream.Collectors.toList;
2826

2927
public interface CypherInvocation extends PsiElement, CypherTyped {
3028

@@ -58,24 +56,25 @@ default List<InvokableInformation> resolve() {
5856
CypherMetadataProviderService svc = getProject().getService(CypherMetadataProviderService.class);
5957
final List<InvokableInformation> matchedInvocations = new ArrayList<>();
6058

59+
final String name = getFullName();
60+
6161
if (this instanceof CypherProcedureInvocation) {
62-
svc.findProcedure(getFullName())
62+
svc.findProcedure(name)
6363
.map(CypherProcedureElement::getInvokableInformation)
6464
.ifPresent(matchedInvocations::add);
6565
return matchedInvocations;
6666
}
6767

68-
String name = getFullName();
69-
7068
matchedInvocations.addAll(CypherBuiltInFunctions.FUNCTIONS.stream()
7169
.map(CypherBuiltInFunctionElement::getInvokable)
7270
.filter(invokable -> Objects.equals(invokable.getName(), name))
73-
.collect(toList()));
71+
.toList());
7472

7573
if (matchedInvocations.isEmpty()) {
76-
svc.findFunction(getFullName())
77-
.map(CypherFunctionElement::getInvokableInformation)
78-
.ifPresent(matchedInvocations::add);
74+
matchedInvocations.addAll(svc.findFunctions(getFullName())
75+
.stream()
76+
.map(CypherFunctionElement::getInvokableInformation)
77+
.toList());
7978
}
8079
return matchedInvocations;
8180
}

language/cypher/src/main/resources/com/albertoventurini/graphdbplugin/language/cypher/documentation/database/built-in/functions/abs.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

language/cypher/src/main/resources/com/albertoventurini/graphdbplugin/language/cypher/documentation/database/built-in/functions/acos.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

language/cypher/src/main/resources/com/albertoventurini/graphdbplugin/language/cypher/documentation/database/built-in/functions/all.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

language/cypher/src/main/resources/com/albertoventurini/graphdbplugin/language/cypher/documentation/database/built-in/functions/any.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

language/cypher/src/main/resources/com/albertoventurini/graphdbplugin/language/cypher/documentation/database/built-in/functions/asin.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)