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

checker.src.org.checkerframework.checker.nullness.NullnessAnnotatedTypeFormatter 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.nullness;

import org.checkerframework.framework.type.AnnotatedTypeMirror;
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedNullType;
import org.checkerframework.framework.type.DefaultAnnotatedTypeFormatter;
import org.checkerframework.framework.util.AnnotationFormatter;
import org.checkerframework.framework.util.DefaultAnnotationFormatter;

import java.util.Set;

/**
 * A DefaultAnnotatedTypeFormatter that prints null literals without their annotations.
 */
public class NullnessAnnotatedTypeFormatter extends DefaultAnnotatedTypeFormatter {
    public NullnessAnnotatedTypeFormatter(boolean printVerboseGenerics, boolean printInvisibleQualifiers) {
        super(new NullnessFormattingVisitor(new DefaultAnnotationFormatter(), printVerboseGenerics,  printInvisibleQualifiers));
    }

    protected static class NullnessFormattingVisitor extends FormattingVisitor {

        public NullnessFormattingVisitor(AnnotationFormatter annoFormatter, boolean printVerboseGenerics,
                                         boolean defaultInvisiblesSetting) {
            super(annoFormatter, printVerboseGenerics, defaultInvisiblesSetting);
        }

        @Override
        public String visitNull(AnnotatedNullType type, Set visiting) {
            // The null literal will be understood as nullable by readers, therefore omit the annotations
            // Note: The visitTypeVariable will still print lower bounds with Null kind as "Void"
            if (!currentPrintInvisibleSetting) {
                return "null";
            } // else

            return super.visitNull(type, visiting);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy