Пример #1
0
 /**
  * Checks order of methods.
  *
  * @param methods Iterable<DetailAST> methods
  */
 private void checkOrder(final Iterable<DetailAST> methods) {
   MethodsOrderCheck.Modifiers prev = MethodsOrderCheck.Modifiers.PUB;
   for (final DetailAST method : methods) {
     final MethodsOrderCheck.Modifiers mtype = MethodsOrderCheck.getModifierType(method);
     if (mtype.getOrder() < prev.getOrder()) {
       this.log(method.getLineNo(), "Wrong method declaration order");
     } else {
       prev = mtype;
     }
   }
 }
Пример #2
0
 /**
  * Get method modifier as enum {@code Modifiers}.
  *
  * @param method DetailAST of method
  * @return Element of {@code Modifiers} enum
  */
 private static MethodsOrderCheck.Modifiers getModifierType(final DetailAST method) {
   final DetailAST modifiers = method.findFirstToken(TokenTypes.MODIFIERS);
   final DetailAST modifier =
       Optional.fromNullable(modifiers.findFirstToken(MethodsOrderCheck.Modifiers.PUB.getType()))
           .or(
               Optional.fromNullable(
                   modifiers.findFirstToken(MethodsOrderCheck.Modifiers.PROT.getType())))
           .or(
               Optional.fromNullable(
                   modifiers.findFirstToken(MethodsOrderCheck.Modifiers.PRIV.getType())))
           .orNull();
   MethodsOrderCheck.Modifiers mod;
   if (modifier == null) {
     mod = MethodsOrderCheck.Modifiers.DEF;
   } else {
     mod = MethodsOrderCheck.Modifiers.getByType(modifier.getType());
   }
   return mod;
 }