org.eclipse.xtext.scoping.impl.SimpleScope Java Examples
The following examples show how to use
org.eclipse.xtext.scoping.impl.SimpleScope.
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: TypeScopes.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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; } }
Example #2
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 #3
Source File: XtextScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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; }
Example #4
Source File: FeatureScopes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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)); } }; }
Example #5
Source File: PersistenceGlobalScopeProvider.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override protected IScope getScope(Resource resource, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> predicate) { IScope parentScope = super.getScope(resource, ignoreCase, type, predicate); List<IEObjectDescription> descs = new ArrayList<>(); 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); }
Example #6
Source File: PersistenceGlobalScopeProvider.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Override protected IScope getScope(Resource resource, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> predicate) { IScope parentScope = super.getScope(resource, ignoreCase, type, predicate); List<IEObjectDescription> descs = new ArrayList<>(); 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); }
Example #7
Source File: ValidScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #8
Source File: ExportScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #9
Source File: ScopeScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #10
Source File: LazyLinkingTestLanguageScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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); } })); }
Example #11
Source File: Bug443705Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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()))); }
Example #12
Source File: XtextScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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; }
Example #13
Source File: XtextScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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()); } })); }
Example #14
Source File: XtextScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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); } })); }
Example #15
Source File: XtextScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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); } })); }
Example #16
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void completeXMemberFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (model instanceof XMemberFeatureCall) { XExpression memberCallTarget = ((XMemberFeatureCall) model).getMemberCallTarget(); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(memberCallTarget); LightweightTypeReference memberCallTargetType = resolvedTypes.getActualType(memberCallTarget); Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(model, input -> { if(input instanceof JvmOperation && input.isStatic()) { List<JvmFormalParameter> parameters = ((JvmOperation) input).getParameters(); if(parameters.size() > 0) { JvmFormalParameter firstParam = parameters.get(0); JvmTypeReference parameterType = firstParam.getParameterType(); if(parameterType != null) { LightweightTypeReference lightweightTypeReference = memberCallTargetType.getOwner().toLightweightTypeReference(parameterType); if(lightweightTypeReference != null) { return memberCallTargetType.isAssignableFrom(lightweightTypeReference); } } } } return false; }); // Create StaticExtensionFeatureDescriptionWithImplicitFirstArgument instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> { QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName()); return new StaticExtensionFeatureDescriptionWithImplicitFirstArgument(qualifiedName, feature, memberCallTarget, memberCallTargetType, 0, true); }); // Scope for all static features IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures); proposeFavoriteStaticFeatures(model, context, acceptor, staticMemberScope); // Regular proposals createReceiverProposals(((XMemberFeatureCall) model).getMemberCallTarget(), (CrossReference) assignment.getTerminal(), context, acceptor); } else if (model instanceof XAssignment) { createReceiverProposals(((XAssignment) model).getAssignable(), (CrossReference) assignment.getTerminal(), context, acceptor); } }
Example #17
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 #18
Source File: SerializerScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IScope getAccessorScope(String simpleName, QualifiedName qn, JvmIdentifiableElement feature) { String shorthandName = PropertyUtil.tryGetShorthandName(simpleName); if (shorthandName != null) { List<IEObjectDescription> result = Lists.newArrayListWithCapacity(2); result.add(EObjectDescription.create(shorthandName, feature)); result.add(EObjectDescription.create(qn, feature)); return new SimpleScope(result); } else { return new SingletonScope(EObjectDescription.create(qn, feature), IScope.NULLSCOPE); } }
Example #19
Source File: Scopes.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * 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)); }
Example #20
Source File: ScopeTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private AbstractScope getEcoreClassifiersScope() { return new SimpleScope(getEcoreClassesScope(),Scopes.scopedElementsFor(Iterables.filter(EcorePackage.eINSTANCE.getEClassifiers(), EDataType.class))); }
Example #21
Source File: ScopeTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private AbstractScope getEcoreClassesScope() { return new SimpleScope(IScope.NULLSCOPE,Scopes.scopedElementsFor(Iterables .filter(EcorePackage.eINSTANCE.getEClassifiers(), EClass.class))); }
Example #22
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void createLocalVariableAndImplicitProposals( EObject context, IExpressionScope.Anchor anchor, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) { String prefix = contentAssistContext.getPrefix(); if (prefix.length() > 0) { if (!Character.isJavaIdentifierStart(prefix.charAt(0))) { if (prefix.length() > 1) { if (prefix.charAt(0) == '^' && !Character.isJavaIdentifierStart(prefix.charAt(1))) { return; } } } } // long time = System.currentTimeMillis(); Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext); IResolvedTypes resolvedTypes = context != null ? typeResolver.resolveTypes(context) : typeResolver.resolveTypes(contentAssistContext.getResource()); IExpressionScope expressionScope = resolvedTypes.getExpressionScope(context, anchor); // TODO use the type name information IScope scope = expressionScope.getFeatureScope(); getCrossReferenceProposalCreator().lookupCrossReference(scope, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory); // System.out.printf("XbaseProposalProvider.createLocalVariableAndImplicitProposals = %d\n", System.currentTimeMillis() - time); // time = System.currentTimeMillis(); // TODO use the type name information proposeDeclaringTypeForStaticInvocation(context, null /* ignore */, contentAssistContext, acceptor); // System.out.printf("XbaseProposalProvider.proposeDeclaringTypeForStaticInvocation = %d\n", System.currentTimeMillis() - time); if(context != null && !(context instanceof XMemberFeatureCall)) { Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(context, input->true); // Create StaticFeatureDescription instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> { QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName()); return new StaticFeatureDescription(qualifiedName, feature, 0, true); }); // Scope for all static features IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures); proposeFavoriteStaticFeatures(context, contentAssistContext, acceptor, staticMemberScope); } }
Example #23
Source File: ScopeScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * 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)); }
Example #24
Source File: ExportScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * 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)); }
Example #25
Source File: ValidScopeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * 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)); }