public Object visit(KindedPointcut node, Object parent, RequestContext context) { context.kinds &= node.couldMatchKinds(); if (node.getKind().bit == Shadow.FieldGetBit || node.getKind().bit == Shadow.FieldSetBit) { context.targetFilters.add(node.getSignature()); } else { context.thisFilters.add(node.getSignature()); } installIfNotBelowAnd(parent, context); return null; }
private void checkParameterAnnotations( PointcutExpression pe, int parameterNumber, String expectedParameterAnnotations, String expectedParameterTypeAnnotations, String expectedNodeStructure) { org.aspectj.weaver.patterns.Pointcut p = ((PointcutExpressionImpl) pe).getUnderlyingPointcut(); KindedPointcut kindedP = (KindedPointcut) p; SignaturePattern sp = kindedP.getSignature(); TypePatternList tpl = sp.getParameterTypes(); TypePattern[] tps = tpl.getTypePatterns(); // A visitor over the annotation pattern for the parameter will break it down into parameter vs // parameter type annotations MyPatternNodeVisitor mpnv = new MyPatternNodeVisitor(); tps[parameterNumber].getAnnotationPattern().accept(mpnv, null); if (expectedNodeStructure == null) { // The caller hasn't worked it out yet!! System.out.println(mpnv.getStringRepresentation()); } else if (!mpnv.getStringRepresentation().equals(expectedNodeStructure)) { System.out.println(mpnv.getStringRepresentation()); fail( "Expected annotation pattern node structure for expression " + pe.getPointcutExpression() + " was '" + expectedNodeStructure + "' but it turned out to be '" + mpnv.getStringRepresentation() + "'"); } tps[parameterNumber].getAnnotationPattern().toString(); // parameter type annotation checking Set<String> expected = new HashSet<String>(); expected.addAll(mpnv.getParameterTypeAnnotations()); StringTokenizer st = new StringTokenizer( expectedParameterTypeAnnotations == null ? "" : expectedParameterTypeAnnotations); while (st.hasMoreTokens()) { String nextToken = st.nextToken(); if (!expected.contains(nextToken)) fail( "In pointcut expression " + pe.getPointcutExpression() + " parameter " + parameterNumber + ". The annotation type pattern did not include parameter type annotation " + nextToken + ". It's full set was " + mpnv.getParameterTypeAnnotations()); expected.remove(nextToken); } if (expected.size() > 0) { // we have excess ones! StringBuffer excessTokens = new StringBuffer(); for (Iterator iterator = expected.iterator(); iterator.hasNext(); ) { String string = (String) iterator.next(); excessTokens.append(string).append(" "); } fail( "In pointcut expression " + pe.getPointcutExpression() + " parameter " + parameterNumber + ". The annotation type pattern has these unexpected parameter type annotations " + excessTokens.toString()); } // parameter annotation checking expected = new HashSet<String>(); expected.addAll(mpnv.getParameterAnnotations()); st = new StringTokenizer( expectedParameterAnnotations == null ? "" : expectedParameterAnnotations); while (st.hasMoreTokens()) { String nextToken = st.nextToken(); if (!expected.contains(nextToken)) fail( "In pointcut expression " + pe.getPointcutExpression() + " parameter " + parameterNumber + ". The annotation type pattern did not include parameter annotation " + nextToken + ". It's full set was " + mpnv.getParameterAnnotations()); expected.remove(nextToken); } if (expected.size() > 0) { // we have excess ones! StringBuffer excessTokens = new StringBuffer(); for (Iterator iterator = expected.iterator(); iterator.hasNext(); ) { String string = (String) iterator.next(); excessTokens.append(string).append(" "); } fail( "In pointcut expression " + pe.getPointcutExpression() + " parameter " + parameterNumber + ". The annotation type pattern has these unexpected parameter annotations " + excessTokens.toString()); } }