1 package com.stateofflow.eclipse.metrics.bindings;
2
3 import org.eclipse.jdt.core.dom.ITypeBinding;
4
5 class TypeVariableAnalyser {
6 public static boolean containsTypeVariables(final ITypeBinding type) {
7 return type.isTypeVariable() || isArrayContainingTypeVariables(type) || isCaptureContainingTypeVariables(type) || isParameterizedTypeContainingTypeVariables(type) || isTypeVariableContainingTypeVariables(type) || isWildcardTypeContainingTypeVariables(type);
8 }
9
10 private static boolean isWildcardTypeContainingTypeVariables(final ITypeBinding type) {
11 return type.isWildcardType() && type.getBound() != null && containsTypeVariables(type.getBound());
12 }
13
14 private static boolean isTypeVariableContainingTypeVariables(final ITypeBinding type) {
15 return type.isTypeVariable() && containsTypeVariables(type.getTypeBounds());
16 }
17
18 private static boolean isParameterizedTypeContainingTypeVariables(final ITypeBinding type) {
19 return type.isParameterizedType() && containsTypeVariables(type.getTypeArguments());
20 }
21
22 private static boolean isCaptureContainingTypeVariables(final ITypeBinding type) {
23 return type.isCapture() && containsTypeVariables(type.getWildcard());
24 }
25
26 private static boolean isArrayContainingTypeVariables(final ITypeBinding type) {
27 return type.isArray() && containsTypeVariables(type.getElementType());
28 }
29
30 private static boolean containsTypeVariables(final ITypeBinding[] types) {
31 for (int i = 0; i < types.length; i++) {
32 if (containsTypeVariables(types[i])) {
33 return true;
34 }
35 }
36 return false;
37 }
38 }
39