diff options
author | kmoore | 2010-12-30 19:02:39 +0000 |
---|---|---|
committer | kmoore | 2010-12-30 19:02:39 +0000 |
commit | 58b6dcf62a7f803a187ef418db2c7147399ca7c0 (patch) | |
tree | 393d8c1fb744f7337ad99c3e8dbe8a93ebba3a1a | |
parent | efff6ace83460ae1ba5eea7babaea2e4829323f3 (diff) | |
download | webtools.dali-58b6dcf62a7f803a187ef418db2c7147399ca7c0.tar.gz webtools.dali-58b6dcf62a7f803a187ef418db2c7147399ca7c0.tar.xz webtools.dali-58b6dcf62a7f803a187ef418db2c7147399ca7c0.zip |
added some modifier support to handle determining which fields/properties in the context model are persistent depending on access type
6 files changed, 118 insertions, 148 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMember.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMember.java index 042933f1bb..b4bc89f2e1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMember.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMember.java @@ -18,7 +18,6 @@ import org.eclipse.jpt.jaxb.core.resource.java.Annotation; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMember; import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceNode; import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; /** * Java source member (annotations, "persistable") @@ -28,10 +27,14 @@ abstract class SourceMember<M extends Member> implements JavaResourceMember { - boolean persistable; - boolean final_; // 'final' is a reserved word + boolean transient_; // 'transient' is a reserved word + + boolean public_; // 'public' is a reserved word + + boolean static_; // 'static' is a reserved word + // ********** construction/initialization ********** @@ -42,17 +45,21 @@ abstract class SourceMember<M extends Member> @Override public void initialize(CompilationUnit astRoot) { super.initialize(astRoot); - this.persistable = this.buildPersistable(astRoot); IBinding binding = this.annotatedElement.getBinding(astRoot); this.final_ = this.buildFinal(binding); + this.transient_ = this.buildTransient(binding); + this.public_ = this.buildPublic(binding); + this.static_ = this.buildStatic(binding); } @Override public void synchronizeWith(CompilationUnit astRoot) { super.synchronizeWith(astRoot); - this.syncPersistable(this.buildPersistable(astRoot)); IBinding binding = this.annotatedElement.getBinding(astRoot); this.syncFinal(this.buildFinal(binding)); + this.syncTransient(this.buildTransient(binding)); + this.syncPublic(this.buildPublic(binding)); + this.syncStatic(this.buildStatic(binding)); } @@ -82,22 +89,6 @@ abstract class SourceMember<M extends Member> } - // ********** persistable ********** - - public boolean isPersistable() { - return this.persistable; - } - - private void syncPersistable(boolean astPersistable) { - boolean old = this.persistable; - this.persistable = astPersistable; - this.firePropertyChanged(PERSISTABLE_PROPERTY, old, astPersistable); - } - - private boolean buildPersistable(CompilationUnit astRoot) { - return this.annotatedElement.isPersistable(astRoot); - } - // ***** final public boolean isFinal() { return this.final_; @@ -113,6 +104,51 @@ abstract class SourceMember<M extends Member> return (binding == null) ? false : Modifier.isFinal(binding.getModifiers()); } + // ***** transient + public boolean isTransient() { + return this.transient_; + } + + private void syncTransient(boolean astTransient) { + boolean old = this.transient_; + this.transient_ = astTransient; + this.firePropertyChanged(TRANSIENT_PROPERTY, old, astTransient); + } + + private boolean buildTransient(IBinding binding) { + return (binding == null) ? false : Modifier.isTransient(binding.getModifiers()); + } + + // ***** public + public boolean isPublic() { + return this.public_; + } + + private void syncPublic(boolean astPublic) { + boolean old = this.public_; + this.public_ = astPublic; + this.firePropertyChanged(PUBLIC_PROPERTY, old, astPublic); + } + + private boolean buildPublic(IBinding binding) { + return (binding == null) ? false : Modifier.isPublic(binding.getModifiers()); + } + + // ***** static + public boolean isStatic() { + return this.static_; + } + + private void syncStatic(boolean astStatic) { + boolean old = this.static_; + this.static_ = astStatic; + this.firePropertyChanged(STATIC_PROPERTY, old, astStatic); + } + + private boolean buildStatic(IBinding binding) { + return (binding == null) ? false : Modifier.isStatic(binding.getModifiers()); + } + // ********** miscellaneous ********** @@ -121,18 +157,6 @@ abstract class SourceMember<M extends Member> } public void resolveTypes(CompilationUnit astRoot) { - this.syncPersistable(this.buildPersistable(astRoot)); } - /** - * convenience method - */ - <T extends JavaResourceMember> Iterable<T> getPersistableMembers(Iterable<T> members) { - return new FilteringIterable<T>(members) { - @Override - protected boolean accept(T m) { - return m.isPersistable(); - } - }; - } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMethod.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMethod.java index 7e901f2bf8..7aa53a80e4 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMethod.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceMethod.java @@ -33,6 +33,7 @@ final class SourceMethod extends SourceAttribute<MethodAttribute> implements JavaResourceMethod { + boolean constructor; private final Vector<String> parameterTypeNames = new Vector<String>(); @@ -66,6 +67,7 @@ final class SourceMethod public void initialize(CompilationUnit astRoot) { super.initialize(astRoot); IMethodBinding binding = this.annotatedElement.getBinding(astRoot); + this.constructor = this.buildConstructor(binding); this.parameterTypeNames.addAll(this.buildParameterTypeNames(binding)); } @@ -73,6 +75,11 @@ final class SourceMethod // ******** overrides ******** @Override + protected JavaResourceType getParent() { + return (JavaResourceType) super.getParent(); + } + + @Override public void resolveTypes(CompilationUnit astRoot) { super.resolveTypes(astRoot); } @@ -81,17 +88,36 @@ final class SourceMethod public void synchronizeWith(CompilationUnit astRoot) { super.synchronizeWith(astRoot); IMethodBinding binding = this.annotatedElement.getBinding(astRoot); - + this.syncConstructor(this.buildConstructor(binding)); this.syncParameterTypeNames(this.buildParameterTypeNames(binding)); } @Override public void toString(StringBuilder sb) { - sb.append(this.getName()); + sb.append(this.getMethodName()); } // ******** JavaResourceMethod implementation ******** + + public String getMethodName() { + return this.annotatedElement.getName(); + } + + // ***** constructor + public boolean isConstructor() { + return this.constructor; + } + + private void syncConstructor(boolean astConstructor) { + boolean old = this.constructor; + this.constructor = astConstructor; + this.firePropertyChanged(CONSTRUCTOR_PROPERTY, old, astConstructor); + } + + private boolean buildConstructor(IMethodBinding methodBinding) { + return methodBinding == null ? false : methodBinding.isConstructor(); + } public boolean isFor(MethodSignature signature, int occurrence) { return this.annotatedElement.matches(signature, occurrence); @@ -195,7 +221,12 @@ final class SourceMethod } ArrayList<String> names = new ArrayList<String>(); for (ITypeBinding parameterType : methodBinding.getParameterTypes()) { - names.add(parameterType.getQualifiedName()); + if (parameterType.isTypeVariable()) { + // e.g. "E extends Number" has an erasure of "Number" + parameterType = parameterType.getErasure(); + } + String ptName = parameterType.getTypeDeclaration().getQualifiedName(); + names.add(ptName); } return names; } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceType.java index b4efa8088e..6ec6552153 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceType.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceType.java @@ -47,8 +47,6 @@ final class SourceType private boolean abstract_; // 'abstract' is a reserved word - private boolean static_; // 'static' is a reserved word - private boolean hasNoArgConstructor; private final Vector<JavaResourceType> types; @@ -114,7 +112,6 @@ final class SourceType ITypeBinding binding = this.annotatedElement.getBinding(astRoot); this.superclassQualifiedName = this.buildSuperclassQualifiedName(binding); this.abstract_ = this.buildAbstract(binding); - this.static_ = this.buildStatic(binding); this.hasNoArgConstructor = this.buildHasNoArgConstructor(binding); this.initializeTypes(astRoot); this.initializeEnums(astRoot); @@ -131,7 +128,6 @@ final class SourceType ITypeBinding binding = this.annotatedElement.getBinding(astRoot); this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(binding)); this.syncAbstract(this.buildAbstract(binding)); - this.syncStatic(this.buildStatic(binding)); this.syncHasNoArgConstructor(this.buildHasNoArgConstructor(binding)); this.syncTypes(astRoot); this.syncEnums(astRoot); @@ -206,21 +202,6 @@ final class SourceType return (binding == null) ? false : Modifier.isAbstract(binding.getModifiers()); } - // ***** static - public boolean isStatic() { - return this.static_; - } - - private void syncStatic(boolean static_) { - boolean old = this.static_; - this.static_ = static_; - this.firePropertyChanged(STATIC_PROPERTY, old, static_); - } - - private boolean buildStatic(ITypeBinding binding) { - return (binding == null) ? false : Modifier.isStatic(binding.getModifiers()); - } - // ***** no-arg constructor public boolean hasNoArgConstructor() { return this.hasNoArgConstructor; @@ -266,10 +247,6 @@ final class SourceType }; } - public Iterable<JavaResourceType> getPersistableTypes() { - return this.getPersistableMembers(this.getTypes()); - } - private JavaResourceType getType(String typeName, int occurrence) { for (JavaResourceType type : this.getTypes()) { if (type.isFor(typeName, occurrence)) { @@ -388,10 +365,6 @@ final class SourceType return new LiveCloneIterable<JavaResourceField>(this.fields); } - public Iterable<JavaResourceField> getPersistableFields() { - return this.getPersistableMembers(this.getFields()); - } - private void addField(JavaResourceField field) { this.addItemToCollection(field, this.fields, FIELDS_COLLECTION); } @@ -459,10 +432,6 @@ final class SourceType return new LiveCloneIterable<JavaResourceMethod>(this.methods); } - public Iterable<JavaResourceMethod> getPersistableProperties() { - return this.getPersistableMembers(this.getMethods()); - } - private JavaResourceMethod getMethod(MethodSignature signature, int occurrence) { for (JavaResourceMethod method : this.getMethods()) { if (method.isFor(signature, occurrence)) { @@ -512,33 +481,4 @@ final class SourceType private JavaResourceMethod buildMethod(MethodSignature signature, int occurrence, CompilationUnit astRoot) { return SourceMethod.newInstance(this, this.annotatedElement, signature, occurrence, this.getJavaResourceCompilationUnit(), astRoot); } - - - // ********** attributes ********** - -// @SuppressWarnings("unchecked") -// public Iterable<JavaResourceAttribute> getPersistableAttributes() { -// return new CompositeIterable<JavaResourceAttribute>( -// this.getPersistableFields(), -// this.getPersistableProperties() -// ); -// } -// -// //TODO XmlAccessType.PUBLIC_MEMBER and XmlAccessType.NONE -// public Iterable<JavaResourceAttribute> getPersistableAttributes(XmlAccessType specifiedAccess) { -// if (specifiedAccess == null) { -// throw new IllegalArgumentException("specified access is null"); //$NON-NLS-1$ -// } -// return (specifiedAccess == XmlAccessType.FIELD) ? -// this.getPersistableAttributesForFieldAccessType() : -// this.getPersistableAttributesForPropertyAccessType(); -// } -// -// private Iterable<JavaResourceAttribute> getPersistableAttributesForFieldAccessType() { -// return this.getPersistableFields(); -// } -// -// private Iterable<JavaResourceMethod> getPersistableAttributesForPropertyAccessType() { -// return this.getPersistableProperties(); -// } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMember.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMember.java index f55c554258..8d0b75aa97 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMember.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMember.java @@ -37,21 +37,27 @@ public interface JavaResourceMember Annotation setPrimaryAnnotation(String primaryAnnotationName, Iterable<String> supportingAnnotationNames); - // ********** queries ********** - - /** - * Return whether the underlying JDT member is persistable according to - * the JPA spec. - */ - boolean isPersistable(); - String PERSISTABLE_PROPERTY = "persistable"; //$NON-NLS-1$ + + // ********** modifiers ********** /** * Return whether the member is final. */ boolean isFinal(); String FINAL_PROPERTY = "final"; //$NON-NLS-1$ - + + boolean isTransient(); + String TRANSIENT_PROPERTY = "transient"; //$NON-NLS-1$ + + boolean isPublic(); + String PUBLIC_PROPERTY = "public"; //$NON-NLS-1$ + + boolean isStatic(); + String STATIC_PROPERTY = "static"; //$NON-NLS-1$ + + + // ********** queries ********** + /** * Return whether the Java resource member is for the specified * member. diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMethod.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMethod.java index 12d10a4ffe..3a284fc6ab 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMethod.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceMethod.java @@ -28,11 +28,17 @@ public interface JavaResourceMethod extends JavaResourceMember { /** - * The Java resource method's name does not change. + * Return the methods's name, as opposed to the member's name + * (e.g. "getFoo()" returns "foo"). This does not change. */ String getName(); /** + * The Java resource method's name does not change. + */ + String getMethodName(); + + /** * Return whether the Java resource persistent attribute is for the specified * method. */ @@ -110,4 +116,8 @@ public interface JavaResourceMethod String PARAMETER_TYPE_NAMES_LIST = "parameterTypeNames"; //$NON-NLS-1$ int getParametersSize(); + + boolean isConstructor(); + String CONSTRUCTOR_PROPERTY = "constructor"; //$NON-NLS-1$ + } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceType.java index ee1199ac9f..44f719f6aa 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceType.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JavaResourceType.java @@ -37,13 +37,6 @@ public interface JavaResourceType boolean isAbstract(); String ABSTRACT_PROPERTY = "abstract"; //$NON-NLS-1$ - - /** - * Return whether the type is static. - */ - boolean isStatic(); - String STATIC_PROPERTY = "static"; //$NON-NLS-1$ - /** * Return whether the type has a no-arg constructor (private, protected, or public) */ @@ -51,14 +44,6 @@ public interface JavaResourceType String NO_ARG_CONSTRUCTOR_PROPERTY = "noArgConstructor"; //$NON-NLS-1$ - // ********** types ********** - - /** - * Return the immediately nested persistable types. - */ - Iterable<JavaResourceType> getPersistableTypes(); - - // ********** fields ********** /** @@ -67,11 +52,6 @@ public interface JavaResourceType Iterable<JavaResourceField> getFields(); String FIELDS_COLLECTION = "fields"; //$NON-NLS-1$ - /** - * Return the type's persistable fields. - */ - Iterable<JavaResourceField> getPersistableFields(); - // ********** methods ********** @@ -80,26 +60,5 @@ public interface JavaResourceType */ Iterable<JavaResourceMethod> getMethods(); String METHODS_COLLECTION = "methods"; //$NON-NLS-1$ -// -// /** -// * Return the type's persistable properties. This returns only the getter methods -// * that match the JavaBeans criteria for JPA, hence the name properties instead of methods -// */ -// Iterable<JavaResourceMethod> getPersistableProperties(); -// -// -// // ********** attributes ********** -// -// /** -// * Return the type's persistable fields and properties. -// * {@link JavaResourceMember#isPersistable()} -// */ -// Iterable<JavaResourceAttribute> getPersistableAttributes(); -// -// /** -// * Return the persistable properties and/or fields given the non-null specified access type -// * {@link JavaResourceMember#isPersistable()} -// */ -// Iterable<JavaResourceAttribute> getPersistableAttributes(XmlAccessType specifiedAccess); - + } |