use of com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase in project bsl-language-server by 1c-syntax.
the class ModuleSymbolComputerTest method testModuleName.
@Test
void testModuleName() {
// given
var documentContext = spy(TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/ModuleSymbol.bsl"));
var computer = new ModuleSymbolComputer(documentContext);
MDOReference mdoReference = mock(MDOReference.class);
when(mdoReference.getMdoRef()).thenReturn("Document.Document1");
AbstractMDObjectBase mdObject = mock(AbstractMDObjectBase.class);
when(mdObject.getMdoReference()).thenReturn(mdoReference);
doReturn(Optional.of(mdObject)).when(documentContext).getMdObject();
// when-then pairs:
// when
doReturn(ModuleType.UNKNOWN).when(documentContext).getModuleType();
var moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1");
// when
doReturn(ModuleType.ObjectModule).when(documentContext).getModuleType();
moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1.ObjectModule");
// when
doReturn(ModuleType.ManagerModule).when(documentContext).getModuleType();
moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1.ManagerModule");
}
use of com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase in project bsl-language-server by 1c-syntax.
the class AnalyzeCommand method getFileInfoFromFile.
private FileInfo getFileInfoFromFile(Path srcDir, File file) {
String textDocumentContent;
try {
textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
DocumentContext documentContext = context.addDocument(file.toURI(), textDocumentContent, 1);
Path filePath = srcDir.relativize(Absolute.path(file));
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
String mdoRef = "";
Optional<AbstractMDObjectBase> mdObjectBase = documentContext.getMdObject();
if (mdObjectBase.isPresent()) {
mdoRef = mdObjectBase.get().getMdoReference().getMdoRef();
}
FileInfo fileInfo = new FileInfo(filePath, mdoRef, diagnostics, metrics);
// clean up AST after diagnostic computing to free up RAM.
documentContext.clearSecondaryData();
return fileInfo;
}
Aggregations