@Test void testLanguageEngineRun() { CobolPreprocessor preprocessor = mock(CobolPreprocessor.class); CobolLanguageEngine engine = new CobolLanguageEngine(preprocessor); Locality locality = Locality.builder() .uri(URI) .range(new Range(new Position(0, 0), new Position(0, 0))) .build(); SyntaxError error = SyntaxError.syntaxError() .locality(locality) .suggestion("suggestion") .severity(ERROR) .build(); ExtendedDocument extendedDocument = new ExtendedDocument( TEXT, new NamedSubContext(), Map.of( URI, new DocumentMapping( List.of( Locality.builder() .uri(URI) .range(new Range(new Position(0, 0), new Position(0, 7))) .token(" ") .build(), Locality.builder() .uri(URI) .range(new Range(new Position(0, 7), new Position(0, 20))) .token("IDENTIFICATION") .build(), Locality.builder() .uri(URI) .range(new Range(new Position(0, 21), new Position(0, 22))) .token(" ") .build(), Locality.builder() .uri(URI) .range(new Range(new Position(0, 22), new Position(0, 29))) .token("DIVISION") .build(), Locality.builder() .uri(URI) .range(new Range(new Position(0, 30), new Position(0, 31))) .token(".") .build()), Map.of())), Map.of()); when(preprocessor.process(URI, TEXT, PROCESSING_MODE)) .thenReturn(new ResultWithErrors<>(extendedDocument, List.of(error))); Range outlineRange = new Range(new org.eclipse.lsp4j.Position(0, 7), new org.eclipse.lsp4j.Position(0, 30)); List<DocumentSymbol> expectedOutlineTree = List.of( new DocumentSymbol( "PROGRAM", NodeType.PROGRAM.getSymbolKind(), outlineRange, outlineRange, "", List.of( new DocumentSymbol( "IDENTIFICATION DIVISION", NodeType.DIVISION.getSymbolKind(), outlineRange, outlineRange, "", List.of())))); ResultWithErrors<SemanticContext> expected = new ResultWithErrors<>( new SemanticContext( Map.of(), Map.of(), Map.of(), Map.of(), getConstantDefinitions(), Map.of(), Map.of(), Map.of(), expectedOutlineTree), List.of(error)); ResultWithErrors<SemanticContext> actual = engine.run(URI, TEXT, PROCESSING_MODE); assertEquals(expected, actual); }
@Nonnull public ResultWithErrors<SemanticContext> run( @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode) { ResultWithErrors<ExtendedDocument> preProcessorOutput = preprocessor.process(documentUri, text, copybookProcessingMode); List<SyntaxError> accumulatedErrors = new ArrayList<>(preProcessorOutput.getErrors()); ExtendedDocument extendedDocument = preProcessorOutput.getResult(); CobolLexer lexer = new CobolLexer(CharStreams.fromString(extendedDocument.getText())); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); ParserListener listener = new ParserListener(); CobolParser parser = new CobolParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(listener); parser.setErrorHandler(new CobolErrorStrategy()); CobolParser.StartRuleContext tree = parser.startRule(); Map<Token, Locality> positionMapping = LocalityMappingUtils.createPositionMapping( tokens.getTokens(), extendedDocument.getDocumentMapping(), documentUri); CobolVisitor visitor = new CobolVisitor(documentUri, extendedDocument.getCopybooks(), tokens, positionMapping); visitor.visit(tree); accumulatedErrors.addAll(finalizeErrors(listener.getErrors(), positionMapping)); accumulatedErrors.addAll(visitor.getErrors()); accumulatedErrors.addAll( collectErrorsForCopybooks(accumulatedErrors, extendedDocument.getCopyStatements())); return new ResultWithErrors<>(visitor.getSemanticContext(), accumulatedErrors); }
CobolLanguageEngine { @Nonnull public ResultWithErrors<SemanticContext> run( @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode) { ResultWithErrors<ExtendedDocument> preProcessorOutput = preprocessor.process(documentUri, text, copybookProcessingMode); List<SyntaxError> accumulatedErrors = new ArrayList<>(preProcessorOutput.getErrors()); ExtendedDocument extendedDocument = preProcessorOutput.getResult(); CobolLexer lexer = new CobolLexer(CharStreams.fromString(extendedDocument.getText())); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); ParserListener listener = new ParserListener(); CobolParser parser = new CobolParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(listener); parser.setErrorHandler(new CobolErrorStrategy()); CobolParser.StartRuleContext tree = parser.startRule(); Map<Token, Locality> positionMapping = LocalityMappingUtils.createPositionMapping( tokens.getTokens(), extendedDocument.getDocumentMapping(), documentUri); CobolVisitor visitor = new CobolVisitor(documentUri, extendedDocument.getCopybooks(), tokens, positionMapping); visitor.visit(tree); accumulatedErrors.addAll(finalizeErrors(listener.getErrors(), positionMapping)); accumulatedErrors.addAll(visitor.getErrors()); accumulatedErrors.addAll( collectErrorsForCopybooks(accumulatedErrors, extendedDocument.getCopyStatements())); return new ResultWithErrors<>(visitor.getSemanticContext(), accumulatedErrors); } }
CobolLanguageEngine { @Nonnull public ResultWithErrors<SemanticContext> run( @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode) { ResultWithErrors<ExtendedDocument> preProcessorOutput = preprocessor.process(documentUri, text, copybookProcessingMode); List<SyntaxError> accumulatedErrors = new ArrayList<>(preProcessorOutput.getErrors()); ExtendedDocument extendedDocument = preProcessorOutput.getResult(); CobolLexer lexer = new CobolLexer(CharStreams.fromString(extendedDocument.getText())); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); ParserListener listener = new ParserListener(); CobolParser parser = new CobolParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(listener); parser.setErrorHandler(new CobolErrorStrategy()); CobolParser.StartRuleContext tree = parser.startRule(); Map<Token, Locality> positionMapping = LocalityMappingUtils.createPositionMapping( tokens.getTokens(), extendedDocument.getDocumentMapping(), documentUri); CobolVisitor visitor = new CobolVisitor(documentUri, extendedDocument.getCopybooks(), tokens, positionMapping); visitor.visit(tree); accumulatedErrors.addAll(finalizeErrors(listener.getErrors(), positionMapping)); accumulatedErrors.addAll(visitor.getErrors()); accumulatedErrors.addAll( collectErrorsForCopybooks(accumulatedErrors, extendedDocument.getCopyStatements())); return new ResultWithErrors<>(visitor.getSemanticContext(), accumulatedErrors); } @Inject  CobolLanguageEngine(CobolPreprocessor preprocessor); }
CobolLanguageEngine { @Nonnull public ResultWithErrors<SemanticContext> run( @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode) { ResultWithErrors<ExtendedDocument> preProcessorOutput = preprocessor.process(documentUri, text, copybookProcessingMode); List<SyntaxError> accumulatedErrors = new ArrayList<>(preProcessorOutput.getErrors()); ExtendedDocument extendedDocument = preProcessorOutput.getResult(); CobolLexer lexer = new CobolLexer(CharStreams.fromString(extendedDocument.getText())); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); ParserListener listener = new ParserListener(); CobolParser parser = new CobolParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(listener); parser.setErrorHandler(new CobolErrorStrategy()); CobolParser.StartRuleContext tree = parser.startRule(); Map<Token, Locality> positionMapping = LocalityMappingUtils.createPositionMapping( tokens.getTokens(), extendedDocument.getDocumentMapping(), documentUri); CobolVisitor visitor = new CobolVisitor(documentUri, extendedDocument.getCopybooks(), tokens, positionMapping); visitor.visit(tree); accumulatedErrors.addAll(finalizeErrors(listener.getErrors(), positionMapping)); accumulatedErrors.addAll(visitor.getErrors()); accumulatedErrors.addAll( collectErrorsForCopybooks(accumulatedErrors, extendedDocument.getCopyStatements())); return new ResultWithErrors<>(visitor.getSemanticContext(), accumulatedErrors); } @Inject  CobolLanguageEngine(CobolPreprocessor preprocessor); @Nonnull ResultWithErrors<SemanticContext> run(
      @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode); }
CobolLanguageEngine { @Nonnull public ResultWithErrors<SemanticContext> run( @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode) { ResultWithErrors<ExtendedDocument> preProcessorOutput = preprocessor.process(documentUri, text, copybookProcessingMode); List<SyntaxError> accumulatedErrors = new ArrayList<>(preProcessorOutput.getErrors()); ExtendedDocument extendedDocument = preProcessorOutput.getResult(); CobolLexer lexer = new CobolLexer(CharStreams.fromString(extendedDocument.getText())); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); ParserListener listener = new ParserListener(); CobolParser parser = new CobolParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(listener); parser.setErrorHandler(new CobolErrorStrategy()); CobolParser.StartRuleContext tree = parser.startRule(); Map<Token, Locality> positionMapping = LocalityMappingUtils.createPositionMapping( tokens.getTokens(), extendedDocument.getDocumentMapping(), documentUri); CobolVisitor visitor = new CobolVisitor(documentUri, extendedDocument.getCopybooks(), tokens, positionMapping); visitor.visit(tree); accumulatedErrors.addAll(finalizeErrors(listener.getErrors(), positionMapping)); accumulatedErrors.addAll(visitor.getErrors()); accumulatedErrors.addAll( collectErrorsForCopybooks(accumulatedErrors, extendedDocument.getCopyStatements())); return new ResultWithErrors<>(visitor.getSemanticContext(), accumulatedErrors); } @Inject  CobolLanguageEngine(CobolPreprocessor preprocessor); @Nonnull ResultWithErrors<SemanticContext> run(
      @Nonnull String documentUri, @Nonnull String text, @Nonnull CopybookProcessingMode copybookProcessingMode);  }