void (CompileContext context, String filePath, Iterable<Map.Entry<? extends JavacRef, Integer>> refs, Collection<? extends JavacDef> defs, Collection<? extends JavacTypeCast> casts, Collection<? extends JavacRef> implicitToString) { final Set<String> definedClasses = new HashSet<>(); for (JavacDef def : defs) { if (def instanceof JavacDef.JavacClassDef) { final JavacRef element = def.getDefinedElement(); if (element instanceof JavacRef.JavacClass) { definedClasses.add(element.getName()); } } } if (definedClasses.isEmpty()) { return; } Iterator<Map.Entry<? extends JavacRef, Integer>> iterator = refs.iterator(); if (iterator.hasNext()) { final Set<String> classImports = new HashSet<>(); final Set<String> staticImports = new HashSet<>(); final Map<String, List<Callbacks.ConstantRef>> cRefs = new HashMap<>(); while (iterator.hasNext()) { JavacRef ref = iterator.next().getKey(); final JavacRef.ImportProperties importProps = ref.getImportProperties(); if (importProps != null) { // the reference comes from import list if (ref instanceof JavacRef.JavacClass) { classImports.add(ref.getName()); if (importProps.isStatic() && importProps.isOnDemand()) { staticImports.add(ref.getName() + ".*"); } } else { if (ref instanceof JavacRef.JavacField || ref instanceof JavacRef.JavacMethod) { staticImports.add(ref.getOwnerName() + "." + ref.getName()); } } } else if (ref instanceof JavacRef.JavacField && ref.getModifiers().contains(Modifier.FINAL)) { final JavacRef.JavacField fieldRef = (JavacRef.JavacField)ref; final String descriptor = fieldRef.getDescriptor(); if (descriptor != null && definedClasses.contains(fieldRef.getContainingClass()) && !definedClasses.contains(fieldRef.getOwnerName())) { List<Callbacks.ConstantRef> refsList = cRefs.get(fieldRef.getContainingClass()); if (refsList == null) { refsList = new ArrayList<>(); cRefs.put(fieldRef.getContainingClass(), refsList); } refsList.add(Callbacks.createConstantReference(fieldRef.getOwnerName(), fieldRef.getName(), descriptor)); } } } if (!classImports.isEmpty() || !staticImports.isEmpty()) { final Callbacks.Backend reg = JavaBuilderUtil.getDependenciesRegistrar(context); for (String aClass : definedClasses) { reg.registerImports(aClass, classImports, staticImports); } } if (!cRefs.isEmpty()) { final Callbacks.Backend reg = JavaBuilderUtil.getDependenciesRegistrar(context); for (String aClass : definedClasses) { final List<Callbacks.ConstantRef> classCRefs = cRefs.get(aClass); reg.registerConstantReferences(aClass, classCRefs != null? classCRefs : Collections.emptyList()); } } } }