@Override @SuppressWarnings("ConstantConditions") protected void doVisitField( @Nullable VariableElement oldField, @Nullable VariableElement newField) { if (!shouldCheck(oldField, newField)) { return; } Predicate<VariableElement> isNotEnumConstant = v -> v.getKind() != ElementKind.ENUM_CONSTANT; List<? extends VariableElement> fields = ElementFilter.fieldsIn(oldField.getEnclosingElement().getEnclosedElements()); fields.removeIf(isNotEnumConstant); int oldIdx = fields.indexOf(oldField); fields = ElementFilter.fieldsIn(newField.getEnclosingElement().getEnclosedElements()); fields.removeIf(isNotEnumConstant); int newIdx = fields.indexOf(newField); if (newIdx != oldIdx) { pushActive(oldField, newField, oldIdx, newIdx); } }
private void checkForMutableFields(Protoclass protoclass, TypeElement element) { for (VariableElement field : ElementFilter.fieldsIn( processing.getElementUtils().getAllMembers(CachingElements.getDelegate(element)))) { if (!field.getModifiers().contains(Modifier.FINAL)) { Reporter report = protoclass.report(); boolean ownField = CachingElements.equals(element, field.getEnclosingElement()); if (ownField) { report .withElement(field) .warning("Avoid introduction of fields (except constants) in abstract value types"); } else { report.warning("Abstract value type inherits mutable fields"); } } } }