MCPcopy Index your code
hub / github.com/apache/groovy / sortClasses

Method sortClasses

src/main/java/org/codehaus/groovy/ast/ModuleNode.java:852–870  ·  view source on GitHub ↗

Sorts classes in dependency order based on class hierarchy. Inner classes and dependent classes are ordered after their dependencies. This ensures that base classes are defined before derived classes during compilation. Does nothing if the module is empty or contains only one class.

()

Source from the content-addressed store, hash-verified

850 * Does nothing if the module is empty or contains only one class.
851 */
852 public void sortClasses() {
853 if (isEmpty()) return;
854 List<ClassNode> classes = getClasses();
855 if (classes.size() == 1) return;
856 List<ClassNode> ordered = new LinkedList<>();
857 int level = 1;
858 while (!classes.isEmpty()) {
859 for (Iterator<ClassNode> it = classes.iterator(); it.hasNext(); ) {
860 ClassNode cn = it.next(), sc = cn.getSuperClass();
861
862 for (int i = 1; i < level && sc != null; i += 1) sc = sc.getSuperClass();
863 if (sc != null && sc.isPrimaryClassNode()) continue;
864 ordered.add(cn);
865 it.remove();
866 }
867 level += 1;
868 }
869 this.classes = ordered;
870 }
871
872 /**
873 * Checks whether imports have been resolved for this module.

Callers

nothing calls this directly

Calls 10

isEmptyMethod · 0.95
getClassesMethod · 0.95
getSuperClassMethod · 0.95
isPrimaryClassNodeMethod · 0.95
sizeMethod · 0.65
iteratorMethod · 0.65
addMethod · 0.65
removeMethod · 0.65
hasNextMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected