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