1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  package org.grouplens.grapht;
21  
22  import org.apache.commons.lang3.tuple.Pair;
23  import org.grouplens.grapht.reflect.Desire;
24  import org.grouplens.grapht.reflect.InjectionPoint;
25  import org.grouplens.grapht.reflect.Satisfaction;
26  import org.grouplens.grapht.solver.DesireChain;
27  import org.grouplens.grapht.solver.InjectionContext;
28  import org.grouplens.grapht.solver.SolverException;
29  
30  
31  
32  
33  
34  
35  
36  @SuppressWarnings("deprecation")
37  public class ResolutionException extends SolverException {
38      private static final long serialVersionUID = 1L;
39  
40      public ResolutionException() {
41          super();
42      }
43  
44      public ResolutionException(String msg) {
45          super(msg);
46      }
47  
48      public ResolutionException(Throwable throwable) {
49          super(throwable);
50      }
51  
52      public ResolutionException(String msg, Throwable throwable) {
53          super(msg, throwable);
54      }
55      
56      protected String format(InjectionContext ctx, DesireChain desires) {
57          StringBuilder sb = new StringBuilder();
58          
59          
60          sb.append("Context:\n");
61          sb.append("  Type path:\n");
62          for (Pair<Satisfaction, InjectionPoint> path: ctx) {
63              Satisfaction sat = path.getLeft();
64              Class<?> type = sat == null ? null : sat.getErasedType();
65              sb.append("    ")
66                .append(format(path.getRight(), type))
67                .append('\n');
68          }
69          sb.append('\n');
70          
71          
72          sb.append("  Prior desires:\n");
73          for (Desire desire: desires.getPreviousDesires()) {
74              sb.append("    ")
75                .append(format(desire.getInjectionPoint(), desire.getDesiredType()))
76                .append('\n');
77          }
78  
79          return sb.toString();
80      }
81  
82      protected String format(InjectionPoint ip) {
83          return format(ip, ip.getErasedType());
84      }
85  
86      protected String format(InjectionPoint ip, Class<?> type) {
87          if (type == null) {
88              type = ip.getErasedType();
89          }
90          String base = (ip.getQualifier() != null ? ip.getQualifier() + ":" : "");
91          String name = type == null ? null : type.getName();
92          return base + name;
93      }
94  }