ileasile commented on a change in pull request #3440: [ZEPPELIN-4323] Kotlin 
support for Spark interpreter
URL: https://github.com/apache/zeppelin/pull/3440#discussion_r344468835
 
 

 ##########
 File path: 
kotlin/src/main/java/org/apache/zeppelin/kotlin/reflect/ContextUpdater.java
 ##########
 @@ -0,0 +1,150 @@
+/*
+ * 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.zeppelin.kotlin.reflect;
+
+import org.jetbrains.kotlin.cli.common.repl.AggregatedReplStageState;
+import org.jetbrains.kotlin.cli.common.repl.ReplHistoryRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import kotlin.Pair;
+import kotlin.reflect.KFunction;
+import kotlin.reflect.KProperty;
+import kotlin.reflect.jvm.ReflectJvmMapping;
+
+/**
+ * ContextUpdater updates current user-defined functions and variables
+ * to use in completion and KotlinContext.
+ */
+public class ContextUpdater {
+  private final Logger logger = LoggerFactory.getLogger(ContextUpdater.class);
+  private final Set<Method> objectMethods =
+      new HashSet<>(Arrays.asList(Object.class.getMethods()));
+  
+  private AggregatedReplStageState<?, ?> state;
+  private Map<String, KotlinVariableInfo> vars;
+  private Set<KotlinFunctionInfo> functions;
+
+  public ContextUpdater(AggregatedReplStageState<?, ?> state,
+                        Map<String, KotlinVariableInfo> vars, 
+                        Set<KotlinFunctionInfo> functions) {
+    this.state = state;
+    this.vars = vars;
+    this.functions = functions;
+  }
+
+  public void update() {
+    try {
+      List<Object> lines = getLines();
+      refreshVariables(lines);
+      refreshMethods(lines);
+    } catch (ReflectiveOperationException | NullPointerException e) {
+      logger.error("Exception updating current variables", e);
+    }
+  }
+
+  private void refreshMethods(List<Object> lines) {
+    functions.clear();
+    for (Object line : lines) {
+      Method[] methods = line.getClass().getMethods();
+      for (Method method : methods) {
+        if (objectMethods.contains(method) || method.getName().equals("main")) 
{
 
 Review comment:
   Ok, do you mean that `line` is an instance of `KotlinReceiver` (or its 
subclass) here?
   If yes, let's make an explicit type cast (maybe above in the code).
   If no, please clarify what's the nature of this variable and how may it be 
instantiated.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to