milamberspace commented on code in PR #6860:
URL: https://github.com/apache/jmeter/pull/6860#discussion_r4732222521


##########
src/dist/src/dist/expected_release_jars.csv:
##########
@@ -2,6 +2,7 @@
 31094,annotations-26.1.0.jar
 6806,apiguardian-api-1.1.2.jar
 126151,asm-9.10.1.jar
+159093,autocomplete-4.0.0.jar

Review Comment:
   This file no longer exists on master (#6846). After the rebase, please add 
`com.fifesoft:autocomplete` to 
`src/dist/src/dist/expected_release_artifacts.txt` instead. 
`-PupdateExpectedJars` regenerates it.



##########
src/core/src/main/java/org/apache/jmeter/util/JSR223BeanInfoSupport.java:
##########
@@ -83,7 +84,14 @@ protected Object[][] getContents() {
     };
 
     protected JSR223BeanInfoSupport(Class<? extends TestBean> beanClass) {
+        this(beanClass, false);
+    }
+
+    protected JSR223BeanInfoSupport(Class<? extends TestBean> beanClass, 
boolean hasSampleResultBinding) {

Review Comment:
   A single boolean only covers `SampleResult`. Other elements also have their 
own bindings:
   - `JSR223Assertion` binds `AssertionResult`, which is probably the most 
useful object in an assertion script.
   - `JSR223Listener` binds `sampleEvent` and `sampleResult` (lower case).
   
   Could this take the element's extra bindings instead, e.g. a `String...` of 
names or a small enum, so that each BeanInfo declares what its element exposes, 
and `JSR223Completion` adds the matching variables/methods? The Sampler and 
Assertion would then pass `SampleResult` (plus `AssertionResult` for the 
assertion), and the Listener `sampleEvent`/`sampleResult`.



##########
xdocs/changes.xml:
##########
@@ -86,6 +86,7 @@ Summary
     <li><issue>6357</issue><pr>6358</pr> Ensure writable directories when 
copying template files while report generation.</li>
     <li><pr>6509</pr><pr>6675</pr> Synchronize recent file menu across 
multiple JVMs. Contributed by Corneliu C (https://github.com/KingRabbid)</li>
     <li><pr>6596</pr>Fallback to English locale when loading test plans that 
use string values for enum properties, so old sample plans load correctly even 
with non-English locales.</li>
+    <li><issue>4540</issue>Provide Ctrl+Space code completion for JMeter 
bindings in JSR223 script editors.</li>

Review Comment:
   Please add `<pr>6860</pr>` here, and also document the Ctrl+Space shortcut 
in `component_reference.xml` for the JSR223 elements.



##########
src/core/src/main/java/org/apache/jmeter/gui/util/JSR223Completion.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.apache.jmeter.gui.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.fife.ui.autocomplete.AutoCompletion;
+import org.fife.ui.autocomplete.DefaultCompletionProvider;
+import org.fife.ui.autocomplete.DescWindowVisibility;
+import org.fife.ui.autocomplete.FunctionCompletion;
+import org.fife.ui.autocomplete.ParameterizedCompletion;
+import org.fife.ui.autocomplete.VariableCompletion;
+
+/**
+ * Installs Ctrl+Space completion for the bindings exposed to JSR223 scripts.
+ */
+public final class JSR223Completion {
+
+    public static final String SAMPLE_RESULT_BINDING = 
"jsr223.sampleResultBinding";
+
+    private JSR223Completion() {
+    }
+
+    public static AutoCompletion install(JSyntaxTextArea area) {
+        return install(area, false);
+    }
+
+    public static AutoCompletion install(JSyntaxTextArea area, boolean 
hasSampleResultBinding) {
+        AutoCompletion completion = new 
AutoCompletion(createProvider(hasSampleResultBinding));
+        completion.setAutoActivationEnabled(false);
+        completion.setDescWindowVisibility(DescWindowVisibility.ALWAYS);
+        completion.setParameterAssistanceEnabled(true);
+        completion.install(area);
+        return completion;
+    }
+
+    static DefaultCompletionProvider createProvider(boolean 
hasSampleResultBinding) {
+        DefaultCompletionProvider provider = new DefaultCompletionProvider() {
+            @Override
+            protected boolean isValidChar(char ch) {
+                return super.isValidChar(ch) || ch == '.';
+            }
+        };
+        provider.setParameterizedCompletionParams('(', ", ", ')');
+
+        variable(provider, "vars", "JMeterVariables", "Thread-local JMeter 
variables");
+        variable(provider, "props", "java.util.Properties", "JMeter properties 
shared by all threads");
+        variable(provider, "ctx", "JMeterContext", "Current thread context");
+        variable(provider, "log", "org.slf4j.Logger", "Logger for jmeter.log");
+        variable(provider, "sampler", "Sampler", "The current sampler");
+        variable(provider, "prev", "SampleResult", "Previous sample result");
+        variable(provider, "Label", "String", "Element name");
+        variable(provider, "FileName", "String", "Script file name");
+        variable(provider, "Parameters", "String", "Parameters field as one 
string");
+        variable(provider, "args", "String[]", "Parameters split on 
whitespace");
+        variable(provider, "OUT", "java.io.PrintStream", "System.out");
+
+        method(provider, "vars.get", "String", "Get variable value", "String 
name");
+        method(provider, "vars.put", "void", "Set variable value", "String 
name", "String value");
+        method(provider, "vars.getObject", "Object", "Get object variable", 
"String name");
+        method(provider, "vars.putObject", "void", "Set object variable", 
"String name", "Object value");
+        method(provider, "vars.remove", "void", "Remove variable", "String 
name");

Review Comment:
   Nit: `JMeterVariables.remove` returns `Object` (the removed value), not 
`void`.



##########
src/core/src/main/java/org/apache/jmeter/testbeans/gui/TypeEditor.java:
##########
@@ -48,6 +48,12 @@ PropertyEditor getInstance(PropertyDescriptor descriptor) {
             return new TextAreaEditor(descriptor);
         }
     },
+    JSR223TextAreaEditor {

Review Comment:
   Nit: nothing uses `ordinal()`/`values()` on this enum today, but adding the 
new constant at the end would be safer than inserting it in the middle.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to