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())); } } }
static boolean isStatic(Element element) { for (Modifier modifier : element.getModifiers()) { if (modifier.equals(Modifier.STATIC)) { return true; } } return false; }
/** * 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(" "); } }
/** Emits the modifiers to the writer. */ private void emitModifiers(Set<Modifier> modifiers) throws IOException { // Use an EnumSet to ensure the proper ordering if (!(modifiers instanceof EnumSet)) { modifiers = EnumSet.copyOf(modifiers); } for (Modifier modifier : modifiers) { out.append(modifier.toString()).append(' '); } }
private int[] modifierIntArray(String[] values) { int[] mods = new int[values.length]; for (int i = 0; i < mods.length; i++) { mods[i] = Modifier.valueOf(values[i]).ordinal(); } return mods; }
@Override protected StringBuilder appendDescription(final StringBuilder sb) { for (final javax.lang.model.element.Modifier modifier : Flags.asModifierSet(getModifiers() & ~Flags.ACC_VARARGS)) { sb.append(modifier.toString()); sb.append(' '); } if (isEnum()) { sb.append("enum "); } else if (isInterface()) { sb.append("interface "); if (isAnnotation()) { sb.append('@'); } } else { sb.append("class "); } StringBuilder s = super.appendDescription(sb); final TypeReference baseType = getBaseType(); if (baseType != null) { s.append(" extends "); s = baseType.appendBriefDescription(s); } final List<TypeReference> interfaces = getExplicitInterfaces(); final int interfaceCount = interfaces.size(); if (interfaceCount > 0) { s.append(" implements "); for (int i = 0; i < interfaceCount; ++i) { if (i != 0) { s.append(","); } s = interfaces.get(i).appendBriefDescription(s); } } return s; }
/** * Loads the given integer array into the input fields of the included modifiers. * * @param inModifiers - modifiers to load */ public void setIncludedModifiers(int[] inModifiers) { for (int mod : inModifiers) { lpIncModifier.addItem(Modifier.values()[mod].name()); } }
/** * Loads the given integer array into the input fields of the excluded modifiers. * * @param exModifiers - modifiers to load */ public void setExcludedModifiers(int[] exModifiers) { for (int mod : exModifiers) { lpExcModifier.addItem(Modifier.values()[mod].name()); } }
/** INTERNAL: */ protected int getModifiers(Set<Modifier> modifiers) { int mods = 0; for (Modifier modifier : modifiers) { if (modifier.equals(Modifier.ABSTRACT)) { mods += java.lang.reflect.Modifier.ABSTRACT; } if (modifier.equals(Modifier.FINAL)) { mods += java.lang.reflect.Modifier.FINAL; } if (modifier.equals(Modifier.NATIVE)) { mods += java.lang.reflect.Modifier.NATIVE; } if (modifier.equals(Modifier.PRIVATE)) { mods += java.lang.reflect.Modifier.PRIVATE; } if (modifier.equals(Modifier.PROTECTED)) { mods += java.lang.reflect.Modifier.PROTECTED; } if (modifier.equals(Modifier.PUBLIC)) { mods += java.lang.reflect.Modifier.PUBLIC; } if (modifier.equals(Modifier.STATIC)) { mods += java.lang.reflect.Modifier.STATIC; } if (modifier.equals(Modifier.STRICTFP)) { mods += java.lang.reflect.Modifier.STRICT; } if (modifier.equals(Modifier.SYNCHRONIZED)) { mods += java.lang.reflect.Modifier.SYNCHRONIZED; } if (modifier.equals(Modifier.TRANSIENT)) { mods += java.lang.reflect.Modifier.TRANSIENT; } if (modifier.equals(Modifier.VOLATILE)) { mods += java.lang.reflect.Modifier.VOLATILE; } } return mods; }
/** * 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; }