Search in sources :

Example 6 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class UIParticipant method createLabelProvider.

@Override
public ILabelProvider createLabelProvider() {
    return new ILabelProvider() {

        @Override
        public void removeListener(ILabelProviderListener listener) {
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        }

        @Override
        public String getText(Object element) {
            IReferenceDescription referenceDescription = (IReferenceDescription) element;
            URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
            final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
            IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
            if (resourceDescription != null) {
                for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
                    if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
                        return globalDescriptionsLabelProvider.getText(eObjectDescription);
                    }
                }
            }
            return "unknown";
        }

        @Override
        public Image getImage(Object element) {
            IReferenceDescription referenceDescription = (IReferenceDescription) element;
            URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
            final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
            IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
            if (resourceDescription != null) {
                for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
                    if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
                        return globalDescriptionsLabelProvider.getImage(eObjectDescription);
                    }
                }
            }
            return null;
        }
    };
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 7 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class DirtyStateEditorSupportIntegrationTest method testUndoRedo.

/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=354123
 */
@Test
public void testUndoRedo() {
    this.pushKey((IterableExtensions.<Character>head(((Iterable<Character>) Conversions.doWrapArray("a".toCharArray())))).charValue(), 0);
    Assert.assertEquals(1, this.events.size());
    Assert.assertEquals("fooa", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
    ISourceViewer _internalSourceViewer = this.editor.getInternalSourceViewer();
    final IUndoManager undoManager = ((XtextSourceViewer) _internalSourceViewer).getUndoManager();
    undoManager.undo();
    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
    this.syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor);
    this.syncUtil.waitForReconciler(this.editor);
    Assert.assertEquals(2, this.events.size());
    Assert.assertNull(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew());
    undoManager.redo();
    NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
    this.syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor_1);
    this.syncUtil.waitForReconciler(this.editor);
    Assert.assertEquals(3, this.events.size());
    Assert.assertEquals("fooa", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtextSourceViewer(org.eclipse.xtext.ui.editor.XtextSourceViewer) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IUndoManager(org.eclipse.jface.text.IUndoManager) Event(org.eclipse.swt.widgets.Event) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 8 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class DirtyStateEditorSupportIntegrationTest method testSaveAndEdit.

/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=488380
 */
@Test
public void testSaveAndEdit() {
    this.pushKey((IterableExtensions.<Character>head(((Iterable<Character>) Conversions.doWrapArray("a".toCharArray())))).charValue(), 0);
    Assert.assertEquals(1, this.events.size());
    Assert.assertEquals("fooa", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
    this.editor.doSave(_nullProgressMonitor);
    NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
    this.syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor_1);
    Assert.assertEquals(2, this.events.size());
    Assert.assertNull(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew());
    this.pushKey(((char) 0), SWT.BS);
    Assert.assertEquals(3, this.events.size());
    Assert.assertEquals("foo", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Event(org.eclipse.swt.widgets.Event) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 9 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class RefactoringCrossReferenceSerializerTest method testSerializer.

@Test
public void testSerializer() throws Exception {
    RefactoringCrossReferenceSerializer.RefTextEvaluator evaluator = new RefactoringCrossReferenceSerializer.RefTextEvaluator() {

        @Override
        public boolean isValid(IEObjectDescription target) {
            return true;
        }

        @Override
        public boolean isBetterThan(String newText, String currentText) {
            return newText.length() < currentText.length();
        }
    };
    String model = "bar { ref foo } foo";
    String wsRelativePath = "test/test." + getCurrentFileExtension();
    IFile file = createFile(wsRelativePath, model);
    Main main = (Main) getModel(file.getContents());
    XtextResource resource = (XtextResource) main.eResource();
    resource.setURI(URI.createPlatformResourceURI(wsRelativePath, true));
    Element bar = (Element) main.getElements().get(0);
    Element foo = bar.getReferenced().get(0);
    assertEquals("foo", foo.getName());
    CrossReference crossref = GrammarUtil.containedCrossReferences(grammarAccess.getElementRule()).get(0);
    TextRegion linkTextRegion = new TextRegion(model.lastIndexOf("foo"), 3);
    String linkText = facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status);
    assertEquals(linkText, "foo");
    assertTrue(status.getRefactoringStatus().isOK());
    foo.setName("fooBar");
    resource.getCache().clear(resource);
    String linkText1 = facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status);
    assertEquals(linkText1, "fooBar");
    assertTrue(status.getRefactoringStatus().isOK());
    assertEquals(foo, ((Main) resource.getContents().get(0)).getElements().get(1));
    foo.setName("bar");
    resource.getCache().clear(resource);
    assertNull(facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status));
}
Also used : RefactoringCrossReferenceSerializer(org.eclipse.xtext.ui.refactoring.impl.RefactoringCrossReferenceSerializer) IFile(org.eclipse.core.resources.IFile) TextRegion(org.eclipse.xtext.util.TextRegion) Element(org.eclipse.xtext.ui.tests.refactoring.refactoring.Element) CrossReference(org.eclipse.xtext.CrossReference) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.ui.tests.refactoring.refactoring.Main) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 10 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XbaseProposalProvider method createLocalVariableAndImplicitProposals.

protected void createLocalVariableAndImplicitProposals(EObject context, IExpressionScope.Anchor anchor, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
    String prefix = contentAssistContext.getPrefix();
    if (prefix.length() > 0) {
        if (!Character.isJavaIdentifierStart(prefix.charAt(0))) {
            if (prefix.length() > 1) {
                if (prefix.charAt(0) == '^' && !Character.isJavaIdentifierStart(prefix.charAt(1))) {
                    return;
                }
            }
        }
    }
    // long time = System.currentTimeMillis();
    Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext);
    IResolvedTypes resolvedTypes = context != null ? typeResolver.resolveTypes(context) : typeResolver.resolveTypes(contentAssistContext.getResource());
    IExpressionScope expressionScope = resolvedTypes.getExpressionScope(context, anchor);
    // TODO use the type name information
    IScope scope = expressionScope.getFeatureScope();
    getCrossReferenceProposalCreator().lookupCrossReference(scope, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
    // System.out.printf("XbaseProposalProvider.createLocalVariableAndImplicitProposals = %d\n", System.currentTimeMillis() - time);
    // time = System.currentTimeMillis();
    // TODO use the type name information
    proposeDeclaringTypeForStaticInvocation(context, null, /* ignore */
    contentAssistContext, acceptor);
// System.out.printf("XbaseProposalProvider.proposeDeclaringTypeForStaticInvocation = %d\n", System.currentTimeMillis() - time);
}
Also used : IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IExpressionScope(org.eclipse.xtext.xbase.typesystem.IExpressionScope) IScope(org.eclipse.xtext.scoping.IScope) StyledString(org.eclipse.jface.viewers.StyledString) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)324 Test (org.junit.Test)95 EObject (org.eclipse.emf.ecore.EObject)82 QualifiedName (org.eclipse.xtext.naming.QualifiedName)79 IScope (org.eclipse.xtext.scoping.IScope)56 URI (org.eclipse.emf.common.util.URI)41 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)33 EClass (org.eclipse.emf.ecore.EClass)30 Resource (org.eclipse.emf.ecore.resource.Resource)28 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)22 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)22 ArrayList (java.util.ArrayList)19 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)14 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 StyledString (org.eclipse.jface.viewers.StyledString)12 XtextResource (org.eclipse.xtext.resource.XtextResource)11 StringInputStream (org.eclipse.xtext.util.StringInputStream)11 EReference (org.eclipse.emf.ecore.EReference)10 List (java.util.List)9