blob: bd76ba56d67ed58b6240a8ee4d17bf27611f8a3b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 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.resource.java;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
import org.eclipse.jpt.core.resource.java.JPA;
import org.eclipse.jpt.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.core.resource.java.OverrideAnnotation;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.Member;
public abstract class OverrideImpl
extends AbstractResourceAnnotation<Member>
implements OverrideAnnotation
{
// hold this so we can get the 'name' text range
private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter;
private final AnnotationElementAdapter<String> nameAdapter;
private String name;
protected OverrideImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
super(parent, member, daa, annotationAdapter);
this.nameDeclarationAdapter = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, JPA.ATTRIBUTE_OVERRIDE__NAME, false); // false = do not remove annotation when empty
this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(getMember(),this.nameDeclarationAdapter);
}
public void initialize(CompilationUnit astRoot) {
this.name = this.name(astRoot);
}
public IndexedAnnotationAdapter getIndexedAnnotationAdapter() {
return (IndexedAnnotationAdapter) super.getAnnotationAdapter();
}
public void moveAnnotation(int newIndex) {
getIndexedAnnotationAdapter().moveAnnotation(newIndex);
}
public void initializeFrom(NestableAnnotation oldAnnotation) {
OverrideAnnotation oldOverride = (OverrideAnnotation) oldAnnotation;
setName(oldOverride.getName());
}
//************ AttriubteOverride implementation ****************
public String getName() {
return this.name;
}
public void setName(String newName) {
if (attributeValueHasNotChanged(this.name, newName)) {
return;
}
String oldName = this.name;
this.name = newName;
this.nameAdapter.setValue(newName);
firePropertyChanged(OverrideAnnotation.NAME_PROPERTY, oldName, newName);
}
public TextRange getNameTextRange(CompilationUnit astRoot) {
return this.getElementTextRange(this.nameDeclarationAdapter, astRoot);
}
public boolean nameTouches(int pos, CompilationUnit astRoot) {
return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot);
}
public void updateFromJava(CompilationUnit astRoot) {
this.setName(this.name(astRoot));
}
protected String name(CompilationUnit astRoot) {
return this.nameAdapter.getValue(astRoot);
}
}