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

eu.cqse.check.framework.scanner.EmptyTokenStreamScanner 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.framework.scanner;

import java.io.Reader;

import org.conqat.lib.commons.test.IndexValueClass;

/**
 * A {@link ILenientScanner} that always generates an empty token stream.
 *
 * To be precise, it will always generate one {@link TextToken} of type {@link ETokenType#EOF} to
 * satisfy the interface. However, since EOF tokens are not forwarded by the callers of
 * {@link #getNextToken()}, this leads to an empty token stream.
 *
 * This scanner should be used for languages that are not text based (e.g., Simulink models, which
 * are binary files).
 */
class EmptyTokenStreamScanner implements ILenientScanner {

	private final ELanguage language;

	private String originId;

	public EmptyTokenStreamScanner(ELanguage language, String originId) {
		this.language = language;
		this.originId = originId;
	}

	@Override
	public IToken getNextToken() {
		return new EofToken(language, originId);
	}

	@Override
	public void reset(Reader reader, String originId) {
		this.originId = originId;
	}

	@Override
	public void close() {
		// nothing to close
	}

	@IndexValueClass(containedInBackup = true)
	private static class EofToken extends Token {

		private static final long serialVersionUID = 8837738130642447042L;

		private final ELanguage language;

		private EofToken(ELanguage language, String originId) {
			super(ETokenType.EOF, 0, 0, "\n", originId);
			this.language = language;
		}

		@Override
		public ELanguage getLanguage() {
			return language;
		}

		@Override
		public IToken newToken(ETokenType type, int offset, int lineNumber, String text, String originId) {
			return new EofToken(language, this.originId);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy