From fb76daf5e4320e31f19dcbd6c7a4036109d71ad7 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 21 Mar 2012 05:29:35 +0100 Subject: Added ability to create new instances of AnnotationValues with all default values --- src/core/lombok/core/AnnotationValues.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/core/lombok') diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java index 64111dae..df056dd4 100644 --- a/src/core/lombok/core/AnnotationValues.java +++ b/src/core/lombok/core/AnnotationValues.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Project Lombok Authors. + * Copyright (C) 2009-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 @@ -118,6 +118,18 @@ public class AnnotationValues { this.ast = ast; } + public static AnnotationValues of(Class type) { + return new AnnotationValues(type, Collections.emptyMap(), null); + } + + /** + * Creates a new annotation wrapper with all default values, and using the provided ast as lookup anchor for + * class literals. + */ + public static AnnotationValues of(Class type, LombokNode ast) { + return new AnnotationValues(type, Collections.emptyMap(), ast); + } + /** * Thrown on the fly if an actual annotation instance procured via the {@link #getInstance()} method is queried * for a method for which this AnnotationValues instance either doesn't have a guess or can't manage to fit @@ -423,7 +435,7 @@ public class AnnotationValues { } /* 2. Walk through non-star imports and search for a match. */ { - for (String im : ast.getImportStatements()) { + for (String im : ast == null ? Collections.emptyList() : ast.getImportStatements()) { if (im.endsWith(".*")) continue; int idx = im.lastIndexOf('.'); String simple = idx == -1 ? im : im.substring(idx+1); @@ -434,7 +446,7 @@ public class AnnotationValues { } /* 3. Walk through star imports and, if they start with "java.", use Class.forName based resolution. */ { - List imports = new ArrayList(ast.getImportStatements()); + List imports = ast == null ? Collections.emptyList() : new ArrayList(ast.getImportStatements()); imports.add("java.lang.*"); for (String im : imports) { if (!im.endsWith(".*") || !im.startsWith("java.")) continue; @@ -465,7 +477,7 @@ public class AnnotationValues { private static String inLocalPackage(LombokNode node, String typeName) { StringBuilder result = new StringBuilder(); - if (node.getPackageDeclaration() != null) result.append(node.getPackageDeclaration()); + if (node != null && node.getPackageDeclaration() != null) result.append(node.getPackageDeclaration()); if (result.length() > 0) result.append('.'); result.append(typeName); return result.toString(); -- cgit