checker.src.org.checkerframework.checker.fenum.FenumChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
The Checker Framework enhances Java’s type system to
make it more powerful and useful. This lets software developers
detect and prevent errors in their Java programs.
The Checker Framework includes compiler plug-ins ("checkers")
that find bugs or verify their absence. It also permits you to
write your own compiler plug-ins.
package org.checkerframework.checker.fenum;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.processing.SupportedOptions;
import org.checkerframework.common.basetype.BaseTypeChecker;
import org.checkerframework.common.basetype.BaseTypeVisitor;
import org.checkerframework.common.subtyping.SubtypingChecker;
import org.checkerframework.framework.qual.StubFiles;
/**
* The main checker class for the Fake Enum Checker.
*
* There are two options to distinguish different enumerators:
*
*
* - {@code @Fenum("Name")}: introduces a fake enumerator with the name
* "Name". Enumerators with different names are distinct. The default name is
* empty, but you are encouraged to use a unique name for your purpose.
*
*
* - Alternatively, you can specify the annotation to use with the
* {@code -Aqual} command line argument.
*
*
*
* @author wmdietl
* @checker_framework.manual #fenum-checker Fake Enum Checker
*/
@StubFiles("jdnc.astub")
@SupportedOptions( { "quals", "qualDirs" } )
public class FenumChecker extends BaseTypeChecker {
/*
@Override
public void initChecker() {
super.initChecker();
}
*/
/** Copied from SubtypingChecker; cannot reuse it, because SubtypingChecker is final.
* @see SubtypingChecker#getSuppressWarningsKeys()
*/
@Override
public Collection getSuppressWarningsKeys() {
Set> annos = ((BaseTypeVisitor)visitor).getTypeFactory().getSupportedTypeQualifiers();
if (annos.isEmpty()) {
return super.getSuppressWarningsKeys();
}
Set swKeys = new HashSet<>();
swKeys.add(SUPPRESS_ALL_KEY);
for (Class anno : annos) {
swKeys.add(anno.getSimpleName().toLowerCase());
}
return swKeys;
}
}