View | Details | Raw Unified | Return to bug 329268 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/aspectj/org/eclipse/jdt/core/dom/AbstractBooleanTypePattern.java (+36 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
public abstract class AbstractBooleanTypePattern extends TypePattern {
13
14
	private TypePattern left;
15
	private TypePattern right;
16
17
	AbstractBooleanTypePattern(AST ast, TypePattern left, TypePattern right,
18
			String booleanOperator) {
19
		super(ast, booleanOperator);
20
		this.left = left;
21
		this.right = right;
22
	}
23
24
	public TypePattern getLeft() {
25
		return left;
26
	}
27
28
	public TypePattern getRight() {
29
		return right;
30
	}
31
32
	int treeSize() {
33
		return memSize() + (this.left == null ? 0 : getLeft().treeSize())
34
				+ (this.right == null ? 0 : getRight().treeSize());
35
	}
36
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java (-14 / +133 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 406-412 Link Here
406
				((DeclareAtTypeDeclaration) declareDeclaration).setAnnotationName(annotationName);
406
				((DeclareAtTypeDeclaration) declareDeclaration).setAnnotationName(annotationName);
407
			} else if (da.getKind().equals(DeclareAnnotation.AT_CONSTRUCTOR)) {
407
			} else if (da.getKind().equals(DeclareAnnotation.AT_CONSTRUCTOR)) {
408
				declareDeclaration = new DeclareAtConstructorDeclaration(this.ast);
408
				declareDeclaration = new DeclareAtConstructorDeclaration(this.ast);
409
				((DeclareAtConstructorDeclaration) declareDeclaration).setPatternNode(convert(da.getSignaturePattern()));
409
				((DeclareAtConstructorDeclaration) declareDeclaration).setPatternNode(convertSignature(da.getSignaturePattern()));
410
				SimpleName annotationName = new SimpleName(this.ast);
410
				SimpleName annotationName = new SimpleName(this.ast);
411
				annotationName.setSourceRange(da.getAnnotationSourceStart(),
411
				annotationName.setSourceRange(da.getAnnotationSourceStart(),
412
						da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
412
						da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
Lines 414-420 Link Here
414
				((DeclareAtConstructorDeclaration) declareDeclaration).setAnnotationName(annotationName);
414
				((DeclareAtConstructorDeclaration) declareDeclaration).setAnnotationName(annotationName);
415
			} else if (da.getKind().equals(DeclareAnnotation.AT_FIELD)) {
415
			} else if (da.getKind().equals(DeclareAnnotation.AT_FIELD)) {
416
				declareDeclaration = new DeclareAtFieldDeclaration(this.ast);
416
				declareDeclaration = new DeclareAtFieldDeclaration(this.ast);
417
				((DeclareAtFieldDeclaration) declareDeclaration).setPatternNode(convert(da.getSignaturePattern()));
417
				((DeclareAtFieldDeclaration) declareDeclaration).setPatternNode(convertSignature(da.getSignaturePattern()));
418
				SimpleName annotationName = new SimpleName(this.ast);
418
				SimpleName annotationName = new SimpleName(this.ast);
419
				annotationName.setSourceRange(da.getAnnotationSourceStart(),
419
				annotationName.setSourceRange(da.getAnnotationSourceStart(),
420
						da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
420
						da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
Lines 422-428 Link Here
422
				((DeclareAtFieldDeclaration) declareDeclaration).setAnnotationName(annotationName);
422
				((DeclareAtFieldDeclaration) declareDeclaration).setAnnotationName(annotationName);
423
			} else if (da.getKind().equals(DeclareAnnotation.AT_METHOD)) {
423
			} else if (da.getKind().equals(DeclareAnnotation.AT_METHOD)) {
424
				declareDeclaration = new DeclareAtMethodDeclaration(this.ast);
424
				declareDeclaration = new DeclareAtMethodDeclaration(this.ast);
425
				((DeclareAtMethodDeclaration) declareDeclaration).setPatternNode(convert(da.getSignaturePattern()));
425
				((DeclareAtMethodDeclaration) declareDeclaration).setPatternNode(convertSignature(da.getSignaturePattern()));
426
				SimpleName annotationName = new SimpleName(this.ast);
426
				SimpleName annotationName = new SimpleName(this.ast);
427
				annotationName.setSourceRange(da.getAnnotationSourceStart(),
427
				annotationName.setSourceRange(da.getAnnotationSourceStart(),
428
						da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
428
						da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
Lines 475-482 Link Here
475
						.setTypePattern((org.aspectj.org.eclipse.jdt.core.dom.TypePattern) pNode);
475
						.setTypePattern((org.aspectj.org.eclipse.jdt.core.dom.TypePattern) pNode);
476
			}
476
			}
477
		}
477
		}
478
		declareDeclaration.setSourceRange(declareDecl.declarationSourceStart, declareDecl.declarationSourceEnd
478
		
479
				- declareDecl.declarationSourceStart + 1);
479
		if (declareDeclaration != null) {
480
			declareDeclaration.setSourceRange(declareDecl.declarationSourceStart, declareDecl.declarationSourceEnd
481
					- declareDecl.declarationSourceStart + 1);
482
		}
480
		return declareDeclaration;
483
		return declareDeclaration;
481
	}
484
	}
482
485
Lines 624-631 Link Here
624
		return pointcutDesi;
627
		return pointcutDesi;
625
	}
628
	}
626
629
627
	public org.aspectj.org.eclipse.jdt.core.dom.PatternNode convert(ISignaturePattern patternNode) {
630
	public org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern convertSignature(ISignaturePattern patternNode) {
628
		org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = null;
631
		org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern pNode = null;
629
		if (patternNode instanceof SignaturePattern) {
632
		if (patternNode instanceof SignaturePattern) {
630
			SignaturePattern sigPat = (SignaturePattern) patternNode;
633
			SignaturePattern sigPat = (SignaturePattern) patternNode;
631
			pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast, sigPat.toString());
634
			pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast, sigPat.toString());
Lines 636-649 Link Here
636
		return pNode;
639
		return pNode;
637
	}
640
	}
638
641
639
	public org.aspectj.org.eclipse.jdt.core.dom.PatternNode convert(PatternNode patternNode) {
642
	public org.aspectj.org.eclipse.jdt.core.dom.PatternNode convert(
640
		// this is a stub to be used until dom classes have been created for
643
			PatternNode patternNode) {
641
		// the different weaver TypePattern's
642
		org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = null;
644
		org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = null;
643
		if (patternNode instanceof TypePattern) {
645
		if (patternNode instanceof TypePattern) {
644
			TypePattern typePat = (TypePattern) patternNode;
646
			TypePattern weaverTypePattern = (TypePattern) patternNode;
645
			pNode = new DefaultTypePattern(this.ast, typePat.toString());
647
			return convert(weaverTypePattern);
646
			pNode.setSourceRange(typePat.getStart(), (typePat.getEnd() - typePat.getStart() + 1));
648
647
		} else if (patternNode instanceof SignaturePattern) {
649
		} else if (patternNode instanceof SignaturePattern) {
648
			SignaturePattern sigPat = (SignaturePattern) patternNode;
650
			SignaturePattern sigPat = (SignaturePattern) patternNode;
649
			pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast, sigPat.toString());
651
			pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast, sigPat.toString());
Lines 653-658 Link Here
653
655
654
	}
656
	}
655
657
658
	public org.aspectj.org.eclipse.jdt.core.dom.TypePattern convert(
659
			TypePattern weaverNode) {
660
661
		// First check if the node is a Java type (WildType, ExactType,
662
		// BindingType)
663
		org.aspectj.org.eclipse.jdt.core.dom.TypePattern domNode = createIdentifierTypePattern(weaverNode);
664
665
		if (domNode == null) {
666
			if (weaverNode instanceof org.aspectj.weaver.patterns.EllipsisTypePattern) {
667
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.EllipsisTypePattern(
668
						ast);
669
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.NoTypePattern) {
670
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.NoTypePattern(
671
						ast);
672
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.AnyTypePattern) {
673
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.AnyTypePattern(
674
						ast);
675
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.AnyWithAnnotationTypePattern) {
676
				// For now construct the node with just the annotation
677
				// expression
678
				String annotationExpression = ((org.aspectj.weaver.patterns.AnyWithAnnotationTypePattern) weaverNode)
679
						.toString();
680
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.AnyWithAnnotationTypePattern(
681
						ast, annotationExpression);
682
683
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.OrTypePattern) {
684
				org.aspectj.weaver.patterns.OrTypePattern compilerOrNode = (org.aspectj.weaver.patterns.OrTypePattern) weaverNode;
685
				domNode = new OrTypePattern(this.ast,
686
						convert(compilerOrNode.getLeft()),
687
						convert(compilerOrNode.getRight()));
688
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.AndTypePattern) {
689
				org.aspectj.weaver.patterns.AndTypePattern compilerAndType = (org.aspectj.weaver.patterns.AndTypePattern) weaverNode;
690
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.AndTypePattern(
691
						this.ast, convert(compilerAndType.getLeft()),
692
						convert(compilerAndType.getRight()));
693
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.NotTypePattern) {
694
				//NOTE: the source range for not type patterns is the source range of the negated type pattern
695
				// EXCLUDING the "!" character. Example: !A. If A starts at 1, the source starting point for the
696
				// nottypepattern is 1, NOT 0.
697
				TypePattern negatedTypePattern = ((org.aspectj.weaver.patterns.NotTypePattern) weaverNode)
698
						.getNegatedPattern();
699
				org.aspectj.org.eclipse.jdt.core.dom.TypePattern negatedDomTypePattern = convert(negatedTypePattern);
700
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.NotTypePattern(
701
						ast, negatedDomTypePattern);
702
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.TypeCategoryTypePattern) {
703
				org.aspectj.weaver.patterns.TypeCategoryTypePattern typeCategoryWeaverNode = (org.aspectj.weaver.patterns.TypeCategoryTypePattern) weaverNode;
704
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.TypeCategoryTypePattern(
705
						ast, typeCategoryWeaverNode.getTypeCategory());
706
707
			} else if (weaverNode instanceof org.aspectj.weaver.patterns.HasMemberTypePattern) {
708
				ISignaturePattern weaverSignature = ((org.aspectj.weaver.patterns.HasMemberTypePattern) weaverNode)
709
						.getSignaturePattern();
710
				org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern signature = convertSignature(weaverSignature);
711
				domNode = new org.aspectj.org.eclipse.jdt.core.dom.HasMemberTypePattern(
712
						ast, signature);
713
			} else {
714
				// Handle any cases that are not yet implemented. Create a
715
				// default node for
716
				// them.
717
				domNode = new DefaultTypePattern(this.ast,
718
						weaverNode.toString());
719
			}
720
		}
721
722
		if (domNode != null) {
723
			domNode.setSourceRange(weaverNode.getStart(), (weaverNode.getEnd()
724
					- weaverNode.getStart() + 1));
725
		}
726
		return domNode;
727
	}
728
729
	/**
730
	 * Creates an ExactType, WildType, or BindingType, or null if none of the
731
	 * three can be created
732
	 * 
733
	 * @param weaverTypePattern
734
	 *            to convert to a DOM equivalent
735
	 * @return DOM node or null if it was not created
736
	 */
737
	protected org.aspectj.org.eclipse.jdt.core.dom.TypePattern createIdentifierTypePattern(
738
			TypePattern weaverTypePattern) {
739
		String typeExpression = weaverTypePattern.toString();
740
741
		org.aspectj.org.eclipse.jdt.core.dom.TypePattern domTypePattern = null;
742
		if (weaverTypePattern instanceof org.aspectj.weaver.patterns.WildTypePattern) {
743
			// Use the expression for wild type patterns as a Name may not be
744
			// constructed
745
			// for a Type with a unresolved typeExpression
746
			domTypePattern = new org.aspectj.org.eclipse.jdt.core.dom.WildTypePattern(
747
					ast, typeExpression);
748
		} else {
749
			// TODO: At this point, the type pattern should be resolved. Type
750
			// information
751
			// may be able to be obtained from the exact type in the weaver
752
			// pattern, therefore
753
			// replace using the expression to construct the Type and use more
754
			// appropriate
755
			// information obtained from the exact type
756
757
			if (weaverTypePattern instanceof org.aspectj.weaver.patterns.ExactTypePattern) {
758
				Type type = this.ast.newSimpleType(this.ast
759
						.newSimpleName(typeExpression));
760
				domTypePattern = new ExactTypePattern(ast, type);
761
			} else if (weaverTypePattern instanceof org.aspectj.weaver.patterns.BindingTypePattern) {
762
				Type type = this.ast.newSimpleType(this.ast
763
						.newSimpleName(typeExpression));
764
				String binding = ((org.aspectj.weaver.patterns.BindingTypePattern) weaverTypePattern)
765
						.getBindingName();
766
				FormalBinding formalBinding = new FormalBinding(type, binding,
767
						ast);
768
				domTypePattern = new org.aspectj.org.eclipse.jdt.core.dom.BindingTypePattern(
769
						ast, formalBinding);
770
			}
771
		}
772
		return domTypePattern;
773
	}
774
656
	public ASTNode convert(
775
	public ASTNode convert(
657
			org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration annotationTypeMemberDeclaration) {
776
			org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration annotationTypeMemberDeclaration) {
658
		checkCanceled();
777
		checkCanceled();
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AjASTMatcher.java (-1 / +125 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 258-261 Link Here
258
		}
258
		}
259
		return node.getDetail().equals(((SignaturePattern) other).getDetail());
259
		return node.getDetail().equals(((SignaturePattern) other).getDetail());
260
	}
260
	}
261
262
	public boolean match(AndTypePattern node, Object other) {
263
		if (node == other) {
264
			return true;
265
		}
266
		if (!(other instanceof AndTypePattern)) {
267
			return false;
268
		}
269
		AndTypePattern otherBoolean = (AndTypePattern) other;
270
		return safeSubtreeMatch(node.getLeft(), otherBoolean.getLeft())
271
				&& safeSubtreeMatch(node.getRight(), otherBoolean.getRight());
272
	}
273
274
	public boolean match(OrTypePattern node, Object other) {
275
		if (node == other) {
276
			return true;
277
		}
278
		if (!(other instanceof OrTypePattern)) {
279
			return false;
280
		}
281
		OrTypePattern otherBoolean = (OrTypePattern) other;
282
		return safeSubtreeMatch(node.getLeft(), otherBoolean.getLeft())
283
				&& safeSubtreeMatch(node.getRight(), otherBoolean.getRight());
284
	}
285
286
	public boolean match(AnyTypePattern node, Object other) {
287
		// AnyTypePattern nodes don't hold state aside from the AST, so just do a reference check
288
		if (node == other) {
289
			return true;
290
		}
291
		return false;
292
	}
293
294
	public boolean match(AnyWithAnnotationTypePattern node, Object other) {
295
		if (node == other) {
296
			return true;
297
		}
298
		if (!(other instanceof AnyWithAnnotationTypePattern)) {
299
			return false;
300
		}
301
		// For now only do an expression matching. In future versions, when
302
		// the node supports AnnotationTypes, this may have to be changed
303
		return node.getTypePatternExpression().equals(
304
				((AnyWithAnnotationTypePattern) other)
305
						.getTypePatternExpression());
306
	}
307
308
	public boolean match(EllipsisTypePattern node, Object other) {
309
		// Ellipsis nodes don't hold state aside from the AST, so just do a reference check
310
		if (node == other) {
311
			return true;
312
		}
313
		return false;
314
	}
315
316
	public boolean match(NotTypePattern node, Object other) {
317
		if (node == other) {
318
			return true;
319
		}
320
		if (!(other instanceof NotTypePattern)) {
321
			return false;
322
		}
323
		return safeSubtreeMatch(node.getNegatedTypePattern(),
324
				((NotTypePattern) other).getNegatedTypePattern());
325
	}
326
327
	public boolean match(NoTypePattern node, Object other) {
328
		// NoTypePattern nodes don't hold state aside from the AST, so just do a reference check
329
		if (node == other) {
330
			return true;
331
		}
332
		return false;
333
	}
334
335
	public boolean match(HasMemberTypePattern node, Object other) {
336
		if (node == other) {
337
			return true;
338
		}
339
		if (!(other instanceof HasMemberTypePattern)) {
340
			return false;
341
		}
342
		return safeSubtreeMatch(node.getSignaturePattern(),
343
				((HasMemberTypePattern) other).getSignaturePattern());
344
	}
345
346
	public boolean match(IdentifierTypePattern node, Object other) {
347
		if (node == other) {
348
			return true;
349
		}
350
		if (!(other instanceof IdentifierTypePattern)) {
351
			return false;
352
		}
353
		return safeSubtreeMatch(node.getType(),
354
				((IdentifierTypePattern) other).getType());
355
	}
356
357
	public boolean match(TypeCategoryTypePattern node, Object other) {
358
		if (node == other) {
359
			return true;
360
		}
361
		if (!(other instanceof TypeCategoryTypePattern)) {
362
			return false;
363
		}
364
		return node.getTypeCategory() == ((TypeCategoryTypePattern) other)
365
				.getTypeCategory();
366
	}
367
368
	public boolean match(Type type, Object other) {
369
		if (type == other) {
370
			return true;
371
		}
372
		// For now only support simple type/simple name matching. Support for
373
		// other types
374
		// may have to be added here
375
		if (type instanceof SimpleType && other instanceof SimpleType) {
376
			Name name = ((SimpleType) type).getName();
377
			Name otherName = ((SimpleType) other).getName();
378
			if (name instanceof SimpleName && otherName instanceof SimpleName) {
379
				return ((SimpleName) name).getIdentifier().equals(
380
						((SimpleName) otherName).getIdentifier());
381
			}
382
		}
383
		return false;
384
	}
261
}
385
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AjASTVisitor.java (-1 / +85 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 244-247 Link Here
244
	
244
	
245
	public void endVisit(SignaturePattern node) {
245
	public void endVisit(SignaturePattern node) {
246
	}
246
	}
247
	
248
	/*
249
	 * TODO: if necessary split this into the two specialised
250
	 * boolean type patterns (AndTypePattern, OrTypePattern)
251
	 */
252
	public boolean visit(AbstractBooleanTypePattern node) {
253
		return true;
254
	}
255
256
	public void endVisit(AbstractBooleanTypePattern node) {
257
258
	}
259
260
	public boolean visit(AnyTypePattern node) {
261
		return true;
262
	}
263
264
	public void endVisit(AnyTypePattern node) {
265
266
	}
267
268
	public boolean visit(AnyWithAnnotationTypePattern node) {
269
		return true;
270
	}
271
272
	public void endVisit(AnyWithAnnotationTypePattern node) {
273
274
	}
275
276
	public boolean visit(EllipsisTypePattern node) {
277
		return true;
278
	}
279
280
	public void endVisit(EllipsisTypePattern node) {
281
282
	}
283
284
	public boolean visit(HasMemberTypePattern node) {
285
		return true;
286
	}
287
288
	public void endVisit(HasMemberTypePattern node) {
289
290
	}
291
292
	public boolean visit(IdentifierTypePattern node) {
293
		return true;
294
	}
295
296
	public void endVisit(IdentifierTypePattern node) {
297
298
	}
299
300
	public boolean visit(NotTypePattern node) {
301
		return true;
302
	}
303
304
	public void endVisit(NotTypePattern node) {
305
306
	}
307
308
	public boolean visit(NoTypePattern node) {
309
		return true;
310
	}
311
312
	public void endVisit(NoTypePattern node) {
313
314
	}
315
316
	public boolean visit(TypeCategoryTypePattern node) {
317
		return true;
318
	}
319
320
	public void endVisit(TypeCategoryTypePattern node) {
321
322
	}
323
	
324
	public boolean visit(Type node) {
325
		return true;
326
	}
327
328
	public void endVisit(Type node) {
329
	
330
	}
247
}
331
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AjNaiveASTFlattener.java (-4 / +56 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1720-1730 Link Here
1720
		return false;
1720
		return false;
1721
	}
1721
	}
1722
	
1722
	
1723
	public boolean visit(DefaultTypePattern node) {
1723
	public boolean visit(AbstractBooleanTypePattern node) {
1724
		this.buffer.append(node.getDetail());
1724
		
1725
		// Flatten boolean expressions in order, meaning
1726
		// the left node needs to be appended first, followed by the
1727
		// boolean operator, followed by the right node.
1728
		node.getLeft().accept(this);
1729
		this.buffer.append(" ");
1730
		this.buffer.append(node.getTypePatternExpression());
1731
		this.buffer.append(" ");
1732
		node.getRight().accept(this);
1733
		
1734
		// No need to visit the childrena, as they were already visited above
1725
		return false;
1735
		return false;
1726
	}
1736
	}
1727
	
1737
1738
	public boolean visit(AnyTypePattern node) {
1739
		this.buffer.append(node.getTypePatternExpression());
1740
		return false;
1741
	}
1742
1743
	public boolean visit(AnyWithAnnotationTypePattern node) {
1744
		this.buffer.append(node.getTypePatternExpression());
1745
		return false;
1746
	}
1747
1748
	public boolean visit(EllipsisTypePattern node) {
1749
		this.buffer.append(node.getTypePatternExpression());
1750
		return false;
1751
	}
1752
1753
	public boolean visit(HasMemberTypePattern node) {
1754
		this.buffer.append(node.getTypePatternExpression());
1755
		return false;
1756
	}
1757
1758
	public boolean visit(IdentifierTypePattern node) {
1759
		this.buffer.append(node.getTypePatternExpression());
1760
		return false;
1761
	}
1762
1763
	public boolean visit(NotTypePattern node) {
1764
		this.buffer.append(node.getTypePatternExpression());
1765
		// Visit the children in this case, as the child of a not type pattern
1766
		// is the negated type pattern
1767
		return true;
1768
	}
1769
1770
	public boolean visit(NoTypePattern node) {
1771
		this.buffer.append(node.getTypePatternExpression());
1772
		return false;
1773
	}
1774
1775
	public boolean visit(TypeCategoryTypePattern node) {
1776
		this.buffer.append(node.getTypePatternExpression());
1777
		return false;
1778
	}
1779
1728
	public boolean visit(DefaultPointcut node) {
1780
	public boolean visit(DefaultPointcut node) {
1729
		this.buffer.append(node.getDetail());
1781
		this.buffer.append(node.getDetail());
1730
		return false;
1782
		return false;
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AndTypePattern.java (+54 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class AndTypePattern extends AbstractBooleanTypePattern {
15
16
	public static final String AND_OPERATOR = "&&";
17
18
	AndTypePattern(AST ast, TypePattern left, TypePattern right) {
19
		super(ast, left, right, AND_OPERATOR);
20
	}
21
22
	List<?> internalStructuralPropertiesForType(int apiLevel) {
23
		return null;
24
	}
25
26
	ASTNode clone0(AST target) {
27
		AndTypePattern cloned = new AndTypePattern(target,
28
				(TypePattern) getLeft().clone(target), (TypePattern) getRight()
29
						.clone(target));
30
		cloned.setSourceRange(getStartPosition(), getLength());
31
		return cloned;
32
	}
33
	
34
	void accept0(ASTVisitor visitor) {
35
		if (visitor instanceof AjASTVisitor) {
36
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
37
			boolean visit = ajVisitor.visit(this);
38
			if (visit) {
39
				acceptChild(visitor, getLeft());
40
				acceptChild(visitor, getRight());
41
			}
42
			ajVisitor.endVisit(this);
43
		}
44
	}
45
	
46
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
47
		if (matcher instanceof AjASTMatcher) {
48
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
49
			return ajmatcher.match(this, other);
50
		}
51
		return false;
52
	}
53
54
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AnyTypePattern.java (+47 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class AnyTypePattern extends TypePattern {
15
16
	public static final String ANYTYPE_DETAIL = "*";
17
18
	AnyTypePattern(AST ast) {
19
		super(ast, ANYTYPE_DETAIL);
20
	}
21
22
	List<?> internalStructuralPropertiesForType(int apiLevel) {
23
		return null;
24
	}
25
26
	ASTNode clone0(AST target) {
27
		AnyTypePattern cloned = new AnyTypePattern(target);
28
		cloned.setSourceRange(getStartPosition(), getLength());
29
		return cloned;
30
	}
31
	
32
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
33
		if (matcher instanceof AjASTMatcher) {
34
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
35
			return ajmatcher.match(this, other);
36
		}
37
		return false;
38
	}
39
	
40
	void accept0(ASTVisitor visitor) {
41
		if (visitor instanceof AjASTVisitor) {
42
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
43
			ajVisitor.visit(this);
44
			ajVisitor.endVisit(this);
45
		}
46
	}
47
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/AnyWithAnnotationTypePattern.java (+52 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
/**
15
 * TODO: Add support for proper AnnotationPatterns instead of the annotation
16
 * expression
17
 * 
18
 */
19
public class AnyWithAnnotationTypePattern extends TypePattern {
20
21
	AnyWithAnnotationTypePattern(AST ast, String annotationExpression) {
22
		// Is this correct? should the "*" be added
23
		super(ast, annotationExpression);
24
	}
25
26
	ASTNode clone0(AST target) {
27
		ASTNode node = new AnyWithAnnotationTypePattern(target,
28
				getTypePatternExpression());
29
		node.setSourceRange(getStartPosition(), getLength());
30
		return node;
31
	}
32
33
	List<?> internalStructuralPropertiesForType(int apiLevel) {
34
		return null;
35
	}
36
37
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
38
		if (matcher instanceof AjASTMatcher) {
39
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
40
			return ajmatcher.match(this, other);
41
		}
42
		return false;
43
	}
44
	
45
	void accept0(ASTVisitor visitor) {
46
		if (visitor instanceof AjASTVisitor) {
47
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
48
			ajVisitor.visit(this);
49
			ajVisitor.endVisit(this);
50
		}
51
	}
52
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/BindingTypePattern.java (+66 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class BindingTypePattern extends IdentifierTypePattern {
15
16
	private FormalBinding formalBinding;
17
18
	public BindingTypePattern(AST ast, FormalBinding formalBinding) {
19
		super(ast, null);
20
		this.formalBinding = formalBinding;
21
		setTypePatternExpression(generateTypePatternExpression(this.formalBinding));
22
	}
23
24
	List<?> internalStructuralPropertiesForType(int apiLevel) {
25
		return null;
26
	}
27
28
	public FormalBinding getFormalBinding() {
29
		return formalBinding;
30
	}
31
32
	ASTNode clone0(AST target) {
33
		ASTNode node = new BindingTypePattern(target,
34
				(FormalBinding) getFormalBinding().clone(target));
35
		node.setSourceRange(getStartPosition(), getLength());
36
		return node;
37
	}
38
39
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
40
		if (matcher instanceof AjASTMatcher) {
41
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
42
			return ajmatcher.match(this, other);
43
		}
44
		return false;
45
	}
46
47
	void accept0(ASTVisitor visitor) {
48
		if (visitor instanceof AjASTVisitor) {
49
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
50
			boolean visited = ajVisitor.visit(this);
51
52
			if (visited) {
53
				ajVisitor.visit(getFormalBinding());
54
			}
55
			ajVisitor.endVisit(this);
56
		}
57
	}
58
59
	protected String generateTypePatternExpression(FormalBinding formalBinding) {
60
		String expression = super.generateTypePatternExpression(formalBinding
61
				.getType());
62
		expression += expression + " " + formalBinding.getBinding();
63
		return expression;
64
	}
65
66
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/EllipsisTypePattern.java (+48 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class EllipsisTypePattern extends TypePattern {
15
16
	public static final String ELLIPSIS_DETAIL = "..";
17
18
	EllipsisTypePattern(AST ast) {
19
		super(ast, ELLIPSIS_DETAIL);
20
	}
21
22
	List<?> internalStructuralPropertiesForType(int apiLevel) {
23
		return null;
24
	}
25
26
	ASTNode clone0(AST target) {
27
		ASTNode node = new EllipsisTypePattern(target);
28
		node.setSourceRange(getStartPosition(), getLength());
29
		return node;
30
	}
31
	
32
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
33
		if (matcher instanceof AjASTMatcher) {
34
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
35
			return ajmatcher.match(this, other);
36
		}
37
		return false;
38
	}
39
40
	void accept0(ASTVisitor visitor) {
41
		if (visitor instanceof AjASTVisitor) {
42
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
43
			ajVisitor.visit(this);
44
			ajVisitor.endVisit(this);
45
		}
46
	}
47
48
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/ExactTypePattern.java (+43 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class ExactTypePattern extends IdentifierTypePattern {
15
16
	ExactTypePattern(AST ast, Type type) {
17
		super(ast, type);
18
	}
19
20
21
	List<?> internalStructuralPropertiesForType(int apiLevel) {
22
		return null;
23
	}
24
25
	ASTNode clone0(AST target) {
26
		Type clonedType = getType();
27
		if (clonedType != null) {
28
			clonedType = (Type) clonedType.clone(target);
29
		}
30
		ASTNode node = new ExactTypePattern(target, clonedType);
31
		node.setSourceRange(getStartPosition(), getLength());
32
		return node;
33
	}
34
	
35
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
36
		if (matcher instanceof AjASTMatcher) {
37
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
38
			return ajmatcher.match(this, other);
39
		}
40
		return false;
41
	}
42
43
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/FormalBinding.java (+88 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class FormalBinding extends Type {
15
16
	private Type type;
17
	private String binding;
18
19
	/**
20
	 * 
21
	 * @param type
22
	 *            must not be null
23
	 * @param binding
24
	 *            must not be null
25
	 * @param ast
26
	 *            must not be null
27
	 */
28
	public FormalBinding(Type type, String binding, AST ast) {
29
		super(ast);
30
	}
31
32
	public Type getType() {
33
		return type;
34
	}
35
36
	public String getBinding() {
37
		return binding;
38
	}
39
40
	@Override
41
	List<?> internalStructuralPropertiesForType(int apiLevel) {
42
		return null;
43
	}
44
45
	@Override
46
	int getNodeType0() {
47
		return 0;
48
	}
49
50
	@Override
51
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
52
		if (matcher instanceof AjASTMatcher) {
53
			return ((AjASTMatcher) matcher).match(this, other);
54
		}
55
		return false;
56
	}
57
58
	@Override
59
	ASTNode clone0(AST target) {
60
		ASTNode node = new FormalBinding((Type) getType().clone(target),
61
				getBinding(), target);
62
		node.setSourceRange(getStartPosition(), getLength());
63
		return node;
64
	}
65
66
	@Override
67
	void accept0(ASTVisitor visitor) {
68
		if (visitor instanceof AjASTVisitor) {
69
			boolean visited = ((AjASTVisitor) visitor).visit(this);
70
			if (visited) {
71
				((AjASTVisitor) visitor).visit(getType());
72
			}
73
			((AjASTVisitor) visitor).endVisit(this);
74
		}
75
76
	}
77
78
	@Override
79
	int treeSize() {
80
		return getType().treeSize();
81
	}
82
83
	@Override
84
	int memSize() {
85
		return BASE_NODE_SIZE + (3 * 4) + getType().memSize();
86
	}
87
88
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/HasMemberTypePattern.java (+64 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
/**
15
 *
16
 */
17
public class HasMemberTypePattern extends TypePattern {
18
19
	private SignaturePattern signaturePattern;
20
21
	public HasMemberTypePattern(AST ast, SignaturePattern signaturePattern) {
22
		super(ast, signaturePattern.getDetail());
23
		this.signaturePattern = signaturePattern;
24
	}
25
26
	List<?> internalStructuralPropertiesForType(int apiLevel) {
27
		return null;
28
	}
29
30
	public SignaturePattern getSignaturePattern() {
31
		return signaturePattern;
32
	}
33
34
	ASTNode clone0(AST target) {
35
		ASTNode cloned = new HasMemberTypePattern(target,
36
				(SignaturePattern) getSignaturePattern().clone(target));
37
		cloned.setSourceRange(getStartPosition(), getLength());
38
		return cloned;
39
	}
40
41
	void accept0(ASTVisitor visitor) {
42
		if (visitor instanceof AjASTVisitor) {
43
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
44
			boolean visited = ajVisitor.visit(this);
45
			if (visited) {
46
				ajVisitor.visit(getSignaturePattern());
47
			}
48
			ajVisitor.endVisit(this);
49
		}
50
	}
51
52
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
53
		if (matcher instanceof AjASTMatcher) {
54
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
55
			return ajmatcher.match(this, other);
56
		}
57
		return false;
58
	}
59
60
	int memSize() {
61
		return super.memSize() + getSignaturePattern().memSize();
62
	}
63
64
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/IdentifierTypePattern.java (+82 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
public abstract class IdentifierTypePattern extends TypePattern {
13
14
	private Type type;
15
16
	IdentifierTypePattern(AST ast, Type type) {
17
		super(ast);
18
		this.type = type;
19
		setTypePatternExpression(generateTypePatternExpression(this.type));
20
	}
21
22
	/**
23
	 * This may be null if no Type has been resolved. A String representation
24
	 * may still exist.
25
	 * 
26
	 * @return type if defined or resolved, or null if not defined or resolved
27
	 *         at the time when this node is created
28
	 */
29
	public Type getType() {
30
		return type;
31
	}
32
33
	/**
34
	 * Generate an expression (String representation) for the given type.
35
	 * 
36
	 * @param type
37
	 * @return non-null expression for the given type. Null if no expression can
38
	 *         be generated.
39
	 */
40
	protected String generateTypePatternExpression(Type type) {
41
		String typeExpression = null;
42
		if (type instanceof SimpleType) {
43
			Name name = ((SimpleType) type).getName();
44
			if (name instanceof SimpleName) {
45
				typeExpression = ((SimpleName) name).getIdentifier();
46
			}
47
		}
48
49
		// If expression hasn't been resolved yet, get the toString
50
		// representation
51
		if (typeExpression == null && type != null) {
52
			typeExpression = type.toString();
53
		}
54
55
		return typeExpression;
56
	}
57
58
	int memSize() {
59
60
		int memSize = super.memSize();
61
62
		Type type = getType();
63
		if (type != null) {
64
			memSize += type.memSize();
65
		}
66
67
		return memSize;
68
	}
69
70
	void accept0(ASTVisitor visitor) {
71
		if (visitor instanceof AjASTVisitor) {
72
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
73
			boolean visited = ajVisitor.visit(this);
74
			Type type = getType();
75
			if (visited && type != null) {
76
				ajVisitor.visit(type);
77
			}
78
			ajVisitor.endVisit(this);
79
		}
80
	}
81
82
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/NoTypePattern.java (+50 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class NoTypePattern extends TypePattern {
15
16
	NoTypePattern(AST ast) {
17
		super(ast);
18
	}
19
20
	List<?> internalStructuralPropertiesForType(int apiLevel) {
21
		return null;
22
	}
23
24
	public boolean isStar() {
25
		return false;
26
	}
27
28
	ASTNode clone0(AST target) {
29
		ASTNode node = new NoTypePattern(target);
30
		node.setSourceRange(getStartPosition(), getLength());
31
		return node;
32
	}
33
	
34
	void accept0(ASTVisitor visitor) {
35
		if (visitor instanceof AjASTVisitor) {
36
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
37
			ajVisitor.visit(this);
38
			ajVisitor.endVisit(this);
39
		}
40
	}
41
	
42
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
43
		if (matcher instanceof AjASTMatcher) {
44
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
45
			return ajmatcher.match(this, other);
46
		}
47
		return false;
48
	}
49
50
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/NotTypePattern.java (+69 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class NotTypePattern extends TypePattern {
15
16
	private TypePattern negatedPattern;
17
18
	/**
19
	 * The negated type pattern cannot be null
20
	 * 
21
	 * @param ast
22
	 *            not null
23
	 * @param negatedPattern
24
	 *            not null
25
	 */
26
	NotTypePattern(AST ast, TypePattern negatedPattern) {
27
		super(ast, "!");
28
		this.negatedPattern = negatedPattern;
29
	}
30
31
	List<?> internalStructuralPropertiesForType(int apiLevel) {
32
		return null;
33
	}
34
35
	public TypePattern getNegatedTypePattern() {
36
		return negatedPattern;
37
	}
38
39
	ASTNode clone0(AST target) {
40
		ASTNode node = new NotTypePattern(target,
41
				(TypePattern) getNegatedTypePattern().clone(target));
42
		node.setSourceRange(getStartPosition(), getLength());
43
		return node;
44
	}
45
46
	void accept0(ASTVisitor visitor) {
47
		if (visitor instanceof AjASTVisitor) {
48
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
49
			boolean visit = ajVisitor.visit(this);
50
			if (visit) {
51
				acceptChild(ajVisitor, getNegatedTypePattern());
52
			}
53
			ajVisitor.endVisit(this);
54
		}
55
	}
56
	
57
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
58
		if (matcher instanceof AjASTMatcher) {
59
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
60
			return ajmatcher.match(this, other);
61
		}
62
		return false;
63
	}
64
65
	int memSize() {
66
		return super.memSize() + getNegatedTypePattern().memSize();
67
	}
68
69
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/OrTypePattern.java (+55 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class OrTypePattern extends AbstractBooleanTypePattern {
15
16
	public static final String OR_OPERATOR = "||";
17
18
	OrTypePattern(AST ast,
19
			org.aspectj.org.eclipse.jdt.core.dom.TypePattern left,
20
			org.aspectj.org.eclipse.jdt.core.dom.TypePattern right) {
21
		super(ast, left, right, OR_OPERATOR);
22
	}
23
24
	List<?> internalStructuralPropertiesForType(int apiLevel) {
25
		return null;
26
	}
27
28
	ASTNode clone0(AST target) {
29
		OrTypePattern cloned = new OrTypePattern(target,
30
				(TypePattern) getLeft().clone(target), (TypePattern) getRight()
31
						.clone(target));
32
		cloned.setSourceRange(getStartPosition(), getLength());
33
		return cloned;
34
	}
35
36
	void accept0(ASTVisitor visitor) {
37
		if (visitor instanceof AjASTVisitor) {
38
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
39
			boolean visit = ajVisitor.visit(this);
40
			if (visit) {
41
				acceptChild(visitor, getLeft());
42
				acceptChild(visitor, getRight());
43
			}
44
			ajVisitor.endVisit(this);
45
		}
46
	}
47
48
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
49
		if (matcher instanceof AjASTMatcher) {
50
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
51
			return ajmatcher.match(this, other);
52
		}
53
		return false;
54
	}
55
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/PatternNode.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/********************************************************************
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
2
 * Copyright (c) 2006, 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
5
 * which accompanies this distribution and is available at 
Lines 27-31 Link Here
27
	int memSize() {
27
	int memSize() {
28
		return 0; // stub method
28
		return 0; // stub method
29
	}
29
	}
30
30
	
31
}
31
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/TypeCategoryTypePattern.java (+113 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class TypeCategoryTypePattern extends TypePattern {
15
16
	private int typeCategory;
17
18
	public static final int CLASS = org.aspectj.weaver.patterns.TypeCategoryTypePattern.CLASS;
19
	public static final int INTERFACE = org.aspectj.weaver.patterns.TypeCategoryTypePattern.INTERFACE;
20
	public static final int ASPECT = org.aspectj.weaver.patterns.TypeCategoryTypePattern.ASPECT;
21
	public static final int INNER = org.aspectj.weaver.patterns.TypeCategoryTypePattern.INNER;
22
	public static final int ANONYMOUS = org.aspectj.weaver.patterns.TypeCategoryTypePattern.ANONYMOUS;
23
	public static final int ENUM = org.aspectj.weaver.patterns.TypeCategoryTypePattern.ENUM;
24
	public static final int ANNOTATION = org.aspectj.weaver.patterns.TypeCategoryTypePattern.ANNOTATION;
25
26
	/**
27
	 * 
28
	 * See the weaver implementation for the type categories.
29
	 * 
30
	 * @see org.aspectj.weaver.patterns.TypeCategoryTypePattern
31
	 * @param ast
32
	 *            must not be null
33
	 * @param typeCategory
34
	 *            as defined in the corresponding weaver node type
35
	 */
36
	TypeCategoryTypePattern(AST ast, int typeCategory) {
37
		super(ast, null);
38
		this.typeCategory = typeCategory;
39
	}
40
41
	/**
42
	 * 
43
	 * See the weaver implementation for the type categories.
44
	 * 
45
	 * @see org.aspectj.weaver.patterns.TypeCategoryTypePattern
46
	 * @return type category
47
	 */
48
	public int getTypeCategory() {
49
		return typeCategory;
50
	}
51
52
	List<?> internalStructuralPropertiesForType(int apiLevel) {
53
		return null;
54
	}
55
56
	public String getTypePatternExpression() {
57
58
		String expression = super.getTypePatternExpression();
59
		if (expression == null) {
60
			switch (getTypeCategory()) {
61
			case CLASS:
62
				expression = "ClassType";
63
				break;
64
			case INNER:
65
				expression = "InnerType";
66
				break;
67
			case INTERFACE:
68
				expression = "InterfaceType";
69
				break;
70
			case ANNOTATION:
71
				expression = "AnnotationType";
72
				break;
73
			case ANONYMOUS:
74
				expression = "AnonymousType";
75
				break;
76
			case ASPECT:
77
				expression = "AspectType";
78
				break;
79
			case ENUM:
80
				expression = "EnumType";
81
				break;
82
			}
83
			expression = (expression != null) ? "is(" + expression + ")"
84
					: EMPTY_EXPRESSION;
85
			setTypePatternExpression(expression);
86
87
		}
88
		return expression;
89
	}
90
91
	ASTNode clone0(AST target) {
92
		ASTNode cloned = new TypeCategoryTypePattern(target, getTypeCategory());
93
		cloned.setSourceRange(getStartPosition(), getLength());
94
		return cloned;
95
	}
96
97
	void accept0(ASTVisitor visitor) {
98
		if (visitor instanceof AjASTVisitor) {
99
			AjASTVisitor ajVisitor = (AjASTVisitor) visitor;
100
			ajVisitor.visit(this);
101
			ajVisitor.endVisit(this);
102
		}
103
	}
104
105
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
106
		if (matcher instanceof AjASTMatcher) {
107
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
108
			return ajmatcher.match(this, other);
109
		}
110
		return false;
111
	}
112
113
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/TypePattern.java (-6 / +32 lines)
Lines 1-5 Link Here
1
/********************************************************************
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
2
 * Copyright (c) 2006, 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
5
 * which accompanies this distribution and is available at 
Lines 10-29 Link Here
10
 *******************************************************************/
10
 *******************************************************************/
11
package org.aspectj.org.eclipse.jdt.core.dom;
11
package org.aspectj.org.eclipse.jdt.core.dom;
12
12
13
14
/**
13
/**
15
 * abstract TypePattern DOM AST node.
14
 * abstract TypePattern DOM AST node.
16
 * has:
17
 *   nothing at the moment
18
 */
15
 */
19
public abstract class TypePattern extends PatternNode {
16
public abstract class TypePattern extends PatternNode {
20
17
18
	private String typePatternExpression;
19
	
20
	public static final String EMPTY_EXPRESSION = "";
21
21
	TypePattern(AST ast) {
22
	TypePattern(AST ast) {
22
		super(ast);
23
		super(ast);
23
	}
24
	}
24
25
25
	int memSize() {
26
	TypePattern(AST ast, String typePatternExpression) {
26
		return 0; // stub method
27
		super(ast);
28
		this.typePatternExpression = typePatternExpression;
29
	}
30
31
	/**
32
	 * Should be called for internal setting only, if the expression needs to be set
33
	 * lazily
34
	 * @param typePatternExpression
35
	 */
36
	protected void setTypePatternExpression(String typePatternExpression) {
37
		this.typePatternExpression = typePatternExpression;
38
	}
39
40
	/**
41
	 * Return the type pattern in expression form (String representation). In
42
	 * many cases, this is not null, although it may be null in some cases like
43
	 * the NoTypePattern
44
	 * 
45
	 * @return String expression of the type pattern. May be null.
46
	 */
47
	public String getTypePatternExpression() {
48
		return typePatternExpression;
49
	}
50
51
	int treeSize() {
52
		return memSize();
27
	}
53
	}
28
54
29
}
55
}
(-)src/org/aspectj/org/eclipse/jdt/core/dom/WildTypePattern.java (+60 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: Nieraj Singh - initial implementation
9
 *******************************************************************/
10
package org.aspectj.org.eclipse.jdt.core.dom;
11
12
import java.util.List;
13
14
public class WildTypePattern extends IdentifierTypePattern {
15
16
	/**
17
	 * Use this constructor if Type is known
18
	 * 
19
	 * @param ast
20
	 * @param type
21
	 */
22
	WildTypePattern(AST ast, Type type) {
23
		super(ast, type);
24
	}
25
26
	/**
27
	 * Use this constructor if Type cannot be determined
28
	 * 
29
	 * @param ast
30
	 * @param typeExpression
31
	 */
32
	WildTypePattern(AST ast, String typeExpression) {
33
		super(ast, null);
34
		setTypePatternExpression(typeExpression);
35
	}
36
37
	List<?> internalStructuralPropertiesForType(int apiLevel) {
38
		return null;
39
	}
40
41
	ASTNode clone0(AST target) {
42
		Type type = getType();
43
44
		ASTNode cloned = type != null ? new WildTypePattern(target,
45
				(Type) type.clone(target)) : new WildTypePattern(target,
46
				getTypePatternExpression());
47
		cloned.setSourceRange(getStartPosition(), getLength());
48
49
		return cloned;
50
	}
51
	
52
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
53
		if (matcher instanceof AjASTMatcher) {
54
			AjASTMatcher ajmatcher = (AjASTMatcher) matcher;
55
			return ajmatcher.match(this, other);
56
		}
57
		return false;
58
	}
59
60
}
(-)testsrc/org/aspectj/tools/ajc/ASTVisitorTest.java (-12 / +154 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-31 Link Here
17
17
18
import org.aspectj.org.eclipse.jdt.core.dom.AST;
18
import org.aspectj.org.eclipse.jdt.core.dom.AST;
19
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
19
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
20
import org.aspectj.org.eclipse.jdt.core.dom.AbstractBooleanTypePattern;
20
import org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration;
21
import org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration;
21
import org.aspectj.org.eclipse.jdt.core.dom.AfterReturningAdviceDeclaration;
22
import org.aspectj.org.eclipse.jdt.core.dom.AfterReturningAdviceDeclaration;
22
import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
23
import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
23
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
24
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
24
import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
25
import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
26
import org.aspectj.org.eclipse.jdt.core.dom.AndTypePattern;
27
import org.aspectj.org.eclipse.jdt.core.dom.AnyTypePattern;
28
import org.aspectj.org.eclipse.jdt.core.dom.AnyWithAnnotationTypePattern;
25
import org.aspectj.org.eclipse.jdt.core.dom.AroundAdviceDeclaration;
29
import org.aspectj.org.eclipse.jdt.core.dom.AroundAdviceDeclaration;
26
import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
30
import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
27
import org.aspectj.org.eclipse.jdt.core.dom.Assignment;
31
import org.aspectj.org.eclipse.jdt.core.dom.Assignment;
28
import org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration;
32
import org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration;
33
import org.aspectj.org.eclipse.jdt.core.dom.BindingTypePattern;
29
import org.aspectj.org.eclipse.jdt.core.dom.Block;
34
import org.aspectj.org.eclipse.jdt.core.dom.Block;
30
import org.aspectj.org.eclipse.jdt.core.dom.BlockComment;
35
import org.aspectj.org.eclipse.jdt.core.dom.BlockComment;
31
import org.aspectj.org.eclipse.jdt.core.dom.BodyDeclaration;
36
import org.aspectj.org.eclipse.jdt.core.dom.BodyDeclaration;
Lines 39-56 Link Here
39
import org.aspectj.org.eclipse.jdt.core.dom.DeclarePrecedenceDeclaration;
44
import org.aspectj.org.eclipse.jdt.core.dom.DeclarePrecedenceDeclaration;
40
import org.aspectj.org.eclipse.jdt.core.dom.DeclareSoftDeclaration;
45
import org.aspectj.org.eclipse.jdt.core.dom.DeclareSoftDeclaration;
41
import org.aspectj.org.eclipse.jdt.core.dom.DeclareWarningDeclaration;
46
import org.aspectj.org.eclipse.jdt.core.dom.DeclareWarningDeclaration;
42
import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern;
43
import org.aspectj.org.eclipse.jdt.core.dom.EnumDeclaration;
47
import org.aspectj.org.eclipse.jdt.core.dom.EnumDeclaration;
48
import org.aspectj.org.eclipse.jdt.core.dom.ExactTypePattern;
44
import org.aspectj.org.eclipse.jdt.core.dom.ExpressionStatement;
49
import org.aspectj.org.eclipse.jdt.core.dom.ExpressionStatement;
45
import org.aspectj.org.eclipse.jdt.core.dom.FieldAccess;
50
import org.aspectj.org.eclipse.jdt.core.dom.FieldAccess;
46
import org.aspectj.org.eclipse.jdt.core.dom.FieldDeclaration;
51
import org.aspectj.org.eclipse.jdt.core.dom.FieldDeclaration;
52
import org.aspectj.org.eclipse.jdt.core.dom.IdentifierTypePattern;
47
import org.aspectj.org.eclipse.jdt.core.dom.InfixExpression;
53
import org.aspectj.org.eclipse.jdt.core.dom.InfixExpression;
48
import org.aspectj.org.eclipse.jdt.core.dom.Initializer;
54
import org.aspectj.org.eclipse.jdt.core.dom.Initializer;
49
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration;
55
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration;
50
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
56
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
51
import org.aspectj.org.eclipse.jdt.core.dom.MethodDeclaration;
57
import org.aspectj.org.eclipse.jdt.core.dom.MethodDeclaration;
52
import org.aspectj.org.eclipse.jdt.core.dom.MethodInvocation;
58
import org.aspectj.org.eclipse.jdt.core.dom.MethodInvocation;
59
import org.aspectj.org.eclipse.jdt.core.dom.NotTypePattern;
53
import org.aspectj.org.eclipse.jdt.core.dom.NumberLiteral;
60
import org.aspectj.org.eclipse.jdt.core.dom.NumberLiteral;
61
import org.aspectj.org.eclipse.jdt.core.dom.OrTypePattern;
54
import org.aspectj.org.eclipse.jdt.core.dom.PerCflow;
62
import org.aspectj.org.eclipse.jdt.core.dom.PerCflow;
55
import org.aspectj.org.eclipse.jdt.core.dom.PerObject;
63
import org.aspectj.org.eclipse.jdt.core.dom.PerObject;
56
import org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin;
64
import org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin;
Lines 61-69 Link Here
61
import org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern;
69
import org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern;
62
import org.aspectj.org.eclipse.jdt.core.dom.SimpleName;
70
import org.aspectj.org.eclipse.jdt.core.dom.SimpleName;
63
import org.aspectj.org.eclipse.jdt.core.dom.StringLiteral;
71
import org.aspectj.org.eclipse.jdt.core.dom.StringLiteral;
72
import org.aspectj.org.eclipse.jdt.core.dom.TypeCategoryTypePattern;
64
import org.aspectj.org.eclipse.jdt.core.dom.TypeDeclaration;
73
import org.aspectj.org.eclipse.jdt.core.dom.TypeDeclaration;
65
import org.aspectj.org.eclipse.jdt.core.dom.VariableDeclaration;
74
import org.aspectj.org.eclipse.jdt.core.dom.VariableDeclaration;
66
import org.aspectj.org.eclipse.jdt.core.dom.VariableDeclarationStatement;
75
import org.aspectj.org.eclipse.jdt.core.dom.VariableDeclarationStatement;
76
import org.aspectj.org.eclipse.jdt.core.dom.WildTypePattern;
67
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
77
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
68
78
69
public class ASTVisitorTest extends TestCase {
79
public class ASTVisitorTest extends TestCase {
Lines 280-289 Link Here
280
				"(compilationUnit(class(simpleName)(method(primitiveType)(simpleName)(block(expressionStatement(methodInvocation(simpleName))))))(aspect(simpleName)(constructorITD(primitiveType)(simpleName)(block))))");
290
				"(compilationUnit(class(simpleName)(method(primitiveType)(simpleName)(block(expressionStatement(methodInvocation(simpleName))))))(aspect(simpleName)(constructorITD(primitiveType)(simpleName)(block))))");
281
	}
291
	}
282
	
292
	
283
	public void testDeclareParents(){
293
	/*
294
	 * 
295
	 * START: Test TypePattern nodes introduced in Bugzilla 329268.
296
	 * 
297
	 */
298
	
299
	public void testDeclareParents() {
284
		check("class A{}class B{}aspect C {declare parents : A extends B;}",
300
		check("class A{}class B{}aspect C {declare parents : A extends B;}",
285
				"(compilationUnit(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents(defaultTypePattern)(defaultTypePattern))))");
301
				"(compilationUnit(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents(wildTypePattern)(wildTypePattern))))");
302
	}
303
304
	public void testDeclareParentsAnyTypePattern() {
305
		check("class A{}class B{}aspect C {declare parents : * extends B;}",
306
				"(compilationUnit(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents(anyTypePattern)(wildTypePattern))))");
307
	}
308
309
	public void testDeclareParentsAndTypePattern() {
310
		check("class A{}class B{}class D{}class E{}aspect C {declare parents : A && B && D extends E;}",
311
				"(compilationUnit(class(simpleName))(class(simpleName))(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)andTypePattern((wildTypePattern)andTypePattern(wildTypePattern)))(wildTypePattern))))");
312
	}
313
314
	public void testDeclareParentsOrTypePattern() {
315
		check("class A{}class B{}class D{}class E{}aspect C {declare parents : A || B || D extends E;}",
316
				"(compilationUnit(class(simpleName))(class(simpleName))(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)orTypePattern((wildTypePattern)orTypePattern(wildTypePattern)))(wildTypePattern))))");
317
	}
318
319
	public void testDeclareParentsAndOrTypePattern() {
320
		check("class A{}class B{}class D{}class E{}aspect C {declare parents : A && (B || D) extends E;}",
321
				"(compilationUnit(class(simpleName))(class(simpleName))(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)andTypePattern((wildTypePattern)orTypePattern(wildTypePattern)))(wildTypePattern))))");
322
	}
323
324
	public void testDeclareParentsOrAndTypePattern() {
325
		check("class A{}class B{}class D{}class E{}aspect C {declare parents : A || B && D extends E;}",
326
				"(compilationUnit(class(simpleName))(class(simpleName))(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)orTypePattern((wildTypePattern)andTypePattern(wildTypePattern)))(wildTypePattern))))");
327
	}
328
329
	public void testDeclareParentsNotTypePattern() {
330
		check("class A{}class B{}class D{}class E{}aspect C {declare parents : A && !B extends E;}",
331
				"(compilationUnit(class(simpleName))(class(simpleName))(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)andTypePattern(notTypePattern(wildTypePattern)))(wildTypePattern))))");
332
	}
333
334
	public void testDeclareParentsTypeCategoryTypePattern() {
335
		check("class A{}class E{}aspect C {declare parents : A && is(ClassType) extends E;}",
336
				"(compilationUnit(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)andTypePattern(typeCategoryTypePattern))(wildTypePattern))))");
337
	}
338
339
	public void testDeclareParentsTypeCategoryTypePatternNot() {
340
		check("class A{}class E{}aspect C {declare parents : A && !is(InnerType) extends E;}",
341
				"(compilationUnit(class(simpleName))(class(simpleName))(aspect(simpleName)(declareParents((wildTypePattern)andTypePattern(notTypePattern(typeCategoryTypePattern)))(wildTypePattern))))");
342
	}
343
344
	public void testDeclareParentsAnyWithAnnotationTypePattern() {
345
		check("class E{}aspect C {declare parents : (@AnnotationT *) extends E;}",
346
				"(compilationUnit(class(simpleName))(aspect(simpleName)(declareParents(anyWithAnnotationTypePattern)(wildTypePattern))))");
286
	}
347
	}
348
	
349
	
350
	/*
351
	 * 
352
	 * END: Test TypePattern nodes introduced in Bugzilla 329268.
353
	 * 
354
	 */
355
	
356
	
287
	public void testDeclareWarning(){
357
	public void testDeclareWarning(){
288
		check("aspect A {pointcut a();declare warning: a(): \"warning\";}",
358
		check("aspect A {pointcut a();declare warning: a(): \"warning\";}",
289
				"(compilationUnit(aspect(simpleName)(pointcut(simpleName))(declareWarning(referencePointcut(simpleName))(stringLiteral))))");
359
				"(compilationUnit(aspect(simpleName)(pointcut(simpleName))(declareWarning(referencePointcut(simpleName))(stringLiteral))))");
Lines 294-308 Link Here
294
	}
364
	}
295
	public void testDeclareSoft(){
365
	public void testDeclareSoft(){
296
		check("aspect A {pointcut a();declare soft: Exception+: a();}",
366
		check("aspect A {pointcut a();declare soft: Exception+: a();}",
297
				"(compilationUnit(aspect(simpleName)(pointcut(simpleName))(declareSoft(referencePointcut(simpleName))(defaultTypePattern))))");
367
				"(compilationUnit(aspect(simpleName)(pointcut(simpleName))(declareSoft(referencePointcut(simpleName))(wildTypePattern))))");
298
	}
368
	}
299
	public void testDeclarePrecedence(){
369
	public void testDeclarePrecedence(){
300
		check("aspect A{}aspect B{declare precedence: B,A;}",
370
		check("aspect A{}aspect B{declare precedence: B,A;}",
301
				"(compilationUnit(aspect(simpleName))(aspect(simpleName)(declarePrecedence(defaultTypePattern)(defaultTypePattern))))");
371
				"(compilationUnit(aspect(simpleName))(aspect(simpleName)(declarePrecedence(wildTypePattern)(wildTypePattern))))");
302
	}
372
	}
303
	public void testDeclareAnnotationType(){
373
	public void testDeclareAnnotationType(){
304
		checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @type: C : @MyAnnotation;}",
374
		checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @type: C : @MyAnnotation;}",
305
				"(compilationUnit(simpleName)(class(simpleName))(aspect(simpleName)(declareAtType(defaultTypePattern)(simpleName))))");
375
				"(compilationUnit(simpleName)(class(simpleName))(aspect(simpleName)(declareAtType(wildTypePattern)(simpleName))))");
306
	}
376
	}
307
	public void testDeclareAnnotationMethod(){
377
	public void testDeclareAnnotationMethod(){
308
		checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @method:public * C.*(..) : @MyAnnotation;}",
378
		checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @method:public * C.*(..) : @MyAnnotation;}",
Lines 727-739 Link Here
727
	public void endVisit(DeclareWarningDeclaration node) {
797
	public void endVisit(DeclareWarningDeclaration node) {
728
		b.append(")"); //$NON-NLS-1$
798
		b.append(")"); //$NON-NLS-1$
729
	}
799
	}
730
	public boolean visit(DefaultTypePattern node) {
800
	
731
		b.append("(defaultTypePattern");
801
	public boolean visit(AbstractBooleanTypePattern node) {
732
		return isVisitingChildren();		
802
		b.append("(");
803
		node.getLeft().accept(this);
804
		if (node instanceof AndTypePattern) {
805
			b.append("andTypePattern");
806
		} else if (node instanceof OrTypePattern) {
807
			b.append("orTypePattern");
808
		}
809
		node.getRight().accept(this);
810
		b.append(")");
811
		
812
		// Don't visit the children, as that is done above in order (left node first, boolean operator next, right node last
813
		return false;
733
	}
814
	}
734
	public void endVisit(DefaultTypePattern node) {
815
735
		b.append(")"); //$NON-NLS-1$
816
817
	public boolean visit(AnyTypePattern node) {
818
		b.append("(anyTypePattern");
819
		return isVisitingChildren();
736
	}
820
	}
821
822
823
	public void endVisit(AnyTypePattern node) {
824
		b.append(")"); 
825
	}
826
827
828
	public boolean visit(AnyWithAnnotationTypePattern node) {
829
		b.append("(anyWithAnnotationTypePattern");
830
		return isVisitingChildren();
831
	}
832
833
834
	public void endVisit(AnyWithAnnotationTypePattern node) {
835
		b.append(")"); 
836
	}
837
838
	public boolean visit(IdentifierTypePattern node) {
839
		if (node instanceof WildTypePattern) {
840
			b.append("(wildTypePattern");
841
		} else if (node instanceof ExactTypePattern) {
842
			b.append("(exactTypePattern");
843
		} else if (node instanceof BindingTypePattern) {
844
			b.append("(bindingTypePattern");
845
		}
846
		return isVisitingChildren();
847
	}
848
849
850
	public void endVisit(IdentifierTypePattern node) {
851
		b.append(")"); 
852
	}
853
854
855
	public boolean visit(NotTypePattern node) {
856
		b.append("(notTypePattern");
857
		return isVisitingChildren();
858
	}
859
860
861
	public void endVisit(NotTypePattern node) {
862
		b.append(")"); 
863
	}
864
865
866
	public boolean visit(TypeCategoryTypePattern node) {
867
		b.append("(typeCategoryTypePattern");
868
		return isVisitingChildren();
869
	}
870
871
872
	public void endVisit(TypeCategoryTypePattern node) {
873
		b.append(")"); 
874
	}
875
	
876
	
877
	// End of TypePattern additions for Bugzilla 329268
878
737
	public boolean visit(SignaturePattern node) {
879
	public boolean visit(SignaturePattern node) {
738
		b.append("(signaturePattern");
880
		b.append("(signaturePattern");
739
		return isVisitingChildren();		
881
		return isVisitingChildren();		
(-)testsrc/org/aspectj/tools/ajc/AjASTTest.java (-3 / +240 lines)
Lines 1-15 Link Here
1
/********************************************************************
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
2
 * Copyright (c) 2006, 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
7
 *  
8
 * Contributors: IBM Corporation - initial API and implementation 
8
 * Contributors: IBM Corporation - initial API and implementation 
9
 * 				 Helen Hawkins   - iniital version
9
 * 				 Helen Hawkins   - initial version
10
 *******************************************************************/
10
 *******************************************************************/
11
package org.aspectj.tools.ajc;
11
package org.aspectj.tools.ajc;
12
12
13
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.Collections;
14
import java.util.Iterator;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.List;
Lines 17-22 Link Here
17
import org.aspectj.org.eclipse.jdt.core.dom.AST;
18
import org.aspectj.org.eclipse.jdt.core.dom.AST;
18
import org.aspectj.org.eclipse.jdt.core.dom.ASTNode;
19
import org.aspectj.org.eclipse.jdt.core.dom.ASTNode;
19
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
20
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
21
import org.aspectj.org.eclipse.jdt.core.dom.AbstractBooleanTypePattern;
20
import org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration;
22
import org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration;
21
import org.aspectj.org.eclipse.jdt.core.dom.AfterReturningAdviceDeclaration;
23
import org.aspectj.org.eclipse.jdt.core.dom.AfterReturningAdviceDeclaration;
22
import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
24
import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
Lines 24-29 Link Here
24
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
26
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
25
import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
27
import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
26
import org.aspectj.org.eclipse.jdt.core.dom.AndPointcut;
28
import org.aspectj.org.eclipse.jdt.core.dom.AndPointcut;
29
import org.aspectj.org.eclipse.jdt.core.dom.AnyTypePattern;
30
import org.aspectj.org.eclipse.jdt.core.dom.AnyWithAnnotationTypePattern;
27
import org.aspectj.org.eclipse.jdt.core.dom.AroundAdviceDeclaration;
31
import org.aspectj.org.eclipse.jdt.core.dom.AroundAdviceDeclaration;
28
import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
32
import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
29
import org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration;
33
import org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration;
Lines 43-53 Link Here
43
import org.aspectj.org.eclipse.jdt.core.dom.DeclareWarningDeclaration;
47
import org.aspectj.org.eclipse.jdt.core.dom.DeclareWarningDeclaration;
44
import org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut;
48
import org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut;
45
import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern;
49
import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern;
50
import org.aspectj.org.eclipse.jdt.core.dom.EllipsisTypePattern;
51
import org.aspectj.org.eclipse.jdt.core.dom.HasMemberTypePattern;
46
import org.aspectj.org.eclipse.jdt.core.dom.IExtendedModifier;
52
import org.aspectj.org.eclipse.jdt.core.dom.IExtendedModifier;
53
import org.aspectj.org.eclipse.jdt.core.dom.IdentifierTypePattern;
47
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration;
54
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration;
48
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
55
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
49
import org.aspectj.org.eclipse.jdt.core.dom.Javadoc;
56
import org.aspectj.org.eclipse.jdt.core.dom.Javadoc;
57
import org.aspectj.org.eclipse.jdt.core.dom.NoTypePattern;
50
import org.aspectj.org.eclipse.jdt.core.dom.NotPointcut;
58
import org.aspectj.org.eclipse.jdt.core.dom.NotPointcut;
59
import org.aspectj.org.eclipse.jdt.core.dom.NotTypePattern;
51
import org.aspectj.org.eclipse.jdt.core.dom.OrPointcut;
60
import org.aspectj.org.eclipse.jdt.core.dom.OrPointcut;
52
import org.aspectj.org.eclipse.jdt.core.dom.PerCflow;
61
import org.aspectj.org.eclipse.jdt.core.dom.PerCflow;
53
import org.aspectj.org.eclipse.jdt.core.dom.PerObject;
62
import org.aspectj.org.eclipse.jdt.core.dom.PerObject;
Lines 62-69 Link Here
62
import org.aspectj.org.eclipse.jdt.core.dom.SingleVariableDeclaration;
71
import org.aspectj.org.eclipse.jdt.core.dom.SingleVariableDeclaration;
63
import org.aspectj.org.eclipse.jdt.core.dom.StringLiteral;
72
import org.aspectj.org.eclipse.jdt.core.dom.StringLiteral;
64
import org.aspectj.org.eclipse.jdt.core.dom.Type;
73
import org.aspectj.org.eclipse.jdt.core.dom.Type;
74
import org.aspectj.org.eclipse.jdt.core.dom.TypeCategoryTypePattern;
65
import org.aspectj.org.eclipse.jdt.core.dom.TypeDeclaration;
75
import org.aspectj.org.eclipse.jdt.core.dom.TypeDeclaration;
66
import org.aspectj.org.eclipse.jdt.core.dom.TypePattern;
76
import org.aspectj.org.eclipse.jdt.core.dom.TypePattern;
77
import org.aspectj.org.eclipse.jdt.internal.core.SourceRange;
67
78
68
/**
79
/**
69
 * For each AspectJ ASTNode there is a test for:
80
 * For each AspectJ ASTNode there is a test for:
Lines 1649-1655 Link Here
1649
	public void testDeclareParents() {
1660
	public void testDeclareParents() {
1650
		checkJLS3("class A{}class B{}aspect C {declare parents : A extends B;}", 28, 29);
1661
		checkJLS3("class A{}class B{}aspect C {declare parents : A extends B;}", 28, 29);
1651
	}
1662
	}
1652
1663
	
1664
	
1665
	/*
1666
	 * 
1667
	 * 
1668
	 * START: Test TypePattern nodes introduced in Bugzilla 329268.
1669
	 * 
1670
	 * 
1671
	 */
1672
	
1673
	public void testDeclareParentsTypePatternNodeSource() {
1674
		checkTypePatternSourceRangesJLS3("class A{}class B{}aspect C {declare parents : A extends B;}", new int[][] {{46, 1} , {56, 1 }});
1675
	}
1676
	
1677
	public void testDeclareParentsAnySource() {
1678
		checkTypePatternSourceRangesJLS3("class A{}class B{}aspect C {declare parents : * extends B;}", new int[][] {{46, 1} , {56, 1 }});
1679
	}
1680
	
1681
	public void testDeclareParentsAndSource() {
1682
1683
		checkTypePatternSourceRangesJLS3(
1684
				"class A{}class B{}class D{}class E{}aspect C {declare parents : A && B && D extends E;}",
1685
				new int[][] { { 64, 11 },// A && B && D,
1686
						{ 64, 1 }, // A
1687
						{ 69, 6 }, // B && D
1688
						{ 69, 1 }, // B
1689
						{ 74, 1 }, // D
1690
						{ 84, 1 } // E
1691
				});
1692
	}
1693
	
1694
	public void testDeclareParentsNotSource() {
1695
1696
		checkTypePatternSourceRangesJLS3(
1697
				"class A{}class B{}class D{}class E{}aspect C {declare parents : A && !B extends E;}",
1698
				new int[][] { { 64, 7 },// A && !B
1699
						{ 64, 1 }, // A
1700
						{ 70, 1 }, // !B: the source location for a negated pattern is the start of the negated pattern excluding "!". Is this a bug?
1701
						{ 70, 1 }, // B
1702
						{ 80, 1 } // E
1703
				});
1704
	}
1705
	
1706
	public void testDeclareParentsOrSource() {
1707
		checkTypePatternSourceRangesJLS3(
1708
				"class A{}class B{}class D{}class E{}aspect C {declare parents : A || B || D extends E;}",
1709
				new int[][] { { 64, 11 },// A || B || D,
1710
						{ 64, 1 }, // A
1711
						{ 69, 6 }, // B || D
1712
						{ 69, 1 }, // B
1713
						{ 74, 1 }, // D
1714
						{ 84, 1 } // E
1715
				});
1716
	}
1717
	
1718
	public void testDeclareParentsAnyWithAnnotationSource() {
1719
		checkTypePatternSourceRangesJLS3(
1720
				"@interface AnnotationT {}class E{}aspect C {declare parents : (@AnnotationT *) extends E;}",
1721
				new int[][] { { 62, 16 },// (@AnnotationT *)
1722
						{ 87, 1 } // E
1723
				});
1724
		
1725
	}
1726
	
1727
	public void testDeclareParentsTypeCategorySource() {
1728
		checkTypePatternSourceRangesJLS3(
1729
				"class A{}class E{}aspect C {declare parents : A && is(ClassType) extends E;}",
1730
				new int[][] { { 46, 18 },// A && !is(InnerType)
1731
						{ 46, 1 }, // A
1732
						{ 51, 13}, // is(InnerType)
1733
						{ 73, 1 } // E
1734
				});
1735
	}
1736
1737
	public void testDeclareParentsTypeCategoryNotSource() {
1738
		checkTypePatternSourceRangesJLS3(
1739
				"class A{}class E{}aspect C {declare parents : A && !is(InnerType) extends E;}",
1740
				new int[][] { { 46, 19 },// A && !is(InnerType)
1741
						{ 46, 1 }, // A
1742
						{ 52, 13}, // !is(InnerType): the source location for a negated pattern is the start of the negated pattern excluding "!". Is this a bug?
1743
						{ 52, 13}, // is(InnerType)
1744
						{ 74, 1 } // E
1745
				});
1746
	}
1747
1748
	// // TODO: commenting out as there isn't proper support for hasmethod(..)
1749
	// yet. Uncomment and fix when hasmethod is supported
1750
	// public void testDeclareParentsHasMember() {
1751
	// // This is wrong. Call checkTypePatternJLS3 instead to check the source
1752
	// ranges for hasMethod...
1753
	// checkJLS3("class A{}class B{ public void fooB() {}}class D{}aspect C {declare parents : A && hasmethod(void foo*(..)) extends D;}",
1754
	// 37, 34);
1755
	// }
1756
1757
	public void testDeclareParentsTypeCategoryInner() {
1758
		checkCategoryTypePatternJLS3(
1759
				"class A{class B{}}class E{}aspect C {declare parents : B && is(InnerType) extends E;}",
1760
				TypeCategoryTypePattern.INNER, "is(InnerType)");
1761
	}
1762
1763
	public void testDeclareParentsTypeCategoryInterface() {
1764
		checkCategoryTypePatternJLS3(
1765
				"interface B{}interface E{}aspect C {declare parents : B && is(InterfaceType) extends E;}",
1766
				TypeCategoryTypePattern.INTERFACE, "is(InterfaceType)");
1767
	}
1768
1769
	public void testDeclareParentsTypeCategoryClass() {
1770
		checkCategoryTypePatternJLS3(
1771
				"class B{}class E{}aspect C {declare parents : B && is(ClassType) extends E;}",
1772
				TypeCategoryTypePattern.CLASS, "is(ClassType)");
1773
	}
1774
1775
	public void testDeclareParentsTypeCategoryAnnotation() {
1776
		checkCategoryTypePatternJLS3(
1777
				"@interface B{}class E{}aspect C {declare parents : B && is(AnnotationType) extends E;}",
1778
				TypeCategoryTypePattern.ANNOTATION, "is(AnnotationType)");
1779
	}
1780
1781
	public void testDeclareParentsTypeCategoryAnonymous() {
1782
		checkCategoryTypePatternJLS3(
1783
				"class A{B annonymousB = new B() {};}class B{}class E{}aspect C {declare parents : B && is(AnonymousType) extends E;}",
1784
				TypeCategoryTypePattern.ANONYMOUS, "is(AnonymousType)");
1785
	}
1786
1787
	public void testDeclareParentsTypeCategoryEnum() {
1788
		checkCategoryTypePatternJLS3(
1789
				"class B{}class E{}aspect C {declare parents : B && !is(EnumType) extends E;}",
1790
				TypeCategoryTypePattern.ENUM, "is(EnumType)");
1791
	}
1792
	
1793
	/*
1794
	 * 
1795
	 * 
1796
	 * END: Test TypePattern nodes introduced in Bugzilla 329268.
1797
	 * 
1798
	 * 
1799
	 */
1800
	
1801
	
1653
	public void testDeclareWarning() {
1802
	public void testDeclareWarning() {
1654
		checkJLS3("aspect A {pointcut a();declare warning: a(): \"error\";}", 23, 30);
1803
		checkJLS3("aspect A {pointcut a();declare warning: a(): \"error\";}", 23, 30);
1655
	}
1804
	}
Lines 1680-1687 Link Here
1680
		assertEquals("expected there to be one comment but found " + cu.getCommentList().size(), 1, cu.getCommentList().size());
1829
		assertEquals("expected there to be one comment but found " + cu.getCommentList().size(), 1, cu.getCommentList().size());
1681
	}
1830
	}
1682
1831
1832
	
1833
	protected void assertExpression(String expectedExpression, TypePattern node) {
1834
		assertTrue("Expected: " + expectedExpression + ". Actual: " + node.getTypePatternExpression(), node.getTypePatternExpression().equals(expectedExpression));
1835
		
1836
	}
1837
	
1838
	protected void assertNodeType(Class<?> expected, TypePattern node) {
1839
		assertTrue("Expected " + expected.toString() + ". Actual: " + node.getClass().toString(), node.getClass().equals(expected));
1840
	}
1841
}
1842
1843
1844
1845
class TypeCategoryTypeVisitor extends AjASTVisitor {
1846
	
1847
	private TypeCategoryTypePattern typeCategory = null;
1848
	
1849
	public boolean visit(TypeCategoryTypePattern node) {
1850
		typeCategory = node;
1851
		return false;
1852
	}
1853
	
1854
	public TypeCategoryTypePattern getTypeCategoryNode() {
1855
		return typeCategory;
1856
	}
1857
}
1858
1859
class TypePatternSourceRangeVisitor extends AjASTVisitor {
1860
	private List<SourceRange> sourceRanges = new ArrayList<SourceRange>();
1861
1862
	public List<SourceRange> getVisitedSourceRanges() {
1863
		return sourceRanges;
1864
	}
1865
1866
	public boolean visit(AbstractBooleanTypePattern node) {
1867
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1868
				.getLength()));
1869
		return true;
1870
	}
1871
1872
	public boolean visit(AnyTypePattern node) {
1873
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1874
				.getLength()));
1875
		return true;
1876
	}
1877
1878
	public boolean visit(AnyWithAnnotationTypePattern node) {
1879
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1880
				.getLength()));
1881
		return true;
1882
	}
1883
1884
	public boolean visit(EllipsisTypePattern node) {
1885
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1886
				.getLength()));
1887
		return true;
1888
	}
1889
1890
	public boolean visit(HasMemberTypePattern node) {
1891
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1892
				.getLength()));
1893
		return true;
1894
	}
1895
1896
	public boolean visit(IdentifierTypePattern node) {
1897
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1898
				.getLength()));
1899
		return true;
1900
	}
1901
1902
	public boolean visit(NotTypePattern node) {
1903
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1904
				.getLength()));
1905
		return true;
1906
	}
1907
1908
	public boolean visit(NoTypePattern node) {
1909
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1910
				.getLength()));
1911
		return true;
1912
	}
1913
1914
	public boolean visit(TypeCategoryTypePattern node) {
1915
		sourceRanges.add(new SourceRange(node.getStartPosition(), node
1916
				.getLength()));
1917
		return true;
1918
	}
1683
}
1919
}
1684
1920
1921
1685
class SourceRangeVisitor extends AjASTVisitor {
1922
class SourceRangeVisitor extends AjASTVisitor {
1686
1923
1687
	boolean visitTheKids = true;
1924
	boolean visitTheKids = true;
(-)testsrc/org/aspectj/tools/ajc/AjASTTestCase.java (-11 / +190 lines)
Lines 1-5 Link Here
1
/********************************************************************
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
2
 * Copyright (c) 2006, 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
5
 * which accompanies this distribution and is available at 
Lines 10-23 Link Here
10
 *******************************************************************/
10
 *******************************************************************/
11
package org.aspectj.tools.ajc;
11
package org.aspectj.tools.ajc;
12
12
13
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.List;
14
16
15
import junit.framework.TestCase;
17
import junit.framework.TestCase;
16
18
17
import org.aspectj.org.eclipse.jdt.core.dom.AST;
19
import org.aspectj.org.eclipse.jdt.core.dom.AST;
18
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
20
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
19
import org.aspectj.org.eclipse.jdt.core.dom.AjAST;
21
import org.aspectj.org.eclipse.jdt.core.dom.AjAST;
22
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
20
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
23
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
24
import org.aspectj.org.eclipse.jdt.internal.core.SourceRange;
21
25
22
public abstract class AjASTTestCase extends TestCase {
26
public abstract class AjASTTestCase extends TestCase {
23
27
Lines 35-57 Link Here
35
		parser.setCompilerOptions(new HashMap());
39
		parser.setCompilerOptions(new HashMap());
36
		CompilationUnit cu = (CompilationUnit) parser.createAST(null);
40
		CompilationUnit cu = (CompilationUnit) parser.createAST(null);
37
		AST ast = cu.getAST();
41
		AST ast = cu.getAST();
38
		assertTrue("the ast should be an instance of AjAST",ast instanceof AjAST);
42
		assertTrue("the ast should be an instance of AjAST",
39
		return (AjAST)ast;
43
				ast instanceof AjAST);
44
		return (AjAST) ast;
40
	}
45
	}
41
46
42
	protected void checkJLS3(String source, int start, int length) {
47
	protected void checkJLS3(String source, ITypePatternTester tester) {
43
		ASTParser parser = ASTParser.newParser(AST.JLS3);
48
		ASTParser parser = ASTParser.newParser(AST.JLS3);
44
		parser.setCompilerOptions(new HashMap());
49
		parser.setCompilerOptions(new HashMap());
45
		parser.setSource(source.toCharArray());
50
		parser.setSource(source.toCharArray());
46
		CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
51
		CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
47
		SourceRangeVisitor visitor = new SourceRangeVisitor();
52
		AjASTVisitor visitor = tester.createVisitor();
48
		cu2.accept(visitor);
53
		cu2.accept(visitor);
49
		int s = visitor.getStart();
54
		tester.testCondition(visitor);
50
		int l = visitor.getLength();
55
	}
51
		assertTrue("Expected start position: "+ start + ", Actual:" + s,
56
52
				start == s);
57
	protected void checkJLS3(String source, int start, int length) {
53
		assertTrue("Expected length: "+ length + ", Actual:" + l,
58
		checkJLS3(source, new SourceRangeTester(start, length));
54
				length == l);
59
	}
60
61
	/**
62
	 * 
63
	 * @param source
64
	 *            to parse and visit
65
	 * @param expectedSourceRanges
66
	 *            of TypePattern nodes encountered while visiting the AST
67
	 */
68
	protected void checkTypePatternSourceRangesJLS3(String source,
69
			int[][] expectedSourceRanges) {
70
		checkJLS3(source,
71
				new TypePatternSourceRangeTester(expectedSourceRanges));
72
	}
73
74
	/**
75
	 * 
76
	 * @param source
77
	 *            to parse and visit
78
	 * @param expectedCategory
79
	 *            expected category of a TypeCategoryTypePattern node
80
	 *            encountered in the AST
81
	 */
82
	protected void checkCategoryTypePatternJLS3(String source,
83
			int expectedCategory, String expectedExpression) {
84
		checkJLS3(source, new TypeCategoryTester(expectedCategory, expectedExpression));
85
	}
86
87
88
	protected List<SourceRange> getSourceRanges(int[][] sourceRanges) {
89
		List<SourceRange> convertedRanges = new ArrayList<SourceRange>();
90
91
		for (int i = 0; i < sourceRanges.length; i++) {
92
			convertedRanges.add(new SourceRange(sourceRanges[i][0],
93
					sourceRanges[i][1]));
94
		}
95
		return convertedRanges;
96
	}
97
98
	/*
99
	 * 
100
	 * 
101
	 * Testing Classes and Interfaces
102
	 */
103
104
	/**
105
	 * Tests the results of a visitor when walking the AST
106
	 * 
107
	 */
108
	interface ITypePatternTester {
109
110
		/**
111
		 * 
112
		 * @return visitor to walk the AST. Must not be null.
113
		 */
114
		public AjASTVisitor createVisitor();
115
116
		/**
117
		 * Tests a condition after the visitor has visited the AST. This means
118
		 * the visitor should contain the results of the visitation.
119
		 * 
120
		 * @return true if test condition passed. False otherwise
121
		 */
122
		public void testCondition(AjASTVisitor visitor);
123
	}
124
125
	/**
126
	 * Tests whether a particular type category type pattern (InnerType,
127
	 * InterfaceType, ClassType, etc..) is encountered when visiting nodes in an
128
	 * AST.
129
	 * 
130
	 */
131
	class TypeCategoryTester implements ITypePatternTester {
132
133
		private int expectedCategory;
134
		private String expectedExpression;
135
136
		public TypeCategoryTester(int expectedCategory,
137
				String expectedExpression) {
138
			this.expectedCategory = expectedCategory;
139
			this.expectedExpression = expectedExpression;
140
		}
141
142
		public AjASTVisitor createVisitor() {
143
			return new TypeCategoryTypeVisitor();
144
		}
145
146
		public void testCondition(AjASTVisitor visitor) {
147
			TypeCategoryTypeVisitor tcVisitor = (TypeCategoryTypeVisitor) visitor;
148
			assertTrue("Expected type category: " + expectedCategory
149
					+ ". Actual type category: "
150
					+ tcVisitor.getTypeCategoryNode().getTypeCategory(),
151
					expectedCategory == tcVisitor.getTypeCategoryNode()
152
							.getTypeCategory());
153
			assertTrue("Expected type category expression: "
154
					+ expectedExpression
155
					+ ". Actual type category expression: "
156
					+ tcVisitor.getTypeCategoryNode()
157
							.getTypePatternExpression(),
158
					expectedExpression.equals(tcVisitor.getTypeCategoryNode()
159
							.getTypePatternExpression()));
160
		}
161
	}
162
163
	/**
164
	 * Tests the starting location and source length of each TypePattern node
165
	 * encountered while walking the AST.
166
	 * 
167
	 */
168
	class TypePatternSourceRangeTester implements ITypePatternTester {
169
170
		private int[][] expectedRawSourceRanges;
171
172
		public TypePatternSourceRangeTester(int[][] expectedRawSourceRanges) {
173
			this.expectedRawSourceRanges = expectedRawSourceRanges;
174
		}
175
176
		public AjASTVisitor createVisitor() {
177
			return new TypePatternSourceRangeVisitor();
178
		}
179
180
		public void testCondition(AjASTVisitor visitor) {
181
			TypePatternSourceRangeVisitor sourceRangeVisitor = (TypePatternSourceRangeVisitor) visitor;
182
183
			List<SourceRange> actualRanges = sourceRangeVisitor
184
					.getVisitedSourceRanges();
185
			List<SourceRange> expectedRanges = getSourceRanges(expectedRawSourceRanges);
186
187
			assertTrue("Expected " + expectedRanges.size()
188
					+ " number of source range entries. Actual: "
189
					+ actualRanges.size(),
190
					expectedRanges.size() == actualRanges.size());
191
192
			for (int i = 0; i < actualRanges.size(); i++) {
193
				SourceRange expected = expectedRanges.get(i);
194
				SourceRange actual = actualRanges.get(i);
195
				assertTrue(
196
						"Expected source range: " + expected.toString()
197
								+ " does not match actual source range: "
198
								+ actual.toString(), expected.equals(actual));
199
			}
200
201
		}
202
	}
203
204
	/**
205
	 * Tests whether a particular AST node starts at a given expected location
206
	 * and has an expected length
207
	 * 
208
	 */
209
	class SourceRangeTester implements ITypePatternTester {
210
211
		private int expectedStart;
212
		private int expectedLength;
213
214
		public SourceRangeTester(int expectedStart, int expectedLength) {
215
			this.expectedLength = expectedLength;
216
			this.expectedStart = expectedStart;
217
		}
218
219
		public AjASTVisitor createVisitor() {
220
			return new SourceRangeVisitor();
221
		}
222
223
		public void testCondition(AjASTVisitor visitor) {
224
225
			int s = ((SourceRangeVisitor) visitor).getStart();
226
			int l = ((SourceRangeVisitor) visitor).getLength();
227
			assertTrue("Expected start position: " + expectedStart
228
					+ ", Actual:" + s, expectedStart == s);
229
			assertTrue("Expected length: " + expectedLength + ", Actual:" + l,
230
					expectedLength == l);
231
232
		}
233
55
	}
234
	}
56
235
57
}
236
}
(-)testsrc/org/aspectj/tools/ajc/AjNaiveASTFlattenerTest.java (-1 / +57 lines)
Lines 1-5 Link Here
1
/********************************************************************
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
2
 * Copyright (c) 2006, 2010 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
5
 * which accompanies this distribution and is available at 
Lines 67-72 Link Here
67
				"public aspect A {\n  declare parents: X extends Y;\n}\n");
67
				"public aspect A {\n  declare parents: X extends Y;\n}\n");
68
	}
68
	}
69
	
69
	
70
	
71
	/*
72
	 * 
73
	 * 
74
	 * START: Test TypePattern nodes introduced in Bugzilla 329268.
75
	 * 
76
	 * 
77
	 */
78
	
79
	public void testDeclareParentsDeclarationAny() throws Exception {
80
		check("public aspect A { declare parents: * extends Y; }",
81
				"public aspect A {\n  declare parents: * extends Y;\n}\n");
82
	}
83
	
84
	public void testDeclareParentsAndDeclaration() throws Exception {
85
		check("public aspect A { declare parents: W && X && Y extends Z; }",
86
				"public aspect A {\n  declare parents: W && X && Y extends Z;\n}\n");
87
	}
88
	
89
	public void testDeclareParentsOrDeclaration() throws Exception {
90
		check("public aspect A { declare parents: W || X || Y extends Z; }",
91
				"public aspect A {\n  declare parents: W || X || Y extends Z;\n}\n");
92
	}
93
	
94
	public void testDeclareParentsNot() throws Exception {
95
		check("public aspect A { declare parents: W && !X extends Z; }",
96
				"public aspect A {\n  declare parents: W && !X extends Z;\n}\n");
97
	}
98
	
99
	public void testDeclareParentsTypeCategory() throws Exception {
100
		check("public aspect A { declare parents: B && is(AnonymousType) extends Z; }",
101
		"public aspect A {\n  declare parents: B && is(AnonymousType) extends Z;\n}\n");
102
		
103
	}
104
	
105
	public void testDeclareParentsTypeCategoryNot() throws Exception {
106
		check("public aspect A { declare parents: B && !is(InnerType) extends Z; }",
107
		"public aspect A {\n  declare parents: B && !is(InnerType) extends Z;\n}\n");
108
	}
109
110
	
111
	// TODO: commented until hasmethod is supported in AspectJ
112
//	public void testDeclareParentsHasMember() {
113
//		check("public aspect A { declare parents : A && hasmethod(void foo*(..)) extends D; }",
114
//		"public aspect A {\n  declare parents : A && hasmethod(void foo*(..)) extends D;\n}\n");
115
//	}
116
117
	
118
	/*
119
	 * 
120
	 * 
121
	 * END: Test TypePattern nodes introduced in Bugzilla 329268.
122
	 * 
123
	 * 
124
	 */
125
	
70
	public void testDeclareWarning() throws Exception {
126
	public void testDeclareWarning() throws Exception {
71
		check("public aspect A { declare warning: call(* *.*(..)) : \"warning!\"; }",
127
		check("public aspect A { declare warning: call(* *.*(..)) : \"warning!\"; }",
72
				"public aspect A {\n  declare warning: call(* *.*(..)) : \"warning!\" ;\n}\n");
128
				"public aspect A {\n  declare warning: call(* *.*(..)) : \"warning!\" ;\n}\n");
(-)src/org/aspectj/weaver/patterns/AnyTypePattern.java (+112 lines)
Added Link Here
1
/* *******************************************************************
2
 * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC) and others.
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Eclipse Public License v1.0 
6
 * which accompanies this distribution and is available at 
7
 * http://www.eclipse.org/legal/epl-v10.html 
8
 *  
9
 * Contributors: 
10
 *     PARC     initial implementation 
11
 * ******************************************************************/
12
package org.aspectj.weaver.patterns;
13
14
import java.io.IOException;
15
import java.util.Map;
16
17
import org.aspectj.util.FuzzyBoolean;
18
import org.aspectj.weaver.CompressingDataOutputStream;
19
import org.aspectj.weaver.ResolvedType;
20
import org.aspectj.weaver.World;
21
22
public class AnyTypePattern extends TypePattern {
23
24
	/**
25
	 * Constructor for EllipsisTypePattern.
26
	 * 
27
	 * @param includeSubtypes
28
	 */
29
	public AnyTypePattern() {
30
		super(false, false, new TypePatternList());
31
	}
32
33
	/*
34
	 * (non-Javadoc)
35
	 * 
36
	 * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
37
	 */
38
	@Override
39
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
40
		return true;
41
	}
42
43
	/**
44
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
45
	 */
46
	@Override
47
	protected boolean matchesExactly(ResolvedType type) {
48
		return true;
49
	}
50
51
	@Override
52
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
53
		return true;
54
	}
55
56
	/**
57
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
58
	 */
59
	@Override
60
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
61
		return FuzzyBoolean.YES;
62
	}
63
64
	@Override
65
	public void write(CompressingDataOutputStream s) throws IOException {
66
		s.writeByte(ANY_KEY);
67
	}
68
69
	/**
70
	 * @see org.aspectj.weaver.patterns.TypePattern#matches(IType, MatchKind)
71
	 */
72
	// public FuzzyBoolean matches(IType type, MatchKind kind) {
73
	// return FuzzyBoolean.YES;
74
	// }
75
	/**
76
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesSubtypes(IType)
77
	 */
78
	@Override
79
	protected boolean matchesSubtypes(ResolvedType type) {
80
		return true;
81
	}
82
83
	@Override
84
	public boolean isStar() {
85
		return true;
86
	}
87
88
	@Override
89
	public String toString() {
90
		return "*";
91
	}
92
93
	@Override
94
	public boolean equals(Object obj) {
95
		return (obj instanceof AnyTypePattern);
96
	}
97
98
	@Override
99
	public int hashCode() {
100
		return 37;
101
	}
102
103
	@Override
104
	public Object accept(PatternNodeVisitor visitor, Object data) {
105
		return visitor.visit(this, data);
106
	}
107
108
	@Override
109
	public TypePattern parameterizeWith(Map arg0, World w) {
110
		return this;
111
	}
112
}
(-)src/org/aspectj/weaver/patterns/AnyWithAnnotationTypePattern.java (+142 lines)
Added Link Here
1
/* *******************************************************************
2
 * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC) and others.
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Eclipse Public License v1.0 
6
 * which accompanies this distribution and is available at 
7
 * http://www.eclipse.org/legal/epl-v10.html 
8
 *  
9
 * Contributors: 
10
 *     PARC     initial implementation 
11
 * ******************************************************************/
12
package org.aspectj.weaver.patterns;
13
14
import java.io.IOException;
15
import java.lang.reflect.Modifier;
16
import java.util.Map;
17
18
import org.aspectj.bridge.MessageUtil;
19
import org.aspectj.util.FuzzyBoolean;
20
import org.aspectj.weaver.CompressingDataOutputStream;
21
import org.aspectj.weaver.ISourceContext;
22
import org.aspectj.weaver.ResolvedType;
23
import org.aspectj.weaver.VersionedDataInputStream;
24
import org.aspectj.weaver.WeaverMessages;
25
import org.aspectj.weaver.World;
26
27
28
/**
29
 * This type represents a type pattern of '*' but with an annotation specified, e.g. '@Color *'
30
 */
31
public class AnyWithAnnotationTypePattern extends TypePattern {
32
33
	public AnyWithAnnotationTypePattern(AnnotationTypePattern atp) {
34
		super(false, false);
35
		annotationPattern = atp;
36
	}
37
38
	@Override
39
	public Object accept(PatternNodeVisitor visitor, Object data) {
40
		return visitor.visit(this, data);
41
	}
42
43
	@Override
44
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
45
		return true;
46
	}
47
48
	@Override
49
	protected boolean matchesExactly(ResolvedType type) {
50
		annotationPattern.resolve(type.getWorld());
51
		boolean b = false;
52
		if (type.temporaryAnnotationTypes != null) {
53
			b = annotationPattern.matches(type, type.temporaryAnnotationTypes).alwaysTrue();
54
		} else {
55
			b = annotationPattern.matches(type).alwaysTrue();
56
		}
57
		return b;
58
	}
59
60
	@Override
61
	public TypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding, boolean requireExactType) {
62
		if (requireExactType) {
63
			scope.getWorld().getMessageHandler().handleMessage(
64
					MessageUtil.error(WeaverMessages.format(WeaverMessages.WILDCARD_NOT_ALLOWED), getSourceLocation()));
65
			return NO;
66
		}
67
		return super.resolveBindings(scope, bindings, allowBinding, requireExactType);
68
	}
69
70
	@Override
71
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
72
		annotationPattern.resolve(type.getWorld());
73
		return annotationPattern.matches(annotatedType).alwaysTrue();
74
	}
75
76
	@Override
77
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
78
		if (Modifier.isFinal(type.getModifiers())) {
79
			return FuzzyBoolean.fromBoolean(matchesExactly(type));
80
		}
81
		return FuzzyBoolean.MAYBE;
82
	}
83
84
	@Override
85
	public TypePattern parameterizeWith(Map typeVariableMap, World w) {
86
		AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(this.annotationPattern.parameterizeWith(
87
				typeVariableMap, w));
88
		ret.copyLocationFrom(this);
89
		return ret;
90
	}
91
92
	@Override
93
	public void write(CompressingDataOutputStream s) throws IOException {
94
		s.writeByte(TypePattern.ANY_WITH_ANNO);
95
		annotationPattern.write(s);
96
		writeLocation(s);
97
	}
98
99
	public static TypePattern read(VersionedDataInputStream s, ISourceContext c) throws IOException {
100
		AnnotationTypePattern annPatt = AnnotationTypePattern.read(s, c);
101
		AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(annPatt);
102
		ret.readLocation(c, s);
103
		return ret;
104
	}
105
106
	// public FuzzyBoolean matches(IType type, MatchKind kind) {
107
	// return FuzzyBoolean.YES;
108
	// }
109
110
	@Override
111
	protected boolean matchesSubtypes(ResolvedType type) {
112
		return true;
113
	}
114
115
	@Override
116
	public boolean isStar() {
117
		return false;
118
	}
119
120
	@Override
121
	public String toString() {
122
		return "(" + annotationPattern + " *)";
123
	}
124
	
125
	public AnnotationTypePattern getAnnotationTypePattern() {
126
		return annotationPattern;
127
	}
128
129
	@Override
130
	public boolean equals(Object obj) {
131
		if (!(obj instanceof AnyWithAnnotationTypePattern)) {
132
			return false;
133
		}
134
		AnyWithAnnotationTypePattern awatp = (AnyWithAnnotationTypePattern) obj;
135
		return (annotationPattern.equals(awatp.annotationPattern));
136
	}
137
138
	@Override
139
	public int hashCode() {
140
		return annotationPattern.hashCode();
141
	}
142
}
(-)src/org/aspectj/weaver/patterns/BindingTypePattern.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/* *******************************************************************
1
/* *******************************************************************
2
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
2
 * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC).
3
 * All rights reserved. 
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Eclipse Public License v1.0 
5
 * under the terms of the Eclipse Public License v1.0 
Lines 25-30 Link Here
25
25
26
public class BindingTypePattern extends ExactTypePattern implements BindingPattern {
26
public class BindingTypePattern extends ExactTypePattern implements BindingPattern {
27
	private int formalIndex;
27
	private int formalIndex;
28
	private String bindingName;
28
29
29
	public BindingTypePattern(UnresolvedType type, int index, boolean isVarArgs) {
30
	public BindingTypePattern(UnresolvedType type, int index, boolean isVarArgs) {
30
		super(type, false, isVarArgs);
31
		super(type, false, isVarArgs);
Lines 33-43 Link Here
33
34
34
	public BindingTypePattern(FormalBinding binding, boolean isVarArgs) {
35
	public BindingTypePattern(FormalBinding binding, boolean isVarArgs) {
35
		this(binding.getType(), binding.getIndex(), isVarArgs);
36
		this(binding.getType(), binding.getIndex(), isVarArgs);
37
		this.bindingName = binding.getName();
36
	}
38
	}
37
39
38
	public int getFormalIndex() {
40
	public int getFormalIndex() {
39
		return formalIndex;
41
		return formalIndex;
40
	}
42
	}
43
	
44
	public String getBindingName() {
45
		return bindingName;
46
	}
41
47
42
	public boolean equals(Object other) {
48
	public boolean equals(Object other) {
43
		if (!(other instanceof BindingTypePattern)) {
49
		if (!(other instanceof BindingTypePattern)) {
(-)src/org/aspectj/weaver/patterns/EllipsisTypePattern.java (+109 lines)
Added Link Here
1
/* *******************************************************************
2
 * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC) and others.
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Eclipse Public License v1.0 
6
 * which accompanies this distribution and is available at 
7
 * http://www.eclipse.org/legal/epl-v10.html 
8
 *  
9
 * Contributors: 
10
 *     PARC     initial implementation 
11
 * ******************************************************************/
12
package org.aspectj.weaver.patterns;
13
14
import java.io.IOException;
15
import java.util.Map;
16
17
import org.aspectj.util.FuzzyBoolean;
18
import org.aspectj.weaver.CompressingDataOutputStream;
19
import org.aspectj.weaver.ResolvedType;
20
import org.aspectj.weaver.World;
21
22
public class EllipsisTypePattern extends TypePattern {
23
24
	/**
25
	 * Constructor for EllipsisTypePattern.
26
	 * 
27
	 * @param includeSubtypes
28
	 */
29
	public EllipsisTypePattern() {
30
		super(false, false, new TypePatternList());
31
	}
32
33
	/*
34
	 * (non-Javadoc)
35
	 * 
36
	 * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
37
	 */
38
	@Override
39
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
40
		return true;
41
	}
42
43
	/**
44
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
45
	 */
46
	@Override
47
	protected boolean matchesExactly(ResolvedType type) {
48
		return false;
49
	}
50
51
	@Override
52
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
53
		return false;
54
	}
55
56
	/**
57
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
58
	 */
59
	@Override
60
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
61
		return FuzzyBoolean.NO;
62
	}
63
64
	@Override
65
	public void write(CompressingDataOutputStream s) throws IOException {
66
		s.writeByte(ELLIPSIS_KEY);
67
	}
68
69
	@Override
70
	public boolean isEllipsis() {
71
		return true;
72
	}
73
74
	@Override
75
	public String toString() {
76
		return "..";
77
	}
78
79
	/*
80
	 * (non-Javadoc)
81
	 * 
82
	 * @see java.lang.Object#equals(java.lang.Object)
83
	 */
84
	@Override
85
	public boolean equals(Object obj) {
86
		return (obj instanceof EllipsisTypePattern);
87
	}
88
89
	/*
90
	 * (non-Javadoc)
91
	 * 
92
	 * @see java.lang.Object#hashCode()
93
	 */
94
	@Override
95
	public int hashCode() {
96
		return 17 * 37;
97
	}
98
99
	@Override
100
	public Object accept(PatternNodeVisitor visitor, Object data) {
101
		return visitor.visit(this, data);
102
	}
103
104
	@Override
105
	public TypePattern parameterizeWith(Map typeVariableMap, World w) {
106
		return this;
107
	}
108
109
}
(-)src/org/aspectj/weaver/patterns/HasMemberTypePattern.java (+4 lines)
Lines 49-54 Link Here
49
			return hasMethod(type);
49
			return hasMethod(type);
50
		}
50
		}
51
	}
51
	}
52
	
53
	public ISignaturePattern getSignaturePattern() {
54
		return signaturePattern;
55
	}
52
56
53
	private final static String declareAtPrefix = "ajc$declare_at";
57
	private final static String declareAtPrefix = "ajc$declare_at";
54
58
(-)src/org/aspectj/weaver/patterns/NoTypePattern.java (+106 lines)
Added Link Here
1
package org.aspectj.weaver.patterns;
2
3
import java.io.IOException;
4
import java.util.Map;
5
6
import org.aspectj.util.FuzzyBoolean;
7
import org.aspectj.weaver.CompressingDataOutputStream;
8
import org.aspectj.weaver.ResolvedType;
9
import org.aspectj.weaver.World;
10
11
public class NoTypePattern extends TypePattern {
12
13
	public NoTypePattern() {
14
		super(false, false, new TypePatternList());
15
	}
16
17
	/*
18
	 * (non-Javadoc)
19
	 * 
20
	 * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
21
	 */
22
	@Override
23
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
24
		return false;
25
	}
26
27
	/**
28
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
29
	 */
30
	@Override
31
	protected boolean matchesExactly(ResolvedType type) {
32
		return false;
33
	}
34
35
	@Override
36
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
37
		return false;
38
	}
39
40
	/**
41
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
42
	 */
43
	@Override
44
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
45
		return FuzzyBoolean.NO;
46
	}
47
48
	@Override
49
	public void write(CompressingDataOutputStream s) throws IOException {
50
		s.writeByte(NO_KEY);
51
	}
52
53
	/**
54
	 * @see org.aspectj.weaver.patterns.TypePattern#matches(IType, MatchKind)
55
	 */
56
	// public FuzzyBoolean matches(IType type, MatchKind kind) {
57
	// return FuzzyBoolean.YES;
58
	// }
59
	/**
60
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesSubtypes(IType)
61
	 */
62
	@Override
63
	protected boolean matchesSubtypes(ResolvedType type) {
64
		return false;
65
	}
66
67
	@Override
68
	public boolean isStar() {
69
		return false;
70
	}
71
72
	@Override
73
	public String toString() {
74
		return "<nothing>";
75
	}// FIXME AV - bad! toString() cannot be parsed back (not idempotent)
76
77
	/*
78
	 * (non-Javadoc)
79
	 * 
80
	 * @see java.lang.Object#equals(java.lang.Object)
81
	 */
82
	@Override
83
	public boolean equals(Object obj) {
84
		return (obj instanceof NoTypePattern);
85
	}
86
87
	/*
88
	 * (non-Javadoc)
89
	 * 
90
	 * @see java.lang.Object#hashCode()
91
	 */
92
	@Override
93
	public int hashCode() {
94
		return 17 * 37 * 37;
95
	}
96
97
	@Override
98
	public Object accept(PatternNodeVisitor visitor, Object data) {
99
		return visitor.visit(this, data);
100
	}
101
102
	@Override
103
	public TypePattern parameterizeWith(Map arg0, World w) {
104
		return this;
105
	}
106
}
(-)src/org/aspectj/weaver/patterns/TypeCategoryTypePattern.java (+4 lines)
Lines 44-49 Link Here
44
		super(false);
44
		super(false);
45
		this.category = category;
45
		this.category = category;
46
	}
46
	}
47
	
48
	public int getTypeCategory() {
49
		return category;
50
	}
47
51
48
	@Override
52
	@Override
49
	protected boolean matchesExactly(ResolvedType type) {
53
	protected boolean matchesExactly(ResolvedType type) {
(-)src/org/aspectj/weaver/patterns/TypePattern.java (-390 / +1 lines)
Lines 1-5 Link Here
1
/* *******************************************************************
1
/* *******************************************************************
2
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
2
 * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC).
3
 * All rights reserved. 
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Eclipse Public License v1.0 
5
 * under the terms of the Eclipse Public License v1.0 
Lines 13-26 Link Here
13
package org.aspectj.weaver.patterns;
13
package org.aspectj.weaver.patterns;
14
14
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.lang.reflect.Modifier;
17
import java.util.Iterator;
16
import java.util.Iterator;
18
import java.util.Map;
17
import java.util.Map;
19
18
20
import org.aspectj.bridge.MessageUtil;
19
import org.aspectj.bridge.MessageUtil;
21
import org.aspectj.util.FuzzyBoolean;
20
import org.aspectj.util.FuzzyBoolean;
22
import org.aspectj.weaver.BCException;
21
import org.aspectj.weaver.BCException;
23
import org.aspectj.weaver.CompressingDataOutputStream;
24
import org.aspectj.weaver.ISourceContext;
22
import org.aspectj.weaver.ISourceContext;
25
import org.aspectj.weaver.IntMap;
23
import org.aspectj.weaver.IntMap;
26
import org.aspectj.weaver.ResolvedType;
24
import org.aspectj.weaver.ResolvedType;
Lines 357-748 Link Here
357
355
358
}
356
}
359
357
360
class EllipsisTypePattern extends TypePattern {
361
358
362
	/**
363
	 * Constructor for EllipsisTypePattern.
364
	 * 
365
	 * @param includeSubtypes
366
	 */
367
	public EllipsisTypePattern() {
368
		super(false, false, new TypePatternList());
369
	}
370
371
	/*
372
	 * (non-Javadoc)
373
	 * 
374
	 * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
375
	 */
376
	@Override
377
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
378
		return true;
379
	}
380
381
	/**
382
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
383
	 */
384
	@Override
385
	protected boolean matchesExactly(ResolvedType type) {
386
		return false;
387
	}
388
389
	@Override
390
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
391
		return false;
392
	}
393
394
	/**
395
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
396
	 */
397
	@Override
398
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
399
		return FuzzyBoolean.NO;
400
	}
401
402
	@Override
403
	public void write(CompressingDataOutputStream s) throws IOException {
404
		s.writeByte(ELLIPSIS_KEY);
405
	}
406
407
	@Override
408
	public boolean isEllipsis() {
409
		return true;
410
	}
411
412
	@Override
413
	public String toString() {
414
		return "..";
415
	}
416
417
	/*
418
	 * (non-Javadoc)
419
	 * 
420
	 * @see java.lang.Object#equals(java.lang.Object)
421
	 */
422
	@Override
423
	public boolean equals(Object obj) {
424
		return (obj instanceof EllipsisTypePattern);
425
	}
426
427
	/*
428
	 * (non-Javadoc)
429
	 * 
430
	 * @see java.lang.Object#hashCode()
431
	 */
432
	@Override
433
	public int hashCode() {
434
		return 17 * 37;
435
	}
436
437
	@Override
438
	public Object accept(PatternNodeVisitor visitor, Object data) {
439
		return visitor.visit(this, data);
440
	}
441
442
	@Override
443
	public TypePattern parameterizeWith(Map typeVariableMap, World w) {
444
		return this;
445
	}
446
447
}
448
449
class AnyTypePattern extends TypePattern {
450
451
	/**
452
	 * Constructor for EllipsisTypePattern.
453
	 * 
454
	 * @param includeSubtypes
455
	 */
456
	public AnyTypePattern() {
457
		super(false, false, new TypePatternList());
458
	}
459
460
	/*
461
	 * (non-Javadoc)
462
	 * 
463
	 * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
464
	 */
465
	@Override
466
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
467
		return true;
468
	}
469
470
	/**
471
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
472
	 */
473
	@Override
474
	protected boolean matchesExactly(ResolvedType type) {
475
		return true;
476
	}
477
478
	@Override
479
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
480
		return true;
481
	}
482
483
	/**
484
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
485
	 */
486
	@Override
487
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
488
		return FuzzyBoolean.YES;
489
	}
490
491
	@Override
492
	public void write(CompressingDataOutputStream s) throws IOException {
493
		s.writeByte(ANY_KEY);
494
	}
495
496
	/**
497
	 * @see org.aspectj.weaver.patterns.TypePattern#matches(IType, MatchKind)
498
	 */
499
	// public FuzzyBoolean matches(IType type, MatchKind kind) {
500
	// return FuzzyBoolean.YES;
501
	// }
502
	/**
503
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesSubtypes(IType)
504
	 */
505
	@Override
506
	protected boolean matchesSubtypes(ResolvedType type) {
507
		return true;
508
	}
509
510
	@Override
511
	public boolean isStar() {
512
		return true;
513
	}
514
515
	@Override
516
	public String toString() {
517
		return "*";
518
	}
519
520
	@Override
521
	public boolean equals(Object obj) {
522
		return (obj instanceof AnyTypePattern);
523
	}
524
525
	@Override
526
	public int hashCode() {
527
		return 37;
528
	}
529
530
	@Override
531
	public Object accept(PatternNodeVisitor visitor, Object data) {
532
		return visitor.visit(this, data);
533
	}
534
535
	@Override
536
	public TypePattern parameterizeWith(Map arg0, World w) {
537
		return this;
538
	}
539
}
540
541
/**
542
 * This type represents a type pattern of '*' but with an annotation specified, e.g. '@Color *'
543
 */
544
class AnyWithAnnotationTypePattern extends TypePattern {
545
546
	public AnyWithAnnotationTypePattern(AnnotationTypePattern atp) {
547
		super(false, false);
548
		annotationPattern = atp;
549
	}
550
551
	@Override
552
	public Object accept(PatternNodeVisitor visitor, Object data) {
553
		return visitor.visit(this, data);
554
	}
555
556
	@Override
557
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
558
		return true;
559
	}
560
561
	@Override
562
	protected boolean matchesExactly(ResolvedType type) {
563
		annotationPattern.resolve(type.getWorld());
564
		boolean b = false;
565
		if (type.temporaryAnnotationTypes != null) {
566
			b = annotationPattern.matches(type, type.temporaryAnnotationTypes).alwaysTrue();
567
		} else {
568
			b = annotationPattern.matches(type).alwaysTrue();
569
		}
570
		return b;
571
	}
572
573
	@Override
574
	public TypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding, boolean requireExactType) {
575
		if (requireExactType) {
576
			scope.getWorld().getMessageHandler().handleMessage(
577
					MessageUtil.error(WeaverMessages.format(WeaverMessages.WILDCARD_NOT_ALLOWED), getSourceLocation()));
578
			return NO;
579
		}
580
		return super.resolveBindings(scope, bindings, allowBinding, requireExactType);
581
	}
582
583
	@Override
584
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
585
		annotationPattern.resolve(type.getWorld());
586
		return annotationPattern.matches(annotatedType).alwaysTrue();
587
	}
588
589
	@Override
590
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
591
		if (Modifier.isFinal(type.getModifiers())) {
592
			return FuzzyBoolean.fromBoolean(matchesExactly(type));
593
		}
594
		return FuzzyBoolean.MAYBE;
595
	}
596
597
	@Override
598
	public TypePattern parameterizeWith(Map typeVariableMap, World w) {
599
		AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(this.annotationPattern.parameterizeWith(
600
				typeVariableMap, w));
601
		ret.copyLocationFrom(this);
602
		return ret;
603
	}
604
605
	@Override
606
	public void write(CompressingDataOutputStream s) throws IOException {
607
		s.writeByte(TypePattern.ANY_WITH_ANNO);
608
		annotationPattern.write(s);
609
		writeLocation(s);
610
	}
611
359
612
	public static TypePattern read(VersionedDataInputStream s, ISourceContext c) throws IOException {
613
		AnnotationTypePattern annPatt = AnnotationTypePattern.read(s, c);
614
		AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(annPatt);
615
		ret.readLocation(c, s);
616
		return ret;
617
	}
618
619
	// public FuzzyBoolean matches(IType type, MatchKind kind) {
620
	// return FuzzyBoolean.YES;
621
	// }
622
623
	@Override
624
	protected boolean matchesSubtypes(ResolvedType type) {
625
		return true;
626
	}
627
628
	@Override
629
	public boolean isStar() {
630
		return false;
631
	}
632
633
	@Override
634
	public String toString() {
635
		return "(" + annotationPattern + " *)";
636
	}
637
638
	@Override
639
	public boolean equals(Object obj) {
640
		if (!(obj instanceof AnyWithAnnotationTypePattern)) {
641
			return false;
642
		}
643
		AnyWithAnnotationTypePattern awatp = (AnyWithAnnotationTypePattern) obj;
644
		return (annotationPattern.equals(awatp.annotationPattern));
645
	}
646
647
	@Override
648
	public int hashCode() {
649
		return annotationPattern.hashCode();
650
	}
651
}
652
653
class NoTypePattern extends TypePattern {
654
655
	public NoTypePattern() {
656
		super(false, false, new TypePatternList());
657
	}
658
659
	/*
660
	 * (non-Javadoc)
661
	 * 
662
	 * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
663
	 */
664
	@Override
665
	protected boolean couldEverMatchSameTypesAs(TypePattern other) {
666
		return false;
667
	}
668
669
	/**
670
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
671
	 */
672
	@Override
673
	protected boolean matchesExactly(ResolvedType type) {
674
		return false;
675
	}
676
677
	@Override
678
	protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
679
		return false;
680
	}
681
682
	/**
683
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
684
	 */
685
	@Override
686
	public FuzzyBoolean matchesInstanceof(ResolvedType type) {
687
		return FuzzyBoolean.NO;
688
	}
689
690
	@Override
691
	public void write(CompressingDataOutputStream s) throws IOException {
692
		s.writeByte(NO_KEY);
693
	}
694
695
	/**
696
	 * @see org.aspectj.weaver.patterns.TypePattern#matches(IType, MatchKind)
697
	 */
698
	// public FuzzyBoolean matches(IType type, MatchKind kind) {
699
	// return FuzzyBoolean.YES;
700
	// }
701
	/**
702
	 * @see org.aspectj.weaver.patterns.TypePattern#matchesSubtypes(IType)
703
	 */
704
	@Override
705
	protected boolean matchesSubtypes(ResolvedType type) {
706
		return false;
707
	}
708
709
	@Override
710
	public boolean isStar() {
711
		return false;
712
	}
713
714
	@Override
715
	public String toString() {
716
		return "<nothing>";
717
	}// FIXME AV - bad! toString() cannot be parsed back (not idempotent)
718
719
	/*
720
	 * (non-Javadoc)
721
	 * 
722
	 * @see java.lang.Object#equals(java.lang.Object)
723
	 */
724
	@Override
725
	public boolean equals(Object obj) {
726
		return (obj instanceof NoTypePattern);
727
	}
728
729
	/*
730
	 * (non-Javadoc)
731
	 * 
732
	 * @see java.lang.Object#hashCode()
733
	 */
734
	@Override
735
	public int hashCode() {
736
		return 17 * 37 * 37;
737
	}
738
739
	@Override
740
	public Object accept(PatternNodeVisitor visitor, Object data) {
741
		return visitor.visit(this, data);
742
	}
743
744
	@Override
745
	public TypePattern parameterizeWith(Map arg0, World w) {
746
		return this;
747
	}
748
}

Return to bug 329268