From 54dce4c83b57b78c75f471ec5978b87b2bbd464f Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 29 Jan 2019 00:43:46 +0100 Subject: [fixes #2024] FieldNameConstants was causing lots of problems in eclipse, especially with save actions. --- doc/changelog.markdown | 5 +-- .../eclipse/handlers/HandleFieldNameConstants.java | 40 ++++++++++++---------- .../lombok/eclipse/agent/EclipsePatcher.java | 6 ++-- .../lombok/eclipse/agent/PatchDiagnostics.java | 11 ++++-- .../lombok/launch/PatchFixesHider.java | 12 ++++--- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 5e1c8a82..5f950cf0 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -3,13 +3,14 @@ Lombok Changelog ### v1.18.5 "Edgy Guinea Pig" * FEATURE: Javadoc on fields will now also be copied to the Builders' setters. Thanks for the contribution, Emil Lundberg. [Issue #2008](https://github.com/rzwitserloot/lombok/issues/2008) -* BUGFIX: Since version 1.18.4, the delombok ant task didn't work and errored with a `NoClassDefFoundError`. [Issue #1932](https://github.com/rzwitserloot/lombok/issues/1932) -* BUGFIX: Combining both `@Setter` and `@Wither` on the same field, when that field also has javadoc with a `--setter--` section or an `@param` tag, resulted in a race condition where the first handler to get to the field would take that part of the javadoc. This is a step along the way to fixing [Issue #1033](https://github.com/rzwitserloot/lombok/issues/1033) * FEATURE: The `@FieldNameConstants` feature now allows you to write the inner type by hand and add whatever you like to it; lombok will add the constants to this class. See the updated [FieldNameConstants feature](https://projectlombok.org/features/experimental/FieldNameConstants) page. * FEATURE: There is now a `lombok.config` key to configure `@ToString`'s call super behavior; it's just like `@EqualsAndHashCode` which has had it for a while now. [Issue #1918](https://github.com/rzwitserloot/lombok/issues/1918) * ENHANCEMENT: The toString generation of enums now contains the name of the enum constant. [Issue #1916](https://github.com/rzwitserloot/lombok/issues/1916) * PLATFORM: Due to changes to switch statements in JDK12, lombok wasn't working with the JDK12 preview. [Issue #1888](https://github.com/rzwitserloot/lombok/issues/1888) * BUGFIX: Using `@Delegate` in combination `@NonNull` would give an error in jdk8. [Issue #1935](https://github.com/rzwitserloot/lombok/issues/1935) +* BUGFIX: Using the new `@FieldNameConstants` in eclipse would cause errors in the error log view, and error popups if save actions are turned on. [Issue #2024](https://github.com/rzwitserloot/lombok/issues/2024) +* BUGFIX: Since version 1.18.4, the delombok ant task didn't work and errored with a `NoClassDefFoundError`. [Issue #1932](https://github.com/rzwitserloot/lombok/issues/1932) +* BUGFIX: Combining both `@Setter` and `@Wither` on the same field, when that field also has javadoc with a `--setter--` section or an `@param` tag, resulted in a race condition where the first handler to get to the field would take that part of the javadoc. This is a step along the way to fixing [Issue #1033](https://github.com/rzwitserloot/lombok/issues/1033) ### v1.18.4 (October 30th, 2018) * PLATFORM: Support for Eclipse Photon. [Issue #1831](https://github.com/rzwitserloot/lombok/issues/1831) diff --git a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java index 9e81a068..1caccd59 100644 --- a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java +++ b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2018 The Project Lombok Authors. + * Copyright (C) 2014-2019 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,15 +27,7 @@ import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import java.util.ArrayList; import java.util.List; -import lombok.AccessLevel; -import lombok.ConfigurationKeys; -import lombok.core.AST.Kind; -import lombok.core.AnnotationValues; -import lombok.eclipse.Eclipse; -import lombok.eclipse.EclipseAnnotationHandler; -import lombok.eclipse.EclipseNode; -import lombok.experimental.FieldNameConstants; - +import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -51,6 +43,16 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.mangosdk.spi.ProviderFor; +import lombok.AccessLevel; +import lombok.ConfigurationKeys; +import lombok.core.AST.Kind; +import lombok.core.AnnotationValues; +import lombok.eclipse.Eclipse; +import lombok.eclipse.EclipseAnnotationHandler; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; +import lombok.experimental.FieldNameConstants; + @ProviderFor(EclipseAnnotationHandler.class) public class HandleFieldNameConstants extends EclipseAnnotationHandler { public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit) { @@ -88,7 +90,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler annotation, Annotation ast, EclipseNode annotationNode) { + @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.FIELD_NAME_CONSTANTS_FLAG_USAGE, "@FieldNameConstants"); EclipseNode node = annotationNode.up(); @@ -117,6 +119,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler fields, boolean asEnum, String innerTypeName) { if (fields.isEmpty()) return; + ASTVisitor generatedByVisitor = new SetGeneratedByVisitor(source); TypeDeclaration parent = (TypeDeclaration) typeNode.get(); EclipseNode fieldsType = findInnerClass(typeNode, innerTypeName); boolean genConstr = false, genClinit = false; @@ -125,11 +128,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandlerdo provide a useful message. */ public static boolean setSourceRangeCheck(Object astNode, int startPosition, int length) { + String nodeTxt; if (startPosition >= 0 && length < 0) { + if (astNode == null) nodeTxt = "(NULL NODE)"; + else nodeTxt = astNode.getClass() + ": " + astNode.toString(); throw new IllegalArgumentException("startPos = " + startPosition + " and length is " + length + ".\n" + - "This breaks the rule that lengths are not allowed to be negative. Affected Node:\n" + astNode); + "This breaks the rule that lengths are not allowed to be negative. Affected Node:\n" + nodeTxt); } if (startPosition < 0 && length != 0) { + if (astNode == null) nodeTxt = "(NULL NODE)"; + else nodeTxt = astNode.getClass() + ": " + astNode.toString(); throw new IllegalArgumentException("startPos = " + startPosition + " and length is " + length + ".\n" + - "This breaks the rule that length must be 0 if startPosition is negative. Affected Node:\n" + astNode); + "This breaks the rule that length must be 0 if startPosition is negative. Affected Node:\n" + nodeTxt); } return false; diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java index 5c409603..3741aba8 100755 --- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java +++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 The Project Lombok Authors. + * Copyright (C) 2010-2019 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,8 +31,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Stack; -import lombok.eclipse.EclipseAugments; - import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IAnnotatable; import org.eclipse.jdt.core.IAnnotation; @@ -64,6 +62,8 @@ import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner; import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; +import lombok.eclipse.EclipseAugments; + /** These contain a mix of the following: *
    *
  • 'dependency free' method wrappers that cross the shadowloader barrier. @@ -476,8 +476,10 @@ final class PatchFixesHider { return original == -1 ? start : original; } - public static int fixRetrieveIdentifierEndPosition(int original, int end) { - return original == -1 ? end : original; + public static int fixRetrieveIdentifierEndPosition(int original, int start, int end) { + if (original == -1) return end; + if (original < start) return end; + return original; } public static int fixRetrieveEllipsisStartPosition(int original, int end) { -- cgit