~ubuntu-branches/ubuntu/wily/aspectj/wily-proposed

« back to all changes in this revision

Viewing changes to org.aspectj/modules/org.aspectj.matcher/src/org/aspectj/weaver/patterns/TypePattern.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.1.5 upstream) (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110315235431-7d8cs3gvs4tnqx7t
Tags: 1.6.11+dfsg-1
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* *******************************************************************
2
 
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 
2
 * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC).
3
3
 * All rights reserved. 
4
4
 * This program and the accompanying materials are made available 
5
5
 * under the terms of the Eclipse Public License v1.0 
8
8
 *  
9
9
 * Contributors: 
10
10
 *     PARC     initial implementation 
 
11
 *     Nieraj Singh
11
12
 * ******************************************************************/
12
13
 
13
14
package org.aspectj.weaver.patterns;
14
15
 
15
16
import java.io.IOException;
16
 
import java.lang.reflect.Modifier;
17
17
import java.util.Iterator;
18
18
import java.util.Map;
19
19
 
20
20
import org.aspectj.bridge.MessageUtil;
21
21
import org.aspectj.util.FuzzyBoolean;
22
22
import org.aspectj.weaver.BCException;
23
 
import org.aspectj.weaver.CompressingDataOutputStream;
24
23
import org.aspectj.weaver.ISourceContext;
25
24
import org.aspectj.weaver.IntMap;
26
25
import org.aspectj.weaver.ResolvedType;
357
356
 
358
357
}
359
358
 
360
 
class EllipsisTypePattern extends TypePattern {
361
 
 
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
 
 
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
 
}
 
359
 
 
360