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 .....

Re: How calculate CBO coupling between objects in java 80 80

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.

Re: How calculate CBO coupling between objects in java 80 80

Ok..I will write my code ..

Re: How calculate CBO coupling between objects in java 80 80
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();


 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++)


 /** 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();




for(Field field:javaClass.getFields())




    for(Method method:javaClass.getMethods())


Re: How calculate CBO coupling between objects in java 80 80

Why does this look so much like http://stackoverflow.com/questions/34733653/how-calculate-cbo-coupling-between-objects-in-java

Anyhow, there were prior answers that tracked some source code for you to get this code metric. I don't write my own code analyzers since there are so many nice ones today. But I do tend to use open source when I want to see what happens underneath.

Be a part of the DaniWeb community

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