[lombok] Fixed inspection text and added test

GitOrigin-RevId: 5a2240bf9b95f9b01f19f9aeb3feef2a46ae9fad
This commit is contained in:
Michail Plushnikov
2023-11-12 17:19:04 +01:00
committed by intellij-monorepo-bot
parent 4809a581fa
commit 0c40fa211a
7 changed files with 99 additions and 15 deletions

View File

@@ -37,20 +37,15 @@ public class DeprecatedLombokAnnotationInspection extends LombokJavaInspectionBa
checkFor("lombok.experimental.Wither", LombokClassNames.WITH, annotation); checkFor("lombok.experimental.Wither", LombokClassNames.WITH, annotation);
} }
private void checkFor(String deprecatedAnnotationFQN, String newAnnotationFQN, PsiAnnotation psiAnnotation) { private void checkFor(String deprecatedFQN, String newFQN, PsiAnnotation psiAnnotation) {
if (psiAnnotation.hasQualifiedName(deprecatedAnnotationFQN)) { if (psiAnnotation.hasQualifiedName(deprecatedFQN)) {
final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(psiAnnotation, PsiModifierListOwner.class, false); final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(psiAnnotation, PsiModifierListOwner.class, false);
if (null != listOwner) { if (null != listOwner) {
String message = LombokBundle.message("inspection.message.lombok.annotation.deprecated.not.supported", deprecatedFQN, newFQN);
holder.registerProblem(psiAnnotation, holder.registerProblem(psiAnnotation, message, ProblemHighlightType.ERROR,
LombokBundle new AddAnnotationFix(newFQN, listOwner,
.message("inspection.message.lombok.annotation.deprecated.not.supported", deprecatedAnnotationFQN,
newAnnotationFQN),
ProblemHighlightType.ERROR,
new AddAnnotationFix(newAnnotationFQN,
listOwner,
psiAnnotation.getParameterList().getAttributes(), psiAnnotation.getParameterList().getAttributes(),
deprecatedAnnotationFQN)); deprecatedFQN));
} }
} }
} }

View File

@@ -0,0 +1,9 @@
import lombok.Synchronized;
public class X {
@Synchronized
public void doSomething() {
// do something
}
}

View File

@@ -0,0 +1,6 @@
public class X {
public <spot>synchronized</spot> void doSomething() {
// do something
}
}

View File

@@ -0,0 +1,6 @@
<html>
<body>
Reports usage of java <code>synchronized</code> modifiers, that can be converted to Lombok's <code>@Synchronized</code> annotation
<p>See for more <a href="https://projectlombok.org/features/Synchronized">details</a></p>
</body>
</html>

View File

@@ -13,7 +13,7 @@ replace.explicit.type.with.0.lombok=Replace explicit type with ''{0}'' (Lombok)
dialog.message.logger.field.s.not.private.sfinal.field.named.s.refactor.anyway=Logger field: "{0}" Is not private {1, choice, 0#|1#static }final field named "{2}". Refactor anyway? dialog.message.logger.field.s.not.private.sfinal.field.named.s.refactor.anyway=Logger field: "{0}" Is not private {1, choice, 0#|1#static }final field named "{2}". Refactor anyway?
dialog.title.attention=Attention! dialog.title.attention=Attention!
dialog.message.this.element.cannot.be.renamed=This element cannot be renamed. dialog.message.this.element.cannot.be.renamed=This element cannot be renamed.
inspection.message.lombok.annotation.deprecated.not.supported=Lombok's annotation ''{0}'' is deprecated and not supported by lombok-plugin anymore. Use ''{1}'' instead. inspection.message.lombok.annotation.deprecated.not.supported=Lombok''s annotation ''{0}'' is deprecated and not supported by lombok-plugin anymore. Use ''{1}'' instead.
inspection.message.default.constructor.doesn.t.exist=Default constructor doesn't exist inspection.message.default.constructor.doesn.t.exist=Default constructor doesn't exist
inspection.message.slf4j.logger.defined.explicitly=Slf4j Logger is defined explicitly. Use Lombok @Slf4j annotation instead. inspection.message.slf4j.logger.defined.explicitly=Slf4j Logger is defined explicitly. Use Lombok @Slf4j annotation instead.
intention.name.replace.with.lombok=Replace with Lombok intention.name.replace.with.lombok=Replace with Lombok
@@ -104,8 +104,8 @@ inspection.message.s.can.be.used.on.classes.only=''@{0}'' can be used on classes
inspection.message.syntax.either.obtain.via.field=The syntax is either @ObtainVia(field = "fieldName") or @ObtainVia(method = "methodName"). inspection.message.syntax.either.obtain.via.field=The syntax is either @ObtainVia(field = "fieldName") or @ObtainVia(method = "methodName").
inspection.message.lombok.annotations.are.not.allowed.on.builder.class=Lombok's annotations are not allowed on builder class. inspection.message.lombok.annotations.are.not.allowed.on.builder.class=Lombok's annotations are not allowed on builder class.
inspection.message.s.not.valid.identifier=''{0}'' is not a valid identifier inspection.message.s.not.valid.identifier=''{0}'' is not a valid identifier
inspection.message.can.t.singularize.this.name=Can't singularize this name: ''{0}''; please specify the singular explicitly (i.e. @Singular("sheep")) inspection.message.can.t.singularize.this.name=Can''t singularize this name: ''{0}''; please specify the singular explicitly (i.e. @Singular("sheep"))
inspection.message.lombok.does.not.know=Lombok does not know how to create the singular-form builder methods for type ''{0}''; they won't be generated. inspection.message.lombok.does.not.know=Lombok does not know how to create the singular-form builder methods for type ''{0}''; they won''t be generated.
inspection.message.builder.default.requires.initializing.expression=@Builder.Default requires an initializing expression (' = something;'). inspection.message.builder.default.requires.initializing.expression=@Builder.Default requires an initializing expression (' = something;').
inspection.message.builder.default.singular.cannot.be.mixed=@Builder.Default and @Singular cannot be mixed. inspection.message.builder.default.singular.cannot.be.mixed=@Builder.Default and @Singular cannot be mixed.
inspection.message.obtain.via.is.static.true.not.valid.unless.method.has.been.set=@ObtainVia(isStatic = true) is not valid unless 'method' has been set. inspection.message.obtain.via.is.static.true.not.valid.unless.method.has.been.set=@ObtainVia(isStatic = true) is not valid unless 'method' has been set.

View File

@@ -0,0 +1,68 @@
package de.plushnikov.intellij.plugin.inspection;
import com.intellij.codeInspection.InspectionProfileEntry;
import org.intellij.lang.annotations.Language;
public class DeprecatedLombokAnnotationInspectionTest extends LombokInspectionTest {
@Override
protected InspectionProfileEntry getInspection() {
return new DeprecatedLombokAnnotationInspection();
}
private void addOldClassDefinition(String className) {
final @Language("JAVA") String template = """
package lombok.experimental;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface {className} {
String value() default "";
}""";
myFixture.addClass(template.replace("{className}", className));
}
public void testDeprecatedBuilder() {
final @Language("JAVA") String testClassText = """
<error descr="Lombok's annotation 'lombok.experimental.Builder' is deprecated and not supported by lombok-plugin anymore. Use 'lombok.Builder' instead.">@lombok.experimental.Builder</error>
public class DeprecationTest {
private String someStr;
}""";
addOldClassDefinition("Builder");
myFixture.configureByText("DeprecationTest.java", testClassText);
myFixture.checkHighlighting();
}
public void testDeprecatedValue() {
final @Language("JAVA") String testClassText = """
<error descr="Lombok's annotation 'lombok.experimental.Value' is deprecated and not supported by lombok-plugin anymore. Use 'lombok.Value' instead.">@lombok.experimental.Value</error>
public class DeprecationTest {
private String someStr;
}""";
addOldClassDefinition("Value");
myFixture.configureByText("DeprecationTest.java", testClassText);
myFixture.checkHighlighting();
}
public void testDeprecatedWither() {
final @Language("JAVA") String testClassText = """
<error descr="Lombok's annotation 'lombok.experimental.Wither' is deprecated and not supported by lombok-plugin anymore. Use 'lombok.With' instead.">@lombok.experimental.Wither</error>
public class DeprecationTest {
private String someStr;
}""";
addOldClassDefinition("Wither");
myFixture.configureByText("DeprecationTest.java", testClassText);
myFixture.checkHighlighting();
}
}

View File

@@ -1,5 +1,5 @@
//skip compare content //skip compare content
<error descr="Lombok does not know how to create the singular-form builder methods for type 'java.lang.String[]'; they wont be generated.">@lombok.Builder</error> <error descr="Lombok does not know how to create the singular-form builder methods for type 'java.lang.String[]'; they won't be generated.">@lombok.Builder</error>
@lombok.ToString @lombok.ToString
public class BuilderSingularInvalidOnArray { public class BuilderSingularInvalidOnArray {
private String foo; private String foo;