KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > bridge > ConstructorElementImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.bridge;
21
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24
25 import org.openide.src.*;
26 import org.netbeans.jmi.javamodel.Constructor;
27
28 class ConstructorElementImpl extends CallableImpl {
29
30     private ElementImpl.ElementListener callableListener;
31
32     private static final long serialVersionUID = 3379682002192002288L;
33
34     ConstructorElementImpl(DefaultLangModel model, Constructor constructor) {
35         super(model, constructor);
36     }
37
38     protected void setParent(ElementImpl impl) {
39         if (impl instanceof ClassElementImpl) {
40             this.declaringClassImpl = (ClassElementImpl)impl;
41         }
42     }
43     
44     public Object JavaDoc readResolve() {
45         return null;
46     }
47     
48     public void connectListener () {
49         callableListener = new CallableImpl.CallableListener (this);
50         callableListener.connect ();
51     }
52     
53     protected Identifier createName(String JavaDoc dummy) {
54         if (getDeclaringImpl() != null)
55             return Identifier.create(getDeclaringImpl().getName().getSourceName());
56         else
57             return super.createName(dummy);
58     }
59     
60     /** Imposes additional constraint on the constructor: the declaring class'
61      * name must match the constructor's name.
62      */

63     protected void checkNameConstraints(Identifier name) throws SourceException {
64         super.checkNameConstraints(name);
65         // additional constraint:
66
// PENDING: do not check depending on model lock type.
67
if (!name.getName().equals(getDeclaringImpl().getName().getName())) {
68             throw new SourceException("Invalid constructor name: " + name); // NOI18N
69
}
70     }
71     
72     /** Check for modifiers disallowed on a constructor: static, strictfp, final,
73      * synchronized, abstract
74      */

75     protected void checkModifierConstraints(int newMods) throws SourceException {
76         super.checkModifierConstraints(newMods);
77         // PENDING: constraint checking depending on the lock type
78
if ((newMods & (Modifier.STATIC | Modifier.STRICT | Modifier.FINAL |
79             Modifier.ABSTRACT | Modifier.SYNCHRONIZED)) > 0) {
80             throw new SourceException("Invalid constructor modifiers : " + // NOI18N
81
Modifier.toString(newMods));
82         }
83     }
84
85     public String JavaDoc toString() {
86         return "ConstructorElementImpl[" + getName().getSourceName() + ", " + // NOI18N
87
getParameters().length + " args]"; // NOI18N
88
}
89     
90     protected Element cloneSelf() {
91         ConstructorElement clone = new ConstructorElement();
92         copyCallableProperties(clone);
93         return clone;
94     }
95 }
Popular Tags