<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed 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 com.intellij.debugger.engine.requests;

import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ArrayUtil;
import com.sun.jdi.Method;
import com.sun.jdi.ObjectCollectedException;
import com.sun.jdi.Value;
import com.sun.jdi.event.MethodExitEvent;
import com.sun.jdi.request.MethodExitRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;

/**
 * @author <NAME>
 *         Date: Nov 23, 2006
 */
public class MethodReturnValueWatcher  {
  private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.engine.requests.MethodReturnValueWatcher");
  private @Nullable Method myLastExecutedMethod;
  private @Nullable Value myLastMethodReturnValue;
  private @NotNull final MethodExitRequest myWatchMethodReturnValueRequest;
  private java.lang.reflect.Method myReturnValueMethod;
  private volatile boolean myIsTrackingEnabled;
  private boolean myFeatureEnabled;

  public MethodReturnValueWatcher(final MethodExitRequest request) {
    myWatchMethodReturnValueRequest = request;
    myIsTrackingEnabled = request.isEnabled();
    myFeatureEnabled = DebuggerSettings.getInstance().WATCH_RETURN_VALUES;
  }

  public boolean processMethodExitEvent(MethodExitEvent event) {
    if (event.request() != myWatchMethodReturnValueRequest) {
      return false;
    }
    try {
      myLastExecutedMethod = event.method();
      //myLastMethodReturnValue = event.returnValue();
      try {
        if (myReturnValueMethod == null) {
          //noinspection HardCodedStringLiteral
          myReturnValueMethod = MethodExitEvent.class.getDeclaredMethod("returnValue", ArrayUtil.EMPTY_CLASS_ARRAY);
        }
        myLastMethodReturnValue = (Value)myReturnValueMethod.invoke(event);
      }
      catch (NoSuchMethodException ignored) {
      }
      catch (IllegalAccessException ignored) {<commit_msg>usability: MethodReturnValueWatcher to store results from non-void methods only  (IDEA-57994)<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed 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 com.intellij.debugger.engine.requests;

import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ArrayUtil;
import com.sun.jdi.Method;
import com.sun.jdi.ObjectCollectedException;
import com.sun.jdi.Value;
import com.sun.jdi.event.MethodExitEvent;
import com.sun.jdi.request.MethodExitRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;

/**
 * @author <NAME>
 *         Date: Nov 23, 2006
 */
public class MethodReturnValueWatcher  {
  private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.engine.requests.MethodReturnValueWatcher");
  private @Nullable Method myLastExecutedMethod;
  private @Nullable Value myLastMethodReturnValue;
  private @NotNull final MethodExitRequest myWatchMethodReturnValueRequest;
  private java.lang.reflect.Method myReturnValueMethod;
  private volatile boolean myIsTrackingEnabled;
  private boolean myFeatureEnabled;

  public MethodReturnValueWatcher(final MethodExitRequest request) {
    myWatchMethodReturnValueRequest = request;
    myIsTrackingEnabled = request.isEnabled();
    myFeatureEnabled = DebuggerSettings.getInstance().WATCH_RETURN_VALUES;
  }

  public boolean processMethodExitEvent(MethodExitEvent event) {
    if (event.request() != myWatchMethodReturnValueRequest) {
      return false;
    }
    try {
      final Method method = event.method();
      //myLastMethodReturnValue = event.returnValue();
      try {
        if (myReturnValueMethod == null) {
          //noinspection HardCodedStringLiteral
          myReturnValueMethod = MethodExitEvent.class.getDeclaredMethod("returnValue", ArrayUtil.EMPTY_CLASS_ARRAY);
        }
        final Value retVal = (Value)myReturnValueMethod.invoke(event);
        
        if (method == null || !"void".equals(method.returnTypeName())) {
          // remember methods with non-void return types only
          myLastExecutedMethod = method;
          myLastMethodReturnValue = retVal;
        }
      }
      catch (NoSuchMethodException ignored) {
      }
      catch (IllegalAccessException ignored) {
{'fraction_non_alphanumeric': 0.08371163973125113, 'fraction_numerical': 0.007445069911022335, 'mean_word_length': 4.2208530805687206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5400540', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1474, 'n_words': 400}