use of org.eclipse.n4js.ts.types.TClassifier in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method createMemberValidationList.
private MemberCube createMemberValidationList() {
MemberCollector memberCollector = containerTypesHelper.fromContext(getCurrentClassifierDefinition());
TClassifier tClassifier = getCurrentClassifier();
return new MemberCube(tClassifier, memberCollector);
}
use of org.eclipse.n4js.ts.types.TClassifier in project n4js by eclipse.
the class PolyfillValidatorFragment method holdsPolyfill.
/**
* Checks polyfill constraints on given class declaration using validator to issue errors. Constraints (Polyfill
* Class) 156: Polyfill
*/
public boolean holdsPolyfill(N4JSClassValidator validator, N4ClassDeclaration n4Class) {
boolean isStaticPolyFill = isStaticPolyfill(n4Class);
if (isStaticPolyFill || isPolyfill(n4Class)) {
PolyfillValidationState state = new PolyfillValidationState();
state.host = validator;
state.n4Class = n4Class;
state.name = n4Class.getName();
if (state.name == null || !(n4Class.getDefinedType() instanceof TClass)) {
// consequential error, AST corrupt
return true;
}
state.polyType = (TClass) n4Class.getDefinedType();
if (state.polyType == null || state.name == null) {
// consequential error
return true;
}
if (!holdsExpliciteExtends(state)) {
return false;
}
final Type superType = n4Class.getSuperClassRef().getDeclaredType();
if (!(superType instanceof TClassifier)) {
// consequential error
return true;
}
state.filledType = (TClassifier) superType;
// Different rules for static/non-static polyfills:
if (!isStaticPolyFill) {
if (!(//
holdPolyfillName(state) && //
holdsProvidedByRuntime(state) && //
holdsNoImplementsOrConsumes(state) && //
holdsEqualModifiers(state) && //
holdsEqualTypeVariables(state) && //
holdsSinglePolyfillSource(state))) {
return false;
}
} else {
// static polyfill case, IDE-1735
if (!(//
holdPolyfillName(state) && // && holdsNoImplementsOrConsumes(state) //
holdsFilledClassIsStaticPolyfillAware(//
state) && //
holdsSameJavascriptVariant(state) && //
holdsEqualModifiers(state) && //
holdsEqualTypeVariables(state) && //
holdsSinglePolyfillSource(state))) {
return false;
}
}
}
// ยง 140.1 only polyfills are allowed in StaticPolyfillModule.
if (!isStaticPolyFill && isContainedInStaticPolyfillModule(n4Class)) {
// n4Class is toplevel by default
validator.addIssue(getMessageForPOLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES(), n4Class, N4_TYPE_DECLARATION__NAME, POLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES);
return false;
}
return true;
}
use of org.eclipse.n4js.ts.types.TClassifier 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.TClassifier 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.TClassifier 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;
}
Aggregations