<commit_before>package ibis.util;

import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;

import java.util.*;

public class BT_Analyzer { 
        boolean verbose;

	public JavaClass specialInterface;
	public JavaClass subject;

	public String classname;
	public String packagename;	     

	public Vector specialInterfaces;
	public Vector specialMethods;
	public Vector subjectSpecialMethods;

        public BT_Analyzer(JavaClass subject, JavaClass specialInterface, boolean verbose) { 
		this.subject          = subject;
		this.specialInterface = specialInterface;
		this.verbose          = verbose;
		
		if (verbose) { 
			System.out.println("BT_Analyzer looking for " + specialInterface.getClassName() + " in " + subject.getClassName());
		}
	}

	private boolean compareMethods(Method m1, Method m2) {
		return m1.getSignature().equals(m2.getSignature()) && m1.getName().equals(m2.getName());
	} 
       
	public boolean isSpecial(Method m1) {
                if (specialMethods == null) {
                        return false;
                }

                for (int i=0;i<specialMethods.size();i++) { 
			Method m2 = (Method) specialMethods.get(i);
                        if (compareMethods(m1, m2)) {
                                return true;
                        }
                }

                return false;
	}
	
	private void addSpecialMethod(Vector specialMethods, Method m) { 
		for (int i=0;i<specialMethods.size();i++) { 
			if (compareMethods(m, (Method) specialMethods.get(i))) { 
				// it is already in the vector
				return;
			}
		}

		specialMethods.addElement(m);
	} 

	private void findSpecialMethods(JavaClass specialInterface, Vector specialMethods) { 
		Method[] methods = specialInterface.getMethods();

		for (int i=0;i<methods.length;i++) { 
		    if (! methods[i].getName().equals("<clinit>")) {
			addSpecialMethod(specialMethods, methods[i]);
		    }
		}		
	}

	Vector findSpecialMethods(Vector specialInterfaces) { 
		Vector specialMethods = new Vector();

		for (int i=0;i<specialInterfaces.size();i++) { 
			findSpecialMethods((JavaClass) specialInterfaces.get(i), specialMethods);
		} 
		
		return specialMethods;
	} 

	private void findSubjectSpecialMethod(Method[] subject, Method special, Vector dest) {

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

			Method temp = subject[i];

			if (compareMethods(special, temp)) { 
//				System.out.println(temp.fullName() + " equals " + special.fullName());
				dest.add(temp);
			}
		} 
	}
 
	Vector findSubjectSpecialMethods() { 
		Vector temp = new Vector();
		Method v[] = subject.getMethods();

		for (int i=0;i<specialMethods.size();i++) { 
			findSubjectSpecialMethod(v, (Method) specialMethods.get(i), temp);
		} 
		
		return temp;
	} 


	boolean findSpecialInterfaces(String inter, Vector specialInterfaces) {
		boolean result = false;
		JavaClass interf = Repository.lookupClass(inter);

		if (inter.equals(specialInterface.getClassName())) {
			result = true;
		} else {
			String[] interfaces = interf.getInterfaceNames();
			
			for (int i=0;i<interfaces.length;i++) { 
				result |= findSpecialInterfaces(interfaces[i], specialInterfaces);
			}
		} 

		if (result) { 
			if (!specialInterfaces.contains(inter)) { 
				specialInterfaces.addElement(interf);
			}
		} 

		return result;
	}

	Vector findSpecialInterfaces() { 
		Vector specialInterfaces = new Vector();

		String[] interfaces = subject.getInterfaceNames();
		
		for (int i=0;i<interfaces.length;i++) { 
			if (verbose) {
			    System.out.println(subject.getClassName() + " implements " + interfaces[i]);
			}
			findSpecialInterfaces(interfaces[i], specialInterfaces);
		}

		return specialInterfaces;
	}

	public void start() {

		String temp = subject.getClassName();
		packagename = subject.getPackageName();
		classname = temp.substring(temp.lastIndexOf('.')+1);

		specialInterfaces = findSpecialInterfaces();<commit_msg>Moved Analyzer to ibis/classfile<commit_after>package ibis.util;

import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;

import java.util.*;

public class BT_Analyzer { 
        boolean verbose;

	public JavaClass specialInterface;
	public JavaClass subject;

	public String classname;
	public String packagename;	     

	public Vector specialInterfaces;
	public Vector specialMethods;
	public Vector subjectSpecialMethods;

        public BT_Analyzer(JavaClass subject, JavaClass specialInterface, boolean verbose) { 
		this.subject          = subject;
		this.specialInterface = specialInterface;
		this.verbose          = verbose;
		
		if (verbose) { 
			System.out.println("BT_Analyzer looking for " + specialInterface.getClassName() + " in " + subject.getClassName());
		}
	}

	private boolean compareMethods(Method m1, Method m2) {
		return m1.getSignature().equals(m2.getSignature()) && m1.getName().equals(m2.getName());
	} 
       
	public boolean isSpecial(Method m1) {
                if (specialMethods == null) {
                        return false;
                }

                for (int i=0;i<specialMethods.size();i++) { 
			Method m2 = (Method) specialMethods.get(i);
                        if (compareMethods(m1, m2)) {
                                return true;
                        }
                }

                return false;
	}
	
	private void addSpecialMethod(Vector specialMethods, Method m) { 
		for (int i=0;i<specialMethods.size();i++) { 
			if (compareMethods(m, (Method) specialMethods.get(i))) { 
				// it is already in the vector
				return;
			}
		}

		specialMethods.addElement(m);
	} 

	private void findSpecialMethods(JavaClass specialInterface, Vector specialMethods) { 
		Method[] methods = specialInterface.getMethods();

		for (int i=0;i<methods.length;i++) { 
		    if (! methods[i].getName().equals("<clinit>")) {
			addSpecialMethod(specialMethods, methods[i]);
		    }
		}		
	}

	Vector findSpecialMethods(Vector specialInterfaces) { 
		Vector specialMethods = new Vector();

		for (int i=0;i<specialInterfaces.size();i++) { 
			findSpecialMethods((JavaClass) specialInterfaces.get(i), specialMethods);
		} 
		
		return specialMethods;
	} 

	private void findSubjectSpecialMethod(Method[] subject, Method special, Vector dest) {

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

			Method temp = subject[i];

			if (compareMethods(special, temp)) { 
//				System.out.println(temp.fullName() + " equals " + special.fullName());
				dest.add(temp);
			}
		} 
	}
 
	Vector findSubjectSpecialMethods() { 
		Vector temp = new Vector();
		Method v[] = subject.getMethods();

		for (int i=0;i<specialMethods.size();i++) { 
			findSubjectSpecialMethod(v, (Method) specialMethods.get(i), temp);
		} 
		
		return temp;
	} 


	boolean findSpecialInterfaces(String inter, Vector specialInterfaces) {
		boolean result = false;
		JavaClass interf = Repository.lookupClass(inter);

		if (inter.equals(specialInterface.getClassName())) {
			result = true;
		} else {
			String[] interfaces = interf.getInterfaceNames();
			
			for (int i=0;i<interfaces.length;i++) { 
				result |= findSpecialInterfaces(interfaces[i], specialInterfaces);
			}
		} 

		if (result) { 
			if (!specialInterfaces.contains(inter)) { 
				specialInterfaces.addElement(interf);
			}
		} 

		return result;
	}

	Vector findSpecialInterfaces() { 
		Vector specialInterfaces = new Vector();

		if (! subject.isClass()) {
		    findSpecialInterfaces(subject.getClassName(), specialInterfaces);
		}
		else {
		    String[] interfaces = subject.getInterfaceNames();
		
		    for (int i=0;i<interfaces.length;i++) { 
			    if (verbose) {
				System.out.println(subject.getClassName() + " implements " + interfaces[i]);
			    }
			    findSpecialInterfaces(interfaces[i], specialInterfaces);
		    }
		}

		return specialInterfaces;
	}

	public void start() {

		String temp = subject.getClassName();
		packagename = subject.getPackageName();
		classname = temp.substring(temp.lastIndexOf('.')+1);

		specialInterfaces = findSpecialInterfaces();
{'fraction_non_alphanumeric': 0.12450199203187251, 'fraction_numerical': 0.0047310756972111555, 'mean_word_length': 3.196969696969697, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5425397', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2350, 'n_words': 497}