All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.cqse.check.base.EntityTokenPatternCheckBase Maven / Gradle / Ivy

Go to download

The Teamscale Custom Check API allows users to extend Teamscale by writing custom analyses that create findings.

There is a newer version: 2024.7.2
Show newest version
/*
 * Copyright (c) CQSE GmbH
 *
 * 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 eu.cqse.check.base;

import java.util.List;

import eu.cqse.check.framework.core.CheckException;
import eu.cqse.check.framework.scanner.IToken;
import eu.cqse.check.framework.util.tokens.TokenPattern;
import eu.cqse.check.framework.util.tokens.TokenPatternMatch;

/**
 * Base class for tokens that create findings if a token pattern matches the processed tokens.
 *
 * @deprecated This class is deprecated because its superclass is deprecated. Also, this class
 *             implements almost no logic. To get help for replacing this class, please contact the
 *             Teamscale support.
 */
@Deprecated
public abstract class EntityTokenPatternCheckBase extends EntityTokenCheckBase {

	/** {@inheritDoc} */
	@Override
	protected void processTokens(List tokens) throws CheckException {
		TokenPattern pattern = getFindingPattern();
		for (TokenPatternMatch match : pattern.findAll(tokens)) {
			List matchedTokens = match.groupTokens(0);
			String message = getFindingMessage(matchedTokens);
			buildFinding(message, buildLocation().forTokens(matchedTokens)).createAndStore();
		}
	}

	/**
	 * Returns the pattern that the processed tokens are matched against. The pattern must define the
	 * group index 0 with {@link TokenPattern#group(int)}. All tokens that are matched within this group
	 * are passed to {@link #getFindingMessage(List)} and a finding will be created for them.
	 */
	protected abstract TokenPattern getFindingPattern();

	/** Creates a finding messages for the given tokens. */
	protected abstract String getFindingMessage(List tokens);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy