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

checker.src.org.checkerframework.checker.nullness.qual.RequiresNonNull Maven / Gradle / Ivy

package org.checkerframework.checker.nullness.qual;

import org.checkerframework.checker.nullness.qual.NonNull;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.checkerframework.framework.qual.PreconditionAnnotation;

/**
 * Indicates a method precondition:  the method expects the specified
 * expressions to be non-null when the annotated method is invoked.
 *
 * 

For example: * *

 *  @Nullable Object field1;
 *  @Nullable Object field2;
 *
 *  @RequiresNonNull("field1")
 *  void method1() {
 *    field1.toString();        // OK, field1 is known to be non-null
 *    field2.toString();        // error, might throw NullPointerException
 *  }
 *
 *  void method2() {
 *    field1 = new Object();
 *    method1();                // OK, satisfies method precondition
 *    field1 = null;
 *    method1();                // error, does not satisfy method precondition
 *  }
 * 
* * @checker_framework.manual #nullness-checker Nullness Checker */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.CONSTRUCTOR }) @PreconditionAnnotation(qualifier = NonNull.class) public @interface RequiresNonNull { /** * The Java expressions that need to be {@link NonNull}. * * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions */ String[] value(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy