myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: refactored
Date Mon, 15 Jul 2019 14:47:23 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new d9c89df  refactored
d9c89df is described below

commit d9c89dfb36353b80562d39ca78fd5103897e337e
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Mon Jul 15 16:47:16 2019 +0200

    refactored
---
 .../org/apache/myfaces/util/lang/ClassUtils.java   | 54 +++++++---------------
 .../myfaces/view/facelets/ViewPoolProcessor.java   | 30 +++++-------
 .../myfaces/view/facelets/compiler/TextUnit.java   |  9 ++--
 .../myfaces/view/facelets/compiler/UILeaf.java     | 28 ++---------
 4 files changed, 36 insertions(+), 85 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java b/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java
index 3a8af26..629e68e 100755
--- a/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java
@@ -426,17 +426,7 @@ public final class ClassUtils
         {
             return clazz.newInstance();
         }
-        catch(NoClassDefFoundError e)
-        {
-            log.log(Level.SEVERE, "Class : "+clazz.getName()+" not found.",e);
-            throw new FacesException(e);
-        }
-        catch (InstantiationException e)
-        {
-            log.log(Level.SEVERE, e.getMessage(), e);
-            throw new FacesException(e);
-        }
-        catch (IllegalAccessException e)
+        catch (NoClassDefFoundError | InstantiationException | IllegalAccessException e)
         {
             log.log(Level.SEVERE, e.getMessage(), e);
             throw new FacesException(e);
@@ -515,22 +505,20 @@ public final class ClassUtils
      */
     public static ClassLoader getContextClassLoader()
     {
-      if (System.getSecurityManager() != null) 
-      {
-          try 
-          {
-              return (ClassLoader) AccessController.doPrivileged(
-                      (PrivilegedExceptionAction) () -> Thread.currentThread().getContextClassLoader());
-          }
-          catch (PrivilegedActionException pae)
-          {
-              throw new FacesException(pae);
-          }
-      }
-      else
-      {
-          return Thread.currentThread().getContextClassLoader();
-      }
+        if (System.getSecurityManager() != null) 
+        {
+            try 
+            {
+                return (ClassLoader) AccessController.doPrivileged(
+                        (PrivilegedExceptionAction) () -> Thread.currentThread().getContextClassLoader());
+            }
+            catch (PrivilegedActionException pae)
+            {
+                throw new FacesException(pae);
+            }
+        }
+
+        return Thread.currentThread().getContextClassLoader();
     }
     
     /**
@@ -622,17 +610,7 @@ public final class ClassUtils
                         // create new decorator wrapping current
                         newCurrent = delegationConstructor.newInstance(new Object[] { current
});
                     }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
+                    catch (InstantiationException | IllegalAccessException | InvocationTargetException
e)
                     {
                         log.log(Level.SEVERE, e.getMessage(), e);
                         throw new FacesException(e);
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java b/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java
index a17c267..856b2b0 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/ViewPoolProcessor.java
@@ -217,6 +217,7 @@ public class ViewPoolProcessor
             // state saving algorithm for that.
             return null;
         }
+
         Boolean enableViewPool = (Boolean) root.getAttributes().get(ViewPoolProcessor.ENABLE_VIEW_POOL);
         if (enableViewPool != null && !Boolean.TRUE.equals(enableViewPool))
         {
@@ -237,26 +238,19 @@ public class ViewPoolProcessor
             // state saving algorithm for that.
             return false;
         }
+
         Boolean enableViewPool = (Boolean) root.getAttributes().get(ViewPoolProcessor.ENABLE_VIEW_POOL);
         if (enableViewPool != null)
         {
-            if (Boolean.TRUE.equals(enableViewPool))
-            {
-                return true;
-            }
-            else
-            {
-                return false;
-            }
+            return enableViewPool;
         }
-        else
+
+        ViewPool viewPool = getViewPool(context, root);
+        if (viewPool != null)
         {
-            ViewPool viewPool = getViewPool(context, root);
-            if (viewPool != null)
-            {
-                return true;
-            }
+            return true;
         }
+
         return false;
     }
 
@@ -343,7 +337,7 @@ public class ViewPoolProcessor
         {
             if (oldView.getFacetCount() > 0)
             {
-                List<String> facetKeys = new ArrayList<String>(oldView.getFacets().keySet());
+                List<String> facetKeys = new ArrayList<>(oldView.getFacets().keySet());
 
                 for (String facetKey : facetKeys)
                 {
@@ -515,7 +509,7 @@ public class ViewPoolProcessor
                 // add partial structure view to the map.
                 clearTransientAndRemoveNonResetableComponents(context, ptc, view, viewStructureMetadata);
                 int reusableCount = ptc.getCount();
-                float factor = ((float)reusableCount) / ((float)count);
+                float factor = ((float) reusableCount) / ((float) count);
                 if (factor > 0.3f)
                 {
                     viewPool.pushPartialStructureView(context, view);
@@ -847,7 +841,7 @@ public class ViewPoolProcessor
             {
                 UIComponent child = component.getChildren().get(i);
                 boolean containsFaceletId = child.getAttributes().containsKey(ComponentSupport.MARK_CREATED);
-                if (child != null && child.isTransient() && !containsFaceletId)
+                if (child.isTransient() && !containsFaceletId)
                 {
                     //Transient and not bound to facelets tag, remove it!.
                     component.getChildren().remove(i);
@@ -913,7 +907,7 @@ public class ViewPoolProcessor
             {
                 UIComponent fc = itr.next();
                 boolean containsFaceletId = fc.getAttributes().containsKey(ComponentSupport.MARK_CREATED);
-                if (fc != null && fc.isTransient() && !containsFaceletId)
+                if (fc.isTransient() && !containsFaceletId)
                 {
                     //Transient and not bound to facelets tag, remove it!.
                     itr.remove();
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TextUnit.java b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TextUnit.java
index 09e4dea..a25f200 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TextUnit.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TextUnit.java
@@ -79,6 +79,7 @@ final class TextUnit extends CompilationUnit
         this.compressSpaces = compressSpaces;
     }
 
+    @Override
     public FaceletHandler createFaceletHandler()
     {
         this.flushBufferToConfig(true);
@@ -294,12 +295,11 @@ final class TextUnit extends CompilationUnit
         TagAttribute[] attrs = tag.getAttributes().getAll();
         if (attrs.length > 0)
         {
-            for (int i = 0; i < attrs.length; i++)
+            for (TagAttribute attr : attrs)
             {
-                String qname = attrs[i].getQName();
-                String value = attrs[i].getValue();
+                String qname = attr.getQName();
+                String value = attr.getValue();
                 this.buffer.append(' ').append(qname).append("=\"").append(value).append('"');
-
                 ELText txt = ELText.parseAllowEmptyString(value);
                 if (txt != null)
                 {
@@ -718,6 +718,7 @@ final class TextUnit extends CompilationUnit
         return 0;
     }
 
+    @Override
     public String toString()
     {
         return "TextUnit[" + this.children.size() + ']';
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java
index 4612ea1..75f9293 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java
@@ -182,23 +182,6 @@ class UILeaf extends UIComponent implements UntargetableComponent, Map<String,
O
 
 
     //-------------- END TAKEN FROM UICOMPONENTBASE ------------------
-    
-
-    private static Map<String, UIComponent> facets = new HashMap<String, UIComponent>()
-    {
-
-        @Override
-        public void putAll(Map<? extends String, ? extends UIComponent> map)
-        {
-            // do nothing
-        }
-
-        @Override
-        public UIComponent put(String name, UIComponent value)
-        {
-            return null;
-        }
-    };
 
     private UIComponent parent;
 
@@ -305,8 +288,7 @@ class UILeaf extends UIComponent implements UntargetableComponent, Map<String,
O
     @Override
     public List<UIComponent> getChildren()
     {
-        List<UIComponent> children = Collections.emptyList();
-        return children;
+        return Collections.emptyList();
     }
 
     @Override
@@ -324,7 +306,7 @@ class UILeaf extends UIComponent implements UntargetableComponent, Map<String,
O
     @Override
     public Map<String, UIComponent> getFacets()
     {
-        return facets;
+        return Collections.emptyMap();
     }
 
     @Override
@@ -339,13 +321,9 @@ class UILeaf extends UIComponent implements UntargetableComponent, Map<String,
O
         return null;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public Iterator<UIComponent> getFacetsAndChildren()
-    {
-        // Performance: Collections.emptyList() is Singleton,
-        // but .iterator() creates new instance of AbstractList$Itr every invocation, because
-        // emptyList() extends AbstractList.  Therefore we cannot use Collections.emptyList()
here. 
+    { 
         return Collections.emptyIterator();
     }
 


Mime
View raw message