001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.core.ext.typeinfo;
017:
018: import java.lang.annotation.Annotation;
019: import java.util.Map;
020:
021: /**
022: * Represents a parameter in a declaration.
023: */
024: public class JParameter implements HasAnnotations, HasMetaData {
025:
026: private final Annotations annotations;
027:
028: private final HasMetaData metaData = new MetaData();
029:
030: private final String name;
031:
032: private JType type;
033:
034: private final JAbstractMethod enclosingMethod;
035:
036: public JParameter(JAbstractMethod enclosingMethod, JType type,
037: String name) {
038: this (enclosingMethod, type, name, null);
039: }
040:
041: public JParameter(
042: JAbstractMethod enclosingMethod,
043: JType type,
044: String name,
045: Map<Class<? extends Annotation>, Annotation> declaredAnnotations) {
046: this .enclosingMethod = enclosingMethod;
047: this .type = type;
048: this .name = name;
049:
050: enclosingMethod.addParameter(this );
051:
052: annotations = new Annotations();
053: annotations.addAnnotations(declaredAnnotations);
054: }
055:
056: JParameter(JAbstractMethod enclosingMethod, JParameter srcParam) {
057: this .enclosingMethod = enclosingMethod;
058: this .type = srcParam.type;
059: this .name = srcParam.name;
060: this .annotations = new Annotations(srcParam.annotations);
061: MetaData.copy(this , srcParam);
062: }
063:
064: public void addMetaData(String tagName, String[] values) {
065: metaData.addMetaData(tagName, values);
066: }
067:
068: public <T extends Annotation> T getAnnotation(
069: Class<T> annotationClass) {
070: return annotations.getAnnotation(annotationClass);
071: }
072:
073: public Annotation[] getAnnotations() {
074: return annotations.getAnnotations();
075: }
076:
077: public Annotation[] getDeclaredAnnotations() {
078: return annotations.getDeclaredAnnotations();
079: }
080:
081: public JAbstractMethod getEnclosingMethod() {
082: return enclosingMethod;
083: }
084:
085: public String[][] getMetaData(String tagName) {
086: return metaData.getMetaData(tagName);
087: }
088:
089: public String[] getMetaDataTags() {
090: return metaData.getMetaDataTags();
091: }
092:
093: public String getName() {
094: return name;
095: }
096:
097: public JType getType() {
098: return type;
099: }
100:
101: public boolean isAnnotationPresent(
102: Class<? extends Annotation> annotationClass) {
103: return annotations.isAnnotationPresent(annotationClass);
104: }
105:
106: public String toString() {
107: StringBuffer sb = new StringBuffer();
108: sb.append(type.getQualifiedSourceName());
109: sb.append(" ");
110: sb.append(getName());
111: return sb.toString();
112: }
113:
114: // Called when parameter types are found to be parameterized
115: void setType(JType type) {
116: this.type = type;
117: }
118: }
|