org.eclipse.xtext.scoping.Scopes Java Examples
The following examples show how to use
org.eclipse.xtext.scoping.Scopes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_02() { maxCallCount = 0; ImmutableList<EClassifier> classifiers = ImmutableList.of( createEClass(), createEDataType() ); for(EClassifier classifier: classifiers) { classifier.setName("Same"); } expected.addAll(classifiers); helper.checkUniqueNames( Scopes.scopedElementsFor(classifiers), this, this); assertEquals(classifiers.size(), callCount); assertTrue(expected.isEmpty()); }
Example #2
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_01() { maxCallCount = 0; ImmutableList<EClass> classes = ImmutableList.of( createEClass(), createEClass() ); for(EClass clazz: classes) { clazz.setName("Same"); } expected.addAll(classes); helper.checkUniqueNames( Scopes.scopedElementsFor(classes), this, this); assertEquals(classes.size(), callCount); assertTrue(expected.isEmpty()); }
Example #3
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_03() { maxCallCount = 0; ImmutableList<ENamedElement> elements = ImmutableList.of( createEClass(), createEDataType(), createEPackage() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } expected.addAll(elements.subList(0, 2)); helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); assertEquals(elements.size(), callCount); assertTrue(expected.isEmpty()); }
Example #4
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_04() { maxCallCount = 0; ImmutableList<ENamedElement> elements = ImmutableList.of( createEClass(), createEDataType(), createEPackage(), createEPackage() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } expected.addAll(elements); helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); assertEquals(elements.size(), callCount); assertTrue(expected.isEmpty()); }
Example #5
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_05() { maxCallCount = 0; ImmutableList<ENamedElement> elements = ImmutableList.of( createEPackage(), createEDataType(), createEPackage() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } expected.add(elements.get(0)); expected.add(elements.get(2)); helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); assertEquals(elements.size(), callCount); assertTrue(expected.isEmpty()); }
Example #6
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_06() { maxCallCount = 1; ImmutableList<ENamedElement> elements = ImmutableList.of( createEPackage(), createEDataType(), createEPackage() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } try { helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); fail("cancellation expected"); } catch (OperationCanceledError e) { } assertEquals(1, callCount); }
Example #7
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testCreatedErrors_07() { maxCallCount = 0; ImmutableList<ENamedElement> elements = ImmutableList.of( createEPackage(), createEDataType(), EcoreFactory.eINSTANCE.createEEnumLiteral() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } expected.add(elements.get(0)); expected.add(elements.get(2)); helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); assertEquals(elements.size(), callCount); assertTrue(expected.isEmpty()); }
Example #8
Source File: SyntheticResourceAwareScopeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public IScope scope_Codetemplates_language(Codetemplates templates, EReference reference) { if (TemplateResourceProvider.SYNTHETIC_SCHEME.equals(templates.eResource().getURI().scheme())) { ResourceSet resourceSet = templates.eResource().getResourceSet(); List<Grammar> grammars = Lists.newArrayListWithExpectedSize(1); for(Resource resource: resourceSet.getResources()) { EObject root = resource.getContents().get(0); if (root instanceof Grammar) { grammars.add((Grammar) root); } } return Scopes.scopeFor(grammars, new Function<Grammar, QualifiedName>() { @Override public QualifiedName apply(Grammar from) { return qualifiedNameConverter.toQualifiedName(from.getName()); } }, IScope.NULLSCOPE); } else { return delegateGetScope(templates, reference); } }
Example #9
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testManyManyDup() { List<ENamedElement> elements = new ArrayList<>(); for(int i = 0, j = 0; i < MANY; i++) { if (i % 100 == 0) { j++; } EClass c = createEClass(); c.setName("i" + j); elements.add(c); } maxCallCount = 0; expected.addAll(elements); helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); }
Example #10
Source File: Bug311337TestLanguageRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public IScope scope_Reference_refChild(NestedRef context, EReference ref) { EList<Child> childList = null; Child child = context.getLeft().getRefChild(); childList = child.getLink().getChild(); IScope newScope = Scopes.scopeFor(childList); return newScope; }
Example #11
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test public void testManyUnique() { List<ENamedElement> elements = new ArrayList<>(); for(int i = 0; i < MANY; i++) { EClass c = createEClass(); c.setName("i" + i); elements.add(c); } maxCallCount = 0; helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); }
Example #12
Source File: TypeSystemAwareScope.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { List<IEObjectDescription> result = Lists.newArrayList(); Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor( EcoreUtil2.<EObject> getObjectsByType(typeSystem.getConcreteTypes(), eClass), qualifiedNameProvider); Iterables.addAll(result, iterable); return result; }
Example #13
Source File: Bug311337TestLanguageRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public IScope scope_Reference_refChild(Reference context, EReference ref) { Definition localClass = null; EList<Child> childList = null; localClass = EcoreUtil2.getContainerOfType(context, Definition.class); childList = localClass.getChild(); IScope newScope = Scopes.scopeFor(childList); return newScope; }
Example #14
Source File: CatalogFromExtensionPointScope.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { loadDefinitions(); if (loadedModel == null) { return ImmutableList.of(); } XtextResource resource = (XtextResource) loadedModel.eResource(); IQualifiedNameProvider nameProvider = resource.getResourceServiceProvider().get(IQualifiedNameProvider.class); return Scopes.scopedElementsFor(ImmutableList.of(loadedModel), nameProvider); }
Example #15
Source File: CheckCfgScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public IScope getScope(final EObject context, final EReference reference) { if (reference == CheckcfgPackage.Literals.CONFIGURED_CHECK__CHECK) { // Note that context object can be either a configured check (if 'optional' keyword has been provided // so that a new instance is created and the configured catalog does not contain any configured checks // yet) or a configured catalog (in all other cases) final ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context, ConfiguredCatalog.class); if (configuredCatalog == null || configuredCatalog.getCatalog() == null) { return IScope.NULLSCOPE; } CheckCatalog catalog = configuredCatalog.getCatalog(); return Scopes.scopeFor(catalog.getAllChecks(), checkQualifiedNameProvider, IScope.NULLSCOPE); } else if (reference == CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER) { // a new list of FormalParameters to scope to EList<FormalParameter> parameters = ECollections.newBasicEList(); final ConfiguredCheck configuredCheck = EcoreUtil2.getContainerOfType(context, ConfiguredCheck.class); if (configuredCheck != null) { // add FormalParameter definitions from linked check parameters.addAll(configuredCheck.getCheck().getFormalParameters()); } // add inferred FormalParameters (properties) final CheckConfiguration checkConfiguration = EcoreUtil2.getContainerOfType(context, CheckConfiguration.class); parameters.addAll(checkConfiguration.getProperties()); return Scopes.scopeFor(parameters, checkQualifiedNameProvider, IScope.NULLSCOPE); } return super.getScope(context, reference); }
Example #16
Source File: STextNamesAreUniqueValidator.java From statecharts with Eclipse Public License 1.0 | 5 votes |
/** * The default implementation checks only for objects that are exported via description strategy. * It should also check for uniqueness of internal elements. */ @Override public void doCheckUniqueNames(Resource resource, CancelIndicator cancelIndicator) { Iterable<EObject> iterable = () -> EcoreUtil.getAllContents(resource, true); List<EObject> candiatates = StreamSupport.stream(iterable.spliterator(), false) .filter((it) -> it instanceof NamedElement).collect(Collectors.toList()); helper.checkUniqueNames(Scopes.scopedElementsFor(candiatates, fqnProvider), cancelIndicator, this); }
Example #17
Source File: TypeSystemAwareScope.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { List<IEObjectDescription> result = Lists.newArrayList(); Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor( EcoreUtil2.<EObject> getObjectsByType(typeSystem.getConcreteTypes(), eClass), qualifiedNameProvider); Iterables.addAll(result, iterable); return result; }
Example #18
Source File: AbstractLibraryGlobalScopeProvider.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected Iterable<IEObjectDescription> getDescriptions(Resource context, URI uri) { List<IEObjectDescription> result = Lists.newArrayList(); ResourceSet set = new ResourceSetImpl(); 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; }
Example #19
Source File: ExpressionsScopeProvider.java From xsemantics with Eclipse Public License 1.0 | 5 votes |
public IScope scope_Variable(Variable variable, EReference ref) { // only the variables declared before this one Model model = EcoreUtil2.getContainerOfType(variable, Model.class); if (model == null) return IScope.NULLSCOPE; EList<Variable> variables = model.getVariables(); return Scopes .scopeFor(variables.subList(0, variables.indexOf(variable))); }
Example #20
Source File: NamesAreUniqueValidationHelperTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test public void testCancel_02() { maxCallCount = 0; helper.checkUniqueNames( Scopes.scopedElementsFor(ImmutableList.of( createEClass(), createEClass() )), this, this); assertEquals(2, callCount); }
Example #21
Source File: AbstractMemberScope.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { Iterable<? extends TMember> iMembers = Iterables.filter(getMembers(), new Predicate<TMember>() { @Override public boolean apply(TMember input) { return input.isStatic() == staticAccess; } }); return Scopes.scopedElementsFor(iMembers); }
Example #22
Source File: ElementReferenceScope.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { List<EObject> result = Lists.newArrayList(); result.addAll(functionMembers()); result.addAll(contractMembers()); return Scopes.scopedElementsFor(result); }
Example #23
Source File: XbaseImportedNamespaceScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ISelectable internalGetAllDescriptions(final Resource resource) { Iterable<EObject> allContents = new Iterable<EObject>(){ @Override public Iterator<EObject> iterator() { return EcoreUtil.getAllContents(resource, false); } }; Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider); return new MultimapBasedSelectable(allDescriptions); }
Example #24
Source File: XImportSectionNamespaceScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ISelectable internalGetAllDescriptions(final Resource resource) { Iterable<EObject> allContents = new Iterable<EObject>(){ @Override public Iterator<EObject> iterator() { return EcoreUtil.getAllContents(resource, false); } }; Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider); return new MultimapBasedSelectable(allDescriptions); }
Example #25
Source File: AbstractTypeScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public IScope createMemberScope(JvmType containerType, Predicate<JvmMember> filter, Function<JvmMember, QualifiedName> names, IScope outer) { if (containerType == null || containerType.eIsProxy()) return outer; if (containerType instanceof JvmDeclaredType) { IScope result = outer; List<JvmTypeReference> superTypes = ((JvmDeclaredType) containerType).getSuperTypes(); for(JvmTypeReference superType: superTypes) { if (superType.getType() != null) result = createMemberScope(superType.getType(), filter, names, result); } List<JvmMember> members = ((JvmDeclaredType) containerType).getMembers(); return Scopes.scopeFor(Iterables.filter(members, filter), names, result); } return outer; }
Example #26
Source File: Bug291022TestLanguageRuntimeModule.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public IScope getScope(EObject context, EReference reference) { if (Bug291022TestLanguagePackage.Literals.MODEL_ELEMENT__SECOND_REFERENCE == reference) { List<EObject> scope = Lists.newArrayList(); if (context instanceof ModelElement) { ModelElement modelElement = (ModelElement) context; if (modelElement.getFirstReference() != null && !modelElement.getFirstReference().eIsProxy()) scope.add(modelElement.getFirstReference()); } return Scopes.scopeFor(scope); } return super.getScope(context, reference); }
Example #27
Source File: CodetemplatesScopeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public IScope scope_Codetemplate_context(Codetemplate template, EReference reference) { Codetemplates root = EcoreUtil2.getContainerOfType(template, Codetemplates.class); if (root != null && root.getLanguage() != null) { Grammar grammar = root.getLanguage(); if (!grammar.eIsProxy()) { LinkedHashSet<AbstractRule> usedRules = Sets.newLinkedHashSet(); new UsedRulesFinder(usedRules).compute(grammar); return Scopes.scopeFor(Iterables.filter(usedRules, ParserRule.class)); } } return IScope.NULLSCOPE; }
Example #28
Source File: ArithmeticsScopeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private IScope getModuleScope(EObject context, EReference reference, Module module, IScope parent) { Iterable<Definition> allDefinitions = IterableExtensions.filter(module.getStatements(), Definition.class); if (context instanceof FunctionCall) { Iterable<Definition> matchingDefs = IterableExtensions.filter(allDefinitions, (d) -> ((FunctionCall) context).getArgs().size() == d.getArgs().size()); return Scopes.scopeFor(matchingDefs, parent); } else { return Scopes.scopeFor(allDefinitions, parent); } }
Example #29
Source File: ArithmeticsScopeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private IScope getDefinitionScope(EObject context, EReference reference, IScope parent) { Definition containingDef = EcoreUtil2.getContainerOfType(context, Definition.class); if (containingDef == null) { return parent; } return Scopes.scopeFor(containingDef.getArgs(), parent); }
Example #30
Source File: SimpleLocalScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected ISelectable getAllDescriptions(final Resource resource) { Iterable<EObject> allContents = new Iterable<EObject>(){ @Override public Iterator<EObject> iterator() { return resource.getAllContents(); } }; Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider); return new MultimapBasedSelectable(allDescriptions); }