use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class N4JSASTUtils method getOwnOrSuperCtor.
private static TMember getOwnOrSuperCtor(final ContainerType<?> ownerOfField) {
TClass klass = (TClass) (ownerOfField instanceof TClass ? ownerOfField : null);
while (null != klass) {
final TMember ctor = klass.findOwnedMember(CONSTRUCTOR);
if (null != ctor) {
return ctor;
}
final ParameterizedTypeRef superClassRef = klass.getSuperClassRef();
if (null == superClassRef) {
klass = null;
} else {
final Type declaredType = superClassRef.getDeclaredType();
klass = (TClass) (declaredType instanceof TClass ? declaredType : null);
}
}
return null;
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method addIssueToMemberOrInterfaceReference.
private void addIssueToMemberOrInterfaceReference(RedefinitionType redefinitionType, TMember overriding, TMember implemented, String message, String issueCode, String... issueData) {
if (redefinitionType == RedefinitionType.overridden && overriding.getContainingType() != getCurrentClassifier()) {
throw new IllegalStateException("must not happen as member is not consumed");
}
TClassifier currentClassifier = getCurrentClassifier();
if (overriding.getContainingType() == currentClassifier) {
addIssue(message, overriding.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, issueCode, issueData);
} else {
MemberCollector memberCollector = containerTypesHelper.fromContext(getCurrentClassifierDefinition());
ContainerType<?> bequestingType = memberCollector.directSuperTypeBequestingMember(currentClassifier, implemented);
Optional<ParameterizedTypeRef> optRef = StreamSupport.stream(getCurrentClassifierDefinition().getImplementedOrExtendedInterfaceRefs().spliterator(), false).filter(ref -> ref.getDeclaredType() == bequestingType).findAny();
ParameterizedTypeRef ref = optRef.get();
EStructuralFeature feature = ref.eContainingFeature();
List<?> list = (List<?>) getCurrentClassifierDefinition().eGet(feature);
int index = list.indexOf(ref);
addIssue(message, getCurrentClassifierDefinition(), feature, index, issueCode, issueData);
}
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef 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.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method checkMemberRedefinitions.
/**
* Checks constraints defined in chapter 5.4. Redefinition of Members.
*/
@Check
public void checkMemberRedefinitions(N4ClassifierDefinition n4ClassifierDefinition) {
if (!(n4ClassifierDefinition.getDefinedType() instanceof TClassifier)) {
// wrongly parsed
return;
}
TClassifier tClassifier = (TClassifier) n4ClassifierDefinition.getDefinedType();
getContext().put(TClassifier.class, tClassifier);
RuleEnvironment g = RuleEnvironmentExtensions.newRuleEnvironment(tClassifier);
getContext().put(RuleEnvironment.class, g);
// the context for type variables
ParameterizedTypeRef classTypeRef = TypeUtils.createTypeRef(tClassifier);
getContext().put(TYPE_VAR_CONTEXT, classTypeRef);
MemberCube memberCube = createMemberValidationList();
final boolean isClass = tClassifier instanceof TClass;
final Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef = new HashMap<>();
for (Entry<NameStaticPair, MemberMatrix> entry : memberCube.entrySet()) {
MemberMatrix mm = entry.getValue();
// Set to collect all owned members that are lacking an override annotation.
Collection<TMember> membersMissingOverrideAnnotation = new HashSet<>();
if (isClass) {
constraints_67_MemberOverride_checkEntry(mm, membersMissingOverrideAnnotation);
}
if (mm.hasImplemented()) {
// first mix in
if (holdConstraints_68_Consumption(mm)) {
// then check if everything is implemented
constraints_69_Implementation(mm, membersMissingOverrideAnnotation);
}
}
constraints_60_InheritedConsumedCovariantSpecConstructor(tClassifier, mm);
constraints_66_NonOverride(mm);
constraints_42_45_46_AbstractMember(mm, nonAccessibleAbstractMembersBySuperTypeRef);
unusedGenericTypeVariable(mm);
checkUnpairedAccessorConsumption(mm, n4ClassifierDefinition);
checkUnpairedAccessorFilling(mm, n4ClassifierDefinition);
messageMissingOverrideAnnotation(mm, membersMissingOverrideAnnotation);
}
final boolean foundImpossibleExtendsImplements = !nonAccessibleAbstractMembersBySuperTypeRef.isEmpty();
if (foundImpossibleExtendsImplements) {
messageImpossibleExtendsImplements(n4ClassifierDefinition, nonAccessibleAbstractMembersBySuperTypeRef);
}
if (!foundImpossibleExtendsImplements) {
// avoid consequential errors
constraints_41_AbstractClass(tClassifier, memberCube);
}
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class N4JSSyntaxValidator method checkInterfaceDeclaration.
/**
* Checks that no "with" or "role" is used and that list of implemented interfaces is separated with commas and not
* with keywords. These checks (with some warnings created instead of errors) should help the transition from roles
* to interfaces. However, they may be useful later on as well, e.g., if an interface is manually refactored into a
* class or vice versa.
* <p>
* Note that "with" is used in Dart for roles, so maybe it is useful to have a user-friendly message instead of a
* parser error.
* <p>
* "role" will be removed in grammar.
*/
@Check
public void checkInterfaceDeclaration(N4InterfaceDeclaration n4InterfaceDecl) {
ICompositeNode node = NodeModelUtils.findActualNodeFor(n4InterfaceDecl);
ILeafNode keywordNode;
keywordNode = findLeafWithKeyword(n4InterfaceDecl, "{", node, IMPLEMENTS_KEYWORD, false);
if (keywordNode != null) {
TInterface tinterface = n4InterfaceDecl.getDefinedTypeAsInterface();
if (tinterface == null) {
// avoid consequential errors
return;
}
if (tinterface.getSuperInterfaceRefs().isEmpty()) {
// ok
return;
}
if (tinterface.getSuperInterfaceRefs().stream().allMatch(superTypeRef -> superTypeRef.getDeclaredType() instanceof TInterface)) {
List<? extends IdentifiableElement> interfaces = tinterface.getSuperInterfaceRefs().stream().flatMap((ParameterizedTypeRef ref) -> {
Type declaredType = ref.getDeclaredType();
if (declaredType instanceof TInterface) {
return Stream.of((TInterface) declaredType);
}
return Stream.empty();
}).collect(Collectors.toList());
String message = getMessageForSYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP(validatorMessageHelper.description(tinterface), "implement", "interface" + (interfaces.size() > 1 ? "s " : " ") + validatorMessageHelper.names(interfaces), EXTENDS_KEYWORD);
addIssue(message, n4InterfaceDecl, keywordNode.getTotalOffset(), keywordNode.getLength(), SYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP);
}
}
}
Aggregations