Skip to content

Commit

Permalink
fix: get groovydoc task working again
Browse files Browse the repository at this point in the history
Reverts some changes that updated to Java 17 syntax `instanceof`. At the moment this breaks groovydoc generation with the message:
Use of patterns with instanceof is not supported. Pay attention that this feature is supported starting from 'JAVA_14' language level. If you need that feature the language level must be configured in the configuration before parsing the source files.

As these changes are purely cosmetic I'm find it better to revert them.
  • Loading branch information
matrei committed Sep 22, 2024
1 parent 6b62af5 commit a926e13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public class EntityASTTransformation implements ASTTransformation, CompilationUn

public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) {

if (!(astNodes[0] instanceof AnnotationNode node) || !(astNodes[1] instanceof AnnotatedNode parent)) {
if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
}

if (!MY_TYPE.equals(node.getClassNode()) || !(parent instanceof ClassNode cNode)) {
AnnotatedNode parent = (AnnotatedNode) astNodes[1];
AnnotationNode node = (AnnotationNode) astNodes[0];
if (!MY_TYPE.equals(node.getClassNode()) || !(parent instanceof ClassNode)) {
return;
}

ClassNode cNode = (ClassNode) parent;
String cName = cNode.getName();
if (cNode.isInterface()) {
throw new RuntimeException("Error processing interface '" + cName + "'. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ public List<UrlMapping> evaluateMappings(Resource resource) {

@Override
public List<UrlMapping> evaluateMappings(Class<?> mappingsClass) {
var obj = (GroovyObject) BeanUtils.instantiateClass(mappingsClass);
if (obj instanceof Script script) {
var binding = new Binding();
var closure = new MappingCapturingClosure(script);
GroovyObject obj = (GroovyObject) BeanUtils.instantiateClass(mappingsClass);
if (obj instanceof Script) {
Script script = (Script) obj;
Binding binding = new Binding();
MappingCapturingClosure closure = new MappingCapturingClosure(script);
binding.setVariable("mappings", closure);
script.setBinding(binding);
script.run();
Expand Down Expand Up @@ -596,8 +597,10 @@ private Object _invoke(String methodName, Object arg, Object delegate) {
urlDefiningMode = false;
}
args = args != null && args.length > 0 ? args : new Object[] {Collections.emptyMap()};
if (args[0] instanceof Closure<?> callable) {
var urlData = createUrlMappingData(mappedURI, isResponseCode);
if (args[0] instanceof Closure<?>) {
UrlMappingData urlData = createUrlMappingData(mappedURI, isResponseCode);

Closure<?> callable = (Closure<?>) args[0];

if (delegate != null) {
callable.setDelegate(delegate);
Expand Down Expand Up @@ -638,7 +641,8 @@ private Object _invoke(String methodName, Object arg, Object delegate) {
return urlMapping;
}

if (args[0] instanceof Map<?,?> namedArguments) {
if (args[0] instanceof Map) {
Map<?,?> namedArguments = (Map<?,?>) args[0];
String version = null;

if (namedArguments.containsKey(UrlMapping.VERSION)) {
Expand Down Expand Up @@ -704,7 +708,8 @@ private Object _invoke(String methodName, Object arg, Object delegate) {
}
}
} else if ((!urlDefiningMode || (!parentResources.isEmpty() && parentResources.peek().isGroup)) && CONSTRAINTS.equals(mappedURI)) {
if (args.length > 0 && (args[0] instanceof Closure<?> callable)) {
if (args.length > 0 && (args[0] instanceof Closure<?>)) {
Closure<?> callable = (Closure<?>) args[0];
var builder = constraintsEvaluator.newConstrainedPropertyBuilder(UrlMapping.class);
for (var constrainedProperty : currentConstraints) {
builder.getConstrainedProperties().put(constrainedProperty.getPropertyName(), constrainedProperty);
Expand All @@ -729,7 +734,8 @@ private List<String> calculateIncludes(Map<?,?> namedArguments, List<String> def

Object excludesObject = namedArguments.get("excludes");
if (excludesObject != null) {
if (excludesObject instanceof List<?> excludeList) {
if (excludesObject instanceof List<?>) {
List<?> excludeList = (List<?>) excludesObject;
for (Object exc : excludeList) {
if (exc != null) {
includes.remove(exc.toString().toLowerCase());
Expand All @@ -741,7 +747,8 @@ private List<String> calculateIncludes(Map<?,?> namedArguments, List<String> def
}
Object includesObject = namedArguments.get("includes");
if (includesObject != null) {
if (includesObject instanceof List<?> includeList) {
if (includesObject instanceof List<?>) {
List<?> includeList = (List<?>) includesObject;
includes.clear();
for (Object inc : includeList) {
if (inc != null) {
Expand Down Expand Up @@ -1079,7 +1086,8 @@ private UrlMapping getURLMappingForNamedArgs(Map<?,?> namedArguments, UrlMapping
var exceptionArg = getException(namedArguments, bindingVariables);

if (isResponseCode && exceptionArg != null) {
if (exceptionArg instanceof Class<?> exClass) {
if (exceptionArg instanceof Class<?>) {
Class<?> exClass = (Class<?>) exceptionArg;
if (Throwable.class.isAssignableFrom(exClass)) {
((ResponseCodeUrlMapping) urlMapping).setExceptionType(exClass);
} else {
Expand Down

0 comments on commit a926e13

Please sign in to comment.