Search in sources :

Example 6 with JSCodeStyleSettings

use of com.intellij.lang.javascript.formatter.JSCodeStyleSettings in project intellij-plugins by JetBrains.

the class ActionScriptFormatterTest method testActionScriptRestParameter.

public void testActionScriptRestParameter() throws Exception {
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
    final JSCodeStyleSettings jsSettings = settings.getCustomSettings(ECMA4CodeStyleSettings.class);
    jsSettings.SPACE_AFTER_DOTS_IN_REST_PARAMETER = false;
    doTest("class Bar {\n" + "    public function foo(...    rest):void {\n" + "    }\n" + "}", "class Bar {\n" + "    public function foo(...rest):void {\n" + "    }\n" + "}", ".as");
    jsSettings.SPACE_AFTER_DOTS_IN_REST_PARAMETER = true;
    doTest("class Bar {\n" + "    public function foo(...    rest):void {\n" + "    }\n" + "}", "class Bar {\n" + "    public function foo(... rest):void {\n" + "    }\n" + "}", ".as");
}
Also used : JSCodeStyleSettings(com.intellij.lang.javascript.formatter.JSCodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) XmlCodeStyleSettings(com.intellij.psi.formatter.xml.XmlCodeStyleSettings) ECMA4CodeStyleSettings(com.intellij.lang.javascript.formatter.ECMA4CodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) JSCodeStyleSettings(com.intellij.lang.javascript.formatter.JSCodeStyleSettings)

Example 7 with JSCodeStyleSettings

use of com.intellij.lang.javascript.formatter.JSCodeStyleSettings in project intellij-plugins by JetBrains.

the class ActionScriptHighlightingTest method testPropertyPrefix.

public void testPropertyPrefix() throws Exception {
    JSCodeStyleSettings jsCodeStyleSettings = CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JSCodeStyleSettings.class);
    String prefix = jsCodeStyleSettings.PROPERTY_PREFIX;
    jsCodeStyleSettings.PROPERTY_PREFIX = "prop";
    try {
        doSimpleHighlightingWithInvokeFixAndCheckResult("Change PropertyPrefix.ee() signature");
    } finally {
        jsCodeStyleSettings.PROPERTY_PREFIX = prefix;
    }
}
Also used : JSCodeStyleSettings(com.intellij.lang.javascript.formatter.JSCodeStyleSettings)

Example 8 with JSCodeStyleSettings

use of com.intellij.lang.javascript.formatter.JSCodeStyleSettings in project intellij-plugins by JetBrains.

the class AngularBracesInterpolationTypedHandler method beforeCharTyped.

@Override
public Result beforeCharTyped(char c, Project project, Editor editor, PsiFile file, FileType fileType) {
    if (file.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider || DumbService.isDumb(project))
        return Result.CONTINUE;
    if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET)
        return Result.DEFAULT;
    // we should use AngularJSBracesUtil here
    if (file.getFileType() == HtmlFileType.INSTANCE) {
        final Document document = editor.getDocument();
        if (c == '{') {
            if (!AngularJSBracesUtil.DEFAULT_START.equals(AngularJSBracesUtil.getInjectionStart(project)) || !AngularJSBracesUtil.DEFAULT_END.equals(AngularJSBracesUtil.getInjectionEnd(project)))
                return Result.CONTINUE;
            JSCodeStyleSettings jsSettings = JSCodeStyleSettings.getSettings(file);
            boolean addWhiteSpaceBetweenBraces = jsSettings.SPACES_WITHIN_INTERPOLATION_EXPRESSIONS;
            int offset = editor.getCaretModel().getOffset();
            String chars = document.getText();
            if (offset > 0 && (chars.charAt(offset - 1)) == '{') {
                if (offset < 2 || (chars.charAt(offset - 2)) != '{') {
                    if (alreadyHasEnding(chars, offset)) {
                        return Result.CONTINUE;
                    } else {
                        String interpolation = addWhiteSpaceBetweenBraces ? "{  }" : "{}";
                        if (offset == chars.length() || (offset < chars.length() && chars.charAt(offset) != '}')) {
                            interpolation += "}";
                        }
                        EditorModificationUtil.insertStringAtCaret(editor, interpolation, true, addWhiteSpaceBetweenBraces ? 2 : 1);
                        return Result.STOP;
                    }
                }
            }
        }
        if (c == '}') {
            if (!AngularJSBracesUtil.DEFAULT_END.equals(AngularJSBracesUtil.getInjectionEnd(project)))
                return Result.CONTINUE;
            final int offset = editor.getCaretModel().getOffset();
            final char charAt;
            if (offset < document.getTextLength()) {
                charAt = document.getCharsSequence().charAt(offset);
                if (charAt == '}') {
                    editor.getCaretModel().moveCaretRelatively(1, 0, false, false, true);
                    return Result.STOP;
                }
            } else if (offset > 0) {
                charAt = document.getCharsSequence().charAt(offset - 1);
                if (charAt != '}') {
                    EditorModificationUtil.insertStringAtCaret(editor, "}}", true, 2);
                    return Result.STOP;
                }
            }
        }
    }
    return Result.CONTINUE;
}
Also used : Document(com.intellij.openapi.editor.Document) JSCodeStyleSettings(com.intellij.lang.javascript.formatter.JSCodeStyleSettings) MultiplePsiFilesPerDocumentFileViewProvider(com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider)

Example 9 with JSCodeStyleSettings

use of com.intellij.lang.javascript.formatter.JSCodeStyleSettings in project intellij-plugins by JetBrains.

the class ActionScriptFormatterTest method testECMAScript2.

public void testECMAScript2() throws Exception {
    doFileTest("");
    doFileTest("_2");
    final JSCodeStyleSettings codeSettings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(ECMA4CodeStyleSettings.class);
    codeSettings.INDENT_PACKAGE_CHILDREN = JSCodeStyleSettings.INDENT;
    doFileTest("_3");
}
Also used : JSCodeStyleSettings(com.intellij.lang.javascript.formatter.JSCodeStyleSettings)

Aggregations

JSCodeStyleSettings (com.intellij.lang.javascript.formatter.JSCodeStyleSettings)9 ECMA4CodeStyleSettings (com.intellij.lang.javascript.formatter.ECMA4CodeStyleSettings)2 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)2 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)2 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)2 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1 Document (com.intellij.openapi.editor.Document)1 MultiplePsiFilesPerDocumentFileViewProvider (com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider)1