KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > internal > lang > reflect > DeclareParentsImpl


1 /* *******************************************************************
2  * Copyright (c) 2005 Contributors.
3  * All rights reserved.
4  * This program and the accompanying materials are made available
5  * under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution and is available at
7  * http://eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Adrian Colyer Initial implementation
11  * ******************************************************************/

12 package org.aspectj.internal.lang.reflect;
13
14 import java.lang.reflect.Type JavaDoc;
15
16 import org.aspectj.lang.reflect.AjType;
17 import org.aspectj.lang.reflect.DeclareParents;
18 import org.aspectj.lang.reflect.TypePattern;
19
20 /**
21  * @author colyer
22  *
23  */

24 public class DeclareParentsImpl implements DeclareParents {
25
26     private AjType<?> declaringType;
27     private TypePattern targetTypesPattern;
28     private Type JavaDoc[] parents;
29     private String JavaDoc parentsString;
30     private String JavaDoc firstMissingTypeName;
31     private boolean isExtends;
32     private boolean parentsError = false;
33     
34     /**
35      * Parents arg is a comma-separate list of type names that needs to be turned into
36      * AjTypes
37      */

38     public DeclareParentsImpl(String JavaDoc targets, String JavaDoc parentsAsString, boolean isExtends, AjType<?> declaring)
39     {
40         this.targetTypesPattern = new TypePatternImpl(targets);
41         this.isExtends = isExtends;
42         this.declaringType = declaring;
43         this.parentsString = parentsAsString;
44         try {
45             this.parents = StringToType.commaSeparatedListToTypeArray(parentsAsString, declaring.getJavaClass());
46         } catch (ClassNotFoundException JavaDoc cnfEx) {
47             this.parentsError = true;
48             this.firstMissingTypeName = cnfEx.getMessage();
49         }
50     }
51
52     /* (non-Javadoc)
53      * @see org.aspectj.lang.reflect.DeclareParents#getDeclaringType()
54      */

55     public AjType getDeclaringType() {
56         return this.declaringType;
57     }
58
59     /* (non-Javadoc)
60      * @see org.aspectj.lang.reflect.DeclareParents#getTargetTypesPattern()
61      */

62     public TypePattern getTargetTypesPattern() {
63         return this.targetTypesPattern;
64     }
65
66     /* (non-Javadoc)
67      * @see org.aspectj.lang.reflect.DeclareParents#isExtends()
68      */

69     public boolean isExtends() {
70         return this.isExtends;
71     }
72
73     /* (non-Javadoc)
74      * @see org.aspectj.lang.reflect.DeclareParents#isImplements()
75      */

76     public boolean isImplements() {
77         return !this.isExtends;
78     }
79
80     /* (non-Javadoc)
81      * @see org.aspectj.lang.reflect.DeclareParents#getParentTypes()
82      */

83     public Type JavaDoc[] getParentTypes() throws ClassNotFoundException JavaDoc {
84         if (parentsError) {
85             throw new ClassNotFoundException JavaDoc(this.firstMissingTypeName);
86         }
87         return this.parents;
88     }
89     
90     public String JavaDoc toString() {
91         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
92         sb.append("declare parents : ");
93         sb.append(getTargetTypesPattern().asString());
94         sb.append(isExtends() ? " extends " : " implements ");
95         sb.append(this.parentsString);
96         return sb.toString();
97     }
98 }
99
Popular Tags