• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / mybatis-3 / 2686

01 Feb 2025 09:55PM UTC coverage: 87.093% (-0.1%) from 87.217%
2686

Pull #3379

github

web-flow
Merge c97c5c598 into 3d71c862a
Pull Request #3379: Resolve type handler based on `java.lang.reflect.Type` instead of `Class` and respect runtime JDBC type

3825 of 4663 branches covered (82.03%)

515 of 579 new or added lines in 36 files covered. (88.95%)

28 existing lines in 6 files now uncovered.

9912 of 11381 relevant lines covered (87.09%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.64
/src/main/java/org/apache/ibatis/type/TypeReference.java
1
/*
2
 *    Copyright 2009-2025 the original author or authors.
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
 *       https://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
package org.apache.ibatis.type;
17

18
import java.lang.reflect.ParameterizedType;
19
import java.lang.reflect.Type;
20

21
/**
22
 * References a generic type.
23
 *
24
 * @param <T>
25
 *          the referenced type
26
 *
27
 * @since 3.1.0
28
 *
29
 * @author Simone Tripodi
30
 */
31
public abstract class TypeReference<T> {
32

33
  private final Type rawType;
34

35
  protected TypeReference() {
1✔
36
    rawType = getSuperclassTypeParameter(getClass());
1✔
37
  }
1✔
38

39
  Type getSuperclassTypeParameter(Class<?> clazz) {
40
    Type genericSuperclass = clazz.getGenericSuperclass();
1✔
41
    if (genericSuperclass instanceof Class) {
1!
42
      // try to climb up the hierarchy until meet something useful
UNCOV
43
      if (TypeReference.class != genericSuperclass) {
×
UNCOV
44
        return getSuperclassTypeParameter(clazz.getSuperclass());
×
45
      }
46

47
      throw new TypeException("'" + getClass() + "' extends TypeReference but misses the type parameter. "
×
48
          + "Remove the extension or add a type parameter to it.");
49
    }
50

51
    return ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0];
1✔
52
  }
53

54
  public final Type getRawType() {
55
    return rawType;
1✔
56
  }
57

58
  @Override
59
  public String toString() {
60
    return rawType.toString();
×
61
  }
62

63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc