Author: kentam
Date: Thu Oct  7 17:14:19 2004
New Revision: 54035

Added:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptUtils.java
   (contents, props changed)
Modified:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlClient.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlInterface.java
Log:
Enforce RUNTIME RetentionPolicy on PropertySets at compile-time.
Tweak asserts.



Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlClient.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlClient.java
        (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlClient.java
        Thu Oct  7 17:14:19 2004
@@ -138,7 +138,8 @@
         if ( _clientDecl == null )
             return null;
         
-        assert _clientDecl.getQualifiedName().equals( getPackage() + "." + 
getShortName() );
+        assert ( getPackage().equals("") ? 
_clientDecl.getQualifiedName().equals( getShortName() ) :
+                _clientDecl.getQualifiedName().equals( getPackage() + "." + 
getShortName() ) );
         
         return _clientDecl.getQualifiedName();
     }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlInterface.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlInterface.java
     (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptControlInterface.java
     Thu Oct  7 17:14:19 2004
@@ -185,6 +185,8 @@
 
         for (TypeDeclaration innerDecl : _intfDecl.getNestedTypes())
         {
+            boolean fError = false;
+
             // HACKHACK: There appear to be mirror API bugs where calling 
getAnnotation()
             // on certain entity types will result in an endless loop.  For 
now, work around
             // this by a priori filtering... but this mechanism will drop 
errors that appear
@@ -194,17 +196,23 @@
 
             if (innerDecl.getAnnotation(PropertySet.class) != null)
             {
-
                 if (! (innerDecl instanceof AnnotationTypeDeclaration))
                 {
                     _env.getMessager().printError(innerDecl.getPosition(),
                         "The PropertySet annotation must be on an Annotation 
type");
+                    fError = true;
                 }
-                else
+
+                if ( !AptUtils.isRuntimeRetention( 
(AnnotationTypeDeclaration)innerDecl ) )
                 {
+                    _env.getMessager().printError(innerDecl.getPosition(),
+                        "The PropertySet annotation must be used in conjuction 
with @Retention(RetentionPolicy.RUNTIME)");
+                    fError = true;
+                }
+
+                if ( !fError )
                     propSets.add(
                         new AptPropertySet(this, 
(AnnotationTypeDeclaration)innerDecl, _env));
-                }
             }
         }
         return propSets;
@@ -275,8 +283,9 @@
         if ( _intfDecl == null || _intfDecl.getQualifiedName() == null )
             return "";
 
-        assert _intfDecl.getQualifiedName().equals( getPackage() + "." + 
getShortName() );
-
+        assert ( getPackage().equals("") ? 
_intfDecl.getQualifiedName().equals( getShortName() ) :
+                _intfDecl.getQualifiedName().equals( getPackage() + "." + 
getShortName() ) );
+        
         return _intfDecl.getQualifiedName();
     }
 

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptUtils.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptUtils.java
        Thu Oct  7 17:14:19 2004
@@ -0,0 +1,39 @@
+package org.apache.beehive.controls.runtime.generator.apt;
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+
+/**
+ * The AptUtils class consolidates helper methods used by various apt 
processors.
+ */
+public class AptUtils
+{
+    /**
+     * Is this annotatation type declared as having runtime retention?
+     */
+    static public boolean isRuntimeRetention( AnnotationTypeDeclaration atd )
+    {
+        Retention ret = atd.getAnnotation(Retention.class);
+        return ( ret != null && ret.value() == RetentionPolicy.RUNTIME );
+    }
+}

Reply via email to