diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-01-30 15:43:41 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-01-30 15:43:41 +0100 |
commit | a7bd812893ecb1fa603229d81c924823426ea973 (patch) | |
tree | 93ff3584b63d89752c7bf7bc4ed97e0ab567c5d1 /src/core/lombok/eclipse | |
parent | 7efbecfe49af452f117e6a16c969a4b2071e80cd (diff) | |
download | lombok-a7bd812893ecb1fa603229d81c924823426ea973.tar.gz lombok-a7bd812893ecb1fa603229d81c924823426ea973.tar.bz2 lombok-a7bd812893ecb1fa603229d81c924823426ea973.zip |
[i623] added eclipse code for generating @javax.annotation.Generated, and refactored java impl to reduce DRY violations. -f pretty now includes skipping generation of this annotation, and updated ALL the test cases.
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 42 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 3 |
2 files changed, 32 insertions, 13 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 87e35269..1b27fce5 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -48,6 +48,7 @@ import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; import lombok.core.debug.ProblemReporter; import lombok.core.handlers.HandlerUtil; +import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAST; import lombok.eclipse.EclipseNode; import lombok.experimental.Accessors; @@ -1213,8 +1214,9 @@ public class EclipseHandlerUtil { * Inserts a field into an existing type. The type must represent a {@code TypeDeclaration}. * The field carries the @{@link SuppressWarnings}("all") annotation. */ - public static EclipseNode injectFieldSuppressWarnings(EclipseNode type, FieldDeclaration field) { - field.annotations = createSuppressWarningsAll(field, field.annotations); + public static EclipseNode injectFieldAndMarkGenerated(EclipseNode type, FieldDeclaration field) { + field.annotations = addSuppressWarningsAll(field, field.annotations); + field.annotations = addGenerated(field, field.annotations); return injectField(type, field); } @@ -1259,7 +1261,8 @@ public class EclipseHandlerUtil { * Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}. */ public static EclipseNode injectMethod(EclipseNode type, AbstractMethodDeclaration method) { - method.annotations = createSuppressWarningsAll(method, method.annotations); + method.annotations = addSuppressWarningsAll(method, method.annotations); + method.annotations = addGenerated(method, method.annotations); TypeDeclaration parent = (TypeDeclaration) type.get(); if (parent.methods == null) { @@ -1301,9 +1304,10 @@ public class EclipseHandlerUtil { * @param type New type (class, interface, etc) to inject. */ public static EclipseNode injectType(final EclipseNode typeNode, final TypeDeclaration type) { - type.annotations = createSuppressWarningsAll(type, type.annotations); + type.annotations = addSuppressWarningsAll(type, type.annotations); + type.annotations = addGenerated(type, type.annotations); TypeDeclaration parent = (TypeDeclaration) typeNode.get(); - + if (parent.memberTypes == null) { parent.memberTypes = new TypeDeclaration[] { type }; } else { @@ -1317,8 +1321,20 @@ public class EclipseHandlerUtil { } private static final char[] ALL = "all".toCharArray(); + private static final char[] LOMBOK = "lombok".toCharArray(); + private static final char[][] JAVAX_ANNOTATION_GENERATED = Eclipse.fromQualifiedName("javax.annotation.Generated"); + + public static Annotation[] addSuppressWarningsAll(ASTNode source, Annotation[] originalAnnotationArray) { + return addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, new StringLiteral(ALL, 0, 0, 0)); + } - public static Annotation[] createSuppressWarningsAll(ASTNode source, Annotation[] originalAnnotationArray) { + public static Annotation[] addGenerated(ASTNode source, Annotation[] originalAnnotationArray) { + return addAnnotation(source, originalAnnotationArray, JAVAX_ANNOTATION_GENERATED, new StringLiteral(LOMBOK, 0, 0, 0)); + } + + private static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, Expression arg) { + char[] simpleName = annotationTypeFqn[annotationTypeFqn.length - 1]; + if (originalAnnotationArray != null) for (Annotation ann : originalAnnotationArray) { char[] lastToken = null; @@ -1329,20 +1345,24 @@ public class EclipseHandlerUtil { lastToken = ((SingleTypeReference) ann.type).token; } - if (lastToken != null && new String(lastToken).equals("SuppressWarnings")) return originalAnnotationArray; + if (lastToken != null && Arrays.equals(simpleName, lastToken)) return originalAnnotationArray; } int pS = source.sourceStart, pE = source.sourceEnd; long p = (long)pS << 32 | pE; - long[] poss = new long[3]; + long[] poss = new long[annotationTypeFqn.length]; Arrays.fill(poss, p); - QualifiedTypeReference suppressWarningsType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, poss); + QualifiedTypeReference suppressWarningsType = new QualifiedTypeReference(annotationTypeFqn, poss); setGeneratedBy(suppressWarningsType, source); SingleMemberAnnotation ann = new SingleMemberAnnotation(suppressWarningsType, pS); ann.declarationSourceEnd = pE; - ann.memberValue = new StringLiteral(ALL, pS, pE, 0); + if (arg != null) { + arg.sourceStart = pS; + arg.sourceEnd = pE; + ann.memberValue = arg; + setGeneratedBy(ann.memberValue, source); + } setGeneratedBy(ann, source); - setGeneratedBy(ann.memberValue, source); if (originalAnnotationArray == null) return new Annotation[] { ann }; Annotation[] newAnnotationArray = new Annotation[originalAnnotationArray.length + 1]; System.arraycopy(originalAnnotationArray, 0, newAnnotationArray, 0, originalAnnotationArray.length); diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index e1b02051..7e2ff513 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2015 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 @@ -561,7 +561,6 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH } NameReference oRef = new SingleNameReference(new char[] { 'o' }, p); setGeneratedBy(oRef, source); - other.annotations = createSuppressWarningsAll(source, null); other.initialization = makeCastExpression(oRef, targetType, source); statements.add(other); } |