Search in sources :

Example 1 with OverrideIndicatorAnnotation

use of org.eclipse.xtend.ide.editor.OverrideIndicatorAnnotation in project xtext-xtend by eclipse.

the class RenameStrategyTest method testOverrideIndicatorAnnotationAfterFileRename.

@Test
public void testOverrideIndicatorAnnotationAfterFileRename() throws Exception {
    testHelper.createFile("test/SuperClass", "package test\nclass SuperClass { def foo() {}}");
    final IFile subClassFile = testHelper.createFile("test/SubClass", "package test\nclass SubClass extends SuperClass { override foo () {}}");
    IResourcesSetupUtil.waitForBuild();
    XtextEditor openEditor = testHelper.openEditor(subClassFile);
    final OverrideIndicatorAnnotation[] annotationBeforeFileRename = new OverrideIndicatorAnnotation[] { null };
    final OverrideIndicatorAnnotation[] annotationAfterFileRename = new OverrideIndicatorAnnotation[] { null };
    final ISourceViewer sourceViewer = openEditor.getInternalSourceViewer();
    sleepWhile(Predicates.isNull(), new Provider<Object>() {

        @Override
        public OverrideIndicatorAnnotation get() {
            annotationBeforeFileRename[0] = Iterators.getOnlyElement(Iterators.filter(sourceViewer.getAnnotationModel().getAnnotationIterator(), OverrideIndicatorAnnotation.class), null);
            return annotationBeforeFileRename[0];
        }
    }, TimeUnit.SECONDS.toMillis(10));
    assertNotNull(annotationBeforeFileRename[0]);
    new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            subClassFile.move(subClassFile.getFullPath().removeLastSegments(1).append("Test.xtend"), true, monitor);
        }
    }.run(new NullProgressMonitor());
    IResourcesSetupUtil.waitForBuild();
    sleepWhile(Predicates.isNull(), new Provider<Object>() {

        @Override
        public OverrideIndicatorAnnotation get() {
            OverrideIndicatorAnnotation ann = Iterators.getOnlyElement(Iterators.filter(sourceViewer.getAnnotationModel().getAnnotationIterator(), OverrideIndicatorAnnotation.class), null);
            if (ann != annotationBeforeFileRename[0])
                annotationAfterFileRename[0] = ann;
            return annotationAfterFileRename[0];
        }
    }, TimeUnit.SECONDS.toMillis(10));
    assertNotNull(annotationAfterFileRename[0]);
    assertNotSame(annotationBeforeFileRename[0], annotationAfterFileRename[0]);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OverrideIndicatorAnnotation(org.eclipse.xtend.ide.editor.OverrideIndicatorAnnotation) IFile(org.eclipse.core.resources.IFile) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) EObject(org.eclipse.emf.ecore.EObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Test(org.junit.Test)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 EObject (org.eclipse.emf.ecore.EObject)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)1 OverrideIndicatorAnnotation (org.eclipse.xtend.ide.editor.OverrideIndicatorAnnotation)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 Test (org.junit.Test)1