Permalink
Browse files

add Nullable annotations

  • Loading branch information...
vladdu committed Mar 17, 2012
1 parent 2d1aacd commit 0b2d23d491e7bc36a6156e6b3c11c382dfac9291
@@ -55,6 +55,7 @@ Export-Package: com.ericsson.otp.erlang,
org.apache.commons.io.filefilter,
org.apache.commons.io.input,
org.apache.commons.io.output,
+ org.eclipse.jdt.annotation,
org.eclipse.xtend2.lib,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtext.xbase.lib.internal;x-internal:=true,
@@ -79,4 +80,5 @@ Export-Package: com.ericsson.otp.erlang,
org.hamcrest.number,
org.hamcrest.object,
org.hamcrest.text,
- org.hamcrest.xml
+ org.hamcrest.xml,
+ org.incava.util.diff
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Stephan Herrmann.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stephan Herrmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.annotation;
+
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <blockquote> This annotation is intended for use by the Eclipse Java Compiler
+ * in order to support intra-procedural null analysis. Please see the original
+ * <a href="http://bugs.eclipse.org/bugs/186342">Bug 186342- [compiler][null]
+ * Using annotations for null checking</a> and the <a
+ * href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Wiki page</a> for
+ * status and availability of the implementation of these analyses.
+ * </blockquote>
+ * <p>
+ * Qualifier for a type in a method signature or a local variable declaration.
+ * The entity (return value, parameter, local variable) whose type has this
+ * annotation can never have the value <code>null</code> at runtime.
+ * <p>
+ * This has two consequences:
+ * <ol>
+ * <li>Dereferencing the entity is safe, i.e., no
+ * <code>NullPointerException</code> can occur at runtime.</li>
+ * <li>An attempt to bind a <code>null</code> value to the entity is a compile
+ * time error.</li>
+ * </ol>
+ * For the second case diagnostics issued by the compiler should distinguish
+ * three situations:
+ * <ol>
+ * <li>Nullness of the value can be statically determined, the entity is
+ * definitely bound from either of:
+ * <ul>
+ * <li>the value <code>null</code>, or</li>
+ * <li>an entity with a {@link Nullable @Nullable} type.</li>
+ * </ul>
+ * </li>
+ * <li>Nullness can not definitely be determined, because different code
+ * branches yield different results.</li>
+ * <li>Nullness can not be determined, because other program elements are
+ * involved for which null annotations are lacking.</li>
+ * </ol>
+ * </p>
+ *
+ * @author stephan
+ */
+@Retention(RetentionPolicy.CLASS)
+@Target({ METHOD, PARAMETER, LOCAL_VARIABLE })
+public @interface NonNull {
+
+}
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Stephan Herrmann.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stephan Herrmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.annotation;
+
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.TYPE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <blockquote> This annotation is intended for use by the Eclipse Java Compiler
+ * in order to support intra-procedural null analysis. Please see the original
+ * <a href="http://bugs.eclipse.org/bugs/186342">Bug 186342- [compiler][null]
+ * Using annotations for null checking</a> and the <a
+ * href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Wiki page</a> for
+ * status and availability of the implementation of these analyses.
+ * </blockquote>
+ * <p>
+ * This annotation can be applied to a package or a type in order to define that
+ * all contained entities for which a null annotation is otherwise lacking
+ * should be considered as {@link NonNull @NonNull}.
+ * <dl>
+ * <dt>Interaction with inheritance</dt>
+ * <dd>The rules regarding inheritance are applied <em>after</em> the applicable
+ * default has been applied to all types lacking an annotation.</dd>
+ * <dt>Nested defaults</dt>
+ * <dd>If a <code>@NonNullByDefault</code> annotation is used within the scope
+ * of a {@link NullableByDefault @NullableByDefault} annotation (or a project
+ * wide default setting) the inner most annotation defines the default
+ * applicable at any given position.</dd>
+ * </dl>
+ * Note that for applying an annotation to a package a file by the name
+ * <code>package-info.java</code> is used.
+ *
+ * @author stephan
+ */
+@Retention(RetentionPolicy.CLASS)
+@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })
+public @interface NonNullByDefault {
+ boolean value() default true;
+}
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Stephan Herrmann.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stephan Herrmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.annotation;
+
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <blockquote> This annotation is intended for use by the Eclipse Java Compiler
+ * in order to support intra-procedural null analysis. Please see the original
+ * <a href="http://bugs.eclipse.org/bugs/186342">Bug 186342- [compiler][null]
+ * Using annotations for null checking</a> and the <a
+ * href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Wiki page</a> for
+ * status and availability of the implementation of these analyses.
+ * </blockquote>
+ * <p>
+ * Qualifier for a type in a method signature or a local variable declaration.
+ * The entity (return value, parameter, local variable) whose type has this
+ * annotation is allowed to have the value <code>null</code> at runtime.
+ * <p>
+ * This has two consequences:
+ * <ul>
+ * <li>Binding a <code>null</code> value to the entity is legal.</li>
+ * <li>Dereferencing the entity is unsafe, i.e., a
+ * <code>NullPointerException</code> can occur at runtime.</li>
+ * </ul>
+ * </p>
+ *
+ * @author stephan
+ */
+@Retention(RetentionPolicy.CLASS)
+@Target({ METHOD, PARAMETER, LOCAL_VARIABLE })
+public @interface Nullable {
+
+}

0 comments on commit 0b2d23d

Please sign in to comment.