Skip to content

Commit

Permalink
Trivial refactoring: extract constants
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellansun committed Nov 23, 2024
1 parent 86b327a commit 9069733
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
* @see AnnotationCollectorTransform#visit(AnnotationNode, AnnotationNode, AnnotatedNode, SourceUnit)
*/
public class AnnotationCollectorTransform {
private static final ClassNode ANNOTATIONCOLLECTOR_ANNOTATION = ClassHelper.make(AnnotationCollector.class);
private static final String ANNOTATIONCOLLECTOR_CLASS_NAME = AnnotationCollector.class.getName();

private static List<AnnotationNode> getMeta(ClassNode cn) {
List<AnnotationNode> meta = cn.getNodeMetaData(AnnotationCollector.class);
Expand Down Expand Up @@ -102,7 +104,7 @@ public static class ClassChanger {
public void transformClass(ClassNode cn) {
AnnotationNode collector = null;
for (AnnotationNode an : cn.getAnnotations()) {
if (an.getClassNode().getName().equals(AnnotationCollector.class.getName())) {
if (an.getClassNode().getName().equals(ANNOTATIONCOLLECTOR_CLASS_NAME)) {
collector = an;
break;
}
Expand Down Expand Up @@ -258,7 +260,7 @@ private static List<AnnotationNode> getTargetListFromAnnotations(ClassNode alias
List<AnnotationNode> ret = new ArrayList<>(annotations.size());
for (AnnotationNode an : annotations) {
ClassNode type = an.getClassNode();
if (type.getName().equals(AnnotationCollector.class.getName())
if (type.getName().equals(ANNOTATIONCOLLECTOR_CLASS_NAME)
|| "java.lang.annotation".equals(type.getPackageName())
|| "org.apache.groovy.lang.annotation.Incubating".equals(type.getName())) continue;
AnnotationNode toAdd = new AnnotationNode(type);
Expand Down Expand Up @@ -300,14 +302,14 @@ private static List<AnnotationNode> getTargetListFromClass(final ClassNode alias

// 2.5.3 and above gets from annotation attribute otherwise self
private static ClassNode getSerializeClass(final ClassNode alias) {
List<AnnotationNode> collectors = alias.getAnnotations(ClassHelper.make(AnnotationCollector.class));
List<AnnotationNode> collectors = alias.getAnnotations(ANNOTATIONCOLLECTOR_ANNOTATION);
if (!collectors.isEmpty()) {
assert collectors.size() == 1;
AnnotationNode collectorNode = collectors.get(0);
Expression serializeClass = collectorNode.getMember("serializeClass");
if (serializeClass instanceof ClassExpression) {
ClassNode serializeClassType = serializeClass.getType();
if (!serializeClassType.getName().equals(AnnotationCollector.class.getName())) {
if (!serializeClassType.getName().equals(ANNOTATIONCOLLECTOR_CLASS_NAME)) {
return serializeClassType;
}
}
Expand Down

0 comments on commit 9069733

Please sign in to comment.