You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/03/09 10:00:28 UTC

[GitHub] [netbeans] ppisl opened a new pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

ppisl opened a new pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736


   
   This is implemented issue #3730.
   
   Added basic code completion for Spock test framework:
     *  Spock block names are offered inside methods if the class extends the Spock specification.
     *  Parameter names are offered if the parameters are defined in a method name that is annotated with @Unroll
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r831576661



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;

Review comment:
       Good idea. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r831575884



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockMethodParamCompletion.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.ListIterator;
+import java.util.Map;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockMethodParamCompletion  extends BaseCompletion {
+    
+    private static class SpockParameter implements Variable {
+
+        private final String name;
+
+        public SpockParameter(String name) {
+            this.name = name;
+        }
+        
+        @Override
+        public ClassNode getType() {
+            return ClassHelper.DYNAMIC_TYPE;
+        }
+
+        @Override
+        public ClassNode getOriginType() {
+            return ClassHelper.GROOVY_OBJECT_TYPE;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Expression getInitialExpression() {
+            return null;
+        }
+
+        @Override
+        public boolean hasInitialExpression() {
+            return false;
+        }
+
+        @Override
+        public boolean isInStaticContext() {
+            return false;
+        }
+
+        @Override
+        public boolean isDynamicTyped() {
+            return true;
+        }
+
+        @Override
+        public boolean isClosureSharedVariable() {
+            return false;
+        }
+
+        @Override
+        public void setClosureSharedVariable(boolean bln) {
+            
+        }
+
+        @Override
+        public int getModifiers() {
+            return 0;
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        boolean updated = false;
+        if ((request.location == CaretLocation.INSIDE_METHOD 
+                || request.location == CaretLocation.INSIDE_CLOSURE) 
+                && SpockUtils.isInSpecificationClass(request)) {
+            
+            ListIterator<ASTNode> leafToRoot = request.path.leafToRoot();
+            
+            MethodNode methodNode = null;
+            while(leafToRoot.hasNext()) {
+                ASTNode next = leafToRoot.next();
+                if (next instanceof MethodNode) {
+                    methodNode = (MethodNode) next;
+                    break;
+                }    
+            }
+            String name = null;
+            if (methodNode != null) {
+                name = methodNode.getName();
+            }
+            
+            if (name != null && name.contains("#")) {   //NOI18N

Review comment:
       You are right, the params in the name method is newer and in parameter of @Unroll is obsolete. But we should support for both cases. Can we treat it as a bug?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r832297560



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockBlockNamesCompletion.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.Map;
+import javax.swing.ImageIcon;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.csl.api.ElementKind;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.elements.KeywordElement;
+import org.openide.util.ImageUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockBlockNamesCompletion extends BaseCompletion {
+
+    enum SpockBlock {
+        SPOCK_and("and"),
+        SPOCK_cleanup("cleanup"),
+        SPOCK_expect("expect"),
+        SPOCK_given("given"),
+        SPOCK_setup("setup"),
+        SPOCK_then("then"),
+        SPOCK_when("when"),
+        SPOCK_where("where");
+        
+        private final String name;
+
+        private SpockBlock(String name) {
+            this.name = name;
+        }   
+    }
+    
+    static class SpockBlockItem extends CompletionItem {
+        private static final String ICON_PATH = "org/netbeans/modules/groovy/editor/resources/spock-16x16.png"; //NOI18N
+        private final String name;
+        private static volatile ImageIcon spockIcon;
+
+        public SpockBlockItem(String name, int anchorOffset) {
+            super(new KeywordElement(name), anchorOffset);
+            this.name = name;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public ElementKind getKind() {
+            return ElementKind.KEYWORD;
+        }
+        
+        @Override
+        public ImageIcon getIcon() {
+            if (spockIcon == null) {
+                spockIcon = ImageUtilities.loadImageIcon(ICON_PATH, false);
+            }
+            return spockIcon;
+        }
+
+        @Override
+        public String getInsertPrefix() {
+            return getName() + ": ";
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        if (request.location == CaretLocation.INSIDE_METHOD 
+                && SpockUtils.isInSpecificationClass(request)) {
+            for (SpockBlock block: SpockBlock.values()) {

Review comment:
       No, because it's called only from complete keywords context, which means that it has to be the first token after a whitespace. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl merged pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl merged pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r832293157



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] sdedic commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r829741824



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockMethodParamCompletion.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.ListIterator;
+import java.util.Map;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockMethodParamCompletion  extends BaseCompletion {
+    
+    private static class SpockParameter implements Variable {
+
+        private final String name;
+
+        public SpockParameter(String name) {
+            this.name = name;
+        }
+        
+        @Override
+        public ClassNode getType() {
+            return ClassHelper.DYNAMIC_TYPE;
+        }
+
+        @Override
+        public ClassNode getOriginType() {
+            return ClassHelper.GROOVY_OBJECT_TYPE;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Expression getInitialExpression() {
+            return null;
+        }
+
+        @Override
+        public boolean hasInitialExpression() {
+            return false;
+        }
+
+        @Override
+        public boolean isInStaticContext() {
+            return false;
+        }
+
+        @Override
+        public boolean isDynamicTyped() {
+            return true;
+        }
+
+        @Override
+        public boolean isClosureSharedVariable() {
+            return false;
+        }
+
+        @Override
+        public void setClosureSharedVariable(boolean bln) {
+            
+        }
+
+        @Override
+        public int getModifiers() {
+            return 0;
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        boolean updated = false;
+        if ((request.location == CaretLocation.INSIDE_METHOD 
+                || request.location == CaretLocation.INSIDE_CLOSURE) 
+                && SpockUtils.isInSpecificationClass(request)) {
+            
+            ListIterator<ASTNode> leafToRoot = request.path.leafToRoot();
+            
+            MethodNode methodNode = null;
+            while(leafToRoot.hasNext()) {
+                ASTNode next = leafToRoot.next();
+                if (next instanceof MethodNode) {
+                    methodNode = (MethodNode) next;
+                    break;
+                }    
+            }
+            String name = null;
+            if (methodNode != null) {
+                name = methodNode.getName();
+            }
+            
+            if (name != null && name.contains("#")) {   //NOI18N
+                String[] parts = name.split("#");       //NOI18N
+                
+                for (int i = 1; i < parts.length; i++) {
+                    String part = parts[i].trim();
+                    if (!part.isEmpty()) {

Review comment:
       Since the `name` is already matched by a regex in split() ... wouldn't it be faster to iterate using `Pattern.compile("#\\p{Alpha}[\\p{Alnum}$_]*)[. ]?*).matcher(name)` ?

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockMethodParamCompletion.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.ListIterator;
+import java.util.Map;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockMethodParamCompletion  extends BaseCompletion {
+    
+    private static class SpockParameter implements Variable {
+
+        private final String name;
+
+        public SpockParameter(String name) {
+            this.name = name;
+        }
+        
+        @Override
+        public ClassNode getType() {
+            return ClassHelper.DYNAMIC_TYPE;
+        }
+
+        @Override
+        public ClassNode getOriginType() {
+            return ClassHelper.GROOVY_OBJECT_TYPE;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Expression getInitialExpression() {
+            return null;
+        }
+
+        @Override
+        public boolean hasInitialExpression() {
+            return false;
+        }
+
+        @Override
+        public boolean isInStaticContext() {
+            return false;
+        }
+
+        @Override
+        public boolean isDynamicTyped() {
+            return true;
+        }
+
+        @Override
+        public boolean isClosureSharedVariable() {
+            return false;
+        }
+
+        @Override
+        public void setClosureSharedVariable(boolean bln) {
+            
+        }
+
+        @Override
+        public int getModifiers() {
+            return 0;
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        boolean updated = false;
+        if ((request.location == CaretLocation.INSIDE_METHOD 
+                || request.location == CaretLocation.INSIDE_CLOSURE) 
+                && SpockUtils.isInSpecificationClass(request)) {
+            
+            ListIterator<ASTNode> leafToRoot = request.path.leafToRoot();
+            
+            MethodNode methodNode = null;
+            while(leafToRoot.hasNext()) {
+                ASTNode next = leafToRoot.next();
+                if (next instanceof MethodNode) {
+                    methodNode = (MethodNode) next;
+                    break;
+                }    
+            }
+            String name = null;
+            if (methodNode != null) {
+                name = methodNode.getName();
+            }
+            
+            if (name != null && name.contains("#")) {   //NOI18N

Review comment:
       Q: it seems that syntax 
   ```
   def "#name should have length #length"() {
   ```
   is supported, but the syntax
   ```
    @Unroll("#name should have length #length")
    def "name length"() {
   ```
   is not ?
   
   I can't see a check for `@Unroll` annotation either

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;
+        while (classNode != null && !visited.contains(name = classNode.getName())) {
+            if ("spock.lang.Specification".equals(name)) {
+                return true;
+            }
+            visited.add(name);
+            classNode = classNode.getSuperClass();
+        }
+        return false;
+    }
+    
+    static boolean isFirstStatement(final CompletionContext request) {
+        TokenSequence<GroovyTokenId> ts = LexUtilities.getGroovyTokenSequence(request.doc, 1);
+
+        if (ts != null) {

Review comment:
       Same method in `KeywordCompletion`, consider reusing this utility there.

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;

Review comment:
       Idea: If there was a `GroovyParserResut` available from the `CompletionContext`, one could do 
   ```
   context.declaringClass.isDerivedFrom(
      parserResult.resolveClassName("spock.lang.Specification")
   )
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r832292549



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;
+        while (classNode != null && !visited.contains(name = classNode.getName())) {
+            if ("spock.lang.Specification".equals(name)) {
+                return true;
+            }
+            visited.add(name);
+            classNode = classNode.getSuperClass();
+        }
+        return false;
+    }
+    
+    static boolean isFirstStatement(final CompletionContext request) {
+        TokenSequence<GroovyTokenId> ts = LexUtilities.getGroovyTokenSequence(request.doc, 1);
+
+        if (ts != null) {

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] sdedic commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r829735500



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockBlockNamesCompletion.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.Map;
+import javax.swing.ImageIcon;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.csl.api.ElementKind;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.elements.KeywordElement;
+import org.openide.util.ImageUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockBlockNamesCompletion extends BaseCompletion {
+
+    enum SpockBlock {
+        SPOCK_and("and"),
+        SPOCK_cleanup("cleanup"),
+        SPOCK_expect("expect"),
+        SPOCK_given("given"),
+        SPOCK_setup("setup"),
+        SPOCK_then("then"),
+        SPOCK_when("when"),
+        SPOCK_where("where");
+        
+        private final String name;
+
+        private SpockBlock(String name) {
+            this.name = name;
+        }   
+    }
+    
+    static class SpockBlockItem extends CompletionItem {
+        private static final String ICON_PATH = "org/netbeans/modules/groovy/editor/resources/spock-16x16.png"; //NOI18N
+        private final String name;
+        private static volatile ImageIcon spockIcon;
+
+        public SpockBlockItem(String name, int anchorOffset) {
+            super(new KeywordElement(name), anchorOffset);
+            this.name = name;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public ElementKind getKind() {
+            return ElementKind.KEYWORD;
+        }
+        
+        @Override
+        public ImageIcon getIcon() {
+            if (spockIcon == null) {
+                spockIcon = ImageUtilities.loadImageIcon(ICON_PATH, false);
+            }
+            return spockIcon;
+        }
+
+        @Override
+        public String getInsertPrefix() {
+            return getName() + ": ";
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        if (request.location == CaretLocation.INSIDE_METHOD 
+                && SpockUtils.isInSpecificationClass(request)) {
+            for (SpockBlock block: SpockBlock.values()) {

Review comment:
       Is the context sufficiently narrow - will these compl items NOT be offered if  i.e.  inside an expression like`obj.wh|` ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] sdedic commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r829735500



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockBlockNamesCompletion.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.Map;
+import javax.swing.ImageIcon;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.csl.api.ElementKind;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.elements.KeywordElement;
+import org.openide.util.ImageUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockBlockNamesCompletion extends BaseCompletion {
+
+    enum SpockBlock {
+        SPOCK_and("and"),
+        SPOCK_cleanup("cleanup"),
+        SPOCK_expect("expect"),
+        SPOCK_given("given"),
+        SPOCK_setup("setup"),
+        SPOCK_then("then"),
+        SPOCK_when("when"),
+        SPOCK_where("where");
+        
+        private final String name;
+
+        private SpockBlock(String name) {
+            this.name = name;
+        }   
+    }
+    
+    static class SpockBlockItem extends CompletionItem {
+        private static final String ICON_PATH = "org/netbeans/modules/groovy/editor/resources/spock-16x16.png"; //NOI18N
+        private final String name;
+        private static volatile ImageIcon spockIcon;
+
+        public SpockBlockItem(String name, int anchorOffset) {
+            super(new KeywordElement(name), anchorOffset);
+            this.name = name;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public ElementKind getKind() {
+            return ElementKind.KEYWORD;
+        }
+        
+        @Override
+        public ImageIcon getIcon() {
+            if (spockIcon == null) {
+                spockIcon = ImageUtilities.loadImageIcon(ICON_PATH, false);
+            }
+            return spockIcon;
+        }
+
+        @Override
+        public String getInsertPrefix() {
+            return getName() + ": ";
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        if (request.location == CaretLocation.INSIDE_METHOD 
+                && SpockUtils.isInSpecificationClass(request)) {
+            for (SpockBlock block: SpockBlock.values()) {

Review comment:
       Is the context sufficiently narrow - will these compl items NOT be offered if  i.e.  inside an expression like`obj.wh|` ?

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockMethodParamCompletion.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.ListIterator;
+import java.util.Map;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockMethodParamCompletion  extends BaseCompletion {
+    
+    private static class SpockParameter implements Variable {
+
+        private final String name;
+
+        public SpockParameter(String name) {
+            this.name = name;
+        }
+        
+        @Override
+        public ClassNode getType() {
+            return ClassHelper.DYNAMIC_TYPE;
+        }
+
+        @Override
+        public ClassNode getOriginType() {
+            return ClassHelper.GROOVY_OBJECT_TYPE;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Expression getInitialExpression() {
+            return null;
+        }
+
+        @Override
+        public boolean hasInitialExpression() {
+            return false;
+        }
+
+        @Override
+        public boolean isInStaticContext() {
+            return false;
+        }
+
+        @Override
+        public boolean isDynamicTyped() {
+            return true;
+        }
+
+        @Override
+        public boolean isClosureSharedVariable() {
+            return false;
+        }
+
+        @Override
+        public void setClosureSharedVariable(boolean bln) {
+            
+        }
+
+        @Override
+        public int getModifiers() {
+            return 0;
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        boolean updated = false;
+        if ((request.location == CaretLocation.INSIDE_METHOD 
+                || request.location == CaretLocation.INSIDE_CLOSURE) 
+                && SpockUtils.isInSpecificationClass(request)) {
+            
+            ListIterator<ASTNode> leafToRoot = request.path.leafToRoot();
+            
+            MethodNode methodNode = null;
+            while(leafToRoot.hasNext()) {
+                ASTNode next = leafToRoot.next();
+                if (next instanceof MethodNode) {
+                    methodNode = (MethodNode) next;
+                    break;
+                }    
+            }
+            String name = null;
+            if (methodNode != null) {
+                name = methodNode.getName();
+            }
+            
+            if (name != null && name.contains("#")) {   //NOI18N
+                String[] parts = name.split("#");       //NOI18N
+                
+                for (int i = 1; i < parts.length; i++) {
+                    String part = parts[i].trim();
+                    if (!part.isEmpty()) {

Review comment:
       Since the `name` is already matched by a regex in split() ... wouldn't it be faster to iterate using `Pattern.compile("#\\p{Alpha}[\\p{Alnum}$_]*)[. ]?*).matcher(name)` ?

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockMethodParamCompletion.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.ListIterator;
+import java.util.Map;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockMethodParamCompletion  extends BaseCompletion {
+    
+    private static class SpockParameter implements Variable {
+
+        private final String name;
+
+        public SpockParameter(String name) {
+            this.name = name;
+        }
+        
+        @Override
+        public ClassNode getType() {
+            return ClassHelper.DYNAMIC_TYPE;
+        }
+
+        @Override
+        public ClassNode getOriginType() {
+            return ClassHelper.GROOVY_OBJECT_TYPE;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Expression getInitialExpression() {
+            return null;
+        }
+
+        @Override
+        public boolean hasInitialExpression() {
+            return false;
+        }
+
+        @Override
+        public boolean isInStaticContext() {
+            return false;
+        }
+
+        @Override
+        public boolean isDynamicTyped() {
+            return true;
+        }
+
+        @Override
+        public boolean isClosureSharedVariable() {
+            return false;
+        }
+
+        @Override
+        public void setClosureSharedVariable(boolean bln) {
+            
+        }
+
+        @Override
+        public int getModifiers() {
+            return 0;
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        boolean updated = false;
+        if ((request.location == CaretLocation.INSIDE_METHOD 
+                || request.location == CaretLocation.INSIDE_CLOSURE) 
+                && SpockUtils.isInSpecificationClass(request)) {
+            
+            ListIterator<ASTNode> leafToRoot = request.path.leafToRoot();
+            
+            MethodNode methodNode = null;
+            while(leafToRoot.hasNext()) {
+                ASTNode next = leafToRoot.next();
+                if (next instanceof MethodNode) {
+                    methodNode = (MethodNode) next;
+                    break;
+                }    
+            }
+            String name = null;
+            if (methodNode != null) {
+                name = methodNode.getName();
+            }
+            
+            if (name != null && name.contains("#")) {   //NOI18N

Review comment:
       Q: it seems that syntax 
   ```
   def "#name should have length #length"() {
   ```
   is supported, but the syntax
   ```
    @Unroll("#name should have length #length")
    def "name length"() {
   ```
   is not ?
   
   I can't see a check for `@Unroll` annotation either

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;
+        while (classNode != null && !visited.contains(name = classNode.getName())) {
+            if ("spock.lang.Specification".equals(name)) {
+                return true;
+            }
+            visited.add(name);
+            classNode = classNode.getSuperClass();
+        }
+        return false;
+    }
+    
+    static boolean isFirstStatement(final CompletionContext request) {
+        TokenSequence<GroovyTokenId> ts = LexUtilities.getGroovyTokenSequence(request.doc, 1);
+
+        if (ts != null) {

Review comment:
       Same method in `KeywordCompletion`, consider reusing this utility there.

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import org.codehaus.groovy.ast.ClassNode;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId;
+import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockUtils {
+    
+    public static boolean isInSpecificationClass(CompletionContext context) {
+        
+        Set<String> visited = new HashSet<>();
+        String name;
+        ClassNode classNode = context.declaringClass;

Review comment:
       Idea: If there was a `GroovyParserResut` available from the `CompletionContext`, one could do 
   ```
   context.declaringClass.isDerivedFrom(
      parserResult.resolveClassName("spock.lang.Specification")
   )
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] mbien commented on pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
mbien commented on pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#issuecomment-1062881755


   hi @ppisl, you can link to issues on the right side under "Development", this will close them automatically post integration ->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] ppisl commented on a change in pull request #3736: [NETBEANS-3730] Add simple code completion for Spock test framework

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3736:
URL: https://github.com/apache/netbeans/pull/3736#discussion_r832281771



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/SpockMethodParamCompletion.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 org.netbeans.modules.groovy.editor.completion;
+
+import java.util.ListIterator;
+import java.util.Map;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.netbeans.modules.csl.api.CompletionProposal;
+import org.netbeans.modules.groovy.editor.api.completion.CaretLocation;
+import org.netbeans.modules.groovy.editor.api.completion.CompletionItem;
+import org.netbeans.modules.groovy.editor.api.completion.util.CompletionContext;
+
+/**
+ *
+ * @author Petr Pisl
+ */
+public class SpockMethodParamCompletion  extends BaseCompletion {
+    
+    private static class SpockParameter implements Variable {
+
+        private final String name;
+
+        public SpockParameter(String name) {
+            this.name = name;
+        }
+        
+        @Override
+        public ClassNode getType() {
+            return ClassHelper.DYNAMIC_TYPE;
+        }
+
+        @Override
+        public ClassNode getOriginType() {
+            return ClassHelper.GROOVY_OBJECT_TYPE;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Expression getInitialExpression() {
+            return null;
+        }
+
+        @Override
+        public boolean hasInitialExpression() {
+            return false;
+        }
+
+        @Override
+        public boolean isInStaticContext() {
+            return false;
+        }
+
+        @Override
+        public boolean isDynamicTyped() {
+            return true;
+        }
+
+        @Override
+        public boolean isClosureSharedVariable() {
+            return false;
+        }
+
+        @Override
+        public void setClosureSharedVariable(boolean bln) {
+            
+        }
+
+        @Override
+        public int getModifiers() {
+            return 0;
+        }
+        
+    }
+    
+    @Override
+    public boolean complete(Map<Object, CompletionProposal> proposals, CompletionContext request, int anchor) {
+        boolean updated = false;
+        if ((request.location == CaretLocation.INSIDE_METHOD 
+                || request.location == CaretLocation.INSIDE_CLOSURE) 
+                && SpockUtils.isInSpecificationClass(request)) {
+            
+            ListIterator<ASTNode> leafToRoot = request.path.leafToRoot();
+            
+            MethodNode methodNode = null;
+            while(leafToRoot.hasNext()) {
+                ASTNode next = leafToRoot.next();
+                if (next instanceof MethodNode) {
+                    methodNode = (MethodNode) next;
+                    break;
+                }    
+            }
+            String name = null;
+            if (methodNode != null) {
+                name = methodNode.getName();
+            }
+            
+            if (name != null && name.contains("#")) {   //NOI18N

Review comment:
       I have implemented `@Unroll` with value. So this is resolved now. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists