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

checker.src.org.checkerframework.checker.experimental.regex_qual.RegexAnnotationConverter Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.42.0
Show newest version
package org.checkerframework.checker.experimental.regex_qual;

import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.qualframework.base.AnnotationConverter;

import java.util.Collection;

import javax.lang.model.element.AnnotationMirror;

/**
 * Convert {@link org.checkerframework.checker.regex.qual.Regex}
 * annotations into a {@link Regex} qualifier.
 */
public class RegexAnnotationConverter implements AnnotationConverter {

    private static final String regexName = org.checkerframework.checker.regex.qual.Regex.class.getName();
    private static final Regex DEFAULT = Regex.TOP;

    /** If annotated with @Regex, create a RegexVal qualifier. **/
    @Override
    public Regex fromAnnotations(Collection annos) {

        for (AnnotationMirror anno: annos) {
            if (AnnotationUtils.annotationName(anno).equals(regexName)) {
                Integer value = AnnotationUtils.getElementValue(anno, "value", Integer.class, true);
                return new Regex.RegexVal(value);
            }
        }
        return DEFAULT;
    }

    @Override
    public boolean isAnnotationSupported(AnnotationMirror anno) {
        return AnnotationUtils.annotationName(anno).equals(regexName);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy