This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 710de13c2b `groovy-contracts`: fix dsld errors and matching
710de13c2b is described below

commit 710de13c2b2c189d4c59f259f1c5ba92cac8a661
Author: Eric Milles <[email protected]>
AuthorDate: Mon Aug 14 12:40:29 2023 -0500

    `groovy-contracts`: fix dsld errors and matching
---
 .../main/resources/dsld/contract_transform.dsld    | 86 ++++++++++++++++++++++
 .../src/main/resources/dsld/org.gcontracts.dsld    | 53 -------------
 2 files changed, 86 insertions(+), 53 deletions(-)

diff --git 
a/subprojects/groovy-contracts/src/main/resources/dsld/contract_transform.dsld 
b/subprojects/groovy-contracts/src/main/resources/dsld/contract_transform.dsld
new file mode 100644
index 0000000000..7948ca6201
--- /dev/null
+++ 
b/subprojects/groovy-contracts/src/main/resources/dsld/contract_transform.dsld
@@ -0,0 +1,86 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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 dsld
+
+import org.codehaus.groovy.ast.*
+
+contribute(bind(closure: inClosure()) & isThisType() & bind(classes: 
enclosingClass(annotations: annotatedBy('groovy.contracts.Invariant')))) {
+  for (AnnotationNode annotation : annotations) {
+    def condition = annotation.getMember('value')
+    if (condition in closure) {
+      def thisType = classes[0]
+
+      delegateType = thisType
+      method name:'getOwner', type: thisType, params: [:]
+      property name: 'owner', type: thisType, readOnly: true
+      method name:'getThisObject', type: thisType, params: [:]
+      property name: 'thisObject', type: thisType, readOnly: true
+
+      return
+    }
+  }
+}
+
+contribute(bind(closure: inClosure()) & isThisType() & bind(methods: 
enclosingMethod(annotations: annotatedBy('groovy.contracts.Requires')))) {
+  for (AnnotationNode annotation : annotations) {
+    def condition = annotation.getMember('value')
+    if (condition in closure) {
+      def thisType = methods[0].declaringClass
+
+      delegateType = thisType
+      method name:'getOwner', type: thisType, params: [:]
+      property name: 'owner', type: thisType, readOnly: true
+      method name:'getThisObject', type: thisType, params: [:]
+      property name: 'thisObject', type: thisType, readOnly: true
+
+      for (Parameter parameter : methods[0].parameters) {
+        property name: parameter.name, type: parameter.type, readOnly: true
+      }
+
+      return
+    }
+  }
+}
+
+contribute(bind(closure: inClosure()) & isThisType() & bind(methods: 
enclosingMethod(annotations: annotatedBy('groovy.contracts.Ensures')))) {
+  for (AnnotationNode annotation : annotations) {
+    def condition = annotation.getMember('value')
+    if (condition in closure) {
+      def thisType = methods[0].declaringClass
+
+      delegateType = thisType
+      method name:'getOwner', type: thisType, params: [:]
+      property name: 'owner', type: thisType, readOnly: true
+      method name:'getThisObject', type: thisType, params: [:]
+      property name: 'thisObject', type: thisType, readOnly: true
+
+      for (Parameter parameter : methods[0].parameters) {
+        property name: parameter.name, type: parameter.type, readOnly: true
+      }
+      if (!methods[0].isConstructor()) {
+        property name: 'old', type: Map, readOnly: true, doc: 'Property values 
before the method call.'
+      }
+      if (!methods[0].isVoidMethod()) {
+        property name: 'result', type: methods[0].returnType, readOnly: true, 
doc: 'Return value of the method call.'
+      }
+
+      return
+    }
+  }
+}
diff --git 
a/subprojects/groovy-contracts/src/main/resources/dsld/org.gcontracts.dsld 
b/subprojects/groovy-contracts/src/main/resources/dsld/org.gcontracts.dsld
deleted file mode 100644
index 97f0821623..0000000000
--- a/subprojects/groovy-contracts/src/main/resources/dsld/org.gcontracts.dsld
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  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 dsld
-
-contribute(bind(closure: enclosingClosure()) & bind(method: 
enclosingMethod(annotatedBy('groovy.contracts.Ensures')))) {
-       property name : 'old', doc: 'java.util.Map of all property values 
before the method call.', provider: 'groovy-contracts', type : java.util.Map
-
-       if (method.isEmpty()) return
-
-    methodNode.parameters.each  {
-               property name : it.name, provider: 'groovy-contracts', type : 
it.type
-       }
-
-       def methodNode = method.first()
-       def returnType = methodNode.returnType
-       if (returnType.name == 'void') return
-
-       property name : 'result', doc: 'The return value of this method.', 
provider: 'groovy-contracts', type : returnType
-}
-
-contribute(bind(closure: enclosingClosure()) & bind(method: 
enclosingMethod(annotatedBy('groovy.contracts.Requires')))) {
-       if (method.isEmpty()) return
-
-       def methodNode = method.first()
-       methodNode.parameters.each {
-               property name : it.name, provider: 'groovy-contracts', type : 
it.type
-       }
-}
-
-contribute(bind(closure: enclosingClosure()) & bind(clazz: 
enclosingClass(annotatedBy('groovy.contracts.Invariant')))) {
-       if (clazz.isEmpty()) return
-
-       def classNode = clazz.first()
-       classNode.properties.each  {
-               property name : it.name, provider: 'groovy-contracts', type : 
it.type
-       }
-}
\ No newline at end of file

Reply via email to