common_code/src/main/java/com/xiongyingqi/utils/code/CodeProcessor.java
private String checkInterfaces(String classSegment) {
        if (builder.getInterfaces() == null || builder.getInterfaces().size() == 0) {
            return classSegment;
        }

        Matcher matcher = PATTERN_FIND_INTERCES.matcher(classSegment);

        if (matcher.find()) {
            final String interfaceDefineString = matcher.group();

            Set<String> interfaceSet = findInterfaces(interfaceDefineString);


            StringBuilder interfaceDefineStringReplace = new StringBuilder(interfaceDefineString);
            for (String interfaceName : builder.getInterfaces()) {
                if (interfaceSet.contains(interfaceName)) {// 如果已经存在接口的定义，则跳过该定义
                    continue;
                }
                interfaceDefineStringReplace.append(", ");
                interfaceDefineStringReplace.append(interfaceName);
            }
            classSegment = StringHelper.replaceFirst(classSegment, interfaceDefineString, interfaceDefineStringReplace.toString());
        } else {
            final String interfaceDefineString = "{";
            StringBuilder interfaceDefineStringReplace = new StringBuilder("implements ");
            boolean isFirstInterface = true;
            for (String interfaceName : builder.getInterfaces()) {
                if (!isFirstInterface) {
                    interfaceDefineStringReplace.append(", ");
                }
                if (isFirstInterface) {
                    isFirstInterface = false;
                }

                interfaceDefineStringReplace.append(interfaceName);
            }
            interfaceDefineStringReplace.append(interfaceDefineString);
            classSegment = StringHelper.replaceFirst(classSegment, interfaceDefineString, interfaceDefineStringReplace.toString());
        }
        return classSegment;
    }
private String checkInterfaces(String classSegment) {
        if (builder.getInterfaces() == null || builder.getInterfaces().size() == 0) {
            return classSegment;
        }

        Matcher matcher = PATTERN_FIND_INTERCES.matcher(classSegment);

        if (matcher.find()) {
            final String interfaceDefineString = matcher.group();

            Set<String> interfaceSet = findInterfaces(interfaceDefineString);


            StringBuilder interfaceDefineStringReplace = new StringBuilder(interfaceDefineString);
            for (String interfaceName : builder.getInterfaces()) {
                if (interfaceSet.contains(interfaceName)) {// 如果已经存在接口的定义，则跳过该定义
                    continue;
                }
                interfaceDefineStringReplace.append(", ");
                interfaceDefineStringReplace.append(interfaceName);
            }
            classSegment = StringHelper.replaceFirst(classSegment, interfaceDefineString, interfaceDefineStringReplace.toString());
        } else {
            final String interfaceDefineString = "{";
            StringBuilder interfaceDefineStringReplace = new StringBuilder("implements ");
            boolean isFirstInterface = true;
            for (String interfaceName : builder.getInterfaces()) {
                if (!isFirstInterface) {
                    interfaceDefineStringReplace.append(", ");
                }
                if (isFirstInterface) {
                    isFirstInterface = false;
                }

                interfaceDefineStringReplace.append(interfaceName);
            }
            interfaceDefineStringReplace.append(interfaceDefineString);
            classSegment = StringHelper.replaceFirst(classSegment, interfaceDefineString, interfaceDefineStringReplace.toString());
        }
        return classSegment;
    }
private String checkInterfaces ( String classSegment ) { if ( builder . getInterfaces ( ) == null || builder . getInterfaces ( ) . size ( ) == 0 ) { return classSegment ; } Matcher matcher = PATTERN_FIND_INTERCES . matcher ( classSegment ) ; if ( matcher . find ( ) ) { final String interfaceDefineString = matcher . group ( ) ; Set < String > interfaceSet = findInterfaces ( interfaceDefineString ) ; StringBuilder interfaceDefineStringReplace = new StringBuilder ( interfaceDefineString ) ; for ( String interfaceName : builder . getInterfaces ( ) ) { if ( interfaceSet . contains ( interfaceName ) ) { // 如果已经存在接口的定义，则跳过该定义 continue ; } interfaceDefineStringReplace . append ( ", " ) ; interfaceDefineStringReplace . append ( interfaceName ) ; } classSegment = StringHelper . replaceFirst ( classSegment , interfaceDefineString , interfaceDefineStringReplace . toString ( ) ) ; } else { final String interfaceDefineString = "{" ; StringBuilder interfaceDefineStringReplace = new StringBuilder ( "implements " ) ; boolean isFirstInterface = true ; for ( String interfaceName : builder . getInterfaces ( ) ) { if ( ! isFirstInterface ) { interfaceDefineStringReplace . append ( ", " ) ; } if ( isFirstInterface ) { isFirstInterface = false ; } interfaceDefineStringReplace . append ( interfaceName ) ; } interfaceDefineStringReplace . append ( interfaceDefineString ) ; classSegment = StringHelper . replaceFirst ( classSegment , interfaceDefineString , interfaceDefineStringReplace . toString ( ) ) ; } return classSegment ; }
检查implements关键字

@param classSegment
@return
检查implements关键字