KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > lookup > AnnotationHolder


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.lookup;
12
13 public class AnnotationHolder {
14     AnnotationBinding[] annotations;
15
16 static AnnotationHolder storeAnnotations(AnnotationBinding[] annotations, AnnotationBinding[][] parameterAnnotations, Object JavaDoc defaultValue) {
17     if (parameterAnnotations != null) {
18         boolean isEmpty = true;
19         for (int i = parameterAnnotations.length; isEmpty && --i >= 0;)
20             if (parameterAnnotations[i] != null && parameterAnnotations[i].length > 0)
21                 isEmpty = false;
22         if (isEmpty)
23             parameterAnnotations = null; // does not have any
24
}
25
26     if (defaultValue != null)
27         return new AnnotationMethodHolder(annotations, parameterAnnotations, defaultValue);
28     if (parameterAnnotations != null)
29         return new MethodHolder(annotations, parameterAnnotations);
30     return new AnnotationHolder().setAnnotations(annotations);
31 }
32
33 AnnotationBinding[] getAnnotations() {
34     return this.annotations;
35 }
36 Object JavaDoc getDefaultValue() {
37     return null;
38 }
39 public AnnotationBinding[][] getParameterAnnotations() {
40     return null;
41 }
42 AnnotationBinding[] getParameterAnnotations(int paramIndex) {
43     return Binding.NO_ANNOTATIONS;
44 }
45 AnnotationHolder setAnnotations(AnnotationBinding[] annotations) {
46     if (annotations == null || annotations.length == 0)
47         return null; // no longer needed
48

49     this.annotations = annotations;
50     return this;
51 }
52
53 static class MethodHolder extends AnnotationHolder {
54     AnnotationBinding[][] parameterAnnotations; // is null if empty
55

56 MethodHolder(AnnotationBinding[] annotations, AnnotationBinding[][] parameterAnnotations) {
57     super();
58     setAnnotations(annotations);
59     this.parameterAnnotations = parameterAnnotations;
60 }
61 public AnnotationBinding[][] getParameterAnnotations() {
62     return this.parameterAnnotations;
63 }
64 AnnotationBinding[] getParameterAnnotations(int paramIndex) {
65     AnnotationBinding[] result = this.parameterAnnotations == null ? null : this.parameterAnnotations[paramIndex];
66     return result == null ? Binding.NO_ANNOTATIONS : result;
67 }
68 AnnotationHolder setAnnotations(AnnotationBinding[] annotations) {
69     this.annotations = annotations == null || annotations.length == 0 ? Binding.NO_ANNOTATIONS : annotations;
70     return this;
71 }
72 }
73
74 static class AnnotationMethodHolder extends MethodHolder {
75     Object JavaDoc defaultValue;
76
77 AnnotationMethodHolder(AnnotationBinding[] annotations, AnnotationBinding[][] parameterAnnotations, Object JavaDoc defaultValue) {
78     super(annotations, parameterAnnotations);
79     this.defaultValue = defaultValue;
80 }
81 Object JavaDoc getDefaultValue() {
82     return this.defaultValue;
83 }
84 }
85 }
86
Popular Tags