public static T replaceParameters()

in customization-base/src/main/java/com/azure/autorest/customization/implementation/Utils.java [412:453]


    public static <T extends CodeCustomization> T replaceParameters(String newParameters,
        CodeCustomization customization, Supplier<T> refreshCustomizationSupplier) {
        SymbolInformation symbol = customization.getSymbol();
        Editor editor = customization.getEditor();
        String fileName = customization.getFileName();
        String fileUri = customization.getFileUri();
        EclipseLanguageClient languageClient = customization.getLanguageClient();

        // Beginning line of the symbol.
        int line = symbol.getLocation().getRange().getStart().getLine();

        // First find the starting location of the parameters.
        // The beginning of the parameters may not be on the same line as the start of the signature.
        Matcher matcher = BEGINNING_OF_PARAMETERS_PATTERN.matcher(editor.getFileLine(fileName, line));
        while (!matcher.matches()) {
            matcher = BEGINNING_OF_PARAMETERS_PATTERN.matcher(editor.getFileLine(fileName, ++line));
        }

        // Now that the line where the parameters begin is found create its position.
        // Starting character is inclusive of the character offset, so add one as ')' isn't included in the capture.
        Position parametersStart = new Position(line, matcher.group(1).length() + 1);

        // Then find where the parameters end.
        // The ending of the parameters may not be on the same line as the start of the parameters.
        matcher = ENDING_OF_PARAMETERS_PATTERN.matcher(editor.getFileLine(fileName, line));
        while (!matcher.matches()) {
            matcher = ENDING_OF_PARAMETERS_PATTERN.matcher(editor.getFileLine(fileName, ++line));
        }

        // Now that the line where the parameters end is found gets create its position.
        // Ending character is exclusive of the character offset.
        Position parametersEnd = new Position(line, matcher.group(1).length());

        editor.replace(fileName, parametersStart, parametersEnd, newParameters);

        FileEvent fileEvent = new FileEvent();
        fileEvent.setUri(fileUri);
        fileEvent.setType(FileChangeType.Changed);
        languageClient.notifyWatchedFilesChanged(Collections.singletonList(fileEvent));

        return refreshCustomizationSupplier.get();
    }