diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2020-12-27 05:31:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 05:31:43 +0100 |
commit | 0532285eb8de98e9e4e3fc4131476b5f4ef2740d (patch) | |
tree | 1622bbb376e8d9f667e9575b7e3d0395c0587c73 /src | |
parent | 8ba5df7161f7a6ef24b67d783f3a4fd6c2359fee (diff) | |
parent | e131cf6b42add619b88fe60c2bff143b5276d55a (diff) | |
download | lombok-0532285eb8de98e9e4e3fc4131476b5f4ef2740d.tar.gz lombok-0532285eb8de98e9e4e3fc4131476b5f4ef2740d.tar.bz2 lombok-0532285eb8de98e9e4e3fc4131476b5f4ef2740d.zip |
Merge pull request #2685 from Rawi01/copy-name-npe
Replace duplicate code with new method, add null check
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 20 |
1 files changed, 11 insertions, 9 deletions
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; |