Java 类org.eclipse.xtext.scoping.impl.FilteringScope 实例源码

项目:statecharts    文件:SGenScopeProvider.java   
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());

}
项目:statecharts    文件:SGenScopeProvider.java   
protected IScope scope_Parameter(final EObject context, EReference reference) {
    IScope libraryScope = getLibraryScope(context.eResource());
    return new FilteringScope(libraryScope, new Predicate<IEObjectDescription>() {
        public boolean apply(IEObjectDescription input) {
            if (!input.getEClass().equals(SGenPackage.Literals.FEATURE_PARAMETER)) {
                return false;
            }
            // Only allow references to FeatureParameters defined by
            // enclosing Feature
            FeatureConfiguration configuration = EcoreUtil2.getContainerOfType(context, FeatureConfiguration.class);
            if (configuration == null || configuration.getType() == null)
                return false;
            String featureName = configuration.getType().getName();
            if (featureName == null) {
                return false;
            }
            return featureName.equals(input.getUserData(FeatureResourceDescription.FEATURE_CONTAINER));

        }
    });
}
项目:Tupi    文件:TupiScopeProvider.java   
@Override
public IScope getScope(EObject context, EReference reference) {

    if (context instanceof Transition) {

        Model m = EcoreUtil2.getContainerOfType(context, Model.class);
        MachineDecl mach = m.getMachine();
        final List<String> objects = getDescriptions(mach);

        return new FilteringScope(super.getScope(context, reference), new Predicate<IEObjectDescription>() {

            @Override
            public boolean apply(IEObjectDescription input) {

                boolean contains = objects.contains(input.getName().toString());
                return contains;
            }
        });
    }
    return super.getScope(context, reference);
}
项目:statecharts    文件:SGenScopeProvider.java   
protected IScope scope_Type(EObject context, EReference reference) {
    IScope libraryScope = getLibraryScope(context.eResource());
    return new FilteringScope(libraryScope, new Predicate<IEObjectDescription>() {
        public boolean apply(IEObjectDescription input) {
            return input.getEClass().equals(SGenPackage.Literals.FEATURE_TYPE);
        }
    });
}
项目:statecharts    文件:STextGlobalScopeProvider.java   
protected IScope filterPropertiesOfLibrary(Resource context, EReference reference, Predicate<IEObjectDescription> filter) {
    return new FilteringScope(libraryScope.getScope(context, reference, filter), new Predicate<IEObjectDescription>() {
        @Override
        public boolean apply(IEObjectDescription input) {
            return input.getEClass() != TypesPackage.Literals.PROPERTY;
        }
    });
}
项目:statecharts    文件:STextScopeProvider.java   
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;
    }
项目:statecharts    文件:STextScopeProvider.java   
/**
 * Scoping for types and taking imported namespaces into account e.g. in
 * variable declarations.
 */
public IScope scope_TypeSpecifier_type(final EObject context, EReference reference) {
    IScope scope = getDelegate().getScope(context, reference);
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    return new FilteringScope(scope, predicate);
}