123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-
- package org.aspectj.weaver.patterns;
-
- import java.io.*;
-
- import org.aspectj.bridge.IMessage;
- import org.aspectj.util.FuzzyBoolean;
- import org.aspectj.weaver.*;
- import org.aspectj.weaver.ast.*;
-
- /**
- * args(arguments)
- *
- * @author Erik Hilsdale
- * @author Jim Hugunin
- */
- public class ArgsPointcut extends NameBindingPointcut {
- TypePatternList arguments;
-
- public ArgsPointcut(TypePatternList arguments) {
- this.arguments = arguments;
- }
-
- public FuzzyBoolean match(Shadow shadow) {
- int n = shadow.getArgCount();
- TypeX[] argTypes = new TypeX[n];
- for (int i=0; i < n; i++) {
- argTypes[i] = shadow.getArgType(i);
- }
- FuzzyBoolean ret =
- arguments.matches(shadow.getIWorld().resolve(argTypes), TypePattern.DYNAMIC);
- return ret;
- }
-
- public void write(DataOutputStream s) throws IOException {
- s.writeByte(Pointcut.ARGS);
- arguments.write(s);
- writeLocation(s);
- }
-
- public static Pointcut read(DataInputStream s, ISourceContext context) throws IOException {
- ArgsPointcut ret = new ArgsPointcut(TypePatternList.read(s, context));
- ret.readLocation(context, s);
- return ret;
- }
-
-
- public boolean equals(Object other) {
- if (!(other instanceof ArgsPointcut)) return false;
- ArgsPointcut o = (ArgsPointcut)other;
- return o.arguments.equals(this.arguments);
- }
-
- public int hashCode() {
- return arguments.hashCode();
- }
-
- public void resolveBindings(IScope scope, Bindings bindings) {
- arguments.resolveBindings(scope, bindings, true);
- if (arguments.ellipsisCount > 1) {
- scope.message(IMessage.ERROR, this,
- "uses more than one .. in args (compiler limitation)");
- }
- }
-
- public void postRead(ResolvedTypeX enclosingType) {
- arguments.postRead(enclosingType);
- }
-
-
- public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
- return new ArgsPointcut(arguments.resolveReferences(bindings));
- }
-
- private Test findResidueNoEllipsis(Shadow shadow, ExposedState state, TypePattern[] patterns) {
- int len = shadow.getArgCount();
- //System.err.println("boudn to : " + len + ", " + patterns.length);
- if (patterns.length != len) {
- throw new RuntimeException("this should never happen");
- //return Literal.FALSE; //??? this should never happen
- }
-
- Test ret = Literal.TRUE;
-
- for (int i=0; i < len; i++) {
- TypeX argType = shadow.getArgType(i);
- TypePattern type = patterns[i];
- if (!(type instanceof BindingTypePattern)) {
- if (type.matchesInstanceof(shadow.getIWorld().resolve(argType)).alwaysTrue()) {
- continue;
- }
- }
- ret = Test.makeAnd(ret,
- exposeStateForVar(shadow.getArgVar(i), type, state,shadow.getIWorld()));
- }
-
- return ret;
- }
-
- public Test findResidue(Shadow shadow, ExposedState state) {
- int ellipsisCount = arguments.ellipsisCount;
- if (ellipsisCount == 0) {
- return findResidueNoEllipsis(shadow, state, arguments.getTypePatterns());
- } else if (ellipsisCount == 1) {
- TypePattern[] patternsWithEllipsis = arguments.getTypePatterns();
- TypePattern[] patternsWithoutEllipsis = new TypePattern[shadow.getArgCount()];
- int lenWithEllipsis = patternsWithEllipsis.length;
- int lenWithoutEllipsis = patternsWithoutEllipsis.length;
- // l1+1 >= l0
- int indexWithEllipsis = 0;
- int indexWithoutEllipsis = 0;
- while (indexWithoutEllipsis < lenWithoutEllipsis) {
- TypePattern p = patternsWithEllipsis[indexWithEllipsis++];
- if (p == TypePattern.ELLIPSIS) {
- int newLenWithoutEllipsis =
- lenWithoutEllipsis - (lenWithEllipsis-indexWithEllipsis);
- while (indexWithoutEllipsis < newLenWithoutEllipsis) {
- patternsWithoutEllipsis[indexWithoutEllipsis++] = TypePattern.ANY;
- }
- } else {
- patternsWithoutEllipsis[indexWithoutEllipsis++] = p;
- }
- }
- return findResidueNoEllipsis(shadow, state, patternsWithoutEllipsis);
- } else {
- throw new BetaException("unimplemented");
- }
- }
-
- public String toString() {
- return "args" + arguments.toString() + "";
- }
- }
|