Clone
Robert Stupp <snazy@snazy.de>
committed
on 02 Sep
Improve incremental compilation for Java
This patch splits the collected dependencies found in a .class file into "accessible" and "private"… Show more
Improve incremental compilation for Java

This patch splits the collected dependencies found in a .class file into "accessible" and "private" dependencies.

* "Accessbile" dependencies are classes that belong to non-private fields, non-private method signatures, class signature ("extends", "implements") etc

* "Private" dependencies are classes that belong to private fields, private methods and classes used in method bodies (i.e. just in "the code")

The TL;DR of the approach is to change the algorithm in `ClassSetAnalysis.getRelevantDependents` to only recurse for "accessible" dependencies.

Goal by example:

Consider classes like

```

class A {

 private B b

}

class B {

 private C c

}

class C {

}

```

The previous algorithm in `ClassSetAnalysis.getRelevantDependents` would recompile all classes, if `C` was changed. The new algorithm recompiles

just `B` and `C`, because `C` has been changed and `B` uses `C`. But it doesn't recompile `A`, because `A` is not affected by the change. The same

is true, if `C` would have been only used in a method body of `B` or in the signature of a `private` function in `B`.

The algorithm properly handles changes to classes used in the following example:

```

public class SomeClass {

   List<Integer> field = new LinkedList<Integer>();

   private AccessedFromPrivateField accessedFromPrivateField;

   AccessedFromPackagePrivateField someField;

   private AccessedFromPrivateMethod accessedFromPrivateMethod() {

       return null;

   }

   public String accessedFromPrivateMethodBody() {

       return new AccessedFromPrivateMethodBody().toString();

   }

   private Set<String> stuff(HashMap<String, String> map) {

       System.out.println(new Foo());

       return new HashSet<String>();

   }

   private class Foo {

       // Hint: this field won't appear in the ClassAnalysis for SomeClass

       public AccessedFromPrivateClassPublicField anotherField;

       public String toString() {

           return "" + new AccessedFromPrivateClass();

       }

   }

}

```

Changes the serialization format of `ClassAnalysis` + `DependentsSet`

Signed-off-by: Robert Stupp <snazy@snazy.de>

Show less

master + 69 more