Skip to content

Commit

Permalink
Issue projectlombok#132: @XArgsConstructor don't show error when used…
Browse files Browse the repository at this point in the history
… on a subclass that requires non-empty super call
  • Loading branch information
Michail Plushnikov committed Nov 1, 2015
1 parent be9098c commit a3c4a62
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
Expand Down Expand Up @@ -57,6 +58,10 @@ protected boolean validate(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiCla
if (!validateVisibility(psiAnnotation)) {
result = false;
}

if (!validateBaseClassConstructor(psiClass, builder)) {
result = false;
}
return result;
}

Expand All @@ -74,6 +79,29 @@ protected boolean validateAnnotationOnRightType(@NotNull PsiClass psiClass, @Not
return result;
}

protected boolean validateBaseClassConstructor(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) {
if (psiClass instanceof PsiAnonymousClass) {
return true;
}
PsiClass baseClass = psiClass.getSuperClass();
if (baseClass == null) {
return true;
}
PsiMethod[] constructors = baseClass.getConstructors();
if (constructors.length == 0) {
return true;
}

for (PsiMethod constructor : constructors) {
final int parametersCount = constructor.getParameterList().getParametersCount();
if (parametersCount == 0 || parametersCount == 1 && constructor.isVarArgs()) {
return true;
}
}
builder.addError("Lombok needs a default constructor in the base class");
return false;
}

public boolean validateIsConstructorDefined(@NotNull PsiClass psiClass, @Nullable String staticConstructorName, @NotNull Collection<PsiField> params, @NotNull ProblemBuilder builder) {
boolean result = true;

Expand Down
1 change: 1 addition & 0 deletions lombok-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<ul>
<li>0.9.7
<ol>
<li>Fixed #130: @XArgsConstructor don't show error when used on a subclass that requires non-empty super call</li>
<li>Fixed #132: Make @EqualsAndHashCode(callSuper = true) default</li>
<li>Fixed #135: Added support for @NoArgsConstructor(force = true)</li>
<li>Fixed #149: Idea cannot generate another constructor when @NoArgsConstructor is used</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
daemon.donate.title=Lombok support plugin updated to v{0}
daemon.donate.content=\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/135">#132</a>): Make quickfix suggestion for @EqualsAndHashCode(callSuper = true) default<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/130">#130</a>): @XArgsConstructor don't show error when used on a subclass that requires non-empty super call<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/132">#132</a>): Make quickfix suggestion for @EqualsAndHashCode(callSuper = true) default<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/135">#135</a>): Feature request: support for @NoArgsConstructor(force = true)<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/135">#149</a>): Idea cannot generate another constructor when @NoArgsConstructor is used<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/149">#149</a>): Idea cannot generate another constructor when @NoArgsConstructor is used<br/>\
<br/>\
If you find my plugin helpful, donate me using <b>\
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\\&hosted_button_id=3F9HXD7A2SMCN">PayPal</a></b>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.plushnikov.constructor;

import lombok.AllArgsConstructor;

public class TestIssue130 {
@AllArgsConstructor
public static class Parent {
private String name;
}

// @AllArgsConstructor
public static class Subclass extends Parent {
private String value;

public Subclass(String name, String value) {
super(name);
}
}

public static void main(String[] args) {
Subclass subclass = new Subclass("name", "value");
}
}

0 comments on commit a3c4a62

Please sign in to comment.