Search in sources :

Example 16 with CommonCodeStyleSettings

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

the class JavaCompletionUtil method insertParentheses.

public static void insertParentheses(final InsertionContext context, final LookupElement item, boolean overloadsMatter, boolean hasParams, final boolean forceClosingParenthesis) {
    final Editor editor = context.getEditor();
    final char completionChar = context.getCompletionChar();
    final PsiFile file = context.getFile();
    final TailType tailType = completionChar == '(' ? TailType.NONE : completionChar == ':' ? TailType.COND_EXPR_COLON : LookupItem.handleCompletionChar(context.getEditor(), item, completionChar);
    final boolean hasTail = tailType != TailType.NONE && tailType != TailType.UNKNOWN;
    final boolean smart = completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR;
    if (completionChar == '(' || completionChar == '.' || completionChar == ',' || completionChar == ';' || completionChar == ':' || completionChar == ' ') {
        context.setAddCompletionChar(false);
    }
    if (hasTail) {
        hasParams = false;
    }
    final boolean needRightParenth = forceClosingParenthesis || !smart && (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET || !hasParams && completionChar != '(');
    context.commitDocument();
    final CommonCodeStyleSettings styleSettings = context.getCodeStyleSettings();
    final PsiElement elementAt = file.findElementAt(context.getStartOffset());
    if (elementAt == null || !(elementAt.getParent() instanceof PsiMethodReferenceExpression)) {
        final boolean hasParameters = hasParams;
        final boolean spaceBetweenParentheses = styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams;
        new ParenthesesInsertHandler<LookupElement>(styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES, spaceBetweenParentheses, needRightParenth, styleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE) {

            @Override
            protected boolean placeCaretInsideParentheses(InsertionContext context1, LookupElement item1) {
                return hasParameters;
            }

            @Override
            protected PsiElement findExistingLeftParenthesis(@NotNull InsertionContext context) {
                PsiElement token = super.findExistingLeftParenthesis(context);
                return isPartOfLambda(token) ? null : token;
            }

            private boolean isPartOfLambda(PsiElement token) {
                return token != null && token.getParent() instanceof PsiExpressionList && PsiUtilCore.getElementType(PsiTreeUtil.nextVisibleLeaf(token.getParent())) == JavaTokenType.ARROW;
            }
        }.handleInsert(context, item);
    }
    if (hasParams) {
        // Invoke parameters popup
        AutoPopupController.getInstance(file.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : (PsiElement) item.getObject());
    }
    if (smart || !needRightParenth || !insertTail(context, item, tailType, hasTail)) {
        return;
    }
    if (completionChar == '.') {
        AutoPopupController.getInstance(file.getProject()).autoPopupMemberLookup(context.getEditor(), null);
    } else if (completionChar == ',') {
        AutoPopupController.getInstance(file.getProject()).autoPopupParameterInfo(context.getEditor(), null);
    }
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) Editor(com.intellij.openapi.editor.Editor) FakePsiElement(com.intellij.psi.impl.FakePsiElement)

Example 17 with CommonCodeStyleSettings

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

the class ParenthesesTailType method processTail.

@Override
public int processTail(final Editor editor, int tailOffset) {
    CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset);
    if (isSpaceBeforeParentheses(styleSettings, editor, tailOffset)) {
        tailOffset = insertChar(editor, tailOffset, ' ');
    }
    tailOffset = insertChar(editor, tailOffset, '(');
    if (isSpaceWithinParentheses(styleSettings, editor, tailOffset)) {
        tailOffset = insertChar(editor, tailOffset, ' ');
        tailOffset = insertChar(editor, tailOffset, ' ');
        tailOffset = insertChar(editor, tailOffset, ')');
        moveCaret(editor, tailOffset, -2);
    } else {
        tailOffset = insertChar(editor, tailOffset, ')');
        moveCaret(editor, tailOffset, -1);
    }
    return tailOffset;
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 18 with CommonCodeStyleSettings

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

the class InvertIfConditionTest method afterActionCompleted.

@Override
protected void afterActionCompleted(final String testName, final String contents) {
    super.afterActionCompleted(testName, contents);
    CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
    settings.ELSE_ON_NEW_LINE = myElseOnNewLine;
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 19 with CommonCodeStyleSettings

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

the class IndentTest method testTernaryOperation.

public void testTernaryOperation() throws Exception {
    defaultSettings();
    CommonCodeStyleSettings settings = getJavaSettings();
    settings.ALIGN_MULTILINE_TERNARY_OPERATION = true;
    doTest("TernaryOperation.java", "TernaryOperation_after.java");
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 20 with CommonCodeStyleSettings

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

the class DetectIndentAndTypeTest method testWhenTabsDetected_SetIndentSizeToTabSize.

public void testWhenTabsDetected_SetIndentSizeToTabSize() {
    CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE);
    CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions();
    assert indentOptions != null;
    indentOptions.INDENT_SIZE = 1;
    indentOptions.TAB_SIZE = 2;
    myFixture.configureByText(JavaFileType.INSTANCE, "public class T {\n" + "\tvoid run() {\n" + "\t\tint a = 2;<caret>\n" + "\t}\n" + "}\n");
    myFixture.type('\n');
    myFixture.checkResult("public class T {\n" + "\tvoid run() {\n" + "\t\tint a = 2;\n" + "\t\t<caret>\n" + "\t}\n" + "}\n");
}
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