From acea9efcff67c7a0bdb85175b84e75a9dad172b8 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 19 Jan 2012 00:33:18 +0100 Subject: @Delegate is no longer legal on static entities (previously no immediate errors but I don't think it would work right anyway), and prettied up the error message when you use @Delegate wrong (on static items or methods with args). Also put back something I accidentally deleted with the previous merge. --- .../lombok/eclipse/agent/PatchDelegate.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java index d6310de1..e510d37b 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java @@ -198,6 +198,12 @@ public class PatchDelegate { if (!isDelegate(ann, decl)) continue; if (alreadyApplied.put(ann, MARKER) == MARKER) continue; + if ((field.modifiers & ClassFileConstants.AccStatic) != 0) { + EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); + eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); + break; + } + List rawTypes = rawTypes(ann, "types"); List excludedRawTypes = rawTypes(ann, "excludes"); @@ -233,6 +239,8 @@ public class PatchDelegate { } } + private static final String LEGALITY_OF_DELEGATE = "@Delegate is legal only on instance fields or no-argument instance methods."; + private static void fillMethodBindingsForMethods(CompilationUnitDeclaration cud, ClassScope scope, List methodsToDelegate) { TypeDeclaration decl = scope.referenceContext; if (decl == null) return; @@ -244,13 +252,18 @@ public class PatchDelegate { if (alreadyApplied.put(ann, MARKER) == MARKER) continue; if (!(methodDecl instanceof MethodDeclaration)) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); - eclipseAst.get(ann).addError("@Delegate is legal only on no-argument methods."); - continue; + eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); + break; } if (methodDecl.arguments != null) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); - eclipseAst.get(ann).addError("@Delegate is legal only on no-argument methods."); - continue; + eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); + break; + } + if ((methodDecl.modifiers & ClassFileConstants.AccStatic) != 0) { + EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); + eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); + break; } MethodDeclaration method = (MethodDeclaration) methodDecl; -- cgit