Initial retouche integration. designer_refactoring1_before_merge
authordeva@netbeans.org
Wed, 07 Feb 2007 00:38:27 +0000
changeset 170653689f709e
parent 16 d3f161b1509b
child 18 72b231a1a161
Initial retouche integration.
Following should work with this check-in
1) View the designer and outline upon project creation or open.
2) Add/remove components onto designer. You may see exceptions when you close and re-open the project with some components
3) View Navigation editor(read-only)
visualweb.insync/nbproject/project.properties
visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/Bean.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/BeanStructureScanner.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/BeansUnit.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/faces/FacesBean.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/ClassUtil.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/JavaClass.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/JavaUnit.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/ReadTaskWrapper.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/TreeMakerUtils.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/TreeUtils.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/WriteTaskWrapper.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/BeansDesignBean.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/ContextMethodHelper.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/DesignBeanNodeLookup.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/SourceLiveRoot.java
visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/FacesModel.java
visualweb.j2ee14classloaderprovider/src/org/netbeans/modules/visualweb/j2ee14classloaderprovider/J2EE14CommonClassloaderProvider.java
visualweb.j2ee15classloaderprovider/src/org/netbeans/modules/visualweb/j2ee15classloaderprovider/J2EE15CommonClassloaderProvider.java
     1.1 --- a/visualweb.insync/nbproject/project.properties	Tue Feb 06 18:59:29 2007 +0000
     1.2 +++ b/visualweb.insync/nbproject/project.properties	Wed Feb 07 00:38:27 2007 +0000
     1.3 @@ -21,6 +21,7 @@
     1.4  #${mdr/module.dir}/${nb.modules.dir}/ext/mdr.jar
     1.5  # Why doesn't the Xerces libs reference in project.xml achieve this?
     1.6  build.compiler.deprecation=false
     1.7 +javac.source=1.5
     1.8  javadoc.arch=${basedir}/arch/arch-insync.xml
     1.9  
    1.10  # XXX release55 hack only - to get around the build check on modules with no public packages.
     2.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/Bean.java	Tue Feb 06 18:59:29 2007 +0000
     2.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/Bean.java	Wed Feb 07 00:38:27 2007 +0000
     2.3 @@ -19,6 +19,7 @@
     2.4   */
     2.5  package org.netbeans.modules.visualweb.insync.beans;
     2.6  
     2.7 +import com.sun.org.apache.bcel.internal.classfile.JavaClass;
     2.8  import com.sun.rave.designtime.Position;
     2.9  import org.netbeans.modules.visualweb.insync.java.JMIUtils;
    2.10  import org.netbeans.modules.visualweb.insync.java.JMIMethodUtils;
    2.11 @@ -105,21 +106,9 @@
    2.12       * @param after existing bean that this bean's entries will be added after
    2.13       */
    2.14      public void insertEntry(Bean after) {
    2.15 -/*//NB6.0
    2.16 -        Class typec = beanInfo.getBeanDescriptor().getBeanClass();
    2.17 -        JMIUtils.beginTrans(true);
    2.18 -        boolean rollback = true;
    2.19 -        try {
    2.20 -            field = unit.getThisClass().addField(name, typec);
    2.21 -
    2.22 -            if (CREATE_GETTER) {
    2.23 -                getter = unit.getThisClass().addGetter(name, typec);
    2.24 -            }
    2.25 -
    2.26 -            if (CREATE_SETTER) {
    2.27 -                setter = unit.getThisClass().addSetter(name, typec);
    2.28 -            }
    2.29 -
    2.30 +        Class type = beanInfo.getBeanDescriptor().getBeanClass();
    2.31 +        unit.getThisClass().addProperty(name, type, CREATE_GETTER, CREATE_SETTER);
    2.32 +        /*
    2.33              String cmn = getCleanupMethod();
    2.34              if (cmn != null) {
    2.35                  Method method = unit.getCleanupMethod();
    2.36 @@ -128,11 +117,7 @@
    2.37                              method, getName(), cmn, new ArrayList());
    2.38                  }
    2.39              }
    2.40 -            rollback = false;
    2.41 -        }finally {
    2.42 -            JMIUtils.endTrans(rollback);
    2.43 -        }
    2.44 - //*/
    2.45 +         */
    2.46      }
    2.47  
    2.48      /**
    2.49 @@ -142,7 +127,6 @@
    2.50       * @return true iff the source entry for this bean was actually removed.
    2.51       */
    2.52      protected boolean removeEntry() {
    2.53 -/*//NB6.0
    2.54          assert Trace.trace("insync.beans", "B.removeEntry: " + this);
    2.55          boolean removed = false;
    2.56          for (Iterator i = properties.iterator(); i.hasNext(); ) {
    2.57 @@ -155,31 +139,19 @@
    2.58              removed |= es.removeEntry();
    2.59              i.remove();
    2.60          }
    2.61 -        
    2.62 -        JMIUtils.beginTrans(true);
    2.63 -        boolean rollback = true;
    2.64 -        try {
    2.65 -            String cmn = getCleanupMethod();  // the name of this bean's cleanup method, if any
    2.66 -            if (cmn != null && unit.getCleanupBlock() != null) {
    2.67 -                Statement cleanupCall = JMIMethodUtils.findStatement(unit.getCleanupBlock(), cmn, name);
    2.68 -                if (cleanupCall != null) {
    2.69 -                    JMIMethodUtils.removeStatement(unit.getCleanupBlock(), cleanupCall);
    2.70 -                }
    2.71 +        /*
    2.72 +        String cmn = getCleanupMethod();  // the name of this bean's cleanup method, if any
    2.73 +        if (cmn != null && unit.getCleanupBlock() != null) {
    2.74 +            Statement cleanupCall = JMIMethodUtils.findStatement(unit.getCleanupBlock(), cmn, name);
    2.75 +            if (cleanupCall != null) {
    2.76 +                JMIMethodUtils.removeStatement(unit.getCleanupBlock(), cleanupCall);
    2.77              }
    2.78 -            unit.getThisClass().removeField(field);
    2.79 -            unit.getThisClass().removeMethod(getter);
    2.80 -            unit.getThisClass().removeMethod(setter);
    2.81 -            rollback = false;
    2.82 -        }finally {
    2.83 -            JMIUtils.endTrans(rollback);
    2.84 -        }
    2.85 +        }*/
    2.86 +        unit.getThisClass().removeProperty(name);
    2.87 +
    2.88          removed |= true; //!CQ don't really know since clazz didn't tell us...
    2.89 -        field = null;
    2.90 -        getter = setter = null;
    2.91 -
    2.92 +        field = getter = setter = null;
    2.93          return removed;
    2.94 - //*/
    2.95 -        return false;
    2.96      }
    2.97  
    2.98      /**
     3.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/BeanStructureScanner.java	Tue Feb 06 18:59:29 2007 +0000
     3.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/BeanStructureScanner.java	Wed Feb 07 00:38:27 2007 +0000
     3.3 @@ -18,6 +18,7 @@
     3.4   */
     3.5  package org.netbeans.modules.visualweb.insync.beans;
     3.6  
     3.7 +import org.netbeans.api.java.source.ElementHandle;
     3.8  import org.netbeans.modules.visualweb.insync.UndoEvent;
     3.9  import org.netbeans.modules.visualweb.insync.java.JavaClassAdapter;
    3.10  import org.netbeans.modules.visualweb.insync.java.JavaUnit;
    3.11 @@ -130,10 +131,9 @@
    3.12       * @param requiredImports An array of classes to be imported, or null to import nothing
    3.13       * @return The existing or newly created method.
    3.14       */
    3.15 -    public  Object/*ExecutableElement*/ ensureEventMethod(MethodDescriptor md, String name, 
    3.16 +    public  ElementHandle ensureEventMethod(MethodDescriptor md, String name, 
    3.17                                      String defaultBody, String[] parameterNames,
    3.18                                      String[] requiredImports) {
    3.19 -/*// NB6.0
    3.20          Class retType = md.getMethod().getReturnType();
    3.21          String body = defaultBody;
    3.22          if(defaultBody == null) {
    3.23 @@ -155,31 +155,25 @@
    3.24              String eventName = NbBundle.getMessage(BeanStructureScanner.class, "EnsureEventMethod"); //NOI18N
    3.25              event = beansUnit.getModel().writeLock(eventName);
    3.26              boolean rollback = true;
    3.27 -            try {
    3.28 -                JMIUtils.beginTrans(true);
    3.29 +                /*
    3.30                  if (requiredImports != null) {
    3.31                      for (int i = 0; i < requiredImports.length; i++) {
    3.32                          JMIUtils.addImport(javaUnit.getJavaClass(), requiredImports[i]);
    3.33                      }
    3.34                  }
    3.35 +                 * */
    3.36                  
    3.37                  org.netbeans.modules.visualweb.insync.java.MethodInfo info =
    3.38                          new org.netbeans.modules.visualweb.insync.java.MethodInfo(name, retType, Modifier.PUBLIC,
    3.39                          pns, pts, body, null);
    3.40                  
    3.41 -                Method m = (Method)beansUnit.getThisClass().addMethod(info);
    3.42 -                rollback = false;
    3.43 -                return m;
    3.44 -            }finally {
    3.45 -                JMIUtils.endTrans(rollback);
    3.46 -            }
    3.47 +                return beansUnit.getThisClass().addMethod(info);
    3.48 +
    3.49          }finally {
    3.50              if(event != null) {
    3.51                  beansUnit.getModel().writeUnlock(event);
    3.52              }
    3.53          }
    3.54 - //*/
    3.55 -        return null;
    3.56      }
    3.57  
    3.58      /**
     4.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/BeansUnit.java	Tue Feb 06 18:59:29 2007 +0000
     4.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/beans/BeansUnit.java	Wed Feb 07 00:38:27 2007 +0000
     4.3 @@ -19,7 +19,7 @@
     4.4  package org.netbeans.modules.visualweb.insync.beans;
     4.5  
     4.6  import org.netbeans.modules.visualweb.insync.java.JMIUtils;
     4.7 -import org.netbeans.modules.visualweb.insync.java.JavaClassAdapter;
     4.8 +import org.netbeans.modules.visualweb.insync.java.JavaClass;
     4.9  import org.netbeans.modules.visualweb.insync.models.FacesModel;
    4.10  import java.beans.BeanInfo;
    4.11  import java.beans.Introspector;
    4.12 @@ -63,7 +63,7 @@
    4.13  
    4.14      protected String packageName;  // package this unit resides in. Same as junit.getPackage().getName()
    4.15  
    4.16 -    protected JavaClassAdapter javaClass;
    4.17 +    protected JavaClass javaClass;
    4.18  
    4.19      protected ParserAnnotation error;
    4.20  
    4.21 @@ -223,7 +223,7 @@
    4.22          // If the JavaUnit does not have a class defined in it, then I will re-use the same scanner
    4.23          // so that a similar class is re-created.
    4.24          if (getJavaUnit().getJavaClass() != null) {
    4.25 -            javaClass = new JavaClassAdapter(junit, getJavaUnit().getJavaClass());
    4.26 +            javaClass = getJavaUnit().getJavaClass();//new JavaClassAdapter(junit, getJavaUnit().getJavaClass());
    4.27              for(int i=0; i<FacesModel.managedBeanNames.length; i++) {
    4.28                  if(getThisClass().isSubTypeOf(FacesModel.managedBeanNames[i])) {
    4.29                      isPageBean = FacesModel.managedBeanIsPage[i];
    4.30 @@ -255,15 +255,15 @@
    4.31       * Bind beans & their properties, events and parents
    4.32       */
    4.33      protected void bind() {
    4.34 +        bindBeans();
    4.35  /*//NB6.0
    4.36 -        bindBeans();
    4.37          StatementBlock[] blocks = getInitBlocks();
    4.38          for(int i = 0; i < blocks.length; i++) {
    4.39              bindProperties(blocks[i]);
    4.40              bindEventSets(blocks[i]);
    4.41          }
    4.42 + //*/
    4.43          bindBeanParents();
    4.44 -//*/
    4.45      }
    4.46  
    4.47      //---------------------------------------------------------------------------------- Unit Output
    4.48 @@ -458,126 +458,39 @@
    4.49       * Run a second parent-child wiring pass
    4.50       */
    4.51      protected void bindBeans() {
    4.52 -/*//NB6.0
    4.53          beans.clear();
    4.54 -        try {
    4.55 -            JMIUtils.beginTrans(false);
    4.56 -            // scan methods for possible getters, & attempt to bind to the associated bean
    4.57 -            Method[] methods = javaClass.getMethods();
    4.58 -            for (int i = 0; i < methods.length; i++) {
    4.59 -                Bean b = bindBean(methods[i]);
    4.60 -                if (b != null)
    4.61 -                    beans.add(b);
    4.62 +        HashMap<String, String> props = javaClass.getPropertiesNamesAndTypes();
    4.63 +        for(String key : props.keySet()) {
    4.64 +            Bean bean = bindBean(key, props.get(key));
    4.65 +            if(bean != null) {
    4.66 +                beans.add(bean);
    4.67              }
    4.68 -        }finally {
    4.69 -            JMIUtils.endTrans();
    4.70          }
    4.71 - //*/
    4.72 -   }
    4.73 -
    4.74 -   /**
    4.75 -    * Run a pass over the beans to see if they need to do parent-child wiring
    4.76 -    */
    4.77 -   protected void bindBeanParents() {
    4.78 -       for (Iterator i = beans.iterator(); i.hasNext(); ) {
    4.79 -           Bean b = (Bean)i.next();
    4.80 -           Bean parent = b.bindParent();
    4.81 -           if (parent != null)
    4.82 -               parent.addChild(b, null);
    4.83 -       }
    4.84     }
    4.85  
    4.86      /**
    4.87 -     * Create a bean bound to a given accessor, but only if it truly represents a bean.
    4.88 -     *
    4.89 -     * @param field
    4.90 -     * @return the new bound bean if bindable, else null
    4.91 +     * Run a pass over the beans to see if they need to do parent-child wiring
    4.92       */
    4.93 -    protected Bean bindBean(Object/*ExecutableElement*/ getter) {
    4.94 -/*//NB6.0
    4.95 -        // can't be abstract or static, and must be public
    4.96 -        long modifiers = getter.getModifiers();
    4.97 -        if ((modifiers & (Modifier.ABSTRACT | Modifier.STATIC)) != 0
    4.98 -                || (modifiers & Modifier.PUBLIC) == 0)
    4.99 -            return null;
   4.100 -
   4.101 -        // must have zero parameters & some form of result (not a ctor)
   4.102 -        if (getter.getParameters().size() != 0 || getter.getType() == null)
   4.103 -            return null;
   4.104 -
   4.105 -        Type type = getter.getType();
   4.106 -        if(type.getName().equals("void"))
   4.107 -            return null;
   4.108 -        /*
   4.109 -        // can't have void result type, or no type which represents an <init> method
   4.110 -        if (getter.getResultType() == null || getter.getResultType().getSymbol() == null)
   4.111 -            return null;
   4.112 -        String type = getter.getResultType().getSymbol().getFullNameWithDims();
   4.113 -        if (type == null || type.equals("void"))  //NOI18N
   4.114 -            return null;
   4.115 -         ** /
   4.116 -
   4.117 -        // must have a getXxx style name (or isXxx for boolean)
   4.118 -        String name = Naming.propertyName(getter.getName(), type.getName().equals("boolean"));
   4.119 -        if (name == null)
   4.120 -            return null;
   4.121 -        
   4.122 -        // HACK During startup JMI/MDR does not correctly return the FQN for Classes from
   4.123 -        // java.lang. This probably happen because there is no explicit import required for
   4.124 -        // classes from java.lang.
   4.125 -        String typeName = type.getName();
   4.126 -        
   4.127 -        Type componentType = type;
   4.128 -        
   4.129 -        // if array find the component type
   4.130 -        while (componentType instanceof org.netbeans.jmi.javamodel.Array) {
   4.131 -            componentType = ((org.netbeans.jmi.javamodel.Array) componentType).getType();
   4.132 +    protected void bindBeanParents() {
   4.133 +        for (Iterator i = beans.iterator(); i.hasNext(); ) {
   4.134 +            Bean b = (Bean)i.next();
   4.135 +            Bean parent = b.bindParent();
   4.136 +            if (parent != null)
   4.137 +                parent.addChild(b, null);
   4.138          }
   4.139 -        
   4.140 +    }
   4.141 +    
   4.142 +    protected Bean bindBean(String name, String typeName) {
   4.143          // Scan all type/name pairs for later name generation
   4.144          scanName(typeName, name);
   4.145 -
   4.146 -        // Get matching field, but ignore fields that cannot be beans
   4.147 -        Field field = javaClass.getField(name);
   4.148 -        if (field != null) {
   4.149 -            long fm = field.getModifiers();
   4.150 -            if ((fm & Modifier.STATIC) != 0)
   4.151 -                field = null;
   4.152 -        }
   4.153 -
   4.154          // make sure we can obtain the bean's beaninfo
   4.155          BeanInfo bi = getBeanInfo(typeName);
   4.156          if (bi == null) {
   4.157 -            //If the project is open along with IDE open, MDR doesn't resolve the types
   4.158 -            //Example - we get the type name as String for java.lang.String
   4.159 -            //Therefore using a utility method to get the type
   4.160 -            if (componentType instanceof JavaClass) {
   4.161 -                Class clazz = JMIUtils.getType(typeName, getJavaUnit().getPackageName());
   4.162 -                if(clazz != null) {
   4.163 -                    bi = getBeanInfo(clazz, getClassLoader());
   4.164 -                }
   4.165 -            }
   4.166 -            if(bi == null) {
   4.167 -                return null;
   4.168 -            }
   4.169 +            return null;
   4.170          }
   4.171 -
   4.172 -        String sname = Naming.setterName(name);
   4.173 -        
   4.174 -        Method setter = javaClass.getMethod(
   4.175 -                sname, new Class[]{bi.getBeanDescriptor().getBeanClass()});
   4.176 -        assert Trace.trace("insync.beans", "BU.bindBean name:" + name + " getter:" + getter);  //NOI18N
   4.177 -
   4.178 -        // getter is required, but field and setter are optional
   4.179 -        if (getter != null) {
   4.180 -            return newBoundBean(bi, name, field, getter, setter);
   4.181 -        }
   4.182 -
   4.183 -        return null;
   4.184 - //*/
   4.185 -        return null;
   4.186 +        return newBoundBean(bi, name, null, null, null);
   4.187      }
   4.188 -
   4.189 +    
   4.190      /**
   4.191       * @param s
   4.192       * @return
   4.193 @@ -682,7 +595,7 @@
   4.194      /**
   4.195       * @return
   4.196       */
   4.197 -    public JavaClassAdapter getThisClass() {
   4.198 +    public JavaClass getThisClass() {
   4.199          return javaClass;
   4.200      }
   4.201  
     5.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/faces/FacesBean.java	Tue Feb 06 18:59:29 2007 +0000
     5.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/faces/FacesBean.java	Wed Feb 07 00:38:27 2007 +0000
     5.3 @@ -120,7 +120,7 @@
     5.4              if (parent instanceof UIComponent) {
     5.5                  String facetName = this.getFacetName();
     5.6                  if (facetName != null) {
     5.7 -                    ((UIComponent)parent).getFacets().put(facetName, instance);
     5.8 +                    ((UIComponent)parent).getFacets().put(facetName, (UIComponent)instance);
     5.9                  }
    5.10                  else {
    5.11                      int index = pos != null ? pos.getIndex() : -1;
     6.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/ClassUtil.java	Tue Feb 06 18:59:29 2007 +0000
     6.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/ClassUtil.java	Wed Feb 07 00:38:27 2007 +0000
     6.3 @@ -69,7 +69,6 @@
     6.4          return Class.forName(type, true, cl);
     6.5      }
     6.6  
     6.7 -
     6.8      /**
     6.9       * Get the actual class given its type. The type may be a primitive and/or it
    6.10       * may be an array.
    6.11 @@ -82,71 +81,4 @@
    6.12          //Use the project classloader to load the class
    6.13          return getClass(type, FacesContainer.getCurrentLoader(ClassUtil.class));
    6.14      }
    6.15 -
    6.16 -    static HashMap arrayTypeKeyHash = new HashMap();
    6.17 -    static {
    6.18 -        arrayTypeKeyHash.put("B", "byte");   //NOI18N
    6.19 -        arrayTypeKeyHash.put("C", "char");   //NOI18N
    6.20 -        arrayTypeKeyHash.put("D", "double");   //NOI18N
    6.21 -        arrayTypeKeyHash.put("F", "float");   //NOI18N
    6.22 -        arrayTypeKeyHash.put("I", "int");   //NOI18N
    6.23 -        arrayTypeKeyHash.put("J", "long");   //NOI18N
    6.24 -        arrayTypeKeyHash.put("S", "short");   //NOI18N
    6.25 -        arrayTypeKeyHash.put("Z", "boolean");   //NOI18N
    6.26 -        arrayTypeKeyHash.put("V", "void");   //NOI18N
    6.27 -    }
    6.28 -
    6.29 -    /*
    6.30 -     * Returns the simple name of the underlying class as given
    6.31 -     * in the source code.
    6.32 -     */
    6.33 -    public static String getSimpleName(String tn) {
    6.34 -        if (isArray(tn)) {
    6.35 -            String retStr = getArrayType(tn);
    6.36 -            for (int i = 0; i < getArrayDimension(tn); i++) {
    6.37 -                retStr += "[]";   //NOI18N
    6.38 -            }
    6.39 -            return retStr;
    6.40 -        }
    6.41 -        return tn;
    6.42 -    }
    6.43 -
    6.44 -    /*
    6.45 -     * Returns array dimension given its internal form of the name
    6.46 -     */
    6.47 -    public static int getArrayDimension(String tn) {
    6.48 -        int dim = 0;
    6.49 -        while (tn.startsWith("[")) {   //NOI18N
    6.50 -            tn = tn.substring(1);
    6.51 -            dim++;
    6.52 -        }
    6.53 -        return dim;
    6.54 -    }
    6.55 -
    6.56 -    /*
    6.57 -     * Checks if the given string in internal form represents an array
    6.58 -     */
    6.59 -    public static boolean isArray(String tn) {
    6.60 -        return tn.startsWith("[") ? true: false;
    6.61 -    }
    6.62 -
    6.63 -    /*
    6.64 -     * Returns array element type given its internal form of the name
    6.65 -     */    
    6.66 -    public static String getArrayType(String tn) {
    6.67 -        if (isArray(tn)) {   
    6.68 -            while (tn.startsWith("[")) {   //NOI18N
    6.69 -                tn = tn.substring(1);
    6.70 -            }
    6.71 -            if (tn.startsWith("L")) {   //NOI18N
    6.72 -                tn = tn.substring(1);
    6.73 -                tn = tn.substring(0, tn.length() - 1);
    6.74 -            }
    6.75 -            else {
    6.76 -                char typeKey = tn.charAt(0);
    6.77 -                tn = (String)arrayTypeKeyHash.get("" + typeKey);   //NOI18N
    6.78 -            }
    6.79 -        }
    6.80 -        return tn;
    6.81 -    }
    6.82  }
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/JavaClass.java	Wed Feb 07 00:38:27 2007 +0000
     7.3 @@ -0,0 +1,482 @@
     7.4 +/*
     7.5 + * The contents of this file are subject to the terms of the Common Development
     7.6 + * and Distribution License (the License). You may not use this file except in
     7.7 + * compliance with the License.
     7.8 + *
     7.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    7.10 + * or http://www.netbeans.org/cddl.txt.
    7.11 + *
    7.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
    7.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
    7.14 + * If applicable, add the following below the CDDL Header, with the fields
    7.15 + * enclosed by brackets [] replaced by your own identifying information:
    7.16 + * "Portions Copyrighted [year] [name of copyright owner]"
    7.17 + *
    7.18 + * The Original Software is NetBeans. The Initial Developer of the Original
    7.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
    7.20 + * Microsystems, Inc. All Rights Reserved.
    7.21 + */
    7.22 +
    7.23 +package org.netbeans.modules.visualweb.insync.java;
    7.24 +
    7.25 +import com.sun.rave.designtime.ContextMethod;
    7.26 +import com.sun.source.tree.ClassTree;
    7.27 +import com.sun.source.tree.CompilationUnitTree;
    7.28 +import com.sun.source.tree.MethodTree;
    7.29 +import com.sun.source.tree.Tree;
    7.30 +import com.sun.source.tree.VariableTree;
    7.31 +import java.util.ArrayList;
    7.32 +import java.util.Collections;
    7.33 +import java.util.HashMap;
    7.34 +import java.util.List;
    7.35 +import java.util.ListIterator;
    7.36 +import java.util.Set;
    7.37 +import javax.lang.model.element.ExecutableElement;
    7.38 +import javax.lang.model.element.Modifier;
    7.39 +import javax.lang.model.element.TypeElement;
    7.40 +import javax.lang.model.element.VariableElement;
    7.41 +import javax.lang.model.type.ArrayType;
    7.42 +import javax.lang.model.type.DeclaredType;
    7.43 +import javax.lang.model.type.TypeKind;
    7.44 +import javax.lang.model.type.TypeMirror;
    7.45 +import javax.lang.model.util.ElementFilter;
    7.46 +import org.netbeans.api.java.source.CompilationInfo;
    7.47 +import org.netbeans.api.java.source.ElementHandle;
    7.48 +import org.netbeans.api.java.source.TreeMaker;
    7.49 +import org.netbeans.api.java.source.WorkingCopy;
    7.50 +import org.netbeans.api.project.FileOwnerQuery;
    7.51 +import org.netbeans.modules.visualweb.insync.beans.Naming;
    7.52 +import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectConstants;
    7.53 +import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
    7.54 +import org.openide.filesystems.FileObject;
    7.55 +
    7.56 +/**
    7.57 + *
    7.58 + * @author jdeva
    7.59 + */
    7.60 +public class JavaClass {
    7.61 +    ElementHandle<TypeElement> typeElementHandle;
    7.62 +    //JavaUnit javaUnit;    //To obtain FileObject/JavaSource
    7.63 +    FileObject fObj;        //Temporary till we plug this into insync
    7.64 +    String name;
    7.65 +    
    7.66 +    /** Creates a new instance of TypeElementAdapter */
    7.67 +    public JavaClass(TypeElement element, FileObject fObj) {
    7.68 +        this.fObj = fObj;
    7.69 +        typeElementHandle = ElementHandle.create(element);
    7.70 +        name = element.getQualifiedName().toString();
    7.71 +    }
    7.72 +    
    7.73 +    /*
    7.74 +     * Returns short name for the class
    7.75 +     */ 
    7.76 +    public String getShortName() {
    7.77 +        return name == null ? null : name.substring(name.lastIndexOf('.')+1);
    7.78 +    }
    7.79 +    
    7.80 +    /*
    7.81 +     * Returns FQN for the class
    7.82 +     */     
    7.83 +    public String getName() {
    7.84 +        return name;
    7.85 +    }
    7.86 +    
    7.87 +    /*
    7.88 +     * Checks if the passed in type as string is a super type of this class
    7.89 +     */ 
    7.90 +    public boolean isSubTypeOf(final String typeName) {
    7.91 +         Boolean result = (Boolean)ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
    7.92 +            public Object run(CompilationInfo cinfo) {
    7.93 +                TypeElement typeElement = typeElementHandle.resolve(cinfo);
    7.94 +                TypeMirror superType = cinfo.getElements().getTypeElement(typeName).asType();
    7.95 +                if(superType.getKind() == TypeKind.DECLARED &&
    7.96 +                   cinfo.getTypes().isSubtype(typeElement.asType(), superType)) {
    7.97 +                        return Boolean.TRUE;
    7.98 +                }
    7.99 +                return Boolean.FALSE;
   7.100 +            }
   7.101 +        }, fObj); 
   7.102 +        return result.booleanValue();
   7.103 +    }    
   7.104 +    
   7.105 +    /*
   7.106 +     * Return all the methods
   7.107 +     */
   7.108 +    public List<ExecutableElement> getMethods() {
   7.109 +        return getMethods(null, null, null);
   7.110 +    }
   7.111 +    
   7.112 +    /*
   7.113 +     * Return all methods that has same return type and parameter types as 
   7.114 +     * specified by arguments
   7.115 +     */ 
   7.116 +    public List<String> getMethodNames(Class[] params, Class retType) {
   7.117 +        List<String> names = new ArrayList<String>();
   7.118 +        for(ExecutableElement method : getMethods(null, params, retType)) {
   7.119 +            names.add(method.getSimpleName().toString());
   7.120 +        }
   7.121 +        return names;
   7.122 +    }    
   7.123 +    
   7.124 +    /*
   7.125 +     * For all the properties found in a class, its names and types are returned in a hashmap
   7.126 +     */    
   7.127 +    public HashMap<String, String> getPropertiesNamesAndTypes() {
   7.128 +        HashMap<String, String> types = (HashMap<String, String>)ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
   7.129 +            public Object run(CompilationInfo cinfo) {
   7.130 +                TypeElement typeElement = typeElementHandle.resolve(cinfo);
   7.131 +                HashMap<String, String> types = new HashMap<String, String>();
   7.132 +                for(ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
   7.133 +                    if(isBeanGetter(method)) {
   7.134 +                        TypeMirror type = method.getReturnType();
   7.135 +                        // In case of array get the component type;
   7.136 +                        if(type.getKind() == TypeKind.ARRAY) {
   7.137 +                            type = ((ArrayType)type).getComponentType();
   7.138 +                        }
   7.139 +                        String typeName = type.toString();
   7.140 +                        // In case of parameterized type, use the raw type
   7.141 +                        if(isParameterizedType(type)) {
   7.142 +                            typeName = cinfo.getTypes().erasure(type).toString();
   7.143 +                        }
   7.144 +                        String name = Naming.propertyName(method.getSimpleName().toString(), typeName.equals("boolean"));
   7.145 +                        types.put(name, typeName);
   7.146 +                    }
   7.147 +                }
   7.148 +                return types;
   7.149 +            }
   7.150 +        }, fObj);
   7.151 +        return types;
   7.152 +    }
   7.153 +    
   7.154 +    /* 
   7.155 +     * Returns a handle corresponding to a field
   7.156 +     */
   7.157 +    public ElementHandle getField(final String name) {
   7.158 +        return (ElementHandle)ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
   7.159 +            public Object run(CompilationInfo cinfo) {
   7.160 +                VariableElement field = getField(cinfo, name);
   7.161 +                if(field != null) {
   7.162 +                    return ElementHandle.create(field);
   7.163 +                }
   7.164 +                return null;
   7.165 +            }
   7.166 +        }, fObj);
   7.167 +    }
   7.168 +    
   7.169 +    /*
   7.170 +     * Inserts a field, getter and setter given the property name and type, boolean 
   7.171 +     * flags to control the addition of getter/setter
   7.172 +     */
   7.173 +    public void addProperty(final String name, final Class type, final boolean getter, final boolean setter) {
   7.174 +        WriteTaskWrapper.execute( new WriteTaskWrapper.Write() {
   7.175 +            public Object run(WorkingCopy wc) {
   7.176 +                TreeMaker make = wc.getTreeMaker();
   7.177 +                TypeElement typeElement = typeElementHandle.resolve(wc);
   7.178 +                ClassTree ctree = wc.getTrees().getTree(typeElement);
   7.179 +                ClassTree newctree = ctree;
   7.180 +                TreeMakerUtils utils = new TreeMakerUtils(wc);
   7.181 +                VariableTree vtree = utils.createPropertyField(name, type);
   7.182 +                
   7.183 +                // Find the constructor
   7.184 +                // TBD: index selection logic, i.e where to add the field, getter and setter
   7.185 +                // For now insert before the ctor
   7.186 +                Tree ctor = getPublicConstructor(wc, ctree);
   7.187 +                newctree = make.insertClassMember(newctree, ctree.getMembers().indexOf(ctor), vtree);
   7.188 +                MethodTree mtree = null;
   7.189 +                if(getter) {
   7.190 +                    mtree = utils.createPropertyGetterMethod(name, type);
   7.191 +                    newctree = make.insertClassMember(newctree, newctree.getMembers().indexOf(ctor), mtree);
   7.192 +                }
   7.193 +                if(setter) {
   7.194 +                    mtree = utils.createPropertySetterMethod(name, type);
   7.195 +                    newctree = make.insertClassMember(newctree, newctree.getMembers().indexOf(ctor), mtree);
   7.196 +                }
   7.197 +                wc.rewrite(ctree, newctree);
   7.198 +                return null;
   7.199 +            }
   7.200 +        }, fObj);    
   7.201 +    }
   7.202 +    
   7.203 +    /*
   7.204 +     * Deletes a field, getter and setter given the property name and type, boolean 
   7.205 +     * flags to control the addition of getter/setter
   7.206 +     */    
   7.207 +    public void removeProperty(final String name) {
   7.208 +        WriteTaskWrapper.execute( new WriteTaskWrapper.Write() {
   7.209 +            public Object run(WorkingCopy wc) {
   7.210 +                TreeMaker make = wc.getTreeMaker();
   7.211 +                TypeElement typeElement = typeElementHandle.resolve(wc);
   7.212 +                ClassTree ctree = wc.getTrees().getTree(typeElement);
   7.213 +                ClassTree newctree = ctree;
   7.214 +                TreeMakerUtils utils = new TreeMakerUtils(wc);
   7.215 +                VariableElement varElem = getField(wc, name);
   7.216 +                if(varElem != null) {
   7.217 +                    newctree = make.removeClassMember(ctree, wc.getTrees().getTree(varElem));
   7.218 +                }
   7.219 +                ExecutableElement getElem = getMethod(wc, Naming.getterName(name), new Class[0]);
   7.220 +                TypeMirror type = null;
   7.221 +                if(getElem != null) {
   7.222 +                    type = getElem.getReturnType();
   7.223 +                    newctree = make.removeClassMember(newctree, wc.getTrees().getTree(getElem));
   7.224 +                    ExecutableElement setElem = getMethod(wc, Naming.setterName(name), Collections.<TypeMirror>singletonList(type));
   7.225 +                    if(setElem != null) {
   7.226 +                        newctree = make.removeClassMember(newctree, wc.getTrees().getTree(setElem));
   7.227 +                    }
   7.228 +                }
   7.229 +                wc.rewrite(ctree, newctree);
   7.230 +                return null;
   7.231 +            }
   7.232 +        }, fObj);    
   7.233 +    }    
   7.234 +
   7.235 +    private ElementHandle<ExecutableElement> addMethod(final ContextMethod cm, final String retType) {
   7.236 +        return (ElementHandle<ExecutableElement>)WriteTaskWrapper.execute( new WriteTaskWrapper.Write() {
   7.237 +            public Object run(WorkingCopy wc) {
   7.238 +                ExecutableElement elem = getMethod(wc, cm.getName(), cm.getParameterTypes());
   7.239 +                if(elem == null) {
   7.240 +                    TreeMaker make = wc.getTreeMaker();
   7.241 +                    TypeElement typeElement = typeElementHandle.resolve(wc);
   7.242 +                    TreeMakerUtils utils = new TreeMakerUtils(wc);
   7.243 +                    ClassTree ctree = wc.getTrees().getTree(typeElement);
   7.244 +                    ClassTree newctree = ctree;
   7.245 +                    MethodTree mtree = utils.createMethod(cm, retType);
   7.246 +                    newctree = make.addClassMember(ctree, mtree);
   7.247 +                    wc.rewrite(ctree, newctree);
   7.248 +                    elem = (ExecutableElement)wc.getTrees().getElement(TreeUtils.getTreePath(wc, mtree));
   7.249 +                }
   7.250 +                return ElementHandle.create(elem);
   7.251 +            }
   7.252 +        }, fObj);            
   7.253 +    }
   7.254 +    
   7.255 +   public ElementHandle<ExecutableElement> addMethod(ContextMethod cm) {
   7.256 +        String retTypeName = null;
   7.257 +        if(cm.getReturnType() != null) {
   7.258 +            retTypeName = cm.getReturnType().getCanonicalName();
   7.259 +        }
   7.260 +        return addMethod(cm, retTypeName);
   7.261 +    }
   7.262 +    
   7.263 +
   7.264 +    public ElementHandle<ExecutableElement> addMethod(MethodInfo mInfo) {
   7.265 +        return addMethod(mInfo, mInfo.getReturnTypeName());
   7.266 +    }
   7.267 +    
   7.268 +    /*
   7.269 +     * Removes a method corresponding to passed in element handle
   7.270 +     */     
   7.271 +    public void removeMethod(final ElementHandle<ExecutableElement> methodElementHandle) {
   7.272 +         WriteTaskWrapper.execute( new WriteTaskWrapper.Write() {
   7.273 +            public Object run(WorkingCopy wc) {
   7.274 +                ExecutableElement execElement = methodElementHandle.resolve(wc);
   7.275 +                TypeElement typeElement = typeElementHandle.resolve(wc);
   7.276 +                ClassTree ctree = wc.getTrees().getTree(typeElement);
   7.277 +                ClassTree newctree = ctree;
   7.278 +                newctree = wc.getTreeMaker().removeClassMember(ctree, wc.getTrees().getTree(execElement));
   7.279 +                wc.rewrite(ctree, newctree);
   7.280 +                return null;
   7.281 +            }
   7.282 +        }, fObj);        
   7.283 +    }    
   7.284 +    
   7.285 +    /*
   7.286 +     * Returns the first public constructor
   7.287 +     */ 
   7.288 +    public MethodTree getPublicConstructor(CompilationInfo cinfo, ClassTree ctree) {
   7.289 +        for(Tree tree : ctree.getMembers()) {
   7.290 +            if(Tree.Kind.METHOD == tree.getKind()) {
   7.291 +                MethodTree mtree = (MethodTree)tree;
   7.292 +                if(mtree.getName().toString().equals("<init>") &&
   7.293 +                        !cinfo.getTreeUtilities().isSynthetic(TreeUtils.getTreePath(cinfo, ctree))) {
   7.294 +                    return mtree;
   7.295 +                }
   7.296 +            }
   7.297 +        }
   7.298 +        return null;
   7.299 +    }
   7.300 +    
   7.301 +    /*
   7.302 +     * Returns a element handle corresponding to a method by given name and parameter types
   7.303 +     */     
   7.304 +    public ElementHandle<ExecutableElement> getMethod(final String name, final Class[] params) {
   7.305 +        return (ElementHandle<ExecutableElement>)ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
   7.306 +            public Object run(CompilationInfo cinfo) {
   7.307 +                return ElementHandle.<ExecutableElement>create(getMethod(cinfo, name, params));
   7.308 +            }
   7.309 +        }, fObj);
   7.310 +    }
   7.311 +    
   7.312 +    /*
   7.313 +     * Returns a element corresponding to a method by given name and parameter types
   7.314 +     */     
   7.315 +    private ExecutableElement getMethod(CompilationInfo cinfo, String name, Class[] params) {
   7.316 +        List<ExecutableElement> methods = getMethods(cinfo, name, params, null);
   7.317 +        return (methods.size() == 1) ? methods.get(0) : null;
   7.318 +    }
   7.319 +    
   7.320 +    /*
   7.321 +     * Returns a element corresponding to a method by given name and parameter types(TypeMirror)
   7.322 +     */
   7.323 +    private ExecutableElement getMethod(CompilationInfo cinfo, String name, List<? extends TypeMirror> paramTypes) {
   7.324 +        TypeElement typeElement = typeElementHandle.resolve(cinfo);
   7.325 +        for(ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
   7.326 +            if( (name == null || method.getSimpleName().toString().equals(name)) &&
   7.327 +                    (paramTypes == null || matchTypes(cinfo, method.getParameters(), paramTypes))) {
   7.328 +                return method;
   7.329 +            }
   7.330 +        }
   7.331 +        return null;
   7.332 +    }    
   7.333 +    
   7.334 +    /*
   7.335 +     *  Returns all methods that match the passed in name, parameter types and return type
   7.336 +     */ 
   7.337 +    private List<ExecutableElement> getMethods(final String name, final Class[] params, final Class retType) {
   7.338 +         return (List<ExecutableElement>)ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
   7.339 +            public Object run(CompilationInfo cinfo) {
   7.340 +                return getMethods(cinfo, name, params, retType);
   7.341 +            }
   7.342 +        }, fObj);
   7.343 +     }
   7.344 +    
   7.345 +    /*
   7.346 +     * Returns all methods that match the passed in name, parameter types and return type
   7.347 +     */ 
   7.348 +    private List<ExecutableElement> getMethods(CompilationInfo cinfo, String name, Class[] params, Class retType) {
   7.349 +        List<ExecutableElement> methods = new ArrayList<ExecutableElement>();
   7.350 +        TypeElement typeElement = typeElementHandle.resolve(cinfo);
   7.351 +        for(ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
   7.352 +            if( (name == null || method.getSimpleName().toString().equals(name)) &&
   7.353 +                    (params == null || matchTypes(cinfo, method.getParameters(), params)) &&
   7.354 +                    (retType == null || matchType(cinfo, method.getReturnType(), retType))) {
   7.355 +                methods.add(method);
   7.356 +            }
   7.357 +        }
   7.358 +        return methods;
   7.359 +    }
   7.360 +    
   7.361 +    /*
   7.362 +     * Returns a element corresponding to a field by given name
   7.363 +     */ 
   7.364 +    private VariableElement getField(CompilationInfo cinfo, String name) {
   7.365 +        TypeElement typeElement = typeElementHandle.resolve(cinfo);
   7.366 +        for(VariableElement var : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
   7.367 +            if(var.getSimpleName().toString().equals(name)) {
   7.368 +                return var;
   7.369 +            }
   7.370 +        }
   7.371 +        return null;
   7.372 +    }    
   7.373 +    
   7.374 +    /*
   7.375 +     * Returns true if the type matches cls type
   7.376 +     */    
   7.377 +    private boolean matchType(CompilationInfo cinfo, TypeMirror type, Class cls) {
   7.378 +        String typeName = type.toString();
   7.379 +        //Use the raw type if the type represents paramaterized type
   7.380 +        TypeMirror compType = type;
   7.381 +        if(type.getKind() == TypeKind.ARRAY) {
   7.382 +            compType = ((ArrayType)type).getComponentType();
   7.383 +        }
   7.384 +        if(isParameterizedType(compType)) {
   7.385 +            typeName = cinfo.getTypes().erasure(type).toString();
   7.386 +        }
   7.387 +        if(cls.getCanonicalName().equals(typeName)) {
   7.388 +            return true;
   7.389 +        }
   7.390 +        return false;
   7.391 +    }
   7.392 +    
   7.393 +    /*
   7.394 +     * Returns true if the variable elements types matches params types
   7.395 +     */
   7.396 +    private boolean matchTypes(CompilationInfo cinfo, List<? extends VariableElement> varElems, Class[] params) {
   7.397 +        if(varElems.size() == params.length) {
   7.398 +            int i = 0;
   7.399 +            for(VariableElement varElem : varElems) {
   7.400 +                if(!matchType(cinfo, varElem.asType(), params[i++])) {
   7.401 +                    return false;
   7.402 +                }
   7.403 +            }
   7.404 +            return true;
   7.405 +        }
   7.406 +        return false;
   7.407 +    }
   7.408 +    
   7.409 +    /*
   7.410 +     * Returns true if the variable elements types matches params types
   7.411 +     */
   7.412 +    private boolean matchTypes(CompilationInfo cinfo, List<? extends VariableElement> varElems, List<? extends TypeMirror> paramTypes) {
   7.413 +        if(varElems.size() == paramTypes.size()) {
   7.414 +            ListIterator<? extends VariableElement> elemsIter = varElems.listIterator();
   7.415 +            ListIterator<? extends TypeMirror> typesIter = paramTypes.listIterator();
   7.416 +            while(elemsIter.hasNext()) {
   7.417 +                if(!cinfo.getTypes().isSameType(elemsIter.next().asType(), typesIter.next())) {
   7.418 +                    return false;
   7.419 +                }
   7.420 +            }
   7.421 +            return true;
   7.422 +        }
   7.423 +        return false;
   7.424 +    }    
   7.425 +    
   7.426 +    /*
   7.427 +     * Returns true if the supplied method qualifies as a bean getter method
   7.428 +     */
   7.429 +    private boolean isBeanGetter(ExecutableElement method) {
   7.430 +        Set<Modifier> mods = method.getModifiers();
   7.431 +        // Must be public and can't be abstract or static
   7.432 +        if(!mods.contains(Modifier.PUBLIC) || 
   7.433 +            mods.contains(Modifier.STATIC) || 
   7.434 +            mods.contains(Modifier.ABSTRACT)) {
   7.435 +            return false;
   7.436 +        }
   7.437 +        
   7.438 +        // Must have zero parameters
   7.439 +        if(method.getParameters().size() > 0) {
   7.440 +            return false;
   7.441 +        }
   7.442 +        
   7.443 +        // Return type should be non void
   7.444 +        TypeMirror type = method.getReturnType();
   7.445 +        if(type.getKind() == TypeKind.VOID) {
   7.446 +            return false;
   7.447 +        }
   7.448 +        
   7.449 +        // Check if it is a valid getter name
   7.450 +        String name = Naming.propertyName(method.getSimpleName().toString(), 
   7.451 +                type.toString().equals("boolean"));
   7.452 +        if (name == null)
   7.453 +            return false;
   7.454 +        
   7.455 +        return true;
   7.456 +    }
   7.457 +    
   7.458 +    /*
   7.459 +     * Returns true if the type represents a parameterized type
   7.460 +     */ 
   7.461 +    private boolean isParameterizedType(TypeMirror type) {
   7.462 +        if(type.getKind() == TypeKind.DECLARED) {
   7.463 +            DeclaredType declType = (DeclaredType)type;
   7.464 +            if(declType.getTypeArguments().size() > 0) {
   7.465 +                return true;
   7.466 +            }
   7.467 +        }
   7.468 +        return false;
   7.469 +    }
   7.470 +    
   7.471 +    /*
   7.472 +     * Returns the TypeElement wrapper for public class in the given file
   7.473 +     */
   7.474 +    public static JavaClass getJavaClass(final FileObject fObj) {
   7.475 +        return (JavaClass)ReadTaskWrapper.execute(new ReadTaskWrapper.Read() {
   7.476 +            public Object run(CompilationInfo cinfo) {
   7.477 +                CompilationUnitTree cu = cinfo.getCompilationUnit();
   7.478 +                String pkgName = JsfProjectUtils.getProjectProperty(FileOwnerQuery.getOwner(fObj), 
   7.479 +                        JsfProjectConstants.PROP_JSF_PAGEBEAN_PACKAGE);
   7.480 +                TypeElement element = cinfo.getElements().getTypeElement(pkgName + "." + fObj.getName());
   7.481 +                return new JavaClass(element, fObj);
   7.482 +            }
   7.483 +        }, fObj);        
   7.484 +    }
   7.485 +}
     8.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/JavaUnit.java	Tue Feb 06 18:59:29 2007 +0000
     8.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/JavaUnit.java	Wed Feb 07 00:38:27 2007 +0000
     8.3 @@ -22,13 +22,14 @@
     8.4  import java.io.OutputStream;
     8.5  import java.io.PrintWriter;
     8.6  import java.io.Writer;
     8.7 -import java.lang.reflect.Modifier;
     8.8  import java.net.URLClassLoader;
     8.9  import java.util.ArrayList;
    8.10  import java.util.List;
    8.11 -import java.util.ListIterator;
    8.12 +import java.util.Locale;
    8.13  
    8.14  import javax.swing.event.DocumentEvent;
    8.15 +import javax.tools.Diagnostic;
    8.16 +import org.netbeans.api.java.source.CompilationInfo;
    8.17  
    8.18  import org.openide.filesystems.FileObject;
    8.19  import org.openide.util.Lookup;
    8.20 @@ -37,6 +38,7 @@
    8.21  import org.netbeans.modules.visualweb.insync.ParserAnnotation;
    8.22  import org.netbeans.modules.visualweb.insync.SourceUnit;
    8.23  import org.netbeans.modules.visualweb.insync.UndoManager;
    8.24 +import org.netbeans.modules.visualweb.insync.Unit.State;
    8.25  import org.netbeans.modules.visualweb.insync.Util;
    8.26  
    8.27  /**
    8.28 @@ -46,11 +48,9 @@
    8.29   */
    8.30  public class JavaUnit extends SourceUnit {
    8.31  
    8.32 -    // project state needed for javac parser
    8.33      URLClassLoader classLoader;
    8.34 -    String sourcepath;
    8.35      private boolean markSourceDirty = true;
    8.36 -    ParserAnnotation[] errors;
    8.37 +    ParserAnnotation[] errors = ParserAnnotation.EMPTY_ARRAY;
    8.38  
    8.39      //--------------------------------------------------------------------------------- Construction
    8.40  
    8.41 @@ -59,7 +59,6 @@
    8.42       */
    8.43      public JavaUnit(FileObject fobj, URLClassLoader cl, UndoManager undoManager) {
    8.44          super(fobj, undoManager);
    8.45 -        setClassLoader(cl);
    8.46          //Trace.enableTraceCategory("insync.java");
    8.47      }
    8.48  
    8.49 @@ -74,66 +73,28 @@
    8.50  
    8.51      //---------------------------------------------------------------------------------------- Input
    8.52  
    8.53 -    /**
    8.54 -     *
    8.55 -     */
    8.56 -    public void setClassLoader(URLClassLoader cl) {
    8.57 -        classLoader = cl != null
    8.58 -                ? cl
    8.59 -                : (URLClassLoader)Lookup.getDefault().lookup(ClassLoader.class);
    8.60 -       //!CQ TODO: could build Paths here based on classLoader's class paths...
    8.61 +    protected void read(char[] cbuf, int len) {
    8.62 +        
    8.63      }
    8.64 -
    8.65 -    /**
    8.66 -     *
    8.67 -     */
    8.68 -    public void setSourcepath(String sp) {
    8.69 -        sourcepath = sp;
    8.70 -    }
    8.71 -
    8.72 -   protected void read(char[] cbuf, int len) {
    8.73 -
    8.74 -   }
    8.75 -
    8.76 +    
    8.77      /**
    8.78       * Read the errors in source
    8.79       */
    8.80      protected void readErrors() {
    8.81 -/*//NB6.0
    8.82 -        JMIUtils.beginTrans(true);
    8.83 -        try {
    8.84 -            Resource res = JavaModel.getResource(fobj);
    8.85 -            List errorsList = res.getErrors();
    8.86 -            int size = errorsList.size();
    8.87 - 
    8.88 -            if (size == 0) {
    8.89 -                errors = ParserAnnotation.EMPTY_ARRAY;
    8.90 -                return;
    8.91 +        ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
    8.92 +            public Object run(CompilationInfo cinfo) {
    8.93 +                List<ParserAnnotation> parserAnnotationsList = new ArrayList<ParserAnnotation>();
    8.94 +                for(Diagnostic diagnostic : cinfo.getDiagnostics()) {
    8.95 +                    if(diagnostic.getKind() == Diagnostic.Kind.ERROR) {
    8.96 +                        ParserAnnotation annotation = new ParserAnnotation(diagnostic.getMessage(Locale.getDefault()),
    8.97 +                                fobj, (int)diagnostic.getLineNumber(), (int)diagnostic.getColumnNumber());
    8.98 +                        parserAnnotationsList.add(annotation);
    8.99 +                    }
   8.100 +                }
   8.101 +                errors = parserAnnotationsList.toArray(ParserAnnotation.EMPTY_ARRAY);
   8.102 +                return null;
   8.103              }
   8.104 - 
   8.105 -            List parserAnnotationsList = new ArrayList();
   8.106 -            for (int i = 0; i < size; i++) {
   8.107 -                ErrorInfo info = (ErrorInfo)errorsList.get(i);
   8.108 -                // Only show errors
   8.109 -                if (ErrorTypeEnum.ERROR.equals(info.getSeverity())) {
   8.110 -                    ParserAnnotation annotation = new ParserAnnotation(info.getDescription(),
   8.111 -                            fobj, info.getLineNumber(), info.getColumn());
   8.112 -                    parserAnnotationsList.add(annotation);
   8.113 -                }
   8.114 -            }
   8.115 - 
   8.116 -            // no errors found
   8.117 -            if (parserAnnotationsList.size() == 0) {
   8.118 -                errors = ParserAnnotation.EMPTY_ARRAY;
   8.119 -                return;
   8.120 -            }
   8.121 - 
   8.122 -            errors = new ParserAnnotation[parserAnnotationsList.size()];
   8.123 -            parserAnnotationsList.toArray(errors);
   8.124 -        }finally {
   8.125 -            JMIUtils.endTrans();
   8.126 -        }
   8.127 -//*/
   8.128 +        }, fobj);
   8.129      }
   8.130  
   8.131      /**
   8.132 @@ -187,48 +148,17 @@
   8.133      /*
   8.134       * Returns the public class in the file JavaUnit represents
   8.135       */
   8.136 -    public Object/*TypeElement or ClassType*/ getJavaClass() {
   8.137 -/*//NB6.0
   8.138 -        // get the resource corresponding to a given file
   8.139 -        JMIUtils.beginTrans(false);
   8.140 -        try {
   8.141 -            Resource res = JavaModel.getResource(fobj);
   8.142 - 
   8.143 -            // get the public class from the resource
   8.144 -            ListIterator iter = res.getClassifiers().listIterator();
   8.145 -            while(iter.hasNext()) {
   8.146 -                JavaClass jCls = (JavaClass)iter.next();
   8.147 -                if((jCls.getModifiers() & Modifier.PUBLIC) > 0)
   8.148 -                    return jCls;
   8.149 -            }
   8.150 -        }finally {
   8.151 -            JMIUtils.endTrans();
   8.152 -        }
   8.153 - 
   8.154 -        return null;
   8.155 -//*/
   8.156 -        return null;
   8.157 +    public JavaClass getJavaClass() {
   8.158 +        return JavaClass.getJavaClass(fobj);
   8.159      }
   8.160  
   8.161  
   8.162      public String getPackageName() {
   8.163 -/*//NB6.0
   8.164 -        JMIUtils.beginTrans(false);
   8.165 -        try {
   8.166 -            Resource resource = getJavaClass().getResource();
   8.167 -            String result = null;
   8.168 -            if (resource != null) {
   8.169 -                result = resource.getPackageName();
   8.170 +       return (String)ReadTaskWrapper.execute( new ReadTaskWrapper.Read() {
   8.171 +            public Object run(CompilationInfo cinfo) {
   8.172 +                return cinfo.getCompilationUnit().getPackageName().toString();
   8.173              }
   8.174 -            if (result == null) {
   8.175 -                result = "";
   8.176 -            }
   8.177 -            return result;
   8.178 -        }finally {
   8.179 -            JMIUtils.endTrans();
   8.180 -        }
   8.181 -//*/
   8.182 -        return null;
   8.183 +        }, fobj);
   8.184      }
   8.185  
   8.186  
   8.187 @@ -264,7 +194,7 @@
   8.188      /**
   8.189       *
   8.190       */
   8.191 -    public JavaClassAdapter addClass(String name) {
   8.192 +    public JavaClass addClass(String name) {
   8.193          return null;
   8.194      }
   8.195  
   8.196 @@ -277,7 +207,7 @@
   8.197      /**
   8.198       *
   8.199       */
   8.200 -    public void removeClass(JavaClassAdapter cls) {
   8.201 +    public void removeClass(JavaClass cls) {
   8.202      }
   8.203  
   8.204      //-------------------------------------------------------------------------------------- Helpers
   8.205 @@ -323,11 +253,9 @@
   8.206      
   8.207      protected synchronized void firstWriteLock() {
   8.208          markSourceDirty = false;
   8.209 -        //JMIUtils.beginTrans(false);
   8.210      }
   8.211  
   8.212      protected synchronized void lastWriteUnlock() {
   8.213 -        //JMIUtils.endTrans();
   8.214          markSourceDirty = true;
   8.215      }
   8.216      
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/ReadTaskWrapper.java	Wed Feb 07 00:38:27 2007 +0000
     9.3 @@ -0,0 +1,68 @@
     9.4 +/*
     9.5 + * The contents of this file are subject to the terms of the Common Development
     9.6 + * and Distribution License (the License). You may not use this file except in
     9.7 + * compliance with the License.
     9.8 + *
     9.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    9.10 + * or http://www.netbeans.org/cddl.txt.
    9.11 + *
    9.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
    9.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
    9.14 + * If applicable, add the following below the CDDL Header, with the fields
    9.15 + * enclosed by brackets [] replaced by your own identifying information:
    9.16 + * "Portions Copyrighted [year] [name of copyright owner]"
    9.17 + *
    9.18 + * The Original Software is NetBeans. The Initial Developer of the Original
    9.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
    9.20 + * Microsystems, Inc. All Rights Reserved.
    9.21 + */
    9.22 +
    9.23 +package org.netbeans.modules.visualweb.insync.java;
    9.24 +
    9.25 +import java.io.IOException;
    9.26 +import org.netbeans.api.java.source.CancellableTask;
    9.27 +import org.netbeans.api.java.source.CompilationController;
    9.28 +import org.netbeans.api.java.source.CompilationInfo;
    9.29 +import org.netbeans.api.java.source.JavaSource;
    9.30 +import org.netbeans.api.java.source.JavaSource.Phase;
    9.31 +import org.openide.filesystems.FileObject;
    9.32 +
    9.33 +/**
    9.34 + *
    9.35 + * @author jdeva
    9.36 + */
    9.37 +public class ReadTaskWrapper implements CancellableTask<CompilationController> {
    9.38 +    public interface Read {
    9.39 +        public Object run(CompilationInfo cinfo);
    9.40 +    }
    9.41 +    Read task;
    9.42 +    Object result;
    9.43 +    ReadTaskWrapper(Read task) {
    9.44 +        this.task = task;
    9.45 +    }
    9.46 +    public void cancel() {}
    9.47 +    
    9.48 +    public void run(CompilationController controller) throws Exception {
    9.49 +        try {
    9.50 +            controller.toPhase(Phase.RESOLVED);
    9.51 +        } catch (IOException ex) {
    9.52 +            ex.printStackTrace();
    9.53 +        }
    9.54 +        result = (Object)task.run(controller);
    9.55 +    }
    9.56 +    
    9.57 +    public static Object execute(Read task,  FileObject fObj) {
    9.58 +        ReadTaskWrapper taskWrapper = new ReadTaskWrapper(task);
    9.59 +        JavaSource js = JavaSource.forFileObject(fObj);
    9.60 +        try {
    9.61 +            js.runUserActionTask(taskWrapper, true);
    9.62 +        } catch (IOException ex) {
    9.63 +            ex.printStackTrace();
    9.64 +        }
    9.65 +        return taskWrapper.result;
    9.66 +    }
    9.67 +}
    9.68 +
    9.69 +
    9.70 +
    9.71 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/TreeMakerUtils.java	Wed Feb 07 00:38:27 2007 +0000
    10.3 @@ -0,0 +1,259 @@
    10.4 +/*
    10.5 + * The contents of this file are subject to the terms of the Common Development
    10.6 + * and Distribution License (the License). You may not use this file except in
    10.7 + * compliance with the License.
    10.8 + *
    10.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
   10.10 + * or http://www.netbeans.org/cddl.txt.
   10.11 + *
   10.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
   10.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
   10.14 + * If applicable, add the following below the CDDL Header, with the fields
   10.15 + * enclosed by brackets [] replaced by your own identifying information:
   10.16 + * "Portions Copyrighted [year] [name of copyright owner]"
   10.17 + *
   10.18 + * The Original Software is NetBeans. The Initial Developer of the Original
   10.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
   10.20 + * Microsystems, Inc. All Rights Reserved.
   10.21 + */
   10.22 +
   10.23 +package org.netbeans.modules.visualweb.insync.java;
   10.24 +
   10.25 +import com.sun.rave.designtime.ContextMethod;
   10.26 +import com.sun.source.tree.AnnotationTree;
   10.27 +import com.sun.source.tree.ExpressionTree;
   10.28 +import com.sun.source.tree.MethodTree;
   10.29 +import com.sun.source.tree.ModifiersTree;
   10.30 +import com.sun.source.tree.Tree;
   10.31 +import com.sun.source.tree.TypeParameterTree;
   10.32 +import com.sun.source.tree.VariableTree;
   10.33 +import java.util.Collections;
   10.34 +import java.util.EnumSet;
   10.35 +import java.util.List;
   10.36 +import javax.lang.model.element.Modifier;
   10.37 +import javax.lang.model.element.TypeElement;
   10.38 +import javax.lang.model.type.TypeKind;
   10.39 +import org.netbeans.api.java.source.Comment;
   10.40 +import org.netbeans.api.java.source.TreeMaker;
   10.41 +import org.netbeans.api.java.source.WorkingCopy;
   10.42 +import org.netbeans.modules.visualweb.insync.beans.Naming;
   10.43 +
   10.44 +/**
   10.45 + *
   10.46 + * @author jdeva
   10.47 + */
   10.48 +public class TreeMakerUtils {
   10.49 +    WorkingCopy workingCopy;
   10.50 +    
   10.51 +    TreeMaker getTreeMaker() {
   10.52 +        return workingCopy.getTreeMaker();
   10.53 +    }
   10.54 +    
   10.55 +    /** Creates a new instance of TreeMakerUtils */
   10.56 +    public TreeMakerUtils(WorkingCopy workingCopy) {
   10.57 +        this.workingCopy = workingCopy;
   10.58 +    }
   10.59 +    
   10.60 +    /*
   10.61 +     * Creates a variable tree for a property field
   10.62 +     */ 
   10.63 +    public VariableTree createPropertyField(String name, Class type) {
   10.64 +        TreeMaker make = getTreeMaker();
   10.65 +        Tree typeTree = createType(type.getCanonicalName());
   10.66 +        ExpressionTree initializer = make.NewClass(null, 
   10.67 +                Collections.<ExpressionTree>emptyList(), 
   10.68 +                (ExpressionTree)typeTree, 
   10.69 +                Collections.<ExpressionTree>emptyList(),
   10.70 +                null);
   10.71 +        return make.Variable(
   10.72 +                createModifiers(Modifier.PRIVATE), 
   10.73 +                name,
   10.74 +                typeTree,
   10.75 +                initializer);
   10.76 +    }
   10.77 +    
   10.78 +    /*
   10.79 +     * Creates a new method tree for a property getter method
   10.80 +     */ 
   10.81 +    public MethodTree createPropertyGetterMethod(String name, Class type){
   10.82 +        TreeMaker make = getTreeMaker();
   10.83 +        return make.Method(
   10.84 +                createModifiers(Modifier.PUBLIC),
   10.85 +                Naming.getterName(name),
   10.86 +                createType(type.getCanonicalName()),
   10.87 +                Collections.<TypeParameterTree>emptyList(),
   10.88 +                Collections.<VariableTree>emptyList(),
   10.89 +                Collections.<ExpressionTree>emptyList(),
   10.90 +                "{ return " + name + "; }", // NOI18N
   10.91 +                null);
   10.92 +    }
   10.93 +    
   10.94 +    /*
   10.95 +     * Creates a new method tree for a property setter method
   10.96 +     */ 
   10.97 +    public MethodTree createPropertySetterMethod(String name, Class type){
   10.98 +        TreeMaker make = getTreeMaker();
   10.99 +        String argName = Naming.paramNames(new Class[] { type }, null)[0];
  10.100 +        return make.Method(
  10.101 +                createModifiers(Modifier.PUBLIC),
  10.102 +                Naming.setterName(name),
  10.103 +                make.PrimitiveType(TypeKind.VOID),
  10.104 +                Collections.<TypeParameterTree>emptyList(),
  10.105 +                Collections.singletonList(createVariable(argName, type)),
  10.106 +                Collections.<ExpressionTree>emptyList(),
  10.107 +                "{ this." + name + " = " + argName + "; }", // NOI18N
  10.108 +                null);
  10.109 +    }
  10.110 +    
  10.111 +    /*
  10.112 +     * Creates a new variable tree for a given name and type
  10.113 +     */     
  10.114 +    public VariableTree createVariable(String name, Class type) {
  10.115 +       return createVariable(name, createType(type.getCanonicalName()));
  10.116 +    }    
  10.117 +    
  10.118 +    /*
  10.119 +     * Creates a new variable tree for a given name and type
  10.120 +     */       
  10.121 +    private VariableTree createVariable(String name, Tree type) {
  10.122 +        TreeMaker make = getTreeMaker();
  10.123 +        return make.Variable(createModifiers(), name, type, null);        
  10.124 +    }
  10.125 +    
  10.126 +    /*
  10.127 +     * Creates a method given context method and return type name
  10.128 +     */       
  10.129 +    public MethodTree createMethod(ContextMethod mInfo, String retTypeName) {
  10.130 +        TreeMaker make = getTreeMaker();
  10.131 +        Class[] pTypes = mInfo.getParameterTypes();
  10.132 +        String[] pNames = mInfo.getParameterNames();
  10.133 +        List<VariableTree> params = Collections.<VariableTree>emptyList();
  10.134 +        for (int i = 0 ; pTypes != null && i < pTypes.length; i++) {
  10.135 +            params.add(createVariable(pNames[i], pTypes[i]));
  10.136 +        }
  10.137 +        
  10.138 +        Class[] excepTypes = mInfo.getExceptionTypes();
  10.139 +        List<ExpressionTree> throwsList = Collections.<ExpressionTree>emptyList();
  10.140 +        for (int i = 0 ; excepTypes != null && i < excepTypes.length; i++) {
  10.141 +            throwsList.add((ExpressionTree)createType(excepTypes[i].getCanonicalName()));
  10.142 +        }
  10.143 +        
  10.144 +        MethodTree mtree = make.Method(createModifiers(mInfo.getModifiers()),
  10.145 +                mInfo.getName(),
  10.146 +                createType(retTypeName),
  10.147 +                Collections.<TypeParameterTree>emptyList(),
  10.148 +                params,
  10.149 +                throwsList,
  10.150 +                mInfo.getMethodBodyText(),
  10.151 +                null
  10.152 +                );
  10.153 +        
  10.154 +         if(mInfo.getCommentText() != null) {
  10.155 +            make.addComment(mtree, Comment.create(mInfo.getCommentText()), true);
  10.156 +        }
  10.157 +        
  10.158 +        return mtree;
  10.159 +    }
  10.160 +     
  10.161 +    /* 
  10.162 +     *
  10.163 +     */
  10.164 +    public MethodTree updateMethod(ContextMethod cm, MethodTree methTree) {
  10.165 +        TreeMaker make = getTreeMaker();
  10.166 +        String[] pNames = cm.getParameterNames();
  10.167 +     
  10.168 +        int mods = cm.getModifiers();
  10.169 +        ModifiersTree modsTree = methTree.getModifiers();
  10.170 +        if (mods > 0) {
  10.171 +            modsTree = createModifiers(mods);
  10.172 +        }
  10.173 +            
  10.174 +        //Update param name(s)
  10.175 +        List<? extends VariableTree> params = methTree.getParameters();
  10.176 +        if(cm.getParameterTypes().length > 0) {
  10.177 +            List<VariableTree> newParams = Collections.<VariableTree>emptyList();
  10.178 +            String[] paramNames = cm.getParameterNames();
  10.179 +            for (int i = 0; i < paramNames.length; i++) {
  10.180 +                VariableTree param = params.get(i);
  10.181 +                newParams.add(createVariable(param.getName().toString(), param.getType()));
  10.182 +            }
  10.183 +            params = newParams;
  10.184 +        }
  10.185 +
  10.186 +        //Update comment
  10.187 +        String commentText = cm.getCommentText();
  10.188 +        if(commentText != null) {
  10.189 +            //m.setJavadocText(commentText);
  10.190 +        }
  10.191 +
  10.192 +        //Update body
  10.193 +        String code = cm.getMethodBodyText();
  10.194 +
  10.195 +        //Update return type
  10.196 +        Tree retTree = methTree.getReturnType();
  10.197 +        if(!cm.getName().equals("<init>")) {
  10.198 +            Class retType = cm.getReturnType();
  10.199 +            if(retType != null) {
  10.200 +                retTree = createType(retType.getCanonicalName());
  10.201 +            }
  10.202 +        }
  10.203 +
  10.204 +        return make.Method(modsTree, cm.getName(), retTree, methTree.getTypeParameters(),
  10.205 +                params, methTree.getThrows(), code, null);
  10.206 +            
  10.207 +    }
  10.208 +    
  10.209 +    /*
  10.210 +     * Returns a tree for a given type in string format
  10.211 +     * Note that import for type is handled by make.QualIdent()
  10.212 +     */ 
  10.213 +    public Tree createType(String typeName) {
  10.214 +        TreeMaker make = getTreeMaker();
  10.215 +        TypeKind primitiveTypeKind = null;
  10.216 +        if ("boolean".equals(typeName)) {           // NOI18N
  10.217 +            primitiveTypeKind = TypeKind.BOOLEAN;
  10.218 +        } else if ("byte".equals(typeName)) {       // NOI18N
  10.219 +            primitiveTypeKind = TypeKind.BYTE;
  10.220 +        } else if ("short".equals(typeName)) {      // NOI18N
  10.221 +            primitiveTypeKind = TypeKind.SHORT;
  10.222 +        } else if ("int".equals(typeName)) {        // NOI18N
  10.223 +            primitiveTypeKind = TypeKind.INT;
  10.224 +        } else if ("long".equals(typeName)) {       // NOI18N
  10.225 +            primitiveTypeKind = TypeKind.LONG;
  10.226 +        } else if ("char".equals(typeName)) {       // NOI18N
  10.227 +            primitiveTypeKind = TypeKind.CHAR;
  10.228 +        } else if ("float".equals(typeName)) {      // NOI18N
  10.229 +            primitiveTypeKind = TypeKind.FLOAT;
  10.230 +        } else if ("double".equals(typeName)) {     // NOI18N
  10.231 +            primitiveTypeKind = TypeKind.DOUBLE;
  10.232 +        }
  10.233 +        if (primitiveTypeKind != null) {
  10.234 +            return make.PrimitiveType(primitiveTypeKind);
  10.235 +        }
  10.236 +        
  10.237 +        TypeElement typeElement = workingCopy.getElements().getTypeElement(typeName);
  10.238 +        if (typeElement == null) {
  10.239 +            throw new IllegalArgumentException("Type " + typeName + " cannot be found"); // NOI18N
  10.240 +        }
  10.241 +        return make.QualIdent(typeElement);        
  10.242 +    }
  10.243 +   
  10.244 +    
  10.245 +    public ModifiersTree createModifiers() {
  10.246 +        return getTreeMaker().Modifiers(Collections.<Modifier>emptySet(), Collections.<AnnotationTree>emptyList());
  10.247 +    }
  10.248 +    
  10.249 +    /*
  10.250 +     * Creates a modifier tree given a single modifier
  10.251 +     */ 
  10.252 +    public ModifiersTree createModifiers(Modifier modifier) {
  10.253 +        return getTreeMaker().Modifiers(EnumSet.of(modifier), Collections.<AnnotationTree>emptyList());
  10.254 +    }
  10.255 +    
  10.256 +    /*
  10.257 +     * Creates a modifier tree givena single modifier
  10.258 +     */ 
  10.259 +    public ModifiersTree createModifiers(long flags) {
  10.260 +        return getTreeMaker().Modifiers(flags, Collections.<AnnotationTree>emptyList());
  10.261 +    }          
  10.262 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/TreeUtils.java	Wed Feb 07 00:38:27 2007 +0000
    11.3 @@ -0,0 +1,46 @@
    11.4 +/*
    11.5 + * The contents of this file are subject to the terms of the Common Development
    11.6 + * and Distribution License (the License). You may not use this file except in
    11.7 + * compliance with the License.
    11.8 + *
    11.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
   11.10 + * or http://www.netbeans.org/cddl.txt.
   11.11 + *
   11.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
   11.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
   11.14 + * If applicable, add the following below the CDDL Header, with the fields
   11.15 + * enclosed by brackets [] replaced by your own identifying information:
   11.16 + * "Portions Copyrighted [year] [name of copyright owner]"
   11.17 + *
   11.18 + * The Original Software is NetBeans. The Initial Developer of the Original
   11.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
   11.20 + * Microsystems, Inc. All Rights Reserved.
   11.21 + */
   11.22 +
   11.23 +package org.netbeans.modules.visualweb.insync.java;
   11.24 +
   11.25 +import com.sun.source.tree.Tree;
   11.26 +import com.sun.source.util.TreePath;
   11.27 +import org.netbeans.api.java.source.CompilationInfo;
   11.28 +
   11.29 +/**
   11.30 + *
   11.31 + * @author jdeva
   11.32 + */
   11.33 +public class TreeUtils {
   11.34 +    
   11.35 +    /*
   11.36 +     * Returns treepath for a given tree
   11.37 +     */
   11.38 +    static TreePath getTreePath(CompilationInfo cinfo, Tree tree) {
   11.39 +        return cinfo.getTrees().getPath(cinfo.getCompilationUnit(), tree);
   11.40 +    }
   11.41 +   
   11.42 +    /*
   11.43 +     * Not sure if it is the correct way of computing FQN
   11.44 +     */    
   11.45 +    static String getFQN(CompilationInfo cinfo, Tree tree) {
   11.46 +        return cinfo.getTrees().getTypeMirror(cinfo.getTrees().getPath(cinfo.getCompilationUnit(), tree)).toString();
   11.47 +    }    
   11.48 +    
   11.49 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/java/WriteTaskWrapper.java	Wed Feb 07 00:38:27 2007 +0000
    12.3 @@ -0,0 +1,69 @@
    12.4 +/*
    12.5 + * The contents of this file are subject to the terms of the Common Development
    12.6 + * and Distribution License (the License). You may not use this file except in
    12.7 + * compliance with the License.
    12.8 + *
    12.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
   12.10 + * or http://www.netbeans.org/cddl.txt.
   12.11 + *
   12.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
   12.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
   12.14 + * If applicable, add the following below the CDDL Header, with the fields
   12.15 + * enclosed by brackets [] replaced by your own identifying information:
   12.16 + * "Portions Copyrighted [year] [name of copyright owner]"
   12.17 + *
   12.18 + * The Original Software is NetBeans. The Initial Developer of the Original
   12.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
   12.20 + * Microsystems, Inc. All Rights Reserved.
   12.21 + */
   12.22 +
   12.23 +package org.netbeans.modules.visualweb.insync.java;
   12.24 +
   12.25 +import java.io.IOException;
   12.26 +import org.netbeans.api.java.source.CancellableTask;
   12.27 +import org.netbeans.api.java.source.JavaSource;
   12.28 +import org.netbeans.api.java.source.JavaSource.Phase;
   12.29 +import org.netbeans.api.java.source.ModificationResult;
   12.30 +import org.netbeans.api.java.source.WorkingCopy;
   12.31 +import org.openide.filesystems.FileObject;
   12.32 +
   12.33 +/**
   12.34 + *
   12.35 + * @author jdeva
   12.36 + */
   12.37 +public class WriteTaskWrapper implements CancellableTask<WorkingCopy> {
   12.38 +    interface Write {
   12.39 +        public Object run(WorkingCopy cinfo);
   12.40 +    }
   12.41 +    Write task;
   12.42 +    Object result;
   12.43 +    WriteTaskWrapper(Write task) {
   12.44 +        this.task = task;
   12.45 +    }
   12.46 +    public void cancel() {}
   12.47 +    
   12.48 +    public void run(WorkingCopy copy) throws Exception {
   12.49 +        try {
   12.50 +            copy.toPhase(Phase.RESOLVED);
   12.51 +        } catch (IOException ex) {
   12.52 +            ex.printStackTrace();
   12.53 +        }
   12.54 +        result = (Object)task.run(copy);
   12.55 +    }
   12.56 +    
   12.57 +    public static Object execute(Write task,  FileObject fObj) {
   12.58 +        WriteTaskWrapper taskWrapper = new WriteTaskWrapper(task);
   12.59 +        JavaSource js = JavaSource.forFileObject(fObj);
   12.60 +        ModificationResult result = null;
   12.61 +        try {
   12.62 +            result = js.runModificationTask(taskWrapper);
   12.63 +            if(result != null) {
   12.64 +                result.commit();
   12.65 +            }
   12.66 +        } catch (IOException ex) {
   12.67 +            ex.printStackTrace();
   12.68 +        }
   12.69 +        return taskWrapper.result;
   12.70 +    }
   12.71 +}
   12.72 +
    13.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/BeansDesignBean.java	Tue Feb 06 18:59:29 2007 +0000
    13.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/BeansDesignBean.java	Wed Feb 07 00:38:27 2007 +0000
    13.3 @@ -78,7 +78,7 @@
    13.4              if (cmn != null) {
    13.5                  try {
    13.6                      Method cm = instance.getClass().getMethod(cmn, new Class[] {});
    13.7 -                    cm.invoke(instance, null);
    13.8 +                    cm.invoke(instance);
    13.9                  }
   13.10                  catch (Exception e) {
   13.11                      //e.printStackTrace();
    14.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/ContextMethodHelper.java	Tue Feb 06 18:59:29 2007 +0000
    14.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/ContextMethodHelper.java	Wed Feb 07 00:38:27 2007 +0000
    14.3 @@ -20,7 +20,7 @@
    14.4  
    14.5  import org.netbeans.modules.visualweb.insync.java.ClassUtil;
    14.6  import org.netbeans.modules.visualweb.insync.java.JMIUtils;
    14.7 -import org.netbeans.modules.visualweb.insync.java.JavaClassAdapter;
    14.8 +import org.netbeans.modules.visualweb.insync.java.JavaClass;
    14.9  import java.util.ArrayList;
   14.10  import java.util.Iterator;
   14.11  import java.util.List;
   14.12 @@ -270,7 +270,7 @@
   14.13          if(method == null || method.getDesignContext() != lu)
   14.14              return null;
   14.15  
   14.16 -        JavaClassAdapter javaClass = lu.getSourceUnit().getThisClass();
   14.17 +        JavaClass javaClass = lu.getSourceUnit().getThisClass();
   14.18  /*//NB6.0
   14.19          JMIUtils.beginTrans(true);
   14.20          boolean rollback = true;
    15.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/DesignBeanNodeLookup.java	Tue Feb 06 18:59:29 2007 +0000
    15.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/DesignBeanNodeLookup.java	Wed Feb 07 00:38:27 2007 +0000
    15.3 @@ -220,7 +220,8 @@
    15.4      }
    15.5  
    15.6      private static Pair cookieSetExitQueryMode(Object prev) {
    15.7 -        return (Pair)invokeOnCookieSet("exitQueryMode", new Class[] {Object.class}, new Object[] {prev});
    15.8 +        Collection col = (Collection)invokeOnCookieSet("exitQueryMode", new Class[] {Object.class}, new Object[] {prev});
    15.9 +        return col != null ? (Pair)col.iterator().next() : null;
   15.10      }
   15.11  
   15.12      private Object cookieSetEntryAllClassesMode() {
    16.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/SourceLiveRoot.java	Tue Feb 06 18:59:29 2007 +0000
    16.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/live/SourceLiveRoot.java	Wed Feb 07 00:38:27 2007 +0000
    16.3 @@ -18,7 +18,7 @@
    16.4   */
    16.5  package org.netbeans.modules.visualweb.insync.live;
    16.6  
    16.7 -import org.netbeans.modules.visualweb.insync.java.JavaClassAdapter;
    16.8 +import org.netbeans.modules.visualweb.insync.java.JavaClass;
    16.9  import java.beans.PropertyDescriptor;
   16.10  import java.util.ArrayList;
   16.11  
   16.12 @@ -49,7 +49,7 @@
   16.13       */
   16.14      public String getInstanceName() {
   16.15          if(unit.sourceUnit != null) {
   16.16 -            JavaClassAdapter adapterClass = unit.sourceUnit.getThisClass();
   16.17 +            JavaClass adapterClass = unit.sourceUnit.getThisClass();
   16.18              if( adapterClass != null)
   16.19                  return adapterClass.getShortName();
   16.20          }
    17.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/FacesModel.java	Tue Feb 06 18:59:29 2007 +0000
    17.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/FacesModel.java	Wed Feb 07 00:38:27 2007 +0000
    17.3 @@ -24,7 +24,7 @@
    17.4  import org.netbeans.modules.visualweb.insync.FacesDnDSupport;
    17.5  import org.netbeans.modules.visualweb.insync.InSyncServiceProvider;
    17.6  import org.netbeans.modules.visualweb.insync.java.JMIUtils;
    17.7 -import org.netbeans.modules.visualweb.insync.java.JavaClassAdapter;
    17.8 +import org.netbeans.modules.visualweb.insync.java.JavaClass;
    17.9  import org.netbeans.modules.visualweb.insync.java.JavaUnit;
   17.10  
   17.11  import java.beans.BeanInfo;
   17.12 @@ -426,8 +426,6 @@
   17.13       * @param cl The new classloader.
   17.14       */
   17.15      void updateClassLoader(ClassLoader cl) {
   17.16 -        if (javaUnit != null)
   17.17 -            javaUnit.setClassLoader((URLClassLoader)cl);
   17.18          if (beansUnit != null)
   17.19              beansUnit.setClassLoader(cl);
   17.20      }
   17.21 @@ -764,7 +762,7 @@
   17.22  
   17.23          //In case we are reacting to .java file creation but before the file is
   17.24          //well formed, we may not be able to get the public class
   17.25 -        Object/*TypeElement or ClassType*/ javaClass = javaUnit.getJavaClass();
   17.26 +        JavaClass javaClass = javaUnit.getJavaClass();
   17.27          if(javaClass == null) {
   17.28              javaUnit.setBusted();
   17.29              return;
   17.30 @@ -774,7 +772,7 @@
   17.31          //Check if we are working with our known managed beans
   17.32          boolean isModelledManagedBean = false;
   17.33          for(int i=0; i<managedBeanNames.length; i++) {
   17.34 -            if(JMIUtils.isSubTypeOf(javaClass, managedBeanNames[i])) {
   17.35 +            if(javaClass.isSubTypeOf(managedBeanNames[i])) {
   17.36                  isModelledManagedBean = true;
   17.37                  break;
   17.38              }
   17.39 @@ -792,7 +790,6 @@
   17.40              return;
   17.41          }
   17.42          
   17.43 -        javaUnit.setSourcepath(sourceFolderFile.getAbsolutePath());
   17.44          javaUnit.sync();
   17.45          if (javaUnit.getState() != Unit.State.CLEAN) {
   17.46              return;
   17.47 @@ -877,7 +874,7 @@
   17.48          // update the missing MB entry in the MBM, getting scope based on the superclass of the bean
   17.49          //!CQ consider fixing broken entry settings in some cases
   17.50          if (mb == null) {
   17.51 -            JavaClassAdapter javaClass = beansUnit.getThisClass();
   17.52 +            JavaClass javaClass = beansUnit.getThisClass();
   17.53              for(int i=0; i<managedBeanNames.length; i++) {
   17.54                  if(javaClass.isSubTypeOf(managedBeanNames[i])) {
   17.55                      UndoEvent event = null;
   17.56 @@ -913,7 +910,7 @@
   17.57          return getScope(getBeansUnit().getThisClass());
   17.58      }
   17.59  
   17.60 -    public ManagedBean.Scope getScope(JavaClassAdapter type) {
   17.61 +    public ManagedBean.Scope getScope(JavaClass type) {
   17.62          if (type == null)
   17.63              return null;
   17.64          for(int i=0; i<managedBeanNames.length; i++) {
    18.1 --- a/visualweb.j2ee14classloaderprovider/src/org/netbeans/modules/visualweb/j2ee14classloaderprovider/J2EE14CommonClassloaderProvider.java	Tue Feb 06 18:59:29 2007 +0000
    18.2 +++ b/visualweb.j2ee14classloaderprovider/src/org/netbeans/modules/visualweb/j2ee14classloaderprovider/J2EE14CommonClassloaderProvider.java	Wed Feb 07 00:38:27 2007 +0000
    18.3 @@ -51,9 +51,9 @@
    18.4          // discovered and loaded by the JSF1.2 RI. Ideally thin jars containing
    18.5          // the META-INF/faces-config.xml should be used. The classes should be loded
    18.6          // from the modules themselves.
    18.7 -        "jar:nbinst:///modules/com-sun-rave-jsfsupport-designtime.jar!/", // NOI18N
    18.8 -        "jar:nbinst:///modules/com-sun-rave-jsfsupport-designtime_1_1.jar!/", // NOI18N
    18.9 -        "jar:nbinst:///modules/com-sun-rave-webui-designtime.jar!/", // NOI18N
   18.10 +        "jar:nbinst:///modules/org-netbeans-modules-visualweb-jsfsupport-designtime.jar!/", // NOI18N
   18.11 +        "jar:nbinst:///modules/org-netbeans-modules-visualweb-jsfsupport-designtime_1_1.jar!/", // NOI18N
   18.12 +        "jar:nbinst:///modules/org-netbeans-modules-visualweb-webui-designtime.jar!/", // NOI18N
   18.13          // The following two jars are here for special handling of JSF1.1 Standard components
   18.14          // and renderkits
   18.15          "jar:nbinst:///modules/ext/jsf-api.jar!/", // NOI18N
    19.1 --- a/visualweb.j2ee15classloaderprovider/src/org/netbeans/modules/visualweb/j2ee15classloaderprovider/J2EE15CommonClassloaderProvider.java	Tue Feb 06 18:59:29 2007 +0000
    19.2 +++ b/visualweb.j2ee15classloaderprovider/src/org/netbeans/modules/visualweb/j2ee15classloaderprovider/J2EE15CommonClassloaderProvider.java	Wed Feb 07 00:38:27 2007 +0000
    19.3 @@ -50,8 +50,8 @@
    19.4          // discovered and loaded by the JSF1.2 RI. Ideally thin jars containing
    19.5          // the META-INF/faces-config.xml should be used. The classes should be loded
    19.6          // from the modules themselves.
    19.7 -        "jar:nbinst:///modules/com-sun-rave-jsfsupport-designtime.jar!/",
    19.8 -        "jar:nbinst:///modules/com-sun-rave-jsfsupport-designtime_1_2.jar!/",
    19.9 +        "jar:nbinst:///modules/org-netbeans-modules-visualweb-jsfsupport-designtime.jar!/",
   19.10 +        "jar:nbinst:///modules/org-netbeans-modules-visualweb-jsfsupport-designtime_1_2.jar!/",
   19.11          "jar:nbinst:///modules/ext/webui-jsf-dt.jar!/",
   19.12      };
   19.13