StringConstants.java revision 1626:d99fa86747ee
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.ArrayList;
30import java.util.Collection;
31import java.util.Collections;
32import java.util.List;
33import jdk.internal.org.objectweb.asm.Type;
34import jdk.nashorn.internal.objects.NativeSymbol;
35import jdk.nashorn.internal.runtime.AccessorProperty;
36import jdk.nashorn.internal.runtime.PropertyMap;
37import jdk.nashorn.internal.runtime.PrototypeObject;
38import jdk.nashorn.internal.runtime.ScriptFunction;
39import jdk.nashorn.internal.runtime.ScriptObject;
40import jdk.nashorn.internal.runtime.Specialization;
41import jdk.nashorn.internal.runtime.Symbol;
42
43/**
44 * String constants used for code generation/instrumentation.
45 */
46@SuppressWarnings("javadoc")
47public interface StringConstants {
48    // standard jdk types, methods
49    static final Type TYPE_METHODHANDLE         = Type.getType(MethodHandle.class);
50    static final Type TYPE_METHODHANDLE_ARRAY   = Type.getType(MethodHandle[].class);
51    static final Type TYPE_SPECIALIZATION       = Type.getType(Specialization.class);
52    static final Type TYPE_SPECIALIZATION_ARRAY = Type.getType(Specialization[].class);
53    static final Type TYPE_OBJECT               = Type.getType(Object.class);
54    static final Type TYPE_STRING               = Type.getType(String.class);
55    static final Type TYPE_CLASS                = Type.getType(Class.class);
56    static final Type TYPE_COLLECTION           = Type.getType(Collection.class);
57    static final Type TYPE_COLLECTIONS          = Type.getType(Collections.class);
58    static final Type TYPE_ARRAYLIST            = Type.getType(ArrayList.class);
59    static final Type TYPE_LIST                 = Type.getType(List.class);
60
61    static final String CLINIT = "<clinit>";
62    static final String INIT = "<init>";
63    static final String DEFAULT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE);
64
65    static final String METHODHANDLE_TYPE = TYPE_METHODHANDLE.getInternalName();
66    static final String SPECIALIZATION_TYPE = TYPE_SPECIALIZATION.getInternalName();
67    static final String SPECIALIZATION_INIT2 = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_METHODHANDLE, Type.getType(boolean.class));
68    static final String SPECIALIZATION_INIT3 = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_METHODHANDLE, TYPE_CLASS, Type.getType(boolean.class));
69    static final String OBJECT_TYPE = TYPE_OBJECT.getInternalName();
70    static final String OBJECT_DESC = TYPE_OBJECT.getDescriptor();
71    static final String STRING_TYPE = TYPE_STRING.getInternalName();
72    static final String STRING_DESC = TYPE_STRING.getDescriptor();
73    static final String OBJECT_ARRAY_DESC = Type.getDescriptor(Object[].class);
74    static final String ARRAYLIST_TYPE = TYPE_ARRAYLIST.getInternalName();
75    static final String COLLECTION_TYPE = TYPE_COLLECTION.getInternalName();
76    static final String COLLECTIONS_TYPE = TYPE_COLLECTIONS.getInternalName();
77
78    // java.util.Collection.add(Object)
79    static final String COLLECTION_ADD = "add";
80    static final String COLLECTION_ADD_DESC = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, TYPE_OBJECT);
81    // java.util.ArrayList.<init>(int)
82    static final String ARRAYLIST_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE);
83    // java.util.Collections.EMPTY_LIST
84    static final String COLLECTIONS_EMPTY_LIST = "EMPTY_LIST";
85    static final String LIST_DESC = TYPE_LIST.getDescriptor();
86
87    // Nashorn types, methods
88    static final Type TYPE_ACCESSORPROPERTY   = Type.getType(AccessorProperty.class);
89    static final Type TYPE_PROPERTYMAP        = Type.getType(PropertyMap.class);
90    static final Type TYPE_PROTOTYPEOBJECT    = Type.getType(PrototypeObject.class);
91    static final Type TYPE_SCRIPTFUNCTION     = Type.getType(ScriptFunction.class);
92    static final Type TYPE_SCRIPTOBJECT       = Type.getType(ScriptObject.class);
93    static final Type TYPE_NATIVESYMBOL       = Type.getType(NativeSymbol.class);
94    static final Type TYPE_SYMBOL             = Type.getType(Symbol.class);
95
96    static final String PROTOTYPE_SUFFIX = "$Prototype";
97    static final String CONSTRUCTOR_SUFFIX = "$Constructor";
98
99    // This field name is known to Nashorn runtime (Context).
100    // Synchronize the name change, if needed at all.
101    static final String PROPERTYMAP_FIELD_NAME = "$nasgenmap$";
102    static final String $CLINIT$ = "$clinit$";
103
104    // AccessorProperty
105    static final String ACCESSORPROPERTY_TYPE = TYPE_ACCESSORPROPERTY.getInternalName();
106    static final String ACCESSORPROPERTY_CREATE = "create";
107    static final String ACCESSORPROPERTY_CREATE_DESC =
108        Type.getMethodDescriptor(TYPE_ACCESSORPROPERTY, TYPE_OBJECT, Type.INT_TYPE, TYPE_METHODHANDLE, TYPE_METHODHANDLE);
109
110    // PropertyMap
111    static final String PROPERTYMAP_TYPE = TYPE_PROPERTYMAP.getInternalName();
112    static final String PROPERTYMAP_DESC = TYPE_PROPERTYMAP.getDescriptor();
113    static final String PROPERTYMAP_NEWMAP = "newMap";
114    static final String PROPERTYMAP_NEWMAP_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP, TYPE_COLLECTION);
115
116    // PrototypeObject
117    static final String PROTOTYPEOBJECT_TYPE = TYPE_PROTOTYPEOBJECT.getInternalName();
118    static final String PROTOTYPEOBJECT_SETCONSTRUCTOR = "setConstructor";
119    static final String PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT, TYPE_OBJECT);
120
121    // ScriptFunction
122    static final String SCRIPTFUNCTION_TYPE = TYPE_SCRIPTFUNCTION.getInternalName();
123    static final String SCRIPTFUNCTION_SETARITY = "setArity";
124    static final String SCRIPTFUNCTION_SETARITY_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE);
125    static final String SCRIPTFUNCTION_SETDOCUMENTATIONKEY = "setDocumentationKey";
126    static final String SCRIPTFUNCTION_SETDOCUMENTATIONKEY_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING);
127    static final String SCRIPTFUNCTION_SETPROTOTYPE = "setPrototype";
128    static final String SCRIPTFUNCTION_SETPROTOTYPE_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT);
129    static final String SCRIPTFUNCTION_CREATEBUILTIN = "createBuiltin";
130    static final String SCRIPTFUNCTION_CREATEBUILTIN_DESC =
131        Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE);
132    static final String SCRIPTFUNCTION_CREATEBUILTIN_SPECS_DESC =
133        Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE, TYPE_SPECIALIZATION_ARRAY);
134    static final String SCRIPTFUNCTION_INIT_DESC3 =
135        Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_SPECIALIZATION_ARRAY);
136    static final String SCRIPTFUNCTION_INIT_DESC4 =
137        Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_PROPERTYMAP, TYPE_SPECIALIZATION_ARRAY);
138
139    // ScriptObject
140    static final String SCRIPTOBJECT_TYPE = TYPE_SCRIPTOBJECT.getInternalName();
141    static final String SCRIPTOBJECT_DESC = TYPE_SCRIPTOBJECT.getDescriptor();
142    static final String SCRIPTOBJECT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_PROPERTYMAP);
143
144    static final String GETTER_PREFIX = "G$";
145    static final String SETTER_PREFIX = "S$";
146
147    // ScriptObject.getClassName() method.
148    static final String GET_CLASS_NAME = "getClassName";
149    static final String GET_CLASS_NAME_DESC = Type.getMethodDescriptor(TYPE_STRING);
150
151    // NativeSymbol
152    static final String NATIVESYMBOL_TYPE = TYPE_NATIVESYMBOL.getInternalName();
153    static final String SYMBOL_DESC = TYPE_SYMBOL.getDescriptor();
154    static final String SYMBOL_PREFIX = "@@";
155}
156