Search in sources :

Example 1 with MDOReference

use of com.github._1c_syntax.mdclasses.mdo.support.MDOReference 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 MDOReference

use of com.github._1c_syntax.mdclasses.mdo.support.MDOReference in project mdclasses by 1c-syntax.

the class PairConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    if ("languages".equals(reader.getNodeName())) {
        var uuid = reader.getAttribute("uuid");
        var language = (MDLanguage) context.convertAnother(new MDLanguage(), MDLanguage.class);
        language.setUuid(uuid);
        language.setMdoReference(new MDOReference(language));
        return Either.right(language);
    } else if (reader.getValue().contains(".")) {
        // уже лежит имя
        return Either.left(reader.getValue());
    } else {
        var type = MDOType.fromValue(reader.getNodeName());
        return type.map(mdoType -> Either.left(mdoType.getName() + "." + reader.getValue())).orElseGet(() -> Either.left(reader.getNodeName() + "." + reader.getValue()));
    }
}
Also used : MDOReference(com.github._1c_syntax.mdclasses.mdo.support.MDOReference) MDLanguage(com.github._1c_syntax.mdclasses.mdo.MDLanguage)

Aggregations

MDOReference (com.github._1c_syntax.mdclasses.mdo.support.MDOReference)2 AbstractMDObjectBase (com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase)1 MDLanguage (com.github._1c_syntax.mdclasses.mdo.MDLanguage)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1