<commit_before>package sds.decompile;

import sds.assemble.BaseContent;
import sds.assemble.ClassContent;

/**
 * This class is for decompiling contents of class.
 * @author inagaki
 */
public class ClassDecompiler extends AbstractDecompiler {
	/**
	 * constructor.
	 * @param result decompiled source
	 */
	public ClassDecompiler(DecompiledResult result) {
		super(result);
	}

	@Override
	public void decompile(BaseContent content) {
		ClassContent cc = (ClassContent)content;
		addAnnotation(cc.getAnnotation());
		addDeclaration(cc);
		result.changeIndent(DecompiledResult.INCREMENT);

		FieldDecompiler fieldDecom = new FieldDecompiler(result);
		fieldDecom.decompile(cc.getFields());

		MethodDecompiler methodDecom = new MethodDecompiler(fieldDecom.getResult());
		methodDecom.decompile(cc.getMethods());

		// end
		result.writeEndScope();
	}

	@Override
	void addDeclaration(BaseContent content) {
		ClassContent cc = (ClassContent)content;
		StringBuilder classDeclaration = new StringBuilder();
		classDeclaration.append(cc.getAccessFlag()).append(cc.getThisClass())
						.append(" extends ").append(cc.getSuperClass());
		if(cc.getInterfaces().length > 0) {
			classDeclaration.append(" implements ");
			String[] interfaces = cc.getInterfaces();
			for(int i = 0; i < interfaces.length - 1; i++) {
				classDeclaration.append(interfaces[i]).append(", ");
			}
			classDeclaration.append(interfaces[interfaces.length - 1]);
		}
		classDeclaration.append(" {");
		result.write(classDeclaration.toString());
	}
}<commit_msg>add generics types.<commit_after>package sds.decompile;

import java.util.Map;
import sds.assemble.BaseContent;
import sds.assemble.ClassContent;

/**
 * This class is for decompiling contents of class.
 * @author inagaki
 */
public class ClassDecompiler extends AbstractDecompiler {
	/**
	 * constructor.
	 * @param result decompiled source
	 */
	public ClassDecompiler(DecompiledResult result) {
		super(result);
	}

	@Override
	public void decompile(BaseContent content) {
		ClassContent cc = (ClassContent)content;
		addAnnotation(cc.getAnnotation());
		addDeclaration(cc);
		result.changeIndent(DecompiledResult.INCREMENT);

		FieldDecompiler fieldDecom = new FieldDecompiler(result);
		fieldDecom.decompile(cc.getFields());

		MethodDecompiler methodDecom = new MethodDecompiler(fieldDecom.getResult(), cc.getThisClass());
		methodDecom.decompile(cc.getMethods());

		// end
		result.writeEndScope();
	}

	@Override
	void addDeclaration(BaseContent content) {
		ClassContent cc = (ClassContent)content;
		StringBuilder classDeclaration = new StringBuilder();
		classDeclaration.append(cc.getAccessFlag()).append(cc.getThisClass());

		// generics
		if(cc.getGenericsMap().size() > 0) {
			classDeclaration.append("<");
			StringBuilder generics = new StringBuilder();
			for(Map.Entry<String, String> e : cc.getGenericsMap().entrySet()) {
				generics.append(e.getKey()).append(" extends ").append(e.getValue()).append(",");
			}
			classDeclaration.append(generics.toString().substring(0, generics.length()-1 ));
			classDeclaration.append(">");
		}

		// extends classes
		classDeclaration.append(" extends ").append(cc.getSuperClass());

		// implements interfaces
		if(cc.getInterfaces().length > 0) {
			classDeclaration.append(" implements ");
			String[] interfaces = cc.getInterfaces();
			for(int i = 0; i < interfaces.length - 1; i++) {
				classDeclaration.append(interfaces[i]).append(", ");
			}
			classDeclaration.append(interfaces[interfaces.length - 1]);
		}

		classDeclaration.append(" {");
		result.write(classDeclaration.toString());
	}
}
{'fraction_non_alphanumeric': 0.13666666666666666, 'fraction_numerical': 0.0030555555555555557, 'mean_word_length': 5.011686143572621, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '3219224', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1054, 'n_words': 201}