com.liferay.source.formatter.checkstyle.util.DetailASTUtil Maven / Gradle / Ivy
The newest version!
/**
* 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.checkstyle.util;
import com.liferay.portal.kernel.util.ArrayUtil;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import java.util.ArrayList;
import java.util.List;
/**
* @author Hugo Huijser
*/
public class DetailASTUtil {
public static final int ALL_TYPES = -1;
public static List getAllChildTokens(
DetailAST detailAST, boolean recursive, int... tokenTypes) {
return _getAllChildTokens(detailAST, recursive, null, tokenTypes);
}
private static List _getAllChildTokens(
DetailAST detailAST, boolean recursive, List list,
int... tokenTypes) {
if (list == null) {
list = new ArrayList<>();
}
DetailAST childDetailAST = detailAST.getFirstChild();
while (childDetailAST != null) {
if (ArrayUtil.contains(tokenTypes, childDetailAST.getType()) ||
ArrayUtil.contains(tokenTypes, ALL_TYPES)) {
list.add(childDetailAST);
}
if (recursive) {
list = _getAllChildTokens(
childDetailAST, recursive, list, tokenTypes);
}
childDetailAST = childDetailAST.getNextSibling();
}
return list;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy