@Test public void createHandler_handlerInvoked_documentContainsOnEventMethod() { testHelper.getPsiClass( classes -> { final CodeInsightTestFixture fixture = testHelper.getFixture(); final PsiFile psiFile = classes.get(0).getContainingFile(); final LightVirtualFile virtualFile = new LightVirtualFile(psiFile.getName(), psiFile.getFileType(), psiFile.getText()); final String generatedOnEvent = "@com.facebook.litho.annotations.OnEvent(TestClass.class)\n" + " static void onTestClass(com.facebook.litho.ComponentContext c) {\n" + " }"; final PsiClass eventClass = JavaPsiFacade.getInstance(fixture.getProject()) .getElementFactory() .createClass("TestClass"); fixture.openFileInEditor(virtualFile); assertThat(fixture.getEditor().getDocument().getText()).doesNotContain(generatedOnEvent); TransactionGuard.getInstance() .submitTransactionAndWait( () -> OnEventGenerateAction.createHandler( (context, project) -> eventClass, onEvent -> { assertThat(onEvent.getName()).isEqualTo("onTestClass"); assertThat(onEvent.getAnnotations()[0].getQualifiedName()) .isEqualTo("com.facebook.litho.annotations.OnEvent"); }) .invoke(fixture.getProject(), fixture.getEditor(), fixture.getFile())); assertThat(fixture.getEditor().getDocument().getText()).contains(generatedOnEvent); return true; }, "LayoutSpec.java"); }
public static CodeInsightActionHandler createHandler( EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener) { return new OnEventGenerateHandler( eventChooser, (project, originalOnEventMethod, context) -> { if (ApplicationManager.getApplication().isUnitTestMode()) { return originalOnEventMethod; } final OnEventChangeSignatureDialog onEventMethodSignatureChooser = new OnEventChangeSignatureDialog(project, originalOnEventMethod, context); onEventMethodSignatureChooser.show(); return onEventMethodSignatureChooser.getMethod(); }, onEventGeneratedListener); }
OnEventGenerateAction extends BaseGenerateAction { public static CodeInsightActionHandler createHandler( EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener) { return new OnEventGenerateHandler( eventChooser, (project, originalOnEventMethod, context) -> { if (ApplicationManager.getApplication().isUnitTestMode()) { return originalOnEventMethod; } final OnEventChangeSignatureDialog onEventMethodSignatureChooser = new OnEventChangeSignatureDialog(project, originalOnEventMethod, context); onEventMethodSignatureChooser.show(); return onEventMethodSignatureChooser.getMethod(); }, onEventGeneratedListener); } }
OnEventGenerateAction extends BaseGenerateAction { public static CodeInsightActionHandler createHandler( EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener) { return new OnEventGenerateHandler( eventChooser, (project, originalOnEventMethod, context) -> { if (ApplicationManager.getApplication().isUnitTestMode()) { return originalOnEventMethod; } final OnEventChangeSignatureDialog onEventMethodSignatureChooser = new OnEventChangeSignatureDialog(project, originalOnEventMethod, context); onEventMethodSignatureChooser.show(); return onEventMethodSignatureChooser.getMethod(); }, onEventGeneratedListener); } OnEventGenerateAction(); }
OnEventGenerateAction extends BaseGenerateAction { public static CodeInsightActionHandler createHandler( EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener) { return new OnEventGenerateHandler( eventChooser, (project, originalOnEventMethod, context) -> { if (ApplicationManager.getApplication().isUnitTestMode()) { return originalOnEventMethod; } final OnEventChangeSignatureDialog onEventMethodSignatureChooser = new OnEventChangeSignatureDialog(project, originalOnEventMethod, context); onEventMethodSignatureChooser.show(); return onEventMethodSignatureChooser.getMethod(); }, onEventGeneratedListener); } OnEventGenerateAction(); static CodeInsightActionHandler createHandler(
      EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener); @Override void update(AnActionEvent e); }
OnEventGenerateAction extends BaseGenerateAction { public static CodeInsightActionHandler createHandler( EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener) { return new OnEventGenerateHandler( eventChooser, (project, originalOnEventMethod, context) -> { if (ApplicationManager.getApplication().isUnitTestMode()) { return originalOnEventMethod; } final OnEventChangeSignatureDialog onEventMethodSignatureChooser = new OnEventChangeSignatureDialog(project, originalOnEventMethod, context); onEventMethodSignatureChooser.show(); return onEventMethodSignatureChooser.getMethod(); }, onEventGeneratedListener); } OnEventGenerateAction(); static CodeInsightActionHandler createHandler(
      EventChooser eventChooser, OnEventGeneratedListener onEventGeneratedListener); @Override void update(AnActionEvent e);  }