<commit_before>package org.gemoc.commons.eclipse.core.resources;

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

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;

public class FileFinderVisitor implements IResourceVisitor {

	public FileFinderVisitor(String fileExtension) 
	{
		_fileExtension = fileExtension;
	}
	
	private String _fileExtension;
	
	protected List<IFile> _files = new ArrayList<IFile>();
	
	/**
	 * @return the first file found, or null if not file found
	 */
	public IFile getFile() {
		if(_files.isEmpty()) return null;
		return _files.get(0);
	}
	/** 
	 * 
	 * @return a list of the files found
	 */
	public List<IFile> getFiles() {
		return _files;
	}

	@Override
	public boolean visit(IResource resource) throws CoreException {
		boolean mustVisitChild = true;
		if(resource instanceof IFile){
			if(resource.getFileExtension().equals(_fileExtension)){
				_files.add((IFile) resource);
			}
			mustVisitChild = false;
		}
		return mustVisitChild;
	}

}<commit_msg>fixed problem of the file finder in case of file with empty extension (the browse button in gemoc was failing in case of projects containing such file in the workspace)<commit_after>package org.gemoc.commons.eclipse.core.resources;

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

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;

public class FileFinderVisitor implements IResourceVisitor {

	/**
	 * Searched file extension
	 * @param fileExtension, must not be null, however it can be the empty string
	 */
	public FileFinderVisitor(String fileExtension) 
	{
		_fileExtension = fileExtension;
	}
	
	private String _fileExtension;
	
	protected List<IFile> _files = new ArrayList<IFile>();
	
	/**
	 * @return the first file found, or null if not file found
	 */
	public IFile getFile() {
		if(_files.isEmpty()) return null;
		return _files.get(0);
	}
	/** 
	 * 
	 * @return a list of the files found
	 */
	public List<IFile> getFiles() {
		return _files;
	}

	@Override
	public boolean visit(IResource resource) throws CoreException {
		boolean mustVisitChild = true;
		if(resource instanceof IFile){
			String resourceExtension = resource.getFileExtension();
			if(resourceExtension == null){
				resourceExtension = "";
			}
			if(resourceExtension.equals(_fileExtension)){
				_files.add((IFile) resource);
			}
			mustVisitChild = false;
		}
		return mustVisitChild;
	}

}
{'fraction_non_alphanumeric': 0.09901738473167045, 'fraction_numerical': 0.0007558578987150416, 'mean_word_length': 4.325955734406438, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5147881', 'n_tokens_mistral': 851, 'n_tokens_neox': 765, 'n_words': 217}