Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import static org.codehaus.groovy.ast.tools.GenericsUtils.correctToGenericsSpecRecurse;
import static org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec;

import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.markAsGenerated;

@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
public class DelegateAsyncTransformation implements ASTTransformation {
private static final ArgumentListExpression NO_ARGS = new ArgumentListExpression();
Expand Down Expand Up @@ -122,6 +124,8 @@ private void applyDelegateAsyncTransform(ClassNode classNode, ClassNode targetAp
MethodCallExpression delegateMethodCall = new MethodCallExpression(new VariableExpression(fieldName), candidate.getName(), arguments);
promiseBody.addStatement(new ExpressionStatement(delegateMethodCall));
MethodNode newMethodNode = new MethodNode(candidate.getName(), Modifier.PUBLIC,promiseNode, parameters,null, methodBody);

markAsGenerated(classNode, newMethodNode);
classNode.addMethod(newMethodNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.grails.datastore.gorm.async.transform

import grails.async.Promise
import groovy.transform.Generated
import org.codehaus.groovy.ast.ClassNode
import spock.lang.Specification

import java.lang.reflect.Method

/**
* Created by graemerocher on 01/07/16.
*/
Expand All @@ -25,7 +28,12 @@ interface Foo<D> {
''')
expect:"The method is retrieved"
new ClassNode(cls).methods
Promise.isAssignableFrom( cls.getMethod("withTransaction", Closure).returnType )

Method method = cls.getMethod("withTransaction", Closure)
Promise.isAssignableFrom( method.returnType )

and: 'marked as Generated'
method.isAnnotationPresent(Generated)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.datastore.mapping.dirty.checking

import groovy.transform.CompileStatic
import groovy.transform.Generated
import org.grails.datastore.mapping.proxy.EntityProxy

import javax.persistence.Transient
Expand All @@ -22,6 +23,7 @@ trait DirtyCheckable {
* Indicates that the instance should start tacking changes. Note that if the instance is dirty this will clear any previously tracked
* changes
*/
@Generated
void trackChanges() {
$changedProperties = new LinkedHashMap<String, Object>()
}
Expand All @@ -31,6 +33,7 @@ trait DirtyCheckable {
*
* @param o a given object
*/
@Generated
void syncChangedProperties(Object o) {
if (o instanceof DirtyCheckable) {
o.trackChanges($changedProperties)
Expand All @@ -42,13 +45,15 @@ trait DirtyCheckable {
*
* @param changedProperties The changes.
*/
void trackChanges(Map<String, Object> changedProperties) {
@Generated
void trackChanges(Map<String, Object> changedProperties) {
$changedProperties = changedProperties
}

/**
* @return True if the instance has any changes
*/
@Generated
boolean hasChanged() {
if(this instanceof EntityProxy && !((EntityProxy)this).isInitialized()) {
return false
Expand All @@ -62,6 +67,7 @@ trait DirtyCheckable {
* @param propertyName The name of the property
* @return True if the given property has any changes
*/
@Generated
boolean hasChanged(String propertyName) {
if(this instanceof EntityProxy && !((EntityProxy)this).isInitialized()) {
return false
Expand All @@ -74,6 +80,7 @@ trait DirtyCheckable {
/**
* Marks the whole class and all its properties as dirty. When called any future call to any of the hasChanged methods will return true.
*/
@Generated
void markDirty() {
if( $changedProperties != null && $changedProperties.isEmpty()) {
$changedProperties = DirtyCheckingSupport.DIRTY_CLASS_MARKER
Expand All @@ -84,6 +91,7 @@ trait DirtyCheckable {
* Marks the given property name as dirty
* @param propertyName The property name
*/
@Generated
void markDirty(String propertyName) {
if( $changedProperties != null && !$changedProperties.containsKey(propertyName)) {
if (DirtyCheckingSupport.DIRTY_CLASS_MARKER.is($changedProperties)) {
Expand All @@ -98,6 +106,7 @@ trait DirtyCheckable {
* @param propertyName The property name
* @param newValue The new value
*/
@Generated
void markDirty(String propertyName, newValue) {
if( $changedProperties != null && !$changedProperties.containsKey(propertyName)) {
def oldValue = ((GroovyObject) this).getProperty(propertyName)
Expand All @@ -110,6 +119,7 @@ trait DirtyCheckable {
* @param propertyName The property name
* @param newValue The new value
*/
@Generated
void markDirty(String propertyName, newValue, oldValue) {
if( $changedProperties != null && !$changedProperties.containsKey(propertyName)) {
boolean isNull = newValue == null
Expand All @@ -127,6 +137,7 @@ trait DirtyCheckable {
/**
* @return A list of the dirty property names
*/
@Generated
List<String> listDirtyPropertyNames() {
if(this instanceof EntityProxy && !((EntityProxy)this).isInitialized()) {
return Collections.emptyList()
Expand All @@ -146,6 +157,7 @@ trait DirtyCheckable {
* @param propertyName The property name
* @return The original value
*/
@Generated
Object getOriginalValue(String propertyName) {
if($changedProperties != null && $changedProperties.containsKey(propertyName)) {
return $changedProperties.get(propertyName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.grails.datastore.mapping.services

import groovy.transform.Generated
import org.grails.datastore.mapping.core.Datastore

/**
Expand All @@ -30,5 +31,15 @@ trait Service<T> {
/**
* The datastore that this service is related to
*/
Datastore datastore
private Datastore datastore

@Generated
Datastore getDatastore() {
return datastore
}

@Generated
void setDatastore(Datastore datastore) {
this.datastore = datastore
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.grails.datastore.mapping.dirty.checking


import groovy.transform.Sortable
import groovy.transform.Generated
import spock.lang.Issue
import spock.lang.Specification

import java.lang.reflect.Method

class DirtyCheckableSpec extends Specification {

@Issue('https://github.com/grails/grails-data-mapping/issues/1231')
Expand Down Expand Up @@ -59,6 +61,13 @@ class DirtyCheckableSpec extends Specification {
animal.hasChanged("barks")

}

void "test that all DirtyCheckable trait methods are marked as Generated"() {
expect: "all DirtyCheckable methods are marked as Generated on implementation class"
DirtyCheckable.getMethods().each { Method traitMethod ->
assert Animal.class.getMethod(traitMethod.name, traitMethod.parameterTypes).isAnnotationPresent(Generated)
}
}
}

class Animal implements DirtyCheckable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.grails.datastore.mapping.services

import groovy.transform.Generated
import org.grails.datastore.mapping.core.Datastore
import org.grails.datastore.mapping.dirty.checking.DirtyCheckable
import spock.lang.Specification

import java.lang.reflect.Method

/**
* Created by graemerocher on 11/01/2017.
*/
Expand All @@ -22,6 +26,13 @@ class DefaultServiceRegistrySpec extends Specification {
reg.getService(TestService) != reg2.getService(TestService)
reg.getService(TestService).datastore != reg2.getService(TestService).datastore
}

void "test that all Service trait methods are marked as Generated"() {
expect: "all Service methods are marked as Generated on implementation class"
Service.getMethods().each { Method traitMethod ->
assert TestService.class.getMethod(traitMethod.name, traitMethod.parameterTypes).isAnnotationPresent(Generated)
}
}
}

class TestService implements Service, ITestService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grails.gorm.async

import groovy.transform.CompileStatic
import groovy.transform.Generated
import org.grails.datastore.gorm.GormEnhancer
import org.grails.datastore.gorm.GormEntity
import org.grails.datastore.gorm.async.GormAsyncStaticApi
Expand All @@ -16,6 +17,7 @@ trait AsyncEntity<D> extends GormEntity<D> {
/**
* @return The async version of the GORM static API
*/
@Generated
static GormAsyncStaticApi<D> getAsync() {
return new GormAsyncStaticApi(GormEnhancer.findStaticApi(this))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grails.gorm.rx
import grails.gorm.api.GormAllOperations
import grails.gorm.rx.api.RxGormAllOperations
import groovy.transform.CompileStatic
import groovy.transform.Generated
import org.grails.datastore.gorm.GormEnhancer
import org.grails.datastore.mapping.core.connections.ConnectionSource
import org.grails.gorm.rx.api.RxGormEnhancer
Expand All @@ -22,6 +23,7 @@ trait MultiTenant<D> extends RxEntity<D> {
* @param callable The closure
* @return The result of the closure
*/
@Generated
static <T> T withTenant(Serializable tenantId, @DelegatesTo(RxGormAllOperations) Closure<T> callable) {
RxGormEnhancer.findStaticApi(this).withTenant tenantId, callable
}
Expand All @@ -32,6 +34,7 @@ trait MultiTenant<D> extends RxEntity<D> {
* @param callable The closure
* @return The result of the closure
*/
@Generated
static RxGormAllOperations<D> eachTenant( @DelegatesTo(RxGormAllOperations) Closure callable) {
RxGormEnhancer.findStaticApi(this, ConnectionSource.DEFAULT).eachTenant callable
}
Expand All @@ -42,6 +45,7 @@ trait MultiTenant<D> extends RxEntity<D> {
* @param tenantId The tenant id
* @return The operations
*/
@Generated
static RxGormAllOperations<D> withTenant(Serializable tenantId) {
(RxGormAllOperations<D>)RxGormEnhancer.findStaticApi(this).withTenant(tenantId)
}
Expand Down
Loading