KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > AnnotationTypeImpl


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 package org.netbeans.modules.javacore.jmiimpl.javamodel;
20
21 import java.lang.ref.WeakReference JavaDoc;
22 import java.util.*;
23 import javax.jmi.reflect.ConstraintViolationException;
24 import org.netbeans.jmi.javamodel.*;
25 import org.netbeans.lib.java.parser.ASTree;
26 import org.netbeans.mdr.storagemodel.StorableObject;
27 import org.netbeans.modules.javacore.parser.ASTProvider;
28 import org.netbeans.modules.javacore.parser.AnnotationTypeInfo;
29 import org.netbeans.modules.javacore.parser.ElementInfo;
30
31 /**
32  *
33  * @author Pavel Flaska
34  */

35 public abstract class AnnotationTypeImpl extends JavaClassImpl implements AnnotationType {
36
37     static final ElementInfo DEFAULT_INFO = new AnnotationTypeInfo(null, AnnotationTypeInfo.ANNOTATIONTYPE_TYPE, null, 0, null, null);
38     
39     /** Creates a new instance of AnnotationTypeImpl */
40     public AnnotationTypeImpl(StorableObject s) {
41         super(s);
42     }
43     
44     public boolean isInterface() {
45         return true;
46     }
47     
48     public void setInterface(boolean newValue) {
49         if (newValue) {
50             throw new UnsupportedOperationException JavaDoc("setInterface()"); // NOI18N
51
}
52     }
53     
54     public List getInterfaces() {
55         TypeClass typeClass = ((JavaModelPackage) refImmediatePackage()).getType();
56         return Collections.singletonList(typeClass.resolve("java.lang.annotation.Annotation")); // NOI18N
57
}
58     
59     /**
60      * Set superclass is not allowed for <tt>AnnotationType</tt> as the
61      * superclass is always <tt>java.lang.annotation.Annotation</tt>.
62      * Implemented only to override java class implementation.
63      *
64      * @param newValue for not null values, it throws ConstraintViolationException
65      * @throws ConstraintViolationException if parameter is not <tt>null</tt> value
66      */

67     public void setSuperClass(JavaClass newValue) {
68         if (newValue != null) {
69             throw new ConstraintViolationException(null, null, "Cannot set superclass of annotation type."); // NOI18N
70
}
71     }
72     
73     public void setSuperClassName(MultipartId newValue) {
74         if (newValue != null) {
75             throw new ConstraintViolationException(null, null, "Cannot set superclass name of annotation type."); // NOI18N
76
}
77     }
78
79     protected ElementInfo getDefaultInfo() {
80         return DEFAULT_INFO;
81     }
82     
83     public List getInterfaceNames() {
84         return Collections.EMPTY_LIST;
85     }
86     
87     protected ASTree getPartEndTree(ElementPartKind part) {
88         if (ElementPartKindEnum.HEADER.equals(part)) {
89             return getASTree().getSubTrees()[1];
90         }
91         return super.getPartEndTree(part);
92     }
93
94     public String JavaDoc getSourceText() {
95         String JavaDoc origElem;
96         if ((origElem = checkChange()) != null)
97             return origElem;
98         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
99         buf.append('\n');
100         generateNewJavaDoc(buf);
101         buf.append(getIndentation());
102         generateNewModifiers(buf);
103         buf.append("@interface "); // NOI18N
104
buf.append(getSimpleName());
105         ClassDefinitionImpl.generateNewFeatures(this, buf, true);
106         return buf.toString();
107     }
108     
109     public void getDiff(List diffList) {
110         AnnotationTypeInfo astInfo = (AnnotationTypeInfo) getElementInfo();
111         ASTProvider parser = getParser();
112         ASTree[] children = getASTree().getSubTrees();
113
114         // javadoc print
115
replaceJavaDoc(diffList);
116         // print modifiers
117
if (isChanged(CHANGED_MODIFIERS | CHANGED_ANNOTATION)) {
118             diffModifiers(diffList, parser.getToken(children[1].getFirstToken() - 2), parser);
119         } else if (children[0] != null) {
120             getCollectionDiff(diffList, parser, CHANGED_ANNOTATION, astInfo.annotations, getAnnotations(), parser.getToken(children[0].getLastToken()).getEndOffset(), " "); // NOI18N
121
}
122         // print name
123
if (isChanged(CHANGED_NAME)) {
124             replaceNode(diffList, parser, children[1], getSimpleName(), 0, null);
125         }
126         getCollectionDiff(diffList, parser, CHANGED_FEATURES, astInfo.features, getContents(), getContentsEndOffset(parser, getASTree()), "\n"); // NOI18N
127
}
128
129     public Element duplicate(JavaModelPackage targetExtent) {
130         return targetExtent.getAnnotationType().createAnnotationType(
131                 getName(),
132                 duplicateList(getAnnotations(), targetExtent),
133                 getModifiers(),
134                 null,
135                 (JavaDoc) duplicateElement(getJavadoc(), targetExtent),
136                 duplicateList(getContents(), targetExtent),
137                 (MultipartId) duplicateElement(getSuperClassName(), targetExtent),
138                 duplicateList(getInterfaceNames(), targetExtent),
139                 duplicateList(getTypeParameters(), targetExtent)
140                );
141     }
142
143 }
144
Popular Tags