1 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 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; } 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 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; 49 this.annotations = annotations; 50 return this; 51 } 52 53 static class MethodHolder extends AnnotationHolder { 54 AnnotationBinding[][] parameterAnnotations; 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 defaultValue; 76 77 AnnotationMethodHolder(AnnotationBinding[] annotations, AnnotationBinding[][] parameterAnnotations, Object defaultValue) { 78 super(annotations, parameterAnnotations); 79 this.defaultValue = defaultValue; 80 } 81 Object getDefaultValue() { 82 return this.defaultValue; 83 } 84 } 85 } 86 | Popular Tags |