blob: b911283fae8881bbf6ccace6092bdf735e273e6f [file] [log] [blame]
Ben Dodson920dbbb2010-08-04 15:21:06 -07001/*
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
17package com.google.doclava;
18
19import com.google.clearsilver.jsilver.data.Data;
20
Jeff Arnesond6570b02014-10-29 15:46:51 -070021import java.util.Collections;
Ben Dodson920dbbb2010-08-04 15:21:06 -070022import java.util.HashSet;
Jeff Arnesond6570b02014-10-29 15:46:51 -070023import java.util.Map;
Ben Dodson920dbbb2010-08-04 15:21:06 -070024
25public 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 Arnesond6570b02014-10-29 15:46:51 -070035 /**
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 Dodson920dbbb2010-08-04 15:21:06 -070043 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 Arnesond6570b02014-10-29 15:46:51 -070058
Ben Dodson920dbbb2010-08-04 15:21:06 -070059 boolean isVarArg() {
60 return mIsVarArg;
61 }
62
63 public void makeHDF(Data data, String base, boolean isLastVararg, HashSet<String> typeVariables) {
Jeff Arnesond6570b02014-10-29 15:46:51 -070064 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 Dodson920dbbb2010-08-04 15:21:06 -070069 data.setValue(base + ".name", this.name());
Jeff Arnesond6570b02014-10-29 15:46:51 -070070 type().getTypeWithArguments(typeMapping).makeHDF(
71 data, base + ".type", isLastVararg, typeVariables);
Ben Dodson920dbbb2010-08-04 15:21:06 -070072 }
73
74 public static void makeHDF(Data data, String base, ParameterInfo[] params, boolean isVararg,
75 HashSet<String> typeVariables) {
Jeff Arnesond6570b02014-10-29 15:46:51 -070076 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 Dodson920dbbb2010-08-04 15:21:06 -070081 for (int i = 0; i < params.length; i++) {
Jeff Arnesond6570b02014-10-29 15:46:51 -070082 params[i].makeHDF(
83 data, base + "." + i, isVararg && (i == params.length - 1), typeVariables, typeMapping);
Ben Dodson920dbbb2010-08-04 15:21:06 -070084 }
85 }
Jeff Arnesond6570b02014-10-29 15:46:51 -070086
Ben Dodson920dbbb2010-08-04 15:21:06 -070087 /**
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}