use of org.eclipse.n4js.ts.types.TMember 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.n4js.ts.types.TMember in project n4js by eclipse.
the class ComposedMemberFactory method create.
@Override
public TMember create(String name) {
if (specialMemberFactory == null)
return null;
TMember composedMember = specialMemberFactory.create(name);
composedMember.getConstituentMembers().addAll(getConstituentMembers());
return composedMember;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSReferenceQueryExecutor method getMemberMatrix.
private MemberMatrix getMemberMatrix(TMember member) {
TClassifier tclassifier = (TClassifier) member.eContainer();
MemberCollector memberCollector = containerTypesHelper.fromContext(tclassifier);
MemberCube memberCube = new MemberCube(tclassifier, memberCollector);
NameStaticPair nsp = NameStaticPair.of(member);
Optional<Entry<NameStaticPair, MemberMatrix>> ret = memberCube.entrySet().stream().filter(entry -> entry.getKey().equals(nsp)).findFirst();
if (ret.isPresent()) {
Entry<NameStaticPair, MemberMatrix> mmEntry = ret.get();
return mmEntry.getValue();
}
return null;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSReferenceQueryExecutor method getTargetURIs.
/**
* Here, we add overridden/overriding members or super/subclasses if needed depending on user preferences when
* finding references.
*/
@Override
protected Iterable<URI> getTargetURIs(EObject primaryTarget) {
@SuppressWarnings("restriction") Iterable<URI> originalResult = super.getTargetURIs(primaryTarget);
List<URI> newResult = Lists.newArrayList(originalResult);
if (primaryTarget instanceof LiteralOrComputedPropertyName) {
primaryTarget = primaryTarget.eContainer();
}
// Handling for various configurations e.g. consider overriden members
List<EObject> realTargets = new ArrayList<>();
if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
// In case of composed member, add the constituent members instead.
List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
for (TMember constituentMember : constituentMembers) {
realTargets.add(constituentMember);
}
} else {
// Standard case
realTargets.add(primaryTarget);
}
for (EObject realTarget : realTargets) {
if (N4JSReferenceQueryExecutor.considerOverridenMethods) {
// Add overriden members
if (realTarget instanceof N4MemberDeclaration || // Only consider members within a classifier.Ignore TStructMember.
(realTarget instanceof TMember && realTarget.eContainer() instanceof TClassifier)) {
TMember tmember;
if (primaryTarget instanceof N4MemberDeclaration) {
tmember = ((N4MemberDeclaration) primaryTarget).getDefinedTypeElement();
} else {
tmember = (TMember) primaryTarget;
}
for (TMember inheritedOrImplementedMember : getInheritedAndImplementedMembers(tmember)) {
URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(inheritedOrImplementedMember);
newResult.add(uri);
}
}
}
}
return newResult;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSReferenceQueryExecutor method getInheritedAndImplementedMembers.
private List<TMember> getInheritedAndImplementedMembers(TMember tmember) {
List<TMember> ret = new ArrayList<>();
MemberMatrix mm = getMemberMatrix(tmember);
if (mm != null) {
for (TMember member : mm.inherited()) {
ret.add(member);
}
for (TMember member : mm.implemented()) {
ret.add(member);
}
}
return ret;
}
Aggregations