Skip to content

Commit

Permalink
Merge pull request #106 from Dafodils/main
Browse files Browse the repository at this point in the history
Fix/issue 103 reduce cognitive complexity of AnnotationChangeRefactor#removeMembersFromAnnotation
  • Loading branch information
RadikalJin authored Jun 22, 2022
2 parents f9615bb + 32078e1 commit 4e14d17
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,25 @@ private Annotation addNewMembersToAnnotation(CompilationUnit compilationUnit, AS


private Annotation removeMembersFromAnnotation(ASTRewrite rewriter, Annotation annotation) {
if (!namesForMembersToRemove.isEmpty()){
if (annotation.isSingleMemberAnnotation() && namesForMembersToRemove.contains(VALUE)) {
return convertAnnotationToMarkerAnnotation(rewriter, annotation);
} else if(annotation.isNormalAnnotation()) {
NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
final ListRewrite listRewrite = rewriter.getListRewrite(normalAnnotation, NormalAnnotation.VALUES_PROPERTY);
@SuppressWarnings("unchecked")
final List<MemberValuePair> rewrittenList = listRewrite.getRewrittenList();
for (MemberValuePair memberValuePair : rewrittenList) {
if(namesForMembersToRemove.contains(memberValuePair.getName().getIdentifier())){
listRewrite.remove(memberValuePair, null);
}
}
if (listRewrite.getRewrittenList().isEmpty()) {
return convertAnnotationToMarkerAnnotation(rewriter, annotation);
} else {
return normalAnnotation;
if (namesForMembersToRemove.isEmpty()){
return annotation;
} else if ( annotation.isSingleMemberAnnotation() && namesForMembersToRemove.contains(VALUE)) {
return convertAnnotationToMarkerAnnotation(rewriter, annotation);
} else if (annotation.isNormalAnnotation()) {
NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
final ListRewrite listRewrite = rewriter.getListRewrite(normalAnnotation, NormalAnnotation.VALUES_PROPERTY);
@SuppressWarnings("unchecked")
final List<MemberValuePair> rewrittenList = listRewrite.getRewrittenList();
for (MemberValuePair memberValuePair : rewrittenList) {
if(namesForMembersToRemove.contains(memberValuePair.getName().getIdentifier())){
listRewrite.remove(memberValuePair, null);
}
}
if (listRewrite.getRewrittenList().isEmpty()) {
return convertAnnotationToMarkerAnnotation(rewriter, annotation);
} else {
return normalAnnotation;
}
}
return annotation;
}
Expand Down

0 comments on commit 4e14d17

Please sign in to comment.