Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6ba2dfe141078a6779f70f9605b49410d5a6de9c (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
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
116
117
118
/*******************************************************************************
 * Copyright (c) 2012 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.jpa.core.internal.jpa2_1.resource.java.source;

import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation;
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.Converter2_1Annotation;
import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;

/**
 * <code>javax.persistence.Converter</code>
 */
public final class SourceConverter2_1Annotation
	extends SourceAnnotation
	implements Converter2_1Annotation
{
	private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);

	private DeclarationAnnotationElementAdapter<Boolean> autoApplyDeclarationAdapter;
	private AnnotationElementAdapter<Boolean> autoApplyAdapter;
	private Boolean autoApply;
	private TextRange autoApplyTextRange;


	public SourceConverter2_1Annotation(JavaResourceAnnotatedElement parent, AnnotatedElement element) {
		super(parent, element, DECLARATION_ANNOTATION_ADAPTER);
		this.autoApplyDeclarationAdapter = this.buildAutoApplyDeclarationAdapter();
		this.autoApplyAdapter = this.buildAutoApplyAdapter();
	}

	@Override
	public void initialize(Annotation astAnnotation) {
		super.initialize(astAnnotation);

		this.autoApply = this.buildAutoApply(astAnnotation);
		this.autoApplyTextRange = this.buildAutoApplyTextRange(astAnnotation);
	}

	@Override
	public void synchronizeWith(Annotation astAnnotation) {
		super.synchronizeWith(astAnnotation);

		this.syncAutoApply(this.buildAutoApply(astAnnotation));
		this.autoApplyTextRange = this.buildAutoApplyTextRange(astAnnotation);
	}

	public String getAnnotationName() {
		return ANNOTATION_NAME;
	}


	//************* Converter2_1Annotation implementation *************

	// ***** autoApply
	public Boolean getAutoApply() {
		return this.autoApply;
	}

	public void setAutoApply(Boolean autoApply) {
		if (this.attributeValueHasChanged(this.autoApply, autoApply)) {
			this.autoApply = autoApply;
			this.autoApplyAdapter.setValue(autoApply);
		}
	}

	private void syncAutoApply(Boolean astAutoApply) {
		Boolean old = this.autoApply;
		this.autoApply = astAutoApply;
		this.firePropertyChanged(AUTO_APPLY_PROPERTY, old, astAutoApply);
	}

	private Boolean buildAutoApply(Annotation astAnnotation) {
		return this.autoApplyAdapter.getValue(astAnnotation);
	}

	public TextRange getAutoApplyTextRange() {
		return this.autoApplyTextRange;
	}

	private TextRange buildAutoApplyTextRange(Annotation astAnnotation) {
		return this.getElementTextRange(this.autoApplyDeclarationAdapter, astAnnotation);
	}

	private DeclarationAnnotationElementAdapter<Boolean> buildAutoApplyDeclarationAdapter() {
		return this.buildBooleanElementAdapter(this.getAutoApplyElementName());
	}

	private AnnotationElementAdapter<Boolean> buildAutoApplyAdapter() {
		return this.buildBooleanElementAdapter(this.autoApplyDeclarationAdapter);
	}

	String getAutoApplyElementName() {
		return JPA2_1.CONVERTER__AUTO_APPLY;
	}


	// ********** misc **********

	@Override
	public boolean isUnset() {
		return super.isUnset() &&
				(this.autoApply == null);
	}
}

Back to the top