Search in sources :

Example 46 with IEObjectDescription

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

the class XtextEObjectSearchDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite container) {
    Composite parent = (Composite) super.createDialogArea(container);
    if (enableStyledLabels && labelProvider instanceof IStyledLabelProvider) {
        final Table table = getTableViewer().getTable();
        final IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) labelProvider;
        TableOwnerDrawSupport.install(table);
        Listener listener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                handleSetData(event);
            }

            protected void handleSetData(Event event) {
                TableItem item = (TableItem) event.item;
                IEObjectDescription description = (IEObjectDescription) item.getData();
                if (description != null) {
                    StyledString styledString = styledLabelProvider.getStyledText(description);
                    String displayString = styledString.toString();
                    StyleRange[] styleRanges = styledString.getStyleRanges();
                    item.setText(displayString);
                    TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
                }
            }
        };
        table.addListener(SWT.SetData, listener);
    }
    messageLabel = new Label(parent, SWT.NONE);
    setDefaultGridData(messageLabel);
    EObjectDescriptionContentProvider contentProvider = new EObjectDescriptionContentProvider();
    getTableViewer().setContentProvider(contentProvider);
    getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (!structuredSelection.isEmpty()) {
                    Object firstElement = structuredSelection.getFirstElement();
                    if (firstElement instanceof IEObjectDescription) {
                        IEObjectDescription eObjectDescription = (IEObjectDescription) firstElement;
                        URI resourceURI = eObjectDescription.getEObjectURI().trimFragment();
                        if (resourceURI.isPlatform()) {
                            messageLabel.setText(resourceURI.toPlatformString(true));
                        } else if (resourceURI.isFile()) {
                            messageLabel.setText(resourceURI.toFileString());
                        } else {
                            messageLabel.setText(resourceURI.toString());
                        }
                        return;
                    }
                }
            }
            // $NON-NLS-1$
            messageLabel.setText("");
        }
    });
    applyFilter();
    return parent;
}
Also used : Table(org.eclipse.swt.widgets.Table) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) StyleRange(org.eclipse.swt.custom.StyleRange) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent)

Example 47 with IEObjectDescription

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

the class AbstractHierarchyBuilder method getDescription.

protected IEObjectDescription getDescription(final URI objectURI) {
    final IResourceDescription resourceDescription = this.getIndexData().getResourceDescription(objectURI.trimFragment());
    if ((resourceDescription == null)) {
        return null;
    }
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
        URI _eObjectURI = it.getEObjectURI();
        return Boolean.valueOf(Objects.equal(_eObjectURI, objectURI));
    };
    return IterableExtensions.<IEObjectDescription>findFirst(resourceDescription.getExportedObjects(), _function);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 48 with IEObjectDescription

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

the class DefaultCallHierarchyBuilder method buildRoots.

@Override
public Collection<IHierarchyNode> buildRoots(final URI rootURI, final IProgressMonitor monitor) {
    final IEObjectDescription rootDeclaration = this.findDeclaration(rootURI);
    if ((rootDeclaration == null)) {
        return CollectionLiterals.<IHierarchyNode>emptyList();
    }
    IHierarchyNode _createRoot = this.createRoot(rootDeclaration);
    return Collections.<IHierarchyNode>unmodifiableList(CollectionLiterals.<IHierarchyNode>newArrayList(_createRoot));
}
Also used : IHierarchyNode(org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNode) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 49 with IEObjectDescription

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

the class NamesAreUniqueValidator method doCheckUniqueNames.

public void doCheckUniqueNames(Resource resource, CancelIndicator cancelIndicator) {
    final IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(resource.getURI());
    if (resourceServiceProvider == null)
        return;
    IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
    if (manager != null) {
        IResourceDescription description = manager.getResourceDescription(resource);
        if (description != null) {
            Iterable<IEObjectDescription> descriptions = description.getExportedObjects();
            helper.checkUniqueNames(descriptions, cancelIndicator, this);
        }
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 50 with IEObjectDescription

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

the class N4JSClassifierWizardModelValidator method getClassifierObjectDescriptionForFQN.

/**
 * Returns with the index entry representing a classifier for the given classifier FQN argument.
 *
 * @param fqn
 *            the fully qualified name of the classifier.
 * @return the index entry representing the classifier.
 */
protected IEObjectDescription getClassifierObjectDescriptionForFQN(String fqn) {
    QualifiedName name = qualifiedNameConverter.toQualifiedName(fqn);
    Iterable<IEObjectDescription> foundObjects = descriptions.getExportedObjects(TypesPackage.eINSTANCE.getTClassifier(), name, false);
    return Iterables.getFirst(foundObjects, null);
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) 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