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 eu.cqse.check.framework.core.CheckException;
020import eu.cqse.check.framework.scanner.ETokenType;
021import eu.cqse.check.framework.shallowparser.TokenStreamTextUtils;
022import eu.cqse.check.framework.shallowparser.TokenStreamUtils;
023import eu.cqse.check.framework.shallowparser.framework.ShallowEntity;
024
025/**
026 * Base class for checks creating a finding for certain token text sequences.
027 */
028public abstract class TokenTextSequenceCheckBase extends EntityCheckBase {
029
030        /** Checks the given entity */
031        protected void checkEntity(ShallowEntity entity, String findingMessage, String... tokenTexts)
032                        throws CheckException {
033                int callIndex = TokenStreamTextUtils.findSequence(entity.ownStartTokens(), 0, ETokenType.IDENTIFIER,
034                                tokenTexts);
035                if (callIndex != TokenStreamUtils.NOT_FOUND) {
036                        createFindingOnFirstLine(findingMessage, entity);
037                }
038        }
039
040}