(List<String> clazz, int keepSegments)
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | protected List<String> ref(List<String> clazz, int keepSegments) { |
| 317 | if (ignoreImports) |
| 318 | return super.ref(clazz, keepSegments); |
| 319 | |
| 320 | List<String> result = new ArrayList<>(clazz == null ? 0 : clazz.size()); |
| 321 | |
| 322 | if (clazz != null) { |
| 323 | for (String c : clazz) { |
| 324 | |
| 325 | // Skip unqualified and primitive types |
| 326 | checks: { |
| 327 | if (!c.contains(".")) |
| 328 | break checks; |
| 329 | |
| 330 | c = patchKotlinClasses(c); |
| 331 | |
| 332 | // com.example.Table.TABLE.COLUMN (with keepSegments = 3) |
| 333 | if (fullyQualifiedTypesPattern != null && fullyQualifiedTypesPattern.matcher(c).matches()) |
| 334 | break checks; |
| 335 | |
| 336 | Matcher m = TYPE_REFERENCE_PATTERN.matcher(c); |
| 337 | if (!m.find()) |
| 338 | break checks; |
| 339 | |
| 340 | // [com, example, Table, TABLE, COLUMN] |
| 341 | List<String> split = Arrays.asList(m.group(1).split("\\.")); |
| 342 | |
| 343 | // com.example.Table |
| 344 | String qualifiedType = StringUtils.join(split.subList(0, split.size() - keepSegments + 1).toArray(), "."); |
| 345 | |
| 346 | // Table |
| 347 | String unqualifiedType = split.get(split.size() - keepSegments); |
| 348 | |
| 349 | // Table.TABLE.COLUMN |
| 350 | String remainder = StringUtils.join(split.subList(split.size() - keepSegments, split.size()).toArray(), "."); |
| 351 | |
| 352 | // [#9697] Don't import a class from a different package by the same name as this class |
| 353 | if ((className.equals(unqualifiedType) && (packageName == null || !qualifiedType.equals(packageName + "." + className))) |
| 354 | || (unqualifiedTypes.containsKey(unqualifiedType) && !qualifiedType.equals(unqualifiedTypes.get(unqualifiedType)))) |
| 355 | break checks; |
| 356 | |
| 357 | // [#10561] Don't import type that conflicts with a local identifier |
| 358 | if (refConflicts.contains(unqualifiedType)) |
| 359 | break checks; |
| 360 | |
| 361 | // [#10561] Don't import a class that conflicts with a local identifier |
| 362 | unqualifiedTypes.put(unqualifiedType, qualifiedType); |
| 363 | qualifiedTypes.add(qualifiedType); |
| 364 | String generic = m.group(2); |
| 365 | |
| 366 | // Consider importing generic type arguments, recursively |
| 367 | c = remainder |
| 368 | + (PLAIN_GENERIC_TYPE_PATTERN.matcher(generic).matches() |
| 369 | ? generic.substring(0, 1) + ref(generic.substring(1, generic.length() - 1)) + generic.substring(generic.length() - 1) |
| 370 | : generic); |
| 371 | } |
| 372 |
no test coverage detected