01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: import java.lang.annotation.Annotation;
19: import java.util.Map;
20:
21: /**
22: * Represents a constructor declaration.
23: */
24: public class JConstructor extends JAbstractMethod {
25: private final JClassType enclosingType;
26:
27: public JConstructor(JClassType enclosingType, String name,
28: int declStart, int declEnd, int bodyStart, int bodyEnd) {
29: this (enclosingType, name, declStart, declEnd, bodyStart,
30: bodyEnd, null);
31: }
32:
33: public JConstructor(
34: JClassType enclosingType,
35: String name,
36: int declStart,
37: int declEnd,
38: int bodyStart,
39: int bodyEnd,
40: Map<Class<? extends Annotation>, Annotation> declaredAnnotations) {
41: super (name, declStart, declEnd, bodyStart, bodyEnd,
42: declaredAnnotations);
43: this .enclosingType = enclosingType;
44: enclosingType.addConstructor(this );
45: }
46:
47: JConstructor(JClassType enclosingType, JConstructor ctor) {
48: super (ctor);
49: this .enclosingType = enclosingType;
50: }
51:
52: @Override
53: public JClassType getEnclosingType() {
54: return enclosingType;
55: }
56:
57: @Override
58: public String getReadableDeclaration() {
59: String[] names = TypeOracle
60: .modifierBitsToNames(getModifierBits());
61: StringBuilder sb = new StringBuilder();
62: for (int i = 0; i < names.length; i++) {
63: sb.append(names[i]);
64: sb.append(" ");
65: }
66: if (getTypeParameters().length > 0) {
67: toStringTypeParams(sb);
68: sb.append(" ");
69: }
70: sb.append(getName());
71: toStringParamsAndThrows(sb);
72: return sb.toString();
73: }
74:
75: @Override
76: public JConstructor isConstructor() {
77: return this ;
78: }
79:
80: @Override
81: public JMethod isMethod() {
82: return null;
83: }
84:
85: @Override
86: public String toString() {
87: return getReadableDeclaration();
88: }
89: }
|