aboutsummaryrefslogtreecommitdiffstats
path: root/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareAnnotationImpl.java
blob: bcc91b987735c8fadda1f1db564e27f17139968e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* *******************************************************************
 * Copyright (c) 2005 Contributors.
 * All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *   Adrian Colyer			Initial implementation
 * ******************************************************************/
package org.aspectj.internal.lang.reflect;

import java.lang.annotation.Annotation;

import org.aspectj.lang.reflect.AjType;
import org.aspectj.lang.reflect.DeclareAnnotation;
import org.aspectj.lang.reflect.SignaturePattern;
import org.aspectj.lang.reflect.TypePattern;

/**
 * @author colyer
 *
 */
public class DeclareAnnotationImpl implements DeclareAnnotation {

	private Annotation theAnnotation;
	private String annText;
	private AjType<?> declaringType;
	private DeclareAnnotation.Kind kind;
	private TypePattern typePattern;
	private SignaturePattern signaturePattern;
	
	public DeclareAnnotationImpl(AjType<?> declaring, String kindString, String pattern, Annotation ann, String annText) {
		this.declaringType = declaring;
		if (kindString.equals("at_type")) this.kind = DeclareAnnotation.Kind.Type;
		else if (kindString.equals("at_field")) this.kind = DeclareAnnotation.Kind.Field;
		else if (kindString.equals("at_method")) this.kind = DeclareAnnotation.Kind.Method;
		else if (kindString.equals("at_constructor")) this.kind = DeclareAnnotation.Kind.Constructor;
		else throw new IllegalStateException("Unknown declare annotation kind: " + kindString);
		if (kind == DeclareAnnotation.Kind.Type) {
			this.typePattern = new TypePatternImpl(pattern);
		} else {
			this.signaturePattern = new SignaturePatternImpl(pattern);
		}
		this.theAnnotation = ann;
		this.annText = annText;
	}

	/* (non-Javadoc)
	 * @see org.aspectj.lang.reflect.DeclareAnnotation#getDeclaringType()
	 */
	public AjType<?> getDeclaringType() {
		return this.declaringType;
	}

	/* (non-Javadoc)
	 * @see org.aspectj.lang.reflect.DeclareAnnotation#getKind()
	 */
	public Kind getKind() {
		return this.kind;
	}

	/* (non-Javadoc)
	 * @see org.aspectj.lang.reflect.DeclareAnnotation#getSignaturePattern()
	 */
	public SignaturePattern getSignaturePattern() {
		return this.signaturePattern;
	}

	/* (non-Javadoc)
	 * @see org.aspectj.lang.reflect.DeclareAnnotation#getTypePattern()
	 */
	public TypePattern getTypePattern() {
		return this.typePattern;
	}

	/* (non-Javadoc)
	 * @see org.aspectj.lang.reflect.DeclareAnnotation#getAnnotation()
	 */
	public Annotation getAnnotation() {
		return this.theAnnotation;
	}
	
	public String getAnnotationAsText() {
		return this.annText;
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("declare @");
		switch(getKind()) {
		case Type:
			sb.append("type : ");
			sb.append(getTypePattern().asString());
			break;
		case Method: 
			sb.append("method : "); 
			sb.append(getSignaturePattern().asString());
			break;
		case Field: 
			sb.append("field : "); 
			sb.append(getSignaturePattern().asString());
			break;
		case Constructor: 
			sb.append("constructor : "); 
			sb.append(getSignaturePattern().asString());
			break;
		}
		sb.append(" : ");
		sb.append(getAnnotationAsText());
		return sb.toString();
	}

}