<commit_before>package de.peeeq.eclipsewurstplugin.builder;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;

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

import de.peeeq.eclipsewurstplugin.WurstConstants;
import de.peeeq.eclipsewurstplugin.editor.CompilationUnitChangeListener;
import de.peeeq.wurstscript.RunArgs;
import de.peeeq.wurstscript.WurstCompilerJassImpl;
import de.peeeq.wurstscript.WurstConfig;
import de.peeeq.wurstscript.ast.Ast;
import de.peeeq.wurstscript.ast.CompilationUnit;
import de.peeeq.wurstscript.ast.WurstModel;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.attributes.attr;
import de.peeeq.wurstscript.gui.WurstGui;
import de.peeeq.wurstscript.utils.Utils;

/**
 * keeps a version of the model which is always the most recent one 
 */
public class ModelManagerImpl implements ModelManager {

	private WurstModel model;
	private final WurstNature nature;
	private Multimap<String, CompilationUnitChangeListener> changeListeners = HashMultimap.create();
	private boolean needsFullBuild = true;
	private Set<String> dependencies = Sets.newHashSet();
	
	public ModelManagerImpl(WurstNature nature) {
		this.nature = nature;
	}
	
	@Override
	public void removeCompilationUnit(IResource resource) {
		if (model == null) {
			return;
		}
		ListIterator<CompilationUnit> it = model.listIterator();
		while (it.hasNext()) {
			CompilationUnit cu = it.next();
			if (cu.getFile().equals(resource.getName())) {
				it.remove();
				break;
			}
		}

	}

	@Override
	public boolean needsFullBuild() {
		return needsFullBuild;
	}

	@Override
	public void clean() {
		model = null;
		needsFullBuild = true;
	}
	
	@Override
	public void typeCheckModel(WurstGui gui) {
		System.out.println("#typechecking");
		if (needsFullBuild) {
			System.out.println("needs full build...");
		}
		if (gui.getErrorCount() > 0) {
			return;
		}
		model.clearAttributes();
		WurstCompilerJassImpl comp = new WurstCompilerJassImpl(gui, RunArgs.defaults());
		WurstConfig.get().setSetting("lib", Utils.join(dependencies, ";"));
		try {
			comp.addImportedLibs(model);		
			comp.checkProg(model);
		} catch (CompileError e) {
			attr.addError(e.getSource(), e.getMessage());
		}
		nature.clearMarkers();
		for (CompileError e : gui.getErrorList()) {
			System.out.println("typecheck error: " + e);
			WurstNature.addErrorMarker(getFile(e.getSource().getFile()), e);
		}
	}
	
	private IFile getFile(String file) {
		return nature.getProject().getFile(file);<commit_msg>Author fix<commit_after>package de.peeeq.eclipsewurstplugin.builder;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;

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

import de.peeeq.eclipsewurstplugin.WurstConstants;
import de.peeeq.eclipsewurstplugin.editor.CompilationUnitChangeListener;
import de.peeeq.wurstscript.RunArgs;
import de.peeeq.wurstscript.WurstCompilerJassImpl;
import de.peeeq.wurstscript.WurstConfig;
import de.peeeq.wurstscript.ast.Ast;
import de.peeeq.wurstscript.ast.CompilationUnit;
import de.peeeq.wurstscript.ast.WurstModel;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.attributes.attr;
import de.peeeq.wurstscript.gui.WurstGui;
import de.peeeq.wurstscript.utils.Utils;

/**
 * keeps a version of the model which is always the most recent one 
 */
public class ModelManagerImpl implements ModelManager {

	private WurstModel model;
	private final WurstNature nature;
	private Multimap<String, CompilationUnitChangeListener> changeListeners = HashMultimap.create();
	private boolean needsFullBuild = true;
	private Set<String> dependencies = Sets.newHashSet();
	
	public ModelManagerImpl(WurstNature nature) {
		this.nature = nature;
	}
	
	@Override
	public void removeCompilationUnit(IResource resource) {
		if (model == null) {
			return;
		}
		ListIterator<CompilationUnit> it = model.listIterator();
		while (it.hasNext()) {
			CompilationUnit cu = it.next();
			if (cu.getFile().equals(resource.getName())) {
				it.remove();
				break;
			}
		}

	}

	@Override
	public boolean needsFullBuild() {
		return needsFullBuild;
	}

	@Override
	public void clean() {
		model = null;
		needsFullBuild = true;
	}
	
	@Override
	public void typeCheckModel(WurstGui gui) {
		System.out.println("#typechecking");
		if (needsFullBuild) {
			System.out.println("needs full build...");
		}
		if (gui.getErrorCount() > 0) {
			return;
		}
		if (model == null) {
			return;
		}
		model.clearAttributes();
		WurstCompilerJassImpl comp = new WurstCompilerJassImpl(gui, RunArgs.defaults());
		WurstConfig.get().setSetting("lib", Utils.join(dependencies, ";"));
		try {
			comp.addImportedLibs(model);		
			comp.checkProg(model);
		} catch (CompileError e) {
			attr.addError(e.getSource(), e.getMessage());
		}
		nature.clearMarkers();
		for (CompileError e : gui.getErrorList()) {
			System.out.println("typecheck error: " + e);
			WurstNature.addErrorMarker(getFile(e.getSource().getFile()), e);
		}
	}
	
	private IFile getFile(String file) {
		return nature.getProject().getFile(file);
{'fraction_non_alphanumeric': 0.12169485958285432, 'fraction_numerical': 0.00032846115946789294, 'mean_word_length': 4.947265625, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '6349294', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2043, 'n_words': 378}