public void validate(
      @NotNull final AbstractSyntaxTreeInterpreter abstractSyntaxTreeInterpreter,
      @NotNull final TypeElement element) {
    final Set<Modifier> modifiers = element.getModifiers();

    for (final Modifier requiredModifier : requiredModifiers) {
      if (!modifiers.contains(requiredModifier)) {
        throw new IncorrectSourceCodeException(
            format(
                "The type '1$%s' does not have the required modifier '%2$s'",
                abstractSyntaxTreeInterpreter.getCanonicalClassName(element),
                requiredModifier.name()));
      }
    }

    for (final Modifier modifierNotAllowed : modifiersNotAllowed) {
      if (!modifiers.contains(modifierNotAllowed)) {
        throw new IncorrectSourceCodeException(
            format(
                "The type '1$%s' has the disallowed modifier '%2$s'",
                abstractSyntaxTreeInterpreter.getCanonicalClassName(element),
                modifierNotAllowed.name()));
      }
    }
  }
示例#2
0
 /**
  * Emits {@code modifiers} in the standard order. Modifiers in {@code implicitModifiers} will not
  * be emitted.
  */
 public void emitModifiers(Set<Modifier> modifiers, Set<Modifier> implicitModifiers)
     throws IOException {
   if (modifiers.isEmpty()) return;
   for (Modifier modifier : EnumSet.copyOf(modifiers)) {
     if (implicitModifiers.contains(modifier)) continue;
     emitAndIndent(modifier.name().toLowerCase(Locale.US));
     emitAndIndent(" ");
   }
 }
示例#3
0
 /**
  * Returns an integer which results in the appropriate modifier based on the element.
  *
  * @param element the element to check the modifiers on
  * @return an integer representing the modifiers
  */
 public static int of(final Element element) {
   int result = 0;
   for (Modifier modifier : element.getModifiers()) {
     switch (modifier.name()) {
       case "ABSTRACT":
         {
           result = result | ABSTRACT;
           break;
         }
       case "FINAL":
         {
           result = result | FINAL;
           break;
         }
       case "NATIVE":
         {
           result = result | NATIVE;
           break;
         }
       case "PRIVATE":
         {
           result = result | PRIVATE;
           break;
         }
       case "PROTECTED":
         {
           result = result | PROTECTED;
           break;
         }
       case "PUBLIC":
         {
           result = result | PUBLIC;
           break;
         }
       case "STATIC":
         {
           result = result | STATIC;
           break;
         }
       case "STRICTFP":
         {
           result = result | STRICTFP;
           break;
         }
       case "SYNCHRONIZED":
         {
           result = result | SYNCHRONIZED;
           break;
         }
       case "TRANSIENT":
         {
           result = result | TRANSIENT;
           break;
         }
       case "VOLATILE":
         {
           result = result | VOLATILE;
           break;
         }
       case "DEFAULT":
         {
           result = result | DEFAULT;
           break;
         }
     }
   }
   if (element instanceof ExecutableElement && ((ExecutableElement) element).isVarArgs()) {
     result = result | VARARGS;
   }
   return result;
 }