[380449] Enhancements to Task Finder

- Introduced a hook to allow stripping of the node text before calling the task parser
- Stripped trailing comment in tasks

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2017-03-22 10:55:54 +01:00
parent 46f2a0155e
commit 770e6897d7
4 changed files with 54 additions and 6 deletions

View file

@ -47,6 +47,7 @@ class DefaultTaskFinderTest extends AbstractXtextTests {
* Fixme no match
* FOO also no match
*/
/* TODO Get rid of this */
Hello notATODO!
''')
)
@ -68,10 +69,18 @@ class DefaultTaskFinderTest extends AbstractXtextTests {
description = " bar"
offset = 17
lineNumber = 3
],
new Task => [
tag = new TaskTag => [
name = "TODO"
priority = Priority.NORMAL
]
description = " Get rid of this "
offset = 73
lineNumber = 7
]
])
}
private def assertContainsTasks(Resource resource, List<Task> expectedTasks) {

View file

@ -72,6 +72,8 @@ public class DefaultTaskFinderTest extends AbstractXtextTests {
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("/* TODO Get rid of this */");
_builder.newLine();
_builder.append("Hello notATODO!");
_builder.newLine();
Task _task = new Task();
@ -102,9 +104,23 @@ public class DefaultTaskFinderTest extends AbstractXtextTests {
it.setLineNumber(3);
};
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_1);
Task _task_2 = new Task();
final Procedure1<Task> _function_2 = (Task it) -> {
TaskTag _taskTag = new TaskTag();
final Procedure1<TaskTag> _function_3 = (TaskTag it_1) -> {
it_1.setName("TODO");
it_1.setPriority(Priority.NORMAL);
};
TaskTag _doubleArrow_2 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_3);
it.setTag(_doubleArrow_2);
it.setDescription(" Get rid of this ");
it.setOffset(73);
it.setLineNumber(7);
};
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_2, _function_2);
this.assertContainsTasks(this.getResourceFromString(
LineDelimiters.toUnix(_builder.toString())),
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow, _doubleArrow_1)));
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow, _doubleArrow_1, _doubleArrow_2)));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}

View file

@ -10,11 +10,11 @@ package org.eclipse.xtext.tasks
import com.google.inject.Inject
import java.util.List
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.AbstractRule
import org.eclipse.xtext.nodemodel.ICompositeNode
import org.eclipse.xtext.nodemodel.ILeafNode
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.AbstractRule
import org.eclipse.xtext.parsetree.reconstr.IHiddenTokenHelper
import org.eclipse.xtext.resource.XtextResource
/**
* @author Stefan Oehme - Initial contribution and API
@ -45,7 +45,7 @@ class DefaultTaskFinder implements ITaskFinder {
protected def List<Task> findTasks(ILeafNode node, TaskTags taskTags) {
if (node.canContainTaskTags) {
//TODO strip comment characters before parsing, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=380449#c13
val tasks = parser.parseTasks(node.text, taskTags)
val tasks = parser.parseTasks(stripText(node, node.text), taskTags)
tasks.forEach [
offset = offset + node.offset
lineNumber = lineNumber + node.startLine - 1
@ -55,6 +55,16 @@ class DefaultTaskFinder implements ITaskFinder {
return #[]
}
/**
* @since 2.12
*/
protected def String stripText(ILeafNode node, String text) {
if (text.endsWith("*/")) {
return text.substring(0, text.length-2)
}
return text
}
protected def boolean canContainTaskTags(ILeafNode node) {
val rule = node.grammarElement
if (rule instanceof AbstractRule) {

View file

@ -89,7 +89,7 @@ public class DefaultTaskFinder implements ITaskFinder {
protected List<Task> findTasks(final ILeafNode node, final TaskTags taskTags) {
boolean _canContainTaskTags = this.canContainTaskTags(node);
if (_canContainTaskTags) {
final List<Task> tasks = this.parser.parseTasks(node.getText(), taskTags);
final List<Task> tasks = this.parser.parseTasks(this.stripText(node, node.getText()), taskTags);
final Consumer<Task> _function = (Task it) -> {
int _offset = it.getOffset();
int _offset_1 = node.getOffset();
@ -107,6 +107,19 @@ public class DefaultTaskFinder implements ITaskFinder {
return Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList());
}
/**
* @since 2.12
*/
protected String stripText(final ILeafNode node, final String text) {
boolean _endsWith = text.endsWith("*/");
if (_endsWith) {
int _length = text.length();
int _minus = (_length - 2);
return text.substring(0, _minus);
}
return text;
}
protected boolean canContainTaskTags(final ILeafNode node) {
final EObject rule = node.getGrammarElement();
if ((rule instanceof AbstractRule)) {