Would it be possible to write Eclipse plugin, that:
Whenever in our code we use
ClassA.staticMethod1();(ClassAcome from included external jar)Plugin creates
ClassAin our project.It copies that one used method only (and all needed imports and dependent methods) from jar to newly created
ClassA- Unneeded class methods aren't copied to project and are still in external jar.When jar is removed all works fine.
What is your solution to achieve this?
thanks in advance
EDIT to clarify for @Thorbjørn Ravn Andersen:
given class is in a jar:
package com.ext.jar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Utilities {
public static Object giveFirstThing(){
// some random method content to show what has to be removed and what has to stay
List list = new ArrayList();
Object o = doThis();
return null;
}
public static Object giveSecondThing(){
List list = new LinkedList();
Object o = doThat();
return null;
}
private static Object doThis(){
Map<Integer, String> myMap = new HashMap<Integer, String>();
return null;
}
private static Object doThat(String ... param){
Set set;
return null;
}
}
This class (in sources project), that uses only part (in this case 1 method, which uses other method) of that jar's class:
package com.foo.bar;
import com.ext.jar.Utilities;
public class Runner {
public static void main(String[] args) {
Utilities.giveFirstThing();
}
}
The result is: class from jar is recreated in my project, as a normal compilable class, without methods and Imports, that I didn't need (so jar can be safety removed from project):
package com.ext.jar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Utilities {
public static Object giveFirstThing(){
// some random method content to show what has to be removed and what has to stay
List list = new ArrayList();
Object o = doThis();
return null;
}
private static Object doThis(){
Map<Integer, String> myMap = new HashMap<Integer, String>();
return null;
}
}
SUM UP:
2 (of 4 total) method where needed, so they are copied.
4 (of 6 total) imports where needed, so they are copied too.
rest of class is ATM useless, so everything else is not copied.
EDIT2: I've added bounty, as a sign that I wish to find solution to this problem, which I believe could be useful open-source project. :)