Search in sources :

Example 1 with Task

use of org.eclipse.xtext.tasks.Task in project xtext-core by eclipse.

the class DefaultTaskFinderTest method test.

@Test
public void test() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("//TODO foo");
        _builder.newLine();
        _builder.append("/*");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* FIXME bar");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* Fixme no match");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* FOO also no match");
        _builder.newLine();
        _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();
        final Procedure1<Task> _function = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_1 = (TaskTag it_1) -> {
                it_1.setName("TODO");
                it_1.setPriority(Priority.NORMAL);
            };
            TaskTag _doubleArrow = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_1);
            it.setTag(_doubleArrow);
            it.setDescription(" foo");
            it.setOffset(2);
            it.setLineNumber(1);
        };
        Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
        Task _task_1 = new Task();
        final Procedure1<Task> _function_1 = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_2 = (TaskTag it_1) -> {
                it_1.setName("FIXME");
                it_1.setPriority(Priority.HIGH);
            };
            TaskTag _doubleArrow_1 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_2);
            it.setTag(_doubleArrow_1);
            it.setDescription(" bar");
            it.setOffset(17);
            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, _doubleArrow_2)));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Task(org.eclipse.xtext.tasks.Task) TaskTag(org.eclipse.xtext.tasks.TaskTag) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 2 with Task

use of org.eclipse.xtext.tasks.Task in project xtext-core by eclipse.

the class DefaultTaskParser method parseTasks.

@Override
public List<Task> parseTasks(final String source, final TaskTags taskTags) {
    ArrayList<Task> _xblockexpression = null;
    {
        boolean _isEmpty = IterableExtensions.isEmpty(taskTags);
        if (_isEmpty) {
            return Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList());
        }
        final Function<TaskTag, String> _function = (TaskTag it) -> {
            return it.getName().toLowerCase();
        };
        final ImmutableMap<String, TaskTag> taskTagsByName = Maps.<String, TaskTag>uniqueIndex(taskTags, _function);
        final Matcher matcher = this.toPattern(taskTags).matcher(source);
        final ArrayList<Task> tasks = CollectionLiterals.<Task>newArrayList();
        int prevLine = 1;
        int prevOffset = 0;
        while (matcher.find()) {
            {
                final Task task = new Task();
                task.setTag(taskTagsByName.get(matcher.group(2).toLowerCase()));
                task.setDescription(matcher.group(3));
                task.setOffset(matcher.start(2));
                int _countLineBreaks = Strings.countLineBreaks(source, prevOffset, task.getOffset());
                int _plus = (_countLineBreaks + prevLine);
                task.setLineNumber(_plus);
                prevLine = task.getLineNumber();
                prevOffset = task.getOffset();
                tasks.add(task);
            }
        }
        _xblockexpression = tasks;
    }
    return _xblockexpression;
}
Also used : Function(com.google.common.base.Function) Task(org.eclipse.xtext.tasks.Task) TaskTag(org.eclipse.xtext.tasks.TaskTag) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with Task

use of org.eclipse.xtext.tasks.Task in project xtext-xtend by eclipse.

the class XtendTaskFinderTest method test.

@Test
public void test() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("\'\'\'", "\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("�", "\t\t");
        _builder.append("�", "\t\t");
        _builder.append("�", "\t\t");
        _builder.append(" TODO this is a todo");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("TODO this is not a todo");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("�", "\t\t");
        _builder.append("�", "\t\t");
        _builder.append("�", "\t\t");
        _builder.append(" FIXME this is a fixme");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("\'\'\'", "\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String contents = Strings.toUnixLineSeparator(_builder.toString());
        final XtendFile file = this.file(contents);
        Task _task = new Task();
        final Procedure1<Task> _function = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_1 = (TaskTag it_1) -> {
                it_1.setName("TODO");
                it_1.setPriority(Priority.NORMAL);
            };
            TaskTag _doubleArrow = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_1);
            it.setTag(_doubleArrow);
            it.setDescription(" this is a todo");
            it.setOffset(50);
            it.setLineNumber(6);
        };
        Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
        Task _task_1 = new Task();
        final Procedure1<Task> _function_1 = (Task it) -> {
            TaskTag _taskTag = new TaskTag();
            final Procedure1<TaskTag> _function_2 = (TaskTag it_1) -> {
                it_1.setName("FIXME");
                it_1.setPriority(Priority.HIGH);
            };
            TaskTag _doubleArrow_1 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_2);
            it.setTag(_doubleArrow_1);
            it.setDescription(" this is a fixme");
            it.setOffset(102);
            it.setLineNumber(8);
        };
        Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_1);
        this.assertContainsTasks(file.eResource(), Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow, _doubleArrow_1)));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) Task(org.eclipse.xtext.tasks.Task) TaskTag(org.eclipse.xtext.tasks.TaskTag) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 4 with Task

use of org.eclipse.xtext.tasks.Task in project xtext-xtend by eclipse.

the class XtendTaskFinderTest method assertContainsTasks.

private void assertContainsTasks(final Resource resource, final List<Task> expectedTasks) {
    final List<Task> actualTasks = this.finder.findTasks(resource);
    Assert.assertEquals(expectedTasks.size(), actualTasks.size());
    int _size = expectedTasks.size();
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
    for (final Integer i : _doubleDotLessThan) {
        XtendTaskFinderTest.assertExactMatch(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
    }
}
Also used : Task(org.eclipse.xtext.tasks.Task) ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange)

Example 5 with Task

use of org.eclipse.xtext.tasks.Task in project xtext-core by eclipse.

the class DefaultTaskFinderTest method assertContainsTasks.

private void assertContainsTasks(final Resource resource, final List<Task> expectedTasks) {
    final List<Task> actualTasks = this.finder.findTasks(resource);
    Assert.assertEquals(expectedTasks.size(), actualTasks.size());
    int _size = expectedTasks.size();
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
    for (final Integer i : _doubleDotLessThan) {
        TaskAssert.assertExactMatch(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
    }
}
Also used : Task(org.eclipse.xtext.tasks.Task) ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange)

Aggregations

Task (org.eclipse.xtext.tasks.Task)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 TaskTag (org.eclipse.xtext.tasks.TaskTag)6 Test (org.junit.Test)6 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 ExclusiveRange (org.eclipse.xtext.xbase.lib.ExclusiveRange)4 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 DefaultTaskFinder (org.eclipse.xtext.tasks.DefaultTaskFinder)1 IntegerRange (org.eclipse.xtext.xbase.lib.IntegerRange)1