Java Code Examples for com.intellij.openapi.util.Disposer#newDisposable()

The following examples show how to use com.intellij.openapi.util.Disposer#newDisposable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CsvAnnotatorTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingDataWrapper data) {
    Project project = myFixture.getProject();
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
    });
    PsiFileImpl file = (PsiFileImpl)this.getHostFile();
    FileElement hardRefToFileElement = file.calcTreeElement();
    if (!DumbService.isDumb(project)) {
        ServiceManager.getService(project, CacheManager.class).getFilesWithWord("XXX", (short)2, GlobalSearchScope.allScope(project), true);
    }

    long start = System.currentTimeMillis();
    Disposable disposable = Disposer.newDisposable();

    List<HighlightInfo> infos;
    try {
        infos = myFixture.doHighlighting();
        this.removeDuplicatedRangesForInjected(infos);
    } finally {
        Disposer.dispose(disposable);
    }

    long elapsed = System.currentTimeMillis() - start;
    data.checkResultWrapper(file, infos, file.getText());
    hardRefToFileElement.hashCode();
    return elapsed;
}
 
Example 2
Source File: GradleDependencyFetcherTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
public static void setUp() {
  Disposable disposable = Disposer.newDisposable();
  ApplicationManager.setApplication(new MockApplication(disposable), disposable);
  Extensions.registerAreaClass("IDEA_PROJECT", null);
  ourProject = new MockProject(ApplicationManager.getApplication().getPicoContainer(), disposable);
}
 
Example 3
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Balloon showPopupHelper(
  InspectorGroupManagerService inspectorService,
  Project project,
  @Nullable DiagnosticsNode node,
  @NotNull InspectorService.Location location,
  FlutterDartAnalysisServer service
) {
  final Color GRAPHITE_COLOR = new JBColor(new Color(236, 236, 236, 215), new Color(60, 63, 65, 215));

  final Disposable panelDisposable = Disposer.newDisposable();
  final PropertyEditorPanel panel =
    new PropertyEditorPanel(inspectorService, project, service, true, true, panelDisposable);

  final StableWidgetTracker tracker = new StableWidgetTracker(location, service, project, panelDisposable);

  final EventStream<VirtualFile> activeFile = new EventStream<>(location.getFile());
  panel.initalize(node, tracker.getCurrentOutlines(), activeFile);

  panel.setBackground(GRAPHITE_COLOR);
  panel.setOpaque(false);
  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(panel);
  balloonBuilder.setFadeoutTime(0);
  balloonBuilder.setFillColor(GRAPHITE_COLOR);
  balloonBuilder.setAnimationCycle(0);
  balloonBuilder.setHideOnClickOutside(true);
  balloonBuilder.setHideOnKeyOutside(false);
  balloonBuilder.setHideOnAction(false);
  balloonBuilder.setCloseButtonEnabled(false);
  balloonBuilder.setBlockClicksThroughBalloon(true);
  balloonBuilder.setRequestFocus(true);
  balloonBuilder.setShadow(true);
  final Balloon balloon = balloonBuilder.createBalloon();
  Disposer.register(balloon, panelDisposable);

  return balloon;
}
 
Example 4
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Balloon showPopupHelper(
  InspectorGroupManagerService inspectorService,
  Project project,
  @Nullable DiagnosticsNode node,
  @NotNull InspectorService.Location location,
  FlutterDartAnalysisServer service
) {
  final Color GRAPHITE_COLOR = new JBColor(new Color(236, 236, 236, 215), new Color(60, 63, 65, 215));

  final Disposable panelDisposable = Disposer.newDisposable();
  final PropertyEditorPanel panel =
    new PropertyEditorPanel(inspectorService, project, service, true, true, panelDisposable);

  final StableWidgetTracker tracker = new StableWidgetTracker(location, service, project, panelDisposable);

  final EventStream<VirtualFile> activeFile = new EventStream<>(location.getFile());
  panel.initalize(node, tracker.getCurrentOutlines(), activeFile);

  panel.setBackground(GRAPHITE_COLOR);
  panel.setOpaque(false);
  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(panel);
  balloonBuilder.setFadeoutTime(0);
  balloonBuilder.setFillColor(GRAPHITE_COLOR);
  balloonBuilder.setAnimationCycle(0);
  balloonBuilder.setHideOnClickOutside(true);
  balloonBuilder.setHideOnKeyOutside(false);
  balloonBuilder.setHideOnAction(false);
  balloonBuilder.setCloseButtonEnabled(false);
  balloonBuilder.setBlockClicksThroughBalloon(true);
  balloonBuilder.setRequestFocus(true);
  balloonBuilder.setShadow(true);
  final Balloon balloon = balloonBuilder.createBalloon();
  Disposer.register(balloon, panelDisposable);

  return balloon;
}
 
Example 5
Source File: BlazeSyncIntegrationTestCase.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Before
public void doSetup() {
  thisClassDisposable = Disposer.newDisposable();
  projectViewManager = new MockProjectViewManager(getProject(), thisClassDisposable);
  new MockBlazeVcsHandler(thisClassDisposable);
  blazeInfoData = new MockBlazeInfoRunner();
  blazeIdeInterface = new MockBlazeIdeInterface();
  eventLogger = new MockEventLoggingService(thisClassDisposable);
  if (isLightTestCase()) {
    moduleMocker = new ProjectModuleMocker(getProject(), thisClassDisposable);
  }
  registerApplicationService(BlazeInfoRunner.class, blazeInfoData);
  registerApplicationService(BlazeIdeInterface.class, blazeIdeInterface);

  errorCollector = new ErrorCollector();

  fileSystem.createDirectory(projectDataDirectory.getPath() + "/.blaze/modules");

  // absolute file paths depend on #isLightTestCase, so can't be determined statically
  String outputBase = fileSystem.createDirectory("output_base").getPath();
  execRoot = fileSystem.createDirectory("execroot/root").getPath();
  String outputPath = execRoot + "/blaze-out";
  String blazeBin = String.format("%s/%s/bin", outputPath, DEFAULT_CONFIGURATION);
  String blazeGenfiles = String.format("%s/%s/genfiles", outputPath, DEFAULT_CONFIGURATION);
  String blazeTestlogs = String.format("%s/%s/testlogs", outputPath, DEFAULT_CONFIGURATION);

  blazeInfoData.setResults(
      ImmutableMap.<String, String>builder()
          .put(BlazeInfo.blazeBinKey(Blaze.getBuildSystem(getProject())), blazeBin)
          .put(BlazeInfo.blazeGenfilesKey(Blaze.getBuildSystem(getProject())), blazeGenfiles)
          .put(BlazeInfo.blazeTestlogsKey(Blaze.getBuildSystem(getProject())), blazeTestlogs)
          .put(BlazeInfo.EXECUTION_ROOT_KEY, execRoot)
          .put(BlazeInfo.OUTPUT_BASE_KEY, outputBase)
          .put(BlazeInfo.OUTPUT_PATH_KEY, outputPath)
          .put(BlazeInfo.PACKAGE_PATH_KEY, workspaceRoot.toString())
          .build());
}
 
Example 6
Source File: AllInPackageTestContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Before
public final void before() {
  // disposed prior to calling parent class's @After methods
  Disposable thisClassDisposable = Disposer.newDisposable();

  projectViewManager = new MockProjectViewManager(getProject(), thisClassDisposable);
  errorCollector = new ErrorCollector();
  context = new BlazeContext();
  context.addOutputSink(IssueOutput.class, errorCollector);
}
 
Example 7
Source File: IntellijTestSetupRule.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws Throwable {
  if (!isRunThroughBlaze()) {
    // If running directly through the IDE, don't try to load plugins from the sandbox environment
    // Instead we'll rely on the slightly more hermetic module classpath
    oldPluginPathProperty = System.getProperty(PathManager.PROPERTY_PLUGINS_PATH);
    System.setProperty(PathManager.PROPERTY_PLUGINS_PATH, "/dev/null");
  }
  testRootDisposable = Disposer.newDisposable();
}
 
Example 8
Source File: IntellijRule.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() {
  testDisposable = Disposer.newDisposable();

  TestUtils.createMockApplication(testDisposable);
  project =
      TestUtils.mockProject(
          ApplicationManager.getApplication().getPicoContainer(), testDisposable);
}
 
Example 9
Source File: Inspect.java    From neovim-intellij-complete with MIT License 4 votes vote down vote up
/**
 * Runs code anlyzis on document found in path and returns all problems found with the document.
 * @param path
 * @param fileContent
 * @return
 */
private static Pair<Document, List<HighlightInfo>> getProblems(final String path, @Nullable final String fileContent) {
    final Ref<PsiFile> psiFileRef = new Ref<>();
    final Ref<Editor> editorRef = new Ref<>();
    final Ref<Document> docRef = new Ref<>();
    final Ref<Project> projectRef = new Ref<>();

    UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
        PsiFile targetPsiFile = EmbeditorUtil.findTargetFile(path);
        VirtualFile targetVirtualFile =  targetPsiFile.getVirtualFile();
        Project project = targetPsiFile.getProject();

        PsiFile fileCopy = fileContent != null
                ? EmbeditorUtil.createDummyPsiFile(project, fileContent, targetPsiFile)
                : EmbeditorUtil.createDummyPsiFile(project, targetPsiFile.getText(), targetPsiFile);

        final Document document = fileCopy.getViewProvider().getDocument();

        editorRef.set(EditorFactory.getInstance().createEditor(document, project, targetVirtualFile, false));
        psiFileRef.set(targetPsiFile);
        docRef.set(document);
        projectRef.set(project);
    });
    Disposable context = Disposer.newDisposable();

    Ref<List<HighlightInfo>> highlightInfoList = new Ref<>();

    ApplicationManager.getApplication().runReadAction(() -> {
        final DaemonProgressIndicator progress = new DaemonProgressIndicator();
        Disposer.register(context, progress);

        ProgressManager.getInstance().runProcess(() -> {

            final DaemonCodeAnalyzerEx analyzer =
                    DaemonCodeAnalyzerEx.getInstanceEx(projectRef.get());
            //analyzer.restart(psiFileRef.get());

            // analyze!
            highlightInfoList.set(analyzer.runMainPasses(
                    psiFileRef.get(), docRef.get(), progress));
        }, progress);
    });
    return Pair.create(docRef.get(), highlightInfoList.get());
}
 
Example 10
Source File: JavaSourceFolderProviderTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Before
public void doSetup() {
  thisClassDisposable = Disposer.newDisposable();
}
 
Example 11
Source File: ExperimentServiceImplTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  testDisposable = Disposer.newDisposable();
  ApplicationManager.setApplication(new MockApplication(testDisposable), testDisposable);
}
 
Example 12
Source File: SingleThreadedMessageBus.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public SingleThreadedMessageBus(@Nullable MessageBus parent) {
    this.owner = parent + " of " + SingleThreadedMessageBus.class;
    this.connectionDisposable = Disposer.newDisposable(owner);
    this.parent = parent;
}