You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2009/08/07 19:51:25 UTC
svn commit: r802105 - in /commons/proper/jexl/branches/2.0/src:
main/java/org/apache/commons/jexl/util/Introspector.java
test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java
Author: rahul
Date: Fri Aug 7 17:51:25 2009
New Revision: 802105
URL: http://svn.apache.org/viewvc?rev=802105&view=rev
Log:
Try list executors before duck.
JEXL-81
Added:
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java (with props)
Modified:
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java?rev=802105&r1=802104&r2=802105&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java Fri Aug 7 17:51:25 2009
@@ -198,11 +198,6 @@
if (executor.isAlive()) {
return executor;
}
- // if that didn't work, look for get("foo")
- executor = new DuckGetExecutor(this, claz, identifier);
- if (executor.isAlive()) {
- return executor;
- }
// let's see if we can convert the identifier to an int,
// if obj is an array or a list, we can still do something
Integer index = toInteger(identifier);
@@ -212,7 +207,11 @@
return executor;
}
}
-
+ // if that didn't work, look for get("foo")
+ executor = new DuckGetExecutor(this, claz, identifier);
+ if (executor.isAlive()) {
+ return executor;
+ }
return null;
}
@@ -239,11 +238,6 @@
if (executor.isAlive()) {
return executor;
}
- // if that didn't work, look for get("foo")
- executor = new DuckSetExecutor(this, claz, property, arg);
- if (executor.isAlive()) {
- return executor;
- }
// let's see if we can convert the identifier to an int,
// if obj is an array or a list, we can still do something
Integer index = toInteger(identifier);
@@ -253,6 +247,11 @@
return executor;
}
}
+ // if that didn't work, look for get("foo")
+ executor = new DuckSetExecutor(this, claz, property, arg);
+ if (executor.isAlive()) {
+ return executor;
+ }
return null;
}
Added: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java?rev=802105&view=auto
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java (added)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java Fri Aug 7 17:51:25 2009
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl.util.introspection;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.jexl.util.Introspector;
+import org.apache.commons.jexl.util.ListGetExecutor;
+import org.apache.commons.jexl.util.ListSetExecutor;
+import org.apache.commons.jexl.util.MapGetExecutor;
+import org.apache.commons.jexl.util.MapSetExecutor;
+
+/**
+ * Tests for checking introspection discovery.
+ *
+ * @since 2.0
+ */
+public class DiscoveryTest extends TestCase {
+
+ public void testListIntrospection() throws Exception {
+ Uberspect uber = Introspector.getUberspect();
+ Introspector intro = (Introspector) uber;
+ List<Object> list = new ArrayList<Object>();
+
+ assertTrue(intro.getGetExecutor(list, "1") instanceof ListGetExecutor);
+ assertTrue(intro.getSetExecutor(list, "1", "foo") instanceof ListSetExecutor);
+
+ assertTrue(uber.getPropertyGet(list, "1", null) instanceof ListGetExecutor);
+ assertTrue(uber.getPropertySet(list, "1", "foo", null) instanceof ListSetExecutor);
+ }
+
+ public void testMapIntrospection() throws Exception {
+ Uberspect uber = Introspector.getUberspect();
+ Introspector intro = (Introspector) uber;
+ Map<String, Object> list = new HashMap<String, Object>();
+
+ assertTrue(intro.getGetExecutor(list, "foo") instanceof MapGetExecutor);
+ assertTrue(intro.getSetExecutor(list, "foo", "bar") instanceof MapSetExecutor);
+
+ assertTrue(uber.getPropertyGet(list, "foo", null) instanceof MapGetExecutor);
+ assertTrue(uber.getPropertySet(list, "foo", "bar", null) instanceof MapSetExecutor);
+ }
+
+}
Propchange: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL