common_code/src/main/java/com/xiongyingqi/utils/code/CodeProcessor.java
private void checkImport() {
        Set<String> classImports = new HashSet<String>();
        classImports.addAll(builder.getImports());

        classImports.removeAll(findImports(content));// 移除已经导入的包

        Set<String> classImportsToRemove = new HashSet<String>();// 如果要导入的包与类所在的package一致，则忽略导入

        final String packageStr = findPackage();// 类所定义的包路径
        if (packageStr != null) {//如果定义了包路径，则在包路径后面新增导入
            String packageName = findPackageName(packageStr);
            for (String impt : classImports) {
                int point = impt.lastIndexOf(".");
                String pkgNameOfImport = impt.substring(0, point);//截取import的类所属包
                if (pkgNameOfImport.equals(packageName)) {// 如果包已经导入，则取消导入
                    classImportsToRemove.add(impt);
                }
            }
            classImports.removeAll(classImportsToRemove);

            //如果定义了包路径，则在包路径后面新增导入
            StringBuilder builder = new StringBuilder(packageStr);
            builder.append(StringHelper.line());
            for (String toImport : classImports) {
                builder.append(StringHelper.line());
                builder.append("import ");
                builder.append(toImport);
                builder.append(";");
            }
            content = StringHelper.replaceFirst(content, packageStr, builder.toString());
        } else {// 如果没有定义包，则在头部导入包
            StringBuilder builder = new StringBuilder();
            for (String toImport : classImports) {
                builder.append(StringHelper.line());
                builder.append("import ");
                builder.append(toImport);
                builder.append(";");
            }
            content = builder.append(content).toString();
        }

    }
private void checkImport() {
        Set<String> classImports = new HashSet<String>();
        classImports.addAll(builder.getImports());

        classImports.removeAll(findImports(content));// 移除已经导入的包

        Set<String> classImportsToRemove = new HashSet<String>();// 如果要导入的包与类所在的package一致，则忽略导入

        final String packageStr = findPackage();// 类所定义的包路径
        if (packageStr != null) {//如果定义了包路径，则在包路径后面新增导入
            String packageName = findPackageName(packageStr);
            for (String impt : classImports) {
                int point = impt.lastIndexOf(".");
                String pkgNameOfImport = impt.substring(0, point);//截取import的类所属包
                if (pkgNameOfImport.equals(packageName)) {// 如果包已经导入，则取消导入
                    classImportsToRemove.add(impt);
                }
            }
            classImports.removeAll(classImportsToRemove);

            //如果定义了包路径，则在包路径后面新增导入
            StringBuilder builder = new StringBuilder(packageStr);
            builder.append(StringHelper.line());
            for (String toImport : classImports) {
                builder.append(StringHelper.line());
                builder.append("import ");
                builder.append(toImport);
                builder.append(";");
            }
            content = StringHelper.replaceFirst(content, packageStr, builder.toString());
        } else {// 如果没有定义包，则在头部导入包
            StringBuilder builder = new StringBuilder();
            for (String toImport : classImports) {
                builder.append(StringHelper.line());
                builder.append("import ");
                builder.append(toImport);
                builder.append(";");
            }
            content = builder.append(content).toString();
        }

    }
检查导入包

@return