Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 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 | |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 21 | import java.util.Collections; |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 22 | import java.util.HashSet; |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 23 | import java.util.Map; |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 24 | |
| 25 | public class ParameterInfo { |
| 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 | |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Clone this Parameter, but replace the type according to the typeArgumentMapping provided. |
| 37 | */ |
| 38 | public ParameterInfo cloneWithTypeArguments(Map<String, TypeInfo> typeArgumentMapping) { |
| 39 | return new ParameterInfo( |
| 40 | mName, mTypeName, mType.getTypeWithArguments(typeArgumentMapping), mIsVarArg, mPosition); |
| 41 | } |
| 42 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 43 | TypeInfo type() { |
| 44 | return mType; |
| 45 | } |
| 46 | |
| 47 | String name() { |
| 48 | return mName; |
| 49 | } |
| 50 | |
| 51 | String typeName() { |
| 52 | return mTypeName; |
| 53 | } |
| 54 | |
| 55 | SourcePositionInfo position() { |
| 56 | return mPosition; |
| 57 | } |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 58 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 59 | boolean isVarArg() { |
| 60 | return mIsVarArg; |
| 61 | } |
| 62 | |
| 63 | public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables) { |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 64 | makeHDF(data, base, isLastVararg, typeVariables, Collections.<String, TypeInfo>emptyMap()); |
| 65 | } |
| 66 | |
| 67 | public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables, |
| 68 | Map<String, TypeInfo> typeMapping) { |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 69 | data.setValue(base + ".name", this.name()); |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 70 | type().getTypeWithArguments(typeMapping).makeHDF( |
| 71 | data, base + ".type", isLastVararg, typeVariables); |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, |
| 75 | HashSet<String> typeVariables) { |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 76 | makeHDF(data, base, params, isVararg, typeVariables, Collections.<String, TypeInfo>emptyMap()); |
| 77 | } |
| 78 | |
| 79 | public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg, |
| 80 | HashSet<String> typeVariables, Map<String, TypeInfo> typeMapping) { |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 81 | for (int i = 0; i < params.length; i++) { |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 82 | params[i].makeHDF( |
| 83 | data, base + "." + i, isVararg && (i == params.length - 1), typeVariables, typeMapping); |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
Jeff Arneson | d6570b0 | 2014-10-29 15:46:51 -0700 | [diff] [blame] | 86 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Returns true if this parameter's dimension information agrees |
| 89 | * with the represented callee's dimension information. |
| 90 | */ |
| 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 | } |