use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method constraints_41_AbstractClass.
/**
* Constraints 41 (Abstract Class)
*/
private boolean constraints_41_AbstractClass(TClassifier classifier, MemberCube memberCube) {
List<TMember> abstractMembers = null;
if (!classifier.isAbstract() && classifier instanceof TClass) {
for (Entry<NameStaticPair, MemberMatrix> entry : memberCube.entrySet()) {
MemberMatrix mm = entry.getValue();
MemberList<TMember> l = new MemberList<>();
Iterators.addAll(l, mm.actuallyInheritedAndMixedMembers());
for (SourceAwareIterator iter = mm.actuallyInheritedAndMixedMembers(); iter.hasNext(); ) {
TMember m = iter.next();
if (m.isAbstract()) {
if (abstractMembers == null) {
abstractMembers = new ArrayList<>();
}
abstractMembers.add(m);
}
}
}
}
if (abstractMembers != null) {
messageMissingImplementations(abstractMembers);
return false;
}
return true;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method constraints_66_NonOverride.
/**
* Constraints 66: Non-Override Declaration
*/
private boolean constraints_66_NonOverride(MemberMatrix mm) {
if (mm.hasOwned()) {
boolean bFoundWronglyDeclaredMember = false;
for (TMember member : mm.owned()) {
if (member.isDeclaredOverride()) {
TMember m = mm.possibleOverrideCandidateOrError(member);
if (m == null) {
bFoundWronglyDeclaredMember = true;
if (member.isStatic() && mm.hasNonImplemented() && !mm.hasInherited() && !mm.hasImplemented()) {
// special case of false @Override annotation: "overriding" a static member of an interface
// simply take the first one
final TMember other = mm.nonImplemented().iterator().next();
String message = getMessageForCLF_OVERRIDE_NON_EXISTENT_INTERFACE(validatorMessageHelper.description(member), validatorMessageHelper.description(other));
addIssue(message, member.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, CLF_OVERRIDE_NON_EXISTENT_INTERFACE);
} else {
// standard case of false @Override annotation
String message = getMessageForCLF_OVERRIDE_NON_EXISTENT(keywordProvider.keyword(member), member.getName());
addIssue(message, member.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, CLF_OVERRIDE_NON_EXISTENT);
}
}
}
}
return bFoundWronglyDeclaredMember;
}
return true;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method unusedGenericTypeVariable.
/**
* GHOLD-234 add warning for unused type variables in function and method declarations (unless the method overrides
* any other method).
*/
private void unusedGenericTypeVariable(MemberMatrix mm) {
for (TMember member : mm.owned()) {
if (member instanceof TMethod) {
TMethod method = (TMethod) member;
if (!mm.hasInherited() && !mm.hasImplemented()) {
// We need the method declaration from the AST in order to pass it to the internal
// validation function. This is necessary because we want to attach the warning to the actual unused
// type variable in the method declaration, and the type variable in the type model is not identical
// to the one in the AST which we actually need.
// Since method is owned by the type being validated, we can safely navigate back from the type
// model to the AST without triggering another parse.
MethodDeclaration methodDeclaration = (MethodDeclaration) method.getAstElement();
internalCheckNoUnusedTypeParameters(methodDeclaration);
}
}
}
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method messageMissingOverrideAnnotation.
/**
* Adds a missing override issue with the fitting verb for all members in the given collection.
*
* @param mm
* The current member matrix
* @param missingOverrideAnnotationMembers
* A collection of overridden members
*/
private void messageMissingOverrideAnnotation(MemberMatrix mm, Collection<TMember> missingOverrideAnnotationMembers) {
if (mm.hasOwned() && missingOverrideAnnotationMembers.size() > 0) {
Iterable<TMember> overriddenMembers = Iterables.concat(mm.inherited(), mm.implemented());
for (TMember overriding : mm.owned()) {
// skip members with proper annotation
if (!missingOverrideAnnotationMembers.contains(overriding)) {
continue;
}
// skip constructors
if (overriding.isConstructor()) {
continue;
}
// skip non-n4js variant members
if (!jsVariantHelper.checkOverrideAnnotation(overriding)) {
continue;
}
/*
* Filter overridden members to only contain metatype compatible members to prevent the generation of
* confusing error message
*/
Iterable<TMember> filteredOverriddenMembers = MemberRedefinitionUtils.getMetatypeCompatibleOverriddenMembers(overriding, overriddenMembers);
// choose redefinition verb based on the origin of the overridden members
String redefinitionVerb = MemberRedefinitionUtils.getRedefinitionVerb(filteredOverriddenMembers, getCurrentClassifier());
String message = getMessageForCLF_OVERRIDE_ANNOTATION(validatorMessageHelper.descriptionDifferentFrom(overriding, overriddenMembers), redefinitionVerb, validatorMessageHelper.descriptions(filteredOverriddenMembers));
addIssue(message, overriding.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, CLF_OVERRIDE_ANNOTATION);
}
}
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method checkUnpairedAccessorConsumption.
/**
* Checks if any accessor has been consumed for which the counterpart accessor is only inherited.
*/
private void checkUnpairedAccessorConsumption(MemberMatrix mm, N4ClassifierDefinition definition) {
// validate conflicts between inherited and consumed accessor members only
if (!mm.hasOwned() && mm.hasInherited() && mm.hasImplemented()) {
// Collect whether getter and setter were consumed as well as the consumed member
boolean getterConsumed = false;
boolean setterConsumed = false;
TMember consumedAccessor = null;
for (TMember implementedMember : mm.implemented()) {
if (implementedMember.isAccessor() && mm.isConsumed(implementedMember)) {
if (implementedMember.getMemberType() == MemberType.GETTER) {
getterConsumed = true;
} else {
setterConsumed = true;
}
consumedAccessor = implementedMember;
}
}
// Issue error if getter/setter has been consumed and the counterpart is inherited.
if ((getterConsumed != setterConsumed) && mm.hasAccessorPair() && null != consumedAccessor) {
messageMissingOwnedAccessorCorrespondingConsumedAccessor((FieldAccessor) consumedAccessor, definition);
}
}
}
Aggregations