com.exadel.aem.toolkit.plugin.utils.ClassUtil Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exadel.aem.toolkit.plugin.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import com.exadel.aem.toolkit.api.annotations.widgets.accessory.Ignore;
import com.exadel.aem.toolkit.api.annotations.widgets.accessory.IgnoreFields;
import com.exadel.aem.toolkit.api.handlers.Source;
import com.exadel.aem.toolkit.plugin.adapters.ClassMemberSetting;
import com.exadel.aem.toolkit.plugin.sources.Sources;
import com.exadel.aem.toolkit.plugin.utils.ordering.OrderingUtil;
/**
* Contains utility methods for parsing AEM components' classes and extracting information related to UI rendering
*/
public class ClassUtil {
private static final String WILDCARD = ".*";
/**
* Default (instantiation-restricting) constructor
*/
private ClassUtil() {
}
/**
* Gets whether the given {@code Class} conforms to one of the provided references that represent package names
* @param sourceClass The class to check
* @param references Zero or more string values; non-blank strings are expected
* @return True or false
*/
public static boolean matchesReference(Class> sourceClass, String... references) {
if (ArrayUtils.isEmpty(references)) {
return true;
}
return Arrays.stream(references)
.filter(StringUtils::isNotBlank)
.map(ref -> ref.endsWith(WILDCARD) ? ref.substring(0, ref.length() - WILDCARD.length()) : ref)
.anyMatch(ref -> sourceClass.getName().startsWith(ref + DialogConstants.SEPARATOR_DOT));
}
/**
* Retrieves a sequential list of {@link Source} objects representing manageable members that belong to a certain
* {@code Class} and its superclasses
* @param sourceClass The class to extract sources from
* @return List of {@code Source} objects
*/
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy