
moxy.compiler.AnnotationRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moxy-compiler Show documentation
Show all versions of moxy-compiler Show documentation
Moxy Compiler library for Android
package moxy.compiler;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
public abstract class AnnotationRule {
protected final ElementKind mValidKind;
protected final Set mValidModifiers;
protected StringBuilder mErrorBuilder;
public AnnotationRule(ElementKind validKind, Modifier... validModifiers) {
if (validModifiers == null || validModifiers.length == 0) {
throw new RuntimeException("Valid modifiers cant be empty or null.");
}
mValidKind = validKind;
mValidModifiers = new HashSet<>(Arrays.asList(validModifiers));
mErrorBuilder = new StringBuilder();
}
/**
* Method describe rules for using Annotation.
*
* @param AnnotatedField Checking annotated field.
*/
public abstract void checkAnnotation(Element AnnotatedField);
public String getErrorStack() {
return mErrorBuilder.toString();
}
protected String validModifiersToString() {
if (mValidModifiers.size() > 1) {
StringBuilder result = new StringBuilder("one of [");
boolean addSeparator = false;
for (Modifier validModifier : mValidModifiers) {
if (addSeparator) {
result.append(", ");
}
addSeparator = true;
result.append(validModifier.toString());
}
result.append("]");
return result.toString();
} else {
return mValidModifiers.iterator().next() + ".";
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy