(ClassEnvironment env)
| 19 | |
| 20 | public final class SignatureInference<T> { |
| 21 | public static void process(ClassEnvironment env) { |
| 22 | Set<String> missingParams = new HashSet<>(); |
| 23 | Set<String> shadowedParams = new HashSet<>(); |
| 24 | |
| 25 | for (ClassInstance cls : env.getClassesA()) { |
| 26 | if (!cls.isInput() || cls.getSignature() != null) continue; |
| 27 | |
| 28 | // find type variables needed by own fields (can't declare their own type variables, so must be from the class) |
| 29 | |
| 30 | for (FieldInstance field : cls.getFields()) { |
| 31 | FieldSignature sig = field.getSignature(); |
| 32 | if (sig == null) continue; |
| 33 | |
| 34 | processRefTypeSig(sig.getCls(), shadowedParams, missingParams); |
| 35 | } |
| 36 | |
| 37 | // find type variables needed by own methods and not declared by them |
| 38 | |
| 39 | for (MethodInstance method : cls.getMethods()) { |
| 40 | MethodSignature sig = method.getSignature(); |
| 41 | if (sig == null) continue; |
| 42 | |
| 43 | if (sig.getTypeParameters() != null) { |
| 44 | for (TypeParameter typeParem : sig.getTypeParameters()) { |
| 45 | shadowedParams.add(typeParem.getIdentifier()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | for (JavaTypeSignature arg : sig.getArgs()) { |
| 50 | ReferenceTypeSignature argRefType = arg.getCls(); |
| 51 | if (argRefType != null) processRefTypeSig(argRefType, shadowedParams, missingParams); |
| 52 | } |
| 53 | |
| 54 | if (sig.getResult() != null) { |
| 55 | if (sig.getResult().getCls() != null) processRefTypeSig(sig.getResult().getCls(), shadowedParams, missingParams); |
| 56 | } |
| 57 | |
| 58 | if (sig.getThrowsSignatures() != null) { |
| 59 | for (ThrowsSignature throwsSig : sig.getThrowsSignatures()) { |
| 60 | if (throwsSig.getCls() != null) { |
| 61 | processClsTypeSig(throwsSig.getCls(), shadowedParams, missingParams); |
| 62 | } else { // throwsSig.getVar() != null |
| 63 | if (!shadowedParams.contains(throwsSig.getVar())) { |
| 64 | missingParams.add(throwsSig.getVar()); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | shadowedParams.clear(); |
| 71 | } |
| 72 | |
| 73 | missingParams.clear(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private static void processRefTypeSig(ReferenceTypeSignature sig, Set<String> shadowedParams, Set<String> missingParams) { |
| 78 | if (sig.getCls() != null) { |
nothing calls this directly
no test coverage detected