MCPcopy
hub / github.com/jOOQ/jOOQ / ref

Method ref

jOOQ-codegen/src/main/java/org/jooq/codegen/JavaWriter.java:315–380  ·  view source on GitHub ↗
(List<String> clazz, int keepSegments)

Source from the content-addressed store, hash-verified

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

Callers 7

printClassMethod · 0.95
patchKotlinClassesMethod · 0.95
generateRelationsMethod · 0.95
generateUDTReferencesMethod · 0.95
generateSequencesMethod · 0.95

Calls 15

patchKotlinClassesMethod · 0.95
joinMethod · 0.95
matcherMethod · 0.80
refMethod · 0.65
sizeMethod · 0.65
containsMethod · 0.65
getMethod · 0.65
equalsMethod · 0.65
addMethod · 0.65
substringMethod · 0.65
lengthMethod · 0.65
matchesMethod · 0.45

Tested by

no test coverage detected