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.Map;
24 
25 public class ParameterInfo {
ParameterInfo(String name, String typeName, TypeInfo type, boolean isVarArg, SourcePositionInfo position)26   public ParameterInfo(String name, String typeName, TypeInfo type, boolean isVarArg,
27       SourcePositionInfo position) {
28     mName = name;
29     mTypeName = typeName;
30     mType = type;
31     mIsVarArg = isVarArg;
32     mPosition = position;
33   }
34 
35   /**
36    * Clone this Parameter, but replace the type according to the typeArgumentMapping provided.
37    */
cloneWithTypeArguments(Map<String, TypeInfo> typeArgumentMapping)38   public ParameterInfo cloneWithTypeArguments(Map<String, TypeInfo> typeArgumentMapping) {
39     return new ParameterInfo(
40         mName, mTypeName, mType.getTypeWithArguments(typeArgumentMapping), mIsVarArg, mPosition);
41   }
42 
type()43   TypeInfo type() {
44     return mType;
45   }
46 
name()47   String name() {
48     return mName;
49   }
50 
typeName()51   String typeName() {
52     return mTypeName;
53   }
54 
position()55   SourcePositionInfo position() {
56     return mPosition;
57   }
58 
isVarArg()59   boolean isVarArg() {
60     return mIsVarArg;
61   }
62 
makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables)63   public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables) {
64     makeHDF(data, base, isLastVararg, typeVariables, Collections.<String, TypeInfo>emptyMap());
65   }
66 
makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping)67   public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables,
68       Map<String, TypeInfo> typeMapping) {
69     data.setValue(base + ".name", this.name());
70     type().getTypeWithArguments(typeMapping).makeHDF(
71         data, base + ".type", isLastVararg, typeVariables);
72   }
73 
makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, HashSet<String> typeVariables)74   public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg,
75       HashSet<String> typeVariables) {
76     makeHDF(data, base, params, isVararg, typeVariables, Collections.<String, TypeInfo>emptyMap());
77   }
78 
makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping)79   public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg,
80       HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping) {
81     for (int i = 0; i < params.length; i++) {
82       params[i].makeHDF(
83           data, base + "." + i, isVararg && (i == params.length - 1), typeVariables, typeMapping);
84     }
85   }
86 
87   /**
88    * Returns true if this parameter's dimension information agrees
89    * with the represented callee's dimension information.
90    */
matchesDimension(String dimension, boolean varargs)91   public boolean matchesDimension(String dimension, boolean varargs) {
92     if (varargs) {
93       dimension += "[]";
94     }
95     return mType.dimension().equals(dimension);
96   }
97 
98   String mName;
99   String mTypeName;
100   TypeInfo mType;
101   boolean mIsVarArg;
102   SourcePositionInfo mPosition;
103 }
104