mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-204102 [java]: use diamonds in initializer when replacing 'var' with explicit type
GitOrigin-RevId: fb9b55071bcfbc19fea0f56c3ec15dda52fd48ee
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f313bc1413
commit
f7dfd48eef
+10
-5
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInspection.RemoveRedundantTypeArgumentsUtil;
|
||||
import com.intellij.codeInspection.VariableTypeCanBeExplicitInspection;
|
||||
import com.intellij.java.analysis.JavaAnalysisBundle;
|
||||
import com.intellij.modcommand.ActionContext;
|
||||
@@ -9,6 +10,7 @@ import com.intellij.modcommand.Presentation;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandAction;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiLambdaExpression;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
@@ -30,17 +32,20 @@ public class ReplaceVarWithExplicitTypeFix extends PsiUpdateModCommandAction<Psi
|
||||
|
||||
@Override
|
||||
protected void invoke(@NotNull ActionContext context, @NotNull PsiTypeElement startElement, @NotNull ModPsiUpdater updater) {
|
||||
if (startElement.getParent() instanceof PsiParameter psiParameter &&
|
||||
psiParameter.getDeclarationScope() instanceof PsiLambdaExpression lambda) {
|
||||
if (startElement.getParent() instanceof PsiParameter p && p.getDeclarationScope() instanceof PsiLambdaExpression lambda) {
|
||||
for (PsiParameter parameter : lambda.getParameterList().getParameters()) {
|
||||
PsiTypeElement typeElement = parameter.getTypeElement();
|
||||
if (typeElement != null) {
|
||||
PsiTypesUtil.replaceWithExplicitType(typeElement);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
PsiTypesUtil.replaceWithExplicitType(startElement);
|
||||
else {
|
||||
PsiTypeElement result = PsiTypesUtil.replaceWithExplicitType(startElement);
|
||||
if (result != null && result.getParent() instanceof PsiLocalVariable var) {
|
||||
RemoveRedundantTypeArgumentsUtil.removeRedundantTypeArguments(var.getInitializer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace 'var' with explicit type" "true-preview"
|
||||
import java.util.*;
|
||||
|
||||
class X {
|
||||
|
||||
void x() {
|
||||
ArrayList<String> x = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace 'var' with explicit type" "true-preview"
|
||||
import java.util.*;
|
||||
|
||||
class X {
|
||||
|
||||
void x() {
|
||||
var<caret> x = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user