aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.xml6
-rw-r--r--buildScripts/website.ant.xml1
-rw-r--r--doc/changelog.markdown1
-rw-r--r--src/core/lombok/bytecode/FixedClassWriter.java42
-rw-r--r--src/core/lombok/core/TypeResolver.java1
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java47
-rw-r--r--src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java6
-rw-r--r--src/core/lombok/eclipse/handlers/HandleGetter.java12
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java6
-rw-r--r--src/core/lombok/eclipse/handlers/HandleToString.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java6
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java13
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java9
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java2
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java48
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java8
-rw-r--r--test/transform/resource/after-delombok/GetterDeprecated.java18
-rw-r--r--test/transform/resource/after-delombok/SetterDeprecated.java18
-rw-r--r--test/transform/resource/after-ecj/GetterDeprecated.java14
-rw-r--r--test/transform/resource/after-ecj/SetterDeprecated.java14
-rw-r--r--test/transform/resource/before/GetterDeprecated.java11
-rw-r--r--test/transform/resource/before/SetterDeprecated.java11
-rw-r--r--website/setup/android.html7
23 files changed, 264 insertions, 39 deletions
diff --git a/build.xml b/build.xml
index e9497c2c..d6134f14 100644
--- a/build.xml
+++ b/build.xml
@@ -391,6 +391,12 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
</tar>
</target>
+ <target name="javadoc" depends="compile, version" description="Builds javadoc into doc/api.">
+ <ant antfile="buildScripts/website.ant.xml" target="javadoc" inheritAll="false">
+ <property name="lombok.version" value="${lombok.version}" />
+ </ant>
+ </target>
+
<target name="maven" depends="version, dist, test" description="Build a maven artifact bundle.">
<ant antfile="buildScripts/website.ant.xml" target="javadoc" inheritAll="false">
<property name="lombok.version" value="${lombok.version}" />
diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml
index d9e2e8a1..f949efcf 100644
--- a/buildScripts/website.ant.xml
+++ b/buildScripts/website.ant.xml
@@ -303,6 +303,7 @@ such as converting the changelog into HTML, and creating javadoc.
]]></echo>
<javadoc sourcepath="src/core" defaultexcludes="yes" destdir="build/api" windowtitle="Lombok" Overview="${javadoc.overview.html}">
<classpath refid="build.path" />
+ <classpath location="build/lombok" />
<link href="http://download.oracle.com/javase/6/docs/api/" />
<link href="http://www.slf4j.org/api/" />
<link href="http://commons.apache.org/logging/apidocs/" />
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 5d32c204..d1743147 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -4,6 +4,7 @@ Lombok Changelog
### v0.10.9 (edge)
* FEATURE: The combination of `@Delegate` and `@Getter` or `@Data` will now delegate to the result of a generated getter. [Issue #328](http://code.google.com/p/projectlombok/issues/detail?id=328)
* BUGFIX: When `@Delegate` would generate a method with type parameters of the type `T extends package.Class`, a dot would be prepended to the type name. [Issue #341](http://code.google.com/p/projectlombok/issues/detail?id=341)
+* BUGFIX: @Getter and @Setter now generate deprecated methods for deprecated fields. Fixes [Issue #342](http://code.google.com/p/projectlombok/issues/detail?id=342)
* BUGFIX: Using `val` with a type like `Outer<TypeArgs>.Inner` now works. [Issue #343](http://code.google.com/p/projectlombok/issues/detail?id=343)
* BUGFIX: `@Getter(lazy=true)` where the variable type is a primitive and the initializing expression is of a different primitive type that would type coerce implicitly, i.e. ints can be assigned to longs without a cast, didn't work before. [Issue #345](http://code.google.com/p/projectlombok/issues/detail?id=345)
* BUGFIX: `val` is no longer legal inside basic for loops (the old kind, not the foreach kind). These variables should rarely be final, and in practice it wasn't possible to delombok this code properly. [Issue #346](http://code.google.com/p/projectlombok/issues/detail?id=346)
diff --git a/src/core/lombok/bytecode/FixedClassWriter.java b/src/core/lombok/bytecode/FixedClassWriter.java
index 42d8c4c1..528bc79d 100644
--- a/src/core/lombok/bytecode/FixedClassWriter.java
+++ b/src/core/lombok/bytecode/FixedClassWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Project Lombok Authors.
+ * Copyright (C) 2010-2012 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
@@ -21,6 +21,9 @@
*/
package lombok.bytecode;
+import java.io.InputStream;
+import java.util.Arrays;
+
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
@@ -36,6 +39,43 @@ class FixedClassWriter extends ClassWriter {
return super.getCommonSuperClass(type1, type2);
} catch (Exception e) {
return "java/lang/Object";
+ } catch (ClassFormatError e) {
+ ClassLoader cl = this.getClass().getClassLoader();
+ if (cl == null) cl = ClassLoader.getSystemClassLoader();
+ String message = debugCheckClassFormatErrorIssue(cl, type1) +
+ debugCheckClassFormatErrorIssue(cl, type2);
+ throw new ClassFormatError(message);
+ }
+ }
+
+
+ // This is debug-aiding code in an attempt to find the cause of issue:
+ // http://code.google.com/p/projectlombok/issues/detail?id=339
+ private static String debugCheckClassFormatErrorIssue(ClassLoader cl, String type) {
+ try {
+ Class.forName(type.replace('/', '.'), false, cl);
+ return String.format("Class.forName debug on %s: no issues\n", type);
+ } catch (ClassFormatError e) {
+ // expected
+ } catch (Throwable e) {
+ return String.format("Class.forName debug on %s: Exception: %s\n", type, e);
+ }
+
+ try {
+ InputStream in = cl.getResourceAsStream(type + ".class");
+ if (in == null) return String.format("Class.forName debug on %s: Can't find resource %s\n", type, type + ".class");
+ try {
+ int[] firstBytes = new int[4];
+ for (int i = 0; i < 4; i++) firstBytes[0] = in.read();
+ if (firstBytes[0] == -1) return String.format("Class.forName debug on %s: file size is 0\n", type);
+ if (firstBytes[3] == -1) return String.format("Class.forName debug on %s: Less than 4 bytes in class file\n", type);
+ if (!Arrays.equals(new int[] {0xCA, 0xFE, 0xBA, 0xBE}, firstBytes)) return String.format("Class.forName debug on %s: no CAFEBABE: %s\n", type, Arrays.toString(firstBytes));
+ return String.format("Class.forName debug on %s: No immediately obvious reason for failure found\n", type);
+ } finally {
+ in.close();
+ }
+ } catch (Throwable e) {
+ return String.format("Class.forName debug on %s: Can't read as stream: %s\n", type, e);
}
}
} \ No newline at end of file
diff --git a/src/core/lombok/core/TypeResolver.java b/src/core/lombok/core/TypeResolver.java
index e5c3fac8..27f0bfc1 100644
--- a/src/core/lombok/core/TypeResolver.java
+++ b/src/core/lombok/core/TypeResolver.java
@@ -48,6 +48,7 @@ public class TypeResolver {
Set<String> imports = new HashSet<String>();
if (packageString != null) imports.add(packageString + ".*");
imports.addAll(importStrings == null ? Collections.<String>emptySet() : importStrings);
+ imports.add("java.lang.*");
return imports;
}
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 3c2ab904..ff743601 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -246,6 +246,27 @@ public class EclipseHandlerUtil {
return node;
}
+ public static MarkerAnnotation generateDeprecatedAnnotation(ASTNode source) {
+ QualifiedTypeReference qtr = new QualifiedTypeReference(new char[][] {
+ {'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'D', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd'}}, poss(source, 3));
+ setGeneratedBy(qtr, source);
+ return new MarkerAnnotation(qtr, source.sourceStart);
+ }
+
+ public static boolean isFieldDeprecated(EclipseNode fieldNode) {
+ FieldDeclaration field = (FieldDeclaration) fieldNode.get();
+ if ((field.modifiers & ClassFileConstants.AccDeprecated) != 0) {
+ return true;
+ }
+ if (field.annotations == null) return false;
+ for (Annotation annotation : field.annotations) {
+ if (typeMatches(Deprecated.class, fieldNode, annotation.type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Checks if the given TypeReference node is likely to be a reference to the provided class.
*
@@ -1024,8 +1045,8 @@ public class EclipseHandlerUtil {
/**
* Wrapper for {@link #methodExists(String, EclipseNode, boolean)} with {@code caseSensitive} = {@code true}.
*/
- public static MemberExistsResult methodExists(String methodName, EclipseNode node) {
- return methodExists(methodName, node, true);
+ public static MemberExistsResult methodExists(String methodName, EclipseNode node, int params) {
+ return methodExists(methodName, node, true, params);
}
/**
@@ -1035,8 +1056,9 @@ public class EclipseHandlerUtil {
* @param methodName the method name to check for.
* @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
* @param caseSensitive If the search should be case sensitive.
+ * @param params The number of parameters the method should have; varargs count as 0-*. Set to -1 to find any method with the appropriate name regardless of parameter count.
*/
- public static MemberExistsResult methodExists(String methodName, EclipseNode node, boolean caseSensitive) {
+ public static MemberExistsResult methodExists(String methodName, EclipseNode node, boolean caseSensitive, int params) {
while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
@@ -1048,7 +1070,24 @@ public class EclipseHandlerUtil {
char[] mName = def.selector;
if (mName == null) continue;
boolean nameEquals = caseSensitive ? methodName.equals(new String(mName)) : methodName.equalsIgnoreCase(new String(mName));
- if (nameEquals) return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
+ if (nameEquals) {
+ if (params > -1) {
+ int minArgs = 0;
+ int maxArgs = 0;
+ if (def.arguments != null && def.arguments.length > 0) {
+ minArgs = def.arguments.length;
+ if ((def.arguments[def.arguments.length - 1].type.bits & ASTNode.IsVarArgs) != 0) {
+ minArgs--;
+ maxArgs = Integer.MAX_VALUE;
+ } else {
+ maxArgs = minArgs;
+ }
+ }
+
+ if (params < minArgs || params > maxArgs) continue;
+ }
+ return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
+ }
}
}
}
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index ef01835c..82a8f00e 100644
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -204,9 +204,9 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
boolean isFinal = (typeDecl.modifiers & ClassFileConstants.AccFinal) != 0;
boolean needsCanEqual = !isDirectDescendantOfObject || !isFinal;
java.util.List<MemberExistsResult> existsResults = new ArrayList<MemberExistsResult>();
- existsResults.add(methodExists("equals", typeNode));
- existsResults.add(methodExists("hashCode", typeNode));
- existsResults.add(methodExists("canEqual", typeNode));
+ existsResults.add(methodExists("equals", typeNode, 1));
+ existsResults.add(methodExists("hashCode", typeNode, 0));
+ existsResults.add(methodExists("canEqual", typeNode, 1));
switch (Collections.max(existsResults)) {
case EXISTS_BY_LOMBOK:
return;
diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java
index c631e583..d53bf89b 100644
--- a/src/core/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleGetter.java
@@ -198,7 +198,7 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
for (String altName : toAllGetterNames(fieldNode, isBoolean)) {
- switch (methodExists(altName, fieldNode, false)) {
+ switch (methodExists(altName, fieldNode, false, 0)) {
case EXISTS_BY_LOMBOK:
return;
case EXISTS_BY_USER:
@@ -216,14 +216,20 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
}
MethodDeclaration method = generateGetter((TypeDeclaration) fieldNode.up().get(), fieldNode, getterName, modifier, source, lazy);
- Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode));
+
+ Annotation[] deprecated = null;
+ if (isFieldDeprecated(fieldNode)) {
+ deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
+ }
+
+ Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode), deprecated);
if (copiedAnnotations.length != 0) {
method.annotations = copiedAnnotations;
}
injectMethod(fieldNode.up(), method);
}
-
+
private static Annotation[] findDelegatesAndMarkAsHandled(EclipseNode fieldNode) {
List<Annotation> delegates = new ArrayList<Annotation>();
for (EclipseNode child : fieldNode.down()) {
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 810096ab..3fa872f9 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -157,7 +157,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
for (String altName : toAllSetterNames(fieldNode, isBoolean)) {
- switch (methodExists(altName, fieldNode, false)) {
+ switch (methodExists(altName, fieldNode, false, 1)) {
case EXISTS_BY_LOMBOK:
return;
case EXISTS_BY_USER:
@@ -188,7 +188,9 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
method.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
setGeneratedBy(method.returnType, source);
- method.annotations = null;
+ if (isFieldDeprecated(fieldNode)) {
+ method.annotations = new Annotation[] { generateDeprecatedAnnotation(source) };
+ }
Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
param.sourceStart = pS; param.sourceEnd = pE;
setGeneratedBy(param, source);
diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java
index 07d88f5f..26f0e9be 100644
--- a/src/core/lombok/eclipse/handlers/HandleToString.java
+++ b/src/core/lombok/eclipse/handlers/HandleToString.java
@@ -159,7 +159,7 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> {
}
}
- switch (methodExists("toString", typeNode)) {
+ switch (methodExists("toString", typeNode, 0)) {
case NOT_EXISTS:
MethodDeclaration toString = createToString(typeNode, nodesForToString, includeFieldNames, callSuper, errorNode.get(), fieldAccess);
injectMethod(typeNode, toString);
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index 0a9d4cc2..00601b56 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -177,9 +177,9 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
boolean isFinal = (((JCClassDecl)typeNode.get()).mods.flags & Flags.FINAL) != 0;
boolean needsCanEqual = !isFinal || !isDirectDescendantOfObject;
java.util.List<MemberExistsResult> existsResults = new ArrayList<MemberExistsResult>();
- existsResults.add(methodExists("equals", typeNode));
- existsResults.add(methodExists("hashCode", typeNode));
- existsResults.add(methodExists("canEqual", typeNode));
+ existsResults.add(methodExists("equals", typeNode, 1));
+ existsResults.add(methodExists("hashCode", typeNode, 0));
+ existsResults.add(methodExists("canEqual", typeNode, 1));
switch (Collections.max(existsResults)) {
case EXISTS_BY_LOMBOK:
return;
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index e49b0ccb..dd0a99ad 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -74,11 +74,9 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
public void generateGetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelGetter) {
if (checkForTypeLevelGetter) {
if (typeNode != null) for (JavacNode child : typeNode.down()) {
- if (child.getKind() == Kind.ANNOTATION) {
- if (annotationTypeMatches(Getter.class, child)) {
- //The annotation will make it happen, so we can skip it.
- return;
- }
+ if (annotationTypeMatches(Getter.class, child)) {
+ //The annotation will make it happen, so we can skip it.
+ return;
}
}
}
@@ -198,7 +196,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
}
for (String altName : toAllGetterNames(fieldNode)) {
- switch (methodExists(altName, fieldNode, false)) {
+ switch (methodExists(altName, fieldNode, false, 0)) {
case EXISTS_BY_LOMBOK:
return;
case EXISTS_BY_USER:
@@ -249,6 +247,9 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
List<JCAnnotation> annsOnMethod = nonNulls.appendList(nullables);
+ if (isFieldDeprecated(field)) {
+ annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil()));
+ }
JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType,
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index 93ea5a5b..2a91fb37 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -170,7 +170,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
}
for (String altName : toAllSetterNames(fieldNode)) {
- switch (methodExists(altName, fieldNode, false)) {
+ switch (methodExists(altName, fieldNode, false, 1)) {
case EXISTS_BY_LOMBOK:
return;
case EXISTS_BY_USER:
@@ -217,6 +217,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
JCBlock methodBody = treeMaker.Block(0, statements);
Name methodName = field.toName(setterName);
List<JCAnnotation> annsOnParam = nonNulls.appendList(nullables);
+
JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
//WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
JCExpression methodType = treeMaker.Type(new JCNoType(getCtcInt(TypeTags.class, "VOID")));
@@ -226,7 +227,11 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
List<JCExpression> throwsClauses = List.nil();
JCExpression annotationMethodDefaultValue = null;
- return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, List.<JCAnnotation>nil()), methodName, methodType,
+ List<JCAnnotation> annsOnMethod = List.nil();
+ if (isFieldDeprecated(field)) {
+ annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil()));
+ }
+ return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType,
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
}
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index a5fb099b..016a7972 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -151,7 +151,7 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
}
}
- switch (methodExists("toString", typeNode)) {
+ switch (methodExists("toString", typeNode, 0)) {
case NOT_EXISTS:
JCMethodDecl method = createToString(typeNode, nodesForToString.toList(), includeFieldNames, callSuper, fieldAccess, source.get());
injectMethod(typeNode, method);
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index c8538296..92629a3c 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -144,6 +144,24 @@ public class JavacHandlerUtil {
}
/**
+ * Returns if a field is marked deprecated, either by {@code @Deprecated} or in javadoc
+ * @param field the field to check
+ * @return {@code true} if a field is marked deprecated, either by {@code @Deprecated} or in javadoc, otherwise {@code false}
+ */
+ public static boolean isFieldDeprecated(JavacNode field) {
+ JCVariableDecl fieldNode = (JCVariableDecl) field.get();
+ if ((fieldNode.mods.flags & Flags.DEPRECATED) != 0) {
+ return true;
+ }
+ for (JavacNode child : field.down()) {
+ if (annotationTypeMatches(Deprecated.class, child)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Creates an instance of {@code AnnotationValues} for the provided AST Node.
*
* @param type An annotation class type, such as {@code lombok.Getter.class}.
@@ -372,8 +390,8 @@ public class JavacHandlerUtil {
return MemberExistsResult.NOT_EXISTS;
}
- public static MemberExistsResult methodExists(String methodName, JavacNode node) {
- return methodExists(methodName, node, true);
+ public static MemberExistsResult methodExists(String methodName, JavacNode node, int params) {
+ return methodExists(methodName, node, true, params);
}
/**
@@ -383,8 +401,9 @@ public class JavacHandlerUtil {
* @param methodName the method name to check for.
* @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.
* @param caseSensitive If the search should be case sensitive.
+ * @param params The number of parameters the method should have; varargs count as 0-*. Set to -1 to find any method with the appropriate name regardless of parameter count.
*/
- public static MemberExistsResult methodExists(String methodName, JavacNode node, boolean caseSensitive) {
+ public static MemberExistsResult methodExists(String methodName, JavacNode node, boolean caseSensitive, int params) {
while (node != null && !(node.get() instanceof JCClassDecl)) {
node = node.up();
}
@@ -392,9 +411,28 @@ public class JavacHandlerUtil {
if (node != null && node.get() instanceof JCClassDecl) {
for (JCTree def : ((JCClassDecl)node.get()).defs) {
if (def instanceof JCMethodDecl) {
- String name = ((JCMethodDecl)def).name.toString();
+ JCMethodDecl md = (JCMethodDecl) def;
+ String name = md.name.toString();
boolean matches = caseSensitive ? name.equals(methodName) : name.equalsIgnoreCase(methodName);
- if (matches) return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
+ if (matches) {
+ if (params > -1) {
+ List<JCVariableDecl> ps = md.params;
+ int minArgs = 0;
+ int maxArgs = 0;
+ if (ps != null && ps.length() > 0) {
+ minArgs = ps.length();
+ if ((ps.last().mods.flags & Flags.VARARGS) != 0) {
+ maxArgs = Integer.MAX_VALUE;
+ minArgs--;
+ } else {
+ maxArgs = minArgs;
+ }
+ }
+
+ if (params < minArgs || params > maxArgs) continue;
+ }
+ return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
+ }
}
}
}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java
index acf1589d..7c73b465 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java
@@ -51,11 +51,9 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
-import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
@@ -613,11 +611,7 @@ public class PatchDelegate {
}
if (isDeprecated) {
- QualifiedTypeReference qtr = new QualifiedTypeReference(new char[][] {
- {'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'D', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd'}}, poss(source, 3));
- setGeneratedBy(qtr, source);
- MarkerAnnotation ann = new MarkerAnnotation(qtr, pS);
- method.annotations = new Annotation[] {ann};
+ method.annotations = new Annotation[] { generateDeprecatedAnnotation(source) };
}
method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
diff --git a/test/transform/resource/after-delombok/GetterDeprecated.java b/test/transform/resource/after-delombok/GetterDeprecated.java
new file mode 100644
index 00000000..3387540f
--- /dev/null
+++ b/test/transform/resource/after-delombok/GetterDeprecated.java
@@ -0,0 +1,18 @@
+class GetterDeprecated {
+ @Deprecated
+ int annotation;
+ /**
+ * @deprecated
+ */
+ int javadoc;
+ @java.lang.Deprecated
+ @java.lang.SuppressWarnings("all")
+ public int getAnnotation() {
+ return this.annotation;
+ }
+ @java.lang.Deprecated
+ @java.lang.SuppressWarnings("all")
+ public int getJavadoc() {
+ return this.javadoc;
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/SetterDeprecated.java b/test/transform/resource/after-delombok/SetterDeprecated.java
new file mode 100644
index 00000000..5a6cf9f3
--- /dev/null
+++ b/test/transform/resource/after-delombok/SetterDeprecated.java
@@ -0,0 +1,18 @@
+class SetterDeprecated {
+ @Deprecated
+ int annotation;
+ /**
+ * @deprecated
+ */
+ int javadoc;
+ @java.lang.Deprecated
+ @java.lang.SuppressWarnings("all")
+ public void setAnnotation(final int annotation) {
+ this.annotation = annotation;
+ }
+ @java.lang.Deprecated
+ @java.lang.SuppressWarnings("all")
+ public void setJavadoc(final int javadoc) {
+ this.javadoc = javadoc;
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/GetterDeprecated.java b/test/transform/resource/after-ecj/GetterDeprecated.java
new file mode 100644
index 00000000..c19198dd
--- /dev/null
+++ b/test/transform/resource/after-ecj/GetterDeprecated.java
@@ -0,0 +1,14 @@
+import lombok.Getter;
+class GetterDeprecated {
+ @Deprecated @Getter int annotation;
+ @Getter int javadoc;
+ public @java.lang.Deprecated @java.lang.SuppressWarnings("all") int getAnnotation() {
+ return this.annotation;
+ }
+ public @java.lang.Deprecated @java.lang.SuppressWarnings("all") int getJavadoc() {
+ return this.javadoc;
+ }
+ GetterDeprecated() {
+ super();
+ }
+}
diff --git a/test/transform/resource/after-ecj/SetterDeprecated.java b/test/transform/resource/after-ecj/SetterDeprecated.java
new file mode 100644
index 00000000..b12ae34d
--- /dev/null
+++ b/test/transform/resource/after-ecj/SetterDeprecated.java
@@ -0,0 +1,14 @@
+import lombok.Setter;
+class SetterDeprecated {
+ @Deprecated @Setter int annotation;
+ @Setter int javadoc;
+ public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void setAnnotation(final int annotation) {
+ this.annotation = annotation;
+ }
+ public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void setJavadoc(final int javadoc) {
+ this.javadoc = javadoc;
+ }
+ SetterDeprecated() {
+ super();
+ }
+}
diff --git a/test/transform/resource/before/GetterDeprecated.java b/test/transform/resource/before/GetterDeprecated.java
new file mode 100644
index 00000000..01b66bca
--- /dev/null
+++ b/test/transform/resource/before/GetterDeprecated.java
@@ -0,0 +1,11 @@
+import lombok.Getter;
+class GetterDeprecated {
+
+ @Deprecated
+ @Getter int annotation;
+
+ /**
+ * @deprecated
+ */
+ @Getter int javadoc;
+} \ No newline at end of file
diff --git a/test/transform/resource/before/SetterDeprecated.java b/test/transform/resource/before/SetterDeprecated.java
new file mode 100644
index 00000000..e655622f
--- /dev/null
+++ b/test/transform/resource/before/SetterDeprecated.java
@@ -0,0 +1,11 @@
+import lombok.Setter;
+class SetterDeprecated {
+
+ @Deprecated
+ @Setter int annotation;
+
+ /**
+ * @deprecated
+ */
+ @Setter int javadoc;
+} \ No newline at end of file
diff --git a/website/setup/android.html b/website/setup/android.html
index bbcc9c66..0eb5853e 100644
--- a/website/setup/android.html
+++ b/website/setup/android.html
@@ -55,7 +55,9 @@
In eclipse, create a 'lightweight' lombok jar that contains only the annotations by running:
<pre>
java -jar lombok.jar publicApi</pre>
- Then, add this jar to your android project, and, as usual, install lombok into eclipse.
+ Then, add the <code>lombok-api.jar</code> file created by running this command
+ to your android project instead of the complete <code>lombok.jar</code>, and,
+ as usual, install lombok into eclipse by double-clicking <code>lombok.jar</code>.
</div>
<h3>Ant</h3>
<div>
@@ -70,6 +72,9 @@ java -jar lombok.jar publicApi</pre>
<h3>Maven</h3>
<div>
You should be able to just follow the normal <a href="../mavenrepo/index.html">lombok with maven instructions</a>.<br />
+ Note that if you use android, eclipse, and maven together you may have to replace <code>lombok.jar</code> in your eclipse android project's build path
+ (which you can modify in that project's properties page) with <code>lombok-api.jar</code>, as produced in the procedure explained for <em>Eclipse</em>,
+ above.
</div>
<div class="endBar">
</div>