public boolean equals(Object o) {
   if (o instanceof StructureViewTreeElementWrapper) {
     return Comparing.equal(
         unwrapValue(getValue()), unwrapValue(((StructureViewTreeElementWrapper) o).getValue()));
   } else if (o instanceof StructureViewTreeElement) {
     return Comparing.equal(unwrapValue(getValue()), ((StructureViewTreeElement) o).getValue());
   }
   return false;
 }
  public boolean equalsByActualOffset(@NotNull HighlightInfo info) {
    if (info == this) return true;

    return info.getSeverity() == getSeverity()
        && info.getActualStartOffset() == getActualStartOffset()
        && info.getActualEndOffset() == getActualEndOffset()
        && Comparing.equal(info.type, type)
        && Comparing.equal(info.gutterIconRenderer, gutterIconRenderer)
        && Comparing.equal(info.forcedTextAttributes, forcedTextAttributes)
        && Comparing.equal(info.forcedTextAttributesKey, forcedTextAttributesKey)
        && Comparing.strEqual(info.getDescription(), getDescription());
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == this) return true;
    if (!(obj instanceof HighlightInfo)) return false;
    HighlightInfo info = (HighlightInfo) obj;

    return info.getSeverity() == getSeverity()
        && info.startOffset == startOffset
        && info.endOffset == endOffset
        && Comparing.equal(info.type, type)
        && Comparing.equal(info.gutterIconRenderer, gutterIconRenderer)
        && Comparing.equal(info.forcedTextAttributes, forcedTextAttributes)
        && Comparing.equal(info.forcedTextAttributesKey, forcedTextAttributesKey)
        && Comparing.strEqual(info.getDescription(), getDescription());
  }
 private static boolean infoEquals(HighlightInfo expectedInfo, HighlightInfo info) {
   if (expectedInfo == info) return true;
   return info.getSeverity() == expectedInfo.getSeverity()
       && info.startOffset == expectedInfo.startOffset
       && info.endOffset == expectedInfo.endOffset
       && info.isAfterEndOfLine() == expectedInfo.isAfterEndOfLine()
       && (expectedInfo.type == WHATEVER || expectedInfo.type.equals(info.type))
       && (Comparing.strEqual(ANY_TEXT, expectedInfo.getDescription())
           || Comparing.strEqual(info.getDescription(), expectedInfo.getDescription()))
       && (expectedInfo.forcedTextAttributes == null
           || Comparing.equal(
               expectedInfo.getTextAttributes(null, null), info.getTextAttributes(null, null)))
       && (expectedInfo.forcedTextAttributesKey == null
           || expectedInfo.forcedTextAttributesKey.equals(info.forcedTextAttributesKey));
 }
  private static boolean addToPath(
      AbstractTreeNode<?> rootElement,
      Object element,
      ArrayList<AbstractTreeNode> result,
      Collection<Object> processedElements) {
    Object value = rootElement.getValue();
    if (value instanceof StructureViewTreeElement) {
      value = ((StructureViewTreeElement) value).getValue();
    }
    if (!processedElements.add(value)) {
      return false;
    }

    if (Comparing.equal(value, element)) {
      result.add(0, rootElement);
      return true;
    }

    Collection<? extends AbstractTreeNode> children = rootElement.getChildren();
    for (AbstractTreeNode child : children) {
      if (addToPath(child, element, result, processedElements)) {
        result.add(0, rootElement);
        return true;
      }
    }

    return false;
  }
 public void refreshPresentation() {
   // 1. vertical 2. number of lines 3. soft wraps (4. ignore spaces)
   PresentationState current = new PresentationState();
   if (myFragmentedContent != null && !Comparing.equal(myPresentationState, current)) {
     myFragmentedContent.recalculate();
     refreshData(myFragmentedContent);
   }
   myPreviousDiff.registerCustomShortcutSet(myPreviousDiff.getShortcutSet(), myParent);
   myNextDiff.registerCustomShortcutSet(myNextDiff.getShortcutSet(), myParent);
 }
  public Couple<String> setText(@Nullable final String text, @Nullable final String requestor) {
    if (StringUtil.isEmpty(text)
        && !Comparing.equal(requestor, myCurrentRequestor)
        && !EventLog.LOG_REQUESTOR.equals(requestor)) {
      return Couple.of(myInfoPanel.getText(), myCurrentRequestor);
    }

    boolean logMode = myInfoPanel.updateText(EventLog.LOG_REQUESTOR.equals(requestor) ? "" : text);
    myCurrentRequestor = logMode ? EventLog.LOG_REQUESTOR : requestor;
    return Couple.of(text, requestor);
  }
 @Nullable
 private VirtualFile findNextFile(final VirtualFile file) {
   final EditorWindow[] windows = getWindows(); // TODO: use current file as base
   for (int i = 0; i != windows.length; ++i) {
     final VirtualFile[] files = windows[i].getFiles();
     for (final VirtualFile fileAt : files) {
       if (!Comparing.equal(fileAt, file)) {
         return fileAt;
       }
     }
   }
   return null;
 }
  private static boolean containsLineMarker(LineMarkerInfo info, Collection<LineMarkerInfo> where) {
    final String infoTooltip = info.getLineMarkerTooltip();

    for (LineMarkerInfo markerInfo : where) {
      String markerInfoTooltip;
      if (markerInfo.startOffset == info.startOffset
          && markerInfo.endOffset == info.endOffset
          && (Comparing.equal(infoTooltip, markerInfoTooltip = markerInfo.getLineMarkerTooltip())
              || ANY_TEXT.equals(markerInfoTooltip)
              || ANY_TEXT.equals(infoTooltip))) {
        return true;
      }
    }
    return false;
  }
 private void closeEditor() {
   boolean unsplit = false;
   if (mySplittedWindow != null && !mySplittedWindow.isDisposed()) {
     final EditorWithProviderComposite[] editors = mySplittedWindow.getEditors();
     if (editors.length == 1 && Comparing.equal(editors[0].getFile(), myNewVirtualFile)) {
       unsplit = true;
     }
   }
   FileEditorManager.getInstance(myProject).closeFile(myNewVirtualFile);
   if (unsplit) {
     for (EditorWindow editorWindow : mySplittedWindow.findSiblings()) {
       editorWindow.unsplit(true);
     }
   }
 }
 protected static void assertSameLinesWithFile(String filePath, String actualText) {
   String fileText;
   try {
     if (OVERWRITE_TESTDATA) {
       VfsTestUtil.overwriteTestData(filePath, actualText);
       System.out.println("File " + filePath + " created.");
     }
     fileText = FileUtil.loadFile(new File(filePath), CharsetToolkit.UTF8);
   } catch (FileNotFoundException e) {
     VfsTestUtil.overwriteTestData(filePath, actualText);
     throw new AssertionFailedError("No output text found. File " + filePath + " created.");
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   String expected = StringUtil.convertLineSeparators(fileText.trim());
   String actual = StringUtil.convertLineSeparators(actualText.trim());
   if (!Comparing.equal(expected, actual)) {
     throw new FileComparisonFailure(null, expected, actual, filePath);
   }
 }
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean selected, boolean focused, int row, int column) {
    RendererComponent panel = getEditorPanel(table);
    EditorEx editor = panel.getEditor();
    editor.getColorsScheme().setEditorFontSize(table.getFont().getSize());

    editor
        .getColorsScheme()
        .setColor(EditorColors.SELECTION_BACKGROUND_COLOR, table.getSelectionBackground());
    editor
        .getColorsScheme()
        .setColor(EditorColors.SELECTION_FOREGROUND_COLOR, table.getSelectionForeground());
    editor.setBackgroundColor(selected ? table.getSelectionBackground() : table.getBackground());
    panel.setSelected(!Comparing.equal(editor.getBackgroundColor(), table.getBackground()));

    panel.setBorder(
        null); // prevents double border painting when ExtendedItemRendererComponentWrapper is used

    customizeEditor(editor, table, value, selected, row, column);
    return panel;
  }
 @NotNull
 public VirtualFile[] getSelectedFiles() {
   final Set<VirtualFile> files = new ArrayListSet<VirtualFile>();
   for (final EditorWindow window : myWindows) {
     final VirtualFile file = window.getSelectedFile();
     if (file != null) {
       files.add(file);
     }
   }
   final VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files);
   final VirtualFile currentFile = getCurrentFile();
   if (currentFile != null) {
     for (int i = 0; i != virtualFiles.length; ++i) {
       if (Comparing.equal(virtualFiles[i], currentFile)) {
         virtualFiles[i] = virtualFiles[0];
         virtualFiles[0] = currentFile;
         break;
       }
     }
   }
   return virtualFiles;
 }
  public ApplicationImpl(
      boolean isInternal,
      boolean isUnitTestMode,
      boolean isHeadless,
      boolean isCommandLine,
      @NotNull String appName,
      Splash splash) {
    super(null);

    ApplicationManagerEx.setApplication(
        this, myLastDisposable); // reset back to null only when all components already disposed

    getPicoContainer().registerComponentInstance(Application.class, this);

    CommonBundle.assertKeyIsFound = isUnitTestMode;
    AWTExceptionHandler.register(); // do not crash AWT on exceptions
    if ((isInternal || isUnitTestMode)
        && !Comparing.equal("off", System.getProperty("idea.disposer.debug"))) {
      Disposer.setDebugMode(true);
    }
    myStartTime = System.currentTimeMillis();
    mySplash = splash;
    myName = appName;

    PluginsFacade.INSTANCE =
        new PluginsFacade() {
          public IdeaPluginDescriptor getPlugin(PluginId id) {
            return PluginManager.getPlugin(id);
          }

          public IdeaPluginDescriptor[] getPlugins() {
            return PluginManager.getPlugins();
          }
        };

    myIsInternal = isInternal;
    myTestModeFlag = isUnitTestMode;
    myHeadlessMode = isHeadless;
    myCommandLineMode = isCommandLine;

    myDoNotSave = myTestModeFlag || myHeadlessMode;

    loadApplicationComponents();

    if (myTestModeFlag) {
      registerShutdownHook();
    }

    if (!isUnitTestMode && !isHeadless) {
      Disposer.register(this, Disposer.newDisposable(), "ui");

      StartupUtil.addExternalInstanceListener(
          new Consumer<List<String>>() {
            @Override
            public void consume(final List<String> args) {
              invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      final Project project = CommandLineProcessor.processExternalCommandLine(args);
                      final IdeFrame frame;
                      if (project != null) {
                        frame = WindowManager.getInstance().getIdeFrame(project);
                      } else {
                        frame = WindowManager.getInstance().getAllFrames()[0];
                      }
                      ((IdeFrameImpl) frame).requestFocus();
                    }
                  });
            }
          });
    }

    final String s = System.getProperty("jb.restart.code");
    if (s != null) {
      try {
        myRestartCode = Integer.parseInt(s);
      } catch (NumberFormatException ignore) {
      }
    }

    registerFont("/fonts/Inconsolata.ttf");
  }
 public final void setSubId(@Nullable String subId) {
   if (Comparing.strEqual(mySubId, subId)) return;
   saveExpandedPaths();
   mySubId = subId;
 }
  public static String composeText(
      final Map<String, ExpectedHighlightingSet> types,
      Collection<HighlightInfo> infos,
      String text) {
    // filter highlighting data and map each highlighting to a tag name
    List<Pair<String, HighlightInfo>> list =
        ContainerUtil.mapNotNull(
            infos,
            (NullableFunction<HighlightInfo, Pair<String, HighlightInfo>>)
                info -> {
                  for (Map.Entry<String, ExpectedHighlightingSet> entry : types.entrySet()) {
                    final ExpectedHighlightingSet set = entry.getValue();
                    if (set.enabled
                        && set.severity == info.getSeverity()
                        && set.endOfLine == info.isAfterEndOfLine()) {
                      return Pair.create(entry.getKey(), info);
                    }
                  }
                  return null;
                });

    boolean showAttributesKeys = false;
    for (ExpectedHighlightingSet eachSet : types.values()) {
      for (HighlightInfo eachInfo : eachSet.infos) {
        if (eachInfo.forcedTextAttributesKey != null) {
          showAttributesKeys = true;
          break;
        }
      }
    }

    // sort filtered highlighting data by end offset in descending order
    Collections.sort(
        list,
        (o1, o2) -> {
          HighlightInfo i1 = o1.second;
          HighlightInfo i2 = o2.second;

          int byEnds = i2.endOffset - i1.endOffset;
          if (byEnds != 0) return byEnds;

          if (!i1.isAfterEndOfLine() && !i2.isAfterEndOfLine()) {
            int byStarts = i1.startOffset - i2.startOffset;
            if (byStarts != 0) return byStarts;
          } else {
            int byEOL = Comparing.compare(i2.isAfterEndOfLine(), i1.isAfterEndOfLine());
            if (byEOL != 0) return byEOL;
          }

          int bySeverity = i2.getSeverity().compareTo(i1.getSeverity());
          if (bySeverity != 0) return bySeverity;

          return Comparing.compare(i1.getDescription(), i2.getDescription());
        });

    // combine highlighting data with original text
    StringBuilder sb = new StringBuilder();
    Couple<Integer> result = composeText(sb, list, 0, text, text.length(), 0, showAttributesKeys);
    sb.insert(0, text.substring(0, result.second));
    return sb.toString();
  }
  public ApplicationImpl(
      boolean isInternal,
      boolean isUnitTestMode,
      boolean isHeadless,
      boolean isCommandLine,
      @NotNull String appName) {
    super(null);

    getPicoContainer().registerComponentInstance(Application.class, this);

    CommonBundle.assertKeyIsFound = isUnitTestMode;

    if ((isInternal || isUnitTestMode)
        && !Comparing.equal("off", System.getProperty("idea.disposer.debug"))) {
      Disposer.setDebugMode(true);
    }
    myStartTime = System.currentTimeMillis();
    myName = appName;
    ApplicationManagerEx.setApplication(this);

    PluginsFacade.INSTANCE =
        new PluginsFacade() {
          public IdeaPluginDescriptor getPlugin(PluginId id) {
            return PluginManager.getPlugin(id);
          }

          public IdeaPluginDescriptor[] getPlugins() {
            return PluginManager.getPlugins();
          }
        };

    if (!isUnitTestMode && !isHeadless) {
      Toolkit.getDefaultToolkit().getSystemEventQueue().push(IdeEventQueue.getInstance());
      if (Patches.SUN_BUG_ID_6209673) {
        RepaintManager.setCurrentManager(new IdeRepaintManager());
      }
      IconLoader.activate();
    }

    myIsInternal = isInternal;
    myTestModeFlag = isUnitTestMode;
    myHeadlessMode = isHeadless;
    myCommandLineMode = isCommandLine;

    loadApplicationComponents();

    if (myTestModeFlag) {
      registerShutdownHook();
    }

    if (!isUnitTestMode && !isHeadless) {
      Disposer.register(this, Disposer.newDisposable(), "ui");

      StartupUtil.addExternalInstanceListener(
          new Consumer<List<String>>() {
            @Override
            public void consume(final List<String> args) {
              invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      final Project project = CommandLineProcessor.processExternalCommandLine(args);
                      final IdeFrame frame;
                      if (project != null) {
                        frame = WindowManager.getInstance().getIdeFrame(project);
                      } else {
                        frame = WindowManager.getInstance().getAllFrames()[0];
                      }
                      ((IdeFrameImpl) frame).requestFocus();
                    }
                  });
            }
          });
    }

    final String s = System.getProperty("jb.restart.code");
    if (s != null) {
      try {
        myRestartCode = Integer.parseInt(s);
      } catch (NumberFormatException ignore) {
      }
    }
  }