diff options
author | Miguel Landaeta <miguel@miguel.cc> | 2010-08-19 19:15:00 -0430 |
---|---|---|
committer | Miguel Landaeta <miguel@miguel.cc> | 2010-08-19 19:15:00 -0430 |
commit | bba4c82c66206b947df4d4c37d4e8106d6a6dafa (patch) | |
tree | 120fa72598aad9f2e8598a5db902a53098682214 |
upstream import 0.1~+svn49
59 files changed, 1349 insertions, 0 deletions
diff --git a/.project b/.project new file mode 100644 index 0000000..1669c02 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>jsr305-trunk</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + </buildSpec> + <natures> + </natures> +</projectDescription> diff --git a/Readme.rtf b/Readme.rtf new file mode 100644 index 0000000..7880558 --- /dev/null +++ b/Readme.rtf @@ -0,0 +1,12 @@ +{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf420 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\margl1440\margr1440\vieww9000\viewh8400\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural + +\f0\fs24 \cf0 After installing maven, do the update and at the main directory, run either\ +\ + * mvn eclipse:clean eclipse:eclipse\ + * mvn idea:idea\ +\ +}
\ No newline at end of file @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jsr-305</groupId>
+ <artifactId>jsr-305</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <url>http://code.google.com/p/jsr-305/</url>
+ <packaging>pom</packaging>
+ <name>JSR 305: Annotations for Software Defect Detection in Java</name>
+ <description>Master Maven project for all JSR 305 projects</description>
+
+
+ <modules>
+ <module>ri</module>
+ <module>tcl</module>
+ <module>sampleUses</module>
+ <module>proposedAnnotations</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/proposedAnnotations/pom.xml b/proposedAnnotations/pom.xml new file mode 100644 index 0000000..831ae27 --- /dev/null +++ b/proposedAnnotations/pom.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jsr-305</groupId>
+ <artifactId>jsr-305</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jsr-305</groupId>
+ <artifactId>proposedAnnotations</artifactId>
+ <packaging>jar</packaging>
+ <name>JSR 305 Proposed Annotations</name>
+ <version>0.1-SNAPSHOT</version>
+ <description>Proposed Annotations for JSR-305</description>
+</project>
diff --git a/ri/.classpath b/ri/.classpath new file mode 100644 index 0000000..b0f1c60 --- /dev/null +++ b/ri/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="build/classes"/> +</classpath> diff --git a/ri/.project b/ri/.project new file mode 100644 index 0000000..4855f3b --- /dev/null +++ b/ri/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>JSR305-ri</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/ri/.settings/org.eclipse.jdt.core.prefs b/ri/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..1bb83fc --- /dev/null +++ b/ri/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Wed Jun 20 13:34:34 GMT-05:00 2007 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/ri/.settings/org.eclipse.jdt.ui.prefs b/ri/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..f1d942c --- /dev/null +++ b/ri/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,3 @@ +#Wed Jun 20 13:34:34 GMT-05:00 2007 +eclipse.preferences.version=1 +internal.default.compliance=default diff --git a/ri/LICENSE b/ri/LICENSE new file mode 100644 index 0000000..6736681 --- /dev/null +++ b/ri/LICENSE @@ -0,0 +1,28 @@ +Copyright (c) 2007-2009, JSR305 expert group +All rights reserved. + +http://www.opensource.org/licenses/bsd-license.php + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the JSR305 expert group nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/ri/build.xml b/ri/build.xml new file mode 100644 index 0000000..ad07dec --- /dev/null +++ b/ri/build.xml @@ -0,0 +1,35 @@ + +<project name="JSR305-ri" default="build"> + + + <target name="build" depends="clean,classes,jars"/> + <target name="classes"> + <mkdir dir="build/classes"/> + <javac destdir="build/classes" source="1.5" target="1.5" debug="on"> + <src path="src/main/java"/> + <classpath> + <pathelement location="build/classes"/> + </classpath> + </javac> + </target> + + <target name="clean"> + <delete dir="build/classes"/> + </target> + <target name="jars" depends="classes"> + <delete quiet="true"> + <fileset dir="build/jsr305.jar"/> + <fileset dir="build/jsr305-src.jar"/> + </delete> + <jar destfile="build/jsr305.jar"> + <fileset dir="src/main/java"/> + <fileset dir="build/classes"/> + </jar> + <jar destfile="build/jsr305-src.jar"> + <fileset dir="src/main/java"/> + <fileset dir="src/main/resources"/> + </jar> + </target> +</project> + +<!-- vim:set ts=4: --> diff --git a/ri/nbproject/project.xml b/ri/nbproject/project.xml new file mode 100644 index 0000000..e4a7852 --- /dev/null +++ b/ri/nbproject/project.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.ant.freeform</type> + <configuration> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> + <name>JSR305-ri</name> + </general-data> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2"> + <!-- Do not use Project Properties customizer when editing this file manually. --> + <name>JSR305-ri</name> + <properties/> + <folders> + <source-folder> + <label>src/main/java</label> + <type>java</type> + <location>src/main/java</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>src/main/resources</label> + <type>java</type> + <location>src/main/resources</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>JSR305-ri</label> + <location>.</location> + <encoding>UTF-8</encoding> + </source-folder> + </folders> + <ide-actions> + <action name="build"> + <target>build</target> + </action> + <action name="clean"> + <target>clean</target> + </action> + <action name="rebuild"> + <target>clean</target> + <target>build</target> + </action> + </ide-actions> + <export> + <type>folder</type> + <location>build</location> + <build-target>build</build-target> + </export> + <view> + <items> + <source-folder style="packages"> + <label>src/main/java</label> + <location>src/main/java</location> + </source-folder> + <source-folder style="packages"> + <label>src/main/resources</label> + <location>src/main/resources</location> + </source-folder> + <source-file> + <location>build.xml</location> + </source-file> + </items> + <context-menu> + <ide-action name="build"/> + <ide-action name="rebuild"/> + <ide-action name="clean"/> + </context-menu> + </view> + </general-data> + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"> + <compilation-unit> + <package-root>src/main/java</package-root> + <package-root>src/main/resources</package-root> + <built-to>build</built-to> + <source-level>1.5</source-level> + </compilation-unit> + </java-data> + </configuration> +</project> diff --git a/ri/pom.xml b/ri/pom.xml new file mode 100644 index 0000000..becde96 --- /dev/null +++ b/ri/pom.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jsr-305</groupId>
+ <artifactId>jsr-305</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jsr-305</groupId>
+ <artifactId>ri</artifactId>
+ <packaging>jar</packaging>
+ <name>JSR 305 Implementation</name>
+ <version>0.1-SNAPSHOT</version>
+ <description>Implementation for JSR-305</description>
+
+
+</project>
diff --git a/ri/src/main/java/javax/annotation/CheckForNull.java b/ri/src/main/java/javax/annotation/CheckForNull.java new file mode 100644 index 0000000..6fe5200 --- /dev/null +++ b/ri/src/main/java/javax/annotation/CheckForNull.java @@ -0,0 +1,16 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.MAYBE) +@Retention(RetentionPolicy.RUNTIME) +public @interface CheckForNull { + +} diff --git a/ri/src/main/java/javax/annotation/CheckForSigned.java b/ri/src/main/java/javax/annotation/CheckForSigned.java new file mode 100644 index 0000000..f3bc597 --- /dev/null +++ b/ri/src/main/java/javax/annotation/CheckForSigned.java @@ -0,0 +1,24 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +/** + * Used to annotate a value that may be either negative or nonnegative, and + * indicates that uses of it should check for + * negative values before using it in a way that requires the value to be + * nonnegative, and check for it being nonnegative before using it in a way that + * requires it to be negative. + */ + +@Documented +@TypeQualifierNickname +@Nonnegative(when = When.MAYBE) +@Retention(RetentionPolicy.RUNTIME) +public @interface CheckForSigned { + +} diff --git a/ri/src/main/java/javax/annotation/CheckReturnValue.java b/ri/src/main/java/javax/annotation/CheckReturnValue.java new file mode 100644 index 0000000..370fa38 --- /dev/null +++ b/ri/src/main/java/javax/annotation/CheckReturnValue.java @@ -0,0 +1,17 @@ +package javax.annotation; + +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 javax.annotation.meta.When; + +@Documented +@Target( { ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE, + ElementType.PACKAGE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface CheckReturnValue { + When when() default When.ALWAYS; +} diff --git a/ri/src/main/java/javax/annotation/Detainted.java b/ri/src/main/java/javax/annotation/Detainted.java new file mode 100644 index 0000000..d8620f2 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Detainted.java @@ -0,0 +1,16 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Untainted(when = When.ALWAYS) +@Retention(RetentionPolicy.RUNTIME) +public @interface Detainted { + +} diff --git a/ri/src/main/java/javax/annotation/MatchesPattern.java b/ri/src/main/java/javax/annotation/MatchesPattern.java new file mode 100644 index 0000000..775d21c --- /dev/null +++ b/ri/src/main/java/javax/annotation/MatchesPattern.java @@ -0,0 +1,30 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.regex.Pattern; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.TypeQualifierValidator; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier(applicableTo = String.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface MatchesPattern { + @RegEx + String value(); + + int flags() default 0; + + static class Checker implements TypeQualifierValidator<MatchesPattern> { + public When forConstantValue(MatchesPattern annotation, Object value) { + Pattern p = Pattern.compile(annotation.value(), annotation.flags()); + if (p.matcher(((String) value)).matches()) + return When.ALWAYS; + return When.NEVER; + } + + } +} diff --git a/ri/src/main/java/javax/annotation/Nonnegative.java b/ri/src/main/java/javax/annotation/Nonnegative.java new file mode 100644 index 0000000..21d1793 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Nonnegative.java @@ -0,0 +1,41 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.TypeQualifierValidator; +import javax.annotation.meta.When; + +/** Used to annotate a value that should only contain nonnegative values */ +@Documented +@TypeQualifier(applicableTo = Number.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface Nonnegative { + When when() default When.ALWAYS; + + class Checker implements TypeQualifierValidator<Nonnegative> { + + public When forConstantValue(Nonnegative annotation, Object v) { + if (!(v instanceof Number)) + return When.NEVER; + boolean isNegative; + Number value = (Number) v; + if (value instanceof Long) + isNegative = value.longValue() < 0; + else if (value instanceof Double) + isNegative = value.doubleValue() < 0; + else if (value instanceof Float) + isNegative = value.floatValue() < 0; + else + isNegative = value.intValue() < 0; + + if (isNegative) + return When.NEVER; + else + return When.ALWAYS; + + } + } +} diff --git a/ri/src/main/java/javax/annotation/Nonnull.java b/ri/src/main/java/javax/annotation/Nonnull.java new file mode 100644 index 0000000..4b7aad9 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Nonnull.java @@ -0,0 +1,26 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.TypeQualifierValidator; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier +@Retention(RetentionPolicy.RUNTIME) +public @interface Nonnull { + When when() default When.ALWAYS; + + static class Checker implements TypeQualifierValidator<Nonnull> { + + public When forConstantValue(Nonnull qualifierqualifierArgument, + Object value) { + if (value == null) + return When.NEVER; + return When.ALWAYS; + } + } +} diff --git a/ri/src/main/java/javax/annotation/Nullable.java b/ri/src/main/java/javax/annotation/Nullable.java new file mode 100644 index 0000000..d31993d --- /dev/null +++ b/ri/src/main/java/javax/annotation/Nullable.java @@ -0,0 +1,16 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.UNKNOWN) +@Retention(RetentionPolicy.RUNTIME) +public @interface Nullable { + +} diff --git a/ri/src/main/java/javax/annotation/OverridingMethodsMustInvokeSuper.java b/ri/src/main/java/javax/annotation/OverridingMethodsMustInvokeSuper.java new file mode 100644 index 0000000..4e3344e --- /dev/null +++ b/ri/src/main/java/javax/annotation/OverridingMethodsMustInvokeSuper.java @@ -0,0 +1,20 @@ +package javax.annotation; + +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; + +/** + * When this annotation is applied to a method, it indicates that if this method + * is overridden in a subclass, the overriding method should invoke this method + * (through method invocation on super). + * + */ +@Documented +@Target( { ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface OverridingMethodsMustInvokeSuper { + +} diff --git a/ri/src/main/java/javax/annotation/ParametersAreNonnullByDefault.java b/ri/src/main/java/javax/annotation/ParametersAreNonnullByDefault.java new file mode 100644 index 0000000..6424b87 --- /dev/null +++ b/ri/src/main/java/javax/annotation/ParametersAreNonnullByDefault.java @@ -0,0 +1,27 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierDefault; + +/** + * This annotation can be applied to a package, class or method to indicate that + * the method parameters in that element are nonnull by default unless there is: + * <ul> + * <li>An explicit nullness annotation + * <li>The method overrides a method in a superclass (in which case the + * annotation of the corresponding parameter in the superclass applies) + * <li> there is a default parameter annotation applied to a more tightly nested + * element. + * </ul> + * + */ +@Documented +@Nonnull +@TypeQualifierDefault(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface ParametersAreNonnullByDefault { +} diff --git a/ri/src/main/java/javax/annotation/ParametersAreNullableByDefault.java b/ri/src/main/java/javax/annotation/ParametersAreNullableByDefault.java new file mode 100644 index 0000000..01d4d80 --- /dev/null +++ b/ri/src/main/java/javax/annotation/ParametersAreNullableByDefault.java @@ -0,0 +1,30 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierDefault; + +/** + * This annotation can be applied to a package, class or method to indicate that + * the method parameters in that element are nullable by default unless there is: + * <ul> + * <li>An explicit nullness annotation + * <li>The method overrides a method in a superclass (in which case the + * annotation of the corresponding parameter in the superclass applies) + * <li> there is a default parameter annotation applied to a more tightly nested + * element. + * </ul> + * <p>This annotation implies the same "nullness" as no annotation. However, it is different + * than having no annotation, as it is inherited and it can override a ParametersAreNonnullByDefault + * annotation at an outer scope. + * + */ +@Documented +@Nullable +@TypeQualifierDefault(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface ParametersAreNullableByDefault { +} diff --git a/ri/src/main/java/javax/annotation/PropertyKey.java b/ri/src/main/java/javax/annotation/PropertyKey.java new file mode 100644 index 0000000..780782d --- /dev/null +++ b/ri/src/main/java/javax/annotation/PropertyKey.java @@ -0,0 +1,15 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier +@Retention(RetentionPolicy.RUNTIME) +public @interface PropertyKey { + When when() default When.ALWAYS; +} diff --git a/ri/src/main/java/javax/annotation/RegEx.java b/ri/src/main/java/javax/annotation/RegEx.java new file mode 100644 index 0000000..21697a7 --- /dev/null +++ b/ri/src/main/java/javax/annotation/RegEx.java @@ -0,0 +1,42 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.TypeQualifierValidator; +import javax.annotation.meta.When; + +/** + * This qualifier is used to denote String values that should be a Regular + * expression. + * + */ +@Documented +@Syntax("RegEx") +@TypeQualifierNickname +@Retention(RetentionPolicy.RUNTIME) +public @interface RegEx { + When when() default When.ALWAYS; + + static class Checker implements TypeQualifierValidator<RegEx> { + + public When forConstantValue(RegEx annotation, Object value) { + if (!(value instanceof String)) + return When.NEVER; + + try { + Pattern.compile((String) value); + } catch (PatternSyntaxException e) { + return When.NEVER; + } + return When.ALWAYS; + + } + + } + +} diff --git a/ri/src/main/java/javax/annotation/Signed.java b/ri/src/main/java/javax/annotation/Signed.java new file mode 100644 index 0000000..2c2fa06 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Signed.java @@ -0,0 +1,18 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +/** Used to annotate a value of unknown sign */ + +@Documented +@TypeQualifierNickname +@Nonnegative(when = When.UNKNOWN) +@Retention(RetentionPolicy.RUNTIME) +public @interface Signed { + +} diff --git a/ri/src/main/java/javax/annotation/Syntax.java b/ri/src/main/java/javax/annotation/Syntax.java new file mode 100644 index 0000000..5491093 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Syntax.java @@ -0,0 +1,44 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.When; + +/** + * This annotation a value that is of a particular syntax, such as Java syntax + * or regular expression syntax. This can be used to provide syntax checking of + * constant values at compile time, run time checking at runtime, and can assist + * IDEs in deciding how to interpret String constants (e.g., should a + * refactoring that renames method x() to y() update the String constant "x()"). + * + * + */ +@Documented +@TypeQualifier(applicableTo = String.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface Syntax { + /** + * Value indicating the particular syntax denoted by this annotation. + * Different tools will recognize different syntaxes, but some proposed + * canonical values are: + * <ul> + * <li> "Java" + * <li> "RegEx" + * <li> "JavaScript" + * <li> "Ruby" + * <li> "Groovy" + * <li> "SQL" + * <li> "FormatString" + * </ul> + * + * Syntax names can be followed by a colon and a list of key value pairs, + * separated by commas. For example, "SQL:dialect=Oracle,version=2.3". Tools + * should ignore any keys they don't recognize. + */ + String value(); + + When when() default When.ALWAYS; +} diff --git a/ri/src/main/java/javax/annotation/Tainted.java b/ri/src/main/java/javax/annotation/Tainted.java new file mode 100644 index 0000000..6715d70 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Tainted.java @@ -0,0 +1,16 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Untainted(when = When.MAYBE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Tainted { + +} diff --git a/ri/src/main/java/javax/annotation/Untainted.java b/ri/src/main/java/javax/annotation/Untainted.java new file mode 100644 index 0000000..4a26a49 --- /dev/null +++ b/ri/src/main/java/javax/annotation/Untainted.java @@ -0,0 +1,15 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier +@Retention(RetentionPolicy.RUNTIME) +public @interface Untainted { + When when() default When.ALWAYS; +} diff --git a/ri/src/main/java/javax/annotation/WillClose.java b/ri/src/main/java/javax/annotation/WillClose.java new file mode 100644 index 0000000..9ea70cf --- /dev/null +++ b/ri/src/main/java/javax/annotation/WillClose.java @@ -0,0 +1,15 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Documented +@Retention(RetentionPolicy.RUNTIME) +/** + * Used to annotate a method parameter to indicate that this method will close + * the resource. + */ +public @interface WillClose { + +} diff --git a/ri/src/main/java/javax/annotation/WillCloseWhenClosed.java b/ri/src/main/java/javax/annotation/WillCloseWhenClosed.java new file mode 100644 index 0000000..13c927d --- /dev/null +++ b/ri/src/main/java/javax/annotation/WillCloseWhenClosed.java @@ -0,0 +1,15 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Documented +@Retention(RetentionPolicy.RUNTIME) +/** + * Used to annotate a constructor/factory parameter to indicate that returned + * object (X) will close the resource when X is closed. + */ +public @interface WillCloseWhenClosed { + +} diff --git a/ri/src/main/java/javax/annotation/WillNotClose.java b/ri/src/main/java/javax/annotation/WillNotClose.java new file mode 100644 index 0000000..d698b7c --- /dev/null +++ b/ri/src/main/java/javax/annotation/WillNotClose.java @@ -0,0 +1,15 @@ +package javax.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Documented +@Retention(RetentionPolicy.RUNTIME) +/** + * Used to annotate a method parameter to indicate that this method will not + * close the resource. + */ +public @interface WillNotClose { + +} diff --git a/ri/src/main/java/javax/annotation/concurrent/GuardedBy.java b/ri/src/main/java/javax/annotation/concurrent/GuardedBy.java new file mode 100644 index 0000000..9d6641d --- /dev/null +++ b/ri/src/main/java/javax/annotation/concurrent/GuardedBy.java @@ -0,0 +1,38 @@ +package javax.annotation.concurrent; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/* + * Copyright (c) 2005 Brian Goetz + * Released under the Creative Commons Attribution License + * (http://creativecommons.org/licenses/by/2.5) + * Official home: http://www.jcip.net + */ + +/** + * GuardedBy + * + * The field or method to which this annotation is applied can only be accessed + * when holding a particular lock, which may be a built-in (synchronization) + * lock, or may be an explicit java.util.concurrent.Lock. + * + * The argument determines which lock guards the annotated field or method: this : + * The string literal "this" means that this field is guarded by the class in + * which it is defined. class-name.this : For inner classes, it may be necessary + * to disambiguate 'this'; the class-name.this designation allows you to specify + * which 'this' reference is intended itself : For reference fields only; the + * object to which the field refers. field-name : The lock object is referenced + * by the (instance or static) field specified by field-name. + * class-name.field-name : The lock object is reference by the static field + * specified by class-name.field-name. method-name() : The lock object is + * returned by calling the named nil-ary method. class-name.class : The Class + * object for the specified class should be used as the lock object. + */ +@Target( { ElementType.FIELD, ElementType.METHOD }) +@Retention(RetentionPolicy.CLASS) +public @interface GuardedBy { + String value(); +} diff --git a/ri/src/main/java/javax/annotation/concurrent/Immutable.java b/ri/src/main/java/javax/annotation/concurrent/Immutable.java new file mode 100644 index 0000000..03f1cb5 --- /dev/null +++ b/ri/src/main/java/javax/annotation/concurrent/Immutable.java @@ -0,0 +1,36 @@ +package javax.annotation.concurrent; + +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; + +/* + * Copyright (c) 2005 Brian Goetz + * Released under the Creative Commons Attribution License + * (http://creativecommons.org/licenses/by/2.5) + * Official home: http://www.jcip.net + */ + +/** + * Immutable + * + * The class to which this annotation is applied is immutable. This means that + * its state cannot be seen to change by callers. Of necessity this means that + * all public fields are final, and that all public final reference fields refer + * to other immutable objects, and that methods do not publish references to any + * internal state which is mutable by implementation even if not by design. + * Immutable objects may still have internal mutable state for purposes of + * performance optimization; some state variables may be lazily computed, so + * long as they are computed from immutable state and that callers cannot tell + * the difference. + * + * Immutable objects are inherently thread-safe; they may be passed between + * threads or published without synchronization. + */ +@Documented +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.CLASS) +public @interface Immutable { +} diff --git a/ri/src/main/java/javax/annotation/concurrent/NotThreadSafe.java b/ri/src/main/java/javax/annotation/concurrent/NotThreadSafe.java new file mode 100644 index 0000000..d948142 --- /dev/null +++ b/ri/src/main/java/javax/annotation/concurrent/NotThreadSafe.java @@ -0,0 +1,30 @@ +package javax.annotation.concurrent; + +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; + +/* + * Copyright (c) 2005 Brian Goetz + * Released under the Creative Commons Attribution License + * (http://creativecommons.org/licenses/by/2.5) + * Official home: http://www.jcip.net + */ + +/** + * NotThreadSafe + * + * The class to which this annotation is applied is not thread-safe. This + * annotation primarily exists for clarifying the non-thread-safety of a class + * that might otherwise be assumed to be thread-safe, despite the fact that it + * is a bad idea to assume a class is thread-safe without good reason. + * + * @see ThreadSafe + */ +@Documented +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.CLASS) +public @interface NotThreadSafe { +} diff --git a/ri/src/main/java/javax/annotation/concurrent/ThreadSafe.java b/ri/src/main/java/javax/annotation/concurrent/ThreadSafe.java new file mode 100644 index 0000000..3c86128 --- /dev/null +++ b/ri/src/main/java/javax/annotation/concurrent/ThreadSafe.java @@ -0,0 +1,22 @@ +package javax.annotation.concurrent; + +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; + +/** + * ThreadSafe + * + * The class to which this annotation is applied is thread-safe. This means that + * no sequences of accesses (reads and writes to public fields, calls to public + * methods) may put the object into an invalid state, regardless of the + * interleaving of those actions by the runtime, and without requiring any + * additional synchronization or coordination on the part of the caller. + */ +@Documented +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.CLASS) +public @interface ThreadSafe { +} diff --git a/ri/src/main/java/javax/annotation/meta/Exclusive.java b/ri/src/main/java/javax/annotation/meta/Exclusive.java new file mode 100644 index 0000000..d018c33 --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/Exclusive.java @@ -0,0 +1,26 @@ +package javax.annotation.meta; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * This annotation can be applied to the value() element of an annotation that + * is annotated as a TypeQualifier. + * + * For example, the following defines a type qualifier such that if you know a + * value is {@literal @Foo(1)}, then the value cannot be {@literal @Foo(2)} or {{@literal @Foo(3)}. + * + * <code> + * @TypeQualifier @interface Foo { + * @Exclusive int value(); + * } + * </code> + * + */ + +@Documented +@Retention(RetentionPolicy.RUNTIME) +public @interface Exclusive { + +} diff --git a/ri/src/main/java/javax/annotation/meta/Exhaustive.java b/ri/src/main/java/javax/annotation/meta/Exhaustive.java new file mode 100644 index 0000000..dc75f06 --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/Exhaustive.java @@ -0,0 +1,33 @@ +package javax.annotation.meta; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * This annotation can be applied to the value() element of an annotation that + * is annotated as a TypeQualifier. This is only appropriate if the value field + * returns a value that is an Enumeration. + * + * Applications of the type qualifier with different values are exclusive, and + * the enumeration is an exhaustive list of the possible values. + * + * For example, the following defines a type qualifier such that if you know a + * value is neither {@literal @Foo(Color.Red)} or {@literal @Foo(Color.Blue)}, + * then the value must be {@literal @Foo(Color.Green)}. And if you know it is + * {@literal @Foo(Color.Green)}, you know it cannot be + * {@literal @Foo(Color.Red)} or {@literal @Foo(Color.Blue)} + * + * <code> + * @TypeQualifier @interface Foo { + * enum Color {RED, BLUE, GREEN}; + * @Exhaustive Color value(); + * } + * </code> + */ + +@Documented +@Retention(RetentionPolicy.RUNTIME) +public @interface Exhaustive { + +} diff --git a/ri/src/main/java/javax/annotation/meta/TypeQualifier.java b/ri/src/main/java/javax/annotation/meta/TypeQualifier.java new file mode 100644 index 0000000..99f6312 --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/TypeQualifier.java @@ -0,0 +1,27 @@ +package javax.annotation.meta; + +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; + +/** + * This qualifier is applied to an annotation to denote that the annotation + * should be treated as a type qualifier. + */ + +@Documented +@Target(ElementType.ANNOTATION_TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface TypeQualifier { + + /** + * Describes the kinds of values the qualifier can be applied to. If a + * numeric class is provided (e.g., Number.class or Integer.class) then the + * annotation can also be applied to the corresponding primitive numeric + * types. + */ + Class<?> applicableTo() default Object.class; + +} diff --git a/ri/src/main/java/javax/annotation/meta/TypeQualifierDefault.java b/ri/src/main/java/javax/annotation/meta/TypeQualifierDefault.java new file mode 100644 index 0000000..0c8bd52 --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/TypeQualifierDefault.java @@ -0,0 +1,20 @@ +package javax.annotation.meta; + +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; + +/** + * This qualifier is applied to an annotation to denote that the annotation + * defines a default type qualifier that is visible within the scope of the + * element it is applied to. + */ + +@Documented +@Target(ElementType.ANNOTATION_TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface TypeQualifierDefault { + ElementType[] value() default {}; +} diff --git a/ri/src/main/java/javax/annotation/meta/TypeQualifierNickname.java b/ri/src/main/java/javax/annotation/meta/TypeQualifierNickname.java new file mode 100644 index 0000000..40c9983 --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/TypeQualifierNickname.java @@ -0,0 +1,33 @@ +package javax.annotation.meta; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * + * This annotation is applied to a annotation, and marks the annotation as being + * a qualifier nickname. Applying a nickname annotation X to a element Y should + * be interpreted as having the same meaning as applying all of annotations of X + * (other than QualifierNickname) to Y. + * + * <p> + * Thus, you might define a qualifier SocialSecurityNumber as follows: + * </p> + * + * + * <code> + @Documented + @TypeQualifierNickname @Pattern("[0-9]{3}-[0-9]{2}-[0-9]{4}") + @Retention(RetentionPolicy.RUNTIME) + public @interface SocialSecurityNumber { + } + </code> + * + * + */ +@Documented +@Target(ElementType.ANNOTATION_TYPE) +public @interface TypeQualifierNickname { + +} diff --git a/ri/src/main/java/javax/annotation/meta/TypeQualifierValidator.java b/ri/src/main/java/javax/annotation/meta/TypeQualifierValidator.java new file mode 100644 index 0000000..8053011 --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/TypeQualifierValidator.java @@ -0,0 +1,21 @@ +package javax.annotation.meta; + +import java.lang.annotation.Annotation; + +import javax.annotation.Nonnull; + +public interface TypeQualifierValidator<A extends Annotation> { + /** + * Given a type qualifier, check to see if a known specific constant value + * is an instance of the set of values denoted by the qualifier. + * + * @param annotation + * the type qualifier + * @param value + * the value to check + * @return a value indicating whether or not the value is an member of the + * values denoted by the type qualifier + */ + public @Nonnull + When forConstantValue(@Nonnull A annotation, Object value); +} diff --git a/ri/src/main/java/javax/annotation/meta/When.java b/ri/src/main/java/javax/annotation/meta/When.java new file mode 100644 index 0000000..ec8a1bc --- /dev/null +++ b/ri/src/main/java/javax/annotation/meta/When.java @@ -0,0 +1,23 @@ +package javax.annotation.meta; + +/** + * Used to describe the relationship between a qualifier T and the set of values + * S possible on an annotated element. + * + * In particular, an issues should be reported if an ALWAYS or MAYBE value is + * used where a NEVER value is required, or if a NEVER or MAYBE value is used + * where an ALWAYS value is required. + * + * + */ +public enum When { + /** S is a subset of T */ + ALWAYS, + /** nothing definitive is known about the relation between S and T */ + UNKNOWN, + /** S intersection T is non empty and S - T is nonempty */ + MAYBE, + /** S intersection T is empty */ + NEVER; + +} diff --git a/sampleUses/.classpath b/sampleUses/.classpath new file mode 100644 index 0000000..f508c72 --- /dev/null +++ b/sampleUses/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry combineaccessrules="false" kind="src" path="/JSR305-ri"/> + <classpathentry kind="output" path="build/classes"/> +</classpath> diff --git a/sampleUses/.project b/sampleUses/.project new file mode 100644 index 0000000..bfe32bc --- /dev/null +++ b/sampleUses/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>JSR305-uses</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/sampleUses/pom.xml b/sampleUses/pom.xml new file mode 100644 index 0000000..0199223 --- /dev/null +++ b/sampleUses/pom.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jsr-305</groupId>
+ <artifactId>jsr-305</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jsr-305</groupId>
+ <artifactId>sampleUses</artifactId>
+ <packaging>jar</packaging>
+ <name>JSR 305 Sample Use Cases</name>
+ <version>0.1-SNAPSHOT</version>
+ <description>Use Cases for JSR-305</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.jsr-305</groupId>
+ <artifactId>ri</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/sampleUses/src/main/java/CreditCardNumber.java b/sampleUses/src/main/java/CreditCardNumber.java new file mode 100644 index 0000000..ef5f711 --- /dev/null +++ b/sampleUses/src/main/java/CreditCardNumber.java @@ -0,0 +1,27 @@ +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.MatchesPattern; +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.TypeQualifierValidator; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier +@MatchesPattern("[0-9]{16}") +@Retention(RetentionPolicy.RUNTIME) +public @interface CreditCardNumber { + class Checker implements TypeQualifierValidator<CreditCardNumber> { + + public When forConstantValue(CreditCardNumber annotation, Object v) { + if (!(v instanceof String)) + return When.NEVER; + String s = (String) v; + if (LuhnVerification.checkNumber(s)) + return When.ALWAYS; + return When.NEVER; + } + } +} diff --git a/sampleUses/src/main/java/FixedLengthString.java b/sampleUses/src/main/java/FixedLengthString.java new file mode 100644 index 0000000..bf7ba44 --- /dev/null +++ b/sampleUses/src/main/java/FixedLengthString.java @@ -0,0 +1,26 @@ +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.TypeQualifierValidator; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier(applicableTo=String.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface FixedLengthString { + int value(); + + class Checker implements TypeQualifierValidator<FixedLengthString> { + + public When forConstantValue(FixedLengthString annotation, Object v) { + if (!(v instanceof String)) + return When.NEVER; + String s = (String) v; + if (s.length() == annotation.value()) + return When.ALWAYS; + return When.NEVER; + } + } +}
\ No newline at end of file diff --git a/sampleUses/src/main/java/LuhnVerification.java b/sampleUses/src/main/java/LuhnVerification.java new file mode 100644 index 0000000..f9ad241 --- /dev/null +++ b/sampleUses/src/main/java/LuhnVerification.java @@ -0,0 +1,26 @@ +public class LuhnVerification { + + static boolean checkNumber(String value) { + int result = 0; + boolean special = false; + for (int i = value.length() - 1; i >= 0; i--) { + int v = value.charAt(i) - '0'; + if (v < 0 || v > 9) + return false; + if (special) { + v = v * 2; + if (v > 9) + v = v - 10 + 1; + } + result += v; + special = !special; + } + System.out.println(result); + return result % 10 == 0; + } + + public static void main(String args[]) { + System.out.println(checkNumber("")); + } + +} diff --git a/sampleUses/src/main/java/SocialSecurityNumber.java b/sampleUses/src/main/java/SocialSecurityNumber.java new file mode 100644 index 0000000..a20c21b --- /dev/null +++ b/sampleUses/src/main/java/SocialSecurityNumber.java @@ -0,0 +1,14 @@ +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.MatchesPattern; +import javax.annotation.meta.TypeQualifierNickname; + +@Documented +@TypeQualifierNickname +@MatchesPattern("[0-9]{3}-[0-9]{2}-[0-9]{4}") +@Retention(RetentionPolicy.RUNTIME) +public @interface SocialSecurityNumber { +} diff --git a/sampleUses/src/main/java/edu/umd/cs/findbugs/DottedClassName.java b/sampleUses/src/main/java/edu/umd/cs/findbugs/DottedClassName.java new file mode 100644 index 0000000..f8779d0 --- /dev/null +++ b/sampleUses/src/main/java/edu/umd/cs/findbugs/DottedClassName.java @@ -0,0 +1,14 @@ +package edu.umd.cs.findbugs; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@SlashedClassName(when=When.NEVER) +@TypeQualifierNickname +@Retention(RetentionPolicy.RUNTIME) +public @interface DottedClassName { }
\ No newline at end of file diff --git a/sampleUses/src/main/java/edu/umd/cs/findbugs/SlashedClassName.java b/sampleUses/src/main/java/edu/umd/cs/findbugs/SlashedClassName.java new file mode 100644 index 0000000..cc06384 --- /dev/null +++ b/sampleUses/src/main/java/edu/umd/cs/findbugs/SlashedClassName.java @@ -0,0 +1,15 @@ +package edu.umd.cs.findbugs; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; +import javax.annotation.meta.When; + +@Documented +@TypeQualifier(applicableTo=CharSequence.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface SlashedClassName { + When when() default When.ALWAYS; +} diff --git a/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/ParametersAreSlashedByDefault.java b/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/ParametersAreSlashedByDefault.java new file mode 100644 index 0000000..28e30e8 --- /dev/null +++ b/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/ParametersAreSlashedByDefault.java @@ -0,0 +1,13 @@ +package edu.umd.cs.findbugs.examples; + +import java.lang.annotation.ElementType; + +import javax.annotation.meta.TypeQualifierDefault; + +import edu.umd.cs.findbugs.SlashedClassName; + +@SlashedClassName +@TypeQualifierDefault(ElementType.PARAMETER) +public @interface ParametersAreSlashedByDefault { + +} diff --git a/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/Test.java b/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/Test.java new file mode 100644 index 0000000..1246131 --- /dev/null +++ b/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/Test.java @@ -0,0 +1,31 @@ +package edu.umd.cs.findbugs.examples; + +import javax.annotation.meta.When; + +import edu.umd.cs.findbugs.DottedClassName; +import edu.umd.cs.findbugs.SlashedClassName; + +public class Test { + + + public void foo(@SlashedClassName String foo) {} + + public void foo2(@DottedClassName String foo) { + foo(foo); // should get warning here + } + + public void foo3(String foo) { + foo(foo); + } + public void foo4(@DottedClassName String foo) { + foo3(foo); + } + + public void foo5(@SlashedClassName(when=When.MAYBE) String foo) { + foo(foo); + } + public void foo6(@SlashedClassName(when=When.UNKNOWN) String foo) { + foo(foo); + } +} + diff --git a/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/TestDefaults.java b/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/TestDefaults.java new file mode 100644 index 0000000..c6e8013 --- /dev/null +++ b/sampleUses/src/main/java/edu/umd/cs/findbugs/examples/TestDefaults.java @@ -0,0 +1,19 @@ +package edu.umd.cs.findbugs.examples; + +import javax.annotation.meta.When; + +import edu.umd.cs.findbugs.DottedClassName; +import edu.umd.cs.findbugs.SlashedClassName; + +@ParametersAreSlashedByDefault +public class TestDefaults { + public void foo(String c) {} + + public void foo2(@DottedClassName String c) { + foo(c); + } + + public void foo3(@SlashedClassName(when=When.UNKNOWN) String c) { + foo(c); + } +} diff --git a/sampleUses/src/main/java/java/sql/ResultSetConcurrency.java b/sampleUses/src/main/java/java/sql/ResultSetConcurrency.java new file mode 100644 index 0000000..418fa9e --- /dev/null +++ b/sampleUses/src/main/java/java/sql/ResultSetConcurrency.java @@ -0,0 +1,14 @@ +package java.sql; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; + +@Documented +@TypeQualifier(applicableTo=Integer.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface ResultSetConcurrency { + +} diff --git a/sampleUses/src/main/java/java/sql/ResultSetHoldability.java b/sampleUses/src/main/java/java/sql/ResultSetHoldability.java new file mode 100644 index 0000000..4bfdce2 --- /dev/null +++ b/sampleUses/src/main/java/java/sql/ResultSetHoldability.java @@ -0,0 +1,14 @@ +package java.sql; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; + +@Documented +@TypeQualifier(applicableTo=Integer.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface ResultSetHoldability { + +} diff --git a/sampleUses/src/main/java/java/sql/ResultSetType.java b/sampleUses/src/main/java/java/sql/ResultSetType.java new file mode 100644 index 0000000..888db2c --- /dev/null +++ b/sampleUses/src/main/java/java/sql/ResultSetType.java @@ -0,0 +1,14 @@ +package java.sql; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifier; + +@Documented +@TypeQualifier(applicableTo=Integer.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface ResultSetType { + +} diff --git a/tcl/pom.xml b/tcl/pom.xml new file mode 100644 index 0000000..36028b7 --- /dev/null +++ b/tcl/pom.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jsr-305</groupId>
+ <artifactId>jsr-305</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jsr-305</groupId>
+ <artifactId>tcl</artifactId>
+ <packaging>jar</packaging>
+ <name>JSR 305 Test Cases</name>
+ <version>0.1-SNAPSHOT</version>
+ <description>Test Cases for JSR-305 Implementations</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jsr-305</groupId>
+ <artifactId>ri</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
|