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

moosetechnology / VerveineJ / 20030877272

08 Dec 2025 02:07PM UTC coverage: 50.923% (-0.07%) from 50.991%
20030877272

Pull #178

github

web-flow
Merge 8fac9388f into ccd766c89
Pull Request #178: Some cleanings

1898 of 3934 branches covered (48.25%)

Branch coverage included in aggregate %.

90 of 105 new or added lines in 7 files covered. (85.71%)

2 existing lines in 2 files now uncovered.

4255 of 8149 relevant lines covered (52.21%)

2.11 hits per line

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

85.19
/app/src/main/java/fr/inria/verveine/extractor/java/VerveineJParser.java
1
package fr.inria.verveine.extractor.java;
2

3
import ch.akuhn.fame.Repository;
4
import ch.akuhn.fame.internal.RepositoryVisitor.UnknownElementError;
5
import fr.inria.verveine.extractor.java.utils.Util;
6

7
import org.eclipse.jdt.core.dom.AST;
8
import org.eclipse.jdt.core.dom.ASTParser;
9
import org.moosetechnology.model.famix.famixjavaentities.Entity;
10
import org.moosetechnology.model.famix.famixjavaentities.FamixJavaEntitiesModel;
11
import org.moosetechnology.model.famix.famixjavaentities.Package;
12
import org.moosetechnology.model.famix.famixjavaentities.SourceLanguage;
13
import org.moosetechnology.model.famix.famixreplication.FamixReplicationModel;
14
import org.moosetechnology.model.famix.famixtraits.FamixTraitsModel;
15
import org.moosetechnology.model.famix.moose.MooseModel;
16
import org.moosetechnology.model.famix.moosequery.MooseQueryModel;
17
import org.moosetechnology.model.famix.tagging.TaggingModel;
18

19
import java.io.*;
20
import java.nio.charset.StandardCharsets;
21
import java.util.Collection;
22

23
/**
24
 * A batch parser inspired from org.eclipse.jdt.internal.compiler.batch.Main (JDT-3.6)
25
 * run with:
26
 * java -cp lib/org.eclipse.jdt.core_3.6.0.v_A48.jar:../Fame:/usr/local/share/eclipse/plugins/org.eclipse.equinox.common_3.5.1.R35x_v20090807-1100.jar:/usr/local/share/eclipse/plugins/org.eclipse.equinox.preferences_3.2.301.R35x_v20091117.jar:/usr/local/share/eclipse/plugins/org.eclipse.core.jobs_3.4.100.v20090429-1800.jar:/usr/local/share/eclipse/plugins/org.eclipse.core.contenttype_3.4.1.R35x_v20090826-0451.jar:/usr/local/share/eclipse/plugins/org.eclipse.core.resources_3.5.2.R35x_v20091203-1235.jar:/usr/local/share/eclipse/plugins/org.eclipse.core.runtime_3.5.0.v20090525.jar:/usr/local/share/eclipse/plugins/org.eclipse.osgi_3.5.2.R35x_v20100126.jar:../Fame/lib/akuhn-util-r28011.jar:lib/fame.jar:bin eu.synectique.verveine.extractor.java.VerveineJParser [files|directory]_to_parse
27
 */
28

29
public class VerveineJParser {
30

31
        public VerveineJOptions options;
32

33
        /**
34
         * Java parser, provided by JDT
35
         */
36
        protected ASTParser jdtParser;
37

38
        /**
39
         * Famix repository where the entities are stored
40
         */
41
        protected Repository famixRepo;
42

43
        public VerveineJParser() {
2✔
44
                this.setFamixRepo(new Repository(FamixJavaEntitiesModel.metamodel()));
6✔
45
                FamixReplicationModel.importInto(this.getFamixRepo().getMetamodel());
4✔
46
                FamixTraitsModel.importInto(this.getFamixRepo().getMetamodel());
4✔
47
                MooseModel.importInto(this.getFamixRepo().getMetamodel());
4✔
48
                MooseQueryModel.importInto(this.getFamixRepo().getMetamodel());
4✔
49
                TaggingModel.importInto(this.getFamixRepo().getMetamodel());
4✔
50

51

52
                options = new VerveineJOptions();
5✔
53
                jdtParser = ASTParser.newParser(AST.JLS23);
4✔
54
        }
1✔
55

56
        public void configure(String[] args) {
57
                options.setOptions(args);
4✔
58
                options.configureJDTParser(jdtParser);
5✔
59
        }
1✔
60

61
        protected SourceLanguage getMyLgge() {
62
                return new SourceLanguage();
4✔
63
        }
64

65
        public void parse() {
66

67
                if (this.linkToExisting()) {
3✔
68
                        this.expandPackagesNames();
2✔
69
                }
70

71
                FamixRequestor req = new FamixRequestor(getFamixRepo(), options);
8✔
72

73
                Util.metamodel = this.getFamixRepo().getMetamodel();
4✔
74
                try {
75
                        jdtParser.createASTs(
5✔
76
                                        options.sourceFilesToParse(),
6✔
77
                                        /*encodings*/null,
78
                                        /*bindingKeys*/new String[0],
79
                                        /*requestor*/req,
80
                                        /*monitor*/null);
81
                } catch (java.lang.IllegalStateException e) {
×
82
                        System.out.println("VerveineJ could not launch parser, received error: " + e.getMessage());
×
83
                }
1✔
84

85
                this.compressPackagesNames();
2✔
86
        }
1✔
87

88
        /**
89
         * As explained in EntityDictionary, Namespaces are created with their fully qualified name.
90
         * We need now to give them their simple name
91
         */
92
        protected void compressPackagesNames() {
93
                for (Package ns : listAll(Package.class)) {
12✔
94
                        String name = ns.getName();
3✔
95
                        int last = name.lastIndexOf('.');
4✔
96
                        if (last >= 0) {
2✔
97
                                ns.setName(name.substring(last + 1));
7✔
98
                        }
99
                }
1✔
100
        }
1✔
101

102
        /**
103
         * @see VerveineJParser#compressPackagesNames()
104
         */
105
        protected void expandPackagesNames() {
106
                for (Package ns : listAll(Package.class)) {
12✔
107
                        expandPackageName(ns);
3✔
108
                }
1✔
109
        }
1✔
110

111
        protected void expandPackageName(Package ns) {
112
                String name = ns.getName();
3✔
113
                if (name.indexOf('.') <= 0) {
4✔
114
                        Package parent = (Package) ns.getParentPackage();
4✔
115
                        if (parent != null)  {
2✔
116
                                expandPackageName(parent);
3✔
117
                                ns.setName(parent.getName() + "." + ns.getName());
7✔
118
                        }
119
                }
120
        }
1✔
121

122
        protected boolean linkToExisting() {
123
                if (!this.options.incrementalParsing) {
4✔
124
                        return false;
2✔
125
                }
126

127
                File existingMSE = new File(options.getOutputFileName());
7✔
128
                if (existingMSE.exists()) {
3✔
129
                        this.getFamixRepo().importMSEFile(options.getOutputFileName());
6✔
130
                        return true;
2✔
131
                } else {
132
                        return false;
2✔
133
                }
134
        }
135

136
        /**
137
         * Outputs repository to a file
138
         */
139
        public void exportModel() {
140
                this.exportModel(this.options.outputFileName);
5✔
141
        }
1✔
142

143
        public void exportModel(String outputFile) {
144
                try {
145
                        exportModel(new FileOutputStream(outputFile));
6✔
146
                } catch (FileNotFoundException e) {
×
147
                        e.printStackTrace();
×
148
                }
1✔
149
        }
1✔
150

151
        /**
152
         * Outputs the repository to an opened Stream according to the format in options
153
         * also add to it a SourceLanguage entity if there is none.
154
         * The SourceLanguage entity is the one returned by getMyLgge().
155
         *
156
         * @param output
157
         */
158
        public void exportModel(OutputStream output) {
159
                // Adds default SourceLanguage for the repository
160
                if ((listAll(SourceLanguage.class).size() == 0) && (getMyLgge() != null)) {
8!
161
                        getFamixRepo().add(getMyLgge());
5✔
162
                }
163

164
                // Outputting to a file
165
                try {
166
                        Writer writer = new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
9✔
167
                        if (this.options.outputFormat.equalsIgnoreCase(VerveineJOptions.MSE_OUTPUT_FORMAT)) {
6✔
168
                                try {
169
                                        famixRepo.exportMSE(writer);
4✔
170
                                }
171
                                catch (UnknownElementError err) {
×
172
                            System.err.println("** UnknownElementException while exporting Famix repository.\n" +
×
173
                                            "  This might happen when an entity inside the repository refers to an entity outside the repository\n");
174
                            if (options.withDebug()) {
×
175
                                    Util.traceUnknownElementError(err);
×
176
                            }
177
                                }
1✔
178
                        } else if (this.options.outputFormat.equalsIgnoreCase(VerveineJOptions.JSON_OUTPUT_FORMAT)) {
6!
179
                                if (this.options.prettyPrint) {
4!
180
                                        famixRepo.exportPrettyJSON(writer);
×
181
                                } else {
182
                                        famixRepo.exportJSON(writer);
4✔
183
                                }
184
                        }
185
                        writer.close();
2✔
NEW
186
                } catch (IOException | UnknownElementError e) {
×
187
                        e.printStackTrace();
×
188
                }
1✔
189
    }
1✔
190

191
        /**
192
         * Returns a Collection of all FAMIXEntities in the repository of the given fmxClass
193
         */
194
        public <T extends Entity> Collection<T> listAll(Class<T> fmxClass) {
195
                return getFamixRepo().all(fmxClass);
5✔
196
        }
197

198
        public Repository getFamixRepo() {
199
                return famixRepo;
3✔
200
        }
201

202
        public void setFamixRepo(Repository famixRepo) {
203
                this.famixRepo = famixRepo;
3✔
204
        }
1✔
205

206
}
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