
package com.togethersoft.modules.qa.metrics.ExmMt1;

import com.togethersoft.openapi.sci.*;
import com.togethersoft.openapi.sci.enum.*;

import com.togethersoft.modules.qa.api.*;
import com.togethersoft.modules.qa.utils.*;

public class ExmMt1 extends MetricsPluginImpl {

    // plugin entry point
    public boolean run(SciObject obj, MetricsResult result) {

        // we have no need to call AuditPluginImpl.process()
        // since we need only to enumerate class operations
        // and have no need of processing of their code
        // By the same reason, we can allow processing of byte codes
        // (see method canProcessByteCode below)

        // process only classes
        if( !(obj instanceof SciClass) )
            return true;

        SciClass cls = (SciClass)obj;

        int cnt = 0;

        // get class operations enumeration
        SciOperationEnumeration oprs = cls.operations();

        // go through all class operations
        while (oprs.hasMoreElements()) {
            SciOperation opr = oprs.nextSciOperation();
                cnt++;
        }
        result.setValue(cnt);
        return true;
    }

    // Plugin title - would be displayed in the plugins list
    public String getTitle ()
    {
        return "Metrics example: maximum number of operations within class";
    }

    // group name - used for grouping plugins
    public String getGroupName ()
    {
        return "Samples";
    }

    // don't aggregate results
    public String getDefaultAggregation() {
        return AGGR_NONE;
    }

    // allow processing of byte codes,
    // since we are only counting operations, we needn't examine source code -
    public boolean canProcessByteCode () {
        return true;
    }
}
