Skip to main content
summaryrefslogtreecommitdiffstats
blob: aceeb486161ee43ab7118c4413c25dad88a25065 (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
/*******************************************************************************
 * 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.core.internal.utility.jdt;

import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.Member;
import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.utility.internal.StringTools;

/**
 * Adapt a member and an indexed declaration annotation adapter.
 */
public class MemberIndexedAnnotationAdapter
	extends AbstractAnnotationAdapter
	implements IndexedAnnotationAdapter
{
	private final IndexedDeclarationAnnotationAdapter idaa;


	// ********** constructor **********

	public MemberIndexedAnnotationAdapter(Member member, IndexedDeclarationAnnotationAdapter idaa) {
		super(member, idaa);
		this.idaa = idaa;
	}


	// ********** IndexedAnnotationAdapter implementation **********

	public int getIndex() {
		return this.idaa.getIndex();
	}

	public void moveAnnotation(int newIndex) {
		this.edit(this.buildMoveAnnotationEditor(newIndex));
	}


	// ********** factory methods **********

	protected Member.Editor buildMoveAnnotationEditor(int newIndex) {
		return new MoveAnnotationEditor(this.idaa, newIndex);
	}


	// ********** member classes **********

	protected static class MoveAnnotationEditor implements Member.Editor {
		private final IndexedDeclarationAnnotationAdapter idaa;
		private int index;

		MoveAnnotationEditor(IndexedDeclarationAnnotationAdapter idaa, int index) {
			super();
			this.idaa = idaa;
			this.index = index;
		}
		public void edit(ModifiedDeclaration declaration) {
			this.idaa.moveAnnotation(this.index, declaration);
		}
		@Override
		public String toString() {
			return StringTools.buildToStringFor(this);
		}
	}

}

Back to the top