Clover Coverage Report - XWiki Commons - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 17:13:48 CET
../../../../img/srcFileCovDistChart3.png 64% of files have more coverage
34   155   17   4.25
14   90   0.5   8
8     2.12  
1    
 
  DefaultParameterizedType       Line # 31 34 0% 17 39 30.4% 0.30357143
 
No Tests
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.component.util;
21   
22    import java.lang.reflect.ParameterizedType;
23    import java.lang.reflect.Type;
24    import java.util.Arrays;
25   
26    /**
27    * Basic implementation of {@link ParameterizedType}.
28    *
29    * @version $Id: e48d8a6e652ca20496a0f5f64d7e5ba6f8d90a1d $
30    */
 
31    public class DefaultParameterizedType implements ParameterizedType
32    {
33    /**
34    * @see #getActualTypeArguments()
35    */
36    private final Type[] actualTypeArguments;
37   
38    /**
39    * @see #getOwnerType()
40    */
41    private final Type ownerType;
42   
43    /**
44    * @see #getRawType()
45    */
46    private final Class< ? > rawType;
47   
48    /**
49    * @param ownerType the owner type
50    * @param rawType the raw type
51    * @param actualTypeArguments the generic arguments
52    */
 
53  113 toggle public DefaultParameterizedType(Type ownerType, Class< ? > rawType, Type... actualTypeArguments)
54    {
55  113 this.ownerType = ownerType;
56  113 this.actualTypeArguments = actualTypeArguments;
57  113 this.rawType = rawType;
58    }
59   
60    /**
61    * @param type the type to duplicate
62    */
 
63  0 toggle public DefaultParameterizedType(ParameterizedType type)
64    {
65  0 this(type.getOwnerType(), (Class< ? >) type.getRawType(), type.getActualTypeArguments());
66    }
67   
 
68  11 toggle @Override
69    public Type[] getActualTypeArguments()
70    {
71  11 return this.actualTypeArguments.clone();
72    }
73   
 
74  1 toggle @Override
75    public Type getOwnerType()
76    {
77  1 return this.ownerType;
78    }
79   
 
80  21 toggle @Override
81    public Type getRawType()
82    {
83  21 return this.rawType;
84    }
85   
 
86  2 toggle @Override
87    public int hashCode()
88    {
89  2 return Arrays.hashCode(this.actualTypeArguments) ^ ObjectUtils.hasCode(this.ownerType)
90    ^ ObjectUtils.hasCode(this.rawType);
91    }
92   
 
93  6 toggle @Override
94    public boolean equals(Object o)
95    {
96  6 if (o == null || !(o instanceof ParameterizedType)) {
97  0 return false;
98    }
99   
100  6 ParameterizedType parameterizedType = (ParameterizedType) o;
101   
102  6 return ObjectUtils.equals(this.rawType, parameterizedType.getRawType())
103    && ObjectUtils.equals(this.ownerType, parameterizedType.getOwnerType())
104    && Arrays.equals(this.actualTypeArguments, parameterizedType.getActualTypeArguments());
105    }
106   
 
107  0 toggle @Override
108    public String toString()
109    {
110  0 StringBuilder sb = new StringBuilder();
111  0 if (this.ownerType != null) {
112  0 if (this.ownerType instanceof Class) {
113  0 sb.append(((Class< ? >) this.ownerType).getName());
114    } else {
115  0 sb.append(this.ownerType.toString());
116    }
117   
118  0 sb.append('.');
119   
120  0 if (this.ownerType instanceof ParameterizedType) {
121    // Find simple name of nested type by removing the
122    // shared prefix with owner.
123  0 sb.append(this.rawType.getName().replace(
124    ((Class< ? >) ((ParameterizedType) ownerType).getRawType()).getName() + '$', ""));
125    } else {
126  0 sb.append(this.rawType.getName());
127    }
128    } else {
129  0 sb.append(this.rawType.getName());
130    }
131   
132  0 if (this.actualTypeArguments != null && this.actualTypeArguments.length > 0) {
133  0 sb.append("< ");
134   
135  0 boolean first = true;
136  0 for (Type type : this.actualTypeArguments) {
137  0 if (!first) {
138  0 sb.append(", ");
139    }
140   
141  0 if (type instanceof Class) {
142  0 sb.append(((Class< ? >) type).getName());
143    } else {
144  0 sb.append(type.toString());
145    }
146   
147  0 first = false;
148    }
149   
150  0 sb.append(" >");
151    }
152   
153  0 return sb.toString();
154    }
155    }