org.codehaus.groovy.runtime.StringGroovyMethods Java Examples

The following examples show how to use org.codehaus.groovy.runtime.StringGroovyMethods. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourceCopyTask.java    From native-samples with Apache License 2.0 6 votes vote down vote up
public void doCopyDir(String templateDirName, String srcName, String targetDir, Action<TemplateDirectory> dirAction) {
    String srcFileName = templateDirName + "/" + srcName;
    File srcDir = getTemplatesDir().dir(srcFileName).get().getAsFile();
    if (!srcDir.isDirectory() || srcDir.list().length == 0) {
        return;

    }

    final TemplateDirectory dirDetails = new TemplateDirectory(srcName);
    dirAction.execute(dirDetails);
    File destDir = getSampleDir().dir(targetDir + "/" + dirDetails.getTargetDirName()).get().getAsFile();
    copy(srcDir, destDir, dirDetails.getLineFilter(), dirDetails.getRecursive());
    if (dirDetails.getRecursive()) {
        return;

    }

    Arrays.stream(srcDir.listFiles()).forEach(f -> {
        if (f.isDirectory() && !f.getName().equals(".gradle")) {
            doCopyDir(templateDirName, StringGroovyMethods.asBoolean(srcName) ? srcName + "/" + f.getName() : f.getName(), targetDir, dirAction);
        }
    });
}
 
Example #2
Source File: StringUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
public static String replaceStandardEscapes(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	String result = StringGroovyMethods.replaceAll((CharSequence) text, STANDARD_ESCAPES_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1, String _2) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			Character character = STANDARD_ESCAPES.get(_2.charAt(0));
			return _1 + (character != null ? character : _2);
		}
	});

	return replace(result,"\\\\", "\\");
}
 
Example #3
Source File: StringUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
private static String replaceLineEscape(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	text = StringGroovyMethods.replaceAll((CharSequence) text, LINE_ESCAPE_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			return _1;
		}
	});

	return text;
}
 
Example #4
Source File: XmlUtil.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Escape the following characters {@code " ' & < >} with their XML entities, e.g.
 * {@code "bread" & "butter"} becomes {@code &quot;bread&quot; &amp; &quot;butter&quot}.
 * Notes:<ul>
 * <li>Supports only the five basic XML entities (gt, lt, quot, amp, apos)</li>
 * <li>Does not escape control characters</li>
 * <li>Does not support DTDs or external entities</li>
 * <li>Does not treat surrogate pairs specially</li>
 * <li>Does not perform Unicode validation on its input</li>
 * </ul>
 *
 * @param orig the original String
 * @return A new string in which all characters that require escaping
 *         have been replaced with the corresponding XML entities.
 * @see #escapeControlCharacters(String)
 */
public static String escapeXml(String orig) {
    return StringGroovyMethods.collectReplacements(orig, new Closure<String>(null) {
        public String doCall(Character arg) {
            switch (arg) {
                case '&':
                    return "&amp;";
                case '<':
                    return "&lt;";
                case '>':
                    return "&gt;";
                case '"':
                    return "&quot;";
                case '\'':
                    return "&apos;";
            }
            return null;
        }
    });
}
 
Example #5
Source File: BaseDuration.java    From groovy with Apache License 2.0 6 votes vote down vote up
public String toString() {
    List buffer = new ArrayList();

    if (this.years != 0) buffer.add(this.years + " years");
    if (this.months != 0) buffer.add(this.months + " months");
    if (this.days != 0) buffer.add(this.days + " days");
    if (this.hours != 0) buffer.add(this.hours + " hours");
    if (this.minutes != 0) buffer.add(this.minutes + " minutes");

    if (this.seconds != 0 || this.millis != 0) {
        int norm_millis = this.millis % 1000;
        int norm_seconds = this.seconds + DefaultGroovyMethods.intdiv(this.millis - norm_millis, 1000).intValue();
        CharSequence millisToPad = "" + Math.abs(norm_millis);
        buffer.add((norm_seconds == 0 ? (norm_millis < 0 ? "-0" : "0") : norm_seconds) + "." + StringGroovyMethods.padLeft(millisToPad, 3, "0") + " seconds");
    }

    if (!buffer.isEmpty()) {
        return DefaultGroovyMethods.join(buffer.iterator(), ", ");
    } else {
        return "0";
    }
}
 
Example #6
Source File: GroovyDocToolTest.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void testAbstractMethods() throws Exception {
    final String base = "org/codehaus/groovy/tools/groovydoc/testfiles";
    htmlTool.add(Arrays.asList(
        base + "/GroovyClassWithMultipleInterfaces.groovy",
        base + "/JavaClassWithDiamond.java"
    ));

    final MockOutputTool output = new MockOutputTool();
    htmlTool.renderToOutput(output, MOCK_DIR);

    final String groovydoc = output.getText(MOCK_DIR + "/" + base + "/GroovyClassWithMultipleInterfaces.html");
    final String javadoc = StringGroovyMethods.normalize(output.getText(MOCK_DIR + "/" + base + "/JavaClassWithDiamond.html"));

    final Pattern methodSummary = Pattern.compile("<code>(public&nbsp;)?abstract&nbsp;void</code>");
    final Pattern methodDetails = Pattern.compile("<h4>(public&nbsp;)?abstract&nbsp;void <strong>link</strong>");

    assertTrue("The Groovy method summary should contain 'abstract'", methodSummary.matcher(groovydoc).find());
    assertTrue("The Java method summary should contain 'abstract'", methodSummary.matcher(javadoc).find());
    assertTrue("The Groovy method details should contain 'abstract'", methodDetails.matcher(groovydoc).find());
    assertTrue("The Java method details should contain 'abstract'", methodDetails.matcher(javadoc).find());
}
 
Example #7
Source File: Node.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Float object.
 *
 * @return the GPathResult, converted to a <code>Float</code>
 */
public Float toFloat() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toFloat((CharSequence)text());
}
 
Example #8
Source File: Node.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Long object.
 *
 * @return the GPathResult, converted to a <code>Long</code>
 */
public Long toLong() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toLong((CharSequence)text());
}
 
Example #9
Source File: Node.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Integer object.
 *
 * @return the GPathResult, converted to a <code>Integer</code>
 */
public Integer toInteger() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toInteger((CharSequence)text());
}
 
Example #10
Source File: ConfigObject.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static void writeValue(String key, String space, String prefix, Object value, BufferedWriter out) throws IOException {
//        key = key.indexOf('.') > -1 ? InvokerHelper.inspect(key) : key;
        boolean isKeyword = KEYWORDS.contains(key);
        key = isKeyword ? InvokerHelper.inspect(key) : key;

        if (!StringGroovyMethods.asBoolean(prefix) && isKeyword) prefix = "this.";
        out.append(space).append(prefix).append(key).append('=').append(InvokerHelper.inspect(value));
        out.newLine();
    }
 
Example #11
Source File: GroovyMain.java    From groovy with Apache License 2.0 5 votes vote down vote up
private List<String> getConfigScripts() {
    List<String> scripts = new ArrayList<String>();

    if (this.configscript != null) {
        scripts.add(this.configscript);
    }

    String configScripts = System.getProperty("groovy.starter.configscripts", null);

    if (configScripts != null && !configScripts.isEmpty()) {
        scripts.addAll(StringGroovyMethods.tokenize(configScripts, ','));
    }

    return scripts;
}
 
Example #12
Source File: Node.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Double object.
 *
 * @return the GPathResult, converted to a <code>Double</code>
 */
public Double toDouble() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toDouble((CharSequence)text());
}
 
Example #13
Source File: DefaultTypeTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static Collection asCollection(Object value) {
    if (value == null) {
        return Collections.EMPTY_LIST;
    } else if (value instanceof Collection) {
        return (Collection) value;
    } else if (value instanceof Map) {
        Map map = (Map) value;
        return map.entrySet();
    } else if (value.getClass().isArray()) {
        return arrayAsCollection(value);
    } else if (value instanceof MethodClosure) {
        MethodClosure method = (MethodClosure) value;
        IteratorClosureAdapter adapter = new IteratorClosureAdapter(method.getDelegate());
        method.call(adapter);
        return adapter.asList();
    } else if (value instanceof String || value instanceof GString) {
        return StringGroovyMethods.toList((CharSequence) value);
    } else if (value instanceof File) {
        try {
            return ResourceGroovyMethods.readLines((File) value);
        } catch (IOException e) {
            throw new GroovyRuntimeException("Error reading file: " + value, e);
        }
    } else if (value instanceof Class && ((Class) value).isEnum()) {
        Object[] values = (Object[]) InvokerHelper.invokeMethod(value, "values", EMPTY_OBJECT_ARRAY);
        return Arrays.asList(values);
    } else {
        // let's assume it's a collection of 1
        return Collections.singletonList(value);
    }
}
 
Example #14
Source File: SortableASTTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static void createComparatorFor(ClassNode classNode, PropertyNode property, boolean reversed) {
    String propName = StringGroovyMethods.capitalize((CharSequence) property.getName());
    String className = classNode.getName() + "$" + propName + "Comparator";
    ClassNode superClass = makeClassSafeWithGenerics(AbstractComparator.class, classNode);
    InnerClassNode cmpClass = new InnerClassNode(classNode, className, ACC_PRIVATE | ACC_STATIC, superClass);
    addGeneratedInnerClass(classNode, cmpClass);

    addGeneratedMethod(cmpClass,
            "compare",
            ACC_PUBLIC,
            ClassHelper.int_TYPE,
            params(param(newClass(classNode), ARG0), param(newClass(classNode), ARG1)),
            ClassNode.EMPTY_ARRAY,
            createCompareMethodBody(property, reversed)
    );

    String fieldName = "this$" + propName + "Comparator";
    // private final Comparator this$<property>Comparator = new <type>$<property>Comparator();
    FieldNode cmpField = classNode.addField(
            fieldName,
            ACC_STATIC | ACC_FINAL | ACC_PRIVATE | ACC_SYNTHETIC,
            COMPARATOR_TYPE,
            ctorX(cmpClass));

    addGeneratedMethod(classNode,
            "comparatorBy" + propName,
            ACC_PUBLIC | ACC_STATIC,
            COMPARATOR_TYPE,
            Parameter.EMPTY_ARRAY,
            ClassNode.EMPTY_ARRAY,
            returnS(fieldX(cmpField))
    );
}
 
Example #15
Source File: ConsoleTextEditor.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // starting position in document
    int start = textEditor.viewToModel(getViewport().getViewPosition());
    // end position in document
    int end = textEditor.viewToModel(new Point(10,
            getViewport().getViewPosition().y +
                    (int) textEditor.getVisibleRect().getHeight())
    );

    // translate offsets to lines
    Document doc = textEditor.getDocument();
    int startline = doc.getDefaultRootElement().getElementIndex(start) + 1;
    int endline = doc.getDefaultRootElement().getElementIndex(end) + 1;
    Font f = textEditor.getFont();
    int fontHeight = g.getFontMetrics(f).getHeight();
    int fontDesc = g.getFontMetrics(f).getDescent();
    int startingY = -1;

    try {
        startingY = textEditor.modelToView(start).y + fontHeight - fontDesc;
    } catch (BadLocationException e1) {
        System.err.println(e1.getMessage());
    }
    g.setFont(f);
    for (int line = startline, y = startingY; line <= endline; y += fontHeight, line++) {
        String lineNumber = StringGroovyMethods.padLeft((CharSequence)Integer.toString(line), 4, " ");
        g.drawString(lineNumber, 0, y);
    }
}
 
Example #16
Source File: Node.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a BigDecimal object.
 *
 * @return the GPathResult, converted to a <code>BigDecimal</code>
 */
public BigDecimal toBigDecimal() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toBigDecimal((CharSequence)text());
}
 
Example #17
Source File: ReleasePlugin.java    From native-samples with Apache License 2.0 5 votes vote down vote up
public void apply(final Project project) {
    project.getPluginManager().apply("swiftpm-export");
    project.getTasks().register("release", task -> {
        // Generate the Swift PM manifest prior to commit
        task.dependsOn(project.getTasks().named("generateSwiftPmManifest"));
        task.doLast(it -> {
            // Commit and tag changes
            project.exec(execSpec -> {
                execSpec.commandLine("git", "add", "Package.swift");
            });
            project.exec(execSpec -> {
                execSpec.commandLine("git", "commit", "-a", "-m", "version " + project.getVersion());
            });
            project.exec(execSpec -> {
                execSpec.commandLine("git", "tag", project.getVersion());
            });

            // Increment the version in the build script, for next release
            Pattern versionPattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d)");
            Matcher matcher = versionPattern.matcher(project.getVersion().toString());
            if (!matcher.matches()) {
                throw new GradleException("Could not parse project version \'" + project.getVersion() + "\'");
            }

            String newVersion = matcher.group(1) + "." + ((StringGroovyMethods.asType(matcher.group(2), Integer.class)) + 1) + ".0";
            String buildFileText = readFileAsString(project.getBuildFile());
            String updatedText = buildFileText.replaceAll("version\\s*=\\s*\'" + String.valueOf(project.getVersion()) + "\'", "version = \'" + newVersion + "\'");
            if (updatedText.equals(buildFileText)) {
                throw new GradleException("Could not update version in " + project.getBuildFile().getName());
            }

            writeFile(project.getBuildFile(), updatedText);
        });
    });
}
 
Example #18
Source File: Node.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a BigInteger object.
 *
 * @return the GPathResult, converted to a <code>BigInteger</code>
 */
public BigInteger toBigInteger() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toBigInteger((CharSequence)text());
}
 
Example #19
Source File: GPathResult.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Double object.
 *
 * @return the GPathResult, converted to a <code>Double</code>
 */
public Double toDouble() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toDouble((CharSequence)text());
}
 
Example #20
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, Callable<FileTree> warTree) {
    War warTask = overlay.getWarTask();

    String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
    String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());

    File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
    Action<CopySpec> extractOverlay = copySpec -> {
        copySpec.into(destinationDir);
        copySpec.from(warTree);
    };

    Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);

    overlay.getWarCopySpec().from(extractOverlayTask);

    if (overlay.isEnableCompilation()) {

        if (!destinationDir.exists() || isEmpty(destinationDir)) {
            project.sync(extractOverlay);
        }

        project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);

        ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
                .builtBy(extractOverlayTask);

        project.getDependencies().add(getClasspathConfigurationName(overlay), classes);

        FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
                .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));

        project.getDependencies().add(getClasspathConfigurationName(overlay), libs);
    }
}
 
Example #21
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, Callable<FileTree> warTree) {
    War warTask = overlay.getWarTask();

    String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
    String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());

    File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
    Action<CopySpec> extractOverlay = copySpec -> {
        copySpec.into(destinationDir);
        copySpec.from(warTree);
    };

    Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);

    overlay.getWarCopySpec().from(extractOverlayTask);

    if (overlay.isEnableCompilation()) {

        if (!destinationDir.exists() || isEmpty(destinationDir)) {
            project.sync(extractOverlay);
        }

        project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);

        ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
                .builtBy(extractOverlayTask);

        project.getDependencies().add(getClasspathConfigurationName(overlay), classes);

        FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
                .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));

        project.getDependencies().add(getClasspathConfigurationName(overlay), libs);
    }
}
 
Example #22
Source File: GPathResult.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Integer object.
 *
 * @return the GPathResult, converted to a <code>Integer</code>
 */
public Integer toInteger() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toInteger((CharSequence)text());
}
 
Example #23
Source File: GPathResult.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Long object.
 *
 * @return the GPathResult, converted to a <code>Long</code>
 */
public Long toLong() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toLong((CharSequence)text());
}
 
Example #24
Source File: GPathResult.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a Float object.
 *
 * @return the GPathResult, converted to a <code>Float</code>
 */
public Float toFloat() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toFloat((CharSequence)text());
}
 
Example #25
Source File: StringUtils.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static String replaceOctalEscapes(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	return StringGroovyMethods.replaceAll((CharSequence) text, OCTAL_ESCAPES_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1, String _2) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			return _1 + new String(Character.toChars(Integer.parseInt(_2, 8)));
		}
	});
}
 
Example #26
Source File: GPathResult.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a BigDecimal object.
 *
 * @return the GPathResult, converted to a <code>BigDecimal</code>
 */
public BigDecimal toBigDecimal() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toBigDecimal((CharSequence)text());
}
 
Example #27
Source File: GPathResult.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the text of this GPathResult to a BigInteger object.
 *
 * @return the GPathResult, converted to a <code>BigInteger</code>
 */
public BigInteger toBigInteger() {
    if(textIsEmptyOrNull()){
        return null;
    }
    return StringGroovyMethods.toBigInteger((CharSequence)text());
}
 
Example #28
Source File: StringUtils.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static String replaceHexEscapes(String text) {
	if (!text.contains(BACKSLASH)) {
		return text;
	}

	return StringGroovyMethods.replaceAll((CharSequence) text, HEX_ESCAPES_PATTERN, new Closure<Void>(null, null) {
		Object doCall(String _0, String _1, String _2) {
			if (isLengthOdd(_1)) {
				return _0;
			}

			return _1 + new String(Character.toChars(Integer.parseInt(_2, 16)));
		}
	});
}
 
Example #29
Source File: FileSystemCompiler.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CompilerConfiguration toCompilerConfiguration() throws IOException {
    // Setup the configuration data
    CompilerConfiguration configuration = new CompilerConfiguration();

    if (classpath != null) {
        configuration.setClasspath(classpath);
    }

    if (targetDir != null && targetDir.getName().length() > 0) {
        configuration.setTargetDirectory(targetDir);
    }

    configuration.setParameters(parameterMetadata);
    configuration.setPreviewFeatures(previewFeatures);
    configuration.setSourceEncoding(encoding);
    configuration.setScriptBaseClass(scriptBaseClass);

    // joint compilation parameters
    if (jointCompilation) {
        Map<String, Object> compilerOptions = new HashMap<>();
        compilerOptions.put("flags", javacFlags());
        compilerOptions.put("namedValues", javacNamedValues());
        configuration.setJointCompilationOptions(compilerOptions);
    }

    final List<String> transformations = new ArrayList<>();
    if (compileStatic) {
        transformations.add("ast(groovy.transform.CompileStatic)");
    }
    if (typeChecked) {
        transformations.add("ast(groovy.transform.TypeChecked)");
    }
    if (!transformations.isEmpty()) {
        processConfigScriptText(buildConfigScriptText(transformations), configuration);
    }

    String configScripts = System.getProperty("groovy.starter.configscripts", null);
    if (configScript != null || (configScripts != null && !configScripts.isEmpty())) {
        List<String> scripts = new ArrayList<>();
        if (configScript != null) {
            scripts.add(configScript);
        }
        if (configScripts != null) {
            scripts.addAll(StringGroovyMethods.tokenize(configScripts, ','));
        }
        processConfigScripts(scripts, configuration);
    }

    return configuration;
}
 
Example #30
Source File: ConfigObject.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void writeConfig(String prefix, ConfigObject map, BufferedWriter out, int tab, boolean apply) throws IOException {
    String space = apply ? StringGroovyMethods.multiply(TAB_CHARACTER, tab) : "";

    for (Object o1 : map.keySet()) {
        String key = (String) o1;
        Object v = map.get(key);

        if (v instanceof ConfigObject) {
            ConfigObject value = (ConfigObject) v;

            if (!value.isEmpty()) {

                Object dotsInKeys = null;
                for (Object o : value.entrySet()) {
                    Entry e = (Entry) o;
                    String k = (String) e.getKey();
                    if (k.indexOf('.') > -1) {
                        dotsInKeys = e;
                        break;
                    }
                }

                int configSize = value.size();
                Object firstKey = value.keySet().iterator().next();
                Object firstValue = value.values().iterator().next();

                int firstSize;
                if (firstValue instanceof ConfigObject) {
                    firstSize = ((ConfigObject) firstValue).size();
                } else {
                    firstSize = 1;
                }

                if (configSize == 1 || DefaultGroovyMethods.asBoolean(dotsInKeys)) {
                    if (firstSize == 1 && firstValue instanceof ConfigObject) {
                        key = KEYWORDS.contains(key) ? InvokerHelper.inspect(key) : key;
                        String writePrefix = prefix + key + "." + firstKey + ".";
                        writeConfig(writePrefix, (ConfigObject) firstValue, out, tab, true);
                    } else if (!DefaultGroovyMethods.asBoolean(dotsInKeys) && firstValue instanceof ConfigObject) {
                        writeNode(key, space, tab, value, out);
                    } else {
                        for (Object j : value.keySet()) {
                            Object v2 = value.get(j);
                            Object k2 = ((String) j).indexOf('.') > -1 ? InvokerHelper.inspect(j) : j;
                            if (v2 instanceof ConfigObject) {
                                key = KEYWORDS.contains(key) ? InvokerHelper.inspect(key) : key;
                                writeConfig(prefix + key, (ConfigObject) v2, out, tab, false);
                            } else {
                                writeValue(key + "." + k2, space, prefix, v2, out);
                            }
                        }
                    }
                } else {
                    writeNode(key, space, tab, value, out);
                }
            }
        } else {
            writeValue(key, space, prefix, v, out);
        }
    }
}