<commit_before>package org.osgi.tools.xmldoclet;

import java.io.*;
import java.util.*;

import com.sun.javadoc.*;

public class XmlDoclet extends Doclet {
	PrintWriter pw;
	String currentPackage;

	public static boolean start(RootDoc doc) {
		try {
			XmlDoclet doclet = new XmlDoclet();
			doclet.startx(doc);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public void startx(RootDoc doc) throws Exception {
		FileOutputStream out = new FileOutputStream("javadoc.xml");
		pw = new PrintWriter(new OutputStreamWriter(out, "utf-8"));

		pw.println("<?xml version='1.0' encoding='utf-8'?>");
		pw.println("<top>");

		PackageDoc packages[] = doc.specifiedPackages();
		for (int p = 0; packages != null && p < packages.length; p++)
			print(packages[p]);

		pw.println("</top>");
		pw.close();
		out.close();
	}

	void print(PackageDoc pack) {
		currentPackage = pack.name();
		pw.println("  <package name='" + pack.name() + "' fqn='" + pack.name()
				+ "' qn='" + pack.name() + "'>");
		printComment(pack);
		ClassDoc all[] = pack.allClasses();
		Hashtable ht = new Hashtable();
		for (int i = 0; i < all.length; i++) {
			ClassDoc c = all[i];
			PackageDoc imports[] = c.importedPackages();
			for (int j = 0; j < imports.length; j++) {
				PackageDoc p = imports[j];
				if (!p.name().equals("java.lang") && ht.get(p) == null) {
					Tag version[] = p.tags("@version");
					String v = toString(version).trim();
					ht.put(p.name(), v);
				}
			}
		}
		for (Enumeration e = ht.keys(); e.hasMoreElements();) {
			String key = (String) e.nextElement();
			String version = (String) ht.get(key);
			pw.println("<import name='" + key
					+ (version.length() == 0 ? "" : "' version='" + version)
					+ "'/>");
		}
		ClassDoc classes[] = pack.allClasses();
		for (int c = 0; classes != null && c < classes.length; c++)
			print(classes[c]);
		pw.println("  </package>");
	}

	void print(ClassDoc clazz) {
		String name = simplify(clazz.name());
		String superclass = null;

		// interface do not have a superclass and cannot implement
		// other interfaces. So an interface can have at most 1 implements
		// record, which should be interpreted as the
		if (clazz.superclass() != null)
			superclass = clazz.superclass().name();

		if (clazz.isInterface() && clazz.interfaces().length > 0) {
			superclass = clazz.interfaces()[0].name();
		}

		pw.println("  <class name='" + name + "' fqn='" + clazz.qualifiedName()
				+ "' qn='" + clazz.name() + "' package='"
				+ clazz.containingPackage().name() + "' modifiers='"
				+ clazz.modifiers() + (clazz.isClass() ? " class" : "")
				+ (superclass != null ? "' superclass='" + superclass : "")
				+ (clazz.isInterface() ? "' interface='yes" : "") + "'>");
		printComment(clazz);

		if (!clazz.isInterface()) {
			ClassDoc ptr = clazz;
			Hashtable ht = new Hashtable();
			while (ptr != null) {
				ClassDoc interfaces[] = ptr.interfaces();
				for (int i = 0; i < interfaces.length; i++) {
					if (ht.get(interfaces[i]) == null) {
						pw.println("<implements name='" + interfaces[i].name()
								+ "' fqn='" + interfaces[i].qualifiedName()
								+ "' qn='" + interfaces[i].name()
								+ "' package='"
								+ interfaces[i].containingPackage().name()
								+ "' local='" + (ptr = clazz) + "'/>");
						ht.put(interfaces[i], "");
					}
				}
				ptr = null; // ptr.superclass();
			}
		}
		ConstructorDoc constructors[] = clazz.constructors();
		for (int cnst = 0; cnst < constructors.length; cnst++)
			print(constructors[cnst]);

		FieldDoc fields[] = clazz.fields();
		for (int f = 0; f < fields.length; f++)
			print(fields[f]);

		MethodDoc methods[] = clazz.methods();
		for (int m = 0; m < methods.length; m++)
			print(methods[m]);

		pw.println("  </class>");
	}

	void print(ConstructorDoc cnst) {
		pw.println("    <method name='" + cnst.name() + "' fqn='"
				+ cnst.qualifiedName() + "' qn='"
				+ cnst.containingClass().name() + "." + cnst.name()
				+ flatten(cnst.signature()) + "' package='"
				+ cnst.containingPackage().name() + "' modifiers='"
				+ cnst.modifiers() + "' signature='" + cnst.signature()
				+ "' flatSignature='" + flatten(cnst.signature())
				+ "' isConstructor='true'>");
		printMember(cnst);
		pw.println("     </method>");
	}

	void print(MethodDoc cnst) {
		pw.println("    <method name='" + cnst.name() + "' fqn='"
				+ cnst.qualifiedName() + "' qn='"
				+ cnst.containingClass().name() + "." + cnst.name()
				+ flatten(cnst.signature()) + "' package='"
				+ cnst.containingPackage().name() + "' modifiers='"
				+ cnst.modifiers() + "' typeName='"
				+ cnst.returnType().typeName() + "' qualifiedTypeName='"
				+ cnst.returnType().qualifiedTypeName() + "' dimension='"
				+ cnst.returnType().dimension() + "' signature='"
				+ cnst.signature() + "' flatSignature='"
				+ flatten(cnst.signature()) + "'>");
		printMember(cnst);
		pw.println("     </method>");
	}

	void print(FieldDoc cnst) {
		String constantValueExpression = null;
		try {
			constantValueExpression = cnst.constantValueExpression();
		} catch (Error e) {
			// Is Java 1.4, so we accept a failure
		}

		pw.println("    <field name='"
				+ cnst.name()
				+ "' fqn='"
				+ cnst.qualifiedName()
				+ "' qn='"
				+ cnst.containingClass().name()
				+ "."
				+ cnst.name()
				+ "' package='"
				+ cnst.containingPackage().name()
				+ "' modifiers='"
				+ cnst.modifiers()
				+ "' typeName='"
				+ cnst.type().typeName()
				+ "' qualifiedTypeName='"
				+ cnst.type().qualifiedTypeName()
				+ (constantValueExpression != null ? "' constantValue='"
						+ escape(constantValueExpression) : "") + "'>");
		printComment(cnst);
		pw.println("     </field>");
	}

	void printMember(ExecutableMemberDoc x) {
		printComment(x);
		Parameter parameters[] = x.parameters();
		for (int i = 0; i < parameters.length; i++) {
			print(parameters[i]);
		}
		ClassDoc exceptions[] = x.thrownExceptions();
		for (int i = 0; i < exceptions.length; i++) {
			pw.println("<exception name='" + exceptions[i].name() + "' fqn='"
					+ exceptions[i].qualifiedName() + "'/>");
		}
	}

	void print(Parameter param) {
		pw.println("<parameter name='" + param.name() + "' dimension='"
				+ param.type().dimension() + "' typeName='"
				+ param.type().typeName() + "' fqn='"
				+ param.type().qualifiedTypeName() + "'/>");
	}

	void printThrows(StringBuffer sb, ThrowsTag tag) {
		sb.append("   <throws name='"
				+ simplify(tag.exceptionName())
				+ (tag.exception() != null ? "' exception='"
						+ tag.exception().qualifiedName() : "") + "'>");
		sb.append(html(toString(tag.inlineTags())));
		sb.append("   </throws>");
	}

	void printParam(StringBuffer sb, ParamTag tag) {
		sb.append("   <param name='" + tag.parameterName() + "'>");<commit_msg>Java 5 inserts <any> for some types and you can't store that unescaped in XML ..<commit_after>package org.osgi.tools.xmldoclet;

import java.io.*;
import java.util.*;

import com.sun.javadoc.*;

public class XmlDoclet extends Doclet {
	PrintWriter pw;
	String currentPackage;

	public static boolean start(RootDoc doc) {
		try {
			XmlDoclet doclet = new XmlDoclet();
			doclet.startx(doc);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public void startx(RootDoc doc) throws Exception {
		FileOutputStream out = new FileOutputStream("javadoc.xml");
		pw = new PrintWriter(new OutputStreamWriter(out, "utf-8"));

		pw.println("<?xml version='1.0' encoding='utf-8'?>");
		pw.println("<top>");

		PackageDoc packages[] = doc.specifiedPackages();
		for (int p = 0; packages != null && p < packages.length; p++)
			print(packages[p]);

		pw.println("</top>");
		pw.close();
		out.close();
	}

	void print(PackageDoc pack) {
		currentPackage = pack.name();
		pw.println("  <package name='" + pack.name() + "' fqn='" + pack.name()
				+ "' qn='" + pack.name() + "'>");
		printComment(pack);
		ClassDoc all[] = pack.allClasses();
		Hashtable ht = new Hashtable();
		for (int i = 0; i < all.length; i++) {
			ClassDoc c = all[i];
			PackageDoc imports[] = c.importedPackages();
			for (int j = 0; j < imports.length; j++) {
				PackageDoc p = imports[j];
				if (!p.name().equals("java.lang") && ht.get(p) == null) {
					Tag version[] = p.tags("@version");
					String v = toString(version).trim();
					ht.put(p.name(), v);
				}
			}
		}
		for (Enumeration e = ht.keys(); e.hasMoreElements();) {
			String key = (String) e.nextElement();
			String version = (String) ht.get(key);
			pw.println("<import name='" + key
					+ (version.length() == 0 ? "" : "' version='" + version)
					+ "'/>");
		}
		ClassDoc classes[] = pack.allClasses();
		for (int c = 0; classes != null && c < classes.length; c++)
			print(classes[c]);
		pw.println("  </package>");
	}

	void print(ClassDoc clazz) {
		String name = simplify(clazz.name());
		String superclass = null;

		// interface do not have a superclass and cannot implement
		// other interfaces. So an interface can have at most 1 implements
		// record, which should be interpreted as the
		if (clazz.superclass() != null)
			superclass = clazz.superclass().name();

		if (clazz.isInterface() && clazz.interfaces().length > 0) {
			superclass = clazz.interfaces()[0].name();
		}

		pw.println("  <class name='" + name + "' fqn='" + clazz.qualifiedName()
				+ "' qn='" + clazz.name() + "' package='"
				+ clazz.containingPackage().name() + "' modifiers='"
				+ clazz.modifiers() + (clazz.isClass() ? " class" : "")
				+ (superclass != null ? "' superclass='" + superclass : "")
				+ (clazz.isInterface() ? "' interface='yes" : "") + "'>");
		printComment(clazz);

		if (!clazz.isInterface()) {
			ClassDoc ptr = clazz;
			Hashtable ht = new Hashtable();
			while (ptr != null) {
				ClassDoc interfaces[] = ptr.interfaces();
				for (int i = 0; i < interfaces.length; i++) {
					if (ht.get(interfaces[i]) == null) {
						pw.println("<implements name='" + interfaces[i].name()
								+ "' fqn='" + interfaces[i].qualifiedName()
								+ "' qn='" + interfaces[i].name()
								+ "' package='"
								+ interfaces[i].containingPackage().name()
								+ "' local='" + (ptr = clazz) + "'/>");
						ht.put(interfaces[i], "");
					}
				}
				ptr = null; // ptr.superclass();
			}
		}
		ConstructorDoc constructors[] = clazz.constructors();
		for (int cnst = 0; cnst < constructors.length; cnst++)
			print(constructors[cnst]);

		FieldDoc fields[] = clazz.fields();
		for (int f = 0; f < fields.length; f++)
			print(fields[f]);

		MethodDoc methods[] = clazz.methods();
		for (int m = 0; m < methods.length; m++)
			print(methods[m]);

		pw.println("  </class>");
	}

	void print(ConstructorDoc cnst) {
		pw.println("    <method name='" + cnst.name() + "' fqn='"
				+ escape(cnst.qualifiedName()) + "' qn='"
				+ cnst.containingClass().name() + "." + cnst.name()
				+ escape(flatten(cnst.signature())) + "' package='"
				+ cnst.containingPackage().name() + "' modifiers='"
				+ cnst.modifiers() + "' signature='" + escape(cnst.signature())
				+ "' flatSignature='" + escape(flatten(cnst.signature()))
				+ "' isConstructor='true'>");
		printMember(cnst);
		pw.println("     </method>");
	}

	void print(MethodDoc cnst) {
		pw.println("    <method name='" + cnst.name() + "' fqn='"
				+ cnst.qualifiedName() + "' qn='"
				+ cnst.containingClass().name() + "." + cnst.name()
				+ escape(flatten(cnst.signature())) + "' package='"
				+ cnst.containingPackage().name() + "' modifiers='"
				+ cnst.modifiers() + "' typeName='"
				+ escape(cnst.returnType().typeName()) + "' qualifiedTypeName='"
				+ escape(cnst.returnType().qualifiedTypeName()) + "' dimension='"
				+ cnst.returnType().dimension() + "' signature='"
				+ escape(cnst.signature()) + "' flatSignature='"
				+ escape(flatten(cnst.signature())) + "'>");
		printMember(cnst);
		pw.println("     </method>");
	}

	void print(FieldDoc cnst) {
		String constantValueExpression = null;
		try {
			constantValueExpression = cnst.constantValueExpression();
		} catch (Error e) {
			// Is Java 1.4, so we accept a failure
		}

		pw.println("    <field name='"
				+ cnst.name()
				+ "' fqn='"
				+ cnst.qualifiedName()
				+ "' qn='"
				+ cnst.containingClass().name()
				+ "."
				+ cnst.name()
				+ "' package='"
				+ cnst.containingPackage().name()
				+ "' modifiers='"
				+ cnst.modifiers()
				+ "' typeName='"
				+ escape(cnst.type().typeName())
				+ "' qualifiedTypeName='"
				+ escape(cnst.type().qualifiedTypeName())
				+ (constantValueExpression != null ? "' constantValue='"
						+ escape(constantValueExpression) : "") + "'>");
		printComment(cnst);
		pw.println("     </field>");
	}

	void printMember(ExecutableMemberDoc x) {
		printComment(x);
		Parameter parameters[] = x.parameters();
		for (int i = 0; i < parameters.length; i++) {
			print(parameters[i]);
		}
		ClassDoc exceptions[] = x.thrownExceptions();
		for (int i = 0; i < exceptions.length; i++) {
			pw.println("<exception name='" + exceptions[i].name() + "' fqn='"
					+ exceptions[i].qualifiedName() + "'/>");
		}
	}

	void print(Parameter param) {
		pw.println("<parameter name='" + param.name() + "' dimension='"
				+ param.type().dimension() + "' typeName='"
				+ escape(param.type().typeName()) + "' fqn='"
				+ escape(param.type().qualifiedTypeName()) + "'/>");
	}

	void printThrows(StringBuffer sb, ThrowsTag tag) {
		sb.append("   <throws name='"
				+ simplify(tag.exceptionName())
				+ (tag.exception() != null ? "' exception='"
						+ tag.exception().qualifiedName() : "") + "'>");
		sb.append(html(toString(tag.inlineTags())));
		sb.append("   </throws>");
	}

	void printParam(StringBuffer sb, ParamTag tag) {
		sb.append("   <param name='" + tag.parameterName() + "'>");
{'fraction_non_alphanumeric': 0.206647714848021, 'fraction_numerical': 0.00298855601720242, 'mean_word_length': 3.3555555555555556, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 2, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4737762', 'n_tokens_mistral': 5558, 'n_tokens_neox': 4673, 'n_words': 961}