23
23
24
24
import com .github ._1c_syntax .bsl .mdo .MD ;
25
25
import com .github ._1c_syntax .bsl .mdo .Module ;
26
- import com .github ._1c_syntax .bsl .mdo .ModuleOwner ;
27
26
import com .github ._1c_syntax .bsl .mdo .children .ObjectModule ;
28
27
import com .github ._1c_syntax .bsl .reader .MDOReader ;
29
28
import com .github ._1c_syntax .bsl .reader .common .TransformationUtils ;
55
54
public class MDCReaderContext implements ReaderContext {
56
55
57
56
private static final String UUID_FIELD_NAME = "uuid" ;
57
+ private static final String MDO_REFERENCE_FIELD_NAME = "mdoReference" ;
58
58
private static final String SUPPORT_VALIANT_FIELD_NAME = "SupportVariant" ;
59
59
private static final String CHILD_FILED_NAME = "child" ;
60
+ private static final String COMPATIBILITY_MODE_FILED_NAME = "compatibilityMode" ;
61
+ private static final String CONFIGURATION_SOURCE_MODE_FILED_NAME = "configurationSource" ;
62
+ private static final String MODULES_FIELD_NAME = "modules" ;
60
63
61
64
/**
62
65
* Класс будущего объекта
@@ -131,22 +134,19 @@ public MDCReaderContext(@NonNull Class<?> clazz, @NonNull HierarchicalStreamRead
131
134
@ Override
132
135
public Object build () {
133
136
var mdoReference = MdoReference .create (mdoType , name );
134
- setValue ("mdoReference" , mdoReference );
137
+ setValue (MDO_REFERENCE_FIELD_NAME , mdoReference );
135
138
136
139
if (compatibilityMode == null ) {
137
- setValue ("compatibilityMode" , configurationExtensionCompatibilityMode );
140
+ setValue (COMPATIBILITY_MODE_FILED_NAME , configurationExtensionCompatibilityMode );
138
141
}
139
142
140
143
if (isDesignerFormat ) {
141
- setValue ("configurationSource" , ConfigurationSource .DESIGNER );
144
+ setValue (CONFIGURATION_SOURCE_MODE_FILED_NAME , ConfigurationSource .DESIGNER );
142
145
} else {
143
- setValue ("configurationSource" , ConfigurationSource .EDT );
144
- }
145
-
146
- if (ModuleOwner .class .isAssignableFrom (realClass )) {
147
- setValueModules (mdoReference );
146
+ setValue (CONFIGURATION_SOURCE_MODE_FILED_NAME , ConfigurationSource .EDT );
148
147
}
149
148
149
+ setValueModules (mdoReference );
150
150
setValueChildren ();
151
151
152
152
return TransformationUtils .build (builder );
@@ -175,36 +175,19 @@ private void setValueChildren() {
175
175
}
176
176
177
177
private void setValueModules (MdoReference mdoReference ) {
178
- var moduleTypes = ModuleType . byMDOType ( mdoType );
179
- if (moduleTypes . isEmpty ()) {
178
+ var folder = getModuleFolder ( );
179
+ if (! folder . toFile (). exists ()) {
180
180
return ;
181
181
}
182
182
183
- // todo переделать
184
- Path folder ;
185
- if (isDesignerFormat ) {
186
- folder = DesignerPaths .moduleFolder (currentPath , mdoType );
187
- } else {
188
- folder = EDTPaths .moduleFolder (currentPath , mdoType );
189
- }
190
-
191
- if (!folder .toFile ().exists ()) {
183
+ var moduleTypes = ModuleType .byMDOType (mdoType );
184
+ if (moduleTypes .isEmpty ()) {
192
185
return ;
193
186
}
194
187
195
188
List <Module > modules = new ArrayList <>();
196
189
moduleTypes .forEach ((ModuleType moduleType ) -> {
197
- Path modulePath ;
198
- // todo переделать
199
- if (isDesignerFormat ) {
200
- modulePath = DesignerPaths .modulePath (folder , name , moduleType );
201
- } else if (mdoType == MDOType .CONFIGURATION ) {
202
- modulePath = EDTPaths .modulePath (folder , MDOType .CONFIGURATION .getName (), moduleType );
203
- } else {
204
- modulePath = EDTPaths .modulePath (folder , name , moduleType );
205
- }
206
-
207
- var protectedModuleInfo = new ProtectedModuleInfo (modulePath );
190
+ var protectedModuleInfo = getModuleInfo (folder , moduleType );
208
191
if (protectedModuleInfo .getModulePath ().toFile ().exists ()) {
209
192
modules .add (ObjectModule .builder ()
210
193
.moduleType (moduleType )
@@ -216,7 +199,24 @@ private void setValueModules(MdoReference mdoReference) {
216
199
}
217
200
}
218
201
);
219
- setValue ("modules" , modules );
202
+ setValue (MODULES_FIELD_NAME , modules );
220
203
}
221
204
205
+ private Path getModuleFolder () {
206
+ if (isDesignerFormat ) {
207
+ return DesignerPaths .moduleFolder (currentPath , mdoType );
208
+ } else {
209
+ return EDTPaths .moduleFolder (currentPath , mdoType );
210
+ }
211
+ }
212
+
213
+ private ProtectedModuleInfo getModuleInfo (Path folder , ModuleType moduleType ) {
214
+ Path modulePath ;
215
+ if (isDesignerFormat ) {
216
+ modulePath = DesignerPaths .modulePath (folder , name , moduleType );
217
+ } else {
218
+ modulePath = EDTPaths .modulePath (folder , MDOType .CONFIGURATION .getName (), moduleType );
219
+ }
220
+ return new ProtectedModuleInfo (modulePath );
221
+ }
222
222
}
0 commit comments