Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ITextRange.java34
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleTextRange.java56
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlEObject.java82
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaAttributeMapping.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaTypeMapping.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentAttribute.java341
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/AbstractJavaTable.java89
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddable.java40
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddableProvider.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java105
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntityProvider.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclass.java62
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclassProvider.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMapping.java38
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMappingProvider.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaTypeMapping.java81
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlColumn.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlNamedColumn.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlTable.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlAttributeMapping.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinColumn.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPrimaryKeyJoinColumn.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlTypeMapping.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/ASTNodeTextRange.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/plugin.properties12
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/plugin.xml17
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java90
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/StringTools.java289
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java139
35 files changed, 1185 insertions, 583 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ITextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ITextRange.java
index 497586bedb..d0fc42dac2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ITextRange.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ITextRange.java
@@ -1,23 +1,31 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
- * Contributors: Oracle. - initial API and implementation
+ * Contributors:
+ * Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.core.internal;
/**
- * A text range defines the offset into and length of a piece of text
+ * A text range defines the offset into, length of, and line of a piece
+ * of text.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
*/
-public interface ITextRange
-{
+public interface ITextRange {
/**
+ * Returns the offset of the text.
+ *
+ * @return the offset of the text
+ */
+ int getOffset();
+
+ /**
* Returns the length of the text.
*
* @return the length of the text
@@ -25,14 +33,12 @@ public interface ITextRange
int getLength();
/**
- * Returns the offset of the text.
- *
- * @return the offset of the text
+ * Return whether the range includes the specified index.
*/
- int getOffset();
-
+ boolean includes(int index);
+
/**
- * Retruns the line number in the text
+ * Returns the line number of the text.
*
* @return line number
*/
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleTextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleTextRange.java
new file mode 100644
index 0000000000..054957c3a6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleTextRange.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+
+/**
+ * Straightforward, albeit almost useless, implementation of ITextRange.
+ */
+public class SimpleTextRange implements ITextRange {
+ private final int offset;
+ private final int length;
+ private final int lineNumber;
+
+ public SimpleTextRange(int offset, int length, int lineNumber) {
+ super();
+ this.offset = offset;
+ this.length = length;
+ this.lineNumber = lineNumber;
+ }
+
+ public int getOffset() {
+ return this.offset;
+ }
+
+ public int getLength() {
+ return this.length;
+ }
+
+ public int getLineNumber() {
+ return this.lineNumber;
+ }
+
+ public boolean includes(int index) {
+ return (this.offset <= index) && (index <= this.end());
+ }
+
+ private int end() {
+ return this.offset + this.length - 1;
+ }
+
+ @Override
+ public String toString() {
+ String start = String.valueOf(this.offset);
+ String end = String.valueOf(this.end());
+ return StringTools.buildToStringFor(this, start + ", " + end);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlEObject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlEObject.java
index fd11a89188..2db6130ae6 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlEObject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlEObject.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2006, 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal;
import java.util.Collection;
@@ -14,12 +15,14 @@ import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IResource;
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapter;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
@@ -76,7 +79,7 @@ public abstract class XmlEObject extends JpaEObject implements IXmlEObject
}
@Override
- public EList eAdapters() {
+ public EList<Adapter> eAdapters() {
if (this.eAdapters == null) {
this.eAdapters = new XmlEAdapterList(this);
}
@@ -148,26 +151,11 @@ public abstract class XmlEObject extends JpaEObject implements IXmlEObject
}
public ITextRange getTextRange() {
- return getTextRange(node);
+ return buildTextRange(node);
}
- protected ITextRange getTextRange(final IDOMNode aNode) {
- return new ITextRange() {
- public int getLength() {
- if (aNode.getNodeType() == Node.ELEMENT_NODE) {
- return ((IDOMElement) aNode).getStartEndOffset() - aNode.getStartOffset();
- }
- return aNode.getLength();
- }
-
- public int getLineNumber() {
- return aNode.getStructuredDocument().getLineOfOffset(getOffset()) + 1;
- }
-
- public int getOffset() {
- return aNode.getStartOffset();
- }
- };
+ protected ITextRange buildTextRange(IDOMNode domNode) {
+ return new DOMNodeTextRange(domNode);
}
protected boolean xmlFeatureIsSignificant(int featureId) {
@@ -214,4 +202,46 @@ public abstract class XmlEObject extends JpaEObject implements IXmlEObject
// when you override this method, don't forget to include:
// super.addInsignificantXmlFeatureIdsTo(insignificantXmlFeatureIds);
}
-}
+ /**
+ * Implementation of ITextRange that adapts a IDOMNode.
+ */
+ private static class DOMNodeTextRange implements ITextRange
+ {
+ private final IDOMNode node;
+
+ DOMNodeTextRange(IDOMNode node) {
+ super();
+ this.node = node;
+ }
+
+ public int getOffset() {
+ return this.node.getStartOffset();
+ }
+
+ public int getLength() {
+ if (this.node.getNodeType() == Node.ELEMENT_NODE) {
+ return ((IDOMElement) this.node).getStartEndOffset() - this.node.getStartOffset();
+ }
+ return this.node.getLength();
+ }
+
+ public int getLineNumber() {
+ return this.node.getStructuredDocument().getLineOfOffset(getOffset()) + 1;
+ }
+
+ public boolean includes(int index) {
+ return (this.getOffset() <= index) && (index <= this.end());
+ }
+
+ private int end() {
+ return this.getOffset() + this.getLength() - 1;
+ }
+
+ @Override
+ public String toString() {
+ String start = String.valueOf(this.getOffset());
+ String end = String.valueOf(this.getOffset() + this.getLength() - 1);
+ return StringTools.buildToStringFor(this, start + ", " + end);
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaAttributeMapping.java
index 6287777c19..918f77c821 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaAttributeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaAttributeMapping.java
@@ -1,17 +1,19 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0, which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java;
+import java.util.Iterator;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.IAttributeMapping;
import org.eclipse.jpt.core.internal.platform.DefaultsContext;
+import org.eclipse.jpt.utility.internal.Filter;
/**
* <!-- begin-user-doc -->
@@ -41,7 +43,8 @@ public interface IJavaAttributeMapping extends IAttributeMapping
/**
* Refresh defaults using the given DefaultsContext
- * @param defaultsContext
*/
void refreshDefaults(DefaultsContext defaultsContext);
+
+ Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot);
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaTypeMapping.java
index b05dab619a..4a9646480d 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/IJavaTypeMapping.java
@@ -9,9 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java;
-import java.util.List;
+import java.util.Iterator;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.ITypeMapping;
+import org.eclipse.jpt.utility.internal.Filter;
/**
* <!-- begin-user-doc -->
@@ -35,5 +36,9 @@ public interface IJavaTypeMapping extends ITypeMapping
void updateFromJava(CompilationUnit astRoot);
- List<String> candidateValuesFor(int pos, CompilationUnit astRoot);
+ /**
+ * Return the candidate code-completion values for the specified position
+ * in the source code.
+ */
+ Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot);
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentAttribute.java
index e603fb9fda..79018049f4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentAttribute.java
@@ -11,9 +11,7 @@ package org.eclipse.jpt.core.internal.content.java;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
@@ -41,6 +39,7 @@ import org.eclipse.jpt.core.internal.content.java.mappings.JavaVersionProvider;
import org.eclipse.jpt.core.internal.jdtutility.Attribute;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.platform.DefaultsContext;
+import org.eclipse.jpt.utility.internal.Filter;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
@@ -65,26 +64,6 @@ public class JavaPersistentAttribute extends JavaEObject
implements IPersistentAttribute
{
/**
- * The default value of the '{@link #getMappingKey() <em>Mapping Key</em>}' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #getMappingKey()
- * @generated
- * @ordered
- */
- protected static final String MAPPING_KEY_EDEFAULT = null;
-
- /**
- * The cached value of the '{@link #getMappingKey() <em>Mapping Key</em>}' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #getMappingKey()
- * @generated
- * @ordered
- */
- protected String mappingKey = MAPPING_KEY_EDEFAULT;
-
- /**
* The cached value of the '{@link #getDefaultMapping() <em>Default Mapping</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -106,14 +85,14 @@ public class JavaPersistentAttribute extends JavaEObject
private Attribute attribute;
- // TODO move these to a singleton?
+ // TODO move these to the platform
private IJavaAttributeMappingProvider[] attributeMappingProviders;
/**
* the "null" attribute mapping is used when the attribute is neither
* modified with a mapping annotation nor mapped by a "default" mapping
*/
- // TODO move this to a singleton?
+ // TODO move this to the platform
private IJavaAttributeMappingProvider nullAttributeMappingProvider;
/**
@@ -130,6 +109,7 @@ public class JavaPersistentAttribute extends JavaEObject
this.attribute = attribute;
this.attributeMappingProviders = this.buildAttributeMappingProviders();
this.nullAttributeMappingProvider = this.buildNullAttributeMappingProvider();
+ this.setDefaultMapping(this.nullAttributeMappingProvider.buildMapping(this.attribute));
}
private IJavaAttributeMappingProvider[] buildAttributeMappingProviders() {
@@ -171,23 +151,6 @@ public class JavaPersistentAttribute extends JavaEObject
}
/**
- * Returns the value of the '<em><b>Mapping Key</b></em>' attribute.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Mapping Key</em>' attribute isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Mapping Key</em>' attribute.
- * @see org.eclipse.jpt.core.internal.content.java.JpaJavaPackage#getIPersistentAttribute_MappingKey()
- * @model required="true" changeable="false"
- * @generated
- */
- public String getMappingKey() {
- return mappingKey;
- }
-
- /**
* Returns the value of the '<em><b>Default Mapping</b></em>' containment reference.
* <!-- begin-user-doc -->
* <p>
@@ -231,7 +194,7 @@ public class JavaPersistentAttribute extends JavaEObject
* @see #getDefaultMapping()
* @generated
*/
- public void setDefaultMapping(IJavaAttributeMapping newDefaultMapping) {
+ public void setDefaultMappingGen(IJavaAttributeMapping newDefaultMapping) {
if (newDefaultMapping != defaultMapping) {
NotificationChain msgs = null;
if (defaultMapping != null)
@@ -247,6 +210,13 @@ public class JavaPersistentAttribute extends JavaEObject
}
/**
+ * clients do not set the "default" mapping
+ */
+ private void setDefaultMapping(IJavaAttributeMapping defaultMapping) {
+ this.setDefaultMappingGen(defaultMapping);
+ }
+
+ /**
* Returns the value of the '<em><b>Specified Mapping</b></em>' containment reference.
* <!-- begin-user-doc -->
* <p>
@@ -285,6 +255,8 @@ public class JavaPersistentAttribute extends JavaEObject
/**
* Sets the value of the '{@link org.eclipse.jpt.core.internal.content.java.JavaPersistentAttribute#getSpecifiedMapping <em>Specified Mapping</em>}' containment reference.
* <!-- begin-user-doc -->
+ * clients do not set the "specified" mapping directly;
+ * call #setMappingKey(String, boolean) instead
* <!-- end-user-doc -->
* @param value the new value of the '<em>Specified Mapping</em>' containment reference.
* @see #getSpecifiedMapping()
@@ -306,56 +278,11 @@ public class JavaPersistentAttribute extends JavaEObject
}
/**
- * This should not be called when updating the persistence model
- * from the java model, it should only be called when going in the
- * other direction. This will update the java code appropriately
- * to the change in mapping in the persistence model.
- */
- public void setSpecifiedMapping(IJavaAttributeMapping newMapping) {
- if (this.specifiedMapping != null) {
- this.attribute.removeAnnotation(this.annotationAdapterForAttributeMappingKey(this.specifiedMapping.getKey()));
- }
- if (newMapping != null) {
- this.attribute.newMarkerAnnotation(this.annotationAdapterForAttributeMappingKey(newMapping.getKey()));
- }
- this.setSpecifiedMappingGen(newMapping);
- }
-
- protected void setMappingKeyInternal(String newMappingKey) {
- String oldMappingKey = mappingKey;
- mappingKey = newMappingKey;
- if (eNotificationRequired())
- eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING_KEY, oldMappingKey, mappingKey));
- }
-
- /**
- * This should not be called when updating the persistence model
- * from the java model, it should only be called when going in the
- * other direction. This will update the java code appropriately
- * to the change in mapping in the persistence model.
+ * clients do not set the "specified" mapping;
+ * use #setMappingKey(String)
*/
- public void setMappingKey(String newMappingKey, boolean default_) {
- if (default_) {
- setSpecifiedMapping(null);
- setMappingKeyInternal(newMappingKey);
- return;
- }
- this.setSpecifiedMapping(this.buildMapping(newMappingKey));
- if (this.specifiedMapping != null) {
- this.specifiedMapping.initialize();
- }
- this.setMappingKeyInternal(newMappingKey);
- //TODO need to support mapping morphing, copying common settings over
- //to the new mapping. This can't be done in the same was as XmlAttributeMapping
- //since we don't know all the possible mapping types
- }
-
- public IJavaAttributeMapping getMapping() {
- return getSpecifiedMapping() != null ? getSpecifiedMapping() : getDefaultMapping();
- }
-
- public String getName() {
- return getAttribute().attributeName();
+ private void setSpecifiedMapping(IJavaAttributeMapping specifiedMapping) {
+ this.setSpecifiedMappingGen(specifiedMapping);
}
/**
@@ -382,8 +309,6 @@ public class JavaPersistentAttribute extends JavaEObject
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
- case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING_KEY :
- return getMappingKey();
case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__DEFAULT_MAPPING :
return getDefaultMapping();
case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__SPECIFIED_MAPPING :
@@ -436,8 +361,6 @@ public class JavaPersistentAttribute extends JavaEObject
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
- case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING_KEY :
- return MAPPING_KEY_EDEFAULT == null ? mappingKey != null : !MAPPING_KEY_EDEFAULT.equals(mappingKey);
case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__DEFAULT_MAPPING :
return defaultMapping != null;
case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__SPECIFIED_MAPPING :
@@ -461,8 +384,8 @@ public class JavaPersistentAttribute extends JavaEObject
}
if (baseClass == IPersistentAttribute.class) {
switch (derivedFeatureID) {
- case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING_KEY :
- return JpaCorePackage.IPERSISTENT_ATTRIBUTE__MAPPING_KEY;
+ case JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING :
+ return JpaCorePackage.IPERSISTENT_ATTRIBUTE__MAPPING;
default :
return -1;
}
@@ -485,8 +408,8 @@ public class JavaPersistentAttribute extends JavaEObject
}
if (baseClass == IPersistentAttribute.class) {
switch (baseFeatureID) {
- case JpaCorePackage.IPERSISTENT_ATTRIBUTE__MAPPING_KEY :
- return JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING_KEY;
+ case JpaCorePackage.IPERSISTENT_ATTRIBUTE__MAPPING :
+ return JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING;
default :
return -1;
}
@@ -494,30 +417,74 @@ public class JavaPersistentAttribute extends JavaEObject
return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- @Override
- public String toString() {
- if (eIsProxy())
- return super.toString();
- StringBuffer result = new StringBuffer(super.toString());
- result.append(" (mappingKey: ");
- result.append(mappingKey);
- result.append(')');
- return result.toString();
- }
-
public IPersistentType getPersistentType() {
return (IPersistentType) this.eContainer();
}
+ public IJavaAttributeMapping getMapping() {
+ return (this.specifiedMapping != null) ? this.specifiedMapping : this.defaultMapping;
+ }
+
+ public String getName() {
+ return this.attribute.attributeName();
+ }
+
public ITypeMapping typeMapping() {
return this.getPersistentType().getMapping();
}
+ public String mappingKey() {
+ return this.getMapping().getKey();
+ }
+
+ /**
+ * return null if there is no "default" mapping for the attribute
+ */
+ public String defaultMappingKey() {
+ return this.defaultMapping.getKey();
+ }
+
+ /**
+ * return null if there is no "specified" mapping for the attribute
+ */
+ public String specifiedMappingKey() {
+ return (this.specifiedMapping == null) ? null : this.specifiedMapping.getKey();
+ }
+
+ // TODO support morphing mappings, i.e. copying common settings over
+ // to the new mapping; this can't be done in the same was as XmlAttributeMapping
+ // since we don't know all the possible mapping types
+ public void setSpecifiedMappingKey(String newKey) {
+ String oldKey = this.specifiedMappingKey();
+ if (newKey == oldKey) {
+ return;
+ }
+ IJavaAttributeMapping old = this.getMapping();
+ if (newKey == null) {
+ // remove mapping annotation
+ this.setSpecifiedMapping(null);
+ this.attribute.removeAnnotation(this.declarationAnnotationAdapterForAttributeMappingKey(oldKey));
+ } else {
+ // add or replace mapping annotation
+ this.setSpecifiedMapping(this.attributeMappingProviderFor(newKey).buildMapping(this.attribute));
+ if (oldKey != null) {
+ this.attribute.removeAnnotation(this.declarationAnnotationAdapterForAttributeMappingKey(oldKey));
+ }
+ this.attribute.newMarkerAnnotation(this.declarationAnnotationAdapterForAttributeMappingKey(newKey));
+ this.specifiedMapping.initialize();
+ }
+ if (this.eNotificationRequired()) {
+ this.eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING, old, this.getMapping()));
+ }
+ }
+
+ private DeclarationAnnotationAdapter declarationAnnotationAdapterForAttributeMappingKey(String attributeMappingKey) {
+ return this.attributeMappingProviderFor(attributeMappingKey).declarationAnnotationAdapter();
+ }
+
+ /**
+ * throw an exception if the provider is not found
+ */
private IJavaAttributeMappingProvider attributeMappingProviderFor(String attributeMappingKey) {
for (IJavaAttributeMappingProvider provider : this.attributeMappingProviders) {
if (provider.key() == attributeMappingKey) {
@@ -527,14 +494,11 @@ public class JavaPersistentAttribute extends JavaEObject
throw new IllegalArgumentException("Unsupported attribute mapping key: " + attributeMappingKey);
}
- private DeclarationAnnotationAdapter annotationAdapterForAttributeMappingKey(String attributeMappingKey) {
- return this.attributeMappingProviderFor(attributeMappingKey).declarationAnnotationAdapter();
- }
-
public Iterator<String> candidateMappingKeys() {
return new TransformationIterator<IJavaAttributeMappingProvider, String>(new ArrayIterator<IJavaAttributeMappingProvider>(this.attributeMappingProviders)) {
- protected String transform(IJavaAttributeMappingProvider next) {
- return next.key();
+ @Override
+ protected String transform(IJavaAttributeMappingProvider provider) {
+ return provider.key();
}
};
}
@@ -556,97 +520,96 @@ public class JavaPersistentAttribute extends JavaEObject
}
public void updateFromJava(CompilationUnit astRoot) {
- String jpaKey = null;
- if (this.specifiedMapping != null) {
- jpaKey = this.specifiedMapping.getKey();
- }
- String javaKey = this.javaAttributeMappingKey(astRoot);
- if (javaKey == null) { // no annotation
- if (this.specifiedMapping != null) {
- setSpecifiedMapping(null);
+ // synchronize the "specified" mapping with the Java source
+ String jpaKey = this.specifiedMappingKey();
+ IJavaAttributeMappingProvider javaProvider = this.javaAttributeMappingProvider(astRoot);
+ String javaKey = ((javaProvider == null) ? null : javaProvider.key());
+ if (javaKey != jpaKey) {
+ IJavaAttributeMapping old = this.getMapping();
+ if (javaKey == null) {
+ // no mapping annotation found in Java source
+ this.setSpecifiedMapping(null);
+ } else {
+ // the mapping has changed
+ this.setSpecifiedMapping(javaProvider.buildMapping(this.attribute));
+ this.specifiedMapping.initialize();
}
- }
- else if (jpaKey != javaKey) {
- this.createAndSetMappingFromJava(javaKey);
- }
- if (getMapping() != null) {
- getMapping().updateFromJava(astRoot);
- }
- }
-
- private void createAndSetMappingFromJava(String key) {
- this.setSpecifiedMappingGen(this.buildMapping(key));
- this.specifiedMapping.initialize();
- this.setMappingKeyInternal(this.specifiedMapping.getKey());
- }
-
- //A null key means there is no "mapping" annotation on the attribute.
- //In this case check the attributeMappingProviders for one that the defaultApplies
- //and create the mapping. If the key is not null then create the mapping
- //based on the appropriate provider, otherwise return the a nullAttributeMapping
- private IJavaAttributeMapping buildMapping(String key) {
- if (key == null) {
- return null;
- }
- for (IJavaAttributeMappingProvider provider : this.attributeMappingProviders) {
- if (provider.key() == key) {
- return provider.buildMapping(this.attribute);
+ if (this.eNotificationRequired()) {
+ this.eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING, old, this.getMapping()));
}
}
- return this.nullAttributeMappingProvider.buildMapping(this.attribute);
+ // once the "specified" mapping is in place, update it from Java;
+ // unless it is null, in which case we update the "default" mapping from Java
+ this.getMapping().updateFromJava(astRoot);
}
- private String javaAttributeMappingKey(CompilationUnit astRoot) {
+ /**
+ * return null if we can't find a mapping annotation on the attribute
+ */
+ private IJavaAttributeMappingProvider javaAttributeMappingProvider(CompilationUnit astRoot) {
for (IJavaAttributeMappingProvider provider : this.attributeMappingProviders) {
if (this.attribute.containsAnnotation(provider.declarationAnnotationAdapter(), astRoot)) {
- return provider.key();
+ return provider;
}
}
return null;
}
- public String defaultKey() {
- if (this.defaultMapping != null) {
- return this.defaultMapping.getKey();
- }
- return null;
- }
-
public String primaryKeyColumnName() {
- if (getMapping() != null) {
- return getMapping().primaryKeyColumnName();
- }
- return null;
+ IJavaAttributeMapping mapping = this.getMapping();
+ return (mapping == null) ? null : mapping.primaryKeyColumnName();
}
- public boolean isAttributeMappingDefault() {
+ /**
+ * the mapping might be "default", but it still might be a "null" mapping...
+ */
+ public boolean mappingIsDefault() {
return this.specifiedMapping == null;
}
- public List<String> candidateValuesFor(int pos, CompilationUnit astRoot) {
- return Collections.emptyList();
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ return this.getMapping().candidateValuesFor(pos, filter, astRoot);
}
+ /**
+ * check to see whether the "default" mapping has changed
+ */
public void refreshDefaults(DefaultsContext defaultsContext) {
+ IJavaAttributeMappingProvider defaultProvider = this.defaultAttributeMappingProvider(defaultsContext);
+ if (defaultProvider.key() == this.defaultMapping.getKey()) {
+ return;
+ }
+ // the "default" mapping has changed
+ IJavaAttributeMapping old = this.getMapping();
+ this.setDefaultMapping(defaultProvider.buildMapping(this.attribute));
+ this.defaultMapping.updateFromJava(this.attribute.astRoot());
+ if (this.eNotificationRequired()) {
+ this.eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaPackage.JAVA_PERSISTENT_ATTRIBUTE__MAPPING, old, this.getMapping()));
+ }
+ }
+
+ /**
+ * return the first(?) provider that can supply a "default" mapping for the attribute;
+ * return the null provider if we can't find a provider
+ */
+ private IJavaAttributeMappingProvider defaultAttributeMappingProvider(DefaultsContext defaultsContext) {
for (IJavaAttributeMappingProvider provider : this.attributeMappingProviders) {
if (provider.defaultApplies(this.attribute, defaultsContext)) {
- if (getDefaultMapping() != null) {
- if (getDefaultMapping().getKey() == provider.key()) {
- return;
- }
- }
- setDefaultMapping(provider.buildMapping(this.attribute));
- getDefaultMapping().updateFromJava(getAttribute().astRoot());
- if (getSpecifiedMapping() == null) {
- setMappingKeyInternal(getDefaultMapping().getKey());
- }
- return;
+ return provider;
}
}
- setDefaultMapping(this.nullAttributeMappingProvider.buildMapping(this.attribute));
- getDefaultMapping().updateFromJava(getAttribute().astRoot());
- if (getSpecifiedMapping() == null) {
- setMappingKeyInternal(getDefaultMapping().getKey());
- }
+ return this.nullAttributeMappingProvider;
+ }
+
+ public boolean isOverridableAttribute() {
+ return this.getMapping().isOverridableAttributeMapping();
+ }
+
+ public boolean isOverridableAssociation() {
+ return this.getMapping().isOverridableAssociationMapping();
+ }
+
+ public boolean isIdAttribute() {
+ return this.getMapping().isIdMapping();
}
-} // JavaPersistentAttribute
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java
index af562bbea2..0c99d1cac4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java
@@ -68,6 +68,7 @@ import org.eclipse.jpt.core.internal.jdtutility.JDTTools;
import org.eclipse.jpt.core.internal.jdtutility.MethodAttribute;
import org.eclipse.jpt.core.internal.jdtutility.Type;
import org.eclipse.jpt.core.internal.platform.DefaultsContext;
+import org.eclipse.jpt.utility.internal.Filter;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.utility.internal.iterators.ChainIterator;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
@@ -602,10 +603,10 @@ public class JavaPersistentType extends JavaEObject implements IPersistentType
return result.toString();
}
- public void setJdtType(IType iType) {
+ public void setJdtType(IType iType, CompilationUnit astRoot) {
this.type = new Type(iType);
- this.setAccess(this.javaAccessType(this.getType().astRoot()));
- this.createAndSetPersistentTypeMappingFromJava(this.javaTypeMappingKey());
+ this.setAccess(this.javaAccessType(astRoot));
+ this.createAndSetPersistentTypeMappingFromJava(this.javaTypeMappingKey(astRoot));
}
public JavaPersistentAttribute addJavaPersistentAttribute(IMember jdtMember) {
@@ -661,11 +662,10 @@ public class JavaPersistentType extends JavaEObject implements IPersistentType
return this.type.wraps(member);
}
- protected void updateFromJava() {
- CompilationUnit astRoot = this.getType().astRoot();
+ protected void updateFromJava(CompilationUnit astRoot) {
this.setAccess(this.javaAccessType(astRoot));
String jpaKey = this.getMapping().getKey();
- String javaKey = this.javaTypeMappingKey();
+ String javaKey = this.javaTypeMappingKey(astRoot);
if (jpaKey != javaKey) {
this.createAndSetPersistentTypeMappingFromJava(javaKey);
}
@@ -718,8 +718,7 @@ public class JavaPersistentType extends JavaEObject implements IPersistentType
return AttributeAnnotationTools.persistablePropertyGetters(jdtType());
}
- private String javaTypeMappingKey() {
- CompilationUnit astRoot = this.type.astRoot();
+ private String javaTypeMappingKey(CompilationUnit astRoot) {
for (IJavaTypeMappingProvider provider : this.typeMappingProviders) {
if (this.type.containsAnnotation(provider.declarationAnnotationAdapter(), astRoot)) {
return provider.key();
@@ -756,13 +755,13 @@ public class JavaPersistentType extends JavaEObject implements IPersistentType
}
}
- public List<String> candidateValuesFor(int pos, CompilationUnit astRoot) {
- List<String> values = this.mapping.candidateValuesFor(pos, astRoot);
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ Iterator<String> values = this.mapping.candidateValuesFor(pos, filter, astRoot);
if (values != null) {
return values;
}
for (JavaPersistentAttribute attribute : this.getAttributes()) {
- values = attribute.candidateValuesFor(pos, astRoot);
+ values = attribute.candidateValuesFor(pos, filter, astRoot);
if (values != null) {
return values;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java
index 4f387634f3..c0fbe3e9c4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java
@@ -11,7 +11,7 @@ package org.eclipse.jpt.core.internal.content.java;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.notify.NotificationChain;
@@ -37,6 +37,8 @@ import org.eclipse.jpt.core.internal.JpaFile;
import org.eclipse.jpt.core.internal.jdtutility.ASTNodeTextRange;
import org.eclipse.jpt.core.internal.jdtutility.AttributeAnnotationTools;
import org.eclipse.jpt.core.internal.jdtutility.JDTTools;
+import org.eclipse.jpt.utility.internal.Filter;
+import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
/**
* <!-- begin-user-doc -->
@@ -288,7 +290,7 @@ public class JpaCompilationUnit extends JavaEObject
}
public ITextRange getTextRange() {
- return new ASTNodeTextRange(JDTTools.createASTRoot(compilationUnit));
+ return new ASTNodeTextRange(this.astRoot());
}
public Object getId() {
@@ -301,27 +303,27 @@ public class JpaCompilationUnit extends JavaEObject
}
public void setFile(IFile file) {
- compilationUnit = JavaCore.createCompilationUnitFrom(file);
+ this.compilationUnit = JavaCore.createCompilationUnitFrom(file);
try {
- compilationUnit.open(null);
+ this.compilationUnit.open(null);
}
catch (JavaModelException jme) {
// do nothing - we just won't have a primary type in this case
}
- updatePersistentTypes();
+ this.synchronizePersistentTypes();
}
- public JavaPersistentType addJavaPersistentType(IType primaryType) {
- return addJavaPersistentType(createJavaPersistentType(), primaryType);
+ public JavaPersistentType addJavaPersistentType(IType primaryType, CompilationUnit astRoot) {
+ return this.addJavaPersistentType(this.createJavaPersistentType(), primaryType, astRoot);
}
public JavaPersistentType createJavaPersistentType() {
return JpaJavaFactory.eINSTANCE.createJavaPersistentType();
}
- private JavaPersistentType addJavaPersistentType(JavaPersistentType javaPersistentType, IType primaryType) {
- getTypes().add(javaPersistentType);
- javaPersistentType.setJdtType(primaryType);
+ private JavaPersistentType addJavaPersistentType(JavaPersistentType javaPersistentType, IType primaryType, CompilationUnit astRoot) {
+ this.getTypes().add(javaPersistentType);
+ javaPersistentType.setJdtType(primaryType, astRoot);
return javaPersistentType;
}
@@ -365,30 +367,31 @@ public class JpaCompilationUnit extends JavaEObject
if (!delta.getElement().equals(this.compilationUnit)) {
return;
}
- updatePersistentTypes();
+ this.synchronizePersistentTypes();
}
- private void updatePersistentTypes() {
- List<JavaPersistentType> persistentTypesToRemove = new ArrayList<JavaPersistentType>(getTypes());
- IType[] iTypes = compilationUnitTypes();
+ private void synchronizePersistentTypes() {
+ CompilationUnit astRoot = this.astRoot();
+ List<JavaPersistentType> persistentTypesToRemove = new ArrayList<JavaPersistentType>(this.getTypes());
+ IType[] iTypes = this.compilationUnitTypes();
for (IType iType : iTypes) {
- JavaPersistentType persistentType = persistentTypeFor(iType);
+ JavaPersistentType persistentType = this.persistentTypeFor(iType);
if (persistentType == null) {
if (AttributeAnnotationTools.typeIsPersistable(iType)) {
- persistentType = addJavaPersistentType(iType);
+ persistentType = this.addJavaPersistentType(iType, astRoot);
}
}
if (persistentType != null) {
persistentTypesToRemove.remove(persistentType);
if (AttributeAnnotationTools.typeIsPersistable(iType)) {
- persistentType.updateFromJava();
+ persistentType.updateFromJava(astRoot);
}
else {
- getTypes().remove(persistentType);
+ this.getTypes().remove(persistentType);
}
}
}
- getTypes().removeAll(persistentTypesToRemove);
+ this.getTypes().removeAll(persistentTypesToRemove);
}
private JavaPersistentType persistentTypeFor(IType iType) {
@@ -411,15 +414,15 @@ public class JpaCompilationUnit extends JavaEObject
}
}
- public List<String> candidateValuesFor(int pos) {
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter) {
CompilationUnit astRoot = this.astRoot();
for (JavaPersistentType persistentType : this.getTypes()) {
- List<String> list = persistentType.candidateValuesFor(pos, astRoot);
- if (list != null) {
- return list;
+ Iterator<String> values = persistentType.candidateValuesFor(pos, filter, astRoot);
+ if (values != null) {
+ return values;
}
}
- return Collections.emptyList();
+ return EmptyIterator.instance();
}
public CompilationUnit astRoot() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/AbstractJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/AbstractJavaTable.java
index c7f4d8734b..ba988c5763 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/AbstractJavaTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/AbstractJavaTable.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java.mappings;
+import java.util.Iterator;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
@@ -26,8 +27,12 @@ import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
import org.eclipse.jpt.core.internal.platform.BaseJpaPlatform;
import org.eclipse.jpt.core.internal.platform.DefaultsContext;
import org.eclipse.jpt.db.internal.ConnectionProfile;
+import org.eclipse.jpt.db.internal.Database;
import org.eclipse.jpt.db.internal.Schema;
import org.eclipse.jpt.db.internal.Table;
+import org.eclipse.jpt.utility.internal.Filter;
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
/**
* <!-- begin-user-doc -->
@@ -676,14 +681,26 @@ public abstract class AbstractJavaTable extends JavaEObject implements ITable
return this.elementTextRange(this.nameDeclarationAdapter);
}
+ public ITextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.elementTextRange(this.nameDeclarationAdapter, astRoot);
+ }
+
public ITextRange getSchemaTextRange() {
return this.elementTextRange(this.schemaDeclarationAdapter);
}
+ public ITextRange getSchemaTextRange(CompilationUnit astRoot) {
+ return this.elementTextRange(this.schemaDeclarationAdapter, astRoot);
+ }
+
public ITextRange getCatalogTextRange() {
return this.elementTextRange(this.catalogDeclarationAdapter);
}
+ public ITextRange getCatalogTextRange(CompilationUnit astRoot) {
+ return this.elementTextRange(this.catalogDeclarationAdapter, astRoot);
+ }
+
//TODO should we allow setting through the ecore, that would make this method
//public and part of the ITable api. only the model needs to be setting the default,
//but the ui needs to be listening for changes to the default.
@@ -739,12 +756,12 @@ public abstract class AbstractJavaTable extends JavaEObject implements ITable
}
public Schema dbSchema() {
- return this.getJpaProject().connectionProfile().getDatabase().schemaNamed(this.getSchema());
+ return this.database().schemaNamed(this.getSchema());
}
public boolean isConnected() {
- ConnectionProfile connectionProfile = this.getJpaProject().connectionProfile();
- return connectionProfile != null && connectionProfile.isConnected();
+ ConnectionProfile cp = this.connectionProfile();
+ return (cp != null) && cp.isConnected();
}
public boolean hasResolvedSchema() {
@@ -758,4 +775,70 @@ public abstract class AbstractJavaTable extends JavaEObject implements ITable
protected ITextRange elementTextRange(DeclarationAnnotationElementAdapter elementAdapter) {
return this.elementTextRange(this.member.annotationElementTextRange(elementAdapter));
}
+
+ protected ITextRange elementTextRange(DeclarationAnnotationElementAdapter elementAdapter, CompilationUnit astRoot) {
+ return this.elementTextRange(this.member.annotationElementTextRange(elementAdapter, astRoot));
+ }
+
+ /**
+ * name, schema, catalog
+ */
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ if (this.isConnected()) {
+ if (this.getNameTextRange(astRoot).includes(pos)) {
+ return this.quotedCandidateNames(filter);
+ }
+ if (this.getSchemaTextRange(astRoot).includes(pos)) {
+ return this.quotedCandidateSchemas(filter);
+ }
+ if (this.getCatalogTextRange(astRoot).includes(pos)) {
+ return this.quotedCandidateCatalogs(filter);
+ }
+ }
+ return null;
+ }
+
+ private ConnectionProfile connectionProfile() {
+ return this.getJpaProject().connectionProfile();
+ }
+
+ private Database database() {
+ return this.connectionProfile().getDatabase();
+ }
+
+ private Iterator<String> candidateNames() {
+ return this.dbSchema().tableNames();
+ }
+
+ private Iterator<String> candidateNames(Filter<String> filter) {
+ return new FilteringIterator<String>(this.candidateNames(), filter);
+ }
+
+ private Iterator<String> quotedCandidateNames(Filter<String> filter) {
+ return StringTools.quote(this.candidateNames(filter));
+ }
+
+ private Iterator<String> candidateSchemas() {
+ return this.database().schemaNames();
+ }
+
+ private Iterator<String> candidateSchemas(Filter<String> filter) {
+ return new FilteringIterator<String>(this.candidateSchemas(), filter);
+ }
+
+ private Iterator<String> quotedCandidateSchemas(Filter<String> filter) {
+ return StringTools.quote(this.candidateSchemas(filter));
+ }
+
+ private Iterator<String> candidateCatalogs() {
+ return this.database().catalogNames();
+ }
+
+ private Iterator<String> candidateCatalogs(Filter<String> filter) {
+ return new FilteringIterator<String>(this.candidateCatalogs(), filter);
+ }
+
+ private Iterator<String> quotedCandidateCatalogs(Filter<String> filter) {
+ return StringTools.quote(this.candidateCatalogs(filter));
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java
index d7d8e6dc0a..f7bb9f840a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java.mappings;
+import java.util.Iterator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.CompilationUnit;
@@ -24,6 +25,7 @@ import org.eclipse.jpt.core.internal.jdtutility.MemberAnnotationAdapter;
import org.eclipse.jpt.core.internal.mappings.INamedColumn;
import org.eclipse.jpt.core.internal.platform.DefaultsContext;
import org.eclipse.jpt.db.internal.Table;
+import org.eclipse.jpt.utility.internal.Filter;
/**
* <!-- begin-user-doc -->
@@ -89,7 +91,7 @@ public abstract class JavaAttributeMapping extends JavaEObject
}
public boolean isDefault() {
- return getPersistentAttribute().isAttributeMappingDefault();
+ return getPersistentAttribute().mappingIsDefault();
}
public ITypeMapping typeMapping() {
@@ -109,7 +111,9 @@ public abstract class JavaAttributeMapping extends JavaEObject
return this.typeMapping().getPersistentType().findJdtType();
}
- public void updateFromJava(CompilationUnit astRoot) {}
+ public void updateFromJava(CompilationUnit astRoot) {
+ // do nothing - override as appropriate
+ }
// TODO figure out how to use [stupid] EMF to implement the Column.Owner interface directly
protected INamedColumn.Owner buildColumnOwner() {
@@ -129,10 +133,26 @@ public abstract class JavaAttributeMapping extends JavaEObject
}
public void refreshDefaults(DefaultsContext defaultsContext) {
- //do nothing, override if necessary
+ // do nothing - override as appropriate
}
public String primaryKeyColumnName() {
return null;
}
-} // JavaAttributeMapping \ No newline at end of file
+
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ return null;
+ }
+
+ public boolean isOverridableAttributeMapping() {
+ return false;
+ }
+
+ public boolean isOverridableAssociationMapping() {
+ return false;
+ }
+
+ public boolean isIdMapping() {
+ return false;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddable.java
index 1c372a1853..08b8a3c239 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddable.java
@@ -9,18 +9,12 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java.mappings;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.SimpleDeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.Type;
import org.eclipse.jpt.core.internal.mappings.IEmbeddable;
-import org.eclipse.jpt.core.internal.mappings.ITable;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
/**
* <!-- begin-user-doc -->
@@ -34,7 +28,7 @@ import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
*/
public class JavaEmbeddable extends JavaTypeMapping implements IEmbeddable
{
- public static final DeclarationAnnotationAdapter ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.EMBEDDABLE);
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.EMBEDDABLE);
protected JavaEmbeddable() {
throw new UnsupportedOperationException("Use JavaEmbeddable(Type) instead");
@@ -46,7 +40,7 @@ public class JavaEmbeddable extends JavaTypeMapping implements IEmbeddable
@Override
protected DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return ANNOTATION_ADAPTER;
+ return DECLARATION_ANNOTATION_ADAPTER;
}
/**
@@ -63,36 +57,8 @@ public class JavaEmbeddable extends JavaTypeMapping implements IEmbeddable
return IMappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY;
}
- public boolean tableNameIsInvalid(String tableName) {
- return false;
- }
-
- public Iterator<String> associatedTableNamesIncludingInherited() {
- return EmptyIterator.instance();
- }
-
- public Iterator<ITable> associatedTables() {
- return EmptyIterator.instance();
- }
-
- public Iterator<ITable> associatedTablesIncludingInherited() {
- return EmptyIterator.instance();
- }
-
- public Iterator<String> overridableAttributeNames() {
- return EmptyIterator.instance();
- }
-
- public Iterator<String> overridableAssociationNames() {
- return EmptyIterator.instance();
- }
-
@Override
public boolean attributeMappingKeyAllowed(String attributeMappingKey) {
return attributeMappingKey == IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY || attributeMappingKey == IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY;
}
-
- public List<String> candidateValuesFor(int pos, CompilationUnit astRoot) {
- return Collections.emptyList();
- }
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddableProvider.java
index 879b5f1f39..714a815a6c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddableProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEmbeddableProvider.java
@@ -48,7 +48,7 @@ public class JavaEmbeddableProvider
}
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return JavaEmbeddable.ANNOTATION_ADAPTER;
+ return JavaEmbeddable.DECLARATION_ANNOTATION_ADAPTER;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java
index 5fe6cf40e0..48f0d0e099 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java
@@ -10,7 +10,6 @@
package org.eclipse.jpt.core.internal.content.java.mappings;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.notify.Notification;
@@ -56,8 +55,8 @@ import org.eclipse.jpt.core.internal.mappings.InheritanceType;
import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
import org.eclipse.jpt.db.internal.Table;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.Filter;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
@@ -329,7 +328,7 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
private AnnotationAdapter sequenceGeneratorAnnotationAdapter;
- public static final DeclarationAnnotationAdapter ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.ENTITY);
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.ENTITY);
private static final DeclarationAnnotationElementAdapter NAME_ADAPTER = buildNameAdapter();
@@ -339,7 +338,7 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
private static final DeclarationAnnotationAdapter DISCRIMINATOR_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.DISCRIMINATOR_VALUE);
- private static final DeclarationAnnotationElementAdapter DISCRIMINATOR_VALUE_ADAPTER = buildValueAdapter();
+ private static final DeclarationAnnotationElementAdapter DISCRIMINATOR_VALUE_ADAPTER = buildDiscriminatorValueAdapter();
protected JavaEntity() {
this(null);
@@ -375,11 +374,11 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
@Override
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return ANNOTATION_ADAPTER;
+ return DECLARATION_ANNOTATION_ADAPTER;
}
private static DeclarationAnnotationElementAdapter buildNameAdapter() {
- return new ConversionDeclarationAnnotationElementAdapter(ANNOTATION_ADAPTER, JPA.ENTITY__NAME, false); // false = do not remove annotation when empty
+ return new ConversionDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ENTITY__NAME, false); // false = do not remove annotation when empty
}
/**
@@ -1171,14 +1170,6 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
return specifiedName;
}
- private String specifiedNameFromJava() {
- return (String) this.getType().annotationElementValue(NAME_ADAPTER);
- }
-
- private String defaultNameFromJava() {
- return super.getName();
- }
-
/**
* Sets the value of the '{@link org.eclipse.jpt.core.internal.content.java.mappings.JavaEntity#getSpecifiedName <em>Specified Name</em>}' attribute.
* <!-- begin-user-doc -->
@@ -2256,24 +2247,29 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
@Override
public void updateFromJava(CompilationUnit astRoot) {
- //TODO creating a new AST for each of these, maybe we should reduce this
- //and have the javaChanged(ElementChangedEvent) pass the AST.
- //same problem in the xml world, the defaults are taken from java
- this.setSpecifiedName(specifiedNameFromJava());
- this.setDefaultName(defaultNameFromJava());
- ((JavaTable) this.getTable()).updateFromJava(astRoot);
+ this.setSpecifiedName((String) this.getType().annotationElementValue(NAME_ADAPTER, astRoot));
+ this.setDefaultName(this.getType().getName());
+ this.getJavaTable().updateFromJava(astRoot);
this.updateSecondaryTablesFromJava(astRoot);
this.updateNamedQueriesFromJava(astRoot);
this.updateNamedNativeQueriesFromJava(astRoot);
this.updateAttributeOverridesFromJava(astRoot);
this.setInheritanceStrategy(InheritanceType.fromJavaAnnotationValue(this.inheritanceStrategyAdapter.getValue(astRoot)));
- ((JavaDiscriminatorColumn) this.getDiscriminatorColumn()).updateFromJava(astRoot);
+ this.getJavaDiscriminatorColumn().updateFromJava(astRoot);
this.setSpecifiedDiscriminatorValue((String) this.discriminatorValueAdapter.getValue(astRoot));
this.setDefaultDiscriminatorValue(this.javaDefaultDiscriminatorValue());
this.updateTableGeneratorFromJava(astRoot);
this.updateSequenceGeneratorFromJava(astRoot);
}
+ private JavaTable getJavaTable() {
+ return (JavaTable) this.table;
+ }
+
+ private JavaDiscriminatorColumn getJavaDiscriminatorColumn() {
+ return (JavaDiscriminatorColumn) this.discriminatorColumn;
+ }
+
private void updateTableGeneratorFromJava(CompilationUnit astRoot) {
if (this.tableGeneratorAnnotationAdapter.getAnnotation(astRoot) == null) {
if (getTableGenerator() != null) {
@@ -2313,7 +2309,13 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
* TODO extension point for provider-specific function?
*/
private String javaDefaultDiscriminatorValue() {
- return ((!getType().isAbstract()) && this.discriminatorType().isString()) ? getName() : null;
+ if (this.getType().isAbstract()) {
+ return null;
+ }
+ if (!this.discriminatorType().isString()) {
+ return null;
+ }
+ return this.getName();
}
private DiscriminatorType discriminatorType() {
@@ -2567,14 +2569,17 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
return pkAttributeName;
}
+ @Override
public boolean tableNameIsInvalid(String tableName) {
return !CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName);
}
+ @Override
public Iterator<ITable> associatedTables() {
return new CompositeIterator<ITable>(this.getTable(), this.getSecondaryTables().iterator());
}
+ @Override
public Iterator<ITable> associatedTablesIncludingInherited() {
return new CompositeIterator<ITable>(new TransformationIterator<ITypeMapping, Iterator<ITable>>(this.inheritanceHierarchy()) {
@Override
@@ -2592,6 +2597,7 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
});
}
+ @Override
public Iterator<String> associatedTableNamesIncludingInherited() {
return this.nonNullTableNames(this.associatedTablesIncludingInherited());
}
@@ -2647,14 +2653,6 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
});
}
- public Iterator<String> overridableAttributeNames() {
- return EmptyIterator.instance();
- }
-
- public Iterator<String> overridableAssociationNames() {
- return EmptyIterator.instance();
- }
-
public IAttributeOverride createAttributeOverride(int index) {
return createJavaAttributeOverride(index);
}
@@ -2746,8 +2744,49 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
}
}
- public List<String> candidateValuesFor(int pos, CompilationUnit astRoot) {
- return Collections.emptyList();
+ @Override
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ Iterator<String> result;
+ result = this.getJavaTable().candidateValuesFor(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ // result = this.secondaryTablesCandidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ // result = this.specifiedPrimaryKeyJoinColumnsCandidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ // result = this.attributeOverridesCandidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ // result = this.associationOverridesCandidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ // result = this.getJavaDiscriminatorColumn().candidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ // result = this.tableGeneratorCandidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ // result = this.sequenceGeneratorCandidateValuesFor(pos, astRoot);
+ // if (result != null) {
+ // return result;
+ // }
+ //
+ return null;
}
// ********** static methods **********
@@ -2755,7 +2794,7 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
return new EnumDeclarationAnnotationElementAdapter(INHERITANCE_ANNOTATION_ADAPTER, JPA.INHERITANCE__STRATEGY);
}
- private static DeclarationAnnotationElementAdapter buildValueAdapter() {
+ private static DeclarationAnnotationElementAdapter buildDiscriminatorValueAdapter() {
return new ConversionDeclarationAnnotationElementAdapter(DISCRIMINATOR_ANNOTATION_ADAPTER, JPA.DISCRIMINATOR_VALUE__VALUE);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntityProvider.java
index 868c5d918f..fe3796d8b5 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntityProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntityProvider.java
@@ -48,7 +48,7 @@ public class JavaEntityProvider
}
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return JavaEntity.ANNOTATION_ADAPTER;
+ return JavaEntity.DECLARATION_ANNOTATION_ADAPTER;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclass.java
index f8999c5da3..f5e9743bc8 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclass.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclass.java
@@ -9,19 +9,14 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java.mappings;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.SimpleDeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.Type;
import org.eclipse.jpt.core.internal.mappings.IMappedSuperclass;
-import org.eclipse.jpt.core.internal.mappings.ITable;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
@@ -38,7 +33,7 @@ import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
public class JavaMappedSuperclass extends JavaTypeMapping
implements IMappedSuperclass
{
- public static final DeclarationAnnotationAdapter ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.MAPPED_SUPERCLASS);
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.MAPPED_SUPERCLASS);
/**
* <!-- begin-user-doc -->
@@ -55,7 +50,7 @@ public class JavaMappedSuperclass extends JavaTypeMapping
@Override
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return ANNOTATION_ADAPTER;
+ return DECLARATION_ANNOTATION_ADAPTER;
}
/**
@@ -72,53 +67,40 @@ public class JavaMappedSuperclass extends JavaTypeMapping
return IMappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY;
}
- public boolean tableNameIsInvalid(String tableName) {
- return false;
- }
-
- public Iterator<String> associatedTableNamesIncludingInherited() {
- return EmptyIterator.instance();
- }
-
- public Iterator<ITable> associatedTables() {
- return EmptyIterator.instance();
- }
-
- public Iterator<ITable> associatedTablesIncludingInherited() {
- return EmptyIterator.instance();
+ @Override
+ public Iterator<String> overridableAttributeNames() {
+ return this.namesOf(this.overridableAttributes());
}
- public Iterator<String> overridableAttributeNames() {
- return new TransformationIterator<IPersistentAttribute, String>(new FilteringIterator<IPersistentAttribute>(getPersistentType().attributes()) {
+ private Iterator<IPersistentAttribute> overridableAttributes() {
+ return new FilteringIterator<IPersistentAttribute>(this.getPersistentType().attributes()) {
@Override
protected boolean accept(Object o) {
- String key = ((IPersistentAttribute) o).getMappingKey();
- return key == IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY || key == IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY;
- }
- }) {
- @Override
- protected String transform(IPersistentAttribute next) {
- return next.getName();
+ return ((IPersistentAttribute) o).isOverridableAttribute();
}
};
}
+ @Override
public Iterator<String> overridableAssociationNames() {
- return new TransformationIterator<IPersistentAttribute, String>(new FilteringIterator<IPersistentAttribute>(getPersistentType().attributes()) {
+ return this.namesOf(this.overridableAssociations());
+ }
+
+ private Iterator<IPersistentAttribute> overridableAssociations() {
+ return new FilteringIterator<IPersistentAttribute>(this.getPersistentType().attributes()) {
@Override
protected boolean accept(Object o) {
- String key = ((IPersistentAttribute) o).getMappingKey();
- return key == IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY || key == IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY;
- }
- }) {
- @Override
- protected String transform(IPersistentAttribute next) {
- return next.getName();
+ return ((IPersistentAttribute) o).isOverridableAssociation();
}
};
}
- public List<String> candidateValuesFor(int pos, CompilationUnit astRoot) {
- return Collections.emptyList();
+ private Iterator<String> namesOf(Iterator<IPersistentAttribute> attributes) {
+ return new TransformationIterator<IPersistentAttribute, String>(attributes) {
+ @Override
+ protected String transform(IPersistentAttribute attribute) {
+ return attribute.getName();
+ }
+ };
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclassProvider.java
index 9689b8fd48..b149fcabc7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclassProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMappedSuperclassProvider.java
@@ -48,7 +48,7 @@ public class JavaMappedSuperclassProvider
}
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return JavaMappedSuperclass.ANNOTATION_ADAPTER;
+ return JavaMappedSuperclass.DECLARATION_ANNOTATION_ADAPTER;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMapping.java
index 19cc26a072..aa20d185bd 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMapping.java
@@ -9,16 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java.mappings;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.NullDeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.Type;
-import org.eclipse.jpt.core.internal.mappings.ITable;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
/**
* <!-- begin-user-doc -->
@@ -32,7 +26,7 @@ import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
*/
public class JavaNullTypeMapping extends JavaTypeMapping
{
- public static final DeclarationAnnotationAdapter ANNOTATION_ADAPTER = NullDeclarationAnnotationAdapter.instance();
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = NullDeclarationAnnotationAdapter.instance();
/**
* <!-- begin-user-doc -->
@@ -49,7 +43,7 @@ public class JavaNullTypeMapping extends JavaTypeMapping
@Override
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return ANNOTATION_ADAPTER;
+ return DECLARATION_ANNOTATION_ADAPTER;
}
/**
@@ -65,32 +59,4 @@ public class JavaNullTypeMapping extends JavaTypeMapping
public String getKey() {
return null;
}
-
- public boolean tableNameIsInvalid(String tableName) {
- return false;
- }
-
- public Iterator<String> associatedTableNamesIncludingInherited() {
- return EmptyIterator.instance();
- }
-
- public Iterator<ITable> associatedTables() {
- return EmptyIterator.instance();
- }
-
- public Iterator<ITable> associatedTablesIncludingInherited() {
- return EmptyIterator.instance();
- }
-
- public Iterator<String> overridableAssociationNames() {
- return EmptyIterator.instance();
- }
-
- public Iterator<String> overridableAttributeNames() {
- return EmptyIterator.instance();
- }
-
- public List<String> candidateValuesFor(int pos, CompilationUnit astRoot) {
- return Collections.emptyList();
- }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMappingProvider.java
index 8c692695bd..3e12a969f2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMappingProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaNullTypeMappingProvider.java
@@ -49,7 +49,7 @@ public class JavaNullTypeMappingProvider
}
public DeclarationAnnotationAdapter declarationAnnotationAdapter() {
- return JavaNullTypeMapping.ANNOTATION_ADAPTER;
+ return JavaNullTypeMapping.DECLARATION_ANNOTATION_ADAPTER;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaTypeMapping.java
index f18152a0de..fdda0b69c7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaTypeMapping.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java.mappings;
+import java.util.Iterator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.IPersistentType;
@@ -19,7 +20,10 @@ import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.internal.jdtutility.Type;
+import org.eclipse.jpt.core.internal.mappings.ITable;
import org.eclipse.jpt.db.internal.Table;
+import org.eclipse.jpt.utility.internal.Filter;
+import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
/**
* <!-- begin-user-doc -->
@@ -89,38 +93,12 @@ public abstract class JavaTypeMapping extends JavaEObject
return JpaJavaMappingsPackage.Literals.JAVA_TYPE_MAPPING;
}
- /**
- * Returns the value of the '<em><b>Name</b></em>' attribute.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Name</em>' attribute isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Name</em>' attribute.
- * @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getITypeMapping_Name()
- * @model changeable="false" volatile="true" derived="true"
- * @generated NOT
- */
public String getName() {
- return getType().getName();
+ return this.getType().getName();
}
- /**
- * Returns the value of the '<em><b>Table Name</b></em>' attribute.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Table Name</em>' attribute isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Table Name</em>' attribute.
- * @see org.eclipse.jpt.core.internal.content.java.mappings.JpaJavaMappingsPackage#getITypeMapping_TableName()
- * @model changeable="false" volatile="true" derived="true"
- * @generated NOT
- */
public String getTableName() {
- return getType().getName();
+ return this.getType().getName();
}
/**
@@ -135,14 +113,8 @@ public abstract class JavaTypeMapping extends JavaEObject
throw new UnsupportedOperationException();
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model kind="operation" required="true"
- * @generated NOT
- */
public IPersistentType getPersistentType() {
- return (IPersistentType) eContainer();
+ return (IPersistentType) this.eContainer();
}
/**
@@ -230,7 +202,7 @@ public abstract class JavaTypeMapping extends JavaEObject
}
public void updateFromJava(CompilationUnit astRoot) {
- // do nothing
+ // do nothing
}
public Type getType() {
@@ -238,8 +210,8 @@ public abstract class JavaTypeMapping extends JavaEObject
}
public ITextRange getTextRange() {
- ITextRange textRange = type.annotationTextRange(declarationAnnotationAdapter());
- return (textRange == null) ? getPersistentType().getTextRange() : textRange;
+ ITextRange textRange = this.type.annotationTextRange(this.declarationAnnotationAdapter());
+ return (textRange != null) ? textRange : this.getPersistentType().getTextRange();
}
public Table primaryDbTable() {
@@ -250,12 +222,35 @@ public abstract class JavaTypeMapping extends JavaEObject
return null;
}
- /**
- * @see ITypeMapping#attributeMappingKeyAllowed(String)
- *
- * Default implementation: override where needed
- */
public boolean attributeMappingKeyAllowed(String attributeMappingKey) {
return true;
}
+
+ public Iterator<ITable> associatedTables() {
+ return EmptyIterator.instance();
+ }
+
+ public Iterator<String> associatedTableNamesIncludingInherited() {
+ return EmptyIterator.instance();
+ }
+
+ public Iterator<ITable> associatedTablesIncludingInherited() {
+ return EmptyIterator.instance();
+ }
+
+ public Iterator<String> candidateValuesFor(int pos, Filter<String> filter, CompilationUnit astRoot) {
+ return EmptyIterator.instance();
+ }
+
+ public Iterator<String> overridableAssociationNames() {
+ return EmptyIterator.instance();
+ }
+
+ public Iterator<String> overridableAttributeNames() {
+ return EmptyIterator.instance();
+ }
+
+ public boolean tableNameIsInvalid(String tableName) {
+ return false;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlColumn.java
index d9d9d6c750..9a6932202a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlColumn.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2007 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0, which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html.
+ * 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
@@ -924,6 +924,6 @@ public abstract class AbstractXmlColumn extends AbstractXmlNamedColumn
return owner.getTextRange();
}
IDOMNode tableNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.ENTITY__TABLE);
- return (tableNode == null) ? getTextRange() : getTextRange(tableNode);
+ return (tableNode == null) ? getTextRange() : buildTextRange(tableNode);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlNamedColumn.java
index d12c7259d8..bacb48c8cc 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlNamedColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlNamedColumn.java
@@ -442,7 +442,7 @@ public abstract class AbstractXmlNamedColumn extends XmlEObject
return owner.getTextRange();
}
IDOMNode nameNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.NAME);
- return (nameNode == null) ? getTextRange() : getTextRange(nameNode);
+ return (nameNode == null) ? getTextRange() : buildTextRange(nameNode);
}
public void refreshDefaults(DefaultsContext defaultsContext) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlTable.java
index f9e60bf29f..7d2c7fbc06 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/AbstractXmlTable.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.content.orm;
import java.util.Set;
@@ -869,7 +870,7 @@ public abstract class AbstractXmlTable extends XmlEObject implements ITable
return owner.getTextRange();
}
IDOMNode nameNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.NAME);
- return (nameNode == null) ? getTextRange() : getTextRange(nameNode);
+ return (nameNode == null) ? getTextRange() : buildTextRange(nameNode);
}
public ITextRange getSchemaTextRange() {
@@ -877,7 +878,7 @@ public abstract class AbstractXmlTable extends XmlEObject implements ITable
return owner.getTextRange();
}
IDOMNode schemaNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.SCHEMA);
- return (schemaNode == null) ? getTextRange() : getTextRange(schemaNode);
+ return (schemaNode == null) ? getTextRange() : buildTextRange(schemaNode);
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlAttributeMapping.java
index dd7c123e60..220380093f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlAttributeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlAttributeMapping.java
@@ -352,10 +352,22 @@ public abstract class XmlAttributeMapping extends XmlEObject
public ITextRange getNameTextRange() {
IDOMNode nameNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.NAME);
if (nameNode != null) {
- return getTextRange(nameNode);
+ return buildTextRange(nameNode);
}
else {
return getTextRange();
}
}
+
+ public boolean isOverridableAttributeMapping() {
+ return false;
+ }
+
+ public boolean isOverridableAssociationMapping() {
+ return false;
+ }
+
+ public boolean isIdMapping() {
+ return false;
+ }
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinColumn.java
index 4d301f1331..f8af8e2b85 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlJoinColumn.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.content.orm;
import org.eclipse.emf.common.notify.Notification;
@@ -445,7 +446,7 @@ public class XmlJoinColumn extends AbstractXmlColumn implements IJoinColumn
return owner.getTextRange();
}
IDOMNode referencedColumnNameNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.REFERENCED_COLUMN_NAME);
- return (referencedColumnNameNode == null) ? getTextRange() : getTextRange(referencedColumnNameNode);
+ return (referencedColumnNameNode == null) ? getTextRange() : buildTextRange(referencedColumnNameNode);
}
public void refreshDefaults(DefaultsContext defaultsContext) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPrimaryKeyJoinColumn.java
index 4da746485c..7e7a752e1b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPrimaryKeyJoinColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPrimaryKeyJoinColumn.java
@@ -406,6 +406,6 @@ public class XmlPrimaryKeyJoinColumn extends AbstractXmlNamedColumn
return owner.getTextRange();
}
IDOMNode referencedColumnNameNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.REFERENCED_COLUMN_NAME);
- return (referencedColumnNameNode == null) ? getTextRange() : getTextRange(referencedColumnNameNode);
+ return (referencedColumnNameNode == null) ? getTextRange() : buildTextRange(referencedColumnNameNode);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlTypeMapping.java
index 6b9f03a2b0..8ea3b36374 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlTypeMapping.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2006, 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.content.orm;
import org.eclipse.emf.common.notify.Notification;
@@ -613,7 +614,7 @@ public abstract class XmlTypeMapping extends XmlEObject implements ITypeMapping
public ITextRange getClassTextRange() {
IDOMNode classNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.CLASS);
if (classNode != null) {
- return getTextRange(classNode);
+ return buildTextRange(classNode);
}
else {
return getTextRange();
@@ -623,7 +624,7 @@ public abstract class XmlTypeMapping extends XmlEObject implements ITypeMapping
public ITextRange getAttributesTextRange() {
IDOMNode attributesNode = (IDOMNode) DOMUtilities.getNodeChild(node, OrmXmlMapper.ATTRIBUTES);
if (attributesNode != null) {
- return getTextRange(attributesNode);
+ return buildTextRange(attributesNode);
}
else {
return getTextRange();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java
index 3a4e455e11..046bb0ec6e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
- * Contributors: Oracle - initial API and implementation
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.content.persistence;
import org.eclipse.emf.common.notify.Notification;
@@ -159,10 +160,10 @@ public class JavaClassRef extends XmlEObject
public ITextRange getTextRange() {
IDOMNode textNode = (IDOMNode) DOMUtilities.getChildTextNode(node);
if (textNode != null) {
- return getTextRange(textNode);
+ return buildTextRange(textNode);
}
else {
- return getTextRange(node);
+ return buildTextRange(node);
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java
index 402355225d..131f5e3224 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
- * Contributors: Oracle - initial API and implementation
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.content.persistence;
import java.util.Iterator;
@@ -193,7 +194,7 @@ public class MappingFileRef extends XmlEObject
@Override
public ITextRange getTextRange() {
IDOMNode textNode = (IDOMNode) DOMUtilities.getChildTextNode(node);
- return (textNode == null) ? getTextRange(node) : getTextRange(textNode);
+ return (textNode == null) ? buildTextRange(node) : buildTextRange(textNode);
}
public IJpaFile getMappingFile() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/ASTNodeTextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/ASTNodeTextRange.java
index ec204946b3..8884f10764 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/ASTNodeTextRange.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/ASTNodeTextRange.java
@@ -12,6 +12,7 @@ package org.eclipse.jpt.core.internal.jdtutility;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.ITextRange;
+import org.eclipse.jpt.utility.internal.StringTools;
/**
* Straightforward implementation of ITextRange that adapts an ASTNode.
@@ -24,10 +25,6 @@ public class ASTNodeTextRange implements ITextRange {
this.astNode = astNode;
}
- public int getLineNumber() {
- return ((CompilationUnit) this.astNode.getRoot()).getLineNumber(this.getOffset());
- }
-
public int getOffset() {
return this.astNode.getStartPosition();
}
@@ -36,4 +33,23 @@ public class ASTNodeTextRange implements ITextRange {
return this.astNode.getLength();
}
+ public int getLineNumber() {
+ return ((CompilationUnit) this.astNode.getRoot()).getLineNumber(this.getOffset());
+ }
+
+ public boolean includes(int index) {
+ return (this.getOffset() <= index) && (index <= this.end());
+ }
+
+ private int end() {
+ return this.getOffset() + this.getLength() - 1;
+ }
+
+ @Override
+ public String toString() {
+ String start = String.valueOf(this.getOffset());
+ String end = String.valueOf(this.getOffset() + this.getLength() - 1);
+ return StringTools.buildToStringFor(this, start + ", " + end);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java
index f3cf3de1d6..8318f55ea0 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java
@@ -1,15 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved. This program and
- * the accompanying materials are made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.validation;
import org.eclipse.jpt.core.internal.ITextRange;
+import org.eclipse.jpt.core.internal.SimpleTextRange;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -18,20 +19,7 @@ public class JpaValidationMessages
{
private static String[] DEFAULT_PARAMS = new String[0];
- private static ITextRange DEFAULT_TEXT_RANGE =
- new ITextRange() {
- public int getLength() {
- return 0;
- }
-
- public int getLineNumber() {
- return 0;
- }
-
- public int getOffset() {
- return 0;
- }
- };
+ private static ITextRange DEFAULT_TEXT_RANGE = new SimpleTextRange(0, 0, 0);
public static IMessage buildMessage(
int severity, String messageId, Object targetObject) {
diff --git a/jpa/plugins/org.eclipse.jpt.ui/plugin.properties b/jpa/plugins/org.eclipse.jpt.ui/plugin.properties
index b92c5001be..995f6f5058 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.ui/plugin.properties
@@ -1,12 +1,11 @@
###############################################################################
-# Copyright (c) 2006 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
+# Copyright (c) 2006, 2007 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
#
# Contributors:
-# Oracle. - initial API and implementation
+# Oracle - initial API and implementation
###############################################################################
# ====================================================================
@@ -48,3 +47,4 @@ jpaPerspective = JPA Development
jpaDetails = JPA Details
jpaStructure = JPA Structure
+JpaProposalCategory = JPA Proposals
diff --git a/jpa/plugins/org.eclipse.jpt.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.ui/plugin.xml
index 9fae188700..0a2d07d569 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.ui/plugin.xml
@@ -222,16 +222,27 @@
</extension>
+<!-- =================================================================================== -->
+<!-- Extension: Java Completion Proposal Computer -->
+<!-- =================================================================================== -->
+
<extension
point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
- id="Foo"
- name="JPA Proposals">
+ id="JpaCompletionProposalComputer">
<javaCompletionProposalComputer
class="org.eclipse.jpt.ui.internal.JpaCompletionProposalComputer"
- categoryId="org.eclipse.jdt.ui.javaTypeProposalCategory">
+ categoryId="org.eclipse.jpt.ui.jpaProposalCategory">
<partition type="__dftl_partition_content_type"/>
<partition type="__java_string"/>
</javaCompletionProposalComputer>
</extension>
+ <extension
+ point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
+ id="jpaProposalCategory"
+ name="%JpaProposalCategory">
+ <proposalCategory
+ icon="$nl$/icons/full/eview16/jpa_perspective.gif"/>
+ </extension>
+
</plugin>
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java
index d13045878f..d556ed22cf 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java
@@ -9,21 +9,26 @@
******************************************************************************/
package org.eclipse.jpt.ui.internal;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
+
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jpt.core.internal.IJpaFile;
-import org.eclipse.jpt.core.internal.IJpaProject;
import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.jpt.core.internal.content.java.JavaPersistentType;
import org.eclipse.jpt.core.internal.content.java.JpaCompilationUnit;
+import org.eclipse.jpt.utility.internal.Filter;
+import org.eclipse.jpt.utility.internal.StringTools;
public class JpaCompletionProposalComputer implements IJavaCompletionProposalComputer {
@@ -37,40 +42,58 @@ public class JpaCompletionProposalComputer implements IJavaCompletionProposalCom
@SuppressWarnings("unchecked")
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
-// this.xxx((JavaContentAssistInvocationContext) context);
- return Collections.EMPTY_LIST;
+ return (context instanceof JavaContentAssistInvocationContext) ?
+ this.computeCompletionProposals((JavaContentAssistInvocationContext) context)
+ :
+ Collections.emptyList();
}
- private void xxx(JavaContentAssistInvocationContext context) {
+ private List<ICompletionProposal> computeCompletionProposals(JavaContentAssistInvocationContext context) {
try {
- this.xxx_(context);
- } catch (Exception ex) {
+ return this.computeCompletionProposals_(context);
+ } catch (JavaModelException ex) {
throw new RuntimeException(ex);
}
}
- private void xxx_(JavaContentAssistInvocationContext context) throws Exception {
- System.out.println(context.getCoreContext());
-// System.out.println("identifier prefix: " + context.computeIdentifierPrefix());
-// System.out.println("select length: " + context.getCompilationUnit().codeSelect(context.getInvocationOffset(), 0).length);
-
+ private List<ICompletionProposal> computeCompletionProposals_(JavaContentAssistInvocationContext context) throws JavaModelException {
ICompilationUnit cu = context.getCompilationUnit();
- IResource resource = cu.getCorrespondingResource();
- System.out.println("CU resource: " + resource);
- IFile file = (IFile) resource;
+ if (cu == null) {
+ return Collections.emptyList();
+ }
+
+ IJpaFile jpaFile = JptCorePlugin.getJpaFile((IFile) cu.getCorrespondingResource());
+ if (jpaFile == null) {
+ return Collections.emptyList();
+ }
- IJpaFile jpaFile = JptCorePlugin.getJpaFile(file);
- System.out.println("JPA file: " + jpaFile);
-
JpaCompilationUnit jpaCU = (JpaCompilationUnit) jpaFile.getContent();
- System.out.println("java persistent type: " + jpaCU.candidateValuesFor(context.getInvocationOffset()));
-
- IJpaProject jpaProject = jpaFile.getJpaProject();
- System.out.println("JPA project: " + jpaProject);
-
- IType iType = cu.findPrimaryType();
- JavaPersistentType pType = jpaProject.findJavaPersistentType(iType);
- System.out.println("java persistent type: " + pType);
+ CompletionContext cc = context.getCoreContext();
+
+ // the context's "token" is really a sort of "prefix" - it does NOT
+ // correspond to the "start" and "end" we get below...
+ char[] prefix = cc.getToken();
+ Filter<String> filter = new IgnoreCasePrefixFilter(prefix);
+ // the token "start" is the offset of the token's first character
+ int tokenStart = cc.getTokenStart();
+ // the token "end" is the offset of the token's last character (yuk)
+ int tokenEnd = cc.getTokenEnd();
+
+// System.out.println("prefix: " + new String(prefix));
+// System.out.println("token start: " + tokenStart);
+// System.out.println("token end: " + tokenEnd);
+// String source = cu.getSource();
+// String token = source.substring(tokenStart, tokenEnd + 1);
+// System.out.println("token: =>" + token + "<=");
+// String snippet = source.substring(Math.max(0, tokenStart - 20), Math.min(source.length(), tokenEnd + 21));
+// System.out.println("surrounding snippet: =>" + snippet + "<=");
+
+ List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+ for (Iterator<String> stream = jpaCU.candidateValuesFor(context.getInvocationOffset(), filter); stream.hasNext(); ) {
+ String s = stream.next();
+ proposals.add(new CompletionProposal(s, tokenStart, tokenEnd - tokenStart + 1, s.length()));
+ }
+ return proposals;
}
@SuppressWarnings("unchecked")
@@ -86,4 +109,15 @@ public class JpaCompletionProposalComputer implements IJavaCompletionProposalCom
// do nothing
}
+ private class IgnoreCasePrefixFilter implements Filter<String> {
+ private final char[] prefix;
+ IgnoreCasePrefixFilter(char[] prefix) {
+ super();
+ this.prefix = prefix;
+ }
+ public boolean accept(String s) {
+ return StringTools.stringStartsWithIgnoreCase(s.toCharArray(), prefix);
+ }
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/StringTools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/StringTools.java
index eac9e5e42d..5d17b69a15 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/StringTools.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/StringTools.java
@@ -12,6 +12,9 @@ package org.eclipse.jpt.utility.internal;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
+import java.util.Iterator;
+
+import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
/**
* Convenience methods related to the java.lang.String class.
@@ -21,6 +24,10 @@ public final class StringTools {
/** carriage return */
public static final String CR = System.getProperty("line.separator");
+ /** double quote */
+ public static final char QUOTE = '"';
+
+
// ********** padding/truncating **********
@@ -766,6 +773,242 @@ public final class StringTools {
}
+ // ********** wrapping/quoting **********
+
+ /**
+ * Wrap the specified string with double quotes.
+ */
+ public static String quote(String string) {
+ return wrap(string, QUOTE);
+ }
+
+ /**
+ * Wrap the specified string with double quotes.
+ */
+ public static void quoteOn(String string, Writer writer) {
+ wrapOn(string, QUOTE, writer);
+ }
+
+ /**
+ * Wrap the specified string with double quotes.
+ */
+ public static void quoteOn(String string, StringBuffer sb) {
+ wrapOn(string, QUOTE, sb);
+ }
+
+ /**
+ * Wrap each of the specified strings with double quotes.
+ */
+ public static Iterator<String> quote(Iterator<String> strings) {
+ return new TransformationIterator<String, String>(strings) {
+ @Override
+ protected String transform(String string) {
+ return StringTools.quote(string);
+ }
+ };
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static String wrap(String string, char wrap) {
+ return new String(wrap(string.toCharArray(), wrap));
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(String string, char wrap, Writer writer) {
+ wrapOn(string.toCharArray(), wrap, writer);
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(String string, char wrap, StringBuffer sb) {
+ wrapOn(string.toCharArray(), wrap, sb);
+ }
+
+ /**
+ * Wrap each of the specified strings with the specified wrap; i.e. put a
+ * copy of the wrap at the front and back of the resulting string.
+ */
+ public static Iterator<String> wrap(Iterator<String> strings, final char wrap) {
+ return new TransformationIterator<String, String>(strings) {
+ @Override
+ protected String transform(String string) {
+ return StringTools.wrap(string, wrap);
+ }
+ };
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static String wrap(String string, String wrap) {
+ return new String(wrap(string.toCharArray(), wrap.toCharArray()));
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(String string, String wrap, Writer writer) {
+ wrapOn(string.toCharArray(), wrap.toCharArray(), writer);
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(String string, String wrap, StringBuffer sb) {
+ wrapOn(string.toCharArray(), wrap.toCharArray(), sb);
+ }
+
+ /**
+ * Wrap each of the specified strings with the specified wrap; i.e. put a
+ * copy of the wrap at the front and back of the resulting string.
+ */
+ public static Iterator<String> wrap(Iterator<String> strings, final String wrap) {
+ return new TransformationIterator<String, String>(strings) {
+ @Override
+ protected String transform(String string) {
+ return StringTools.wrap(string, wrap);
+ }
+ };
+ }
+
+ /**
+ * Wrap the specified string with double quotes.
+ */
+ public static char[] quote(char[] string) {
+ return wrap(string, QUOTE);
+ }
+
+ /**
+ * Wrap the specified string with double quotes.
+ */
+ public static void quoteOn(char[] string, Writer writer) {
+ wrapOn(string, QUOTE, writer);
+ }
+
+ /**
+ * Wrap the specified string with double quotes.
+ */
+ public static void quoteOn(char[] string, StringBuffer sb) {
+ wrapOn(string, QUOTE, sb);
+ }
+
+ /**
+ * Wrap each of the specified strings with double quotes.
+ */
+ public static Iterator<char[]> quoteCharArrays(Iterator<char[]> strings) {
+ return new TransformationIterator<char[], char[]>(strings) {
+ @Override
+ protected char[] transform(char[] string) {
+ return StringTools.quote(string);
+ }
+ };
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static char[] wrap(char[] string, char wrap) {
+ int len = string.length;
+ char[] result = new char[len+2];
+ result[0] = wrap;
+ System.arraycopy(string, 0, result, 1, len);
+ result[len+1] = wrap;
+ return result;
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(char[] string, char wrap, Writer writer) {
+ writeCharOn(wrap, writer);
+ writeStringOn(string, writer);
+ writeCharOn(wrap, writer);
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(char[] string, char wrap, StringBuffer sb) {
+ sb.append(wrap);
+ sb.append(string);
+ sb.append(wrap);
+ }
+
+ /**
+ * Wrap each of the specified strings with the specified wrap; i.e. put a
+ * copy of the wrap at the front and back of the resulting string.
+ */
+ public static Iterator<char[]> wrapCharArrays(Iterator<char[]> strings, final char wrap) {
+ return new TransformationIterator<char[], char[]>(strings) {
+ @Override
+ protected char[] transform(char[] string) {
+ return StringTools.wrap(string, wrap);
+ }
+ };
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static char[] wrap(char[] string, char[] wrap) {
+ int stringLength = string.length;
+ int wrapLength = wrap.length;
+ char[] result = new char[stringLength+(2*wrapLength)];
+ System.arraycopy(wrap, 0, result, 0, wrapLength);
+ System.arraycopy(string, 0, result, wrapLength, stringLength);
+ System.arraycopy(wrap, 0, result, stringLength+wrapLength, wrapLength);
+ return result;
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(char[] string, char[] wrap, Writer writer) {
+ writeStringOn(wrap, writer);
+ writeStringOn(string, writer);
+ writeStringOn(wrap, writer);
+ }
+
+ /**
+ * Wrap the specified string with the specified wrap; i.e. put a copy of
+ * the wrap at the front and back of the resulting string.
+ */
+ public static void wrapOn(char[] string, char[] wrap, StringBuffer sb) {
+ sb.append(wrap);
+ sb.append(string);
+ sb.append(wrap);
+ }
+
+ /**
+ * Wrap each of the specified strings with the specified wrap; i.e. put a
+ * copy of the wrap at the front and back of the resulting string.
+ */
+ public static Iterator<char[]> wrapCharArrays(Iterator<char[]> strings, final char[] wrap) {
+ return new TransformationIterator<char[], char[]>(strings) {
+ @Override
+ protected char[] transform(char[] string) {
+ return StringTools.wrap(string, wrap);
+ }
+ };
+ }
+
+
// ********** removing characters **********
/**
@@ -997,7 +1240,7 @@ public final class StringTools {
* String#commonPrefixLength(String, int)
*/
public static int commonPrefixLength(String s1, String s2, int max) {
- return commonPrefixLength(s1.toCharArray(), s2.toCharArray());
+ return commonPrefixLength(s1.toCharArray(), s2.toCharArray(), max);
}
/**
@@ -1374,9 +1617,51 @@ public final class StringTools {
if ((s1 == null) || (s2 == null)) {
return false; // one is null but the other is not
}
- return new String(s1).equalsIgnoreCase(new String(s2));
+ if (s1.length != s2.length) {
+ return false;
+ }
+ for (int i = s1.length; i-- > 0; ) {
+ if ( ! charactersAreEqualIgnoreCase(s1[i], s2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Return whether the specified string starts with the specified prefix,
+ * ignoring case.
+ */
+ public static boolean stringStartsWithIgnoreCase(char[] string, char[] prefix) {
+ if (string.length < prefix.length) {
+ return false;
+ }
+ for (int i = prefix.length; i-- > 0; ) {
+ if ( ! charactersAreEqualIgnoreCase(string[i], prefix[i])) {
+ return false;
+ }
+ }
+ return true;
}
+ /**
+ * Return whether the specified string starts with the specified prefix,
+ * ignoring case.
+ */
+ public static boolean stringStartsWithIgnoreCase(String string, String prefix) {
+ return string.regionMatches(true, 0, prefix, 0, prefix.length());
+ }
+
+ /**
+ * Return whether the specified characters are are equal, ignoring case.
+ * @see java.lang.String#regionMatches(boolean, int, String, int, int)
+ */
+ public static boolean charactersAreEqualIgnoreCase(char c1, char c2) {
+ // something about the Georgian alphabet requires us to check lower case also
+ return (c1 == c2)
+ || (Character.toUpperCase(c1) == Character.toUpperCase(c2))
+ || (Character.toLowerCase(c1) == Character.toLowerCase(c2));
+ }
// ********** conversions **********
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
index 8e911e8e5a..454cb81651 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
@@ -226,6 +226,76 @@ public class StringToolsTests extends TestCase {
assertEquals(expected, sb.toString());
}
+ // ********** wrapping **********
+
+ public void testWrap() {
+ this.verifyWrap("Employee", "123", "123Employee123");
+ this.verifyWrap("123", "123", "123123123");
+ this.verifyWrap("", "123", "123123");
+ }
+
+ private void verifyWrap(String string, String wrap, String expectedString) {
+ assertEquals(expectedString, StringTools.wrap(string, wrap));
+ }
+
+ public void testWrapOnWriter() {
+ this.verifyWrapOnWriter("Employee", "123", "123Employee123");
+ this.verifyWrapOnWriter("123", "123", "123123123");
+ this.verifyWrapOnWriter("", "123", "123123");
+ }
+
+ private void verifyWrapOnWriter(String string, String wrap, String expectedString) {
+ Writer writer = new StringWriter();
+ StringTools.wrapOn(string, wrap, writer);
+ assertEquals(expectedString, writer.toString());
+ }
+
+ public void testWrapOnStringBuffer() {
+ this.verifyWrapOnStringBuffer("Employee", "123", "123Employee123");
+ this.verifyWrapOnStringBuffer("123", "123", "123123123");
+ this.verifyWrapOnStringBuffer("", "123", "123123");
+ }
+
+ private void verifyWrapOnStringBuffer(String string, String wrap, String expectedString) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.wrapOn(string, wrap, sb);
+ assertEquals(expectedString, sb.toString());
+ }
+
+ public void testQuote() {
+ this.verifyQuote("Employee", "\"Employee\"");
+ this.verifyQuote("123", "\"123\"");
+ this.verifyQuote("", "\"\"");
+ }
+
+ private void verifyQuote(String string, String expectedString) {
+ assertEquals(expectedString, StringTools.quote(string));
+ }
+
+ public void testQuoteOnWriter() {
+ this.verifyQuoteOnWriter("Employee", "\"Employee\"");
+ this.verifyQuoteOnWriter("123", "\"123\"");
+ this.verifyQuoteOnWriter("", "\"\"");
+ }
+
+ private void verifyQuoteOnWriter(String string, String expectedString) {
+ Writer writer = new StringWriter();
+ StringTools.quoteOn(string, writer);
+ assertEquals(expectedString, writer.toString());
+ }
+
+ public void testQuoteOnStringBuffer() {
+ this.verifyQuoteOnStringBuffer("Employee", "\"Employee\"");
+ this.verifyQuoteOnStringBuffer("123", "\"123\"");
+ this.verifyQuoteOnStringBuffer("", "\"\"");
+ }
+
+ private void verifyQuoteOnStringBuffer(String string, String expectedString) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.quoteOn(string, sb);
+ assertEquals(expectedString, sb.toString());
+ }
+
// ********** removing characters **********
public void testRemoveFirstOccurrence() {
@@ -337,6 +407,13 @@ public class StringToolsTests extends TestCase {
assertEquals(3, StringTools.commonPrefixLength("foo", "foo"));
}
+ public void testCommonPrefixLengthMax() {
+ assertEquals(2, StringTools.commonPrefixLength("fooZZZ", "fooBBB", 2));
+ assertEquals(2, StringTools.commonPrefixLength("foo", "fooBBB", 2));
+ assertEquals(2, StringTools.commonPrefixLength("fooZZZ", "foo", 2));
+ assertEquals(2, StringTools.commonPrefixLength("foo", "foo", 2));
+ }
+
// ********** capitalization **********
public void testCapitalizeCharArray() {
@@ -525,7 +602,7 @@ public class StringToolsTests extends TestCase {
// ********** queries **********
- public void testStringIsEmpty() {
+ public void testStringIsEmptyString() {
assertTrue(StringTools.stringIsEmpty((String) null));
assertTrue(StringTools.stringIsEmpty(""));
assertTrue(StringTools.stringIsEmpty(" "));
@@ -533,7 +610,19 @@ public class StringToolsTests extends TestCase {
assertTrue(StringTools.stringIsEmpty(" \t\t " + StringTools.CR));
}
- public void testStringsAreEqualIgnoreCase() {
+ public void testStringIsEmptyCharArray() {
+ assertTrue(StringTools.stringIsEmpty((char[]) null));
+ this.verifyStringIsEmptyCharArray("");
+ this.verifyStringIsEmptyCharArray(" \t\t ");
+ this.verifyStringIsEmptyCharArray(" ");
+ this.verifyStringIsEmptyCharArray(" \t\t " + StringTools.CR);
+ }
+
+ private void verifyStringIsEmptyCharArray(String string) {
+ assertTrue(StringTools.stringIsEmpty(string.toCharArray()));
+ }
+
+ public void testStringsAreEqualIgnoreCaseStringString() {
assertTrue(StringTools.stringsAreEqualIgnoreCase((String) null, (String) null));
assertFalse(StringTools.stringsAreEqualIgnoreCase(null, "asdf"));
assertFalse(StringTools.stringsAreEqualIgnoreCase("asdf", null));
@@ -541,6 +630,52 @@ public class StringToolsTests extends TestCase {
assertTrue(StringTools.stringsAreEqualIgnoreCase("asdf", "ASDF"));
}
+ public void testStringsAreEqualIgnoreCaseCharArrayCharArray() {
+ assertTrue(StringTools.stringsAreEqualIgnoreCase((char[]) null, (char[]) null));
+ assertFalse(StringTools.stringsAreEqualIgnoreCase((char[]) null, "asdf".toCharArray()));
+ assertFalse(StringTools.stringsAreEqualIgnoreCase("asdf".toCharArray(), (char[]) null));
+ assertTrue(StringTools.stringsAreEqualIgnoreCase("asdf".toCharArray(), "asdf".toCharArray()));
+ assertTrue(StringTools.stringsAreEqualIgnoreCase("asdf".toCharArray(), "ASDF".toCharArray()));
+ }
+
+ public void testStringStartsWithIgnoreCaseStringString() {
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", "as"));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", "aS"));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", ""));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", "A"));
+
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "bsdf"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "g"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "asdg"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "asdfg"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "asdfgggggg"));
+ }
+
+ public void testStringStartsWithIgnoreCaseCharArrayCharArray() {
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "as".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "aS".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "A".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "ASDF".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdf".toCharArray()));
+
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "bsdf".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "g".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdg".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdfg".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdfgggggg".toCharArray()));
+ }
+
+ public void testCharactersAreEqualIgnoreCase() {
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('a', 'a'));
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('a', 'A'));
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('A', 'a'));
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('A', 'A'));
+
+ assertFalse(StringTools.charactersAreEqualIgnoreCase('a', 'b'));
+ assertFalse(StringTools.charactersAreEqualIgnoreCase('A', 'b'));
+ }
+
// ********** conversions **********
public void testConvertCamelCaseToAllCaps() {

Back to the top