use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class ComposedMemberScope method getOrCreateComposedMemberCache.
/**
* Returns the composed member cache for the given ComposedTypeRef, creating it if it does not exist yet. Returns
* <code>null</code> if a cache could not be created, because the given type reference is not contained in an
* N4JSResource or this resource does not have a TModule.
*/
private ComposedMemberCache getOrCreateComposedMemberCache() {
if (request.provideContainedMembers) {
final //
MemberAccess contextCasted = // cast is valid, see MemberScopeRequest#provideContainedMembers
(MemberAccess) request.context;
final ComposedMemberCache cache = contextCasted.getComposedMemberCache();
if (cache != null && TypeCompareUtils.isEqual(cache.getComposedTypeRef(), this.composedTypeRef)) {
return cache;
}
// does not exist yet -> create new composed member cache in TModule:
final Resource res = contextCasted.eResource();
final TModule module = res instanceof N4JSResource ? ((N4JSResource) res).getModule() : null;
if (module != null) {
// Search in the module for composed member cache containing equivalent composed type ref
for (ComposedMemberCache existingCache : module.getComposedMemberCaches()) {
if (TypeCompareUtils.isEqual(existingCache.getComposedTypeRef(), composedTypeRef)) {
return existingCache;
}
}
final ComposedMemberCache cacheNew = TypesFactory.eINSTANCE.createComposedMemberCache();
EcoreUtilN4.doWithDeliver(false, () -> {
// Order important due to notification!
cacheNew.setComposedTypeRef(TypeUtils.copyIfContained(composedTypeRef));
module.getComposedMemberCaches().add(cacheNew);
contextCasted.setComposedMemberCache(cacheNew);
}, module, contextCasted);
return cacheNew;
}
}
return null;
}
use of org.eclipse.n4js.ts.types.TModule 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;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method checkAccessibilityAndOverrideCompatibility.
/**
* @param m
* the overriding member
* @param s
* the overridden or implemented member
* @param consumptionConflict
* check override or implementation override, the latter usually stems from a consumption conflict (so
* that s did not get consumed in the first place)
* @param mm
* member matrix, only to improve error message
*/
private OverrideCompatibilityResult checkAccessibilityAndOverrideCompatibility(RedefinitionType redefinitionType, TMember m, TMember s, boolean consumptionConflict, MemberMatrix mm) {
// getter/setter combination not checked here
if (TypeUtils.isAccessorPair(m, s)) {
return OverrideCompatibilityResult.ACCESSOR_PAIR;
}
// of @CovariantConstructor classes or implementing @CovariantConstructor interfaces
if (m.isConstructor() && s.isConstructor() && !(isPolyfill(m) || isCovarianceForConstructorsRequired(m, s))) {
return OverrideCompatibilityResult.COMPATIBLE;
}
// Nr.1 of Constraints 67 (Overriding Members) and Constraints 69 (Implementation of Interface Members)
// --> s must be accessible
final TModule contextModule = m.getContainingModule();
final ContainerType<?> contextType = m.getContainingType();
if (contextModule != null && contextType != null && !memberVisibilityChecker.isVisibleWhenOverriding(contextModule, contextType, contextType, s)) {
if (!consumptionConflict) {
// avoid consequential errors
messageOverrideNonAccessible(redefinitionType, m, s);
}
return OverrideCompatibilityResult.ERROR;
}
// continue checking Constraints 65
return constraints_65_overrideCompatible(redefinitionType, m, s, consumptionConflict, mm);
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method constraints_42_45_46_AbstractMember.
/**
* Constraints 42, 3 (Abstract Member)<br>
* Constraints 45, 4 (Extending Interfaces)<br>
* Constraints 46, 5 (Implementing Interfaces)
*
* This method doesn't add issues for missing override annotations but adds the missing-annotation-members to the
* given collection.
*/
private void constraints_42_45_46_AbstractMember(MemberMatrix mm, Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef) {
N4ClassifierDefinition classifierDefinition = getCurrentClassifierDefinition();
TClassifier classifier = getCurrentClassifier();
TModule contextModule = EcoreUtil2.getContainerOfType(classifier, TModule.class);
for (SourceAwareIterator iter = mm.allMembers(); iter.hasNext(); ) {
TMember m = iter.next();
if (!iter.isOwnedMember() && m.isAbstract()) {
if (!memberVisibilityChecker.isVisibleWhenOverriding(contextModule, classifier, classifier, m)) {
Iterable<ParameterizedTypeRef> superTypeRefs = FindClassifierInHierarchyUtils.findSuperTypesWithMember(classifierDefinition, m);
for (ParameterizedTypeRef superTypeRef : superTypeRefs) {
MemberList<TMember> nonAccessible = nonAccessibleAbstractMembersBySuperTypeRef.get(superTypeRef);
if (nonAccessible == null) {
nonAccessible = new MemberList<>();
nonAccessibleAbstractMembersBySuperTypeRef.put(superTypeRef, nonAccessible);
}
nonAccessible.add(m);
}
}
}
}
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class KeyUtils method getSpecKeyWithoutProjectFolder.
/**
* @return a unique key for the given element. The source folder is not part of the key. Instead, only the module
* name is used.
*/
public static String getSpecKeyWithoutProjectFolder(RepoRelativePathHolder rrph, IdentifiableElement element) {
if (element instanceof TMember) {
ContainerType<?> containingType = ((TMember) element).getContainingType();
String specKeyOfType = getSpecKeyWithoutProjectFolder(rrph, containingType);
String specKey = specKeyOfType + "." + element.getName();
return specKey;
}
TModule module = element.getContainingModule();
if (module == null) {
return "GLOBAL.";
} else {
RepoRelativePath rrp = rrph.get(element);
String elementName = nameFromElement(rrph, element);
String key = getSpecKeyWithoutProjectFolder(rrp, elementName);
return key;
}
}
Aggregations