Commits

Anonymous committed ae745a3

Resolves OGNL-23. String concatenation not working properly in ternary statements.

Comments (0)

Files changed (3)

   </component>
   <component name="ChangeListManager">
     <list default="true" name="Default" comment="">
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/QuotingTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/QuotingTest.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTConst.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTConst.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/NullStringCatenationTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/NullStringCatenationTest.java" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTAdd.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTAdd.java" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/OGNL.iws" afterPath="$PROJECT_DIR$/OGNL.iws" />
     </list>
       <file leaf-file-name="ExpressionCompiler.java" pinned="false" current="true" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="386" column="16" selection-start="14723" selection-end="14723" vertical-scroll-proportion="0.3858603">
+            <state line="381" column="11" selection-start="14550" selection-end="14550" vertical-scroll-proportion="0.32197616">
               <folding />
             </state>
           </provider>
           <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
         </PATH_ELEMENT>
       </PATH>
-      <PATH>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="OGNL.ipr" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="OGNL" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewModuleNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/test" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/test/java" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/test/java/org/ognl/test" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-      </PATH>
-      <PATH>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="OGNL.ipr" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="OGNL" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewModuleNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-      </PATH>
     </subPane>
   </component>
   <component name="ProjectReloadState">
   </component>
   <component name="RecentsManager" />
   <component name="RestoreUpdateTree" />
-  <component name="RunManager" selected="JUnit.NullStringCatenationTest">
-    <tempConfiguration default="false" name="NullStringCatenationTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
+  <component name="RunManager" selected="JUnit.PropertyTest">
+    <tempConfiguration default="false" name="PropertyTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
       <pattern value="org.ognl.test.*" />
       <module name="OGNL" />
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
       <option name="ALTERNATIVE_JRE_PATH" />
       <option name="PACKAGE_NAME" value="org.ognl.test" />
-      <option name="MAIN_CLASS_NAME" value="org.ognl.test.NullStringCatenationTest" />
+      <option name="MAIN_CLASS_NAME" value="org.ognl.test.PropertyTest" />
       <option name="METHOD_NAME" />
       <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" />
     <option name="PERFORM_COMMIT_IN_BACKGROUND" value="false" />
     <option name="PUT_FOCUS_INTO_COMMENT" value="false" />
     <option name="FORCE_NON_EMPTY_COMMENT" value="false" />
-    <option name="LAST_COMMIT_MESSAGE" value="Resolves OGNL-22. Null strings weren't being handled properly in mathematical expressions." />
+    <option name="LAST_COMMIT_MESSAGE" value="Resolves OGNL-23. String concatenation not working properly in ternary statements." />
     <option name="SAVE_LAST_COMMIT_MESSAGE" value="true" />
     <option name="CHECKIN_DIALOG_SPLITTER_PROPORTION" value="0.8" />
     <option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
     <option name="UPDATE_GROUP_BY_PACKAGES" value="false" />
     <option name="SHOW_FILE_HISTORY_AS_TREE" value="false" />
     <option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
-    <MESSAGE value="Minor code formatting / cleanup." />
     <MESSAGE value="Partially fixes OGNL-17 . It's only partial because someone tried to sneak in two different tickets under one." />
     <MESSAGE value="Fixes OGNL-17. ...Too much to list, the summary is that ASTCtor / ASTList hadn't had the same kind of context/ refactoring love &#10;that ASTMethod/ property/ etc had ...." />
     <MESSAGE value="Fixes OGNL-18.&#10;&#10;Array/List/etc accessors weren't properly detecting object vs primitive types when accessing their respective properties because ASTConst was still sticking the old object class type as the current context type. This involved refactoring ASTConst to correctly place the native type for numerics as well as fixing all the problems resulting from this new behavior." />
     <MESSAGE value="Fixes number of bugs resulting from more ASTConst changes and how the context types are figured out." />
     <MESSAGE value="Upgraded javacc and re-ran grammar generator." />
     <MESSAGE value="Resolves OGNL-22. Null strings weren't being handled properly in mathematical expressions." />
+    <MESSAGE value="Resolves OGNL-23. String concatenation not working properly in ternary statements." />
   </component>
   <component name="antWorkspaceConfiguration">
     <option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
     <option name="myLastEditedConfigurable" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ListPropertyAccessor.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="220" column="0" selection-start="8555" selection-end="8555" vertical-scroll-proportion="0.85519594">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/InterfaceInheritanceTest.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="47" column="8" selection-start="2174" selection-end="2174" vertical-scroll-proportion="0.012776831">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ArrayPropertyAccessor.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="206" column="0" selection-start="8452" selection-end="8452" vertical-scroll-proportion="0.70187396">
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTProperty.java">
       <provider selected="true" editor-type-id="text-editor">
         <state line="445" column="124" selection-start="19295" selection-end="19295" vertical-scroll-proportion="0.012776831">
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTAdd.java">
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/NullStringCatenationTest.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="163" column="82" selection-start="6354" selection-end="6354" vertical-scroll-proportion="0.43911007">
+        <state line="45" column="6" selection-start="2361" selection-end="2361" vertical-scroll-proportion="0.26346603">
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/NullStringCatenationTest.java">
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/JavaSource.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="39" column="0" selection-start="1924" selection-end="1924" vertical-scroll-proportion="0.11499148">
+        <state line="34" column="0" selection-start="1086" selection-end="1086" vertical-scroll-proportion="0.5620609">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTChain.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="43" column="1" selection-start="2083" selection-end="2083" vertical-scroll-proportion="0.17564403">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/PropertyTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="45" column="87" selection-start="2136" selection-end="2136" vertical-scroll-proportion="0.15332198">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTAdd.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="227" column="0" selection-start="10070" selection-end="10070" vertical-scroll-proportion="0.44463372">
           <folding />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="386" column="16" selection-start="14723" selection-end="14723" vertical-scroll-proportion="0.3858603">
+        <state line="381" column="11" selection-start="14550" selection-end="14550" vertical-scroll-proportion="0.32197616">
           <folding />
         </state>
       </provider>

src/java/ognl/ASTAdd.java

 package ognl;
 
 import ognl.enhance.ExpressionCompiler;
+import ognl.enhance.OrderedReturn;
 import ognl.enhance.UnsupportedCompilationException;
 
 import java.math.BigDecimal;
                 context.setCurrentAccessor(currAccessor);
             }
 
-
-
             // reset context since previous children loop would have changed it
             
             context.setCurrentObject(target);
             
             if ((_children != null) && (_children.length > 0)) {
                 for ( int i = 0; i < _children.length; ++i ) {
+                    
                     if (i > 0) {
                         result += " " + getExpressionOperator(i) + " ";
                     }
-                    
+
                     String expr = _children[i].toGetSourceString(context, target);
 
                     if ((expr != null && "null".equals(expr))
                         }
                     }
 
+                    if (!OrderedReturn.class.isInstance(_parent)) {
+                        result += "(";
+                    }
                     result += expr;
                     
                     if ((lastType == null || !String.class.isAssignableFrom(lastType.getGetterClass()))
                         }
                     }
 
+                    if (!OrderedReturn.class.isInstance(_parent)) {
+                        result += ")";
+                    }
                 }
             }
             

src/test/java/org/ognl/test/NullStringCatenationTest.java

 import junit.framework.TestSuite;
 import org.ognl.test.objects.Root;
 
-public class NullStringCatenationTest extends OgnlTestCase
-{
+public class NullStringCatenationTest extends OgnlTestCase {
 
     private static Root ROOT = new Root();
 
     private static Object[][] TESTS = {
-    // Null string catenation
-           { ROOT, "\"bar\" + null", "barnull" }, // Catenate null to a string  
-           { ROOT, "\"bar\" + nullObject", "barnull" }, // Catenate null to a string 
-           { ROOT, "20.56 + nullObject", NullPointerException.class }, // Catenate null to a number 
-            
+            // Null string catenation
+            {ROOT, "\"bar\" + null", "barnull"}, // Catenate null to a string
+            {ROOT, "\"bar\" + nullObject", "barnull"}, // Catenate null to a string
+            {ROOT, "20.56 + nullObject", NullPointerException.class}, // Catenate null to a number 
+            {ROOT, "(true ? 'tabHeader' : '') + (false ? 'tabHeader' : '')", "tabHeader"}
     };
-    
+
     /*
-     * =================================================================== Public static methods
-     * ===================================================================
-     */
+    * =================================================================== Public static methods
+    * ===================================================================
+    */
     public static TestSuite suite()
     {
         TestSuite result = new TestSuite();
 
-        for(int i = 0; i < TESTS.length; i++) {
+        for (int i = 0; i < TESTS.length; i++) {
             if (TESTS[i].length == 3) {
                 result.addTest(new NullStringCatenationTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
                         TESTS[i][2]));
     }
 
     public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult,
-            Object setValue, Object expectedAfterSetResult)
+                                    Object setValue, Object expectedAfterSetResult)
     {
         super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
     }
 
     public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult,
-            Object setValue)
+                                    Object setValue)
     {
         super(name, root, expressionString, expectedResult, setValue);
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.