<commit_before>/*******************************************************************************
 * Copyright (c) 2014 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     <NAME> - initial API and implementation
 ******************************************************************************/
package cuchaz.enigma.analysis;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtField;
import javassist.bytecode.Descriptor;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;

import cuchaz.enigma.mapping.ArgumentEntry;
import cuchaz.enigma.mapping.BehaviorEntry;
import cuchaz.enigma.mapping.ClassEntry;
import cuchaz.enigma.mapping.Entry;
import cuchaz.enigma.mapping.EntryFactory;
import cuchaz.enigma.mapping.FieldEntry;
import cuchaz.enigma.mapping.Translator;

public class TranslationIndex implements Serializable {
	
	private static final long serialVersionUID = 738687982126844179L;
	
	private Map<ClassEntry,ClassEntry> m_superclasses;
	private Multimap<ClassEntry,FieldEntry> m_fieldEntries;
	private Multimap<ClassEntry,BehaviorEntry> m_behaviorEntries;
	private Multimap<ClassEntry,ClassEntry> m_interfaces;
	
	public TranslationIndex() {
		m_superclasses = Maps.newHashMap();
		m_fieldEntries = HashMultimap.create();
		m_behaviorEntries = HashMultimap.create();
		m_interfaces = HashMultimap.create();
	}
	
	public TranslationIndex(TranslationIndex other, Translator translator) {
		
		// translate the superclasses
		m_superclasses = Maps.newHashMap();
		for (Map.Entry<ClassEntry,ClassEntry> mapEntry : other.m_superclasses.entrySet()) {
			m_superclasses.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
		
		// translate the interfaces
		m_interfaces = HashMultimap.create();
		for (Map.Entry<ClassEntry,ClassEntry> mapEntry : other.m_interfaces.entries()) {
			m_interfaces.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
		
		// translate the fields
		m_fieldEntries = HashMultimap.create();
		for (Map.Entry<ClassEntry,FieldEntry> mapEntry : other.m_fieldEntries.entries()) {
			m_fieldEntries.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
		
		m_behaviorEntries = HashMultimap.create();
		for (Map.Entry<ClassEntry,BehaviorEntry> mapEntry : other.m_behaviorEntries.entries()) {
			m_behaviorEntries.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
	}
	
	public void indexClass(CtClass c) {
		indexClass(c, true);
	}
	
	public void indexClass(CtClass c, boolean indexMembers) {
		
		ClassEntry classEntry = EntryFactory.getClassEntry(c);
		if (isJre(classEntry)) {
			return;
		}
		
		// add the superclass
		ClassEntry superclassEntry = EntryFactory.getSuperclassEntry(c);
		if (superclassEntry != null && !isJre(superclassEntry)) {
			m_superclasses.put(classEntry, superclassEntry);
		}<commit_msg>save more translation information for m3l<commit_after>/*******************************************************************************
 * Copyright (c) 2014 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     <NAME> - initial API and implementation
 ******************************************************************************/
package cuchaz.enigma.analysis;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtField;
import javassist.bytecode.Descriptor;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;

import cuchaz.enigma.mapping.ArgumentEntry;
import cuchaz.enigma.mapping.BehaviorEntry;
import cuchaz.enigma.mapping.ClassEntry;
import cuchaz.enigma.mapping.Entry;
import cuchaz.enigma.mapping.EntryFactory;
import cuchaz.enigma.mapping.FieldEntry;
import cuchaz.enigma.mapping.Translator;

public class TranslationIndex implements Serializable {
	
	private static final long serialVersionUID = 738687982126844179L;
	
	private Map<ClassEntry,ClassEntry> m_superclasses;
	private Multimap<ClassEntry,FieldEntry> m_fieldEntries;
	private Multimap<ClassEntry,BehaviorEntry> m_behaviorEntries;
	private Multimap<ClassEntry,ClassEntry> m_interfaces;
	
	public TranslationIndex() {
		m_superclasses = Maps.newHashMap();
		m_fieldEntries = HashMultimap.create();
		m_behaviorEntries = HashMultimap.create();
		m_interfaces = HashMultimap.create();
	}
	
	public TranslationIndex(TranslationIndex other, Translator translator) {
		
		// translate the superclasses
		m_superclasses = Maps.newHashMap();
		for (Map.Entry<ClassEntry,ClassEntry> mapEntry : other.m_superclasses.entrySet()) {
			m_superclasses.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
		
		// translate the interfaces
		m_interfaces = HashMultimap.create();
		for (Map.Entry<ClassEntry,ClassEntry> mapEntry : other.m_interfaces.entries()) {
			m_interfaces.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
		
		// translate the fields
		m_fieldEntries = HashMultimap.create();
		for (Map.Entry<ClassEntry,FieldEntry> mapEntry : other.m_fieldEntries.entries()) {
			m_fieldEntries.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
		
		m_behaviorEntries = HashMultimap.create();
		for (Map.Entry<ClassEntry,BehaviorEntry> mapEntry : other.m_behaviorEntries.entries()) {
			m_behaviorEntries.put(
				translator.translateEntry(mapEntry.getKey()),
				translator.translateEntry(mapEntry.getValue())
			);
		}
	}
	
	public void indexClass(CtClass c) {
		indexClass(c, true);
	}
	
	public void indexClass(CtClass c, boolean indexMembers) {
		
		ClassEntry classEntry = EntryFactory.getClassEntry(c);
		if (isJre(classEntry)) {
			return;
		}
		
		// add the superclass
		ClassEntry superclassEntry = EntryFactory.getSuperclassEntry(c);
		if (superclassEntry != null) {
			m_superclasses.put(classEntry, superclassEntry);
		}
{'fraction_non_alphanumeric': 0.1416722408026756, 'fraction_numerical': 0.006555183946488294, 'mean_word_length': 5.433734939759036, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3826472', 'n_tokens_mistral': 2469, 'n_tokens_neox': 2189, 'n_words': 428}