diff options
author | Brian Vosburgh | 2013-01-28 20:16:59 +0000 |
---|---|---|
committer | Brian Vosburgh | 2013-01-28 21:15:19 +0000 |
commit | 1a911cb6ed7c832339ea3e14dc5ade7b8dcf0810 (patch) | |
tree | 64b1e4638717aca1ab0336af8558922e51b569a3 /jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb | |
parent | f7b7e7ff48ae689d470a51e42473d01bebdf4ec8 (diff) | |
download | webtools.dali-1a911cb6ed7c832339ea3e14dc5ade7b8dcf0810.tar.gz webtools.dali-1a911cb6ed7c832339ea3e14dc5ade7b8dcf0810.tar.xz webtools.dali-1a911cb6ed7c832339ea3e14dc5ade7b8dcf0810.zip |
clean up utility classes (iterables and iterators in particular); add
lots of Transformers
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb')
27 files changed, 547 insertions, 503 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 a3e133a33d..8892a001df 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2013 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. @@ -12,6 +12,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.JptResourceModel; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; /** * A JAXB Project contains JAXB files for all files in the project that @@ -44,7 +46,16 @@ public interface JaxbFile * compilation unit, a JPA XML resource, or a JPA package fragment root (JAR). */ JptResourceModel getResourceModel(); - + Transformer<JaxbFile, JptResourceModel> RESOURCE_MODEL_TRANSFORMER = new ResourceModelTransformer(); + class ResourceModelTransformer + extends TransformerAdapter<JaxbFile, JptResourceModel> + { + @Override + public JptResourceModel transform(JaxbFile jaxbFile) { + return jaxbFile.getResourceModel(); + } + } + /** * Convenience method. Return the resource model corresponding to the JPA * file if the file's content is a "kind-of" the specified content type; diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/SchemaEntry.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/SchemaEntry.java index df2686c56c..e77025360e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/SchemaEntry.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/SchemaEntry.java @@ -1,5 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 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.jaxb.core; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.xsd.XsdSchema; /** @@ -25,11 +36,29 @@ public interface SchemaEntry { * - a namespace */ String getLocation(); + Transformer<SchemaEntry, String> LOCATION_TRANSFORMER = new LocationTransformer(); + class LocationTransformer + extends TransformerAdapter<SchemaEntry, String> + { + @Override + public String transform(SchemaEntry schemaEntry) { + return schemaEntry.getLocation(); + } + } /** * Return the namespace of the schema */ String getNamespace(); + Transformer<SchemaEntry, String> NAMESPACE_TRANSFORMER = new NamespaceTransformer(); + class NamespaceTransformer + extends TransformerAdapter<SchemaEntry, String> + { + @Override + public String transform(SchemaEntry schemaEntry) { + return schemaEntry.getNamespace(); + } + } /** * Return whether the schema referred to by the entry is loaded diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributeMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributeMapping.java index 6f93697e3a..90fd260fdb 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributeMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributeMapping.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context; import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.xsd.XsdTypeDefinition; @@ -78,6 +80,15 @@ public interface JaxbAttributeMapping * (Used for constructing Jaxb context) */ Iterable<String> getReferencedXmlTypeNames(); + Transformer<JaxbAttributeMapping, Iterable<String>> REFERENCED_XML_TYPE_NAMES_TRANSFORMER = new ReferencedXmlTypeNamesTransformer(); + class ReferencedXmlTypeNamesTransformer + extends TransformerAdapter<JaxbAttributeMapping, Iterable<String>> + { + @Override + public Iterable<String> transform(JaxbAttributeMapping mapping) { + return mapping.getReferencedXmlTypeNames(); + } + } /** * Return whether the attribute is mapped to a particle diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java index ae5d3abb8f..8c9637986b 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbAttributesContainer.java @@ -1,14 +1,17 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; + /** * Holds the attributes represented by a particular JavaResourceType and XmlAccessType. * <p> @@ -27,6 +30,15 @@ public interface JaxbAttributesContainer // ***** attributes ***** Iterable<JaxbPersistentAttribute> getAttributes(); + Transformer<JaxbAttributesContainer, Iterable<JaxbPersistentAttribute>> ATTRIBUTES_TRANSFORMER = new AttributesTransformer(); + class AttributesTransformer + extends TransformerAdapter<JaxbAttributesContainer, Iterable<JaxbPersistentAttribute>> + { + @Override + public Iterable<JaxbPersistentAttribute> transform(JaxbAttributesContainer container) { + return container.getAttributes(); + } + } int getAttributesSize(); diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java index f047fb25c6..34634828ee 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbClassMapping.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context; +import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; import org.eclipse.jpt.common.utility.iterable.ListIterable; +import org.eclipse.jpt.common.utility.transformer.Transformer; public interface JaxbClassMapping @@ -68,6 +70,16 @@ public interface JaxbClassMapping String SUPERCLASS_PROPERTY = "superclass"; //$NON-NLS-1$ JaxbClassMapping getSuperclass(); + + Transformer<JaxbClassMapping, JaxbClassMapping> SUPER_CLASS_TRANSFORMER = new SuperClassTransformer(); + class SuperClassTransformer + extends AbstractTransformer<JaxbClassMapping, JaxbClassMapping> + { + @Override + protected JaxbClassMapping transform_(JaxbClassMapping mapping) { + return mapping.getSuperclass(); + } + } // ***** attributes ***** @@ -76,6 +88,16 @@ public interface JaxbClassMapping * Return the attributes defined on this class (not its superclass) */ Iterable<JaxbPersistentAttribute> getAttributes(); + + Transformer<JaxbClassMapping, Iterable<JaxbPersistentAttribute>> ATTRIBUTES_TRANSFORMER = new AttributesTransformer(); + class AttributesTransformer + extends AbstractTransformer<JaxbClassMapping, Iterable<JaxbPersistentAttribute>> + { + @Override + protected Iterable<JaxbPersistentAttribute> transform_(JaxbClassMapping mapping) { + return mapping.getAttributes(); + } + } int getAttributesSize(); diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java index a0014c35a5..bb5dea6f20 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPackage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Oracle. All rights reserved. + * Copyright (c) 2010, 2013 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. @@ -9,6 +9,8 @@ ******************************************************************************/ package org.eclipse.jpt.jaxb.core.context; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.xsd.XsdSchema; /** @@ -31,6 +33,15 @@ public interface JaxbPackage * This is unchanging in that, if a package name changes, a new JaxbPackage is created. */ String getName(); + Transformer<JaxbPackage, String> NAME_TRANSFORMER = new NameTransformer(); + class NameTransformer + extends TransformerAdapter<JaxbPackage, String> + { + @Override + public String transform(JaxbPackage table) { + return table.getName(); + } + } /** * The optional package-info diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java index 161abde362..4db23915f0 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/JaxbPersistentAttribute.java @@ -1,18 +1,20 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context; import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; import org.eclipse.jpt.common.core.resource.java.JavaResourceField; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; /** * Represents a JAXB attribute (field/property). @@ -53,6 +55,15 @@ public interface JaxbPersistentAttribute * new JaxbPersistentAttribute will be built if the name changes. */ String getName(); + Transformer<JaxbPersistentAttribute, String> NAME_TRANSFORMER = new NameTransformer(); + class NameTransformer + extends TransformerAdapter<JaxbPersistentAttribute, String> + { + @Override + public String transform(JaxbPersistentAttribute attribute) { + return attribute.getName(); + } + } // ***** resource attribute ***** @@ -87,10 +98,19 @@ public interface JaxbPersistentAttribute /** * Return the attribute's mapping. This is never <code>null</code> * (although, it may be a <em>null</em> mapping). - * Set the mapping via {@link PersistentAttribute#setMappingKey(String)}. + * Set the mapping via {@link #setMappingKey(String)}. */ JaxbAttributeMapping getMapping(); String MAPPING_PROPERTY = "mapping"; //$NON-NLS-1$ + Transformer<JaxbPersistentAttribute, JaxbAttributeMapping> MAPPING_TRANSFORMER = new MappingTransformer(); + class MappingTransformer + extends TransformerAdapter<JaxbPersistentAttribute, JaxbAttributeMapping> + { + @Override + public JaxbAttributeMapping transform(JaxbPersistentAttribute attribute) { + return attribute.getMapping(); + } + } /** * Return the attribute's mapping key. diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElement.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElement.java index c14627b9b5..bb7caab240 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElement.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElement.java @@ -1,16 +1,20 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context; import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; +import org.eclipse.jpt.jaxb.core.resource.jaxbindex.JaxbIndexResource; +import org.eclipse.jpt.jaxb.core.resource.jaxbindex.JaxbIndexResource.ClassNamesTransformer; import org.eclipse.jpt.jaxb.core.xsd.XsdElementDeclaration; /** @@ -99,6 +103,15 @@ public interface XmlElement * (Used for constructing Jaxb context) */ Iterable<String> getReferencedXmlTypeNames(); + Transformer<XmlElement, Iterable<String>> REFERENCED_XML_TYPE_NAMES_TRANSFORMER = new ReferencedXmlTypeNamesTransformer(); + class ReferencedXmlTypeNamesTransformer + extends TransformerAdapter<XmlElement, Iterable<String>> + { + @Override + public Iterable<String> transform(XmlElement xmlElement) { + return xmlElement.getReferencedXmlTypeNames(); + } + } /** * Return the schema element declaration referenced, if it can be resolved. diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElementRef.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElementRef.java index 2ea999d044..310316ac3b 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElementRef.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlElementRef.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context; import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation; /** @@ -74,6 +76,15 @@ public interface XmlElementRef * (Used for constructing Jaxb context) */ Iterable<String> getReferencedXmlTypeNames(); + Transformer<XmlElementRef, Iterable<String>> REFERENCED_XML_TYPE_NAMES_TRANSFORMER = new ReferencedXmlTypeNamesTransformer(); + class ReferencedXmlTypeNamesTransformer + extends TransformerAdapter<XmlElementRef, Iterable<String>> + { + @Override + public Iterable<String> transform(XmlElementRef ref) { + return ref.getReferencedXmlTypeNames(); + } + } // ***** validation ***** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaClass.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaClass.java index 08e60052d3..a2bc4e143b 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaClass.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/java/JavaClass.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.context.java; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.context.XmlRegistry; /** @@ -39,4 +41,13 @@ public interface JavaClass String XML_REGISTRY_PROPERTY = "xmlRegistry"; //$NON-NLS-1$ XmlRegistry getXmlRegistry(); + Transformer<JavaClass, XmlRegistry> XML_REGISTRY_TRANSFORMER = new XmlRegistryTransformer(); + class XmlRegistryTransformer + extends TransformerAdapter<JavaClass, XmlRegistry> + { + @Override + public XmlRegistry transform(JavaClass javaClass) { + return javaClass.getXmlRegistry(); + } + } } 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 bab7f442b5..f9fc83d231 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 @@ -14,7 +14,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.Vector; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -55,14 +54,14 @@ import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.BitTools; import org.eclipse.jpt.common.utility.internal.command.ThreadLocalExtendedCommandExecutor; -import org.eclipse.jpt.common.utility.internal.filter.NotNullFilter; -import org.eclipse.jpt.common.utility.internal.iterable.ArrayIterable; import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; +import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneIterable; import org.eclipse.jpt.common.utility.internal.iterable.SnapshotCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.JaxbFile; import org.eclipse.jpt.jaxb.core.JaxbProject; import org.eclipse.jpt.jaxb.core.SchemaLibrary; @@ -594,16 +593,16 @@ public abstract class AbstractJaxbProject if (contentType.isKindOf(JavaResourceCompilationUnit.PACKAGE_INFO_CONTENT_TYPE)) { try { - return new FilteringIterable<JaxbPackageInfo>( - new TransformationIterable<IPackageDeclaration, JaxbPackageInfo>( - new ArrayIterable<IPackageDeclaration>(cu.getPackageDeclarations())) { - @Override - protected JaxbPackageInfo transform(IPackageDeclaration o) { - JaxbPackage jaxbPackage = getContextRoot().getPackage(o.getElementName()); - return (jaxbPackage != null) ? jaxbPackage.getPackageInfo() : null; - } - }, - NotNullFilter.<JaxbPackageInfo>instance()); + Transformer<IPackageDeclaration, JaxbPackageInfo> transformer = new TransformerAdapter<IPackageDeclaration, JaxbPackageInfo>() { + @Override + public JaxbPackageInfo transform(IPackageDeclaration o) { + JaxbPackage jaxbPackage = getContextRoot().getPackage(o.getElementName()); + return (jaxbPackage != null) ? jaxbPackage.getPackageInfo() : null; + } + }; + return IterableTools.notNulls( + IterableTools.transform( + IterableTools.iterable(cu.getPackageDeclarations()), transformer)); } catch (JavaModelException jme) { return EmptyIterable.instance(); @@ -611,16 +610,15 @@ public abstract class AbstractJaxbProject } else if (contentType.isKindOf(JavaResourceCompilationUnit.CONTENT_TYPE)) { try { - return new FilteringIterable<JavaType>( - new TransformationIterable<IType, JavaType>( - new ArrayIterable<IType>(cu.getAllTypes())) { - @Override - protected JavaType transform(IType o) { - JavaType jaxbType = getContextRoot().getJavaType(o.getFullyQualifiedName('.')); - return jaxbType; - } - }, - NotNullFilter.<JavaType>instance()); + Transformer<IType, JavaType> transformer = new TransformerAdapter<IType, JavaType>() { + @Override + public JavaType transform(IType o) { + return getContextRoot().getJavaType(o.getFullyQualifiedName('.')); + } + }; + return IterableTools.notNulls( + IterableTools.transform( + IterableTools.iterable(cu.getAllTypes()), transformer)); } catch (JavaModelException jme) { return EmptyIterable.instance(); @@ -673,7 +671,7 @@ public abstract class AbstractJaxbProject // ********** annotated Java source classes ********** public Iterable<JavaResourceAbstractType> getJavaSourceResourceTypes() { - return new CompositeIterable<JavaResourceAbstractType>(this.getInternalJavaSourceResourceTypeSets()); + return IterableTools.compositeIterable(this.getInternalJavaResourceCompilationUnits(), JavaResourceNode.Root.TYPES_TRANSFORMER); } public Iterable<JavaResourceAbstractType> getAnnotatedJavaSourceResourceTypes() { @@ -694,28 +692,10 @@ public abstract class AbstractJaxbProject // }; // } - /* - * Return the sets of {@link JavaResourceType}s that are represented by java source within this project - */ - protected Iterable<Iterable<JavaResourceAbstractType>> getInternalJavaSourceResourceTypeSets() { - return new TransformationIterable<JavaResourceCompilationUnit, Iterable<JavaResourceAbstractType>>( - this.getInternalJavaResourceCompilationUnits()) { - @Override - protected Iterable<JavaResourceAbstractType> transform(JavaResourceCompilationUnit compilationUnit) { - return compilationUnit.getTypes(); - } - }; - } - protected Iterable<JavaResourceCompilationUnit> getInternalJavaResourceCompilationUnits() { - return new TransformationIterable<JaxbFile, JavaResourceCompilationUnit>(this.getJavaSourceJaxbFiles()) { - @Override - protected JavaResourceCompilationUnit transform(JaxbFile jaxbFile) { - return (JavaResourceCompilationUnit) jaxbFile.getResourceModel(); - } - }; + return IterableTools.subIterable(IterableTools.transform(this.getJavaSourceJaxbFiles(), JaxbFile.RESOURCE_MODEL_TRANSFORMER)); } - + /** * return JAXB files with Java source "content" */ @@ -726,20 +706,14 @@ public abstract class AbstractJaxbProject // ********** Java resource package look-up ********** - public Iterable<JavaResourcePackage> getJavaResourcePackages(){ - return new FilteringIterable<JavaResourcePackage>( - new TransformationIterable<JaxbFile, JavaResourcePackage>(this.getPackageInfoSourceJaxbFiles()) { - @Override - protected JavaResourcePackage transform(JaxbFile jaxbFile) { - return ((JavaResourcePackageInfoCompilationUnit) jaxbFile.getResourceModel()).getPackage(); - } - }) { - + public Iterable<JavaResourcePackage> getJavaResourcePackages() { + Transformer<JaxbFile, JavaResourcePackage> transformer = new TransformerAdapter<JaxbFile, JavaResourcePackage>() { @Override - protected boolean accept(JavaResourcePackage resourcePackage) { - return resourcePackage != null; + public JavaResourcePackage transform(JaxbFile jaxbFile) { + return ((JavaResourcePackageInfoCompilationUnit) jaxbFile.getResourceModel()).getPackage(); } }; + return IterableTools.notNulls(IterableTools.transform(this.getPackageInfoSourceJaxbFiles(), transformer)); } public JavaResourcePackage getJavaResourcePackage(String packageName) { @@ -795,17 +769,7 @@ public abstract class AbstractJaxbProject } protected Iterable<JavaResourceAbstractType> getJavaResourceTypes() { - return new CompositeIterable<JavaResourceAbstractType>(this.getJavaResourceTypeSets()); - } - - protected Iterable<Iterable<JavaResourceAbstractType>> getJavaResourceTypeSets() { - return new TransformationIterable<JavaResourceNode.Root, Iterable<JavaResourceAbstractType>>( - this.getJavaResourceNodeRoots()) { - @Override - protected Iterable<JavaResourceAbstractType> transform(JavaResourceNode.Root root) { - return root.getTypes(); - } - }; + return IterableTools.compositeIterable(this.getJavaResourceNodeRoots(), JavaResourceNode.Root.TYPES_TRANSFORMER); } @SuppressWarnings("unchecked") @@ -911,12 +875,7 @@ public abstract class AbstractJaxbProject // **************** jaxb.index resources ********************************** public Iterable<JaxbIndexResource> getJaxbIndexResources() { - return new TransformationIterable<JaxbFile, JaxbIndexResource>(getJaxbFiles(JaxbIndexResource.CONTENT_TYPE)) { - @Override - protected JaxbIndexResource transform(JaxbFile o) { - return (JaxbIndexResource) o.getResourceModel(); - } - }; + return IterableTools.subIterable(IterableTools.transform(getJaxbFiles(JaxbIndexResource.CONTENT_TYPE), JaxbFile.RESOURCE_MODEL_TRANSFORMER)); } public JaxbIndexResource getJaxbIndexResource(String packageName) { @@ -932,12 +891,7 @@ public abstract class AbstractJaxbProject // **************** jaxb.properties resources ***************************** public Iterable<JaxbPropertiesResource> getJaxbPropertiesResources() { - return new TransformationIterable<JaxbFile, JaxbPropertiesResource>(getJaxbFiles(JaxbPropertiesResource.CONTENT_TYPE)) { - @Override - protected JaxbPropertiesResource transform(JaxbFile o) { - return (JaxbPropertiesResource) o.getResourceModel(); - } - }; + return IterableTools.subIterable(IterableTools.transform(getJaxbFiles(JaxbPropertiesResource.CONTENT_TYPE), JaxbFile.RESOURCE_MODEL_TRANSFORMER)); } public JaxbPropertiesResource getJaxbPropertiesResource(String packageName) { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/SchemaLibraryImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/SchemaLibraryImpl.java index b5f9b62edb..d1d3768bee 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/SchemaLibraryImpl.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/SchemaLibraryImpl.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 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 - *******************************************************************************/ + * Copyright (c) 2010, 2013 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.jaxb.core.internal; import java.util.Collections; @@ -19,7 +19,7 @@ import org.eclipse.jpt.common.utility.collection.Bag; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.collection.HashBag; import org.eclipse.jpt.common.utility.internal.collection.ListTools; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.jaxb.core.JaxbPreferences; import org.eclipse.jpt.jaxb.core.JaxbProject; import org.eclipse.jpt.jaxb.core.SchemaEntry; @@ -55,12 +55,7 @@ public class SchemaLibraryImpl public List<String> getSchemaLocations() { return Collections.unmodifiableList( ListTools.list( - new TransformationIterable<SchemaEntry, String>(this.schemaEntries) { - @Override - protected String transform(SchemaEntry o) { - return o.getLocation(); - } - })); + IterableTools.transform(this.schemaEntries, SchemaEntry.LOCATION_TRANSFORMER))); } public void setSchemaLocations(List<String> schemaLocations) { 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 6d7305a5aa..e53e34de86 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Oracle. All rights reserved. + * Copyright (c) 2010, 2013 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. @@ -23,13 +23,12 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceType; 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.filter.NotNullFilter; -import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; +import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneIterable; import org.eclipse.jpt.common.utility.internal.iterable.SnapshotCloneIterable; import org.eclipse.jpt.common.utility.internal.iterable.SubIterableWrapper; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.jaxb.core.JaxbProject; import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; import org.eclipse.jpt.jaxb.core.context.JaxbPackage; @@ -218,13 +217,7 @@ public abstract class AbstractJaxbContextRoot */ protected Set<String> calculateInitialPackageNames() { return CollectionTools.set( - new TransformationIterable<JavaResourcePackage, String>( - getJaxbProject().getAnnotatedJavaResourcePackages()) { - @Override - protected String transform(JavaResourcePackage o) { - return o.getName(); - } - }); + IterableTools.transform(getJaxbProject().getAnnotatedJavaResourcePackages(), JavaResourcePackage.NAME_TRANSFORMER)); } /** @@ -272,23 +265,25 @@ public abstract class AbstractJaxbContextRoot }); CollectionTools.addAll( set, - new FilteringIterable<JavaResourceAbstractType>( - new TransformationIterable<String, JavaResourceAbstractType>( - new CompositeIterable<String>( - new TransformationIterable<JaxbIndexResource, Iterable<String>>(getJaxbProject().getJaxbIndexResources()) { - @Override - protected Iterable<String>transform(JaxbIndexResource o) { - return o.getFullyQualifiedClassNames(); - } - })) { - @Override - protected JavaResourceAbstractType transform(String o) { - return getJaxbProject().getJavaResourceType(o); - } - }, - NotNullFilter.<JavaResourceAbstractType>instance())); + IterableTools.notNulls( + IterableTools.transform( + IterableTools.compositeIterable( + getJaxbProject().getJaxbIndexResources(), JaxbIndexResource.CLASS_NAMES_TRANSFORMER + ), + new JavaResourceTypeTransformer() + ) + ) + ); return set; } + protected class JavaResourceTypeTransformer + extends TransformerAdapter<String, JavaResourceAbstractType> + { + @Override + public JavaResourceAbstractType transform(String typeName) { + return getJaxbProject().getJavaResourceType(typeName); + } + } protected void processType(JavaResourceAbstractType resourceType, Set<String> typesToUpdate, boolean defaultMapped) { TypeKind jaxbTypeKind = calculateJaxbTypeKind(resourceType); @@ -495,14 +490,9 @@ public abstract class AbstractJaxbContextRoot } public Iterable<XmlRegistry> getXmlRegistries(JaxbPackage jaxbPackage) { - return new FilteringIterable<XmlRegistry>( - new TransformationIterable<JavaClass, XmlRegistry>(getJavaClasses(jaxbPackage)) { - @Override - protected XmlRegistry transform(JavaClass o) { - return o.getXmlRegistry(); - } - }, - NotNullFilter.INSTANCE); + return IterableTools.notNulls( + IterableTools.transform(getJavaClasses(jaxbPackage), JavaClass.XML_REGISTRY_TRANSFORMER) + ); } public JavaTypeMapping getTypeMapping(String typeName) { 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 d2bfe49d75..71b3ee2a78 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 @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.internal.context.java; import java.util.HashSet; @@ -21,7 +21,6 @@ import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.collection.Bag; 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.ChainIterable; import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.EmptyListIterable; @@ -30,7 +29,6 @@ import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneIterable; import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable; import org.eclipse.jpt.common.utility.internal.iterable.SubIterableWrapper; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; import org.eclipse.jpt.common.utility.iterable.ListIterable; import org.eclipse.jpt.jaxb.core.MappingKeys; import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping; @@ -500,17 +498,7 @@ public class GenericJavaClassMapping // ***** included attributes ***** public Iterable<JaxbPersistentAttribute> getIncludedAttributes() { - return new CompositeIterable<JaxbPersistentAttribute>(getIncludedAttributeSets()); - } - - protected Iterable<Iterable<JaxbPersistentAttribute>> getIncludedAttributeSets() { - return new TransformationIterable<JaxbAttributesContainer, Iterable<JaxbPersistentAttribute>>( - getIncludedAttributesContainers()) { - @Override - protected Iterable<JaxbPersistentAttribute> transform(JaxbAttributesContainer attributesContainer) { - return attributesContainer.getAttributes(); - } - }; + return IterableTools.compositeIterable(getIncludedAttributesContainers(), JaxbAttributesContainer.ATTRIBUTES_TRANSFORMER); } protected Iterable<JaxbAttributesContainer> getIncludedAttributesContainers() { @@ -611,19 +599,9 @@ public class GenericJavaClassMapping * return those inherited attributes that are not included */ protected Iterable<JaxbPersistentAttribute> getOtherInheritedAttributes() { - return new CompositeIterable<JaxbPersistentAttribute>( - new TransformationIterable<JaxbClassMapping, Iterable<JaxbPersistentAttribute>>( - new ChainIterable<JaxbClassMapping>(getSuperclass()) { - @Override - protected JaxbClassMapping nextLink(JaxbClassMapping currentLink) { - return currentLink.getSuperclass(); - } - }) { - @Override - protected Iterable<JaxbPersistentAttribute> transform(JaxbClassMapping o) { - return o.getAttributes(); - } - }); + return IterableTools.compositeIterable( + IterableTools.chainIterable(getSuperclass(), JaxbClassMapping.SUPER_CLASS_TRANSFORMER), + JaxbClassMapping.ATTRIBUTES_TRANSFORMER); } @@ -671,14 +649,8 @@ public class GenericJavaClassMapping protected Iterable<String> getNonTransientReferencedXmlTypeNames() { return new CompositeIterable<String>( super.getNonTransientReferencedXmlTypeNames(), - new SingleElementIterable(this.superclassName), - new CompositeIterable<String>( - new TransformationIterable<JaxbPersistentAttribute, Iterable<String>>(getAttributes()) { - @Override - protected Iterable<String> transform(JaxbPersistentAttribute o) { - return o.getMapping().getReferencedXmlTypeNames(); - } - })); + new SingleElementIterable<String>(this.superclassName), + IterableTools.compositeIterable(getAttributeMappings(), JaxbAttributeMapping.REFERENCED_XML_TYPE_NAMES_TRANSFORMER)); } public JaxbAttributeMapping getXmlIdMapping() { @@ -686,12 +658,7 @@ public class GenericJavaClassMapping new FilteringIterable<XmlNamedNodeMapping>( new SubIterableWrapper<JaxbAttributeMapping, XmlNamedNodeMapping>( new FilteringIterable<JaxbAttributeMapping>( - new TransformationIterable<JaxbPersistentAttribute, JaxbAttributeMapping>(getAllAttributes()) { - @Override - protected JaxbAttributeMapping transform(JaxbPersistentAttribute o) { - return o.getMapping(); - } - }) { + IterableTools.transform(getAllAttributes(), JaxbPersistentAttribute.MAPPING_TRANSFORMER)) { @Override protected boolean accept(JaxbAttributeMapping o) { return (o.getKey() == MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY @@ -707,12 +674,7 @@ public class GenericJavaClassMapping } protected Iterable<? extends JaxbAttributeMapping> getAttributeMappings() { - return new TransformationIterable<JaxbPersistentAttribute, JaxbAttributeMapping>(getAttributes()) { - @Override - protected JaxbAttributeMapping transform(JaxbPersistentAttribute attribute) { - return attribute.getMapping(); - } - }; + return IterableTools.transform(getAttributes(), JaxbPersistentAttribute.MAPPING_TRANSFORMER); } @@ -743,13 +705,10 @@ public class GenericJavaClassMapping } protected Iterable<String> getPropProposals() { - return new TransformationIterable<String, String>( - new TransformationIterable<JaxbPersistentAttribute, String>(getAllLocallyDefinedAttributes()) { - @Override - protected String transform(JaxbPersistentAttribute o) { - return o.getName(); - } - }, + return IterableTools.transform( + IterableTools.transform( + getAllLocallyDefinedAttributes(), + JaxbPersistentAttribute.NAME_TRANSFORMER), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefs.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefs.java index e62371a176..9a0f91e345 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefs.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementRefs.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.internal.context.java; import java.util.List; @@ -15,10 +15,8 @@ import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.collection.Bag; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.collection.HashBag; -import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; import org.eclipse.jpt.common.utility.iterable.ListIterable; import org.eclipse.jpt.jaxb.core.context.JaxbContextNode; import org.eclipse.jpt.jaxb.core.context.XmlElementRef; @@ -193,13 +191,7 @@ public class GenericJavaXmlElementRefs // ***** misc ***** public Iterable<String> getReferencedXmlTypeNames() { - return new CompositeIterable<String>( - new TransformationIterable<XmlElementRef, Iterable<String>>(getXmlElementRefs()) { - @Override - protected Iterable<String> transform(XmlElementRef xmlElementRef) { - return xmlElementRef.getReferencedXmlTypeNames(); - } - }); + return IterableTools.compositeIterable(getXmlElementRefs(), XmlElementRef.REFERENCED_XML_TYPE_NAMES_TRANSFORMER); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementsMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementsMapping.java index 13ef33817e..a8b6ec379e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementsMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlElementsMapping.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.internal.context.java; import java.util.List; @@ -19,7 +19,9 @@ import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.iterable.ListIterable; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.MappingKeys; import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping; import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; @@ -36,7 +38,7 @@ import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlElementsAnnotation; import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; -import org.eclipse.jpt.jaxb.core.xsd.XsdFeature; +import org.eclipse.jpt.jaxb.core.xsd.XsdElementDeclaration; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -268,15 +270,9 @@ public class GenericJavaXmlElementsMapping @Override public Iterable<String> getReferencedXmlTypeNames() { - return new CompositeIterable<String>( + return IterableTools.compositeIterable( super.getReferencedXmlTypeNames(), - new CompositeIterable<String>( - new TransformationIterable<XmlElement, Iterable<String>>(getXmlElements()) { - @Override - protected Iterable<String> transform(XmlElement o) { - return o.getReferencedXmlTypeNames(); - } - })); + IterableTools.compositeIterable(getXmlElements(), XmlElement.REFERENCED_XML_TYPE_NAMES_TRANSFORMER)); } @Override @@ -465,36 +461,45 @@ public class GenericJavaXmlElementsMapping } public Iterable<ValidatableReference> getReferences() { - return new TransformationIterable<XmlElement, ValidatableReference>( - GenericJavaXmlElementsMapping.this.getXmlElements()) { - - @Override - protected ValidatableReference transform(final XmlElement o) { - - return new ValidatableReference() { - - public String getFullyQualifiedType() { - return o.getFullyQualifiedType(); - } - - public TextRange getTypeTextRange() { - return o.getTypeTextRange(); - } - - public XsdFeature getXsdFeature() { - return o.getXsdElement(); - } - - public TextRange getXsdFeatureTextRange() { - return o.getQName().getNameTextRange(); - } - }; - } - }; + return IterableTools.transform(GenericJavaXmlElementsMapping.this.getXmlElements(), XML_ELEMENT_TRANSFORMER); } public boolean isList() { return false; } } + protected static final Transformer<XmlElement, ValidatableReference> XML_ELEMENT_TRANSFORMER = new XmlElementTransformer(); + public static class XmlElementTransformer + extends TransformerAdapter<XmlElement, ValidatableReference> + { + @Override + public ValidatableReference transform(XmlElement xmlElement) { + return new XmlElementValidatableReference(xmlElement); + } + } + + public static class XmlElementValidatableReference + implements ValidatableReference + { + protected final XmlElement xmlElement; + public XmlElementValidatableReference(XmlElement xmlElement) { + super(); + this.xmlElement = xmlElement; + } + public String getFullyQualifiedType() { + return this.xmlElement.getFullyQualifiedType(); + } + + public TextRange getTypeTextRange() { + return this.xmlElement.getTypeTextRange(); + } + + public XsdElementDeclaration getXsdFeature() { + return this.xmlElement.getXsdElement(); + } + + public TextRange getXsdFeatureTextRange() { + return this.xmlElement.getQName().getNameTextRange(); + } + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java index 5b431aa447..a0b95fd845 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Oracle. All rights reserved. + * Copyright (c) 2010, 2013 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. @@ -15,7 +15,6 @@ 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; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; import org.eclipse.jpt.common.utility.iterable.ListIterable; import org.eclipse.jpt.jaxb.core.SchemaEntry; import org.eclipse.jpt.jaxb.core.context.JaxbPackage; @@ -272,14 +271,10 @@ public class GenericJavaXmlSchema } protected Iterable<String> getNamespaceProposals() { - return new TransformationIterable<String, String>( - new TransformationIterable<SchemaEntry, String>( - getJaxbProject().getSchemaLibrary().getSchemaEntries()) { - @Override - protected String transform(SchemaEntry o) { - return o.getNamespace(); - } - }, + return IterableTools.transform( + IterableTools.transform( + getJaxbProject().getSchemaLibrary().getSchemaEntries(), + SchemaEntry.NAMESPACE_TRANSFORMER), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetDataModelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetDataModelProvider.java index 195931e1b1..a0f1c6ab03 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetDataModelProvider.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetDataModelProvider.java @@ -20,7 +20,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.jaxb.core.JaxbProject; import org.eclipse.jpt.jaxb.core.JaxbWorkspace; import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages; @@ -195,16 +195,19 @@ public abstract class JaxbFacetDataModelProvider } protected DataModelPropertyDescriptor[] buildValidPlatformDescriptors() { - Iterable<JaxbPlatformConfig> validPlatformConfigs = buildValidPlatformConfigs(); Iterable<DataModelPropertyDescriptor> validPlatformDescriptors = - new TransformationIterable<JaxbPlatformConfig, DataModelPropertyDescriptor>(validPlatformConfigs) { - @Override - protected DataModelPropertyDescriptor transform(JaxbPlatformConfig config) { - return buildPlatformDescriptor(config); - } - }; + IterableTools.transform(buildValidPlatformConfigs(), new JaxbPlatformConfigTransformer()); return ArrayTools.sort(ArrayTools.array(validPlatformDescriptors, EMPTY_DMPD_ARRAY), DMPD_COMPARATOR); } + + public class JaxbPlatformConfigTransformer + extends TransformerAdapter<JaxbPlatformConfig, DataModelPropertyDescriptor> + { + @Override + public DataModelPropertyDescriptor transform(JaxbPlatformConfig config) { + return buildPlatformDescriptor(config); + } + } protected Iterable<JaxbPlatformConfig> buildValidPlatformConfigs() { return new FilteringIterable<JaxbPlatformConfig>(this.getJaxbPlatformConfigs()) { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetVersionChangeDataModelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetVersionChangeDataModelProvider.java index b604d22c3d..d0c9fce641 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetVersionChangeDataModelProvider.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/facet/JaxbFacetVersionChangeDataModelProvider.java @@ -1,16 +1,15 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 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 - *******************************************************************************/ + * Copyright (c) 2010, 2013 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.jaxb.core.internal.facet; import org.eclipse.core.runtime.IStatus; -import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.jaxb.core.internal.JptJaxbCoreMessages; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformConfig; @@ -29,7 +28,7 @@ public class JaxbFacetVersionChangeDataModelProvider // add existing platform to list of choices Iterable<JaxbPlatformConfig> validPlatformDescs = super.buildValidPlatformConfigs(); if (! IterableTools.contains(validPlatformDescs, getPlatformConfig())) { - validPlatformDescs = new CompositeIterable(getPlatformConfig(), validPlatformDescs); + validPlatformDescs = IterableTools.insert(getPlatformConfig(), validPlatformDescs); } return validPlatformDescs; } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java index 53cd6f73b6..df4ac9e2ab 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libval/JaxbLibraryValidatorTools.java @@ -23,8 +23,9 @@ import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jdt.launching.LibraryLocation;
import org.eclipse.jpt.common.core.internal.libval.LibraryValidatorTools;
import org.eclipse.jpt.common.core.libprov.JptLibraryProviderInstallOperationConfig;
-import org.eclipse.jpt.common.utility.internal.iterable.ArrayIterable;
-import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jst.common.project.facet.core.JavaFacet;
import org.eclipse.jst.common.project.facet.core.StandardJreRuntimeComponent;
@@ -170,13 +171,17 @@ public class JaxbLibraryValidatorTools { }
private static Iterable<IPath> buildLibraryPaths(IVMInstall vm) {
- return new TransformationIterable<LibraryLocation, IPath>(
- new ArrayIterable<LibraryLocation>(JavaRuntime.getLibraryLocations(vm))) {
- @Override
- protected IPath transform(LibraryLocation libraryLocation) {
- return libraryLocation.getSystemLibraryPath();
- }
- };
+ return IterableTools.transform(IterableTools.iterable(JavaRuntime.getLibraryLocations(vm)), LIBRARY_LOCATION_TRANSFORMER);
+ }
+
+ private static final Transformer<LibraryLocation, IPath> LIBRARY_LOCATION_TRANSFORMER = new LibraryLocationTransformer();
+ /* CU private */ static class LibraryLocationTransformer
+ extends TransformerAdapter<LibraryLocation, IPath>
+ {
+ @Override
+ public IPath transform(LibraryLocation libraryLocation) {
+ return libraryLocation.getSystemLibraryPath();
+ }
}
private static final String XML_SEE_ALSO = "javax/xml/bind/annotation/XmlSeeAlso.class"; //$NON-NLS-1$
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/jaxbindex/JaxbIndexResource.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/jaxbindex/JaxbIndexResource.java index c67dba3b12..d0f3860461 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/jaxbindex/JaxbIndexResource.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/jaxbindex/JaxbIndexResource.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Oracle. All rights reserved. + * Copyright (c) 2011, 2013 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. @@ -13,6 +13,8 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.common.core.JptResourceModel; import org.eclipse.jpt.common.core.JptResourceType; import org.eclipse.jpt.common.core.internal.utility.PlatformTools; +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; public interface JaxbIndexResource @@ -31,4 +33,13 @@ public interface JaxbIndexResource String getPackageName(); Iterable<String> getFullyQualifiedClassNames(); + Transformer<JaxbIndexResource, Iterable<String>> CLASS_NAMES_TRANSFORMER = new ClassNamesTransformer(); + class ClassNamesTransformer + extends TransformerAdapter<JaxbIndexResource, Iterable<String>> + { + @Override + public Iterable<String> transform(JaxbIndexResource jaxbIndexResource) { + return jaxbIndexResource.getFullyQualifiedClassNames(); + } + } } 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 c0cc4a448f..fe203b8ce0 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 @@ -1,18 +1,20 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.xsd; import java.util.ArrayList; import java.util.List; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.xsd.XSDAttributeUse; import org.eclipse.xsd.XSDComplexTypeDefinition; import org.eclipse.xsd.XSDContentTypeCategory; @@ -49,27 +51,27 @@ public class XsdComplexTypeDefinition @Override public Iterable<String> getAttributeNames(String namespace) { - return new TransformationIterable<XsdAttributeUse, String>(getAttributeUses(namespace)) { - @Override - protected String transform(XsdAttributeUse attrUse) { - return attrUse.getXSDComponent().getAttributeDeclaration().getName(); - } - }; + return IterableTools.transform(getAttributeUses(namespace), XSD_ATTRIBUTE_USE_TRANSFORMER); + } + + protected static final Transformer<XsdAttributeUse, String> XSD_ATTRIBUTE_USE_TRANSFORMER = new XsdAttributeUseTransformer(); + public static class XsdAttributeUseTransformer + extends TransformerAdapter<XsdAttributeUse, String> + { + @Override + public String transform(XsdAttributeUse attrUse) { + return attrUse.getXSDComponent().getAttributeDeclaration().getName(); + } } protected Iterable<XsdAttributeUse> getAttributeUses(final String namespace) { - return new TransformationIterable<XSDAttributeUse, XsdAttributeUse>( + return IterableTools.transform( new FilteringIterable<XSDAttributeUse>(getXSDComponent().getAttributeUses()) { @Override protected boolean accept(XSDAttributeUse attrUse) { return XsdUtil.namespaceEquals(attrUse.getAttributeDeclaration(), namespace); } - }) { - @Override - protected XsdAttributeUse transform(XSDAttributeUse attrUse) { - return (XsdAttributeUse) XsdUtil.getAdapter(attrUse); - } - }; + }, XsdUtil.<XsdAttributeUse>adapterTransformer()); } @Override @@ -84,27 +86,27 @@ public class XsdComplexTypeDefinition @Override public Iterable<String> getElementNames(String namespace, boolean recurseChildren) { - return new TransformationIterable<XsdElementDeclaration, String>(getElementDeclarations(namespace, recurseChildren)) { - @Override - protected String transform(XsdElementDeclaration element) { - return element.getXSDComponent().getName(); - } - }; + return IterableTools.transform(getElementDeclarations(namespace, recurseChildren), XSD_ELEMENT_DECLARATION_TRANSFORMER); + } + + protected static final Transformer<XsdElementDeclaration, String> XSD_ELEMENT_DECLARATION_TRANSFORMER = new XsdElementDeclarationTransformer(); + public static class XsdElementDeclarationTransformer + extends TransformerAdapter<XsdElementDeclaration, String> + { + @Override + public String transform(XsdElementDeclaration element) { + return element.getXSDComponent().getName(); + } } protected Iterable<XsdElementDeclaration> getElementDeclarations(final String namespace, boolean recurseChildren) { - return new TransformationIterable<XSDElementDeclaration, XsdElementDeclaration>( + return IterableTools.transform( new FilteringIterable<XSDElementDeclaration>(getXSDElementDeclarations(recurseChildren)) { @Override protected boolean accept(XSDElementDeclaration element) { return XsdUtil.namespaceEquals(element, namespace); } - }) { - @Override - protected XsdElementDeclaration transform(XSDElementDeclaration element) { - return (XsdElementDeclaration) XsdUtil.getAdapter(element); - } - }; + }, XsdUtil.<XsdElementDeclaration>adapterTransformer()); } protected Iterable<XSDElementDeclaration> getXSDElementDeclarations(boolean recurseChildren) { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdFeature.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdFeature.java index 120f69dfe9..653ac73677 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdFeature.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdFeature.java @@ -1,14 +1,16 @@ /******************************************************************************* - * Copyright (c) 2011 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.xsd; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.xsd.XSDFeature; @@ -27,6 +29,15 @@ public abstract class XsdFeature<A extends XSDFeature> public String getName() { return getXSDFeature().getName(); } + public static final Transformer<XsdFeature, String> NAME_TRANSFORMER = new NameTransformer(); + public static class NameTransformer + extends TransformerAdapter<XsdFeature, String> + { + @Override + public String transform(XsdFeature feature) { + return feature.getName(); + } + } public abstract XsdTypeDefinition getType(); 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 bdfb517659..fc7321c402 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 @@ -1,17 +1,18 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.xsd; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; +import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.SnapshotCloneIterable; import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; import org.eclipse.xsd.XSDElementDeclaration; @@ -35,55 +36,29 @@ public class XsdSchema public Iterable<String> getNamespaces() { Iterable<String> result = new SnapshotCloneIterable(getXSDSchema().getQNamePrefixToNamespaceMap().values()); if (StringTools.isBlank(getXSDSchema().getTargetNamespace())) { - result = new CompositeIterable<String>("", result); + result = IterableTools.insert("", result); } return result; } public Iterable<XsdTypeDefinition> getAllTypeDefinitions() { - return new TransformationIterable<XSDTypeDefinition, XsdTypeDefinition>(getAllXSDTypeDefinitions()) { - @Override - protected XsdTypeDefinition transform(XSDTypeDefinition o) { - return (XsdTypeDefinition) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getAllXSDTypeDefinitions(), XsdUtil.<XsdTypeDefinition>adapterTransformer()); } public Iterable<XsdTypeDefinition> getDeclaredTypeDefinitions() { - return new TransformationIterable<XSDTypeDefinition, XsdTypeDefinition>(getDeclaredXSDTypeDefinitions()) { - @Override - protected XsdTypeDefinition transform(XSDTypeDefinition o) { - return (XsdTypeDefinition) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getDeclaredXSDTypeDefinitions(), XsdUtil.<XsdTypeDefinition>adapterTransformer()); } public Iterable<XsdTypeDefinition> getBuiltInTypeDefinitions() { - return new TransformationIterable<XSDTypeDefinition, XsdTypeDefinition>(getBuiltInXSDTypeDefinitions()) { - @Override - protected XsdTypeDefinition transform(XSDTypeDefinition o) { - return (XsdTypeDefinition) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getBuiltInXSDTypeDefinitions(), XsdUtil.<XsdTypeDefinition>adapterTransformer()); } public Iterable<XsdTypeDefinition> getTypeDefinitions(final String namespace) { - return new TransformationIterable<XSDTypeDefinition, XsdTypeDefinition>(getXSDTypeDefinitions(namespace)) { - @Override - protected XsdTypeDefinition transform(XSDTypeDefinition o) { - return (XsdTypeDefinition) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getXSDTypeDefinitions(namespace), XsdUtil.<XsdTypeDefinition>adapterTransformer()); } public Iterable<XsdSimpleTypeDefinition> getSimpleTypeDefinitions(final String namespace) { - return new TransformationIterable<XSDSimpleTypeDefinition, XsdSimpleTypeDefinition>( - getXSDSimpleTypeDefinitions(namespace)) { - @Override - protected XsdSimpleTypeDefinition transform(XSDSimpleTypeDefinition o) { - return (XsdSimpleTypeDefinition) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getXSDSimpleTypeDefinitions(namespace), XsdUtil.<XsdSimpleTypeDefinition>adapterTransformer()); } /** @@ -128,42 +103,27 @@ public class XsdSchema } protected Iterable<XSDSimpleTypeDefinition> getXSDSimpleTypeDefinitions(String namespace) { - return new TransformationIterable<XSDTypeDefinition, XSDSimpleTypeDefinition>( + return IterableTools.subIterable( new FilteringIterable<XSDTypeDefinition>(getXSDTypeDefinitions(namespace)) { @Override protected boolean accept(XSDTypeDefinition o) { return o instanceof XSDSimpleTypeDefinition; } - }) { - @Override - protected XSDSimpleTypeDefinition transform(XSDTypeDefinition o) { - return (XSDSimpleTypeDefinition) o; - } - }; + }); } public Iterable<XsdElementDeclaration> getElementDeclarations() { - return new TransformationIterable<XSDElementDeclaration, XsdElementDeclaration>(getXSDElementDeclarations()) { - @Override - protected XsdElementDeclaration transform(XSDElementDeclaration o) { - return (XsdElementDeclaration) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getXSDElementDeclarations(), XsdUtil.<XsdElementDeclaration>adapterTransformer()); } public Iterable<XsdElementDeclaration> getElementDeclarations(final String namespace) { - return new TransformationIterable<XSDElementDeclaration, XsdElementDeclaration>( + return IterableTools.transform( new FilteringIterable<XSDElementDeclaration>(getXSDElementDeclarations()) { @Override protected boolean accept(XSDElementDeclaration o) { return XsdUtil.namespaceEquals(o, namespace); } - }) { - @Override - protected XsdElementDeclaration transform(XSDElementDeclaration o) { - return (XsdElementDeclaration) XsdUtil.getAdapter(o); - } - }; + }, XsdUtil.<XsdElementDeclaration>adapterTransformer()); } public XsdElementDeclaration getElementDeclaration(String namespace, String name) { @@ -184,35 +144,20 @@ public class XsdSchema } public Iterable<String> getTypeNameProposals(String namespace) { - return new TransformationIterable<String, String>( - new TransformationIterable<XsdTypeDefinition, String>(this.getTypeDefinitions(namespace)) { - @Override - protected String transform(XsdTypeDefinition o) { - return o.getName(); - } - }, + return IterableTools.transform( + IterableTools.transform(this.getTypeDefinitions(namespace), XsdTypeDefinition.NAME_TRANSFORMER), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } public Iterable<String> getSimpleTypeNameProposals(String namespace) { - return new TransformationIterable<String, String>( - new TransformationIterable<XsdSimpleTypeDefinition, String>(this.getSimpleTypeDefinitions(namespace)) { - @Override - protected String transform(XsdSimpleTypeDefinition o) { - return o.getName(); - } - }, + return IterableTools.transform( + IterableTools.transform(this.getSimpleTypeDefinitions(namespace), XsdTypeDefinition.NAME_TRANSFORMER), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } public Iterable<String> getElementNameProposals(String namespace) { - return new TransformationIterable<String, String>( - new TransformationIterable<XsdElementDeclaration, String>(this.getElementDeclarations(namespace)) { - @Override - protected String transform(XsdElementDeclaration o) { - return o.getName(); - } - }, + return IterableTools.transform( + IterableTools.transform(this.getElementDeclarations(namespace), XsdFeature.NAME_TRANSFORMER), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java index 89f00fef62..dbeae12cb7 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java @@ -1,17 +1,19 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 - *******************************************************************************/ + * Copyright (c) 2011, 2013 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.jaxb.core.xsd; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.xsd.XSDEnumerationFacet; import org.eclipse.xsd.XSDSimpleTypeDefinition; import org.eclipse.xsd.XSDVariety; @@ -61,13 +63,7 @@ public class XsdSimpleTypeDefinition * If the type is of variety UNION, this will return the member types of the union */ public Iterable<XsdSimpleTypeDefinition> getMemberTypes() { - return new TransformationIterable<XSDSimpleTypeDefinition, XsdSimpleTypeDefinition>( - getXSDComponent().getMemberTypeDefinitions()) { - @Override - protected XsdSimpleTypeDefinition transform(XSDSimpleTypeDefinition o) { - return (XsdSimpleTypeDefinition) XsdUtil.getAdapter(o); - } - }; + return IterableTools.transform(getXSDComponent().getMemberTypeDefinitions(), XsdUtil.<XsdSimpleTypeDefinition>adapterTransformer()); } @Override @@ -95,13 +91,19 @@ public class XsdSimpleTypeDefinition } public Iterable<String> getEnumValueProposals() { - return new TransformationIterable<String, String>( - new TransformationIterable<XSDEnumerationFacet, String>(getXSDComponent().getEnumerationFacets()) { - @Override - protected String transform(XSDEnumerationFacet enumFacet) { - return enumFacet.getLexicalValue(); - } - }, + return IterableTools.transform( + IterableTools.transform(getXSDComponent().getEnumerationFacets(), + XSD_ENUMERATION_FACET_TRANSFORMER), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } + + protected static final Transformer<XSDEnumerationFacet, String> XSD_ENUMERATION_FACET_TRANSFORMER = new XSDEnumerationFacetTransformer(); + public static class XSDEnumerationFacetTransformer + extends TransformerAdapter<XSDEnumerationFacet, String> + { + @Override + public String transform(XSDEnumerationFacet enumFacet) { + return enumFacet.getLexicalValue(); + } + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java index a57c6d87b0..e35e2a57d6 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java @@ -1,17 +1,19 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 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 + * Copyright (c) 2011, 2013 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.jaxb.core.xsd; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.context.TypeKind; import org.eclipse.xsd.XSDTypeDefinition; @@ -47,6 +49,15 @@ public abstract class XsdTypeDefinition<A extends XSDTypeDefinition> public String getName() { return getXSDComponent().getName(); } + public static final Transformer<XsdTypeDefinition, String> NAME_TRANSFORMER = new NameTransformer(); + public static class NameTransformer + extends TransformerAdapter<XsdTypeDefinition, String> + { + @Override + public String transform(XsdTypeDefinition def) { + return def.getName(); + } + } public abstract boolean hasTextContent(); 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 d43aa12e73..58d2d3bf80 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Oracle. All rights reserved. + * Copyright (c) 2011, 2013 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. @@ -22,6 +22,8 @@ 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.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jaxb.core.internal.plugin.JptJaxbCorePlugin; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; import org.eclipse.wst.xml.core.internal.XMLCorePlugin; @@ -155,7 +157,19 @@ public class XsdUtil { public static Object getAdapter(Notifier notifier) { return adapterFactory.adapt(notifier); } - + @SuppressWarnings("unchecked") + public static final <O> Transformer<Notifier, O> adapterTransformer() { + return (Transformer<Notifier, O>) ADAPTER_TRANSFORMER; + } + public static final Transformer<Notifier, Object> ADAPTER_TRANSFORMER = new AdapterTransformer(); + public static class AdapterTransformer + extends TransformerAdapter<Notifier, Object> + { + @Override + public Object transform(Notifier notifier) { + return getAdapter(notifier); + } + } /** * The Factory for the XSD adapter model. It provides a create method for each |