mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method ref: spaces around dbl colon
This commit is contained in:
@@ -185,6 +185,7 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett
|
||||
"\n" +
|
||||
" public void foo(int x, int y) {" +
|
||||
" Runnable r = () -> {};\n" +
|
||||
" Runnable r1 = this :: bar;\n" +
|
||||
" for (int i = 0; i < x; i++) {\n" +
|
||||
" y += (y ^ 0x123) << 2;\n" +
|
||||
" }\n" +
|
||||
|
||||
@@ -1184,6 +1184,14 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
|
||||
if ((myRole1 == ChildRole.DOUBLE_COLON && myRole2 == ChildRole.EXPRESSION) ||
|
||||
(myRole1 == ChildRole.EXPRESSION && myRole2 == ChildRole.DOUBLE_COLON)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_METHOD_REF_DBL_COLON);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitForStatement(PsiForStatement statement) {
|
||||
if (myRole2 == ChildRole.LPARENTH) {
|
||||
createSpaceInCode(mySettings.SPACE_BEFORE_FOR_PARENTHESES);
|
||||
|
||||
@@ -157,6 +157,7 @@ public class ChildRole {
|
||||
public static final int ANNOTATION = 250; // in MODIFIER_LIST
|
||||
public static final int CATCH_SECTION = 251; // in TRY_STATEMENT
|
||||
public static final int ARROW = 252; // in LAMBDA STATEMENT
|
||||
public static final int DOUBLE_COLON = 253; // in METHOD_REF
|
||||
|
||||
private ChildRole() {
|
||||
}
|
||||
|
||||
+12
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.source.resolve.ResolveCache;
|
||||
import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.scope.ElementClassFilter;
|
||||
@@ -29,6 +31,7 @@ import com.intellij.psi.scope.conflictResolvers.DuplicateConflictResolver;
|
||||
import com.intellij.psi.scope.processor.FilterScopeProcessor;
|
||||
import com.intellij.psi.scope.processor.MethodCandidatesProcessor;
|
||||
import com.intellij.psi.scope.util.PsiScopesUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -77,6 +80,15 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
PsiScopesUtil.resolveAndWalk(proc, this, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildRole(ASTNode child) {
|
||||
final IElementType elType = child.getElementType();
|
||||
if (elType == JavaTokenType.DOUBLE_COLON) {
|
||||
return ChildRole.DOUBLE_COLON;
|
||||
}
|
||||
return ChildRole.EXPRESSION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult[] multiResolve(final boolean incompleteCode) {
|
||||
|
||||
@@ -313,6 +313,17 @@ public class JavaFormatterSpaceTest extends AbstractJavaFormatterTest {
|
||||
"()->{}");
|
||||
}
|
||||
|
||||
public void testSpacesInsideMethodRef() throws Exception {
|
||||
getSettings().SPACE_AROUND_METHOD_REF_DBL_COLON = true;
|
||||
|
||||
doMethodTest("Runnable r = this::foo",
|
||||
"Runnable r = this :: foo");
|
||||
|
||||
getSettings().SPACE_AROUND_METHOD_REF_DBL_COLON = false;
|
||||
doMethodTest("Runnable r = this::foo",
|
||||
"Runnable r = this::foo");
|
||||
}
|
||||
|
||||
public void testSpacesBeforeResourceList() throws Exception {
|
||||
getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
|
||||
getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
|
||||
@@ -33,6 +33,7 @@ public interface CodeStyleSettingsCustomizable {
|
||||
SPACE_AROUND_SHIFT_OPERATORS,
|
||||
SPACE_AROUND_UNARY_OPERATOR,
|
||||
SPACE_AROUND_LAMBDA_ARROW,
|
||||
SPACE_AROUND_METHOD_REF_DBL_COLON,
|
||||
SPACE_AFTER_COMMA,
|
||||
SPACE_AFTER_COMMA_IN_TYPE_ARGUMENTS,
|
||||
SPACE_BEFORE_COMMA,
|
||||
|
||||
@@ -525,6 +525,7 @@ public class CommonCodeStyleSettings {
|
||||
public boolean SPACE_AROUND_UNARY_OPERATOR = false;
|
||||
|
||||
public boolean SPACE_AROUND_LAMBDA_ARROW = true;
|
||||
public boolean SPACE_AROUND_METHOD_REF_DBL_COLON = true;
|
||||
|
||||
public boolean SPACE_AFTER_COMMA = true;
|
||||
public boolean SPACE_AFTER_COMMA_IN_TYPE_ARGUMENTS = true;
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel {
|
||||
initBooleanField("SPACE_AROUND_SHIFT_OPERATORS", ApplicationBundle.message("checkbox.spaces.shift.operators"), SPACES_AROUND_OPERATORS);
|
||||
initBooleanField("SPACE_AROUND_UNARY_OPERATOR", ApplicationBundle.message("checkbox.spaces.around.unary.operator"), SPACES_AROUND_OPERATORS);
|
||||
initBooleanField("SPACE_AROUND_LAMBDA_ARROW", ApplicationBundle.message("checkbox.spaces.around.lambda.arrow"), SPACES_AROUND_OPERATORS);
|
||||
initBooleanField("SPACE_AROUND_METHOD_REF_DBL_COLON", ApplicationBundle.message("checkbox.spaces.around.method.ref.dbl.colon.arrow"), SPACES_AROUND_OPERATORS);
|
||||
initCustomOptions(SPACES_AROUND_OPERATORS);
|
||||
|
||||
initBooleanField("SPACE_BEFORE_CLASS_LBRACE", ApplicationBundle.message("checkbox.spaces.class.left.brace"), SPACES_BEFORE_LEFT_BRACE);
|
||||
|
||||
@@ -560,4 +560,5 @@ arrangement.action.rule.add.text=Add rule
|
||||
arrangement.action.rule.add.description=Add new arrangement rule
|
||||
arrangement.action.rule.remove.text=Remove rule
|
||||
arrangement.action.rule.remove.description=Remove selected arrangement rule
|
||||
checkbox.spaces.around.lambda.arrow=Lambda arrow
|
||||
checkbox.spaces.around.lambda.arrow=Lambda arrow
|
||||
checkbox.spaces.around.method.ref.dbl.colon.arrow=Method reference double colon
|
||||
Reference in New Issue
Block a user