//
// This file is part of the prose package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is prose.
//
// The Initial Developer of the Original Code is Andrei Popovici. Portions
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
// All Rights Reserved.
//
// Contributor(s):
// $Id: Cflow.java,v 1.3 2008/11/18 11:38:01 anicoara Exp $
// =====================================================================
//
package ch.ethz.prose.filter;
// used packages
import ch.ethz.jvmai.JoinPointKinds;
import ch.ethz.jvmai.CodeJoinPoint;
import ch.ethz.prose.engine.JoinPointRequest;
import ch.ethz.prose.crosscut.MethodCut;
/**
* Class Cflow
*
* @version $Revision: 1.3 $
* @author Andrei Popovici
*/
public class Cflow {
static class BelowPointCutter extends PointCutter implements JoinPointKinds {
private static final long serialVersionUID = 3904680466131988530L;
PointCutter pcut;
protected BelowPointCutter(PointCutter pcut) {
if (pcut == null)
throw new IllegalArgumentException("the argument to Cflow.below cannot be null");
acceptMask = MASK_ALL_JP;
canFilterStaticallyMask = 0;
mayFilterStaticallyMask = 0;
this.pcut = pcut;
}
protected boolean doIsSpecialRequest(JoinPointRequest jpr) {
throw new Error("if we cannot filter statically, we should not be here");
}
protected boolean doIsSpecialEvent(CodeJoinPoint jpe) {
try {
CodeJoinPoint upper = jpe.getEnclosingJoinPoint();
while (upper != null) {
if (pcut.isSpecialEvent(upper))
return true;
upper=upper.getEnclosingJoinPoint();
}
return false;
}
catch (ch.ethz.jvmai.JVMAIRuntimeException e) {
// System.err.println("hitting the ceiling");
return false;
}
}
};
static class BelowMethodCut extends PointCutter implements JoinPointKinds {
private static final long serialVersionUID = 3257290235984754993L;
MethodCut mcut;
protected BelowMethodCut(MethodCut methCut) {
if (methCut == null)
throw new IllegalArgumentException("the argument to Cflow.below cannot be null");
acceptMask = MASK_ALL_JP;
canFilterStaticallyMask = 0;
mayFilterStaticallyMask = 0;
mcut = methCut;
}
protected boolean doIsSpecialRequest(JoinPointRequest jpr) {
throw new Error("if we cannot filter statically, we should not be here");
}
protected boolean doIsSpecialEvent(CodeJoinPoint jpe) {
try {
CodeJoinPoint upper = jpe.getEnclosingJoinPoint();
while (upper != null) {
if (mcut.equivalentSpecializer().isSpecialEvent(upper))
return true;
upper=upper.getEnclosingJoinPoint();
}
return false;
}
catch (ch.ethz.jvmai.JVMAIRuntimeException e) {
// System.err.println("hitting the ceiling");
return false;
}
}
};
public static PointCutter below(MethodCut mcut) {
return new BelowMethodCut(mcut);
}
public static PointCutter below(PointCutter pcut) {
return new BelowPointCutter(pcut);
}
}