1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Fix for 192152, duplicate todo-tasks.

This commit is contained in:
Markus Schorn 2007-07-17 09:24:11 +00:00
parent e3d42ea529
commit e89e37b00c
2 changed files with 20 additions and 29 deletions

View file

@ -90,6 +90,8 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
finally { finally {
index.releaseWriteLock(0); index.releaseWriteLock(0);
} }
// remove task-tags.
TodoTaskUpdater.removeTasksFor(project.getProject());
} }
private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {

View file

@ -7,16 +7,19 @@
* *
* Contributors: * Contributors:
* Sergey Prigogin (Google) - initial API and implementation * Sergey Prigogin (Google) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.indexer; package org.eclipse.cdt.internal.core.pdom.indexer;
import java.util.HashMap;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.internal.core.pdom.ITodoTaskUpdater; import org.eclipse.cdt.internal.core.pdom.ITodoTaskUpdater;
import org.eclipse.cdt.internal.core.pdom.indexer.TodoTaskParser.Task; import org.eclipse.cdt.internal.core.pdom.indexer.TodoTaskParser.Task;
@ -31,7 +34,6 @@ import org.eclipse.osgi.util.NLS;
public class TodoTaskUpdater implements ITodoTaskUpdater { public class TodoTaskUpdater implements ITodoTaskUpdater {
private static final IMarker[] EMPTY_MARKER_ARRAY = new IMarker[0];
private static final String SOURCE_ID = "CDT"; //$NON-NLS-1$ private static final String SOURCE_ID = "CDT"; //$NON-NLS-1$
private static final String[] TASK_MARKER_ATTRIBUTE_NAMES = { private static final String[] TASK_MARKER_ATTRIBUTE_NAMES = {
IMarker.MESSAGE, IMarker.MESSAGE,
@ -80,15 +82,18 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
taskParser = new TodoTaskParser(taskTags, taskPriorities, isTaskCaseSensitive); taskParser = new TodoTaskParser(taskTags, taskPriorities, isTaskCaseSensitive);
} }
public void updateTasks(IASTComment[] comments, IIndexFileLocation[] fileLocations) { public void updateTasks(IASTComment[] comments, IIndexFileLocation[] filesToUpdate) {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
for (int i = 0; i < fileLocations.length; i++) { // first collect all valid file-locations and remove old tasks.
IIndexFileLocation indexFileLocation = fileLocations[i]; final HashMap locationToFile= new HashMap();
String filepath = indexFileLocation.getFullPath(); for (int i = 0; i < filesToUpdate.length; i++) {
final IIndexFileLocation indexFileLocation = filesToUpdate[i];
final String filepath = indexFileLocation.getFullPath();
if (filepath != null) { if (filepath != null) {
IFile file = workspaceRoot.getFile(new Path(filepath)); IFile file = workspaceRoot.getFile(new Path(filepath));
if (file != null && getTasksFor(file).length != 0) { if (file.exists()) {
locationToFile.put(IndexLocationFactory.getAbsolutePath(indexFileLocation), file);
removeTasksFor(file); removeTasksFor(file);
} }
} }
@ -98,19 +103,13 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
return; return;
} }
Task[] tasks = taskParser.parse(comments); final Task[] tasks = taskParser.parse(comments);
String location = null;
IFile[] files = null;
for (int i = 0; i < tasks.length; i++) { for (int i = 0; i < tasks.length; i++) {
Task task = tasks[i]; final Task task = tasks[i];
if (!task.getFileLocation().equals(location)) { final IFile file= (IFile) locationToFile.get(new Path(task.getFileLocation()));
location = task.getFileLocation(); if (file != null) {
files = workspaceRoot.findFilesForLocation(new Path(location));
}
for (int j = 0; j < files.length; j++) {
try { try {
applyTask(task, files[j]); applyTask(task, file);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
@ -135,17 +134,7 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
}); });
} }
private static IMarker[] getTasksFor(IResource resource) { public static void removeTasksFor(IResource resource) {
try {
if (resource != null && resource.exists())
return resource.findMarkers(ICModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
CCorePlugin.log(e);
}
return EMPTY_MARKER_ARRAY;
}
private static void removeTasksFor(IResource resource) {
try { try {
if (resource != null && resource.exists()) if (resource != null && resource.exists())
resource.deleteMarkers(ICModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); resource.deleteMarkers(ICModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE);