Search in sources :

Example 91 with Procedure0

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

the class TypeResourceUnloaderTest method testNonStructuralChange.

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

        @Override
        public void apply() {
            int methodBody = document.get().indexOf("{}") + 1;
            assertNull("event is null before the document was modified", event);
            try {
                document.replace(methodBody, 0, "ignored.toString();");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNull(event);
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 92 with Procedure0

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

the class TypeResourceUnloaderTest method testAddParam.

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

        @Override
        public void apply() {
            int idx = document.get().lastIndexOf("(");
            assertNull("event is null before the document was modified", event);
            try {
                document.replace(idx + 1, 0, "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)

Example 93 with Procedure0

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

the class TypeResourceUnloaderTest method testCloseEditorAndDiscardWorkingCopy.

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

        @Override
        public void apply() {
            try {
                compilationUnit.discardWorkingCopy();
                ((ITextEditor) editor).close(false);
            } catch (JavaModelException e) {
                throw new RuntimeException(e);
            }
        }
    }, false);
    assertNull(event);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) Test(org.junit.Test)

Example 94 with Procedure0

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

the class TypeResourceUnloaderTest method testRemoveNestedClass.

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

        @Override
        public void apply() {
            int idx = document.get().indexOf("public abstract class Inner");
            assertNull("event is null before the document was modified", event);
            try {
                int closing = document.get().substring(idx).indexOf("\t}");
                document.replace(idx, closing + 2, "");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNotNull(event);
    assertTrue(subsequentEvents.toString(), subsequentEvents.isEmpty());
    assertEquals("" + event.getDeltas(), 3, event.getDeltas().size());
    assertNull(event.getDeltas().get(2).getNew());
    assertEquals("java:/Objects/" + NESTED_TYPES, event.getDeltas().get(0).getUri().toString());
    assertEquals("java:/Objects/" + NESTED_TYPES, event.getDeltas().get(1).getUri().toString());
    assertEquals("java:/Objects/" + NESTED_TYPES, event.getDeltas().get(2).getUri().toString());
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 95 with Procedure0

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

the class TypeResourceUnloaderTest method testNullChange.

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

        @Override
        public void apply() {
            try {
                int lastBrace = document.get().lastIndexOf("}");
                document.replace(lastBrace, 0, " ");
            } catch (BadLocationException e) {
                Assert.fail(e.getMessage());
            }
        }
    });
    assertNull(event);
}
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)97 Test (org.junit.Test)76 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)52 BadLocationException (org.eclipse.jface.text.BadLocationException)11 AbstractBuilderParticipantTest (org.eclipse.xtext.builder.impl.AbstractBuilderParticipantTest)10 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)10 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 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)3 IFile (org.eclipse.core.resources.IFile)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 MutableTypeParameterDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration)2 HashMap (java.util.HashMap)1 List (java.util.List)1