diff options
Diffstat (limited to 'common')
5 files changed, 72 insertions, 45 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java index 00c554427d..bb6003bf85 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 Oracle. All rights reserved. + * Copyright (c) 2008, 2016 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. @@ -365,7 +365,7 @@ public abstract class AbstractJptGenerator implements JptGenerator try { File jarInstallDir = this.getBundleParentDir(JptCommonCorePlugin.instance().getBundle()); - List<File> result = new ArrayList<File>(); + List<File> result = new ArrayList<>(); this.findFileStartingWith(genJarName, jarInstallDir, result); if (result.isEmpty()) { throw new RuntimeException("Could not find: " + genJarName + "#.#.#v###.jar in: " + jarInstallDir); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java index e40ae9a001..2227f81996 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java @@ -20,6 +20,14 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; * pluggable property aspect adapter} to convert one of a {@link Model model's} * <em>bound</em> properties to a * {@link org.eclipse.jpt.common.utility.model.value.PropertyValueModel property value model}. + * <p> + * <strong>NB:</strong> + * The {@link #propertyTransformer} <em>must</em> transform + * a non-<code>null</code> subject into the same value as the value + * passed by the correponding change event; i.e. it should invoke a + * "standard" getter. The only thing, in addition to calling the property's + * getter, the transformer can do is return something other than <code>null</code> + * if the subject is <code>null</code>. * * @param <V> the type of the adapter's value * @param <S> the type of the subject whose <em>bound</em> property is transformed into @@ -67,6 +75,13 @@ public final class ModelPropertyAspectAdapter<V, S extends Model> return this.propertyTransformer.transform(null); } + /** + * <strong>NB:</strong> + * The event's new value is passed through <em>untouched</em>; + * i.e. the {@link #propertyTransformer} <em>must</em> transform + * a non-<code>null</code> subject into the same value as the value + * passed to the correponding change event. + */ public void propertyChanged(PropertyChangeEvent event) { @SuppressWarnings("unchecked") V newValue = (V) event.getNewValue(); diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java index 2709c039d7..11af56500a 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java @@ -15,7 +15,7 @@ import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; /** - * This adapter adapts an subject property value model whose value is another model + * This adapter adapts a subject property value model whose value is another model * and treats the <em>inner</em> model's value as this adapter's models's value. * As a result, this adapter listens for changes to either model * (<em>inner</em> or <em>subject</em>). diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java index 1f126b396e..dd70260c50 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java @@ -13,7 +13,6 @@ import java.util.HashMap; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter; import org.eclipse.jpt.common.utility.model.listener.ChangeListener; @@ -49,16 +48,7 @@ public class CompoundPropertyValueModelTests } protected PropertyValueModel<SimplePropertyValueModel<String>> buildValueModelModel() { - return PropertyValueModelTools.transform(this.keyModel, new KeyTransformer()); - } - - public class KeyTransformer - extends TransformerAdapter<String, SimplePropertyValueModel<String>> - { - @Override - public SimplePropertyValueModel<String> transform(String key) { - return CompoundPropertyValueModelTests.this.getValueModel(key); - } + return PropertyValueModelTools.transform(this.keyModel, key -> this.getValueModel(key)); } protected SimplePropertyValueModel<String> getValueModel(String key) { diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java index cb4d7c4f9d..f0df86a1f1 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.common.utility.tests.internal.model.value; import org.eclipse.jpt.common.utility.closure.BiClosure; +import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.closure.BiClosureAdapter; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; @@ -30,7 +31,7 @@ public class PropertyAspectAdapterTests extends TestCase { private TestSubject subject1; - private ModifiablePropertyValueModel<TestSubject> subjectHolder1; + private ModifiablePropertyValueModel<TestSubject> subjectModel1; private ModifiablePropertyValueModel<String> aa1; private PropertyChangeEvent event1; private PropertyChangeListener listener1; @@ -48,8 +49,8 @@ public class PropertyAspectAdapterTests protected void setUp() throws Exception { super.setUp(); this.subject1 = new TestSubject("foo", "test subject 1"); - this.subjectHolder1 = new SimplePropertyValueModel<>(this.subject1); - this.aa1 = this.buildAspectAdapter(this.subjectHolder1); + this.subjectModel1 = new SimplePropertyValueModel<>(this.subject1); + this.aa1 = this.buildAspectAdapter(this.subjectModel1); this.listener1 = this.buildValueChangeListener1(); this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1); this.event1 = null; @@ -57,9 +58,9 @@ public class PropertyAspectAdapterTests this.subject2 = new TestSubject("bar", "test subject 2"); } - private ModifiablePropertyValueModel<String> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { + private ModifiablePropertyValueModel<String> buildAspectAdapter(PropertyValueModel<TestSubject> subjectModel) { return PropertyValueModelTools.modifiableSubjectModelAspectAdapter( - subjectHolder, + subjectModel, TestSubject.NAME_PROPERTY, TestSubject.NAME_TRANSFORMER, TestSubject.SET_NAME_CLOSURE @@ -85,11 +86,11 @@ public class PropertyAspectAdapterTests super.tearDown(); } - public void testSubjectHolder() { + public void testSubjectModel() { assertEquals("foo", this.aa1.getValue()); assertNull(this.event1); - this.subjectHolder1.setValue(this.subject2); + this.subjectModel1.setValue(this.subject2); assertNotNull(this.event1); assertEquals(this.aa1, this.event1.getSource()); assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); @@ -98,7 +99,7 @@ public class PropertyAspectAdapterTests assertEquals("bar", this.aa1.getValue()); this.event1 = null; - this.subjectHolder1.setValue(null); + this.subjectModel1.setValue(null); assertNotNull(this.event1); assertEquals(this.aa1, this.event1.getSource()); assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); @@ -107,7 +108,7 @@ public class PropertyAspectAdapterTests assertNull(this.aa1.getValue()); this.event1 = null; - this.subjectHolder1.setValue(this.subject1); + this.subjectModel1.setValue(this.subject1); assertNotNull(this.event1); assertEquals(this.aa1, this.event1.getSource()); assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); @@ -163,7 +164,7 @@ public class PropertyAspectAdapterTests assertEquals("foo", this.aa1.getValue()); this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - this.subjectHolder1.setValue(this.subject2); + this.subjectModel1.setValue(this.subject2); assertEquals(null, this.aa1.getValue()); this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1); @@ -193,15 +194,16 @@ public class PropertyAspectAdapterTests } /** - * test a bug where we would call #buildValue() in - * #engageNonNullSubject(), when we needed to call - * it in #engageSubject(), so the cached value would - * be rebuilt when the this.subject was set to null + * Test a bug: + * we would call <code>buildValue()</code> in + * <code>engageNonNullSubject()</code>, when we needed to call + * it in <code>engageSubject()</code>, so the cached value would + * be rebuilt when the the <code>subject</code> was set to <code>null</code> */ public void testCustomBuildValueWithNullSubject() { TestSubject customSubject = new TestSubject("fred", "laborer"); - ModifiablePropertyValueModel<TestSubject> customSubjectHolder = new SimplePropertyValueModel<>(customSubject); - ModifiablePropertyValueModel<String> customAA = this.buildCustomAspectAdapter(customSubjectHolder); + ModifiablePropertyValueModel<TestSubject> customSubjectModel = new SimplePropertyValueModel<>(customSubject); + ModifiablePropertyValueModel<String> customAA = this.buildCustomAspectAdapter(customSubjectModel); PropertyChangeListener customListener = this.buildCustomValueChangeListener(); customAA.addPropertyChangeListener(PropertyValueModel.VALUE, customListener); assertEquals("fred", customAA.getValue()); @@ -213,7 +215,7 @@ public class PropertyAspectAdapterTests assertEquals("wilma", this.customValueEvent.getNewValue()); this.customValueEvent = null; - customSubjectHolder.setValue(null); + customSubjectModel.setValue(null); // this would fail - the value would be null... assertEquals("<unnamed>", customAA.getValue()); assertEquals("wilma", this.customValueEvent.getOldValue()); @@ -224,8 +226,8 @@ public class PropertyAspectAdapterTests * Test a bug: * If two listeners were added to an aspect adapter, one with an * aspect name and one without, the aspect adapter would add its - * 'subjectChangeListener' to its 'subjectHolder' twice. As a result, - * the following code will trigger an IllegalArgumentException + * <code>subjectChangeListener</code> to its <code>subjectModel</code> twice. As a result, + * the following code will trigger an {@link IllegalArgumentException} * if the bug is present; otherwise, it completes silently. */ public void testDuplicateListener() { @@ -233,11 +235,40 @@ public class PropertyAspectAdapterTests this.aa1.addChangeListener(listener2); } - private ModifiablePropertyValueModel<String> buildCustomAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { + public void testBogusTransformer() { + PropertyValueModel<Boolean> nameIsFooModel = this.buildNameIsFooModel(this.subjectModel1); + assertNull(nameIsFooModel.getValue()); + + nameIsFooModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1); + assertTrue(nameIsFooModel.getValue().booleanValue()); + this.subjectModel1.getValue().setName("bar"); + boolean exCaught = false; + try { + assertFalse(nameIsFooModel.getValue().booleanValue()); + } catch (ClassCastException ex) { + exCaught = true; + } + assertTrue(exCaught); + } + + // ********** + // ********** NB: this type of aspect adapter is NOT ALLOWED! :-) + // ********** an aspect adapter's value MUST match the aspect's value; + // ********** it CANNOT transform it + // ********** + private PropertyValueModel<Boolean> buildNameIsFooModel(PropertyValueModel<TestSubject> subjectModel) { + return PropertyValueModelTools.subjectModelAspectAdapter( + subjectModel, + TestSubject.NAME_PROPERTY, + s -> Boolean.valueOf((s != null) && ObjectTools.equals(s.getName(), "foo")) + ); + } + + private ModifiablePropertyValueModel<String> buildCustomAspectAdapter(PropertyValueModel<TestSubject> subjectModel) { return PropertyValueModelTools.modifiableSubjectModelAspectAdapter_( - subjectHolder, + subjectModel, TestSubject.NAME_PROPERTY, - TestSubject.CUSTOM_NAME_TRANSFORMER, + s -> (s == null) ? "<unnamed>" : s.getName(), TestSubject.SET_NAME_CLOSURE ); } @@ -271,15 +302,6 @@ public class PropertyAspectAdapterTests return model.getName(); } } - public static final Transformer<TestSubject, String> CUSTOM_NAME_TRANSFORMER = new CustomNameTransformer(); - public static final class CustomNameTransformer - extends TransformerAdapter<TestSubject, String> - { - @Override - public String transform(TestSubject model) { - return (model == null) ? "<unnamed>" : model.getName(); - } - } public static final BiClosure<TestSubject, String> SET_NAME_CLOSURE = new SetNameClosure(); public static final class SetNameClosure extends BiClosureAdapter<TestSubject, String> |