From 32db0ef71022040cb574a96d448f4b44518f8637 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Tue, 14 Jul 2020 16:43:04 +0200 Subject: Generate Pure annotation for cached hashCode --- src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 6 ++++-- src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index cf735dee..37379bb9 100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -272,8 +272,10 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandlernil()); List annsOnMethod = List.of(overrideAnnotation); CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(typeNode); - // TODO: maybe not add this annotation if cacheHashCode is true because we *do* modify a field - if (checkerFramework.generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.nil())); + if (cacheHashCode && checkerFramework.generatePure()) { + annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__PURE), List.nil())); + } else if (checkerFramework.generateSideEffectFree()) { + annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.nil())); + } JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod); JCExpression returnType = maker.TypeIdent(CTC_INT); ListBuffer statements = new ListBuffer(); -- cgit