Repository navigation
Refactoring JavaKeywordCompletion and PsiJavaPatterns - #310
Conversation
|
@claude review pr with inline comments |
|
Claude finished @unv-unv's task in 3m 23s —— View job Claude finished reviewing PR #310
SummaryI found no logic changes. Most of the PR is reformatting (2 → 4 space indent, braces on single-line Inline comments
I didn't build or run tests; this is a read-only review. |
There was a problem hiding this comment.
Inline review from Claude. Overall the refactoring looks behavior-preserving: I checked every non-whitespace hunk (pattern-matching instanceof rewrites, the flattened else if in createTypeDeclaration, the inlined boolean chains in nextIsIdentifier, isInstanceofPlace, isVariableTypePosition, isInsideQualifierClass and isInsideInheritorClass, and Conditions.instanceOf → PsiTypeElement.class::isInstance) and found no logic changes. The comments below are about where @RequiredReadAction is applied, leftover final modifiers, and a couple of indentation slips from the reformat.
| @Override | ||
| @RequiredReadAction |
There was a problem hiding this comment.
This accepts only calls Class.isInstance, so it never touches PSI and doesn't need @RequiredReadAction. Meanwhile the conditions that do read PSI (psiNewExpression, psiLiteral, literalExpression) have no annotation. I'd drop it here (and in psiModifierListOwner below) and add it where it actually applies.
| @Override | |
| @RequiredReadAction | |
| @Override |
| @Override | ||
| @RequiredReadAction |
There was a problem hiding this comment.
Same here: a plain instanceof check doesn't need a read action.
| @Override | |
| @RequiredReadAction | |
| @Override |
|
|
||
| public static PsiJavaElementPattern.Capture<PsiNewExpression> psiNewExpression(final String... fqns) { | ||
| return new PsiJavaElementPattern.Capture<>(new InitialPatternCondition<>(PsiNewExpression.class) { | ||
| @Override |
There was a problem hiding this comment.
This is the condition that needs @RequiredReadAction: getClassOrAnonymousClassReference() and getQualifiedName() both walk or resolve PSI. The same goes for PsiLiteral.getValue() in psiLiteral (L86) and literalExpression (L119).
| @Override | |
| @Override | |
| @RequiredReadAction |
| } | ||
|
|
||
| @SafeVarargs | ||
| public static PsiJavaElementPattern.Capture<PsiElement> psiJavaElement(final Class<? extends PsiElement>... classAlternatives) { |
There was a problem hiding this comment.
Nit: the reformat removed final from the other parameters (for example psiJavaElement(Class<T> aClass)), but it's still here and on L84, L98 and L117. Effectively-final is enough for capture in the anonymous classes.
| public static PsiJavaElementPattern.Capture<PsiElement> psiJavaElement(final Class<? extends PsiElement>... classAlternatives) { | |
| public static PsiJavaElementPattern.Capture<PsiElement> psiJavaElement(Class<? extends PsiElement>... classAlternatives) { |
| return psiLiteral(null); | ||
| } | ||
|
|
||
| public static PsiJavaElementPattern.Capture<PsiLiteral> psiLiteral(@Nullable final ElementPattern value) { |
There was a problem hiding this comment.
| public static PsiJavaElementPattern.Capture<PsiLiteral> psiLiteral(@Nullable final ElementPattern value) { | |
| public static PsiJavaElementPattern.Capture<PsiLiteral> psiLiteral(@Nullable ElementPattern value) { |
| .accepts(myPosition)) { | ||
| PsiMethod method = PsiTreeUtil.getParentOfType(myPosition, PsiMethod.class, false, PsiClass.class); | ||
| assert method != null; | ||
| final boolean hasParams = superConstructorHasParameters(method); |
There was a problem hiding this comment.
Nit: this final is a leftover; the PR drops final elsewhere, and effectively-final is enough for the anonymous ParenthesesInsertHandler.
| final boolean hasParams = superConstructorHasParameters(method); | |
| boolean hasParams = superConstructorHasParameters(method); |
| || isStatementPosition(position); | ||
| } | ||
|
|
||
| private boolean isLambdaParameterType() { |
There was a problem hiding this comment.
@RequiredReadAction was added to almost every PSI-touching method in this file, but a few were missed: isLambdaParameterType, getFileForDeclaration (L741), expectsClassLiteral (L993), isForLoopMachinery (L1098) and superConstructorHasParameters (L1146). Some of them are called from annotated methods, so the read-action inspection may flag the gaps.
| private boolean isLambdaParameterType() { | |
| @RequiredReadAction | |
| private boolean isLambdaParameterType() { |
| if (expressionPosition && !session.isKeywordAlreadyProcessed(PsiKeyword.VOID)) { | ||
| result.accept(BasicExpressionCompletionContributor.createKeywordLookupItem(position, PsiKeyword.VOID)); | ||
| } | ||
| private static boolean expectsClassLiteral(PsiElement position) { |
There was a problem hiding this comment.
| private static boolean expectsClassLiteral(PsiElement position) { | |
| @RequiredReadAction | |
| private static boolean expectsClassLiteral(PsiElement position) { |
| if (isEndOfBlock(position) && | ||
| PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class) != null) { | ||
| return !isForLoopMachinery(position); | ||
| private static boolean isForLoopMachinery(PsiElement position) { |
There was a problem hiding this comment.
| private static boolean isForLoopMachinery(PsiElement position) { | |
| @RequiredReadAction | |
| private static boolean isForLoopMachinery(PsiElement position) { |
| if (psiClass == null) { | ||
| return false; | ||
| } | ||
| private static boolean superConstructorHasParameters(PsiMethod method) { |
There was a problem hiding this comment.
| private static boolean superConstructorHasParameters(PsiMethod method) { | |
| @RequiredReadAction | |
| private static boolean superConstructorHasParameters(PsiMethod method) { |
No description provided.