Mercurial > hg > truffle
comparison graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaMethod.java @ 21556:48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 May 2015 00:36:16 +0200 |
parents | graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaMethod.java@bf7db79a6e45 |
children |
comparison
equal
deleted
inserted
replaced
21555:d12eaef9af72 | 21556:48c1ebd24120 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2012, 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.jvmci.meta; | |
24 | |
25 import java.util.*; | |
26 | |
27 /** | |
28 * Represents a reference to a Java method, either resolved or unresolved. Methods, like fields and | |
29 * types, are resolved through {@link ConstantPool constant pools}. | |
30 */ | |
31 public interface JavaMethod extends TrustedInterface { | |
32 | |
33 /** | |
34 * Returns the name of this method. | |
35 */ | |
36 String getName(); | |
37 | |
38 /** | |
39 * Returns the {@link JavaType} object representing the class or interface that declares this | |
40 * method. | |
41 */ | |
42 JavaType getDeclaringClass(); | |
43 | |
44 /** | |
45 * Returns the signature of this method. | |
46 */ | |
47 Signature getSignature(); | |
48 | |
49 /** | |
50 * Gets a string for this method formatted according to a given format specification. A format | |
51 * specification is composed of characters that are to be copied verbatim to the result and | |
52 * specifiers that denote an attribute of this method that is to be copied to the result. A | |
53 * specifier is a single character preceded by a '%' character. The accepted specifiers and the | |
54 * method attributes they denote are described below: | |
55 * | |
56 * <pre> | |
57 * Specifier | Description | Example(s) | |
58 * ----------+------------------------------------------------------------------------------------------ | |
59 * 'R' | Qualified return type | "int" "java.lang.String" | |
60 * 'r' | Unqualified return type | "int" "String" | |
61 * 'H' | Qualified holder | "java.util.Map.Entry" | |
62 * 'h' | Unqualified holder | "Entry" | |
63 * 'n' | Method name | "add" | |
64 * 'P' | Qualified parameter types, separated by ', ' | "int, java.lang.String" | |
65 * 'p' | Unqualified parameter types, separated by ', ' | "int, String" | |
66 * 'f' | Indicator if method is unresolved, static or virtual | "unresolved" "static" "virtual" | |
67 * '%' | A '%' character | "%" | |
68 * </pre> | |
69 * | |
70 * @param format a format specification | |
71 * @return the result of formatting this method according to {@code format} | |
72 * @throws IllegalFormatException if an illegal specifier is encountered in {@code format} | |
73 */ | |
74 default String format(String format) throws IllegalFormatException { | |
75 StringBuilder sb = new StringBuilder(); | |
76 int index = 0; | |
77 Signature sig = null; | |
78 while (index < format.length()) { | |
79 char ch = format.charAt(index++); | |
80 if (ch == '%') { | |
81 if (index >= format.length()) { | |
82 throw new UnknownFormatConversionException("An unquoted '%' character cannot terminate a method format specification"); | |
83 } | |
84 char specifier = format.charAt(index++); | |
85 boolean qualified = false; | |
86 switch (specifier) { | |
87 case 'R': | |
88 qualified = true; | |
89 // fall through | |
90 case 'r': { | |
91 if (sig == null) { | |
92 sig = getSignature(); | |
93 } | |
94 sb.append(sig.getReturnType(null).toJavaName(qualified)); | |
95 break; | |
96 } | |
97 case 'H': | |
98 qualified = true; | |
99 // fall through | |
100 case 'h': { | |
101 sb.append(getDeclaringClass().toJavaName(qualified)); | |
102 break; | |
103 } | |
104 case 'n': { | |
105 sb.append(getName()); | |
106 break; | |
107 } | |
108 case 'P': | |
109 qualified = true; | |
110 // fall through | |
111 case 'p': { | |
112 if (sig == null) { | |
113 sig = getSignature(); | |
114 } | |
115 for (int i = 0; i < sig.getParameterCount(false); i++) { | |
116 if (i != 0) { | |
117 sb.append(", "); | |
118 } | |
119 sb.append(sig.getParameterType(i, null).toJavaName(qualified)); | |
120 } | |
121 break; | |
122 } | |
123 case 'f': { | |
124 sb.append(!(this instanceof ResolvedJavaMethod) ? "unresolved" : ((ResolvedJavaMethod) this).isStatic() ? "static" : "virtual"); | |
125 break; | |
126 } | |
127 case '%': { | |
128 sb.append('%'); | |
129 break; | |
130 } | |
131 default: { | |
132 throw new UnknownFormatConversionException(String.valueOf(specifier)); | |
133 } | |
134 } | |
135 } else { | |
136 sb.append(ch); | |
137 } | |
138 } | |
139 return sb.toString(); | |
140 } | |
141 } |