001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: NameExpression.java,v 1.1.1.1 2003/07/02 15:30:52 apopovic Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose.filter;
028:
029: // used packages
030: import java.io.Serializable;
031: import java.lang.reflect.Member;
032:
033: import org.apache.regexp.RE;
034: import org.apache.regexp.RESyntaxException;
035:
036: /**
037: * Class NameExpression defines (and encapsulates) some handy mathing routines.
038: *
039: *
040: * @version $Revision: 1.1.1.1 $
041: * @author Andrei Popovici
042: */
043: class NameExpression implements Serializable {
044: private static final long serialVersionUID = 3258134669538243124L;
045: String regexp;
046: transient RE re = null;
047:
048: NameExpression(String regexp) {
049:
050: this .regexp = regexp;
051: try {
052: re = new RE(regexp);
053: } catch (RESyntaxException e) {
054: throw new IllegalArgumentException("NameExpression: "
055: + regexp + " is not a valid regexp." + e.toString());
056: }
057:
058: }
059:
060: private RE getRE() {
061: try {
062: if (re == null)
063: re = new RE(regexp);
064: } catch (RESyntaxException cannotB) {
065: throw new Error(
066: "NameExpression.getRE: regezp was not verified");
067: }
068: return re;
069: }
070:
071: boolean classMatchesRegexp(Class cls) {
072: //System.out.println(" ->>>>>>>>> NameExpression - classMatchesRegexp -> className(cls.getName()) = " + className(cls.getName())); //angy test
073: //System.out.println(" ->>>>>>>>> NameExpression - classMatchesRegexp -> regexp = " + regexp); //angy test
074: return getRE().match(className(cls.getName()));
075: }
076:
077: boolean packageMatchesRegexp(Class cls) {
078: return getRE().match(packageName(cls.getName()));
079: }
080:
081: boolean qualifiedClassMatchesRegexp(Class cls) {
082: return getRE().match(cls.getName());
083: }
084:
085: boolean memberMatchesRegexp(Member m) {
086: return getRE().match(m.getName());
087: }
088:
089: private String className(String qualifiedClassName) {
090: int lastDotIndex = qualifiedClassName.lastIndexOf('.');
091: return qualifiedClassName.substring(lastDotIndex + 1);
092: }
093:
094: private String packageName(String qualifiedClassName) {
095: int lastDotIndex = qualifiedClassName.lastIndexOf('.');
096: return (lastDotIndex != -1) ? qualifiedClassName.substring(0,
097: lastDotIndex) : "";
098: }
099:
100: public String toString() {
101: return regexp;
102: }
103:
104: }
105:
106: //======================================================================
107: //
108: // $Log: NameExpression.java,v $
109: // Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
110: // Imported from ETH Zurich
111: //
112: // Revision 1.3 2003/07/02 12:42:57 anicoara
113: // Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
114: //
115: // Revision 1.2 2003/05/06 15:51:40 popovici
116: // Mozilla-ification
117: //
118: // Revision 1.1 2003/05/05 13:58:06 popovici
119: // renaming from runes to prose
120: //
121: // Revision 1.4 2003/04/17 14:46:04 popovici
122: // ThiS renamed to This; additional method renamings
123: //
124: // Revision 1.3 2003/04/17 13:59:37 popovici
125: // This class and methods renamed
126: //
127: // Revision 1.2 2003/03/04 18:24:09 popovici
128: // Refactoring of the specializer. De-obfuscation
129: // by exposing the inner classes of the factory methods
130: // The specializer implementations now end in 'filter',
131: // whereas the old factory methods 'xxxS' remain
132: // pure bootstrap objects.
133: //
134: // Revision 1.1 2002/05/16 09:18:30 popovici
135: // ClasseS and CFlow replaced with Target, This; the crosscut spec package is refactorized. Now all
136: // crosscuts are grouped (abstract definitions + concrete definitions). Crosscuts explicitely are dynamic and static, and
137: // or/Not/And combinations can be created.
138: //
|