org.eclipse.xtext.scoping.IScope Java Examples
The following examples show how to use
org.eclipse.xtext.scoping.IScope.
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: ExpressionScope.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected IScope getFeatureScope(Anchor anchor) { IScope cached = cachedFeatureScope.get(anchor); if (cached != null) return cached; if (anchor != Anchor.RECEIVER) { cached = createSimpleFeatureCallScope(); cachedFeatureScope.put(anchor, cached); return cached; } else if (context instanceof XExpression) { cached = createFeatureCallScopeForReceiver(null); // receiver is missing intentionally cachedFeatureScope.put(anchor, cached); return cached; } cachedFeatureScope.put(anchor, IScope.NULLSCOPE); return IScope.NULLSCOPE; }
Example #2
Source File: NonVersionAwareContextScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Instantiates a new {@link FailedToInferContextVersionWrappingScope} that wraps around the given scope and * decorates all of its descriptions. * * @param parent * The parent scope to wrap around * @param versionAwareContextSupport * Specifies whether the scope context allows for <code>@VersionAware</code> contexts (e.g. N4IDL). * @param messageHelper * An injected instance of {@link ValidatorMessageHelper} * */ public NonVersionAwareContextScope(IScope parent, boolean versionAwareContextSupport, ValidatorMessageHelper messageHelper) { super(parent, d -> { EObject element = d.getEObjectOrProxy(); if (null != element && !element.eIsProxy()) { // wrap all elements that are in a version-aware context return !VersionUtils.isVersionAwareContext(element); } else { // leave all non-version-aware descriptions un-decorated return true; } }); // store service dependencies in fields this.messageHelper = messageHelper; // store whether context supports versioned types this.versionAwareContextSupport = versionAwareContextSupport; }
Example #3
Source File: XtextMetamodelReferenceHelper.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
static List<EObject> findBestMetamodelForType(TypeRef context, final String alias, String typeName, IScope scope) { final List<AbstractMetamodelDeclaration> generatedMetamodels = new ArrayList<AbstractMetamodelDeclaration>(); final List<AbstractMetamodelDeclaration> importedMetamodels = new ArrayList<AbstractMetamodelDeclaration>(); filterMetamodelsInScope(alias, scope, generatedMetamodels, importedMetamodels); final List<AbstractMetamodelDeclaration> exactMatches = new ArrayList<AbstractMetamodelDeclaration>(); filterExactMatches(alias, importedMetamodels, exactMatches); List<EObject> result = findReferencedMetamodelWithType(typeName, exactMatches); if (result != null) return result; result = findReferencedMetamodelWithType(typeName, importedMetamodels); if (result != null) return result; result = findSingleElementInCollections(alias, generatedMetamodels); if (result != null) return result; result = findSingleElementInCollections(alias, importedMetamodels); if (result != null) return result; return Collections.emptyList(); }
Example #4
Source File: SerializerScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { int segmentIndex = countSegments(call); String packageName = ((JvmDeclaredType) type).getPackageName(); List<String> splitted = Strings.split(packageName, '.'); String segment = splitted.get(segmentIndex); return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE); } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget(); if (target.isPackageFragment()) { String qualifiedName = type.getQualifiedName(); int dot = qualifiedName.lastIndexOf('.'); String simpleName = qualifiedName.substring(dot + 1); return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE); } else { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } } }
Example #5
Source File: SGenGlobalScopeProvider.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * Overidden to avoid scope nesting which comes with shadowing problems when * potential elements in scope have the same name */ @Override protected IScope getScope(IScope parent, final Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) { IScope result = parent; if (context == null || context.getResourceSet() == null) return result; List<IContainer> containers = Lists.newArrayList(getVisibleContainers(context)); Collections.reverse(containers); List<IEObjectDescription> objectDescriptions = new ArrayList<IEObjectDescription>(); Iterator<IContainer> iter = containers.iterator(); while (iter.hasNext()) { IContainer container = iter.next(); result = createContainerScopeWithContext(context, IScope.NULLSCOPE, container, filter, type, ignoreCase); Iterables.addAll(objectDescriptions, result.getAllElements()); } return new SimpleScope(objectDescriptions); }
Example #6
Source File: ReferenceResolutionFinder.java From n4js with Eclipse Public License 1.0 | 6 votes |
private IEObjectDescription getCandidateViaScope(IScope scope) { // performance issue: scope.getElements List<IEObjectDescription> elements = Lists.newArrayList(scope.getElements(QualifiedName.create(shortName))); if (elements.isEmpty()) { return null; } if (elements.size() > 1) { for (IEObjectDescription element : elements) { if (isEqualCandidateName(element, qualifiedName)) { return element; } } } if (!elements.isEmpty()) { return elements.get(0); } return null; }
Example #7
Source File: URINormalizationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testGetElementByClasspathURIEObject() throws Exception { with(ImportUriTestLanguageStandaloneSetup.class); Main main = (Main) getModel("import 'classpath:/org/eclipse/xtext/linking/05.importuritestlanguage'\n" + "type Bar extends Foo"); Type bar = main.getTypes().get(0); Type foo = bar.getExtends(); assertNotNull(foo); assertFalse(foo.eIsProxy()); // we don't put contextual classpath:/ uris into the index thus // they are partially normalized if (Platform.isRunning()) { assertEquals("bundleresource", EcoreUtil.getURI(foo).scheme()); } else { assertEquals("file", EcoreUtil.getURI(foo).scheme()); } IScopeProvider scopeProvider = get(IScopeProvider.class); IScope scope = scopeProvider.getScope(bar, ImportedURIPackage.Literals.TYPE__EXTENDS); Iterable<IEObjectDescription> elements = scope.getElements(foo); assertEquals(1, size(elements)); assertEquals(EcoreUtil2.getPlatformResourceOrNormalizedURI(foo), elements.iterator().next().getEObjectURI()); }
Example #8
Source File: ReferenceUpdater.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference upd) { IUpdatableReference updatable = upd; if (rewriter.isModified(updatable.getReferenceRegion())) { return; } IScope scope = scopeProvider.getScope(updatable.getSourceEObject(), updatable.getEReference()); ISemanticRegion region = updatable.getReferenceRegion(); QualifiedName oldName = nameConverter.toQualifiedName(region.getText()); IEObjectDescription oldDesc = scope.getSingleElement(oldName); if (oldDesc != null && oldDesc.getEObjectOrProxy() == updatable.getTargetEObject()) { return; } String newName = findValidName(updatable, scope); if (newName != null) { rewriter.replace(region, newName); } }
Example #9
Source File: UserDataAwareScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Factory method to produce a scope. The factory pattern allows to bypass the explicit object creation if the * produced scope would be empty. * * @param canLoadFromDescriptionHelper * utility to decide if a resource must be loaded from source or may be loaded from the index. */ public static IScope createScope( IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase, ResourceSet resourceSet, CanLoadFromDescriptionHelper canLoadFromDescriptionHelper, IContainer container) { if (selectable == null || selectable.isEmpty()) return outer; IScope scope = new UserDataAwareScope(outer, selectable, filter, type, ignoreCase, resourceSet, canLoadFromDescriptionHelper, container); return scope; }
Example #10
Source File: AbstractRecursiveScope.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * For debugging. * * @return A string representation of the scope useful for debugging. */ @SuppressWarnings("nls") @Override public String toString() { final StringBuilder result = new StringBuilder(getClass().getName()); result.append('@'); result.append(Integer.toHexString(hashCode())); result.append(" (id: "); result.append(getId()); result.append(')'); final IScope outerScope = getParent(); if (outerScope != IScope.NULLSCOPE) { result.append("\n >> "); result.append(outerScope.toString().replaceAll("\\\n", "\n ")); } return result.toString(); }
Example #11
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 #12
Source File: ProjectImportEnablingScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Wraps the given parent scope to enable project imports (see {@link ProjectImportEnablingScope} for details). * <p> * To support tests that use multiple projects without properly setting up IN4JSCore, we simply return 'parent' in * such cases; however, project imports will not be available in such tests. * * @param importDecl * if an import declaration is provided, imported error reporting will be activated (i.e. an * {@link IEObjectDescriptionWithError} will be returned instead of <code>null</code> in case of * unresolvable references). */ public static IScope create(IN4JSCore n4jsCore, Resource resource, Optional<ImportDeclaration> importDecl, IScope parent, IScope delegate) { if (n4jsCore == null || resource == null || importDecl == null || parent == null) { throw new IllegalArgumentException("none of the arguments may be null"); } if (importDecl.isPresent() && importDecl.get().eResource() != resource) { throw new IllegalArgumentException("given import declaration must be contained in the given resource"); } final Optional<? extends IN4JSProject> contextProject = n4jsCore.findProject(resource.getURI()); if (!contextProject.isPresent()) { // we failed to obtain an IN4JSProject for the project containing 'importDecl' // -> it would be best to throw an exception in this case, but we have many tests that use multiple projects // without properly setting up the IN4JSCore; to not break those tests, we return 'parent' here return parent; } return new ProjectImportEnablingScope(n4jsCore, contextProject.get(), importDecl, parent, delegate); }
Example #13
Source File: MapBasedScope.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase) { Map<QualifiedName, IEObjectDescription> map = null; for(IEObjectDescription description: descriptions) { if (map == null) map = new LinkedHashMap<QualifiedName, IEObjectDescription>(4); QualifiedName name = ignoreCase ? description.getName().toLowerCase() : description.getName(); IEObjectDescription previous = map.put(name, description); // we are optimistic that no duplicate names are used // however, if the name was already used, the first one should win if (previous != null) { map.put(name, previous); } } if (map == null || map.isEmpty()) { return parent; } return new MapBasedScope(parent, map, ignoreCase); }
Example #14
Source File: FeatureScopes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IScope createImplicitExtensionScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type != null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createStaticExtensionsScope(featureCall, implicitReceiver, type, true, parent, session); } } return parent; }
Example #15
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 #16
Source File: MultimapBasedScope.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase) { Multimap<QualifiedName, IEObjectDescription> map = null; for(IEObjectDescription description: descriptions) { if (map == null) map = LinkedHashMultimap.create(5,2); if (ignoreCase) map.put(description.getName().toLowerCase(), description); else map.put(description.getName(), description); } if (map == null || map.isEmpty()) { return parent; } return new MultimapBasedScope(parent, map, ignoreCase); }
Example #17
Source File: ExportScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Create a scope for any EClass reference, containing all the EClasses of the package the export section is for. * * @param context * The Export * @param reference * The EReference * @return The scope */ // CHECKSTYLE:OFF (MethodName) public IScope scope_EClass(final ExportModel context, final EReference reference) { // CHECKSTYLE:ON IScope result = IScope.NULLSCOPE; for (Import importedPackage : context.getImports()) { result = createEClassScope(result, importedPackage); } return result; }
Example #18
Source File: MemberScope.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * @see MemberScopeFactory#create(ContainerType, EObject, boolean, boolean, boolean) */ MemberScope(ContainerTypesHelper containerTypesHelper, ContainerType<?> type, EObject context, boolean staticAccess, boolean structFieldInitMode, boolean isDynamicType, JavaScriptVariantHelper jsVariantHelper) { super(IScope.NULLSCOPE, context, staticAccess, structFieldInitMode, isDynamicType, jsVariantHelper); this.containerTypesHelper = containerTypesHelper; this.type = type; this.members = null; }
Example #19
Source File: StaticFeatureScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public StaticFeatureScope( IScope parent, IFeatureScopeSession session, XAbstractFeatureCall featureCall, XExpression receiver, LightweightTypeReference receiverType, TypeBucket bucket, OperatorMapping operatorMapping) { super(parent, session, featureCall, operatorMapping); this.receiver = receiver; this.receiverType = receiverType; this.bucket = bucket; }
Example #20
Source File: ImportingTypesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public FQNImporter(Resource context, ITextViewer viewer, IScope scope, IQualifiedNameConverter qualifiedNameConverter, IValueConverter<String> valueConverter, RewritableImportSection.Factory importSectionFactory, ReplaceConverter replaceConverter) { super(context, scope, qualifiedNameConverter, valueConverter); this.viewer = viewer; this.importSectionFactory = importSectionFactory; this.replaceConverter = replaceConverter; }
Example #21
Source File: Bug287941TestLanguageRuntimeModule.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public IScope scope_FromEntry(MQLquery _this, EClass type) { Iterable<IEObjectDescription> transformed = transform( _this.getFromEntries(), new Function<FromEntry, IEObjectDescription>() { @Override public IEObjectDescription apply(FromEntry from) { return EObjectDescription.create(QualifiedName.create(from.getAlias()), from); } }); return new SimpleScope(IScope.NULLSCOPE, transformed); }
Example #22
Source File: ImportedNamesRecordingScopeAccess.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Obtain a global scope to lookup polyfills. Any request by name on the returned scope will record the name in the * list of imported names of the given context resource. */ public IScope getRecordingPolyfillScope(Resource context) { ImportedNamesAdapter importedNamesAdapter = getImportedNamesAdapter(context); IScope scope = globalScopeProvider.getScope(context, TypeRefsPackage.Literals.PARAMETERIZED_TYPE_REF__DECLARED_TYPE, null); return importedNamesAdapter.wrap(scope); }
Example #23
Source File: XtextScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected IScope createScope(Resource resource, EClass type, IScope parent) { if (resource.getContents().size() < 1) throw new IllegalArgumentException("resource is not as expected: contents.size == " + resource.getContents().size() + " but expected: >= 1"); final EObject firstContent = resource.getContents().get(0); if (!(firstContent instanceof Grammar)) return parent; return createScope((Grammar) firstContent, type, parent); }
Example #24
Source File: AbstractJavaBasedContentProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void lookupCrossReference(IScope scope, EObject model, EReference reference, ICompletionProposalAcceptor acceptor, Predicate<IEObjectDescription> filter, Function<IEObjectDescription, ICompletionProposal> proposalFactory) { Function<IEObjectDescription, ICompletionProposal> wrappedFactory = getWrappedFactory(model, reference, proposalFactory); Iterable<IEObjectDescription> candidates = queryScope(scope, model, reference, filter); for (IEObjectDescription candidate : candidates) { if (!acceptor.canAcceptMoreProposals()) return; if (filter.apply(candidate)) { acceptor.accept(wrappedFactory.apply(candidate)); } } }
Example #25
Source File: XbaseBatchScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public IScope getScope(EObject context, EReference reference) { if (context == null || context.eResource() == null || context.eResource().getResourceSet() == null) { return IScope.NULLSCOPE; } if (isFeatureCallScope(reference)) { IExpressionScope.Anchor anchor = IExpressionScope.Anchor.BEFORE; if (context instanceof XAbstractFeatureCall) { EObject proxyOrResolved = (EObject) context.eGet(reference, false); if (proxyOrResolved != null && !proxyOrResolved.eIsProxy()) { XExpression receiver = ((XAbstractFeatureCall) context).getActualReceiver(); if (receiver == null && context instanceof XMemberFeatureCall) { receiver = ((XMemberFeatureCall) context).getMemberCallTarget(); } if (receiver != null) { anchor = IExpressionScope.Anchor.RECEIVER; context = receiver; } } else if (context instanceof XBinaryOperation) { context = ((XBinaryOperation) context).getLeftOperand(); anchor = IExpressionScope.Anchor.RECEIVER; } else if (context instanceof XMemberFeatureCall) { context = ((XMemberFeatureCall) context).getMemberCallTarget(); anchor = IExpressionScope.Anchor.RECEIVER; } } IExpressionScope expressionScope = typeResolver.resolveTypes(context).getExpressionScope(context, anchor); return expressionScope.getFeatureScope(); } if (isTypeScope(reference)) { return typeScopes.createTypeScope(context, reference); } return delegateGetScope(context, reference); }
Example #26
Source File: CompositeScope.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new {@link CompositeScope}; if no scopes are given, {@link IScope#NULLSCOPE} is returned. */ public static final IScope create(IScope... scopes) { if (scopes.length == 0) { return IScope.NULLSCOPE; } return new CompositeScope(scopes); }
Example #27
Source File: SerializerScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IScope doGetTypeScope(XAbstractFeatureCall call, JvmType type) { if (call instanceof XFeatureCall) { return doGetTypeScope((XFeatureCall) call, type); } else if (call instanceof XMemberFeatureCall) { return doGetTypeScope((XMemberFeatureCall) call, type); } else { return IScope.NULLSCOPE; } }
Example #28
Source File: XtendSerializerScopeProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected IScope doCreateConstructorCallSerializationScope(XConstructorCall context) { if (context.eContainer() instanceof AnonymousClass) { final AnonymousClass anonymousClass = (AnonymousClass) context.eContainer(); final JvmType superType = anonymousClassUtil.getSuperType(anonymousClass); if(superType != null) { return createAnonymousClassConstructorScope(context, superType); } } return super.doCreateConstructorCallSerializationScope(context); }
Example #29
Source File: ConstructorScopes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Creates the constructor scope for {@link XConstructorCall}. * The scope will likely contain descriptions for {@link JvmConstructor constructors}. * If there is not constructor declared, it may contain {@link JvmType types}. * * @param session the currently available visibilityHelper data * @param reference the reference that will hold the resolved constructor * @param resolvedTypes the currently known resolved types */ public IScope createConstructorScope(EObject context, EReference reference, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { if (!(context instanceof XConstructorCall)) { return IScope.NULLSCOPE; } /* * We use a type scope here in order to provide better feedback for users, * e.g. if the constructor call refers to an interface or a primitive. */ final IScope delegateScope = typeScopes.createTypeScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, session, resolvedTypes); IScope result = new ConstructorTypeScopeWrapper(context, session, delegateScope); return result; }
Example #30
Source File: ImportScope.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public ImportScope(List<ImportNormalizer> namespaceResolvers, IScope parent, ISelectable importFrom, EClass type, boolean ignoreCase) { super(parent, ignoreCase); this.type = type; this.normalizers = removeDuplicates(namespaceResolvers); this.importFrom = importFrom; }