diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | fdb2704414a9ed92394ada0d1395e4db86889465 (patch) | |
tree | 9b591a4a50054274a197f02b3ccb51313681879f /annotation/src | |
download | libcore-fdb2704414a9ed92394ada0d1395e4db86889465.zip libcore-fdb2704414a9ed92394ada0d1395e4db86889465.tar.gz libcore-fdb2704414a9ed92394ada0d1395e4db86889465.tar.bz2 |
Initial Contribution
Diffstat (limited to 'annotation/src')
20 files changed, 1109 insertions, 0 deletions
diff --git a/annotation/src/main/java/java/lang/annotation/Annotation.java b/annotation/src/main/java/java/lang/annotation/Annotation.java new file mode 100644 index 0000000..43ad1bb --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/Annotation.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Defines the interface implemented by all annotations. Note that the interface + * itself is <i>not</i> an annotation, and neither is an interface that simply + * extends this one. Only the compiler is able to create proper annotation + * types. + * + * @since Android 1.0 + */ +public interface Annotation { + + /** + * Returns the type of this annotation. + * + * @return A {@code Class} instance representing the annotation type. + * + * @since Android 1.0 + */ + Class<? extends Annotation> annotationType(); + + /** + * Determines whether or not this annotation is equivalent to the annotation + * passed. This is determined according to the following rules: + * + * <ul> + * <li> + * Two annotations {@code x} and {@code y} are equal if and only if + * they are members of the same annotation type and all the member + * values of {@code x} are equal to the corresponding member values + * of {@code y}. + * </li> + * <li> + * The equality of primitive member values {@code x} and {@code y} + * is determined (in a way similar to) using the corresponding + * wrapper classes. For example, + * {@code Integer.valueOf(x).equals(Integer.valueOf(y)} is used for + * {@code int} values. Note: The behavior is identical to the + * {@code ==} operator for all but the floating point type, so the + * implementation may as well use {@code ==} in these cases for + * performance reasons. Only for the {@code float} and {@code double} + * types the result will be slightly different: {@code NaN} is equal + * to {@code NaN}, and {@code -0.0} is equal to {@code 0.0}, both of + * which is normally not the case. + * </li> + * <li> + * The equality of two array member values {@code x} and {@code y} + * is determined using the corresponding {@code equals(x, y)} + * helper function in {@link java.util.Arrays}. + * </li> + * <li> + * The hash code for all other member values is determined by simply + * calling their {@code equals()} method. + * </li> + * </ul> + * + * @param obj + * The object to compare to. + * + * @return {@code true} if {@code obj} is equal to this annotation, + * {@code false} otherwise. + * + * @since Android 1.0 + */ + boolean equals(Object obj); + + /** + * Returns the hash code of this annotation. The hash code is determined + * according to the following rules: + * + * <ul> + * <li> + * The hash code of an annotation is the sum of the hash codes of + * its annotation members. + * </li> + * <li> + * The hash code of an annotation member is calculated as {@code + * (0x7f * n.hashCode()) ^ v.hashCode())}, where {@code n} is the + * name of the member (as a {@code String}) and {@code v} its value. + * </li> + * <li> + * The hash code for a primitive member value is determined using + * the corresponding wrapper type. For example, {@code + * Integer.valueOf(v).hashCode()} is used for an {@code int} value + * {@code v}. + * </li> + * <li> + * The hash code for an array member value {@code v} is determined + * using the corresponding {@code hashCode(v)} helper function in + * {@link java.util.Arrays}. + * </li> + * <li> + * The hash code for all other member values is determined by simply + * calling their {@code hashCode} method. + * </li> + * </ul> + * + * @return the hash code. + * + * @since Android 1.0 + */ + int hashCode(); + + /** + * Returns a {@code String} representation of this annotation. It is not + * strictly defined what the representation has to look like, but it usually + * consists of the name of the annotation, preceded by a "@". If the + * annotation contains field members, their names and values are also + * included in the result. + * + * @return the {@code String} that represents this annotation. + * + * @since Android 1.0 + */ + String toString(); +} diff --git a/annotation/src/main/java/java/lang/annotation/AnnotationFormatError.java b/annotation/src/main/java/java/lang/annotation/AnnotationFormatError.java new file mode 100644 index 0000000..ce5c3a0 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/AnnotationFormatError.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Indicates that an annotation in the binary representation of a class is + * syntactically incorrect and the annotation parser is unable to process it. + * This exception is unlikely to ever occur, given that the code has been + * compiled by an ordinary Java compiler. + * + * @since Android 1.0 + */ +public class AnnotationFormatError extends Error { + + private static final long serialVersionUID = -4256701562333669892L; + + /** + * Constructs an instance with the message provided. + * + * @param message + * the details of the error. + * + * @since Android 1.0 + */ + public AnnotationFormatError(String message) { + super(message); + } + + /** + * Constructs an instance with a message and a cause. + * + * @param message + * the details of the error. + * + * @param cause + * the cause of the error or {@code null} if none. + * + * @since Android 1.0 + */ + public AnnotationFormatError(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs an instance with a cause. If the cause is not + * {@code null}, then {@code cause.toString()} is used as the + * error's message. + * + * @param cause + * the cause of the error or {@code null} if none. + * + * @since Android 1.0 + */ + public AnnotationFormatError(Throwable cause) { + super(cause == null ? null : cause.toString(), cause); + } + +} diff --git a/annotation/src/main/java/java/lang/annotation/AnnotationTypeMismatchException.java b/annotation/src/main/java/java/lang/annotation/AnnotationTypeMismatchException.java new file mode 100644 index 0000000..5bb3cbf --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/AnnotationTypeMismatchException.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +import java.lang.reflect.Method; + +import org.apache.harmony.annotation.internal.nls.Messages; + +/** + * Indicates that an annotation type has changed since it was compiled or + * serialized. + * + * @since Android 1.0 + */ +public class AnnotationTypeMismatchException extends RuntimeException { + + private static final long serialVersionUID = 8125925355765570191L; + + private Method element; + + private String foundType; + + /** + * Constructs an instance for the given type element and the type found. + * + * @param element + * the annotation type element. + * + * @param foundType + * the invalid type that was found. This is actually the textual + * type description found in the binary class representation, + * so it may not be human-readable. + * + * @since Android 1.0 + */ + public AnnotationTypeMismatchException(Method element, String foundType) { + super(Messages.getString("annotation.1", element, foundType)); //$NON-NLS-1$ + this.element = element; + this.foundType = foundType; + } + + /** + * Returns the method object for the invalid type. + * + * @return a {@link Method} instance. + * + * @since Android 1.0 + */ + public Method element() { + return element; + } + + /** + * Returns the invalid type. + * + * @return a string describing the invalid data. + * + * @since Android 1.0 + */ + public String foundType() { + return foundType; + } +} diff --git a/annotation/src/main/java/java/lang/annotation/Documented.java b/annotation/src/main/java/java/lang/annotation/Documented.java new file mode 100644 index 0000000..2849fd2 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/Documented.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Defines a meta-annotation for indicating that an annotation is documented and + * considered part of the public API. + * + * @since Android 1.0 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface Documented { +} diff --git a/annotation/src/main/java/java/lang/annotation/ElementType.java b/annotation/src/main/java/java/lang/annotation/ElementType.java new file mode 100644 index 0000000..92f5109 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/ElementType.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Defines an enumeration for Java program elements. It is used in conjunction + * with the {@link Target} meta-annotation to restrict the use of an annotation + * to certain program elements. + * + * @since Android 1.0 + */ +public enum ElementType { + /** + * Class, interface or enum declaration. + */ + TYPE, + /** + * Field declaration. + */ + FIELD, + /** + * Method declaration. + */ + METHOD, + /** + * Parameter declaration. + */ + PARAMETER, + /** + * Constructor declaration. + */ + CONSTRUCTOR, + /** + * Local variable declaration. + */ + LOCAL_VARIABLE, + /** + * Annotation type declaration. + */ + ANNOTATION_TYPE, + /** + * Package declaration. + */ + PACKAGE +} diff --git a/annotation/src/main/java/java/lang/annotation/IncompleteAnnotationException.java b/annotation/src/main/java/java/lang/annotation/IncompleteAnnotationException.java new file mode 100644 index 0000000..3a31551 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/IncompleteAnnotationException.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +import org.apache.harmony.annotation.internal.nls.Messages; + +/** + * Indicates that an element of an annotation type was accessed that was added + * after the type was compiled or serialized. This does not apply to new + * elements that have default values. + * + * @since Android 1.0 + */ +public class IncompleteAnnotationException extends RuntimeException { + + private static final long serialVersionUID = 8445097402741811912L; + + private Class<? extends Annotation> annotationType; + + private String elementName; + + /** + * Constructs an instance with the incomplete annotation type and the name + * of the element that's missing. + * + * @param annotationType + * the annotation type. + * @param elementName + * the name of the incomplete element. + * + * @since Android 1.0 + */ + public IncompleteAnnotationException( + Class<? extends Annotation> annotationType, String elementName) { + super(Messages.getString("annotation.0", elementName, annotationType.getName())); //$NON-NLS-1$ + this.annotationType = annotationType; + this.elementName = elementName; + } + + /** + * Returns the annotation type. + * + * @return a Class instance. + * + * @since Android 1.0 + */ + public Class<? extends Annotation> annotationType() { + return annotationType; + } + + /** + * Returns the incomplete element's name. + * + * @return the name of the element. + * + * @since Android 1.0 + */ + public String elementName() { + return elementName; + } +} diff --git a/annotation/src/main/java/java/lang/annotation/Inherited.java b/annotation/src/main/java/java/lang/annotation/Inherited.java new file mode 100644 index 0000000..b0b2695 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/Inherited.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Defines a meta-annotation for indicating indicating that an annotation is + * automatically inherited. + * + * @since Android 1.0 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface Inherited { +} diff --git a/annotation/src/main/java/java/lang/annotation/Retention.java b/annotation/src/main/java/java/lang/annotation/Retention.java new file mode 100644 index 0000000..257877a --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/Retention.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +// BEGIN android-note +// Un-linked RetentionPolicy#RUNTIME due to droiddoc problem (it doesn't +// yet deal with links to enums). +// END android-note + +/** + * Defines a meta-annotation for determining the scope of retention for an + * annotation. The default value is {@code RetentionPolicy.RUNTIME}. + * + * @since Android 1.0 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface Retention { + RetentionPolicy value() default RetentionPolicy.CLASS; +} diff --git a/annotation/src/main/java/java/lang/annotation/RetentionPolicy.java b/annotation/src/main/java/java/lang/annotation/RetentionPolicy.java new file mode 100644 index 0000000..014b910 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/RetentionPolicy.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Defines an enumeration for annotation retention policies. Used in conjunction + * with the {@link Retention} annotation to specify an annotation's time-to-live + * in the overall development life cycle. + * + * @since Android 1.0 + */ +public enum RetentionPolicy { + /** + * Annotation is only available in the source code. + */ + SOURCE, + /** + * Annotation is available in the source code and in the class file, but not + * at runtime. This is the default policy. + */ + CLASS, + /** + * Annotation is available in the source code, the class file and is + * available at runtime. + */ + RUNTIME +} diff --git a/annotation/src/main/java/java/lang/annotation/Target.java b/annotation/src/main/java/java/lang/annotation/Target.java new file mode 100644 index 0000000..1f53fa0 --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/Target.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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 java.lang.annotation; + +/** + * Defines a meta-annotation for determining what {@link ElementType}s an + * annotation can be applied to. + * + * @since Android 1.0 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface Target { + ElementType[] value(); +} diff --git a/annotation/src/main/java/java/lang/annotation/package.html b/annotation/src/main/java/java/lang/annotation/package.html new file mode 100644 index 0000000..99c98cc --- /dev/null +++ b/annotation/src/main/java/java/lang/annotation/package.html @@ -0,0 +1,10 @@ +<html> + <body> + <p> + Defines interfaces and exceptions necessary for annotation support. Also + provides some predefined annotations that are used throughout the Android + libraries. + </p> + @since Android 1.0 + </body> +</html>
\ No newline at end of file diff --git a/annotation/src/main/java/org/apache/harmony/annotation/internal/nls/Messages.java b/annotation/src/main/java/org/apache/harmony/annotation/internal/nls/Messages.java new file mode 100644 index 0000000..2182ae0 --- /dev/null +++ b/annotation/src/main/java/org/apache/harmony/annotation/internal/nls/Messages.java @@ -0,0 +1,126 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* + * THE FILE HAS BEEN AUTOGENERATED BY MSGTOOL TOOL. + * All changes made to this file manually will be overwritten + * if this tool runs again. Better make changes in the template file. + */ + +package org.apache.harmony.annotation.internal.nls; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.apache.harmony.luni.util.MsgHelp; + +/** + * This class retrieves strings from a resource bundle and returns them, + * formatting them with MessageFormat when required. + * <p> + * It is used by the system classes to provide national language support, by + * looking up messages in the <code> + * org.apache.harmony.annotation.internal.nls.messages + * </code> + * resource bundle. Note that if this file is not available, or an invalid key + * is looked up, or resource bundle support is not available, the key itself + * will be returned as the associated message. This means that the <em>KEY</em> + * should a reasonable human-readable (english) string. + * + */ +public class Messages { + + private static final String sResource = + "org.apache.harmony.annotation.internal.nls.messages"; + + /** + * Retrieves a message which has no arguments. + * + * @param msg + * String the key to look up. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg) { + return MsgHelp.getString(sResource, msg); + } + + /** + * Retrieves a message which takes 1 argument. + * + * @param msg + * String the key to look up. + * @param arg + * Object the object to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, Object arg) { + return getString(msg, new Object[] { arg }); + } + + /** + * Retrieves a message which takes 1 integer argument. + * + * @param msg + * String the key to look up. + * @param arg + * int the integer to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, int arg) { + return getString(msg, new Object[] { Integer.toString(arg) }); + } + + /** + * Retrieves a message which takes 1 character argument. + * + * @param msg + * String the key to look up. + * @param arg + * char the character to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, char arg) { + return getString(msg, new Object[] { String.valueOf(arg) }); + } + + /** + * Retrieves a message which takes 2 arguments. + * + * @param msg + * String the key to look up. + * @param arg1 + * Object an object to insert in the formatted output. + * @param arg2 + * Object another object to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, Object arg1, Object arg2) { + return getString(msg, new Object[] { arg1, arg2 }); + } + + /** + * Retrieves a message which takes several arguments. + * + * @param msg + * String the key to look up. + * @param args + * Object[] the objects to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, Object[] args) { + return MsgHelp.getString(sResource, msg, args); + } +} diff --git a/annotation/src/main/java/org/apache/harmony/annotation/internal/nls/messages.properties b/annotation/src/main/java/org/apache/harmony/annotation/internal/nls/messages.properties new file mode 100644 index 0000000..613c54d --- /dev/null +++ b/annotation/src/main/java/org/apache/harmony/annotation/internal/nls/messages.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +# messages for EN locale +annotation.0=The element, {0}, is not complete for the annotation {1}. +annotation.1=The annotation element, {0}, doesn't match the type {1}. diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java new file mode 100644 index 0000000..6662037 --- /dev/null +++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java @@ -0,0 +1,42 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.harmony.annotation.tests.java.lang.annotation; + +import org.apache.harmony.nio_char.tests.java.nio.charset.ASCIICharsetEncoderTest; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite for java.nio.charset package. + */ +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for java.lang.annotation"); + // $JUnit-BEGIN$ + + suite.addTestSuite(AnnotationFormatErrorTest.class); + suite.addTestSuite(AnnotationTypeMismatchExceptionTest.class); + suite.addTestSuite(ElementTypeTest.class); + suite.addTestSuite(IncompleteAnnotationExceptionTest.class); + suite.addTestSuite(RetentionPolicyTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java new file mode 100644 index 0000000..b80f3a9 --- /dev/null +++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.AnnotationFormatError; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.AnnotationFormatError + */ +public class AnnotationFormatErrorTest extends TestCase { + /** + * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(String) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_String() { + AnnotationFormatError e = new AnnotationFormatError("some message"); + assertEquals("some message", e.getMessage()); + } + + /** + * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(Throwable) + */ + public void test_constructorLjava_lang_Throwable() { + IllegalArgumentException iae = new IllegalArgumentException(); + AnnotationFormatError e = new AnnotationFormatError(iae); + assertSame(iae, e.getCause()); + } + + /** + * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(String,Throwable) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_StringLjava_lang_Throwable() { + IllegalArgumentException iae = new IllegalArgumentException(); + AnnotationFormatError e = new AnnotationFormatError("some message", iae); + assertEquals("some message", e.getMessage()); + assertSame(iae, e.getCause()); + } +} diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java new file mode 100644 index 0000000..9948e29 --- /dev/null +++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.AnnotationTypeMismatchException; +import java.lang.reflect.Method; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.AnnotationTypeMismatchException + */ +public class AnnotationTypeMismatchExceptionTest extends TestCase { + + /** + * @throws ClassNotFoundException + * @throws SecurityException + * @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method, + * String) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException { + Method[] methods = Class.forName("java.lang.String").getMethods(); + Method m = methods[0]; + AnnotationTypeMismatchException e = new AnnotationTypeMismatchException( + m, "some type"); + assertNotNull("can not instanciate AnnotationTypeMismatchException", e); + assertSame("wrong method name", m, e.element()); + assertEquals("wrong found type", "some type", e.foundType()); + } +} diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java new file mode 100644 index 0000000..d81cabd --- /dev/null +++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.ElementType; +import java.util.Arrays; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.ElementType + */ +public class ElementTypeTest extends TestCase { + + /** + * @throws Exception + * @tests java.lang.annotation.ElementType#valueOf(String) + */ + @SuppressWarnings("nls") + public void test_valueOfLjava_lang_String() throws Exception { + assertSame(ElementType.ANNOTATION_TYPE, ElementType + .valueOf("ANNOTATION_TYPE")); + assertSame(ElementType.CONSTRUCTOR, ElementType.valueOf("CONSTRUCTOR")); + assertSame(ElementType.FIELD, ElementType.valueOf("FIELD")); + assertSame(ElementType.LOCAL_VARIABLE, ElementType + .valueOf("LOCAL_VARIABLE")); + assertSame(ElementType.METHOD, ElementType.valueOf("METHOD")); + assertSame(ElementType.PACKAGE, ElementType.valueOf("PACKAGE")); + assertSame(ElementType.PARAMETER, ElementType.valueOf("PARAMETER")); + assertSame(ElementType.TYPE, ElementType.valueOf("TYPE")); + try { + ElementType.valueOf("OTHER"); + fail("Should throw an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected + } + } + + /** + * @throws Exception + * @tests java.lang.annotation.ElementType#values() + */ + @SuppressWarnings("nls") + public void test_values() throws Exception { + ElementType[] values = ElementType.values(); + assertTrue(values.length > 1); + Arrays.sort(values); + assertTrue(Arrays.binarySearch(values, ElementType.METHOD) >= 0); + } +} diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java new file mode 100644 index 0000000..0acd4fa --- /dev/null +++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.IncompleteAnnotationException; + +import junit.framework.TestCase; + +/** + * + */ +public class IncompleteAnnotationExceptionTest extends TestCase { + + /* + * Class under test for void IncompleteAnnotationException(String) + * Regression for HARMONY-2477 + */ + public void testNullType() { + try { + new IncompleteAnnotationException(null, "str"); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + // Expected + } + } + + /** + * @throws Exception + * @tests java.lang.annotation.IncompleteAnnotationException#IncompleteAnnotationException(Class, + * String) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_Class_Ljava_lang_String() + throws Exception { + Class clazz = String.class; + String elementName = "some element"; + IncompleteAnnotationException e = new IncompleteAnnotationException( + clazz, elementName); + assertNotNull("can not instanciate IncompleteAnnotationException", e); + assertSame("wrong annotation type", clazz, e.annotationType()); + assertSame("wrong element name", elementName, e.elementName()); + } +} diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java new file mode 100644 index 0000000..c4f7c03 --- /dev/null +++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.RetentionPolicy + */ +public class RetentionPolicyTest extends TestCase { + /** + * @throws Exception + * @tests java.lang.annotation.RetentionPolicy#valueOf(String) + */ + @SuppressWarnings("nls") + public void test_valueOfLjava_lang_String() throws Exception { + assertSame(RetentionPolicy.CLASS, RetentionPolicy + .valueOf("CLASS")); + assertSame(RetentionPolicy.RUNTIME, RetentionPolicy + .valueOf("RUNTIME")); + assertSame(RetentionPolicy.SOURCE, RetentionPolicy + .valueOf("SOURCE")); + try { + RetentionPolicy.valueOf("OTHER"); + fail("Should throw an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected + } + } + + /** + * @throws Exception + * @tests java.lang.annotation.RetentionPolicy#values() + */ + @SuppressWarnings("nls") + public void test_values() throws Exception { + RetentionPolicy[] values = RetentionPolicy.values(); + assertTrue(values.length > 1); + Arrays.sort(values); + assertTrue(Arrays.binarySearch(values, RetentionPolicy.RUNTIME) >= 0); + } +} diff --git a/annotation/src/test/java/tests/annotation/AllTests.java b/annotation/src/test/java/tests/annotation/AllTests.java new file mode 100644 index 0000000..84b1b40 --- /dev/null +++ b/annotation/src/test/java/tests/annotation/AllTests.java @@ -0,0 +1,38 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 tests.annotation; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite that includes all tests for the NIO_Char project. + */ +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All Annotation test suites"); + // $JUnit-BEGIN$ + suite.addTest(org.apache.harmony.annotation.tests.java.lang.annotation.AllTests.suite()); + // $JUnit-END$ + return suite; + } +} |