Hi, in this code how can I calculate coupling between objects CBO in java after parsing java file using registerCoupling method and retrieve any coupling between classes through argument, class name,type and so on .....

Recommended Answers

All 4 Replies

I see no code and this looks to be your fourth post about this. Try supplying code and more "specs." That is, there are code examiners on the web with source for you to dissect or just use the result.

Ok..I will write my code ..

package javaapplication12;

 import java.io.*;

import java.util.*;


import com.sun.org.apache.bcel.internal.classfile.ClassParser;
import com.sun.org.apache.bcel.internal.classfile.JavaClass;

import com.sun.org.apache.bcel.internal.classfile.*;

import com.sun.org.apache.bcel.internal.generic.*;

import com.sun.org.apache.bcel.internal.Repository;

import com.sun.org.apache.bcel.internal.Constants;

 import com.sun.org.apache.bcel.internal.util.*;

  import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;


 import com.sun.xml.internal.ws.org.objectweb.asm.MethodVisitor;

    import java.lang.reflect.Modifier;


public class  CyclomaticComplexity {



private static Object argsTypes;




  /** The class's constant pool. */



   private ConstantPoolGen cp;

 /** The class's fully qualified name. */


 private String myClassName;

 /** The container where metrics for all classes are stored. */




 HashSet<String> efferentCoupleclass = new HashSet<String>();
public void visitMethod(Method method) {

MethodGen mg = new MethodGen(method, javaclass.getClassName(),cp);


Type   result_type = mg.getReturnType();



 registerCoupling(mg.getReturnType());


 Type[] argTypes   = mg.getArgumentTypes();

 Type[] argTypes=mg.getArgumentTypes();


  LocalVariableTable localVariableTable = mg.getLocalVariableTable(cp);


  CodeExceptionGen[] exceptionHandlers = mg.getExceptionHandlers();


   for (int i = 0; i < argTypes.length; i++)


    registerCoupling(argTypes[i]);
    }

 /** Return a class name associated with a type. */
 static String className (Type t) {
String ts = t.toString();

if (t.getType() <= Constants.T_VOID) {
    return "java.PRIMITIVE";
} else if(t instanceof ArrayType) {
    ArrayType at = (ArrayType)t;
    return className(at.getBasicType());
} else {
    return t.toString();
}
}




public static void registerCoupling (Type type) {

}


public static void main(String[]ss) throws ClassFormatException, IOException     {
ClassParser parser= new ClassParser(Cycl.class.getResourceAsStream("/javaapplication12/Cycl.class"),"Cycl.class";

          JavaClass javaClass=parser.parse();



   System.out.print("*******Fields*********");

    System.out.print(Arrays.toString(javaClass.getFields()));

     System.out.print();  


for(Field field:javaClass.getFields())
  {

   efferentCoupleclass.add(field);

        registerCoupling(field.getType());


       }




    for(Method method:javaClass.getMethods())
     {

    registerCoupling(method.getReturnType());   

     } 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.