Issue #46: loops should not contain more then one break.

This commit is contained in:
Ilja Dubinin 2015-09-04 01:23:30 +01:00 committed by Roman Ivanov
parent f7e41edb94
commit 0b4ae9160b
1 changed files with 18 additions and 7 deletions

View File

@ -142,11 +142,7 @@ public class ModifierOrderCheck
final Iterator<DetailAST> it = modifiers.iterator();
//Speed past all initial annotations
DetailAST modifier;
do {
modifier = it.next();
}
while (it.hasNext() && modifier.getType() == TokenTypes.ANNOTATION);
DetailAST modifier = skipAnnotations(it);
DetailAST offendingModifier = null;
@ -154,7 +150,9 @@ public class ModifierOrderCheck
if (modifier.getType() != TokenTypes.ANNOTATION) {
int i = 0;
while (modifier != null) {
while (modifier != null
&& offendingModifier == null) {
if (modifier.getType() == TokenTypes.ANNOTATION) {
//Annotation not at start of modifiers, bad
offendingModifier = modifier;
@ -169,7 +167,6 @@ public class ModifierOrderCheck
if (i == JLS_ORDER.length) {
//Current modifier is out of JLS order
offendingModifier = modifier;
break;
}
else if (it.hasNext()) {
modifier = it.next();
@ -182,4 +179,18 @@ public class ModifierOrderCheck
}
return offendingModifier;
}
/**
* Skip all annotations in modifier block.
* @param modifierIterator iterator for collection of modifiers
* @return modifier next to last annotation
*/
private static DetailAST skipAnnotations(Iterator<DetailAST> modifierIterator) {
DetailAST modifier;
do {
modifier = modifierIterator.next();
}
while (modifierIterator.hasNext() && modifier.getType() == TokenTypes.ANNOTATION);
return modifier;
}
}