Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
99585ebc
Commit
99585ebc
authored
6 years ago
by
peter
Browse files
Options
Download
Email Patches
Plain Diff
unify various places where switch-case is checked in java completion
parent
ee20aa08
Branches unavailable
Tags unavailable
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
java/java-impl/src/com/intellij/codeInsight/completion/BasicExpressionCompletionContributor.java
+2
-3
...ight/completion/BasicExpressionCompletionContributor.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java
+9
-5
...lij/codeInsight/completion/JavaCompletionContributor.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionStatistician.java
+1
-1
...ij/codeInsight/completion/JavaCompletionStatistician.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java
+2
-2
...ntellij/codeInsight/completion/JavaKeywordCompletion.java
java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java
+3
-10
.../completion/ReferenceExpressionCompletionContributor.java
java/java-impl/src/com/intellij/psi/filters/getters/JavaMembersGetter.java
+1
-1
...c/com/intellij/psi/filters/getters/JavaMembersGetter.java
with
18 additions
and
22 deletions
+18
-22
java/java-impl/src/com/intellij/codeInsight/completion/BasicExpressionCompletionContributor.java
+
2
-
3
View file @
99585ebc
...
...
@@ -65,9 +65,8 @@ public class BasicExpressionCompletionContributor {
addKeyword
(
result
,
position
,
PsiKeyword
.
TRUE
);
addKeyword
(
result
,
position
,
PsiKeyword
.
FALSE
);
final
PsiElement
parent
=
position
.
getParent
();
if
(
parent
!=
null
&&
!(
parent
.
getParent
()
instanceof
PsiSwitchLabelStatement
))
{
for
(
final
PsiExpression
expression
:
ThisGetter
.
getThisExpressionVariants
(
position
))
{
if
(!
JavaCompletionContributor
.
IN_SWITCH_LABEL
.
accepts
(
position
))
{
for
(
PsiExpression
expression
:
ThisGetter
.
getThisExpressionVariants
(
position
))
{
result
.
consume
(
new
ExpressionLookupItem
(
expression
));
}
}
...
...
This diff is collapsed.
Click to expand it.
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java
+
9
-
5
View file @
99585ebc
...
...
@@ -78,7 +78,10 @@ public class JavaCompletionContributor extends CompletionContributor {
private
static
final
ElementPattern
<
PsiElement
>
ANNOTATION_ATTRIBUTE_NAME
=
or
(
psiElement
(
PsiIdentifier
.
class
).
withParent
(
NAME_VALUE_PAIR
),
psiElement
().
afterLeaf
(
"("
).
withParent
(
psiReferenceExpression
().
withParent
(
NAME_VALUE_PAIR
)));
private
static
final
ElementPattern
SWITCH_LABEL
=
public
static
final
ElementPattern
<
PsiElement
>
IN_SWITCH_LABEL
=
psiElement
().
withSuperParent
(
2
,
psiElement
(
PsiSwitchLabelStatement
.
class
).
withSuperParent
(
2
,
PsiSwitchStatement
.
class
));
private
static
final
ElementPattern
IN_ENUM_SWITCH_LABEL
=
psiElement
().
withSuperParent
(
2
,
psiElement
(
PsiSwitchLabelStatement
.
class
).
withSuperParent
(
2
,
psiElement
(
PsiSwitchStatement
.
class
).
with
(
new
PatternCondition
<
PsiSwitchStatement
>(
"enumExpressionType"
)
{
@Override
...
...
@@ -89,6 +92,7 @@ public class JavaCompletionContributor extends CompletionContributor {
return
aClass
!=
null
&&
aClass
.
isEnum
();
}
})));
private
static
final
ElementPattern
<
PsiElement
>
AFTER_NUMBER_LITERAL
=
psiElement
().
afterLeaf
(
psiElement
().
withElementType
(
elementType
().
oneOf
(
JavaTokenType
.
DOUBLE_LITERAL
,
JavaTokenType
.
LONG_LITERAL
,
JavaTokenType
.
FLOAT_LITERAL
,
JavaTokenType
.
INTEGER_LITERAL
)));
...
...
@@ -153,7 +157,7 @@ public class JavaCompletionContributor extends CompletionContributor {
return
new
ExcludeFilter
(
var
);
}
if
(
SWITCH_LABEL
.
accepts
(
position
))
{
if
(
IN_ENUM_
SWITCH_LABEL
.
accepts
(
position
))
{
return
new
ClassFilter
(
PsiField
.
class
)
{
@Override
public
boolean
isAcceptable
(
Object
element
,
PsiElement
context
)
{
...
...
@@ -420,7 +424,7 @@ public class JavaCompletionContributor extends CompletionContributor {
MultiMap
<
CompletionResultSet
,
LookupElement
>
items
=
MultiMap
.
create
();
final
PsiElement
position
=
parameters
.
getPosition
();
final
boolean
first
=
parameters
.
getInvocationCount
()
<=
1
;
final
boolean
isSwitchLabel
=
SWITCH_LABEL
.
accepts
(
position
);
final
boolean
isSwitchLabel
=
IN_ENUM_
SWITCH_LABEL
.
accepts
(
position
);
final
boolean
isAfterNew
=
JavaClassNameCompletionContributor
.
AFTER_NEW
.
accepts
(
position
);
final
boolean
pkgContext
=
JavaCompletionUtil
.
inSomePackage
(
position
);
final
PsiType
[]
expectedTypes
=
ExpectedTypesGetter
.
getExpectedTypes
(
parameters
.
getPosition
(),
true
);
...
...
@@ -531,8 +535,7 @@ public class JavaCompletionContributor extends CompletionContributor {
return
false
;
}
PsiElement
grand
=
parent
.
getParent
();
if
(
grand
instanceof
PsiSwitchLabelStatement
)
{
if
(
IN_SWITCH_LABEL
.
accepts
(
position
))
{
return
false
;
}
...
...
@@ -540,6 +543,7 @@ public class JavaCompletionContributor extends CompletionContributor {
return
isSecondCompletion
;
}
PsiElement
grand
=
parent
.
getParent
();
if
(
grand
instanceof
PsiAnonymousClass
)
{
grand
=
grand
.
getParent
();
}
...
...
This diff is collapsed.
Click to expand it.
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionStatistician.java
+
1
-
1
View file @
99585ebc
...
...
@@ -51,7 +51,7 @@ public class JavaCompletionStatistician extends CompletionStatistician{
}
PsiElement
position
=
location
.
getCompletionParameters
().
getPosition
();
if
(
SUPER_CALL
.
accepts
(
position
)
||
ReferenceExpression
CompletionContributor
.
IN_SWITCH_LABEL
.
accepts
(
position
))
{
if
(
SUPER_CALL
.
accepts
(
position
)
||
Java
CompletionContributor
.
IN_SWITCH_LABEL
.
accepts
(
position
))
{
return
StatisticsInfo
.
EMPTY
;
}
...
...
This diff is collapsed.
Click to expand it.
java/java-impl/src/com/intellij/codeInsight/completion/JavaKeywordCompletion.java
+
2
-
2
View file @
99585ebc
...
...
@@ -98,13 +98,13 @@ public class JavaKeywordCompletion {
psiElement
().
withParent
(
psiElement
(
PsiReferenceExpression
.
class
).
withParent
(
not
(
or
(
psiElement
(
PsiSwitchLabelStatement
.
class
),
psiElement
(
PsiExpressionStatement
.
class
),
psiElement
(
PsiPrefixExpression
.
class
)
)
)
)),
not
(
psiElement
().
afterLeaf
(
"."
))
not
(
psiElement
().
afterLeaf
(
"."
)),
not
(
JavaCompletionContributor
.
IN_SWITCH_LABEL
)
);
private
final
CompletionParameters
myParameters
;
...
...
This diff is collapsed.
Click to expand it.
java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java
+
3
-
10
View file @
99585ebc
...
...
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.completion;
import
com.intellij.codeInsight.lookup.ExpressionLookupItem
;
import
com.intellij.codeInsight.lookup.LookupElement
;
import
com.intellij.openapi.diagnostic.Logger
;
import
com.intellij.patterns.ElementPattern
;
import
com.intellij.patterns.StandardPatterns
;
import
com.intellij.psi.*
;
import
com.intellij.psi.filters.*
;
...
...
@@ -44,21 +43,15 @@ import static com.intellij.patterns.PsiJavaPatterns.psiElement;
*/
public
class
ReferenceExpressionCompletionContributor
{
private
static
final
Logger
LOG
=
Logger
.
getInstance
(
"#com.intellij.codeInsight.completion.ReferenceExpressionCompletionContributor"
);
public
static
final
ElementPattern
<
PsiElement
>
IN_SWITCH_LABEL
=
psiElement
().
withSuperParent
(
2
,
psiElement
(
PsiSwitchLabelStatement
.
class
).
withSuperParent
(
2
,
PsiSwitchStatement
.
class
));
@NotNull
@NotNull
static
ElementFilter
getReferenceFilter
(
PsiElement
element
,
boolean
allowRecursion
)
{
//throw foo
if
(
psiElement
().
withParent
(
psiElement
(
PsiReferenceExpression
.
class
).
withParent
(
PsiThrowStatement
.
class
)).
accepts
(
element
))
{
return
TrueFilter
.
INSTANCE
;
}
if
(
psiElement
().
inside
(
StandardPatterns
.
or
(
psiElement
(
PsiAnnotationParameterList
.
class
),
psiElement
(
PsiSwitchLabelStatement
.
class
))
).
accepts
(
element
))
{
if
(
psiElement
().
inside
(
StandardPatterns
.
or
(
psiElement
(
PsiAnnotationParameterList
.
class
),
JavaCompletionContributor
.
IN_SWITCH_LABEL
)).
accepts
(
element
))
{
return
new
ElementExtractorFilter
(
new
AndFilter
(
new
ClassFilter
(
PsiField
.
class
),
new
ModifierFilter
(
PsiKeyword
.
STATIC
,
PsiKeyword
.
FINAL
)
...
...
@@ -176,7 +169,7 @@ public class ReferenceExpressionCompletionContributor {
@NotNull
public
static
Set
<
PsiField
>
findConstantsUsedInSwitch
(
@Nullable
PsiElement
position
)
{
return
IN_SWITCH_LABEL
.
accepts
(
position
)
return
JavaCompletionContributor
.
IN_SWITCH_LABEL
.
accepts
(
position
)
?
findConstantsUsedInSwitch
(
ObjectUtils
.
assertNotNull
(
PsiTreeUtil
.
getParentOfType
(
position
,
PsiSwitchStatement
.
class
)))
:
Collections
.
emptySet
();
}
...
...
This diff is collapsed.
Click to expand it.
java/java-impl/src/com/intellij/psi/filters/getters/JavaMembersGetter.java
+
1
-
1
View file @
99585ebc
...
...
@@ -56,7 +56,7 @@ public class JavaMembersGetter extends MembersGetter {
addConstantsFromReferencedClassesInSwitch
(
results
);
}
if
(
myPlace
.
getParent
().
getParent
()
instanceof
PsiSwitchLabelStatement
)
{
if
(
JavaCompletionContributor
.
IN_SWITCH_LABEL
.
accepts
(
myPlace
)
)
{
return
;
//non-enum values are processed above, enum values will be suggested by reference completion
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help