public MethodCustomization getMethod()

in customization-base/src/main/java/com/azure/autorest/customization/ClassCustomization.java [153:186]


    public MethodCustomization getMethod(String methodNameOrSignature) {
        String methodName;
        String methodSignature = null;
        if (methodNameOrSignature.contains("(")) {
            // method signature
            methodSignature = BLOCK_OPEN.matcher(methodNameOrSignature).replaceFirst("");
            methodSignature = PUBLIC_MODIFIER.matcher(methodSignature).replaceFirst("");
            methodSignature = PRIVATE_MODIFIER.matcher(methodSignature).replaceFirst("");

            String returnTypeAndMethodName = methodNameOrSignature.split("\\(")[0];
            if (returnTypeAndMethodName.contains(" ")) {
                methodName = Utils.ANYTHING_THEN_SPACE_PATTERN.matcher(returnTypeAndMethodName).replaceAll("");
            } else {
                methodName = returnTypeAndMethodName;
            }
        } else {
            methodName = methodNameOrSignature;
        }
        Optional<SymbolInformation> methodSymbol = languageClient.listDocumentSymbols(fileUri)
            .stream().filter(si -> si.getKind() == SymbolKind.Method
                && MEMBER_PARAMS.matcher(si.getName()).replaceFirst("").equals(methodName))
            .filter(si -> editor.getFileLine(fileName, si.getLocation().getRange().getStart().getLine()).contains(methodNameOrSignature))
            .findFirst();
        if (methodSymbol.isEmpty()) {
            throw new IllegalArgumentException("Method " + methodNameOrSignature + " does not exist in class " + className);
        }
        if (methodSignature == null) {
            methodSignature = editor.getFileLine(fileName, methodSymbol.get().getLocation().getRange().getStart().getLine());
            methodSignature = BLOCK_OPEN.matcher(methodSignature).replaceFirst("");
            methodSignature = PUBLIC_MODIFIER.matcher(methodSignature).replaceFirst("");
            methodSignature = PRIVATE_MODIFIER.matcher(methodSignature).replaceFirst("");
        }
        return new MethodCustomization(editor, languageClient, packageName, className, methodName, methodSignature, methodSymbol.get());
    }