Skip to content

Package: ObjectModel

ObjectModel

nameinstructionbranchcomplexitylinemethod
ObjectModel(JCodeModel)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getCodeModel()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
writeModel(String)
M: 8 C: 27
77%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 3 C: 7
70%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.owl2java;
16:
17: import com.sun.codemodel.CodeWriter;
18: import com.sun.codemodel.JCodeModel;
19: import com.sun.codemodel.writer.FileCodeWriter;
20: import org.slf4j.Logger;
21: import org.slf4j.LoggerFactory;
22:
23: import java.io.File;
24: import java.io.IOException;
25: import java.nio.charset.StandardCharsets;
26:
27: /**
28: * Wraps the generated object model, allowing to access it in memory or write it out to the file system.
29: */
30: class ObjectModel {
31:
32: private static final Logger LOG = LoggerFactory.getLogger(ObjectModel.class);
33:
34: private final JCodeModel codeModel;
35:
36: ObjectModel(JCodeModel codeModel) {
37: this.codeModel = codeModel;
38: }
39:
40: JCodeModel getCodeModel() {
41: return codeModel;
42: }
43:
44: /**
45: * Writes out the object model.
46: *
47: * @param targetDir Target directory for the object model
48: */
49: void writeModel(String targetDir) {
50: try {
51: final File file = new File(targetDir);
52: final boolean result = file.mkdirs();
53:• if (!result && !file.exists()) {
54: LOG.error("Unable to create target directory structure.");
55: }
56: // Explicitly use UTF-8 encoding to prevent issues with character encoding on different platforms
57: final CodeWriter writer = new FileCodeWriter(file, false, StandardCharsets.UTF_8.toString());
58: codeModel.build(writer);
59: } catch (IOException e) {
60: LOG.error("Unable to write out the generated object model.", e);
61: }
62: }
63: }