KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > ast > ConstructorPattern


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.crosscuts.ast;
26 import org.aspectj.compiler.base.ast.*;
27 import org.aspectj.compiler.crosscuts.joinpoints.*;
28
29 import org.aspectj.compiler.base.JavaCompiler;
30
31 import java.util.*;
32 import org.aspectj.util.FuzzyBoolean;
33
34 /**
35   * @grammar modifiers [declaringType].new(formals) throws
36   * @child FormalsPattern formalsPattern
37   * @child NameTypeDsPattern throwsPattern
38   */

39 public class ConstructorPattern extends CodePattern {
40     public String JavaDoc toShortString() {
41         //XXX this ignores throws for now
42
String JavaDoc mods = modifiers.toShortString();
43         if (mods.length() > 0) mods += " ";
44         mods += makeDeclaringTypeString() + "new" + formalsPattern.toShortString();
45         if (throwsPattern != null) {
46             mods += " throws ...";
47         }
48
49         return mods;
50     }
51
52     public String JavaDoc getLookupId() { return "new"; }
53
54     protected boolean isStaticMatch(SemanticObject so) {
55         return true;
56     }
57     
58     public FuzzyBoolean matches(JoinPoint jp) {
59         if (! (jp.getTargetSO() instanceof Constructor) ) {
60             return FuzzyBoolean.NO;
61         }
62         
63         Constructor m = (Constructor)jp.getTargetSO();
64         
65         if (!formalsPattern.matches(m.getFormals())) {
66             return FuzzyBoolean.NO;
67         }
68         if (throwsPattern != null && !throwsPattern.matches(m.getThrows())) {
69             return FuzzyBoolean.NO;
70         }
71         
72         return super.matches(jp);
73     }
74     
75     //BEGIN: Generated from @child and @property
76
protected FormalsPattern formalsPattern;
77     public FormalsPattern getFormalsPattern() { return formalsPattern; }
78     public void setFormalsPattern(FormalsPattern _formalsPattern) {
79         if (_formalsPattern != null) _formalsPattern.setParent(this);
80         formalsPattern = _formalsPattern;
81     }
82     
83     protected NameTypeDsPattern throwsPattern;
84     public NameTypeDsPattern getThrowsPattern() { return throwsPattern; }
85     public void setThrowsPattern(NameTypeDsPattern _throwsPattern) {
86         if (_throwsPattern != null) _throwsPattern.setParent(this);
87         throwsPattern = _throwsPattern;
88     }
89     
90     public ConstructorPattern(SourceLocation location, Modifiers _modifiers, GenTypeName _declaringTypeName, FormalsPattern _formalsPattern, NameTypeDsPattern _throwsPattern) {
91         super(location, _modifiers, _declaringTypeName);
92         setFormalsPattern(_formalsPattern);
93         setThrowsPattern(_throwsPattern);
94     }
95     protected ConstructorPattern(SourceLocation source) {
96         super(source);
97     }
98     
99     public ASTObject copyWalk(CopyWalker walker) {
100         ConstructorPattern ret = new ConstructorPattern(getSourceLocation());
101         ret.preCopy(walker, this);
102         if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) );
103         if (declaringTypeName != null) ret.setDeclaringTypeName( (GenTypeName)walker.process(declaringTypeName) );
104         if (formalsPattern != null) ret.setFormalsPattern( (FormalsPattern)walker.process(formalsPattern) );
105         if (throwsPattern != null) ret.setThrowsPattern( (NameTypeDsPattern)walker.process(throwsPattern) );
106         return ret;
107     }
108     
109     public ASTObject getChildAt(int childIndex) {
110         switch(childIndex) {
111         case 2: return formalsPattern;
112         case 3: return throwsPattern;
113         default: return super.getChildAt(childIndex);
114         }
115     }
116      public String JavaDoc getChildNameAt(int childIndex) {
117         switch(childIndex) {
118         case 2: return "formalsPattern";
119         case 3: return "throwsPattern";
120         default: return super.getChildNameAt(childIndex);
121         }
122     }
123      public void setChildAt(int childIndex, ASTObject child) {
124         switch(childIndex) {
125         case 2: setFormalsPattern((FormalsPattern)child); return;
126         case 3: setThrowsPattern((NameTypeDsPattern)child); return;
127         default: super.setChildAt(childIndex, child); return;
128         }
129     }
130      public int getChildCount() {
131         return 4;
132     }
133     
134     public String JavaDoc getDefaultDisplayName() {
135         return "ConstructorPattern()";
136     }
137     
138     //END: Generated from @child and @property
139
}
140
141
Popular Tags