-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjavaTokens.test.js
131 lines (121 loc) · 3.52 KB
/
javaTokens.test.js
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
import {JavaTokens} from './javaTokens.js';
describe('javaTokens.js', () => {
const config = {collect: ['unannType']};
it('returns an empty array on empty input', () => {
const visitor = new JavaTokens('', config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([]);
})
it('returns method result type', () => {
const source = `
public class HelloWorldExample {
private ReturnType methodName() {
}
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"ReturnType"
]);
})
it('returns method parameters type', () => {
const source = `
public class HelloWorldExample {
private void methodName(ParameterType parameter1, T parameter2) {
}
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"ParameterType",
"T"
]);
})
it('returns local variables type', () => {
const source = `
public class HelloWorldExample {
private void methodName() {
VariableType variable = new VariableInstanceType(parameter1);
List<TypeParameter> list = null;
var variable = new String();
}
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"VariableType",
"TypeParameter",
"var"
]);
})
it('returns lambda parameter type', () => {
const source = `
public class HelloWorldExample {
private void methodName() {
var list = (Truc x) -> {return new Bidule(x.p());};
}
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"var",
"Truc"
]);
})
it('returns instance variables type', () => {
const source = `
public class HelloWorldExample {
private InstanceVariable toto = new InstanceTruc();
private void methodName() {}
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"InstanceVariable"
]);
})
it('returns class variables type', () => {
const source = `
public class HelloWorldExample {
private static ClassVariable toto = new ClassTruc();
private void methodName() {}
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"ClassVariable"
]);
})
it('returns innermost type parameters', () => {
const source = `
public class HelloWorldExample {
private static ParamType<Type1, ParamType<Type2>> toto = null;
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"Type1",
"Type2"
]);
})
it('returns type parameters bound', () => {
const source = `
public class HelloWorldExample {
private static ParamType<? super Type1, ParamType<? extends Type2>> toto = null;
}
`
const visitor = new JavaTokens(source, config);
const identifiers = visitor.parse();
expect(identifiers).toEqual([
"Type2",
"Type1"
]);
})
})