• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / VerveineJ / 16717510835

04 Aug 2025 08:03AM UTC coverage: 50.9% (-0.1%) from 51.019%
16717510835

push

github

web-flow
Merge pull request #157 from moosetechnology/issue/156

fix issue #156 + added a test for it

1908 of 3964 branches covered (48.13%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

13 existing lines in 1 file now uncovered.

4283 of 8199 relevant lines covered (52.24%)

2.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.38
/app/src/main/java/fr/inria/verveine/extractor/java/FamixRequestor.java
1
package fr.inria.verveine.extractor.java;
2

3
import java.io.File;
4
import java.util.HashMap;
5
import java.util.Map;
6

7
import fr.inria.verveine.extractor.java.visitors.refvisitors.*;
8
import org.eclipse.jdt.core.dom.CompilationUnit;
9
import org.eclipse.jdt.core.dom.FileASTRequestor;
10

11
import ch.akuhn.fame.Repository;
12
import fr.inria.verveine.extractor.java.visitors.defvisitors.VisitorClassMethodDef;
13
import fr.inria.verveine.extractor.java.visitors.defvisitors.VisitorComments;
14
import fr.inria.verveine.extractor.java.visitors.defvisitors.VisitorPackageDef;
15
import fr.inria.verveine.extractor.java.visitors.defvisitors.VisitorVarsDef;
16

17
public class FamixRequestor extends FileASTRequestor {
18

19
        protected EntityDictionary famixDictionnary;
20

21
        protected VerveineJOptions options;
22
        
23
        /**
24
         * Maps the arguments (file names or dir names) to their absolute path (well actually it is the other way around)
25
         */
26
        protected Map<String, String> dirMap;
27
        protected Map<String, String> fileMap;
28

29
        public FamixRequestor(Repository famixRepo, VerveineJOptions options) {
30
                super();
2✔
31

32
                this.options = options;
3✔
33
                initFileMaps(options);
3✔
34
                this.famixDictionnary = new EntityDictionary(famixRepo);
6✔
35
        }
1✔
36

37
        protected void initFileMaps(VerveineJOptions options) {
38
                this.fileMap = new HashMap<String, String>();
5✔
39
                // initialization of the Map with the absolute paths
40
                for (String tempArgFile : options.argFiles)
11✔
41
                        this.fileMap.put(new File(tempArgFile).getAbsolutePath(), tempArgFile);
11✔
42

43
                this.dirMap = new HashMap<String, String>();
5✔
44
                // initialization of the Map with the absolute paths
45
                for (String tempArgDir : options.argPath) {
11✔
46
                        this.dirMap.put(new File(tempArgDir).getAbsolutePath(), tempArgDir);
10✔
47
                }
1✔
48
        }
1✔
49

50
        public void acceptAST(String sourceFilePath, CompilationUnit ast) {
51
                String path = relativePath(sourceFilePath);
4✔
52
                System.out.println("Processing file: " + path);
4✔
53

54
                ast.setProperty(EntityDictionary.SOURCE_FILENAME_PROPERTY, path);
4✔
55
                try {
56
                        ast.accept(new VisitorPackageDef(famixDictionnary, options));
9✔
57
                        ast.accept(new VisitorClassMethodDef(famixDictionnary, options));
9✔
58
                        
59
                        ast.accept(new VisitorVarsDef(famixDictionnary, options));
9✔
60
                        ast.accept(new VisitorComments(famixDictionnary, options));
9✔
61

62
                        ast.accept(new VisitorInheritanceRef(famixDictionnary, options));
9✔
63
                        ast.accept(new VisitorTypeRefRef(famixDictionnary, options));
9✔
64
                        ast.accept(new VisitorAccessRef(famixDictionnary, options));
9✔
65
                        ast.accept(new VisitorInvocRef(famixDictionnary, options));
9✔
66
                        ast.accept(new VisitorAnnotationRef(famixDictionnary, options));
9✔
67
                        ast.accept(new VisitorExceptionRef(famixDictionnary, options));
9✔
68

UNCOV
69
                } catch (Exception err) {
×
UNCOV
70
                        err.printStackTrace();
×
UNCOV
71
                        System.err.println("*** " + getVisitorName(err, path) + " got exception: '" + err + "' while processing file: " + path);
×
72
                }
1✔
73
        }
1✔
74

75
        private String getVisitorName(Exception err, String path) {
UNCOV
76
                String visitorName = "";
×
UNCOV
77
                StackTraceElement[] stack = err.getStackTrace();
×
UNCOV
78
                if (stack.length == 0) {
×
79
                        return "Unknown Class";
×
80
                }
81

UNCOV
82
                for (int i = 0; (! visitorName.startsWith("Visitor")) && (i < stack.length); i++) {
×
UNCOV
83
                        visitorName = stack[i].getClassName() + ":" + stack[i].getLineNumber();
×
UNCOV
84
                        int dot = visitorName.lastIndexOf('.');
×
UNCOV
85
                        if (dot > 0) {
×
UNCOV
86
                                visitorName = visitorName.substring(dot + 1);
×
87
                        }
88

89
                }
UNCOV
90
                if (visitorName.startsWith("Visitor")) {
×
UNCOV
91
                        return visitorName;
×
92
                }
93
                else {
94
                        return stack[0].getClassName();  // did not find the Visitor in the stack, return the top frame
×
95
                }
96
        }
97

98
        /**
99
         * Search in the program args the corresponding path of the provided fileAbsolutePath
100
         * @param fileAbsolutePath the absolute path of a parsed file
101
         * @return the path of the same file relative to the appropriate verveinej argument
102
         */
103
        private String relativePath(String fileAbsolutePath) {
104
                File file = new File(fileAbsolutePath);
5✔
105
                String fullPath = file.getAbsolutePath();
3✔
106

107
                if (this.fileMap.containsKey(fullPath)) {
5✔
108
                        // parsed file was an argument of verveinej, return the path that was given as argument
109
                        return this.fileMap.get(fullPath);
6✔
110
                }
111

112
                // file belongs to a directory that was a verveinej arg
113
                // need to find back this arg
114
                while (file != null) {
2!
115
                        String key = file.getAbsolutePath();
3✔
116

117
                        if (this.dirMap.containsKey(key)) {
5✔
118
                                // relative path = verveineJ arg + local-path-to-the-file
119
                                if (!this.dirMap.get(key).endsWith(File.separator))
8✔
120
                                        return this.dirMap.get(key) + "/" + fullPath.substring(key.length() + 1);
13✔
121
                                else
122
                                        return this.dirMap.get(key) + fullPath.substring(key.length() + 1);
13✔
123
                        } else
124
                                file = file.getParentFile();
3✔
125
                }
1✔
126
                return fullPath;
×
127
        }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc