KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
22 import javax.jmi.model.MofClass;
23 import javax.jmi.model.NameNotFoundException;
24 import javax.jmi.reflect.*;
25 import org.netbeans.api.mdr.MDRObject;
26 import org.netbeans.api.mdr.MDRepository;
27 import org.netbeans.api.mdr.events.MDRChangeListener;
28 import org.netbeans.jmi.javamodel.*;
29 import org.netbeans.mdr.handlers.InstanceHandler;
30 import org.netbeans.mdr.handlers.BaseObjectHandler;
31 import org.netbeans.mdr.storagemodel.StorableObject;
32
33 /**
34  *
35  * @author Dusan Balek, Martin Matula
36  */

37 public abstract class ParameterizedTypeImpl extends InstanceHandler implements ParameterizedType {
38
39     JavaClass definition = null;
40     List parameters = null;
41     ParameterizedType outerCls = null;
42     Map substMap = null;
43     int wildcards[];
44
45     private WrapperList featureList = null;
46     private WrapperList contentsList = null;
47
48     public ParameterizedTypeImpl(StorableObject s) {
49         super(s);
50     }
51
52     // ParameterizedType implementation .........................................
53

54     public JavaClass getDefinition() {
55         return definition;
56     }
57
58     public List getParameters() {
59         return parameters;
60     }
61     
62     public int getWildCardStatus(int paramIndex) {
63         return wildcards != null ? wildcards[paramIndex] : 0;
64     }
65     
66     public void setWildCardStatus(int paramIndex, int status) {
67         if (wildcards == null) {
68             wildcards = new int[parameters.size()];
69         }
70         wildcards[paramIndex] = status;
71     }
72     
73     public boolean isValid() {
74         return definition.isValid();
75     }
76
77     public void setDefinition(JavaClass newValue) {
78         throw constructIsReadOnly(this, "definition"); // NOI18N
79
}
80
81     // JavaClass implementation .................................................
82

83     public String JavaDoc getSimpleName() {
84         return constructName(false);
85     }
86
87     public boolean isInterface() {
88         return definition.isInterface();
89     }
90     
91     public boolean isInner() {
92         return definition.isInner();
93     }
94     
95     public void setInterface(boolean newValue) {
96         throw constructIsReadOnly(this, "interface"); // NOI18N
97
}
98
99     public void setSimpleName(String JavaDoc newValue) {
100         throw constructIsReadOnly(this, "simpleName"); // NOI18N
101
}
102
103     public java.util.Collection JavaDoc findSubTypes(boolean recursively) {
104         return definition.findSubTypes(recursively);
105     }
106
107     public java.util.Collection JavaDoc getImplementors() {
108         return definition.getImplementors();
109     }
110     
111     public java.util.Collection JavaDoc getSubClasses() {
112         return definition.getSubClasses();
113     }
114     
115     // Feature implementation ...............................................
116

117     public boolean isDeprecated() {
118         return definition.isDeprecated();
119     }
120
121     public void setDeprecated(boolean newValue) {
122         definition.setDeprecated(newValue);
123     }
124     
125     // ClassMember implementation ...............................................
126

127     public ClassDefinition getDeclaringClass() {
128         return outerCls != null ? outerCls : definition.getDeclaringClass();
129     }
130
131     public JavaDoc getJavadoc() {
132         return definition.getJavadoc();
133     }
134
135     public String JavaDoc getJavadocText() {
136         return definition.getJavadocText();
137     }
138
139     public int getModifiers() {
140         return definition.getModifiers();
141     }
142
143     public void setJavadoc(JavaDoc newValue) {
144         throw constructIsReadOnly(this, "javaDoc"); // NOI18N
145
}
146
147     public void setJavadocText(String JavaDoc newValue) {
148         throw constructIsReadOnly(this, "javaDocText"); // NOI18N
149
}
150
151     public void setModifiers(int newValue) {
152         throw constructIsReadOnly(this, "modifiers"); // NOI18N
153
}
154     
155     public List getChildren() {
156         return Collections.EMPTY_LIST;
157     }
158
159     public void replaceChild(Element oldElement, Element newElement) {
160         throw new UnsupportedOperationException JavaDoc();
161     }
162
163     // AnnotableElement implementation ..........................................
164

165     public List getAnnotations() {
166         return definition.getAnnotations();
167     }
168
169     // NamedElement implementation ..............................................
170

171     public String JavaDoc getName() {
172         return constructName(true);
173     }
174
175     public void setName(String JavaDoc newValue) {
176         throw constructIsReadOnly(this, "name"); // NOI18N
177
}
178     
179     public Collection getReferences() {
180         return definition.getReferences();
181     }
182
183     // ClassDefinition implementation ...........................................
184

185     public Constructor getConstructor(List parameters, boolean includeSupertypes) {
186         initSubstitutionMap();
187         return (Constructor)wrap(definition.getConstructor(parameters, includeSupertypes));
188     }
189
190     public List getContents() {
191         initSubstitutionMap();
192         if (contentsList == null)
193             contentsList = new WrapperList(definition.getContents(), "contents"); // NOI18N
194
return contentsList;
195     }
196
197     public List getFeatures() {
198         initSubstitutionMap();
199         if (featureList == null)
200             featureList = new WrapperList(definition.getFeatures(), "features"); // NOI18N
201
return featureList;
202     }
203
204     public Field getField(String JavaDoc name, boolean includeSupertypes) {
205         initSubstitutionMap();
206         return (Field)wrap(definition.getField(name, includeSupertypes));
207     }
208
209     public JavaClass getInnerClass(String JavaDoc simpleName, boolean includeSupertypes) {
210         initSubstitutionMap();
211         return (JavaClass)wrap(definition.getInnerClass(simpleName, includeSupertypes));
212     }
213
214     public List getInterfaceNames() {
215         return definition.getInterfaceNames();
216     }
217
218     public List getInterfaces() {
219         initSubstitutionMap();
220         return new SubstitutionList(definition.getInterfaces());
221     }
222
223     public Method getMethod(String JavaDoc name, List parameters, boolean includeSupertypes) {
224         initSubstitutionMap();
225         return ClassDefinitionImpl.getMethod(this, name, parameters, includeSupertypes);
226     }
227
228     public JavaClass getSuperClass() {
229         return (JavaClass) rebuildObject(definition.getSuperClass());
230     }
231
232     public MultipartId getSuperClassName() {
233         return definition.getSuperClassName();
234     }
235
236     public void setSuperClass(JavaClass newValue) {
237         throw constructIsReadOnly(this, "superClass"); // NOI18N
238
}
239
240     public void setSuperClassName(MultipartId newValue) {
241         throw constructIsReadOnly(this, "superClassName"); // NOI18N
242
}
243     
244     public boolean isSubTypeOf(ClassDefinition cls) {
245         return definition.isSubTypeOf(cls);
246     }
247
248     // GenericElement implementation ............................................
249

250     public List getTypeParameters() {
251         return definition.getTypeParameters();
252     }
253
254     // Element implementation ............................................
255

256     public Resource getResource() {
257         return definition.getResource();
258     }
259
260     // helper methods ...........................................................
261

262     static ConstraintViolationException constructIsReadOnly(RefObject obj, String JavaDoc attrName) {
263         RefObject attr = null;
264         try {
265             attr = ((MofClass) obj.refMetaObject()).lookupElementExtended(attrName);
266         } catch (NameNotFoundException e) {
267             // ignore
268
}
269         attrName = attrName.substring(0, 1).toUpperCase() + attrName.substring(1);
270         return new ConstraintViolationException(obj, attr, attrName + " is readonly."); // NOI18N
271
}
272
273     String JavaDoc constructName(boolean useFQN) {
274         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
275         if (useFQN) {
276             if (outerCls != null) {
277                 sb.append(outerCls.getName());
278                 sb.append('.'); // NOI18N
279
sb.append(definition.getSimpleName());
280             } else {
281                 sb.append(definition.getName());
282             }
283         } else {
284             sb.append(definition.getSimpleName());
285         }
286         if (parameters != null && parameters.size() > 0) {
287             sb.append('<'); // NOI18N
288
Iterator it = parameters.iterator();
289             
290             for (int i=0;it.hasNext();i++) {
291                 Type param = (Type) it.next();
292                 int status=getWildCardStatus(i);
293                 
294                 if (status>0) {
295                     sb.append("?");
296                     switch (status) {
297                         case 1: // lower bound
298
sb.append(" extends ");
299                             break;
300                         case 2: // upper bound
301
sb.append(" super ");
302                             break;
303                         case 3: // wildcard
304
break;
305                         default:
306                             throw new IllegalArgumentException JavaDoc("Invalid bound "+status);
307                     }
308                 }
309                 if (status!=3) {
310                     sb.append(!useFQN && param instanceof JavaClass ? ((JavaClass)param).getSimpleName() : param.getName());
311                 }
312                 if (it.hasNext())
313                     sb.append(',');
314             }
315             sb.append('>'); // NOI18N
316
}
317         return sb.toString();
318     }
319     
320     void initSubstitutionMap() {
321         if (substMap != null) return;
322         substMap = new HashMap();
323         ClassDefinition cd = this;
324         while (cd instanceof ParameterizedType) {
325             List parameters = ((ParameterizedType)cd).getParameters();
326             Iterator itt = parameters.iterator();
327             if (itt.hasNext()) {
328                 for (Iterator it = ((ParameterizedType)cd).getDefinition().getTypeParameters().iterator(); it.hasNext() && itt.hasNext();) {
329                     substMap.put(it.next(), itt.next());
330                 }
331             }
332             cd = ((ParameterizedType)cd).getDeclaringClass();
333         }
334     }
335
336     private void lock() {
337         ((BaseObjectHandler) definition).repository().beginTrans(false);
338     }
339
340     private void unlock() {
341         ((BaseObjectHandler) definition).repository().endTrans(false);
342     }
343
344     private class WrapperList implements List {
345
346         private List list;
347         private String JavaDoc attrName;
348
349         public WrapperList(List list, String JavaDoc attrName) {
350             this.list = list;
351             this.attrName = attrName;
352         }
353
354         public int size() {
355             return list.size();
356         }
357
358         public boolean isEmpty() {
359             return list.isEmpty();
360         }
361
362         public boolean contains(Object JavaDoc o) {
363             Object JavaDoc obj = o;
364             if (obj instanceof Wrapper) {
365                 obj = ((Wrapper)obj).getWrappedObject();
366             }
367             return list.contains(obj);
368         }
369
370         public Iterator iterator() {
371             return listIterator();
372         }
373
374         public Object JavaDoc[] toArray() {
375             lock();
376             try {
377                 Object JavaDoc[] result = list.toArray();
378                 for (int i = 0; i<result.length; i++) {
379                     result[i] = wrap(result[i]);
380                 }
381                 return result;
382             } finally {
383                 unlock();
384             }
385         }
386
387         public Object JavaDoc[] toArray(Object JavaDoc a[]) {
388             lock();
389             try {
390                 a = list.toArray(a);
391                 for (int i = 0; i<a.length && a[i]!=null; i++) {
392                     a[i] = wrap(a[i]);
393                 }
394                 return a;
395             } finally {
396                 unlock();
397             }
398         }
399
400         public boolean add(Object JavaDoc o) {
401             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
402         }
403
404         public boolean remove(Object JavaDoc o) {
405             throw constructIsReadOnly(null, attrName);
406         }
407
408         public boolean containsAll(Collection c) {
409             lock();
410             try {
411                 for (Iterator it = c.iterator(); it.hasNext();) {
412                     if (!contains(it.next())) {
413                         return false;
414                     }
415                 }
416                 return true;
417             } finally {
418                 unlock();
419             }
420         }
421
422         public boolean addAll(Collection c) {
423             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
424         }
425
426         public boolean addAll(int index, Collection c) {
427             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
428         }
429
430         public boolean removeAll(Collection c) {
431             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
432         }
433
434         public boolean retainAll(Collection c) {
435             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
436         }
437
438         public void clear() {
439             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
440         }
441
442         public Object JavaDoc get(int index) {
443             lock();
444             try {
445                 return listIterator(index).next();
446             } finally {
447                 unlock();
448             }
449         }
450
451         public Object JavaDoc set(int index, Object JavaDoc element) {
452             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
453         }
454
455         public void add(int index, Object JavaDoc element) {
456             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
457         }
458
459         public Object JavaDoc remove(int index) {
460             throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
461         }
462
463         public int indexOf(Object JavaDoc o) {
464             lock();
465             try {
466                 for (ListIterator it = listIterator(); it.hasNext();) {
467                     if (it.next().equals(o)) {
468                         return it.previousIndex();
469                     }
470                 }
471                 return -1;
472             } finally {
473                 unlock();
474             }
475         }
476
477         public int lastIndexOf(Object JavaDoc o) {
478             lock();
479             try {
480                 int result = -1;
481                 for (ListIterator it = listIterator(); it.hasNext();) {
482                     if (it.next().equals(o)) {
483                         result = it.previousIndex();
484                     }
485                 }
486                 return result;
487             } finally {
488                 unlock();
489             }
490         }
491
492         public ListIterator listIterator() {
493             return new WrapperListIterator(list.listIterator());
494         }
495
496         public ListIterator listIterator(int index) {
497             return new WrapperListIterator(list.listIterator(index));
498         }
499
500         public List subList(int fromIndex, int toIndex) {
501             throw new UnsupportedOperationException JavaDoc();
502         }
503
504         private class WrapperListIterator implements ListIterator {
505
506             private ListIterator delegate;
507
508             public WrapperListIterator(ListIterator delegate) {
509                 this.delegate = delegate;
510             }
511
512             public boolean hasNext() {
513                 return delegate.hasNext();
514             }
515
516             public Object JavaDoc next() {
517                 return wrap(delegate.next());
518             }
519
520             public boolean hasPrevious() {
521                 return delegate.hasPrevious();
522             }
523
524             public Object JavaDoc previous() {
525                 return wrap(delegate.previous());
526             }
527
528             public int nextIndex() {
529                 return delegate.nextIndex();
530             }
531
532             public int previousIndex() {
533                 return delegate.previousIndex();
534             }
535
536             public void remove() {
537                 throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
538             }
539
540             public void set(Object JavaDoc o) {
541                 throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
542             }
543
544             public void add(Object JavaDoc o) {
545                 throw constructIsReadOnly(ParameterizedTypeImpl.this, attrName);
546             }
547         }
548     }
549
550     public abstract class Wrapper implements MDRObject {
551
552         private Object JavaDoc obj;
553
554         public Wrapper(Object JavaDoc obj) {
555             this.obj = obj;
556         }
557
558         public Object JavaDoc getWrappedObject() {
559             return obj;
560         }
561         
562         public MDRepository repository() {
563             return ((MDRObject) obj).repository();
564         }
565
566         public void addListener(MDRChangeListener listener) {
567             ((MDRObject) obj).addListener(listener);
568         }
569         
570         public void addListener(MDRChangeListener listener, int mask) {
571             ((MDRObject) obj).addListener(listener, mask);
572         }
573         
574         public void removeListener(MDRChangeListener listener) {
575             ((MDRObject) obj).removeListener(listener);
576         }
577         
578         public void removeListener(MDRChangeListener listener, int mask) {
579             ((MDRObject) obj).removeListener(listener, mask);
580         }
581     }
582
583     private Object JavaDoc wrap(Object JavaDoc obj) {
584         if (obj instanceof Wrapper) {
585             return obj;
586         }
587         if (obj instanceof Field)
588             return new FieldWrapper(obj);
589         if (obj instanceof Method)
590             return new MethodWrapper(obj);
591         if (obj instanceof Constructor)
592             return new ConstructorWrapper(obj);
593         if (obj instanceof Parameter)
594             return new ParameterWrapper(obj);
595         if (obj instanceof TypeParameter)
596             return substitute((Type)obj);
597         if (obj instanceof JavaClass) {
598             JavaClass jcls=(JavaClass)obj;
599             ParameterizedTypeClass ptc = ((JavaModelPackage)jcls.refImmediatePackage()).getParameterizedType();
600             return ptc.resolveParameterizedType(jcls, null, this);
601         }
602         return obj;
603     }
604
605     private Type substitute(Type typ) {
606         initSubstitutionMap();
607         if (typ instanceof TypeParameter) {
608             Type subst = (Type) substMap.get(typ);
609             if (subst == null) {
610                 subst = TypeClassImpl.getRawType(typ);
611                 substMap.put(typ, subst);
612             }
613             typ = subst;
614         } else if (typ instanceof Array) {
615             Type subst = substitute(((Array)typ).getType());
616             return subst != null ? ((ArrayClass)typ.refClass()).resolveArray(subst) : typ;
617         }
618         return (Type) rebuildObject(typ);
619     }
620     
621     private Object JavaDoc rebuildObject(Object JavaDoc obj) {
622         initSubstitutionMap();
623         if (obj instanceof ParameterizedTypeImpl) {
624             ParameterizedTypeImpl pt = (ParameterizedTypeImpl) obj;
625             List parameters = pt.getParameters();
626             List newParameters = new ArrayList(parameters.size());
627             boolean createNew = false;
628             for (Iterator it = parameters.iterator(); it.hasNext();) {
629                 Type oldType = (Type) it.next();
630                 Type newType = substitute(oldType);
631                 newParameters.add(newType);
632                 if (!oldType.equals(newType)) {
633                     createNew = true;
634                 }
635             }
636             if (createNew) {
637                 ParameterizedTypeImpl newType = (ParameterizedTypeImpl) ((ParameterizedTypeClass) pt.refClass()).resolveParameterizedType(pt.definition, newParameters, pt.outerCls);
638                 for (int i=0;i<newParameters.size();i++) {
639                     newType.setWildCardStatus(i,pt.getWildCardStatus(i));
640                 }
641                 obj = newType;
642             }
643         }
644         return obj;
645     }
646
647     private class TypedElementWrapper extends Wrapper implements TypedElement {
648
649         public TypedElementWrapper(Object JavaDoc typedElement) {
650             super(typedElement);
651         }
652         
653         private TypedElement typedElement() {
654             return (TypedElement) getWrappedObject();
655         }
656
657         public Type getType() {
658             return substitute(typedElement().getType());
659         }
660
661         public void setType(Type newValue) {
662             throw constructIsReadOnly(this, "type"); // NOI18N
663
}
664         
665         public Element duplicate() {
666             return typedElement().duplicate();
667         }
668
669         public List getChildren() {
670             return typedElement().getChildren();
671         }
672
673         public int getEndOffset() {
674             return typedElement().getEndOffset();
675         }
676
677         public int getPartEndOffset(ElementPartKind part) {
678             return typedElement().getPartEndOffset(part);
679         }
680
681         public int getPartStartOffset(ElementPartKind part) {
682             return typedElement().getPartStartOffset(part);
683         }
684
685         public Resource getResource() {
686             return typedElement().getResource();
687         }
688
689         public int getStartOffset() {
690             return typedElement().getStartOffset();
691         }
692
693         public boolean isValid() {
694             return typedElement().isValid();
695         }
696
697         public void replaceChild(Element oldChild, Element newChild) {
698             typedElement().replaceChild(oldChild, newChild);
699         }
700
701         public RefClass refClass() {
702             return typedElement().refClass();
703         }
704
705         public void refDelete() {
706             typedElement().refDelete();
707         }
708
709         public RefFeatured refImmediateComposite() {
710             return typedElement().refImmediateComposite();
711         }
712
713         public boolean refIsInstanceOf(RefObject refObject, boolean b) {
714             return typedElement().refIsInstanceOf(refObject, b);
715         }
716
717         public RefFeatured refOutermostComposite() {
718             return typedElement().refOutermostComposite();
719         }
720
721         public Object JavaDoc refGetValue(RefObject refObject) {
722             return typedElement().refGetValue(refObject);
723         }
724
725         public Object JavaDoc refGetValue(String JavaDoc s) {
726             return typedElement().refGetValue(s);
727         }
728
729         public Object JavaDoc refInvokeOperation(RefObject refObject, List list) throws RefException {
730             return typedElement().refInvokeOperation(refObject, list);
731         }
732
733         public Object JavaDoc refInvokeOperation(String JavaDoc s, List list) throws RefException {
734             return typedElement().refInvokeOperation(s, list);
735         }
736
737         public void refSetValue(RefObject refObject, Object JavaDoc o) {
738             typedElement().refSetValue(refObject, o);
739         }
740
741         public void refSetValue(String JavaDoc s, Object JavaDoc o) {
742             typedElement().refSetValue(s, o);
743         }
744
745         public RefPackage refImmediatePackage() {
746             return typedElement().refImmediatePackage();
747         }
748
749         public RefObject refMetaObject() {
750             return typedElement().refMetaObject();
751         }
752
753         public String JavaDoc refMofId() {
754             return typedElement().refMofId();
755         }
756
757         public RefPackage refOutermostPackage() {
758             return typedElement().refOutermostPackage();
759         }
760
761         public Collection refVerifyConstraints(boolean b) {
762             return typedElement().refVerifyConstraints(b);
763         }
764     }
765
766     private class FeatureWrapper extends TypedElementWrapper implements Feature {
767
768         public FeatureWrapper(Object JavaDoc feature) {
769             super(feature);
770         }
771         
772         private Feature feature() {
773             return (Feature) getWrappedObject();
774         }
775
776         public ClassDefinition getDeclaringClass() {
777             return feature().getDeclaringClass();
778         }
779
780         public int getModifiers() {
781             return feature().getModifiers();
782         }
783
784         public void setModifiers(int newValue) {
785             feature().setModifiers(newValue);
786         }
787         
788         public boolean isDeprecated() {
789             return feature().isDeprecated();
790         }
791
792         public String JavaDoc getJavadocText() {
793             return feature().getJavadocText();
794         }
795
796         public void setJavadocText(String JavaDoc newValue) {
797             feature().setJavadocText(newValue);
798         }
799
800         public JavaDoc getJavadoc() {
801             return feature().getJavadoc();
802         }
803
804         public void setJavadoc(JavaDoc newValue) {
805             feature().setJavadoc(newValue);
806         }
807
808         public List getAnnotations() {
809             return feature().getAnnotations();
810         }
811
812         public String JavaDoc getName() {
813             return feature().getName();
814         }
815
816         public void setName(String JavaDoc newValue) {
817             feature().setName(newValue);
818         }
819
820         public Collection getReferences() {
821             return feature().getReferences();
822         }
823         
824         public void setDeprecated(boolean deprecated) {
825             feature().setDeprecated(deprecated);
826         }
827     }
828
829     private class FieldWrapper extends FeatureWrapper implements Field {
830
831         public FieldWrapper(Object JavaDoc field) {
832             super(field);
833         }
834         
835         private Field field() {
836             return (Field) getWrappedObject();
837         }
838
839         public InitialValue getInitialValue() {
840             return field().getInitialValue();
841         }
842
843         public void setInitialValue(InitialValue newValue) {
844             field().setInitialValue(newValue);
845         }
846
847         public String JavaDoc getInitialValueText() {
848             return field().getInitialValueText();
849         }
850
851         public void setInitialValueText(String JavaDoc newValue) {
852             field().setInitialValueText(newValue);
853         }
854
855         public boolean isFinal() {
856             return field().isFinal();
857         }
858
859         public void setFinal(boolean newValue) {
860             field().setFinal(newValue);
861         }
862
863         public TypeReference getTypeName() {
864             return field().getTypeName();
865         }
866
867         public void setTypeName(TypeReference newValue) {
868             field().setTypeName(newValue);
869         }
870
871         public int getDimCount() {
872             return field().getDimCount();
873         }
874
875         public void setDimCount(int newValue) {
876             field().setDimCount(newValue);
877         }
878
879         public String JavaDoc toString() {
880             return "field " + getName(); // NOI18N
881
}
882     }
883
884     private class CallableFeatureWrapper extends FeatureWrapper implements CallableFeature {
885
886         private WrapperList paramList = null;
887         private WrapperList exceptionList = null;
888
889         public CallableFeatureWrapper(Object JavaDoc callableFeature) {
890             super(callableFeature);
891             if (!(callableFeature instanceof CallableFeatureImpl) || ((CallableFeatureImpl)callableFeature).hasTypeParameters()) {
892                 for (Iterator it = callableFeature().getTypeParameters().iterator(); it.hasNext();) {
893                     Object JavaDoc tp = it.next();
894                     substMap.put(tp, tp);
895                 }
896             }
897         }
898         
899         private CallableFeature callableFeature() {
900             return (CallableFeature) getWrappedObject();
901         }
902
903         public List getParameters() {
904             if (paramList == null)
905                 paramList = new WrapperList(callableFeature().getParameters(), "parameters"); // NOI18N
906
return paramList;
907         }
908
909         public List getExceptionNames() {
910             return callableFeature().getExceptionNames();
911         }
912
913         public List getExceptions() {
914             if (exceptionList == null)
915                 exceptionList = new WrapperList(callableFeature().getExceptions(), "exceptions"); // NOI18N
916
return exceptionList;
917         }
918
919         public StatementBlock getBody() {
920             return callableFeature().getBody();
921         }
922
923         public void setBody(StatementBlock newValue) {
924             callableFeature().setBody(newValue);
925         }
926
927         public String JavaDoc getBodyText() {
928             return callableFeature().getBodyText();
929         }
930
931         public void setBodyText(String JavaDoc newValue) {
932             callableFeature().setBodyText(newValue);
933         }
934
935         public List getTypeParameters() {
936             return callableFeature().getTypeParameters();
937         }
938     }
939
940     private class MethodWrapper extends CallableFeatureWrapper implements Method {
941
942         public MethodWrapper(Object JavaDoc method) {
943             super(method);
944         }
945         
946         private Method method() {
947             return (Method) getWrappedObject();
948         }
949
950         public TypeReference getTypeName() {
951             return method().getTypeName();
952         }
953
954         public void setTypeName(TypeReference newValue) {
955             method().setTypeName(newValue);
956         }
957
958         public int getDimCount() {
959             return method().getDimCount();
960         }
961
962         public void setDimCount(int newValue) {
963             method().setDimCount(newValue);
964         }
965         
966         public Collection findDependencies(boolean usages, boolean overridenMethods, boolean fromBaseClass) {
967             return method().findDependencies(usages, overridenMethods, fromBaseClass);
968         }
969         
970         public boolean signatureEquals(Method method) {
971             return MethodImpl.signatureEquals(this, method);
972         }
973         
974         public String JavaDoc toString() {
975             return "method " + getName(); // NOI18N
976
}
977     }
978
979     private class ConstructorWrapper extends CallableFeatureWrapper implements Constructor {
980
981         public ConstructorWrapper(Object JavaDoc constructor) {
982             super(constructor);
983         }
984     }
985
986     private class ParameterWrapper extends TypedElementWrapper implements Parameter {
987
988         public ParameterWrapper(Object JavaDoc parameter) {
989             super(parameter);
990         }
991         
992         private Parameter parameter() {
993             return (Parameter) getWrappedObject();
994         }
995
996         public boolean isVarArg() {
997             return parameter().isVarArg();
998         }
999
1000        public void setVarArg(boolean newValue) {
1001            parameter().setVarArg(newValue);
1002        }
1003
1004        public boolean isFinal() {
1005            return parameter().isFinal();
1006        }
1007
1008        public void setFinal(boolean newValue) {
1009            parameter().setFinal(newValue);
1010        }
1011
1012        public TypeReference getTypeName() {
1013            return parameter().getTypeName();
1014        }
1015
1016        public void setTypeName(TypeReference newValue) {
1017            parameter().setTypeName(newValue);
1018        }
1019
1020        public int getDimCount() {
1021            return parameter().getDimCount();
1022        }
1023
1024        public void setDimCount(int newValue) {
1025            parameter().setDimCount(newValue);
1026        }
1027
1028        public List getAnnotations() {
1029            return parameter().getAnnotations();
1030        }
1031
1032        public String JavaDoc getName() {
1033            return parameter().getName();
1034        }
1035
1036        public void setName(String JavaDoc newValue) {
1037            parameter().setName(newValue);
1038        }
1039
1040        public Collection getReferences() {
1041            return parameter().getReferences();
1042        }
1043    }
1044    
1045    private class SubstitutionList extends AbstractList {
1046        private final List inner;
1047        
1048        SubstitutionList(List inner) {
1049            this.inner = inner;
1050        }
1051        
1052        public void add(int index, Object JavaDoc object) {
1053            inner.add(index, object);
1054        }
1055        
1056        public Object JavaDoc remove(int index) {
1057            return rebuildObject(inner.remove(index));
1058        }
1059        
1060        public Object JavaDoc set(int index, Object JavaDoc object) {
1061            return rebuildObject(inner.set(index, object));
1062        }
1063        
1064        public Object JavaDoc get(int index) {
1065            return rebuildObject(inner.get(index));
1066        }
1067        
1068        public int size() {
1069            return inner.size();
1070        }
1071    }
1072
1073    public int getStartOffset() {
1074        throw new UnsupportedOperationException JavaDoc();
1075    }
1076    
1077    public int getEndOffset() {
1078        throw new UnsupportedOperationException JavaDoc();
1079    }
1080    
1081    public int getPartStartOffset(ElementPartKind part) {
1082        throw new UnsupportedOperationException JavaDoc();
1083    }
1084
1085    public int getPartEndOffset(ElementPartKind part) {
1086        throw new UnsupportedOperationException JavaDoc();
1087    }
1088    
1089    public Element duplicate() {
1090        throw new UnsupportedOperationException JavaDoc("The operation is intentionally unsupported at this element."); // NOI18N
1091
}
1092}
1093
Popular Tags