use of org.eclipse.n4js.n4JS.N4Modifier in project n4js by eclipse.
the class N4JSSyntaxValidator method holdsNotMoreThanOneAccessModifier.
/**
* Check that not more than one access modifier is given. Access modifiers are those for which
* {@link ModifierUtils#isAccessModifier(N4Modifier)} returns <code>true</code>.
*/
private boolean holdsNotMoreThanOneAccessModifier(ModifiableElement elem) {
boolean hasIssue = false;
boolean hasAccessModifier = false;
for (int idx = 0; idx < elem.getDeclaredModifiers().size(); idx++) {
final N4Modifier mod = elem.getDeclaredModifiers().get(idx);
final boolean isAccessModifier = ModifierUtils.isAccessModifier(mod);
if (hasAccessModifier && isAccessModifier) {
final ILeafNode node = ModifierUtils.getNodeForModifier(elem, idx);
addIssue(IssueCodes.getMessageForSYN_MODIFIER_ACCESS_SEVERAL(), elem, node.getOffset(), node.getLength(), IssueCodes.SYN_MODIFIER_ACCESS_SEVERAL);
hasIssue = true;
}
hasAccessModifier |= isAccessModifier;
}
return !hasIssue;
}
use of org.eclipse.n4js.n4JS.N4Modifier in project n4js by eclipse.
the class N4JSSyntaxValidator method holdsCorrectOrder.
/**
* Check for correct ordering of access modifiers.
*/
private boolean holdsCorrectOrder(ModifiableElement elem) {
boolean isOrderMessedUp = false;
int lastValue = -1;
for (N4Modifier mod : elem.getDeclaredModifiers()) {
final int currValue = mod.getValue();
if (currValue < lastValue) {
isOrderMessedUp = true;
break;
}
lastValue = currValue;
}
if (isOrderMessedUp) {
final List<N4Modifier> modifiers = ModifierUtils.getSortedModifiers(elem.getDeclaredModifiers());
final String modifiersStr = Joiner.on(' ').join(modifiers.iterator());
final ILeafNode nodeFirst = ModifierUtils.getNodeForModifier(elem, 0);
final ILeafNode nodeLast = ModifierUtils.getNodeForModifier(elem, elem.getDeclaredModifiers().size() - 1);
addIssue(IssueCodes.getMessageForSYN_MODIFIER_BAD_ORDER(modifiersStr), elem, nodeFirst.getOffset(), nodeLast.getOffset() - nodeFirst.getOffset() + nodeLast.getLength(), IssueCodes.SYN_MODIFIER_BAD_ORDER);
return false;
}
return true;
}
use of org.eclipse.n4js.n4JS.N4Modifier in project n4js by eclipse.
the class N4JSSyntaxValidator method holdsNoInvalidOrDuplicateModifiers.
/**
* Check for invalid modifiers (e.g. ABSTRACT on a field) and duplicates.
*/
private boolean holdsNoInvalidOrDuplicateModifiers(ModifiableElement elem) {
boolean hasIssue = false;
final Set<N4Modifier> checked = new HashSet<>();
for (int idx = 0; idx < elem.getDeclaredModifiers().size(); idx++) {
final N4Modifier mod = elem.getDeclaredModifiers().get(idx);
final boolean duplicate = !checked.add(mod);
if (!ModifierUtils.isValid(elem.eClass(), mod)) {
final ILeafNode node = ModifierUtils.getNodeForModifier(elem, idx);
addIssue(IssueCodes.getMessageForSYN_MODIFIER_INVALID(mod.getName(), keywordProvider.keyword(elem)), elem, node.getOffset(), node.getLength(), IssueCodes.SYN_MODIFIER_INVALID);
hasIssue = true;
} else if (duplicate) {
final ILeafNode node = ModifierUtils.getNodeForModifier(elem, idx);
addIssue(IssueCodes.getMessageForSYN_MODIFIER_DUPLICATE(mod.getName()), elem, node.getOffset(), node.getLength(), IssueCodes.SYN_MODIFIER_DUPLICATE);
hasIssue = true;
}
}
return !hasIssue;
}
Aggregations