KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > core > ext > typeinfo > JMethod


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.core.ext.typeinfo;
17
18 /**
19  * Represents a method declaration.
20  */

21 public class JMethod extends JAbstractMethod {
22
23   private final JClassType enclosingType;
24
25   private JType returnType;
26
27   public JMethod(JClassType enclosingType, String JavaDoc name, int declStart,
28       int declEnd, int bodyStart, int bodyEnd) {
29     super(name, declStart, declEnd, bodyStart, bodyEnd);
30     this.enclosingType = enclosingType;
31     enclosingType.addMethod(this);
32   }
33
34   public JClassType getEnclosingType() {
35     return enclosingType;
36   }
37
38   public String JavaDoc getReadableDeclaration() {
39     return getReadableDeclaration(getModifierBits());
40   }
41
42   public String JavaDoc getReadableDeclaration(boolean noAccess, boolean noNative,
43       boolean noStatic, boolean noFinal, boolean noAbstract) {
44     int bits = getModifierBits();
45     if (noAccess) {
46       bits &= ~(TypeOracle.MOD_PUBLIC | TypeOracle.MOD_PRIVATE | TypeOracle.MOD_PROTECTED);
47     }
48     if (noNative) {
49       bits &= ~TypeOracle.MOD_NATIVE;
50     }
51     if (noStatic) {
52       bits &= ~TypeOracle.MOD_STATIC;
53     }
54     if (noFinal) {
55       bits &= ~TypeOracle.MOD_FINAL;
56     }
57     if (noAbstract) {
58       bits &= ~TypeOracle.MOD_ABSTRACT;
59     }
60     return getReadableDeclaration(bits);
61   }
62
63   public JType getReturnType() {
64     return returnType;
65   }
66
67   public boolean isAbstract() {
68     return 0 != (getModifierBits() & TypeOracle.MOD_ABSTRACT);
69   }
70
71   public JConstructor isConstructor() {
72     return null;
73   }
74
75   public boolean isFinal() {
76     return 0 != (getModifierBits() & TypeOracle.MOD_FINAL);
77   }
78
79   public JMethod isMethod() {
80     return this;
81   }
82
83   public boolean isNative() {
84     return 0 != (getModifierBits() & TypeOracle.MOD_NATIVE);
85   }
86
87   public boolean isStatic() {
88     return 0 != (getModifierBits() & TypeOracle.MOD_STATIC);
89   }
90
91   public void setReturnType(JType type) {
92     returnType = type;
93   }
94
95   public String JavaDoc toString() {
96     return getReadableDeclaration();
97   }
98
99   String JavaDoc getReadableDeclaration(int modifierBits) {
100     String JavaDoc[] names = TypeOracle.modifierBitsToNames(modifierBits);
101     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
102     for (int i = 0; i < names.length; i++) {
103       sb.append(names[i]);
104       sb.append(" ");
105     }
106     sb.append(returnType.getParameterizedQualifiedSourceName());
107     sb.append(" ");
108     sb.append(getName());
109
110     toStringParamsAndThrows(sb);
111
112     return sb.toString();
113   }
114 }
115
Popular Tags