1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.component.util

File DefaultParameterizedType.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

14
34
8
1
156
91
17
0.5
4.25
8
2.12

Classes

Class Line # Actions
DefaultParameterizedType 32 34 0% 17 15
0.7321428773.2%
 

Contributing tests

This file is covered by 2237 tests. .

Source view

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    import java.util.Objects;
26   
27    /**
28    * Basic implementation of {@link ParameterizedType}.
29    *
30    * @version $Id: 935f5eecbbc5bb3ad7dd33cc9f4207be1d4c5f06 $
31    */
 
32    public class DefaultParameterizedType implements ParameterizedType
33    {
34    /**
35    * @see #getActualTypeArguments()
36    */
37    private final Type[] actualTypeArguments;
38   
39    /**
40    * @see #getOwnerType()
41    */
42    private final Type ownerType;
43   
44    /**
45    * @see #getRawType()
46    */
47    private final Class<?> rawType;
48   
49    /**
50    * @param ownerType the owner type
51    * @param rawType the raw type
52    * @param actualTypeArguments the generic arguments
53    */
 
54  690104 toggle public DefaultParameterizedType(Type ownerType, Class<?> rawType, Type... actualTypeArguments)
55    {
56  690072 this.ownerType = ownerType;
57  690076 this.actualTypeArguments = actualTypeArguments;
58  690058 this.rawType = rawType;
59    }
60   
61    /**
62    * @param type the type to duplicate
63    */
 
64  0 toggle public DefaultParameterizedType(ParameterizedType type)
65    {
66  0 this(type.getOwnerType(), (Class<?>) type.getRawType(), type.getActualTypeArguments());
67    }
68   
 
69  5862040 toggle @Override
70    public Type[] getActualTypeArguments()
71    {
72  5862058 return this.actualTypeArguments.clone();
73    }
74   
 
75  781310309 toggle @Override
76    public Type getOwnerType()
77    {
78  781310336 return this.ownerType;
79    }
80   
 
81  784595940 toggle @Override
82    public Type getRawType()
83    {
84  784596336 return this.rawType;
85    }
86   
 
87  7092715 toggle @Override
88    public int hashCode()
89    {
90  7092723 return Arrays.hashCode(this.actualTypeArguments) ^ Objects.hashCode(this.ownerType)
91    ^ Objects.hashCode(this.rawType);
92    }
93   
 
94  54942861 toggle @Override
95    public boolean equals(Object o)
96    {
97  55018319 if (o == null || !(o instanceof ParameterizedType)) {
98  44433402 return false;
99    }
100   
101  10559549 ParameterizedType parameterizedType = (ParameterizedType) o;
102   
103  10559692 return Objects.equals(this.rawType, parameterizedType.getRawType())
104    && Objects.equals(this.ownerType, parameterizedType.getOwnerType())
105    && Arrays.equals(this.actualTypeArguments, parameterizedType.getActualTypeArguments());
106    }
107   
 
108  26052 toggle @Override
109    public String toString()
110    {
111  26053 StringBuilder sb = new StringBuilder();
112  26053 if (this.ownerType != null) {
113  0 if (this.ownerType instanceof Class) {
114  0 sb.append(((Class<?>) this.ownerType).getName());
115    } else {
116  0 sb.append(this.ownerType.toString());
117    }
118   
119  0 sb.append('.');
120   
121  0 if (this.ownerType instanceof ParameterizedType) {
122    // Find simple name of nested type by removing the
123    // shared prefix with owner.
124  0 sb.append(this.rawType.getName().replace(
125    ((Class<?>) ((ParameterizedType) this.ownerType).getRawType()).getName() + '$', ""));
126    } else {
127  0 sb.append(this.rawType.getName());
128    }
129    } else {
130  26053 sb.append(this.rawType.getName());
131    }
132   
133  26054 if (this.actualTypeArguments != null && this.actualTypeArguments.length > 0) {
134  26054 sb.append("< ");
135   
136  26053 boolean first = true;
137  26053 for (Type type : this.actualTypeArguments) {
138  51769 if (!first) {
139  25716 sb.append(", ");
140    }
141   
142  51769 if (type instanceof Class) {
143  51769 sb.append(((Class<?>) type).getName());
144    } else {
145  1 sb.append(type.toString());
146    }
147   
148  51769 first = false;
149    }
150   
151  26054 sb.append(" >");
152    }
153   
154  26054 return sb.toString();
155    }
156    }