Search in sources :

Example 91 with IEObjectDescription

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

the class STextGlobalScopeProvider method getScope.

public IScope getScope(Resource context, EReference reference, Predicate<IEObjectDescription> filter) {
    IScope parentScope = super.getScope(context, reference, filter);
    parentScope = new SimpleScope(parentScope, filterPropertiesOfLibrary(context, reference, filter).getAllElements());
    final Statechart statechart = getStatechart(context);
    parentScope = new TypeSystemAwareScope(parentScope, typeSystem, qualifiedNameProvider, reference.getEReferenceType());
    IScope result = new FilteringScope(parentScope, new Predicate<IEObjectDescription>() {

        @Override
        public boolean apply(IEObjectDescription input) {
            String userData = input.getUserData(DomainRegistry.DOMAIN_ID);
            if (userData == null)
                return true;
            return statechart.getDomainID().equals(userData);
        }
    });
    result = filterAnnotations(reference, result);
    return new FilteringScope(result, input -> {
        String isVisible = input.getUserData(TypedResourceDescriptionStrategy.IS_VISIBLE_TYPE);
        return isVisible == null || Boolean.valueOf(isVisible);
    });
}
Also used : SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) Statechart(org.yakindu.sct.model.sgraph.Statechart) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 92 with IEObjectDescription

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

the class STextGlobalScopeProvider method getScope.

/**
 * Overidden to avoid scope nesting which is not required and slows down because
 * of shadowing testing.
 */
@Override
protected IScope getScope(Resource resource, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
    final LinkedHashSet<URI> uniqueImportURIs = getImportedUris(resource);
    IResourceDescriptions descriptions = getResourceDescriptions(resource, uniqueImportURIs);
    List<URI> urisAsList = Lists.newArrayList(uniqueImportURIs);
    Collections.reverse(urisAsList);
    List<IEObjectDescription> objectDescriptions = new ArrayList<IEObjectDescription>();
    for (URI uri : urisAsList) {
        IScope scope = createLazyResourceScope(IScope.NULLSCOPE, uri, descriptions, type, filter, ignoreCase);
        Iterables.addAll(objectDescriptions, scope.getAllElements());
    }
    return MapBasedScope.createScope(IScope.NULLSCOPE, objectDescriptions);
}
Also used : IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 93 with IEObjectDescription

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

the class STextScopeProvider method scope_ElementReferenceExpression_reference.

public IScope scope_ElementReferenceExpression_reference(final EObject context, EReference reference) {
    IScope namedScope = getNamedTopLevelScope(context, reference);
    IScope unnamedScope = getUnnamedTopLevelScope(context, reference);
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    unnamedScope = new FilteringScope(unnamedScope, predicate);
    return new SimpleScope(unnamedScope, namedScope.getAllElements());
}
Also used : SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 94 with IEObjectDescription

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

the class STextScopeProvider method scope_FeatureCall_feature.

public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    Expression owner = context.getOwner();
    EObject element = null;
    if (owner instanceof ElementReferenceExpression) {
        element = ((ElementReferenceExpression) owner).getReference();
    } else if (owner instanceof FeatureCall) {
        element = ((FeatureCall) owner).getFeature();
    } else {
        return getDelegate().getScope(context, reference);
    }
    IScope scope = IScope.NULLSCOPE;
    InferenceResult result = typeInferrer.infer(owner);
    Type ownerType = result != null ? result.getType() : null;
    if (element instanceof Scope) {
        scope = Scopes.scopeFor(((Scope) element).getDeclarations());
        return new FilteringScope(scope, predicate);
    } else if (ownerType != null) {
        scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
        scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
    }
    if (ownerType instanceof ComplexType) {
        return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
    }
    if (ownerType instanceof EnumerationType) {
        return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
    }
    return scope;
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) EnumerationType(org.yakindu.base.types.EnumerationType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComplexType(org.yakindu.base.types.ComplexType) EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Expression(org.yakindu.base.expressions.expressions.Expression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ComplexType(org.yakindu.base.types.ComplexType) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope)

Example 95 with IEObjectDescription

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

the class STextNamesAreUniqueValidationHelper method checkUniqueNames.

/**
 * <p>
 * {@inheritDoc}
 * </p>
 * The cancel indicator will be queried everytime a description has been
 * processed. It should provide a fast answer about its canceled state.
 */
@Override
public void checkUniqueNames(Iterable<IEObjectDescription> descriptions, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor) {
    Iterator<IEObjectDescription> iter = descriptions.iterator();
    this.nameMap = new HashMap<>();
    this.caseInsensitiveMap = new HashMap<>();
    this.lastElementMap = new HashMap<>();
    if (!iter.hasNext())
        return;
    while (iter.hasNext()) {
        IEObjectDescription description = iter.next();
        checkDescriptionForDuplicatedName(description, acceptor);
        operationCanceledManager.checkCanceled(cancelIndicator);
    }
}
Also used : 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