mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
skip fields with initializer when generate constructor parameters; also skip static fields without initializer (IDEA-76621)
This commit is contained in:
@@ -381,7 +381,9 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
String message = JavaErrorMessages.message("private.field.is.not.used", identifier.getText());
|
||||
|
||||
HighlightInfo highlightInfo = suggestionsToMakeFieldUsed(field, identifier, message);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, HighlightMethodUtil.getFixRange(field), new CreateConstructorParameterFromFieldFix(field), null);
|
||||
if (!field.hasInitializer()) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, HighlightMethodUtil.getFixRange(field), new CreateConstructorParameterFromFieldFix(field), null);
|
||||
}
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
|
||||
+9
-6
@@ -77,16 +77,17 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
final PsiField field = getField();
|
||||
return isAvailable(getField());
|
||||
}
|
||||
|
||||
private static boolean isAvailable(PsiField field) {
|
||||
PsiClass containingClass = field == null ? null : field.getContainingClass();
|
||||
return
|
||||
field != null
|
||||
return field != null
|
||||
&& field.getManager().isInProject(field)
|
||||
&& !field.hasModifierProperty(PsiModifier.STATIC)
|
||||
&& containingClass != null
|
||||
&& !(containingClass instanceof JspClass)
|
||||
&& containingClass.getName() != null
|
||||
;
|
||||
&& containingClass.getName() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,7 +147,7 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
final List<PsiField> fields = new ArrayList<PsiField>();
|
||||
for (SmartPsiElementPointer<PsiField> elementPointer : fieldsToFix) {
|
||||
final PsiField field = elementPointer.getElement();
|
||||
if (field != null && filterConstructorsIfFieldAlreadyAssigned(new PsiMethod[]{constructor}, field).contains(constructor)) {
|
||||
if (field != null && isAvailable(field) && filterConstructorsIfFieldAlreadyAssigned(new PsiMethod[]{constructor}, field).contains(constructor)) {
|
||||
fields.add(field);
|
||||
}
|
||||
}
|
||||
@@ -165,6 +166,8 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
return new AbstractCollection<SmartPsiElementPointer<PsiField>>() {
|
||||
@Override
|
||||
public boolean add(SmartPsiElementPointer<PsiField> psiVariable) {
|
||||
PsiField field = psiVariable.getElement();
|
||||
if (field == null || !isAvailable(field)) return false;
|
||||
return finalFields.put(psiVariable, Boolean.TRUE) == null;
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Add constructor parameter" "true"
|
||||
public class ConstructorParams {
|
||||
private final String myText;
|
||||
private final static Object ourO;
|
||||
|
||||
public ConstructorParams(String myText) {
|
||||
this.myText = myText;<caret>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Add constructor parameter" "true"
|
||||
public class ConstructorParams {
|
||||
private final String myText;
|
||||
private final Object ourO = null;
|
||||
|
||||
public ConstructorParams(String myText) {
|
||||
this.myText = myText;<caret>
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add constructor parameter" "true"
|
||||
public class ConstructorParams {
|
||||
private final String my<caret>Text;
|
||||
private final static Object ourO;
|
||||
|
||||
public ConstructorParams() {
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add constructor parameter" "true"
|
||||
public class ConstructorParams {
|
||||
private final String my<caret>Text;
|
||||
private final Object ourO = null;
|
||||
|
||||
public ConstructorParams() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user