jtl-eclipse-master/ASPT.resource.aspt/src-gen/ASPT/resource/aspt/mopp/AsptTaskItemBuilder.java
/**
 * <copyright>
 * </copyright>
 *
 * 
 */
package ASPT.resource.aspt.mopp;

/**
 * The AsptTaskItemBuilder is used to find task items in text documents. The
 * current implementation uses the generated lexer and the TaskItemDetector to
 * detect task items. This class is called by the BuilderAdapter, which runs both
 * this builder and the default builder that is intended to be customized.
 */
public class AsptTaskItemBuilder {
	
	public void build(org.eclipse.core.resources.IFile resource, org.eclipse.emf.ecore.resource.ResourceSet resourceSet, org.eclipse.core.runtime.IProgressMonitor monitor) {
		monitor.setTaskName("Searching for task items");
		new ASPT.resource.aspt.mopp.AsptMarkerHelper().removeAllMarkers(resource, org.eclipse.core.resources.IMarker.TASK);
		if (isInBinFolder(resource)) {
			return;
		}
		java.util.List<ASPT.resource.aspt.mopp.AsptTaskItem> taskItems = new java.util.ArrayList<ASPT.resource.aspt.mopp.AsptTaskItem>();
		ASPT.resource.aspt.mopp.AsptTaskItemDetector taskItemDetector = new ASPT.resource.aspt.mopp.AsptTaskItemDetector();
		try {
			java.io.InputStream inputStream = resource.getContents();
			String content = ASPT.resource.aspt.util.AsptStreamUtil.getContent(inputStream);
			ASPT.resource.aspt.IAsptTextScanner lexer = new ASPT.resource.aspt.mopp.AsptMetaInformation().createLexer();
			lexer.setText(content);
			
			ASPT.resource.aspt.IAsptTextToken nextToken = lexer.getNextToken();
			while (nextToken != null) {
				String text = nextToken.getText();
				taskItems.addAll(taskItemDetector.findTaskItems(text, nextToken.getLine(), nextToken.getOffset()));
				nextToken = lexer.getNextToken();
			}
		} catch (java.io.IOException e) {
			ASPT.resource.aspt.mopp.AsptPlugin.logError("Exception while searching for task items", e);
		} catch (org.eclipse.core.runtime.CoreException e) {
			ASPT.resource.aspt.mopp.AsptPlugin.logError("Exception while searching for task items", e);
		}
		
		for (ASPT.resource.aspt.mopp.AsptTaskItem taskItem : taskItems) {
			java.util.Map<String, Object> markerAttributes = new java.util.LinkedHashMap<String, Object>();
			markerAttributes.put(org.eclipse.core.resources.IMarker.USER_EDITABLE, false);
			markerAttributes.put(org.eclipse.core.resources.IMarker.DONE, false);
			markerAttributes.put(org.eclipse.core.resources.IMarker.LINE_NUMBER, taskItem.getLine());
			markerAttributes.put(org.eclipse.core.resources.IMarker.CHAR_START, taskItem.getCharStart());
			markerAttributes.put(org.eclipse.core.resources.IMarker.CHAR_END, taskItem.getCharEnd());
			markerAttributes.put(org.eclipse.core.resources.IMarker.MESSAGE, taskItem.getMessage());
			new ASPT.resource.aspt.mopp.AsptMarkerHelper().createMarker(resource, org.eclipse.core.resources.IMarker.TASK, markerAttributes);
		}
	}
	
	public String getBuilderMarkerId() {
		return org.eclipse.core.resources.IMarker.TASK;
	}
	
	public boolean isInBinFolder(org.eclipse.core.resources.IFile resource) {
		org.eclipse.core.resources.IContainer parent = resource.getParent();
		while (parent != null) {
			if ("bin".equals(parent.getName())) {
				return true;
			}
			parent = parent.getParent();
		}
		return false;
	}
	
}
