001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.lookup;
011:
012: public class AnnotationHolder {
013: AnnotationBinding[] annotations;
014:
015: static AnnotationHolder storeAnnotations(
016: AnnotationBinding[] annotations,
017: AnnotationBinding[][] parameterAnnotations,
018: Object defaultValue) {
019: if (parameterAnnotations != null) {
020: boolean isEmpty = true;
021: for (int i = parameterAnnotations.length; isEmpty
022: && --i >= 0;)
023: if (parameterAnnotations[i] != null
024: && parameterAnnotations[i].length > 0)
025: isEmpty = false;
026: if (isEmpty)
027: parameterAnnotations = null; // does not have any
028: }
029:
030: if (defaultValue != null)
031: return new AnnotationMethodHolder(annotations,
032: parameterAnnotations, defaultValue);
033: if (parameterAnnotations != null)
034: return new MethodHolder(annotations, parameterAnnotations);
035: return new AnnotationHolder().setAnnotations(annotations);
036: }
037:
038: AnnotationBinding[] getAnnotations() {
039: return this .annotations;
040: }
041:
042: Object getDefaultValue() {
043: return null;
044: }
045:
046: public AnnotationBinding[][] getParameterAnnotations() {
047: return null;
048: }
049:
050: AnnotationBinding[] getParameterAnnotations(int paramIndex) {
051: return Binding.NO_ANNOTATIONS;
052: }
053:
054: AnnotationHolder setAnnotations(AnnotationBinding[] annotations) {
055: if (annotations == null || annotations.length == 0)
056: return null; // no longer needed
057:
058: this .annotations = annotations;
059: return this ;
060: }
061:
062: static class MethodHolder extends AnnotationHolder {
063: AnnotationBinding[][] parameterAnnotations; // is null if empty
064:
065: MethodHolder(AnnotationBinding[] annotations,
066: AnnotationBinding[][] parameterAnnotations) {
067: super ();
068: setAnnotations(annotations);
069: this .parameterAnnotations = parameterAnnotations;
070: }
071:
072: public AnnotationBinding[][] getParameterAnnotations() {
073: return this .parameterAnnotations;
074: }
075:
076: AnnotationBinding[] getParameterAnnotations(int paramIndex) {
077: AnnotationBinding[] result = this .parameterAnnotations == null ? null
078: : this .parameterAnnotations[paramIndex];
079: return result == null ? Binding.NO_ANNOTATIONS : result;
080: }
081:
082: AnnotationHolder setAnnotations(AnnotationBinding[] annotations) {
083: this .annotations = annotations == null
084: || annotations.length == 0 ? Binding.NO_ANNOTATIONS
085: : annotations;
086: return this ;
087: }
088: }
089:
090: static class AnnotationMethodHolder extends MethodHolder {
091: Object defaultValue;
092:
093: AnnotationMethodHolder(AnnotationBinding[] annotations,
094: AnnotationBinding[][] parameterAnnotations,
095: Object defaultValue) {
096: super (annotations, parameterAnnotations);
097: this .defaultValue = defaultValue;
098: }
099:
100: Object getDefaultValue() {
101: return this.defaultValue;
102: }
103: }
104: }
|