com.liferay.source.formatter.check.PropertiesStylingCheck Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.source.formatter.check;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.util.NaturalOrderStringComparator;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Alan Huang
* @author Hugo Huijser
*/
public class PropertiesStylingCheck extends BaseFileCheck {
@Override
protected String doProcess(
String fileName, String absolutePath, String content) {
content = content.replaceAll(
"(\n\n)((( *#+)( [^#\n]+)\n)+( *#))", "$1$4\n$2");
content = content.replaceAll(
"(\n\n)( *#+)(\n(\\2( [^#\n]+)\n)+)(?! *#)", "$1$2$3$2\n");
content = content.replaceAll(
"(\\A|(? 0) {
content = StringUtil.replaceFirst(
content, properties, previousProperties,
propertiesStartPosition);
content = StringUtil.replaceFirst(
content, previousProperties, properties,
previousPropertiesStartPosition);
return content;
}
previousProperties = properties;
previousPropertiesComment = propertiesComment;
previousPropertiesStartPosition = propertiesStartPosition;
}
return content;
}
private class CommentComparator extends NaturalOrderStringComparator {
@Override
public int compare(String comment1, String comment2) {
if (comment1.equals(" Default")) {
return -1;
}
if (comment2.equals(" Default")) {
return 1;
}
return super.compare(comment1, comment2);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy