mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-261935 - check whether every ctor param has an associated field by name
GitOrigin-RevId: 8d225300a2752035b3f15d64ba932a8dd2308eae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c03a44af2a
commit
671b158a08
+8
-1
@@ -236,11 +236,18 @@ public class ConvertToRecordFix extends InspectionGadgetsFix {
|
||||
private RecordConstructorCandidate(@NotNull PsiMethod constructor, @NotNull Set<PsiField> instanceFields) {
|
||||
myConstructor = constructor;
|
||||
|
||||
if (constructor.getTypeParameters().length > 0) {
|
||||
if (myConstructor.getTypeParameters().length > 0) {
|
||||
myCanonical = false;
|
||||
return;
|
||||
}
|
||||
PsiParameter[] ctorParams = myConstructor.getParameterList().getParameters();
|
||||
Set<String> instanceFieldNames = instanceFields.stream().map(PsiField::getName).collect(Collectors.toSet());
|
||||
for (PsiParameter param : ctorParams) {
|
||||
if (!instanceFieldNames.contains(param.getName())) {
|
||||
myCanonical = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Map<String, PsiType> ctorParamsWithType = Arrays.stream(ctorParams)
|
||||
.collect(Collectors.toMap(param -> param.getName(), param -> param.getType(), (first, second) -> first));
|
||||
if (ctorParams.length != ctorParamsWithType.size()) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class RecordBuilder {
|
||||
String annotationsText = generateAnnotationsText(parameterName, fieldAccessors);
|
||||
recordComponentsJoiner.add(annotationsText + parameter.getType().getCanonicalText() + " " + parameterName);
|
||||
}
|
||||
myRecordText.append(recordComponentsJoiner.toString());
|
||||
myRecordText.append(recordComponentsJoiner);
|
||||
}
|
||||
myRecordText.append(")");
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Convert to a record" "false"
|
||||
class <caret>R {
|
||||
final int first;
|
||||
|
||||
R(int first, int second) {
|
||||
this.first = first;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
// "Convert to a record" "false"
|
||||
class <caret>R {
|
||||
int first = 1;
|
||||
final int second;
|
||||
|
||||
R(int second) {
|
||||
this.second = second;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user