Esempio n. 1
0
  public BytecodeToolWindow(Project project, ToolWindow toolWindow) {
    super(new BorderLayout());
    myProject = project;
    this.toolWindow = toolWindow;

    myEditor =
        EditorFactory.getInstance()
            .createEditor(
                EditorFactory.getInstance().createDocument(""),
                project,
                JavaFileType.INSTANCE,
                true);
    add(myEditor.getComponent());

    JPanel optionPanel = new JPanel(new BorderLayout());
    add(optionPanel, BorderLayout.NORTH);

    /*TODO: try to extract default parameter from compiler options*/
    enableInline = new JCheckBox("Enable inline");
    optionPanel.add(enableInline, BorderLayout.WEST);

    new InfinitePeriodicalTask(
            UPDATE_DELAY,
            Alarm.ThreadToUse.SWING_THREAD,
            this,
            new Computable<LongRunningReadTask>() {
              @Override
              public LongRunningReadTask compute() {
                return new UpdateBytecodeToolWindowTask();
              }
            })
        .start();

    setText(DEFAULT_TEXT);
  }
  public LanguageConsoleImpl(
      Project project, String title, LightVirtualFile lightFile, boolean initComponents) {
    myProject = project;
    myTitle = title;
    myVirtualFile = lightFile;
    EditorFactory editorFactory = EditorFactory.getInstance();
    myHistoryFile = new LightVirtualFile(getTitle() + ".history.txt", FileTypes.PLAIN_TEXT, "");
    myEditorDocument = FileDocumentManager.getInstance().getDocument(lightFile);
    reparsePsiFile();
    assert myEditorDocument != null;
    myConsoleEditor = (EditorEx) editorFactory.createEditor(myEditorDocument, myProject);
    myConsoleEditor.addFocusListener(myFocusListener);
    myCurrentEditor = myConsoleEditor;
    myHistoryViewer =
        (EditorEx)
            editorFactory.createViewer(
                ((EditorFactoryImpl) editorFactory).createDocument(true), myProject);
    myUpdateQueue = new MergingUpdateQueue("ConsoleUpdateQueue", 300, true, null);
    Disposer.register(this, myUpdateQueue);

    // action shortcuts are not yet registered
    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                installEditorFactoryListener();
              }
            });

    if (initComponents) {
      initComponents();
    }
  }
  private Content getOrCreateConsoleContent(final ContentManager contentManager) {
    final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name");
    Content content = contentManager.findContent(displayName);
    if (content == null) {
      releaseEditor();
      final EditorFactory editorFactory = EditorFactory.getInstance();
      final Editor editor = editorFactory.createViewer(editorFactory.createDocument(""), myProject);
      EditorSettings editorSettings = editor.getSettings();
      editorSettings.setLineMarkerAreaShown(false);
      editorSettings.setIndentGuidesShown(false);
      editorSettings.setLineNumbersShown(false);
      editorSettings.setFoldingOutlineShown(false);

      ((EditorEx) editor).getScrollPane().setBorder(null);
      myEditorAdapter = new EditorAdapter(editor, myProject, false);
      final JPanel panel = new JPanel(new BorderLayout());
      panel.add(editor.getComponent(), BorderLayout.CENTER);

      content = ContentFactory.SERVICE.getInstance().createContent(panel, displayName, true);
      contentManager.addContent(content);

      for (Pair<String, TextAttributes> pair : myPendingOutput) {
        myEditorAdapter.appendString(pair.first, pair.second);
      }
      myPendingOutput.clear();
    }
    return content;
  }
 private static Editor createEditor() {
   EditorFactory editorFactory = EditorFactory.getInstance();
   Document document = editorFactory.createDocument("");
   EditorEx editor = (EditorEx) editorFactory.createEditor(document);
   reinitSettings(editor);
   return editor;
 }
 public static Editor createPlainCodeEditor(
     @NotNull final Project project, @NotNull final String text) {
   final EditorFactory editorFactory = EditorFactory.getInstance();
   assert editorFactory != null;
   final Document document = editorFactory.createDocument(text);
   EditorEx editor = (EditorEx) editorFactory.createEditor(document, project);
   setupEditor(editor);
   return editor;
 }
 protected Editor createIdeaEditor(String text) {
   Document doc = EditorFactory.getInstance().createDocument(text);
   Editor editor = EditorFactory.getInstance().createViewer(doc, myProject);
   editor.getSettings().setFoldingOutlineShown(false);
   editor.getSettings().setLineNumbersShown(false);
   editor.getSettings().setLineMarkerAreaShown(false);
   editor.getSettings().setIndentGuidesShown(false);
   return editor;
 }
  public void dispose() {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    editorFactory.releaseEditor(myConsoleEditor);
    editorFactory.releaseEditor(myHistoryViewer);

    final FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
    final boolean isOpen = editorManager.isFileOpen(myVirtualFile);
    if (isOpen) {
      editorManager.closeFile(myVirtualFile);
    }
  }
Esempio n. 8
0
  public static void doTearDown() throws Exception {
    UsefulTestCase.doPostponedFormatting(ourProject);

    LookupManager.getInstance(ourProject).hideActiveLookup();

    InspectionProfileManager.getInstance().deleteProfile(PROFILE);
    assertNotNull("Application components damaged", ProjectManager.getInstance());

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                try {
                  final VirtualFile[] children = ourSourceRoot.getChildren();
                  for (VirtualFile child : children) {
                    child.delete(this);
                  }
                } catch (IOException e) {
                  //noinspection CallToPrintStackTrace
                  e.printStackTrace();
                }
                FileDocumentManager manager = FileDocumentManager.getInstance();
                if (manager instanceof FileDocumentManagerImpl) {
                  ((FileDocumentManagerImpl) manager).dropAllUnsavedDocuments();
                }
              }
            });
    //    final Project[] openProjects = ProjectManagerEx.getInstanceEx().getOpenProjects();
    //    assertTrue(Arrays.asList(openProjects).contains(ourProject));
    assertFalse(PsiManager.getInstance(getProject()).isDisposed());
    if (!ourAssertionsInTestDetected) {
      if (IdeaLogger.ourErrorsOccurred != null) {
        throw IdeaLogger.ourErrorsOccurred;
      }
      // assertTrue("Logger errors occurred. ", IdeaLogger.ourErrorsOccurred == null);
    }
    ((PsiDocumentManagerImpl) PsiDocumentManager.getInstance(getProject()))
        .clearUncommitedDocuments();

    ((UndoManagerImpl) UndoManager.getGlobalInstance()).dropHistoryInTests();

    ProjectManagerEx.getInstanceEx().setCurrentTestProject(null);
    ourApplication.setDataProvider(null);
    ourTestCase = null;
    ((PsiManagerImpl) ourPsiManager).cleanupForNextTest();

    final Editor[] allEditors = EditorFactory.getInstance().getAllEditors();
    if (allEditors.length > 0) {
      for (Editor allEditor : allEditors) {
        EditorFactory.getInstance().releaseEditor(allEditor);
      }
      fail("Unreleased editors: " + allEditors.length);
    }
  }
  public static Editor createPythonCodeEditor(
      @NotNull final Project project, @NotNull final IpnbCodeSourcePanel codeSourcePanel) {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    assert editorFactory != null;
    final Document document = createPythonCodeDocument(project, codeSourcePanel);
    assert document != null;
    EditorEx editor =
        (EditorEx) editorFactory.createEditor(document, project, PythonFileType.INSTANCE, false);

    setupEditor(editor);
    return editor;
  }
Esempio n. 10
0
 public static EditorEx createEditor(Document document, Project project, boolean isViewer) {
   EditorFactory factory = EditorFactory.getInstance();
   EditorEx editor =
       (EditorEx)
           (isViewer
               ? factory.createViewer(document, project)
               : factory.createEditor(document, project));
   editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
   editor.setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.VCS_DIFF);
   editor.getGutterComponentEx().revalidateMarkup();
   return editor;
 }
  @NotNull
  private static Editor createView(Project project) {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document document = editorFactory.createDocument("");
    Editor result = editorFactory.createViewer(document, project);

    EditorSettings editorSettings = result.getSettings();
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setFoldingOutlineShown(false);
    return result;
  }
 public void testE13() {
   DocumentEx document =
       (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', 10));
   List<RangeMarker> mm = add(document, 5, 9, 9, 9, 7, 7, 6, 8);
   edit(document, 2, 1, 0);
   delete(mm, 0, 2);
 }
Esempio n. 13
0
  private void highlightSearch(final boolean noSmartCase) {
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
      Editor current = FileEditorManager.getInstance(project).getSelectedTextEditor();
      Editor[] editors =
          current == null
              ? null
              : EditorFactory.getInstance().getEditors(current.getDocument(), project);
      if (editors == null) {
        continue;
      }

      for (final Editor editor : editors) {
        String els = EditorData.getLastSearch(editor);
        if (!showSearchHighlight) {
          removeSearchHighlight(editor);

          continue;
        } else if (lastSearch != null && lastSearch.equals(els)) {
          continue;
        } else if (lastSearch == null) {
          continue;
        }

        removeSearchHighlight(editor);
        highlightSearchLines(editor, lastSearch, 0, -1, shouldIgnoreCase(lastSearch, noSmartCase));

        EditorData.setLastSearch(editor, lastSearch);
      }
    }
  }
  public void testRangeMarkersAreLazyCreated() throws Exception {
    final Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");
    RangeMarker m1 = document.createRangeMarker(2, 4);
    RangeMarker m2 = document.createRangeMarker(2, 4);

    assertEquals(2, ((DocumentImpl) document).getRangeMarkersSize());
    assertEquals(1, ((DocumentImpl) document).getRangeMarkersNodeSize());

    RangeMarker m3 = document.createRangeMarker(2, 5);
    assertEquals(2, ((DocumentImpl) document).getRangeMarkersNodeSize());
    document.deleteString(4, 5);
    assertTrue(m1.isValid());
    assertTrue(m2.isValid());
    assertTrue(m3.isValid());
    assertEquals(1, ((DocumentImpl) document).getRangeMarkersNodeSize());

    m1.setGreedyToLeft(true);
    assertTrue(m1.isValid());
    assertEquals(3, ((DocumentImpl) document).getRangeMarkersSize());
    assertEquals(2, ((DocumentImpl) document).getRangeMarkersNodeSize());

    m3.dispose();
    assertTrue(m1.isValid());
    assertTrue(m2.isValid());
    assertFalse(m3.isValid());
    assertEquals(2, ((DocumentImpl) document).getRangeMarkersSize());
    assertEquals(2, ((DocumentImpl) document).getRangeMarkersNodeSize());
  }
 public void testE11() {
   DocumentEx document =
       (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', 10));
   List<RangeMarker> mm = add(document, 9, 9, 7, 7, 1, 6, 3, 7);
   // edit(document, 0,0,0);
   delete(mm, 1);
 }
 public void testE5() {
   DocumentEx document =
       (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', 10));
   List<RangeMarker> mm = add(document, 9, 9, 4, 4, 1, 7, 7, 7, 4, 7);
   edit(document, 1, 5, 0);
   delete(mm, 3);
 }
 public void testE4() {
   DocumentEx document =
       (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', 10));
   List<RangeMarker> mm = add(document, 3, 5, 5, 6, 4, 8, 6, 9, 8, 9);
   edit(document, 6, 0, 0, 3, 0, 2);
   delete(mm, 1, 0);
 }
  public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception {
    final int N = 50000;
    Document document =
        EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N));

    final MarkupModelEx markupModel =
        (MarkupModelEx) DocumentMarkupModel.forDocument(document, ourProject, true);
    for (int i = 0; i < N - 1; i++) {
      markupModel.addRangeHighlighter(2 * i, 2 * i + 1, 0, null, HighlighterTargetArea.EXACT_RANGE);
    }
    markupModel.addRangeHighlighter(
        N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE);

    PlatformTestUtil.startPerformanceTest(
            "slow highlighters lookup",
            (int) (N * Math.log(N) / 1000),
            new ThrowableRunnable() {
              @Override
              public void run() {
                List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>();
                CommonProcessors.CollectProcessor<RangeHighlighterEx> coll =
                    new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list);
                for (int i = 0; i < N - 1; i++) {
                  list.clear();
                  markupModel.processRangeHighlightersOverlappingWith(2 * i, 2 * i + 1, coll);
                  assertEquals(2, list.size()); // 1 line plus one exact range marker
                }
              }
            })
        .assertTiming();
  }
Esempio n. 19
0
 @Override
 public void initComponent() {
   if (!ApplicationManager.getApplication().isUnitTestMode()) {
     System.out.println("UpdateComponent.initComponent");
     EditorFactory.getInstance().addEditorFactoryListener(myListener, this);
   }
 }
  public HighlightManagerImpl(Project project) {
    myProject = project;
    ActionManagerEx.getInstanceEx().addAnActionListener(new MyAnActionListener(), myProject);

    DocumentListener documentListener =
        new DocumentAdapter() {
          @Override
          public void documentChanged(DocumentEvent event) {
            Document document = event.getDocument();
            Editor[] editors = EditorFactory.getInstance().getEditors(document);
            for (Editor editor : editors) {
              Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, false);
              if (map == null) return;

              ArrayList<RangeHighlighter> highlightersToRemove = new ArrayList<RangeHighlighter>();
              for (RangeHighlighter highlighter : map.keySet()) {
                HighlightInfo info = map.get(highlighter);
                if (!info.editor.getDocument().equals(document)) continue;
                if (BitUtil.isSet(info.flags, HIDE_BY_TEXT_CHANGE)) {
                  highlightersToRemove.add(highlighter);
                }
              }

              for (RangeHighlighter highlighter : highlightersToRemove) {
                removeSegmentHighlighter(editor, highlighter);
              }
            }
          }
        };
    EditorFactory.getInstance()
        .getEventMulticaster()
        .addDocumentListener(documentListener, myProject);
  }
 @Override
 public void dispose() {
   if (myMockTextEditor != null) {
     EditorFactory.getInstance().releaseEditor(myMockTextEditor);
   }
   myPanel.dispose();
 }
  public void initComponent() {
    log.info("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");
    // System.out.println("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");

    // Set runtime constants
    IDE_NAME = PlatformUtils.getPlatformPrefix();
    IDE_VERSION = ApplicationInfo.getInstance().getFullVersion();

    if (!Dependencies.isCLIInstalled()) {
      log.info("Downloading and installing wakatime-cli ...");
      Dependencies.installCLI();
    } else if (Dependencies.isCLIOld()) {
      log.info("Upgrading wakatime-cli ...");
      Dependencies.upgradeCLI();
    }

    if (Dependencies.isPythonInstalled()) {

      WakaTime.DEBUG = WakaTime.isDebugEnabled();
      if (WakaTime.DEBUG) {
        log.setLevel(Level.DEBUG);
        log.debug("Logging level set to DEBUG");
      }

      log.debug("Python location: " + Dependencies.getPythonLocation());
      log.debug("CLI location: " + Dependencies.getCLILocation());

      // prompt for apiKey if it does not already exist
      if (ApiKey.getApiKey().equals("")) {
        Project project = ProjectManager.getInstance().getDefaultProject();
        ApiKey apiKey = new ApiKey(project);
        apiKey.promptForApiKey();
      }
      log.debug("Api Key: " + ApiKey.getApiKey());

      // add WakaTime item to File menu
      ActionManager am = ActionManager.getInstance();
      PluginMenu action = new PluginMenu();
      am.registerAction("WakaTimeApiKey", action);
      DefaultActionGroup fileMenu = (DefaultActionGroup) am.getAction("FileMenu");
      fileMenu.addSeparator();
      fileMenu.add(action);

      // Setup message listeners
      MessageBus bus = ApplicationManager.getApplication().getMessageBus();
      connection = bus.connect();
      connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener());
      EditorFactory.getInstance()
          .getEventMulticaster()
          .addDocumentListener(new CustomDocumentListener());

      log.debug("Finished initializing WakaTime plugin");

    } else {
      Messages.showErrorDialog(
          "WakaTime requires Python to be installed.\nYou can install it from https://www.python.org/downloads/\nAfter installing Python, restart your IDE.",
          "Error");
    }
  }
 private void releaseAllEditors() {
   for (final Editor editor : myEditors.values()) {
     if (!editor.isDisposed()) {
       EditorFactory.getInstance().releaseEditor(editor);
     }
   }
   myEditors.clear();
 }
  @Override
  protected void releaseResources() {
    super.releaseResources();
    if (myPreview == null) return;

    EditorFactory.getInstance().releaseEditor(myPreview);
    myPreview = null;
  }
 private void releaseEditor() {
   if (myEditorAdapter != null) {
     final Editor editor = myEditorAdapter.getEditor();
     if (!editor.isDisposed()) {
       EditorFactory.getInstance().releaseEditor(editor);
     }
   }
 }
  public void testRangeMarkersAreWeakReferenced_NoVerify() throws Exception {
    final Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");
    for (int i = 0; i < 10; i++) {
      document.createRangeMarker(0, document.getTextLength());
    }

    LeakHunter.checkLeak(document, RangeMarker.class);
  }
 public void dispose() {
   super.dispose();
   for (StatementExecutionVariableValueForm variableValueForm : variableValueForms) {
     variableValueForm.dispose();
   }
   variableValueForms.clear();
   variablesBundle = null;
   EditorFactory.getInstance().releaseEditor(viewer);
 }
 @Override
 public void disposeUIResources() {
   myMainPanel = null;
   if (myTemplateEditor != null) {
     EditorFactory.getInstance().releaseEditor(myTemplateEditor);
     myTemplateEditor = null;
   }
   myFile = null;
 }
Esempio n. 29
0
 void updateGlobalScheme() {
   if (myColorsManager != null) {
     EditorColorsScheme globalScheme = myColorsManager.getGlobalScheme();
     globalScheme.setEditorFontSize(getFontSize());
     globalScheme.setEditorFontName(getFontFamily());
     globalScheme.setLineSpacing(((float) getLineSpacing()));
     EditorFactory.getInstance().refreshAllEditors();
   }
 }
  private void updateViewerForSelection() {
    if (myAllContents.isEmpty()) return;
    String fullString = getSelectedText();

    if (myViewer != null) {
      EditorFactory.getInstance().releaseEditor(myViewer);
    }

    if (myUseIdeaEditor) {
      myViewer = createIdeaEditor(fullString);
      JComponent component = myViewer.getComponent();
      component.setPreferredSize(JBUI.size(300, 500));
      mySplitter.setSecondComponent(component);
    } else {
      final JTextArea textArea = new JTextArea(fullString);
      textArea.setRows(3);
      textArea.setWrapStyleWord(true);
      textArea.setLineWrap(true);
      textArea.setSelectionStart(0);
      textArea.setSelectionEnd(textArea.getText().length());
      textArea.setEditable(false);
      mySplitter.setSecondComponent(ScrollPaneFactory.createScrollPane(textArea));
    }
    mySplitter.revalidate();
  }