Skip to content
This repository
Browse code

add Nullable annotations

  • Loading branch information...
commit 0b2d23d491e7bc36a6156e6b3c11c382dfac9291 1 parent 2d1aacd
Vlad Dumitrescu authored
4  org.erlide.libs/META-INF/MANIFEST.MF
@@ -55,6 +55,7 @@ Export-Package: com.ericsson.otp.erlang,
55 55
  org.apache.commons.io.filefilter,
56 56
  org.apache.commons.io.input,
57 57
  org.apache.commons.io.output,
  58
+ org.eclipse.jdt.annotation,
58 59
  org.eclipse.xtend2.lib,
59 60
  org.eclipse.xtext.xbase.lib,
60 61
  org.eclipse.xtext.xbase.lib.internal;x-internal:=true,
@@ -79,4 +80,5 @@ Export-Package: com.ericsson.otp.erlang,
79 80
  org.hamcrest.number,
80 81
  org.hamcrest.object,
81 82
  org.hamcrest.text,
82  
- org.hamcrest.xml
  83
+ org.hamcrest.xml,
  84
+ org.incava.util.diff
64  org.erlide.libs/src/org/eclipse/jdt/annotation/NonNull.java
... ...
@@ -0,0 +1,64 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2011 Stephan Herrmann.
  3
+ * All rights reserved. This program and the accompanying materials
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ *
  8
+ * Contributors:
  9
+ *     Stephan Herrmann - initial API and implementation 
  10
+ *******************************************************************************/
  11
+package org.eclipse.jdt.annotation;
  12
+
  13
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
  14
+import static java.lang.annotation.ElementType.METHOD;
  15
+import static java.lang.annotation.ElementType.PARAMETER;
  16
+
  17
+import java.lang.annotation.Retention;
  18
+import java.lang.annotation.RetentionPolicy;
  19
+import java.lang.annotation.Target;
  20
+
  21
+/**
  22
+ * <blockquote> This annotation is intended for use by the Eclipse Java Compiler
  23
+ * in order to support intra-procedural null analysis. Please see the original
  24
+ * <a href="http://bugs.eclipse.org/bugs/186342">Bug 186342- [compiler][null]
  25
+ * Using annotations for null checking</a> and the <a
  26
+ * href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Wiki page</a> for
  27
+ * status and availability of the implementation of these analyses.
  28
+ * </blockquote>
  29
+ * <p>
  30
+ * Qualifier for a type in a method signature or a local variable declaration.
  31
+ * The entity (return value, parameter, local variable) whose type has this
  32
+ * annotation can never have the value <code>null</code> at runtime.
  33
+ * <p>
  34
+ * This has two consequences:
  35
+ * <ol>
  36
+ * <li>Dereferencing the entity is safe, i.e., no
  37
+ * <code>NullPointerException</code> can occur at runtime.</li>
  38
+ * <li>An attempt to bind a <code>null</code> value to the entity is a compile
  39
+ * time error.</li>
  40
+ * </ol>
  41
+ * For the second case diagnostics issued by the compiler should distinguish
  42
+ * three situations:
  43
+ * <ol>
  44
+ * <li>Nullness of the value can be statically determined, the entity is
  45
+ * definitely bound from either of:
  46
+ * <ul>
  47
+ * <li>the value <code>null</code>, or</li>
  48
+ * <li>an entity with a {@link Nullable @Nullable} type.</li>
  49
+ * </ul>
  50
+ * </li>
  51
+ * <li>Nullness can not definitely be determined, because different code
  52
+ * branches yield different results.</li>
  53
+ * <li>Nullness can not be determined, because other program elements are
  54
+ * involved for which null annotations are lacking.</li>
  55
+ * </ol>
  56
+ * </p>
  57
+ * 
  58
+ * @author stephan
  59
+ */
  60
+@Retention(RetentionPolicy.CLASS)
  61
+@Target({ METHOD, PARAMETER, LOCAL_VARIABLE })
  62
+public @interface NonNull {
  63
+
  64
+}
53  org.erlide.libs/src/org/eclipse/jdt/annotation/NonNullByDefault.java
... ...
@@ -0,0 +1,53 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2011 Stephan Herrmann.
  3
+ * All rights reserved. This program and the accompanying materials
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ *
  8
+ * Contributors:
  9
+ *     Stephan Herrmann - initial API and implementation 
  10
+ *******************************************************************************/
  11
+package org.eclipse.jdt.annotation;
  12
+
  13
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
  14
+import static java.lang.annotation.ElementType.METHOD;
  15
+import static java.lang.annotation.ElementType.PACKAGE;
  16
+import static java.lang.annotation.ElementType.TYPE;
  17
+
  18
+import java.lang.annotation.Retention;
  19
+import java.lang.annotation.RetentionPolicy;
  20
+import java.lang.annotation.Target;
  21
+
  22
+/**
  23
+ * <blockquote> This annotation is intended for use by the Eclipse Java Compiler
  24
+ * in order to support intra-procedural null analysis. Please see the original
  25
+ * <a href="http://bugs.eclipse.org/bugs/186342">Bug 186342- [compiler][null]
  26
+ * Using annotations for null checking</a> and the <a
  27
+ * href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Wiki page</a> for
  28
+ * status and availability of the implementation of these analyses.
  29
+ * </blockquote>
  30
+ * <p>
  31
+ * This annotation can be applied to a package or a type in order to define that
  32
+ * all contained entities for which a null annotation is otherwise lacking
  33
+ * should be considered as {@link NonNull @NonNull}.
  34
+ * <dl>
  35
+ * <dt>Interaction with inheritance</dt>
  36
+ * <dd>The rules regarding inheritance are applied <em>after</em> the applicable
  37
+ * default has been applied to all types lacking an annotation.</dd>
  38
+ * <dt>Nested defaults</dt>
  39
+ * <dd>If a <code>@NonNullByDefault</code> annotation is used within the scope
  40
+ * of a {@link NullableByDefault @NullableByDefault} annotation (or a project
  41
+ * wide default setting) the inner most annotation defines the default
  42
+ * applicable at any given position.</dd>
  43
+ * </dl>
  44
+ * Note that for applying an annotation to a package a file by the name
  45
+ * <code>package-info.java</code> is used.
  46
+ * 
  47
+ * @author stephan
  48
+ */
  49
+@Retention(RetentionPolicy.CLASS)
  50
+@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })
  51
+public @interface NonNullByDefault {
  52
+    boolean value() default true;
  53
+}
48  org.erlide.libs/src/org/eclipse/jdt/annotation/Nullable.java
... ...
@@ -0,0 +1,48 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2011 Stephan Herrmann.
  3
+ * All rights reserved. This program and the accompanying materials
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ *
  8
+ * Contributors:
  9
+ *     Stephan Herrmann - initial API and implementation 
  10
+ *******************************************************************************/
  11
+package org.eclipse.jdt.annotation;
  12
+
  13
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
  14
+import static java.lang.annotation.ElementType.METHOD;
  15
+import static java.lang.annotation.ElementType.PARAMETER;
  16
+
  17
+import java.lang.annotation.Retention;
  18
+import java.lang.annotation.RetentionPolicy;
  19
+import java.lang.annotation.Target;
  20
+
  21
+/**
  22
+ * <blockquote> This annotation is intended for use by the Eclipse Java Compiler
  23
+ * in order to support intra-procedural null analysis. Please see the original
  24
+ * <a href="http://bugs.eclipse.org/bugs/186342">Bug 186342- [compiler][null]
  25
+ * Using annotations for null checking</a> and the <a
  26
+ * href="http://wiki.eclipse.org/JDT_Core/Null_Analysis">Wiki page</a> for
  27
+ * status and availability of the implementation of these analyses.
  28
+ * </blockquote>
  29
+ * <p>
  30
+ * Qualifier for a type in a method signature or a local variable declaration.
  31
+ * The entity (return value, parameter, local variable) whose type has this
  32
+ * annotation is allowed to have the value <code>null</code> at runtime.
  33
+ * <p>
  34
+ * This has two consequences:
  35
+ * <ul>
  36
+ * <li>Binding a <code>null</code> value to the entity is legal.</li>
  37
+ * <li>Dereferencing the entity is unsafe, i.e., a
  38
+ * <code>NullPointerException</code> can occur at runtime.</li>
  39
+ * </ul>
  40
+ * </p>
  41
+ * 
  42
+ * @author stephan
  43
+ */
  44
+@Retention(RetentionPolicy.CLASS)
  45
+@Target({ METHOD, PARAMETER, LOCAL_VARIABLE })
  46
+public @interface Nullable {
  47
+
  48
+}

0 notes on commit 0b2d23d

Please sign in to comment.
Something went wrong with that request. Please try again.