Skip to content

Commit fd6b13f

Browse files
committed
null safe
1 parent 4c42e80 commit fd6b13f

4 files changed

Lines changed: 34 additions & 22 deletions

File tree

src/main/java/com/github/_1c_syntax/bsl/reader/designer/DesignerReader.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
6868
import com.thoughtworks.xstream.io.xml.QNameMap;
6969
import lombok.Getter;
70-
import lombok.NonNull;
7170
import lombok.extern.slf4j.Slf4j;
7271
import org.apache.commons.io.FilenameUtils;
7372

@@ -98,9 +97,15 @@ public class DesignerReader implements MDReader {
9897

9998
public DesignerReader(Path path, boolean skipSupport) {
10099
xstream = createXMLMapper();
101-
var file = path.toFile();
100+
var normalizedPath = path.toAbsolutePath();
101+
var file = normalizedPath.toFile();
102102
if (file.isFile() && CONFIGURATION_MDO_FILE_NAME.equals(file.getName())) { // передали сам файл, а не каталог
103-
rootPath = path.getParent();
103+
var parent = normalizedPath.getParent();
104+
if (parent == null) {
105+
throw new IllegalArgumentException(
106+
"Не удалось определить каталог конфигурации для файла " + normalizedPath);
107+
}
108+
rootPath = parent;
104109
} else {
105110
rootPath = path;
106111
}
@@ -110,13 +115,11 @@ public DesignerReader(Path path, boolean skipSupport) {
110115
}
111116

112117
@Override
113-
@NonNull
114118
public ConfigurationSource getConfigurationSource() {
115119
return ConfigurationSource.DESIGNER;
116120
}
117121

118122
@Override
119-
@NonNull
120123
public MDClass readConfiguration() {
121124
var mdc = Optional.ofNullable((MDClass) read(
122125
mdoPath(rootPath, MDOType.CONFIGURATION, MDOType.CONFIGURATION.nameEn())
@@ -125,7 +128,6 @@ public MDClass readConfiguration() {
125128
}
126129

127130
@Override
128-
@NonNull
129131
public ExternalSource readExternalSource() {
130132
var value = read(rootPath);
131133
if (value instanceof ExternalSource externalSource) {
@@ -165,7 +167,6 @@ public FormData readFormData(Path currentPath, String name, MDOType mdoType) {
165167
}
166168

167169
@Override
168-
@NonNull
169170
public Path moduleFolder(Path mdoPath, MDOType mdoType) {
170171
if (mdoType == MDOType.COMMAND) {
171172
return childrenFolder(mdoPath, mdoType);
@@ -177,7 +178,6 @@ public Path moduleFolder(Path mdoPath, MDOType mdoType) {
177178
}
178179

179180
@Override
180-
@NonNull
181181
public Path modulePath(Path folder, String name, ModuleType moduleType) {
182182
var subdirectory = "Ext";
183183

@@ -193,19 +193,16 @@ public Path modulePath(Path folder, String name, ModuleType moduleType) {
193193
}
194194

195195
@Override
196-
@NonNull
197196
public Path mdoTypeFolderPath(Path mdoPath) {
198197
return Paths.get(FilenameUtils.getFullPathNoEndSeparator(mdoPath.toString()));
199198
}
200199

201200
@Override
202-
@NonNull
203201
public String subsystemsNodeName() {
204202
return "Subsystem";
205203
}
206204

207205
@Override
208-
@NonNull
209206
public String configurationExtensionFilter() {
210207
return "(<ObjectBelonging>)";
211208
}

src/main/java/com/github/_1c_syntax/bsl/reader/designer/package-info.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@
2222
/**
2323
* Содержит ридер для формата конфигуратора
2424
*/
25+
@ParametersAreNonnullByDefault
26+
@ReturnValuesAreNonnullByDefault
2527
package com.github._1c_syntax.bsl.reader.designer;
28+
29+
import edu.umd.cs.findbugs.annotations.ReturnValuesAreNonnullByDefault;
30+
31+
import javax.annotation.ParametersAreNonnullByDefault;

src/main/java/com/github/_1c_syntax/bsl/reader/edt/EDTReader.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import com.thoughtworks.xstream.core.util.CompositeClassLoader;
6666
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
6767
import lombok.Getter;
68-
import lombok.NonNull;
6968
import lombok.extern.slf4j.Slf4j;
7069
import org.apache.commons.io.FilenameUtils;
7170

@@ -96,9 +95,21 @@ public class EDTReader implements MDReader {
9695

9796
public EDTReader(Path path, boolean skipSupport) {
9897
xstream = createXMLMapper();
99-
var file = path.toFile();
98+
var normalizedPath = path.toAbsolutePath();
99+
var file = normalizedPath.toFile();
100100
if (file.isFile() && CONFIGURATION_MDO_FILE_NAME.equals(file.getName())) { // передали сам файл, а не каталог
101-
rootPath = path.getParent().getParent().getParent();
101+
var configurationDir = normalizedPath.getParent();
102+
if (configurationDir == null) {
103+
throw new IllegalArgumentException(
104+
"Не удалось определить каталог Configuration для файла " + normalizedPath);
105+
}
106+
var srcDir = configurationDir.getParent();
107+
var projectRoot = srcDir != null ? srcDir.getParent() : null;
108+
if (srcDir == null || projectRoot == null) {
109+
throw new IllegalArgumentException(
110+
"Не удалось определить корень проекта EDT для файла " + normalizedPath);
111+
}
112+
rootPath = projectRoot;
102113
} else {
103114
rootPath = path;
104115
}
@@ -108,13 +119,11 @@ public EDTReader(Path path, boolean skipSupport) {
108119
}
109120

110121
@Override
111-
@NonNull
112122
public ConfigurationSource getConfigurationSource() {
113123
return ConfigurationSource.EDT;
114124
}
115125

116126
@Override
117-
@NonNull
118127
public MDClass readConfiguration() {
119128
var mdc = Optional.ofNullable((MDClass) read(
120129
mdoPath(rootPath, MDOType.CONFIGURATION, MDOType.CONFIGURATION.nameEn())
@@ -123,7 +132,6 @@ public MDClass readConfiguration() {
123132
}
124133

125134
@Override
126-
@NonNull
127135
public ExternalSource readExternalSource() {
128136
var value = read(rootPath);
129137
if (value instanceof ExternalSource externalSource) {
@@ -170,7 +178,6 @@ public FormData readFormData(Path currentPath, String name, MDOType mdoType) {
170178
}
171179

172180
@Override
173-
@NonNull
174181
public Path moduleFolder(Path mdoPath, MDOType mdoType) {
175182
if (mdoType == MDOType.EXTERNAL_DATA_SOURCE_TABLE) {
176183
return mdoPath.getParent().getParent();
@@ -182,7 +189,6 @@ public Path moduleFolder(Path mdoPath, MDOType mdoType) {
182189
}
183190

184191
@Override
185-
@NonNull
186192
public Path modulePath(Path folder, String name, ModuleType moduleType) {
187193
if (ModuleType.byMDOType(MDOType.CONFIGURATION).contains(moduleType)) {
188194
return Paths.get(folder.toString(), MDOType.CONFIGURATION.nameEn(), moduleType.getFileName());
@@ -191,20 +197,17 @@ public Path modulePath(Path folder, String name, ModuleType moduleType) {
191197
}
192198

193199
@Override
194-
@NonNull
195200
public Path mdoTypeFolderPath(Path mdoPath) {
196201
return Paths.get(FilenameUtils.getFullPathNoEndSeparator(
197202
FilenameUtils.getFullPathNoEndSeparator(mdoPath.toString())));
198203
}
199204

200205
@Override
201-
@NonNull
202206
public String subsystemsNodeName() {
203207
return "subsystems";
204208
}
205209

206210
@Override
207-
@NonNull
208211
public String configurationExtensionFilter() {
209212
return "(<objectBelonging>)";
210213
}

src/main/java/com/github/_1c_syntax/bsl/reader/edt/package-info.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@
2222
/**
2323
* Содержит ридер для формата ЕДТ
2424
*/
25+
@ParametersAreNonnullByDefault
26+
@ReturnValuesAreNonnullByDefault
2527
package com.github._1c_syntax.bsl.reader.edt;
28+
29+
import edu.umd.cs.findbugs.annotations.ReturnValuesAreNonnullByDefault;
30+
31+
import javax.annotation.ParametersAreNonnullByDefault;

0 commit comments

Comments
 (0)