Search in sources :

Example 6 with Procedure0

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

the class TypeResourceUnloaderTest method testCloseAndReopenEditor.

@Test
public void testCloseAndReopenEditor() throws InterruptedException, PartInitException, JavaModelException {
    waitForEvent(new Procedure0() {

        @Override
        public void apply() {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
            try {
                editor = JavaUI.openInEditor(compilationUnit);
            } catch (PartInitException e) {
                fail(e.getMessage());
            } catch (JavaModelException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNull(event);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 7 with Procedure0

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

the class TypeResourceUnloaderTest method testAddNestedClass.

@Test
public void testAddNestedClass() 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, 0, " public abstract class InnerSibling {} ");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNotNull(event);
    assertTrue(subsequentEvents.toString(), subsequentEvents.isEmpty());
    assertEquals("" + event.getDeltas(), 4, event.getDeltas().size());
    assertNull(event.getDeltas().get(3).getOld());
    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());
    assertEquals("java:/Objects/" + NESTED_TYPES, event.getDeltas().get(3).getUri().toString());
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 8 with Procedure0

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

the class TypeResourceUnloaderTest method testTypeParameterAdded.

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

        @Override
        public void apply() {
            String lookup = "NestedTypes";
            int idx = document.get().indexOf(lookup) + "NestedTypes".length();
            assertNull("event is null before the document was modified", event);
            try {
                document.replace(idx, 0, "<Abc>");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNotNull(event);
    assertTrue(subsequentEvents.toString(), subsequentEvents.isEmpty());
    assertEquals("" + event.getDeltas(), 3, event.getDeltas().size());
    IResourceDescription.Delta delta = event.getDeltas().get(0);
    assertNotNull(delta.getNew());
    assertNotNull(delta.getOld());
    assertEquals("java:/Objects/" + NESTED_TYPES, delta.getUri().toString());
    Collection<String> allNames = getNames(event.getDeltas());
    assertOriginalValues(allNames);
    assertEquals("" + allNames, 3, allNames.size());
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 9 with Procedure0

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

the class TypeResourceUnloaderTest method testRenameInnerMethod.

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

        @Override
        public void apply() {
            int idx = document.get().indexOf("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 10 with Procedure0

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

the class TypeResourceUnloaderTest method testRemoveMethod.

@Test
public void testRemoveMethod() 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(), "");
            } catch (BadLocationException e) {
                fail(e.getMessage());
            }
        }
    });
    assertNotNull(event);
    assertTrue(subsequentEvents.toString(), subsequentEvents.isEmpty());
    assertEquals("" + event.getDeltas(), 3, event.getDeltas().size());
    IResourceDescription.Delta delta = event.getDeltas().get(0);
    assertNotNull(delta.getNew());
    assertNotNull(delta.getOld());
    assertEquals("java:/Objects/" + NESTED_TYPES, delta.getUri().toString());
    Collection<String> allNames = getNames(event.getDeltas());
    assertOriginalValues(allNames);
    assertEquals("" + allNames, 3, allNames.size());
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) 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 AbstractQueuedBuildDataTest (org.eclipse.xtend.ide.tests.builder.AbstractQueuedBuildDataTest)50 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