Java Code Examples for org.eclipse.xtext.scoping.IScope

The following examples show how to use org.eclipse.xtext.scoping.IScope. These examples are extracted from open source projects. 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 Project: xtext-core   Source File: MapBasedScope.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 2
Source Project: xtext-core   Source File: ReferenceUpdater.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 3
/**
 * 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 4
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 5
Source Project: n4js   Source File: ReferenceResolutionFinder.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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 6
Source Project: n4js   Source File: ProjectImportEnablingScope.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 7
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 8
Source Project: n4js   Source File: UserDataAwareScope.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 9
Source Project: n4js   Source File: NonVersionAwareContextScope.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 10
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 11
Source Project: xtext-core   Source File: URINormalizationTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 12
Source Project: xtext-extras   Source File: ExpressionScope.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 13
Source Project: dsl-devkit   Source File: AbstractRecursiveScope.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 14
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 15
public IsInScopeWithOptionalPositionPredicate(IQualifiedNameConverter converter, URI currentURI,
		boolean withLineNumber, IScope scope) {
	super();
	this.converter = converter;
	this.scope = scope;
	this.currentURI = currentURI;
	this.withLineNumber = withLineNumber;
}
 
Example 16
public List<EObject> getLinkedOperation(ArgumentExpression context, EReference ref, INode node) {
	final EClass requiredType = ref.getEReferenceType();
	if (requiredType == null) {
		return Collections.<EObject>emptyList();
	}
	final String crossRefString = getCrossRefNodeAsString(node);
	if (crossRefString == null || crossRefString.equals("")) {
		return Collections.<EObject>emptyList();
	}
	final IScope scope = getScope(context, ref);
	final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
	// Adoption to super class implementation here to return multi elements
	final Iterable<IEObjectDescription> eObjectDescription = scope.getElements(qualifiedLinkName);
	int size = Iterables.size(eObjectDescription);
	if (size == 0)
		return Collections.emptyList();
	if (size == 1)
		return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
	// Two operation with same name found here
	List<IEObjectDescription> candidates = new ArrayList<>();
	for (IEObjectDescription currentDescription : eObjectDescription) {
		if (currentDescription.getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) {
			candidates.add(currentDescription);
		}
	}
	Optional<Operation> operation = operationsLinker.linkOperation(candidates, context);
	if (operation.isPresent()) {
		return Collections.singletonList(operation.get());
	}
	//Link to first operation to get parameter errors instead of linking errors
	return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
}
 
Example 17
Source Project: xtext-extras   Source File: FeatureScopes.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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 18
Source Project: dsl-devkit   Source File: ExportScopeProvider.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 19
Source Project: n4js   Source File: SpecInfosByName.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private RepoRelativePath computeRRP(FullMemberReference ref, TMember testMember) {
	IScope scope = globalScopeProvider.getScope(testMember.eResource(),
			N4JSPackage.Literals.IMPORT_DECLARATION__MODULE);
	QualifiedName qn = QualifiedName.create(ref.getModuleName().split("/"));
	IEObjectDescription eod = scope.getSingleElement(qn);
	if (eod != null) {
		FileURI uri = new FileURI(eod.getEObjectURI());
		RepoRelativePath rrp = RepoRelativePath.compute(uri, n4jsCore);
		return rrp;
	} else {
		issueAcceptor.addWarning("Cannot resolve testee " + ref, testMember);
		return null;
	}

}
 
Example 20
protected IScope getResourceScope(Resource res, EReference reference) {
	EObject context = res.getContents().get(0);
	IScope globalScope = getGlobalScope(res, reference);
	List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference));
	if (!normalizers.isEmpty()) {
		globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(), isIgnoreCase(reference));
	}
	return getResourceScope(globalScope, context, reference);
}
 
Example 21
Source Project: n4js   Source File: ReferenceResolutionFinder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private IScope getScopeForContentAssist(ReferenceDescriptor reference) {
	try (Measurement m = contentAssistDataCollectors.dcGetScope().getMeasurement()) {
		IContentAssistScopeProvider contentAssistScopeProvider = (IContentAssistScopeProvider) scopeProvider;
		return contentAssistScopeProvider.getScopeForContentAssist(reference.astNode,
				reference.eReference);
	}
}
 
Example 22
Source Project: n4js   Source File: ReferenceResolutionFinder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a resolution if the given candidate is a valid target element for the given reference text (full name or
 * just prefix, depending on <code>requireFullMatch</code>); otherwise <code>null</code> is returned.
 *
 * @param candidate
 *            the {@link IEObjectDescription} representing the potential target element of the resolution.
 * @param scopeForCollisionCheck
 *            a scope that will be used for a collision check. If the reference being resolved is known to be an
 *            unresolved reference and <code>requireFullMatch</code> is set to <code>true</code>, then this
 *            collision check can safely be omitted.
 * @return the resolution of <code>null</code> if the candidate is not a valid match for the reference.
 */
private ReferenceResolution getResolution(String text, INode parseTreeNode, boolean requireFullMatch,
		IEObjectDescription candidate, Optional<IScope> scopeForCollisionCheck, Predicate<String> conflictChecker) {

	try (Measurement m = contentAssistDataCollectors.dcGetResolution().getMeasurement()) {
		ReferenceResolutionCandidate rrc = new ReferenceResolutionCandidate(candidate, scopeForCollisionCheck, text,
				requireFullMatch, parseTreeNode, conflictChecker);

		if (!rrc.isValid) {
			return null;
		}

		try {
			int version = N4JSResourceDescriptionStrategy.getVersion(candidate);

			String proposal = getProposal(rrc);
			String label = getLabel(rrc, version);
			String description = getDescription(rrc);
			ImportDescriptor importToBeAdded = getImportToBeAdded(rrc);

			return new ReferenceResolution(candidate, proposal, label, description, importToBeAdded);

		} catch (ValueConverterException e) {
			// text does not match the concrete syntax
		}

		return null;
	}
}
 
Example 23
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 24
Source Project: xtext-extras   Source File: StaticFeatureScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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 25
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 26
/**
 * 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 27
Source Project: xtext-core   Source File: XtextScopeProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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 28
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 29
@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 30
Source Project: n4js   Source File: CompositeScope.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}