blob: 56c394de6c7c2e36c953e7846d7a545a4dc3ef7c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 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.content.java.mappings;
import java.util.Iterator;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.ITextRange;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
import org.eclipse.jpt.core.internal.jdtutility.AnnotationElementAdapter;
import org.eclipse.jpt.core.internal.jdtutility.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.jdtutility.IndexedAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.IndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.Member;
import org.eclipse.jpt.core.internal.jdtutility.MemberIndexedAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.ShortCircuitAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.mappings.IOverride;
import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
import org.eclipse.jpt.utility.internal.Filter;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>Java Override</b></em>'.
* <!-- end-user-doc -->
*
*
* @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getJavaOverride()
* @model kind="class" abstract="true"
* @generated
*/
public abstract class JavaOverride extends JavaEObject implements IOverride
{
/**
* The default value of the '{@link #getName() <em>Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getName()
* @generated
* @ordered
*/
protected static final String NAME_EDEFAULT = null;
/**
* The cached value of the '{@link #getName() <em>Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getName()
* @generated
* @ordered
*/
protected String name = NAME_EDEFAULT;
private final Owner owner;
private final Member member;
private final IndexedDeclarationAnnotationAdapter daa;
private final IndexedAnnotationAdapter annotationAdapter;
private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter;
private final AnnotationElementAdapter<String> nameAdapter;
protected JavaOverride() {
throw new UnsupportedOperationException("use JavaAttributeOverride(Owner, Member, IndexedDeclarationAnnotationAdapter)");
}
protected JavaOverride(Owner owner, Member member, IndexedDeclarationAnnotationAdapter daa) {
super();
this.owner = owner;
this.member = member;
this.daa = daa;
this.annotationAdapter = new MemberIndexedAnnotationAdapter(member, daa);
this.nameDeclarationAdapter = ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.nameElementName());
this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(this.member, this.nameDeclarationAdapter);
}
protected abstract String nameElementName();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return JpaJavaMappingsPackage.Literals.JAVA_OVERRIDE;
}
/**
* Returns the value of the '<em><b>Name</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Name</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Name</em>' attribute.
* @see #setName(String)
* @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getIOverride_Name()
* @model
* @generated
*/
public String getName() {
return name;
}
/**
* Sets the value of the '{@link org.eclipse.jpt.core.internal.content.java.mappings.JavaOverride#getName <em>Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Name</em>' attribute.
* @see #getName()
* @generated
*/
public void setNameGen(String newName) {
String oldName = name;
name = newName;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME, oldName, name));
}
public void setName(String newName) {
setNameGen(newName);
if (!this.isVirtual()) {
setNameInJava(newName);
}
}
private void setNameInJava(String newName) {
this.nameAdapter.setValue(newName);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME :
return getName();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME :
setName((String) newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME :
setName(NAME_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME :
return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
if (baseClass == IOverride.class) {
switch (derivedFeatureID) {
case JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME :
return JpaCoreMappingsPackage.IOVERRIDE__NAME;
default :
return -1;
}
}
return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
if (baseClass == IOverride.class) {
switch (baseFeatureID) {
case JpaCoreMappingsPackage.IOVERRIDE__NAME :
return JpaJavaMappingsPackage.JAVA_OVERRIDE__NAME;
default :
return -1;
}
}
return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy())
return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (name: ");
result.append(name);
result.append(')');
return result.toString();
}
public boolean isVirtual() {
return getOwner().isVirtual(this);
}
public Owner getOwner() {
return this.owner;
}
protected Member getMember() {
return this.member;
}
/**
* allow owners to verify the annotation
*/
public Annotation annotation(CompilationUnit astRoot) {
return this.annotationAdapter.getAnnotation(astRoot);
}
protected boolean elementTouches(DeclarationAnnotationElementAdapter<?> elementAdapter, int pos, CompilationUnit astRoot) {
return this.elementTouches(this.member.annotationElementTextRange(elementAdapter, astRoot), pos);
}
public boolean nameTouches(int pos, CompilationUnit astRoot) {
return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot);
}
protected abstract Iterator<String> candidateNames();
private Iterator<String> candidateNames(Filter<String> filter) {
return new FilteringIterator<String>(this.candidateNames(), filter);
}
private Iterator<String> quotedCandidateNames(Filter<String> filter) {
return StringTools.quote(this.candidateNames(filter));
}
@Override
public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
Iterator<String> result = super.candidateValuesFor(pos, filter, astRoot);
if (result != null) {
return result;
}
if (this.nameTouches(pos, astRoot)) {
return this.quotedCandidateNames(filter);
}
return null;
}
public void updateFromJava(CompilationUnit astRoot) {
setName(this.nameAdapter.getValue(astRoot));
}
// ********** persistence model -> java annotations **********
void moveAnnotation(int newIndex) {
this.annotationAdapter.moveAnnotation(newIndex);
}
void newAnnotation() {
this.annotationAdapter.newMarkerAnnotation();
}
void removeAnnotation() {
this.annotationAdapter.removeAnnotation();
}
public ITextRange validationTextRange() {
ITextRange textRange = this.member.annotationTextRange(this.daa);
return (textRange == null) ? getOwner().validationTextRange() : textRange;
}
protected IndexedDeclarationAnnotationAdapter getDeclarationAnnotationAdapter() {
return this.daa;
}
}