Search in sources :

Example 86 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project statecharts by Yakindu.

the class STextProposalProvider method getProposalFactory.

protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName, ContentAssistContext contentAssistContext) {
    return new DefaultProposalCreator(contentAssistContext, ruleName, getQualifiedNameConverter()) {

        @Override
        public ICompletionProposal apply(IEObjectDescription candidate) {
            ICompletionProposal proposal = super.apply(candidate);
            EObject eObjectOrProxy = candidate.getEObjectOrProxy();
            if (eObjectOrProxy.eIsProxy()) {
                return proposal;
            }
            if (eObjectOrProxy instanceof Operation) {
                Operation operation = (Operation) eObjectOrProxy;
                if (operation.getParameters().size() > 0 && (proposal instanceof ConfigurableCompletionProposal)) {
                    ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) proposal;
                    configurableProposal.setReplacementString(configurableProposal.getReplacementString() + "()");
                    configurableProposal.setCursorPosition(configurableProposal.getCursorPosition() + 1);
                }
            }
            return proposal;
        }
    };
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EObject(org.eclipse.emf.ecore.EObject) Operation(org.yakindu.base.types.Operation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 87 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project statecharts by Yakindu.

the class AbstractLibraryGlobalScopeProvider method getDescriptions.

protected Iterable<IEObjectDescription> getDescriptions(Resource context, URI uri) {
    List<IEObjectDescription> result = Lists.newArrayList();
    ResourceSet set = context.getResourceSet();
    Resource resource = set.getResource(uri, true);
    IResourceServiceProvider resourceServiceProvider = serviceProviderRegistry.getResourceServiceProvider(uri);
    if (resourceServiceProvider == null) {
        Iterables.addAll(result, Scopes.scopedElementsFor(Lists.newArrayList(resource.getAllContents())));
    } else {
        IResourceDescription resourceDescription = resourceServiceProvider.getResourceDescriptionManager().getResourceDescription(resource);
        Iterables.addAll(result, resourceDescription.getExportedObjects());
    }
    resource.unload();
    return result;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 88 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project statecharts by Yakindu.

the class FeatureResourceDescription method computeExportedObjects.

@Override
protected List<IEObjectDescription> computeExportedObjects() {
    Iterator<EObject> contents = resource.getAllContents();
    List<IEObjectDescription> result = Lists.newArrayList();
    while (contents.hasNext()) {
        EObject eObject = contents.next();
        QualifiedName qualifiedName = qualifiedNameProvider.apply(eObject);
        if (qualifiedName != null) {
            Map<String, String> userData = new HashMap<String, String>();
            if (eObject instanceof FeatureParameter) {
                userData.put(FEATURE_CONTAINER, getFqName(eObject));
            }
            result.add(new EObjectDescription(qualifiedName, eObject, userData));
        }
    }
    return result;
}
Also used : EObjectDescription(org.eclipse.xtext.resource.EObjectDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) HashMap(java.util.HashMap) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) FeatureParameter(org.yakindu.sct.model.sgen.FeatureParameter) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 89 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project statecharts by Yakindu.

the class SGenScopeProvider method scope_GeneratorEntry_elementRef.

protected IScope scope_GeneratorEntry_elementRef(final EObject context, final EReference reference) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil2.getRootContainer(context);
    String id = generatorModel.getGeneratorId();
    final IGeneratorDescriptor desc = GeneratorExtensions.getGeneratorDescriptor(id);
    if (desc == null)
        return IScope.NULLSCOPE;
    final String elementRefType = desc.getElementRefType();
    IScope scope = new FilteringScope(getDelegate().getScope(context, reference), new Predicate<IEObjectDescription>() {

        public boolean apply(IEObjectDescription input) {
            EList<EClass> allSuperTypes = input.getEClass().getESuperTypes();
            for (EClass eClass : allSuperTypes) {
                if (elementRefType.equals(eClass.getInstanceClassName()))
                    return true;
            }
            return elementRefType.equals(input.getEClass().getInstanceClassName());
        }
    });
    return new SimpleScope(scope.getAllElements());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EList(org.eclipse.emf.common.util.EList) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 90 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project statecharts by Yakindu.

the class SGenScopeProvider method getLibraryScope.

protected SimpleScope getLibraryScope(Resource resource) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil.getObjectByType(resource.getContents(), SGenPackage.Literals.GENERATOR_MODEL);
    Assert.isNotNull(generatorModel);
    String generatorId = generatorModel.getGeneratorId();
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    Iterable<IEObjectDescription> allElements = Lists.newArrayList();
    if (generatorDescriptor != null) {
        Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
        for (ILibraryDescriptor desc : libraryDescriptor) {
            Resource library = resourceSet.getResource(desc.getURI(), true);
            FeatureResourceDescription description = new FeatureResourceDescription(library);
            injector.injectMembers(description);
            allElements = Iterables.concat(allElements, description.getExportedObjects());
        }
    }
    return new SimpleScope(allElements);
}
Also used : FeatureResourceDescription(org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)

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