@@ -14,27 +14,43 @@ const (
1414 ExtJava = ".java"
1515)
1616
17- // findJavaFile finds a java file in a vcs repository.
18- func (ff FileFinder ) findJavaFile (ctx context.Context , mappings ... * config.MappingConfig ) (* vcsv1.GetFileResponse , error ) {
19- sp , ctx := opentracing .StartSpanFromContext (ctx , "findJavaFile" )
20- defer sp .Finish ()
21- sp .SetTag ("file.function_name" , ff .file .FunctionName )
22- sp .SetTag ("file.path" , ff .file .Path )
23-
24- pathSegments := strings .Split (ff .file .FunctionName , "/" )
17+ func convertJavaFunctionNameToPath (functionName string ) string {
18+ pathSegments := strings .Split (functionName , "/" )
2519 last := len (pathSegments ) - 1
2620
21+ // pos to cut from
22+ pos := - 1
23+ updatePos := func (v int ) {
24+ if v != - 1 {
25+ return
26+ }
27+ if pos == - 1 || pos > v {
28+ pos = v
29+ }
30+ }
31+
2732 // find first dot in last segment
28- posDot := strings .Index (pathSegments [last ], "." )
29- if posDot > 0 {
30- pathSegments [last ] = pathSegments [last ][:posDot ]
33+ updatePos (strings .Index (pathSegments [last ], "." ))
34+
35+ // find first $ in last segment
36+ updatePos (strings .Index (pathSegments [last ], "$" ))
37+
38+ if pos > 0 {
39+ pathSegments [last ] = pathSegments [last ][:pos ]
3140 }
32- // TODO: treat $$
3341
3442 pathSegments [last ] = pathSegments [last ] + ExtJava
43+ return strings .Join (pathSegments , "/" )
44+ }
3545
36- javaPath := strings .Join (pathSegments , "/" )
46+ // findJavaFile finds a java file in a vcs repository.
47+ func (ff FileFinder ) findJavaFile (ctx context.Context , mappings ... * config.MappingConfig ) (* vcsv1.GetFileResponse , error ) {
48+ sp , ctx := opentracing .StartSpanFromContext (ctx , "findJavaFile" )
49+ defer sp .Finish ()
50+ sp .SetTag ("file.function_name" , ff .file .FunctionName )
51+ sp .SetTag ("file.path" , ff .file .Path )
3752
53+ javaPath := convertJavaFunctionNameToPath (ff .file .FunctionName )
3854 for _ , m := range mappings {
3955 return ff .fetchMappingFile (ctx , m , javaPath )
4056 }
0 commit comments