use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-community by JetBrains.
the class BlockJoinLinesHandler method getForceBraceSetting.
private static int getForceBraceSetting(PsiElement statement) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(statement.getProject());
final CommonCodeStyleSettings codeStyleSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
if (statement instanceof PsiIfStatement) {
return codeStyleSettings.IF_BRACE_FORCE;
}
if (statement instanceof PsiWhileStatement) {
return codeStyleSettings.WHILE_BRACE_FORCE;
}
if (statement instanceof PsiForStatement) {
return codeStyleSettings.FOR_BRACE_FORCE;
}
if (statement instanceof PsiDoWhileStatement) {
return codeStyleSettings.DOWHILE_BRACE_FORCE;
}
return CommonCodeStyleSettings.DO_NOT_FORCE;
}
use of com.intellij.psi.codeStyle.CommonCodeStyleSettings in project intellij-community by JetBrains.
the class SmartTypeCompletionTest method testNewRunnableInsideMethodMultiParams.
public void testNewRunnableInsideMethodMultiParams() throws Throwable {
CommonCodeStyleSettings settings = getCodeStyleSettings();
boolean lParenOnNextLine = settings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE;
boolean rParenOnNextLine = settings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE;
try {
settings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
settings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
doTest();
} finally {
settings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = lParenOnNextLine;
settings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = rParenOnNextLine;
}
}
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;
}
Aggregations