From e131cf6b42add619b88fe60c2bff143b5276d55a Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 23 Dec 2020 09:45:14 +0100 Subject: [refactor] Replace duplicate code with new method, add null check --- .../lombok/eclipse/handlers/EclipseHandlerUtil.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 5da7abfd..62c71f5b 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -292,9 +292,7 @@ public class EclipseHandlerUtil { MarkerAnnotation ann = new MarkerAnnotation(copyType(annotation.type, source), pS); setGeneratedBy(ann, source); ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = pE; - try { - reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, ann, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, annotation)); - } catch (Exception ignore) { /* Various eclipse versions don't have it */ } + copyMemberValuePairName(ann, annotation); return ann; } @@ -303,9 +301,7 @@ public class EclipseHandlerUtil { setGeneratedBy(ann, source); ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = pE; ann.memberValue = copyAnnotationMemberValue(((SingleMemberAnnotation) annotation).memberValue); - try { - reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, ann, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, annotation)); - } catch (Exception ignore) { /* Various eclipse versions don't have it */ } + copyMemberValuePairName(ann, annotation); return ann; } @@ -321,15 +317,21 @@ public class EclipseHandlerUtil { for (int i = 0; i < inPairs.length; i++) ann.memberValuePairs[i] = new MemberValuePair(inPairs[i].name, inPairs[i].sourceStart, inPairs[i].sourceEnd, copyAnnotationMemberValue(inPairs[i].value)); } - try { - reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, ann, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, annotation)); - } catch (Exception ignore) { /* Various eclipse versions don't have it */ } + copyMemberValuePairName(ann, annotation); return ann; } return annotation; } + private static void copyMemberValuePairName(Annotation source, Annotation target) { + if (ANNOTATION__MEMBER_VALUE_PAIR_NAME == null) return; + + try { + reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, source, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, target)); + } catch (Exception ignore) { /* Various eclipse versions don't have it */ } + } + static class EclipseReflectiveMembers { public static final Field STRING_LITERAL__LINE_NUMBER; public static final Field ANNOTATION__MEMBER_VALUE_PAIR_NAME; -- cgit