use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class FilterWithErrorMarkerScope method getSingleElement.
/**
* Returns the first not filtered element found in the parent scope; if no such element is found, an
* {@link IEObjectDescriptionWithError} is created for the element originally found in the parent scope by that
* name.
* <p>
* Note that the extended behavior of looking for possibly shadowed elements makes only sense if the parent's
* {@link IScope#getElements(QualifiedName)} returns more than one element and if
* {@link IScope#getSingleElement(EObject)} is only an optimization in case only one element is present.
*/
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
IEObjectDescription result = parent.getSingleElement(name);
if (result == null || isAccepted(result)) {
return result;
}
Iterable<IEObjectDescription> allElements = parent.getElements(name);
for (IEObjectDescription description : allElements) {
if (isAccepted(description)) {
return description;
}
}
return wrapFilteredDescription(result);
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class PolyfillValidatorFragment method holdsSinglePolyfillSource.
/**
* Constraints 129 (Applying Polyfills) No member must be filled by more than one polyfill.
*/
private boolean holdsSinglePolyfillSource(PolyfillValidationState state) {
EList<TMember> myPolyMember = state.polyType.getOwnedMembers();
// a) find references to the filled type
// b) check, that they are in the same Project
// c) search for clashing contributions.
XtextResource res = (XtextResource) state.polyType.eResource();
IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(res);
// a+b) all polyfills to same calssifier in same project:
IContainer container = containerManager.getContainer(res.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res), index);
// Iterable over all exported Polyfills
Iterable<IEObjectDescription> iterEObj = container.getExportedObjects(TypesPackage.Literals.TCLASSIFIER, N4TSQualifiedNameProvider.getPolyfillFQN(state.filledType, qualifiedNameProvider), false);
// collection of involved TModules for each Member.
ListMultimap<TMember, TModule> clashProviders = LinkedListMultimap.create();
for (IEObjectDescription pivotObjectDescription : iterEObj) {
EObject eob = pivotObjectDescription.getEObjectOrProxy();
// Resolve
if (eob.eIsProxy()) {
eob = EcoreUtil.resolve(eob, res);
}
if (eob == state.polyType) {
// saw myself .-.
continue;
}
EList<TMember> pivotPolyMember = ((TClassifier) eob).getOwnedMembers();
ListMultimap<TMember, TMember> clashing = findClashingMembersByName(myPolyMember, pivotPolyMember);
for (TMember myMember : clashing.keySet()) {
// only interested in the module, so first is sufficient
clashProviders.put(myMember, clashing.get(myMember).get(0).getContainingModule());
}
}
List<TMember> sortedMembers = clashProviders.keySet().stream().sorted().collect(Collectors.toList());
for (TMember myMember : sortedMembers) {
// Combine list of Modules involved in the polyfill clash.
String uris = Stream.concat(Stream.of(myMember.getContainingModule()), clashProviders.get(myMember).stream()).map(u -> u.getQualifiedName().toString()).sorted().reduce("", (a, b) -> a + PREFIX_LIST + b);
if (uris.startsWith(PREFIX_LIST))
uris = uris.substring(PREFIX_LIST.length());
int lastPrefix_idx = uris.lastIndexOf(PREFIX_LIST);
if (lastPrefix_idx >= 0) {
StringBuffer sb = new StringBuffer(uris);
uris = sb.replace(lastPrefix_idx, lastPrefix_idx + PREFIX_LIST.length(), " and ").toString();
}
// give Qualified name filled in Property.
String memberAxis = myMember.getContainingType().getName() + "." + myMember.getName();
// Issue on filled Member-name declaration:
String msg = IssueCodes.getMessageForCLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT(uris, memberAxis);
state.host.addIssue(msg, myMember.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, IssueCodes.CLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT);
}
return true;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class IntersectionMemberScope method getCheckedDescription.
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
IEObjectDescription description = EObjectDescription.create(member.getName(), member);
QualifiedName qn = QualifiedName.create(name);
boolean allDescrWithError = true;
for (IScope currSubScope : subScopes) {
IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
allDescrWithError &= descrWithError;
}
if (allDescrWithError) {
return createComposedMemberDescriptionWithErrors(description);
}
return description;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class UnionMemberScope method getCheckedDescription.
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
IEObjectDescription description = EObjectDescription.create(member.getName(), member);
QualifiedName qn = QualifiedName.create(name);
for (IScope currSubScope : subScopes) {
IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
if (descrWithError) {
return createComposedMemberDescriptionWithErrors(description);
}
}
return description;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class ImportProvidedElementLabelprovider method getText.
@Override
public String getText(Object element) {
if (element instanceof ImportableObject) {
ImportableObject io = (ImportableObject) element;
return getText(io.getTe());
}
if (element instanceof ImportProvidedElement) {
ImportProvidedElement ele = ((ImportProvidedElement) element);
TModule tm = ((ImportDeclaration) ele.getImportSpecifier().eContainer()).getModule();
return ele.getLocalName() + " from " + findLocation(tm);
}
if (element instanceof IEObjectDescription) {
IEObjectDescription ieod = (IEObjectDescription) element;
EObject eo = ieod.getEObjectOrProxy();
if (eo instanceof TExportableElement && !eo.eIsProxy()) {
return getText(eo);
}
return ieod.getName().getLastSegment() + " from " + qualifiedNameConverter.toString(ieod.getName().skipLast(1));
}
if (element instanceof TExportableElement) {
TExportableElement te = (TExportableElement) element;
return te.getName() + " (exported as " + te.getExportedName() + ") from " + findLocation(te.getContainingModule());
}
return n4Labelprovider.getText(element);
}
Aggregations