You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeclareAnnotationImpl.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  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://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.internal.lang.reflect;
  13. import java.lang.annotation.Annotation;
  14. import org.aspectj.lang.reflect.AjType;
  15. import org.aspectj.lang.reflect.DeclareAnnotation;
  16. import org.aspectj.lang.reflect.SignaturePattern;
  17. import org.aspectj.lang.reflect.TypePattern;
  18. /**
  19. * @author colyer
  20. *
  21. */
  22. public class DeclareAnnotationImpl implements DeclareAnnotation {
  23. private Annotation theAnnotation;
  24. private String annText;
  25. private AjType<?> declaringType;
  26. private DeclareAnnotation.Kind kind;
  27. private TypePattern typePattern;
  28. private SignaturePattern signaturePattern;
  29. public DeclareAnnotationImpl(AjType<?> declaring, String kindString, String pattern, Annotation ann, String annText) {
  30. this.declaringType = declaring;
  31. if (kindString.equals("at_type")) this.kind = DeclareAnnotation.Kind.Type;
  32. else if (kindString.equals("at_field")) this.kind = DeclareAnnotation.Kind.Field;
  33. else if (kindString.equals("at_method")) this.kind = DeclareAnnotation.Kind.Method;
  34. else if (kindString.equals("at_constructor")) this.kind = DeclareAnnotation.Kind.Constructor;
  35. else throw new IllegalStateException("Unknown declare annotation kind: " + kindString);
  36. if (kind == DeclareAnnotation.Kind.Type) {
  37. this.typePattern = new TypePatternImpl(pattern);
  38. } else {
  39. this.signaturePattern = new SignaturePatternImpl(pattern);
  40. }
  41. this.theAnnotation = ann;
  42. this.annText = annText;
  43. }
  44. public AjType<?> getDeclaringType() {
  45. return this.declaringType;
  46. }
  47. public Kind getKind() {
  48. return this.kind;
  49. }
  50. public SignaturePattern getSignaturePattern() {
  51. return this.signaturePattern;
  52. }
  53. public TypePattern getTypePattern() {
  54. return this.typePattern;
  55. }
  56. public Annotation getAnnotation() {
  57. return this.theAnnotation;
  58. }
  59. public String getAnnotationAsText() {
  60. return this.annText;
  61. }
  62. public String toString() {
  63. StringBuffer sb = new StringBuffer();
  64. sb.append("declare @");
  65. switch(getKind()) {
  66. case Type:
  67. sb.append("type : ");
  68. sb.append(getTypePattern().asString());
  69. break;
  70. case Method:
  71. sb.append("method : ");
  72. sb.append(getSignaturePattern().asString());
  73. break;
  74. case Field:
  75. sb.append("field : ");
  76. sb.append(getSignaturePattern().asString());
  77. break;
  78. case Constructor:
  79. sb.append("constructor : ");
  80. sb.append(getSignaturePattern().asString());
  81. break;
  82. }
  83. sb.append(" : ");
  84. sb.append(getAnnotationAsText());
  85. return sb.toString();
  86. }
  87. }