mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-383698 [java]: shorten generated fully-qualified name
GitOrigin-RevId: 6ec8829ee9a1b1b156cf1d04b6661080e1a1eb75
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e188ac9e23
commit
f335e07320
@@ -5,6 +5,7 @@ import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -68,11 +69,10 @@ public class ConvertToVarargsMethodFix extends PsiUpdateModCommandQuickFix {
|
||||
|
||||
private static void makeMethodVarargs(PsiMethod method) {
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.isEmpty()) {
|
||||
final PsiParameter lastParameter = parameterList.getParameter(parameterList.getParametersCount() - 1);
|
||||
if (lastParameter == null) {
|
||||
return;
|
||||
}
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
final PsiParameter lastParameter = parameters[parameters.length - 1];
|
||||
lastParameter.normalizeDeclaration();
|
||||
final PsiType type = lastParameter.getType();
|
||||
if (!(type instanceof PsiArrayType arrayType)) {
|
||||
@@ -85,16 +85,15 @@ public class ConvertToVarargsMethodFix extends PsiUpdateModCommandQuickFix {
|
||||
final PsiTypeElement typeElement = lastParameter.getTypeElement();
|
||||
if (typeElement != null) {
|
||||
CommentTracker ct = new CommentTracker();
|
||||
ct.grabComments(typeElement);
|
||||
PsiElement result = typeElement.replace(newTypeElement);
|
||||
PsiElement result = ct.replace(typeElement, newTypeElement);
|
||||
ct.insertCommentsBefore(result.getLastChild()); // Swap comments, example: String /* Foo */ [] -> String/* Foo */...
|
||||
JavaCodeStyleManager.getInstance(method.getProject()).shortenClassReferences(result);
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeMethodCallsVarargs(Collection<PsiReferenceExpression> referenceExpressions) {
|
||||
for (PsiReferenceExpression referenceExpression : referenceExpressions) {
|
||||
final PsiElement parent = referenceExpression.getParent();
|
||||
if (!(parent instanceof PsiMethodCallExpression methodCallExpression)) {
|
||||
if (!(referenceExpression.getParent() instanceof PsiMethodCallExpression methodCallExpression)) {
|
||||
continue;
|
||||
}
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
|
||||
@@ -111,7 +111,8 @@ public final class VarargParameterInspection extends BaseInspection {
|
||||
}
|
||||
PsiTypeElement typeElement = lastParameter.getTypeElement();
|
||||
assert typeElement != null;
|
||||
new CommentTracker().replaceAndRestoreComments(typeElement, newTypeElement);
|
||||
PsiElement result = new CommentTracker().replaceAndRestoreComments(typeElement, newTypeElement);
|
||||
JavaCodeStyleManager.getInstance(method.getProject()).shortenClassReferences(result);
|
||||
}
|
||||
|
||||
private static void modifyJavadoc(int indexOfFirstVarargArgument, @NotNull PsiElement reference) {
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class FieldSet<T> {
|
||||
public FieldSet<T> set(T[] fields) {
|
||||
public FieldSet<T> set(T @NotNull [] fields) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class FieldSet<T> {
|
||||
public FieldSet<T> set(<caret>T... fields) {
|
||||
public FieldSet<T> set(<caret>T @NotNull ... fields) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class Test {
|
||||
public void foo(final String... arg) {
|
||||
public void foo(final String @NotNull ... arg) {
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class Test {
|
||||
public void foo(final String[] a<caret>rg) {
|
||||
public void foo(final String @NotNull [] a<caret>rg) {
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -11,6 +11,13 @@ public class VarargParameterFixTest extends IGQuickFixesTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new VarargParameterInspection());
|
||||
myFixture.addClass("""
|
||||
package org.jetbrains.annotations;
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE})
|
||||
public @interface NotNull {}
|
||||
""");
|
||||
myRelativePath = "jdk/vararg_parameter";
|
||||
myDefaultHint = InspectionGadgetsBundle.message("variable.argument.method.quickfix");
|
||||
}
|
||||
|
||||
+7
@@ -20,6 +20,13 @@ public class ConvertToVarargsMethodFixTest extends IGQuickFixesTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new MethodCanBeVariableArityMethodInspection());
|
||||
myFixture.addClass("""
|
||||
package org.jetbrains.annotations;
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE})
|
||||
public @interface NotNull {}
|
||||
""");
|
||||
myRelativePath = "migration/convert_to_varargs_method";
|
||||
myDefaultHint = InspectionGadgetsBundle.message("convert.to.variable.arity.method.quickfix");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user