mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 14:17:48 +00:00
[fixes #2024] FieldNameConstants was causing lots of problems in eclipse, especially with save actions.
This commit is contained in:
1 parent
2a8225a6af
commit
54dce4c83b
5 files changed
+43
-31
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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<FieldNameConstants> {
|
||||
public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit) {
|
||||
@@ -88,7 +90,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
|
||||
return filterField(fieldDecl);
|
||||
}
|
||||
|
||||
public void handle(AnnotationValues<FieldNameConstants> annotation, Annotation ast, EclipseNode annotationNode) {
|
||||
@Override public void handle(AnnotationValues<FieldNameConstants> 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<FieldName
|
||||
private void createInnerTypeFieldNameConstants(EclipseNode typeNode, EclipseNode errorNode, ASTNode source, AccessLevel level, List<EclipseNode> 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 EclipseAnnotationHandler<FieldName
|
||||
if (fieldsType == null) {
|
||||
generatedInnerType = new TypeDeclaration(parent.compilationResult);
|
||||
generatedInnerType.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
generatedInnerType.modifiers = toEclipseModifier(level) | (asEnum ? ClassFileConstants.AccEnum : ClassFileConstants.AccStatic | ClassFileConstants.AccFinal);
|
||||
generatedInnerType.modifiers = toEclipseModifier(level) | (asEnum ? ClassFileConstants.AccEnum : (ClassFileConstants.AccStatic | ClassFileConstants.AccFinal));
|
||||
generatedInnerType.name = name;
|
||||
fieldsType = injectType(typeNode, generatedInnerType);
|
||||
genConstr = true;
|
||||
genClinit = asEnum;
|
||||
generatedInnerType.traverse(generatedByVisitor, ((TypeDeclaration) typeNode.get()).scope);
|
||||
} else {
|
||||
TypeDeclaration builderTypeDeclaration = (TypeDeclaration) fieldsType.get();
|
||||
if (asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccEnum) == 0) {
|
||||
@@ -146,8 +150,6 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
|
||||
if (genConstr) {
|
||||
ConstructorDeclaration constructor = new ConstructorDeclaration(parent.compilationResult);
|
||||
constructor.selector = name;
|
||||
constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
|
||||
constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
|
||||
constructor.modifiers = ClassFileConstants.AccPrivate;
|
||||
ExplicitConstructorCall superCall = new ExplicitConstructorCall(0);
|
||||
superCall.sourceStart = source.sourceStart;
|
||||
@@ -157,11 +159,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
|
||||
if (!asEnum) constructor.statements = new Statement[0];
|
||||
injectMethod(fieldsType, constructor);
|
||||
}
|
||||
|
||||
if (genClinit) {
|
||||
Clinit cli = new Clinit(parent.compilationResult);
|
||||
injectMethod(fieldsType, cli);
|
||||
cli.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).scope);
|
||||
}
|
||||
|
||||
|
||||
for (EclipseNode fieldNode : fields) {
|
||||
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
|
||||
@@ -171,19 +174,20 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
|
||||
long p = (long) pS << 32 | pE;
|
||||
FieldDeclaration constantField = new FieldDeclaration(fName, pS, pE);
|
||||
constantField.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
constantField.modifiers = asEnum ? 0 : ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal;
|
||||
constantField.type = asEnum ? null : new QualifiedTypeReference(TypeConstants.JAVA_LANG_STRING, new long[] {p, p, p});
|
||||
if (asEnum) {
|
||||
AllocationExpression ac = new AllocationExpression();
|
||||
ac.enumConstant = constantField;
|
||||
ac.sourceStart = source.sourceStart;
|
||||
ac.sourceEnd = source.sourceEnd;
|
||||
constantField.initialization = ac;
|
||||
constantField.modifiers = 0;
|
||||
} else {
|
||||
constantField.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_STRING, new long[] {p, p, p});
|
||||
constantField.initialization = new StringLiteral(field.name, pS, pE, 0);
|
||||
constantField.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal;
|
||||
}
|
||||
constantField.traverse(new SetGeneratedByVisitor(source), null);
|
||||
injectField(fieldsType, constantField);
|
||||
constantField.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).initializerScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2015 The Project Lombok Authors.
|
||||
* Copyright (C) 2009-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
|
||||
@@ -392,8 +392,8 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
private static void patchIdentifierEndReparse(ScriptManager sm) {
|
||||
sm.addScript(ScriptBuilder.wrapReturnValue()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveIdentifierEndPosition"))
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveIdentifierEndPosition", "int", "int", "int"))
|
||||
.transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build());
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveIdentifierEndPosition", "int", "int", "int", "int"))
|
||||
.transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM1, StackRequest.PARAM2).build());
|
||||
}
|
||||
|
||||
private static void patchRetrieveEllipsisStartPosition(ScriptManager sm) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Project Lombok Authors.
|
||||
* Copyright (C) 2012-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
|
||||
@@ -29,14 +29,19 @@ public class PatchDiagnostics {
|
||||
* checks, and throw the exact same exception (thus, effectively, we don't change how eclipse operates), but, we <em>do</em> 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;
|
||||
|
||||
@@ -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:
|
||||
* <ul>
|
||||
* <li> '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) {
|
||||
|
||||
Reference in new issue
Block a user