KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 import org.aspectj.compiler.base.ast.*;
28
29 import org.aspectj.compiler.base.JavaCompiler;
30
31 import java.util.*;
32
33 /**
34  * @grammar names..*
35  * @property String packageName
36  * @property NamePattern className
37  * @property boolean includeSubpackages
38  */

39
40 public class NameTypeDPattern extends ASTObject {
41     private Set _typeDecs = null;
42
43     private String JavaDoc getMyPackageName() {
44         if (packageName == null) {
45             //!!! bad overriding of getPackageName method by NameTypeD
46
return getCompilationUnit().getPackageName();
47         } else {
48             return packageName;
49         }
50     }
51
52     public boolean matches(TypeD typeD) {
53         return matches(typeD.getType());
54     }
55
56     private boolean matches(Type type) {
57         if (type == null) return false;
58
59         if (!className.matches(type.getId())) {
60             return false;
61         }
62         String JavaDoc packageName = type.getPackageName();
63         String JavaDoc myPackageName = getMyPackageName();
64         if (myPackageName == null) return packageName == null;
65         if (packageName == null) return false;
66
67         if (includeSubpackages) {
68             //!!! might want to check for . at end to be careful...
69
return packageName.startsWith(myPackageName);
70         } else {
71             return myPackageName.equals(packageName);
72         }
73     }
74
75
76 // public TypeDec[] getTypeDecs() {
77
// return (TypeDec[])getTypeDecSet().toArray(new TypeDec[0]);
78
// }
79

80 // public Set getTypeDecSet() {
81
// if (_typeDecs != null) return _typeDecs;
82
//
83
// List allDecs = new ArrayList(); //getWorld().getTypes();
84
// Set matchingDecs = new HashSet();
85
//
86
// for(int i=0; i<allDecs.size(); i++) {
87
// if (!(allDecs.get(i) instanceof TypeDec)) continue;
88
//
89
// TypeDec typeDec = (TypeDec)allDecs.get(i);
90
// if (this.matches(typeDec)) {
91
// matchingDecs.add(typeDec);
92
// }
93
// }
94
//
95
// _typeDecs = matchingDecs;
96
// return matchingDecs;
97
// }
98

99     //BEGIN: Generated from @child and @property
100
protected String JavaDoc packageName;
101     public String JavaDoc getPackageName() { return packageName; }
102     public void setPackageName(String JavaDoc _packageName) { packageName = _packageName; }
103     
104     protected NamePattern className;
105     public NamePattern getClassName() { return className; }
106     public void setClassName(NamePattern _className) { className = _className; }
107     
108     protected boolean includeSubpackages;
109     public boolean getIncludeSubpackages() { return includeSubpackages; }
110     public void setIncludeSubpackages(boolean _includeSubpackages) { includeSubpackages = _includeSubpackages; }
111     
112     public NameTypeDPattern(SourceLocation location, String JavaDoc _packageName, NamePattern _className, boolean _includeSubpackages) {
113         super(location);
114         setPackageName(_packageName);
115         setClassName(_className);
116         setIncludeSubpackages(_includeSubpackages);
117     }
118     protected NameTypeDPattern(SourceLocation source) {
119         super(source);
120     }
121     
122     public ASTObject copyWalk(CopyWalker walker) {
123         NameTypeDPattern ret = new NameTypeDPattern(getSourceLocation());
124         ret.preCopy(walker, this);
125         ret.packageName = packageName;
126         ret.className = className;
127         ret.includeSubpackages = includeSubpackages;
128         return ret;
129     }
130     
131     
132     public String JavaDoc getDefaultDisplayName() {
133         return "NameTypeDPattern(packageName: "+packageName+", "+"className: "+className+", "+"includeSubpackages: "+includeSubpackages+")";
134     }
135     
136     //END: Generated from @child and @property
137
}
138
Popular Tags