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 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* (non-Javadoc)
  45. * @see org.aspectj.lang.reflect.DeclareAnnotation#getDeclaringType()
  46. */
  47. public AjType<?> getDeclaringType() {
  48. return this.declaringType;
  49. }
  50. /* (non-Javadoc)
  51. * @see org.aspectj.lang.reflect.DeclareAnnotation#getKind()
  52. */
  53. public Kind getKind() {
  54. return this.kind;
  55. }
  56. /* (non-Javadoc)
  57. * @see org.aspectj.lang.reflect.DeclareAnnotation#getSignaturePattern()
  58. */
  59. public SignaturePattern getSignaturePattern() {
  60. return this.signaturePattern;
  61. }
  62. /* (non-Javadoc)
  63. * @see org.aspectj.lang.reflect.DeclareAnnotation#getTypePattern()
  64. */
  65. public TypePattern getTypePattern() {
  66. return this.typePattern;
  67. }
  68. /* (non-Javadoc)
  69. * @see org.aspectj.lang.reflect.DeclareAnnotation#getAnnotation()
  70. */
  71. public Annotation getAnnotation() {
  72. return this.theAnnotation;
  73. }
  74. public String getAnnotationAsText() {
  75. return this.annText;
  76. }
  77. public String toString() {
  78. StringBuffer sb = new StringBuffer();
  79. sb.append("declare @");
  80. switch(getKind()) {
  81. case Type:
  82. sb.append("type : ");
  83. sb.append(getTypePattern().asString());
  84. break;
  85. case Method:
  86. sb.append("method : ");
  87. sb.append(getSignaturePattern().asString());
  88. break;
  89. case Field:
  90. sb.append("field : ");
  91. sb.append(getSignaturePattern().asString());
  92. break;
  93. case Constructor:
  94. sb.append("constructor : ");
  95. sb.append(getSignaturePattern().asString());
  96. break;
  97. }
  98. sb.append(" : ");
  99. sb.append(getAnnotationAsText());
  100. return sb.toString();
  101. }
  102. }