StringConstants.java revision 830:03b2757e2eba
1/*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package jdk.nashorn.internal.tools.nasgen;
27
28import java.lang.invoke.MethodHandle;
29import java.util.Collection;
30import java.util.ArrayList;
31import java.util.Collections;
32import java.util.List;
33import jdk.internal.org.objectweb.asm.Type;
34import jdk.nashorn.internal.objects.PrototypeObject;
35import jdk.nashorn.internal.objects.ScriptFunctionImpl;
36import jdk.nashorn.internal.runtime.AccessorProperty;
37import jdk.nashorn.internal.runtime.PropertyMap;
38import jdk.nashorn.internal.runtime.ScriptFunction;
39import jdk.nashorn.internal.runtime.ScriptObject;
40
41/**
42 * String constants used for code generation/instrumentation.
43 */
44@SuppressWarnings("javadoc")
45public interface StringConstants {
46    // standard jdk types, methods
47    static final Type TYPE_METHODHANDLE       = Type.getType(MethodHandle.class);
48    static final Type TYPE_METHODHANDLE_ARRAY = Type.getType(MethodHandle[].class);
49    static final Type TYPE_OBJECT             = Type.getType(Object.class);
50    static final Type TYPE_STRING             = Type.getType(String.class);
51    static final Type TYPE_COLLECTION         = Type.getType(Collection.class);
52    static final Type TYPE_COLLECTIONS        = Type.getType(Collections.class);
53    static final Type TYPE_ARRAYLIST          = Type.getType(ArrayList.class);
54    static final Type TYPE_LIST               = Type.getType(List.class);
55
56    static final String CLINIT = "<clinit>";
57    static final String INIT = "<init>";
58    static final String DEFAULT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE);
59
60    static final String METHODHANDLE_TYPE = TYPE_METHODHANDLE.getInternalName();
61    static final String OBJECT_TYPE = TYPE_OBJECT.getInternalName();
62    static final String OBJECT_DESC = TYPE_OBJECT.getDescriptor();
63    static final String OBJECT_ARRAY_DESC = Type.getDescriptor(Object[].class);
64    static final String ARRAYLIST_TYPE = TYPE_ARRAYLIST.getInternalName();
65    static final String COLLECTION_TYPE = TYPE_COLLECTION.getInternalName();
66    static final String COLLECTIONS_TYPE = TYPE_COLLECTIONS.getInternalName();
67
68    // java.util.Collection.add(Object)
69    static final String COLLECTION_ADD = "add";
70    static final String COLLECTION_ADD_DESC = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, TYPE_OBJECT);
71    // java.util.ArrayList.<init>(int)
72    static final String ARRAYLIST_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE);
73    // java.util.Collections.EMPTY_LIST
74    static final String COLLECTIONS_EMPTY_LIST = "EMPTY_LIST";
75    static final String LIST_DESC = TYPE_LIST.getDescriptor();
76
77    // Nashorn types, methods
78    static final Type TYPE_ACCESSORPROPERTY   = Type.getType(AccessorProperty.class);
79    static final Type TYPE_PROPERTYMAP        = Type.getType(PropertyMap.class);
80    static final Type TYPE_PROTOTYPEOBJECT    = Type.getType(PrototypeObject.class);
81    static final Type TYPE_SCRIPTFUNCTION     = Type.getType(ScriptFunction.class);
82    static final Type TYPE_SCRIPTFUNCTIONIMPL = Type.getType(ScriptFunctionImpl.class);
83    static final Type TYPE_SCRIPTOBJECT       = Type.getType(ScriptObject.class);
84
85    static final String PROTOTYPE_SUFFIX = "$Prototype";
86    static final String CONSTRUCTOR_SUFFIX = "$Constructor";
87
88    // This field name is known to Nashorn runtime (Context).
89    // Synchronize the name change, if needed at all.
90    static final String PROPERTYMAP_FIELD_NAME = "$nasgenmap$";
91    static final String $CLINIT$ = "$clinit$";
92
93    // AccessorProperty
94    static final String ACCESSORPROPERTY_TYPE = TYPE_ACCESSORPROPERTY.getInternalName();
95    static final String ACCESSORPROPERTY_CREATE = "create";
96    static final String ACCESSORPROPERTY_CREATE_DESC =
97        Type.getMethodDescriptor(TYPE_ACCESSORPROPERTY, TYPE_STRING, Type.INT_TYPE, TYPE_METHODHANDLE, TYPE_METHODHANDLE);
98
99    // PropertyMap
100    static final String PROPERTYMAP_TYPE = TYPE_PROPERTYMAP.getInternalName();
101    static final String PROPERTYMAP_DESC = TYPE_PROPERTYMAP.getDescriptor();
102    static final String PROPERTYMAP_NEWMAP = "newMap";
103    static final String PROPERTYMAP_NEWMAP_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP, TYPE_COLLECTION);
104
105    // PrototypeObject
106    static final String PROTOTYPEOBJECT_TYPE = TYPE_PROTOTYPEOBJECT.getInternalName();
107    static final String PROTOTYPEOBJECT_SETCONSTRUCTOR = "setConstructor";
108    static final String PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT, TYPE_OBJECT);
109
110    // ScriptFunction
111    static final String SCRIPTFUNCTION_TYPE = TYPE_SCRIPTFUNCTION.getInternalName();
112    static final String SCRIPTFUNCTION_SETARITY = "setArity";
113    static final String SCRIPTFUNCTION_SETARITY_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE);
114    static final String SCRIPTFUNCTION_SETPROTOTYPE = "setPrototype";
115    static final String SCRIPTFUNCTION_SETPROTOTYPE_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT);
116
117    // ScriptFunctionImpl
118    static final String SCRIPTFUNCTIONIMPL_TYPE = TYPE_SCRIPTFUNCTIONIMPL.getInternalName();
119    static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION = "makeFunction";
120    static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC =
121        Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE);
122    static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC =
123        Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE, TYPE_METHODHANDLE_ARRAY);
124    static final String SCRIPTFUNCTIONIMPL_INIT_DESC3 =
125        Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_METHODHANDLE_ARRAY);
126    static final String SCRIPTFUNCTIONIMPL_INIT_DESC4 =
127        Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_PROPERTYMAP, TYPE_METHODHANDLE_ARRAY);
128
129    // ScriptObject
130    static final String SCRIPTOBJECT_TYPE = TYPE_SCRIPTOBJECT.getInternalName();
131    static final String SCRIPTOBJECT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_PROPERTYMAP);
132
133    static final String GETTER_PREFIX = "G$";
134    static final String SETTER_PREFIX = "S$";
135
136    // ScriptObject.getClassName() method.
137    static final String GET_CLASS_NAME = "getClassName";
138    static final String GET_CLASS_NAME_DESC = Type.getMethodDescriptor(TYPE_STRING);
139}
140