From cd1b0f5f31e5dc77b43a487c2c3d42fc97ebb432 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 28 May 2015 14:03:35 +0300 Subject: [PATCH] build annotations.jar for Java 8 which contains @NotNull/@Nullable annotations which can be applied to types (IDEA-123048) --- .idea/compiler.xml | 2 + .idea/modules.xml | 2 + build/scripts/layouts.gant | 11 ++++- platform/annotations/annotations.iml | 5 +- .../annotations/common/annotations-common.iml | 11 +++++ .../org/intellij/lang/annotations/Flow.java | 17 +++---- .../intellij/lang/annotations/Identifier.java | 0 .../lang/annotations/JdkConstants.java | 0 .../intellij/lang/annotations/Language.java | 0 .../lang/annotations/MagicConstant.java | 0 .../intellij/lang/annotations/Pattern.java | 0 .../lang/annotations/PrintFormat.java | 0 .../org/intellij/lang/annotations/RegExp.java | 0 .../org/intellij/lang/annotations/Subst.java | 0 .../org/jetbrains/annotations/Contract.java | 0 .../src/org/jetbrains/annotations/Nls.java | 0 .../src/org/jetbrains/annotations/NonNls.java | 0 .../jetbrains/annotations/PropertyKey.java | 0 .../org/jetbrains/annotations/TestOnly.java | 0 .../org/jetbrains/annotations/NotNull.java | 0 .../org/jetbrains/annotations/Nullable.java | 0 .../annotations/java8/annotations-java8.iml | 12 +++++ .../org/jetbrains/annotations/NotNull.java | 46 +++++++++++++++++++ .../org/jetbrains/annotations/Nullable.java | 44 ++++++++++++++++++ python/build/pycharm_community_build.gant | 5 +- python/edu/build/pycharm_edu_build.gant | 5 +- 26 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 platform/annotations/common/annotations-common.iml rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/Flow.java (91%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/Identifier.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/JdkConstants.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/Language.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/MagicConstant.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/Pattern.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/PrintFormat.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/RegExp.java (100%) rename platform/annotations/{ => common}/src/org/intellij/lang/annotations/Subst.java (100%) rename platform/annotations/{ => common}/src/org/jetbrains/annotations/Contract.java (100%) rename platform/annotations/{ => common}/src/org/jetbrains/annotations/Nls.java (100%) rename platform/annotations/{ => common}/src/org/jetbrains/annotations/NonNls.java (100%) rename platform/annotations/{ => common}/src/org/jetbrains/annotations/PropertyKey.java (100%) rename platform/annotations/{ => common}/src/org/jetbrains/annotations/TestOnly.java (100%) rename platform/annotations/{ => java5}/src/org/jetbrains/annotations/NotNull.java (100%) rename platform/annotations/{ => java5}/src/org/jetbrains/annotations/Nullable.java (100%) create mode 100644 platform/annotations/java8/annotations-java8.iml create mode 100644 platform/annotations/java8/src/org/jetbrains/annotations/NotNull.java create mode 100644 platform/annotations/java8/src/org/jetbrains/annotations/Nullable.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 45b7ee7bca2c..ab40a1f9a05c 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -31,6 +31,8 @@ + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 00496ab2ae4e..608f45776b35 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -20,6 +20,8 @@ + + diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 8371da01bba4..99ef7740bfce 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -133,7 +133,14 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir openapiModules.each { module it} } - jar("annotations.jar") { module("annotations")} + jar("annotations.jar") { + module("annotations-common") + module("annotations") + } + jar("annotations-java8.jar") { + module("annotations-common") + module("annotations-java8") + } jar("jdkAnnotations.jar") { fileset(dir: "${home}/java/jdkAnnotations") } @@ -752,6 +759,7 @@ def layoutJps(String home, String targetDir, String buildNumber, Closure additio layout(targetDir) { zip("standalone-jps-${buildNumber}.zip") { jar("util.jar") { + module("annotations-common") module("annotations") module("util-rt") module("util") @@ -842,6 +850,7 @@ def layout_core(String home, String target) { } jar("annotations.jar") { + module("annotations-common") module("annotations") } diff --git a/platform/annotations/annotations.iml b/platform/annotations/annotations.iml index 262fa5663fcd..a60e6489f219 100644 --- a/platform/annotations/annotations.iml +++ b/platform/annotations/annotations.iml @@ -4,9 +4,10 @@ + + - - + \ No newline at end of file diff --git a/platform/annotations/common/annotations-common.iml b/platform/annotations/common/annotations-common.iml new file mode 100644 index 000000000000..f22b3a197539 --- /dev/null +++ b/platform/annotations/common/annotations-common.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/platform/annotations/src/org/intellij/lang/annotations/Flow.java b/platform/annotations/common/src/org/intellij/lang/annotations/Flow.java similarity index 91% rename from platform/annotations/src/org/intellij/lang/annotations/Flow.java rename to platform/annotations/common/src/org/intellij/lang/annotations/Flow.java index 212103e904c9..1854d4c2297e 100644 --- a/platform/annotations/src/org/intellij/lang/annotations/Flow.java +++ b/platform/annotations/common/src/org/intellij/lang/annotations/Flow.java @@ -15,9 +15,10 @@ */ package org.intellij.lang.annotations; -import org.jetbrains.annotations.NonNls; - -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * This annotation assists the 'Data flow to this' feature by describing data flow @@ -60,8 +61,8 @@ public @interface Flow { * */ String source() default org.intellij.lang.annotations.Flow.DEFAULT_SOURCE; - @NonNls String DEFAULT_SOURCE = "The method argument (if parameter was annotated) or this container (if instance method was annotated)"; - @NonNls String THIS_SOURCE = "this"; + String DEFAULT_SOURCE = "The method argument (if parameter was annotated) or this container (if instance method was annotated)"; + String THIS_SOURCE = "this"; /** * true if the data source is container and we should track not the expression but its contents.
@@ -109,9 +110,9 @@ public @interface Flow { * */ String target() default org.intellij.lang.annotations.Flow.DEFAULT_TARGET; - @NonNls String DEFAULT_TARGET = "This container (if the parameter was annotated) or the return value (if instance method was annotated)"; - @NonNls String RETURN_METHOD_TARGET = "The return value of this method"; - @NonNls String THIS_TARGET = "this"; + String DEFAULT_TARGET = "This container (if the parameter was annotated) or the return value (if instance method was annotated)"; + String RETURN_METHOD_TARGET = "The return value of this method"; + String THIS_TARGET = "this"; /** * true if the data target is container and we should track not the expression but its contents.
diff --git a/platform/annotations/src/org/intellij/lang/annotations/Identifier.java b/platform/annotations/common/src/org/intellij/lang/annotations/Identifier.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/Identifier.java rename to platform/annotations/common/src/org/intellij/lang/annotations/Identifier.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/JdkConstants.java b/platform/annotations/common/src/org/intellij/lang/annotations/JdkConstants.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/JdkConstants.java rename to platform/annotations/common/src/org/intellij/lang/annotations/JdkConstants.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/Language.java b/platform/annotations/common/src/org/intellij/lang/annotations/Language.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/Language.java rename to platform/annotations/common/src/org/intellij/lang/annotations/Language.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/MagicConstant.java b/platform/annotations/common/src/org/intellij/lang/annotations/MagicConstant.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/MagicConstant.java rename to platform/annotations/common/src/org/intellij/lang/annotations/MagicConstant.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/Pattern.java b/platform/annotations/common/src/org/intellij/lang/annotations/Pattern.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/Pattern.java rename to platform/annotations/common/src/org/intellij/lang/annotations/Pattern.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/PrintFormat.java b/platform/annotations/common/src/org/intellij/lang/annotations/PrintFormat.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/PrintFormat.java rename to platform/annotations/common/src/org/intellij/lang/annotations/PrintFormat.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/RegExp.java b/platform/annotations/common/src/org/intellij/lang/annotations/RegExp.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/RegExp.java rename to platform/annotations/common/src/org/intellij/lang/annotations/RegExp.java diff --git a/platform/annotations/src/org/intellij/lang/annotations/Subst.java b/platform/annotations/common/src/org/intellij/lang/annotations/Subst.java similarity index 100% rename from platform/annotations/src/org/intellij/lang/annotations/Subst.java rename to platform/annotations/common/src/org/intellij/lang/annotations/Subst.java diff --git a/platform/annotations/src/org/jetbrains/annotations/Contract.java b/platform/annotations/common/src/org/jetbrains/annotations/Contract.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/Contract.java rename to platform/annotations/common/src/org/jetbrains/annotations/Contract.java diff --git a/platform/annotations/src/org/jetbrains/annotations/Nls.java b/platform/annotations/common/src/org/jetbrains/annotations/Nls.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/Nls.java rename to platform/annotations/common/src/org/jetbrains/annotations/Nls.java diff --git a/platform/annotations/src/org/jetbrains/annotations/NonNls.java b/platform/annotations/common/src/org/jetbrains/annotations/NonNls.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/NonNls.java rename to platform/annotations/common/src/org/jetbrains/annotations/NonNls.java diff --git a/platform/annotations/src/org/jetbrains/annotations/PropertyKey.java b/platform/annotations/common/src/org/jetbrains/annotations/PropertyKey.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/PropertyKey.java rename to platform/annotations/common/src/org/jetbrains/annotations/PropertyKey.java diff --git a/platform/annotations/src/org/jetbrains/annotations/TestOnly.java b/platform/annotations/common/src/org/jetbrains/annotations/TestOnly.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/TestOnly.java rename to platform/annotations/common/src/org/jetbrains/annotations/TestOnly.java diff --git a/platform/annotations/src/org/jetbrains/annotations/NotNull.java b/platform/annotations/java5/src/org/jetbrains/annotations/NotNull.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/NotNull.java rename to platform/annotations/java5/src/org/jetbrains/annotations/NotNull.java diff --git a/platform/annotations/src/org/jetbrains/annotations/Nullable.java b/platform/annotations/java5/src/org/jetbrains/annotations/Nullable.java similarity index 100% rename from platform/annotations/src/org/jetbrains/annotations/Nullable.java rename to platform/annotations/java5/src/org/jetbrains/annotations/Nullable.java diff --git a/platform/annotations/java8/annotations-java8.iml b/platform/annotations/java8/annotations-java8.iml new file mode 100644 index 000000000000..e88ccbbc628e --- /dev/null +++ b/platform/annotations/java8/annotations-java8.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/annotations/java8/src/org/jetbrains/annotations/NotNull.java b/platform/annotations/java8/src/org/jetbrains/annotations/NotNull.java new file mode 100644 index 000000000000..d71b3c6c086b --- /dev/null +++ b/platform/annotations/java8/src/org/jetbrains/annotations/NotNull.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +/** + * An element annotated with NotNull claims null value is forbidden + * to return (for methods), pass to (parameters) and hold (local variables and fields). + * Apart from documentation purposes this annotation is intended to be used by static analysis tools + * to validate against probable runtime errors and element contract violations. + * + * @author max + */ +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { + /** + * @return Custom exception message + */ + String value() default ""; + + /** + * @return Custom exception type that should be thrown when not-nullity contract is violated. + * The exception class should have a constructor with one String argument (message). + * + * By default, {@link IllegalArgumentException} is thrown on null method arguments and + * {@link IllegalStateException} — on null return value. + */ + Class exception() default Exception.class; +} diff --git a/platform/annotations/java8/src/org/jetbrains/annotations/Nullable.java b/platform/annotations/java8/src/org/jetbrains/annotations/Nullable.java new file mode 100644 index 000000000000..39e3123061d2 --- /dev/null +++ b/platform/annotations/java8/src/org/jetbrains/annotations/Nullable.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +/** + * An element annotated with {@link Nullable} claims {@code null} value is perfectly valid + * to return (for methods), pass to (parameters) or hold in (local variables and fields). + * Apart from documentation purposes this annotation is intended to be used by static analysis tools + * to validate against probable runtime errors or element contract violations. + *
+ * By convention, this annotation applied only when the value should always be checked against {@code null} + * because the developer could do nothing to prevent null from happening. + * Otherwise, too eager {@link Nullable} usage could lead to too many false positives from static analysis tools. + *
+ * For example, {@link java.util.Map#get(Object key)} should not be annotated {@link Nullable} because + * someone may have put not-null value in the map by this key and is expecting to find this value there ever since. + *
+ * On the other hand, the {@link java.lang.ref.Reference#get()} should be annotated {@link Nullable} because + * it returns {@code null} if object got collected which can happen at any time completely unexpectedly. + * + * @author max + */ +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface Nullable { + String value() default ""; +} diff --git a/python/build/pycharm_community_build.gant b/python/build/pycharm_community_build.gant index dc268982e831..9a2564fe10d9 100644 --- a/python/build/pycharm_community_build.gant +++ b/python/build/pycharm_community_build.gant @@ -213,7 +213,10 @@ private layoutFull(Map args, String target, Set usedJars) { openapiModules.each { module it } } - jar("annotations.jar") { module("annotations") } + jar("annotations.jar") { + module("annotations-common") + module("annotations") + } jar("extensions.jar") { module("extensions") } jar("pycharm.jar") { diff --git a/python/edu/build/pycharm_edu_build.gant b/python/edu/build/pycharm_edu_build.gant index 4d38e7955e14..0e6f046312e2 100644 --- a/python/edu/build/pycharm_edu_build.gant +++ b/python/edu/build/pycharm_edu_build.gant @@ -246,7 +246,10 @@ private layoutFull(Map args, String target, Set usedJars) { openapiModules.each { module it } } - jar("annotations.jar") { module("annotations") } + jar("annotations.jar") { + module("annotations-common") + module("annotations") + } jar("extensions.jar") { module("extensions") } jar("pycharm.jar") {