mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
StreamToLoopInspection: minor cleanup
This commit is contained in:
@@ -111,7 +111,7 @@ abstract class FunctionHelper {
|
||||
|
||||
/**
|
||||
* Renames references to the variable oldName in given expression into newName
|
||||
* @param expression
|
||||
* @param expression an expression to search-and-replace references inside
|
||||
* @param oldName old name
|
||||
* @param newName new name
|
||||
* @param context context
|
||||
|
||||
+1
-2
@@ -106,7 +106,7 @@ public class StreamToLoopInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
cur = parent;
|
||||
parent = cur.getParent();
|
||||
}
|
||||
if(parent instanceof PsiExportsStatement || parent instanceof PsiReturnStatement || parent instanceof PsiExpressionStatement) return true;
|
||||
if(parent instanceof PsiReturnStatement || parent instanceof PsiExpressionStatement) return true;
|
||||
if(parent instanceof PsiLocalVariable) {
|
||||
PsiElement grandParent = parent.getParent();
|
||||
if(grandParent instanceof PsiDeclarationStatement && ((PsiDeclarationStatement)grandParent).getDeclaredElements().length == 1) {
|
||||
@@ -362,7 +362,6 @@ public class StreamToLoopInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
}
|
||||
|
||||
public String registerVarName(Collection<String> variants) {
|
||||
// TODO: avoid introducing conflicts with nested scopes (variables declared in lambdas, nested lambdas)
|
||||
if(variants.isEmpty()) {
|
||||
return registerVarName(Collections.singleton("val"));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.streamToLoop;
|
||||
|
||||
import com.intellij.codeInspection.streamToLoop.StreamToLoopInspection.StreamToLoopReplacementContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -51,7 +52,7 @@ class StreamVariable {
|
||||
}
|
||||
|
||||
@Override
|
||||
void register(StreamToLoopInspection.StreamToLoopReplacementContext context) {
|
||||
void register(StreamToLoopReplacementContext context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,12 +105,12 @@ class StreamVariable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register variable within {@link com.intellij.codeInspection.streamToLoop.StreamToLoopInspection.StreamToLoopReplacementContext}.
|
||||
* Register variable within {@link StreamToLoopReplacementContext}.
|
||||
* Must be called once after all name candidates are registered. Now variable gets an actual name.
|
||||
*
|
||||
* @param context context to use
|
||||
*/
|
||||
void register(StreamToLoopInspection.StreamToLoopReplacementContext context) {
|
||||
void register(StreamToLoopReplacementContext context) {
|
||||
LOG.assertTrue(myName == null);
|
||||
List<String> variants = StreamEx.of(myBestCandidates).append(myOtherCandidates).distinct().toList();
|
||||
if (variants.isEmpty()) variants.add("val");
|
||||
|
||||
Reference in New Issue
Block a user