(Type type, ClassInstance context)
| 147 | } |
| 148 | |
| 149 | private String toDesc(Type type, ClassInstance context) { |
| 150 | if (type instanceof PrimitiveType) { |
| 151 | PrimitiveType t = (PrimitiveType) type; |
| 152 | |
| 153 | switch (t.getType()) { |
| 154 | case BOOLEAN: return "Z"; |
| 155 | case BYTE: return "B"; |
| 156 | case CHAR: return "C"; |
| 157 | case DOUBLE: return "D"; |
| 158 | case FLOAT: return "F"; |
| 159 | case INT: return "I"; |
| 160 | case LONG: return "J"; |
| 161 | case SHORT: return "S"; |
| 162 | default: |
| 163 | throw new IllegalArgumentException("invalid primitive type class: "+t.getType().getClass().getName()); |
| 164 | } |
| 165 | } else if (type instanceof VoidType) { |
| 166 | return "V"; |
| 167 | } else if (type instanceof ClassOrInterfaceType) { |
| 168 | ClassOrInterfaceType t = (ClassOrInterfaceType) type; |
| 169 | String name; |
| 170 | |
| 171 | if (!t.getScope().isPresent()) { |
| 172 | name = t.getNameAsString(); |
| 173 | } else { |
| 174 | List<String> parts = new ArrayList<>(); |
| 175 | |
| 176 | do { |
| 177 | parts.add(t.getName().getIdentifier()); |
| 178 | } while ((t = t.getScope().orElse(null)) != null); |
| 179 | |
| 180 | StringBuilder sb = new StringBuilder(); |
| 181 | |
| 182 | for (int i = parts.size() - 1; i >= 0; i--) { |
| 183 | if (sb.length() > 1) sb.append('/'); |
| 184 | sb.append(parts.get(i)); |
| 185 | } |
| 186 | |
| 187 | name = sb.toString(); |
| 188 | } |
| 189 | |
| 190 | assert name.indexOf('.') == -1; |
| 191 | |
| 192 | // direct lookup (for fully qualified name without nested classes) |
| 193 | ClassInstance cls = getClsByName(name); |
| 194 | if (cls != null) return ClassInstance.getId(name); |
| 195 | |
| 196 | // nested lookup (if name is a nested class of the context class) |
| 197 | String nestedName = getName(context) + '$' + name.replace('/', '$'); |
| 198 | cls = getClsByName(nestedName); |
| 199 | if (cls != null) return ClassInstance.getId(nestedName); |
| 200 | |
| 201 | int pkgEnd = name.lastIndexOf('/'); |
| 202 | int nameEnd = name.length(); |
| 203 | |
| 204 | for (;;) { |
| 205 | if (pkgEnd == -1) { // non-fqn (fqn without package was already checked) |
| 206 | String cName = name.substring(pkgEnd + 1, nameEnd); |
no test coverage detected