Source Code Cross Referenced for Setter.java in  » Scripting » Kawa » gnu » kawa » functions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » Kawa » gnu.kawa.functions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package gnu.kawa.functions;
002:
003:        import gnu.bytecode.*;
004:        import gnu.mapping.*;
005:        import gnu.expr.*;
006:        import gnu.mapping.Procedure;
007:        import gnu.kawa.reflect.Invoke;
008:        import gnu.kawa.reflect.ArraySet;
009:
010:        /** Implements Kawa extension function "setter", as in SRFI-17. */
011:
012:        public class Setter extends Procedure1 implements  CanInline, HasSetter {
013:            public static final Setter setter = new Setter();
014:            static {
015:                setter.setName("setter");
016:            }
017:
018:            public static Object setter(Procedure arg) {
019:                return arg.getSetter();
020:            }
021:
022:            public Object apply1(Object arg) {
023:                if (!(arg instanceof  Procedure)) {
024:                    /* #ifdef JAVA2 */
025:                    if (arg instanceof  java.util.List)
026:                        return new SetList((java.util.List) arg);
027:                    /* #else */
028:                    // if (arg instanceof gnu.lists.Sequence)
029:                    //   return new SetList((gnu.lists.Sequence) arg);
030:                    /* #endif */
031:                    Class cl = arg.getClass();
032:                    if (cl.isArray())
033:                        return new SetArray(arg, Language.getDefaultLanguage()/*FIXME*/);
034:                }
035:                return ((Procedure) arg).getSetter();
036:            }
037:
038:            public Expression inline(ApplyExp exp, ExpWalker walker) {
039:                Expression[] args = exp.getArgs();
040:                if (args.length == 1) {
041:                    Expression arg = args[0];
042:                    Type argType = arg.getType();
043:                    ClassType ctype;
044:                    if (argType instanceof  ArrayType) {
045:                        return new SetArrayExp(arg, (ArrayType) argType);
046:                    }
047:                    if (argType instanceof  ClassType
048:                            && (ctype = (ClassType) argType)
049:                                    .isSubclass(ApplyToArgs.typeList)) {
050:                        if (exp instanceof  SetListExp)
051:                            return exp;
052:                        else
053:                            return new SetListExp(exp.getFunction(), args);
054:                    }
055:                    if (arg instanceof  ReferenceExp) {
056:                        Declaration decl = ((ReferenceExp) arg).getBinding();
057:                        if (decl != null)
058:                            arg = decl.getValue();
059:                    }
060:                    if (arg instanceof  QuoteExp) {
061:                        Object value = ((QuoteExp) arg).getValue();
062:                        if (value instanceof  Procedure) {
063:                            Object setter = ((Procedure) value).getSetter();
064:                            if (setter instanceof  Procedure) {
065:                                if (setter instanceof  java.io.Externalizable)
066:                                    return new QuoteExp(setter);
067:                                Declaration decl = Declaration
068:                                        .getDeclaration((Procedure) setter);
069:                                if (decl != null)
070:                                    return new ReferenceExp(decl);
071:                            }
072:                        }
073:                    }
074:                }
075:                return exp;
076:            }
077:
078:            public void set1(Object arg1, Object value) throws Throwable {
079:                ((Procedure) arg1).setSetter((Procedure) value);
080:            }
081:
082:            static final ClassType setterType = ClassType
083:                    .make("gnu.kawa.functions.Setter");
084:            static final Field setterField = setterType
085:                    .getDeclaredField("setter");
086:            public static final Declaration setterDecl = new Declaration(
087:                    "setter", setterField);
088:            static {
089:                setterDecl.noteValue(new QuoteExp(Setter.setter));
090:            }
091:
092:        }
093:
094:        class SetArray extends Procedure2 {
095:            Object array;
096:            Type elementType;
097:
098:            public SetArray(Object array, Language language) {
099:                Class elementClass = array.getClass().getComponentType();
100:                elementType = language.getTypeFor(elementClass);
101:                this .array = array;
102:            }
103:
104:            public Object apply2(Object index, Object value) {
105:                value = elementType.coerceFromObject(value);
106:                java.lang.reflect.Array.set(array, ((Number) index).intValue(),
107:                        value);
108:                return Values.empty;
109:            }
110:        }
111:
112:        class SetList extends Procedure2 {
113:            /* #ifdef JAVA2 */
114:            java.util.List list;
115:
116:            public SetList(java.util.List list) {
117:                this .list = list;
118:            }
119:
120:            /* #else */
121:            // gnu.lists.Sequence list;
122:            // public SetList (gnu.lists.Sequence list)
123:            // {
124:            //   this.list = list;
125:            // }
126:            /* #endif */
127:            Type elementType;
128:
129:            public Object apply2(Object index, Object value) {
130:                list.set(((Number) index).intValue(), value);
131:                return Values.empty;
132:            }
133:        }
134:
135:        class SetArrayExp extends ApplyExp {
136:            public static final ClassType typeSetArray = ClassType
137:                    .make("gnu.kawa.functions.SetArray");
138:
139:            Type elementType;
140:
141:            public SetArrayExp(Expression array, ArrayType arrayType) {
142:                super (Invoke.make, new Expression[] {
143:                        new QuoteExp(typeSetArray), array });
144:                elementType = arrayType.getComponentType();
145:            }
146:
147:            public Expression inline(ApplyExp exp, InlineCalls walker,
148:                    Declaration decl) {
149:                Expression[] args = exp.getArgs();
150:                if (args.length == 2) {
151:                    Expression array = this .getArgs()[1];
152:                    Expression[] xargs = new Expression[3];
153:                    xargs[0] = array;
154:                    xargs[1] = args[0];
155:                    xargs[2] = args[1];
156:                    ArraySet arrSetter = new ArraySet(elementType);
157:                    return walker.walkApplyOnly(new ApplyExp(arrSetter, xargs));
158:                }
159:                return exp;
160:            }
161:        }
162:
163:        class SetListExp extends ApplyExp {
164:            public SetListExp(Expression func, Expression[] args) {
165:                super (func, args);
166:            }
167:
168:            public Expression inline(ApplyExp exp, InlineCalls walker,
169:                    Declaration decl) {
170:                Expression[] args = exp.getArgs();
171:                if (args.length == 2) {
172:                    Expression[] xargs = new Expression[4];
173:                    xargs[0] = this .getArgs()[0];
174:                    xargs[1] = QuoteExp.getInstance("set");
175:                    xargs[2] = Convert.makeCoercion(args[0], Type.int_type);
176:                    xargs[3] = args[1];
177:                    Expression set = walker.walkApplyOnly(new ApplyExp(
178:                            Invoke.invoke, xargs));
179:                    return Convert.makeCoercion(set, Type.void_type);
180:                }
181:                return exp;
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.