Search in sources :

Example 86 with CommonCodeStyleSettings

use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-plugins by JetBrains.

the class GherkinLanguageCodeStyleSettingsProvider method getDefaultCommonSettings.

@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
    CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(GherkinLanguage.INSTANCE);
    CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
    indentOptions.INDENT_SIZE = 2;
    return defaultSettings;
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 87 with CommonCodeStyleSettings

use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-plugins by JetBrains.

the class DartTypingTest method testAutoWrapString.

public void testAutoWrapString() {
    CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(DartLanguage.INSTANCE);
    settings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue;
    settings.RIGHT_MARGIN = 42;
    doTypingTest('3', "var x = '12345678901234567890123456789012<caret>'", "var x = '123456789012345678901234567890'\n" + "    '123<caret>'");
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 88 with CommonCodeStyleSettings

use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-plugins by JetBrains.

the class DartStyleTest method runTestInDirectory.

/**
   * Run a test defined in "*.unit" or "*.stmt" file inside directory <code>dirName</code>.
   * Only signal failures for tests that fail and are not listed in <code>knownFailures.</code>
   */
protected void runTestInDirectory(String dirName, Set knownFailures) throws Exception {
    Pattern indentPattern = Pattern.compile("^.*\\s\\(indent (\\d+)\\)\\s*");
    String testName = getTestName(true);
    if (Character.isLetter(testName.charAt(0)) && Character.isDigit(testName.charAt(testName.length() - 1))) {
        testName = testName.substring(0, testName.length() - 1);
    }
    File dir = new File(new File(getTestDataPath(), getBasePath()), dirName);
    boolean found = false;
    final StringBuilder combinedActualResult = new StringBuilder();
    final StringBuilder combinedExpectedResult = new StringBuilder();
    for (String ext : new String[] { ".stmt", ".unit" }) {
        String testFileName = testName + ext;
        File entry = new File(dir, testFileName);
        if (!entry.exists()) {
            continue;
        }
        found = true;
        String[] lines = ArrayUtil.toStringArray(FileUtil.loadLines(entry, "UTF-8"));
        boolean isCompilationUnit = entry.getName().endsWith(".unit");
        // The first line may have a "|" to indicate the page width.
        int pageWidth = 80;
        int i = 0;
        if (lines[0].endsWith("|")) {
            // As it happens, this is always 40 except for some files in 'regression'
            pageWidth = lines[0].indexOf("|");
            i = 1;
        }
        // Adjust for indent in case test is near margin.
        if (!isCompilationUnit)
            pageWidth += 2;
        System.out.println("\nTest: " + dirName + "/" + testFileName + ", Right margin: " + pageWidth);
        final CommonCodeStyleSettings settings = getSettings(DartLanguage.INSTANCE);
        settings.RIGHT_MARGIN = pageWidth;
        // TODO Decide whether this should be the default -- risky!
        settings.KEEP_LINE_BREAKS = false;
        settings.KEEP_BLANK_LINES_IN_CODE = 1;
        while (i < lines.length) {
            String description = (dirName + "/" + testFileName + ":" + (i + 1) + " " + lines[i++].replaceAll(">>>", "")).trim();
            // Let the test specify a leading indentation. This is handy for
            // regression tests which often come from a chunk of nested code.
            int leadingIndent = 0;
            Matcher matcher = indentPattern.matcher(description);
            if (matcher.matches()) {
                // The leadingIndent is only used by some tests in 'regression'.
                leadingIndent = Integer.parseInt(matcher.group(1));
                settings.RIGHT_MARGIN = pageWidth - leadingIndent;
            }
            String input = "";
            // The formatter fails horribly otherwise.
            if (!isCompilationUnit)
                input += "m() {\n";
            while (!lines[i].startsWith("<<<")) {
                String line = lines[i++];
                if (leadingIndent > 0 && leadingIndent < line.length())
                    line = line.substring(leadingIndent);
                if (!isCompilationUnit && !line.isEmpty())
                    line = "  " + line;
                input += line + "\n";
            }
            if (!isCompilationUnit)
                input += "}\n";
            String expectedOutput = "";
            if (!isCompilationUnit)
                expectedOutput += "m() {\n";
            i++;
            while (i < lines.length && !lines[i].startsWith(">>>")) {
                String line = lines[i++];
                if (leadingIndent > 0 && leadingIndent < line.length())
                    line = line.substring(leadingIndent);
                if (!isCompilationUnit && !line.isEmpty())
                    line = "  " + line;
                expectedOutput += line + "\n";
            }
            if (!isCompilationUnit)
                expectedOutput += "}\n";
            SourceCode inputCode = extractSourceSelection(input, expectedOutput, isCompilationUnit);
            SourceCode expected = extractSelection(expectedOutput, isCompilationUnit);
            try {
                doTextTest(inputCode.text, expected.text);
                if (knownFailures.contains(description)) {
                    fail("The test passed, but was expected to fail: " + description);
                }
                System.out.println("TEST PASSED: " + (description.isEmpty() ? "(unnamed)" : description));
            } catch (ComparisonFailure failure) {
                if (!knownFailures.contains(description.replace('"', '\''))) {
                    combinedExpectedResult.append("TEST: ").append(description).append("\n").append(failure.getExpected()).append("\n");
                    combinedActualResult.append("TEST: ").append(description).append("\n").append(failure.getActual()).append("\n");
                }
            }
        }
    }
    if (!found) {
        fail("No test data for " + testName);
    }
    assertEquals(combinedExpectedResult.toString(), combinedActualResult.toString());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ComparisonFailure(junit.framework.ComparisonFailure) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) File(java.io.File)

Example 89 with CommonCodeStyleSettings

use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-plugins by JetBrains.

the class DartTypingTest method testAutoWrapCascade.

public void testAutoWrapCascade() {
    CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(DartLanguage.INSTANCE);
    settings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue;
    settings.RIGHT_MARGIN = 42;
    doTypingTest('3', "var x = a123456789012345..b890123456789012<caret>", "var x = a123456789012345\n" + "  ..b8901234567890123");
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 90 with CommonCodeStyleSettings

use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-plugins by JetBrains.

the class DartFormatterTest method testSpaceLeftBraces.

public void testSpaceLeftBraces() throws Exception {
    final CommonCodeStyleSettings settings = getSettings(DartLanguage.INSTANCE);
    settings.KEEP_LINE_BREAKS = false;
    settings.SPACE_BEFORE_METHOD_LBRACE = false;
    settings.SPACE_BEFORE_IF_LBRACE = false;
    settings.SPACE_BEFORE_ELSE_LBRACE = false;
    settings.SPACE_BEFORE_FOR_LBRACE = false;
    settings.SPACE_BEFORE_WHILE_LBRACE = false;
    settings.SPACE_BEFORE_SWITCH_LBRACE = false;
    settings.SPACE_BEFORE_TRY_LBRACE = false;
    settings.SPACE_BEFORE_CATCH_LBRACE = false;
    doTest();
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Aggregations

CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)202 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)19 TextRange (com.intellij.openapi.util.TextRange)5 PsiElement (com.intellij.psi.PsiElement)5 ASTNode (com.intellij.lang.ASTNode)4 Editor (com.intellij.openapi.editor.Editor)4 JavaCodeStyleSettings (com.intellij.psi.codeStyle.JavaCodeStyleSettings)4 EditorSettingsExternalizable (com.intellij.openapi.editor.ex.EditorSettingsExternalizable)3 PsiFile (com.intellij.psi.PsiFile)3 File (java.io.File)3 Matcher (java.util.regex.Matcher)3 NonNls (org.jetbrains.annotations.NonNls)3 NotNull (org.jetbrains.annotations.NotNull)3 Document (com.intellij.openapi.editor.Document)2 Project (com.intellij.openapi.project.Project)2 CodeStyleManager (com.intellij.psi.codeStyle.CodeStyleManager)2 ArrangementGroupingRule (com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule)2 IElementType (com.intellij.psi.tree.IElementType)2 Nullable (org.jetbrains.annotations.Nullable)2 GroovyCodeStyleSettings (org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings)2