Search in sources :

Example 6 with CommonCodeStyleSettings

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

the class GroovyFormattingModelBuilder method createModel.

@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
    ASTNode node = element.getNode();
    assert node != null;
    PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(GroovyLanguage.INSTANCE);
    assert containingFile != null : element.getContainingFile();
    ASTNode astNode = containingFile.getNode();
    assert astNode != null;
    CommonCodeStyleSettings groovySettings = settings.getCommonSettings(GroovyLanguage.INSTANCE);
    GroovyCodeStyleSettings customSettings = settings.getCustomSettings(GroovyCodeStyleSettings.class);
    final AlignmentProvider alignments = new AlignmentProvider();
    if (customSettings.USE_FLYING_GEESE_BRACES) {
        element.accept(new PsiRecursiveElementVisitor() {

            @Override
            public void visitElement(PsiElement element) {
                if (GeeseUtil.isClosureRBrace(element)) {
                    GeeseUtil.calculateRBraceAlignment(element, alignments);
                } else {
                    super.visitElement(element);
                }
            }
        });
    }
    final GroovyBlock block = new GroovyBlock(astNode, Indent.getAbsoluteNoneIndent(), null, new FormattingContext(groovySettings, alignments, customSettings, false));
    return new GroovyFormattingModel(containingFile, block, FormattingDocumentModelImpl.createOn(containingFile));
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) GroovyBlock(org.jetbrains.plugins.groovy.formatter.blocks.GroovyBlock) GroovyCodeStyleSettings(org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings) ASTNode(com.intellij.lang.ASTNode) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with CommonCodeStyleSettings

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

the class PyWrapTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
    final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
    myOldWrap = settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
    myOldMargin = pythonSettings.RIGHT_MARGIN;
    settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true;
    pythonSettings.RIGHT_MARGIN = 80;
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 8 with CommonCodeStyleSettings

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

the class PyWrapTest method tearDown.

@Override
protected void tearDown() throws Exception {
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
    final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
    settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = myOldWrap;
    pythonSettings.RIGHT_MARGIN = myOldMargin;
    super.tearDown();
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 9 with CommonCodeStyleSettings

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

the class PyWrapTest method testWrapRightMargin.

public void testWrapRightMargin() {
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
    final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
    int oldValue = pythonSettings.RIGHT_MARGIN;
    boolean oldMarginValue = settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
    pythonSettings.RIGHT_MARGIN = 100;
    settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true;
    try {
        final String testName = "wrap/" + getTestName(true);
        myFixture.configureByFile(testName + ".py");
        for (int i = 0; i != 45; ++i) {
            myFixture.type(' ');
        }
        myFixture.checkResultByFile(testName + ".after.py");
    } finally {
        pythonSettings.RIGHT_MARGIN = oldValue;
        settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = oldMarginValue;
    }
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 10 with CommonCodeStyleSettings

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

the class XmlLanguageCodeStyleSettingsProvider method getDefaultCommonSettings.

@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
    CommonCodeStyleSettings xmlSettings = new CommonCodeStyleSettings(getLanguage());
    CommonCodeStyleSettings.IndentOptions indentOptions = xmlSettings.initIndentOptions();
    xmlSettings.setForceArrangeMenuAvailable(true);
    // HACK [yole]
    if (PlatformUtils.isRubyMine()) {
        indentOptions.INDENT_SIZE = 2;
    }
    return xmlSettings;
}
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