1 /* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.doclava; 18 19 import com.google.clearsilver.jsilver.data.Data; 20 21 import java.util.Collections; 22 import java.util.HashSet; 23 import java.util.List; 24 import java.util.Map; 25 26 public class ParameterInfo { ParameterInfo(String name, String typeName, TypeInfo type, boolean isVarArg, SourcePositionInfo position, List<AnnotationInstanceInfo> annotationInstanceInfos)27 public ParameterInfo(String name, String typeName, TypeInfo type, boolean isVarArg, 28 SourcePositionInfo position, List<AnnotationInstanceInfo> annotationInstanceInfos) { 29 mName = name; 30 mTypeName = typeName; 31 mType = type; 32 mIsVarArg = isVarArg; 33 mPosition = position; 34 mAnnotations = annotationInstanceInfos; 35 } 36 37 /** 38 * Clone this Parameter, but replace the type according to the typeArgumentMapping provided. 39 */ cloneWithTypeArguments(Map<String, TypeInfo> typeArgumentMapping)40 public ParameterInfo cloneWithTypeArguments(Map<String, TypeInfo> typeArgumentMapping) { 41 return new ParameterInfo( 42 mName, mTypeName, mType.getTypeWithArguments(typeArgumentMapping), 43 mIsVarArg, mPosition, mAnnotations); 44 } 45 type()46 public TypeInfo type() { 47 return mType; 48 } 49 name()50 String name() { 51 return mName; 52 } 53 typeName()54 public String typeName() { 55 return mTypeName; 56 } 57 position()58 SourcePositionInfo position() { 59 return mPosition; 60 } 61 isVarArg()62 boolean isVarArg() { 63 return mIsVarArg; 64 } 65 annotations()66 List<AnnotationInstanceInfo> annotations() { 67 return mAnnotations; 68 } 69 makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables)70 public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables) { 71 makeHDF(data, base, isLastVararg, typeVariables, Collections.<String, TypeInfo>emptyMap()); 72 } 73 makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping)74 public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables, 75 Map<String, TypeInfo> typeMapping) { 76 data.setValue(base + ".name", this.name()); 77 type().getTypeWithArguments(typeMapping).makeHDF( 78 data, base + ".type", isLastVararg, typeVariables); 79 } 80 makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, HashSet<String> typeVariables)81 public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, 82 HashSet<String> typeVariables) { 83 makeHDF(data, base, params, isVararg, typeVariables, Collections.<String, TypeInfo>emptyMap()); 84 } 85 makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping)86 public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, 87 HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping) { 88 for (int i = 0; i < params.length; i++) { 89 params[i].makeHDF( 90 data, base + "." + i, isVararg && (i == params.length - 1), typeVariables, typeMapping); 91 } 92 } 93 94 /** 95 * Returns true if this parameter's dimension information agrees 96 * with the represented callee's dimension information. 97 */ matchesDimension(String dimension, boolean varargs)98 public boolean matchesDimension(String dimension, boolean varargs) { 99 if (varargs) { 100 dimension += "[]"; 101 } 102 return mType.dimension().equals(dimension); 103 } 104 105 String mName; 106 String mTypeName; 107 TypeInfo mType; 108 boolean mIsVarArg; 109 SourcePositionInfo mPosition; 110 List<AnnotationInstanceInfo> mAnnotations; 111 } 112