Search in sources :

Example 1 with ModuleSymbol

use of com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol 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 ModuleSymbol

use of com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol in project bsl-language-server by 1c-syntax.

the class SymbolTreeComputer method compute.

@Override
public SymbolTree compute() {
    ModuleSymbol moduleSymbol = new ModuleSymbolComputer(documentContext).compute();
    List<MethodSymbol> methods = new MethodSymbolComputer(documentContext).compute();
    List<RegionSymbol> regions = new RegionSymbolComputer(documentContext).compute();
    List<VariableSymbol> variables = new VariableSymbolComputer(documentContext).compute();
    List<SourceDefinedSymbol> allOfThem = new ArrayList<>(methods);
    allOfThem.addAll(regions);
    allOfThem.addAll(variables);
    allOfThem.sort(Comparator.comparingInt(symbol -> symbol.getRange().getStart().getLine()));
    List<SourceDefinedSymbol> topLevelSymbols = new ArrayList<>();
    SourceDefinedSymbol currentParent = moduleSymbol;
    for (SourceDefinedSymbol symbol : allOfThem) {
        currentParent = placeSymbol(topLevelSymbols, currentParent, symbol);
    }
    return new SymbolTree(moduleSymbol);
}
Also used : RegionSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol) List(java.util.List) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) VariableSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol) SymbolTree(com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree) Optional(java.util.Optional) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ModuleSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol) SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) Comparator(java.util.Comparator) MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) ArrayList(java.util.ArrayList) RegionSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol) ModuleSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol) ArrayList(java.util.ArrayList) MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) SymbolTree(com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree) SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) VariableSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)1 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)1 ModuleSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol)1 RegionSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol)1 SourceDefinedSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol)1 SymbolTree (com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree)1 VariableSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol)1 Ranges (com.github._1c_syntax.bsl.languageserver.utils.Ranges)1 AbstractMDObjectBase (com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase)1 MDOReference (com.github._1c_syntax.mdclasses.mdo.support.MDOReference)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1