| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2011, 2014 Stephan Herrmann and others. |
| 3 | * |
| 4 | * This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | * |
| 9 | * SPDX-License-Identifier: EPL-2.0 |
| 10 | * |
| 11 | * Contributors: |
| 12 | * Stephan Herrmann - initial API and implementation |
| 13 | * IBM Corporation - bug fixes |
| 14 | *******************************************************************************/ |
| 15 | package org.eclipse.jdt.annotation; |
| 16 | |
| 17 | import java.lang.annotation.ElementType; |
| 18 | import static org.eclipse.jdt.annotation.DefaultLocation.*; |
| 19 | |
| 20 | import java.lang.annotation.Documented; |
| 21 | import java.lang.annotation.Retention; |
| 22 | import java.lang.annotation.RetentionPolicy; |
| 23 | |
| 24 | /** |
| 25 | * Applying this annotation to a declaration has the effect that type references, |
| 26 | * which are contained in the declaration, and for which a null annotation is otherwise lacking, |
| 27 | * should be considered as {@link NonNull @NonNull}. |
| 28 | * <dl> |
| 29 | * <dt>Locations</dt> |
| 30 | * <dd>This annotation is permitted for these declarations: |
| 31 | * {@link ElementType#PACKAGE PACKAGE}, {@link ElementType#TYPE TYPE}, |
| 32 | * {@link ElementType#METHOD METHOD}, {@link ElementType#CONSTRUCTOR CONSTRUCTOR}, |
| 33 | * {@link ElementType#FIELD FIELD}, {@link ElementType#LOCAL_VARIABLE LOCAL_VARIABLE}.</dd> |
| 34 | * <dt>Fine tuning</dt> |
| 35 | * <dd>The exact effect is further controlled by the attribute {@link #value}, specifying what |
| 36 | * kinds of locations within the given declaration will be affected. See {@link DefaultLocation} |
| 37 | * for the meaning of the available values.</dd> |
| 38 | * <dt>Nested defaults</dt> |
| 39 | * <dd>If this annotation is applied to a declaration that is already affected by the same |
| 40 | * annotation at an enclosing scope, the inner annotation <em>replaces</em> the effect of the |
| 41 | * outer annotation for the scope of the inner declaration.</dd> |
| 42 | * <dt>Canceling a default</dt> |
| 43 | * <dd>In particular, specifying an empty value (<code>{}</code>) for the {@link #value} |
| 44 | * attribute has the effect of canceling any null defaults that might be defined for any |
| 45 | * enclosing scope.</dd> |
| 46 | * </dl> |
| 47 | * <p> |
| 48 | * Note that for applying an annotation to a package, a file by the name |
| 49 | * <code>package-info.java</code> is used. |
| 50 | * </p> |
| 51 | * <p> |
| 52 | * <b>Note:</b> Since org.eclipse.jdt.annotation 2.0.0, this annotation also applies to field and |
| 53 | * local variable declarations and since 2.2.0 also to parameter and module declarations. |
| 54 | * For the old API, see |
| 55 | * <a href="http://help.eclipse.org/kepler/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/annotation/NonNullByDefault.html"> |
| 56 | * <code>@NonNullByDefault</code> in 1.1.0</a>. |
| 57 | * </p> |
| 58 | * @since 1.0 |
| 59 | */ |
| 60 | @Documented |
| 61 | @Retention(RetentionPolicy.CLASS) |
| 62 | public @interface NonNullByDefault { |
| 63 | /** |
| 64 | * Specifies the set of locations within the annotated declaration that should be affected by the nonnull default. |
| 65 | * @return the locations, or an empty array to cancel any null defaults from enclosing scopes |
| 66 | * @since 2.0 |
| 67 | */ |
| 68 | DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT }; |
| 69 | } |