private static void invokeSurrounderInTests(Project project, Editor editor, PsiFile file, Surrounder surrounder, int startOffset, int endOffset, List<SurroundDescriptor> surroundDescriptors) { assert ApplicationManager.getApplication().isUnitTestMode(); for (SurroundDescriptor descriptor : surroundDescriptors) { final PsiElement[] elements = descriptor.getElementsToSurround(file, startOffset, endOffset); if (elements.length > 0) { for (Surrounder descriptorSurrounder : descriptor.getSurrounders()) { if (surrounder.getClass().equals(descriptorSurrounder.getClass())) { doSurround(project, editor, surrounder, elements); return; } } } } }
public void testNoParenthesisSurrounderForLambdaParameter() { configureByFile(BASE_PATH + getTestName(false) + ".java"); SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE)); assertNotNull(item); SelectionModel selectionModel = getEditor().getSelectionModel(); PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); assertEmpty(elements); }
private void doTest(@NotNull String fileName, Surrounder surrounder) { configureByFile(BASE_PATH + fileName + ".java"); SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE)); assertNotNull(item); SelectionModel selectionModel = getEditor().getSelectionModel(); PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); assertTrue(surrounder.isApplicable(elements)); SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder); checkResultByFile(BASE_PATH + fileName + "_after.java"); }