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);
}
}
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;
}
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;
}
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");
}
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");
}
Aggregations