Search in sources :

Example 1 with Procedure0

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure0 in project xtext-eclipse by eclipse.

the class ChangeConverter method _handleReplacements.

protected void _handleReplacements(final IEmfResourceChange change) {
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final Procedure0 _function = () -> {
        try {
            final IFile file = this.resourceUriConverter.toFile(change.getResource().getURI());
            boolean _canWrite = this.canWrite(file);
            boolean _not = (!_canWrite);
            if (_not) {
                StringConcatenation _builder = new StringConcatenation();
                _builder.append("Affected file \'");
                IPath _fullPath = file.getFullPath();
                _builder.append(_fullPath);
                _builder.append("\' is read-only");
                this.issues.add(RefactoringIssueAcceptor.Severity.ERROR, _builder.toString());
            }
            this.checkDerived(file);
            change.getResource().save(outputStream, null);
            final byte[] newContent = outputStream.toByteArray();
            String _lastSegment = change.getOldURI().lastSegment();
            final ReplaceFileContentChange ltkChange = new ReplaceFileContentChange(_lastSegment, file, newContent);
            this.addChange(ltkChange);
        } catch (Throwable _e) {
            throw Exceptions.sneakyThrow(_e);
        }
    };
    TryWithResource.tryWith(outputStream, _function);
}
Also used : IFile(org.eclipse.core.resources.IFile) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) IPath(org.eclipse.core.runtime.IPath) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReplaceFileContentChange(org.eclipse.xtext.ui.refactoring2.ReplaceFileContentChange)

Example 2 with Procedure0

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure0 in project xtext-eclipse by eclipse.

the class StatusWidget method addStatus.

public Procedure0 addStatus(final int severity, final String text) {
    Procedure0 _xifexpression = null;
    boolean _isEmpty = this.link.getText().trim().isEmpty();
    if (_isEmpty) {
        final Procedure0 _function = () -> {
        };
        final Procedure0 _function_1 = () -> {
        };
        _xifexpression = this.setStatus(severity, text, _function, _function_1);
    } else {
        String _text = this.link.getText();
        String _plus = (_text + "\n");
        String _plus_1 = (_plus + text);
        this.link.setText(_plus_1);
        final Matcher matcher = Pattern.compile("<a>(.*)</a>").matcher(text.trim());
        this.link.setToolTipText(matcher.replaceAll("$1"));
        if ((severity > this.severity)) {
            this.severity = severity;
            this.setVisible((severity != IMessageProvider.NONE));
            this.imageLabel.setImage(this.imageFor(severity));
        }
    }
    return _xifexpression;
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) Matcher(java.util.regex.Matcher)

Example 3 with Procedure0

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure0 in project xtext-eclipse by eclipse.

the class TypeResourceUnloaderTest method testRenameMethod.

@Test
public void testRenameMethod() throws BadLocationException, JavaModelException, InterruptedException {
    waitForEvent(new Procedure0() {

        @Override
        public void apply() {
            int idx = document.get().lastIndexOf("method(");
            assertNull("event is null before the document was modified", event);
            try {
                document.replace(idx + "method".length(), 0, "2");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNotNull(event);
    assertTrue(subsequentEvents.toString(), subsequentEvents.isEmpty());
    assertEquals("" + event.getDeltas(), 3, event.getDeltas().size());
    Collection<String> allNames = getNames(event.getDeltas());
    assertOriginalValues(allNames);
    assertEquals("" + allNames, 3, allNames.size());
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 4 with Procedure0

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure0 in project xtext-eclipse by eclipse.

the class TypeResourceUnloaderTest method testCloseEditor.

@Test
public void testCloseEditor() throws InterruptedException {
    waitForEvent(new Procedure0() {

        @Override
        public void apply() {
            ((ITextEditor) editor).close(false);
        }
    }, false);
    assertNull(event);
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) Test(org.junit.Test)

Example 5 with Procedure0

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure0 in project xtext-eclipse by eclipse.

the class TypeResourceUnloaderTest method testAddMethod.

@Test
public void testAddMethod() throws BadLocationException, JavaModelException, InterruptedException {
    waitForEvent(new Procedure0() {

        @Override
        public void apply() {
            String lookup = "abstract boolean method();";
            int idx = document.get().lastIndexOf(lookup);
            assertNull("event is null before the document was modified", event);
            try {
                document.replace(idx + lookup.length(), 0, "abstract int foobar();");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNotNull(event);
    assertTrue(subsequentEvents.toString(), subsequentEvents.isEmpty());
    assertEquals("" + event.getDeltas(), 3, event.getDeltas().size());
    Collection<String> allNames = getNames(event.getDeltas());
    assertOriginalValues(allNames);
    assertEquals("" + allNames, 3, allNames.size());
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Aggregations

Procedure0 (org.eclipse.xtext.xbase.lib.Procedures.Procedure0)102 Test (org.junit.Test)79 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)53 AbstractBuilderParticipantTest (org.eclipse.xtext.builder.impl.AbstractBuilderParticipantTest)13 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)13 BadLocationException (org.eclipse.jface.text.BadLocationException)11 IFile (org.eclipse.core.resources.IFile)6 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)6 LocalArgumentsVariable (org.eclipse.n4js.n4JS.LocalArgumentsVariable)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 List (java.util.List)4 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)4 File (java.io.File)3 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)3 Matcher (java.util.regex.Matcher)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)2 MutableInterfaceDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration)2 MutableMethodDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)2