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

项目:xtext-extras    文件:TypeScopes.java   
public IScope createTypeScope(EObject context, EReference reference) {
    if (context.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) {
        JvmInnerTypeReference casted = (JvmInnerTypeReference) context;
        JvmParameterizedTypeReference outerType = casted.getOuter();
        JvmType outerRawType = outerType.getType();
        if (outerRawType instanceof JvmDeclaredType) {
            Iterable<JvmDeclaredType> nestedTypes = ((JvmDeclaredType) outerRawType).getAllNestedTypes();
            List<IEObjectDescription> descriptions = Lists.newArrayList();
            for(JvmDeclaredType nestedType: nestedTypes) {
                descriptions.add(EObjectDescription.create(nestedType.getSimpleName(), nestedType));
            }
            return new SimpleScope(descriptions);
        }
        return IScope.NULLSCOPE;
    } else {
        final IScope delegateScope = getDelegate().getScope(context, reference);
        return delegateScope;
    }
}
项目:xtext-core    文件:XtextScopeProvider.java   
protected IScope createScope(final Grammar grammar, EClass type, IScope current) {
    if (EcorePackage.Literals.EPACKAGE == type) {
        return createEPackageScope(grammar);
    } else if (AbstractMetamodelDeclaration.class.isAssignableFrom(type.getInstanceClass())) {
        return new SimpleScope(IScope.NULLSCOPE,Iterables.transform(grammar.getMetamodelDeclarations(),
                        new Function<AbstractMetamodelDeclaration,IEObjectDescription>(){
                            @Override
                            public IEObjectDescription apply(AbstractMetamodelDeclaration from) {
                                String name = from.getAlias() != null ? from.getAlias() : "";
                                return EObjectDescription.create(QualifiedName.create(name), from);
                            }
                        }));
    }
    final List<Grammar> allGrammars = getAllGrammars(grammar);
    for (int i = allGrammars.size() - 1; i >= 0; i--) {
        current = doCreateScope(allGrammars.get(i), type, current);
    }
    return current;
}
项目: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 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);
}
项目:OCCI-Studio    文件:OCCIScopeProvider.java   
public SimpleScope scope_Transition_action(final Transition transition, final EReference reference) {
  ArrayList<IEObjectDescription> res = new ArrayList<IEObjectDescription>();
  EObject _eContainer = transition.eContainer();
  State s = ((State) _eContainer);
  EObject _eContainer_1 = s.eContainer();
  FSM fsm = ((FSM) _eContainer_1);
  EObject _eContainer_2 = fsm.eContainer();
  Type t = ((Type) _eContainer_2);
  EList<Action> _actions = t.getActions();
  for (final Action action : _actions) {
    res.add(EObjectDescription.create(QualifiedName.create(action.getName()), action));
  }
  return new SimpleScope(IScope.NULLSCOPE, res);
}
项目:xtext-extras    文件:FeatureScopes.java   
protected IScope createFollowUpErrorScope(/* @Nullable */ final LightweightTypeReference receiverType) {
    return new SimpleScope(Collections.<IEObjectDescription>emptyList()) {
        @Override
        public Iterable<IEObjectDescription> getElements(QualifiedName name) {
            return Collections.<IEObjectDescription>singletonList(new ScopeProviderAccess.ErrorDescription(receiverType));
        }
    };
}
项目:xtext-core    文件:XtextScopeProvider.java   
protected IScope createEnumLiteralsScope(EEnum eEnum) {
    return new SimpleScope(IScope.NULLSCOPE,Iterables.transform(eEnum.getELiterals(), new Function<EEnumLiteral, IEObjectDescription>() {
                        @Override
                        public IEObjectDescription apply(EEnumLiteral param) {
                            return EObjectDescription.create(QualifiedName.create(param.getName()), param);
                        }
                    }));
}
项目:xtext-core    文件:XtextScopeProvider.java   
protected IScope createClassifierScope(Iterable<EClassifier> classifiers) {
    return new SimpleScope(
            IScope.NULLSCOPE,Iterables.transform(classifiers, new Function<EClassifier, IEObjectDescription>() {
                @Override
                public IEObjectDescription apply(EClassifier param) {
                    return EObjectDescription.create(QualifiedName.create(param.getName()), param);
                }
            }));
}
项目:xtext-core    文件:XtextScopeProvider.java   
protected IScope createEPackageScope(final Grammar grammar, IScope parent) {
    return new SimpleScope(parent,Iterables.transform(Iterables.filter(grammar.getMetamodelDeclarations(),
            new Predicate<AbstractMetamodelDeclaration>() {
                @Override
                public boolean apply(AbstractMetamodelDeclaration input) {
                    return input.getEPackage() != null;
                }
            }), new Function<AbstractMetamodelDeclaration, IEObjectDescription>() {
        @Override
        public IEObjectDescription apply(AbstractMetamodelDeclaration from) {
            return EObjectDescription.create(QualifiedName.create(from.getEPackage().getNsURI()), from.getEPackage());
        }
    }));
}
项目:xtext-core    文件:XtextScopeProvider.java   
protected IScope createEPackageScope(final Grammar grammar) {
    final List<Grammar> allGrammars = getAllGrammars(grammar);
    IScope current = new SimpleScope(IScope.NULLSCOPE, Iterables.transform(EPackage.Registry.INSTANCE.keySet(), new Function<String, IEObjectDescription>() {
        @Override
        public IEObjectDescription apply(String from) {
            InternalEObject proxyPackage = (InternalEObject) EcoreFactory.eINSTANCE.createEPackage();
            proxyPackage.eSetProxyURI(URI.createURI(from));
            return EObjectDescription.create(QualifiedName.create(from), proxyPackage, Collections.singletonMap("nsURI", "true"));
        }
    }));
    for (int i = allGrammars.size() - 1; i >= 0; i--) {
        current = createEPackageScope(allGrammars.get(i), current);
    }
    return current;
}
项目:xtext-core    文件:Bug443705Test.java   
public IScope scope_Property_type(Property p, EReference ref) {
    // try causing a CyclicResolutionException twice to test if 
    // org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolving
    // is cleaned up properly
    Assert.assertTrue(p.getType().get(0).eIsProxy());
    Assert.assertTrue(p.getType().get(0).eIsProxy());
    return new SimpleScope(Collections.singleton(EObjectDescription.create("Bar", p.eContainer())));
}
项目:xtext-core    文件:LazyLinkingTestLanguageScopeProvider.java   
public IScope scope_Property(Type t, EReference ref) {
    return new SimpleScope(IScope.NULLSCOPE, Iterables.transform(t.getExtends().getProperties(), new Function<Property, IEObjectDescription>(){
        @Override
        public IEObjectDescription apply(Property param) {
            return EObjectDescription.create(QualifiedName.create(param.getName()), param);
        }
    }));
}
项目:dsl-devkit    文件:ScopeScopeProvider.java   
/**
 * Create a scope containing the EClasses of an EPackage.
 * 
 * @param parent
 *          The parent scope
 * @param importedPackage
 *          The Import of the package
 * @return The scope
 */
private IScope createEClassScope(final IScope parent, final Import importedPackage) {
  final String prefix = ScopeUtil.getPackageName(importedPackage);
  final Iterable<EClass> classes = Iterables.filter(importedPackage.getPackage().getEClassifiers(), EClass.class);
  final Iterable<IEObjectDescription> elements = EObjectDescriptions.<EClass> all(classes, NameFunctions.pair(NameFunctions.fromFeature(EcorePackage.Literals.ENAMED_ELEMENT__NAME), new AbstractNameFunction() {
    public QualifiedName apply(final EObject from) {
      return QualifiedName.create(prefix, ((EClass) from).getName());
    }
  }));
  return new SimpleScope(parent, elements);
}
项目:dsl-devkit    文件:ExportScopeProvider.java   
/**
 * Create a scope containing the EClasses of an EPackage.
 * 
 * @param parent
 *          The parent scope
 * @param importedPackage
 *          The Import of the package
 * @return The scope
 */
private IScope createEClassScope(final IScope parent, final Import importedPackage) {
  final String prefix = importedPackage.getPackageName();
  final Iterable<EClass> classes = Iterables.filter(importedPackage.getPackage().getEClassifiers(), EClass.class);
  final Iterable<IEObjectDescription> elements = EObjectDescriptions.<EClass> all(classes, NameFunctions.pair(NameFunctions.fromFeature(EcorePackage.Literals.ENAMED_ELEMENT__NAME), new AbstractNameFunction() {

    public QualifiedName apply(final EObject from) {
      return QualifiedName.create(prefix, ((EClass) from).getName());
    }
  }));
  return new SimpleScope(parent, elements);
}
项目:dsl-devkit    文件:ValidScopeProvider.java   
/**
 * Creates the Eclass scope provider (all EClasses from the parent classifiers, referenced by their fully qualified (::) names.
 * 
 * @param parent
 *          the parent
 * @param classifiers
 *          the classifiers
 * @return the i scope
 */
private IScope createEClassScope(final IScope parent, final Iterable<EClassifier> classifiers) {
  final Iterable<EClass> classes = Iterables.filter(classifiers, EClass.class);
  Iterable<IEObjectDescription> elements = EObjectDescriptions.all(classes, EcorePackage.Literals.ENAMED_ELEMENT__NAME);
  elements = Iterables.concat(elements, EObjectDescriptions.all(classes, new AbstractNameFunction() {
    public QualifiedName apply(final EObject from) {
      final EClass param = (EClass) from;
      return QualifiedName.create(param.getEPackage().getNsPrefix(), param.getName());
    }
  }));
  return new SimpleScope(parent, elements);
}
项目:openhab-hdl    文件:PersistenceGlobalScopeProvider.java   
@Override
protected IScope getScope(Resource resource, boolean ignoreCase,
        EClass type, Predicate<IEObjectDescription> predicate) {
    IScope parentScope = super.getScope(resource, ignoreCase, type, predicate);
    List<IEObjectDescription> descs = Lists.newArrayList();
    for(EObject eObj : res.getContents()) {
        if (eObj instanceof Strategy) {
            Strategy strategy = (Strategy) eObj;
            descs.add(EObjectDescription.create(strategy.getName(), strategy));
        }
    }
    return new SimpleScope(parentScope, descs);
}
项目:eclectic    文件:ApiDescriptionLanguageScopeProvider.java   
public IScope scope_SetFeature_feature(SetFeature this_, EReference ref) {
    SimpleClassMapping mapping = (SimpleClassMapping) EcoreUtil2.getContainerOfType(this_, ClassMapping.class);
    EList<FeatureMapping> featureMappings = mapping.getFeatureMappings();
    LinkedList<IEObjectDescription> desc = new LinkedList<IEObjectDescription>();
        for (FeatureMapping featureMapping : featureMappings) {         
        desc.add(EObjectDescription.create(featureMapping.getFeatureName(), featureMapping));           
    }
        return new SimpleScope(desc);
}
项目:eclectic    文件:ApiDescriptionLanguageScopeProvider.java   
public IScope scope_SimpleReferenceMapping_type(SimpleReferenceMapping this_, EReference ref) {
    ApiDescription api = (ApiDescription) EcoreUtil2.getContainerOfType(this_, ApiDescription.class);
    EList<ClassMapping> classMappings = api.getClassMappings();
    LinkedList<IEObjectDescription> desc = new LinkedList<IEObjectDescription>();
        for (ClassMapping classMapping : classMappings) {
            SimpleClassMapping m = (SimpleClassMapping) classMapping;
        desc.add(EObjectDescription.create(m.getMetaclassName(), classMapping));            
    }
        return new SimpleScope(desc);
}
项目:eclectic    文件:ApiDescriptionLanguageScopeProvider.java   
public IScope scope_Constructor_parameters(Constructor this_, EReference ref) {
    SimpleClassMapping mapping = (SimpleClassMapping) EcoreUtil2.getContainerOfType(this_, ClassMapping.class);
    EList<FeatureMapping> featureMappings = mapping.getFeatureMappings();
    LinkedList<IEObjectDescription> desc = new LinkedList<IEObjectDescription>();
        for (FeatureMapping featureMapping : featureMappings) {         
        desc.add(EObjectDescription.create(featureMapping.getFeatureName(), featureMapping));           
    }
        return new SimpleScope(desc);
}
项目:xtext-core    文件:Scopes.java   
/**
 * creates a scope using the passed function to compute the names and sets the passed scope as the parent scope
 */
public static <T extends EObject> IScope scopeFor(Iterable<? extends T> elements,
        final Function<T, QualifiedName> nameComputation, IScope outer) {
    return new SimpleScope(outer,scopedElementsFor(elements, nameComputation));
}
项目:xtext-core    文件:ScopeTest.java   
private AbstractScope getEcoreClassifiersScope() {
    return new SimpleScope(getEcoreClassesScope(),Scopes.scopedElementsFor(Iterables.filter(EcorePackage.eINSTANCE.getEClassifiers(),
                    EDataType.class)));
}
项目:xtext-core    文件:ScopeTest.java   
private AbstractScope getEcoreClassesScope() {
    return new SimpleScope(IScope.NULLSCOPE,Scopes.scopedElementsFor(Iterables
                    .filter(EcorePackage.eINSTANCE.getEClassifiers(), EClass.class)));
}
项目:CooperateModelingEnvironment    文件:CooperateGlobalScopeProvider.java   
private IScope createScopeForStream(Stream<EObject> results, Predicate<IEObjectDescription> predicate) {
    Collection<IEObjectDescription> descriptions = results.map(this::getDescriptionFor).flatMap(Collection::stream)
            .filter(Objects::nonNull).filter(d -> predicate == null ? true : predicate.apply(d))
            .collect(Collectors.toList());
    return new SimpleScope(descriptions);
}
项目:dsl-devkit    文件:ScopeScopeProvider.java   
/**
 * Create a scope for the given elements, using their "name" attribute for the name.
 * 
 * @param elements
 *          The elements
 * @return The scope
 */
private IScope createENamedElementScope(final Iterable<? extends ENamedElement> elements) {
  return new SimpleScope(IScope.NULLSCOPE, EObjectDescriptions.all(elements, EcorePackage.Literals.ENAMED_ELEMENT__NAME));
}
项目:dsl-devkit    文件:ExportScopeProvider.java   
/**
 * Create a scope for the given elements, using their "name" attribute for the name.
 * 
 * @param elements
 *          The elements
 * @return The scope
 */
private IScope createENamedElementScope(final Iterable<? extends ENamedElement> elements) {
  return new SimpleScope(IScope.NULLSCOPE, EObjectDescriptions.all(elements, EcorePackage.Literals.ENAMED_ELEMENT__NAME));
}
项目:dsl-devkit    文件:ValidScopeProvider.java   
/**
 * Creates a scope in which the elements are referenced by their name.
 * 
 * @param elements
 *          the elements
 * @return the i scope
 */
private IScope createENamedElementScope(final Iterable<? extends ENamedElement> elements) {
  return new SimpleScope(IScope.NULLSCOPE, EObjectDescriptions.all(elements, EcorePackage.Literals.ENAMED_ELEMENT__NAME));
}