Search in sources :

Example 1 with I18nizeAction

use of com.intellij.codeInspection.i18n.I18nizeAction in project intellij-community by JetBrains.

the class I18nizeTest method doTest.

private void doTest(@NonNls String ext) throws Exception {
    configureByFile(getBasePath() + "/before" + getTestName(false) + "." + ext);
    I18nizeAction action = new I18nizeAction();
    DataContext dataContext = DataManager.getInstance().getDataContext(myEditor.getComponent());
    AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "place", dataContext);
    action.update(event);
    @NonNls String afterFile = getBasePath() + "/after" + getTestName(false) + "." + ext;
    boolean afterFileExists = new File(PathManagerEx.getTestDataPath() + afterFile).exists();
    I18nQuickFixHandler handler = I18nizeAction.getHandler(event);
    try {
        if (handler != null) {
            handler.checkApplicability(getFile(), getEditor());
        }
    } catch (IncorrectOperationException e) {
        event.getPresentation().setEnabled(false);
    }
    assertEquals(afterFileExists, event.getPresentation().isEnabled());
    if (afterFileExists) {
        PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(getFile(), getEditor());
        assertNotNull(handler);
        ApplicationManager.getApplication().runWriteAction(() -> handler.performI18nization(getFile(), getEditor(), literalExpression, Collections.<PropertiesFile>emptyList(), "key1", "value1", "i18nizedExpr", PsiExpression.EMPTY_ARRAY, JavaI18nUtil.DEFAULT_PROPERTY_CREATION_HANDLER));
        checkResultByFile(afterFile);
    }
}
Also used : I18nizeAction(com.intellij.codeInspection.i18n.I18nizeAction) NonNls(org.jetbrains.annotations.NonNls) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) I18nQuickFixHandler(com.intellij.codeInspection.i18n.I18nQuickFixHandler) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) File(java.io.File)

Aggregations

I18nQuickFixHandler (com.intellij.codeInspection.i18n.I18nQuickFixHandler)1 I18nizeAction (com.intellij.codeInspection.i18n.I18nizeAction)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 File (java.io.File)1 NonNls (org.jetbrains.annotations.NonNls)1