/*
 * Created on 2005-05-23
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2005
 */
package pl.zalewski.mikolaj.symbdev.errorparsers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

/**
 * The CDT ErrorParserManager treats the filenames case-sensitive
 * event under Windows (at least in version 2.1.1). This class
 * overwrites the findFileName to be case-insensitive.
 * 
 * @author mikolaj
 */
public class CaseInsensitiveErrorParserManager extends ErrorParserManager {

    public CaseInsensitiveErrorParserManager(IProject project,
            IPath workingDirectory, IMarkerGenerator markerGenerator,
            String[] parsersIDs) {
        super(project, workingDirectory, markerGenerator, parsersIDs);
        fProject=project;
		initFilesMap();
    }

	/**
	 * Called by the error parsers.
	 */
	public IFile findFileName(String fileName) {
		IPath path = new Path(fileName);
		return (IFile) fFilesInProjectLowerCase.get(path.lastSegment());
	}
	
	void initFilesMap() {
		fFilesInProjectLowerCase = new HashMap();

		List collectedFiles = new ArrayList();
		collectFiles(fProject, collectedFiles);

		for (int i = 0; i < collectedFiles.size(); i++) {
			IFile file = (IFile) collectedFiles.get(i);
			fFilesInProjectLowerCase.put(file.getName().toLowerCase(), file);
		}
	}	
	
	HashMap fFilesInProjectLowerCase;
	protected IProject fProject;
}
