@Ignore("T73932936") @Test public void resolveRedSymbols() throws IOException { final Project project = testHelper.getFixture().getProject(); final PsiJavaFile pf = (PsiJavaFile) testHelper.configure("ResolveRedSymbolsActionTest.java"); final VirtualFile vf = pf.getViewProvider().getVirtualFile(); final Editor editor = testHelper.getFixture().getEditor(); final PsiFile specPsiFile = testHelper.configure("LayoutSpec.java"); ApplicationManager.getApplication() .invokeAndWait( () -> { PsiSearchUtils.addMock( "LayoutSpec", PsiTreeUtil.findChildOfType(specPsiFile, PsiClass.class)); parseDocument(editor.getDocument(), pf, project); final HashMap<String, String> eventMetadata = new HashMap<>(); ResolveRedSymbolsAction.resolveRedSymbols( pf, vf, editor, project, eventMetadata, ignore -> { assertThat(eventMetadata).isNotEmpty(); }); assertThat(eventMetadata.get("resolved_red_symbols")).isEqualTo("[Layout]"); final PsiClass cached = ComponentsCacheService.getInstance(project).getComponent("Layout"); assertThat(cached).isNotNull(); assertThat(cached.getName()).isEqualTo("Layout"); }); }
public static void resolveRedSymbols( PsiJavaFile psiFile, VirtualFile virtualFile, Editor editor, Project project, Map<String, String> eventMetadata, Consumer<Boolean> onFinished) { final Map<PsiClass, List<PsiElement>> resolved = new HashMap<>(); Runnable action = () -> resolved.putAll( collectAndAddToCache( psiFile, virtualFile, editor.getDocument(), project, eventMetadata)); if (ApplicationManager.getApplication().isUnitTestMode()) { action.run(); return; } ReadAction.nonBlocking(action) .inSmartMode(project) .expireWith(project) .expireWhen(editor::isDisposed) .finishOnUiThread( ModalityState.NON_MODAL, aVoid -> { if (resolved.isEmpty()) { onFinished.accept(false); return; } long bindStart = System.currentTimeMillis(); if (!bindExpressions(resolved, virtualFile, editor, project)) { onFinished.accept(false); return; } final long bindDelta = System.currentTimeMillis() - bindStart; eventMetadata.put(EventLogger.KEY_TIME_BIND_RED_SYMBOLS, String.valueOf(bindDelta)); onFinished.accept(true); }) .submit(AppExecutorUtil.getAppExecutorService()); }
ResolveRedSymbolsAction extends AnAction { public static void resolveRedSymbols( PsiJavaFile psiFile, VirtualFile virtualFile, Editor editor, Project project, Map<String, String> eventMetadata, Consumer<Boolean> onFinished) { final Map<PsiClass, List<PsiElement>> resolved = new HashMap<>(); Runnable action = () -> resolved.putAll( collectAndAddToCache( psiFile, virtualFile, editor.getDocument(), project, eventMetadata)); if (ApplicationManager.getApplication().isUnitTestMode()) { action.run(); return; } ReadAction.nonBlocking(action) .inSmartMode(project) .expireWith(project) .expireWhen(editor::isDisposed) .finishOnUiThread( ModalityState.NON_MODAL, aVoid -> { if (resolved.isEmpty()) { onFinished.accept(false); return; } long bindStart = System.currentTimeMillis(); if (!bindExpressions(resolved, virtualFile, editor, project)) { onFinished.accept(false); return; } final long bindDelta = System.currentTimeMillis() - bindStart; eventMetadata.put(EventLogger.KEY_TIME_BIND_RED_SYMBOLS, String.valueOf(bindDelta)); onFinished.accept(true); }) .submit(AppExecutorUtil.getAppExecutorService()); } }
ResolveRedSymbolsAction extends AnAction { public static void resolveRedSymbols( PsiJavaFile psiFile, VirtualFile virtualFile, Editor editor, Project project, Map<String, String> eventMetadata, Consumer<Boolean> onFinished) { final Map<PsiClass, List<PsiElement>> resolved = new HashMap<>(); Runnable action = () -> resolved.putAll( collectAndAddToCache( psiFile, virtualFile, editor.getDocument(), project, eventMetadata)); if (ApplicationManager.getApplication().isUnitTestMode()) { action.run(); return; } ReadAction.nonBlocking(action) .inSmartMode(project) .expireWith(project) .expireWhen(editor::isDisposed) .finishOnUiThread( ModalityState.NON_MODAL, aVoid -> { if (resolved.isEmpty()) { onFinished.accept(false); return; } long bindStart = System.currentTimeMillis(); if (!bindExpressions(resolved, virtualFile, editor, project)) { onFinished.accept(false); return; } final long bindDelta = System.currentTimeMillis() - bindStart; eventMetadata.put(EventLogger.KEY_TIME_BIND_RED_SYMBOLS, String.valueOf(bindDelta)); onFinished.accept(true); }) .submit(AppExecutorUtil.getAppExecutorService()); }  }
ResolveRedSymbolsAction extends AnAction { public static void resolveRedSymbols( PsiJavaFile psiFile, VirtualFile virtualFile, Editor editor, Project project, Map<String, String> eventMetadata, Consumer<Boolean> onFinished) { final Map<PsiClass, List<PsiElement>> resolved = new HashMap<>(); Runnable action = () -> resolved.putAll( collectAndAddToCache( psiFile, virtualFile, editor.getDocument(), project, eventMetadata)); if (ApplicationManager.getApplication().isUnitTestMode()) { action.run(); return; } ReadAction.nonBlocking(action) .inSmartMode(project) .expireWith(project) .expireWhen(editor::isDisposed) .finishOnUiThread( ModalityState.NON_MODAL, aVoid -> { if (resolved.isEmpty()) { onFinished.accept(false); return; } long bindStart = System.currentTimeMillis(); if (!bindExpressions(resolved, virtualFile, editor, project)) { onFinished.accept(false); return; } final long bindDelta = System.currentTimeMillis() - bindStart; eventMetadata.put(EventLogger.KEY_TIME_BIND_RED_SYMBOLS, String.valueOf(bindDelta)); onFinished.accept(true); }) .submit(AppExecutorUtil.getAppExecutorService()); }  @Override void update(AnActionEvent e); @Override void actionPerformed(AnActionEvent e); static void resolveRedSymbols(
      PsiJavaFile psiFile,
      VirtualFile virtualFile,
      Editor editor,
      Project project,
      Map<String, String> eventMetadata,
      Consumer<Boolean> onFinished); }
ResolveRedSymbolsAction extends AnAction { public static void resolveRedSymbols( PsiJavaFile psiFile, VirtualFile virtualFile, Editor editor, Project project, Map<String, String> eventMetadata, Consumer<Boolean> onFinished) { final Map<PsiClass, List<PsiElement>> resolved = new HashMap<>(); Runnable action = () -> resolved.putAll( collectAndAddToCache( psiFile, virtualFile, editor.getDocument(), project, eventMetadata)); if (ApplicationManager.getApplication().isUnitTestMode()) { action.run(); return; } ReadAction.nonBlocking(action) .inSmartMode(project) .expireWith(project) .expireWhen(editor::isDisposed) .finishOnUiThread( ModalityState.NON_MODAL, aVoid -> { if (resolved.isEmpty()) { onFinished.accept(false); return; } long bindStart = System.currentTimeMillis(); if (!bindExpressions(resolved, virtualFile, editor, project)) { onFinished.accept(false); return; } final long bindDelta = System.currentTimeMillis() - bindStart; eventMetadata.put(EventLogger.KEY_TIME_BIND_RED_SYMBOLS, String.valueOf(bindDelta)); onFinished.accept(true); }) .submit(AppExecutorUtil.getAppExecutorService()); }  @Override void update(AnActionEvent e); @Override void actionPerformed(AnActionEvent e); static void resolveRedSymbols(
      PsiJavaFile psiFile,
      VirtualFile virtualFile,
      Editor editor,
      Project project,
      Map<String, String> eventMetadata,
      Consumer<Boolean> onFinished);  }