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/21 21:56:18 UTC

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

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