| /******************************************************************************* |
| * Copyright (c) 2007, 2013 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0, which accompanies this distribution |
| * and is available at https://www.eclipse.org/legal/epl-2.0/. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.jpa.core.internal.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.resource.java.JavaResourceModel; |
| 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.AnnotationAdapter; |
| 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.common.utility.internal.ObjectTools; |
| import org.eclipse.jpt.jpa.core.resource.java.OverrideAnnotation; |
| |
| /** |
| * <code><ul> |
| * <li>javax.persistence.AttributeOverride |
| * <li>javax.persistence.AssociationOverride |
| * </ul></code> |
| */ |
| abstract class SourceOverrideAnnotation |
| extends SourceAnnotation |
| implements OverrideAnnotation |
| { |
| DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; |
| AnnotationElementAdapter<String> nameAdapter; |
| String name; |
| TextRange nameTextRange; |
| |
| |
| SourceOverrideAnnotation(JavaResourceModel parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { |
| super(parent, element, daa, annotationAdapter); |
| this.nameDeclarationAdapter = this.buildNameDeclarationAdapter(); |
| this.nameAdapter = this.buildNameAdapter(); |
| } |
| |
| @Override |
| public void initialize(Annotation astAnnotation) { |
| super.initialize(astAnnotation); |
| this.name = this.buildName(astAnnotation); |
| this.nameTextRange = this.buildNameTextRange(astAnnotation); |
| } |
| |
| @Override |
| public void synchronizeWith(Annotation astAnnotation) { |
| super.synchronizeWith(astAnnotation); |
| this.syncName(this.buildName(astAnnotation)); |
| this.nameTextRange = this.buildNameTextRange(astAnnotation); |
| } |
| |
| |
| // ********** OverrideAnnotation implementation ********** |
| |
| // ***** name |
| public String getName() { |
| return this.name; |
| } |
| |
| public void setName(String name) { |
| if (ObjectTools.notEquals(this.name, name)) { |
| this.name = name; |
| this.nameAdapter.setValue(name); |
| } |
| } |
| |
| private void syncName(String astName) { |
| String old = this.name; |
| this.name = astName; |
| this.firePropertyChanged(NAME_PROPERTY, old, astName); |
| } |
| |
| private String buildName(Annotation astAnnotation) { |
| return this.nameAdapter.getValue(astAnnotation); |
| } |
| |
| public TextRange getNameTextRange() { |
| return this.nameTextRange; |
| } |
| |
| private TextRange buildNameTextRange(Annotation astAnnotation) { |
| return this.getElementTextRange(this.nameDeclarationAdapter, astAnnotation); |
| } |
| |
| public boolean nameTouches(int pos) { |
| return this.textRangeTouches(this.nameTextRange, pos); |
| } |
| |
| private DeclarationAnnotationElementAdapter<String> buildNameDeclarationAdapter() { |
| return this.buildStringElementAdapter(this.getNameElementName()); |
| } |
| |
| private AnnotationElementAdapter<String> buildNameAdapter() { |
| return this.buildStringElementAdapter(this.nameDeclarationAdapter); |
| } |
| |
| protected abstract String getNameElementName(); |
| |
| |
| // ********** misc ********** |
| |
| @Override |
| public boolean isUnset() { |
| return super.isUnset() && |
| (this.name == null); |
| } |
| |
| @Override |
| public void toString(StringBuilder sb) { |
| sb.append(this.name); |
| } |
| } |