From 157bbba3acd78aaff2ba0946ddb60a981186c7db Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sat, 27 Jun 2009 03:10:04 +0200 Subject: Added a caching mechanism to AnnotationValues, for instantiating the annotation. --- src/lombok/core/AnnotationValues.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lombok/core/AnnotationValues.java b/src/lombok/core/AnnotationValues.java index 8c69ffc4..515079e6 100644 --- a/src/lombok/core/AnnotationValues.java +++ b/src/lombok/core/AnnotationValues.java @@ -77,8 +77,11 @@ public class AnnotationValues { "No value supplied but " + method.getName() + " has no default either.", -1); } + private A cachedInstance = null; + @SuppressWarnings("unchecked") public A getInstance() throws AnnotationValueDecodeFail { + if ( cachedInstance != null ) return cachedInstance; InvocationHandler invocations = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { AnnotationValue v = values.get(method.getName()); @@ -134,7 +137,7 @@ public class AnnotationValues { } }; - return (A) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, invocations); + return cachedInstance = (A) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, invocations); } private Object guessToType(Object guess, Class expected, AnnotationValue v, int pos) { -- cgit