Search in sources :

Example 11 with CommonCodeStyleSettings

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

the class EnterInStringLiteralHandler method preprocessEnter.

@Override
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull Ref<Integer> caretOffsetRef, @NotNull final Ref<Integer> caretAdvanceRef, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) {
    int caretOffset = caretOffsetRef.get().intValue();
    int caretAdvance = caretAdvanceRef.get().intValue();
    if (!isInStringLiteral(editor, dataContext, caretOffset))
        return Result.Continue;
    PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
    PsiElement psiAtOffset = file.findElementAt(caretOffset);
    if (psiAtOffset != null && psiAtOffset.getTextOffset() < caretOffset) {
        Document document = editor.getDocument();
        CharSequence text = document.getText();
        ASTNode token = psiAtOffset.getNode();
        JavaLikeQuoteHandler quoteHandler = getJavaLikeQuoteHandler(editor, psiAtOffset);
        if (quoteHandler != null && quoteHandler.getConcatenatableStringTokenTypes() != null && quoteHandler.getConcatenatableStringTokenTypes().contains(token.getElementType())) {
            TextRange range = token.getTextRange();
            final char literalStart = token.getText().charAt(0);
            final StringLiteralLexer lexer = new StringLiteralLexer(literalStart, token.getElementType());
            lexer.start(text, range.getStartOffset(), range.getEndOffset());
            while (lexer.getTokenType() != null) {
                if (lexer.getTokenStart() < caretOffset && caretOffset < lexer.getTokenEnd()) {
                    if (StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(lexer.getTokenType())) {
                        caretOffset = lexer.getTokenEnd();
                    }
                    break;
                }
                lexer.advance();
            }
            if (quoteHandler.needParenthesesAroundConcatenation(psiAtOffset)) {
                document.insertString(psiAtOffset.getTextRange().getEndOffset(), ")");
                document.insertString(psiAtOffset.getTextRange().getStartOffset(), "(");
                caretOffset++;
                caretAdvance++;
            }
            final String insertedFragment = literalStart + " " + quoteHandler.getStringConcatenationOperatorRepresentation();
            document.insertString(caretOffset, insertedFragment + " " + literalStart);
            caretOffset += insertedFragment.length();
            caretAdvance = 1;
            CommonCodeStyleSettings langSettings = CodeStyleSettingsManager.getSettings(file.getProject()).getCommonSettings(file.getLanguage());
            if (langSettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE) {
                caretOffset -= 1;
                caretAdvance = 3;
            }
            caretOffsetRef.set(caretOffset);
            caretAdvanceRef.set(caretAdvance);
            return Result.DefaultForceIndent;
        }
    }
    return Result.Continue;
}
Also used : JavaLikeQuoteHandler(com.intellij.codeInsight.editorActions.JavaLikeQuoteHandler) StringLiteralLexer(com.intellij.lexer.StringLiteralLexer) ASTNode(com.intellij.lang.ASTNode) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Example 12 with CommonCodeStyleSettings

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

the class CommenterForm method reset.

public void reset(@NotNull CodeStyleSettings settings) {
    CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
    myLineCommentAtFirstColumnCb.setSelected(langSettings.LINE_COMMENT_AT_FIRST_COLUMN);
    myBlockCommentAtFirstJBCheckBox.setSelected(langSettings.BLOCK_COMMENT_AT_FIRST_COLUMN);
    myLineCommentAddSpaceCb.setSelected(langSettings.LINE_COMMENT_ADD_SPACE && !langSettings.LINE_COMMENT_AT_FIRST_COLUMN);
    myLineCommentAddSpaceCb.setEnabled(!langSettings.LINE_COMMENT_AT_FIRST_COLUMN);
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 13 with CommonCodeStyleSettings

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

the class RightMarginForm method reset.

public void reset(@NotNull CodeStyleSettings settings) {
    CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
    if (langSettings != settings && langSettings.RIGHT_MARGIN >= 0) {
        myDefaultGeneralCheckBox.setSelected(false);
        myRightMarginField.setText(Integer.toString(langSettings.RIGHT_MARGIN));
    } else {
        myDefaultGeneralCheckBox.setSelected(true);
        myRightMarginField.setText(Integer.toString(settings.getDefaultRightMargin()));
        if (langSettings == settings) {
            myDefaultGeneralCheckBox.setEnabled(false);
            myRightMarginField.setEnabled(false);
        }
    }
    for (int i = 0; i < CodeStyleSettingsCustomizable.WRAP_ON_TYPING_VALUES.length; i++) {
        if (langSettings.WRAP_ON_TYPING == CodeStyleSettingsCustomizable.WRAP_ON_TYPING_VALUES[i]) {
            myWrapOnTypingCombo.setSelectedIndex(i);
            break;
        }
    }
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 14 with CommonCodeStyleSettings

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

the class RightMarginForm method apply.

public void apply(@NotNull CodeStyleSettings settings) {
    CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage);
    if (langSettings != settings) {
        if (myDefaultGeneralCheckBox.isSelected()) {
            langSettings.RIGHT_MARGIN = -1;
        } else {
            langSettings.RIGHT_MARGIN = getFieldRightMargin(settings.getDefaultRightMargin());
        }
    }
    langSettings.WRAP_ON_TYPING = getSelectedWrapOnTypingValue();
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 15 with CommonCodeStyleSettings

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

the class ArrangementSettingsPanel method apply.

@Override
public void apply(CodeStyleSettings settings) {
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(myLanguage);
    commonSettings.setArrangementSettings(createSettings());
    if (myForceArrangementPanel != null) {
        commonSettings.FORCE_REARRANGE_MODE = myForceArrangementPanel.getRearrangeMode();
    }
}
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