001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright 2005-2011 the ConQAT Project                                   |
004|                                                                          |
005| Licensed under the Apache License, Version 2.0 (the "License");          |
006| you may not use this file except in compliance with the License.         |
007| You may obtain a copy of the License at                                  |
008|                                                                          |
009|    http://www.apache.org/licenses/LICENSE-2.0                            |
010|                                                                          |
011| Unless required by applicable law or agreed to in writing, software      |
012| distributed under the License is distributed on an "AS IS" BASIS,        |
013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
014| See the License for the specific language governing permissions and      |
015| limitations under the License.                                           |
016+-------------------------------------------------------------------------*/
017package eu.cqse.check.base;
018
019import java.util.List;
020
021import org.conqat.lib.commons.collections.CollectionUtils;
022
023import eu.cqse.check.framework.core.CheckException;
024import eu.cqse.check.framework.core.CheckImplementationBase;
025import eu.cqse.check.framework.shallowparser.framework.ShallowEntity;
026
027/**
028 * Base class for checks that analyze top-level types.
029 */
030public abstract class TopLevelTypeCheckBase extends CheckImplementationBase {
031
032        /** {@inheritDoc} */
033        @Override
034        public void execute() throws CheckException {
035                List<ShallowEntity> typeEntities = select(getXPathTypeSelectionString());
036                analyzeTopLevelTypes(CollectionUtils.filter(typeEntities, this::isTopLevelType));
037        }
038
039        /** Returns the xPath selection string that is used to select all types. */
040        protected String getXPathTypeSelectionString() {
041                return "//TYPE";
042        }
043
044        /** Analyzes the given top-level entities. */
045        protected abstract void analyzeTopLevelTypes(List<ShallowEntity> topLevelTypeEntities) throws CheckException;
046
047        /** Returns whether the given entity represents a top-level type. */
048        protected abstract boolean isTopLevelType(ShallowEntity typeEntity);
049}