Skip to content

Commit

Permalink
fix: Default methods should be lifecycle methods
Browse files Browse the repository at this point in the history
Fixes #318
  • Loading branch information
pauxus committed Mar 7, 2024
1 parent 6bc76ef commit eb292e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.blackbuild.groovy.configdsl.transform.cast.NeedsDSLClass;
import com.blackbuild.klum.cast.KlumCastValidated;
import com.blackbuild.klum.cast.checks.ClassNeedsAnnotation;
import com.blackbuild.klum.cast.checks.NeedsOneOf;
import com.blackbuild.klum.cast.checks.OnlyOn;
import groovy.lang.Closure;
Expand Down Expand Up @@ -86,6 +85,7 @@
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@KlumCastValidated
@WriteAccess
@NeedsDSLClass
@NeedsOneOf(whenOn = ElementType.FIELD, value = {"field", "delegate", "code"}, exclusive = true)
@Documented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package com.blackbuild.groovy.configdsl.transform

import org.codehaus.groovy.control.MultipleCompilationErrorsException
import spock.lang.Ignore
import spock.lang.Issue

class DefaultValuesSpec extends AbstractDSLSpec {

Expand Down Expand Up @@ -288,4 +289,32 @@ class DefaultValuesSpec extends AbstractDSLSpec {
foo.value == "model"
}

@Issue("318")
def "default methods should be lifecycle methods"() {
when:
createClass '''
package pk
@DSL
class Foo {
String value
@Default
void aDefaultMethod() {
value = "default"
}
}
'''

then:
notThrown(MultipleCompilationErrorsException)
hasNoMethod(clazz, "aDefaultMethod")
hasNoMethod(rwClazz, "aDefaultMethod")

when:
def foo = create("pk.Foo")

then:
foo.value == "default"
}

}

0 comments on commit eb292e4

Please sign in to comment.