diff options
author | Brian Vosburgh | 2013-03-25 20:43:40 +0000 |
---|---|---|
committer | Brian Vosburgh | 2013-03-26 15:25:39 +0000 |
commit | 72e6a5b48f3b431e6ce572e58f2122016d6bf649 (patch) | |
tree | b21099591646a1b5365b0d3836e1fad74bed8cf1 /jaxb | |
parent | fee644652c5f085660cfc3f4b1da040341c78b76 (diff) | |
download | webtools.dali-72e6a5b48f3b431e6ce572e58f2122016d6bf649.tar.gz webtools.dali-72e6a5b48f3b431e6ce572e58f2122016d6bf649.tar.xz webtools.dali-72e6a5b48f3b431e6ce572e58f2122016d6bf649.zip |
clean up Predicates
Diffstat (limited to 'jaxb')
23 files changed, 144 insertions, 361 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFile.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFile.java index 5c3b0db829..a228916839 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFile.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFile.java @@ -11,8 +11,8 @@ package org.eclipse.jpt.jaxb.core; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jpt.common.core.ContentTypeReference; import org.eclipse.jpt.common.core.JptResourceModel; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.transformer.Transformer; @@ -30,33 +30,13 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; * @since 3.0 */ public interface JaxbFile - extends JaxbNode + extends JaxbNode, ContentTypeReference { /** * Return the JAXB file's Eclipse file. */ IFile getFile(); - /**JAXB - * Return the JPA file's content type. - */ - IContentType getContentType(); - - class ContentIsKindOf - extends PredicateAdapter<JaxbFile> - { - private final IContentType contentType; - public ContentIsKindOf(IContentType contentType) { - super(); - this.contentType = contentType; - } - @Override - public boolean evaluate(JaxbFile jaxbFile) { - return jaxbFile.getContentType().isKindOf(this.contentType); - } - } - - /** * Return the resource model corresponding to the JPA file; typically a JPA * compilation unit, a JPA XML resource, or a JPA package fragment root (JAR). diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNamedNodeMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNamedNodeMapping.java index 60d3e74ea6..2c0d31001f 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNamedNodeMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNamedNodeMapping.java @@ -34,6 +34,16 @@ public interface XmlNamedNodeMapping String XML_ID_PROPERTY = "xmlID"; //$NON-NLS-1$ XmlID getXmlID(); + Predicate<XmlNamedNodeMapping> HAS_XML_ID = new HasXmlID(); + class HasXmlID + extends PredicateAdapter<XmlNamedNodeMapping> + { + @Override + public boolean evaluate(XmlNamedNodeMapping mapping) { + return mapping.getXmlID() != null; + } + } + XmlID addXmlID(); @@ -66,8 +76,8 @@ public interface XmlNamedNodeMapping XsdFeature getXsdFeature(); - Predicate<JaxbAttributeMapping> MAPPING_IS_NAMED_NODE_MAPPING = new MappingIsNamedNodeMapping(); - class MappingIsNamedNodeMapping + Predicate<JaxbAttributeMapping> IS_NAMED_NODE_MAPPING = new IsNamedNodeMapping(); + class IsNamedNodeMapping extends PredicateAdapter<JaxbAttributeMapping> { @Override diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaType.java index 0eeffc687e..2f9dfbf912 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaType.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaType.java @@ -11,7 +11,7 @@ package org.eclipse.jpt.jaxb.core.context.java; import java.util.List; import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; +import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate; import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; import org.eclipse.jpt.jaxb.core.context.JaxbPackage; import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; @@ -45,16 +45,13 @@ public interface JavaType */ TypeKind getKind(); class IsKind - extends PredicateAdapter<JavaType> + extends CriterionPredicate<JavaType, TypeKind> { - private final TypeKind typeKind; public IsKind(TypeKind typeKind) { - super(); - this.typeKind = typeKind; + super(typeKind); } - @Override public boolean evaluate(JavaType type) { - return type.getKind() == this.typeKind; + return type.getKind() == this.criterion; } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java index 564800d20e..f675f6b1bc 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java @@ -36,6 +36,7 @@ import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jpt.common.core.ContentTypeReference; import org.eclipse.jpt.common.core.JptResourceModel; import org.eclipse.jpt.common.core.JptResourceModelListener; import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryTypeCache; @@ -346,7 +347,7 @@ public abstract class AbstractJaxbProject } protected Iterable<JaxbFile> getJaxbFiles(final IContentType contentType) { - return IterableTools.filter(this.getJaxbFiles(), new JaxbFile.ContentIsKindOf(contentType)); + return IterableTools.filter(this.getJaxbFiles(), new ContentTypeReference.ContentTypeIsKindOf(contentType)); } @Override diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java index 27f290b12f..c5fcbcd9de 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java @@ -24,6 +24,7 @@ import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; +import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate; import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.predicate.Predicate; @@ -450,16 +451,13 @@ public abstract class AbstractJaxbContextRoot } public static class JavaTypeIsInPackage - extends PredicateAdapter<JavaType> + extends CriterionPredicate<JavaType, String> { - private final JaxbPackage jaxbPackage; public JavaTypeIsInPackage(JaxbPackage jaxbPackage) { - super(); - this.jaxbPackage = jaxbPackage; + super(jaxbPackage.getName()); } - @Override public boolean evaluate(JavaType javaType) { - return javaType.getTypeName().getPackageName().equals(this.jaxbPackage.getName()); + return javaType.getTypeName().getPackageName().equals(this.criterion); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java index 70a393809f..1da4952d28 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java @@ -9,18 +9,16 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.core.internal.context.java; -import java.lang.reflect.Modifier; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Vector; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMember; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.predicate.Predicate; @@ -55,8 +53,8 @@ public class GenericJavaAttributesContainer return (JaxbClassMapping) getParent(); } - public boolean isFor(JavaResourceType javaResourceType) { - return this.javaResourceType == javaResourceType; + public boolean isFor(JavaResourceType jrt) { + return this.javaResourceType == jrt; } @@ -138,12 +136,12 @@ public class GenericJavaAttributesContainer * 4. all annotated methods (some will have a matching getter/setter, some will be standalone) */ private void initializePublicMemberAccessAttributes() { - this.initializeFieldAttributes(PUBLIC_MEMBER_ACCESS_TYPE_RESOURCE_FIELDS_FILTER); + this.initializeFieldAttributes(JavaResourceField.IS_RELEVANT_FOR_PUBLIC_MEMBER_ACCESS); Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getResourceMethods()); //iterate through all persistable resource method getters - for (JavaResourceMethod getterMethod : this.getResourceMethods(this.buildPersistablePropertyGetterMethodsFilter())) { - JavaResourceMethod setterMethod = getValidSiblingSetMethod(getterMethod, resourceMethods); - if (methodsArePersistablePublicMemberAccess(getterMethod, setterMethod)) { + for (JavaResourceMethod getterMethod : this.getResourcePropertyGetters()) { + JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); + if (includePublicMemberAccessProperty(getterMethod, setterMethod)) { this.attributes.add(this.buildProperty(getterMethod, setterMethod)); } resourceMethods.remove(getterMethod); @@ -158,7 +156,7 @@ public class GenericJavaAttributesContainer * 2. all annotated methods getters/setters */ private void intializeFieldAccessAttributes() { - this.initializeFieldAttributes(this.buildNonTransientNonStaticResourceFieldsFilter()); + this.initializeFieldAttributes(JavaResourceField.IS_RELEVANT_FOR_FIELD_ACCESS); this.initializeAnnotatedPropertyAttributes(); } @@ -169,13 +167,13 @@ public class GenericJavaAttributesContainer * 3. all annotated methods getters/setters that don't have a matching pair */ private void intializePropertyAccessAttributes() { - this.initializeFieldAttributes(ANNOTATED_RESOURCE_FIELDS_FILTER); + this.initializeFieldAttributes(JavaResourceAnnotatedElement.IS_ANNOTATED); Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getResourceMethods()); //iterate through all resource methods searching for persistable getters - for (JavaResourceMethod getterMethod : this.getResourceMethods(this.buildPersistablePropertyGetterMethodsFilter())) { - JavaResourceMethod setterMethod = getValidSiblingSetMethod(getterMethod, resourceMethods); - if (methodsArePersistableProperties(getterMethod, setterMethod)) { + for (JavaResourceMethod getterMethod : this.getResourcePropertyGetters()) { + JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); + if (this.includeProperty(getterMethod, setterMethod)) { this.attributes.add(this.buildProperty(getterMethod, setterMethod)); } resourceMethods.remove(getterMethod); @@ -190,11 +188,11 @@ public class GenericJavaAttributesContainer * 2. all annotated methods getters/setters (some will have a matching getter/setter, some will be standalone) */ private void intializeNoneAccessAttributes() { - this.initializeFieldAttributes(ANNOTATED_RESOURCE_FIELDS_FILTER); + this.initializeFieldAttributes(JavaResourceAnnotatedElement.IS_ANNOTATED); this.initializeAnnotatedPropertyAttributes(); } - private void initializeFieldAttributes(Predicate<JavaResourceField> filter) { + private void initializeFieldAttributes(Predicate<? super JavaResourceField> filter) { for (JavaResourceField resourceField : this.getResourceFields(filter)) { this.attributes.add(this.buildField(resourceField)); } @@ -211,22 +209,20 @@ public class GenericJavaAttributesContainer } } - private static boolean methodsArePersistableProperties(JavaResourceMethod getterMethod, JavaResourceMethod setterMethod) { - if (setterMethod != null) { - return true; - } - //Lists do not have to have a corresponding setter method - else if (getterMethod.getTypeBinding().getQualifiedName().equals("java.util.List")) { //$NON-NLS-1$ - return true; - } - else if (getterMethod.isAnnotated()) { - //annotated getter with no corresponding setter, bring into context model for validation purposes - return true; - } - return false; + /** + * Return whether the pair of methods (that form a "property") are to be + * included in the contailner. + * Lists do not need a setter.... + * An annotated getter with no setter is still brought into the context + * model (for validation purposes).... + */ + private boolean includeProperty(JavaResourceMethod getterMethod, JavaResourceMethod setterMethod) { + return (setterMethod != null) || + getterMethod.getTypeBinding().getQualifiedName().equals(java.util.List.class.getName()) || + getterMethod.isAnnotated(); } - private static boolean methodsArePersistablePublicMemberAccess(JavaResourceMethod getterMethod, JavaResourceMethod setterMethod) { + private boolean includePublicMemberAccessProperty(JavaResourceMethod getterMethod, JavaResourceMethod setterMethod) { if (getterMethod.isPublic()) { if (setterMethod != null) { if (setterMethod.isPublic()) { @@ -234,7 +230,7 @@ public class GenericJavaAttributesContainer } } //Lists do not have to have a corresponding setter method - else if (getterMethod.getTypeBinding().getQualifiedName().equals("java.util.List")) { //$NON-NLS-1$ + else if (getterMethod.getTypeBinding().getQualifiedName().equals(java.util.List.class.getName())) { return true; } else if (getterMethod.isAnnotated()) { @@ -251,8 +247,8 @@ public class GenericJavaAttributesContainer private void initializeAnnotatedPropertyAttributes() { Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getResourceMethods()); //iterate through all resource methods searching for persistable getters - for (JavaResourceMethod getterMethod : this.getResourceMethods(buildPersistablePropertyGetterMethodsFilter())) { - JavaResourceMethod setterMethod = getValidSiblingSetMethod(getterMethod, resourceMethods); + for (JavaResourceMethod getterMethod : this.getResourcePropertyGetters()) { + JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); if (getterMethod.isAnnotated() || (setterMethod != null && setterMethod.isAnnotated())) { this.attributes.add(this.buildProperty(getterMethod, setterMethod)); } @@ -270,51 +266,18 @@ public class GenericJavaAttributesContainer return this.javaResourceType.getMethods(); } - protected Iterable<JavaResourceField> getResourceFields(Predicate<JavaResourceField> filter) { + protected Iterable<JavaResourceField> getResourceFields(Predicate<? super JavaResourceField> filter) { return IterableTools.filter(getResourceFields(), filter); } - protected Iterable<JavaResourceMethod> getResourceMethods(Predicate<JavaResourceMethod> filter) { + protected Iterable<JavaResourceMethod> filterResourceMethods(Predicate<JavaResourceMethod> filter) { return IterableTools.filter(getResourceMethods(), filter); } - protected Predicate<JavaResourceField> buildNonTransientNonStaticResourceFieldsFilter() { - return new Predicate<JavaResourceField>() { - public boolean evaluate(JavaResourceField resourceField) { - return memberIsNonTransientNonStatic(resourceField) || resourceField.isAnnotated(); - } - }; - } - - protected static Predicate<JavaResourceField> PUBLIC_MEMBER_ACCESS_TYPE_RESOURCE_FIELDS_FILTER = new Predicate<JavaResourceField>() { - public boolean evaluate(JavaResourceField resourceField) { - return memberIsPublicNonTransientNonStatic(resourceField) || resourceField.isAnnotated(); - } - }; - - protected Predicate<JavaResourceMethod> buildPersistablePropertyGetterMethodsFilter() { - return new Predicate<JavaResourceMethod>() { - public boolean evaluate(JavaResourceMethod resourceMethod) { - return methodIsPersistablePropertyGetter(resourceMethod, getResourceMethods()); - } - }; - } - - protected static boolean memberIsPublicNonTransientNonStatic(JavaResourceMember resourceMember) { - return resourceMember.isPublic() && memberIsNonTransientNonStatic(resourceMember); + protected Iterable<JavaResourceMethod> getResourcePropertyGetters() { + return this.filterResourceMethods(JavaResourceMethod.IS_PROPERTY_GETTER); } - protected static boolean memberIsNonTransientNonStatic(JavaResourceMember resourceMember) { - return !resourceMember.isTransient() && !resourceMember.isStatic(); - } - - protected static Predicate<JavaResourceField> ANNOTATED_RESOURCE_FIELDS_FILTER = - new Predicate<JavaResourceField>() { - public boolean evaluate(JavaResourceField resourceField) { - return resourceField.isAnnotated(); - } - }; - /** * The attributes are synchronized during the <em>update</em> because * the list of resource attributes is determined by the access type @@ -351,13 +314,13 @@ public class GenericJavaAttributesContainer private void syncPublicMemberAccessAttributes() { HashSet<JavaPersistentAttribute> contextAttributes = CollectionTools.set(this.getAttributes()); - this.syncFieldAttributes(contextAttributes, PUBLIC_MEMBER_ACCESS_TYPE_RESOURCE_FIELDS_FILTER); + this.syncFieldAttributes(contextAttributes, JavaResourceField.IS_RELEVANT_FOR_PUBLIC_MEMBER_ACCESS); Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getResourceMethods()); //iterate through all persistable resource method getters - for (JavaResourceMethod getterMethod : this.getResourceMethods(this.buildPersistablePropertyGetterMethodsFilter())) { - JavaResourceMethod setterMethod = getValidSiblingSetMethod(getterMethod, resourceMethods); - if (methodsArePersistablePublicMemberAccess(getterMethod, setterMethod)) { + for (JavaResourceMethod getterMethod : this.getResourcePropertyGetters()) { + JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); + if (includePublicMemberAccessProperty(getterMethod, setterMethod)) { boolean match = false; for (Iterator<JavaPersistentAttribute> stream = contextAttributes.iterator(); stream.hasNext();) { JavaPersistentAttribute contextAttribute = stream.next(); @@ -386,7 +349,7 @@ public class GenericJavaAttributesContainer private void syncFieldAccessAttributes() { HashSet<JavaPersistentAttribute> contextAttributes = CollectionTools.set(this.getAttributes()); - this.syncFieldAttributes(contextAttributes, this.buildNonTransientNonStaticResourceFieldsFilter()); + this.syncFieldAttributes(contextAttributes, JavaResourceField.IS_RELEVANT_FOR_FIELD_ACCESS); this.syncAnnotatedPropertyAttributes(contextAttributes); } @@ -399,13 +362,13 @@ public class GenericJavaAttributesContainer private void syncPropertyAccessAttributes() { HashSet<JavaPersistentAttribute> contextAttributes = CollectionTools.set(this.getAttributes()); - this.syncFieldAttributes(contextAttributes, ANNOTATED_RESOURCE_FIELDS_FILTER); + this.syncFieldAttributes(contextAttributes, JavaResourceAnnotatedElement.IS_ANNOTATED); Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getResourceMethods()); //iterate through all resource methods searching for persistable getters - for (JavaResourceMethod getterMethod : this.getResourceMethods(this.buildPersistablePropertyGetterMethodsFilter())) { - JavaResourceMethod setterMethod = getValidSiblingSetMethod(getterMethod, resourceMethods); - if (methodsArePersistableProperties(getterMethod, setterMethod)) { + for (JavaResourceMethod getterMethod : this.getResourcePropertyGetters()) { + JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); + if (this.includeProperty(getterMethod, setterMethod)) { boolean match = false; for (Iterator<JavaPersistentAttribute> stream = contextAttributes.iterator(); stream.hasNext();) { JavaPersistentAttribute contextAttribute = stream.next(); @@ -434,15 +397,15 @@ public class GenericJavaAttributesContainer private void syncNoneAccessAttributes() { HashSet<JavaPersistentAttribute> contextAttributes = CollectionTools.set(this.getAttributes()); - this.syncFieldAttributes(contextAttributes, ANNOTATED_RESOURCE_FIELDS_FILTER); + this.syncFieldAttributes(contextAttributes, JavaResourceAnnotatedElement.IS_ANNOTATED); this.syncAnnotatedPropertyAttributes(contextAttributes); } private void syncAnnotatedPropertyAttributes(HashSet<JavaPersistentAttribute> contextAttributes) { Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getResourceMethods()); //iterate through all resource methods searching for persistable getters - for (JavaResourceMethod getterMethod : this.getResourceMethods(buildPersistablePropertyGetterMethodsFilter())) { - JavaResourceMethod setterMethod = getValidSiblingSetMethod(getterMethod, resourceMethods); + for (JavaResourceMethod getterMethod : this.getResourcePropertyGetters()) { + JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); if (getterMethod.isAnnotated() || (setterMethod != null && setterMethod.isAnnotated())) { boolean match = false; for (Iterator<JavaPersistentAttribute> stream = contextAttributes.iterator(); stream.hasNext();) { @@ -464,7 +427,7 @@ public class GenericJavaAttributesContainer this.syncRemainingResourceMethods(contextAttributes, resourceMethods); } - private void syncFieldAttributes(HashSet<JavaPersistentAttribute> contextAttributes, Predicate<JavaResourceField> filter) { + private void syncFieldAttributes(HashSet<JavaPersistentAttribute> contextAttributes, Predicate<? super JavaResourceField> filter) { for (JavaResourceField resourceField : this.getResourceFields(filter)) { boolean match = false; for (Iterator<JavaPersistentAttribute> stream = contextAttributes.iterator(); stream.hasNext(); ) { @@ -513,134 +476,6 @@ public class GenericJavaAttributesContainer } } - /** - * Return whether the specified method is a "getter" method that - * represents a property that may be "persisted". - */ - protected static boolean methodIsPersistablePropertyGetter(JavaResourceMethod resourceMethod, Iterable<JavaResourceMethod> allMethods) { - if (methodHasInvalidModifiers(resourceMethod)) { - return false; - } - if (resourceMethod.isConstructor()) { - return false; - } - - String returnTypeName = resourceMethod.getTypeBinding().getQualifiedName(); - if (returnTypeName == null) { - return false; // DOM method bindings can have a null name - } - if (returnTypeName.equals("void")) { //$NON-NLS-1$ - return false; - } - if (methodHasParameters(resourceMethod)) { - return false; - } - - boolean booleanGetter = methodIsBooleanGetter(resourceMethod); - - // if the type has both methods: - // boolean isProperty() - // boolean getProperty() - // then #isProperty() takes precedence and we ignore #getProperty(); - // but only having #getProperty() is OK too - // (see the JavaBeans spec 1.01) - if (booleanGetter && methodHasValidSiblingIsMethod(resourceMethod, allMethods)) { - return false; // since the type also defines #isProperty(), ignore #getProperty() - } - return true; - } - - private static boolean methodIsBooleanGetter(JavaResourceMethod resourceMethod) { - String returnTypeName = resourceMethod.getTypeBinding().getQualifiedName(); - String name = resourceMethod.getMethodName(); - boolean booleanGetter = false; - if (name.startsWith("is")) { //$NON-NLS-1$ - if (returnTypeName.equals("boolean")) { //$NON-NLS-1$ - } else { - return false; - } - } else if (name.startsWith("get")) { //$NON-NLS-1$ - if (returnTypeName.equals("boolean")) { //$NON-NLS-1$ - booleanGetter = true; - } - } else { - return false; - } - return booleanGetter; - } - - /** - * Return whether the method's modifiers prevent it - * from being a getter or setter for a "persistent" property. - */ - private static boolean methodHasInvalidModifiers(JavaResourceMethod resourceMethod) { - int modifiers = resourceMethod.getModifiers(); - if (Modifier.isStatic(modifiers)) { - return true; - } - return false; - } - - private static boolean methodHasParameters(JavaResourceMethod resourceMethod) { - return resourceMethod.getParametersSize() != 0; - } - - /** - * Return whether the method has a sibling "is" method for the specified - * property and that method is valid for a "persistable" property. - * Pre-condition: the method is a "boolean getter" (e.g. 'public boolean getProperty()'); - * this prevents us from returning true when the method itself is an - * "is" method. - */ - private static boolean methodHasValidSiblingIsMethod(JavaResourceMethod getMethod, Iterable<JavaResourceMethod> resourceMethods) { - String capitalizedAttributeName = StringTools.capitalize(getMethod.getName()); - for (JavaResourceMethod sibling : resourceMethods) { - if ((sibling.getParametersSize() == 0) - && sibling.getMethodName().equals("is" + capitalizedAttributeName)) { //$NON-NLS-1$ - return methodIsValidSibling(sibling, "boolean"); //$NON-NLS-1$ - } - } - return false; - } - - /** - * Return whether the method has a sibling "set" method - * and that method is valid for a "persistable" property. - */ - private static JavaResourceMethod getValidSiblingSetMethod(JavaResourceMethod getMethod, Collection<JavaResourceMethod> resourceMethods) { - String capitalizedSetAttributeName = "set" + StringTools.capitalize(getMethod.getName());//$NON-NLS-1$ - String parameterTypeErasureName = getMethod.getTypeBinding().getQualifiedName(); - for (JavaResourceMethod sibling : resourceMethods) { - if ((sibling.getParametersSize() == 1) - && sibling.getMethodName().equals(capitalizedSetAttributeName) - && sibling.getParameterTypeName(0).equals(parameterTypeErasureName)) { - return methodIsValidSibling(sibling, "void") ? sibling : null; //$NON-NLS-1$ - } - } - return null; - } - - /** - * Return whether the specified method is a valid sibling with the - * specified return type. - */ - private static boolean methodIsValidSibling(JavaResourceMethod resourceMethod, String returnTypeName) { - if (resourceMethod == null) { - return false; - } - if (methodHasInvalidModifiers(resourceMethod)) { - return false; - } - if (resourceMethod.isConstructor()) { - return false; - } - String rtName = resourceMethod.getTypeBinding().getQualifiedName(); - if (rtName == null) { - return false; // DOM method bindings can have a null name - } - return rtName.equals(returnTypeName); - } - // ********** validation ********** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java index 2a054c705f..9e7e6fb343 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java @@ -15,7 +15,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import org.eclipse.jpt.common.core.internal.utility.JDTTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.collection.Bag; @@ -641,9 +641,8 @@ public class GenericJavaClassMapping if (jaxbType.getMapping() != null && ! jaxbType.getMapping().isXmlTransient() && jaxbType.getMapping().getXmlRootElement() != null - && JDTTools.typeIsSubType( - getJaxbProject().getJavaProject(), - jaxbType.getTypeName().getFullyQualifiedName(), getJavaType().getTypeName().getFullyQualifiedName())) { + && TypeTools.isSubType( + jaxbType.getTypeName().getFullyQualifiedName(), getJavaType().getTypeName().getFullyQualifiedName(), getJaxbProject().getJavaProject())) { return true; } } @@ -677,21 +676,11 @@ public class GenericJavaClassMapping IterableTools.transform( getAllAttributes(), JaxbPersistentAttribute.MAPPING_TRANSFORMER), - XmlNamedNodeMapping.MAPPING_IS_NAMED_NODE_MAPPING)), - MAPPING_HAS_XML_ID).iterator(); + XmlNamedNodeMapping.IS_NAMED_NODE_MAPPING)), + XmlNamedNodeMapping.HAS_XML_ID).iterator(); return allXmlIdMappings.hasNext() ? allXmlIdMappings.next() : null; } - protected static final Predicate<XmlNamedNodeMapping> MAPPING_HAS_XML_ID = new MappingHasXmlID(); - public static class MappingHasXmlID - extends PredicateAdapter<XmlNamedNodeMapping> - { - @Override - public boolean evaluate(XmlNamedNodeMapping mapping) { - return mapping.getXmlID() != null; - } - } - protected Iterable<? extends JaxbAttributeMapping> getAttributeMappings() { return IterableTools.transform(getAttributes(), JaxbPersistentAttribute.MAPPING_TRANSFORMER); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java index e960f96486..27853d4f61 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElement.java @@ -10,7 +10,8 @@ package org.eclipse.jpt.jaxb.core.internal.context.java; import java.util.List; -import org.eclipse.jpt.common.core.internal.utility.JDTTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; +import org.eclipse.jpt.common.core.internal.utility.JavaProjectTools; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; @@ -376,10 +377,10 @@ public class GenericJavaXmlElement } if (! StringTools.isBlank(this.specifiedType) // verify that type actually exists before validating - && JDTTools.findType(getJaxbProject().getJavaProject(), fqType) != null) { + && JavaProjectTools.findType(getJaxbProject().getJavaProject(), fqType) != null) { String attributeBaseType = getAttributeMapping().getValueTypeName(); if (! StringTools.isBlank(attributeBaseType) // can be null if there is a setter with no getter - && ! JDTTools.typeIsSubType(getJaxbProject().getJavaProject(), fqType, attributeBaseType)) { + && ! TypeTools.isSubType(fqType, attributeBaseType, getJaxbProject().getJavaProject())) { messages.add( this.buildValidationMessage( getTypeTextRange(), diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java index d247a2e86f..dc60764bdb 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRef.java @@ -10,7 +10,8 @@ package org.eclipse.jpt.jaxb.core.internal.context.java; import java.util.List; -import org.eclipse.jpt.common.core.internal.utility.JDTTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; +import org.eclipse.jpt.common.core.internal.utility.JavaProjectTools; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.StringTools; @@ -248,9 +249,9 @@ public class GenericJavaXmlElementRef } else if (! StringTools.isBlank(this.specifiedType) // verify that type actually exists before validating - && JDTTools.findType(getJaxbProject().getJavaProject(), fqType) != null) { + && JavaProjectTools.findType(getJaxbProject().getJavaProject(), fqType) != null) { String attributeValueType = getContext().getAttributeMapping().getValueTypeName(); - if (! JDTTools.typeIsSubType(getJaxbProject().getJavaProject(), fqType, attributeValueType)) { + if (! TypeTools.isSubType(fqType, attributeValueType, getJaxbProject().getJavaProject())) { messages.add( this.buildValidationMessage( getTypeTextRange(), diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlRegistry.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlRegistry.java index e15f6faf42..7797378392 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlRegistry.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlRegistry.java @@ -119,19 +119,10 @@ public class GenericJavaXmlRegistry { @Override public boolean evaluate(JavaResourceMethod method) { - return methodIsElementFactoryMethod(method); + return method.getAnnotation(JAXB.XML_ELEMENT_DECL) != null; } } - // Return methods with XmlElementDecl annotation - protected static boolean methodIsElementFactoryMethod(JavaResourceMethod method) { - return methodHasXmlElementDeclAnnotation(method); - } - - protected static boolean methodHasXmlElementDeclAnnotation(JavaResourceMethod method) { - return method.getAnnotation(JAXB.XML_ELEMENT_DECL) != null; - } - protected static boolean methodReturnTypeIsJAXBElement(JavaResourceMethod method) { return method.getTypeBinding().isSubTypeOf(JAXB.XML_ELEMENT); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/gen/SchemaGenerator.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/gen/SchemaGenerator.java index 89a3152019..c5d7d0ec0a 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/gen/SchemaGenerator.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/gen/SchemaGenerator.java @@ -34,7 +34,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
-import org.eclipse.jpt.common.core.internal.utility.JDTTools;
+import org.eclipse.jpt.common.core.internal.utility.JavaProjectTools;
import org.eclipse.jpt.common.utility.internal.io.FileTools;
import org.eclipse.jpt.jaxb.core.JptJaxbCoreMessages;
@@ -186,7 +186,7 @@ public class SchemaGenerator extends AbstractJptGenerator * Returns null if no "jaxb.properties" file is found.
*/
private IFile getJaxbPropertiesFile() {
- return getJaxbPropertiesFileFromPackageRoots(JDTTools.getJavaSourceFolders(this.getJavaProject()));
+ return getJaxbPropertiesFileFromPackageRoots(JavaProjectTools.getSourceFolders(this.getJavaProject()));
}
private IFile getJaxbPropertiesFileFromPackageRoots(Iterable<IPackageFragmentRoot> packageFragmentRoots){
@@ -289,7 +289,7 @@ public class SchemaGenerator extends AbstractJptGenerator String packageName = sourceClassName.substring(0, sourceClassName.lastIndexOf('.'));
//Find the existing package fragment where we want to generate
- for (IPackageFragmentRoot pfr : JDTTools.getJavaSourceFolders(this.getJavaProject())) {
+ for (IPackageFragmentRoot pfr : JavaProjectTools.getSourceFolders(this.getJavaProject())) {
//use the package of the first source class as the package for generation
IPackageFragment packageFragment = pfr.getPackageFragment(packageName);
if (packageFragment.exists()){
@@ -305,7 +305,7 @@ public class SchemaGenerator extends AbstractJptGenerator }
private IPackageFragmentRoot getFirstJavaSourceFolder() {
- Iterator<IPackageFragmentRoot> i = JDTTools.getJavaSourceFolders(this.getJavaProject()).iterator();
+ Iterator<IPackageFragmentRoot> i = JavaProjectTools.getSourceFolders(this.getJavaProject()).iterator();
return i.hasNext() ? i.next() : null;
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/InternalJaxbPlatformManager.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/InternalJaxbPlatformManager.java index a2743f162e..04d3fa0922 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/InternalJaxbPlatformManager.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/InternalJaxbPlatformManager.java @@ -23,7 +23,7 @@ import org.eclipse.jpt.common.core.internal.utility.ConfigurationElementTools; import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.iterable.SuperIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter;
+import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate;
import org.eclipse.jpt.common.utility.predicate.Predicate;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JaxbWorkspace;
@@ -349,20 +349,17 @@ public class InternalJaxbPlatformManager }
private Predicate<JaxbPlatformConfig> buildInternalJaxbPlatformConfigFilter() {
- return new InternalJaxbPlatformConfigFilter(this.getPluginID());
+ return new FactoryClassNameStartsWith(this.getPluginID());
}
- /* CU private */ static class InternalJaxbPlatformConfigFilter
- extends PredicateAdapter<JaxbPlatformConfig>
+ /* CU private */ static class FactoryClassNameStartsWith
+ extends CriterionPredicate<JaxbPlatformConfig, String>
{
- private final String prefix;
- InternalJaxbPlatformConfigFilter(String prefix) {
- super();
- this.prefix = prefix;
+ FactoryClassNameStartsWith(String prefix) {
+ super(prefix);
}
- @Override
public boolean evaluate(JaxbPlatformConfig config) {
- return config.getFactoryClassName().startsWith(this.prefix);
+ return config.getFactoryClassName().startsWith(this.criterion);
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSchemaTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSchemaTypeAnnotation.java index 62dd540c8c..4cd33fb8a1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSchemaTypeAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSchemaTypeAnnotation.java @@ -13,7 +13,7 @@ import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation; -import org.eclipse.jpt.common.core.internal.utility.JDTTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.jaxb.core.resource.java.JAXB; @@ -120,7 +120,7 @@ public class BinaryXmlSchemaTypeAnnotation } private String buildFullyQualifiedType(IAnnotation jdtAnnotation) { - return JDTTools.resolveType((IType)jdtAnnotation.getAncestor(IJavaElement.TYPE), this.type); + return TypeTools.resolveType((IType)jdtAnnotation.getAncestor(IJavaElement.TYPE), this.type); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java index 66cb185f68..efd6abd5a8 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java @@ -100,11 +100,11 @@ public class JaxbValidator * specified in the preferences). */ private Iterable<IMessage> buildNonIgnoredValidationMessages(IReporter reporter, IProject project) { - return IterableTools.filter(this.buildValidationMessages(reporter, project), NON_IGNORED_MESSAGE); + return IterableTools.filter(this.buildValidationMessages(reporter, project), MESSAGE_IS_NOT_IGNORED); } - private static final Predicate<IMessage> NON_IGNORED_MESSAGE = new NonIgnoredMessage(); - /* CU private */ static class NonIgnoredMessage + private static final Predicate<IMessage> MESSAGE_IS_NOT_IGNORED = new MessageIsNotIgnored(); + /* CU private */ static class MessageIsNotIgnored extends PredicateAdapter<IMessage> { @Override diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/platform/JaxbPlatformConfig.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/platform/JaxbPlatformConfig.java index 16e2968528..72cca6799e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/platform/JaxbPlatformConfig.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/platform/JaxbPlatformConfig.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.core.platform; +import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate; import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.predicate.Predicate; @@ -79,16 +80,13 @@ public interface JaxbPlatformConfig { boolean supportsJaxbFacetVersion(IProjectFacetVersion jaxbFacetVersion); class SupportsJaxbFacetVersion - extends PredicateAdapter<JaxbPlatformConfig> + extends CriterionPredicate<JaxbPlatformConfig, IProjectFacetVersion> { - private final IProjectFacetVersion jaxbFacetVersion; public SupportsJaxbFacetVersion(IProjectFacetVersion jaxbFacetVersion) { - super(); - this.jaxbFacetVersion = jaxbFacetVersion; + super(jaxbFacetVersion); } - @Override public boolean evaluate(JaxbPlatformConfig config) { - return config.supportsJaxbFacetVersion(this.jaxbFacetVersion); + return config.supportsJaxbFacetVersion(this.criterion); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java index 95ca4c853b..94ccccf0f6 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdComplexTypeDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.jaxb.core.xsd; import java.util.ArrayList; import java.util.List; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; +import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.xsd.XSDAttributeUse; @@ -73,16 +73,13 @@ public class XsdComplexTypeDefinition } public static class AttributeUsesNamespace - extends PredicateAdapter<XSDAttributeUse> + extends CriterionPredicate<XSDAttributeUse, String> { - private final String namespace; public AttributeUsesNamespace(String namespace) { - super(); - this.namespace = namespace; + super(namespace); } - @Override public boolean evaluate(XSDAttributeUse attrUse) { - return XsdUtil.namespaceEquals(attrUse.getAttributeDeclaration(), this.namespace); + return XsdUtil.namespaceEquals(attrUse.getAttributeDeclaration(), this.criterion); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java index 4bb82a6a0b..0a055fc9da 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java @@ -96,7 +96,7 @@ public class XsdSchema protected Iterable<XSDSimpleTypeDefinition> getXSDSimpleTypeDefinitions(String namespace) { return IterableTools.downCast( - IterableTools.filter(getXSDTypeDefinitions(namespace), PredicateTools.<XSDTypeDefinition>instanceOfPredicate(XSDSimpleTypeDefinition.class))); + IterableTools.filter(getXSDTypeDefinitions(namespace), PredicateTools.<XSDTypeDefinition>instanceOf(XSDSimpleTypeDefinition.class))); } public Iterable<XsdElementDeclaration> getElementDeclarations() { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java index 4d13b6a367..54f146a58c 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdUtil.java @@ -22,7 +22,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; +import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.internal.plugin.JptJaxbCorePlugin; @@ -62,16 +62,13 @@ public class XsdUtil { } public static class NamespaceEquals - extends PredicateAdapter<XSDNamedComponent> + extends CriterionPredicate<XSDNamedComponent, String> { - private final String namespace; public NamespaceEquals(String namespace) { - super(); - this.namespace = namespace; + super(namespace); } - @Override public boolean evaluate(XSDNamedComponent component) { - return namespaceEquals(component, this.namespace); + return namespaceEquals(component, this.criterion); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELXmlNamedNodeMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELXmlNamedNodeMapping.java index 8adc1f4c0c..f92d05f9f7 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELXmlNamedNodeMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELXmlNamedNodeMapping.java @@ -9,7 +9,10 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.eclipselink.core.context; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.context.XmlNamedNodeMapping; @@ -54,6 +57,19 @@ public interface ELXmlNamedNodeMapping */ void removeXmlKey(); + Predicate<ELXmlNamedNodeMapping> HAS_XML_KEY = new HasXmlKey(); + class HasXmlKey + extends PredicateAdapter<ELXmlNamedNodeMapping> + { + @Override + public boolean evaluate(ELXmlNamedNodeMapping mapping) { + return mapping.getXmlKey() != null; + } + } + + @SuppressWarnings("unchecked") + Predicate<ELXmlNamedNodeMapping> HAS_KEY = PredicateTools.or(HAS_XML_KEY, HAS_XML_ID); + // ***** misc ***** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaClassMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaClassMapping.java index 92b0b63642..b2d32ca966 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaClassMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaClassMapping.java @@ -208,20 +208,10 @@ public class ELJavaClassMapping IterableTools.transform( getAllAttributes(), JaxbPersistentAttribute.MAPPING_TRANSFORMER), - XmlNamedNodeMapping.MAPPING_IS_NAMED_NODE_MAPPING)), - MAPPING_HAS_KEY); + XmlNamedNodeMapping.IS_NAMED_NODE_MAPPING)), + ELXmlNamedNodeMapping.HAS_KEY); } - protected static final Predicate<ELXmlNamedNodeMapping> MAPPING_HAS_KEY = new MappingHasKey(); - public static class MappingHasKey - extends PredicateAdapter<ELXmlNamedNodeMapping> - { - @Override - public boolean evaluate(ELXmlNamedNodeMapping mapping) { - return (mapping.getXmlID() != null) || (mapping.getXmlKey() != null); - } - } - // ***** content assist ***** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlElementRef.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlElementRef.java index 551ce2d57c..508dd2b298 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlElementRef.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlElementRef.java @@ -9,7 +9,7 @@ *******************************************************************************/ package org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java; -import org.eclipse.jpt.common.core.internal.utility.JDTTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.jaxb.core.context.JaxbContextNode; import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlElementRef; import org.eclipse.jpt.jaxb.core.resource.java.JAXB; @@ -26,6 +26,6 @@ public class ELJavaXmlElementRef @Override protected boolean isTypeJAXBElement() { String fqType = getFullyQualifiedType(); - return fqType != null && JDTTools.typeIsSubType(getJaxbProject().getJavaProject(), getFullyQualifiedType(), JAXB.JAXB_ELEMENT); + return fqType != null && TypeTools.isSubType(getFullyQualifiedType(), JAXB.JAXB_ELEMENT, getJaxbProject().getJavaProject()); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/navigator/ELJaxbPackageContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/navigator/ELJaxbPackageContentProvider.java index 7649b63ff2..3218f8d4a1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/navigator/ELJaxbPackageContentProvider.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/navigator/ELJaxbPackageContentProvider.java @@ -18,9 +18,9 @@ import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueMo import org.eclipse.jpt.common.utility.internal.model.value.ListCurator;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.predicate.Predicate;
import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.jaxb.core.context.TypeKind;
import org.eclipse.jpt.jaxb.core.context.java.JavaClass;
@@ -62,7 +62,7 @@ public class ELJaxbPackageContentProvider return this.subject.getOxmFile();
}
}),
- PredicateTools.notNullPredicate());
+ PredicateTools.isNotNull());
}
protected CollectionValueModel<JaxbContextNode> buildJavaTypeChildrenModel() {
@@ -74,25 +74,23 @@ public class ELJaxbPackageContentProvider return new SuperIterableWrapper<JaxbContextNode>(
IterableTools.filter(
this.subject.getJavaTypes(ELJaxbPackageContentProvider.this.item),
- new JavaTypeFilter(contextRoot))).iterator();
+ new IsJavaType(contextRoot))).iterator();
}
});
}
- protected class JavaTypeFilter
- implements Predicate<JavaType> {
+ public static class IsJavaType
+ extends CriterionPredicate<JavaType, ELJaxbContextRoot> {
- private final ELJaxbContextRoot contextRoot;
-
- protected JavaTypeFilter(ELJaxbContextRoot contextRoot) {
- this.contextRoot = contextRoot;
+ public IsJavaType(ELJaxbContextRoot contextRoot) {
+ super(contextRoot);
}
public boolean evaluate(JavaType o) {
String typeName = o.getTypeName().getFullyQualifiedName();
// TODO xml-registry, xml-java-type-adapter
JavaTypeMapping typeMapping = o.getMapping();
- if (typeMapping != null && contextRoot.getTypeMapping(typeName) == typeMapping) {
+ if (typeMapping != null && this.criterion.getTypeMapping(typeName) == typeMapping) {
return true;
}
if (o.getXmlJavaTypeAdapter() != null) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java index 1de957914b..db35a1e76d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java @@ -28,7 +28,7 @@ import org.eclipse.jpt.common.core.internal.utility.PlatformTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; -import org.eclipse.jpt.common.utility.internal.predicate.TruePredicate; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.jaxb.core.JaxbProject; import org.eclipse.jpt.jaxb.core.JaxbProjectManager; @@ -204,20 +204,7 @@ public class JaxbJavaCompletionProposalComputer private Predicate<String> buildPrefixFilter(char[] prefix) { return (prefix == null) ? - TruePredicate.<String>instance() : - new IgnoreCasePrefixFilter(prefix); - } - - private static class IgnoreCasePrefixFilter - implements Predicate<String> - { - private final String prefix; - IgnoreCasePrefixFilter(char[] prefix) { - super(); - this.prefix = new String(prefix); - } - public boolean evaluate(String s) { - return StringTools.startsWithIgnoreCase(s, this.prefix); - } + PredicateTools.<String>true_() : + new StringTools.StartsWithIgnoreCase(new String(prefix)); } } |