[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-10-11 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17774099#comment-17774099
 ] 

Leonard Brünings commented on GROOVY-9510:
--

[~emilles] I finally got around to verify the DSLD part in eclipse. 
https://github.com/spockframework/spock/pull/1808

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-21 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17757046#comment-17757046
 ] 

Eric Milles commented on GROOVY-9510:
-

If you have made a change to {{PreconditionContext}} and 
{{RetryConditionContext}}, then the dsld needs a small update.  I'm unable to 
test that out fully since I don't have the spock snapshot.

You can replace "enclosingClass(subType('spock.lang.Specification'))" with 
"bind(classes: enclosingClass(subType('spock.lang.Specification')))" and then 
the delegate type gets templated, like we discussed above:

"org.spockframework.runtime.extension.builtin.PreconditionContext<${classes[0].getName()}>"

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-21 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17757008#comment-17757008
 ] 

Leonard Brünings commented on GROOVY-9510:
--

Sure, I can add this, so we don't use/need the type parameter anymore for 
{{PreconditionContext}}? If so, I'll have to remove it again.
Do I need to add any version check, so as not to break older tooling versions?
We still have this check: {{assertVersion(groovyEclipse: "2.7.2") // tested 
against this version}}

[leonard84/spock/enhance-conditional-extensions-ide-experience|https://github.com/leonard84/spock/tree/enhance-conditional-extensions-ide-experience]

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-15 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17754669#comment-17754669
 ] 

Eric Milles commented on GROOVY-9510:
-

I found that the delegate needs to be set only once.  So the contributions can 
be simplified a bit:
{code:groovy}
def hasPrecondition = { annotatedBy(name('spock.lang.Requires') | 
name('spock.lang.IgnoreIf') | name('spock.lang.PendingFeatureIf')) }

contribute(inClosure() & isThisType() & 
enclosingClass(subType('spock.lang.Specification'))
 & (enclosingClass(conditions: hasPrecondition()) | enclosingMethod(conditions: 
hasPrecondition( {
  for (AnnotationNode pre : conditions) {
def condition = pre.getMember('value')
if (condition.getCode().is(currentNode)) {
  delegateType = 
resolver.resolve('org.spockframework.runtime.extension.builtin.PreconditionContext')
  provider = 'Spock framework'
  return
}
  }
}

contribute(inClosure() & isThisType() & 
enclosingClass(subType('spock.lang.Specification'))
 & (enclosingClass(annotations: annotatedBy('spock.lang.Retry')) | 
enclosingMethod(annotations: annotatedBy('spock.lang.Retry' {
  for (AnnotationNode retry : annotations) {
def condition = retry.getMember('condition')
if (condition.getCode().is(currentNode)) {
  delegateType = 
resolver.resolve('org.spockframework.runtime.extension.builtin.RetryConditionContext')
  provider = 'Spock framework'
  return
}
  }
}
{code}

In this case, {{currentType}} is {{Class}} in recent tooling 
snapshots.  At the moment, {{currentType}} is not used.  But if it were (as we 
discussed above) we'd need to check for {{Class}} and 
{{TheSpecClass}}.  Otherwise there is a cross-compatible way to capture from 
the {{enclosingClass(...)}} pointcut.

Could you add this to your "spk.dsld"?  And possibly rename the file to 
"spock_tests.dsld"?

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-12 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17753562#comment-17753562
 ] 

Eric Milles commented on GROOVY-9510:
-

A couple additional ways to detect closure nesting without my {{isInClosure}} 
solution:

{code:groovy}
contribute(bind(closure: inClosure()) & isThisType() & 
enclosingClass(subType('spock.lang.Specification')) & 
(enclosingClass(annotations: annotatedBy('spock.lang.Retry')) | 
enclosingMethod(annotations: annotatedBy('spock.lang.Retry' {
  for (AnnotationNode retry : annotations) {
def condition = retry.getMember('condition')
if (condition in closure) { // closure is a collection
  ...
}
  }
}
{code}

{code:groovy}
contribute(inClosure() & isThisType() & 
enclosingClass(subType('spock.lang.Specification')) & 
(enclosingClass(annotations: annotatedBy('spock.lang.Retry')) | 
enclosingMethod(annotations: annotatedBy('spock.lang.Retry' {
  for (AnnotationNode retry : annotations) {
def condition = retry.getMember('condition')
if (condition === delegate.@scope.enclosingClosure) { // scope is private 
field of DSLContributionGroup
  ...
}
  }
}
{code}


> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-09 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17752502#comment-17752502
 ] 

Leonard Brünings commented on GROOVY-9510:
--

bq. In addition to setting the delegate to PreconditionContext, spock also 
calls the closure with a PreconditionContext argument.

Yes, this was mainly added to provide a way for type safety, due to not getting 
the GDSL/DSLD working back then. Although, it is much more verbose.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-09 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17752450#comment-17752450
 ] 

Eric Milles commented on GROOVY-9510:
-

There was a discussion of using a closure resolve strategy of {{OWNER_FIRST}} 
in order to resolve static fields and properties of the enclosing class.  In 
this case, it is less of an issue since {{PreconditionContext}} or 
{{RetryConditionContext}} only respond to a few names.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-09 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17752432#comment-17752432
 ] 

Eric Milles commented on GROOVY-9510:
-

In addition to setting the delegate to {{PreconditionContext}}, spock also 
calls the closure with a {{PreconditionContext}} argument.  So I am able to do 
this:
{code:groovy}
import org.spockframework.runtime.extension.builtin.PreconditionContext
import spock.lang.*

@Requires({ PreconditionContext pc -> pc.os.windows })
class Groovy9510 extends Specification {
  String string
  def sample() {
   expect:
println 'works'
  }
}
{code}


> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-08 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17752188#comment-17752188
 ] 

Eric Milles commented on GROOVY-9510:
-

The method target was added to help this and GROOVY-10192.  No support was 
added to the type checker.  Not sure if IntelliJ added any support or not.  I 
removed the target in this commit, but I could put it back if it is still 
useful.  
https://github.com/apache/groovy/commit/5f8c82e9c88bb7087bdf134f2864d7ca9008b9e7

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-07 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751790#comment-17751790
 ] 

Leonard Brünings commented on GROOVY-9510:
--

Adding a type parameter is definitely doable. I'll have to check if IntelliJ 
can also resolve parametrized types.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-07 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751637#comment-17751637
 ] 

Eric Milles commented on GROOVY-9510:
-

One possibility for handling "getInstance()" and "getShared()" is to declare a 
type parameter.
{code:java}
class PreconditionContext {
  S getInstance() { ... }
  S getShared() { ... }
}
{code}

Then when indicating the type in DSLD, it would be given with a type argument:
{code:groovy}
contribute(...) {
  for (AnnotationNode pre : conditions) {
Expression value= pre.getMember('value')
if (value instanceof ClosureExpression && isInClosure(value, currentNode)) {
  delegateType = 
resolver.resolve("org.spockframework.runtime.extension.builtin.PreconditionContext<$currentType.name>")
  ...
}
  }
}
{code}

Note: I also tried "Inferencing Suggestions" which lets a user specify the type 
of a variable like "instance".  The drawback with that feature is you get one 
type per project.  So not a good option.

I also tried just checking for "PreconditionContext" or "RetryConditionContext" 
and changing the return type.  This does work, but requires each IDE to make a 
change and cannot extend to a new situation.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-06 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751410#comment-17751410
 ] 

Eric Milles commented on GROOVY-9510:
-

Here is what I have at the moment.  I worked out the hover display.  And I am 
going to check on some other ways to handle "getInstance()" and "getShared()".

{code:groovy}
import org.codehaus.groovy.ast.*
import org.codehaus.groovy.ast.expr.*

boolean isInClosure(ClosureExpression closure, ASTNode node) {
  final boolean[] result = new boolean[1]

  closure.visit(new CodeVisitorSupport() {
@Override
void visitConstantExpression(ConstantExpression expression) {
  if (expression == node) result[0] = true
}
@Override
void visitVariableExpression(VariableExpression expression) {
  if (expression == node) result[0] = true
}
  })

  return result[0]
}

def hasPrecondition = { annotatedBy(name('spock.lang.Requires') | 
name('spock.lang.IgnoreIf') | name('spock.lang.PendingFeatureIf')) }

contribute(inClosure() & isThisType() & 
enclosingClass(subType('spock.lang.Specification')) & 
(enclosingClass(conditions: hasPrecondition()) | enclosingMethod(conditions: 
hasPrecondition( {
  for (AnnotationNode pre : conditions) {
Expression value= pre.getMember('value')
if (value instanceof ClosureExpression && isInClosure(value, currentNode)) {
  delegatesTo type: 
resolver.resolve('org.spockframework.runtime.extension.builtin.PreconditionContext')
  provider = 'Spock framework'
  return
}
  }
}

contribute(inClosure() & isThisType() & 
enclosingClass(subType('spock.lang.Specification')) & 
(enclosingClass(annotations: annotatedBy('spock.lang.Retry')) | 
enclosingMethod(annotations: annotatedBy('spock.lang.Retry' {
  for (AnnotationNode retry : annotations) {
Expression cond = retry.getMember('condition')
if (cond instanceof ClosureExpression && isInClosure(cond, currentNode)) {
  delegatesTo type: 
resolver.resolve('org.spockframework.runtime.extension.builtin.RetryConditionContext')
  provider = 'Spock framework'
  return
}
  }
}
{code}

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-06 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751390#comment-17751390
 ] 

Leonard Brünings commented on GROOVY-9510:
--

I tried to do the equivalent in GDSL, but unfortunately {{delegatesTo}} wins in 
IntelliJ.
{code:groovy}
  property name: 'instance', type: currentType, readOnly: true
  method name: 'getInstance', type: currentType, params: [:]
  property name: 'shared', type: currentType, readOnly: true
  method name: 'getShared', type: currentType, params: [:]
{code}



> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-06 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751382#comment-17751382
 ] 

Eric Milles commented on GROOVY-9510:
-

I’m working on isInClosure. At the moment I just have enough for a very simple 
case. And I may provide something via the DSLD meta-DSL to do it.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-06 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751378#comment-17751378
 ] 

Leonard Brünings commented on GROOVY-9510:
--

{{@Retry}} delegates to 
[org.spockframework.runtime.extension.builtin.RetryConditionContext|https://github.com/spockframework/spock/blob/3a9b830ded6ba95f10f51e971ca00e2fa10bccf3/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/RetryConditionContext.java]
 which has a {{getInstance()}} method returning the specification instance as 
well.

Is the method {{isInClosure}} missing its body, or does it work by some magic 
due do its argument declaration when it is called without in the {{contribute}} 
clause?


{quote}I can’t think of a way to indicate those methods return type is the 
containing spec class, besides DSLD/GDSL.{quote}

Yeah, that's what I expected and not a problem. The this goes beyond the simple 
type annotation proposal.
However, it might work by introducing helper annotations to put on those 
methods that help the IDE to figure it out. {{@ReturnsEnclosingClass}}, or 
something.
Although, that might be too special cased.

Thank you for this productive interaction.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-05 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751327#comment-17751327
 ] 

Eric Milles commented on GROOVY-9510:
-

Does {{spock.lang.Retry}}'s {{condition}} attribute work the same way?  Are 
there any others?

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-05 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751326#comment-17751326
 ] 

Eric Milles commented on GROOVY-9510:
-

Here is a more complete example that handles the 2 annotation types and checks 
for closure containment.  The hover is not so good, but that's a greclipse 
problem that I can remedy.  And I do have some duplication in proposals because 
"method name:'getInstance', ..." and "delegatesTo type:..." both provide 
"getInstance".

{code:groovy}
import org.codehaus.groovy.ast.*
import org.codehaus.groovy.ast.expr.*

boolean isInClosure(ClosureExpression closure, ASTNode node) {
  // leverage closure.visit(...) to determine if node is within
}

def hasPrecondition = { annotatedBy(name('spock.lang.Requires') | 
name('spock.lang.IgnoreIf') | name('spock.lang.PendingFeatureIf')) }

contribute(inClosure() & isThisType() & 
enclosingClass(subType('spock.lang.Specification')) & 
(enclosingClass(conditions: hasPrecondition()) | enclosingMethod(conditions: 
hasPrecondition( {
  for (AnnotationNode pre : conditions) {
Expression value= pre.getMember('value')
if (value instanceof ClosureExpression && isInClosure(value, currentNode)) {
  property name: 'instance', type: currentType, readOnly: true
  method name: 'getInstance', type: currentType, params: [:]
  property name: 'shared', type: currentType, readOnly: true
  method name: 'getShared', type: currentType, params: [:]
  // must follow method/property contributions that PreconditionContext 
also provides
  delegatesTo type: 
resolver.resolve('org.spockframework.runtime.extension.builtin.PreconditionContext')
  provider = 'Spock framework'
  return
}
  }
}
{code}

 !screenshot-1.png! 

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png, screenshot-1.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-05 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751315#comment-17751315
 ] 

Eric Milles commented on GROOVY-9510:
-

I can’t think of a way to indicate those methods return type is the containing 
spec class, besides DSLD/GDSL.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-05 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751310#comment-17751310
 ] 

Leonard Brünings commented on GROOVY-9510:
--

Yes, they are both of the type of the spec class, just different instances.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751218#comment-17751218
 ] 

Eric Milles commented on GROOVY-9510:
-

I mean to say what is the difference between “instance” and “shared instance”?  
Are they both of the type of the spec class?

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751205#comment-17751205
 ] 

Leonard Brünings commented on GROOVY-9510:
--

{{Object}}, but you can see it here 
https://github.com/spockframework/spock/blob/master/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/PreconditionContext.java#L84-L111



> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751199#comment-17751199
 ] 

Eric Milles commented on GROOVY-9510:
-

What is the type of the “shared” property?

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751198#comment-17751198
 ] 

Leonard Brünings commented on GROOVY-9510:
--

You are talking about a generic type parameter right, not a getter that returns 
a class?
At the moment there isn't either, it should use the type of the annotated 
Specification.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751197#comment-17751197
 ] 

Eric Milles commented on GROOVY-9510:
-

Adding support for the other annotation types is no problem. I just gave a kwik 
sample. 

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751193#comment-17751193
 ] 

Eric Milles commented on GROOVY-9510:
-

Is the type of either given by a type parameter of PreconditionContext?

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751188#comment-17751188
 ] 

Eric Milles commented on GROOVY-9510:
-

I included enclosingClass but did not test. To add type info for getInstance 
and getShared, you can declare a “method” addition in the pointcut body. I’ll 
update when I am back at my terminal.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751176#comment-17751176
 ] 

Leonard Brünings commented on GROOVY-9510:
--

Does your DSLD version also work for class-level annotations?

{code:groovy}
import spock.lang.IgnoreIf
import spock.lang.Requires
import spock.lang.Specification

@Requires({ jvm.java8Compatible })
@IgnoreIf(value = { jvm.isJava18Compatible() }, reason = "qed")
class Foo extends Specification{

@Requires({ jvm.java8Compatible })
@IgnoreIf(value = { jvm.isJava18Compatible() }, reason = "qed")
def "feature"() {
def cls = {
// shouldn't work here
true 
}
expect:
cls() == true
}
}
{code}

This is the example I was testing with. We have {{@Requires}}, {{@IgnoreIf}}, 
and {{@PendingFeatureIf}}.


> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751173#comment-17751173
 ] 

Eric Milles commented on GROOVY-9510:
-

I'm going to poke around to see why {{DelegatesTo}} has method target.  It 
looks like parameter is the only type-checked target type.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751171#comment-17751171
 ] 

Leonard Brünings commented on GROOVY-9510:
--

After giving it yet another try, much trial, and error and reading through 
IntelliJ's source I managed to get this:
{code:groovy}
def conditionalExtensions = ['spock.lang.Requires', 'spock.lang.IgnoreIf', 
'spock.lang.PendingFeatureIf'].collect { annot -> context(ctype: 
"spock.lang.Specification", scope: closureScope(annotationName: annot))}
contributor(conditionalExtensions, {

delegatesTo(findClass('org.spockframework.runtime.extension.builtin.PreconditionContext'))
})
{code}
I guess, this works fine, as long as the annotation only has a single closure.

I assume your example would be the DSLD variant?


Yes, I think type use would be more elegant than the alternative of allowing it 
for methods and putting it before .

{code:java}
public @interface Requires {
  @DelegatesTo(PreconditionContext.class) Class value();
}
{code}



> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751167#comment-17751167
 ] 

Eric Milles commented on GROOVY-9510:
-

{{DelegatesTo}} does support a method target.  I'm not sure if the intent is 
for methods that return a closure.  But you should be able to mark up your 
{{value()}} method.  Do you get a compiler error if you do this?

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
> Attachments: image-2023-08-04-11-04-29-834.png
>
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751153#comment-17751153
 ] 

Eric Milles commented on GROOVY-9510:
-

So one option would be to support {{@ClosureParams}} and {{@DelegatesTo}} as 
type annotations so you could write it this way.  This would require STC 
changes to pick up on.
{code:java}
...
public @interface Requires {
  Class value();
}
{code}



> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2023-08-04 Thread Jira


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17751151#comment-17751151
 ] 

Leonard Brünings commented on GROOVY-9510:
--

[~emilles] can you provide some example how that would look, all I know is how 
to do this for method calls. 
I have tried numerous times to make sense of the GDSL/DSLD, but the examples 
are rather limited and I couldn't find any that deal with closures for 
annotations.
It is not for lack of trying that we don't have those in the Spock's GDSL/DSLD 
definitions yet.

bq. Any change to allow @ClosureParams or @DelegatesTo in new positions would 
require IDE changes to support for purposes of content assist, syntax 
highlighting, etc.

I don't really think that is an argument against doing this, as IDEs have to 
support new features all the time and have done so. 
There were also GDSLs/DSLDs for features that are now described with Groovy's 
built-in annotations, following that logic it wouldn't have made sense to add 
those annotations at all.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>  Labels: annotations
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (GROOVY-9510) DelegatesTo and similar for annotation member methods

2020-04-22 Thread Eric Milles (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17089727#comment-17089727
 ] 

Eric Milles commented on GROOVY-9510:
-

You can define DSLD or GDSL and include it with Spock so that IDE is informed 
that {{@Requires}} delegates to {{PreconditionContext}} within its value 
closure.

> DelegatesTo and similar for annotation member methods
> -
>
> Key: GROOVY-9510
> URL: https://issues.apache.org/jira/browse/GROOVY-9510
> Project: Groovy
>  Issue Type: Bug
>Reporter: Björn Kautler
>Priority: Major
>
> If you have an annotation with a closure field like for example this in Spock:
> {code:java}
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ElementType.TYPE, ElementType.METHOD})
> @ExtensionAnnotation(RequiresExtension.class)
> public @interface Requires {
>   Class value();
> }{code}
> you can use it like
> {code:java}
> @Requires({ os.windows }){code}
> But I see no way to add IDE-hints for that closure like 
> {{@DelegatesTo(PreconditionContext.class)}} as it is restriced to parameters.
> It would be nice if you could also annotate annotation member methods (and if 
> IDEs would then support that too).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)