Hibernate SVN: r20130 - in core/trunk/core/src/main/java/org/hibernate: proxy/pojo/cglib and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-08-09 15:56:25 -0400 (Mon, 09 Aug 2010)
New Revision: 20130
Modified:
core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java
core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java
core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java
core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java
core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java
core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java
core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java
core/trunk/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java
core/trunk/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java
core/trunk/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java
Log:
HHH-5451 - deprecate cglib as bytecode provider
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -39,7 +39,10 @@
* which simply acts as an adpater to the {@link BulkBean} class.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class AccessOptimizerAdapter implements ReflectionOptimizer.AccessOptimizer, Serializable {
public static final String PROPERTY_GET_EXCEPTION =
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -41,11 +41,17 @@
* Bytecode provider implementation for CGLIB.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class BytecodeProviderImpl implements BytecodeProvider {
-
private static final Logger log = LoggerFactory.getLogger( BytecodeProviderImpl.class );
+ public BytecodeProviderImpl() {
+ log.warn( "Per HHH-5451 support for cglib as a bytecode provider has been deprecated." );
+ }
+
public ProxyFactoryFactory getProxyFactoryFactory() {
return new ProxyFactoryFactoryImpl();
}
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -52,7 +52,10 @@
* This interface is then used by Hibernate for some optimizations.
*
* @author Emmanuel Bernard
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class CglibClassTransformer extends AbstractClassTransformerImpl {
private static Logger log = LoggerFactory.getLogger( CglibClassTransformer.class.getName() );
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -35,10 +35,13 @@
/**
* The {@link ReflectionOptimizer.InstantiationOptimizer} implementation for CGLIB
- * which simply acts as an adpater to the {@link FastClass} class.
+ * which simply acts as an adapter to the {@link FastClass} class.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class InstantiationOptimizerAdapter implements ReflectionOptimizer.InstantiationOptimizer, Serializable {
private FastClass fastClass;
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -45,7 +45,10 @@
* A factory for CGLIB-based {@link ProxyFactory} instances.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class ProxyFactoryFactoryImpl implements ProxyFactoryFactory {
/**
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -32,7 +32,10 @@
* ReflectionOptimizer implementation for CGLIB.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class ReflectionOptimizerImpl implements ReflectionOptimizer, Serializable {
private transient InstantiationOptimizerAdapter instantiationOptimizer;
private transient AccessOptimizerAdapter accessOptimizer;
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.cglib;
@@ -46,7 +45,10 @@
/**
* A <tt>LazyInitializer</tt> implemented using the CGLIB bytecode generation library
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public final class CGLIBLazyInitializer extends BasicLazyInitializer implements InvocationHandler {
private static final CallbackFilter FINALIZE_FILTER = new CallbackFilter() {
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -35,7 +35,10 @@
/**
* @author Gavin King
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public class CGLIBProxyFactory implements ProxyFactory {
protected static final Class[] NO_CLASSES = new Class[0];
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -33,7 +33,10 @@
/**
* Serializable placeholder for <tt>CGLIB</tt> proxies
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
+@Deprecated
public final class SerializableProxy extends AbstractSerializableProxy {
private Class persistentClass;
Modified: core/trunk/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
Modified: core/trunk/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tool.instrument.cglib;
@@ -34,7 +33,7 @@
* field-level interception using CGLIB.
* <p/>
* In order to use this task, typically you would define a a taskdef
- * similiar to:<pre>
+ * similar to:<pre>
* <taskdef name="instrument" classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
* <classpath refid="lib.class.path"/>
* </taskdef>
@@ -54,7 +53,7 @@
* instrumented.
* <p/>
* Optionally you can chose to enable "Extended Instrumentation" if desired
- * by specifying the extended attriubute on the task:<pre>
+ * by specifying the extended attribute on the task:<pre>
* <instrument extended="true">
* ...
* </instrument>
@@ -63,8 +62,16 @@
*
* @author Gavin King
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated; use
+ * {@link org.hibernate.tool.instrument.javassist.InstrumentTask} instead
*/
+@Deprecated
public class InstrumentTask extends BasicInstrumentationTask {
+ public InstrumentTask() {
+ System.err.println( "Per HHH-5451 support for cglib as a bytecode provider has been deprecated." );
+ }
+
protected Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options) {
return new CGLIBInstrumenter( logger, options );
}
Modified: core/trunk/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java 2010-08-09 19:55:23 UTC (rev 20129)
+++ core/trunk/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java 2010-08-09 19:56:25 UTC (rev 20130)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tool.instrument.javassist;
15 years, 4 months
Hibernate SVN: r20129 - in core/branches/Branch_3_5/core/src/main/java/org/hibernate: proxy/pojo/cglib and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-08-09 15:55:23 -0400 (Mon, 09 Aug 2010)
New Revision: 20129
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java
Log:
HHH-5451 - deprecate cglib as bytecode provider
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/AccessOptimizerAdapter.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -39,6 +39,8 @@
* which simply acts as an adpater to the {@link BulkBean} class.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class AccessOptimizerAdapter implements ReflectionOptimizer.AccessOptimizer, Serializable {
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/BytecodeProviderImpl.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -41,11 +41,16 @@
* Bytecode provider implementation for CGLIB.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class BytecodeProviderImpl implements BytecodeProvider {
-
private static final Logger log = LoggerFactory.getLogger( BytecodeProviderImpl.class );
+ public BytecodeProviderImpl() {
+ log.warn( "Per HHH-5451 support for cglib as a bytecode provider has been deprecated." );
+ }
+
public ProxyFactoryFactory getProxyFactoryFactory() {
return new ProxyFactoryFactoryImpl();
}
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/CglibClassTransformer.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -52,6 +52,8 @@
* This interface is then used by Hibernate for some optimizations.
*
* @author Emmanuel Bernard
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class CglibClassTransformer extends AbstractClassTransformerImpl {
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -35,9 +35,11 @@
/**
* The {@link ReflectionOptimizer.InstantiationOptimizer} implementation for CGLIB
- * which simply acts as an adpater to the {@link FastClass} class.
+ * which simply acts as an adapter to the {@link FastClass} class.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class InstantiationOptimizerAdapter implements ReflectionOptimizer.InstantiationOptimizer, Serializable {
private FastClass fastClass;
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ProxyFactoryFactoryImpl.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -45,6 +45,8 @@
* A factory for CGLIB-based {@link ProxyFactory} instances.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class ProxyFactoryFactoryImpl implements ProxyFactoryFactory {
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/cglib/ReflectionOptimizerImpl.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -32,6 +32,8 @@
* ReflectionOptimizer implementation for CGLIB.
*
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class ReflectionOptimizerImpl implements ReflectionOptimizer, Serializable {
private transient InstantiationOptimizerAdapter instantiationOptimizer;
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.cglib;
@@ -46,6 +45,8 @@
/**
* A <tt>LazyInitializer</tt> implemented using the CGLIB bytecode generation library
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public final class CGLIBLazyInitializer extends BasicLazyInitializer implements InvocationHandler {
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/CGLIBProxyFactory.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.cglib;
@@ -36,6 +35,8 @@
/**
* @author Gavin King
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public class CGLIBProxyFactory implements ProxyFactory {
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/proxy/pojo/cglib/SerializableProxy.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.proxy.pojo.cglib;
@@ -34,6 +33,8 @@
/**
* Serializable placeholder for <tt>CGLIB</tt> proxies
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated.
*/
public final class SerializableProxy extends AbstractSerializableProxy {
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/BasicInstrumentationTask.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/cglib/InstrumentTask.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tool.instrument.cglib;
@@ -34,7 +33,7 @@
* field-level interception using CGLIB.
* <p/>
* In order to use this task, typically you would define a a taskdef
- * similiar to:<pre>
+ * similar to:<pre>
* <taskdef name="instrument" classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
* <classpath refid="lib.class.path"/>
* </taskdef>
@@ -54,7 +53,7 @@
* instrumented.
* <p/>
* Optionally you can chose to enable "Extended Instrumentation" if desired
- * by specifying the extended attriubute on the task:<pre>
+ * by specifying the extended attribute on the task:<pre>
* <instrument extended="true">
* ...
* </instrument>
@@ -63,8 +62,15 @@
*
* @author Gavin King
* @author Steve Ebersole
+ *
+ * @deprecated Per HHH-5451 support for cglib as a bytecode provider has been deprecated; use
+ * {@link org.hibernate.tool.instrument.javassist.InstrumentTask} instead
*/
public class InstrumentTask extends BasicInstrumentationTask {
+ public InstrumentTask() {
+ System.err.println( "Per HHH-5451 support for cglib as a bytecode provider has been deprecated." );
+ }
+
protected Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options) {
return new CGLIBInstrumenter( logger, options );
}
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java 2010-08-08 17:58:31 UTC (rev 20128)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/tool/instrument/javassist/InstrumentTask.java 2010-08-09 19:55:23 UTC (rev 20129)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tool.instrument.javassist;
15 years, 4 months
Hibernate SVN: r20128 - in validator/trunk/hibernate-validator-annotation-processor/src: main/resources/org/hibernate/validator/ap and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 13:58:31 -0400 (Sun, 08 Aug 2010)
New Revision: 20128
Added:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongMessageAttribute.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java
Log:
HV-299: Implemented check, that each constraint annotation type defines a member 'String message()'
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -0,0 +1,102 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.Types;
+
+import org.hibernate.validator.ap.util.AnnotationApiHelper;
+import org.hibernate.validator.ap.util.CollectionHelper;
+
+import static javax.lang.model.util.ElementFilter.methodsIn;
+
+/**
+ * Checks, that each constraint annotation type declares the members message(), groups() and payload().
+ *
+ * @author Gunnar Morling
+ */
+public class AnnotationTypeMemberCheck extends AbstractConstraintCheck {
+
+ private final AnnotationApiHelper annotationApiHelper;
+
+ private final Types typeUtils;
+
+ public AnnotationTypeMemberCheck(AnnotationApiHelper annotationApiHelper, Types typeUtils) {
+
+ this.annotationApiHelper = annotationApiHelper;
+ this.typeUtils = typeUtils;
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkAnnotationType(TypeElement element, AnnotationMirror annotation) {
+
+ Set<ConstraintCheckError> theValue = CollectionHelper.newHashSet();
+
+ theValue.addAll( checkMessageAttribute( element ) );
+ theValue.addAll( checkGroupsAttribute( element ) );
+ theValue.addAll( checkPayloadAttribute( element ) );
+
+ return theValue;
+ }
+
+ private Set<ConstraintCheckError> checkMessageAttribute(TypeElement element) {
+
+ ExecutableElement messageMethod = getMethod( element, "message" );
+
+ if ( messageMethod == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( element, null, "CONSTRAINT_TYPE_MUST_DECLARE_MESSAGE_MEMBER" )
+ );
+ }
+
+ if ( !typeUtils.isSameType(
+ annotationApiHelper.getMirrorForType( String.class ), messageMethod.getReturnType()
+ ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( messageMethod, null, "RETURN_TYPE_MUST_BE_STRING" )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+ private Set<ConstraintCheckError> checkGroupsAttribute(TypeElement element) {
+ return Collections.emptySet();
+ }
+
+ private Set<ConstraintCheckError> checkPayloadAttribute(TypeElement element) {
+ return Collections.emptySet();
+ }
+
+ private ExecutableElement getMethod(TypeElement element, String name) {
+
+ for ( ExecutableElement oneMethod : methodsIn( element.getEnclosedElements() ) ) {
+
+ if ( oneMethod.getSimpleName().contentEquals( name ) ) {
+ return oneMethod;
+ }
+ }
+
+ return null;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-08-08 17:45:24 UTC (rev 20127)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -108,7 +108,8 @@
new SingleValuedChecks(
new RetentionPolicyCheck( annotationApiHelper ),
new TargetCheck( annotationApiHelper ),
- new ConstraintValidatorCheck( constraintHelper, annotationApiHelper )
+ new ConstraintValidatorCheck( constraintHelper, annotationApiHelper ),
+ new AnnotationTypeMemberCheck( annotationApiHelper, typeUtils )
)
);
annotationTypeChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-08-08 17:45:24 UTC (rev 20127)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-08-08 17:58:31 UTC (rev 20128)
@@ -13,4 +13,6 @@
ATVALID_NOT_ALLOWED_AT_METHOD_RETURNING_PRIMITIVE_TYPE=Methods returning a primitive type must not annotated with @Valid.
CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION=Constraint annotation types must be annotated with @Retention(RUNTIME).
CONSTRAINT_TYPE_WITH_WRONG_TARGET=Constraint annotation types must have at least one of the element types FIELD, METHOD, TYPE or ANNOTATION_TYPE as target.
-CONSTRAINT_TYPE_WITHOUT_VALIDATOR=For non-composed constraints a validator implementation must be specified using @Constraint#validatedBy().
\ No newline at end of file
+CONSTRAINT_TYPE_WITHOUT_VALIDATOR=For non-composed constraints a validator implementation must be specified using @Constraint#validatedBy().
+CONSTRAINT_TYPE_MUST_DECLARE_MESSAGE_MEMBER=Constraint annotation types must declare a member 'String message()'.
+RETURN_TYPE_MUST_BE_STRING=Return type of constraint annotation type member 'message()' must be 'String'.
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 17:45:24 UTC (rev 20127)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -24,6 +24,7 @@
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalRetentionPolicies;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalTargets;
+import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongMessageAttribute;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithoutValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.DummyValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
@@ -66,7 +67,7 @@
assertFalse( compilationResult );
assertThatDiagnosticsMatch(
diagnostics,
- new DiagnosticExpectation( Kind.ERROR, 33 ), new DiagnosticExpectation( Kind.ERROR, 42 )
+ new DiagnosticExpectation( Kind.ERROR, 34 ), new DiagnosticExpectation( Kind.ERROR, 49 )
);
}
@@ -82,7 +83,7 @@
assertFalse( compilationResult );
assertThatDiagnosticsMatch(
diagnostics,
- new DiagnosticExpectation( Kind.ERROR, 42 ), new DiagnosticExpectation( Kind.ERROR, 52 )
+ new DiagnosticExpectation( Kind.ERROR, 43 ), new DiagnosticExpectation( Kind.ERROR, 59 )
);
}
@@ -98,7 +99,23 @@
assertFalse( compilationResult );
assertThatDiagnosticsMatch(
diagnostics,
- new DiagnosticExpectation( Kind.ERROR, 34 )
+ new DiagnosticExpectation( Kind.ERROR, 35 )
);
}
+
+ @Test
+ public void testThatConstraintAnnotationTypeWithMissingOrWrongMessageAttributeCausesCompilationError() {
+
+ File sourceFile1 = compilerHelper.getSourceFile( ConstraintsWithWrongMessageAttribute.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 35 ), new DiagnosticExpectation( Kind.ERROR, 50 )
+ );
+ }
}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java 2010-08-08 17:45:24 UTC (rev 20127)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -20,6 +20,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.validation.Constraint;
+import javax.validation.Payload;
/**
* @author Gunnar Morling
@@ -33,6 +34,12 @@
@Retention(RetentionPolicy.CLASS)
public @interface ConstraintWithWrongRetentionPolicy {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -41,6 +48,12 @@
@Constraint(validatedBy = { DummyValidator.class })
public @interface ConstraintWithoutRetentionPolicy {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -50,6 +63,12 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface ConstraintWithCorrectRetentionPolicy {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java 2010-08-08 17:45:24 UTC (rev 20127)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -21,6 +21,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.Payload;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
@@ -42,6 +43,12 @@
@Target({ LOCAL_VARIABLE })
public @interface ConstraintWithWrongTarget {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -52,6 +59,12 @@
@Target({ })
public @interface ConstraintWithEmptyTarget {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -61,6 +74,12 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface ConstraintWithDefaultTarget {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -71,6 +90,12 @@
@Target({ FIELD })
public @interface ConstraintWithAllowedTargetField {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -81,6 +106,12 @@
@Target({ METHOD })
public @interface ConstraintWithAllowedTargetMethod {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -91,6 +122,12 @@
@Target({ TYPE })
public @interface ConstraintWithAllowedTargetType {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -101,6 +138,12 @@
@Target({ ANNOTATION_TYPE })
public @interface ConstraintWithAllowedTargetAnnotationType {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
}
\ No newline at end of file
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongMessageAttribute.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongMessageAttribute.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongMessageAttribute.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -0,0 +1,73 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithWrongMessageAttribute {
+
+ /**
+ * Compilation error expected as no message() attribute is specified.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithoutMessageAttribute {
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected as message() attribute doesn't have String as return type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithMessageAttributeWithWrongReturnType {
+
+ public int message();
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * No compilation error expected.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithMessageAttribute {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongMessageAttribute.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java 2010-08-08 17:45:24 UTC (rev 20127)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java 2010-08-08 17:58:31 UTC (rev 20128)
@@ -20,6 +20,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.validation.Constraint;
+import javax.validation.Payload;
import javax.validation.constraints.Size;
/**
@@ -34,6 +35,12 @@
@Constraint(validatedBy = { })
public @interface ConstraintWithoutValidator {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -43,6 +50,12 @@
@Constraint(validatedBy = { DummyValidator.class })
public @interface ConstraintWithValidator {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
/**
@@ -53,6 +66,12 @@
@Constraint(validatedBy = { })
public @interface ComposedConstraintWithoutValidator {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
}
}
\ No newline at end of file
15 years, 4 months
Hibernate SVN: r20127 - validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 13:45:24 -0400 (Sun, 08 Aug 2010)
New Revision: 20127
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java
Log:
HV-299: Removed direct access to Constraint#validatedBy(), using mirror-based API instead in order to avoid MirrorTypeException
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java 2010-08-08 16:45:57 UTC (rev 20126)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java 2010-08-08 17:45:24 UTC (rev 20127)
@@ -48,10 +48,14 @@
@Override
public Set<ConstraintCheckError> checkAnnotationType(TypeElement element, AnnotationMirror annotation) {
- Constraint constraint = element.getAnnotation( Constraint.class );
+ AnnotationMirror constraintMirror = annotationApiHelper.getMirror(
+ element.getAnnotationMirrors(), Constraint.class
+ );
+ boolean atLeastOneValidatorGiven = !annotationApiHelper.getAnnotationArrayValue(
+ constraintMirror, "validatedBy"
+ ).isEmpty();
- //raise an error if neither a validator is given and this is not a composed constraint
- if ( !( constraint.validatedBy().length > 0 || constraintHelper.isComposedConstraint( element ) ) ) {
+ if ( !( atLeastOneValidatorGiven || constraintHelper.isComposedConstraint( element ) ) ) {
return CollectionHelper.asSet(
new ConstraintCheckError(
15 years, 4 months
Hibernate SVN: r20126 - in validator/trunk/hibernate-validator-annotation-processor/src: main/java/org/hibernate/validator/ap/util and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 12:45:57 -0400 (Sun, 08 Aug 2010)
New Revision: 20126
Added:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/DummyValidator.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
Log:
HV-299: Implemented check for validator specification at constraint annotation types, added SVN keywords property
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -106,7 +106,9 @@
annotationTypeChecks.put(
AnnotationType.CONSTRAINT_META_ANNOTATION,
new SingleValuedChecks(
- new RetentionPolicyCheck( annotationApiHelper ), new TargetCheck( annotationApiHelper )
+ new RetentionPolicyCheck( annotationApiHelper ),
+ new TargetCheck( annotationApiHelper ),
+ new ConstraintValidatorCheck( constraintHelper, annotationApiHelper )
)
);
annotationTypeChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -0,0 +1,68 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.TypeElement;
+import javax.validation.Constraint;
+
+import org.hibernate.validator.ap.util.AnnotationApiHelper;
+import org.hibernate.validator.ap.util.CollectionHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper;
+
+/**
+ * Checks, that for each constraint annotation type, which is not a composed constraint,
+ * a validator implementation is specified using {@link Constraint#validatedBy()}.
+ *
+ * @author Gunnar Morling
+ */
+public class ConstraintValidatorCheck extends AbstractConstraintCheck {
+
+ private ConstraintHelper constraintHelper;
+
+ private final AnnotationApiHelper annotationApiHelper;
+
+ public ConstraintValidatorCheck(ConstraintHelper constraintHelper, AnnotationApiHelper annotationApiHelper) {
+
+ this.constraintHelper = constraintHelper;
+ this.annotationApiHelper = annotationApiHelper;
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkAnnotationType(TypeElement element, AnnotationMirror annotation) {
+
+ Constraint constraint = element.getAnnotation( Constraint.class );
+
+ //raise an error if neither a validator is given and this is not a composed constraint
+ if ( !( constraint.validatedBy().length > 0 || constraintHelper.isComposedConstraint( element ) ) ) {
+
+ return CollectionHelper.asSet(
+ new ConstraintCheckError(
+ element,
+ annotationApiHelper.getMirror( element.getAnnotationMirrors(), Constraint.class ),
+ "CONSTRAINT_TYPE_WITHOUT_VALIDATOR"
+ )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintValidatorCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -1,4 +1,4 @@
-// $Id: RetentionPolicyCheck.java 19310 2010-04-27 22:51:17Z gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -1,4 +1,4 @@
-// $Id: TargetCheck.java 19310 2010-04-27 22:51:17Z gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -29,6 +29,7 @@
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
@@ -307,6 +308,29 @@
);
}
+ /**
+ * Checks, whether the given type element represents a composed constraint or not.
+ *
+ * @param element The type element of interest. Must not be null.
+ *
+ * @return True if the given element represents a composed constraint, false otherwise.
+ */
+ public boolean isComposedConstraint(TypeElement element) {
+
+ return Boolean.TRUE.equals(
+ element.asType().accept(
+ new TypeKindVisitor6<Boolean, Void>() {
+
+ @Override
+ public Boolean visitDeclared(DeclaredType constraintValidatorImplementation, Void p) {
+ return !getComposingConstraints( constraintValidatorImplementation ).isEmpty();
+ }
+
+ }, null
+ )
+ );
+ }
+
// ==================================
// private API below
// ==================================
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-08-08 16:45:57 UTC (rev 20126)
@@ -12,4 +12,5 @@
ATVALID_NOT_ALLOWED_AT_PRIMITIVE_FIELD=Fields of a primitive type must not annotated with @Valid.
ATVALID_NOT_ALLOWED_AT_METHOD_RETURNING_PRIMITIVE_TYPE=Methods returning a primitive type must not annotated with @Valid.
CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION=Constraint annotation types must be annotated with @Retention(RUNTIME).
-CONSTRAINT_TYPE_WITH_WRONG_TARGET=Constraint annotation types must have at least one of the element types FIELD, METHOD, TYPE or ANNOTATION_TYPE as target.
\ No newline at end of file
+CONSTRAINT_TYPE_WITH_WRONG_TARGET=Constraint annotation types must have at least one of the element types FIELD, METHOD, TYPE or ANNOTATION_TYPE as target.
+CONSTRAINT_TYPE_WITHOUT_VALIDATOR=For non-composed constraints a validator implementation must be specified using @Constraint#validatedBy().
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -1,4 +1,4 @@
-// $Id: AnnotationTypeValidationTest.java 19525 2010-05-15 16:05:09Z gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
@@ -24,6 +24,8 @@
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalRetentionPolicies;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalTargets;
+import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithoutValidator;
+import org.hibernate.validator.ap.testmodel.constrainttypes.DummyValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
import org.hibernate.validator.ap.util.DiagnosticExpectation;
@@ -55,10 +57,11 @@
@Test
public void testThatConstraintAnnotationTypeWithWrongRetentionPolicyCausesCompilationError() {
- File sourceFile = compilerHelper.getSourceFile( ConstraintsWithIllegalRetentionPolicies.class );
+ File sourceFile1 = compilerHelper.getSourceFile( ConstraintsWithIllegalRetentionPolicies.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
boolean compilationResult =
- compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
assertFalse( compilationResult );
assertThatDiagnosticsMatch(
@@ -70,10 +73,11 @@
@Test
public void testThatConstraintAnnotationTypeWithWrongTargetCausesCompilationError() {
- File sourceFile = compilerHelper.getSourceFile( ConstraintsWithIllegalTargets.class );
+ File sourceFile1 = compilerHelper.getSourceFile( ConstraintsWithIllegalTargets.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
boolean compilationResult =
- compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
assertFalse( compilationResult );
assertThatDiagnosticsMatch(
@@ -82,5 +86,19 @@
);
}
+ @Test
+ public void testThatConstraintAnnotationTypeWithoutValidatorCausesCompilationError() {
+ File sourceFile1 = compilerHelper.getSourceFile( ConstraintsWithoutValidator.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 34 )
+ );
+ }
}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -1,4 +1,4 @@
-// $Id: ConstraintValidationProcessorTestBase.java 19033 Aug 8, 2010 11:14:14 AM gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -1,4 +1,4 @@
-// $Id: ConstraintWithWrongRetentionPolicy.java 19033 Aug 1, 2010 5:44:13 PM gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
@@ -29,7 +29,7 @@
/**
* Compilation error expected as wrong retention policy is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.CLASS)
public @interface ConstraintWithWrongRetentionPolicy {
@@ -38,7 +38,7 @@
/**
* Compilation error expected as no retention policy is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
public @interface ConstraintWithoutRetentionPolicy {
}
@@ -46,7 +46,7 @@
/**
* No compilation error expected as correct retention policy is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
public @interface ConstraintWithCorrectRetentionPolicy {
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java 2010-08-08 15:00:19 UTC (rev 20125)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -1,4 +1,4 @@
-// $Id: ConstraintsWithIllegalTargets.java 19033 Aug 1, 2010 5:44:13 PM gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
@@ -37,7 +37,7 @@
/**
* Compilation error expected due to none supported target type being given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
@Target({ LOCAL_VARIABLE })
public @interface ConstraintWithWrongTarget {
@@ -47,7 +47,7 @@
/**
* Compilation error expected as no supported target type is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
@Target({ })
public @interface ConstraintWithEmptyTarget {
@@ -57,7 +57,7 @@
/**
* No compilation error expected, as not specifying @Target allows this constraint for all element types.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
public @interface ConstraintWithDefaultTarget {
@@ -66,7 +66,7 @@
/**
* No compilation error expected, as supported target type FIELD is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
@Target({ FIELD })
public @interface ConstraintWithAllowedTargetField {
@@ -76,7 +76,7 @@
/**
* No compilation error expected, as supported target type METHOD is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
@Target({ METHOD })
public @interface ConstraintWithAllowedTargetMethod {
@@ -86,7 +86,7 @@
/**
* No compilation error expected, as supported target type TYPE is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE })
public @interface ConstraintWithAllowedTargetType {
@@ -96,7 +96,7 @@
/**
* No compilation error expected, as supported target type ANNOTATION_TYPE is given.
*/
- @Constraint(validatedBy = { })
+ @Constraint(validatedBy = { DummyValidator.class })
@Retention(RetentionPolicy.RUNTIME)
@Target({ ANNOTATION_TYPE })
public @interface ConstraintWithAllowedTargetAnnotationType {
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -0,0 +1,58 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithoutValidator {
+
+ /**
+ * Compilation error expected as no validator is given.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { })
+ public @interface ConstraintWithoutValidator {
+
+ }
+
+ /**
+ * No compilation error expected as a validator is given.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithValidator {
+
+ }
+
+ /**
+ * No compilation error as this is a composed constraint.
+ */
+ @Size
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { })
+ public @interface ComposedConstraintWithoutValidator {
+
+ }
+
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithoutValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/DummyValidator.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/DummyValidator.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/DummyValidator.java 2010-08-08 16:45:57 UTC (rev 20126)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Annotation;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Gunnar Morling
+ */
+public class DummyValidator implements ConstraintValidator<Annotation, Object> {
+
+ public void initialize(Annotation constraintAnnotation) {
+ throw new UnsupportedOperationException( "Not implemented" );
+ }
+
+ public boolean isValid(Object value, ConstraintValidatorContext context) {
+ throw new UnsupportedOperationException( "Not implemented" );
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/DummyValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
15 years, 4 months
Hibernate SVN: r20125 - validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 11:00:19 -0400 (Sun, 08 Aug 2010)
New Revision: 20125
Added:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java
Removed:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithWrongRetentionPolicy.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithoutRetentionPolicy.java
Log:
HV-299: Refactored retention policy check test
Deleted: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithWrongRetentionPolicy.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithWrongRetentionPolicy.java 2010-08-08 11:27:49 UTC (rev 20124)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithWrongRetentionPolicy.java 2010-08-08 15:00:19 UTC (rev 20125)
@@ -1,31 +0,0 @@
-// $Id: ConstraintWithWrongRetentionPolicy.java 19033 Aug 1, 2010 5:44:13 PM gunnar.morling $
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validator.ap.testmodel.constrainttypes;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import javax.validation.Constraint;
-
-/**
- * @author Gunnar Morling
- */
-@Constraint(validatedBy = { })
-(a)Retention(RetentionPolicy.CLASS)
-public @interface ConstraintWithWrongRetentionPolicy {
-
-}
Deleted: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithoutRetentionPolicy.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithoutRetentionPolicy.java 2010-08-08 11:27:49 UTC (rev 20124)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithoutRetentionPolicy.java 2010-08-08 15:00:19 UTC (rev 20125)
@@ -1,28 +0,0 @@
-// $Id: ConstraintWithoutRetentionPolicy.java 19033 Aug 1, 2010 5:44:13 PM gunnar.morling $
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validator.ap.testmodel.constrainttypes;
-
-import javax.validation.Constraint;
-
-/**
- * @author Gunnar Morling
- */
-@Constraint(validatedBy = { })
-public @interface ConstraintWithoutRetentionPolicy {
-
-}
Copied: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java (from rev 20121, validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintWithWrongRetentionPolicy.java)
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalRetentionPolicies.java 2010-08-08 15:00:19 UTC (rev 20125)
@@ -0,0 +1,55 @@
+// $Id: ConstraintWithWrongRetentionPolicy.java 19033 Aug 1, 2010 5:44:13 PM gunnar.morling $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithIllegalRetentionPolicies {
+
+ /**
+ * Compilation error expected as wrong retention policy is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.CLASS)
+ public @interface ConstraintWithWrongRetentionPolicy {
+
+ }
+
+ /**
+ * Compilation error expected as no retention policy is given.
+ */
+ @Constraint(validatedBy = { })
+ public @interface ConstraintWithoutRetentionPolicy {
+
+ }
+
+ /**
+ * No compilation error expected as correct retention policy is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface ConstraintWithCorrectRetentionPolicy {
+
+ }
+
+}
\ No newline at end of file
15 years, 4 months
Hibernate SVN: r20124 - validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 07:27:49 -0400 (Sun, 08 Aug 2010)
New Revision: 20124
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
Log:
HV-299: Refactored retention policy check test
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 11:16:14 UTC (rev 20123)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 11:27:49 UTC (rev 20124)
@@ -22,8 +22,7 @@
import org.testng.annotations.Test;
-import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintWithWrongRetentionPolicy;
-import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintWithoutRetentionPolicy;
+import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalRetentionPolicies;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalTargets;
import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
import org.hibernate.validator.ap.util.DiagnosticExpectation;
@@ -54,27 +53,18 @@
}
@Test
- public void testThatConstraintAnnotationTypeWithoutRetentionPolicyCausesCompilationError() {
-
- File sourceFile = compilerHelper.getSourceFile( ConstraintWithoutRetentionPolicy.class );
-
- boolean compilationResult =
- compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
-
- assertFalse( compilationResult );
- assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 26 ) );
- }
-
- @Test
public void testThatConstraintAnnotationTypeWithWrongRetentionPolicyCausesCompilationError() {
- File sourceFile = compilerHelper.getSourceFile( ConstraintWithWrongRetentionPolicy.class );
+ File sourceFile = compilerHelper.getSourceFile( ConstraintsWithIllegalRetentionPolicies.class );
boolean compilationResult =
compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
assertFalse( compilationResult );
- assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 28 ) );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 33 ), new DiagnosticExpectation( Kind.ERROR, 42 )
+ );
}
@Test
15 years, 4 months
Hibernate SVN: r20123 - in validator/trunk/hibernate-validator-annotation-processor/src: main/resources/org/hibernate/validator/ap and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 07:16:14 -0400 (Sun, 08 Aug 2010)
New Revision: 20123
Added:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
Log:
HV-299: Check target element types for constraint annotation types
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-08-08 10:32:12 UTC (rev 20122)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-08-08 11:16:14 UTC (rev 20123)
@@ -106,7 +106,7 @@
annotationTypeChecks.put(
AnnotationType.CONSTRAINT_META_ANNOTATION,
new SingleValuedChecks(
- new RetentionPolicyCheck( annotationApiHelper )
+ new RetentionPolicyCheck( annotationApiHelper ), new TargetCheck( annotationApiHelper )
)
);
annotationTypeChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java 2010-08-08 10:32:12 UTC (rev 20122)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/RetentionPolicyCheck.java 2010-08-08 11:16:14 UTC (rev 20123)
@@ -41,8 +41,7 @@
}
@Override
- public Set<ConstraintCheckError> checkAnnotationType(TypeElement element,
- AnnotationMirror annotation) {
+ public Set<ConstraintCheckError> checkAnnotationType(TypeElement element, AnnotationMirror annotation) {
Retention retention = element.getAnnotation( Retention.class );
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TargetCheck.java 2010-08-08 11:16:14 UTC (rev 20123)
@@ -0,0 +1,91 @@
+// $Id: TargetCheck.java 19310 2010-04-27 22:51:17Z gunnar.morling $
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.TypeElement;
+
+import org.hibernate.validator.ap.util.AnnotationApiHelper;
+import org.hibernate.validator.ap.util.CollectionHelper;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+
+/**
+ * Checks, that at least one of the {@link ElementType}s FIELD, METHOD, TYPE or ANNOTATION_TYPE is specified
+ * using the {@link Target} meta-annotation for constraint annotation types.
+ *
+ * @author Gunnar Morling
+ */
+public class TargetCheck extends AbstractConstraintCheck {
+
+ private final AnnotationApiHelper annotationApiHelper;
+
+ /**
+ * Each constraint annotation type must be targeted at one of these element types at least.
+ */
+ private final EnumSet<ElementType> supportedTypes = EnumSet.of( FIELD, METHOD, TYPE, ANNOTATION_TYPE );
+
+ public TargetCheck(AnnotationApiHelper annotationApiHelper) {
+ this.annotationApiHelper = annotationApiHelper;
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkAnnotationType(TypeElement element, AnnotationMirror annotation) {
+
+ Target target = element.getAnnotation( Target.class );
+
+ //no target given allows the annotation to be declared at any type
+ if ( target == null ) {
+ return Collections.emptySet();
+ }
+
+ if ( !containsAtLeastOneSupportedElementType( target ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError(
+ element,
+ annotationApiHelper.getMirror( element.getAnnotationMirrors(), Target.class ),
+ "CONSTRAINT_TYPE_WITH_WRONG_TARGET"
+ )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+ private boolean containsAtLeastOneSupportedElementType(Target target) {
+
+ ElementType[] elementTypes = target.value();
+
+ for ( ElementType oneElementType : elementTypes ) {
+ if ( supportedTypes.contains( oneElementType ) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-08-08 10:32:12 UTC (rev 20122)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-08-08 11:16:14 UTC (rev 20123)
@@ -11,4 +11,5 @@
INVALID_DIAGNOSTIC_KIND_GIVEN=The given value {0} is no valid diagnostic kind. Kind.ERROR will be used.
ATVALID_NOT_ALLOWED_AT_PRIMITIVE_FIELD=Fields of a primitive type must not annotated with @Valid.
ATVALID_NOT_ALLOWED_AT_METHOD_RETURNING_PRIMITIVE_TYPE=Methods returning a primitive type must not annotated with @Valid.
-CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION=Constraint annotation types must be annotated with @Retention(RUNTIME).
\ No newline at end of file
+CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION=Constraint annotation types must be annotated with @Retention(RUNTIME).
+CONSTRAINT_TYPE_WITH_WRONG_TARGET=Constraint annotation types must have at least one of the element types FIELD, METHOD, TYPE or ANNOTATION_TYPE as target.
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 10:32:12 UTC (rev 20122)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 11:16:14 UTC (rev 20123)
@@ -24,6 +24,7 @@
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintWithWrongRetentionPolicy;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintWithoutRetentionPolicy;
+import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalTargets;
import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
import org.hibernate.validator.ap.util.DiagnosticExpectation;
@@ -76,4 +77,20 @@
assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 28 ) );
}
+ @Test
+ public void testThatConstraintAnnotationTypeWithWrongTargetCausesCompilationError() {
+
+ File sourceFile = compilerHelper.getSourceFile( ConstraintsWithIllegalTargets.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 42 ), new DiagnosticExpectation( Kind.ERROR, 52 )
+ );
+ }
+
+
}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithIllegalTargets.java 2010-08-08 11:16:14 UTC (rev 20123)
@@ -0,0 +1,106 @@
+// $Id: ConstraintsWithIllegalTargets.java 19033 Aug 1, 2010 5:44:13 PM gunnar.morling $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithIllegalTargets {
+
+
+ /**
+ * Compilation error expected due to none supported target type being given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ LOCAL_VARIABLE })
+ public @interface ConstraintWithWrongTarget {
+
+ }
+
+ /**
+ * Compilation error expected as no supported target type is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ })
+ public @interface ConstraintWithEmptyTarget {
+
+ }
+
+ /**
+ * No compilation error expected, as not specifying @Target allows this constraint for all element types.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface ConstraintWithDefaultTarget {
+
+ }
+
+ /**
+ * No compilation error expected, as supported target type FIELD is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ FIELD })
+ public @interface ConstraintWithAllowedTargetField {
+
+ }
+
+ /**
+ * No compilation error expected, as supported target type METHOD is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ METHOD })
+ public @interface ConstraintWithAllowedTargetMethod {
+
+ }
+
+ /**
+ * No compilation error expected, as supported target type TYPE is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ TYPE })
+ public @interface ConstraintWithAllowedTargetType {
+
+ }
+
+ /**
+ * No compilation error expected, as supported target type ANNOTATION_TYPE is given.
+ */
+ @Constraint(validatedBy = { })
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ ANNOTATION_TYPE })
+ public @interface ConstraintWithAllowedTargetAnnotationType {
+
+ }
+
+}
\ No newline at end of file
15 years, 4 months
Hibernate SVN: r20122 - validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-08 06:32:12 -0400 (Sun, 08 Aug 2010)
New Revision: 20122
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
Log:
HV-299: Set correct line numbers for expected compilation errors
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 10:04:21 UTC (rev 20121)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-08-08 10:32:12 UTC (rev 20122)
@@ -61,7 +61,7 @@
compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
assertFalse( compilationResult );
- assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 27 ) );
+ assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 26 ) );
}
@Test
@@ -73,7 +73,7 @@
compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
assertFalse( compilationResult );
- assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 30 ) );
+ assertThatDiagnosticsMatch( diagnostics, new DiagnosticExpectation( Kind.ERROR, 28 ) );
}
}
15 years, 4 months