Skip to content

Commit

Permalink
Allow parsing nested Groovy annotations (#4549)
Browse files Browse the repository at this point in the history
* Allow parsing nested Groovy annotations

See: #4055 (comment)

* Polish
  • Loading branch information
knutwannheden authored Oct 4, 2024
1 parent 0067a10 commit a0debfd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ public void visitConstantExpression(ConstantExpression expression) {
text = "";
}
jType = JavaType.Primitive.Null;
} else if (expression instanceof AnnotationConstantExpression) {
classVisitor.visitAnnotation((AnnotationNode) value);
return ((Expression) classVisitor.pollQueue()).withPrefix(fmt);
} else {
throw new IllegalStateException("Unexpected constant type " + type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2021 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.groovy.tree;

import org.junit.jupiter.api.Test;
import org.openrewrite.Issue;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.groovy.Assertions.groovy;

@SuppressWarnings({"GroovyUnusedAssignment", "GrUnnecessarySemicolon"})
class AnnotationTest implements RewriteTest {

@Test
void simple() {
rewriteRun(
groovy(
"""
@Foo
class Test {
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/4055")
@Test
void nested() {
rewriteRun(
groovy(
"""
@Foo(bar = @Bar)
class Test {
}
"""
)
);
}
}

0 comments on commit a0debfd

Please sign in to comment.