eu.cqse.check.framework.scanner.EmptyTokenStreamScanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-check-api Show documentation
Show all versions of teamscale-check-api Show documentation
The Teamscale Custom Check API allows users to extend Teamscale by writing custom analyses that create findings.
/*
* 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);
}
}
}