Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 17eb956055376974e29e6c66f320f5bc1376c95a (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2006, 2008 Oracle. 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://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.core.internal.utility.jdt;

import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;

/**
 * Manipulate an annotation that is embedded as an element within
 * another annotation, e.g.
 * <pre>
 *     &#64;Outer(foo=&#64;Inner)
 *     private int id;
 *         outerAnnotationAdapter = AnnotationAdapter<&#64;Outer>
 *         elementName = "foo"
 *         annotationName = "Inner"
 * </pre>
 */
public class NestedDeclarationAnnotationAdapter
	extends AbstractNestedDeclarationAnnotationAdapter
{
	// ********** constructors **********

	/**
	 * The default element name is <code>value</code>.
	 */
	public NestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String annotationName) {
		super(outerAnnotationAdapter, annotationName);
	}

	/**
	 * default behavior is to remove the outer annotation when it is empty
	 */
	public NestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String elementName, String annotationName) {
		super(outerAnnotationAdapter, elementName, annotationName);
	}


	// ********** AbstractNestedDeclarationAnnotationAdapter implementation **********

	@Override
	protected Annotation getAnnotation(Expression value) {
		return this.annotationValue(value);
	}

	@Override
	protected Expression buildNewInnerExpression(Annotation inner) {
		return inner;
	}

	/**
	 * the annotation is the expression itself, so the annotation cannot be
	 * "removed" from itself - return 'false'
	 */
	@Override
	protected boolean removeAnnotation(ModifiedDeclaration declaration, Annotation outer, Expression value) {
		return false;
	}

	/**
	 * <pre>
	 * &#64;Outer("lorem ipsum") => &#64;Outer(&#64;Inner)
	 * </pre>
	 */
	@Override
	protected void modifyAnnotationValue(SingleMemberAnnotation outer, Annotation inner) {
		// replace(?) the current element value
		outer.setValue(inner);
	}

	/**
	 * Simply set the pair's value.
	 */
	@Override
	protected void modifyMemberValuePair(MemberValuePair pair, Annotation inner) {
		pair.setValue(inner);
	}

}

Back to the top