<commit_before>/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.ide.ext.java.client.navigation.filestructure;

import com.google.common.base.Optional;
import com.google.gwt.core.client.Scheduler;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.resources.SyntheticFile;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.ext.java.client.navigation.service.JavaNavigationService;
import org.eclipse.che.ide.ext.java.client.resource.SourceFolderMarker;
import org.eclipse.che.ide.ext.java.client.util.JavaUtil;
import org.eclipse.che.ide.ext.java.shared.dto.Region;
import org.eclipse.che.ide.ext.java.shared.dto.model.Member;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.util.loging.Log;

/**
 * The class that manages class structure window.
 *
 * @author <NAME>
 * @author <NAME>
 */
@Singleton
public class FileStructurePresenter implements FileStructure.ActionDelegate {
  private final FileStructure view;
  private final JavaNavigationService javaNavigationService;
  private final AppContext context;
  private final EditorAgent editorAgent;

  private TextEditor activeEditor;
  private boolean showInheritedMembers;
  private int cursorOffset;

  @Inject
  public FileStructurePresenter(
      FileStructure view,
      JavaNavigationService javaNavigationService,
      AppContext context,
      EditorAgent editorAgent) {
    this.view = view;
    this.javaNavigationService = javaNavigationService;
    this.context = context;
    this.editorAgent = editorAgent;
    this.view.setDelegate(this);
  }

  /**
   * Shows the structure of the opened class.
   *
   * @param editorPartPresenter the active editor
   */
  public void show(EditorPartPresenter editorPartPresenter) {
    if (!(editorPartPresenter instanceof TextEditor)) {
      Log.error(getClass(), "Open Declaration support only TextEditor as editor");
      return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    cursorOffset = activeEditor.getCursorOffset();
    VirtualFile file = activeEditor.getEditorInput().getFile();

    if (file instanceof Resource) {
      final Optional<Project> project = ((Resource) file).getRelatedProject();

      final Optional<Resource> srcFolder =
          ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);

      if (!srcFolder.isPresent()) {
        return;
      }

      final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
      javaNavigationService
          .getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers)
          .then(
              unit -> {
                view.setTitleCaption(editorPartPresenter.getEditorInput().getFile().getName());
                view.setStructure(unit, showInheritedMembers);
                view.showDialog();
                showInheritedMembers = !showInheritedMembers;
              })
          .catchError(
              arg -> {
                Log.error(FileStructurePresenter.class, arg.getMessage());
              });
    }
  }

  /** {@inheritDoc} */
  @Override
  public void actionPerformed(final Member member) {
    view.close();
    if (member.isBinary()) {

      final Resource resource = context.getResource();

      if (resource == null) {
        return;
      }

      final Optional<Project> project = resource.getRelatedProject();

      javaNavigationService
          .getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath())
          .then(
              entry -> {
                javaNavigationService
                    .getContent(
                        project.get().getLocation(),
                        member.getLibId(),
                        Path.valueOf(entry.getPath()))
                    .then(
                        content -> {
                          final String clazz =<commit_msg>Reset showInheritedMembers flag on each action calls (#8879)<commit_after>/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.ide.ext.java.client.navigation.filestructure;

import com.google.common.base.Optional;
import com.google.gwt.core.client.Scheduler;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.resources.SyntheticFile;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.ext.java.client.navigation.service.JavaNavigationService;
import org.eclipse.che.ide.ext.java.client.resource.SourceFolderMarker;
import org.eclipse.che.ide.ext.java.client.util.JavaUtil;
import org.eclipse.che.ide.ext.java.shared.dto.Region;
import org.eclipse.che.ide.ext.java.shared.dto.model.Member;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.util.loging.Log;

/**
 * The class that manages class structure window.
 *
 * @author <NAME>
 * @author <NAME>
 */
@Singleton
public class FileStructurePresenter implements FileStructure.ActionDelegate {
  private final FileStructure view;
  private final JavaNavigationService javaNavigationService;
  private final AppContext context;
  private final EditorAgent editorAgent;

  private TextEditor activeEditor;
  private boolean showInheritedMembers;
  private int cursorOffset;

  @Inject
  public FileStructurePresenter(
      FileStructure view,
      JavaNavigationService javaNavigationService,
      AppContext context,
      EditorAgent editorAgent) {
    this.view = view;
    this.javaNavigationService = javaNavigationService;
    this.context = context;
    this.editorAgent = editorAgent;
    this.view.setDelegate(this);
  }

  /**
   * Shows the structure of the opened class.
   *
   * @param editorPartPresenter the active editor
   */
  public void show(EditorPartPresenter editorPartPresenter) {
    if (!(editorPartPresenter instanceof TextEditor)) {
      Log.error(getClass(), "Open Declaration support only TextEditor as editor");
      return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    cursorOffset = activeEditor.getCursorOffset();
    VirtualFile file = activeEditor.getEditorInput().getFile();

    if (file instanceof Resource) {
      final Optional<Project> project = ((Resource) file).getRelatedProject();

      final Optional<Resource> srcFolder =
          ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);

      if (!srcFolder.isPresent()) {
        return;
      }

      final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
      javaNavigationService
          .getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers)
          .then(
              unit -> {
                view.setTitleCaption(editorPartPresenter.getEditorInput().getFile().getName());
                view.setStructure(unit, showInheritedMembers);
                view.showDialog();
                showInheritedMembers = !showInheritedMembers;
              })
          .catchError(
              arg -> {
                Log.error(FileStructurePresenter.class, arg.getMessage());
              });
    }
  }

  /** {@inheritDoc} */
  @Override
  public void actionPerformed(final Member member) {
    view.close();
    showInheritedMembers = false;
    if (member.isBinary()) {

      final Resource resource = context.getResource();

      if (resource == null) {
        return;
      }

      final Optional<Project> project = resource.getRelatedProject();

      javaNavigationService
          .getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath())
          .then(
              entry -> {
                javaNavigationService
                    .getContent(
                        project.get().getLocation(),
                        member.getLibId(),
                        Path.valueOf(entry.getPath()))
                    .then(
                        content -> {
                          final String clazz =
{'fraction_non_alphanumeric': 0.10559916274201989, 'fraction_numerical': 0.0029304029304029304, 'mean_word_length': 3.003351487222455, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '6083884', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2557, 'n_words': 545}