-
Notifications
You must be signed in to change notification settings - Fork 1
/
Notes
42 lines (36 loc) · 1.18 KB
/
Notes
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
Old methods from CompilationTree, need verification
====================================================
static int findReferencesFor(QualifiedType qualifiedType) {
int references = 0
findReferencesFor(qualifiedType, { references++ })
return references
}
static int countMethodInvocations(QualifiedType qualifiedType, Collection<String> methods) {
int calls = 0
findReferencesFor(qualifiedType, {
calls = ASTHelper.getChildNodesByType(it, MethodCallExpr.class)
.stream()
.filter { methods.contains(it.name) }
.mapToInt { 1 }
.sum()
})
return calls
}
static void findReferencesFor(QualifiedType qualifiedType, Consumer<CompilationUnit> code) {
def walker = getJavaFilteredFileStream()
walker.forEach {
getCompilationUnit(it)
.ifPresent {
List<ImportDeclaration> imports = it.imports
Optional<ImportDeclaration> maybeImport = imports.stream()
.filter { it.name.toStringWithoutComments() == qualifiedType.name }
.findFirst()
if (maybeImport.isPresent()) {
code.accept(it)
} else if (TypeHelper.isTypePresentInCompilationUnit(it, qualifiedType)) {
code.accept(it)
}
}
}
StreamCloser.quietly(walker)
}