Search in sources :

Example 1 with AbstractMDObjectBase

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");
}
Also used : AbstractMDObjectBase(com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase) MDOReference(com.github._1c_syntax.mdclasses.mdo.support.MDOReference) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AbstractMDObjectBase

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;
}
Also used : Path(java.nio.file.Path) FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) AbstractMDObjectBase(com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase) MetricStorage(com.github._1c_syntax.bsl.languageserver.context.MetricStorage) Diagnostic(org.eclipse.lsp4j.Diagnostic) IOException(java.io.IOException) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Aggregations

AbstractMDObjectBase (com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase)2 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)1 MetricStorage (com.github._1c_syntax.bsl.languageserver.context.MetricStorage)1 FileInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo)1 MDOReference (com.github._1c_syntax.mdclasses.mdo.support.MDOReference)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1