You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cr...@apache.org on 2007/02/09 22:51:57 UTC

svn commit: r505517 - in /beehive/trunk: controls/src/runtime/org/apache/beehive/controls/runtime/generator/ controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ netui/src/compiler-core/org/apache/beehive/netui/compiler/ netui/src/co...

Author: crogers
Date: Fri Feb  9 13:51:57 2007
New Revision: 505517

URL: http://svn.apache.org/viewvc?view=rev&rev=505517
Log:
Changed some code to avoid calls to TypeDeclaration.getPackage() and just get the fully qualified name of the TypeDeclaration, then stripping off the class name portion to get the package name (BEEHIVE-1176).

Tests: Controls BVT, NetUI BVT, and NetUI jsfWeb BVT (WinXP passed)


Added:
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptUtils.java   (with props)
Modified:
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptType.java
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FacesBackingChecker.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/SharedFlowChecker.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java Fri Feb  9 13:51:57 2007
@@ -87,10 +87,10 @@
      */
     public String getPackage()
     {
-        if (_propertySet == null || _propertySet.getPackage() == null )
+        if (_propertySet == null)
             return "";
         
-        return _propertySet.getPackage().getQualifiedName();
+        return AptUtils.getPackageNameFromType(_propertySet);
     }
 
     /**

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptType.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptType.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptType.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptType.java Fri Feb  9 13:51:57 2007
@@ -75,7 +75,7 @@
         if ( _typeDecl == null)
             return "";
 
-        return _typeDecl.getPackage().getQualifiedName();
+        return AptUtils.getPackageNameFromType(_typeDecl);
     }
 
     /**

Added: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptUtils.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptUtils.java?view=auto&rev=505517
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptUtils.java (added)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptUtils.java Fri Feb  9 13:51:57 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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:$
+ */
+package org.apache.beehive.controls.runtime.generator;
+
+import com.sun.mirror.declaration.TypeDeclaration;
+
+/**
+ * Class of utility methods for controls annotation processing.
+ */
+public class AptUtils
+{
+    /**
+     * Returns the fully qualified package name of the given class or
+     * interface declaration.
+     * @param type the class or interface declaration
+     * @return a fully qualified package name 
+     */
+    public static String getPackageNameFromType(TypeDeclaration type) {
+        assert type != null;
+
+        // Calls on PackageDeclaration can be expensive. Just use
+        // the fully qualified name of the type declaration to get
+        // the package name instead of getting the PackageDeclaration
+        // and its qualified name.
+        String className = type.getQualifiedName();
+        int lastDot = className.lastIndexOf('.');
+        return (lastDot != -1 ? className.substring(0, lastDot) : "");
+    }
+}

Propchange: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java Fri Feb  9 13:51:57 2007
@@ -45,13 +45,14 @@
 import com.sun.mirror.type.DeclaredType;
 
 import org.apache.beehive.controls.runtime.bean.ControlUtils;
-import org.apache.beehive.controls.runtime.generator.CodeGenerationException;
 import org.apache.beehive.controls.runtime.generator.AptAnnotationHelper;
 import org.apache.beehive.controls.runtime.generator.AptControlClient;
-import org.apache.beehive.controls.runtime.generator.GeneratorOutput;
+import org.apache.beehive.controls.runtime.generator.AptUtils;
+import org.apache.beehive.controls.runtime.generator.CodeGenerator;
+import org.apache.beehive.controls.runtime.generator.CodeGenerationException;
 import org.apache.beehive.controls.runtime.generator.Generator;
+import org.apache.beehive.controls.runtime.generator.GeneratorOutput;
 import org.apache.beehive.controls.runtime.generator.VelocityGenerator;
-import org.apache.beehive.controls.runtime.generator.CodeGenerator;
 import org.apache.beehive.controls.api.versioning.Version;
 import org.apache.beehive.controls.api.versioning.VersionRequired;
 import org.apache.beehive.controls.api.bean.ControlInterface;
@@ -218,7 +219,7 @@
         {
             // Emit manifest
 
-            String clientPkg = clientType.getPackage().getQualifiedName();
+            String clientPkg = AptUtils.getPackageNameFromType(clientType);
             File clientManifestName =
                 new File( clientType.getSimpleName() + ControlClientManifest.FILE_EXTENSION );
 

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java Fri Feb  9 13:51:57 2007
@@ -997,10 +997,28 @@
      * Infers the Struts module path from the given controller class.
      */
     public static String inferModulePathFromType(TypeDeclaration type) {
-        PackageDeclaration pkg = type.getPackage();
-        return pkg != null ? '/' + pkg.getQualifiedName().replace('.', '/') : "/";
+        String pkg = getPackageNameFromType(type);
+        return '/' + pkg.replace('.', '/');
     }
-    
+
+    /**
+     * Returns the fully qualified package name of the given class or
+     * interface declaration.
+     * @param type the class or interface declaration
+     * @return a fully qualified package name 
+     */
+    public static String getPackageNameFromType(TypeDeclaration type) {
+        assert type != null;
+
+        // Calls on PackageDeclaration can be expensive. Just use
+        // the fully qualified name of the type declaration to get
+        // the package name instead of getting the PackageDeclaration
+        // and its qualified name. 
+        String className = type.getQualifiedName();
+        int lastDot = className.lastIndexOf('.');
+        return (lastDot != -1 ? className.substring(0, lastDot) : "");
+    }
+
     public static TypeDeclaration getDeclaration( DeclaredType type )
     {
         TypeDeclaration decl = type != null ? type.getDeclaration() : null;
@@ -1204,18 +1222,23 @@
         File desiredParentDir = sourceFile.getAbsoluteFile().getParentFile();
         File retVal = new File( desiredParentDir, relativePath );
         
-        //
         // If we still haven't found it, construct a webapp-relative path and look for the file relative to the webapp.
-        //
-        if ( ! retVal.exists() )
-        {
-            PackageDeclaration jpfPackage = outerClass.getPackage();
-            return getWebappRelativeFile( getPathRelativeToPackage( relativePath, jpfPackage ), true, env );
+        if (!retVal.exists()) {
+            String jpfPackage = getPackageNameFromType(outerClass);
+            return getWebappRelativeFile(getPathRelativeToPackage(relativePath, jpfPackage), true, env);
         }
             
         return retVal;
     }
-    
+
+    public static String getPathRelativeToPackage(String relativePath, String packageName) {
+        if (packageName != null && packageName.length() > 0) {
+            return '/' + packageName.replace('.', '/') + '/' + relativePath;
+        }
+
+        return '/' + relativePath;
+    }
+
     public static String getPathRelativeToPackage( String relativePath, PackageDeclaration packageDecl )
     {
         if ( packageDecl != null )

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FacesBackingChecker.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FacesBackingChecker.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FacesBackingChecker.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/FacesBackingChecker.java Fri Feb  9 13:51:57 2007
@@ -47,13 +47,15 @@
         
         ClassDeclaration[] packageClasses = jclass.getPackage().getClasses();
         ClassDeclaration jpfClass = null;
-        
-        for ( int i = 0; i < packageClasses.length; i++ )
-        {
+
+        for (int i = 0; i < packageClasses.length; i++) {
             ClassDeclaration classDecl = packageClasses[i];
-            if ( CompilerUtils.isPageFlowClass( classDecl, getEnv() ) ) jpfClass = classDecl;
+            if (CompilerUtils.isPageFlowClass(classDecl, getEnv())) {
+                jpfClass = classDecl;
+                break;
+            }
         }
-        
+
         // Don't run these checks if there's no associated page flow controller (or if it's in error).
         if (jpfClass != null) {
             FlowControllerInfo fcInfo = new FlowControllerInfo( jpfClass );

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/PageFlowChecker.java Fri Feb  9 13:51:57 2007
@@ -114,15 +114,14 @@
     {
         // Make sure there are no other page flows in this package/directory.
         checkForOverlappingClasses( jpfClass, JPF_BASE_CLASS, JPF_FILE_EXTENSION_DOT, "error.overlapping-pageflows" );
-        
-        PackageDeclaration pkg = jpfClass.getPackage();
+
         File jpfFile = CompilerUtils.getSourceFile( jpfClass, true );
         File parentDir = jpfFile.getParentFile();
         
         //
         // Check the package name.
         //
-        String jpfPackageName = pkg.getQualifiedName();
+        String jpfPackageName = CompilerUtils.getPackageNameFromType(jpfClass);
         
         if ( jpfPackageName != null && jpfPackageName.length() > 0 )
         {
@@ -138,8 +137,7 @@
         // Issue a warning if the class name is the same as the parent package name.
         // This causes ambiguity when resolving inner classes.
         //
-        if ( jpfClass.getSimpleName().equals( pkg.getQualifiedName() ) )
-        {
+        if (jpfClass.getSimpleName().equals(jpfPackageName)) {
             getDiagnostics().addWarning( jpfClass, "warning.classname-same-as-package" );
         }
         

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/SharedFlowChecker.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/SharedFlowChecker.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/SharedFlowChecker.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/SharedFlowChecker.java Fri Feb  9 13:51:57 2007
@@ -43,7 +43,7 @@
         checkForOverlappingClasses( jclass, SHARED_FLOW_BASE_CLASS, SHARED_FLOW_FILE_EXTENSION_DOT,
                                     "error.overlapping-sharedflows" );
         
-        String pkg = jclass.getPackage().getQualifiedName();              
+        String pkg = CompilerUtils.getPackageNameFromType(jclass);              
         
         //
         // If it's Global.app, make sure the package is "global".

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java Fri Feb  9 13:51:57 2007
@@ -77,7 +77,7 @@
         super( jclass.getQualifiedName() );
         
         _jclass = jclass;
-        _containingPackage = jclass.getPackage().getQualifiedName();
+        _containingPackage = CompilerUtils.getPackageNameFromType(jclass);
         _sourceFile = sourceFile;
         _env = env;
         assert fcInfo != null;

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java?view=diff&rev=505517&r1=505516&r2=505517
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/WebappPathType.java Fri Feb  9 13:51:57 2007
@@ -195,8 +195,8 @@
         
         if ( filePath.endsWith( JPF_FILE_EXTENSION_DOT ) )
         {
-            String className = filePath.substring( 0, filePath.length() - JPF_FILE_EXTENSION_DOT.length() );
-            String pkg = outerClass.getPackage().getQualifiedName();
+            String className = filePath.substring(0, filePath.length() - JPF_FILE_EXTENSION_DOT.length());
+            String pkg = CompilerUtils.getPackageNameFromType(outerClass);
 
             // try to normalize the path
             boolean normalized = className.charAt(0) != '.';
@@ -230,8 +230,8 @@
                 // Use the package name to infer the relative path (from web content root) to the page flow directory.
                 String[] webContentRoots = CompilerUtils.getWebContentRoots( env );
                 String jpfParentRelativePath = "";
-                PackageDeclaration jpfPackage = outerClass.getPackage();
-                if ( jpfPackage != null ) jpfParentRelativePath = jpfPackage.getQualifiedName().replace( '.', '/' );
+                String jpfPackage = CompilerUtils.getPackageNameFromType(outerClass);
+                if (jpfPackage.length() > 0) jpfParentRelativePath = jpfPackage.replace('.', '/');
                 
                 for ( int i = 0; i < webContentRoots.length; i++ )
                 {