Hi,

inspired from an article in the german "eclipse magazin" (03/12) i started 
to play around a bit with an eclipse builder for checking our code with 
Jamopp. For experiencing with Jamopp i tried to discover whether a certain 
method ("C.m()" in the code below) is used in certain subclasses 
(subclasses of A or B in the code below).

The good thing first: it worked well for me.

The "not so good" thing: after saving a file, the jamopp builder takes 1 - 
45 seconds to process the current file (depending on LOC and dependencies 
/ subclassing etc.). I'm currently running my analysis on my laptop 
([email protected], 4GB RAM, Win7, Java6 32 bit). Doing a full build on the 
smallest of our projects takes ~ 10 minutes extra for the jamopp analysis 
(ignoring non java and all of our test files already).

Code#1: code for checking whether the current class is a certain subclass 
of A or B:
    CompilationUnit cu = (CompilationUnit) resource.getContents().get(0);  
 
    boolean foundClassForAnalysis = false;
    for (Iterator<ConcreteClassifier> it = 
cu.getClassifiers().get(0).getAllSuperClassifiers().iterator(); 
it.hasNext(); ){
        ConcreteClassifier cc = it.next();
        if ("A".equals(cc.getName()) || "B".equals(cc.getName())) {
            foundClassForAnalysis = true;
            break;
        } 
    }

Code#2: code for checking whether a certain method is used within this 
class ("C.m()"):
    if (foundClassForAnalysis) {
        for (Iterator<EObject> i = cu.eAllContents(); i.hasNext(); ) {
            EObject next = i.next();
            if (next instanceof MethodCall) {
                MethodCall methodCall = (MethodCall) next;
                Method method = (Method) methodCall.getTarget();
                if ("m".equals(method.getName())) {
                    ConcreteClassifier methodContainer = 
method.getContainingConcreteClassifier();
                    if ("C".equals(methodContainer.getName())) {
                        resource.addWarning("dont use method C.m in 
subclasses of A or B", JavaEProblemType.ANALYSIS_PROBLEM, next);
                    }

The performance problems are located in these statements (measured with 
timestamps before / after the mentioned calls in the eclipse error log):
a) Code#1: EList<ConcreteClassifier> allSuperClassifiers = 
cu.getClassifiers().get(0).getAllSuperClassifiers();
=> takes ~6 seconds on the mentioned class (with returning 3 super 
classifiers)

b) Code#2: Method method = (Method) methodCall.getTarget();
Iterating over cu.eAllContents() takes ~40 seconds (with returning 1850 
elements in cu.eAllContents(), thereof 63 methods). 
Calling methodCall.getTarget() takes up to 15 seconds for each of the 63 
methods.

So my question is whether anyone of you has a "better code" regarding 
performance for my scenario (maybe other method calls return the desired 
information in less time or similar) ? 

best regards,
Oliver Imlinger
_______________________________________________
emftext-users mailing list
[email protected]
http://mail-st.inf.tu-dresden.de/cgi-bin/mailman/listinfo/emftext-users

Reply via email to