Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2010-01-05 05:37:21 +0000
committerbvosburgh2010-01-05 05:37:21 +0000
commit4394bdb502dc33f81b744137cbf8cc618476b917 (patch)
treebdc5a172064ef7cd67227e54fb97e4a6474d01fb
parent28096602a832fbf503892b83054abcdb951e65d6 (diff)
downloadwebtools.dali-4394bdb502dc33f81b744137cbf8cc618476b917.tar.gz
webtools.dali-4394bdb502dc33f81b744137cbf8cc618476b917.tar.xz
webtools.dali-4394bdb502dc33f81b744137cbf8cc618476b917.zip
utility work
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceType.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeMetamodelSynchronizer.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java38
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkConvert.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/EntityGenerator.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenScope.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenTable.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ArrayTools.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassName.java421
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassTools.java1708
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Classpath.java220
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CollectionTools.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CompositeCommand.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/FileTools.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/HashBag.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/IdentityHashBag.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/JDBCType.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/NotNullFilter.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ReflectionTools.java1544
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/StringTools.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Tools.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/enumerations/EmptyEnumeration.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyIterable.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyListIterable.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/FilteringIterable.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/StackIterable.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubIterableWrapper.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubListIterableWrapper.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperIterableWrapper.java (renamed from jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/GenericIterableWrapper.java)8
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperListIterableWrapper.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/CompositeListIterator.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/FilteringIterator.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/ReadOnlyCompositeListIterator.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubIteratorWrapper.java59
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubListIteratorWrapper.java90
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SuperIteratorWrapper.java (renamed from jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/GenericIteratorWrapper.java)10
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SuperListIteratorWrapper.java (renamed from jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/GenericListIteratorWrapper.java)15
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SynchronizedListIterator.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/TransformationListIterator.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringCollectionValueModel.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullCollectionValueModel.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullListValueModel.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullPropertyValueModel.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullTreeValueModel.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/node/AbstractNode.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ComboBoxTableCellRenderer.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ListChooser.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/MultiMethodReflectiveChangeListener.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/ReflectiveChangeListener.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/SingleMethodReflectiveChangeListener.java12
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java9
-rw-r--r--jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java18
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java32
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TextFieldModelAdapterUITest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TriStateCheckBoxModelAdapterUITest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java28
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ArrayToolsTests.java581
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/AsynchronousCommandExecutorTests.java43
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BagTests.java82
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiFilterTests.java88
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiStringConverterTests.java115
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiTransformerTests.java73
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BitToolsTests.java21
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BooleanToolsTests.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassNameTests.java356
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java676
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java296
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java19
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java21
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandRunnableTests.java55
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CompositeCommandTests.java61
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/FileToolsTests.java48
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/HashBagTests.java52
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IdentityHashBagTests.java54
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JptUtilityTests.java12
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ListenerListTests.java56
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReflectionToolsTests.java440
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReverseComparatorTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleAssociationTests.java15
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java9
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/TestTools.java32
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/XMLStringEncoderTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/FilteringIterableTests.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/JptUtilityIterablesTests.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/SuperIterableWrapperTests.java (renamed from jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/GenericIterableWrapperTests.java)12
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java47
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/SuperIteratorWrapperTests.java (renamed from jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/GenericIteratorWrapperTests.java)8
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java188
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java11
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java9
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java7
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java9
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java12
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java13
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java7
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java9
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java13
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java7
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java9
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java16
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java7
176 files changed, 5627 insertions, 3420 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceType.java
index c31c9443a4..42f7f14268 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.core;
import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jpt.utility.internal.ClassTools;
/**
* Describes the file content type and version for JPA resources.
@@ -85,7 +84,7 @@ public class JpaResourceType
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.toStringClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append("(content = "); //$NON-NLS-1$
sb.append(this.contentType);
sb.append(", "); //$NON-NLS-1$
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
index 6231b45c51..d305d9c4bd 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -76,6 +76,7 @@ import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable;
+import org.eclipse.jpt.utility.internal.iterables.SubIterableWrapper;
import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -477,7 +478,7 @@ public abstract class AbstractJpaProject
}
protected Iterable<JpaFile> getJpaFiles(final IContentType contentType) {
- return new FilteringIterable<JpaFile, JpaFile>(this.getJpaFiles()) {
+ return new FilteringIterable<JpaFile>(this.getJpaFiles()) {
@Override
protected boolean accept(JpaFile jpaFile) {
return jpaFile.getContentType().isKindOf(contentType);
@@ -740,7 +741,7 @@ public abstract class AbstractJpaProject
* @see org.eclipse.jpt.core.internal.utility.jdt.JPTTools#typeIsPersistable(org.eclipse.jpt.core.internal.utility.jdt.JPTTools.TypeAdapter)
*/
protected Iterable<JavaResourcePersistentType> getInternalAnnotatedSourceJavaResourcePersistentTypes() {
- return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>(this.getInternalSourceJavaResourcePersistentTypes()) {
+ return new FilteringIterable<JavaResourcePersistentType>(this.getInternalSourceJavaResourcePersistentTypes()) {
@Override
protected boolean accept(JavaResourcePersistentType jrpType) {
return jrpType.isPersistable() && jrpType.isAnnotated(); // i.e. the type is valid and has a valid type annotation
@@ -767,7 +768,7 @@ public abstract class AbstractJpaProject
* referenced in persistence.xml
*/
protected Iterable<JavaResourcePersistentType> getInternalMappedSourceJavaResourcePersistentTypes() {
- return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>(this.getInternalAnnotatedSourceJavaResourcePersistentTypes()) {
+ return new FilteringIterable<JavaResourcePersistentType>(this.getInternalAnnotatedSourceJavaResourcePersistentTypes()) {
@Override
protected boolean accept(JavaResourcePersistentType jrpType) {
return jrpType.isMapped(); // i.e. the type is already persistable and annotated
@@ -779,6 +780,14 @@ public abstract class AbstractJpaProject
* return only those Java resource persistent types that are
* part of the JPA project, ignoring those in JARs referenced in persistence.xml
*/
+ protected Iterable<JavaResourcePersistentType2_0> getInternalSourceJavaResourcePersistentTypes2_0() {
+ return new SubIterableWrapper<JavaResourcePersistentType, JavaResourcePersistentType2_0>(this.getInternalSourceJavaResourcePersistentTypes());
+ }
+
+ /**
+ * return only those Java resource persistent types that are
+ * part of the JPA project, ignoring those in JARs referenced in persistence.xml
+ */
protected Iterable<JavaResourcePersistentType> getInternalSourceJavaResourcePersistentTypes() {
return new CompositeIterable<JavaResourcePersistentType>(this.getInternalSourceJavaResourcePersistentTypeSets());
}
@@ -835,7 +844,7 @@ public abstract class AbstractJpaProject
* @see org.eclipse.jpt.core.internal.utility.jdt.JPTTools#typeIsPersistable(org.eclipse.jpt.core.internal.utility.jdt.JPTTools.TypeAdapter)
*/
protected Iterable<JavaResourcePersistentType> getPersistableJavaResourcePersistentTypes() {
- return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>(this.getJavaResourcePersistentTypes()) {
+ return new FilteringIterable<JavaResourcePersistentType>(this.getJavaResourcePersistentTypes()) {
@Override
protected boolean accept(JavaResourcePersistentType jrpType) {
return jrpType.isPersistable();
@@ -920,10 +929,10 @@ public abstract class AbstractJpaProject
return EmptyIterable.instance();
}
final IPackageFragmentRoot genSourceFolder = this.getMetamodelPackageFragmentRoot();
- return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType2_0>(this.getInternalSourceJavaResourcePersistentTypes()) {
+ return new FilteringIterable<JavaResourcePersistentType2_0>(this.getInternalSourceJavaResourcePersistentTypes2_0()) {
@Override
- protected boolean accept(JavaResourcePersistentType jrpt) {
- return ((JavaResourcePersistentType2_0) jrpt).isGeneratedMetamodel(genSourceFolder);
+ protected boolean accept(JavaResourcePersistentType2_0 jrpt) {
+ return jrpt.isGeneratedMetamodel(genSourceFolder);
}
};
}
@@ -1044,7 +1053,7 @@ public abstract class AbstractJpaProject
}
protected Iterable<IPackageFragmentRoot> getJavaSourceFolders() throws JavaModelException {
- return new FilteringIterable<IPackageFragmentRoot, IPackageFragmentRoot>(
+ return new FilteringIterable<IPackageFragmentRoot>(
this.getPackageFragmentRoots(),
SOURCE_PACKAGE_FRAGMENT_ROOT_FILTER
);
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java
index 381d791dcf..f6d14f5f6b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -167,8 +167,7 @@ public class JpaPlatformRegistry {
return configElementSupportsJpaFacetVersion(configElement, jpaFacetVersion);
}
- private boolean configElementSupportsJpaFacetVersion(
- IConfigurationElement configElement, String jpaFacetVersion) {
+ boolean configElementSupportsJpaFacetVersion(IConfigurationElement configElement, String jpaFacetVersion) {
// config element supports version if it explicitly sets it to that version
// or if it specifies no version at all
@@ -191,7 +190,7 @@ public class JpaPlatformRegistry {
}
private Iterable<IConfigurationElement> getConfigurationElementsForJpaFacetVersion(final String jpaFacetVersion) {
- return new FilteringIterable<IConfigurationElement, IConfigurationElement>(this.jpaPlatformConfigurationElements.values()) {
+ return new FilteringIterable<IConfigurationElement>(this.jpaPlatformConfigurationElements.values()) {
@Override
protected boolean accept(IConfigurationElement configElement) {
return configElementSupportsJpaFacetVersion(configElement, jpaFacetVersion);
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java
index 98d07e6c80..08c0ef2714 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -280,7 +280,7 @@ public abstract class AbstractJavaBaseColumn<T extends BaseColumnAnnotation> ext
}
private Iterator<String> candidateTableNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.candidateTableNames(), filter);
+ return new FilteringIterator<String>(this.candidateTableNames(), filter);
}
private Iterator<String> javaCandidateTableNames(Filter<String> filter) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java
index 58f7c264af..ebaea85e51 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -328,7 +328,7 @@ public abstract class AbstractJavaEntity
}
protected Iterable<org.eclipse.jpt.db.Table> getAssociatedDbTablesIncludingInherited() {
- return new FilteringIterable<org.eclipse.jpt.db.Table, org.eclipse.jpt.db.Table>(this.getAssociatedDbTablesIncludingInherited_()) {
+ return new FilteringIterable<org.eclipse.jpt.db.Table>(this.getAssociatedDbTablesIncludingInherited_()) {
@Override
protected boolean accept(org.eclipse.jpt.db.Table t) {
return t != null;
@@ -962,7 +962,7 @@ public abstract class AbstractJavaEntity
}
protected Iterator<PersistentAttribute> allIdAttributes() {
- return new FilteringIterator<PersistentAttribute, PersistentAttribute>(this.getPersistentType().allAttributes()) {
+ return new FilteringIterator<PersistentAttribute>(this.getPersistentType().allAttributes()) {
@Override
protected boolean accept(PersistentAttribute pa) {
return pa.isIdAttribute();
@@ -993,7 +993,7 @@ public abstract class AbstractJavaEntity
return new CompositeIterable<Table>(new TransformationIterable<TypeMapping, Iterable<Table>>(this.getInheritanceHierarchy()) {
@Override
protected Iterable<Table> transform(TypeMapping mapping) {
- return new FilteringIterable<Table, Table>(CollectionTools.iterable(mapping.associatedTables())) {
+ return new FilteringIterable<Table>(CollectionTools.iterable(mapping.associatedTables())) {
@Override
protected boolean accept(Table o) {
return true;
@@ -1012,7 +1012,7 @@ public abstract class AbstractJavaEntity
}
protected Iterator<String> nonNullTableNames(Iterator<Table> tables) {
- return new FilteringIterator<String, String>(this.tableNames(tables)) {
+ return new FilteringIterator<String>(this.tableNames(tables)) {
@Override
protected boolean accept(String o) {
return o != null;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java
index 21d350ee86..883543ca80 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -308,7 +308,7 @@ public abstract class AbstractJavaIdMapping
}
private Iterator<String> generatorNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.persistenceGeneratorNames(), filter);
+ return new FilteringIterator<String>(this.persistenceGeneratorNames(), filter);
}
protected Iterator<String> persistenceGeneratorNames(Filter<String> filter) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java
index 6072fb7ed3..b63fef8748 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -304,7 +304,7 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi
}
protected Iterator<String> candidateMapKeyNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.candidateMapKeyNames(), filter);
+ return new FilteringIterator<String>(this.candidateMapKeyNames(), filter);
}
public Iterator<String> candidateMapKeyNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java
index c5a3ce1779..77665aa639 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -183,7 +183,7 @@ public abstract class AbstractJavaNamedColumn<T extends NamedColumnAnnotation> e
}
private Iterable<String> getCandidateNames(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateNames(), filter);
+ return new FilteringIterable<String>(this.getCandidateNames(), filter);
}
private Iterable<String> getCandidateNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java
index ca07b093dc..1e3d2bb489 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -89,7 +89,7 @@ public abstract class AbstractJavaOverride extends AbstractJavaJpaContextNode im
protected abstract Iterator<String> candidateNames();
private Iterator<String> candidateNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.candidateNames(), filter);
+ return new FilteringIterator<String>(this.candidateNames(), filter);
}
private Iterator<String> javaCandidateNames(Filter<String> filter) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java
index dec7feba9a..0f286c5582 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -33,7 +33,8 @@ import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.utility.Filter;
import org.eclipse.jpt.utility.internal.ArrayTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.Tools;
import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
@@ -219,21 +220,21 @@ public abstract class AbstractJavaPersistentAttribute
return false;
}
- int arrayDepth = ClassTools.arrayDepthForTypeDeclaration(typeName);
+ int arrayDepth = ReflectionTools.getArrayDepthForTypeDeclaration(typeName);
if (arrayDepth > 1) {
return false; // multi-dimensional arrays are not supported
}
if (arrayDepth == 1) {
- String elementTypeName = ClassTools.elementTypeNameForTypeDeclaration(typeName, 1);
+ String elementTypeName = ReflectionTools.getElementTypeNameForTypeDeclaration(typeName, 1);
return this.elementTypeIsValidForBasicArray(elementTypeName);
}
// arrayDepth == 0
- if (ClassTools.classNamedIsVariablePrimitive(typeName)) {
+ if (ClassName.isVariablePrimitive(typeName)) {
return true; // any primitive but 'void'
}
- if (ClassTools.classNamedIsVariablePrimitiveWrapperClass(typeName)) {
+ if (ClassName.isVariablePrimitiveWrapper(typeName)) {
return true; // any primitive wrapper but 'java.lang.Void'
}
if (this.typeIsOtherValidBasicType(typeName)) {
@@ -296,7 +297,7 @@ public abstract class AbstractJavaPersistentAttribute
if (typeName == null) {
return null;
}
- if (ClassTools.arrayDepthForTypeDeclaration(typeName) != 0) {
+ if (ReflectionTools.getArrayDepthForTypeDeclaration(typeName) != 0) {
return null; // arrays cannot be entities
}
if (this.typeIsContainer(typeName)) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java
index b9b7003fac..616052080c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -402,7 +402,7 @@ public abstract class AbstractJavaPersistentType
}
protected Iterator<JavaPersistentAttribute> attributesNamed(final String attributeName) {
- return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(this.attributes()) {
+ return new FilteringIterator<JavaPersistentAttribute>(this.attributes()) {
@Override
protected boolean accept(JavaPersistentAttribute o) {
return attributeName.equals(o.getName());
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java
index a7bc08d56f..02d7926656 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -104,7 +104,7 @@ public abstract class AbstractJavaSequenceGenerator extends AbstractJavaGenerato
}
protected Iterable<String> getCandidateSequences(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateSequences(), filter);
+ return new FilteringIterable<String>(this.getCandidateSequences(), filter);
}
protected Iterable<String> getCandidateSequences() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java
index e56fdabafe..db128ba727 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -445,7 +445,7 @@ public abstract class AbstractJavaTable
}
protected Iterable<String> getCandidateNames(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateNames(), filter);
+ return new FilteringIterable<String>(this.getCandidateNames(), filter);
}
protected Iterable<String> getCandidateNames() {
@@ -458,7 +458,7 @@ public abstract class AbstractJavaTable
}
protected Iterable<String> getCandidateSchemata(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateSchemata(), filter);
+ return new FilteringIterable<String>(this.getCandidateSchemata(), filter);
}
protected Iterable<String> getCandidateSchemata() {
@@ -470,7 +470,7 @@ public abstract class AbstractJavaTable
}
protected Iterable<String> getCandidateCatalogs(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateCatalogs(), filter);
+ return new FilteringIterable<String>(this.getCandidateCatalogs(), filter);
}
protected Iterable<String> getCandidateCatalogs() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java
index 19527f7484..a5f39d5876 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009 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) 2009, 2010 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.context.java;
import java.util.Iterator;
@@ -131,7 +130,7 @@ public class GenericJavaMappedByJoiningStrategy
}
public Iterator<String> candidateMappedByAttributeNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.candidateMappedByAttributeNames(), filter);
+ return new FilteringIterator<String>(this.candidateMappedByAttributeNames(), filter);
}
protected Iterator<String> javaCandidateMappedByAttributeNames(Filter<String> filter) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java
index eab789c812..08fa64f012 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -31,6 +31,7 @@ import org.eclipse.jpt.utility.internal.CollectionTools;
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.SubIteratorWrapper;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
@@ -112,20 +113,20 @@ public abstract class AbstractOrmEmbeddedMapping<T extends XmlEmbedded>
}
@Override
- public AttributeMapping resolveAttributeMapping(String name) {
+ public AttributeMapping resolveAttributeMapping(String attributeName) {
if (getName() == null) {
return null;
}
- AttributeMapping resolvedMapping = super.resolveAttributeMapping(name);
+ AttributeMapping resolvedMapping = super.resolveAttributeMapping(attributeName);
if (resolvedMapping != null) {
return resolvedMapping;
}
if (this.isJpa2_0Compatible()) {
- int dotIndex = name.indexOf('.');
+ int dotIndex = attributeName.indexOf('.');
if (dotIndex != -1) {
- if (getName().equals(name.substring(0, dotIndex))) {
+ if (getName().equals(attributeName.substring(0, dotIndex))) {
for (AttributeMapping attributeMapping : CollectionTools.iterable(embeddableAttributeMappings())) {
- resolvedMapping = attributeMapping.resolveAttributeMapping(name.substring(dotIndex + 1));
+ resolvedMapping = attributeMapping.resolveAttributeMapping(attributeName.substring(dotIndex + 1));
if (resolvedMapping != null) {
return resolvedMapping;
}
@@ -184,10 +185,13 @@ public abstract class AbstractOrmEmbeddedMapping<T extends XmlEmbedded>
}
public Iterator<RelationshipMapping> allOverridableAssociations() {
- if (this.getTargetEmbeddable() == null) {
- return EmptyIterator.instance();
- }
- return new FilteringIterator<AttributeMapping, RelationshipMapping>(this.getTargetEmbeddable().attributeMappings()) {
+ return (this.getTargetEmbeddable() == null) ?
+ EmptyIterator.<RelationshipMapping>instance() :
+ new SubIteratorWrapper<AttributeMapping, RelationshipMapping>(this.allOverridableAssociations_());
+ }
+
+ protected Iterator<AttributeMapping> allOverridableAssociations_() {
+ return new FilteringIterator<AttributeMapping>(this.getTargetEmbeddable().attributeMappings()) {
@Override
protected boolean accept(AttributeMapping o) {
return o.isOverridableAssociationMapping();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java
index 1f6bf4ea2b..ac9774ccc7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -67,7 +67,7 @@ import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn;
import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.db.Schema;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
@@ -278,7 +278,7 @@ public abstract class AbstractOrmEntity
}
private Iterable<org.eclipse.jpt.db.Table> getAssociatedDbTablesIncludingInherited() {
- return new FilteringIterable<org.eclipse.jpt.db.Table, org.eclipse.jpt.db.Table>(this.getAssociatedDbTablesIncludingInherited_()) {
+ return new FilteringIterable<org.eclipse.jpt.db.Table>(this.getAssociatedDbTablesIncludingInherited_()) {
@Override
protected boolean accept(org.eclipse.jpt.db.Table t) {
return t != null;
@@ -574,7 +574,7 @@ public abstract class AbstractOrmEntity
}
protected Iterator<String> nonNullTableNames(Iterator<Table> tables) {
- return new FilteringIterator<String, String>(this.tableNames(tables)) {
+ return new FilteringIterator<String>(this.tableNames(tables)) {
@Override
protected boolean accept(String o) {
return o != null;
@@ -594,7 +594,7 @@ public abstract class AbstractOrmEntity
return new CompositeIterable<Table>(new TransformationIterable<TypeMapping, Iterable<Table>>(CollectionTools.iterable(this.inheritanceHierarchy())) {
@Override
protected Iterable<Table> transform(TypeMapping mapping) {
- return new FilteringIterable<Table, Table>(CollectionTools.iterable(mapping.associatedTables())) {
+ return new FilteringIterable<Table>(CollectionTools.iterable(mapping.associatedTables())) {
@Override
protected boolean accept(Table o) {
return true;
@@ -1300,7 +1300,7 @@ public abstract class AbstractOrmEntity
}
String className = getClass_();
if (className != null) {
- return ClassTools.shortNameForClassNamed(className);
+ return ClassName.getSimpleName(className);
}
return null;
}
@@ -1564,7 +1564,7 @@ public abstract class AbstractOrmEntity
}
protected Iterator<PersistentAttribute> allIdAttributes() {
- return new FilteringIterator<PersistentAttribute, PersistentAttribute>(this.getPersistentType().allAttributes()) {
+ return new FilteringIterator<PersistentAttribute>(this.getPersistentType().allAttributes()) {
@Override
protected boolean accept(PersistentAttribute pa) {
return pa.isIdAttribute();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java
index a14c5f39f9..0cbfe14257 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -431,7 +431,7 @@ public abstract class AbstractPersistenceUnit
}
public Iterator<MappingFileRef> mappingFileRefsContaining(final String typeName) {
- return new FilteringIterator<MappingFileRef, MappingFileRef> (this.mappingFileRefs()) {
+ return new FilteringIterator<MappingFileRef> (this.mappingFileRefs()) {
@Override
protected boolean accept(MappingFileRef mappingFileRef) {
return mappingFileRef.getPersistentType(typeName) != null;
@@ -695,7 +695,7 @@ public abstract class AbstractPersistenceUnit
}
protected Iterable<PersistentType> getNonNullClassRefPersistentTypes() {
- return new FilteringIterable<PersistentType, PersistentType>(this.getClassRefPersistentTypes(), NotNullFilter.<PersistentType>instance());
+ return new FilteringIterable<PersistentType>(this.getClassRefPersistentTypes(), NotNullFilter.<PersistentType>instance());
}
protected Iterable<PersistentType> getClassRefPersistentTypes() {
@@ -935,7 +935,7 @@ public abstract class AbstractPersistenceUnit
if (propertyNamePrefix == null) {
throw new NullPointerException();
}
- return new FilteringIterator<Property, Property>(this.properties()) {
+ return new FilteringIterator<Property>(this.properties()) {
@Override
protected boolean accept(Property property) {
String pName = property.getName();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java
index 368b210e97..fe66b88e98 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2009 Oracle. All rights reserved.
+* Copyright (c) 2009, 2010 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.
@@ -16,7 +16,7 @@ import java.util.Map;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
/**
@@ -386,7 +386,7 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel
return null;
}
if (value.getClass().isEnum()) {
- return (String) ClassTools.staticFieldValue(value.getClass(), value.toString().toUpperCase(Locale.ENGLISH));
+ return (String) ReflectionTools.getStaticFieldValue(value.getClass(), value.toString().toUpperCase(Locale.ENGLISH));
}
return value.toString();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java
index de24ea665f..3039c44158 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -147,7 +147,7 @@ public class GenericJavaGeneratedValue
}
protected Iterator<String> candidateGeneratorNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.candidateGeneratorNames(), filter);
+ return new FilteringIterator<String>(this.candidateGeneratorNames(), filter);
}
protected Iterator<String> candidateGeneratorNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java
index a28584175b..fbf0307146 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -134,7 +134,7 @@ public class GenericJavaJoinColumn extends AbstractJavaBaseColumn<JoinColumnAnno
}
private Iterable<String> getCandidateReferencedColumnNames(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateReferencedColumnNames(), filter);
+ return new FilteringIterable<String>(this.getCandidateReferencedColumnNames(), filter);
}
private Iterable<String> getCandidateReferencedColumnNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java
index 5b384d77e2..eaaff838d2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -124,7 +124,7 @@ public class GenericJavaPrimaryKeyJoinColumn extends AbstractJavaNamedColumn<Pri
}
private Iterable<String> getCandidateReferencedColumnNames(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateReferencedColumnNames(), filter);
+ return new FilteringIterable<String>(this.getCandidateReferencedColumnNames(), filter);
}
private Iterable<String> getCandidateReferencedColumnNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java
index fd03d3389a..14d6d12607 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -447,7 +447,7 @@ public class GenericJavaTableGenerator
}
protected Iterable<String> getCandidateTables(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateTables(), filter);
+ return new FilteringIterable<String>(this.getCandidateTables(), filter);
}
protected Iterable<String> getCandidateTables() {
@@ -466,7 +466,7 @@ public class GenericJavaTableGenerator
}
protected Iterable<String> getCandidateSchemata(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateSchemata(), filter);
+ return new FilteringIterable<String>(this.getCandidateSchemata(), filter);
}
protected Iterable<String> getCandidateSchemata() {
@@ -485,7 +485,7 @@ public class GenericJavaTableGenerator
}
protected Iterable<String> getCandidateCatalogs(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateCatalogs(), filter);
+ return new FilteringIterable<String>(this.getCandidateCatalogs(), filter);
}
protected Iterable<String> getCandidateCatalogs() {
@@ -504,7 +504,7 @@ public class GenericJavaTableGenerator
}
protected Iterable<String> getCandidateColumnNames(Filter<String> filter) {
- return new FilteringIterable<String, String>(this.getCandidateColumnNames(), filter);
+ return new FilteringIterable<String>(this.getCandidateColumnNames(), filter);
}
protected Iterable<String> getCandidateColumnNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java
index 64246c7f3d..a24d8e8e73 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -158,7 +158,7 @@ public class GenericJavaUniqueConstraint extends AbstractJavaJpaContextNode
}
private Iterator<String> candidateColumnNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.candidateColumnNames(), filter);
+ return new FilteringIterator<String>(this.candidateColumnNames(), filter);
}
private Iterator<String> candidateColumnNames() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java
index 768a1d8082..f962b0e84a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -49,7 +49,7 @@ import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping;
import org.eclipse.jpt.core.resource.orm.XmlTypeMapping;
import org.eclipse.jpt.core.resource.xml.EmfTools;
import org.eclipse.jpt.core.utility.TextRange;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.Tools;
import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
@@ -142,7 +142,7 @@ public class GenericOrmPersistentType
public String getShortName(){
String className = this.getName();
- return (className == null) ? null : ClassTools.shortNameForClassNamed(className);
+ return (className == null) ? null : ClassName.getSimpleName(className);
}
@@ -262,7 +262,7 @@ public class GenericOrmPersistentType
}
protected Iterator<OrmPersistentAttribute> attributesNamed(final String attributeName) {
- return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(this.attributes()) {
+ return new FilteringIterator<OrmPersistentAttribute>(this.attributes()) {
@Override
protected boolean accept(OrmPersistentAttribute o) {
return Tools.valuesAreEqual(attributeName, o.getName());
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeMetamodelSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeMetamodelSynchronizer.java
index 1002ef5192..6e6108c88a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeMetamodelSynchronizer.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeMetamodelSynchronizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -36,7 +36,7 @@ import org.eclipse.jpt.core.jpa2.context.PersistentType2_0;
import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0;
import org.eclipse.jpt.core.jpa2.resource.java.JavaResourcePersistentType2_0;
import org.eclipse.jpt.utility.Filter;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.IndentingPrintWriter;
import org.eclipse.jpt.utility.internal.StringTools;
@@ -157,11 +157,11 @@ public class GenericPersistentTypeMetamodelSynchronizer
// TODO
protected String getPackageName() {
// the default is to store the metamodel in the same package as the model
- return ClassTools.packageNameForClassNamed(this.getMetamodelClassName());
+ return ClassName.getPackageName(this.getMetamodelClassName());
}
protected String getFileName() {
- return ClassTools.shortNameForClassNamed(this.getMetamodelClassName()) + ".java";
+ return ClassName.getSimpleName(this.getMetamodelClassName()) + ".java";
}
protected String getMetamodelClassName() {
@@ -537,7 +537,7 @@ public class GenericPersistentTypeMetamodelSynchronizer
* strip off any non-required imports (e.g. "java.lang.Object')
*/
protected Iterable<Map.Entry<String, ImportPackage>> getRequiredImportEntries() {
- return new FilteringIterable<Map.Entry<String, ImportPackage>, Map.Entry<String, ImportPackage>>(this.imports.entrySet(), this.buildRequiredImportEntriesFilter());
+ return new FilteringIterable<Map.Entry<String, ImportPackage>>(this.imports.entrySet(), this.buildRequiredImportEntriesFilter());
}
protected Filter<Map.Entry<String, ImportPackage>> buildRequiredImportEntriesFilter() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java
index ef0a913e98..aa0866f054 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java
@@ -1,14 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009 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) 2009, 2010 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.jpa2.context.java;
import java.util.List;
@@ -74,7 +72,7 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0
protected String calculateDefaultValue() {
Iterable<AttributeMapping> validAttributeMappings =
- new FilteringIterable<AttributeMapping, AttributeMapping>(
+ new FilteringIterable<AttributeMapping>(
CollectionTools.collection(getMapping().getPersistentAttribute().getTypeMapping().allAttributeMappings())) {
@Override
protected boolean accept(AttributeMapping o) {
@@ -85,9 +83,7 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0
if (CollectionTools.size(validAttributeMappings) == 1) {
return validAttributeMappings.iterator().next().getName();
}
- else {
- return null;
- }
+ return null;
}
protected void addAnnotation() {
@@ -158,9 +154,7 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0
if (StringTools.stringsAreEqual(o.getKey(), MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)) {
return getEmbeddedIdMappingChoiceIterable((EmbeddedIdMapping) o);
}
- else {
- return new SingleElementIterable(o);
- }
+ return new SingleElementIterable<AttributeMapping>(o);
}
};
}
@@ -168,13 +162,11 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0
protected Iterable<AttributeMapping> getEmbeddedIdMappingChoiceIterable(EmbeddedIdMapping mapping) {
Embeddable embeddable = mapping.getTargetEmbeddable();
if (embeddable == null) {
- return new SingleElementIterable(mapping);
+ return new SingleElementIterable<AttributeMapping>(mapping);
}
- else {
- return new CompositeIterable<AttributeMapping>(
- mapping,
- CollectionTools.collection(embeddable.allAttributeMappings()));
- }
+ return new CompositeIterable<AttributeMapping>(
+ mapping,
+ CollectionTools.collection(embeddable.allAttributeMappings()));
}
public boolean isSpecified() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java
index b390a08fbc..a24916a3e7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -17,7 +17,7 @@ import org.eclipse.jpt.core.jpa2.context.MetamodelField;
import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0;
import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
/**
* JPA 2.0 Java persistent attribute
@@ -85,8 +85,8 @@ public class GenericJavaPersistentAttribute2_0
if (typeName == null) {
return MetamodelField.DEFAULT_TYPE_NAME;
}
- if (ClassTools.classNamedIsPrimitive(typeName)) {
- return ClassTools.wrapperClassName(typeName); // ???
+ if (ClassName.isPrimitive(typeName)) {
+ return ClassName.getWrapperClassName(typeName); // ???
}
return typeName;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
index db52d48cf4..3600851036 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009 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) 2009, 2010 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.operations;
import java.util.Iterator;
@@ -348,7 +347,7 @@ public abstract class AbstractJpaFileCreationDataModelProvider
}
protected Iterator<IProject> jpaIProjects() {
- return new FilteringIterator<IProject, IProject>(this.allIProjects(), this.buildJpaIProjectsFilter());
+ return new FilteringIterator<IProject>(this.allIProjects(), this.buildJpaIProjectsFilter());
}
protected Iterator<IProject> allIProjects() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java
index 392396901d..1b3f027257 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -17,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
+
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
@@ -32,7 +33,7 @@ import org.eclipse.jpt.core.resource.java.Annotation;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.utility.MethodSignature;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
import org.eclipse.jpt.utility.internal.NameTools;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
@@ -161,7 +162,7 @@ final class BinaryPersistentAttribute
}
public boolean typeIsVariablePrimitive() {
- return (this.typeName != null) && ClassTools.classNamedIsVariablePrimitive(this.typeName);
+ return (this.typeName != null) && ClassName.isVariablePrimitive(this.typeName);
}
// ***** modifiers
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java
index 41892b9c4f..e5f94a5084 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -180,7 +180,7 @@ abstract class BinaryPersistentMember
* convenience method
*/
<T extends JavaResourcePersistentMember> Iterator<T> persistableMembers(Iterator<T> members) {
- return new FilteringIterator<T, T>(members) {
+ return new FilteringIterator<T>(members) {
@Override
protected boolean accept(T m) {
return m.isPersistable();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java
index 4a8778a721..cc21a6e52e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -256,7 +256,7 @@ final class BinaryPersistentType
}
public Iterator<JavaResourcePersistentAttribute> persistableFieldsWithSpecifiedFieldAccess() {
- return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableFields()) {
+ return new FilteringIterator<JavaResourcePersistentAttribute>(this.persistableFields()) {
@Override
protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) {
return resourceAttribute.getSpecifiedAccess() == AccessType.FIELD;
@@ -320,7 +320,7 @@ final class BinaryPersistentType
}
public Iterator<JavaResourcePersistentAttribute> persistablePropertiesWithSpecifiedPropertyAccess() {
- return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableProperties()) {
+ return new FilteringIterator<JavaResourcePersistentAttribute>(this.persistableProperties()) {
@Override
protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) {
return resourceAttribute.getSpecifiedAccess() == AccessType.PROPERTY;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java
index fead1ebddb..35b2ce4a73 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -17,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
+
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -32,7 +33,7 @@ import org.eclipse.jpt.core.utility.jdt.Attribute;
import org.eclipse.jpt.core.utility.jdt.MethodAttribute;
import org.eclipse.jpt.core.utility.jdt.Type;
import org.eclipse.jpt.utility.MethodSignature;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
@@ -207,7 +208,7 @@ final class SourcePersistentAttribute
}
public boolean typeIsVariablePrimitive() {
- return (this.typeName != null) && ClassTools.classNamedIsVariablePrimitive(this.typeName);
+ return (this.typeName != null) && ClassName.isVariablePrimitive(this.typeName);
}
private ITypeBinding getTypeBinding(CompilationUnit astRoot) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java
index 6fc6b5b38c..443539d0f2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -444,7 +444,7 @@ abstract class SourcePersistentMember<E extends Member>
* convenience method
*/
<T extends JavaResourcePersistentMember> Iterator<T> persistableMembers(Iterator<T> members) {
- return new FilteringIterator<T, T>(members) {
+ return new FilteringIterator<T>(members) {
@Override
protected boolean accept(T m) {
return m.isPersistable();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java
index ad8f496833..92c06f41e7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -466,7 +466,7 @@ final class SourcePersistentType
}
public Iterator<JavaResourcePersistentAttribute> persistableFieldsWithSpecifiedFieldAccess() {
- return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableFields()) {
+ return new FilteringIterator<JavaResourcePersistentAttribute>(this.persistableFields()) {
@Override
protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) {
return resourceAttribute.getSpecifiedAccess() == AccessType.FIELD;
@@ -550,7 +550,7 @@ final class SourcePersistentType
}
public Iterator<JavaResourcePersistentAttribute> persistablePropertiesWithSpecifiedPropertyAccess() {
- return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableProperties()) {
+ return new FilteringIterator<JavaResourcePersistentAttribute>(this.persistableProperties()) {
@Override
protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) {
return resourceAttribute.getSpecifiedAccess() == AccessType.PROPERTY;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java
index 2f6f82dab1..96f2c739e7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -30,6 +30,7 @@ import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
+import org.eclipse.jpt.utility.internal.iterators.SubIteratorWrapper;
/**
* Wrap any of the AST nodes that have modifiers (specifically, annotations);
@@ -125,7 +126,11 @@ public class JDTModifiedDeclaration
* Return the declaration's annotations.
*/
protected Iterator<Annotation> annotations() {
- return new FilteringIterator<IExtendedModifier, Annotation>(this.getModifiers().iterator()) {
+ return new SubIteratorWrapper<IExtendedModifier, Annotation>(this.annotations_());
+ }
+
+ protected Iterator<IExtendedModifier> annotations_() {
+ return new FilteringIterator<IExtendedModifier>(this.getModifiers().iterator()) {
@Override
protected boolean accept(IExtendedModifier next) {
return next.isAnnotation();
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java
index 467715ecd7..af837e3e63 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -18,7 +18,7 @@ import org.eclipse.datatools.modelbase.sql.datatypes.PredefinedDataType;
import org.eclipse.datatools.modelbase.sql.datatypes.PrimitiveType;
import org.eclipse.jpt.db.Column;
import org.eclipse.jpt.utility.JavaType;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.SimpleJavaType;
/**
@@ -134,7 +134,7 @@ final class DTPColumnWrapper
private JavaType getJavaType(PredefinedDataType dataType) {
// this is just a bit hacky: moving from a type declaration to a class name to a type declaration...
String dtpJavaClassName = this.getDefinition(dataType).getJavaClassName();
- return new SimpleJavaType(ClassTools.classNameForTypeDeclaration(dtpJavaClassName));
+ return new SimpleJavaType(ReflectionTools.getClassNameForTypeDeclaration(dtpJavaClassName));
}
private PredefinedDataTypeDefinition getDefinition(PredefinedDataType dataType) {
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java
index 5b69e87c89..633a0f45a1 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -164,7 +164,7 @@ final class DTPForeignKeyWrapper
}
public Iterable<Column> getNonPrimaryKeyBaseColumns() {
- return new FilteringIterable<Column, Column>(this.getBaseColumns()) {
+ return new FilteringIterable<Column>(this.getBaseColumns()) {
@Override
protected boolean accept(Column column) {
return ! column.isPartOfPrimaryKey();
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java
index c2cd5b20e3..73e19744bc 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/LowerCaseFoldingStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.db.internal.vendor;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.StringTools;
/**
@@ -51,7 +50,7 @@ class LowerCaseFoldingStrategy
@Override
public String toString() {
- return ClassTools.toStringClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java
index efdce2d3db..e943d18ec8 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/NonFoldingStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.db.internal.vendor;
-import org.eclipse.jpt.utility.internal.ClassTools;
/**
* Do not fold "normal" identifiers.
@@ -60,7 +59,7 @@ class NonFoldingStrategy
@Override
public String toString() {
- return ClassTools.toStringClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java
index 8c284cd075..f3e88967d6 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/vendor/UpperCaseFoldingStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.db.internal.vendor;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.StringTools;
/**
@@ -51,7 +50,7 @@ class UpperCaseFoldingStrategy
@Override
public String toString() {
- return ClassTools.toStringClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkConvert.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkConvert.java
index cad2f639f2..562960da30 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkConvert.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkConvert.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -253,7 +253,7 @@ public class JavaEclipseLinkConvert extends AbstractJavaJpaContextNode implement
}
private Iterator<String> convertersNames(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.persistenceConvertersNames(), filter);
+ return new FilteringIterator<String>(this.persistenceConvertersNames(), filter);
}
protected Iterator<String> persistenceConvertersNames(Filter<String> filter) {
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java
index 69c9c118c7..8c9e53b6eb 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -16,7 +16,7 @@ import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribut
import org.eclipse.jpt.core.jpa2.context.MetamodelField;
import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
/**
* EclipseLink Java persistent attribute
@@ -86,8 +86,8 @@ public class JavaEclipseLinkPersistentAttribute
if (typeName == null) {
return MetamodelField.DEFAULT_TYPE_NAME;
}
- if (ClassTools.classNamedIsPrimitive(typeName)) {
- return ClassTools.wrapperClassName(typeName); // ???
+ if (ClassName.isPrimitive(typeName)) {
+ return ClassName.getWrapperClassName(typeName); // ???
}
return typeName;
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java
index 8efdedfa89..f0184ed12c 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -279,7 +279,7 @@ public class EclipseLinkPersistenceUnit
}
protected Iterator<String> allNonNullConverterNames() {
- return new FilteringIterator<String, String>(this.allConverterNames()) {
+ return new FilteringIterator<String>(this.allConverterNames()) {
@Override
protected boolean accept(String converterName) {
return converterName != null;
diff --git a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/EntityGenerator.java b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/EntityGenerator.java
index d8edb930f1..bab7a2069f 100644
--- a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/EntityGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/EntityGenerator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -1363,7 +1363,7 @@ public class EntityGenerator {
// ********** BodySource implementation **********
public Iterator<Map.Entry<String, String>> importEntries() {
- return new FilteringIterator<Map.Entry<String, String>, Map.Entry<String, String>>(this.sortedImportEntries()) {
+ return new FilteringIterator<Map.Entry<String, String>>(this.sortedImportEntries()) {
@Override
protected boolean accept(Map.Entry<String, String> next) {
String pkg = next.getValue();
diff --git a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenScope.java b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenScope.java
index 126345f8ea..6004f9c09d 100644
--- a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenScope.java
+++ b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenScope.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -115,7 +115,7 @@ class GenScope {
* entities (i.e. exclude the "join" tables)
*/
Iterator<GenTable> entityGenTables() {
- return new FilteringIterator<GenTable, GenTable>(this.genTables()) {
+ return new FilteringIterator<GenTable>(this.genTables()) {
@Override
protected boolean accept(GenTable genTable) {
return ! genTable.isJoinTable();
@@ -152,7 +152,7 @@ class GenScope {
* return only the "join" gen tables
*/
private Iterator<GenTable> joinGenTables() {
- return new FilteringIterator<GenTable, GenTable>(this.genTables()) {
+ return new FilteringIterator<GenTable>(this.genTables()) {
@Override
protected boolean accept(GenTable genTable) {
return genTable.isJoinTable();
diff --git a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenTable.java b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenTable.java
index 1676ad1e4e..5a1aeb94d8 100644
--- a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenTable.java
+++ b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/old/GenTable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,6 @@ import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.NameTools;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
-import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
/**
* associate a table with the various relations that will be used when
@@ -166,7 +165,7 @@ class GenTable {
* but are also part of an "in-scope" foreign key
*/
Iterable<Column> getReadOnlyPrimaryKeyColumns() {
- return new FilteringIterable<Column, Column>(this.table.getPrimaryKeyColumns()) {
+ return new FilteringIterable<Column>(this.table.getPrimaryKeyColumns()) {
@Override
protected boolean accept(Column pkColumn) {
return pkColumn.isPartOfForeignKey();
@@ -179,7 +178,7 @@ class GenTable {
* but are NOT part of any "in-scope" foreign key
*/
Iterable<Column> getWritablePrimaryKeyColumns() {
- return new FilteringIterable<Column, Column>(this.table.getPrimaryKeyColumns()) {
+ return new FilteringIterable<Column>(this.table.getPrimaryKeyColumns()) {
@Override
protected boolean accept(Column pkColumn) {
return ! pkColumn.isPartOfForeignKey();
@@ -192,7 +191,7 @@ class GenTable {
* NOR part of any foreign key
*/
Iterable<Column> getNonPrimaryKeyBasicColumns() {
- return new FilteringIterable<Column, Column>(this.table.getColumns()) {
+ return new FilteringIterable<Column>(this.table.getColumns()) {
@Override
protected boolean accept(Column column) {
return ! (column.isPartOfPrimaryKey() || column.isPartOfForeignKey());
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java
index 92f5b43a25..2160b76b80 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -127,7 +127,7 @@ public class GenericNavigatorItemContentProviderFactory
})) {
@Override
protected Iterable<JpaContextNode> filter(Iterable<? extends JpaContextNode> items) {
- return new FilteringIterable<JpaContextNode, JpaContextNode>(items) {
+ return new FilteringIterable<JpaContextNode>(items) {
@Override
protected boolean accept(JpaContextNode o) {
return o != null;
@@ -169,7 +169,7 @@ public class GenericNavigatorItemContentProviderFactory
})) {
@Override
protected Iterable<JpaContextNode> filter(Iterable<? extends JpaContextNode> items) {
- return new FilteringIterable<JpaContextNode, JpaContextNode>(items) {
+ return new FilteringIterable<JpaContextNode>(items) {
@Override
protected boolean accept(JpaContextNode o) {
return o != null;
@@ -227,7 +227,7 @@ public class GenericNavigatorItemContentProviderFactory
})) {
@Override
protected Iterable<JpaContextNode> filter(Iterable<? extends JpaContextNode> items) {
- return new FilteringIterable<JpaContextNode, JpaContextNode>(items) {
+ return new FilteringIterable<JpaContextNode>(items) {
@Override
protected boolean accept(JpaContextNode o) {
return o != null;
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java
index a6166e1d2f..1773b6661f 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -17,7 +17,7 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jpt.ui.internal.widgets.NullPostExecution;
import org.eclipse.jpt.ui.internal.widgets.PostExecution;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
@@ -104,12 +104,12 @@ public class SWTUtil {
Object value) {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.shortNameFor(compositeClass));
+ sb.append(compositeClass.getSimpleName());
sb.append("_");
sb.append(value.toString().toLowerCase(Locale.ENGLISH));//bug 234953
//TODO in a future release we should not be converting the key using toLowerCase()
- return (String) ClassTools.staticFieldValue(nlsClass, sb.toString());
+ return (String) ReflectionTools.getStaticFieldValue(nlsClass, sb.toString());
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java
index 12ade28d7a..c6bd5bd9c7 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -32,7 +32,7 @@ import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.ui.JptUiPlugin;
import org.eclipse.jpt.ui.internal.JptUiMessages;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ClassName;
import org.eclipse.jpt.utility.model.Model;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
@@ -153,11 +153,9 @@ public abstract class ClassChooserPane<T extends Model> extends ChooserPane<T>
newClassWizardPage.setSuperInterfaces(getSuperInterfaceNames(), true);
newClassWizardPage.setPackageFragmentRoot(getPackageFragmentRoot(), true);
if (getClassName() != null) {
- newClassWizardPage.setTypeName(ClassTools.shortNameForClassNamed(getClassName()), true);
- String packageName = ClassTools.packageNameForClassNamed(getClassName());
- if (packageName != null) {
- newClassWizardPage.setPackageFragment(getPackageFragmentRoot().getPackageFragment(packageName), true);
- }
+ newClassWizardPage.setTypeName(ClassName.getSimpleName(getClassName()), true);
+ String packageName = ClassName.getPackageName(getClassName());
+ newClassWizardPage.setPackageFragment(getPackageFragmentRoot().getPackageFragment(packageName), true);
}
NewClassCreationWizard wizard = new NewClassCreationWizard(newClassWizardPage, false);
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(getJpaProject().getProject()));//TODO StructuredSelection
@@ -287,7 +285,7 @@ public abstract class ClassChooserPane<T extends Model> extends ChooserPane<T>
scope,
getTypeDialogStyle(),
false,
- getClassName() != null ? ClassTools.shortNameForClassNamed(getClassName()) : ""
+ getClassName() != null ? ClassName.getSimpleName(getClassName()) : ""
);
}
catch (JavaModelException e) {
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java
index a66b5eafd6..48ad9dd8bd 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.ui.internal.widgets;
import java.util.ArrayList;
import java.util.Collection;
+
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IBaseLabelProvider;
@@ -29,7 +30,6 @@ import org.eclipse.jpt.ui.internal.util.LabeledButton;
import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater;
import org.eclipse.jpt.ui.internal.util.SWTUtil;
import org.eclipse.jpt.ui.internal.utility.swt.SWTTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.StringConverter;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.model.Model;
@@ -3589,11 +3589,11 @@ public abstract class Pane<T extends Model>
protected void log(String message) {
Class<?> thisClass = this.getClass();
- String className = ClassTools.shortNameFor(thisClass);
+ String className = thisClass.getSimpleName();
if (thisClass.isAnonymousClass()) {
className = className.substring(0, className.indexOf('$'));
- className += "->" + ClassTools.shortNameFor(thisClass.getSuperclass());
+ className += "->" + thisClass.getSuperclass().getSimpleName();
}
Tracing.log(className + ": " + message);
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ArrayTools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ArrayTools.java
index 040f15f34d..1f17389033 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ArrayTools.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ArrayTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -32,7 +32,7 @@ public final class ArrayTools {
* Return a new array with the specified length
* and the same component type as the specified array.
* <p>
- * Arrays.newArray(Object[] array, int length)
+ * <code>Arrays.newArray(Object[] array, int length)</code>
*/
public static <E> E[] newArray(E[] array, int length) {
return newArray(componentType(array), length);
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassName.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassName.java
new file mode 100644
index 0000000000..6a8185dc14
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassName.java
@@ -0,0 +1,421 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2010 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.utility.internal;
+
+/**
+ * Convenience methods related to Java class names as returned by
+ * {@link java.lang.Class#getName()}.
+ */
+public class ClassName {
+
+ public static final String VOID_CLASS_NAME = ReflectionTools.VOID_CLASS.getName();
+ public static final String VOID_WRAPPER_CLASS_NAME = ReflectionTools.VOID_WRAPPER_CLASS.getName();
+
+ public static final char REFERENCE_CLASS_CODE = 'L';
+ public static final char REFERENCE_CLASS_NAME_DELIMITER = ';';
+
+ /**
+ * Return whether the specified class is an array type.
+ * @see java.lang.Class#getName()
+ */
+ public static boolean isArray(String className) {
+ return className.charAt(0) == '[';
+ }
+
+ /**
+ * Return the "element type" of the specified class.
+ * The element type is the base type held by an array type.
+ * Non-array types simply return themselves.
+ * @see java.lang.Class#getName()
+ */
+ public static String getElementTypeName(String className) {
+ int depth = getArrayDepth(className);
+ if (depth == 0) {
+ // the name is in the form: "java.lang.Object" or "int"
+ return className;
+ }
+ return getElementTypeName_(className, depth);
+ }
+
+ /**
+ * pre-condition: array depth is not zero
+ */
+ private static String getElementTypeName_(String className, int arrayDepth) {
+ int last = className.length() - 1;
+ if (className.charAt(arrayDepth) == REFERENCE_CLASS_CODE) {
+ // the name is in the form: "[[[Ljava.lang.Object;"
+ return className.substring(arrayDepth + 1, last); // drop the trailing ';'
+ }
+ // the name is in the form: "[[[I"
+ return forCode(className.charAt(last));
+ }
+
+ /**
+ * Return the "array depth" of the specified class.
+ * The depth is the number of dimensions for an array type.
+ * Non-array types have a depth of zero.
+ * @see java.lang.Class#getName()
+ */
+ public static int getArrayDepth(String className) {
+ int depth = 0;
+ while (className.charAt(depth) == '[') {
+ depth++;
+ }
+ return depth;
+ }
+
+ /**
+ * Return the specified class's component type.
+ * Return <code>null</code> if the specified class is not an array type.
+ * @see java.lang.Class#getName()
+ */
+ public static String getComponentTypeName(String className) {
+ switch (getArrayDepth(className)) {
+ case 0:
+ return null;
+ case 1:
+ return getElementTypeName_(className, 1);
+ default:
+ return className.substring(1);
+ }
+ }
+
+ /**
+ * Return the specified class's simple name.
+ * Return an empty string if the specified class is anonymous.
+ * <p>
+ * The simple name of an array type is the simple name of the
+ * component type with <code>"[]"</code> appended. In particular,
+ * the simple name of an array type whose component type is
+ * anonymous is simply <code>"[]"</code>.
+ * @see java.lang.Class#getSimpleName()
+ */
+ public static String getSimpleName(String className) {
+ return isArray(className) ?
+ getSimpleName(getComponentTypeName(className)) + "[]" : //$NON-NLS-1$
+ getSimpleName_(className);
+ }
+
+ /**
+ * pre-condition: specified class is not an array type
+ */
+ private static String getSimpleName_(String className) {
+ int index = className.lastIndexOf('$');
+ if (index == -1) { // "top-level" class - strip package name
+ return className.substring(className.lastIndexOf('.') + 1);
+ }
+
+ int len = className.length();
+ for (int i = ++index; i < len; i++) {
+ if ( ! charIsAsciiDigit(className.charAt(i))) {
+ return className.substring(i); // "member" or "local" class
+ }
+ }
+ // all the characters past the '$' are ASCII digits ("anonymous" class)
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Return the specified class's package name (e.g.
+ * <code>"java.lang.Object"</code> returns
+ * <code>"java.lang"</code>).
+ * Return an empty string if the specified class is:<ul>
+ * <li>in the "default" package
+ * <li>an array class
+ * <li>a primtive class
+ * </ul>
+ * @see java.lang.Class#getPackage()
+ * @see java.lang.Package#getName()
+ */
+ public static String getPackageName(String className) {
+ if (isArray(className)) {
+ return ""; //$NON-NLS-1$
+ }
+ int lastPeriod = className.lastIndexOf('.');
+ return (lastPeriod == -1) ? "" : className.substring(0, lastPeriod); //$NON-NLS-1$
+ }
+
+ /**
+ * Return whether the specified class is a "top-level" class,
+ * as opposed to a "member", "local", or "anonymous" class,
+ * using the standard JDK naming conventions (i.e. the class
+ * name does NOT contain a <code>'$'</code>).
+ * A "top-level" class can be either the "primary" (public) class defined
+ * in a file/compilation unit (i.e. the class with the same name as its
+ * file's simple base name) or a "non-primary" (package visible) class
+ * (i.e. the other top-level classes defined in a file).
+ * A "top-level" class can contain any of the other types of classes.
+ * @see java.lang.Class#getName()
+ */
+ public static boolean isTopLevel(String className) {
+ if (isArray(className)) {
+ return false;
+ }
+ return className.lastIndexOf('$') == -1;
+ }
+
+ /**
+ * Return whether the specified class is a "member" class,
+ * as opposed to a "top-level", "local", or "anonymous" class,
+ * using the standard JDK naming convention (i.e. the class
+ * name ends with a <code>'$'</code> followed by a legal class name; e.g.
+ * <code>"TopLevelClass$1LocalClass$MemberClass"</code>).
+ * A "member" class can be either "nested" (static) or "inner";
+ * but there is no way to determine which from the class's name.
+ * A "member" class can contain "local", "anonymous", or other
+ * "member" classes; and vice-versa.
+ * @see java.lang.Class#getName()
+ */
+ public static boolean isMember(String className) {
+ if (isArray(className)) {
+ return false;
+ }
+ int index = className.lastIndexOf('$');
+ if (index == -1) {
+ return false; // "top-level" class
+ }
+ // the character immediately after the dollar sign cannot be an ASCII digit
+ return ! charIsAsciiDigit(className.charAt(++index));
+ }
+
+ /**
+ * Return whether the specified class is a "local" class,
+ * as opposed to a "top-level", "member", or "anonymous" class,
+ * using the standard JDK naming convention (i.e. the class name
+ * ends with <code>"$nnnXXX"</code>,
+ * where the <code>'$'</code> is
+ * followed by a series of numeric digits which are followed by the
+ * local class name; e.g. <code>"TopLevelClass$1LocalClass"</code>).
+ * A "local" class can contain "member", "anonymous", or other
+ * "local" classes; and vice-versa.
+ * @see java.lang.Class#getName()
+ */
+ public static boolean isLocal(String className) {
+ if (isArray(className)) {
+ return false;
+ }
+ int index = className.lastIndexOf('$');
+ if (index == -1) {
+ return false; // "top-level" class
+ }
+ if ( ! charIsAsciiDigit(className.charAt(++index))) {
+ return false; // "member" class
+ }
+ int len = className.length();
+ for (int i = ++index; i < len; i++) {
+ if ( ! charIsAsciiDigit(className.charAt(i))) {
+ return true;
+ }
+ }
+ // all the characters past the '$' are ASCII digits ("anonymous" class)
+ return false;
+ }
+
+ /**
+ * Return whether the specified class is an "anonymous" class,
+ * as opposed to a "top-level", "member", or "local" class,
+ * using the standard JDK naming convention (i.e. the class
+ * name ends with <code>"$nnn"</code> where all the characters past the
+ * last <code>'$'</code> are ASCII numeric digits;
+ * e.g. <code>"TopLevelClass$1"</code>).
+ * An "anonymous" class can contain "member", "local", or other
+ * "anonymous" classes; and vice-versa.
+ * @see java.lang.Class#getName()
+ */
+ public static boolean isAnonymous(String className) {
+ if (isArray(className)) {
+ return false;
+ }
+ int index = className.lastIndexOf('$');
+ if (index == -1) {
+ return false; // "top-level" class
+ }
+ if ( ! charIsAsciiDigit(className.charAt(++index))) {
+ return false; // "member" class
+ }
+ int len = className.length();
+ for (int i = ++index; i < len; i++) {
+ if ( ! charIsAsciiDigit(className.charAt(i))) {
+ return false; // "local" class
+ }
+ }
+ // all the characters past the '$' are ASCII digits ("anonymous" class)
+ return true;
+ }
+
+ /**
+ * {@link Character#isDigit(char)} returns <code>true</code> for some non-ASCII
+ * digits. This method does not.
+ */
+ private static boolean charIsAsciiDigit(char c) {
+ return ('0' <= c) && (c <= '9');
+ }
+
+ /**
+ * Return whether the specified class is a "reference"
+ * class (i.e. neither <code>void</code> nor one of the primitive variable classes,
+ * <code>boolean</code>, <code>int</code>, <code>float</code>, etc.).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ */
+ public static boolean isReference(String className) {
+ return ! isPrimitive(className);
+ }
+
+ /**
+ * Return whether the specified class is a primitive
+ * class (i.e. <code>void</code> or one of the primitive variable classes,
+ * <code>boolean</code>, <code>int</code>, <code>float</code>, etc.).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ */
+ public static boolean isPrimitive(String className) {
+ if (isArray(className) || (className.length() > ReflectionTools.MAX_PRIMITIVE_CLASS_NAME_LENGTH)) {
+ return false; // performance tweak
+ }
+ for (ReflectionTools.Primitive primitive : ReflectionTools.PRIMITIVES) {
+ if (className.equals(primitive.javaClass.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return whether the specified class is a primitive wrapper
+ * class (i.e. <code>java.lang.Void</code> or one of the primitive
+ * variable wrapper classes, <code>java.lang.Boolean</code>,
+ * <code>java.lang.Integer</code>, <code>java.lang.Float</code>, etc.).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ */
+ public static boolean isPrimitiveWrapper(String className) {
+ if (isArray(className) || (className.length() > ReflectionTools.MAX_PRIMITIVE_WRAPPER_CLASS_NAME_LENGTH)) {
+ return false; // performance tweak
+ }
+ for (ReflectionTools.Primitive primitive : ReflectionTools.PRIMITIVES) {
+ if (className.equals(primitive.wrapperClass.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return whether the specified class is a "variable" primitive
+ * class (i.e. <code>boolean</code>, <code>int</code>, <code>float</code>, etc.,
+ * but not <code>void</code>).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ */
+ public static boolean isVariablePrimitive(String className) {
+ return isPrimitive(className)
+ && ( ! className.equals(VOID_CLASS_NAME));
+ }
+
+ /**
+ * Return whether the specified class is a "variable" primitive wrapper
+ * class (i.e. <code>java.lang.Boolean</code>,
+ * <code>java.lang.Integer</code>, <code>java.lang.Float</code>, etc.,
+ * but not <code>java.lang.Void</code>).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ */
+ public static boolean isVariablePrimitiveWrapper(String className) {
+ return isPrimitiveWrapper(className)
+ && ( ! className.equals(VOID_WRAPPER_CLASS_NAME));
+ }
+
+ /**
+ * Return the name of the primitive wrapper class corresponding to the specified
+ * primitive class. Return <code>null</code> if the specified class is not a primitive.
+ */
+ public static String getWrapperClassName(String primitiveClassName) {
+ for (ReflectionTools.Primitive primitive : ReflectionTools.PRIMITIVES) {
+ if (primitive.javaClass.getName().equals(primitiveClassName)) {
+ return primitive.wrapperClass.getName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the name of the primitive class corresponding to the specified
+ * primitive wrapper class. Return <code>null</code> if the specified class
+ * is not a primitive wrapper.
+ */
+ public static String getPrimitiveClassName(String primitiveWrapperClassName) {
+ for (ReflectionTools.Primitive primitive : ReflectionTools.PRIMITIVES) {
+ if (primitive.wrapperClass.getName().equals(primitiveWrapperClassName)) {
+ return primitive.javaClass.getName();
+ }
+ }
+ return null;
+ }
+
+
+ // ********** primitive codes **********
+
+ /**
+ * Return the primitive class name for the specified primitive class code.
+ * Return <code>null</code> if the specified code
+ * is not a primitive class code.
+ * @see java.lang.Class#getName()
+ */
+ public static String forCode(int classCode) {
+ return forCode((char) classCode);
+ }
+
+ /**
+ * Return the primitive class name for the specified primitive class code.
+ * Return <code>null</code> if the specified code
+ * is not a primitive class code.
+ * @see java.lang.Class#getName()
+ */
+ public static String forCode(char classCode) {
+ Class<?> primitiveClass = ReflectionTools.getClassForCode(classCode);
+ return (primitiveClass == null) ? null : primitiveClass.getName();
+ }
+
+ /**
+ * Return the class code for the specified primitive class.
+ * Return <code>0</code> if the specified class
+ * is not a primitive class.
+ * @see java.lang.Class#getName()
+ */
+ public static char getCodeForClassName(String primitiveClassName) {
+ if (( ! isArray(primitiveClassName)) && (primitiveClassName.length() <= ReflectionTools.MAX_PRIMITIVE_CLASS_NAME_LENGTH)) {
+ for (ReflectionTools.Primitive primitive : ReflectionTools.PRIMITIVES) {
+ if (primitive.javaClass.getName().equals(primitiveClassName)) {
+ return primitive.code;
+ }
+ }
+ }
+ return 0;
+ }
+
+ static void append(String className, StringBuilder sb) {
+ sb.append(REFERENCE_CLASS_CODE);
+ sb.append(className);
+ sb.append(REFERENCE_CLASS_NAME_DELIMITER);
+ }
+
+
+ // ********** suppressed constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private ClassName() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassTools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassTools.java
deleted file mode 100644
index 806d23e56f..0000000000
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ClassTools.java
+++ /dev/null
@@ -1,1708 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 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.utility.internal;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.Stack;
-
-import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
-
-/**
- * Convenience methods related to the java.lang.reflect package.
- * These methods provide shortcuts for manipulating objects via
- * reflection; particularly when dealing with fields and/or methods that
- * are not publicly accessible or are inherited.
- *
- * In most cases, all the exceptions are handled and
- * wrapped in java.lang.RuntimeExceptions; so these methods should
- * be used when you are confident that you will not having any problems
- * using reflection.
- *
- * There are also a number of methods whose names
- * begin with "attempt". These methods will throw a NoSuchMethodException
- * or NoSuchFieldException when appropriate, allowing you to probe
- * for methods that should be present but might not.
- */
-public final class ClassTools {
-
- public static final Class<?>[] ZERO_PARAMETER_TYPES = new Class[0];
- public static final Object[] ZERO_PARAMETERS = new Object[0];
- private static final String CR = StringTools.CR;
-
- public static final char NESTED_CLASS_NAME_SEPARATOR = '$';
-
- public static final char ARRAY_INDICATOR = '[';
- public static final char TYPE_DECLARATION_ARRAY_OPEN = '[';
- public static final char TYPE_DECLARATION_ARRAY_CLOSE = ']';
-
- public static final char REFERENCE_CLASS_CODE = 'L';
- public static final char REFERENCE_CLASS_NAME_DELIMITER = ';';
-
- private static final Iterable<Primitive> PRIMITIVES = buildPrimitives();
- public static final char BYTE_CODE = 'B';
- public static final char CHAR_CODE = 'C';
- public static final char DOUBLE_CODE = 'D';
- public static final char FLOAT_CODE = 'F';
- public static final char INT_CODE = 'I';
- public static final char LONG_CODE = 'J';
- public static final char SHORT_CODE = 'S';
- public static final char BOOLEAN_CODE = 'Z';
- public static final char VOID_CODE = 'V';
- private static final int MAX_PRIMITIVE_CLASS_NAME_LENGTH = calculateMaxPrimitiveClassNameLength();
- private static final int MAX_PRIMITIVE_WRAPPER_CLASS_NAME_LENGTH = calculateMaxPrimitiveWrapperClassNameLength();
-
- public static final String VOID_CLASS_NAME = void.class.getName();
- public static final String VOID_WRAPPER_CLASS_NAME = java.lang.Void.class.getName();
-
-
- /**
- * Return all the fields for the
- * specified class, including inherited fields.
- * Class#allFields()
- */
- public static Field[] allFields(Class<?> javaClass) {
- Stack<Field> stack = new Stack<Field>();
- for (Class<?> tempClass = javaClass; tempClass != null; tempClass = tempClass.getSuperclass()) {
- pushDeclaredFields(tempClass, stack);
- }
- Collections.reverse(stack);
- return stack.toArray(new Field[stack.size()]);
- }
-
- /**
- * Return all the methods for the
- * specified class, including inherited methods.
- * Class#allMethods()
- */
- public static Method[] allMethods(Class<?> javaClass) {
- Stack<Method> stack = new Stack<Method>();
- for (Class<?> tempClass = javaClass; tempClass != null; tempClass = tempClass.getSuperclass()) {
- pushDeclaredMethods(tempClass, stack);
- }
- Collections.reverse(stack);
- return stack.toArray(new Method[stack.size()]);
- }
-
- /**
- * Convenience method.
- * Return a new instance of the specified class,
- * using the class's default (zero-argument) constructor.
- * Throw an exception if the default constructor is not defined.
- * Class#newInstance() throws NoSuchMethodException
- */
- public static <T> T attemptNewInstance(Class<T> javaClass) throws NoSuchMethodException {
- return attemptNewInstance(javaClass, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Return a new instance of the specified class,
- * given the constructor parameter types and parameters.
- * Throw an exception if the constructor is not defined.
- * Class#newInstance(Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException
- */
- public static <T> T attemptNewInstance(Class<T> javaClass, Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException {
- try {
- return constructor(javaClass, parameterTypes).newInstance(parameters);
- } catch (InstantiationException ie) {
- throw new RuntimeException(ie + CR + fullyQualifiedConstructorSignature(javaClass, parameterTypes), ie);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + fullyQualifiedConstructorSignature(javaClass, parameterTypes), iae);
- } catch (InvocationTargetException ite) {
- throw new RuntimeException(fullyQualifiedConstructorSignature(javaClass, parameterTypes) + CR + ite.getTargetException(), ite);
- }
- }
-
- /**
- * Convenience method.
- * Return a new instance of the specified class,
- * given the constructor parameter type and parameter.
- * Throw an exception if the constructor is not defined.
- * Class#newInstance(Class<?> parameterType, Object parameter) throws NoSuchMethodException
- */
- public static <T> T attemptNewInstance(Class<T> javaClass, Class<?> parameterType, Object parameter) throws NoSuchMethodException {
- return attemptNewInstance(javaClass, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Attempt to get a field value, given the containing object and field name.
- * Return its result.
- * Useful for accessing private, package, or protected fields.
- * Throw an exception if the field is not defined.
- * Object#getFieldValue(String fieldName) throws NoSuchFieldException
- */
- public static Object attemptToGetFieldValue(Object object, String fieldName) throws NoSuchFieldException {
- try {
- return field(object, fieldName).get(object);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + fullyQualifiedFieldName(object, fieldName), iae);
- }
- }
-
- /**
- * Attempt to get a static field value, given the containing object and field name.
- * Return its result.
- * Useful for accessing private, package, or protected fields.
- * Throw an exception if the field is not defined.
- * Class#getStaticFieldValue(String fieldName) throws NoSuchFieldException
- */
- public static Object attemptToGetStaticFieldValue(Class<?> javaClass, String fieldName) throws NoSuchFieldException {
- try {
- return field(javaClass, fieldName).get(null);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + fullyQualifiedFieldName(javaClass, fieldName), iae);
- }
- }
-
- /**
- * Convenience method.
- * Attempt to execute a zero-argument method,
- * given the receiver and method name.
- * Return its result.
- * Throw an exception if the method is not found.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName) throws NoSuchMethodException
- */
- public static Object attemptToExecuteMethod(Object receiver, String methodName) throws NoSuchMethodException {
- return attemptToExecuteMethod(receiver, methodName, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Convenience method.
- * Attempt to execute a method, given the receiver,
- * method name, parameter type, and parameter.
- * Return its result.
- * Throw an exception if the method is not found.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?> parameterType, Object parameter) throws NoSuchMethodException
- */
- public static Object attemptToExecuteMethod(Object receiver, String methodName, Class<?> parameterType, Object parameter) throws NoSuchMethodException {
- return attemptToExecuteMethod(receiver, methodName, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Attempt to execute a method, given the receiver,
- * method name, parameter types, and parameters.
- * Return its result.
- * Throw an exception if the method is not found.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException
- */
- public static Object attemptToExecuteMethod(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException {
- return executeMethod(method(receiver, methodName, parameterTypes), receiver, parameters);
- }
-
- /**
- * Attempt to execute a method, given the receiver,
- * method name, parameter types, and parameters.
- * Return its result.
- * Throw an exception if the method is not found.
- * If the executed method throws an exception, rethrow that exception.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException
- */
- public static Object attemptToExecuteMethodWithException(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] parameters)
- throws Throwable, NoSuchMethodException
- {
- return executeMethodWithException(method(receiver, methodName, parameterTypes), receiver, parameters);
- }
-
- /**
- * Convenience method.
- * Attempt to execute a zero-argument static method,
- * given the class and method name.
- * Return its result.
- * Throw an exception if the method is not found.
- * Useful for invoking private, package, or protected methods.
- * Class#executeStaticMethod(String methodName) throws NoSuchMethodException
- */
- public static Object attemptToExecuteStaticMethod(Class<?> javaClass, String methodName) throws NoSuchMethodException {
- return attemptToExecuteStaticMethod(javaClass, methodName, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Attempt to execute a static method, given the class,
- * method name, parameter types, and parameters.
- * Return its result.
- * Throw an exception if the method is not found.
- * Useful for invoking private, package, or protected methods.
- * Class#executeStaticMethod(String methodName, Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException
- */
- public static Object attemptToExecuteStaticMethod(Class<?> javaClass, String methodName, Class<?>[] parameterTypes, Object[] parameters) throws NoSuchMethodException {
- return executeStaticMethod(staticMethod(javaClass, methodName, parameterTypes), parameters);
- }
-
- /**
- * Convenience method.
- * Attempt to execute a static method, given the class,
- * method name, parameter type, and parameter.
- * Return its result.
- * Throw an exception if the method is not found.
- * Useful for invoking private, package, or protected methods.
- * Class#executeStaticMethod(String methodName, Class<?> parameterType, Object parameter) throws NoSuchMethodException
- */
- public static Object attemptToExecuteStaticMethod(Class<?> javaClass, String methodName, Class<?> parameterType, Object parameter) throws NoSuchMethodException {
- return attemptToExecuteStaticMethod(javaClass, methodName, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Attempt to set a field value, given the
- * containing object, field name, and new field value.
- * Useful for accessing private, package, or protected fields.
- * Throw an exception if the field is not defined.
- * Object#setFieldValue(String fieldName, Object fieldValue) throws NoSuchFieldException
- */
- public static void attemptToSetFieldValue(Object object, String fieldName, Object fieldValue) throws NoSuchFieldException {
- try {
- field(object, fieldName).set(object, fieldValue);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + fullyQualifiedFieldName(object, fieldName), iae);
- }
- }
-
- /**
- * Attempt to set a static field value, given the
- * containing class, field name, and new field value.
- * Useful for accessing private, package, or protected fields.
- * Throw an exception if the field is not defined.
- * Class#setStaticFieldValue(String fieldName, Object fieldValue) throws NoSuchFieldException
- */
- public static void attemptToSetStaticFieldValue(Class<?> javaClass, String fieldName, Object fieldValue) throws NoSuchFieldException {
- try {
- field(javaClass, fieldName).set(null, fieldValue);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + fullyQualifiedFieldName(javaClass, fieldName), iae);
- }
- }
-
- /**
- * Convenience method.
- * Return the default (zero-argument) constructor
- * for the specified class.
- * Set accessible to true, so we can access
- * private/package/protected constructors.
- * Class#constructor() throws NoSuchMethodException
- */
- public static <T> Constructor<T> constructor(Class<T> javaClass) throws NoSuchMethodException {
- return constructor(javaClass, ZERO_PARAMETER_TYPES);
- }
-
- /**
- * Return the constructor for the specified class
- * and formal parameter types.
- * Set accessible to true, so we can access
- * private/package/protected constructors.
- * Class#constructor(Class<?>[] parameterTypes) throws NoSuchMethodException
- */
- public static <T> Constructor<T> constructor(Class<T> javaClass, Class<?>[] parameterTypes) throws NoSuchMethodException {
- Constructor<T> constructor = javaClass.getDeclaredConstructor(parameterTypes);
- constructor.setAccessible(true);
- return constructor;
- }
-
- /**
- * Convenience method.
- * Return the constructor for the specified class
- * and formal parameter type.
- * Set accessible to true, so we can access
- * private/package/protected constructors.
- * Class#constructor(Class<?> parameterType) throws NoSuchMethodException
- */
- public static <T> Constructor<T> constructor(Class<T> javaClass, Class<?> parameterType) throws NoSuchMethodException {
- return constructor(javaClass, new Class[] {parameterType});
- }
-
- /**
- * Return the declared fields for the specified class.
- * Set accessible to true, so we can access
- * private/package/protected fields.
- * Class#accessibleDeclaredFields()
- */
- public static Field[] declaredFields(Class<?> javaClass) {
- Field[] fields = javaClass.getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- }
- return fields;
- }
-
- /**
- * Return the declared methods for the
- * specified class.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- * Class#accessibleDeclaredMethods()
- */
- public static Method[] declaredMethods(Class<?> javaClass) {
- Method[] methods = javaClass.getDeclaredMethods();
- for (Method method : methods) {
- method.setAccessible(true);
- }
- return methods;
- }
-
- /**
- * Return the default (zero-argument) constructor
- * for the specified class.
- * Set accessible to true, so we can access
- * private/package/protected constructors.
- * Class#defaultConstructor()
- */
- public static <T> Constructor<T> defaultConstructor(Class<T> javaClass) throws NoSuchMethodException {
- return constructor(javaClass);
- }
-
- /**
- * Return a field for the specified class and field name.
- * If the class does not directly
- * define the field, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected fields.
- */
- public static Field field(Class<?> javaClass, String fieldName) throws NoSuchFieldException {
- Field field = null;
- try {
- field = javaClass.getDeclaredField(fieldName);
- } catch (NoSuchFieldException ex) {
- Class<?> superclass = javaClass.getSuperclass();
- if (superclass == null) {
- throw ex;
- }
- // recurse
- return field(superclass, fieldName);
- }
- field.setAccessible(true);
- return field;
- }
-
- /**
- * Convenience method.
- * Return a field for the specified object and field name.
- * If the object's class does not directly
- * define the field, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected fields.
- */
- public static Field field(Object object, String fieldName) throws NoSuchFieldException {
- return field(object.getClass(), fieldName);
- }
-
- /*
- * Return a string representation of the specified constructor.
- */
- private static String fullyQualifiedConstructorSignature(Class<?> javaClass, Class<?>[] parameterTypes) {
- return fullyQualifiedMethodSignature(javaClass, null, parameterTypes);
- }
-
- /*
- * Return a string representation of the specified field.
- */
- private static String fullyQualifiedFieldName(Class<?> javaClass, String fieldName) {
- StringBuilder sb = new StringBuilder(200);
- sb.append(javaClass.getName());
- sb.append('.');
- sb.append(fieldName);
- return sb.toString();
- }
-
- /*
- * Return a string representation of the specified field.
- */
- private static String fullyQualifiedFieldName(Object object, String fieldName) {
- return fullyQualifiedFieldName(object.getClass(), fieldName);
- }
-
- /*
- * Return a string representation of the specified method.
- */
- private static String fullyQualifiedMethodSignature(Class<?> javaClass, String methodName, Class<?>[] parameterTypes) {
- StringBuilder sb = new StringBuilder(200);
- sb.append(javaClass.getName());
- // this check allows us to use this code for constructors, where the methodName is null
- if (methodName != null) {
- sb.append('.');
- sb.append(methodName);
- }
- sb.append('(');
- int max = parameterTypes.length - 1;
- if (max != -1) {
- // stop one short of the end of the array
- for (int i = 0; i < max; i++) {
- sb.append(parameterTypes[i].getName());
- sb.append(", "); //$NON-NLS-1$
- }
- sb.append(parameterTypes[max].getName());
- }
- sb.append(')');
- return sb.toString();
- }
-
- /*
- * Return a string representation of the specified method.
- */
- private static String fullyQualifiedMethodSignature(Object receiver, String methodName, Class<?>[] parameterTypes) {
- return fullyQualifiedMethodSignature(receiver.getClass(), methodName, parameterTypes);
- }
-
- /**
- * Get a field value, given the containing object and field name.
- * Return its result.
- * Useful for accessing private, package, or protected fields.
- * Object#getFieldValue(String fieldName)
- */
- public static Object fieldValue(Object object, String fieldName) {
- try {
- return attemptToGetFieldValue(object, fieldName);
- } catch (NoSuchFieldException nsfe) {
- throw new RuntimeException(nsfe + CR + fullyQualifiedFieldName(object, fieldName), nsfe);
- }
- }
-
- /**
- * Get a static field value, given the containing class and field name.
- * Return its result.
- * Useful for accessing private, package, or protected fields.
- * Class#getStaticFieldValue(String fieldName)
- */
- public static Object staticFieldValue(Class<?> javaClass, String fieldName) {
- try {
- return attemptToGetStaticFieldValue(javaClass, fieldName);
- } catch (NoSuchFieldException nsfe) {
- throw new RuntimeException(nsfe + CR + fullyQualifiedFieldName(javaClass, fieldName), nsfe);
- }
- }
-
- /**
- * Convenience method.
- * Execute a zero-argument method, given the receiver and method name.
- * Return its result.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName)
- */
- public static Object executeMethod(Object receiver, String methodName) {
- return executeMethod(receiver, methodName, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Execute a method, given the receiver,
- * method name, parameter types, and parameters.
- * Return its result.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?>[] parameterTypes, Object[] parameters)
- */
- public static Object executeMethod(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] parameters) {
- try {
- return attemptToExecuteMethod(receiver, methodName, parameterTypes, parameters);
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(nsme + CR + fullyQualifiedMethodSignature(receiver, methodName, parameterTypes), nsme);
- }
- }
-
- /**
- * Convenience method.
- * Execute a one-argument method, given the receiver,
- * method name, parameter type, and parameter.
- * Return its result.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?> parameterType, Object parameter)
- */
- public static Object executeMethod(Object receiver, String methodName, Class<?> parameterType, Object parameter) {
- return executeMethod(receiver, methodName, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Convenience method.
- * Execute a zero-argument method, given the receiver and method name.
- * Return its result.
- * If the method throws an exception, rethrow that exception.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName)
- */
- public static Object executeMethodWithException(Object receiver, String methodName)
- throws Throwable
- {
- return executeMethodWithException(receiver, methodName, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Convenience method.
- * Execute a one-argument method, given the receiver,
- * method name, parameter type, and parameter.
- * Return its result.
- * If the method throws an exception, rethrow that exception.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?> parameterType, Object parameter)
- */
- public static Object executeMethodWithException(Object receiver, String methodName, Class<?> parameterType, Object parameter)
- throws Throwable
- {
- return executeMethodWithException(receiver, methodName, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Execute a method, given the receiver,
- * method name, parameter types, and parameters.
- * Return its result.
- * If the method throws an exception, rethrow that exception.
- * Useful for invoking private, package, or protected methods.
- * Object#execute(String methodName, Class<?>[] parameterTypes, Object[] parameters)
- */
- public static Object executeMethodWithException(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] parameters)
- throws Throwable
- {
- try {
- return attemptToExecuteMethodWithException(receiver, methodName, parameterTypes, parameters);
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(nsme + CR + fullyQualifiedMethodSignature(receiver, methodName, parameterTypes), nsme);
- }
- }
-
- /**
- * Execute the specified method with the specified parameters.
- * Return its result.
- * Convert exceptions to RuntimeExceptions.
- */
- public static Object executeMethod(Method method, Object receiver, Object[] parameters) {
- try {
- return method.invoke(receiver, parameters);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + method, iae);
- } catch (InvocationTargetException ite) {
- throw new RuntimeException(method + CR + ite.getTargetException(), ite);
- }
- }
-
- /**
- * Execute the specified method with the specified parameters.
- * Return its result.
- * If the method throws an exception, rethrow that exception.
- * Convert all other exceptions to RuntimeExceptions.
- */
- public static Object executeMethodWithException(Method method, Object receiver, Object[] parameters)
- throws Throwable
- {
- try {
- return method.invoke(receiver, parameters);
- } catch (IllegalAccessException iae) {
- throw new RuntimeException(iae + CR + method, iae);
- } catch (InvocationTargetException ite) {
- Throwable cause = ite.getCause();
- if (cause == null) {
- throw new RuntimeException(method.toString(), ite);
- }
- throw cause;
- }
- }
-
- /**
- * Convenience method.
- * Execute a zero-argument static method,
- * given the class and method name.
- * Return its result.
- * Useful for invoking private, package, or protected methods.
- * Class#executeStaticMethod(String methodName)
- */
- public static Object executeStaticMethod(Class<?> javaClass, String methodName) {
- return executeStaticMethod(javaClass, methodName, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Execute a static method, given the class,
- * method name, parameter types, and parameters.
- * Return its result.
- * Useful for invoking private, package, or protected methods.
- * Class#executeStaticMethod(String methodName, Class<?>[] parameterTypes, Object[] parameters)
- */
- public static Object executeStaticMethod(Class<?> javaClass, String methodName, Class<?>[] parameterTypes, Object[] parameters) {
- try {
- return attemptToExecuteStaticMethod(javaClass, methodName, parameterTypes, parameters);
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(nsme + CR + fullyQualifiedMethodSignature(javaClass, methodName, parameterTypes), nsme);
- }
- }
-
- /**
- * Convenience method.
- * Execute a static method, given the class,
- * method name, parameter type, and parameter.
- * Return its result.
- * Useful for invoking private, package, or protected methods.
- * Class#executeStaticMethod(String methodName, Class<?> parameterType, Object parameter)
- */
- public static Object executeStaticMethod(Class<?> javaClass, String methodName, Class<?> parameterType, Object parameter) {
- return executeStaticMethod(javaClass, methodName, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Execute the specified static method with the specified parameters.
- * Return its result.
- * Convert exceptions to RuntimeExceptions.
- */
- public static Object executeStaticMethod(Method method, Object[] parameters) {
- return executeMethod(method, null, parameters);
- }
-
- /**
- * Convenience method.
- * Return a zero-argument method for the specified class
- * and method name. If the class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method method(Class<?> javaClass, String methodName) throws NoSuchMethodException {
- return method(javaClass, methodName, ZERO_PARAMETER_TYPES);
- }
-
- /**
- * Return a method for the specified class, method name,
- * and formal parameter types. If the class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method method(Class<?> javaClass, String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException {
- Method method = null;
- try {
- method = javaClass.getDeclaredMethod(methodName, parameterTypes);
- } catch (NoSuchMethodException ex) {
- Class<?> superclass = javaClass.getSuperclass();
- if (superclass == null) {
- throw ex;
- }
- // recurse
- return method(superclass, methodName, parameterTypes);
- }
- method.setAccessible(true);
- return method;
- }
-
- /**
- * Convenience method.
- * Return a method for the specified class, method name,
- * and formal parameter type. If the class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method method(Class<?> javaClass, String methodName, Class<?> parameterType) throws NoSuchMethodException {
- return method(javaClass, methodName, new Class[] {parameterType});
- }
-
- /**
- * Convenience method.
- * Return a zero-argument method for the specified object
- * and method name. If the object's class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method method(Object object, String methodName) throws NoSuchMethodException {
- return method(object.getClass(), methodName);
- }
-
- /**
- * Convenience method.
- * Return a method for the specified object, method name,
- * and formal parameter types. If the object's class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method method(Object object, String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException {
- return method(object.getClass(), methodName, parameterTypes);
- }
-
- /**
- * Convenience method.
- * Return a method for the specified object, method name,
- * and formal parameter type. If the object's class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method method(Object object, String methodName, Class<?> parameterType) throws NoSuchMethodException {
- return method(object.getClass(), methodName, parameterType);
- }
-
- /**
- * Convenience method.
- * Return the specified class (without the checked exception).
- */
- public static Class<?> classForName(String className) {
- try {
- return Class.forName(className);
- } catch (ClassNotFoundException ex) {
- throw new RuntimeException(className, ex);
- }
- }
-
- /**
- * Convenience method.
- * Return a new instance of the specified class,
- * using the class's default (zero-argument) constructor.
- * Class#newInstance()
- */
- public static <T> T newInstance(Class<T> javaClass) {
- return newInstance(javaClass, ZERO_PARAMETER_TYPES, ZERO_PARAMETERS);
- }
-
- /**
- * Convenience method.
- * Return a new instance of the specified class,
- * using the class's default (zero-argument) constructor.
- * Class#newInstance()
- */
- public static Object newInstance(String className) throws ClassNotFoundException {
- return newInstance(className, null);
- }
-
- /**
- * Convenience method.
- * Return a new instance of the specified class,
- * using the class's default (zero-argument) constructor.
- * Class#newInstance()
- */
- public static Object newInstance(String className, ClassLoader classLoader) throws ClassNotFoundException {
- return newInstance(Class.forName(className, true, classLoader));
- }
-
- /**
- * Return a new instance of the specified class,
- * given the constructor parameter types and parameters.
- * Class#newInstance(Class<?>[] parameterTypes, Object[] parameters)
- */
- public static <T> T newInstance(Class<T> javaClass, Class<?>[] parameterTypes, Object[] parameters) {
- try {
- return attemptNewInstance(javaClass, parameterTypes, parameters);
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(nsme + CR + fullyQualifiedConstructorSignature(javaClass, parameterTypes), nsme);
- }
- }
-
- /**
- * Return a new instance of the specified class,
- * given the constructor parameter types and parameters.
- * Class#newInstance(Class<?>[] parameterTypes, Object[] parameters)
- */
- public static Object newInstance(String className, Class<?>[] parameterTypes, Object[] parameters) throws ClassNotFoundException {
- return newInstance(className, parameterTypes, parameters, null);
- }
-
- /**
- * Return a new instance of the specified class,
- * given the constructor parameter types and parameters.
- * Class#newInstance(Class<?>[] parameterTypes, Object[] parameters)
- */
- public static Object newInstance(String className, Class<?>[] parameterTypes, Object[] parameters, ClassLoader classLoader) throws ClassNotFoundException {
- return newInstance(Class.forName(className, true, classLoader), parameterTypes, parameters);
- }
-
- /**
- * Convenience method.
- * Return a new instance of the specified class,
- * given the constructor parameter type and parameter.
- * Class#newInstance(Class<?> parameterType, Object parameter)
- */
- public static <T> T newInstance(Class<T> javaClass, Class<?> parameterType, Object parameter) {
- return newInstance(javaClass, new Class[] {parameterType}, new Object[] {parameter});
- }
-
- /**
- * Return a new instance of the specified class,
- * given the constructor parameter type and parameter.
- * Class#newInstance(Class<?> parameterType, Object parameter)
- */
- public static Object newInstance(String className, Class<?> parameterType, Object parameter) throws ClassNotFoundException {
- return newInstance(className, parameterType, parameter, null);
- }
-
- /**
- * Return a new instance of the specified class,
- * given the constructor parameter type and parameter.
- * Class#newInstance(Class<?> parameterType, Object parameter)
- */
- public static Object newInstance(String className, Class<?> parameterType, Object parameter, ClassLoader classLoader) throws ClassNotFoundException {
- return newInstance(Class.forName(className, false, classLoader), parameterType, parameter);
- }
-
- /*
- * Push the declared fields for the specified class
- * onto the top of the stack.
- */
- private static void pushDeclaredFields(Class<?> javaClass, Stack<Field> stack) {
- Field[] fields = declaredFields(javaClass);
- for (int i = fields.length; i-- > 0; ) {
- stack.push(fields[i]);
- }
- }
-
- /*
- * Push the declared methods for the specified class
- * onto the top of the stack.
- */
- private static void pushDeclaredMethods(Class<?> javaClass, Stack<Method> stack) {
- Method[] methods = declaredMethods(javaClass);
- for (int i = methods.length; i-- > 0; ) {
- stack.push(methods[i]);
- }
- }
-
- /**
- * Set a field value, given the containing object, field name, and new field value.
- * Useful for accessing private, package, or protected fields.
- * Object#setFieldValue(String fieldName, Object fieldValue)
- */
- public static void setFieldValue(Object object, String fieldName, Object fieldValue) {
- try {
- attemptToSetFieldValue(object, fieldName, fieldValue);
- } catch (NoSuchFieldException nsfe) {
- throw new RuntimeException(nsfe + CR + fullyQualifiedFieldName(object, fieldName), nsfe);
- }
- }
-
- /**
- * Set a static field value, given the containing class, field name, and new field value.
- * Useful for accessing private, package, or protected fields.
- * Class#setStaticFieldValue(String fieldName, Object fieldValue)
- */
- public static void setStaticFieldValue(Class<?> javaClass, String fieldName, Object fieldValue) {
- try {
- attemptToSetStaticFieldValue(javaClass, fieldName, fieldValue);
- } catch (NoSuchFieldException nsfe) {
- throw new RuntimeException(nsfe + CR + fullyQualifiedFieldName(javaClass, fieldName), nsfe);
- }
- }
-
- /**
- * Return the short name of the object's class.
- * Class#getShortName()
- */
- public static String shortClassNameForObject(Object object) {
- return shortNameFor(object.getClass());
- }
-
- /**
- * Return the short name of the class (e.g. "Object").
- * Class#getShortName()
- */
- public static String shortNameForClassNamed(String className) {
- return className.substring(className.lastIndexOf('.') + 1);
- }
-
- /**
- * Return the short name of the class (e.g. "Object").
- * Class#getShortName()
- */
- public static String shortNameFor(Class<?> javaClass) {
- return shortNameForClassNamed(javaClass.getName());
- }
-
- /**
- * Return the nested name of the object's class.
- * Class#getNestedName()
- */
- public static String nestedClassNameForObject(Object object) {
- return nestedNameFor(object.getClass());
- }
-
- /**
- * Return the nested name of the class (e.g. "Entry").
- * Class#getNestedName()
- */
- public static String nestedNameForClassNamed(String className) {
- return className.substring(className.lastIndexOf(NESTED_CLASS_NAME_SEPARATOR) + 1);
- }
-
- /**
- * Return the nested name of the class (e.g. "Entry").
- * Class#getNestedName()
- */
- public static String nestedNameFor(Class<?> javaClass) {
- return nestedNameForClassNamed(javaClass.getName());
- }
-
- /**
- * Return the "toString()" name of the object's class.
- */
- public static String toStringClassNameForObject(Object object) {
- return toStringNameFor(object.getClass());
- }
-
- /**
- * Return the "toString()" name of the class.
- * "Member" classes will return only the final name:
- * "com.foo.bar.TopLevelClass$MemberClass$NestedMemberClass"
- * => "NestedMemberClass"
- * "Local" and "anonymous" classes will still return the embedded '$'s:
- * "com.foo.bar.TopLevelClass$1LocalClass"
- * => "TopLevelClass$1LocalClass"
- * "com.foo.bar.TopLevelClass$1"
- * => "TopLevelClass$1"
- */
- public static String toStringNameForClassNamed(String className) {
- return classNamedIsMember(className) ?
- className.substring(className.lastIndexOf(NESTED_CLASS_NAME_SEPARATOR) + 1)
- :
- className.substring(className.lastIndexOf('.') + 1);
- }
-
- /**
- * Return the "toString()" name of the class.
- */
- public static String toStringNameFor(Class<?> javaClass) {
- return toStringNameForClassNamed(javaClass.getName());
- }
-
- /**
- * Return the package name of the class (e.g. "java.lang").
- * Class#getPackageName()
- */
- public static String packageNameFor(Class<?> javaClass) {
- return packageNameForClassNamed(javaClass.getName());
- }
-
- /**
- * Return the package name of the class (e.g. "java.lang").
- * Class#getPackageName()
- */
- public static String packageNameForClassNamed(String className) {
- int lastPeriod = className.lastIndexOf('.');
- if (lastPeriod == -1) {
- return ""; //$NON-NLS-1$
- }
- return className.substring(0, lastPeriod);
- }
-
- /**
- * Return the short name of the class,
- * followed by its package name (e.g. "Object (java.lang)").
- * Class#getShortNameWithPackage()
- */
- public static String shortNameWithPackage(Class<?> javaClass) {
- StringBuilder sb = new StringBuilder(200);
- sb.append(shortNameFor(javaClass));
- if ( ! javaClass.isPrimitive()) {
- sb.append(" ("); //$NON-NLS-1$
- sb.append(packageNameFor(javaClass));
- sb.append(')');
- }
- return sb.toString();
- }
-
- /**
- * Convenience method.
- * Return a zero-argument, static method for the specified class
- * and method name. If the class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method staticMethod(Class<?> javaClass, String methodName) throws NoSuchMethodException {
- return staticMethod(javaClass, methodName, ZERO_PARAMETER_TYPES);
- }
-
- /**
- * Return a static method for the specified class, method name,
- * and formal parameter types. If the class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method staticMethod(Class<?> javaClass, String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException {
- Method method = method(javaClass, methodName, parameterTypes);
- if (Modifier.isStatic(method.getModifiers())) {
- return method;
- }
- throw new NoSuchMethodException(fullyQualifiedMethodSignature(javaClass, methodName, parameterTypes));
- }
-
- /**
- * Convenience method.
- * Return a static method for the specified class, method name,
- * and formal parameter type. If the class does not directly
- * implement the method, look for it in the class's superclasses.
- * Set accessible to true, so we can access
- * private/package/protected methods.
- */
- public static Method staticMethod(Class<?> javaClass, String methodName, Class<?> parameterTypes) throws NoSuchMethodException {
- return staticMethod(javaClass, methodName, new Class[] {parameterTypes});
- }
-
- /**
- * Return whether the specified class can be "declared" in code;
- * i.e. it is either a "top-level" class or a "member" class, but it
- * is not an "array" class. This method rolls together all the checks
- * from the other methods for a bit of a performance tweak.
- * Class#isDeclarable()
- */
- public static boolean classNamedIsDeclarable(String className) {
- if (className.charAt(0) == ARRAY_INDICATOR) {
- return false; // it is an "array" class
- }
- int index = className.indexOf(NESTED_CLASS_NAME_SEPARATOR);
- if (index == -1) {
- return true; // it is a "top-level" class
- }
- do {
- // the character immediately after each dollar sign cannot be a digit
- index++;
- if (Character.isDigit(className.charAt(index))) {
- return false;
- }
- index = className.indexOf(NESTED_CLASS_NAME_SEPARATOR, index);
- } while (index != -1);
- return true;
- }
-
- /**
- * Return whether the specified class is a "top-level" class,
- * as opposed to a "member", "local", or "anonymous" class,
- * using the standard jdk naming conventions (i.e. the class
- * name does NOT contain a '$': "TopLevelClass").
- * Class#isTopLevel()
- */
- public static boolean classNamedIsTopLevel(String className) {
- if (classNamedIsArray(className)) {
- return false;
- }
- return className.indexOf(NESTED_CLASS_NAME_SEPARATOR) == -1;
- }
-
- /**
- * Return whether the specified class is a "member" class,
- * as opposed to a "top-level", "local", or "anonymous" class,
- * using the standard jdk naming conventions (i.e. the class
- * name contains at least one '$' and all the names between
- * each '$' are legal class names:
- * "TopLevelClass$MemberClass$NestedMemberClass").
- * Class#isMember()
- */
- public static boolean classNamedIsMember(String className) {
- if (classNamedIsArray(className)) {
- return false;
- }
- int index = className.indexOf(NESTED_CLASS_NAME_SEPARATOR);
- if (index == -1) {
- return false; // it is a "top-level" class
- }
- do {
- // the character immediately after each dollar sign cannot be a digit
- index++;
- if (Character.isDigit(className.charAt(index))) {
- return false;
- }
- index = className.indexOf(NESTED_CLASS_NAME_SEPARATOR, index);
- } while (index != -1);
- return true;
- }
-
- /**
- * Return whether the specified class is a "local" class,
- * as opposed to a "top-level", "member", or "anonymous" class,
- * using the standard jdk (or Eclipse) naming conventions.
- * In the jdk, the class name ends with '$nnnXXX' where the '$' is
- * followed by a series of numeric digits which are followed by the
- * local class name: "TopLevelClass$1LocalClass".
- * In Eclipse, the class name ends with '$nnn$XXX' where the '$' is
- * followed by a series of numeric digits which are separated from
- * the local class name by another '$': "TopLevelClass$1$LocalClass".
- * Class#isLocal()
- */
- public static boolean classNamedIsLocal(String className) {
- if (classNamedIsArray(className)) {
- return false;
- }
- int dollar = className.indexOf(NESTED_CLASS_NAME_SEPARATOR);
- if (dollar == -1) {
- return false;
- }
- if ( ! Character.isDigit(className.charAt(dollar + 1))) {
- return false;
- }
- int len = className.length();
- for (int i = dollar + 2; i < len; i++) {
- if (Character.isJavaIdentifierStart(className.charAt(i))) {
- return true;
- }
- }
- // all the characters past the $ are digits (anonymous)
- return false;
- }
-
- /**
- * Return whether the specified class is an "anonymous" class,
- * as opposed to a "top-level", "member", or "local" class,
- * using the standard jdk naming conventions (i.e. the class
- * name ends with '$nnn' where all the characters past the
- * last '$' are numeric digits: "TopLevelClass$1").
- * Class#isAnonymous()
- */
- public static boolean classNamedIsAnonymous(String className) {
- if (classNamedIsArray(className)) {
- return false;
- }
- int dollar = className.indexOf(NESTED_CLASS_NAME_SEPARATOR);
- if (dollar == -1) {
- return false;
- }
- int start = dollar + 1;
- for (int i = className.length(); i-- > start; ) {
- if ( ! Character.isDigit(className.charAt(i))) {
- return false;
- }
- }
- // all the characters past the $ are digits
- return true;
- }
-
- /**
- * Return the "array depth" of the specified class.
- * The depth is the number of dimensions for an array type.
- * Non-array types have a depth of zero.
- * Class#getArrayDepth()
- */
- public static int arrayDepthFor(Class<?> javaClass) {
- int depth = 0;
- while (javaClass.isArray()) {
- depth++;
- javaClass = javaClass.getComponentType();
- }
- return depth;
- }
-
- /**
- * Return the "array depth" of the specified object.
- * The depth is the number of dimensions for an array.
- * Non-arrays have a depth of zero.
- */
- public static int arrayDepthForObject(Object object) {
- return arrayDepthFor(object.getClass());
- }
-
- /**
- * Return the "array depth" of the specified class.
- * The depth is the number of dimensions for an array type.
- * Non-array types have a depth of zero.
- * @see java.lang.Class#getName()
- * Class#getArrayDepth()
- */
- public static int arrayDepthForClassNamed(String className) {
- int depth = 0;
- while (className.charAt(depth) == ARRAY_INDICATOR) {
- depth++;
- }
- return depth;
- }
-
- /**
- * Return whether the specified class is an array type.
- * @see java.lang.Class#getName()
- */
- public static boolean classNamedIsArray(String className) {
- return className.charAt(0) == ARRAY_INDICATOR;
- }
-
- /**
- * Return the "element type" of the specified class.
- * The element type is the base type held by an array type.
- * A non-array type simply returns itself.
- * Class#getElementType()
- */
- public static Class<?> elementTypeFor(Class<?> javaClass) {
- while (javaClass.isArray()) {
- javaClass = javaClass.getComponentType();
- }
- return javaClass;
- }
-
- /**
- * Return the "element type" of the specified object.
- * The element type is the base type held by an array.
- * A non-array simply returns its class.
- */
- public static Class<?> elementTypeForObject(Object object) {
- return elementTypeFor(object.getClass());
- }
-
- /**
- * Return the "element type" of the specified class.
- * The element type is the base type held by an array type.
- * Non-array types simply return themselves.
- * Class#getElementType()
- */
- public static String elementTypeNameFor(Class<?> javaClass) {
- return elementTypeFor(javaClass).getName();
- }
-
- /**
- * Return the "element type" of the specified class.
- * The element type is the base type held by an array type.
- * Non-array types simply return themselves.
- * @see java.lang.Class#getName()
- * Class#getElementType()
- */
- public static String elementTypeNameForClassNamed(String className) {
- int depth = arrayDepthForClassNamed(className);
- if (depth == 0) {
- // the name is in the form: "java.lang.Object" or "int"
- return className;
- }
- int last = className.length() - 1;
- if (className.charAt(depth) == REFERENCE_CLASS_CODE) {
- // the name is in the form: "[[[Ljava.lang.Object;"
- return className.substring(depth + 1, last); // drop the trailing ';'
- }
- // the name is in the form: "[[[I"
- return classNameForCode(className.charAt(last));
- }
-
- /**
- * Return whether the specified class is a "reference"
- * class (i.e. neither 'void' nor one of the primitive variable classes,
- * ['boolean', 'int', 'float', etc.]).
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classNamedIsReference(String className) {
- return ! classNamedIsPrimitive(className);
- }
-
- /**
- * Return whether the specified class is a primitive
- * class (i.e. 'void' or one of the primitive variable classes,
- * ['boolean', 'int', 'float', etc.]).
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classNamedIsPrimitive(String className) {
- if (classNamedIsArray(className) || (className.length() > MAX_PRIMITIVE_CLASS_NAME_LENGTH)) {
- return false; // performance tweak
- }
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass.getName().equals(className)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Return whether the specified class is a "variable" primitive
- * class (i.e. 'boolean', 'int', 'float', etc., but not 'void').
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classNamedIsVariablePrimitive(String className) {
- return classNamedIsPrimitive(className)
- && ( ! className.equals(VOID_CLASS_NAME));
- }
-
- /**
- * Return the name of the wrapper class corresponding to the specified
- * primitive class.
- */
- public static String wrapperClassName(String primitiveClassName) {
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass.getName().equals(primitiveClassName)) {
- return primitive.wrapperClass.getName();
- }
- }
- throw new IllegalArgumentException("unknown primitive: " + primitiveClassName); //$NON-NLS-1$
- }
-
- /**
- * Return the name of the wrapper class corresponding to the specified
- * primitive class.
- */
- public static Class<?> wrapperClass(Class<?> primitiveClass) {
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass == primitiveClass) {
- return primitive.wrapperClass;
- }
- }
- throw new IllegalArgumentException("unknown primitive: " + primitiveClass.getName()); //$NON-NLS-1$
- }
-
- /**
- * Return whether the specified class is a primitive wrapper
- * class (i.e. 'java.lang.Void' or one of the primitive variable wrapper classes,
- * ['java.lang.Boolean', 'java.lang.Integer', 'java.lang.Float', etc.]).
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classNamedIsPrimitiveWrapperClass(String className) {
- if (classNamedIsArray(className) || (className.length() > MAX_PRIMITIVE_WRAPPER_CLASS_NAME_LENGTH)) {
- return false; // performance tweak
- }
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.wrapperClass.getName().equals(className)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Return whether the specified class is a "variable" primitive
- * class (i.e. 'boolean', 'int', 'float', etc., but not 'void').
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classNamedIsVariablePrimitiveWrapperClass(String className) {
- return classNamedIsPrimitiveWrapperClass(className)
- && ( ! className.equals(VOID_WRAPPER_CLASS_NAME));
- }
-
- /**
- * Return whether the specified class is a primitive wrapper
- * class (i.e. 'java.lang.Void' or one of the primitive variable wrapper classes,
- * ['java.lang.Boolean', 'java.lang.Integer', 'java.lang.Float', etc.]).
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classIsPrimitiveWrapperClass(Class<?> javaClass) {
- if (javaClass.isArray() || (javaClass.getName().length() > MAX_PRIMITIVE_WRAPPER_CLASS_NAME_LENGTH)) {
- return false; // performance tweak
- }
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.wrapperClass == javaClass) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Return whether the specified class is a "variable" primitive
- * class (i.e. 'boolean', 'int', 'float', etc., but not 'void').
- * NB: void.class.isPrimitive() == true
- */
- public static boolean classIsVariablePrimitiveWrapperClass(Class<?> javaClass) {
- return classIsPrimitiveWrapperClass(javaClass)
- && (javaClass != java.lang.Void.class);
- }
-
- /**
- * Return the class name for the specified class code.
- * @see java.lang.Class#getName()
- */
- public static String classNameForCode(char classCode) {
- return classForCode(classCode).getName();
- }
-
- /**
- * Return the class name for the specified class code.
- * @see java.lang.Class#getName()
- */
- public static String classNameForCode(int classCode) {
- return classNameForCode((char) classCode);
- }
-
- /**
- * Return the class for the specified class code.
- * @see java.lang.Class#getName()
- */
- public static Class<?> classForCode(char classCode) {
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.code == classCode) {
- return primitive.javaClass;
- }
- }
- throw new IllegalArgumentException(String.valueOf(classCode));
- }
-
- /**
- * Return the class for the specified class code.
- * @see java.lang.Class#getName()
- */
- public static Class<?> classForCode(int classCode) {
- return classForCode((char) classCode);
- }
-
- /**
- * Return the class code for the specified class.
- * @see java.lang.Class#getName()
- */
- public static char codeForClass(Class<?> javaClass) {
- if (( ! javaClass.isArray()) && (javaClass.getName().length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH)) {
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass == javaClass) {
- return primitive.code;
- }
- }
- }
- throw new IllegalArgumentException(javaClass.getName());
- }
-
- /**
- * Return the class code for the specified class.
- * @see java.lang.Class#getName()
- */
- public static char codeForClassNamed(String className) {
- if (( ! classNamedIsArray(className)) && (className.length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH)) {
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass.getName().equals(className)) {
- return primitive.code;
- }
- }
- }
- throw new IllegalArgumentException(className);
- }
-
- /**
- * Return the class for the specified "type declaration".
- */
- public static Class<?> classForTypeDeclaration(String typeDeclaration) throws ClassNotFoundException {
- return classForTypeDeclaration(typeDeclaration, null);
- }
-
- /**
- * Return the class for the specified "type declaration",
- * using the specified class loader.
- */
- public static Class<?> classForTypeDeclaration(String typeDeclaration, ClassLoader classLoader) throws ClassNotFoundException {
- TypeDeclaration td = typeDeclaration(typeDeclaration);
- return classForTypeDeclaration(td.elementTypeName, td.arrayDepth, classLoader);
- }
-
- private static TypeDeclaration typeDeclaration(String typeDeclaration) {
- typeDeclaration = StringTools.removeAllWhitespace(typeDeclaration);
- int arrayDepth = arrayDepthForTypeDeclaration_(typeDeclaration);
- String elementTypeName = elementTypeNameForTypeDeclaration_(typeDeclaration, arrayDepth);
- return new TypeDeclaration(elementTypeName, arrayDepth);
- }
-
- /**
- * Return the class for the specified "type declaration".
- */
- public static Class<?> classForTypeDeclaration(String elementTypeName, int arrayDepth) throws ClassNotFoundException {
- return classForTypeDeclaration(elementTypeName, arrayDepth, null);
- }
-
- /**
- * Return the class for the specified "type declaration",
- * using the specified class loader.
- */
- // see the "Evaluation" of jdk bug 6446627 for a discussion of loading classes
- public static Class<?> classForTypeDeclaration(String elementTypeName, int arrayDepth, ClassLoader classLoader) throws ClassNotFoundException {
- // primitives cannot be loaded via Class#forName(),
- // so check for a primitive class name first
- Primitive pcc = null;
- if (elementTypeName.length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH) { // performance tweak
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass.getName().equals(elementTypeName)) {
- pcc = primitive;
- break;
- }
- }
- }
-
- // non-array
- if (arrayDepth == 0) {
- return (pcc == null) ? Class.forName(elementTypeName, false, classLoader) : pcc.javaClass;
- }
-
- // array
- StringBuilder sb = new StringBuilder(100);
- for (int i = arrayDepth; i-- > 0; ) {
- sb.append(ARRAY_INDICATOR);
- }
- if (pcc == null) {
- sb.append(REFERENCE_CLASS_CODE);
- sb.append(elementTypeName);
- sb.append(REFERENCE_CLASS_NAME_DELIMITER);
- } else {
- sb.append(pcc.code);
- }
- return Class.forName(sb.toString(), false, classLoader);
- }
-
- /**
- * Return the class name for the specified "type declaration"; e.g.
- * "int[]" -> "[I"
- * @see java.lang.Class#getName()
- */
- public static String classNameForTypeDeclaration(String typeDeclaration) {
- TypeDeclaration td = typeDeclaration(typeDeclaration);
- return classNameForTypeDeclaration(td.elementTypeName, td.arrayDepth);
- }
-
- /**
- * Return the array depth for the specified "type declaration"; e.g.
- * "int[]" -> 1
- * "java.lang.String[][][]" -> 3
- */
- public static int arrayDepthForTypeDeclaration(String typeDeclaration) {
- return arrayDepthForTypeDeclaration_(StringTools.removeAllWhitespace(typeDeclaration));
- }
-
- /*
- * Assume no whitespace in the type declaration.
- */
- private static int arrayDepthForTypeDeclaration_(String typeDeclaration) {
- int last = typeDeclaration.length() - 1;
- int depth = 0;
- int close = last;
- while (typeDeclaration.charAt(close) == TYPE_DECLARATION_ARRAY_CLOSE) {
- if (typeDeclaration.charAt(close - 1) == TYPE_DECLARATION_ARRAY_OPEN) {
- depth++;
- } else {
- throw new IllegalArgumentException("invalid type declaration: " + typeDeclaration); //$NON-NLS-1$
- }
- close = last - (depth * 2);
- }
- return depth;
- }
-
- /**
- * Return the element type name for the specified "type declaration"; e.g.
- * "int[]" -> "int"
- * "java.lang.String[][][]" -> "java.lang.String"
- */
- public static String elementTypeNameForTypeDeclaration(String typeDeclaration) {
- typeDeclaration = StringTools.removeAllWhitespace(typeDeclaration);
- return elementTypeNameForTypeDeclaration_(typeDeclaration, arrayDepthForTypeDeclaration_(typeDeclaration));
- }
-
- /**
- * Return the element type name for the specified "type declaration"; e.g.
- * "int[]" -> "int"
- * "java.lang.String[][][]" -> "java.lang.String"
- */
- public static String elementTypeNameForTypeDeclaration(String typeDeclaration, int arrayDepth) {
- return elementTypeNameForTypeDeclaration_(StringTools.removeAllWhitespace(typeDeclaration), arrayDepth);
- }
-
- /*
- * Assume no whitespace in the type declaration.
- */
- public static String elementTypeNameForTypeDeclaration_(String typeDeclaration, int arrayDepth) {
- return typeDeclaration.substring(0, typeDeclaration.length() - (arrayDepth * 2));
- }
-
- /**
- * Return the class name for the specified "type declaration".
- * @see java.lang.Class#getName()
- */
- public static String classNameForTypeDeclaration(String elementTypeName, int arrayDepth) {
- // non-array
- if (arrayDepth == 0) {
- return elementTypeName;
- }
-
- if (elementTypeName.equals(VOID_CLASS_NAME)) {
- throw new IllegalArgumentException('\'' + VOID_CLASS_NAME + "' must have an array depth of zero: " + arrayDepth + '.'); //$NON-NLS-1$
- }
- // array
- StringBuilder sb = new StringBuilder(100);
- for (int i = arrayDepth; i-- > 0; ) {
- sb.append(ARRAY_INDICATOR);
- }
-
- // look for a primitive first
- Primitive pcc = null;
- if (elementTypeName.length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH) { // performance tweak
- for (Primitive primitive : PRIMITIVES) {
- if (primitive.javaClass.getName().equals(elementTypeName)) {
- pcc = primitive;
- break;
- }
- }
- }
-
- if (pcc == null) {
- sb.append(REFERENCE_CLASS_CODE);
- sb.append(elementTypeName);
- sb.append(REFERENCE_CLASS_NAME_DELIMITER);
- } else {
- sb.append(pcc.code);
- }
-
- return sb.toString();
- }
-
-
- // ********** primitive constants **********
-
- private static int calculateMaxPrimitiveClassNameLength() {
- int max = -1;
- for (Primitive primitive : PRIMITIVES) {
- int len = primitive.javaClass.getName().length();
- if (len > max) {
- max = len;
- }
- }
- return max;
- }
-
- private static int calculateMaxPrimitiveWrapperClassNameLength() {
- int max = -1;
- for (Primitive primitive : PRIMITIVES) {
- int len = primitive.wrapperClass.getName().length();
- if (len > max) {
- max = len;
- }
- }
- return max;
- }
-
- /**
- * NB: void.class.isPrimitive() == true
- */
- private static Iterable<Primitive> buildPrimitives() {
- Primitive[] array = new Primitive[9];
- array[0] = new Primitive(BYTE_CODE, java.lang.Byte.class);
- array[1] = new Primitive(CHAR_CODE, java.lang.Character.class);
- array[2] = new Primitive(DOUBLE_CODE, java.lang.Double.class);
- array[3] = new Primitive(FLOAT_CODE, java.lang.Float.class);
- array[4] = new Primitive(INT_CODE, java.lang.Integer.class);
- array[5] = new Primitive(LONG_CODE, java.lang.Long.class);
- array[6] = new Primitive(SHORT_CODE, java.lang.Short.class);
- array[7] = new Primitive(BOOLEAN_CODE, java.lang.Boolean.class);
- array[8] = new Primitive(VOID_CODE, java.lang.Void.class);
- return new ArrayIterable<Primitive>(array);
- }
-
-
- // ********** member classes **********
-
- private static class Primitive {
- final char code;
- final Class<?> javaClass;
- final Class<?> wrapperClass;
- private static final String WRAPPER_CLASS_TYPE_FIELD_NAME = "TYPE"; //$NON-NLS-1$
- // e.g. java.lang.Boolean.TYPE => boolean.class
- Primitive(char code, Class<?> wrapperClass) {
- this.code = code;
- this.wrapperClass = wrapperClass;
- this.javaClass = (Class<?>) staticFieldValue(wrapperClass, WRAPPER_CLASS_TYPE_FIELD_NAME);
- }
- }
-
- private static class TypeDeclaration {
- final String elementTypeName;
- final int arrayDepth;
- TypeDeclaration(String elementTypeName, int arrayDepth) {
- this.elementTypeName = elementTypeName;
- this.arrayDepth = arrayDepth;
- }
- }
-
-
- // ********** suppressed constructor **********
-
- /**
- * Suppress default constructor, ensuring non-instantiability.
- */
- private ClassTools() {
- super();
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Classpath.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Classpath.java
index c26e00c303..3d1ae80a12 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Classpath.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Classpath.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -25,6 +25,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.jpt.utility.Filter;
+import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
@@ -32,7 +33,11 @@ import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
/**
- * TODO
+ * <code>Classpath</code> models a Java classpath, which consists of a list of
+ * {@link Entry}s, each of which contain Java classes. The classpath can return
+ * the names of classes found in it etc. There are a number of static
+ * convenience methods that can be use to construct <code>Classpath</code>s
+ * corresponding to the Java classpath etc.
*/
public class Classpath
implements Serializable
@@ -48,7 +53,7 @@ public class Classpath
// ***** factory methods for "standard" classpaths *****
/**
- * Return the Java "boot" classpath. This includes rt.jar.
+ * Return the Java "boot" classpath. This includes <code>rt.jar</code>.
*/
public static Classpath bootClasspath() {
return new Classpath(System.getProperty("sun.boot.class.path")); //$NON-NLS-1$
@@ -102,9 +107,10 @@ public class Classpath
/**
* Convert a relative file name to a class name; this will work for
* any file that has a single extension beyond the base
- * class name.
- * e.g. "java/lang/String.class" is converted to "java.lang.String"
- * e.g. "java/lang/String.java" is converted to "java.lang.String"
+ * class name:<ul>
+ * <li><code>"java/lang/String.class"</code> is converted to <code>"java.lang.String"</code>
+ * <li><code>"java/lang/String.java"</code> is converted to <code>"java.lang.String"</code>
+ * </ul>
*/
public static String convertToClassName(String classFileName) {
String className = FileTools.stripExtension(classFileName);
@@ -119,7 +125,8 @@ public class Classpath
/**
* Convert a file to a class name;
- * e.g. File(java/lang/String.class) is converted to "java.lang.String"
+ * e.g. <code>File(java/lang/String.class)</code> is converted to
+ * <code>"java.lang.String"</code>.
*/
public static String convertToClassName(File classFile) {
return convertToClassName(classFile.getPath());
@@ -127,7 +134,8 @@ public class Classpath
/**
* Convert a relative file name to a class;
- * e.g. "java/lang/String.class" is converted to java.lang.String.class
+ * e.g. <code>"java/lang/String.class"</code> is converted to
+ * <code>java.lang.String.class</code>.
*/
public static Class<?> convertToClass(String classFileName) throws ClassNotFoundException {
return Class.forName(convertToClassName(classFileName));
@@ -135,7 +143,8 @@ public class Classpath
/**
* Convert a relative file to a class;
- * e.g. File(java/lang/String.class) is converted to java.lang.String.class
+ * e.g. <code>File(java/lang/String.class)</code> is converted to
+ * <code>java.lang.String.class</code>.
*/
public static Class<?> convertToClass(File classFile) throws ClassNotFoundException {
return convertToClass(classFile.getPath());
@@ -146,7 +155,8 @@ public class Classpath
/**
* Convert a class name to an archive entry name base;
- * e.g. "java.lang.String" is converted to "java/lang/String"
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>"java/lang/String"</code>.
*/
public static String convertToArchiveEntryNameBase(String className) {
return className.replace('.', '/');
@@ -154,7 +164,8 @@ public class Classpath
/**
* Convert a class to an archive entry name base;
- * e.g. java.lang.String.class is converted to "java/lang/String"
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>"java/lang/String"</code>.
*/
public static String convertToArchiveEntryNameBase(Class<?> javaClass) {
return convertToArchiveEntryNameBase(javaClass.getName());
@@ -162,7 +173,8 @@ public class Classpath
/**
* Convert a class name to an archive class file entry name;
- * e.g. "java.lang.String" is converted to "java/lang/String.class"
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>"java/lang/String.class"</code>.
*/
public static String convertToArchiveClassFileEntryName(String className) {
return convertToArchiveEntryNameBase(className) + ".class"; //$NON-NLS-1$
@@ -170,7 +182,8 @@ public class Classpath
/**
* Convert a class to an archive class file entry name;
- * e.g. java.lang.String.class is converted to "java/lang/String.class"
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>"java/lang/String.class"</code>.
*/
public static String convertToArchiveClassFileEntryName(Class<?> javaClass) {
return convertToArchiveClassFileEntryName(javaClass.getName());
@@ -181,8 +194,9 @@ public class Classpath
/**
* Convert a class name to a file name base for the current O/S;
- * e.g. "java.lang.String" is converted to "java/lang/String" on Unix
- * and "java\\lang\\String" on Windows
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>"java/lang/String"</code> on Unix and
+ * <code>"java\\lang\\String"</code> on Windows.
*/
public static String convertToFileNameBase(String className) {
return className.replace('.', File.separatorChar);
@@ -190,8 +204,9 @@ public class Classpath
/**
* Convert a class to a file name base for the current O/S;
- * e.g. java.lang.String.class is converted to "java/lang/String" on Unix
- * and "java\\lang\\String" on Windows
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>"java/lang/String"</code> on Unix and
+ * <code>"java\\lang\\String"</code> on Windows.
*/
public static String convertToFileNameBase(Class<?> javaClass) {
return convertToFileNameBase(javaClass.getName());
@@ -199,8 +214,9 @@ public class Classpath
/**
* Convert a class name to a class file name for the current O/S;
- * e.g. "java.lang.String" is converted to "java/lang/String.class" on Unix
- * and "java\\lang\\String.class" on Windows
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>"java/lang/String.class"</code> on Unix and
+ * <code>"java\\lang\\String.class"</code> on Windows.
*/
public static String convertToClassFileName(String className) {
return convertToFileNameBase(className) + ".class"; //$NON-NLS-1$
@@ -208,8 +224,9 @@ public class Classpath
/**
* Convert a class to a class file name for the current O/S;
- * e.g. java.lang.String.class is converted to "java/lang/String.class" on Unix
- * and "java\\lang\\String.class" on Windows
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>"java/lang/String.class"</code> on Unix and
+ * <code>"java\\lang\\String.class"</code> on Windows.
*/
public static String convertToClassFileName(Class<?> javaClass) {
return convertToClassFileName(javaClass.getName());
@@ -217,7 +234,8 @@ public class Classpath
/**
* Convert a class name to a class file for the current O/S;
- * e.g. "java.lang.String" is converted to File(java/lang/String.class)
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>File(java/lang/String.class)</code>.
*/
public static File convertToClassFile(String className) {
return new File(convertToClassFileName(className));
@@ -225,7 +243,8 @@ public class Classpath
/**
* Convert a class to a class file for the current O/S;
- * e.g. java.lang.String.class is converted to File(java/lang/String.class)
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>File(java/lang/String.class)</code>.
*/
public static File convertToClassFile(Class<?> javaClass) {
return convertToClassFile(javaClass.getName());
@@ -233,8 +252,9 @@ public class Classpath
/**
* Convert a class name to a java file name for the current O/S;
- * e.g. "java.lang.String" is converted to "java/lang/String.java" on Unix
- * and "java\\lang\\String.java" on Windows
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>"java/lang/String.java"</code> on Unixl and
+ * <code>"java\\lang\\String.java"</code> on Windows.
*/
public static String convertToJavaFileName(String className) {
return convertToFileNameBase(className) + ".java"; //$NON-NLS-1$
@@ -242,8 +262,9 @@ public class Classpath
/**
* Convert a class to a java file name for the current O/S;
- * e.g. java.lang.String.class is converted to "java/lang/String.java" on Unix
- * and "java\\lang\\String.java" on Windows
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>"java/lang/String.java"</code> on Unix and
+ * <code>"java\\lang\\String.java"</code> on Windows.
*/
public static String convertToJavaFileName(Class<?> javaClass) {
return convertToJavaFileName(javaClass.getName());
@@ -251,7 +272,8 @@ public class Classpath
/**
* Convert a class name to a java file for the current O/S;
- * e.g. "java.lang.String" is converted to File(java/lang/String.java)
+ * e.g. <code>"java.lang.String"</code> is converted to
+ * <code>File(java/lang/String.java)</code>.
*/
public static File convertToJavaFile(String className) {
return new File(convertToJavaFileName(className));
@@ -259,7 +281,8 @@ public class Classpath
/**
* Convert a class to a java file for the current O/S;
- * e.g. java.lang.String.class is converted to File(java/lang/String.java)
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>File(java/lang/String.java)</code>.
*/
public static File convertToJavaFile(Class<?> javaClass) {
return convertToJavaFile(javaClass.getName());
@@ -270,7 +293,8 @@ public class Classpath
/**
* Convert a class to a resource name;
- * e.g. java.lang.String.class is converted to "/java/lang/String.class".
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>"/java/lang/String.class"</code>.
*/
public static String convertToResourceName(Class<?> javaClass) {
return '/' + convertToArchiveClassFileEntryName(javaClass);
@@ -278,8 +302,8 @@ public class Classpath
/**
* Convert a class to a resource;
- * e.g. java.lang.String.class is converted to
- * URL(jar:file:/C:/jdk/1.4.2_04/jre/lib/rt.jar!/java/lang/String.class).
+ * e.g. <code>java.lang.String.class</code> is converted to
+ * <code>URL(jar:file:/C:/jdk/1.4.2_04/jre/lib/rt.jar!/java/lang/String.class)</code>.
*/
public static URL convertToResource(Class<?> javaClass) {
return javaClass.getResource(convertToResourceName(javaClass));
@@ -290,7 +314,7 @@ public class Classpath
/**
* Return whether the specified file is an archive file;
- * i.e. its name ends with ".zip" or ".jar"
+ * i.e. its name ends with <code>".zip"</code> or <code>".jar"</code>.
*/
public static boolean fileNameIsArchive(String fileName) {
String ext = FileTools.extension(fileName).toLowerCase();
@@ -299,7 +323,7 @@ public class Classpath
/**
* Return whether the specified file is an archive file;
- * i.e. its name ends with ".zip" or ".jar"
+ * i.e. its name ends with <code>".zip"</code> or <code>".jar"</code>.
*/
public static boolean fileIsArchive(File file) {
return fileNameIsArchive(file.getName());
@@ -308,7 +332,7 @@ public class Classpath
/**
* Return what should be the fully-qualified file name
* for the JRE runtime JAR;
- * e.g. "C:\jdk1.4.2_04\jre\lib\rt.jar".
+ * e.g. <code>"C:\jdk1.4.2_04\jre\lib\rt.jar"</code>.
*/
public static String rtJarName() {
return locationFor(java.lang.Object.class);
@@ -401,7 +425,7 @@ public class Classpath
/**
* Construct a classpath with the specified entries.
*/
- public Classpath(String[] fileNames) {
+ public Classpath(String... fileNames) {
this(buildEntries(fileNames));
}
@@ -409,10 +433,11 @@ public class Classpath
* Skip empty file names because they will end up expanding to the current
* working directory, which is not what we want. Empty file names actually
* occur with some frequency; such as when the classpath has been built up
- * dynamically with too many separators. For example:
+ * dynamically with too many separators. For example:<pre>
* "C:\dev\foo.jar;;C:\dev\bar.jar"
- * will be parsed into three file names:
+ * </pre>will be parsed into three file names:<pre>
* { "C:\dev\foo.jar", "", "C:\dev\bar.jar" }
+ * </pre>
*/
private static Entry[] buildEntries(String[] fileNames) {
List<Entry> entries = new ArrayList<Entry>();
@@ -434,21 +459,22 @@ public class Classpath
/**
* Construct a classpath with the specified entries.
*/
- public Classpath(List<String> fileNames) {
- this(fileNames.toArray(new String[fileNames.size()]));
+ public Classpath(Iterable<String> fileNames) {
+ this(ArrayTools.array(fileNames, EMPTY_STRING_ARRAY));
}
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
/**
* Consolidate the specified classpaths into a single classpath.
*/
- public Classpath(Classpath[] classpaths) {
+ public Classpath(Classpath... classpaths) {
this(consolidateEntries(classpaths));
}
private static Entry[] consolidateEntries(Classpath[] classpaths) {
List<Entry> entries = new ArrayList<Entry>();
for (Classpath classpath : classpaths) {
- CollectionTools.addAll(entries, classpath.entries());
+ CollectionTools.addAll(entries, classpath.getEntries());
}
return entries.toArray(new Entry[entries.size()]);
}
@@ -459,26 +485,25 @@ public class Classpath
/**
* Return the classpath's entries.
*/
- public Entry[] entries() {
- return this.entries;
+ public Iterable<Entry> getEntries() {
+ return new ArrayIterable<Entry>(this.entries);
}
/**
* Return the classpath's path.
*/
- public String path() {
- Entry[] localEntries = this.entries;
- int max = localEntries.length - 1;
+ public String getPath() {
+ int max = this.entries.length - 1;
if (max == -1) {
return ""; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2000);
// stop one short of the end of the array
for (int i = 0; i < max; i++) {
- sb.append(localEntries[i].fileName());
+ sb.append(this.entries[i].getFileName());
sb.append(File.pathSeparatorChar);
}
- sb.append(localEntries[max].fileName());
+ sb.append(this.entries[max].getFileName());
return sb.toString();
}
@@ -486,12 +511,11 @@ public class Classpath
* Search the classpath for the specified (unqualified) file
* and return its entry. Return null if an entry is not found.
* For example, you could use this method to find the entry
- * for "rt.jar" or "toplink.jar".
+ * for <code>"rt.jar"</code> or <code>"toplink.jar"</code>.
*/
- public Entry entryForFileNamed(String shortFileName) {
- Entry[] localEntries = this.entries;
- for (Entry entry : localEntries) {
- if (entry.file().getName().equals(shortFileName)) {
+ public Entry getEntryForFileNamed(String shortFileName) {
+ for (Entry entry : this.entries) {
+ if (entry.getFile().getName().equals(shortFileName)) {
return entry;
}
}
@@ -503,11 +527,10 @@ public class Classpath
* that contains the specified class.
* Return null if an entry is not found.
*/
- public Entry entryForClassNamed(String className) {
+ public Entry getEntryForClassNamed(String className) {
String relativeClassFileName = convertToClassFileName(className);
String archiveEntryName = convertToArchiveClassFileEntryName(className);
- Entry[] localEntries = this.entries;
- for (Entry entry : localEntries) {
+ for (Entry entry : this.entries) {
if (entry.contains(relativeClassFileName, archiveEntryName)) {
return entry;
}
@@ -518,19 +541,21 @@ public class Classpath
/**
* Return the names of all the classes discovered on the classpath,
* with duplicates removed.
+ * @see #classNames()
*/
- public String[] classNames() {
- return this.classNames(Filter.Null.<String>instance());
+ public Iterable<String> getClassNames() {
+ return this.getClassNames(Filter.Null.<String>instance());
}
/**
* Return the names of all the classes discovered on the classpath
* and accepted by the specified filter, with duplicates removed.
+ * @see #classNames(Filter)
*/
- public String[] classNames(Filter<String> filter) {
+ public Iterable<String> getClassNames(Filter<String> filter) {
Collection<String> classNames = new HashSet<String>(10000);
this.addClassNamesTo(classNames, filter);
- return classNames.toArray(new String[classNames.size()]);
+ return classNames;
}
/**
@@ -546,34 +571,33 @@ public class Classpath
* and accepted by the specified filter to the specified collection.
*/
public void addClassNamesTo(Collection<String> classNames, Filter<String> filter) {
- Entry[] localEntries = this.entries;
- for (Entry entry : localEntries) {
+ for (Entry entry : this.entries) {
entry.addClassNamesTo(classNames, filter);
}
}
/**
* Return the names of all the classes discovered on the classpath.
- * Just a bit more performant than #classNames().
+ * Just a bit more performant than {@link #getClassNames()}.
*/
- public Iterator<String> classNamesStream() {
- return this.classNamesStream(Filter.Null.<String>instance());
+ public Iterator<String> classNames() {
+ return this.classNames(Filter.Null.<String>instance());
}
/**
* Return the names of all the classes discovered on the classpath
* that are accepted by the specified filter.
- * Just a bit more performant than #classNames(Filter).
+ * Just a bit more performant than {@link #getClassNames(Filter)}.
*/
- public Iterator<String> classNamesStream(Filter<String> filter) {
- return new CompositeIterator<String>(this.entryClassNamesStreams(filter));
+ public Iterator<String> classNames(Filter<String> filter) {
+ return new CompositeIterator<String>(this.entryClassNamesIterators(filter));
}
- private Iterator<Iterator<String>> entryClassNamesStreams(final Filter<String> filter) {
+ private Iterator<Iterator<String>> entryClassNamesIterators(final Filter<String> filter) {
return new TransformationIterator<Entry, Iterator<String>>(new ArrayIterator<Entry>(this.entries)) {
@Override
protected Iterator<String> transform(Entry entry) {
- return entry.classNamesStream(filter);
+ return entry.classNames(filter);
}
};
}
@@ -588,28 +612,30 @@ public class Classpath
/**
* Convert the classpath to an array of URLs
- * (that can be used to instantiate a URLClassLoader).
+ * (that can be used to instantiate a {@link java.net.URLClassLoader}).
*/
- public URL[] urls() {
- Entry[] localEntries = this.entries;
- int len = localEntries.length;
+ public Iterable<URL> getURLs() {
+ int len = this.entries.length;
URL[] urls = new URL[len];
for (int i = 0; i < len; i++) {
- urls[i] = localEntries[i].url();
+ urls[i] = this.entries[i].getURL();
}
- return urls;
+ return new ArrayIterable<URL>(urls);
}
@Override
public String toString() {
- return StringTools.buildToStringFor(this, this.path());
+ return StringTools.buildToStringFor(this, this.getPath());
}
// ********** inner class **********
/**
- * TODO
+ * <code>Entry</code> models a Java classpath entry, which can be either a
+ * directory containing <code>.class</code> files or a JAR file (or,
+ * similarly, a <code>.zip</code> file). The entry can return the names of
+ * classes found in it etc.
*/
public static class Entry implements Serializable {
private final String fileName;
@@ -628,19 +654,19 @@ public class Classpath
this.canonicalFile = FileTools.canonicalFile(this.file);
}
- public String fileName() {
+ public String getFileName() {
return this.fileName;
}
- public File file() {
+ public File getFile() {
return this.file;
}
- public File canonicalFile() {
+ public File getCanonicalFile() {
return this.canonicalFile;
}
- public String canonicalFileName() {
+ public String getCanonicalFileName() {
return this.canonicalFile.getAbsolutePath();
}
@@ -660,7 +686,7 @@ public class Classpath
/**
* Return the entry's "canonical" URL.
*/
- public URL url() {
+ public URL getURL() {
try {
return this.canonicalFile.toURI().toURL();
} catch (IOException ex) {
@@ -722,19 +748,21 @@ public class Classpath
/**
* Return the names of all the classes discovered in the entry.
+ * @see #classNames()
*/
- public String[] classNames() {
- return this.classNames(Filter.Null.<String>instance());
+ public Iterable<String> getClassNames() {
+ return this.getClassNames(Filter.Null.<String>instance());
}
/**
* Return the names of all the classes discovered in the entry
* and accepted by the specified filter.
+ * @see #classNames(Filter)
*/
- public String[] classNames(Filter<String> filter) {
+ public Iterable<String> getClassNames(Filter<String> filter) {
Collection<String> classNames = new ArrayList<String>(2000);
this.addClassNamesTo(classNames, filter);
- return classNames.toArray(new String[classNames.size()]);
+ return classNames;
}
/**
@@ -779,7 +807,7 @@ public class Classpath
* under the entry's directory.
*/
private Iterator<File> classFilesForDirectory() {
- return new FilteringIterator<File, File>(FileTools.filesInTree(this.canonicalFile)) {
+ return new FilteringIterator<File>(FileTools.filesInTree(this.canonicalFile)) {
@Override
protected boolean accept(File next) {
return Entry.this.fileNameMightBeForClassFile(next.getName());
@@ -818,7 +846,7 @@ public class Classpath
/**
* Return whether the specified file might be a Java class file.
- * The file name must at least end with ".class" and contain no spaces.
+ * The file name must at least end with <code>".class"</code> and contain no spaces.
* (Neither class names nor package names may contain spaces.)
* Whether it actually is a class file will need to be determined by
* a class loader.
@@ -830,18 +858,18 @@ public class Classpath
/**
* Return the names of all the classes discovered on the classpath.
- * Just a bit more performant than #classNames().
+ * Just a bit more performant than {@link #getClassNames()}.
*/
- public Iterator<String> classNamesStream() {
- return this.classNamesStream(Filter.Null.<String>instance());
+ public Iterator<String> classNames() {
+ return this.classNames(Filter.Null.<String>instance());
}
/**
* Return the names of all the classes discovered on the classpath
* that are accepted by the specified filter.
- * Just a bit more performant than #classNames(Filter).
+ * Just a bit more performant than {@link #getClassNames(Filter)}.
*/
- public Iterator<String> classNamesStream(Filter<String> filter) {
+ public Iterator<String> classNames(Filter<String> filter) {
if (this.canonicalFile.exists()) {
if (this.canonicalFile.isDirectory()) {
return this.classNamesForDirectory(filter);
@@ -859,7 +887,7 @@ public class Classpath
* the specified filter.
*/
private Iterator<String> classNamesForDirectory(Filter<String> filter) {
- return new FilteringIterator<String, String>(this.classNamesForDirectory(), filter);
+ return new FilteringIterator<String>(this.classNamesForDirectory(), filter);
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CollectionTools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CollectionTools.java
index 40fc324875..84042633b6 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CollectionTools.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CollectionTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -28,7 +28,7 @@ import java.util.Vector;
import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator;
-import org.eclipse.jpt.utility.internal.iterators.GenericIteratorWrapper;
+import org.eclipse.jpt.utility.internal.iterators.SuperIteratorWrapper;
import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator;
import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator;
@@ -1798,7 +1798,7 @@ public final class CollectionTools {
if (iterator == null) {
throw new NullPointerException();
}
- this.iterator = new GenericIteratorWrapper<E>(iterator);
+ this.iterator = new SuperIteratorWrapper<E>(iterator);
}
public Iterator<E> iterator() {
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CompositeCommand.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CompositeCommand.java
index ff603eb0b7..cfea4d33a7 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CompositeCommand.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/CompositeCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -10,6 +10,7 @@
package org.eclipse.jpt.utility.internal;
import org.eclipse.jpt.utility.Command;
+import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
/**
* <code>CompositeCommand</code> provides support for treating a collection of
@@ -20,6 +21,10 @@ public class CompositeCommand
{
private final Iterable<Command> commands;
+ public CompositeCommand(Command... commands) {
+ this(new ArrayIterable<Command>(commands));
+ }
+
public CompositeCommand(Iterable<Command> commands) {
super();
this.commands = commands;
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/FileTools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/FileTools.java
index 82bb030168..788bc0aff8 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/FileTools.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/FileTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -191,7 +191,7 @@ public final class FileTools {
}
private static Iterator<File> filesIn(File[] files) {
- return new FilteringIterator<File, File>(new ArrayIterator<File>(files)) {
+ return new FilteringIterator<File>(new ArrayIterator<File>(files)) {
@Override
protected boolean accept(File next) {
return next.isFile();
@@ -218,7 +218,7 @@ public final class FileTools {
}
private static Iterator<File> directoriesIn(File[] files) {
- return new FilteringIterator<File, File>(new ArrayIterator<File>(files)) {
+ return new FilteringIterator<File>(new ArrayIterator<File>(files)) {
@Override
protected boolean accept(File next) {
return next.isDirectory();
@@ -607,10 +607,8 @@ public final class FileTools {
* a number of file names (e.g. CON, AUX, PRN).
*/
public static boolean fileNameIsReserved(String fileName) {
- if (executingOnWindows()) {
- return ArrayTools.contains(WINDOWS_RESERVED_FILE_NAMES, fileName.toLowerCase());
- }
- return false; // Unix does not have any "reserved" file names (I think...)
+ // Unix/Linux does not have any "reserved" file names (I think...)
+ return Tools.osIsWindows() && ArrayTools.contains(WINDOWS_RESERVED_FILE_NAMES, fileName.toLowerCase());
}
/**
@@ -809,24 +807,12 @@ public final class FileTools {
// ********** miscellaneous **********
- private static boolean executingOnWindows() {
- return executingOn("Windows"); //$NON-NLS-1$
- }
-
-// private static boolean executingOnLinux() {
-// return executingOn("Linux");
-// }
-//
- private static boolean executingOn(String osName) {
- return System.getProperty("os.name").indexOf(osName) != -1; //$NON-NLS-1$
- }
-
/**
* Return only the files that fit the filter.
* File#files(FileFilter fileFilter)
*/
public static Iterator<File> filter(Iterator<File> files, final FileFilter fileFilter) {
- return new FilteringIterator<File, File>(files) {
+ return new FilteringIterator<File>(files) {
@Override
protected boolean accept(File next) {
return fileFilter.accept(next);
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/HashBag.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/HashBag.java
index 3bdf8b0b6d..75674135ae 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/HashBag.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/HashBag.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -66,6 +66,7 @@ import java.util.NoSuchElementException;
* @see Bag
* @see SynchronizedBag
* @see Collections#synchronizedCollection(Collection)
+ * @see IdentityHashBag
*/
public class HashBag<E>
extends AbstractCollection<E>
@@ -77,12 +78,12 @@ public class HashBag<E>
/** The total number of entries in the bag. */
transient int size = 0;
- /** The number of unique entries in the bag. */
+ /** The number of UNIQUE entries in the bag. */
transient int uniqueCount = 0;
/**
* The hash table is rehashed when its size exceeds this threshold. (The
- * value of this field is (int)(capacity * loadFactor).)
+ * value of this field is <code>(int) (capacity * loadFactor)</code>.)
*
* @serial
*/
@@ -113,7 +114,7 @@ public class HashBag<E>
/**
* The maximum capacity, used if a higher value is implicitly specified
* by either of the constructors with arguments.
- * MUST be a power of two <= 1<<30.
+ * MUST be a power of two <= (1 << 30).
*/
private static final int MAXIMUM_CAPACITY = 1 << 30;
@@ -198,15 +199,15 @@ public class HashBag<E>
* Return a hash for the specified object.
*/
private int hash(Object o) {
- return (o == null) ? 0 : this.rehash(o.hashCode());
+ return (o == null) ? 0 : this.tweakHash(o.hashCode());
}
/**
* Tweak the specified hash, to defend against poor implementations
- * of <code>#hashCode()</code>.
+ * of {@link Object#hashCode()}.
*/
- private int rehash(int h) {
- h ^= (h >>>20) ^ (h >>> 12);
+ private int tweakHash(int h) {
+ h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
@@ -309,7 +310,7 @@ public class HashBag<E>
}
/**
- * Rehashes the contents of the bag into a new hash table
+ * Rehash the contents of the bag into a new hash table
* with a larger capacity. This method is called when the
* number of different elements in the bag exceeds its
* capacity and load factor.
@@ -318,11 +319,13 @@ public class HashBag<E>
Entry<E>[] oldTable = this.table;
int oldCapacity = oldTable.length;
- int newCapacity = oldCapacity * 2 + 1;
- Entry<E>[] newTable = this.buildTable(newCapacity);
+ if (oldCapacity == MAXIMUM_CAPACITY) {
+ this.threshold = Integer.MAX_VALUE;
+ return;
+ }
- this.threshold = (int) (newCapacity * this.loadFactor);
- this.table = newTable;
+ int newCapacity = 2 * oldCapacity;
+ Entry<E>[] newTable = this.buildTable(newCapacity);
for (int i = oldCapacity; i-- > 0; ) {
for (Entry<E> old = oldTable[i]; old != null; ) {
@@ -334,6 +337,9 @@ public class HashBag<E>
newTable[index] = e;
}
}
+
+ this.table = newTable;
+ this.threshold = (int) (newCapacity * this.loadFactor);
}
// minimize scope of suppressed warnings
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/IdentityHashBag.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/IdentityHashBag.java
index 82a65a9e88..4410e33fa4 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/IdentityHashBag.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/IdentityHashBag.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -84,6 +84,7 @@ import java.util.NoSuchElementException;
* @see Bag
* @see SynchronizedBag
* @see Collections#synchronizedCollection(Collection)
+ * @see HashBag
*/
public class IdentityHashBag<E>
extends AbstractCollection<E>
@@ -95,12 +96,12 @@ public class IdentityHashBag<E>
/** The total number of entries in the bag. */
transient int size = 0;
- /** The number of unique entries in the bag. */
+ /** The number of UNIQUE entries in the bag. */
transient int uniqueCount = 0;
/**
* The hash table is rehashed when its size exceeds this threshold. (The
- * value of this field is (int)(capacity * loadFactor).)
+ * value of this field is <code>(int) (capacity * loadFactor)</code>.)
*
* @serial
*/
@@ -131,8 +132,8 @@ public class IdentityHashBag<E>
/**
* The maximum capacity, used if a higher value is implicitly specified
* by either of the constructors with arguments.
- * MUST be a power of two <= 1<<30.
- */
+ * MUST be a power of two <= (1 << 30).
+ */
private static final int MAXIMUM_CAPACITY = 1 << 30;
/**
@@ -223,15 +224,16 @@ public class IdentityHashBag<E>
* Return a hash for the specified object.
*/
private int hash(Object o) {
- return (o == null) ? 0 : this.rehash(System.identityHashCode(o));
+ return (o == null) ? 0 : this.tweakHash(System.identityHashCode(o));
}
/**
* Tweak the specified hash.
*/
- private int rehash(int h) {
- h ^= (h >>>20) ^ (h >>> 12);
- return h ^ (h >>> 7) ^ (h >>> 4);
+ private int tweakHash(int h) {
+ return h;
+// h ^= (h >>> 20) ^ (h >>> 12);
+// return h ^ (h >>> 7) ^ (h >>> 4);
}
/**
@@ -330,7 +332,7 @@ public class IdentityHashBag<E>
}
/**
- * Rehashes the contents of the bag into a new hash table
+ * Rehash the contents of the bag into a new hash table
* with a larger capacity. This method is called when the
* number of different elements in the bag exceeds its
* capacity and load factor.
@@ -339,11 +341,13 @@ public class IdentityHashBag<E>
Entry<E>[] oldTable = this.table;
int oldCapacity = oldTable.length;
- int newCapacity = oldCapacity * 2 + 1;
- Entry<E>[] newTable = this.buildTable(newCapacity);
+ if (oldCapacity == MAXIMUM_CAPACITY) {
+ this.threshold = Integer.MAX_VALUE;
+ return;
+ }
- this.threshold = (int) (newCapacity * this.loadFactor);
- this.table = newTable;
+ int newCapacity = 2 * oldCapacity;
+ Entry<E>[] newTable = this.buildTable(newCapacity);
for (int i = oldCapacity; i-- > 0; ) {
for (Entry<E> old = oldTable[i]; old != null; ) {
@@ -355,6 +359,9 @@ public class IdentityHashBag<E>
newTable[index] = e;
}
}
+
+ this.table = newTable;
+ this.threshold = (int) (newCapacity * this.loadFactor);
}
// minimize scope of suppressed warnings
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/JDBCType.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/JDBCType.java
index 581487a17e..4a15651163 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/JDBCType.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/JDBCType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -78,7 +78,7 @@ public final class JDBCType
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.shortClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.appendTo(sb);
sb.append(')');
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/NotNullFilter.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/NotNullFilter.java
index 2e315f8c4e..dabfbac229 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/NotNullFilter.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/NotNullFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -39,7 +39,7 @@ public final class NotNullFilter<T>
@Override
public String toString() {
- return ClassTools.shortClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
private static final long serialVersionUID = 1L;
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ReflectionTools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ReflectionTools.java
new file mode 100644
index 0000000000..22bb534cef
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/ReflectionTools.java
@@ -0,0 +1,1544 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2010 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.utility.internal;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+
+import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
+
+/**
+ * Convenience methods related to the <code>java.lang.reflect</code> package.
+ * These methods provide shortcuts for manipulating objects via
+ * reflection; particularly when dealing with fields and/or methods that
+ * are not publicly accessible or are inherited.
+ * <p>
+ * In most cases, all exceptions are handled and wrapped in
+ * {@link java.lang.RuntimeException}s; so these methods should
+ * be used when there should be no problems using reflection (i.e.
+ * the referenced members are presumably present etc.).
+ * <p>
+ * There are also a number of methods whose names
+ * end with an underscore. These methods declare the expected checked
+ * exceptions (e.g. {@link NoSuchMethodException}, {@link NoSuchFieldException}).
+ * These methods can be used to probe
+ * for methods, fields, etc. that should be present but might not be.
+ */
+public final class ReflectionTools {
+
+ public static final Class<?>[] ZERO_PARAMETER_TYPES = new Class[0];
+ public static final Object[] ZERO_ARGUMENTS = new Object[0];
+ private static final String CR = StringTools.CR;
+
+ public static final Class<?> VOID_CLASS = void.class;
+ public static final Class<java.lang.Void> VOID_WRAPPER_CLASS = java.lang.Void.class;
+
+
+ // ********** fields **********
+
+ /**
+ * Get a field value, given the containing object and field name.
+ * Return its result.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Object.getFieldValue(String fieldName)</code>
+ */
+ public static Object getFieldValue(Object object, String fieldName) {
+ try {
+ return getFieldValue_(object, fieldName);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(object, fieldName), ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(object, fieldName), ex);
+ }
+ }
+
+ /**
+ * Get a field value, given the containing object and field name.
+ * Return its result.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Object.getFieldValue(String fieldName)</code>
+ */
+ public static Object getFieldValue_(Object object, String fieldName)
+ throws NoSuchFieldException, IllegalAccessException
+ {
+ return getField_(object, fieldName).get(object);
+ }
+
+ /**
+ * Get a static field value, given the containing class and field name.
+ * Return its result.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Class.getStaticFieldValue(String fieldName)</code>
+ */
+ public static Object getStaticFieldValue(Class<?> javaClass, String fieldName) {
+ try {
+ return getStaticFieldValue_(javaClass, fieldName);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(javaClass, fieldName), ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(javaClass, fieldName), ex);
+ }
+ }
+
+ /**
+ * Get a static field value, given the containing class and field name.
+ * Return its result.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Class.getStaticFieldValue(String fieldName)</code>
+ */
+ public static Object getStaticFieldValue_(Class<?> javaClass, String fieldName)
+ throws NoSuchFieldException, IllegalAccessException
+ {
+ return getField_(javaClass, fieldName).get(null);
+ }
+
+ /**
+ * Set a field value, given the containing object, field name, and new value.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Object.setFieldValue(String fieldName, Object value)</code>
+ */
+ public static void setFieldValue(Object object, String fieldName, Object value) {
+ try {
+ setFieldValue_(object, fieldName, value);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(object, fieldName), ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(object, fieldName), ex);
+ }
+ }
+
+ /**
+ * Set a field value, given the containing object, field name, and new value.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Object.setFieldValue(String fieldName, Object value)</code>
+ */
+ public static void setFieldValue_(Object object, String fieldName, Object value)
+ throws NoSuchFieldException, IllegalAccessException
+ {
+ getField_(object, fieldName).set(object, value);
+ }
+
+ /**
+ * Set a static field value, given the containing class, field name, and new value.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Class.setStaticFieldValue(String fieldName, Object value)</code>
+ */
+ public static void setStaticFieldValue(Class<?> javaClass, String fieldName, Object value) {
+ try {
+ setStaticFieldValue_(javaClass, fieldName, value);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(javaClass, fieldName), ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(javaClass, fieldName), ex);
+ }
+ }
+
+ /**
+ * Set a static field value, given the containing class, field name, and new value.
+ * Useful for accessing private, package, or protected fields.
+ * <p>
+ * <code>Class.setStaticFieldValue(String fieldName, Object value)</code>
+ */
+ public static void setStaticFieldValue_(Class<?> javaClass, String fieldName, Object value)
+ throws NoSuchFieldException, IllegalAccessException
+ {
+ getField_(javaClass, fieldName).set(null, value);
+ }
+
+ /**
+ * Convenience method.
+ * Return a field for the specified object and field name.
+ * If the object's class does not directly
+ * define the field, look for it in the class's superclasses.
+ * Make any private/package/protected field accessible.
+ * <p>
+ * <code>Object.getField(String fieldName)</code>
+ */
+ public static Field getField(Object object, String fieldName) {
+ try {
+ return getField_(object, fieldName);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(object, fieldName), ex);
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Return a field for the specified object and field name.
+ * If the object's class does not directly
+ * define the field, look for it in the class's superclasses.
+ * Make any private/package/protected field accessible.
+ * <p>
+ * <code>Object.getField(String fieldName)</code>
+ */
+ public static Field getField_(Object object, String fieldName)
+ throws NoSuchFieldException
+ {
+ return getField_(object.getClass(), fieldName);
+ }
+
+ /**
+ * Return a field for the specified class and field name.
+ * If the class does not directly
+ * define the field, look for it in the class's superclasses.
+ * Make any private/package/protected field accessible.
+ */
+ public static Field getField(Class<?> javaClass, String fieldName) {
+ try {
+ return getField_(javaClass, fieldName);
+ } catch (NoSuchFieldException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedFieldName(javaClass, fieldName), ex);
+ }
+ }
+
+ /**
+ * Return a field for the specified class and field name.
+ * If the class does not directly
+ * define the field, look for it in the class's superclasses.
+ * Make any private/package/protected field accessible.
+ */
+ public static Field getField_(Class<?> javaClass, String fieldName)
+ throws NoSuchFieldException
+ {
+ Field field = null;
+ try {
+ field = javaClass.getDeclaredField(fieldName);
+ } catch (NoSuchFieldException ex) {
+ Class<?> superclass = javaClass.getSuperclass();
+ if (superclass == null) {
+ throw ex;
+ }
+ return getField_(superclass, fieldName); // recurse
+ }
+ field.setAccessible(true);
+ return field;
+ }
+
+ /**
+ * Return all the fields for the
+ * specified class, including inherited fields.
+ * Make any private/package/protected fields accessible.
+ * <p>
+ * <code>Class.getAllFields()</code>
+ */
+ public static Iterable<Field> getAllFields(Class<?> javaClass) {
+ ArrayList<Field> fields = new ArrayList<Field>();
+ for (Class<?> tempClass = javaClass; tempClass != null; tempClass = tempClass.getSuperclass()) {
+ addDeclaredFieldsTo(tempClass, fields);
+ }
+ return fields;
+ }
+
+ /*
+ * Add the declared fields for the specified class
+ * to the specified list.
+ */
+ private static void addDeclaredFieldsTo(Class<?> javaClass, ArrayList<Field> fields) {
+ for (Field field : getDeclaredFields(javaClass)) {
+ fields.add(field);
+ }
+ }
+
+ /**
+ * Return the declared fields for the specified class.
+ * Make any private/package/protected fields accessible.
+ * <p>
+ * <code>Class.getAccessibleDeclaredFields()</code>
+ */
+ public static Iterable<Field> getDeclaredFields(Class<?> javaClass) {
+ Field[] fields = javaClass.getDeclaredFields();
+ for (Field field : fields) {
+ field.setAccessible(true);
+ }
+ return new ArrayIterable<Field>(fields);
+ }
+
+
+ // ********** methods **********
+
+ /**
+ * Convenience method.
+ * Execute a zero-argument method, given the receiver and method name.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Object.execute(String methodName)</code>
+ */
+ public static Object executeMethod(Object receiver, String methodName) {
+ return executeMethod(receiver, methodName, ZERO_PARAMETER_TYPES, ZERO_ARGUMENTS);
+ }
+
+ /**
+ * Convenience method.
+ * Execute a one-argument method, given the receiver,
+ * method name, parameter type, and argument.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Object.execute(String methodName, Class<?> parameterType, Object argument)</code>
+ */
+ public static Object executeMethod(Object receiver, String methodName, Class<?> parameterType, Object argument) {
+ return executeMethod(receiver, methodName, new Class[] {parameterType}, new Object[] {argument});
+ }
+
+ /**
+ * Execute a method, given the receiver,
+ * method name, parameter types, and arguments.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Object.execute(String methodName, Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static Object executeMethod(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] arguments) {
+ return executeMethod(getMethod(receiver, methodName, parameterTypes), receiver, arguments);
+ }
+
+ /**
+ * Execute the specified method, given the receiver and arguments.
+ * Return its result.
+ * Useful for invoking cached methods.
+ */
+ public static Object executeMethod(Method method, Object receiver, Object[] arguments) {
+ try {
+ return method.invoke(receiver, arguments);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + method, ex);
+ } catch (InvocationTargetException ex) {
+ throw new RuntimeException(method + CR + ex.getTargetException(), ex);
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Execute a zero-argument method,
+ * given the receiver and method name.
+ * Return its result.
+ * Throw an exception if the method is not defined.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Object.execute(String methodName)</code>
+ */
+ public static Object executeMethod_(Object receiver, String methodName)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ return executeMethod_(receiver, methodName, ZERO_PARAMETER_TYPES, ZERO_ARGUMENTS);
+ }
+
+ /**
+ * Convenience method.
+ * Execute a method, given the receiver,
+ * method name, parameter type, and argument.
+ * Return its result.
+ * Throw an exception if the method is not defined.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Object.execute(String methodName, Class<?> parameterType, Object argument)</code>
+ */
+ public static Object executeMethod_(Object receiver, String methodName, Class<?> parameterType, Object argument)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ return executeMethod_(receiver, methodName, new Class[] {parameterType}, new Object[] {argument});
+ }
+
+ /**
+ * Execute a method, given the receiver,
+ * method name, parameter types, and arguments.
+ * Return its result.
+ * Throw an exception if the method is not defined.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Object.execute(String methodName, Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static Object executeMethod_(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] arguments)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ return getMethod_(receiver, methodName, parameterTypes).invoke(receiver, arguments);
+ }
+
+ /**
+ * Convenience method.
+ * Execute a zero-argument static method,
+ * given the class and method name.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Class.executeStaticMethod(String methodName)</code>
+ */
+ public static Object executeStaticMethod(Class<?> javaClass, String methodName) {
+ return executeStaticMethod(javaClass, methodName, ZERO_PARAMETER_TYPES, ZERO_ARGUMENTS);
+ }
+
+ /**
+ * Convenience method.
+ * Execute a static method, given the class,
+ * method name, parameter type, and argument.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Class.executeStaticMethod(String methodName, Class<?> parameterType, Object argument)</code>
+ */
+ public static Object executeStaticMethod(Class<?> javaClass, String methodName, Class<?> parameterType, Object argument) {
+ return executeStaticMethod(javaClass, methodName, new Class[] {parameterType}, new Object[] {argument});
+ }
+
+ /**
+ * Execute a static method, given the class,
+ * method name, parameter types, and arguments.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Class.executeStaticMethod(String methodName, Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static Object executeStaticMethod(Class<?> javaClass, String methodName, Class<?>[] parameterTypes, Object[] arguments) {
+ try {
+ return executeStaticMethod_(javaClass, methodName, parameterTypes, arguments);
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedMethodSignature(javaClass, methodName, parameterTypes), ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedMethodSignature(javaClass, methodName, parameterTypes), ex);
+ } catch (InvocationTargetException ex) {
+ throw new RuntimeException(buildFullyQualifiedMethodSignature(javaClass, methodName, parameterTypes) + CR + ex.getTargetException(), ex);
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Execute a zero-argument static method,
+ * given the class and method name.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Class.executeStaticMethod(String methodName)</code>
+ */
+ public static Object executeStaticMethod_(Class<?> javaClass, String methodName)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ return executeStaticMethod_(javaClass, methodName, ZERO_PARAMETER_TYPES, ZERO_ARGUMENTS);
+ }
+
+ /**
+ * Convenience method.
+ * Execute a static method, given the class,
+ * method name, parameter type, and argument.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Class.executeStaticMethod(String methodName, Class<?> parameterType, Object argument)</code>
+ */
+ public static Object executeStaticMethod_(Class<?> javaClass, String methodName, Class<?> parameterType, Object argument)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ return executeStaticMethod_(javaClass, methodName, new Class[] {parameterType}, new Object[] {argument});
+ }
+
+ /**
+ * Execute a static method, given the class,
+ * method name, parameter types, and arguments.
+ * Return its result.
+ * Useful for invoking private, package, or protected methods.
+ * <p>
+ * <code>Class.executeStaticMethod(String methodName, Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static Object executeStaticMethod_(Class<?> javaClass, String methodName, Class<?>[] parameterTypes, Object[] arguments)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ return getStaticMethod_(javaClass, methodName, parameterTypes).invoke(null, arguments);
+ }
+
+ /**
+ * Convenience method.
+ * Return a zero-argument method for the specified class
+ * and method name. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod(Class<?> javaClass, String methodName) {
+ return getMethod(javaClass, methodName, ZERO_PARAMETER_TYPES);
+ }
+
+ /**
+ * Convenience method.
+ * Return a zero-argument method for the specified class
+ * and method name. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod_(Class<?> javaClass, String methodName)
+ throws NoSuchMethodException
+ {
+ return getMethod_(javaClass, methodName, ZERO_PARAMETER_TYPES);
+ }
+
+ /**
+ * Convenience method.
+ * Return a method for the specified class, method name,
+ * and formal parameter type. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod(Class<?> javaClass, String methodName, Class<?> parameterType) {
+ return getMethod(javaClass, methodName, new Class[] {parameterType});
+ }
+
+ /**
+ * Convenience method.
+ * Return a method for the specified class, method name,
+ * and formal parameter type. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod_(Class<?> javaClass, String methodName, Class<?> parameterType)
+ throws NoSuchMethodException
+ {
+ return getMethod_(javaClass, methodName, new Class[] {parameterType});
+ }
+
+ /**
+ * Return a method for the specified class, method name,
+ * and formal parameter types. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod(Class<?> javaClass, String methodName, Class<?>[] parameterTypes) {
+ try {
+ return getMethod_(javaClass, methodName, parameterTypes);
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedMethodSignature(javaClass, methodName, parameterTypes), ex);
+ }
+ }
+
+ /**
+ * Return a method for the specified class, method name,
+ * and formal parameter types. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod_(Class<?> javaClass, String methodName, Class<?>[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ Method method = null;
+ try {
+ method = javaClass.getDeclaredMethod(methodName, parameterTypes);
+ } catch (NoSuchMethodException ex) {
+ Class<?> superclass = javaClass.getSuperclass();
+ if (superclass == null) {
+ throw ex;
+ }
+ // recurse
+ return getMethod_(superclass, methodName, parameterTypes);
+ }
+ method.setAccessible(true);
+ return method;
+ }
+
+ /**
+ * Convenience method.
+ * Return a zero-argument method for the specified object
+ * and method name. If the object's class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod(Object object, String methodName) {
+ return getMethod(object.getClass(), methodName);
+ }
+
+ /**
+ * Convenience method.
+ * Return a zero-argument method for the specified object
+ * and method name. If the object's class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod_(Object object, String methodName)
+ throws NoSuchMethodException
+ {
+ return getMethod_(object.getClass(), methodName);
+ }
+
+ /**
+ * Convenience method.
+ * Return a method for the specified object, method name,
+ * and formal parameter types. If the object's class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod(Object object, String methodName, Class<?>[] parameterTypes) {
+ return getMethod(object.getClass(), methodName, parameterTypes);
+ }
+
+ /**
+ * Convenience method.
+ * Return a method for the specified object, method name,
+ * and formal parameter types. If the object's class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod_(Object object, String methodName, Class<?>[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ return getMethod_(object.getClass(), methodName, parameterTypes);
+ }
+
+ /**
+ * Convenience method.
+ * Return a method for the specified object, method name,
+ * and formal parameter type. If the object's class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod(Object object, String methodName, Class<?> parameterType) {
+ return getMethod(object.getClass(), methodName, parameterType);
+ }
+
+ /**
+ * Convenience method.
+ * Return a method for the specified object, method name,
+ * and formal parameter type. If the object's class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getMethod_(Object object, String methodName, Class<?> parameterType)
+ throws NoSuchMethodException
+ {
+ return getMethod_(object.getClass(), methodName, parameterType);
+ }
+
+ /**
+ * Convenience method.
+ * Return a zero-argument static method for the specified class
+ * and method name. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getStaticMethod(Class<?> javaClass, String methodName) {
+ return getStaticMethod(javaClass, methodName, ZERO_PARAMETER_TYPES);
+ }
+
+ /**
+ * Convenience method.
+ * Return a static method for the specified class, method name,
+ * and formal parameter type. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getStaticMethod(Class<?> javaClass, String methodName, Class<?> parameterTypes) {
+ return getStaticMethod(javaClass, methodName, new Class[] {parameterTypes});
+ }
+
+ /**
+ * Return a static method for the specified class, method name,
+ * and formal parameter types. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getStaticMethod(Class<?> javaClass, String methodName, Class<?>[] parameterTypes) {
+ try {
+ return getStaticMethod_(javaClass, methodName, parameterTypes);
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedMethodSignature(javaClass, methodName, parameterTypes), ex);
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Return a zero-argument static method for the specified class
+ * and method name. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getStaticMethod_(Class<?> javaClass, String methodName)
+ throws NoSuchMethodException
+ {
+ return getStaticMethod_(javaClass, methodName, ZERO_PARAMETER_TYPES);
+ }
+
+ /**
+ * Convenience method.
+ * Return a static method for the specified class, method name,
+ * and formal parameter type. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getStaticMethod_(Class<?> javaClass, String methodName, Class<?> parameterTypes)
+ throws NoSuchMethodException
+ {
+ return getStaticMethod_(javaClass, methodName, new Class[] {parameterTypes});
+ }
+
+ /**
+ * Return a static method for the specified class, method name,
+ * and formal parameter types. If the class does not directly
+ * implement the method, look for it in the class's superclasses.
+ * Make any private/package/protected method accessible.
+ */
+ public static Method getStaticMethod_(Class<?> javaClass, String methodName, Class<?>[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ Method method = getMethod_(javaClass, methodName, parameterTypes);
+ if (Modifier.isStatic(method.getModifiers())) {
+ return method;
+ }
+ throw new NoSuchMethodException(buildFullyQualifiedMethodSignature(javaClass, methodName, parameterTypes));
+ }
+
+ /**
+ * Return all the methods for the
+ * specified class, including inherited methods.
+ * Make any private/package/protected methods accessible.
+ * <p>
+ * <code>Class.getAllMethods()</code>
+ */
+ public static Iterable<Method> getAllMethods(Class<?> javaClass) {
+ ArrayList<Method> methods = new ArrayList<Method>();
+ for (Class<?> tempClass = javaClass; tempClass != null; tempClass = tempClass.getSuperclass()) {
+ addDeclaredMethodsTo(tempClass, methods);
+ }
+ return methods;
+ }
+
+ /*
+ * Add the declared methods for the specified class
+ * to the specified list.
+ */
+ private static void addDeclaredMethodsTo(Class<?> javaClass, ArrayList<Method> methods) {
+ for (Method method : getDeclaredMethods(javaClass)) {
+ methods.add(method);
+ }
+ }
+
+ /**
+ * Return the declared methods for the specified class.
+ * Make any private/package/protected methods accessible.
+ * <p>
+ * <code>Class.getAccessibleDeclaredMethods()</code>
+ */
+ public static Iterable<Method> getDeclaredMethods(Class<?> javaClass) {
+ Method[] methods = javaClass.getDeclaredMethods();
+ for (Method method : methods) {
+ method.setAccessible(true);
+ }
+ return new ArrayIterable<Method>(methods);
+ }
+
+
+ // ********** constructors **********
+
+ /**
+ * Return the default (zero-argument) constructor
+ * for the specified class.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getDefaultConstructor()</code>
+ */
+ public static <T> Constructor<T> getDefaultConstructor(Class<T> javaClass) {
+ return getConstructor(javaClass);
+ }
+
+ /**
+ * Convenience method.
+ * Return the default (zero-argument) constructor
+ * for the specified class.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getConstructor()</code>
+ */
+ public static <T> Constructor<T> getConstructor(Class<T> javaClass) {
+ return getConstructor(javaClass, ZERO_PARAMETER_TYPES);
+ }
+
+ /**
+ * Convenience method.
+ * Return the constructor for the specified class
+ * and formal parameter type.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getConstructor(Class<?> parameterType)</code>
+ */
+ public static <T> Constructor<T> getConstructor(Class<T> javaClass, Class<?> parameterType) {
+ return getConstructor(javaClass, new Class[] {parameterType});
+ }
+
+ /**
+ * Return the constructor for the specified class
+ * and formal parameter types.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getConstructor(Class<?>[] parameterTypes)</code>
+ */
+ public static <T> Constructor<T> getConstructor(Class<T> javaClass, Class<?>[] parameterTypes) {
+ try {
+ return getConstructor_(javaClass, parameterTypes);
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedConstructorSignature(javaClass, parameterTypes), ex);
+ }
+ }
+
+ /**
+ * Return the default (zero-argument) constructor
+ * for the specified class.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getDefaultConstructor()</code>
+ */
+ public static <T> Constructor<T> getDefaultConstructor_(Class<T> javaClass)
+ throws NoSuchMethodException
+ {
+ return getConstructor_(javaClass);
+ }
+
+ /**
+ * Convenience method.
+ * Return the default (zero-argument) constructor
+ * for the specified class.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getConstructor()</code>
+ */
+ public static <T> Constructor<T> getConstructor_(Class<T> javaClass)
+ throws NoSuchMethodException
+ {
+ return getConstructor_(javaClass, ZERO_PARAMETER_TYPES);
+ }
+
+ /**
+ * Convenience method.
+ * Return the constructor for the specified class
+ * and formal parameter type.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getConstructor(Class<?> parameterType)</code>
+ */
+ public static <T> Constructor<T> getConstructor_(Class<T> javaClass, Class<?> parameterType)
+ throws NoSuchMethodException
+ {
+ return getConstructor_(javaClass, new Class[] {parameterType});
+ }
+
+ /**
+ * Return the constructor for the specified class
+ * and formal parameter types.
+ * Make any private/package/protected constructor accessible.
+ * <p>
+ * <code>Class.getConstructor(Class<?>[] parameterTypes)</code>
+ */
+ public static <T> Constructor<T> getConstructor_(Class<T> javaClass, Class<?>[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ Constructor<T> constructor = javaClass.getDeclaredConstructor(parameterTypes);
+ constructor.setAccessible(true);
+ return constructor;
+ }
+
+ /**
+ * Return the declared constructors for the specified class.
+ * Make any private/package/protected constructors accessible.
+ * <p>
+ * <code>Class.getAccessibleDeclaredConstructors()</code>
+ */
+ public static <T> Iterable<Constructor<T>> getDeclaredConstructors(Class<T> javaClass) {
+ @SuppressWarnings("unchecked")
+ Constructor<T>[] constructors = (Constructor<T>[]) javaClass.getDeclaredConstructors();
+ for (Constructor<T> constructor : constructors) {
+ constructor.setAccessible(true);
+ }
+ return new ArrayIterable<Constructor<T>>(constructors);
+ }
+
+
+ // ********** classes **********
+
+ /**
+ * Convenience method.
+ * Return the specified class (without the checked exception).
+ */
+ public static Class<?> classForName(String className) {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(className, ex);
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Return the specified class (without the checked exception).
+ */
+ public static Class<?> classForName(String className, boolean initialize, ClassLoader classLoader) {
+ try {
+ return Class.forName(className, initialize, classLoader);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(className, ex);
+ }
+ }
+
+ /**
+ * Return the "array depth" of the specified class.
+ * The depth is the number of dimensions for an array type.
+ * Non-array types have a depth of zero.
+ * <p>
+ * <code>Class.getArrayDepth()</code>
+ */
+ public static int getArrayDepth(Class<?> javaClass) {
+ int depth = 0;
+ while (javaClass.isArray()) {
+ depth++;
+ javaClass = javaClass.getComponentType();
+ }
+ return depth;
+ }
+
+ /**
+ * Return the "element type" of the specified class.
+ * The element type is the base type held by an array type.
+ * A non-array type simply returns itself.
+ * <p>
+ * <code>Class.getElementType()</code>
+ */
+ public static Class<?> getElementType(Class<?> javaClass) {
+ while (javaClass.isArray()) {
+ javaClass = javaClass.getComponentType();
+ }
+ return javaClass;
+ }
+
+ /**
+ * Return the wrapper class corresponding to the specified
+ * primitive class. Return <code>null</code> if the specified class
+ * is not a primitive class.
+ * <p>
+ * <code>Class.getWrapperClass()</code>
+ */
+ public static Class<?> getWrapperClass(Class<?> primitiveClass) {
+ for (Primitive primitive : PRIMITIVES) {
+ if (primitive.javaClass == primitiveClass) {
+ return primitive.wrapperClass;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return whether the specified class is a primitive wrapper
+ * class (i.e. <code>java.lang.Void</code> or one of the primitive
+ * variable wrapper classes, <code>java.lang.Boolean</code>,
+ * <code>java.lang.Integer</code>, <code>java.lang.Float</code>, etc.).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ * <p>
+ * <code>Class.isPrimitiveWrapper()</code>
+ */
+ public static boolean classIsPrimitiveWrapper(Class<?> javaClass) {
+ if (javaClass.isArray() || (javaClass.getName().length() > MAX_PRIMITIVE_WRAPPER_CLASS_NAME_LENGTH)) {
+ return false; // performance tweak
+ }
+ for (Primitive primitive : PRIMITIVES) {
+ if (javaClass == primitive.wrapperClass) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return whether the specified class is a "variable" primitive wrapper
+ * class (i.e. <code>java.lang.Boolean</code>,
+ * <code>java.lang.Integer</code>, <code>java.lang.Float</code>, etc.,
+ * but not <code>java.lang.Void</code>).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ * <p>
+ * <code>Class.isVariablePrimitiveWrapper()</code>
+ */
+ public static boolean classIsVariablePrimitiveWrapper(Class<?> javaClass) {
+ return classIsPrimitiveWrapper(javaClass)
+ && (javaClass != VOID_WRAPPER_CLASS);
+ }
+
+ /**
+ * Return whether the specified class is a "variable" primitive
+ * class (i.e. <code>boolean</code>, <code>int</code>,
+ * <code>float</code>, etc., but not <code>void</code>).
+ * <p>
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ * <p>
+ * <code>Class.isVariablePrimitive()</code>
+ */
+ public static boolean classIsVariablePrimitive(Class<?> javaClass) {
+ return javaClass.isPrimitive() && (javaClass != VOID_CLASS);
+ }
+
+ /**
+ * Return the primitive class for the specified primitive class code.
+ * Return <code>null</code> if the specified code
+ * is not a primitive class code.
+ * @see java.lang.Class#getName()
+ */
+ public static Class<?> getClassForCode(int classCode) {
+ return getClassForCode((char) classCode);
+ }
+
+ /**
+ * Return the primitive class for the specified primitive class code.
+ * Return <code>null</code> if the specified code
+ * is not a primitive class code.
+ * @see java.lang.Class#getName()
+ */
+ public static Class<?> getClassForCode(char classCode) {
+ for (Primitive primitive : PRIMITIVES) {
+ if (primitive.code == classCode) {
+ return primitive.javaClass;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the class code for the specified primitive class.
+ * Return <code>0</code> if the specified class
+ * is not a primitive class.
+ * @see java.lang.Class#getName()
+ */
+ public static char getCodeForClass(Class<?> primitiveClass) {
+ if (( ! primitiveClass.isArray()) && (primitiveClass.getName().length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH)) {
+ for (Primitive primitive : PRIMITIVES) {
+ if (primitive.javaClass == primitiveClass) {
+ return primitive.code;
+ }
+ }
+ }
+ return 0;
+ }
+
+
+ // ********** instantiation **********
+
+ /**
+ * Convenience method.
+ * Return a new instance of the specified class,
+ * using the class's default (zero-argument) constructor.
+ * <p>
+ * <code>Class.newInstance()</code>
+ */
+ public static Object newInstance(String className) {
+ return newInstance(className, null);
+ }
+
+ /**
+ * Return a new instance of the specified class,
+ * given the constructor parameter type and argument.
+ * <p>
+ * <code>Class.newInstance(Class<?> parameterType, Object argument)</code>
+ */
+ public static Object newInstance(String className, Class<?> parameterType, Object argument) {
+ return newInstance(className, parameterType, argument, null);
+ }
+
+ /**
+ * Return a new instance of the specified class,
+ * given the constructor parameter types and arguments.
+ * <p>
+ * <code>Class.newInstance(Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static Object newInstance(String className, Class<?>[] parameterTypes, Object[] arguments) {
+ return newInstance(className, parameterTypes, arguments, null);
+ }
+
+ /**
+ * Convenience method.
+ * Return a new instance of the specified class,
+ * using the class's default (zero-argument) constructor.
+ * Use the specified class loader to load the class.
+ * <p>
+ * <code>Class.newInstance()</code>
+ */
+ public static Object newInstance(String className, ClassLoader classLoader) {
+ return newInstance(classForName(className, false, classLoader));
+ }
+
+ /**
+ * Return a new instance of the specified class,
+ * given the constructor parameter type and argument.
+ * <p>
+ * <code>Class.newInstance(Class<?> parameterType, Object argument)</code>
+ */
+ public static Object newInstance(String className, Class<?> parameterType, Object argument, ClassLoader classLoader) {
+ return newInstance(classForName(className, false, classLoader), parameterType, argument);
+ }
+
+ /**
+ * Return a new instance of the specified class,
+ * given the constructor parameter types and arguments.
+ * <p>
+ * <code>Class.newInstance(Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static Object newInstance(String className, Class<?>[] parameterTypes, Object[] arguments, ClassLoader classLoader) {
+ return newInstance(classForName(className, false, classLoader), parameterTypes, arguments);
+ }
+
+ /**
+ * Convenience method.
+ * Return a new instance of the specified class,
+ * using the class's default (zero-argument) constructor.
+ * <p>
+ * <code>Class.newInstance()</code>
+ */
+ public static <T> T newInstance(Class<T> javaClass) {
+ return newInstance(javaClass, ZERO_PARAMETER_TYPES, ZERO_ARGUMENTS);
+ }
+
+ /**
+ * Convenience method.
+ * Return a new instance of the specified class,
+ * given the constructor parameter type and argument.
+ * <p>
+ * <code>Class.newInstance(Class<?> parameterType, Object argument)</code>
+ */
+ public static <T> T newInstance(Class<T> javaClass, Class<?> parameterType, Object argument) {
+ return newInstance(javaClass, new Class[] {parameterType}, new Object[] {argument});
+ }
+
+ /**
+ * Return a new instance of the specified class,
+ * given the constructor parameter types and arguments.
+ * <p>
+ * <code>Class.newInstance(Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static <T> T newInstance(Class<T> javaClass, Class<?>[] parameterTypes, Object[] arguments) {
+ try {
+ return newInstance_(javaClass, parameterTypes, arguments);
+ } catch (InstantiationException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedConstructorSignature(javaClass, parameterTypes), ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedConstructorSignature(javaClass, parameterTypes), ex);
+ } catch (InvocationTargetException ex) {
+ throw new RuntimeException(buildFullyQualifiedConstructorSignature(javaClass, parameterTypes) + CR + ex.getTargetException(), ex);
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException(ex + CR + buildFullyQualifiedConstructorSignature(javaClass, parameterTypes), ex);
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Return a new instance of the specified class,
+ * using the class's default (zero-argument) constructor.
+ * <p>
+ * <code>Class.newInstance()</code>
+ */
+ public static <T> T newInstance_(Class<T> javaClass)
+ throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
+ {
+ return newInstance_(javaClass, ZERO_PARAMETER_TYPES, ZERO_ARGUMENTS);
+ }
+
+ /**
+ * Convenience method.
+ * Return a new instance of the specified class,
+ * given the constructor parameter type and argument.
+ * <p>
+ * <code>Class.newInstance(Class<?> parameterType, Object argument)</code>
+ */
+ public static <T> T newInstance_(Class<T> javaClass, Class<?> parameterType, Object argument)
+ throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
+ {
+ return newInstance_(javaClass, new Class[] {parameterType}, new Object[] {argument});
+ }
+
+ /**
+ * Return a new instance of the specified class,
+ * given the constructor parameter types and arguments.
+ * <p>
+ * <code>Class.newInstance(Class<?>[] parameterTypes, Object[] arguments)</code>
+ */
+ public static <T> T newInstance_(Class<T> javaClass, Class<?>[] parameterTypes, Object[] arguments)
+ throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
+ {
+ return getConstructor_(javaClass, parameterTypes).newInstance(arguments);
+ }
+
+
+ // ********** type declarations **********
+
+ /**
+ * Return the class for the specified "type declaration".
+ */
+ public static Class<?> getClassForTypeDeclaration(String typeDeclaration) {
+ return getClassForTypeDeclaration(typeDeclaration, null);
+ }
+
+ /**
+ * Return the class for the specified "type declaration".
+ */
+ public static Class<?> getClassForTypeDeclaration_(String typeDeclaration)
+ throws ClassNotFoundException
+ {
+ return getClassForTypeDeclaration_(typeDeclaration, null);
+ }
+
+ /**
+ * Return the class for the specified "type declaration",
+ * using the specified class loader.
+ */
+ public static Class<?> getClassForTypeDeclaration(String typeDeclaration, ClassLoader classLoader) {
+ TypeDeclaration td = buildTypeDeclaration(typeDeclaration);
+ return getClassForTypeDeclaration(td.elementTypeName, td.arrayDepth, classLoader);
+ }
+
+ /**
+ * Return the class for the specified "type declaration",
+ * using the specified class loader.
+ */
+ public static Class<?> getClassForTypeDeclaration_(String typeDeclaration, ClassLoader classLoader)
+ throws ClassNotFoundException
+ {
+ TypeDeclaration td = buildTypeDeclaration(typeDeclaration);
+ return getClassForTypeDeclaration_(td.elementTypeName, td.arrayDepth, classLoader);
+ }
+
+ private static TypeDeclaration buildTypeDeclaration(String typeDeclaration) {
+ typeDeclaration = StringTools.removeAllWhitespace(typeDeclaration);
+ int arrayDepth = getArrayDepthForTypeDeclaration_(typeDeclaration);
+ String elementTypeName = getElementTypeNameForTypeDeclaration_(typeDeclaration, arrayDepth);
+ return new TypeDeclaration(elementTypeName, arrayDepth);
+ }
+
+ /**
+ * Return the array depth for the specified "type declaration"; e.g.<ul>
+ * <li><code>"int[]"</code> returns <code>1</code>
+ * <li><code>"java.lang.String[][][]"</code> returns <code>3</code>
+ * </ul>
+ */
+ public static int getArrayDepthForTypeDeclaration(String typeDeclaration) {
+ return getArrayDepthForTypeDeclaration_(StringTools.removeAllWhitespace(typeDeclaration));
+ }
+
+ /**
+ * pre-condition: no whitespace in the type declaration.
+ */
+ private static int getArrayDepthForTypeDeclaration_(String typeDeclaration) {
+ int last = typeDeclaration.length() - 1;
+ int depth = 0;
+ int close = last;
+ while (typeDeclaration.charAt(close) == ']') {
+ if (typeDeclaration.charAt(close - 1) == '[') {
+ depth++;
+ } else {
+ throw new IllegalArgumentException("invalid type declaration: " + typeDeclaration); //$NON-NLS-1$
+ }
+ close = last - (depth * 2);
+ }
+ return depth;
+ }
+
+ /**
+ * Return the element type name for the specified "type declaration"; e.g.<ul>
+ * <li><code>"int[]"</code> returns <code>"int"</code>
+ * <li><code>"java.lang.String[][][]"</code> returns <code>"java.lang.String"</code>
+ * </ul>
+ */
+ public static String getElementTypeNameForTypeDeclaration(String typeDeclaration) {
+ typeDeclaration = StringTools.removeAllWhitespace(typeDeclaration);
+ return getElementTypeNameForTypeDeclaration_(typeDeclaration, getArrayDepthForTypeDeclaration_(typeDeclaration));
+ }
+
+ /**
+ * Return the element type name for the specified "type declaration"; e.g.<ul>
+ * <li><code>"int[]"</code> returns <code>"int"</code>
+ * <li><code>"java.lang.String[][][]"</code> returns <code>"java.lang.String"</code>
+ * </ul>
+ * Useful for clients that have already queried the type declaration's array depth.
+ */
+ public static String getElementTypeNameForTypeDeclaration(String typeDeclaration, int arrayDepth) {
+ return getElementTypeNameForTypeDeclaration_(StringTools.removeAllWhitespace(typeDeclaration), arrayDepth);
+ }
+
+ /**
+ * pre-condition: no whitespace in the type declaration.
+ */
+ private static String getElementTypeNameForTypeDeclaration_(String typeDeclaration, int arrayDepth) {
+ return typeDeclaration.substring(0, typeDeclaration.length() - (arrayDepth * 2));
+ }
+
+ /**
+ * Return the class for the specified "type declaration".
+ */
+ public static Class<?> getClassForTypeDeclaration(String elementTypeName, int arrayDepth) {
+ return getClassForTypeDeclaration(elementTypeName, arrayDepth, null);
+ }
+
+ /**
+ * Return the class for the specified "type declaration".
+ */
+ public static Class<?> getClassForTypeDeclaration_(String elementTypeName, int arrayDepth)
+ throws ClassNotFoundException
+ {
+ return getClassForTypeDeclaration_(elementTypeName, arrayDepth, null);
+ }
+
+ /**
+ * Return the class for the specified "type declaration",
+ * using the specified class loader.
+ */
+ public static Class<?> getClassForTypeDeclaration(String elementTypeName, int arrayDepth, ClassLoader classLoader) {
+ try {
+ return getClassForTypeDeclaration_(elementTypeName, arrayDepth, classLoader);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Return the class for the specified "type declaration",
+ * using the specified class loader.
+ */
+ // see the "Evaluation" of JDK bug 6446627 for a discussion of loading classes
+ public static Class<?> getClassForTypeDeclaration_(String elementTypeName, int arrayDepth, ClassLoader classLoader)
+ throws ClassNotFoundException
+ {
+ // primitives cannot be loaded via Class.forName(),
+ // so check for a primitive class name first
+ Primitive pcc = null;
+ if (elementTypeName.length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH) { // performance tweak
+ for (Primitive primitive : PRIMITIVES) {
+ if (primitive.javaClass.getName().equals(elementTypeName)) {
+ pcc = primitive;
+ break;
+ }
+ }
+ }
+
+ // non-array
+ if (arrayDepth == 0) {
+ return (pcc == null) ? Class.forName(elementTypeName, false, classLoader) : pcc.javaClass;
+ }
+
+ // array
+ StringBuilder sb = new StringBuilder(100);
+ for (int i = arrayDepth; i-- > 0; ) {
+ sb.append('[');
+ }
+ if (pcc == null) {
+ ClassName.append(elementTypeName, sb);
+ } else {
+ sb.append(pcc.code);
+ }
+ return Class.forName(sb.toString(), false, classLoader);
+ }
+
+ /**
+ * Return the class name for the specified "type declaration"; e.g.<ul>
+ * <li><code>"int"</code> returns <code>"int"</code>
+ * <li><code>"int[]"</code> returns <code>"[I"</code>
+ * <li><code>"java.lang.String"</code> returns <code>"java.lang.String"</code>
+ * <li><code>"java.lang.String[][][]"</code> returns <code>"[[[Ljava.lang.String;"</code>
+ * </ul>
+ * @see java.lang.Class#getName()
+ */
+ public static String getClassNameForTypeDeclaration(String typeDeclaration) {
+ TypeDeclaration td = buildTypeDeclaration(typeDeclaration);
+ return getClassNameForTypeDeclaration(td.elementTypeName, td.arrayDepth);
+ }
+
+ /**
+ * Return the class name for the specified "type declaration".
+ * @see java.lang.Class#getName()
+ */
+ public static String getClassNameForTypeDeclaration(String elementTypeName, int arrayDepth) {
+ // non-array
+ if (arrayDepth == 0) {
+ return elementTypeName;
+ }
+
+ if (elementTypeName.equals(ClassName.VOID_CLASS_NAME)) {
+ throw new IllegalArgumentException('\'' + ClassName.VOID_CLASS_NAME + "' must have an array depth of zero: " + arrayDepth + '.'); //$NON-NLS-1$
+ }
+ // array
+ StringBuilder sb = new StringBuilder(100);
+ for (int i = arrayDepth; i-- > 0; ) {
+ sb.append('[');
+ }
+
+ // look for a primitive first
+ Primitive pcc = null;
+ if (elementTypeName.length() <= MAX_PRIMITIVE_CLASS_NAME_LENGTH) { // performance tweak
+ for (Primitive primitive : PRIMITIVES) {
+ if (primitive.javaClass.getName().equals(elementTypeName)) {
+ pcc = primitive;
+ break;
+ }
+ }
+ }
+
+ if (pcc == null) {
+ ClassName.append(elementTypeName, sb);
+ } else {
+ sb.append(pcc.code);
+ }
+
+ return sb.toString();
+ }
+
+
+ // ********** exception messages **********
+
+ /**
+ * Return a string representation of the specified constructor.
+ */
+ private static String buildFullyQualifiedConstructorSignature(Class<?> javaClass, Class<?>[] parameterTypes) {
+ return buildFullyQualifiedMethodSignature(javaClass, null, parameterTypes);
+ }
+
+ /**
+ * Return a string representation of the specified field.
+ */
+ private static String buildFullyQualifiedFieldName(Class<?> javaClass, String fieldName) {
+ StringBuilder sb = new StringBuilder(200);
+ sb.append(javaClass.getName());
+ sb.append('.');
+ sb.append(fieldName);
+ return sb.toString();
+ }
+
+ /**
+ * Return a string representation of the specified field.
+ */
+ private static String buildFullyQualifiedFieldName(Object object, String fieldName) {
+ return buildFullyQualifiedFieldName(object.getClass(), fieldName);
+ }
+
+ /**
+ * Return a string representation of the specified method.
+ */
+ private static String buildFullyQualifiedMethodSignature(Class<?> javaClass, String methodName, Class<?>[] parameterTypes) {
+ StringBuilder sb = new StringBuilder(200);
+ sb.append(javaClass.getName());
+ // this check allows us to use this code for constructors, where the methodName is null
+ if (methodName != null) {
+ sb.append('.');
+ sb.append(methodName);
+ }
+ sb.append('(');
+ int max = parameterTypes.length - 1;
+ if (max != -1) {
+ // stop one short of the end of the array
+ for (int i = 0; i < max; i++) {
+ sb.append(parameterTypes[i].getName());
+ sb.append(", "); //$NON-NLS-1$
+ }
+ sb.append(parameterTypes[max].getName());
+ }
+ sb.append(')');
+ return sb.toString();
+ }
+
+
+ // ********** primitive constants **********
+
+ static final Iterable<Primitive> PRIMITIVES = buildPrimitives();
+
+ public static final char BYTE_CODE = 'B';
+ public static final char CHAR_CODE = 'C';
+ public static final char DOUBLE_CODE = 'D';
+ public static final char FLOAT_CODE = 'F';
+ public static final char INT_CODE = 'I';
+ public static final char LONG_CODE = 'J';
+ public static final char SHORT_CODE = 'S';
+ public static final char BOOLEAN_CODE = 'Z';
+ public static final char VOID_CODE = 'V';
+
+ static final int MAX_PRIMITIVE_CLASS_NAME_LENGTH = calculateMaxPrimitiveClassNameLength();
+ static final int MAX_PRIMITIVE_WRAPPER_CLASS_NAME_LENGTH = calculateMaxPrimitiveWrapperClassNameLength();
+
+ private static int calculateMaxPrimitiveClassNameLength() {
+ int max = -1;
+ for (Primitive primitive : PRIMITIVES) {
+ int len = primitive.javaClass.getName().length();
+ if (len > max) {
+ max = len;
+ }
+ }
+ return max;
+ }
+
+ private static int calculateMaxPrimitiveWrapperClassNameLength() {
+ int max = -1;
+ for (Primitive primitive : PRIMITIVES) {
+ int len = primitive.wrapperClass.getName().length();
+ if (len > max) {
+ max = len;
+ }
+ }
+ return max;
+ }
+
+ /**
+ * <strong>NB:</strong> <code>void.class.isPrimitive() == true</code>
+ */
+ private static Iterable<Primitive> buildPrimitives() {
+ Primitive[] array = new Primitive[9];
+ array[0] = new Primitive(BYTE_CODE, java.lang.Byte.class);
+ array[1] = new Primitive(CHAR_CODE, java.lang.Character.class);
+ array[2] = new Primitive(DOUBLE_CODE, java.lang.Double.class);
+ array[3] = new Primitive(FLOAT_CODE, java.lang.Float.class);
+ array[4] = new Primitive(INT_CODE, java.lang.Integer.class);
+ array[5] = new Primitive(LONG_CODE, java.lang.Long.class);
+ array[6] = new Primitive(SHORT_CODE, java.lang.Short.class);
+ array[7] = new Primitive(BOOLEAN_CODE, java.lang.Boolean.class);
+ array[8] = new Primitive(VOID_CODE, java.lang.Void.class);
+ return new ArrayIterable<Primitive>(array);
+ }
+
+
+ // ********** member classes **********
+
+ static class Primitive {
+ final char code;
+ final Class<?> javaClass;
+ final Class<?> wrapperClass;
+ private static final String WRAPPER_CLASS_TYPE_FIELD_NAME = "TYPE"; //$NON-NLS-1$
+ // e.g. java.lang.Boolean.TYPE => boolean.class
+ Primitive(char code, Class<?> wrapperClass) {
+ this.code = code;
+ this.wrapperClass = wrapperClass;
+ this.javaClass = (Class<?>) getStaticFieldValue(wrapperClass, WRAPPER_CLASS_TYPE_FIELD_NAME);
+ }
+ }
+
+ private static class TypeDeclaration {
+ final String elementTypeName;
+ final int arrayDepth;
+ TypeDeclaration(String elementTypeName, int arrayDepth) {
+ this.elementTypeName = elementTypeName;
+ this.arrayDepth = arrayDepth;
+ }
+ }
+
+
+ // ********** suppressed constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private ReflectionTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java
index 3c1110f286..3a94acea21 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.utility.internal;
import java.io.PrintWriter;
import java.io.Serializable;
+
import org.eclipse.jpt.utility.JavaType;
/**
@@ -45,7 +46,7 @@ public final class SimpleJavaType
if ((elementTypeName == null) || (elementTypeName.length() == 0)) {
throw new IllegalArgumentException("The element type name is required."); //$NON-NLS-1$
}
- if (ClassTools.arrayDepthForClassNamed(elementTypeName) != 0) { // e.g. "[Ljava.lang.Object;"
+ if (ClassName.getArrayDepth(elementTypeName) != 0) { // e.g. "[Ljava.lang.Object;"
throw new IllegalArgumentException("The element type must not be an array: " + elementTypeName + '.'); //$NON-NLS-1$
}
if (arrayDepth < 0) {
@@ -70,7 +71,7 @@ public final class SimpleJavaType
* </code></ul>
*/
public SimpleJavaType(String javaClassName) {
- this(ClassTools.elementTypeNameForClassNamed(javaClassName), ClassTools.arrayDepthForClassNamed(javaClassName));
+ this(ClassName.getElementTypeName(javaClassName), ClassName.getArrayDepth(javaClassName));
}
/**
@@ -99,27 +100,27 @@ public final class SimpleJavaType
}
public boolean isPrimitive() {
- return (this.arrayDepth == 0) && ClassTools.classNamedIsPrimitive(this.elementTypeName);
+ return (this.arrayDepth == 0) && ClassName.isPrimitive(this.elementTypeName);
}
public boolean isPrimitiveWrapper() {
- return (this.arrayDepth == 0) && ClassTools.classNamedIsPrimitiveWrapperClass(this.elementTypeName);
+ return (this.arrayDepth == 0) && ClassName.isPrimitiveWrapper(this.elementTypeName);
}
public boolean isVariablePrimitive() {
- return (this.arrayDepth == 0) && ClassTools.classNamedIsVariablePrimitive(this.elementTypeName);
+ return (this.arrayDepth == 0) && ClassName.isVariablePrimitive(this.elementTypeName);
}
public boolean isVariablePrimitiveWrapper() {
- return (this.arrayDepth == 0) && ClassTools.classNamedIsVariablePrimitiveWrapperClass(this.elementTypeName);
+ return (this.arrayDepth == 0) && ClassName.isVariablePrimitiveWrapper(this.elementTypeName);
}
public Class<?> getJavaClass() throws ClassNotFoundException {
- return ClassTools.classForTypeDeclaration(this.elementTypeName, this.arrayDepth);
+ return ReflectionTools.getClassForTypeDeclaration(this.elementTypeName, this.arrayDepth);
}
public String getJavaClassName() {
- return ClassTools.classNameForTypeDeclaration(this.elementTypeName, this.arrayDepth);
+ return ReflectionTools.getClassNameForTypeDeclaration(this.elementTypeName, this.arrayDepth);
}
@@ -131,7 +132,7 @@ public final class SimpleJavaType
}
public boolean describes(String className) {
- return this.equals(ClassTools.elementTypeNameForClassNamed(className), ClassTools.arrayDepthForClassNamed(className));
+ return this.equals(ClassName.getElementTypeName(className), ClassName.getArrayDepth(className));
}
public boolean describes(Class<?> javaClass) {
@@ -190,7 +191,7 @@ public final class SimpleJavaType
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.shortClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.appendDeclarationTo(sb);
sb.append(')');
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java
index 31d26de325..9145f47b85 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -218,7 +218,7 @@ public final class SimpleMethodSignature
@Override
public String toString() {
StringBuilder sb = new StringBuilder(200);
- sb.append(ClassTools.shortClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.appendSignatureTo(sb);
sb.append(')');
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 260409dde7..71beb434e9 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -3389,7 +3389,7 @@ public final class StringTools {
* ClassName[00F3EE42]
*/
public static void buildSimpleToStringOn(Object o, StringBuffer sb) {
- sb.append(ClassTools.toStringClassNameForObject(o));
+ sb.append(buildToStringClassName(o.getClass()));
sb.append('[');
// use System#identityHashCode(Object), since Object#hashCode() may be overridden
sb.append(zeroPad(Integer.toHexString(System.identityHashCode(o)).toUpperCase(), 8));
@@ -3402,13 +3402,26 @@ public final class StringTools {
* ClassName[00F3EE42]
*/
public static void buildSimpleToStringOn(Object o, StringBuilder sb) {
- sb.append(ClassTools.toStringClassNameForObject(o));
+ sb.append(buildToStringClassName(o.getClass()));
sb.append('[');
// use System#identityHashCode(Object), since Object#hashCode() may be overridden
sb.append(zeroPad(Integer.toHexString(System.identityHashCode(o)).toUpperCase(), 8));
sb.append(']');
}
+ /**
+ * Return a name suitable for a <code>#toString()</code> implementation.
+ * {@link Class#getSimpleName()} isn't quite good enough for anonymous
+ * classes; since it returns an empty string. This method will return the
+ * name of the anonymous class's super class, which is a bit more helpful.
+ */
+ public static String buildToStringClassName(Class<?> javaClass) {
+ String simpleName = javaClass.getSimpleName();
+ return simpleName.equals("") ? //$NON-NLS-1$
+ buildToStringClassName(javaClass.getSuperclass()) : // recurse
+ simpleName;
+ }
+
public static <T> String append(StringBuilder sb, T[] array) {
return append(sb, new ArrayListIterator<T>(array));
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Tools.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Tools.java
index 1366d454fa..2b4eb3fe70 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Tools.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/Tools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,8 +12,11 @@ package org.eclipse.jpt.utility.internal;
/**
* Various utility methods.
*/
+@SuppressWarnings("nls")
public class Tools {
+ // ********** object comparison **********
+
/**
* Return whether the specified values are equal, with the appropriate null checks.
*/
@@ -29,6 +32,45 @@ public class Tools {
}
+ // ********** System properties **********
+
+ /**
+ * Return whether the current JVM is Sun's.
+ */
+ public static boolean jvmIsSun() {
+ return jvmIs("Sun");
+ }
+
+ /**
+ * Return whether the current JVM is IBM's.
+ */
+ public static boolean jvmIsIBM() {
+ return jvmIs("IBM");
+ }
+
+ private static boolean jvmIs(String jvmVendorName) {
+ return System.getProperty("java.vendor").startsWith(jvmVendorName);
+ }
+
+ /**
+ * Return whether the current operating system is Microsoft Windows.
+ */
+ public static boolean osIsWindows() {
+ return osIs("Windows");
+ }
+
+ /**
+ * Return whether the current operating system is Linux.
+ */
+ public static boolean osIsLinux() {
+ return osIs("Linux");
+ }
+
+ private static boolean osIs(String osName) {
+ return System.getProperty("os.name").indexOf(osName) != -1;
+ }
+
+
// ********** constructor **********
/**
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/enumerations/EmptyEnumeration.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/enumerations/EmptyEnumeration.java
index 4beb352d04..cac7247d10 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/enumerations/EmptyEnumeration.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/enumerations/EmptyEnumeration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,8 +12,6 @@ package org.eclipse.jpt.utility.internal.enumerations;
import java.util.Enumeration;
import java.util.NoSuchElementException;
-import org.eclipse.jpt.utility.internal.ClassTools;
-
/**
* An <code>EmptyEnumeration</code> is just that.
*
@@ -52,7 +50,7 @@ public final class EmptyEnumeration<E>
@Override
public String toString() {
- return ClassTools.shortClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
private static final long serialVersionUID = 1L;
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyIterable.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyIterable.java
index 7af45fc30e..a4c38ea9d9 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyIterable.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,6 @@ package org.eclipse.jpt.utility.internal.iterables;
import java.io.Serializable;
import java.util.Iterator;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
/**
@@ -54,7 +53,7 @@ public final class EmptyIterable<E>
@Override
public String toString() {
- return ClassTools.toStringClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
private static final long serialVersionUID = 1L;
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyListIterable.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyListIterable.java
index 5a59b90cbb..2c33be160a 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyListIterable.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/EmptyListIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,6 @@ package org.eclipse.jpt.utility.internal.iterables;
import java.io.Serializable;
import java.util.ListIterator;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator;
/**
@@ -54,7 +53,7 @@ public final class EmptyListIterable<E>
@Override
public String toString() {
- return ClassTools.toStringClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
private static final long serialVersionUID = 1L;
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/FilteringIterable.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/FilteringIterable.java
index 9d1ff94685..a184190ee6 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/FilteringIterable.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/FilteringIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -24,16 +24,15 @@ import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
* of <code>FilteringIterable</code> can override the
* {@link #accept(Object)} method.
*
- * @param <E1> input: the type of elements to be filtered
- * @param <E2> output: the type of elements returned by the iterable's iterator
+ * @param <E> the type of elements to be filtered
*
* @see FilteringIterator
*/
-public class FilteringIterable<E1, E2>
- implements Iterable<E2>
+public class FilteringIterable<E>
+ implements Iterable<E>
{
- private final Iterable<? extends E1> iterable;
- private final Filter<E1> filter;
+ private final Iterable<? extends E> iterable;
+ private final Filter<E> filter;
/**
@@ -43,7 +42,7 @@ public class FilteringIterable<E1, E2>
* {@link #accept(Object)} method instead of building
* a {@link Filter}.
*/
- public FilteringIterable(Iterable<? extends E1> iterable) {
+ public FilteringIterable(Iterable<? extends E> iterable) {
super();
this.iterable = iterable;
this.filter = this.buildDefaultFilter();
@@ -53,18 +52,18 @@ public class FilteringIterable<E1, E2>
* Construct an iterable with the specified nested
* iterable and filter.
*/
- public FilteringIterable(Iterable<? extends E1> iterable, Filter<E1> filter) {
+ public FilteringIterable(Iterable<? extends E> iterable, Filter<E> filter) {
super();
this.iterable = iterable;
this.filter = filter;
}
- protected Filter<E1> buildDefaultFilter() {
+ protected Filter<E> buildDefaultFilter() {
return new DefaultFilter();
}
- public Iterator<E2> iterator() {
- return new FilteringIterator<E1, E2>(this.iterable.iterator(), this.filter);
+ public Iterator<E> iterator() {
+ return new FilteringIterator<E>(this.iterable.iterator(), this.filter);
}
/**
@@ -75,7 +74,7 @@ public class FilteringIterable<E1, E2>
* This method can be overridden by a subclass as an
* alternative to building a {@link Filter}.
*/
- protected boolean accept(@SuppressWarnings("unused") E1 o) {
+ protected boolean accept(@SuppressWarnings("unused") E o) {
throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
}
@@ -87,8 +86,8 @@ public class FilteringIterable<E1, E2>
//********** default filter **********
- protected class DefaultFilter implements Filter<E1> {
- public boolean accept(E1 o) {
+ protected class DefaultFilter implements Filter<E> {
+ public boolean accept(E o) {
return FilteringIterable.this.accept(o);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/StackIterable.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/StackIterable.java
index a1e18318ed..fe14746d97 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/StackIterable.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/StackIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -18,7 +18,7 @@ import org.eclipse.jpt.utility.internal.iterators.StackIterator;
/**
* A <code>StackIterable</code> provides an {@link Iterable}
* for a {@link Stack} of objects of type <code>E</code>. The stack's elements
- * are {@link Stack#pop() pop}ped" as the iterable's iterator returns
+ * are {@link Stack#pop() "popped"} as the iterable's iterator returns
* them with calls to {@link Iterator#next()}.
*
* @param <E> the type of elements returned by the iterable's iterator
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubIterableWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubIterableWrapper.java
new file mode 100644
index 0000000000..de91d46c31
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubIterableWrapper.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.internal.iterables;
+
+import java.util.Iterator;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterators.SubIteratorWrapper;
+
+/**
+ * Wrap an iterable of elements of type <code>E1</code>, converting it into an
+ * iterable of elements of type <code>E2</code>. Assume the wrapped iterable
+ * contains only elements of type <code>E2</code>.
+ *
+ * @param <E1> input: the type of elements contained by the wrapped iterable
+ * @param <E2> output: the type of elements returned by the iterable's iterator
+ *
+ * @see org.eclipse.jpt.utility.internal.iterators.SubIteratorWrapper
+ */
+public class SubIterableWrapper<E1, E2>
+ implements Iterable<E2>
+{
+ private final Iterable<E1> iterable;
+
+
+ public SubIterableWrapper(Iterable<E1> iterable) {
+ super();
+ this.iterable = iterable;
+ }
+
+ public Iterator<E2> iterator() {
+ return new SubIteratorWrapper<E1, E2>(this.iterable.iterator());
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.iterable);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubListIterableWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubListIterableWrapper.java
new file mode 100644
index 0000000000..8803323192
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SubListIterableWrapper.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.internal.iterables;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterators.SubListIteratorWrapper;
+
+/**
+ * Wrap a list iterable of elements of type <code>E1</code>, converting it into
+ * a list iterable of elements of type <code>E2</code>. Assume the wrapped
+ * iterable contains only elements of type <code>E2</code>.
+ *
+ * @param <E1> input: the type of elements contained by the wrapped list iterable
+ * @param <E2> output: the type of elements returned by the iterable's list iterator
+ *
+ * @see org.eclipse.jpt.utility.internal.iterators.SubListIteratorWrapper
+ */
+public class SubListIterableWrapper<E1, E2>
+ implements ListIterable<E2>
+{
+ private final ListIterable<E1> iterable;
+
+
+ public SubListIterableWrapper(List<E1> list) {
+ this(new ListListIterable<E1>(list));
+ }
+
+ public SubListIterableWrapper(ListIterable<E1> iterable) {
+ super();
+ this.iterable = iterable;
+ }
+
+ public ListIterator<E2> iterator() {
+ return new SubListIteratorWrapper<E1, E2>(this.iterable.iterator());
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.iterable);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/GenericIterableWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperIterableWrapper.java
index c3542e3b56..5f1e063635 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/GenericIterableWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperIterableWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2010 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.
@@ -19,15 +19,17 @@ import org.eclipse.jpt.utility.internal.StringTools;
* is no way to add invalid elements to the iterable.
*
* @param <E> the type of elements returned by the iterable's iterator
+ *
+ * @see org.eclipse.jpt.utility.internal.iterators.SuperIteratorWrapper
*/
-public class GenericIterableWrapper<E>
+public class SuperIterableWrapper<E>
implements Iterable<E>
{
private final Iterable<E> iterable;
@SuppressWarnings("unchecked")
- public GenericIterableWrapper(Iterable<? extends E> iterable) {
+ public SuperIterableWrapper(Iterable<? extends E> iterable) {
super();
// this should be a safe cast - the iterator will only ever
// return E (or a sub-type) from #next()
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperListIterableWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperListIterableWrapper.java
new file mode 100644
index 0000000000..db44b17f46
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterables/SuperListIterableWrapper.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.internal.iterables;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterators.SuperListIteratorWrapper;
+
+/**
+ * Wrap a list iterable of elements of any sub-type of <code>E</code>, converting it into a
+ * list iterable of elements of type <code>E</code>. This shouldn't be a problem since the
+ * resulting list iterable's list iterator disables the methods that would put invalid elements
+ * in the list iterator's backing list (i.e. {@link #set(E)} and {@link #add(E)}).
+ *
+ * @param <E> the type of elements returned by the iterable's iterators
+ *
+ * @see org.eclipse.jpt.utility.internal.iterators.SuperListIteratorWrapper
+ */
+public class SuperListIterableWrapper<E>
+ implements ListIterable<E>
+{
+ private final ListIterable<? extends E> iterable;
+
+
+ public <T extends E> SuperListIterableWrapper(List<T> list) {
+ this(new ListListIterable<T>(list));
+ }
+
+ public SuperListIterableWrapper(ListIterable<? extends E> iterable) {
+ super();
+ this.iterable = iterable;
+ }
+
+ public ListIterator<E> iterator() {
+ return new SuperListIteratorWrapper<E>(this.iterable.iterator());
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.iterable);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/CompositeListIterator.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/CompositeListIterator.java
index d7aed2533c..e1d3c7a63c 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/CompositeListIterator.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/CompositeListIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,8 @@ import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.ArrayListIterable;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
* A <code>CompositeListIterator</code> wraps a list
@@ -54,6 +56,20 @@ public class CompositeListIterator<E>
}
/**
+ * Construct a list iterator on the elements in the specified list of lists.
+ */
+ public CompositeListIterator(ListIterable<? extends ListIterable<E>> listIterables) {
+ this(
+ new TransformationListIterator<ListIterable<E>, ListIterator<E>>(listIterables.iterator()) {
+ @Override
+ protected ListIterator<E> transform(ListIterable<E> list) {
+ return list.iterator();
+ }
+ }
+ );
+ }
+
+ /**
* Construct a list iterator with the specified list of list iterators.
*/
public CompositeListIterator(ListIterator<? extends ListIterator<E>> iterators) {
@@ -73,6 +89,14 @@ public class CompositeListIterator<E>
/**
* Construct a list iterator with the specified object prepended
+ * to the specified list.
+ */
+ public CompositeListIterator(E object, ListIterable<E> listIterable) {
+ this(object, listIterable.iterator());
+ }
+
+ /**
+ * Construct a list iterator with the specified object prepended
* to the specified iterator.
*/
@SuppressWarnings("unchecked")
@@ -90,6 +114,14 @@ public class CompositeListIterator<E>
/**
* Construct a list iterator with the specified object appended
+ * to the specified list.
+ */
+ public CompositeListIterator(ListIterable<E> listIterable, E object) {
+ this(listIterable.iterator(), object);
+ }
+
+ /**
+ * Construct a list iterator with the specified object appended
* to the specified iterator.
*/
@SuppressWarnings("unchecked")
@@ -105,6 +137,13 @@ public class CompositeListIterator<E>
}
/**
+ * Construct a list iterator with the specified lists.
+ */
+ public CompositeListIterator(ListIterable<E>... listIterables) {
+ this(new ArrayListIterable<ListIterable<E>>(listIterables));
+ }
+
+ /**
* Construct a list iterator with the specified list iterators.
*/
public CompositeListIterator(ListIterator<E>... iterators) {
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/FilteringIterator.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/FilteringIterator.java
index 4f45947c5d..642b4a32df 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/FilteringIterator.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/FilteringIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -33,17 +33,16 @@ import org.eclipse.jpt.utility.internal.StringTools;
* This also prevents a filtered iterator from supporting the optional
* <code>remove()</code> method.
*
- * @param <E1> input: the type of elements to be filtered
- * @param <E2> output: the type of elements returned by the iterable's iterator
+ * @param <E> the type of elements to be filtered
*
* @see org.eclipse.jpt.utility.internal.iterables.FilteringIterable
*/
-public class FilteringIterator<E1, E2>
- implements Iterator<E2>
+public class FilteringIterator<E>
+ implements Iterator<E>
{
- private final Iterator<? extends E1> iterator;
- private final Filter<E1> filter;
- private E2 next;
+ private final Iterator<? extends E> iterator;
+ private final Filter<E> filter;
+ private E next;
private boolean done;
@@ -54,7 +53,7 @@ public class FilteringIterator<E1, E2>
* {@link #accept(Object)} method instead of building
* a {@link Filter}.
*/
- public FilteringIterator(Iterable<? extends E1> iterable) {
+ public FilteringIterator(Iterable<? extends E> iterable) {
this(iterable.iterator());
}
@@ -65,15 +64,15 @@ public class FilteringIterator<E1, E2>
* {@link #accept(Object)} method instead of building
* a {@link Filter}.
*/
- public FilteringIterator(Iterator<? extends E1> iterator) {
- this(iterator, Filter.Disabled.<E1>instance());
+ public FilteringIterator(Iterator<? extends E> iterator) {
+ this(iterator, Filter.Disabled.<E>instance());
}
/**
* Construct an iterator with the specified
* iterable and filter.
*/
- public FilteringIterator(Iterable<? extends E1> iterable, Filter<E1> filter) {
+ public FilteringIterator(Iterable<? extends E> iterable, Filter<E> filter) {
this(iterable.iterator(), filter);
}
@@ -81,7 +80,7 @@ public class FilteringIterator<E1, E2>
* Construct an iterator with the specified nested
* iterator and filter.
*/
- public FilteringIterator(Iterator<? extends E1> iterator, Filter<E1> filter) {
+ public FilteringIterator(Iterator<? extends E> iterator, Filter<E> filter) {
super();
this.iterator = iterator;
this.filter = filter;
@@ -92,11 +91,11 @@ public class FilteringIterator<E1, E2>
return ! this.done;
}
- public E2 next() {
+ public E next() {
if (this.done) {
throw new NoSuchElementException();
}
- E2 result = this.next;
+ E result = this.next;
this.loadNext();
return result;
}
@@ -117,10 +116,10 @@ public class FilteringIterator<E1, E2>
private void loadNext() {
this.done = true;
while (this.iterator.hasNext() && (this.done)) {
- E1 temp = this.iterator.next();
+ E temp = this.iterator.next();
if (this.accept(temp)) {
// assume that if the object was accepted it is of type E
- this.next = this.cast(temp);
+ this.next = temp;
this.done = false;
} else {
this.next = null;
@@ -130,15 +129,6 @@ public class FilteringIterator<E1, E2>
}
/**
- * We have to assume the filter will only "accept" objects that can
- * be cast to E2.
- */
- @SuppressWarnings("unchecked")
- private E2 cast(E1 o) {
- return (E2) o;
- }
-
- /**
* Return whether the {@link FilteringIterator}
* should return the specified next element from a call to the
* {@link #next()} method.
@@ -146,7 +136,7 @@ public class FilteringIterator<E1, E2>
* This method can be overridden by a subclass as an
* alternative to building a {@link Filter}.
*/
- protected boolean accept(E1 o) {
+ protected boolean accept(E o) {
return this.filter.accept(o);
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/ReadOnlyCompositeListIterator.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/ReadOnlyCompositeListIterator.java
index 0132928815..2ad79fd297 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/ReadOnlyCompositeListIterator.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/ReadOnlyCompositeListIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,8 @@ import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.ArrayListIterable;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
* A <code>ReadOnlyCompositeListIterator</code> wraps a list
@@ -50,6 +52,20 @@ public class ReadOnlyCompositeListIterator<E>
}
/**
+ * Construct a read-only list iterator with the specified list of lists.
+ */
+ public ReadOnlyCompositeListIterator(ListIterable<? extends ListIterable<? extends E>> listIterables) {
+ this(
+ new TransformationListIterator<ListIterable<? extends E>, ListIterator<? extends E>>(listIterables.iterator()) {
+ @Override
+ protected ListIterator<? extends E> transform(ListIterable<? extends E> listIterable) {
+ return listIterable.iterator();
+ }
+ }
+ );
+ }
+
+ /**
* Construct a read-only list iterator with the specified list of
* list iterators.
*/
@@ -69,6 +85,14 @@ public class ReadOnlyCompositeListIterator<E>
/**
* Construct a read-only list iterator with the specified object prepended
+ * to the specified list.
+ */
+ public ReadOnlyCompositeListIterator(E object, ListIterable<? extends E> listIterable) {
+ this(object, listIterable.iterator());
+ }
+
+ /**
+ * Construct a read-only list iterator with the specified object prepended
* to the specified iterator.
*/
@SuppressWarnings("unchecked")
@@ -86,6 +110,14 @@ public class ReadOnlyCompositeListIterator<E>
/**
* Construct a read-only list iterator with the specified object appended
+ * to the specified list.
+ */
+ public ReadOnlyCompositeListIterator(ListIterable<? extends E> listIterable, E object) {
+ this(listIterable.iterator(), object);
+ }
+
+ /**
+ * Construct a read-only list iterator with the specified object appended
* to the specified iterator.
*/
@SuppressWarnings("unchecked")
@@ -101,6 +133,13 @@ public class ReadOnlyCompositeListIterator<E>
}
/**
+ * Construct a read-only list iterator with the specified lists.
+ */
+ public ReadOnlyCompositeListIterator(ListIterable<? extends E>... listIterables) {
+ this(new ArrayListIterable<ListIterable<? extends E>>(listIterables));
+ }
+
+ /**
* Construct a read-only list iterator with the specified list iterators.
*/
public ReadOnlyCompositeListIterator(ListIterator<? extends E>... iterators) {
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubIteratorWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubIteratorWrapper.java
new file mode 100644
index 0000000000..eefcfccbb4
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubIteratorWrapper.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.internal.iterators;
+
+import java.util.Iterator;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+
+/**
+ * Wrap an iterator on elements of type <code>E1</code>, converting it into an
+ * iterator on elements of type <code>E2</code>. Assume the wrapped iterator
+ * returns only elements of type <code>E2</code>.
+ *
+ * @param <E1> input: the type of elements returned by the wrapped iterator
+ * @param <E2> output: the type of elements returned by the iterator
+ *
+ * @see org.eclipse.jpt.utility.internal.iterables.SubIterableWrapper
+ */
+public class SubIteratorWrapper<E1, E2>
+ implements Iterator<E2>
+{
+ private final Iterator<E1> iterator;
+
+
+ public SubIteratorWrapper(Iterable<E1> iterable) {
+ this(iterable.iterator());
+ }
+
+ public SubIteratorWrapper(Iterator<E1> iterator) {
+ super();
+ this.iterator = iterator;
+ }
+
+ public boolean hasNext() {
+ return this.iterator.hasNext();
+ }
+
+ @SuppressWarnings("unchecked")
+ public E2 next() {
+ return (E2) this.iterator.next();
+ }
+
+ public void remove() {
+ this.iterator.remove();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.iterator);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubListIteratorWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubListIteratorWrapper.java
new file mode 100644
index 0000000000..c9e5db72ef
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SubListIteratorWrapper.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.internal.iterators;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+
+/**
+ * Wrap a list iterator on elements of type <code>E1</code>, converting it into
+ * a list iterator on elements of type <code>E2</code>. Assume the wrapped
+ * list iterator returns only elements of type <code>E2</code>.
+ *
+ * @param <E1> input: the type of elements returned by the wrapped list iterator
+ * @param <E2> output: the type of elements returned by the list iterator
+ *
+ * @see org.eclipse.jpt.utility.internal.iterables.SubListIterableWrapper
+ */
+public class SubListIteratorWrapper<E1, E2>
+ implements ListIterator<E2>
+{
+ private final ListIterator<E1> listIterator;
+
+
+ public SubListIteratorWrapper(List<E1> list) {
+ this(list.listIterator());
+ }
+
+ public SubListIteratorWrapper(ListIterable<E1> listIterable) {
+ this(listIterable.iterator());
+ }
+
+ public SubListIteratorWrapper(ListIterator<E1> iterator) {
+ super();
+ this.listIterator = iterator;
+ }
+
+ public boolean hasNext() {
+ return this.listIterator.hasNext();
+ }
+
+ @SuppressWarnings("unchecked")
+ public E2 next() {
+ return (E2) this.listIterator.next();
+ }
+
+ public int nextIndex() {
+ return this.listIterator.nextIndex();
+ }
+
+ public boolean hasPrevious() {
+ return this.listIterator.hasPrevious();
+ }
+
+ @SuppressWarnings("unchecked")
+ public E2 previous() {
+ return (E2) this.listIterator.previous();
+ }
+
+ public int previousIndex() {
+ return this.listIterator.previousIndex();
+ }
+
+ public void remove() {
+ this.listIterator.remove();
+ }
+
+ public void set(E2 e) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(E2 e) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.listIterator);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/GenericIteratorWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SuperIteratorWrapper.java
index 0e6832466e..52fd5f632e 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/GenericIteratorWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SuperIteratorWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -19,19 +19,19 @@ import org.eclipse.jpt.utility.internal.StringTools;
*
* @param <E> the type of elements returned by the iterator
*
- * @see org.eclipse.jpt.utility.internal.iterables.GenericIterableWrapper
+ * @see org.eclipse.jpt.utility.internal.iterables.SuperIterableWrapper
*/
-public class GenericIteratorWrapper<E>
+public class SuperIteratorWrapper<E>
implements Iterator<E>
{
private final Iterator<? extends E> iterator;
- public GenericIteratorWrapper(Iterable<? extends E> iterable) {
+ public SuperIteratorWrapper(Iterable<? extends E> iterable) {
this(iterable.iterator());
}
- public GenericIteratorWrapper(Iterator<? extends E> iterator) {
+ public SuperIteratorWrapper(Iterator<? extends E> iterator) {
super();
this.iterator = iterator;
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/GenericListIteratorWrapper.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SuperListIteratorWrapper.java
index 2816055d64..c3817ac076 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/GenericListIteratorWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SuperListIteratorWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import java.util.List;
import java.util.ListIterator;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
* Wrap a list iterator on elements of any sub-type of <code>E</code>, converting it into a
@@ -22,19 +23,23 @@ import org.eclipse.jpt.utility.internal.StringTools;
*
* @param <E> the type of elements returned by the iterator
*
- * @see org.eclipse.jpt.utility.internal.iterables.GenericListIterableWrapper
+ * @see org.eclipse.jpt.utility.internal.iterables.SuperListIterableWrapper
*/
-public class GenericListIteratorWrapper<E>
+public class SuperListIteratorWrapper<E>
implements ListIterator<E>
{
private final ListIterator<? extends E> listIterator;
- public GenericListIteratorWrapper(List<? extends E> list) {
+ public SuperListIteratorWrapper(List<? extends E> list) {
this(list.listIterator());
}
- public GenericListIteratorWrapper(ListIterator<? extends E> listIterator) {
+ public SuperListIteratorWrapper(ListIterable<? extends E> listIterable) {
+ this(listIterable.iterator());
+ }
+
+ public SuperListIteratorWrapper(ListIterator<? extends E> listIterator) {
super();
this.listIterator = listIterator;
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SynchronizedListIterator.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SynchronizedListIterator.java
index bd40787285..d3ffc94c9f 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SynchronizedListIterator.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/SynchronizedListIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import java.util.List;
import java.util.ListIterator;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
* Wrap a list iterator and synchronize all its methods so it can be safely shared
@@ -37,6 +38,14 @@ public class SynchronizedListIterator<E>
this(list.listIterator(), mutex);
}
+ public SynchronizedListIterator(ListIterable<E> listIterable) {
+ this(listIterable.iterator());
+ }
+
+ public SynchronizedListIterator(ListIterable<E> listIterable, Object mutex) {
+ this(listIterable.iterator(), mutex);
+ }
+
public SynchronizedListIterator(ListIterator<E> listIterator) {
super();
this.listIterator = listIterator;
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/TransformationListIterator.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/TransformationListIterator.java
index b6935a6f7e..358cf6a3c4 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/TransformationListIterator.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/iterators/TransformationListIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -11,8 +11,10 @@ package org.eclipse.jpt.utility.internal.iterators;
import java.util.List;
import java.util.ListIterator;
+
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.Transformer;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
* A <code>TransformationListIterator</code> wraps another {@link ListIterator}
@@ -58,6 +60,17 @@ public class TransformationListIterator<E1, E2>
}
/**
+ * Construct an iterator with the specified list
+ * and a disabled transformer.
+ * Use this constructor if you want to override the
+ * {@link #transform(Object)} method instead of building
+ * a {@link Transformer}.
+ */
+ public TransformationListIterator(ListIterable<? extends E1> listIterable) {
+ this(listIterable.iterator());
+ }
+
+ /**
* Construct an iterator with the specified list and transformer.
*/
public TransformationListIterator(List<? extends E1> list, Transformer<E1, ? extends E2> transformer) {
@@ -65,6 +78,13 @@ public class TransformationListIterator<E1, E2>
}
/**
+ * Construct an iterator with the specified list and transformer.
+ */
+ public TransformationListIterator(ListIterable<? extends E1> listIterable, Transformer<E1, ? extends E2> transformer) {
+ this(listIterable.iterator(), transformer);
+ }
+
+ /**
* Construct an iterator with the specified nested iterator
* and transformer.
*/
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringCollectionValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringCollectionValueModel.java
index 0529dc5214..b7a2884a11 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringCollectionValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -159,7 +159,7 @@ public class FilteringCollectionValueModel<E>
* Return an iterable that filters the specified iterable.
*/
protected Iterable<E> filter(Iterable<? extends E> items) {
- return new FilteringIterable<E, E>(items, this.filter);
+ return new FilteringIterable<E>(items, this.filter);
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullCollectionValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullCollectionValueModel.java
index e09907451d..0ac493105c 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullCollectionValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.utility.internal.model.value;
import java.util.Iterator;
-import org.eclipse.jpt.utility.internal.ClassTools;
+
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.model.value.CollectionValueModel;
@@ -52,7 +52,7 @@ public final class NullCollectionValueModel<E>
@Override
public String toString() {
- return ClassTools.shortClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullListValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullListValueModel.java
index 6035baa11f..35a46b045d 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullListValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullListValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.utility.internal.model.value;
import java.util.Iterator;
import java.util.ListIterator;
-import org.eclipse.jpt.utility.internal.ClassTools;
+
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
@@ -65,7 +65,7 @@ public final class NullListValueModel<E>
@Override
public String toString() {
- return ClassTools.shortClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullPropertyValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullPropertyValueModel.java
index bf0483d50d..500f176ec0 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullPropertyValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.utility.internal.model.value;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
@@ -44,7 +43,7 @@ public final class NullPropertyValueModel<T>
@Override
public String toString() {
- return ClassTools.shortClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullTreeValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullTreeValueModel.java
index 1b0ba72738..fbcc8b1bbd 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullTreeValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/NullTreeValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.utility.internal.model.value;
import java.util.Iterator;
-import org.eclipse.jpt.utility.internal.ClassTools;
+
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.model.value.TreeValueModel;
@@ -46,7 +46,7 @@ public final class NullTreeValueModel<E>
@Override
public String toString() {
- return ClassTools.shortClassNameForObject(this);
+ return this.getClass().getSimpleName();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/node/AbstractNode.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/node/AbstractNode.java
index ffe6f6b9e2..3dd54dec6c 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/node/AbstractNode.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/node/AbstractNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -641,7 +641,7 @@ public abstract class AbstractNode
* Only really used for testing and debugging.
*/
public final Iterator<Node> allDirtyNodes() {
- return new FilteringIterator<Node, Node>(this.allNodes()) {
+ return new FilteringIterator<Node>(this.allNodes()) {
@Override
protected boolean accept(Node node) {
return (node instanceof AbstractNode) && ((AbstractNode) node).isDirty();
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ComboBoxTableCellRenderer.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ComboBoxTableCellRenderer.java
index 55d8d1f9a0..622ed6d10e 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ComboBoxTableCellRenderer.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ComboBoxTableCellRenderer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -26,7 +26,7 @@ import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
/**
* Make the cell look like a combo-box.
@@ -176,7 +176,7 @@ public class ComboBoxTableCellRenderer implements TableCellEditorAdapter.Rendere
private JList getListBox(JComboBox result) {
- return (JList) ClassTools.fieldValue(result.getUI(), "listBox");
+ return (JList) ReflectionTools.getFieldValue(result.getUI(), "listBox");
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ListChooser.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ListChooser.java
index f851b0060d..600652ea49 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ListChooser.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/swing/ListChooser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -31,7 +31,7 @@ import javax.swing.SwingConstants;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.basic.BasicComboBoxUI;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
/**
* This component provides a way to handle selecting an item from a
@@ -116,7 +116,7 @@ public class ListChooser
private JList listBox() {
- return (JList) ClassTools.fieldValue(this.ui, "listBox"); //$NON-NLS-1$
+ return (JList) ReflectionTools.getFieldValue(this.ui, "listBox"); //$NON-NLS-1$
}
/**
@@ -213,7 +213,7 @@ public class ListChooser
private void updateArrowButton() {
try {
BasicComboBoxUI comboBoxUi = (BasicComboBoxUI) ListChooser.this.getUI();
- JButton arrowButton = (JButton) ClassTools.fieldValue(comboBoxUi, "arrowButton"); //$NON-NLS-1$
+ JButton arrowButton = (JButton) ReflectionTools.getFieldValue(comboBoxUi, "arrowButton"); //$NON-NLS-1$
arrowButton.setEnabled(this.isEnabled() && this.choosable);
}
catch (Exception e) {
@@ -387,7 +387,7 @@ public class ListChooser
private void checkComboBoxButton() {
try {
BasicComboBoxUI comboBoxUi = (BasicComboBoxUI) ListChooser.this.getUI();
- JButton arrowButton = (JButton) ClassTools.fieldValue(comboBoxUi, "arrowButton"); //$NON-NLS-1$
+ JButton arrowButton = (JButton) ReflectionTools.getFieldValue(comboBoxUi, "arrowButton"); //$NON-NLS-1$
arrowButton.getModel().setPressed(false);
}
catch (Exception ex) {
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/MultiMethodReflectiveChangeListener.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/MultiMethodReflectiveChangeListener.java
index b862807b44..5dbdd8f904 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/MultiMethodReflectiveChangeListener.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/MultiMethodReflectiveChangeListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.utility.model.listener;
import java.lang.reflect.Method;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.utility.model.event.CollectionClearEvent;
@@ -73,9 +73,9 @@ class MultiMethodReflectiveChangeListener
private void invoke(Method method, CollectionEvent event) {
if (method.getParameterTypes().length == 0) {
- ClassTools.executeMethod(method, this.target, EMPTY_OBJECT_ARRAY);
+ ReflectionTools.executeMethod(method, this.target, EMPTY_OBJECT_ARRAY);
} else {
- ClassTools.executeMethod(method, this.target, new CollectionEvent[] {event});
+ ReflectionTools.executeMethod(method, this.target, new CollectionEvent[] {event});
}
}
@@ -100,9 +100,9 @@ class MultiMethodReflectiveChangeListener
private void invoke(Method method, ListEvent event) {
if (method.getParameterTypes().length == 0) {
- ClassTools.executeMethod(method, this.target, EMPTY_OBJECT_ARRAY);
+ ReflectionTools.executeMethod(method, this.target, EMPTY_OBJECT_ARRAY);
} else {
- ClassTools.executeMethod(method, this.target, new ListEvent[] {event});
+ ReflectionTools.executeMethod(method, this.target, new ListEvent[] {event});
}
}
@@ -135,9 +135,9 @@ class MultiMethodReflectiveChangeListener
private void invoke(Method method, TreeEvent event) {
if (method.getParameterTypes().length == 0) {
- ClassTools.executeMethod(method, this.target, EMPTY_OBJECT_ARRAY);
+ ReflectionTools.executeMethod(method, this.target, EMPTY_OBJECT_ARRAY);
} else {
- ClassTools.executeMethod(method, this.target, new TreeEvent[] {event});
+ ReflectionTools.executeMethod(method, this.target, new TreeEvent[] {event});
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/ReflectiveChangeListener.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/ReflectiveChangeListener.java
index d4c362f0b8..4840d56ac7 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/ReflectiveChangeListener.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/ReflectiveChangeListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.utility.model.listener;
import java.lang.reflect.Method;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.model.event.ChangeEvent;
import org.eclipse.jpt.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.utility.model.event.CollectionChangeEvent;
@@ -144,17 +144,11 @@ public abstract class ReflectiveChangeListener {
* reflectively when a change event occurs.
*/
private static Method findChangeListenerMethod(Object target, String methodName, Class<? extends ChangeEvent>[] eventClassArray) {
- Method method;
try {
- method = ClassTools.method(target, methodName, eventClassArray);
- } catch (NoSuchMethodException ex1) {
- try {
- method = ClassTools.method(target, methodName);
- } catch (NoSuchMethodException ex2) {
- throw new RuntimeException(ex2); // "checked" exceptions bite
- }
+ return ReflectionTools.getMethod(target, methodName, eventClassArray);
+ } catch (RuntimeException ex1) {
+ return ReflectionTools.getMethod(target, methodName);
}
- return method;
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/SingleMethodReflectiveChangeListener.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/SingleMethodReflectiveChangeListener.java
index f0d8583410..4d085431e0 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/SingleMethodReflectiveChangeListener.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/model/listener/SingleMethodReflectiveChangeListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.utility.model.listener;
import java.lang.reflect.Method;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.model.event.StateChangeEvent;
@@ -40,9 +40,9 @@ class SingleMethodReflectiveChangeListener
public void stateChanged(StateChangeEvent event) {
if (this.methodIsZeroArgument) {
- ClassTools.executeMethod(this.method, this.target, EMPTY_OBJECT_ARRAY);
+ ReflectionTools.executeMethod(this.method, this.target, EMPTY_OBJECT_ARRAY);
} else {
- ClassTools.executeMethod(this.method, this.target, new StateChangeEvent[] {event});
+ ReflectionTools.executeMethod(this.method, this.target, new StateChangeEvent[] {event});
}
}
@@ -51,9 +51,9 @@ class SingleMethodReflectiveChangeListener
public void propertyChanged(PropertyChangeEvent event) {
if (this.methodIsZeroArgument) {
- ClassTools.executeMethod(this.method, this.target, EMPTY_OBJECT_ARRAY);
+ ReflectionTools.executeMethod(this.method, this.target, EMPTY_OBJECT_ARRAY);
} else {
- ClassTools.executeMethod(this.method, this.target, new PropertyChangeEvent[] {event});
+ ReflectionTools.executeMethod(this.method, this.target, new PropertyChangeEvent[] {event});
}
}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java
index c0ed65148e..4374e5d207 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.core.tests;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jpt.core.JpaModel;
import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.osgi.framework.BundleContext;
/**
@@ -45,8 +45,8 @@ public class JptCoreTestsPlugin extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
JpaModel jpaModel = JptCorePlugin.getJpaModel();
- ClassTools.executeMethod(jpaModel, "handleEventsSynchronously");
- ClassTools.executeStaticMethod(JptCorePlugin.class, "doNotFlushPreferences");
+ ReflectionTools.executeMethod(jpaModel, "handleEventsSynchronously");
+ ReflectionTools.executeStaticMethod(JptCorePlugin.class, "doNotFlushPreferences");
}
@Override
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java
index b61c3c3559..a62eed9555 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -37,7 +37,7 @@ import org.eclipse.jpt.core.resource.persistence.PersistenceFactory;
import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef;
import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase;
import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
@SuppressWarnings("nls")
public class GenericOrmPersistentTypeTests extends ContextModelTestCase
@@ -572,6 +572,6 @@ public class GenericOrmPersistentTypeTests extends ContextModelTestCase
assertNotNull(javaPersistentAttribute);
assertEquals("id", javaPersistentAttribute.getName());
assertEquals("test.Employee", javaPersistentAttribute.getPersistentType().getName());
- assertEquals("test.Model", ((JavaResourcePersistentType) ClassTools.fieldValue(javaPersistentAttribute.getResourcePersistentAttribute(), "parent")).getQualifiedName());
+ assertEquals("test.Model", ((JavaResourcePersistentType) ReflectionTools.getFieldValue(javaPersistentAttribute.getResourcePersistentAttribute(), "parent")).getQualifiedName());
}
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java
index 11dbf5bea2..89a7b2f764 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -24,7 +24,7 @@ import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider;
import org.eclipse.jpt.core.tests.internal.projects.TestFacetedProject;
import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject;
import org.eclipse.jpt.core.tests.internal.projects.TestPlatformProject;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
@@ -49,7 +49,7 @@ public class JpaModelTests extends TestCase {
}
private boolean debug() {
- Boolean debug = (Boolean) ClassTools.staticFieldValue(this.getGenericJpaModelClass(), "DEBUG");
+ Boolean debug = (Boolean) ReflectionTools.getStaticFieldValue(this.getGenericJpaModelClass(), "DEBUG");
return debug.booleanValue();
}
@@ -86,7 +86,7 @@ public class JpaModelTests extends TestCase {
* pre-existing entities added.
*/
private TestFacetedProject buildTestProject() throws Exception {
- TestJavaProject tjp = TestJavaProject.buildJavaProject(ClassTools.shortClassNameForObject(this), true);
+ TestJavaProject tjp = TestJavaProject.buildJavaProject(this.getClass().getSimpleName(), true);
tjp.installFacet("jst.utility", "1.0");
tjp.createCompilationUnit("test.pkg", "TestEntity.java", "@Entity public class TestEntity {}");
tjp.createCompilationUnit("test.pkg", "TestEntity2.java", "@Entity public class TestEntity2 {}");
@@ -106,7 +106,7 @@ public class JpaModelTests extends TestCase {
private void verifyDEBUG(Class<?> clazz) {
assertFalse("Recompile with \"DEBUG = false\": " + clazz.getName(),
- ((Boolean) ClassTools.staticFieldValue(clazz, "DEBUG")).booleanValue());
+ ((Boolean) ReflectionTools.getStaticFieldValue(clazz, "DEBUG")).booleanValue());
}
public void testJpaModel() {
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java
index 0222496823..f98ccc9d00 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -27,7 +27,7 @@ import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject;
import org.eclipse.jpt.core.tests.internal.utility.jdt.AnnotationTestCase;
import org.eclipse.jpt.utility.CommandExecutor;
import org.eclipse.jpt.utility.internal.BitTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.StringTools;
@SuppressWarnings("nls")
@@ -145,7 +145,7 @@ public class JavaResourceModelTestCase extends AnnotationTestCase
}
protected JavaResourcePersistentType hackJavaResourcePersistentType() {
- return (JavaResourcePersistentType) ClassTools.fieldValue(this.javaResourceCompilationUnit, "persistentType");
+ return (JavaResourcePersistentType) ReflectionTools.getFieldValue(this.javaResourceCompilationUnit, "persistentType");
}
protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) {
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java
index d28312112f..9c7cc16d0a 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -32,7 +32,7 @@ import org.eclipse.jpt.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.core.resource.java.OneToManyAnnotation;
import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.core.utility.jdt.Member.Editor;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@@ -764,7 +764,7 @@ public class JavaResourcePersistentAttributeTests extends JavaResourceModelTestC
ICompilationUnit cu = createTestEntityWithNonResolvingField();
JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
@SuppressWarnings("unchecked")
- List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ClassTools.fieldValue(typeResource, "fields");
+ List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ReflectionTools.getFieldValue(typeResource, "fields");
JavaResourcePersistentAttribute attributeResource = attributes.get(0);
assertEquals("foo", attributeResource.getName());
@@ -780,7 +780,7 @@ public class JavaResourcePersistentAttributeTests extends JavaResourceModelTestC
ICompilationUnit cu = createTestEntityWithNonResolvingField();
JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
@SuppressWarnings("unchecked")
- List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ClassTools.fieldValue(typeResource, "fields");
+ List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ReflectionTools.getFieldValue(typeResource, "fields");
JavaResourcePersistentAttribute attributeResource = attributes.get(0);
assertEquals("foo", attributeResource.getName());
@@ -805,7 +805,7 @@ public class JavaResourcePersistentAttributeTests extends JavaResourceModelTestC
ICompilationUnit cu = createTestEntityWithNonResolvingMethod();
JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
@SuppressWarnings("unchecked")
- List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ClassTools.fieldValue(typeResource, "methods");
+ List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ReflectionTools.getFieldValue(typeResource, "methods");
JavaResourcePersistentAttribute attributeResource = attributes.get(0);
assertEquals("foo", attributeResource.getName());
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java
index e3e909794a..da48f337ea 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -10,8 +10,9 @@
package org.eclipse.jpt.core.tests.internal.utility.jdt;
import org.eclipse.jpt.core.internal.utility.jdt.DefaultAnnotationEditFormatter;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
+@SuppressWarnings("nls")
public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase {
@@ -51,7 +52,7 @@ public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase {
}
private int commaLength(String s) {
- Integer len = (Integer) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "commaLength", String.class, s);
+ Integer len = (Integer) ReflectionTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "commaLength", String.class, s);
return len.intValue();
}
@@ -67,7 +68,7 @@ public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase {
}
private boolean stringIsAnnotation(String s) {
- Boolean b = (Boolean) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "stringIsAnnotation", String.class, s);
+ Boolean b = (Boolean) ReflectionTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "stringIsAnnotation", String.class, s);
return b.booleanValue();
}
diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java
index ea25a8592d..93a577956c 100644
--- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java
+++ b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 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.
@@ -57,7 +57,7 @@ import org.eclipse.jpt.db.Sequence;
import org.eclipse.jpt.db.Table;
import org.eclipse.jpt.db.ForeignKey.ColumnPair;
import org.eclipse.jpt.db.tests.internal.JptDbTestsPlugin;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.IndentingPrintWriter;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterators.ResultSetIterator;
@@ -592,7 +592,7 @@ public abstract class DTPPlatformTests extends TestCase {
}
protected static boolean connectionProfileHasAnyListeners(ConnectionProfile cp) {
- return ((Boolean) ClassTools.executeMethod(cp, "hasAnyListeners")).booleanValue();
+ return ((Boolean) ReflectionTools.executeMethod(cp, "hasAnyListeners")).booleanValue();
}
protected boolean connectionProfileHasNoListeners() {
@@ -600,7 +600,7 @@ public abstract class DTPPlatformTests extends TestCase {
}
protected static boolean connectionProfileHasNoListeners(ConnectionProfile cp) {
- return ((Boolean) ClassTools.executeMethod(cp, "hasNoListeners")).booleanValue();
+ return ((Boolean) ReflectionTools.executeMethod(cp, "hasNoListeners")).booleanValue();
}
@@ -615,11 +615,11 @@ public abstract class DTPPlatformTests extends TestCase {
}
protected static IConnectionProfile getDTPConnectionProfile(ConnectionProfile cp) {
- return (IConnectionProfile) ClassTools.fieldValue(cp, "dtpConnectionProfile");
+ return (IConnectionProfile) ReflectionTools.getFieldValue(cp, "dtpConnectionProfile");
}
protected IManagedConnection getDTPManagedConnection() {
- return (IManagedConnection) ClassTools.fieldValue(this.connectionProfile, "dtpManagedConnection");
+ return (IManagedConnection) ReflectionTools.getFieldValue(this.connectionProfile, "dtpManagedConnection");
}
protected org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase() {
@@ -627,7 +627,7 @@ public abstract class DTPPlatformTests extends TestCase {
}
protected static org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase(Database database) {
- return (org.eclipse.datatools.modelbase.sql.schema.Database) ClassTools.fieldValue(database, "dtpDatabase");
+ return (org.eclipse.datatools.modelbase.sql.schema.Database) ReflectionTools.getFieldValue(database, "dtpDatabase");
}
@SuppressWarnings("unchecked")
@@ -644,7 +644,7 @@ public abstract class DTPPlatformTests extends TestCase {
}
protected static org.eclipse.datatools.modelbase.sql.schema.Catalog getDTPCatalog(Catalog catalog) {
- return (org.eclipse.datatools.modelbase.sql.schema.Catalog) ClassTools.fieldValue(catalog, "dtpCatalog");
+ return (org.eclipse.datatools.modelbase.sql.schema.Catalog) ReflectionTools.getFieldValue(catalog, "dtpCatalog");
}
protected org.eclipse.datatools.modelbase.sql.schema.Schema getDTPSchemaNamed(String name) {
@@ -652,7 +652,7 @@ public abstract class DTPPlatformTests extends TestCase {
}
protected static org.eclipse.datatools.modelbase.sql.schema.Schema getDTPSchema(Schema schema) {
- return (org.eclipse.datatools.modelbase.sql.schema.Schema) ClassTools.fieldValue(schema, "dtpSchema");
+ return (org.eclipse.datatools.modelbase.sql.schema.Schema) ReflectionTools.getFieldValue(schema, "dtpSchema");
}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java
index d0ace3e69a..47e8fc281c 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -31,7 +31,6 @@ import org.eclipse.jpt.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory;
import org.eclipse.jpt.ui.jface.TreeItemContentProvider;
import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.NullCollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
@@ -83,7 +82,7 @@ public class DelegatingLabelProviderUiTest extends ApplicationWindow
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(400, 400);
parent.setLayout(new GridLayout());
Composite mainPanel = new Composite(parent, SWT.NONE);
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java
index 19ac671230..96460f58f1 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
@@ -31,7 +32,6 @@ import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider;
import org.eclipse.jpt.ui.jface.TreeItemContentProvider;
import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
import org.eclipse.jpt.utility.internal.iterators.ReadOnlyListIterator;
@@ -45,7 +45,6 @@ import org.eclipse.jpt.utility.internal.model.value.StaticCollectionValueModel;
import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.swt.SWT;
@@ -59,6 +58,7 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+@SuppressWarnings("nls")
public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
{
private final Root root;
@@ -89,7 +89,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(800, 400);
parent.setLayout(new GridLayout());
Composite mainPanel = new Composite(parent, SWT.NONE);
@@ -286,7 +286,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static abstract class AbstractTreeItemContentProviderFactory
+ static abstract class AbstractTreeItemContentProviderFactory
implements TreeItemContentProviderFactory
{
public TreeItemContentProvider buildItemContentProvider(
@@ -297,13 +297,13 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class ControlTreeItemContentProviderFactory extends AbstractTreeItemContentProviderFactory
+ static class ControlTreeItemContentProviderFactory extends AbstractTreeItemContentProviderFactory
{
}
- private static class ViewTreeItemContentProviderFactory
+ static class ViewTreeItemContentProviderFactory
extends AbstractTreeItemContentProviderFactory
{
@Override
@@ -318,7 +318,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class GenericTreeItemContentProvider extends AbstractTreeItemContentProvider<TreeNode>
+ static class GenericTreeItemContentProvider extends AbstractTreeItemContentProvider<TreeNode>
{
public GenericTreeItemContentProvider(
TreeNode treeNode, DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider) {
@@ -346,7 +346,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
}
- private static class ViewTreeParentItemContentProvider extends GenericTreeItemContentProvider
+ static class ViewTreeParentItemContentProvider extends GenericTreeItemContentProvider
{
public ViewTreeParentItemContentProvider(
TreeNode treeNode, DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider) {
@@ -385,7 +385,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class LabelProvider extends BaseLabelProvider
+ static class LabelProvider extends BaseLabelProvider
implements ILabelProvider
{
public Image getImage(Object element) {
@@ -398,7 +398,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static abstract class TreeNode extends AbstractModel
+ static abstract class TreeNode extends AbstractModel
{
private TreeNode parent;
@@ -468,7 +468,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class Root extends TreeNode
+ static class Root extends TreeNode
{
public Root() {
super(null, null);
@@ -486,7 +486,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class Parent extends TreeNode
+ static class Parent extends TreeNode
{
public Parent(TreeNode parent, String name) {
super(parent, name);
@@ -515,7 +515,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
public Iterator<Child> nestlessChildren() {
- return new FilteringIterator<Child, Child>(
+ return new FilteringIterator<Child>(
new TransformationIterator<TreeNode, Child>(children()) {
@Override
protected Child transform(TreeNode next) {
@@ -534,7 +534,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class Nest extends TreeNode
+ static class Nest extends TreeNode
{
public Nest(TreeNode parent) {
super(parent, "nest");
@@ -557,7 +557,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
}
- private static class Child extends TreeNode
+ static class Child extends TreeNode
{
public Child(TreeNode parent, String name) {
super(parent, name);
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TextFieldModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TextFieldModelAdapterUITest.java
index 6f812805de..dfba51b8aa 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TextFieldModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TextFieldModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,7 +15,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.ui.internal.swt.TextFieldModelAdapter;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
@@ -89,7 +88,7 @@ public class TextFieldModelAdapterUITest
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(400, 100);
Composite mainPanel = new Composite(parent, SWT.NONE);
mainPanel.setLayout(new FormLayout());
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TriStateCheckBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TriStateCheckBoxModelAdapterUITest.java
index 80b8840a85..3993af3570 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TriStateCheckBoxModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/TriStateCheckBoxModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -17,7 +17,6 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jpt.ui.internal.swt.TriStateCheckBoxModelAdapter;
import org.eclipse.jpt.ui.internal.widgets.DefaultWidgetFactory;
import org.eclipse.jpt.ui.internal.widgets.TriStateCheckBox;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
@@ -105,7 +104,7 @@ public class TriStateCheckBoxModelAdapterUITest
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(400, 100);
Composite mainPanel = new Composite(parent, SWT.NONE);
mainPanel.setLayout(new FormLayout());
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java
index eccd44e811..a0317832bb 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,7 @@ import static org.junit.Assert.*;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jpt.ui.internal.util.ControlAligner;
import org.eclipse.jpt.ui.internal.util.SWTUtil;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
@@ -448,9 +448,9 @@ public final class ControlAlignerTest {
assertEquals(newLabelWidth1, controlAligner.getMaximumWidth());
// Make sure all the locked are removed
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner2, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner3, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner2, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner3, "locked"), Boolean.FALSE);
// Change the text of label2
label2.setText("mm");
@@ -466,9 +466,9 @@ public final class ControlAlignerTest {
assertEquals(newLabelWidth2, newLabelWidth3);
assertEquals(newLabelWidth1, controlAligner.getMaximumWidth());
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner2, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner3, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner2, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner3, "locked"), Boolean.FALSE);
// Change the text of label1
label1.setText("a");
@@ -494,9 +494,9 @@ public final class ControlAlignerTest {
assertEquals(newLabelWidth1, controlAligner.getMaximumWidth());
assertFalse(newLabelWidth1 == realWidth);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner2, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner3, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner2, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner3, "locked"), Boolean.FALSE);
// Change the text of label1
label1.setText("Yes another big long long text so that all the labels will have to take the size of this label to make sure ControlAligner works correctly");
@@ -528,9 +528,9 @@ public final class ControlAlignerTest {
assertEquals(controlAligner.getMaximumWidth(), newLabelWidth1);
assertEquals(realWidth, newLabelWidth1);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner2, "locked"), Boolean.FALSE);
- assertEquals(ClassTools.attemptToGetFieldValue(controlAligner3, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner2, "locked"), Boolean.FALSE);
+ assertEquals(ReflectionTools.getFieldValue_(controlAligner3, "locked"), Boolean.FALSE);
}
@Test
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java
index 658ce0b09d..c124f603f6 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.ui.tests.internal.util;
import static org.junit.Assert.*;
import org.eclipse.jpt.ui.internal.util.ControlSwitcher;
import org.eclipse.jpt.ui.internal.util.SWTUtil;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.Transformer;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.swt.SWT;
@@ -126,7 +126,7 @@ public final class ControlSwitcherTest {
// Test 1
switchHolder.setValue(true);
- Control control = (Control) ClassTools.fieldValue(pageBook, "currentPage");
+ Control control = (Control) ReflectionTools.getFieldValue(pageBook, "currentPage");
assertNotNull(
"The page book's page shouldn't be null",
@@ -156,7 +156,7 @@ public final class ControlSwitcherTest {
// Test 2
switchHolder.setValue(false);
- control = (Control) ClassTools.fieldValue(pageBook, "currentPage");
+ control = (Control) ReflectionTools.getFieldValue(pageBook, "currentPage");
assertNotNull(
"The page book's page shouldn't be null",
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java
index 021ed469d8..cfb42b41a7 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,7 +15,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.ui.internal.utility.swt.SWTTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
@@ -75,7 +74,7 @@ public class BooleanStateControllerUITest
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(500, 100);
Composite mainPanel = new Composite(parent, SWT.NONE);
mainPanel.setLayout(new FormLayout());
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java
index 6e19b6725c..e6f232c4e0 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,7 +15,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.ui.internal.utility.swt.SWTTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
@@ -105,7 +104,7 @@ public class CheckBoxModelBindingUITest
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(400, 100);
Composite mainPanel = new Composite(parent, SWT.NONE);
mainPanel.setLayout(new FormLayout());
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java
index 1f1346c7ae..15f31aa182 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.ui.internal.utility.swt.SWTTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
@@ -78,7 +77,7 @@ public class DropDownListBoxModelBindingUITest
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(800, 300);
Composite mainPanel = new Composite(parent, SWT.NONE);
mainPanel.setLayout(new FormLayout());
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java
index 77cad5d9e1..ff19beb19b 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -24,7 +24,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.ui.internal.utility.swt.SWTTools;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter;
@@ -82,7 +81,7 @@ public class ListBoxModelBindingUITest
@Override
protected Control createContents(Composite parent) {
- ((Shell) parent).setText(ClassTools.shortClassNameForObject(this));
+ ((Shell) parent).setText(this.getClass().getSimpleName());
parent.setSize(800, 400);
Composite mainPanel = new Composite(parent, SWT.NONE);
mainPanel.setLayout(new FormLayout());
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ArrayToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ArrayToolsTests.java
index 3e94c216b2..5fffd9c88b 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ArrayToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ArrayToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -20,6 +21,7 @@ import java.util.Vector;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.ArrayTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.Range;
import org.eclipse.jpt.utility.internal.ReverseComparator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
@@ -2855,8 +2857,8 @@ public class ArrayToolsTests extends TestCase {
public void testFillBooleanArrayBoolean() {
boolean[] a1 = new boolean[9];
boolean[] a2 = ArrayTools.fill(a1, true);
- for (boolean b : a1) {
- assertTrue(b);
+ for (boolean x : a1) {
+ assertTrue(x);
}
assertSame(a1, a2);
}
@@ -2868,18 +2870,583 @@ public class ArrayToolsTests extends TestCase {
int to = 6;
boolean[] a3 = ArrayTools.fill(a2, from, to, true);
for (int i = 0; i < a1.length; i++) {
- boolean b = a1[i];
+ boolean x = a1[i];
if (i < from || i >= to) {
- assertFalse(b);
+ assertFalse(x);
} else {
- assertTrue(b);
+ assertTrue(x);
}
}
assertSame(a1, a2);
assertSame(a1, a3);
}
- // TODO
+ public void testFillByteArrayByte() {
+ byte[] a1 = new byte[9];
+ byte[] a2 = ArrayTools.fill(a1, (byte) 77);
+ for (byte x : a1) {
+ assertEquals(77, x);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillByteArrayIntIntByte() {
+ byte[] a1 = new byte[9];
+ byte[] a2 = ArrayTools.fill(a1, (byte) 3);
+ int from = 3;
+ int to = 6;
+ byte[] a3 = ArrayTools.fill(a2, from, to, (byte) 77);
+ for (int i = 0; i < a1.length; i++) {
+ byte x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertEquals(77, x);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillCharArrayChar() {
+ char[] a1 = new char[9];
+ char[] a2 = ArrayTools.fill(a1, 'c');
+ for (char x : a1) {
+ assertEquals('c', x);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillCharArrayIntIntChar() {
+ char[] a1 = new char[9];
+ char[] a2 = ArrayTools.fill(a1, 'a');
+ int from = 3;
+ int to = 6;
+ char[] a3 = ArrayTools.fill(a2, from, to, 'c');
+ for (int i = 0; i < a1.length; i++) {
+ char x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals('a', x);
+ } else {
+ assertEquals('c', x);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillDoubleArrayDouble() {
+ double[] a1 = new double[9];
+ double[] a2 = ArrayTools.fill(a1, 77.77);
+ for (double x : a1) {
+ assertEquals(77.77, x, 0.0);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillDoubleArrayIntIntDouble() {
+ double[] a1 = new double[9];
+ double[] a2 = ArrayTools.fill(a1, 3.3);
+ int from = 3;
+ int to = 6;
+ double[] a3 = ArrayTools.fill(a2, from, to, 77.77);
+ for (int i = 0; i < a1.length; i++) {
+ double x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3.3, x, 0.0);
+ } else {
+ assertEquals(77.77, x, 0.0);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillFloatArrayFloat() {
+ float[] a1 = new float[9];
+ float[] a2 = ArrayTools.fill(a1, 77.77f);
+ for (float x : a1) {
+ assertEquals(77.77f, x, 0.0);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillFloatArrayIntIntFloat() {
+ float[] a1 = new float[9];
+ float[] a2 = ArrayTools.fill(a1, 3.3f);
+ int from = 3;
+ int to = 6;
+ float[] a3 = ArrayTools.fill(a2, from, to, 77.77f);
+ for (int i = 0; i < a1.length; i++) {
+ float x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3.3f, x, 0.0);
+ } else {
+ assertEquals(77.77f, x, 0.0);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillIntArrayInt() {
+ int[] a1 = new int[9];
+ int[] a2 = ArrayTools.fill(a1, 77);
+ for (int x : a1) {
+ assertEquals(77, x);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillIntArrayIntIntInt() {
+ int[] a1 = new int[9];
+ int[] a2 = ArrayTools.fill(a1, 3);
+ int from = 3;
+ int to = 6;
+ int[] a3 = ArrayTools.fill(a2, from, to, 77);
+ for (int i = 0; i < a1.length; i++) {
+ int x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertEquals(77, x);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillObjectArrayObject() {
+ String[] a1 = new String[9];
+ String[] a2 = ArrayTools.fill(a1, "77");
+ for (String x : a1) {
+ assertEquals("77", x);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillObjectArrayIntIntObject() {
+ String[] a1 = new String[9];
+ String[] a2 = ArrayTools.fill(a1, "3");
+ int from = 3;
+ int to = 6;
+ String[] a3 = ArrayTools.fill(a2, from, to, "77");
+ for (int i = 0; i < a1.length; i++) {
+ String x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals("3", x);
+ } else {
+ assertEquals("77", x);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillLongArrayLong() {
+ long[] a1 = new long[9];
+ long[] a2 = ArrayTools.fill(a1, 77);
+ for (long x : a1) {
+ assertEquals(77, x);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillLongArrayIntIntLong() {
+ long[] a1 = new long[9];
+ long[] a2 = ArrayTools.fill(a1, 3);
+ int from = 3;
+ int to = 6;
+ long[] a3 = ArrayTools.fill(a2, from, to, 77);
+ for (int i = 0; i < a1.length; i++) {
+ long x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertEquals(77, x);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testFillShortArrayShort() {
+ short[] a1 = new short[9];
+ short[] a2 = ArrayTools.fill(a1, (short) 77);
+ for (short x : a1) {
+ assertEquals(77, x);
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testFillShortArrayIntIntShort() {
+ short[] a1 = new short[9];
+ short[] a2 = ArrayTools.fill(a1, (short) 3);
+ int from = 3;
+ int to = 6;
+ short[] a3 = ArrayTools.fill(a2, from, to, (short) 77);
+ for (int i = 0; i < a1.length; i++) {
+ short x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertEquals(77, x);
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortByteArray() {
+ byte[] a1 = new byte[3];
+ a1[0] = (byte) 33;
+ a1[1] = (byte) 11;
+ a1[2] = (byte) 22;
+ byte[] a2 = ArrayTools.sort(a1);
+ byte last = (byte) 0;
+ for (byte x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortByteArrayIntInt() {
+ byte[] a1 = new byte[9];
+ byte[] a2 = ArrayTools.fill(a1, (byte) 3);
+ a2[3] = (byte) 33;
+ a2[4] = (byte) 11;
+ a2[5] = (byte) 22;
+ int from = 3;
+ int to = 6;
+ byte[] a3 = ArrayTools.sort(a2, from, to);
+ byte last = (byte) 0;
+ for (int i = 0; i < a1.length; i++) {
+ byte x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortCharArray() {
+ char[] a1 = new char[3];
+ a1[0] = 'z';
+ a1[1] = 'b';
+ a1[2] = 'm';
+ char[] a2 = ArrayTools.sort(a1);
+ char last = 'a';
+ for (char x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortCharArrayIntInt() {
+ char[] a1 = new char[9];
+ char[] a2 = ArrayTools.fill(a1, 'c');
+ a2[3] = 'z';
+ a2[4] = 'b';
+ a2[5] = 'm';
+ int from = 3;
+ int to = 6;
+ char[] a3 = ArrayTools.sort(a2, from, to);
+ char last = 'a';
+ for (int i = 0; i < a1.length; i++) {
+ char x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals('c', x);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortDoubleArray() {
+ double[] a1 = new double[3];
+ a1[0] = 33.33;
+ a1[1] = 11.11;
+ a1[2] = 22.22;
+ double[] a2 = ArrayTools.sort(a1);
+ double last = 0;
+ for (double x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortDoubleArrayIntInt() {
+ double[] a1 = new double[9];
+ double[] a2 = ArrayTools.fill(a1, 3.3);
+ a2[3] = 33.33;
+ a2[4] = 11.11;
+ a2[5] = 22.22;
+ int from = 3;
+ int to = 6;
+ double[] a3 = ArrayTools.sort(a2, from, to);
+ double last = 0;
+ for (int i = 0; i < a1.length; i++) {
+ double x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3.3, x, 0.0);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortFloatArray() {
+ float[] a1 = new float[3];
+ a1[0] = 33.33f;
+ a1[1] = 11.11f;
+ a1[2] = 22.22f;
+ float[] a2 = ArrayTools.sort(a1);
+ float last = 0;
+ for (float x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortFloatArrayIntInt() {
+ float[] a1 = new float[9];
+ float[] a2 = ArrayTools.fill(a1, 3.3f);
+ a2[3] = 33.33f;
+ a2[4] = 11.11f;
+ a2[5] = 22.22f;
+ int from = 3;
+ int to = 6;
+ float[] a3 = ArrayTools.sort(a2, from, to);
+ float last = 0;
+ for (int i = 0; i < a1.length; i++) {
+ float x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3.3f, x, 0.0);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortIntArray() {
+ int[] a1 = new int[3];
+ a1[0] = 33;
+ a1[1] = 11;
+ a1[2] = 22;
+ int[] a2 = ArrayTools.sort(a1);
+ int last = 0;
+ for (int x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortIntArrayIntInt() {
+ int[] a1 = new int[9];
+ int[] a2 = ArrayTools.fill(a1, 3);
+ a2[3] = 33;
+ a2[4] = 11;
+ a2[5] = 22;
+ int from = 3;
+ int to = 6;
+ int[] a3 = ArrayTools.sort(a2, from, to);
+ int last = 0;
+ for (int i = 0; i < a1.length; i++) {
+ int x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortObjectArray() {
+ String[] a1 = new String[3];
+ a1[0] = "y";
+ a1[1] = "b";
+ a1[2] = "m";
+ String[] a2 = ArrayTools.sort(a1);
+ String last = "a";
+ for (String x : a1) {
+ assertTrue(last.compareTo(x) < 0);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortObjectArrayComparator() {
+ String[] a1 = new String[3];
+ a1[0] = "y";
+ a1[1] = "b";
+ a1[2] = "m";
+ String[] a2 = ArrayTools.sort(a1, new ReverseComparator<String>());
+ String last = "z";
+ for (String x : a1) {
+ assertTrue(last.compareTo(x) > 0);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortObjectArrayIntInt() {
+ String[] a1 = new String[9];
+ String[] a2 = ArrayTools.fill(a1, "c");
+ a2[3] = "y";
+ a2[4] = "b";
+ a2[5] = "m";
+ int from = 3;
+ int to = 6;
+ String[] a3 = ArrayTools.sort(a2, from, to);
+ String last = "a";
+ for (int i = 0; i < a1.length; i++) {
+ String x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals("c", x);
+ } else {
+ assertTrue(last.compareTo(x) < 0);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortObjectArrayIntIntComparator() {
+ String[] a1 = new String[9];
+ String[] a2 = ArrayTools.fill(a1, "c");
+ a2[3] = "y";
+ a2[4] = "b";
+ a2[5] = "m";
+ int from = 3;
+ int to = 6;
+ String[] a3 = ArrayTools.sort(a2, from, to, new ReverseComparator<String>());
+ String last = "z";
+ for (int i = 0; i < a1.length; i++) {
+ String x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals("c", x);
+ } else {
+ assertTrue(last.compareTo(x) > 0);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortLongArray() {
+ long[] a1 = new long[3];
+ a1[0] = 33;
+ a1[1] = 11;
+ a1[2] = 22;
+ long[] a2 = ArrayTools.sort(a1);
+ long last = 0;
+ for (long x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortLongArrayIntInt() {
+ long[] a1 = new long[9];
+ long[] a2 = ArrayTools.fill(a1, 3);
+ a2[3] = 33;
+ a2[4] = 11;
+ a2[5] = 22;
+ int from = 3;
+ int to = 6;
+ long[] a3 = ArrayTools.sort(a2, from, to);
+ long last = 0;
+ for (int i = 0; i < a1.length; i++) {
+ long x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+ public void testSortShortArray() {
+ short[] a1 = new short[3];
+ a1[0] = (short) 33;
+ a1[1] = (short) 11;
+ a1[2] = (short) 22;
+ short[] a2 = ArrayTools.sort(a1);
+ short last = (short) 0;
+ for (short x : a1) {
+ assertTrue(last < x);
+ last = x;
+ }
+ assertSame(a1, a2);
+ }
+
+ public void testSortShortArrayIntInt() {
+ short[] a1 = new short[9];
+ short[] a2 = ArrayTools.fill(a1, (short) 3);
+ a2[3] = (short) 33;
+ a2[4] = (short) 11;
+ a2[5] = (short) 22;
+ int from = 3;
+ int to = 6;
+ short[] a3 = ArrayTools.sort(a2, from, to);
+ short last = (short) 0;
+ for (int i = 0; i < a1.length; i++) {
+ short x = a1[i];
+ if (i < from || i >= to) {
+ assertEquals(3, x);
+ } else {
+ assertTrue(last < x);
+ last = x;
+ }
+ }
+ assertSame(a1, a2);
+ assertSame(a1, a3);
+ }
+
+
+ // ********** constructor **********
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ReflectionTools.newInstance(ArrayTools.class);
+ fail("bogus: " + at);
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
// ********** utility **********
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/AsynchronousCommandExecutorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/AsynchronousCommandExecutorTests.java
new file mode 100644
index 0000000000..7d06b5e675
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/AsynchronousCommandExecutorTests.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.Command;
+import org.eclipse.jpt.utility.internal.AsynchronousCommandExecutor;
+import org.eclipse.jpt.utility.internal.StatefulCommandExecutor;
+
+public class AsynchronousCommandExecutorTests extends TestCase {
+
+ public AsynchronousCommandExecutorTests(String name) {
+ super(name);
+ }
+
+ public void testExecution() throws Exception {
+ TestCommand command = new TestCommand();
+ StatefulCommandExecutor commandExecutor = new AsynchronousCommandExecutor();
+ commandExecutor.start();
+ commandExecutor.execute(command);
+ commandExecutor.execute(command);
+ commandExecutor.execute(command);
+ Thread.sleep(200); // wait for the command to execute
+ commandExecutor.stop();
+ assertEquals(3, command.count);
+ }
+
+ static class TestCommand implements Command {
+ int count = 0;
+ public void execute() {
+ this.count++;
+ }
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BagTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BagTests.java
new file mode 100644
index 0000000000..13c6750ccb
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BagTests.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.internal.Bag;
+import org.eclipse.jpt.utility.internal.HashBag;
+
+@SuppressWarnings("nls")
+public class BagTests extends TestCase {
+
+ public BagTests(String name) {
+ super(name);
+ }
+
+ public void testEmptyBag_iterator() throws Exception {
+ assertFalse(Bag.Empty.instance().iterator().hasNext());
+ }
+
+ public void testEmptyBag_size() throws Exception {
+ assertEquals(0, Bag.Empty.instance().size());
+ }
+
+ public void testEmptyBag_uniqueIterator() throws Exception {
+ assertFalse(Bag.Empty.instance().uniqueIterator().hasNext());
+ }
+
+ public void testEmptyBag_uniqueCount() throws Exception {
+ assertEquals(0, Bag.Empty.instance().uniqueCount());
+ }
+
+ public void testEmptyBag_count() throws Exception {
+ assertEquals(0, Bag.Empty.instance().count("foo"));
+ }
+
+ public void testEmptyBag_entries() throws Exception {
+ assertFalse(Bag.Empty.instance().entries().hasNext());
+ }
+
+ public void testEmptyBag_remove() throws Exception {
+ assertFalse(Bag.Empty.instance().remove("foo", 3));
+ }
+
+ public void testEmptyBag_add() throws Exception {
+ boolean exCaught = false;
+ try {
+ Bag.Empty.instance().add("foo", 3);
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEmptyBag_equals() throws Exception {
+ assertTrue(Bag.Empty.instance().equals(Bag.Empty.instance()));
+ assertFalse(Bag.Empty.instance().equals("foo"));
+
+ Bag<Object> bag = new HashBag<Object>();
+ assertTrue(Bag.Empty.instance().equals(bag));
+ bag.add("foo");
+ assertFalse(Bag.Empty.instance().equals(bag));
+ }
+
+ public void testEmptyBag_hashCode() throws Exception {
+ assertEquals(0, Bag.Empty.instance().hashCode());
+ }
+
+ public void testEmptyBag_serialization() throws Exception {
+ Bag<?> xxx = TestTools.serialize(Bag.Empty.instance());
+ assertSame(Bag.Empty.instance(), xxx);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiFilterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiFilterTests.java
new file mode 100644
index 0000000000..3663c3cc6e
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiFilterTests.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.internal.BidiFilter;
+
+@SuppressWarnings("nls")
+public class BidiFilterTests extends TestCase {
+
+ public BidiFilterTests(String name) {
+ super(name);
+ }
+
+ public void testNullBidiFilter_accept() throws Exception {
+ assertTrue(BidiFilter.Null.instance().accept("foo"));
+ }
+
+ public void testNullBidiFilter_reverseAccept() throws Exception {
+ assertTrue(BidiFilter.Null.instance().reverseAccept("foo"));
+ }
+
+ public void testNullBidiFilter_toString() throws Exception {
+ assertNotNull(BidiFilter.Null.instance().toString());
+ }
+
+ public void testNullBidiFilter_serialization() throws Exception {
+ BidiFilter<?> xxx = TestTools.serialize(BidiFilter.Null.instance());
+ assertSame(BidiFilter.Null.instance(), xxx);
+ }
+
+ public void testOpaqueBidiFilter_accept() throws Exception {
+ assertFalse(BidiFilter.Opaque.instance().accept("foo"));
+ }
+
+ public void testOpaqueBidiFilter_reverseAccept() throws Exception {
+ assertFalse(BidiFilter.Opaque.instance().reverseAccept("foo"));
+ }
+
+ public void testOpaqueBidiFilter_toString() throws Exception {
+ assertNotNull(BidiFilter.Opaque.instance().toString());
+ }
+
+ public void testOpaqueBidiFilter_serialization() throws Exception {
+ BidiFilter<?> xxx = TestTools.serialize(BidiFilter.Opaque.instance());
+ assertSame(BidiFilter.Opaque.instance(), xxx);
+ }
+
+ public void testDisabledBidiFilter_accept() throws Exception {
+ boolean exCaught = false;
+ try {
+ BidiFilter.Disabled.instance().accept("foo");
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDisabledBidiFilter_reverseAccept() throws Exception {
+ boolean exCaught = false;
+ try {
+ BidiFilter.Disabled.instance().reverseAccept("foo");
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDisabledBidiFilter_toString() throws Exception {
+ assertNotNull(BidiFilter.Disabled.instance().toString());
+ }
+
+ public void testDisabledBidiFilter_serialization() throws Exception {
+ BidiFilter<?> xxx = TestTools.serialize(BidiFilter.Disabled.instance());
+ assertSame(BidiFilter.Disabled.instance(), xxx);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiStringConverterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiStringConverterTests.java
new file mode 100644
index 0000000000..ec60348959
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiStringConverterTests.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.internal.BidiStringConverter;
+
+@SuppressWarnings("nls")
+public class BidiStringConverterTests extends TestCase {
+
+ public BidiStringConverterTests(String name) {
+ super(name);
+ }
+
+ public void testDefaultBidiStringConverter_convertToString() throws Exception {
+ assertEquals("foo", BidiStringConverter.Default.instance().convertToString("foo"));
+ assertNull(BidiStringConverter.Default.instance().convertToString(null));
+ }
+
+ public void testDefaultBidiStringConverter_convertToObject() throws Exception {
+ assertEquals("foo", BidiStringConverter.Default.instance().convertToObject("foo"));
+ assertNull(BidiStringConverter.Default.instance().convertToString(null));
+ }
+
+ public void testDefaultBidiStringConverter_toString() throws Exception {
+ assertNotNull(BidiStringConverter.Default.instance().toString());
+ }
+
+ public void testDefaultBidiStringConverter_serialization() throws Exception {
+ BidiStringConverter<?> xxx = TestTools.serialize(BidiStringConverter.Default.instance());
+ assertSame(BidiStringConverter.Default.instance(), xxx);
+ }
+
+ public void testDisabledBidiStringConverter_convertToString() throws Exception {
+ boolean exCaught = false;
+ try {
+ BidiStringConverter.Disabled.instance().convertToString("foo");
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDisabledBidiStringConverter_convertToObject() throws Exception {
+ boolean exCaught = false;
+ try {
+ BidiStringConverter.Disabled.instance().convertToObject("foo");
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDisabledBidiStringConverter_toString() throws Exception {
+ assertNotNull(BidiStringConverter.Disabled.instance().toString());
+ }
+
+ public void testDisabledBidiStringConverter_serialization() throws Exception {
+ BidiStringConverter<?> xxx = TestTools.serialize(BidiStringConverter.Disabled.instance());
+ assertSame(BidiStringConverter.Disabled.instance(), xxx);
+ }
+
+ public void testBooleanBidiStringConverter_convertToString() throws Exception {
+ assertEquals("true", BidiStringConverter.BooleanConverter.instance().convertToString(Boolean.TRUE));
+ assertEquals("false", BidiStringConverter.BooleanConverter.instance().convertToString(Boolean.FALSE));
+ assertNull(BidiStringConverter.BooleanConverter.instance().convertToString(null));
+ }
+
+ public void testBooleanBidiStringConverter_convertToObject() throws Exception {
+ assertEquals(Boolean.TRUE, BidiStringConverter.BooleanConverter.instance().convertToObject("true"));
+ assertEquals(Boolean.TRUE, BidiStringConverter.BooleanConverter.instance().convertToObject("TRUE"));
+ assertEquals(Boolean.FALSE, BidiStringConverter.BooleanConverter.instance().convertToObject("false"));
+ assertEquals(Boolean.FALSE, BidiStringConverter.BooleanConverter.instance().convertToObject("xxxx"));
+ assertNull(BidiStringConverter.BooleanConverter.instance().convertToObject(null));
+ }
+
+ public void testBooleanBidiStringConverter_toString() throws Exception {
+ assertNotNull(BidiStringConverter.BooleanConverter.instance().toString());
+ }
+
+ public void testBooleanBidiStringConverter_serialization() throws Exception {
+ BidiStringConverter<?> xxx = TestTools.serialize(BidiStringConverter.BooleanConverter.instance());
+ assertSame(BidiStringConverter.BooleanConverter.instance(), xxx);
+ }
+
+ public void testIntegerBidiStringConverter_convertToString() throws Exception {
+ assertEquals("7", BidiStringConverter.IntegerConverter.instance().convertToString(Integer.valueOf(7)));
+ assertNull(BidiStringConverter.IntegerConverter.instance().convertToString(null));
+ }
+
+ public void testIntegerBidiStringConverter_convertToObject() throws Exception {
+ assertEquals(Integer.valueOf(7), BidiStringConverter.IntegerConverter.instance().convertToObject("7"));
+ assertNull(BidiStringConverter.IntegerConverter.instance().convertToObject(null));
+ }
+
+ public void testIntegerBidiStringConverter_toString() throws Exception {
+ assertNotNull(BidiStringConverter.IntegerConverter.instance().toString());
+ }
+
+ public void testIntegerBidiStringConverter_serialization() throws Exception {
+ BidiStringConverter<?> xxx = TestTools.serialize(BidiStringConverter.IntegerConverter.instance());
+ assertSame(BidiStringConverter.IntegerConverter.instance(), xxx);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiTransformerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiTransformerTests.java
new file mode 100644
index 0000000000..24cfea5866
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BidiTransformerTests.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.internal.BidiTransformer;
+
+@SuppressWarnings("nls")
+public class BidiTransformerTests extends TestCase {
+
+ public BidiTransformerTests(String name) {
+ super(name);
+ }
+
+ public void testNullBidiTransformer_transform() throws Exception {
+ assertEquals("foo", BidiTransformer.Null.instance().transform("foo"));
+ assertNull(BidiTransformer.Null.instance().transform(null));
+ }
+
+ public void testNullBidiTransformer_reverseTransform() throws Exception {
+ assertEquals("foo", BidiTransformer.Null.instance().reverseTransform("foo"));
+ assertNull(BidiTransformer.Null.instance().transform(null));
+ }
+
+ public void testNullBidiTransformer_toString() throws Exception {
+ assertNotNull(BidiTransformer.Null.instance().toString());
+ }
+
+ public void testNullBidiTransformer_serialization() throws Exception {
+ BidiTransformer<?, ?> xxx = TestTools.serialize(BidiTransformer.Null.instance());
+ assertSame(BidiTransformer.Null.instance(), xxx);
+ }
+
+ public void testDisabledBidiTransformer_transform() throws Exception {
+ boolean exCaught = false;
+ try {
+ BidiTransformer.Disabled.instance().transform("foo");
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDisabledBidiTransformer_reverseTransform() throws Exception {
+ boolean exCaught = false;
+ try {
+ BidiTransformer.Disabled.instance().reverseTransform("foo");
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDisabledBidiTransformer_toString() throws Exception {
+ assertNotNull(BidiTransformer.Disabled.instance().toString());
+ }
+
+ public void testDisabledBidiTransformer_serialization() throws Exception {
+ BidiTransformer<?, ?> xxx = TestTools.serialize(BidiTransformer.Disabled.instance());
+ assertSame(BidiTransformer.Disabled.instance(), xxx);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BitToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BitToolsTests.java
index 8f2e9b8492..f669a517ef 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BitToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BitToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,8 +9,12 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal;
+import java.lang.reflect.InvocationTargetException;
+
import junit.framework.TestCase;
+
import org.eclipse.jpt.utility.internal.BitTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
public class BitToolsTests extends TestCase {
@@ -240,4 +244,19 @@ public class BitToolsTests extends TestCase {
assertEquals(0xF010, BitTools.xorFlags(new int[] { 0x0001, 0x0011, 0xF000, 0x0F01, 0x0F01 }));
}
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ReflectionTools.newInstance(BitTools.class);
+ fail("bogus: " + at); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BooleanToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BooleanToolsTests.java
index a1ce2d48b8..817044602a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BooleanToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/BooleanToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,10 +9,13 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal;
-import org.eclipse.jpt.utility.internal.BooleanTools;
+import java.lang.reflect.InvocationTargetException;
import junit.framework.TestCase;
+import org.eclipse.jpt.utility.internal.BooleanTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
+
public class BooleanToolsTests extends TestCase {
private static final Boolean TRUE = Boolean.TRUE;
private static final Boolean FALSE = Boolean.FALSE;
@@ -68,4 +71,19 @@ public class BooleanToolsTests extends TestCase {
assertEquals(TRUE, BooleanTools.xnor(FALSE, FALSE));
}
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ReflectionTools.newInstance(BooleanTools.class);
+ fail("bogus: " + at); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassNameTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassNameTests.java
new file mode 100644
index 0000000000..5588858142
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassNameTests.java
@@ -0,0 +1,356 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2010 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.utility.tests.internal;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.internal.ClassName;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
+
+@SuppressWarnings("nls")
+public class ClassNameTests extends TestCase {
+
+ public ClassNameTests(String name) {
+ super(name);
+ }
+
+ public void testIsArray() {
+ assertFalse(ClassName.isArray(int.class.getName()));
+ assertTrue(ClassName.isArray(int[].class.getName()));
+ assertTrue(ClassName.isArray(int[][].class.getName()));
+
+ assertFalse(ClassName.isArray(java.lang.String.class.getName()));
+ assertTrue(ClassName.isArray(java.lang.String[].class.getName()));
+ assertTrue(ClassName.isArray(java.lang.String[][].class.getName()));
+ }
+
+ public void testGetElementTypeName() {
+ assertEquals(java.util.Vector.class.getName(), ClassName.getElementTypeName(java.util.Vector.class.getName()));
+ assertEquals(int.class.getName(), ClassName.getElementTypeName(int.class.getName()));
+ assertEquals(void.class.getName(), ClassName.getElementTypeName(void.class.getName()));
+ assertEquals(java.util.Vector.class.getName(), ClassName.getElementTypeName(java.util.Vector[].class.getName()));
+ assertEquals(int.class.getName(), ClassName.getElementTypeName(int[].class.getName()));
+ assertEquals(java.util.Vector.class.getName(), ClassName.getElementTypeName(java.util.Vector[][][].class.getName()));
+ assertEquals(int.class.getName(), ClassName.getElementTypeName(int[][][].class.getName()));
+ }
+
+ public void testGetArrayDepth() {
+ assertEquals(0, ClassName.getArrayDepth(java.util.Vector.class.getName()));
+ assertEquals(0, ClassName.getArrayDepth(int.class.getName()));
+ assertEquals(0, ClassName.getArrayDepth(void.class.getName()));
+ assertEquals(1, ClassName.getArrayDepth(java.util.Vector[].class.getName()));
+ assertEquals(1, ClassName.getArrayDepth(int[].class.getName()));
+ assertEquals(3, ClassName.getArrayDepth(java.util.Vector[][][].class.getName()));
+ assertEquals(3, ClassName.getArrayDepth(int[][][].class.getName()));
+ }
+
+ public void testGetComponentTypeName() {
+ assertEquals(null, ClassName.getComponentTypeName(java.lang.Object.class.getName()));
+ assertEquals(java.lang.Object.class.getName(), ClassName.getComponentTypeName(java.lang.Object[].class.getName()));
+ assertEquals(java.lang.Object[].class.getName(), ClassName.getComponentTypeName(java.lang.Object[][].class.getName()));
+
+ assertEquals(null, ClassName.getComponentTypeName(int.class.getName()));
+ assertEquals(int.class.getName(), ClassName.getComponentTypeName(int[].class.getName()));
+ assertEquals(int[].class.getName(), ClassName.getComponentTypeName(int[][].class.getName()));
+ }
+
+ public void testGetSimpleName() throws Exception {
+ assertEquals("Object", ClassName.getSimpleName(java.lang.Object.class.getName()));
+ assertEquals("Object[]", ClassName.getSimpleName(java.lang.Object[].class.getName()));
+ assertEquals("Object[][]", ClassName.getSimpleName(java.lang.Object[][].class.getName()));
+
+ assertEquals("int", ClassName.getSimpleName(int.class.getName()));
+ assertEquals("int[]", ClassName.getSimpleName(int[].class.getName()));
+ assertEquals("int[][]", ClassName.getSimpleName(int[][].class.getName()));
+
+ Object anonObject = new Object() {
+ // anonymous class
+ };
+ assertEquals("", ClassName.getSimpleName(anonObject.getClass().getName()));
+
+ class Local {
+ // anonymous class
+ }
+ Local localObject = new Local();
+ assertEquals("Local", ClassName.getSimpleName(localObject.getClass().getName()));
+ }
+
+ public void testGetPackageName() throws Exception {
+ assertEquals("java.lang", ClassName.getPackageName(java.lang.Object.class.getName()));
+ assertEquals("", ClassName.getPackageName(java.lang.Object[].class.getName()));
+ assertEquals("", ClassName.getPackageName(java.lang.Object[][].class.getName()));
+
+ assertEquals("", ClassName.getPackageName(int.class.getName()));
+ assertEquals("", ClassName.getPackageName(int[].class.getName()));
+ assertEquals("", ClassName.getPackageName(int[][].class.getName()));
+
+ assertEquals("", ClassName.getPackageName(void.class.getName()));
+
+ Object anonObject = new Object() {
+ // anonymous class
+ };
+ assertEquals(anonObject.getClass().getPackage().getName(), ClassName.getPackageName(anonObject.getClass().getName()));
+ }
+
+ public void testIsTopLevel() throws Exception {
+ assertTrue(ClassName.isTopLevel(java.util.Map.class.getName())); // top-level
+ assertFalse(ClassName.isTopLevel(java.util.Map.Entry.class.getName())); // member
+ assertFalse(ClassName.isTopLevel(Class.forName(this.getClass().getName() + "$1LocalClass").getName())); // local
+ assertFalse(ClassName.isTopLevel(Class.forName("java.util.Vector$1").getName())); // anonymous
+
+ Object[] array = new java.util.Map[0]; // top-level
+ assertFalse(ClassName.isTopLevel(array.getClass().getName()));
+ array = new java.util.Map.Entry[0]; // member
+ assertFalse(ClassName.isTopLevel(array.getClass().getName()));
+ Class<?> localClass = Class.forName(this.getClass().getName() + "$1LocalClass"); // local
+ array = (Object[]) Array.newInstance(localClass, 0);
+ assertFalse(ClassName.isTopLevel(array.getClass().getName()));
+ Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
+ array = (Object[]) Array.newInstance(anonClass, 0);
+ assertFalse(ClassName.isTopLevel(array.getClass().getName()));
+ }
+
+ public void testIsMember() throws Exception {
+ assertFalse(ClassName.isMember(java.util.Map.class.getName())); // top-level
+ assertTrue(ClassName.isMember(java.util.Map.Entry.class.getName())); // member
+ assertFalse(ClassName.isMember(Class.forName(this.getClass().getName() + "$1LocalClass").getName())); // local
+ assertFalse(ClassName.isMember(Class.forName("java.util.Vector$1").getName())); // anonymous
+
+ Object[] array = new java.util.Map[0]; // top-level
+ assertFalse(ClassName.isMember(array.getClass().getName()));
+ array = new java.util.Map.Entry[0]; // member
+ assertFalse(ClassName.isMember(array.getClass().getName()));
+ Class<?> localClass = Class.forName(this.getClass().getName() + "$1LocalClass"); // local
+ array = (Object[]) Array.newInstance(localClass, 0);
+ assertFalse(ClassName.isMember(array.getClass().getName()));
+ Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
+ array = (Object[]) Array.newInstance(anonClass, 0);
+ assertFalse(ClassName.isMember(array.getClass().getName()));
+
+ // test a few edge cases
+ assertTrue(ClassName.isMember("java.util.Map$a1"));
+ assertTrue(ClassName.isMember("java.util.Map$1aa$aaa")); // member inside local
+ assertTrue(ClassName.isMember("java.util.Map$1$aaa")); // member inside anonymous
+ assertTrue(ClassName.isMember("java.util.Map$a1$aaa$bbb"));
+ assertTrue(ClassName.isMember("java.util.Map$1a1$aaa")); // member inside local
+ assertFalse(ClassName.isMember("java.util.Map$1a"));
+ assertTrue(ClassName.isMember("java.util.Map$a12345$b12345"));
+ assertFalse(ClassName.isMember("java.util.Map$12345a"));
+ assertFalse(ClassName.isMember("java.util.Map$333"));
+ assertFalse(ClassName.isMember("java.util.Map3$333"));
+ }
+
+ public void testIsLocal() throws Exception {
+ class LocalClass {
+ void foo() {
+ System.getProperty("foo");
+ }
+ }
+ new LocalClass().foo();
+ assertFalse(ClassName.isLocal(java.util.Map.class.getName())); // top-level
+ assertFalse(ClassName.isLocal(java.util.Map.Entry.class.getName())); // member
+ assertTrue(ClassName.isLocal(Class.forName(this.getClass().getName() + "$1LocalClass").getName())); // local
+ assertFalse(ClassName.isLocal(Class.forName("java.util.Vector$1").getName())); // anonymous
+
+ Object[] array = new java.util.Map[0]; // top-level
+ assertFalse(ClassName.isLocal(array.getClass().getName()));
+ array = new java.util.Map.Entry[0]; // member
+ assertFalse(ClassName.isLocal(array.getClass().getName()));
+ Class<?> localClass = Class.forName(this.getClass().getName() + "$1LocalClass"); // local
+ array = (Object[]) Array.newInstance(localClass, 0);
+ assertFalse(ClassName.isLocal(array.getClass().getName()));
+ Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
+ array = (Object[]) Array.newInstance(anonClass, 0);
+ assertFalse(ClassName.isLocal(array.getClass().getName()));
+
+ // test a few edge cases
+ assertFalse(ClassName.isLocal("java.util.Map$a1"));
+ assertFalse(ClassName.isLocal("java.util.Map$a1$aaa$bbb"));
+ assertFalse(ClassName.isLocal("java.util.Map$11$aaa"));
+ assertTrue(ClassName.isLocal("java.util.Map$1a"));
+ assertTrue(ClassName.isLocal("java.util.Map$2abc"));
+ assertTrue(ClassName.isLocal("java.util.Map$2abc1"));
+ assertFalse(ClassName.isLocal("java.util.Map$a12345$b12345"));
+ assertTrue(ClassName.isLocal("java.util.Map$12345$1234a"));
+ assertFalse(ClassName.isLocal("java.util.Map$333"));
+ assertFalse(ClassName.isLocal("java.util.Map3$333"));
+ }
+
+ public void testIsAnonymous() throws Exception {
+ assertFalse(ClassName.isAnonymous(java.util.Map.class.getName())); // top-level
+ assertFalse(ClassName.isAnonymous(java.util.Map.Entry.class.getName())); // member
+ assertFalse(ClassName.isAnonymous(Class.forName(this.getClass().getName() + "$1LocalClass").getName())); // local
+ assertTrue(ClassName.isAnonymous(Class.forName("java.util.Vector$1").getName())); // anonymous
+
+ Object[] array = new java.util.Map[0]; // top-level
+ assertFalse(ClassName.isAnonymous(array.getClass().getName()));
+ array = new java.util.Map.Entry[0]; // member
+ assertFalse(ClassName.isAnonymous(array.getClass().getName()));
+ Class<?> localClass = Class.forName(this.getClass().getName() + "$1LocalClass"); // local
+ array = (Object[]) Array.newInstance(localClass, 0);
+ assertFalse(ClassName.isAnonymous(array.getClass().getName()));
+ Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
+ array = (Object[]) Array.newInstance(anonClass, 0);
+ assertFalse(ClassName.isAnonymous(array.getClass().getName()));
+
+ // test a few edge cases
+ assertFalse(ClassName.isAnonymous("java.util.Map$a1"));
+ assertFalse(ClassName.isAnonymous("java.util.Map$a1$aaa$bbb"));
+ assertFalse(ClassName.isAnonymous("java.util.Map$1a1$aaa"));
+ assertFalse(ClassName.isAnonymous("java.util.Map$1$a"));
+ assertFalse(ClassName.isAnonymous("java.util.Map$1a"));
+ assertFalse(ClassName.isAnonymous("java.util.Map$a12345$b12345"));
+ assertFalse(ClassName.isAnonymous("java.util.Map$12345$a1234"));
+ assertTrue(ClassName.isAnonymous("java.util.Map$333"));
+ assertTrue(ClassName.isAnonymous("java.util.Map3$333"));
+ }
+
+ public void testIsReference() throws Exception {
+ assertFalse(ClassName.isReference(int.class.getName())); // top-level
+
+ assertTrue(ClassName.isReference(java.util.Map.class.getName())); // top-level
+ assertTrue(ClassName.isReference(java.util.Map.Entry.class.getName())); // member
+ assertTrue(ClassName.isReference(Class.forName(this.getClass().getName() + "$1LocalClass").getName())); // local
+ assertTrue(ClassName.isReference(Class.forName("java.util.Vector$1").getName())); // anonymous
+
+ Object[] array = new java.util.Map[0]; // top-level
+ assertTrue(ClassName.isReference(array.getClass().getName()));
+ array = new java.util.Map.Entry[0]; // member
+ assertTrue(ClassName.isReference(array.getClass().getName()));
+ Class<?> localClass = Class.forName(this.getClass().getName() + "$1LocalClass"); // local
+ array = (Object[]) Array.newInstance(localClass, 0);
+ assertTrue(ClassName.isReference(array.getClass().getName()));
+ Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
+ array = (Object[]) Array.newInstance(anonClass, 0);
+ assertTrue(ClassName.isReference(array.getClass().getName()));
+ }
+
+ public void testIsPrimitive() {
+ assertTrue(void.class.isPrimitive());
+
+ assertTrue(ClassName.isPrimitive(void.class.getName()));
+ assertTrue(ClassName.isPrimitive(int.class.getName()));
+ assertTrue(ClassName.isPrimitive(float.class.getName()));
+ assertTrue(ClassName.isPrimitive(boolean.class.getName()));
+
+ assertFalse(ClassName.isPrimitive(java.lang.Number.class.getName()));
+ assertFalse(ClassName.isPrimitive(java.lang.String.class.getName()));
+ assertFalse(ClassName.isPrimitive(java.lang.Boolean.class.getName()));
+ assertFalse(ClassName.isPrimitive(java.lang.Integer.class.getName()));
+ }
+
+ public void testIsPrimitiveWrapper() {
+ assertFalse(ClassName.isPrimitiveWrapper(void.class.getName()));
+ assertFalse(ClassName.isPrimitiveWrapper(int.class.getName()));
+ assertFalse(ClassName.isPrimitiveWrapper(float.class.getName()));
+ assertFalse(ClassName.isPrimitiveWrapper(boolean.class.getName()));
+
+ assertFalse(ClassName.isPrimitiveWrapper(java.lang.reflect.Field.class.getName()));
+ assertFalse(ClassName.isPrimitiveWrapper(java.lang.String.class.getName()));
+ assertTrue(ClassName.isPrimitiveWrapper(java.lang.Boolean.class.getName()));
+ assertTrue(ClassName.isPrimitiveWrapper(java.lang.Integer.class.getName()));
+ }
+
+ public void testIsVariablePrimitive() {
+ assertFalse(ClassName.isVariablePrimitive(void.class.getName()));
+
+ assertTrue(ClassName.isVariablePrimitive(int.class.getName()));
+ assertTrue(ClassName.isVariablePrimitive(float.class.getName()));
+ assertTrue(ClassName.isVariablePrimitive(boolean.class.getName()));
+
+ assertFalse(ClassName.isVariablePrimitive(java.lang.Number.class.getName()));
+ assertFalse(ClassName.isVariablePrimitive(java.lang.String.class.getName()));
+ assertFalse(ClassName.isVariablePrimitive(java.lang.Boolean.class.getName()));
+ }
+
+ public void testIsVariablePrimitiveWrapper() {
+ assertFalse(ClassName.isVariablePrimitiveWrapper(java.lang.Void.class.getName()));
+
+ assertTrue(ClassName.isVariablePrimitiveWrapper(java.lang.Integer.class.getName()));
+ assertTrue(ClassName.isVariablePrimitiveWrapper(java.lang.Float.class.getName()));
+ assertTrue(ClassName.isVariablePrimitiveWrapper(java.lang.Boolean.class.getName()));
+
+ assertFalse(ClassName.isVariablePrimitiveWrapper(java.lang.Number.class.getName()));
+ assertFalse(ClassName.isVariablePrimitiveWrapper(java.lang.String.class.getName()));
+ assertFalse(ClassName.isVariablePrimitiveWrapper(java.lang.Object.class.getName()));
+ }
+
+ public void testGetWrapperClassName() {
+ assertEquals(java.lang.Void.class.getName(), ClassName.getWrapperClassName(void.class.getName()));
+ assertEquals(java.lang.Integer.class.getName(), ClassName.getWrapperClassName(int.class.getName()));
+ assertEquals(java.lang.Float.class.getName(), ClassName.getWrapperClassName(float.class.getName()));
+ assertEquals(java.lang.Boolean.class.getName(), ClassName.getWrapperClassName(boolean.class.getName()));
+
+ assertNull(ClassName.getWrapperClassName(java.lang.String.class.getName()));
+ }
+
+ public void testGetPrimitiveClassName() {
+ assertEquals(void.class.getName(), ClassName.getPrimitiveClassName(java.lang.Void.class.getName()));
+ assertEquals(int.class.getName(), ClassName.getPrimitiveClassName(java.lang.Integer.class.getName()));
+ assertEquals(float.class.getName(), ClassName.getPrimitiveClassName(java.lang.Float.class.getName()));
+ assertEquals(boolean.class.getName(), ClassName.getPrimitiveClassName(java.lang.Boolean.class.getName()));
+
+ assertNull(ClassName.getPrimitiveClassName(java.lang.String.class.getName()));
+ }
+
+ public void testForCode() {
+ assertEquals("byte", ClassName.forCode('B'));
+ assertEquals("char", ClassName.forCode('C'));
+ assertEquals("double", ClassName.forCode('D'));
+ assertEquals("float", ClassName.forCode('F'));
+ assertEquals("int", ClassName.forCode('I'));
+ assertEquals("long", ClassName.forCode('J'));
+ assertEquals("short", ClassName.forCode('S'));
+ assertEquals("boolean", ClassName.forCode('Z'));
+ assertEquals("void", ClassName.forCode('V'));
+
+ assertNull(ClassName.forCode('X'));
+
+ assertEquals("byte", ClassName.forCode((int) 'B'));
+ assertEquals("char", ClassName.forCode((int) 'C'));
+ assertEquals("double", ClassName.forCode((int) 'D'));
+ assertEquals("float", ClassName.forCode((int) 'F'));
+ assertEquals("int", ClassName.forCode((int) 'I'));
+ assertEquals("long", ClassName.forCode((int) 'J'));
+ assertEquals("short", ClassName.forCode((int) 'S'));
+ assertEquals("boolean", ClassName.forCode((int) 'Z'));
+ assertEquals("void", ClassName.forCode((int) 'V'));
+
+ assertNull(ClassName.forCode((int) 'X'));
+ }
+
+ public void testGetCodeForClassName() {
+ assertEquals('I', ClassName.getCodeForClassName(int.class.getName()));
+ assertEquals('I', ClassName.getCodeForClassName("int"));
+ assertEquals('B', ClassName.getCodeForClassName(byte.class.getName()));
+ assertEquals('B', ClassName.getCodeForClassName("byte"));
+
+ assertEquals((char) 0, ClassName.getCodeForClassName(java.lang.Object.class.getName()));
+ }
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ReflectionTools.newInstance(ClassName.class);
+ fail("bogus: " + at); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java
deleted file mode 100644
index 80e9ba38f4..0000000000
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java
+++ /dev/null
@@ -1,676 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 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.utility.tests.internal;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Vector;
-import java.util.Map.Entry;
-import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
-
-@SuppressWarnings("nls")
-public class ClassToolsTests extends TestCase {
-
- private static String testStaticField;
-
- public ClassToolsTests(String name) {
- super(name);
- }
-
- /**
- * Return the compiler-generated class name. The Eclipse compiler generates
- * "local" classes with names in the form "com.foo.Outer$1$Local"; while the
- * JDK compiler generates "com.foo.Outer$1Local". There might be other
- * differences.... ~bjv
- */
- public static String compilerDependentClassNameFor(String className) {
- int index = className.indexOf("$1$");
- if (index == -1) {
- return className;
- }
- try {
- Class.forName(className);
- } catch (ClassNotFoundException ex) {
- return className.substring(0, index + 2) + className.substring(index + 3);
- }
- return className;
- }
-
- private static String munge(String className) {
- return compilerDependentClassNameFor(className);
- }
-
- public void testAllFields() {
- int fieldCount = 0;
- fieldCount += java.util.Vector.class.getDeclaredFields().length;
- fieldCount += java.util.AbstractList.class.getDeclaredFields().length;
- fieldCount += java.util.AbstractCollection.class.getDeclaredFields().length;
- fieldCount += java.lang.Object.class.getDeclaredFields().length;
- Field[] fields = ClassTools.allFields(java.util.Vector.class);
- assertEquals(fieldCount, fields.length);
- assertTrue(CollectionTools.contains(this.names(fields), "modCount"));
- assertTrue(CollectionTools.contains(this.names(fields), "serialVersionUID"));
- assertTrue(CollectionTools.contains(this.names(fields), "capacityIncrement"));
- assertTrue(CollectionTools.contains(this.names(fields), "elementCount"));
- assertTrue(CollectionTools.contains(this.names(fields), "elementData"));
- assertTrue(fields[0].isAccessible());
- }
-
- public void testAllMethods() {
- int methodCount = 0;
- methodCount += java.util.Vector.class.getDeclaredMethods().length;
- methodCount += java.util.AbstractList.class.getDeclaredMethods().length;
- methodCount += java.util.AbstractCollection.class.getDeclaredMethods().length;
- methodCount += java.lang.Object.class.getDeclaredMethods().length;
- Method[] methods = ClassTools.allMethods(java.util.Vector.class);
- assertEquals(methodCount, methods.length);
- assertTrue(CollectionTools.contains(this.names(methods), "wait"));
- assertTrue(CollectionTools.contains(this.names(methods), "addElement"));
- assertTrue(methods[0].isAccessible());
- }
-
- public void testNewInstanceClass() {
- Vector<?> v = ClassTools.newInstance(java.util.Vector.class);
- assertNotNull(v);
- assertEquals(0, v.size());
- }
-
- public void testNewInstanceClassClassObject() {
- int initialCapacity = 200;
- Vector<?> v = ClassTools.newInstance(java.util.Vector.class, int.class, new Integer(initialCapacity));
- assertNotNull(v);
- assertEquals(0, v.size());
- Object[] elementData = (Object[]) ClassTools.fieldValue(v, "elementData");
- assertEquals(initialCapacity, elementData.length);
- }
-
- public void testNewInstanceClassClassArrayObjectArray() {
- int initialCapacity = 200;
- Class<?>[] parmTypes = new Class[1];
- parmTypes[0] = int.class;
- Object[] parms = new Object[1];
- parms[0] = new Integer(initialCapacity);
- Vector<?> v = ClassTools.newInstance(java.util.Vector.class, parmTypes, parms);
- assertNotNull(v);
- assertEquals(0, v.size());
- Object[] elementData = (Object[]) ClassTools.fieldValue(v, "elementData");
- assertEquals(initialCapacity, elementData.length);
-
- parms[0] = new Integer(-1);
- boolean exCaught = false;
- try {
- v = ClassTools.newInstance(java.util.Vector.class, parmTypes, parms);
- } catch (RuntimeException ex) {
- exCaught = true;
- }
- assertTrue("RuntimeException not thrown", exCaught);
-
- parmTypes[0] = java.lang.String.class;
- parms[0] = "foo";
- exCaught = false;
- try {
- v = ClassTools.attemptNewInstance(java.util.Vector.class, parmTypes, parms);
- } catch (NoSuchMethodException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchMethodException not thrown", exCaught);
- }
-
- public void testFieldValue() {
- int initialCapacity = 200;
- Vector<?> v = new Vector<Object>(initialCapacity);
- Object[] elementData = (Object[]) ClassTools.fieldValue(v, "elementData");
- assertEquals(initialCapacity, elementData.length);
-
- // test inherited field
- Integer modCountInteger = (Integer) ClassTools.fieldValue(v, "modCount");
- int modCount = modCountInteger.intValue();
- assertEquals(0, modCount);
-
- boolean exCaught = false;
- Object bogusFieldValue = null;
- try {
- bogusFieldValue = ClassTools.attemptToGetFieldValue(v, "bogusField");
- } catch (NoSuchFieldException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchFieldException not thrown: " + bogusFieldValue, exCaught);
- }
-
- public void testExecuteMethodObjectString() {
- Vector<String> v = new Vector<String>();
- int size = ((Integer) ClassTools.executeMethod(v, "size")).intValue();
- assertEquals(0, size);
-
- v.addElement("foo");
- size = ((Integer) ClassTools.executeMethod(v, "size")).intValue();
- assertEquals(1, size);
- }
-
- public void testExecuteMethodObjectStringClassObject() {
- Vector<String> v = new Vector<String>();
- boolean booleanResult = ((Boolean) ClassTools.executeMethod(v, "add", Object.class, "foo")).booleanValue();
- assertTrue(booleanResult);
- assertTrue(v.contains("foo"));
- Object voidResult = ClassTools.executeMethod(v, "addElement", Object.class, "bar");
- assertNull(voidResult);
- }
-
- public void testExecuteMethodObjectStringClassArrayObjectArray() {
- Vector<String> v = new Vector<String>();
- Class<?>[] parmTypes = new Class[1];
- parmTypes[0] = java.lang.Object.class;
- Object[] parms = new Object[1];
- parms[0] = "foo";
- boolean booleanResult = ((Boolean) ClassTools.executeMethod(v, "add", parmTypes, parms)).booleanValue();
- assertTrue(booleanResult);
- assertTrue(v.contains("foo"));
-
- boolean exCaught = false;
- Object bogusMethodReturnValue = null;
- try {
- bogusMethodReturnValue = ClassTools.attemptToExecuteMethod(v, "bogusMethod", parmTypes, parms);
- } catch (NoSuchMethodException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchMethodException not thrown: " + bogusMethodReturnValue, exCaught);
- }
-
- public void testExecuteStaticMethodClassString() {
- Double randomObject = (Double) ClassTools.executeStaticMethod(java.lang.Math.class, "random");
- assertNotNull(randomObject);
- double random = randomObject.doubleValue();
- assertTrue(random >= 0);
- assertTrue(random < 1);
- }
-
- public void testExecuteStaticMethodClassStringClassObject() {
- String s = (String) ClassTools.executeStaticMethod(java.lang.String.class, "valueOf", boolean.class, Boolean.TRUE);
- assertNotNull(s);
- assertEquals("true", s);
- }
-
- public void testExecuteStaticMethodClassStringClassArrayObjectArray() {
- Class<?>[] parmTypes = new Class[1];
- parmTypes[0] = boolean.class;
- Object[] parms = new Object[1];
- parms[0] = Boolean.TRUE;
- String s = (String) ClassTools.executeStaticMethod(java.lang.String.class, "valueOf", parmTypes, parms);
- assertNotNull(s);
- assertEquals("true", s);
-
- boolean exCaught = false;
- Object bogusStaticMethodReturnValue = null;
- try {
- bogusStaticMethodReturnValue = ClassTools.attemptToExecuteStaticMethod(java.lang.String.class, "bogusStaticMethod", parmTypes, parms);
- } catch (NoSuchMethodException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchMethodException not thrown: " + bogusStaticMethodReturnValue, exCaught);
-
- // test non-static method
- exCaught = false;
- try {
- bogusStaticMethodReturnValue = ClassTools.attemptToExecuteStaticMethod(java.lang.String.class, "toString");
- } catch (NoSuchMethodException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchMethodException not thrown: " + bogusStaticMethodReturnValue, exCaught);
- }
-
- public void testSetFieldValue() {
- Vector<String> v = new Vector<String>();
- Object[] newElementData = new Object[5];
- newElementData[0] = "foo";
- ClassTools.setFieldValue(v, "elementData", newElementData);
- ClassTools.setFieldValue(v, "elementCount", new Integer(1));
- // test inherited field
- ClassTools.setFieldValue(v, "modCount", new Integer(1));
- assertTrue(v.contains("foo"));
-
- boolean exCaught = false;
- try {
- ClassTools.attemptToSetFieldValue(v, "bogusField", "foo");
- } catch (NoSuchFieldException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchFieldException not thrown", exCaught);
- }
-
- public void testSetStaticFieldValue() {
- ClassTools.setStaticFieldValue(this.getClass(), "testStaticField", "new value");
- assertEquals(testStaticField, "new value");
-
- boolean exCaught = false;
- try {
- ClassTools.attemptToSetStaticFieldValue(this.getClass(), "bogusStaticField", "new value");
- } catch (NoSuchFieldException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchFieldException not thrown", exCaught);
- }
-
- public void testShortName() {
- assertEquals("Vector", ClassTools.shortClassNameForObject(new java.util.Vector<Object>()));
- assertEquals("Vector", ClassTools.shortNameFor(java.util.Vector.class));
- }
-
- public void testNestedName() {
- Map<String, String> map = new HashMap<String, String>();
- map.put("foo", "bar");
- Entry<String, String> entry = map.entrySet().iterator().next();
- assertEquals("Entry", ClassTools.nestedClassNameForObject(entry));
- assertEquals("Entry", ClassTools.nestedNameFor(java.util.Map.Entry.class));
- }
-
- public void testPackageName() {
- assertEquals("java.util", ClassTools.packageNameFor(java.util.Vector.class));
- assertEquals("java.util", ClassTools.packageNameFor(java.util.Map.Entry.class));
- }
-
- public void testArrayDepthFor() {
- assertEquals(0, ClassTools.arrayDepthFor(java.util.Vector.class));
- assertEquals(0, ClassTools.arrayDepthFor(int.class));
- assertEquals(0, ClassTools.arrayDepthFor(void.class));
- assertEquals(1, ClassTools.arrayDepthFor(java.util.Vector[].class));
- assertEquals(1, ClassTools.arrayDepthFor(int[].class));
- assertEquals(3, ClassTools.arrayDepthFor(java.util.Vector[][][].class));
- assertEquals(3, ClassTools.arrayDepthFor(int[][][].class));
- }
-
- public void testArrayDepthForObject() {
- assertEquals(0, ClassTools.arrayDepthForObject(new java.util.Vector<Object>()));
- assertEquals(1, ClassTools.arrayDepthForObject(new java.util.Vector[0]));
- assertEquals(1, ClassTools.arrayDepthForObject(new int[0]));
- assertEquals(3, ClassTools.arrayDepthForObject(new java.util.Vector[0][0][0]));
- assertEquals(3, ClassTools.arrayDepthForObject(new int[0][0][0]));
- }
-
- public void testArrayDepthForClassNamed() {
- assertEquals(0, ClassTools.arrayDepthForClassNamed(java.util.Vector.class.getName()));
- assertEquals(0, ClassTools.arrayDepthForClassNamed(int.class.getName()));
- assertEquals(0, ClassTools.arrayDepthForClassNamed(void.class.getName()));
- assertEquals(1, ClassTools.arrayDepthForClassNamed(java.util.Vector[].class.getName()));
- assertEquals(1, ClassTools.arrayDepthForClassNamed(int[].class.getName()));
- assertEquals(3, ClassTools.arrayDepthForClassNamed(java.util.Vector[][][].class.getName()));
- assertEquals(3, ClassTools.arrayDepthForClassNamed(int[][][].class.getName()));
- }
-
- public void testElementTypeFor() {
- assertEquals(java.util.Vector.class, ClassTools.elementTypeFor(java.util.Vector.class));
- assertEquals(int.class, ClassTools.elementTypeFor(int.class));
- assertEquals(void.class, ClassTools.elementTypeFor(void.class));
- assertEquals(java.util.Vector.class, ClassTools.elementTypeFor(java.util.Vector[].class));
- assertEquals(int.class, ClassTools.elementTypeFor(int[].class));
- assertEquals(java.util.Vector.class, ClassTools.elementTypeFor(java.util.Vector[][][].class));
- assertEquals(int.class, ClassTools.elementTypeFor(int[][][].class));
- }
-
- public void testElementTypeForObject() {
- assertEquals(java.util.Vector.class, ClassTools.elementTypeForObject(new java.util.Vector<Object>()));
- assertEquals(java.util.Vector.class, ClassTools.elementTypeForObject(new java.util.Vector[0]));
- assertEquals(int.class, ClassTools.elementTypeForObject(new int[0]));
- assertEquals(java.util.Vector.class, ClassTools.elementTypeForObject(new java.util.Vector[0][0][0]));
- assertEquals(int.class, ClassTools.elementTypeForObject(new int[0][0][0]));
- }
-
- public void testElementTypeNameFor() {
- assertEquals(java.util.Vector.class.getName(), ClassTools.elementTypeNameFor(java.util.Vector.class));
- assertEquals(int.class.getName(), ClassTools.elementTypeNameFor(int.class));
- assertEquals(void.class.getName(), ClassTools.elementTypeNameFor(void.class));
- assertEquals(java.util.Vector.class.getName(), ClassTools.elementTypeNameFor(java.util.Vector[].class));
- assertEquals(int.class.getName(), ClassTools.elementTypeNameFor(int[].class));
- assertEquals(java.util.Vector.class.getName(), ClassTools.elementTypeNameFor(java.util.Vector[][][].class));
- assertEquals(int.class.getName(), ClassTools.elementTypeNameFor(int[][][].class));
- }
-
- public void testElementTypeNameForClassNamed() {
- assertEquals(java.util.Vector.class.getName(), ClassTools.elementTypeNameForClassNamed(java.util.Vector.class.getName()));
- assertEquals(int.class.getName(), ClassTools.elementTypeNameForClassNamed(int.class.getName()));
- assertEquals(void.class.getName(), ClassTools.elementTypeNameForClassNamed(void.class.getName()));
- assertEquals(java.util.Vector.class.getName(), ClassTools.elementTypeNameForClassNamed(java.util.Vector[].class.getName()));
- assertEquals(int.class.getName(), ClassTools.elementTypeNameForClassNamed(int[].class.getName()));
- assertEquals(java.util.Vector.class.getName(), ClassTools.elementTypeNameForClassNamed(java.util.Vector[][][].class.getName()));
- assertEquals(int.class.getName(), ClassTools.elementTypeNameForClassNamed(int[][][].class.getName()));
- }
-
- public void testClassCodes() {
- assertEquals("byte", ClassTools.classNameForCode('B'));
- assertEquals("char", ClassTools.classNameForCode('C'));
- assertEquals("double", ClassTools.classNameForCode('D'));
- assertEquals("float", ClassTools.classNameForCode('F'));
- assertEquals("int", ClassTools.classNameForCode('I'));
- assertEquals("long", ClassTools.classNameForCode('J'));
- assertEquals("short", ClassTools.classNameForCode('S'));
- assertEquals("boolean", ClassTools.classNameForCode('Z'));
- assertEquals("void", ClassTools.classNameForCode('V'));
-
- boolean exCaught = false;
- try {
- ClassTools.classNameForCode('X');
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue("IllegalArgumentException not thrown", exCaught);
- }
-
- public void testClassNamedIsTopLevel() throws Exception {
- assertTrue(ClassTools.classNamedIsTopLevel(java.util.Map.class.getName())); // top-level
- assertFalse(ClassTools.classNamedIsTopLevel(java.util.Map.Entry.class.getName())); // member
- assertFalse(ClassTools.classNamedIsTopLevel(Class.forName(munge(this.getClass().getName() + "$1$LocalClass")).getName())); // local
- assertFalse(ClassTools.classNamedIsTopLevel(Class.forName("java.util.Vector$1").getName())); // anonymous
-
- Object[] array = new java.util.Map[0]; // top-level
- assertFalse(ClassTools.classNamedIsTopLevel(array.getClass().getName()));
- array = new java.util.Map.Entry[0]; // member
- assertFalse(ClassTools.classNamedIsTopLevel(array.getClass().getName()));
- Class<?> localClass = Class.forName(munge(this.getClass().getName() + "$1$LocalClass")); // local
- array = (Object[]) Array.newInstance(localClass, 0);
- assertFalse(ClassTools.classNamedIsTopLevel(array.getClass().getName()));
- Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
- array = (Object[]) Array.newInstance(anonClass, 0);
- assertFalse(ClassTools.classNamedIsTopLevel(array.getClass().getName()));
- }
-
- public void testClassNamedIsMember() throws Exception {
- assertFalse(ClassTools.classNamedIsMember(java.util.Map.class.getName())); // top-level
- assertTrue(ClassTools.classNamedIsMember(java.util.Map.Entry.class.getName())); // member
- assertFalse(ClassTools.classNamedIsMember(Class.forName(munge(this.getClass().getName() + "$1$LocalClass")).getName())); // local
- assertFalse(ClassTools.classNamedIsMember(Class.forName("java.util.Vector$1").getName())); // anonymous
-
- Object[] array = new java.util.Map[0]; // top-level
- assertFalse(ClassTools.classNamedIsMember(array.getClass().getName()));
- array = new java.util.Map.Entry[0]; // member
- assertFalse(ClassTools.classNamedIsMember(array.getClass().getName()));
- Class<?> localClass = Class.forName(munge(this.getClass().getName() + "$1$LocalClass")); // local
- array = (Object[]) Array.newInstance(localClass, 0);
- assertFalse(ClassTools.classNamedIsMember(array.getClass().getName()));
- Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
- array = (Object[]) Array.newInstance(anonClass, 0);
- assertFalse(ClassTools.classNamedIsMember(array.getClass().getName()));
-
- // test a few edge cases
- assertTrue(ClassTools.classNamedIsMember("java.util.Map$a1"));
- assertTrue(ClassTools.classNamedIsMember("java.util.Map$a1$aaa$bbb"));
- assertFalse(ClassTools.classNamedIsMember("java.util.Map$1a1$aaa"));
- assertFalse(ClassTools.classNamedIsMember("java.util.Map$1a"));
- assertTrue(ClassTools.classNamedIsMember("java.util.Map$a12345$b12345"));
- assertFalse(ClassTools.classNamedIsMember("java.util.Map$12345a"));
- assertFalse(ClassTools.classNamedIsMember("java.util.Map$333"));
- assertFalse(ClassTools.classNamedIsMember("java.util.Map3$333"));
- }
-
- public void testClassNamedIsLocal() throws Exception {
- class LocalClass {
- void foo() {
- System.getProperty("foo");
- }
- }
- new LocalClass().foo();
- assertFalse(ClassTools.classNamedIsLocal(java.util.Map.class.getName())); // top-level
- assertFalse(ClassTools.classNamedIsLocal(java.util.Map.Entry.class.getName())); // member
- assertTrue(ClassTools.classNamedIsLocal(Class.forName(munge(this.getClass().getName() + "$1$LocalClass")).getName())); // local
- assertFalse(ClassTools.classNamedIsLocal(Class.forName("java.util.Vector$1").getName())); // anonymous
-
- Object[] array = new java.util.Map[0]; // top-level
- assertFalse(ClassTools.classNamedIsLocal(array.getClass().getName()));
- array = new java.util.Map.Entry[0]; // member
- assertFalse(ClassTools.classNamedIsLocal(array.getClass().getName()));
- Class<?> localClass = Class.forName(munge(this.getClass().getName() + "$1$LocalClass")); // local
- array = (Object[]) Array.newInstance(localClass, 0);
- assertFalse(ClassTools.classNamedIsLocal(array.getClass().getName()));
- Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
- array = (Object[]) Array.newInstance(anonClass, 0);
- assertFalse(ClassTools.classNamedIsLocal(array.getClass().getName()));
-
- // test a few edge cases
- assertFalse(ClassTools.classNamedIsLocal("java.util.Map$a1"));
- assertFalse(ClassTools.classNamedIsLocal("java.util.Map$a1$aaa$bbb"));
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$11$aaa"));
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$1$a")); // eclipse naming convention
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$2$abc")); // eclipse naming convention
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$2$abc1")); // eclipse naming convention
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$1a")); // jdk naming convention
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$2abc")); // jdk naming convention
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$2abc1")); // jdk naming convention
- assertFalse(ClassTools.classNamedIsLocal("java.util.Map$a12345$b12345"));
- assertTrue(ClassTools.classNamedIsLocal("java.util.Map$12345$a1234"));
- assertFalse(ClassTools.classNamedIsLocal("java.util.Map$333"));
- assertFalse(ClassTools.classNamedIsLocal("java.util.Map3$333"));
- }
-
- public void testClassNamedIsAnonymous() throws Exception {
- assertFalse(ClassTools.classNamedIsAnonymous(java.util.Map.class.getName())); // top-level
- assertFalse(ClassTools.classNamedIsAnonymous(java.util.Map.Entry.class.getName())); // member
- assertFalse(ClassTools.classNamedIsAnonymous(Class.forName(munge(this.getClass().getName() + "$1$LocalClass")).getName())); // local
- assertTrue(ClassTools.classNamedIsAnonymous(Class.forName("java.util.Vector$1").getName())); // anonymous
-
- Object[] array = new java.util.Map[0]; // top-level
- assertFalse(ClassTools.classNamedIsAnonymous(array.getClass().getName()));
- array = new java.util.Map.Entry[0]; // member
- assertFalse(ClassTools.classNamedIsAnonymous(array.getClass().getName()));
- Class<?> localClass = Class.forName(munge(this.getClass().getName() + "$1$LocalClass")); // local
- array = (Object[]) Array.newInstance(localClass, 0);
- assertFalse(ClassTools.classNamedIsAnonymous(array.getClass().getName()));
- Class<?> anonClass = Class.forName("java.util.Vector$1"); // local
- array = (Object[]) Array.newInstance(anonClass, 0);
- assertFalse(ClassTools.classNamedIsAnonymous(array.getClass().getName()));
-
- // test a few edge cases
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$a1"));
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$a1$aaa$bbb"));
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$1a1$aaa"));
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$1$a"));
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$1a"));
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$a12345$b12345"));
- assertFalse(ClassTools.classNamedIsAnonymous("java.util.Map$12345$a1234"));
- assertTrue(ClassTools.classNamedIsAnonymous("java.util.Map$333"));
- assertTrue(ClassTools.classNamedIsAnonymous("java.util.Map3$333"));
- }
-
- public void testCodeForClass() {
- assertEquals('I', ClassTools.codeForClass(int.class));
- assertEquals('B', ClassTools.codeForClass(byte.class));
- }
-
- public void testCodeForClassNamed() {
- assertEquals('I', ClassTools.codeForClassNamed(int.class.getName()));
- assertEquals('I', ClassTools.codeForClassNamed("int"));
- assertEquals('B', ClassTools.codeForClassNamed(byte.class.getName()));
- assertEquals('B', ClassTools.codeForClassNamed("byte"));
- }
-
- public void testClassIsPrimitiveWrapperClass() {
- assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Void.class));
- assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Boolean.class));
- assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Integer.class));
- assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Float.class));
-
- assertFalse(ClassTools.classIsPrimitiveWrapperClass(java.lang.String.class));
- assertFalse(ClassTools.classIsPrimitiveWrapperClass(void.class));
- assertFalse(ClassTools.classIsPrimitiveWrapperClass(int.class));
- }
-
- public void testClassIsVariablePrimitiveWrapperClass() {
- assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Void.class));
-
- assertTrue(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Boolean.class));
- assertTrue(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Integer.class));
- assertTrue(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Float.class));
-
- assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.String.class));
- assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(void.class));
- assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(int.class));
- }
-
- public void testClassNamedIsPrimitive() {
- assertTrue(void.class.isPrimitive());
-
- assertTrue(ClassTools.classNamedIsPrimitive(void.class.getName()));
- assertTrue(ClassTools.classNamedIsPrimitive(int.class.getName()));
- assertTrue(ClassTools.classNamedIsPrimitive(float.class.getName()));
- assertTrue(ClassTools.classNamedIsPrimitive(boolean.class.getName()));
-
- assertFalse(ClassTools.classNamedIsPrimitive(java.lang.Number.class.getName()));
- assertFalse(ClassTools.classNamedIsPrimitive(java.lang.String.class.getName()));
- assertFalse(ClassTools.classNamedIsPrimitive(java.lang.Boolean.class.getName()));
- assertFalse(ClassTools.classNamedIsPrimitive(java.lang.Integer.class.getName()));
- }
-
- public void testClassNamedIsVariablePrimitive() {
- assertFalse(ClassTools.classNamedIsVariablePrimitive(void.class.getName()));
-
- assertTrue(ClassTools.classNamedIsVariablePrimitive(int.class.getName()));
- assertTrue(ClassTools.classNamedIsVariablePrimitive(float.class.getName()));
- assertTrue(ClassTools.classNamedIsVariablePrimitive(boolean.class.getName()));
-
- assertFalse(ClassTools.classNamedIsVariablePrimitive(java.lang.Number.class.getName()));
- assertFalse(ClassTools.classNamedIsVariablePrimitive(java.lang.String.class.getName()));
- assertFalse(ClassTools.classNamedIsVariablePrimitive(java.lang.Boolean.class.getName()));
- }
-
- public void testWrapperClassName() {
- assertEquals(java.lang.Void.class.getName(), ClassTools.wrapperClassName(void.class.getName()));
- assertEquals(java.lang.Integer.class.getName(), ClassTools.wrapperClassName(int.class.getName()));
- assertEquals(java.lang.Float.class.getName(), ClassTools.wrapperClassName(float.class.getName()));
- assertEquals(java.lang.Boolean.class.getName(), ClassTools.wrapperClassName(boolean.class.getName()));
-
- try {
- ClassTools.wrapperClassName(java.lang.String.class.getName());
- fail("should not get here...");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-
- public void testWrapperClass() {
- assertEquals(java.lang.Void.class, ClassTools.wrapperClass(void.class));
- assertEquals(java.lang.Integer.class, ClassTools.wrapperClass(int.class));
- assertEquals(java.lang.Float.class, ClassTools.wrapperClass(float.class));
- assertEquals(java.lang.Boolean.class, ClassTools.wrapperClass(boolean.class));
-
- try {
- ClassTools.wrapperClass(java.lang.String.class);
- fail("should not get here...");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-
- public void testClassNamedIsVariablePrimitiveWrapperClass() {
- assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Void.class.getName()));
-
- assertTrue(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Integer.class.getName()));
- assertTrue(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Float.class.getName()));
- assertTrue(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Boolean.class.getName()));
-
- assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Number.class.getName()));
- assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.String.class.getName()));
- assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Object.class.getName()));
- }
-
- public void testClassForTypeDeclarationStringInt() throws Exception {
- assertEquals(int.class, ClassTools.classForTypeDeclaration("int", 0));
- assertEquals(int[].class, ClassTools.classForTypeDeclaration("int", 1));
- assertEquals(int[][][].class, ClassTools.classForTypeDeclaration("int", 3));
-
- assertEquals(Object.class, ClassTools.classForTypeDeclaration("java.lang.Object", 0));
- assertEquals(Object[][][].class, ClassTools.classForTypeDeclaration("java.lang.Object", 3));
-
- assertEquals(void.class, ClassTools.classForTypeDeclaration("void", 0));
- try {
- ClassTools.classForTypeDeclaration(void.class.getName(), 1);
- fail("should not get here...");
- } catch (ClassNotFoundException ex) {
- // expected
- }
- }
-
- public void testClassNameForTypeDeclarationString() throws Exception {
- assertEquals("int", ClassTools.classNameForTypeDeclaration("int"));
- assertEquals("[I", ClassTools.classNameForTypeDeclaration("int[]"));
- assertEquals("[[I", ClassTools.classNameForTypeDeclaration("int [ ] [ ]"));
-
- assertEquals("java.lang.Object", ClassTools.classNameForTypeDeclaration("java.lang.Object"));
- assertEquals("[Ljava.lang.Object;", ClassTools.classNameForTypeDeclaration("java.lang.Object\t[]"));
- assertEquals("[[Ljava.lang.Object;", ClassTools.classNameForTypeDeclaration("java.lang.Object\t[]\t[]"));
- }
-
- public void testArrayDepthForTypeDeclarationString() throws Exception {
- assertEquals(0, ClassTools.arrayDepthForTypeDeclaration("java.lang.Object"));
- assertEquals(1, ClassTools.arrayDepthForTypeDeclaration("java.lang.Object[]"));
- assertEquals(3, ClassTools.arrayDepthForTypeDeclaration("java.lang.Object[][][]"));
-
- assertEquals(0, ClassTools.arrayDepthForTypeDeclaration("int"));
- assertEquals(1, ClassTools.arrayDepthForTypeDeclaration("int[]"));
- assertEquals(3, ClassTools.arrayDepthForTypeDeclaration("int[][][]"));
-
- assertEquals(0, ClassTools.arrayDepthForTypeDeclaration("float"));
- assertEquals(1, ClassTools.arrayDepthForTypeDeclaration("float [ ]"));
- assertEquals(3, ClassTools.arrayDepthForTypeDeclaration("float[] [] []"));
- }
-
- public void testElementTypeNameForTypeDeclarationString() throws Exception {
- assertEquals("java.lang.Object", ClassTools.elementTypeNameForTypeDeclaration("java.lang.Object"));
- assertEquals("java.lang.Object", ClassTools.elementTypeNameForTypeDeclaration("java.lang.Object[]"));
- assertEquals("java.lang.Object", ClassTools.elementTypeNameForTypeDeclaration("java.lang.Object[][][]"));
-
- assertEquals("int", ClassTools.elementTypeNameForTypeDeclaration("int"));
- assertEquals("int", ClassTools.elementTypeNameForTypeDeclaration("int[]"));
- assertEquals("int", ClassTools.elementTypeNameForTypeDeclaration("int[][][]"));
-
- assertEquals("float", ClassTools.elementTypeNameForTypeDeclaration("float"));
- assertEquals("float", ClassTools.elementTypeNameForTypeDeclaration("float [ ]"));
- assertEquals("float", ClassTools.elementTypeNameForTypeDeclaration("float[] [] []"));
- }
-
- public void testClassNameForTypeDeclarationStringInt() throws Exception {
- assertEquals(int.class.getName(), ClassTools.classNameForTypeDeclaration("int", 0));
- assertEquals(int[].class.getName(), ClassTools.classNameForTypeDeclaration("int", 1));
- assertEquals(int[][][].class.getName(), ClassTools.classNameForTypeDeclaration("int", 3));
-
- assertEquals(Object.class.getName(), ClassTools.classNameForTypeDeclaration("java.lang.Object", 0));
- assertEquals(Object[][][].class.getName(), ClassTools.classNameForTypeDeclaration("java.lang.Object", 3));
-
- assertEquals(void.class.getName(), ClassTools.classNameForTypeDeclaration("void", 0));
- try {
- ClassTools.classNameForTypeDeclaration(void.class.getName(), 1);
- fail("should not get here...");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-
- private Iterator<String> names(Field[] fields) {
- return new TransformationIterator<Field, String>(CollectionTools.iterator(fields)) {
- @Override
- protected String transform(Field field) {
- return field.getName();
- }
- };
- }
-
- private Iterator<String> names(Method[] methods) {
- return new TransformationIterator<Method, String>(CollectionTools.iterator(methods)) {
- @Override
- protected String transform(Method method) {
- return method.getName();
- }
- };
- }
-
-}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java
index 0263de0c3c..e219032fe9 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,6 +12,9 @@ package org.eclipse.jpt.utility.tests.internal;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -19,7 +22,9 @@ import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.ArrayTools;
import org.eclipse.jpt.utility.internal.Classpath;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+@SuppressWarnings("nls")
public class ClasspathTests extends TestCase {
private static final String JAVA_HOME = System.getProperty("java.home");
@@ -31,35 +36,35 @@ public class ClasspathTests extends TestCase {
String path = "";
// no changes
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\i18n.jar;C:\\jdk\\i18n.jar;C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\i18n.jar;C:\\jdk\\i18n.jar;C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;;;;C:\\jdk\\jaws.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;;;")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;;;;C:\\jdk\\jaws.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;;;")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
// no changes
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\..\\jdk\\i18n.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\..\\jdk\\i18n.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
- path = new Classpath(this.morph("C:\\jdk1\\jdk2\\jdk3\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk1\\jdk2\\jdk3\\..\\..\\..\\jdk1\\jdk2\\jdk3\\i18n.jar;C:\\jdk\\jaws.jar")).compressed().path();
+ path = new Classpath(this.morph("C:\\jdk1\\jdk2\\jdk3\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk1\\jdk2\\jdk3\\..\\..\\..\\jdk1\\jdk2\\jdk3\\i18n.jar;C:\\jdk\\jaws.jar")).compressed().getPath();
assertEquals(this.morph("C:\\jdk1\\jdk2\\jdk3\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar"), path);
}
@@ -83,107 +88,144 @@ public class ClasspathTests extends TestCase {
assertEquals("java/lang/String.class", fileName);
}
+ public void testConvertToArchiveEntryNameBase() {
+ String fileName = Classpath.convertToArchiveEntryNameBase(java.lang.String.class);
+ assertEquals("java/lang/String", fileName);
+ }
+
public void testConvertToClassFileName() {
char sc = File.separatorChar;
String fileName = Classpath.convertToClassFileName(java.lang.String.class);
assertEquals("java" + sc + "lang" + sc + "String.class", fileName);
}
+ public void testConvertToClassFileString() {
+ char sc = File.separatorChar;
+ File file = Classpath.convertToClassFile(java.lang.String.class.getName());
+ assertEquals("java" + sc + "lang" + sc + "String.class", file.getPath());
+ }
+
+ public void testConvertToClassFileClass() {
+ char sc = File.separatorChar;
+ File file = Classpath.convertToClassFile(java.lang.String.class);
+ assertEquals("java" + sc + "lang" + sc + "String.class", file.getPath());
+ }
+
public void testConvertToJavaFileName() {
char sc = File.separatorChar;
- String fileName = Classpath.convertToJavaFileName(java.lang.String.class.getName());
+ String fileName = Classpath.convertToJavaFileName(java.lang.String.class);
assertEquals("java" + sc + "lang" + sc + "String.java", fileName);
}
+ public void testConvertToJavaFileString() {
+ char sc = File.separatorChar;
+ File file = Classpath.convertToJavaFile(java.lang.String.class.getName());
+ assertEquals("java" + sc + "lang" + sc + "String.java", file.getPath());
+ }
+
+ public void testConvertToJavaFileClass() {
+ char sc = File.separatorChar;
+ File file = Classpath.convertToJavaFile(java.lang.String.class);
+ assertEquals("java" + sc + "lang" + sc + "String.java", file.getPath());
+ }
+
+ public void testConvertToFileNameBase() {
+ char sc = File.separatorChar;
+ String fileName = Classpath.convertToFileNameBase(java.lang.String.class);
+ assertEquals("java" + sc + "lang" + sc + "String", fileName);
+ }
+
public void testConvertToURLs() {
- URL[] entries = new Classpath(this.morph("C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).urls();
- int i = 0;
- assertEquals(this.morphURL("/C:/jdk/rt.jar"), entries[i++].getPath());
- assertEquals(this.morphURL("/C:/jdk/i18n.jar"), entries[i++].getPath());
- assertEquals(this.morphURL("/C:/jdk/jaws.jar"), entries[i++].getPath());
- assertEquals(this.morphURL("/C:/foo/classes"), entries[i++].getPath());
- assertEquals(this.morphURL("/C:/bar/bar.jar"), entries[i++].getPath());
- assertEquals(i, entries.length);
+ Iterator<URL> entries = new Classpath(this.morph("C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getURLs().iterator();
+ assertEquals(this.morphURL("/C:/jdk/rt.jar"), entries.next().getPath());
+ assertEquals(this.morphURL("/C:/jdk/i18n.jar"), entries.next().getPath());
+ assertEquals(this.morphURL("/C:/jdk/jaws.jar"), entries.next().getPath());
+ assertEquals(this.morphURL("/C:/foo/classes"), entries.next().getPath());
+ assertEquals(this.morphURL("/C:/bar/bar.jar"), entries.next().getPath());
+ assertFalse(entries.hasNext());
}
- public void testEntries() {
+ public void testGetEntries() {
Classpath cp = new Classpath(this.morph("C:\\jdk\\rt.jar;;.;C:\\jdk\\i18n.jar;;;C:\\jdk\\jaws.jar;;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\bar\\bar.jar;"));
- Classpath.Entry[] entries = cp.entries();
- int i = 0;
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entries[i++].fileName());
- assertEquals(this.morph("."), entries[i++].fileName());
- assertEquals(this.morph("C:\\jdk\\i18n.jar"), entries[i++].fileName());
- assertEquals(this.morph("C:\\jdk\\jaws.jar"), entries[i++].fileName());
- assertEquals(this.morph("C:\\foo\\classes"), entries[i++].fileName());
- assertEquals(this.morph("C:\\bar\\bar.jar"), entries[i++].fileName());
- assertEquals(this.morph("C:\\bar\\bar.jar"), entries[i++].fileName());
- assertEquals(i, entries.length);
+ Iterator<Classpath.Entry> entries = cp.getEntries().iterator();
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entries.next().getFileName());
+ assertEquals(this.morph("."), entries.next().getFileName());
+ assertEquals(this.morph("C:\\jdk\\i18n.jar"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\jdk\\jaws.jar"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\foo\\classes"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\bar\\bar.jar"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\bar\\bar.jar"), entries.next().getFileName());
+ assertFalse(entries.hasNext());
cp = cp.compressed();
- entries = cp.entries();
- i = 0;
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entries[i++].fileName());
- assertEquals(this.morph("."), entries[i++].fileName());
- assertEquals(this.morph("C:\\jdk\\i18n.jar"), entries[i++].fileName());
- assertEquals(this.morph("C:\\jdk\\jaws.jar"), entries[i++].fileName());
- assertEquals(this.morph("C:\\foo\\classes"), entries[i++].fileName());
- assertEquals(this.morph("C:\\bar\\bar.jar"), entries[i++].fileName());
- assertEquals(i, entries.length);
- }
-
- public void testEntryForFileNamed() {
+ entries = cp.getEntries().iterator();
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entries.next().getFileName());
+ assertEquals(this.morph("."), entries.next().getFileName());
+ assertEquals(this.morph("C:\\jdk\\i18n.jar"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\jdk\\jaws.jar"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\foo\\classes"), entries.next().getFileName());
+ assertEquals(this.morph("C:\\bar\\bar.jar"), entries.next().getFileName());
+ assertFalse(entries.hasNext());
+ }
+
+ public void testGetEntryForFileNamed() {
Classpath.Entry entry = null;
// in the middle - qualified
- entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\rt.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// in the middle - unqualified
- entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;rt.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).entryForFileNamed("rt.jar");
- assertEquals("rt.jar", entry.fileName());
+ entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;rt.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals("rt.jar", entry.getFileName());
// at the beginning - qualified
- entry = new Classpath(this.morph("C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// at the beginning - unqualified
- entry = new Classpath(this.morph("rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).entryForFileNamed("rt.jar");
- assertEquals("rt.jar", entry.fileName());
+ entry = new Classpath(this.morph("rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals("rt.jar", entry.getFileName());
// at the end - qualified
- entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\jdk\\rt.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\jdk\\rt.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// at the end - unqualified
- entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;rt.jar")).entryForFileNamed("rt.jar");
- assertEquals("rt.jar", entry.fileName());
+ entry = new Classpath(this.morph("C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;rt.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals("rt.jar", entry.getFileName());
// alone - qualified
- entry = new Classpath(this.morph("C:\\jdk\\rt.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("C:\\jdk\\rt.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// alone - unqualified
- entry = new Classpath("rt.jar").entryForFileNamed("rt.jar");
- assertEquals("rt.jar", entry.fileName());
+ entry = new Classpath("rt.jar").getEntryForFileNamed("rt.jar");
+ assertEquals("rt.jar", entry.getFileName());
// trick entry at the beginning
- entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// trick entry in the middle
- entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rtrtrt.jar;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rtrtrt.jar;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// trick entry at the end
- entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rtrtrt.jar;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\jdk\\rtrtrt.jar")).entryForFileNamed("rt.jar");
- assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.fileName());
+ entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rtrtrt.jar;C:\\jdk\\rt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\jdk\\rtrtrt.jar")).getEntryForFileNamed("rt.jar");
+ assertEquals(this.morph("C:\\jdk\\rt.jar"), entry.getFileName());
// missing
- entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rtrtrt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\jdk\\rtrtrt.jar")).entryForFileNamed("rt.jar");
+ entry = new Classpath(this.morph("rt.jar.new;C:\\jdk\\rtrtrt.jar;C:\\jdk\\i18n.jar;C:\\jdk\\jaws.jar;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\jdk\\rtrtrt.jar")).getEntryForFileNamed("rt.jar");
assertEquals("path entry should not be found", null, entry);
}
+ public void testGetEntryForClassNamed() {
+ assertNotNull(Classpath.completeClasspath().getEntryForClassNamed(java.lang.String.class.getName()));
+ assertNull(Classpath.completeClasspath().getEntryForClassNamed("foo.bar.Baz"));
+ }
+
public void testLocationForClass() {
Class<?> javaClass = Classpath.class;
File entry = new File(Classpath.locationFor(javaClass));
@@ -206,8 +248,8 @@ public class ClasspathTests extends TestCase {
}
public void testJREClassNames() {
- assertTrue("Vector is missing from JRE class names", ArrayTools.contains(Classpath.bootClasspath().classNames(), java.util.Vector.class.getName()));
- assertTrue("File is missing from JRE class names", ArrayTools.contains(Classpath.bootClasspath().classNames(), java.io.File.class.getName()));
+ assertTrue("Vector is missing from JRE class names", CollectionTools.contains(Classpath.bootClasspath().getClassNames(), java.util.Vector.class.getName()));
+ assertTrue("File is missing from JRE class names", CollectionTools.contains(Classpath.bootClasspath().getClassNames(), java.io.File.class.getName()));
}
public void testJavaExtensionDirectoryNames() {
@@ -222,36 +264,32 @@ public class ClasspathTests extends TestCase {
assertTrue("standard extension dir missing: " + stdExtDir.getParent(), ArrayTools.contains(Classpath.javaExtensionDirectories(), stdExtDir));
}
- //Commented out due to incompatibility with IBM JDK (used in Eclipse WTP Build)
- //TODO Test should be revised to be compatible with IBM JDK
- // public void testJavaExtensionClasspathEntries() {
- // char sep = File.separatorChar;
- // String jdk = System.getProperty("java.version");
- // if (jdk.startsWith("1.4") || jdk.startsWith("1.5")) {
- // Collection jarNames = new ArrayList();
- // Classpath.Entry[] entries = Classpath.javaExtensionClasspath().getEntries();
- // for (int i = 0; i < entries.length; i++) {
- // jarNames.add(entries[i].fileName());
- // }
- // String stdExtJarName = JAVA_HOME + sep + "lib" + sep + "ext" + sep + "dnsns.jar";
- // assertTrue("jdk 1.4.x standard extension jar missing: " + stdExtJarName, jarNames.contains(stdExtJarName));
- // } else {
- // fail("we need to update this test for the current jdk");
- // }
- // }
-
- //Commented out due to incompatibility with IBM JDK (used in Eclipse WTP Build)
- //TODO Test should be revised to be compatible with IBM JDK
- // public void testJavaExtensionClassNames() {
- // String jdk = System.getProperty("java.version");
- // if (jdk.startsWith("1.4") || jdk.startsWith("1.5")) {
- // String className = "sun.net.spi.nameservice.dns.DNSNameService";
- // assertTrue("jdk 1.4.x standard extension class missing: " + className,
- // ArrayTools.contains(Classpath.javaExtensionClasspath().classNames(), className));
- // } else {
- // fail("we need to update this test for the current jdk");
- // }
- // }
+ public void testJavaExtensionClasspathEntries() {
+ char sep = File.separatorChar;
+ String jdk = System.getProperty("java.version");
+ if (jdk.startsWith("1.4") || jdk.startsWith("1.5") || jdk.startsWith("1.6")) {
+ Collection<String> jarNames = new ArrayList<String>();
+ Iterable<Classpath.Entry> entries = Classpath.javaExtensionClasspath().getEntries();
+ for (Classpath.Entry entry : entries) {
+ jarNames.add(entry.getFileName());
+ }
+ String stdExtJarName = JAVA_HOME + sep + "lib" + sep + "ext" + sep + "dnsns.jar";
+ assertTrue("jdk 1.4.x standard extension jar missing: " + stdExtJarName, jarNames.contains(stdExtJarName));
+ } else {
+ fail("we need to update this test for the current jdk");
+ }
+ }
+
+ public void testJavaExtensionClassNames() {
+ String jdk = System.getProperty("java.version");
+ if (jdk.startsWith("1.4") || jdk.startsWith("1.5") || jdk.startsWith("1.6")) {
+ String className = "sun.net.spi.nameservice.dns.DNSNameService";
+ assertTrue("jdk 1.4.x standard extension class missing: " + className,
+ CollectionTools.contains(Classpath.javaExtensionClasspath().classNames(), className));
+ } else {
+ fail("we need to update this test for the current jdk");
+ }
+ }
public void testJavaClasspathClassNames() {
String className = this.getClass().getName();
@@ -260,10 +298,70 @@ public class ClasspathTests extends TestCase {
// when the tests are executed as an ANT task, they are run under
// an ANT class loader and the "Java" classpath does not include this class
if (cl.getClass().getName().startsWith("sun.misc")) {
- assertTrue("class missing: " + className, ArrayTools.contains(Classpath.javaClasspath().classNames(), className));
+ assertTrue("class missing: " + className, CollectionTools.contains(Classpath.javaClasspath().getClassNames(), className));
+ }
+ }
+
+ public void testCompleteClasspathClassNames() {
+ String className = this.getClass().getName();
+ ClassLoader cl = this.getClass().getClassLoader();
+ // make sure we are running under the "normal" class loader;
+ // when the tests are executed as an ANT task, they are run under
+ // an ANT class loader and the "Java" classpath does not include this class
+ if (cl.getClass().getName().startsWith("sun.misc")) {
+ assertTrue("class missing: " + className, CollectionTools.contains(Classpath.completeClasspath().getClassNames(), className));
}
}
+ public void testClasspathForClass() {
+ assertNotNull(Classpath.classpathFor(java.lang.String.class));
+ }
+
+ public void testAddClassNamesTo() {
+ Collection<String> classNames = new ArrayList<String>(1000);
+ Classpath.bootClasspath().addClassNamesTo(classNames);
+ assertTrue(classNames.contains(java.util.Vector.class.getName()));
+ }
+
+ public void testToString() {
+ assertNotNull(Classpath.bootClasspath().toString());
+ }
+
+ public void testEntry_getCanonicalFile() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertTrue(entry.getCanonicalFile().getPath().endsWith(".jar"));
+ }
+
+ public void testEntry_getCanonicalFileName() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertTrue(entry.getCanonicalFileName().endsWith("rt.jar"));
+ }
+
+ public void testEntry_equals() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertFalse(entry.equals("foo"));
+ }
+
+ public void testEntry_containsClass() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertTrue(entry.contains(java.lang.String.class));
+ }
+
+ public void testEntry_containsString() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertTrue(entry.contains(java.lang.String.class.getName()));
+ }
+
+ public void testEntry_getClassNames() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertTrue(CollectionTools.contains(entry.getClassNames(), java.lang.String.class.getName()));
+ }
+
+ public void testEntry_classNames() {
+ Classpath.Entry entry = Classpath.bootClasspath().getEntryForClassNamed(java.lang.String.class.getName());
+ assertTrue(CollectionTools.contains(entry.classNames(), java.lang.String.class.getName()));
+ }
+
/**
* morph the specified path to a platform-independent path
*/
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java
index 92d0523361..52cec208fe 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -29,6 +30,7 @@ import java.util.Vector;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.Bag;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.Range;
@@ -2213,6 +2215,21 @@ public class CollectionToolsTests extends TestCase {
assertEquals(original.get(2), result.get(2));
}
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ReflectionTools.newInstance(CollectionTools.class);
+ fail("bogus: " + at); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+
// ********** test harness **********
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java
index 5ad5e1b869..3b0fd9a01e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandExecutorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -47,6 +47,11 @@ public class CommandExecutorTests extends TestCase {
}
}
+ public void testThreadLocalCommandExecutor_toString() throws Exception {
+ CommandExecutor commandExecutor = new ThreadLocalCommandExecutor();
+ assertNotNull(commandExecutor.toString());
+ }
+
public void testThreadLocalCommandExecutor() throws Exception {
ThreadLocalCommandExecutor threadLocalCommandExecutor = new ThreadLocalCommandExecutor();
TestRunnable testRunnable1 = new TestRunnable(threadLocalCommandExecutor, 1);
@@ -57,14 +62,22 @@ public class CommandExecutorTests extends TestCase {
Thread thread2 = new Thread(testRunnable2);
thread2.run();
+ TestRunnable testRunnable3 = new TestRunnable(threadLocalCommandExecutor, 3, null);
+ Thread thread3 = new Thread(testRunnable3);
+ thread3.run();
+
thread1.join();
thread2.join();
+ thread3.join();
assertEquals(1, testRunnable1.testCommand.count);
assertEquals(1, testRunnable1.testCommandExecutor.count);
assertEquals(2, testRunnable2.testCommand.count);
assertEquals(2, testRunnable2.testCommandExecutor.count);
+
+ assertEquals(3, testRunnable3.testCommand.count);
+ assertNull(testRunnable3.testCommandExecutor);
}
static class TestCommandExecutor implements CommandExecutor {
@@ -79,11 +92,15 @@ public class CommandExecutorTests extends TestCase {
final ThreadLocalCommandExecutor threadLocalCommandExecutor;
final int executionCount;
final TestCommand testCommand = new TestCommand();
- final TestCommandExecutor testCommandExecutor = new TestCommandExecutor();
+ final TestCommandExecutor testCommandExecutor;
TestRunnable(ThreadLocalCommandExecutor threadLocalCommandExecutor, int executionCount) {
+ this(threadLocalCommandExecutor, executionCount, new TestCommandExecutor());
+ }
+ TestRunnable(ThreadLocalCommandExecutor threadLocalCommandExecutor, int executionCount, TestCommandExecutor testCommandExecutor) {
super();
this.threadLocalCommandExecutor = threadLocalCommandExecutor;
this.executionCount = executionCount;
+ this.testCommandExecutor = testCommandExecutor;
}
public void run() {
this.threadLocalCommandExecutor.set(this.testCommandExecutor);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandRunnableTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandRunnableTests.java
new file mode 100644
index 0000000000..717d813f69
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CommandRunnableTests.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.Command;
+import org.eclipse.jpt.utility.internal.CommandRunnable;
+
+@SuppressWarnings("nls")
+public class CommandRunnableTests extends TestCase {
+ boolean commandExecuted = false;
+
+ public CommandRunnableTests(String name) {
+ super(name);
+ }
+
+ public void testNullCommand() {
+ boolean exCaught = false;
+ try {
+ Runnable runnable = new CommandRunnable(null);
+ fail("bogus: " + runnable);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testRun() {
+ Runnable runnable = new CommandRunnable(this.buildCommand());
+ runnable.run();
+ assertTrue(this.commandExecuted);
+ }
+
+ public void testToString() {
+ Runnable runnable = new CommandRunnable(this.buildCommand());
+ assertNotNull(runnable.toString());
+ }
+
+ private Command buildCommand() {
+ return new Command() {
+ public void execute() {
+ CommandRunnableTests.this.commandExecuted = true;
+ }
+ };
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CompositeCommandTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CompositeCommandTests.java
new file mode 100644
index 0000000000..ff81cd152c
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CompositeCommandTests.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.utility.tests.internal;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.Command;
+import org.eclipse.jpt.utility.internal.CommandRunnable;
+import org.eclipse.jpt.utility.internal.CompositeCommand;
+
+public class CompositeCommandTests extends TestCase {
+ boolean command1Executed = false;
+ boolean command2Executed = false;
+
+ public CompositeCommandTests(String name) {
+ super(name);
+ }
+
+ public void testRun() {
+ Runnable runnable = new CommandRunnable(this.buildCompositeCommand());
+ runnable.run();
+ assertTrue(this.command1Executed);
+ assertTrue(this.command2Executed);
+ }
+
+ public void testToString() {
+ Runnable runnable = new CommandRunnable(this.buildCompositeCommand());
+ assertNotNull(runnable.toString());
+ }
+
+ private Command buildCompositeCommand() {
+ return new CompositeCommand(
+ this.buildCommand1(),
+ this.buildCommand2()
+ );
+ }
+
+ private Command buildCommand1() {
+ return new Command() {
+ public void execute() {
+ CompositeCommandTests.this.command1Executed = true;
+ }
+ };
+ }
+
+ private Command buildCommand2() {
+ return new Command() {
+ public void execute() {
+ CompositeCommandTests.this.command2Executed = true;
+ }
+ };
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/FileToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/FileToolsTests.java
index 7c297fadaf..cb02a0c888 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/FileToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/FileToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,11 +23,15 @@ import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
+
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.FileTools;
+import org.eclipse.jpt.utility.internal.Tools;
+@SuppressWarnings("nls")
public class FileToolsTests extends TestCase {
private File tempDir;
@@ -210,23 +214,11 @@ public class FileToolsTests extends TestCase {
assertEquals(file2, file3);
}
- private boolean isExecutingOnWindows() {
- return this.isExecutingOn("Windows");
- }
-
- // private boolean isExecutingOnLinux() {
- // return this.isExecutingOn("Linux");
- // }
- //
- private boolean isExecutingOn(String osName) {
- return System.getProperty("os.name").indexOf(osName) != -1;
- }
-
public void testPathFiles() {
File[] expected;
File[] actual;
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
expected = new File[] { new File("C:/"), new File("C:/foo"), new File("C:/foo/bar"), new File("C:/foo/bar/baz.txt") };
actual = this.pathFiles(new File("C:/foo/bar/baz.txt"));
assertTrue(Arrays.equals(expected, actual));
@@ -250,7 +242,7 @@ public class FileToolsTests extends TestCase {
}
private File[] pathFiles(File file) {
- return (File[]) ClassTools.executeStaticMethod(FileTools.class, "pathFiles", File.class, file);
+ return (File[]) ReflectionTools.executeStaticMethod(FileTools.class, "pathFiles", File.class, file);
}
public void testRelativeParentFile() {
@@ -274,16 +266,16 @@ public class FileToolsTests extends TestCase {
}
private File relativeParentFile(int len) {
- return (File) ClassTools.executeStaticMethod(FileTools.class, "relativeParentFile", int.class, new Integer(len));
+ return (File) ReflectionTools.executeStaticMethod(FileTools.class, "relativeParentFile", int.class, new Integer(len));
}
public void testConvertToRelativeFile() {
- String prefix = this.isExecutingOnWindows() ? "C:" : "";
+ String prefix = Tools.osIsWindows() ? "C:" : "";
File file;
File dir;
File relativeFile;
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
// on Windows, a drive must be specified for a file to be absolute (i.e. not relative)
this.verifyUnchangedRelativeFile("/dir1/dir2/file.txt", "C:/dir1/dir2");
// different drives
@@ -347,12 +339,12 @@ public class FileToolsTests extends TestCase {
}
public void testConvertToAbsoluteFile() {
- String prefix = this.isExecutingOnWindows() ? "C:" : "";
+ String prefix = Tools.osIsWindows() ? "C:" : "";
File file;
File dir;
File absoluteFile;
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
// on Windows, a drive must be specified for a file to be absolute (i.e. not relative)
this.verifyUnchangedAbsoluteFile("C:/dir1/dir2/file.txt", "C:/dir1/dir2");
// different drives
@@ -421,7 +413,7 @@ public class FileToolsTests extends TestCase {
}
public void testFileNameIsReserved() {
- boolean expected = this.isExecutingOnWindows();
+ boolean expected = Tools.osIsWindows();
assertEquals(expected, FileTools.fileNameIsReserved("CON"));
assertEquals(expected, FileTools.fileNameIsReserved("con"));
assertEquals(expected, FileTools.fileNameIsReserved("cON"));
@@ -433,7 +425,7 @@ public class FileToolsTests extends TestCase {
}
public void testFileHasAnyReservedComponents() {
- boolean expected = this.isExecutingOnWindows();
+ boolean expected = Tools.osIsWindows();
assertEquals(expected, FileTools.fileHasAnyReservedComponents(new File("C:/CON")));
assertEquals(expected, FileTools.fileHasAnyReservedComponents(new File("/con/foo")));
assertEquals(expected, FileTools.fileHasAnyReservedComponents(new File("c:/temp/cON")));
@@ -445,7 +437,7 @@ public class FileToolsTests extends TestCase {
}
public void testShortenFileNameFile() {
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
this.verifyShortenFileNameFileWin();
} else {
this.verifyShortenFileNameFileNonWin();
@@ -477,7 +469,7 @@ public class FileToolsTests extends TestCase {
}
public void testShortenFileNameFileInt() {
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
this.verifyShortenFileNameFileIntWin();
} else {
this.verifyShortenFileNameFileIntNonWin();
@@ -509,7 +501,7 @@ public class FileToolsTests extends TestCase {
}
public void testShortenFileNameURL() throws Exception {
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
this.verifyShortenFileNameURLWin();
} else {
this.verifyShortenFileNameURLNonWin();
@@ -531,7 +523,7 @@ public class FileToolsTests extends TestCase {
}
public void testShortenFileNameURLInt() throws Exception {
- if (this.isExecutingOnWindows()) {
+ if (Tools.osIsWindows()) {
this.verifyShortenFileNameURLIntWin();
} else {
this.verifyShortenFileNameURLIntNonWin();
@@ -561,7 +553,7 @@ public class FileToolsTests extends TestCase {
private File buildTempDir() throws IOException {
// build a new directory for each test, to prevent any cross-test effects
- File dir = FileTools.newTemporaryDirectory(ClassTools.shortClassNameForObject(this) + "." + this.getName());
+ File dir = FileTools.newTemporaryDirectory(this.getClass().getSimpleName() + "." + this.getName());
File file0a = new File(dir, "file0a");
file0a.createNewFile();
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/HashBagTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/HashBagTests.java
index 645f55b9ca..3b20add7f4 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/HashBagTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/HashBagTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -20,6 +20,7 @@ import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.ArrayTools;
import org.eclipse.jpt.utility.internal.Bag;
import org.eclipse.jpt.utility.internal.HashBag;
+import org.eclipse.jpt.utility.internal.Tools;
@SuppressWarnings("nls")
public class HashBagTests extends TestCase {
@@ -378,27 +379,34 @@ public class HashBagTests extends TestCase {
assertTrue(exCaught);
}
-//TODO - poor load factor is seen in the Eclipse build environment for some reason
-// public void testHashingDistribution() throws Exception {
-// Bag<String> bigBag = new HashBag<String>();
-// for (int i = 0; i < 10000; i++) {
-// bigBag.add("object" + i);
-// }
-//
-// java.lang.reflect.Field field = bigBag.getClass().getDeclaredField("table");
-// field.setAccessible(true);
-// Object[] table = (Object[]) field.get(bigBag);
-// int bucketCount = table.length;
-// int filledBucketCount = 0;
-// for (Object o : table) {
-// if (o != null) {
-// filledBucketCount++;
-// }
-// }
-// float loadFactor = ((float) filledBucketCount) / ((float) bucketCount);
-// assertTrue("WARNING - poor load factor: " + loadFactor, loadFactor > 0.20);
-// assertTrue("WARNING - poor load factor: " + loadFactor, loadFactor < 0.75);
-// }
+ public void testHashingDistribution() throws Exception {
+ Bag<String> bigBag = new HashBag<String>();
+ for (int i = 0; i < 10000; i++) {
+ bigBag.add("object" + i);
+ }
+
+ java.lang.reflect.Field field = bigBag.getClass().getDeclaredField("table");
+ field.setAccessible(true);
+ Object[] table = (Object[]) field.get(bigBag);
+ int bucketCount = table.length;
+ int filledBucketCount = 0;
+ for (Object o : table) {
+ if (o != null) {
+ filledBucketCount++;
+ }
+ }
+ float loadFactor = ((float) filledBucketCount) / ((float) bucketCount);
+ if ((loadFactor < 0.20) || (loadFactor > 0.80)) {
+ String msg = "poor load factor: " + loadFactor;
+ if (Tools.jvmIsSun()) {
+ fail(msg);
+ } else {
+ // poor load factor is seen in the Eclipse build environment for some reason...
+ System.out.println(this.getClass().getName() + '.' + this.getName() + " - " + msg);
+ TestTools.printSystemProperties();
+ }
+ }
+ }
public void testRemove() {
assertTrue(this.bag.remove("one"));
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IdentityHashBagTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IdentityHashBagTests.java
index a411df4798..7d69a5890b 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IdentityHashBagTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IdentityHashBagTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -20,6 +20,7 @@ import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.ArrayTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.IdentityHashBag;
+import org.eclipse.jpt.utility.internal.Tools;
@SuppressWarnings("nls")
public class IdentityHashBagTests extends TestCase {
@@ -390,29 +391,34 @@ public class IdentityHashBagTests extends TestCase {
assertTrue(exCaught);
}
- // Commenting out this test as it is also failing in the Eclipse build
- // apparenly there are some hashing issues that need to be looked into.
-// public void testHashingDistribution() throws Exception {
-// IdentityHashBag<String> bigBag = new IdentityHashBag<String>();
-// for (int i = 0; i < 10000; i++) {
-// bigBag.add("object" + i);
-// }
-//
-// java.lang.reflect.Field field = bigBag.getClass().getDeclaredField("table");
-// field.setAccessible(true);
-// Object[] table = (Object[]) field.get(bigBag);
-// int bucketCount = table.length;
-// int filledBucketCount = 0;
-// for (int i = 0; i < bucketCount; i++) {
-// if (table[i] != null) {
-// filledBucketCount++;
-// }
-// }
-// float loadFactor = ((float) filledBucketCount)/((float) bucketCount);
-// // System.out.println("load factor: " + loadFactor + " (" + filledBucketCount + "/" + bucketCount + ")");
-// assertTrue("WARNING - poor load factor: " + loadFactor, loadFactor > 0.20);
-// assertTrue("WARNING - poor load factor: " + loadFactor, loadFactor < 0.75);
-// }
+ public void testHashingDistribution() throws Exception {
+ IdentityHashBag<String> bigBag = new IdentityHashBag<String>();
+ for (int i = 0; i < 10000; i++) {
+ bigBag.add("object" + i);
+ }
+
+ java.lang.reflect.Field field = bigBag.getClass().getDeclaredField("table");
+ field.setAccessible(true);
+ Object[] table = (Object[]) field.get(bigBag);
+ int bucketCount = table.length;
+ int filledBucketCount = 0;
+ for (int i = 0; i < bucketCount; i++) {
+ if (table[i] != null) {
+ filledBucketCount++;
+ }
+ }
+ float loadFactor = ((float) filledBucketCount) / ((float) bucketCount);
+ if ((loadFactor < 0.20) || (loadFactor > 0.80)) {
+ String msg = "poor load factor: " + loadFactor;
+ if (Tools.jvmIsSun()) {
+ fail(msg);
+ } else {
+ // poor load factor is seen in the Eclipse build environment for some reason...
+ System.out.println(this.getClass().getName() + '.' + this.getName() + " - " + msg);
+ TestTools.printSystemProperties();
+ }
+ }
+ }
public void testRemove() {
assertTrue(this.bag.remove(this.one));
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java
index 07dad198b5..117aba69c4 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import java.sql.Types;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.JDBCType;
+@SuppressWarnings("nls")
public class JDBCTypeTests extends TestCase {
public JDBCTypeTests(String name) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JptUtilityTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JptUtilityTests.java
index 91a8822499..d602e5f397 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JptUtilityTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JptUtilityTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -35,14 +35,21 @@ public class JptUtilityTests {
suite.addTest(JptUtilitySynchronizersTests.suite());
suite.addTestSuite(ArrayToolsTests.class);
+ suite.addTestSuite(AsynchronousCommandExecutorTests.class);
+ suite.addTestSuite(BagTests.class);
+ suite.addTestSuite(BidiFilterTests.class);
+ suite.addTestSuite(BidiStringConverterTests.class);
+ suite.addTestSuite(BidiTransformerTests.class);
suite.addTestSuite(BitToolsTests.class);
suite.addTestSuite(BooleanReferenceTests.class);
suite.addTestSuite(BooleanToolsTests.class);
suite.addTestSuite(ClasspathTests.class);
- suite.addTestSuite(ClassToolsTests.class);
+ suite.addTestSuite(ClassNameTests.class);
suite.addTestSuite(CollectionToolsTests.class);
suite.addTestSuite(CommandExecutorTests.class);
+ suite.addTestSuite(CommandRunnableTests.class);
suite.addTestSuite(CommandTests.class);
+ suite.addTestSuite(CompositeCommandTests.class);
suite.addTestSuite(ExceptionHandlerTests.class);
suite.addTestSuite(FileToolsTests.class);
suite.addTestSuite(FilterTests.class);
@@ -58,6 +65,7 @@ public class JptUtilityTests {
suite.addTestSuite(NotNullFilterTests.class);
suite.addTestSuite(ObjectReferenceTests.class);
suite.addTestSuite(RangeTests.class);
+ suite.addTestSuite(ReflectionToolsTests.class);
suite.addTestSuite(ReverseComparatorTests.class);
suite.addTestSuite(SimpleAssociationTests.class);
suite.addTestSuite(SimpleQueueTests.class);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ListenerListTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ListenerListTests.java
index 33ea3129b4..98cbfe6609 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ListenerListTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ListenerListTests.java
@@ -1,3 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 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.utility.tests.internal;
import java.io.Serializable;
@@ -7,6 +16,7 @@ import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.ListenerList;
+import org.eclipse.jpt.utility.internal.Tools;
@SuppressWarnings("nls")
public class ListenerListTests extends TestCase {
@@ -138,26 +148,32 @@ public class ListenerListTests extends TestCase {
assertFalse(CollectionTools.contains(listenerList.getListeners(), listener2));
}
-//TODO - This test doesn't pass in the Eclipse build environment (Linux) for some reason
-// public void testSerialization() throws Exception {
-// ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
-// Listener listener1 = new LocalListener();
-// Listener listener2 = new LocalListener();
-// listenerList.add(listener1);
-// listenerList.add(listener2);
-//
-// ListenerList<Listener> listenerList2 = TestTools.serialize(listenerList);
-// assertNotSame(listenerList, listenerList2);
-// assertEquals(2, listenerList2.size());
-//
-// Listener listener3 = new NonSerializableListener();
-// listenerList.add(listener3);
-//
-// listenerList2 = TestTools.serialize(listenerList);
-// assertNotSame(listenerList, listenerList2);
-// assertEquals(2, listenerList2.size());
-//
-// }
+ public void testSerialization() throws Exception {
+ // This test doesn't pass in the Eclipse build environment (Linux/IBM VM) for some reason
+ if (Tools.jvmIsSun()) {
+ this.verifySerialization();
+ }
+ }
+
+ private void verifySerialization() throws Exception {
+ ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
+ Listener listener1 = new LocalListener();
+ Listener listener2 = new LocalListener();
+ listenerList.add(listener1);
+ listenerList.add(listener2);
+
+ ListenerList<Listener> listenerList2 = TestTools.serialize(listenerList);
+ assertNotSame(listenerList, listenerList2);
+ assertEquals(2, listenerList2.size());
+
+ Listener listener3 = new NonSerializableListener();
+ listenerList.add(listener3);
+
+ listenerList2 = TestTools.serialize(listenerList);
+ assertNotSame(listenerList, listenerList2);
+ assertEquals(2, listenerList2.size());
+
+ }
interface Listener extends EventListener {
void somethingHappened();
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReflectionToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReflectionToolsTests.java
new file mode 100644
index 0000000000..afdfc679fd
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReflectionToolsTests.java
@@ -0,0 +1,440 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2010 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.utility.tests.internal;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jpt.utility.internal.ReflectionTools;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
+
+@SuppressWarnings("nls")
+public class ReflectionToolsTests extends TestCase {
+
+ private static String testStaticField;
+
+ public ReflectionToolsTests(String name) {
+ super(name);
+ }
+
+// this is no longer true - it appears the JLS now defines the generated names...
+// /**
+// * Return the compiler-generated class name. The Eclipse compiler generates
+// * "local" classes with names in the form "com.foo.Outer$1$Local"; while the
+// * JDK compiler generates "com.foo.Outer$1Local". There might be other
+// * differences.... ~bjv
+// */
+// public static String compilerDependentClassNameFor(String className) {
+// int index = className.indexOf("$1$");
+// if (index == -1) {
+// return className;
+// }
+// try {
+// Class.forName(className);
+// } catch (ClassNotFoundException ex) {
+// return className.substring(0, index + 2) + className.substring(index + 3);
+// }
+// return className;
+// }
+//
+// private static String munge(String className) {
+// return compilerDependentClassNameFor(className);
+// }
+
+ public void testAllFields() {
+ int fieldCount = 0;
+ fieldCount += java.util.Vector.class.getDeclaredFields().length;
+ fieldCount += java.util.AbstractList.class.getDeclaredFields().length;
+ fieldCount += java.util.AbstractCollection.class.getDeclaredFields().length;
+ fieldCount += java.lang.Object.class.getDeclaredFields().length;
+ Iterable<Field> fields = ReflectionTools.getAllFields(java.util.Vector.class);
+ assertEquals(fieldCount, CollectionTools.size(fields));
+ assertTrue(CollectionTools.contains(this.fieldNames(fields), "modCount"));
+ assertTrue(CollectionTools.contains(this.fieldNames(fields), "serialVersionUID"));
+ assertTrue(CollectionTools.contains(this.fieldNames(fields), "capacityIncrement"));
+ assertTrue(CollectionTools.contains(this.fieldNames(fields), "elementCount"));
+ assertTrue(CollectionTools.contains(this.fieldNames(fields), "elementData"));
+ assertTrue(fields.iterator().next().isAccessible());
+ }
+
+ public void testAllMethods() {
+ int methodCount = 0;
+ methodCount += java.util.Vector.class.getDeclaredMethods().length;
+ methodCount += java.util.AbstractList.class.getDeclaredMethods().length;
+ methodCount += java.util.AbstractCollection.class.getDeclaredMethods().length;
+ methodCount += java.lang.Object.class.getDeclaredMethods().length;
+ Iterable<Method> methods = ReflectionTools.getAllMethods(java.util.Vector.class);
+ assertEquals(methodCount, CollectionTools.size(methods));
+ assertTrue(CollectionTools.contains(this.methodNames(methods), "wait"));
+ assertTrue(CollectionTools.contains(this.methodNames(methods), "addElement"));
+ assertTrue(methods.iterator().next().isAccessible());
+ }
+
+ public void testNewInstanceClass() {
+ Vector<?> v = ReflectionTools.newInstance(java.util.Vector.class);
+ assertNotNull(v);
+ assertEquals(0, v.size());
+ }
+
+ public void testNewInstanceClassClassObject() {
+ int initialCapacity = 200;
+ Vector<?> v = ReflectionTools.newInstance(java.util.Vector.class, int.class, new Integer(initialCapacity));
+ assertNotNull(v);
+ assertEquals(0, v.size());
+ Object[] elementData = (Object[]) ReflectionTools.getFieldValue(v, "elementData");
+ assertEquals(initialCapacity, elementData.length);
+ }
+
+ public void testNewInstanceClassClassArrayObjectArray() {
+ int initialCapacity = 200;
+ Class<?>[] parmTypes = new Class[1];
+ parmTypes[0] = int.class;
+ Object[] parms = new Object[1];
+ parms[0] = new Integer(initialCapacity);
+ Vector<?> v = ReflectionTools.newInstance(java.util.Vector.class, parmTypes, parms);
+ assertNotNull(v);
+ assertEquals(0, v.size());
+ Object[] elementData = (Object[]) ReflectionTools.getFieldValue(v, "elementData");
+ assertEquals(initialCapacity, elementData.length);
+
+ parms[0] = new Integer(-1);
+ boolean exCaught = false;
+ try {
+ v = ReflectionTools.newInstance(java.util.Vector.class, parmTypes, parms);
+ } catch (RuntimeException ex) {
+ exCaught = true;
+ }
+ assertTrue("RuntimeException not thrown", exCaught);
+
+ parmTypes[0] = java.lang.String.class;
+ parms[0] = "foo";
+ exCaught = false;
+ try {
+ v = ReflectionTools.newInstance(java.util.Vector.class, parmTypes, parms);
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchMethodException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchMethodException not thrown", exCaught);
+ }
+
+ public void testFieldValue() {
+ int initialCapacity = 200;
+ Vector<?> v = new Vector<Object>(initialCapacity);
+ Object[] elementData = (Object[]) ReflectionTools.getFieldValue(v, "elementData");
+ assertEquals(initialCapacity, elementData.length);
+
+ // test inherited field
+ Integer modCountInteger = (Integer) ReflectionTools.getFieldValue(v, "modCount");
+ int modCount = modCountInteger.intValue();
+ assertEquals(0, modCount);
+
+ boolean exCaught = false;
+ Object bogusFieldValue = null;
+ try {
+ bogusFieldValue = ReflectionTools.getFieldValue(v, "bogusField");
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchFieldException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchFieldException not thrown: " + bogusFieldValue, exCaught);
+ }
+
+ public void testExecuteMethodObjectString() {
+ Vector<String> v = new Vector<String>();
+ int size = ((Integer) ReflectionTools.executeMethod(v, "size")).intValue();
+ assertEquals(0, size);
+
+ v.addElement("foo");
+ size = ((Integer) ReflectionTools.executeMethod(v, "size")).intValue();
+ assertEquals(1, size);
+ }
+
+ public void testExecuteMethodObjectStringClassObject() {
+ Vector<String> v = new Vector<String>();
+ boolean booleanResult = ((Boolean) ReflectionTools.executeMethod(v, "add", Object.class, "foo")).booleanValue();
+ assertTrue(booleanResult);
+ assertTrue(v.contains("foo"));
+ Object voidResult = ReflectionTools.executeMethod(v, "addElement", Object.class, "bar");
+ assertNull(voidResult);
+ }
+
+ public void testExecuteMethodObjectStringClassArrayObjectArray() {
+ Vector<String> v = new Vector<String>();
+ Class<?>[] parmTypes = new Class[1];
+ parmTypes[0] = java.lang.Object.class;
+ Object[] parms = new Object[1];
+ parms[0] = "foo";
+ boolean booleanResult = ((Boolean) ReflectionTools.executeMethod(v, "add", parmTypes, parms)).booleanValue();
+ assertTrue(booleanResult);
+ assertTrue(v.contains("foo"));
+
+ boolean exCaught = false;
+ Object bogusMethodReturnValue = null;
+ try {
+ bogusMethodReturnValue = ReflectionTools.executeMethod(v, "bogusMethod", parmTypes, parms);
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchMethodException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchMethodException not thrown: " + bogusMethodReturnValue, exCaught);
+ }
+
+ public void testExecuteStaticMethodClassString() {
+ Double randomObject = (Double) ReflectionTools.executeStaticMethod(java.lang.Math.class, "random");
+ assertNotNull(randomObject);
+ double random = randomObject.doubleValue();
+ assertTrue(random >= 0);
+ assertTrue(random < 1);
+ }
+
+ public void testExecuteStaticMethodClassStringClassObject() {
+ String s = (String) ReflectionTools.executeStaticMethod(java.lang.String.class, "valueOf", boolean.class, Boolean.TRUE);
+ assertNotNull(s);
+ assertEquals("true", s);
+ }
+
+ public void testExecuteStaticMethodClassStringClassArrayObjectArray() {
+ Class<?>[] parmTypes = new Class[1];
+ parmTypes[0] = boolean.class;
+ Object[] parms = new Object[1];
+ parms[0] = Boolean.TRUE;
+ String s = (String) ReflectionTools.executeStaticMethod(java.lang.String.class, "valueOf", parmTypes, parms);
+ assertNotNull(s);
+ assertEquals("true", s);
+
+ boolean exCaught = false;
+ Object bogusStaticMethodReturnValue = null;
+ try {
+ bogusStaticMethodReturnValue = ReflectionTools.executeStaticMethod(java.lang.String.class, "bogusStaticMethod", parmTypes, parms);
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchMethodException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchMethodException not thrown: " + bogusStaticMethodReturnValue, exCaught);
+
+ // test non-static method
+ exCaught = false;
+ try {
+ bogusStaticMethodReturnValue = ReflectionTools.executeStaticMethod(java.lang.String.class, "toString");
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchMethodException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchMethodException not thrown: " + bogusStaticMethodReturnValue, exCaught);
+ }
+
+ public void testSetFieldValue() {
+ Vector<String> v = new Vector<String>();
+ Object[] newElementData = new Object[5];
+ newElementData[0] = "foo";
+ ReflectionTools.setFieldValue(v, "elementData", newElementData);
+ ReflectionTools.setFieldValue(v, "elementCount", new Integer(1));
+ // test inherited field
+ ReflectionTools.setFieldValue(v, "modCount", new Integer(1));
+ assertTrue(v.contains("foo"));
+
+ boolean exCaught = false;
+ try {
+ ReflectionTools.setFieldValue(v, "bogusField", "foo");
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchFieldException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchFieldException not thrown", exCaught);
+ }
+
+ public void testSetStaticFieldValue() {
+ ReflectionTools.setStaticFieldValue(this.getClass(), "testStaticField", "new value");
+ assertEquals(testStaticField, "new value");
+
+ boolean exCaught = false;
+ try {
+ ReflectionTools.setStaticFieldValue(this.getClass(), "bogusStaticField", "new value");
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof NoSuchFieldException) {
+ exCaught = true;
+ }
+ }
+ assertTrue("NoSuchFieldException not thrown", exCaught);
+ }
+
+ public void testSimpleName() {
+ assertEquals("Vector", java.util.Vector.class.getSimpleName());
+ assertEquals("Entry", java.util.Map.Entry.class.getSimpleName());
+ assertEquals("int", int.class.getSimpleName());
+ assertEquals("int[]", int[].class.getSimpleName());
+ assertEquals("int[][]", int[][].class.getSimpleName());
+ assertEquals("void", void.class.getSimpleName());
+ }
+
+ public void testPackageName() {
+ assertEquals("java.util", java.util.Vector.class.getPackage().getName());
+ assertEquals("java.util", java.util.Map.Entry.class.getPackage().getName());
+ }
+
+ public void testArrayDepthFor() {
+ assertEquals(0, ReflectionTools.getArrayDepth(java.util.Vector.class));
+ assertEquals(0, ReflectionTools.getArrayDepth(int.class));
+ assertEquals(0, ReflectionTools.getArrayDepth(void.class));
+ assertEquals(1, ReflectionTools.getArrayDepth(java.util.Vector[].class));
+ assertEquals(1, ReflectionTools.getArrayDepth(int[].class));
+ assertEquals(3, ReflectionTools.getArrayDepth(java.util.Vector[][][].class));
+ assertEquals(3, ReflectionTools.getArrayDepth(int[][][].class));
+ }
+
+ public void testElementTypeFor() {
+ assertEquals(java.util.Vector.class, ReflectionTools.getElementType(java.util.Vector.class));
+ assertEquals(int.class, ReflectionTools.getElementType(int.class));
+ assertEquals(void.class, ReflectionTools.getElementType(void.class));
+ assertEquals(java.util.Vector.class, ReflectionTools.getElementType(java.util.Vector[].class));
+ assertEquals(int.class, ReflectionTools.getElementType(int[].class));
+ assertEquals(java.util.Vector.class, ReflectionTools.getElementType(java.util.Vector[][][].class));
+ assertEquals(int.class, ReflectionTools.getElementType(int[][][].class));
+ }
+
+ public void testClassIsPrimitiveWrapperClass() {
+ assertTrue(ReflectionTools.classIsPrimitiveWrapper(java.lang.Void.class));
+ assertTrue(ReflectionTools.classIsPrimitiveWrapper(java.lang.Boolean.class));
+ assertTrue(ReflectionTools.classIsPrimitiveWrapper(java.lang.Integer.class));
+ assertTrue(ReflectionTools.classIsPrimitiveWrapper(java.lang.Float.class));
+
+ assertFalse(ReflectionTools.classIsPrimitiveWrapper(java.lang.String.class));
+ assertFalse(ReflectionTools.classIsPrimitiveWrapper(void.class));
+ assertFalse(ReflectionTools.classIsPrimitiveWrapper(int.class));
+ }
+
+ public void testClassIsVariablePrimitiveWrapperClass() {
+ assertFalse(ReflectionTools.classIsVariablePrimitiveWrapper(java.lang.Void.class));
+
+ assertTrue(ReflectionTools.classIsVariablePrimitiveWrapper(java.lang.Boolean.class));
+ assertTrue(ReflectionTools.classIsVariablePrimitiveWrapper(java.lang.Integer.class));
+ assertTrue(ReflectionTools.classIsVariablePrimitiveWrapper(java.lang.Float.class));
+
+ assertFalse(ReflectionTools.classIsVariablePrimitiveWrapper(java.lang.String.class));
+ assertFalse(ReflectionTools.classIsVariablePrimitiveWrapper(void.class));
+ assertFalse(ReflectionTools.classIsVariablePrimitiveWrapper(int.class));
+ }
+
+ public void testWrapperClass() {
+ assertEquals(java.lang.Void.class, ReflectionTools.getWrapperClass(void.class));
+ assertEquals(java.lang.Integer.class, ReflectionTools.getWrapperClass(int.class));
+ assertEquals(java.lang.Float.class, ReflectionTools.getWrapperClass(float.class));
+ assertEquals(java.lang.Boolean.class, ReflectionTools.getWrapperClass(boolean.class));
+
+ assertNull(ReflectionTools.getWrapperClass(java.lang.String.class));
+ }
+
+ public void testClassForTypeDeclarationStringInt() throws Exception {
+ assertEquals(int.class, ReflectionTools.getClassForTypeDeclaration("int", 0));
+ assertEquals(int[].class, ReflectionTools.getClassForTypeDeclaration("int", 1));
+ assertEquals(int[][][].class, ReflectionTools.getClassForTypeDeclaration("int", 3));
+
+ assertEquals(Object.class, ReflectionTools.getClassForTypeDeclaration("java.lang.Object", 0));
+ assertEquals(Object[][][].class, ReflectionTools.getClassForTypeDeclaration("java.lang.Object", 3));
+
+ assertEquals(void.class, ReflectionTools.getClassForTypeDeclaration("void", 0));
+ try {
+ ReflectionTools.getClassForTypeDeclaration(void.class.getName(), 1);
+ fail("should not get here...");
+ } catch (RuntimeException ex) {
+ // expected
+ }
+ }
+
+ public void testCodeForClass() {
+ assertEquals('I', ReflectionTools.getCodeForClass(int.class));
+ assertEquals('B', ReflectionTools.getCodeForClass(byte.class));
+ }
+
+ public void testClassNameForTypeDeclarationString() throws Exception {
+ assertEquals("int", ReflectionTools.getClassNameForTypeDeclaration("int"));
+ assertEquals("[I", ReflectionTools.getClassNameForTypeDeclaration("int[]"));
+ assertEquals("[[I", ReflectionTools.getClassNameForTypeDeclaration("int [ ] [ ]"));
+
+ assertEquals("java.lang.Object", ReflectionTools.getClassNameForTypeDeclaration("java.lang.Object"));
+ assertEquals("[Ljava.lang.Object;", ReflectionTools.getClassNameForTypeDeclaration("java.lang.Object\t[]"));
+ assertEquals("[[Ljava.lang.Object;", ReflectionTools.getClassNameForTypeDeclaration("java.lang.Object\t[]\t[]"));
+ }
+
+ public void testArrayDepthForTypeDeclarationString() throws Exception {
+ assertEquals(0, ReflectionTools.getArrayDepthForTypeDeclaration("java.lang.Object"));
+ assertEquals(1, ReflectionTools.getArrayDepthForTypeDeclaration("java.lang.Object[]"));
+ assertEquals(3, ReflectionTools.getArrayDepthForTypeDeclaration("java.lang.Object[][][]"));
+
+ assertEquals(0, ReflectionTools.getArrayDepthForTypeDeclaration("int"));
+ assertEquals(1, ReflectionTools.getArrayDepthForTypeDeclaration("int[]"));
+ assertEquals(3, ReflectionTools.getArrayDepthForTypeDeclaration("int[][][]"));
+
+ assertEquals(0, ReflectionTools.getArrayDepthForTypeDeclaration("float"));
+ assertEquals(1, ReflectionTools.getArrayDepthForTypeDeclaration("float [ ]"));
+ assertEquals(3, ReflectionTools.getArrayDepthForTypeDeclaration("float[] [] []"));
+ }
+
+ public void testElementTypeNameForTypeDeclarationString() throws Exception {
+ assertEquals("java.lang.Object", ReflectionTools.getElementTypeNameForTypeDeclaration("java.lang.Object"));
+ assertEquals("java.lang.Object", ReflectionTools.getElementTypeNameForTypeDeclaration("java.lang.Object[]"));
+ assertEquals("java.lang.Object", ReflectionTools.getElementTypeNameForTypeDeclaration("java.lang.Object[][][]"));
+
+ assertEquals("int", ReflectionTools.getElementTypeNameForTypeDeclaration("int"));
+ assertEquals("int", ReflectionTools.getElementTypeNameForTypeDeclaration("int[]"));
+ assertEquals("int", ReflectionTools.getElementTypeNameForTypeDeclaration("int[][][]"));
+
+ assertEquals("float", ReflectionTools.getElementTypeNameForTypeDeclaration("float"));
+ assertEquals("float", ReflectionTools.getElementTypeNameForTypeDeclaration("float [ ]"));
+ assertEquals("float", ReflectionTools.getElementTypeNameForTypeDeclaration("float[] [] []"));
+ }
+
+ public void testClassNameForTypeDeclarationStringInt() throws Exception {
+ assertEquals(int.class.getName(), ReflectionTools.getClassNameForTypeDeclaration("int", 0));
+ assertEquals(int[].class.getName(), ReflectionTools.getClassNameForTypeDeclaration("int", 1));
+ assertEquals(int[][][].class.getName(), ReflectionTools.getClassNameForTypeDeclaration("int", 3));
+
+ assertEquals(Object.class.getName(), ReflectionTools.getClassNameForTypeDeclaration("java.lang.Object", 0));
+ assertEquals(Object[][][].class.getName(), ReflectionTools.getClassNameForTypeDeclaration("java.lang.Object", 3));
+
+ assertEquals(void.class.getName(), ReflectionTools.getClassNameForTypeDeclaration("void", 0));
+ try {
+ ReflectionTools.getClassNameForTypeDeclaration(void.class.getName(), 1);
+ fail("should not get here...");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+ private Iterable<String> fieldNames(Iterable<Field> fields) {
+ return new TransformationIterable<Field, String>(fields) {
+ @Override
+ protected String transform(Field field) {
+ return field.getName();
+ }
+ };
+ }
+
+ private Iterable<String> methodNames(Iterable<Method> methods) {
+ return new TransformationIterable<Method, String>(methods) {
+ @Override
+ protected String transform(Method method) {
+ return method.getName();
+ }
+ };
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReverseComparatorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReverseComparatorTests.java
index 7ae00fdc2e..1661b0ca8f 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReverseComparatorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ReverseComparatorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -16,6 +16,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.ReverseComparator;
+@SuppressWarnings("nls")
public class ReverseComparatorTests extends TestCase {
private Comparator<String> naturalReverseComparator;
private Comparator<String> customComparator;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleAssociationTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleAssociationTests.java
index 5f425f9985..36c706a330 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleAssociationTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleAssociationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -54,6 +54,8 @@ public class SimpleAssociationTests extends TestCase {
}
public void testEquals() {
+ assertFalse(this.assoc.equals("foo"));
+
assertEquals(this.assoc, this.copy(this.assoc));
SimpleAssociation<String, String> assoc2 = new SimpleAssociation<String, String>("foo", "baz");
@@ -61,10 +63,21 @@ public class SimpleAssociationTests extends TestCase {
assoc2 = new SimpleAssociation<String, String>("fop", "bar");
assertFalse(this.assoc.equals(assoc2));
+
+ SimpleAssociation<String, String> assoc3 = new SimpleAssociation<String, String>(null, null);
+ SimpleAssociation<String, String> assoc4 = new SimpleAssociation<String, String>(null, null);
+ assertEquals(assoc3, assoc4);
}
public void testHashCode() {
assertEquals(this.assoc.hashCode(), this.copy(this.assoc).hashCode());
+
+ SimpleAssociation<String, String> assoc2 = new SimpleAssociation<String, String>(null, null);
+ assertEquals(assoc2.hashCode(), this.copy(assoc2).hashCode());
+ }
+
+ public void testToString() {
+ assertNotNull(this.assoc.toString());
}
public void testClone() {
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 0078dcc58b..8319dc0c11 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -912,6 +912,13 @@ public class StringToolsTests extends TestCase {
assertEquals(expected, writer.toString());
}
+ // ********** #toString() **********
+
+ public void testBuildToStringClassName_anonymous() {
+ Object o = new Object(){/*anonymous subclass of Object*/};
+ assertEquals("Object", StringTools.buildToStringClassName(o.getClass()));
+ }
+
// ********** queries **********
public void testStringIsEmptyString() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/TestTools.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/TestTools.java
index c7a4d1c052..7fc143fd90 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/TestTools.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/TestTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -21,6 +21,9 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
import junit.framework.TestCase;
import junit.framework.TestFailure;
import junit.framework.TestResult;
@@ -70,6 +73,33 @@ public final class TestTools {
}
/**
+ * Sort and print out all the current Java System properties on the
+ * console.
+ */
+ public static void printSystemProperties() {
+ synchronized (System.out) {
+ printSystemPropertiesOn(System.out);
+ }
+ }
+
+ /**
+ * Sort and print out all the current Java System properties on the
+ * specified print stream.
+ */
+ public static void printSystemPropertiesOn(PrintStream stream) {
+ SortedSet<String> sortedKeys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+ for (Object key : System.getProperties().keySet()) {
+ sortedKeys.add((String) key);
+ }
+ for (String key : sortedKeys) {
+ stream.print(key);
+ stream.print(" => "); //$NON-NLS-1$
+ stream.print(System.getProperty(key));
+ stream.println();
+ }
+ }
+
+ /**
* execute the specified test and return a text output of its results
*/
public static String execute(TestCase testCase) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/XMLStringEncoderTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/XMLStringEncoderTests.java
index 3b104b9b89..eda0e7f432 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/XMLStringEncoderTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/XMLStringEncoderTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.FileTools;
import org.eclipse.jpt.utility.internal.XMLStringEncoder;
+@SuppressWarnings("nls")
public class XMLStringEncoderTests extends TestCase {
public XMLStringEncoderTests(String name) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/FilteringIterableTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/FilteringIterableTests.java
index 7d870c0a85..713163e06f 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/FilteringIterableTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/FilteringIterableTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -38,7 +38,7 @@ public class FilteringIterableTests extends TestCase {
public void testFilter() {
Filter<String> filter = this.buildFilter();
int i = 0;
- for (String s : new FilteringIterable<String, String>(this.buildNestedIterable(), filter)) {
+ for (String s : new FilteringIterable<String>(this.buildNestedIterable(), filter)) {
assertTrue(s.contains(PREFIX));
i++;
}
@@ -51,7 +51,7 @@ public class FilteringIterableTests extends TestCase {
public void testMissingFilter() {
boolean exCaught = false;
- Iterable<String> iterable = new FilteringIterable<String, String>(this.buildNestedIterable());
+ Iterable<String> iterable = new FilteringIterable<String>(this.buildNestedIterable());
try {
Iterator<String> iterator = iterable.iterator();
fail("bogus iterator: " + iterator);
@@ -66,7 +66,7 @@ public class FilteringIterableTests extends TestCase {
}
private Iterable<String> buildFilteringIterable(Iterable<String> nestedIterable) {
- return new FilteringIterable<String, String>(nestedIterable) {
+ return new FilteringIterable<String>(nestedIterable) {
@Override
protected boolean accept(String s) {
return s.startsWith(PREFIX);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/JptUtilityIterablesTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/JptUtilityIterablesTests.java
index f3f88f4627..9394bd0501 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/JptUtilityIterablesTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/JptUtilityIterablesTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -28,7 +28,7 @@ public class JptUtilityIterablesTests {
suite.addTestSuite(EmptyIterableTests.class);
suite.addTestSuite(EmptyListIterableTests.class);
suite.addTestSuite(FilteringIterableTests.class);
- suite.addTestSuite(GenericIterableWrapperTests.class);
+ suite.addTestSuite(SuperIterableWrapperTests.class);
suite.addTestSuite(GraphIterableTests.class);
suite.addTestSuite(LiveCloneIterableTests.class);
suite.addTestSuite(LiveCloneListIterableTests.class);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/GenericIterableWrapperTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/SuperIterableWrapperTests.java
index c936cf45db..f56b76bbdd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/GenericIterableWrapperTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterables/SuperIterableWrapperTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2010 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.
@@ -14,12 +14,12 @@ import java.util.Collections;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.iterables.GenericIterableWrapper;
+import org.eclipse.jpt.utility.internal.iterables.SuperIterableWrapper;
@SuppressWarnings("nls")
-public class GenericIterableWrapperTests extends TestCase {
+public class SuperIterableWrapperTests extends TestCase {
- public GenericIterableWrapperTests(String name) {
+ public SuperIterableWrapperTests(String name) {
super(name);
}
@@ -34,7 +34,7 @@ public class GenericIterableWrapperTests extends TestCase {
}
assertEquals("foobarbaz", concat);
- Iterable<Object> iterable = new GenericIterableWrapper<Object>(list);
+ Iterable<Object> iterable = new SuperIterableWrapper<Object>(list);
concat = "";
for (Object s : iterable) {
concat += s;
@@ -43,7 +43,7 @@ public class GenericIterableWrapperTests extends TestCase {
}
public void testToString() {
- Iterable<Object> iterable = new GenericIterableWrapper<Object>(Collections.emptyList());
+ Iterable<Object> iterable = new SuperIterableWrapper<Object>(Collections.emptyList());
assertNotNull(iterable.toString());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java
index 6e7940a584..8e1fe4ce6a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,11 +12,11 @@ package org.eclipse.jpt.utility.tests.internal.iterators;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import java.util.NoSuchElementException;
+
import junit.framework.TestCase;
+
import org.eclipse.jpt.utility.Filter;
-import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.SimpleFilter;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
@@ -123,39 +123,6 @@ public class FilteringIteratorTests extends TestCase {
}
}
- // test a filtered iterator with a nested iterator of a sub-type (Number vs. Integer)
- public void testGenerics1() {
- List<Integer> integers = new ArrayList<Integer>();
- integers.add(new Integer(0));
- integers.add(new Integer(1));
- integers.add(new Integer(2));
- integers.add(new Integer(3));
- Iterator<Number> stream = new FilteringIterator<Integer, Number>(integers.iterator()) {
- @Override
- protected boolean accept(Integer o) {
- return o.intValue() > 1;
- }
- };
- assertEquals(2, CollectionTools.size(stream));
- }
-
- // test a filtered iterator with a nested iterator of a super-type (Integer vs. Number)
- // i.e. trust that Filter will only return the appropriate sub-type objects
- public void testGenerics2() {
- List<Number> numbers = new ArrayList<Number>();
- numbers.add(new Integer(0));
- numbers.add(new Long(1));
- numbers.add(new Integer(2));
- numbers.add(new Float(3));
- Iterator<Integer> stream = new FilteringIterator<Number, Integer>(numbers.iterator()) {
- @Override
- protected boolean accept(Number o) {
- return o instanceof Integer;
- }
- };
- assertEquals(2, CollectionTools.size(stream));
- }
-
public void testFilterHasNext() {
int i = 0;
for (Iterator<String> stream = this.buildFilterIterator(); stream.hasNext();) {
@@ -172,11 +139,11 @@ public class FilteringIteratorTests extends TestCase {
}
private Iterator<String> buildFilteredIterator(Iterator<String> nestedIterator, Filter<String> filter) {
- return new FilteringIterator<String, String>(nestedIterator, filter);
+ return new FilteringIterator<String>(nestedIterator, filter);
}
private Iterator<String> buildInnerFilteredIterator(Iterator<String> nestedIterator) {
- return new FilteringIterator<String, String>(nestedIterator) {
+ return new FilteringIterator<String>(nestedIterator) {
@Override
protected boolean accept(String s) {
return s.startsWith(PREFIX);
@@ -190,7 +157,7 @@ public class FilteringIteratorTests extends TestCase {
// this inner iterator will call the "outer" object
private Iterator<String> buildInnerFilteredIterator2(Iterator<String> nestedIterator) {
- return new FilteringIterator<String, String>(nestedIterator) {
+ return new FilteringIterator<String>(nestedIterator) {
@Override
protected boolean accept(String s) {
return s.startsWith(FilteringIteratorTests.this.getPrefix());
@@ -287,7 +254,7 @@ public class FilteringIteratorTests extends TestCase {
boolean exCaught = false;
try {
// missing method override
- Iterator<String> iterator = new FilteringIterator<String, String>(this.buildNestedIterator());
+ Iterator<String> iterator = new FilteringIterator<String>(this.buildNestedIterator());
String s = iterator.next();
fail("invalid string: " + s);
} catch (UnsupportedOperationException ex) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java
index ef3d0d0982..0cd247c942 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2010 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.
@@ -31,7 +31,7 @@ public class JptUtilityIteratorsTests {
suite.addTestSuite(EmptyListIteratorTests.class);
suite.addTestSuite(EnumerationIteratorTests.class);
suite.addTestSuite(FilteringIteratorTests.class);
- suite.addTestSuite(GenericIteratorWrapperTests.class);
+ suite.addTestSuite(SuperIteratorWrapperTests.class);
suite.addTestSuite(GraphIteratorTests.class);
suite.addTestSuite(PeekableIteratorTests.class);
suite.addTestSuite(ReadOnlyCompositeListIteratorTests.class);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/GenericIteratorWrapperTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/SuperIteratorWrapperTests.java
index daafb9ffd4..23c5126148 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/GenericIteratorWrapperTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/SuperIteratorWrapperTests.java
@@ -14,12 +14,12 @@ import java.util.Iterator;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.iterators.GenericIteratorWrapper;
+import org.eclipse.jpt.utility.internal.iterators.SuperIteratorWrapper;
@SuppressWarnings("nls")
-public class GenericIteratorWrapperTests extends TestCase {
+public class SuperIteratorWrapperTests extends TestCase {
- public GenericIteratorWrapperTests(String name) {
+ public SuperIteratorWrapperTests(String name) {
super(name);
}
@@ -34,7 +34,7 @@ public class GenericIteratorWrapperTests extends TestCase {
}
assertEquals("foobarbaz", concat);
- Iterator<Object> iterator = new GenericIteratorWrapper<Object>(list);
+ Iterator<Object> iterator = new SuperIteratorWrapper<Object>(list);
concat = "";
while (iterator.hasNext()) {
Object next = iterator.next();
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java
index 73a51e224a..b7f430b7e8 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,16 +9,25 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal.model;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.EventListener;
import java.util.HashSet;
import java.util.List;
import junit.framework.TestCase;
+import org.eclipse.jpt.utility.internal.ArrayTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.ListenerList;
+import org.eclipse.jpt.utility.internal.Tools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.ChangeSupport;
import org.eclipse.jpt.utility.model.event.CollectionAddEvent;
@@ -44,8 +53,10 @@ import org.eclipse.jpt.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.utility.model.listener.ChangeListener;
import org.eclipse.jpt.utility.model.listener.CollectionChangeAdapter;
import org.eclipse.jpt.utility.model.listener.ListChangeAdapter;
+import org.eclipse.jpt.utility.model.listener.ListChangeListener;
import org.eclipse.jpt.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.utility.model.listener.StateChangeAdapter;
+import org.eclipse.jpt.utility.model.listener.StateChangeListener;
import org.eclipse.jpt.utility.model.listener.TreeChangeAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
@@ -4179,82 +4190,105 @@ public class ChangeSupportTests
// ********** serialization test **********
- //TODO - This test doesn't pass in the Eclipse build environment (Linux) for some reason
-// public void testSerialization() throws java.io.IOException, ClassNotFoundException {
-// LocalModel model1 = new LocalModel();
-// Foo foo1 = new Foo();
-// Bar bar1 = new Bar();
-// Joo joo1 = new Joo();
-// Jar jar1 = new Jar();
-// model1.addStateChangeListener(foo1);
-// model1.addStateChangeListener(bar1);
-// model1.addListChangeListener(joo1);
-// model1.addListChangeListener(jar1);
-//
-// ChangeListener[] listeners1 = this.getListeners(model1, StateChangeListener.class);
-// assertEquals(2, listeners1.length);
-// // the order of these could change...
-// assertEquals(Foo.class, listeners1[0].getClass());
-// assertEquals(Bar.class, listeners1[1].getClass());
-//
-// listeners1 = this.getListeners(model1, ListChangeListener.class);
-// assertEquals(2, listeners1.length);
-// // the order of these could change...
-// assertEquals(Joo.class, listeners1[0].getClass());
-// assertEquals(Jar.class, listeners1[1].getClass());
-//
-// LocalModel model2 = TestTools.serialize(model1);
-//
-// ChangeListener[] listeners2 = this.getListeners(model2, StateChangeListener.class);
-// assertEquals(1, listeners2.length);
-// assertEquals(Foo.class, listeners2[0].getClass());
-//
-// listeners2 = this.getListeners(model2, ListChangeListener.class);
-// assertEquals(1, listeners2.length);
-// assertEquals(Joo.class, listeners2[0].getClass());
-// }
-//
-// private ChangeListener[] getListeners(LocalModel model, Class<? extends ChangeListener> listenerClass) {
-// ChangeSupport changeSupport = (ChangeSupport) ClassTools.fieldValue(model, "changeSupport");
-// return (ChangeListener[]) ClassTools.executeMethod(changeSupport, "getListeners", Class.class, listenerClass);
-// }
-//
-// private static class LocalModel extends AbstractModel {
-// LocalModel() {
-// super();
-// }
-// }
-//
-// private static class Foo implements Serializable, StateChangeListener {
-// Foo() {
-// super();
-// }
-// public void stateChanged(StateChangeEvent event) {
-// // do nothing
-// }
-// }
-//
-// private static class Bar implements StateChangeListener {
-// Bar() {
-// super();
-// }
-// public void stateChanged(StateChangeEvent event) {
-// // do nothing
-// }
-// }
-//
-// private static class Joo extends ListChangeAdapter implements Serializable {
-//// private static final ObjectStreamField[] serialPersistentFields = {new ObjectStreamField("changeSupport", ChangeSupport.class)};
-// Joo() {
-// super();
-// }
-// }
-//
-// private static class Jar extends ListChangeAdapter {
-// Jar() {
-// super();
-// }
-// }
+ public void testSerialization() throws java.io.IOException, ClassNotFoundException {
+ if (Tools.jvmIsSun()) {
+ // This test doesn't pass in the Eclipse build environment (Linux/IBM JVM) for some reason
+ this.verifySerialization();
+ }
+ }
+
+ private void verifySerialization() throws java.io.IOException, ClassNotFoundException {
+ LocalModel model1 = new LocalModel();
+ Foo foo1 = new Foo();
+ Bar bar1 = new Bar();
+ Joo joo1 = new Joo();
+ Jar jar1 = new Jar();
+ model1.addStateChangeListener(foo1);
+ model1.addStateChangeListener(bar1);
+ model1.addListChangeListener("foo", joo1);
+ model1.addListChangeListener("foo", jar1);
+
+ Iterable<EventListener> listeners1 = this.getListeners(model1, StateChangeListener.class, null);
+ Object[] listenersArray1 = ArrayTools.array(listeners1);
+ assertEquals(2, listenersArray1.length);
+ // the order of these could change...
+ assertEquals(Foo.class, listenersArray1[0].getClass());
+ assertEquals(Bar.class, listenersArray1[1].getClass());
+
+ listeners1 = this.getListeners(model1, ListChangeListener.class, "foo");
+ listenersArray1 = ArrayTools.array(listeners1);
+ assertEquals(2, listenersArray1.length);
+ // the order of these could change...
+ assertEquals(Joo.class, listenersArray1[0].getClass());
+ assertEquals(Jar.class, listenersArray1[1].getClass());
+
+ LocalModel model2 = TestTools.serialize(model1);
+
+ Iterable<EventListener> listeners2 = this.getListeners(model2, StateChangeListener.class, null);
+ Object[] listenersArray2 = ArrayTools.array(listeners2);
+ assertEquals(1, listenersArray2.length);
+ assertEquals(Foo.class, listenersArray2[0].getClass());
+
+ listeners2 = this.getListeners(model2, ListChangeListener.class, "foo");
+ listenersArray2 = ArrayTools.array(listeners2);
+ assertEquals(1, listenersArray2.length);
+ assertEquals(Joo.class, listenersArray2[0].getClass());
+ }
+
+ private Iterable<EventListener> getListeners(LocalModel model, Class<? extends EventListener> listenerClass, String aspectName) {
+ return this.getListenerList(model, listenerClass, aspectName).getListeners();
+ }
+
+ @SuppressWarnings("unchecked")
+ private ListenerList<EventListener> getListenerList(LocalModel model, Class<? extends EventListener> listenerClass, String aspectName) {
+ ChangeSupport changeSupport = (ChangeSupport) ReflectionTools.getFieldValue(model, "changeSupport");
+ return (ListenerList<EventListener>) ReflectionTools.executeMethod(changeSupport, "getListenerList_", new Class<?>[] {Class.class, String.class}, new Object[] {listenerClass, aspectName});
+ }
+
+ // we have to manually handle 'changeSupport' since AbstractModel is not Serializable
+ private static class LocalModel extends AbstractModel implements Serializable {
+ LocalModel() {
+ super();
+ }
+ private synchronized void writeObject(ObjectOutputStream s) throws IOException {
+ s.defaultWriteObject();
+ s.writeObject(this.changeSupport);
+ }
+ private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
+ s.defaultReadObject();
+ this.changeSupport = (ChangeSupport) s.readObject();
+ }
+ }
+
+ private static class Foo implements Serializable, StateChangeListener {
+ Foo() {
+ super();
+ }
+ public void stateChanged(StateChangeEvent event) {
+ // do nothing
+ }
+ }
+
+ private static class Bar implements StateChangeListener {
+ Bar() {
+ super();
+ }
+ public void stateChanged(StateChangeEvent event) {
+ // do nothing
+ }
+ }
+
+ private static class Joo extends ListChangeAdapter implements Serializable {
+ Joo() {
+ super();
+ }
+ }
+
+ private static class Jar extends ListChangeAdapter {
+ Jar() {
+ super();
+ }
+ }
// ********** bug(?) test **********
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java
index 76a759d76f..43adcd065e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -17,7 +17,7 @@ import java.util.Iterator;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
@@ -199,7 +199,7 @@ public class ReflectiveCollectionChangeListenerTests extends TestCase {
TestModel testModel = new TestModel();
String string = "foo";
Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string);
- Method method = ClassTools.method(target, "collectionChangedDoubleArgument", new Class[] {CollectionChangeEvent.class, Object.class});
+ Method method = ReflectionTools.getMethod(target, "collectionChangedDoubleArgument", new Class[] {CollectionChangeEvent.class, Object.class});
boolean exCaught = false;
try {
CollectionChangeListener listener = ReflectiveChangeListener.buildCollectionChangeListener(target, method);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java
index ad8b76b362..8a3965d1ae 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -17,7 +17,7 @@ import java.util.ListIterator;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
@@ -323,7 +323,7 @@ public class ReflectiveListChangeListenerTests extends TestCase {
TestModel testModel = new TestModel();
String string = "foo";
Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0);
- Method method = ClassTools.method(target, "listChangedDoubleArgument", new Class[] {ListChangeEvent.class, Object.class});
+ Method method = ReflectionTools.getMethod(target, "listChangedDoubleArgument", new Class[] {ListChangeEvent.class, Object.class});
boolean exCaught = false;
try {
ListChangeListener listener = ReflectiveChangeListener.buildListChangeListener(target, method);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java
index 59d6e8dbce..8ca4f3a10e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.utility.tests.internal.model.listener;
import java.lang.reflect.Method;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
@@ -40,7 +40,7 @@ public class ReflectivePropertyChangeListenerTests extends TestCase {
public void testSingleArgument2() throws Exception {
TestModel testModel = new TestModel(7);
Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99);
- Method method = ClassTools.method(target, "propertyChangedSingleArgument2", new Class[] {Object.class});
+ Method method = ReflectionTools.getMethod(target, "propertyChangedSingleArgument2", new Class[] {Object.class});
testModel.addPropertyChangeListener(TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, method));
testModel.setValue(99);
assertFalse(target.zeroArgumentFlag);
@@ -62,7 +62,7 @@ public class ReflectivePropertyChangeListenerTests extends TestCase {
public void testSingleArgumentNamedProperty2() throws Exception {
TestModel testModel = new TestModel(7);
Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99);
- Method method = ClassTools.method(target, "propertyChangedSingleArgument2", new Class[] {Object.class});
+ Method method = ReflectionTools.getMethod(target, "propertyChangedSingleArgument2", new Class[] {Object.class});
testModel.addPropertyChangeListener(TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, method));
testModel.setValue(99);
assertFalse(target.zeroArgumentFlag);
@@ -105,7 +105,7 @@ public class ReflectivePropertyChangeListenerTests extends TestCase {
public void testBogusDoubleArgument2() throws Exception {
TestModel testModel = new TestModel(7);
Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99);
- Method method = ClassTools.method(target, "propertyChangedDoubleArgument", new Class[] {PropertyChangeEvent.class, Object.class});
+ Method method = ReflectionTools.getMethod(target, "propertyChangedDoubleArgument", new Class[] {PropertyChangeEvent.class, Object.class});
boolean exCaught = false;
try {
PropertyChangeListener listener = ReflectiveChangeListener.buildPropertyChangeListener(target, method);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java
index 4848960509..28aed8f49f 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.utility.tests.internal.model.listener;
import java.lang.reflect.Method;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
@@ -49,7 +49,7 @@ public class ReflectiveStateChangeListenerTests extends TestCase {
public void testSingleArgument2() throws Exception {
TestModel testModel = new TestModel();
Target target = new Target(testModel);
- Method method = ClassTools.method(target, "stateChangedSingleArgument2", new Class[] {Object.class});
+ Method method = ReflectionTools.getMethod(target, "stateChangedSingleArgument2", new Class[] {Object.class});
testModel.addStateChangeListener(ReflectiveChangeListener.buildStateChangeListener(target, method));
testModel.changeState();
assertFalse(target.zeroArgumentFlag);
@@ -92,7 +92,7 @@ public class ReflectiveStateChangeListenerTests extends TestCase {
public void testBogusDoubleArgument2() throws Exception {
TestModel testModel = new TestModel();
Target target = new Target(testModel);
- Method method = ClassTools.method(target, "stateChangedDoubleArgument", new Class[] {StateChangeEvent.class, Object.class});
+ Method method = ReflectionTools.getMethod(target, "stateChangedDoubleArgument", new Class[] {StateChangeEvent.class, Object.class});
boolean exCaught = false;
try {
StateChangeListener listener = ReflectiveChangeListener.buildStateChangeListener(target, method);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java
index 5c1223ae4e..3532f88f2f 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 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.
@@ -20,6 +20,7 @@ import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class CompositeListValueModelTests extends TestCase {
private SimpleListValueModel<String> lvm0;
private SimpleListValueModel<String> lvm1;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java
index dca32f9315..c7d0e9bcaf 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -17,6 +17,7 @@ import org.eclipse.jpt.utility.internal.model.value.StaticCollectionValueModel;
import org.eclipse.jpt.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class StaticCollectionValueModelTests extends TestCase {
private static final Collection<String> COLLECTION = buildCollection();
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java
index 0d7cbc6110..d7a7d24810 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -17,6 +17,7 @@ import org.eclipse.jpt.utility.internal.model.value.StaticListValueModel;
import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class StaticListValueModelTests extends TestCase {
private static final List<String> LIST = buildList();
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java
index 380cf17c58..14e3d9a014 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -14,6 +14,7 @@ import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class StaticValueModelTests extends TestCase {
private PropertyValueModel<String> objectHolder;
private static final PropertyValueModel<String> OBJECT_HOLDER = new StaticPropertyValueModel<String>("foo");
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java
index 49aab95fc0..c8dc777f8e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,7 +15,7 @@ import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencePropertyValueModel;
import org.eclipse.jpt.utility.model.Model;
@@ -373,7 +373,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
}
private boolean nodeHasAnyPrefListeners(Preferences node) throws Exception {
- PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.fieldValue(node, "prefListeners");
+ PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ReflectionTools.getFieldValue(node, "prefListeners");
return prefListeners.length > 0;
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java
index c57af46fb6..390429f54c 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -16,7 +16,7 @@ import java.util.prefs.NodeChangeListener;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencesCollectionValueModel;
@@ -305,7 +305,7 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
}
private boolean nodeHasAnyPrefListeners(Preferences node) throws Exception {
- PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.fieldValue(node, "prefListeners");
+ PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ReflectionTools.getFieldValue(node, "prefListeners");
return prefListeners.length > 0;
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java
index ce4c304a6e..88ca7b93d7 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -14,13 +14,14 @@ import java.util.List;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.Preferences;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.tests.internal.TestTools;
/**
* set up and tear down a test node for any subclass that
* needs to test preferences-related stuff
*/
+@SuppressWarnings("nls")
public abstract class PreferencesTestCase extends TestCase {
protected Preferences classNode;
public Preferences testNode;
@@ -34,12 +35,12 @@ public abstract class PreferencesTestCase extends TestCase {
protected void setUp() throws Exception {
super.setUp();
Preferences packageNode = Preferences.userNodeForPackage(this.getClass());
- this.classNode = packageNode.node(ClassTools.shortClassNameForObject(this));
+ this.classNode = packageNode.node(this.getClass().getSimpleName());
// clean out any leftover crap...
if ((this.classNode.keys().length > 0) || (this.classNode.childrenNames().length > 0)) {
this.classNode.removeNode();
// ...and re-create the node
- this.classNode = packageNode.node(ClassTools.shortClassNameForObject(this));
+ this.classNode = packageNode.node(this.getClass().getSimpleName());
}
this.testNode = this.classNode.node(TEST_NODE_NAME);
}
@@ -79,7 +80,7 @@ public abstract class PreferencesTestCase extends TestCase {
@SuppressWarnings("unchecked")
private List<EventObject> preferencesEventQueue() {
- return (List<EventObject>) ClassTools.staticFieldValue(AbstractPreferences.class, "eventQueue");
+ return (List<EventObject>) ReflectionTools.getStaticFieldValue(AbstractPreferences.class, "eventQueue");
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java
index 4302458d3d..f29d9118a6 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -14,7 +14,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.CheckBoxModelAdapter;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
@@ -22,6 +22,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class CheckBoxModelAdapterTests extends TestCase {
private WritablePropertyValueModel<Boolean> booleanHolder;
private ButtonModel buttonModelAdapter;
@@ -111,12 +112,12 @@ public class CheckBoxModelAdapterTests extends TestCase {
}
private void verifyHasNoListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ReflectionTools.getFieldValue(model, "listenerList");
assertEquals(0, listenerList.getListenerList().length);
}
private void verifyHasListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ReflectionTools.getFieldValue(model, "listenerList");
assertFalse(listenerList.getListenerList().length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java
index c3bc373dc7..7dcf11311e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -36,6 +36,7 @@ import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
/**
* Play around with a set of check boxes.
*/
+@SuppressWarnings("nls")
public class CheckBoxModelAdapterUITest {
private TestModel testModel;
@@ -48,14 +49,14 @@ public class CheckBoxModelAdapterUITest {
private ButtonModel notFlag2ButtonModel;
public static void main(String[] args) throws Exception {
- new CheckBoxModelAdapterUITest().exec(args);
+ new CheckBoxModelAdapterUITest().exec();
}
private CheckBoxModelAdapterUITest() {
super();
}
- private void exec(String[] args) throws Exception {
+ private void exec() throws Exception {
this.testModel = new TestModel(true, true);
this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.flag1Holder = this.buildFlag1Holder(this.testModelHolder);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java
index e79111a232..0bc9a5793b 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,7 +15,7 @@ import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.ListModel;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ComboBoxModelAdapter;
@@ -27,6 +27,7 @@ import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.model.value.CoordinatedList;
+@SuppressWarnings("nls")
public class ComboBoxModelAdapterTests extends TestCase {
public ComboBoxModelAdapterTests(String name) {
@@ -79,12 +80,12 @@ public class ComboBoxModelAdapterTests extends TestCase {
}
private void verifyHasNoListeners(ListModel listModel) throws Exception {
- boolean hasNoListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasNoListDataListeners")).booleanValue();
+ boolean hasNoListeners = ((Boolean) ReflectionTools.executeMethod(listModel, "hasNoListDataListeners")).booleanValue();
assertTrue(hasNoListeners);
}
private void verifyHasListeners(ListModel listModel) throws Exception {
- boolean hasListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasListDataListeners")).booleanValue();
+ boolean hasListeners = ((Boolean) ReflectionTools.executeMethod(listModel, "hasListDataListeners")).booleanValue();
assertTrue(hasListeners);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java
index bb6e8f0ce7..afae125606 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -18,6 +18,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import java.util.List;
+
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ComboBoxModel;
@@ -28,7 +29,7 @@ import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
-import org.eclipse.jpt.utility.internal.ClassTools;
+
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
@@ -49,6 +50,7 @@ import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
* DefaultLongListBrowserDialogUITest subclasses this class; so be
* careful when making changes.
*/
+@SuppressWarnings("nls")
public class ComboBoxModelAdapterUITest {
protected JFrame window;
@@ -60,14 +62,14 @@ public class ComboBoxModelAdapterUITest {
private int nextColorNumber = 0;
public static void main(String[] args) throws Exception {
- new ComboBoxModelAdapterUITest().exec(args);
+ new ComboBoxModelAdapterUITest().exec();
}
protected ComboBoxModelAdapterUITest() {
super();
}
- protected void exec(String[] args) throws Exception {
+ protected void exec() throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); // Metal LAF
// UIManager.setLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel.class.getName());
@@ -119,7 +121,7 @@ public class ComboBoxModelAdapterUITest {
}
private void openWindow() {
- this.window = new JFrame(ClassTools.shortNameFor(this.getClass()));
+ this.window = new JFrame(this.getClass().getSimpleName());
this.window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.window.addWindowListener(this.buildWindowListener());
this.window.getContentPane().add(this.buildMainPanel(), "Center");
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java
index e9c5fc4a09..afc1c15a02 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -17,10 +17,11 @@ import org.eclipse.jpt.utility.model.value.ListValueModel;
/**
*
*/
+@SuppressWarnings("nls")
public class ComboBoxModelAdapterUITest2 extends ComboBoxModelAdapterUITest {
public static void main(String[] args) throws Exception {
- new ComboBoxModelAdapterUITest2().exec(args);
+ new ComboBoxModelAdapterUITest2().exec();
}
public ComboBoxModelAdapterUITest2() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java
index cb255e7b12..a24b75b3bf 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -21,6 +21,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class DateSpinnerModelAdapterTests extends TestCase {
private WritablePropertyValueModel<Object> valueHolder;
private SpinnerModel spinnerModelAdapter;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java
index d647360a88..e980515201 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -14,7 +14,7 @@ import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent.EventType;
import javax.swing.text.Document;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.DocumentAdapter;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
@@ -22,6 +22,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class DocumentAdapterTests extends TestCase {
private WritablePropertyValueModel<String> stringHolder;
Document documentAdapter;
@@ -128,14 +129,14 @@ public class DocumentAdapterTests extends TestCase {
}
private void verifyHasNoListeners(Object document) throws Exception {
- Object delegate = ClassTools.fieldValue(document, "delegate");
- Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getDocumentListeners");
+ Object delegate = ReflectionTools.getFieldValue(document, "delegate");
+ Object[] listeners = (Object[]) ReflectionTools.executeMethod(delegate, "getDocumentListeners");
assertEquals(0, listeners.length);
}
private void verifyHasListeners(Object document) throws Exception {
- Object delegate = ClassTools.fieldValue(document, "delegate");
- Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getDocumentListeners");
+ Object delegate = ReflectionTools.getFieldValue(document, "delegate");
+ Object[] listeners = (Object[]) ReflectionTools.executeMethod(delegate, "getDocumentListeners");
assertFalse(listeners.length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java
index 39b43388cd..c57649b86a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -38,6 +38,7 @@ import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
/**
* Play around with a set of entry fields.
*/
+@SuppressWarnings("nls")
public class DocumentAdapterUITest {
private TestModel testModel;
@@ -48,14 +49,14 @@ public class DocumentAdapterUITest {
private Document upperCaseNameDocument;
public static void main(String[] args) throws Exception {
- new DocumentAdapterUITest().exec(args);
+ new DocumentAdapterUITest().exec();
}
private DocumentAdapterUITest() {
super();
}
- private void exec(String[] args) throws Exception {
+ private void exec() throws Exception {
this.testModel = new TestModel(DEFAULT_NAME);
this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.nameHolder = this.buildNameHolder(this.testModelHolder);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java
index 6765325f00..86f3b698e9 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,7 @@ import javax.swing.ListModel;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.internal.Bag;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
@@ -263,12 +263,12 @@ public class ListModelAdapterTests extends TestCase {
}
private void verifyHasNoListeners(ListModel listModel) throws Exception {
- boolean hasNoListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasNoListDataListeners")).booleanValue();
+ boolean hasNoListeners = ((Boolean) ReflectionTools.executeMethod(listModel, "hasNoListDataListeners")).booleanValue();
assertTrue(hasNoListeners);
}
private void verifyHasListeners(ListModel listModel) throws Exception {
- boolean hasListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasListDataListeners")).booleanValue();
+ boolean hasListeners = ((Boolean) ReflectionTools.executeMethod(listModel, "hasListDataListeners")).booleanValue();
assertTrue(hasListeners);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java
index 0407b59a60..087fefc813 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -20,6 +20,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class ListSpinnerModelAdapterTests extends TestCase {
private WritablePropertyValueModel<Object> valueHolder;
private SpinnerModel spinnerModelAdapter;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java
index bc5df140e8..1debef863e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -20,6 +20,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class NumberSpinnerModelAdapterTests extends TestCase {
private WritablePropertyValueModel<Number> valueHolder;
private SpinnerModel spinnerModelAdapter;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java
index 3a8384c1a7..bbeac0e5fd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -26,6 +26,7 @@ import org.eclipse.jpt.utility.model.listener.ListChangeListener;
import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class PrimitiveListTreeModelTests extends TestCase {
TestModel testModel;
private TreeModel treeModel;
@@ -137,7 +138,7 @@ public class PrimitiveListTreeModelTests extends TestCase {
// ********** inner classes **********
- private class TestModel extends AbstractModel {
+ class TestModel extends AbstractModel {
private final List<String> names;
static final String NAMES_LIST = "names";
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java
index 0c4bbeb9f3..908f4bee86 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -14,7 +14,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.RadioButtonModelAdapter;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
@@ -22,6 +22,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class RadioButtonModelAdapterTests extends TestCase {
private WritablePropertyValueModel<Object> valueHolder;
@@ -207,12 +208,12 @@ public class RadioButtonModelAdapterTests extends TestCase {
}
private void verifyHasNoListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ReflectionTools.getFieldValue(model, "listenerList");
assertEquals(0, listenerList.getListenerList().length);
}
private void verifyHasListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ReflectionTools.getFieldValue(model, "listenerList");
assertFalse(listenerList.getListenerList().length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java
index c8bb0234ef..3d9ac7344d 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,7 @@ import javax.swing.SpinnerModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import junit.framework.TestCase;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.SpinnerModelAdapter;
import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
@@ -21,6 +21,7 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+@SuppressWarnings("nls")
public class SpinnerModelAdapterTests extends TestCase {
private WritablePropertyValueModel<Object> valueHolder;
SpinnerModel spinnerModelAdapter;
@@ -93,14 +94,14 @@ public class SpinnerModelAdapterTests extends TestCase {
}
private void verifyHasNoListeners(Object adapter) throws Exception {
- Object delegate = ClassTools.fieldValue(adapter, "delegate");
- Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getChangeListeners");
+ Object delegate = ReflectionTools.getFieldValue(adapter, "delegate");
+ Object[] listeners = (Object[]) ReflectionTools.executeMethod(delegate, "getChangeListeners");
assertEquals(0, listeners.length);
}
private void verifyHasListeners(Object adapter) throws Exception {
- Object delegate = ClassTools.fieldValue(adapter, "delegate");
- Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getChangeListeners");
+ Object delegate = ReflectionTools.getFieldValue(adapter, "delegate");
+ Object[] listeners = (Object[]) ReflectionTools.executeMethod(delegate, "getChangeListeners");
assertFalse(listeners.length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java
index c08467d97d..ce51ef0776 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -36,9 +36,7 @@ import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
-/**
- *
- */
+@SuppressWarnings("nls")
public class TableModelAdapterTests extends TestCase {
private Crowd crowd;
TableModelEvent event;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java
index 6b70b279ca..78854f61bd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -47,7 +47,6 @@ import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.text.Document;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
@@ -214,7 +213,7 @@ public class TableModelAdapterUITest {
}
private void openWindow() {
- JFrame window = new JFrame(ClassTools.shortClassNameForObject(this));
+ JFrame window = new JFrame(this.getClass().getSimpleName());
window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
window.addWindowListener(this.buildWindowListener());
window.getContentPane().add(this.buildMainPanel(), "Center");
@@ -505,7 +504,7 @@ public class TableModelAdapterUITest {
return this.promptUserForName(null);
}
- private String promptUserForName(String originalName) {
+ private String promptUserForName(@SuppressWarnings("unused") String originalName) {
while (true) {
String name = JOptionPane.showInputDialog("Person Name");
if (name == null) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
index b8f40c394f..7339172161 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -49,6 +49,7 @@ import org.eclipse.jpt.utility.tests.internal.model.value.swing.TreeModelAdapter
/**
* an example UI for testing the TreeModelAdapter
*/
+@SuppressWarnings("nls")
public class TreeModelAdapterUITest {
// hold the tree so we can restore its expansion state
@@ -60,14 +61,14 @@ public class TreeModelAdapterUITest {
private TextField nameTextField;
public static void main(String[] args) throws Exception {
- new TreeModelAdapterUITest().exec(args);
+ new TreeModelAdapterUITest().exec();
}
private TreeModelAdapterUITest() {
super();
}
- private void exec(String[] args) throws Exception {
+ private void exec() throws Exception {
this.rootNodeHolder = this.buildRootNodeHolder();
this.sorted = this.rootNodeHolder.getValue() instanceof SortedTestNode;
this.treeModel = this.buildTreeModel();
@@ -132,7 +133,7 @@ public class TreeModelAdapterUITest {
};
}
- void treeSelectionChanged(TreeSelectionEvent e) {
+ void treeSelectionChanged(@SuppressWarnings("unused") TreeSelectionEvent e) {
TestModel selectedTestModel = this.selectedTestModel();
if (selectedTestModel != null) {
this.nameTextField.setText(selectedTestModel.getName());
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java
index 7a6a82f517..b835e96de6 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.utility.tests.internal.synchronizers;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.Command;
-import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.CompositeException;
import org.eclipse.jpt.utility.internal.ConsumerThreadCoordinator;
import org.eclipse.jpt.utility.internal.synchronizers.AsynchronousSynchronizer;
@@ -58,8 +58,8 @@ public class AsynchronousSynchronizerTests extends TestCase {
}
protected static void stop(Synchronizer synchronizer) {
- ConsumerThreadCoordinator ctc = (ConsumerThreadCoordinator) ClassTools.fieldValue(synchronizer, "consumerThreadCoordinator");
- if (ClassTools.fieldValue(ctc, "thread") != null) {
+ ConsumerThreadCoordinator ctc = (ConsumerThreadCoordinator) ReflectionTools.getFieldValue(synchronizer, "consumerThreadCoordinator");
+ if (ReflectionTools.getFieldValue(ctc, "thread") != null) {
synchronizer.stop();
}
}
@@ -168,8 +168,8 @@ public class AsynchronousSynchronizerTests extends TestCase {
public void testThreadName() {
Synchronizer s = new AsynchronousSynchronizer(this.command1, "sync");
s.start();
- ConsumerThreadCoordinator ctc = (ConsumerThreadCoordinator) ClassTools.fieldValue(s, "consumerThreadCoordinator");
- Thread t = (Thread) ClassTools.fieldValue(ctc, "thread");
+ ConsumerThreadCoordinator ctc = (ConsumerThreadCoordinator) ReflectionTools.getFieldValue(s, "consumerThreadCoordinator");
+ Thread t = (Thread) ReflectionTools.getFieldValue(ctc, "thread");
assertEquals("sync", t.getName());
s.stop();
}
@@ -309,7 +309,7 @@ public class AsynchronousSynchronizerTests extends TestCase {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.toStringClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.toString(sb);
sb.append(')');
@@ -385,7 +385,7 @@ public class AsynchronousSynchronizerTests extends TestCase {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.toStringClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.toString(sb);
sb.append(')');
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
index 054bf08452..c2391be3d4 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,6 @@ package org.eclipse.jpt.utility.tests.internal.synchronizers;
import junit.framework.TestCase;
import org.eclipse.jpt.utility.Command;
-import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.CompositeException;
import org.eclipse.jpt.utility.internal.SynchronizedBoolean;
import org.eclipse.jpt.utility.internal.synchronizers.Synchronizer;
@@ -557,7 +556,7 @@ public class SynchronousSynchronizerTests extends TestCase {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.toStringClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.toString(sb);
sb.append(')');
@@ -633,7 +632,7 @@ public class SynchronousSynchronizerTests extends TestCase {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(ClassTools.toStringClassNameForObject(this));
+ sb.append(this.getClass().getSimpleName());
sb.append('(');
this.toString(sb);
sb.append(')');

Back to the top