001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.vm;
018:
019: import java.lang.annotation.Annotation;
020:
021: /**
022: * Provides the methods to get signatures used to encode Java programming
023: * language type information such as generic type and method declarations and
024: * parameterized types.
025: * <p>
026: * Provides also the methods to get annotations and their elements values.
027: * <p>
028: * This class must be implemented according to the common policy for porting
029: * interfaces - see the porting interface overview for more detailes.
030: *
031: * @author Serguei S. Zapreyev, Alexey V. Varlamov
032: * @version $Revision$
033: *
034: * @api2vm
035: */
036: public final class VMGenericsAndAnnotations {
037:
038: /**
039: * This class is not supposed to be instantiated.
040: */
041: private VMGenericsAndAnnotations() {
042: }
043:
044: /**
045: * This method returns the String representation of a Signature
046: * attribute corresponding to {@link Method}, {@link Constructor}
047: * or {@link Field} object declaration.
048: * <p>
049: * @param id an identifier of a reflection member.
050: * @return the String representation of a Signature attribute or null
051: * if a caller's declaration does not use any generics.
052: *
053: * @api2vm
054: */
055: public static native String getSignature(long id);
056:
057: /**
058: * This method returns the String representation of a Signature
059: * attribute corresponding to {@link Class} object declaration.
060: * <p>
061: * @param cls a class to be reflected.
062: * @return the String representation of a Signature attribute or null
063: * if a caller's declaration does not use any generics.
064: *
065: * @api2vm
066: */
067: public static native String getSignature(Class cls);
068:
069: /**
070: * This method satisfies the requirements of the specification for the
071: * {@link Field#getDeclaredAnnotations() Field.getDeclaredAnnotations()},
072: * {@link Method#getDeclaredAnnotations() Method.getDeclaredAnnotations()},
073: * {@link Constructor#getDeclaredAnnotations()
074: * Constructor.getDeclaredAnnotations()} methods.
075: * <p>
076: * @param id an identifier of the caller (Field, or Method,
077: * or Constructor type).
078: * @return all annotations directly present on this element or zero-sized
079: * array if there are no annotations.
080: * @throws TypeNotPresentException if enum-valued or nested annotation member
081: * (of an annotation) refers to a class that is not accessible.
082: * @throws AnnotationFormatError if reading an annotation from a class file
083: * determines that the annotation is malformed.
084: * @api2vm
085: */
086: public static native Annotation[] getDeclaredAnnotations(long id);
087:
088: /**
089: * This method satisfies the requirements of the specification for the
090: * {@link Class#getDeclaredAnnotations() Class.getDeclaredAnnotations()}.
091: * <p>
092: * @param clss annotated element of the Class type
093: * @return all annotations directly present on this element or zero-sized
094: * array if there are no annotations.
095: * @throws TypeNotPresentException if enum-valued or nested annotation member
096: * (of an annotation) refers to a class that is not accessible.
097: * @throws AnnotationFormatError if reading an annotation from a class file
098: * determines that the annotation is malformed.
099: * @api2vm
100: */
101: public static native Annotation[] getDeclaredAnnotations(Class clss);
102:
103: /**
104: * This method satisfies the requirements of the specification for the
105: * {@link Method#getParameterAnnotations() Method.getParameterAnnotations()}
106: * and {@link Constructor#getParameterAnnotations()
107: * Constructor.getParameterAnnotations()} methods.
108: * <p>
109: * @param id an identifier of the caller (annotated element of the Method
110: * or Constructor type) class.
111: * @return an array of arrays that represent the annotations on the formal
112: * parameters, in declaration order, of the method represented by
113: * this Method object. Returns an array of length zero if the underlying method has
114: * no parameters. If the method has a parameter or more, a nested array of length
115: * zero is returned for each parameter with no annotations.
116: * @throws TypeNotPresentException if Class-valued member (of an annotation)
117: * referring to a class that is not accessible in this VM.
118: * @api2vm
119: */
120: public static native Annotation[][] getParameterAnnotations(long id);
121:
122: /**
123: * This method satisfies the requirements of the specification for the
124: * {@link Method#getDefaultValue() Method.getDefaultValue()} method.
125: * But it takes one additional id parameter.
126: * <p>
127: * @param id an identifier of the caller (annotated element of the Method
128: * type) class.
129: * @return the default value for the annotation member represented by this
130: * Method instance or null.
131: * @throws TypeNotPresentException if the annotation is of type Class and
132: * no definition can be found for the default class value
133: *
134: * @api2vm
135: */
136: public static native Object getDefaultValue(long id);
137: }
|