use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class ScopeXpectMethod method scopeWithPosition.
/**
* Compares scope including resource name and line number.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void scopeWithPosition(//
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
for (IEObjectDescription eo : scope.getAllElements()) {
eo.getEObjectURI();
}
URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(new ScopeAwareIterable(uri, true, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, true, scope));
}
use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class ScopeXpectMethod method scopeWithResource.
/**
* Compares scope including resource name but not line number.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void scopeWithResource(//
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
for (IEObjectDescription eo : scope.getAllElements()) {
eo.getEObjectURI();
}
URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(new ScopeAwareIterable(uri, false, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class N4JSGlobalScopeProvider method createContainerScopeWithContext.
/**
* Creates a new container scope containing only resource descriptions of the current project. With this container a
* {@link UserDataAwareScope} is created.
* <p>
* This method is called for every container (that is source folder or archive) the current project depends on
* according to the settings in the manifest,. This information has been indirectly retrieved via
* {@link org.eclipse.n4js.projectModel.IN4JSProject#getDependencies()}.
*/
@Override
protected IScope createContainerScopeWithContext(Resource resource, IScope parent, IContainer container, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) {
if (resource != null) {
URI uriToFilter = resource.getURI();
// do filter context-resource from scope except in case of static polyfills.
if (container.hasResourceDescription(uriToFilter) && !isStaticPolyFiller(resource))
container = new FilterUriContainer(uriToFilter, container);
IScope result = UserDataAwareScope.createScope(parent, container, filter, type, ignoreCase, resource.getResourceSet(), canLoadFromDescriptionHelper, container);
return result;
}
return IScope.NULLSCOPE;
}
use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class ComposedMemberScope method createComposedMember.
/**
* Key method of entire scoping for composed types e.g. union/intersection types. This creates a new TMember as a
* combination of all members of the given name in the type's contained types. If those members cannot be combined
* into a single valid member, this method creates a dummy placeholder.
*/
private TMember createComposedMember(String memberName) {
// check all subScopes for a member of the given name and
// merge the properties of the existing members into 'composedMember'
final Resource resource = EcoreUtilN4.getResource(request.context, composedTypeRef);
ComposedMemberInfoBuilder cmiBuilder = new ComposedMemberInfoBuilder();
cmiBuilder.init(writeAccess, resource, ts);
for (int idx = 0; idx < subScopes.length; idx++) {
final IScope subScope = subScopes[idx];
final TypeRef typeRef = composedTypeRef.getTypeRefs().get(idx);
final Resource res = EcoreUtilN4.getResource(request.context, composedTypeRef);
final RuleEnvironment GwithSubstitutions = ts.createRuleEnvironmentForContext(typeRef, res);
final TMember member = findMemberInSubScope(subScope, memberName);
cmiBuilder.addMember(member, GwithSubstitutions);
}
// produce result
ComposedMemberInfo cmi = cmiBuilder.get();
ComposedMemberFactory cmf = getComposedMemberFactory(cmi);
if (!cmf.isEmpty()) {
// at least one of the subScopes had an element of that name
final TMember result;
if (cmf.isValid()) {
// success case: The element for that name can be merged into a valid composed member
result = cmf.create(memberName);
} else {
// some of the subScopes do not have an element for that name OR
// they do not form a valid composed member (e.g. they are of different kind)
// -> produce a specific error message explaining the incompatibility
// (this error placeholder will be wrapped with a UncommonMemberDescription
// in #getSingleLocalElementByName(QualifiedName) above)
result = createErrorPlaceholder(memberName);
}
// add composed member to ComposedTypeRef's cache (without notifications to avoid cache-clear)
final ComposedMemberCache cache = getOrCreateComposedMemberCache();
if (cache != null) {
EcoreUtilN4.doWithDeliver(false, () -> {
cache.getCachedComposedMembers().add(result);
}, cache);
}
// if cache==null: simply do not cache the composed member (i.e. member won't be contained in a resource!)
return result;
} else {
// -> produce the ordinary "Cannot resolve reference ..." error by returning 'null'
return null;
}
}
use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class N4JSImportedNamespaceAwareLocalScopeProvider method getResourceScope.
@Override
protected IScope getResourceScope(Resource res, EReference reference) {
EObject context = res.getContents().get(0);
// ||-- changed super-impl here:
// IDE-662 filtering ArgumentsType & EnumBaseType from globalScobe, since it is a VirtualBaseType.
Predicate<IEObjectDescription> filter = p -> {
String name = p.getName().toString();
return !("ArgumentsType".equals(name) || "EnumBaseType".equals(name));
};
IScope globalScope = getGlobalScope(res, reference, filter);
// -- done change --||
List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference));
// IDE-1735 adding support for static-polyfills:
TModule module = (TModule) res.getContents().get(1);
if (module.isStaticPolyfillModule()) {
// limit to situations of resources, that contain at least
// one @StaticPolyfill
normalizers.add(createImportedNamespaceResolver(module.getQualifiedName() + N4JSQualifiedNameConverter.DELIMITER + "*", false));
}
if (!normalizers.isEmpty()) {
globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(), isIgnoreCase(reference));
}
IScope resScope = getResourceScope(globalScope, context, reference);
return resScope;
}
Aggregations