diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutoconfSubstRule.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutoconfSubstRule.java index 6f7ba8fe880..16cec4204f0 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutoconfSubstRule.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutoconfSubstRule.java @@ -76,7 +76,7 @@ public class AutoconfSubstRule implements IPredicateRule { // A valid id has some alphabetic character in it. isId = true; } else if (c >= '0' && c <= '9' || c == '_') { - // continue + // continue } else if (c == '@' && isId) return getSuccessToken(); else diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/PathInfo.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/PathInfo.java index 762dc371828..349f4dd579d 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/PathInfo.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/scannerconfig/PathInfo.java @@ -45,8 +45,7 @@ public final class PathInfo { fQuoteIncludePaths = quoteIncludePaths != null && quoteIncludePaths.length != 0 ? (IPath[]) quoteIncludePaths.clone() : EMPTY_PATH_ARRAY; - fSymbols = symbols != null && symbols.size() != 0 ? getInternedHashMap(symbols) - : new HashMap<>(0); + fSymbols = symbols != null && symbols.size() != 0 ? getInternedHashMap(symbols) : new HashMap<>(0); fIncludeFiles = includeFiles != null && includeFiles.length != 0 ? (IPath[]) includeFiles.clone() : EMPTY_PATH_ARRAY; fMacroFiles = macroFiles != null && macroFiles.length != 0 ? (IPath[]) macroFiles.clone() : EMPTY_PATH_ARRAY; diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java index 02e79c7cfcb..02723556bf6 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java @@ -339,8 +339,7 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC PerFileDiscoveredPathContainer container = new PerFileDiscoveredPathContainer(project); CoreModel.setPathEntryContainer(new ICProject[] { cProject }, container, null); if (changedResources != null) { - List changeDelta = new ArrayList<>( - changedResources.size()); + List changeDelta = new ArrayList<>(changedResources.size()); for (IResource resource : changedResources) { IPath path = resource.getFullPath(); changeDelta.add( diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java index 70b5171ddf0..9f17d0ac91a 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java @@ -338,8 +338,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn LinkedHashMap persistedSymbols = discPathInfo.getSymbolMap(); // Step 3. Merge scanner config from steps 1 and 2 - LinkedHashMap candidateSymbols = new LinkedHashMap<>( - persistedSymbols); + LinkedHashMap candidateSymbols = new LinkedHashMap<>(persistedSymbols); addedSymbols |= ScannerConfigUtil.scAddSymbolEntryMap2SymbolEntryMap(candidateSymbols, sumDiscoveredSymbols); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java index 7e92e4129d1..68094517dae 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java @@ -58,8 +58,7 @@ public class Preconditions extends TestCase { IContentType contentTypeC = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE); fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - Set expectedExts = new TreeSet<>( - Arrays.asList(new String[] { "C", "c", "c++", "cc", "cpp", "cxx" })); + Set expectedExts = new TreeSet<>(Arrays.asList(new String[] { "C", "c", "c++", "cc", "cpp", "cxx" })); assertEquals("Precodition FAILED - Content Types do not match expected defaults.", expectedExts.toString(), fileExts.toString()); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index 29c0bcaa538..a498ba1363b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -2163,8 +2163,7 @@ public class ManagedBuildManager extends AbstractCExtension { // Call the start up config extensions. These may rely on the standard elements // having already been loaded so we wait to call them from here. if (startUpConfigElements != null) { - buildDefStartupList = new ArrayList<>( - startUpConfigElements.size()); + buildDefStartupList = new ArrayList<>(startUpConfigElements.size()); for (IManagedConfigElement startUpConfigElement : startUpConfigElements) { IManagedBuildDefinitionsStartup customConfigLoader; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index a6fb4c7d961..666187ed6cf 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -1466,8 +1466,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild ICSettingEntry[] libs = CDataUtil.resolveEntries(unresolved, des); if (libs.length > 0) { for (ICExternalSetting setting : des.getExternalSettings()) { - Set entries = new LinkedHashSet<>( - Arrays.asList(setting.getEntries())); + Set entries = new LinkedHashSet<>(Arrays.asList(setting.getEntries())); for (ICSettingEntry lib : libs) { if (entries.contains(lib)) { entries.remove(lib); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilderExternalSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilderExternalSettingsProvider.java index 0c06fe854c5..46648561369 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilderExternalSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilderExternalSettingsProvider.java @@ -91,8 +91,7 @@ public class HeadlessBuilderExternalSettingsProvider extends CExternalSettingPro if (desc == null) continue; for (ICConfigurationDescription cfg : desc.getConfigurations()) { - ArrayList extSettingIds = new ArrayList<>( - Arrays.asList(cfg.getExternalSettingsProviderIds())); + ArrayList extSettingIds = new ArrayList<>(Arrays.asList(cfg.getExternalSettingsProviderIds())); for (Iterator it = extSettingIds.iterator(); it.hasNext();) if (ID.equals(it.next())) it.remove(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java index 47669958f47..8a16828d6c3 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java @@ -296,8 +296,7 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest case UNDEF_MACRO_FILES: if (option.value != null) { @SuppressWarnings("unchecked") - ArrayList list = new ArrayList<>( - (ArrayList) option.value); + ArrayList list = new ArrayList<>((ArrayList) option.value); value = list; } if (option.defaultValue != null) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/BuildEntryStorage.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/BuildEntryStorage.java index 91f4563b209..9a8c242ab8c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/BuildEntryStorage.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/BuildEntryStorage.java @@ -254,8 +254,7 @@ public class BuildEntryStorage extends AbstractEntryStorage { } else { // If resolved, add each resolved entry as a separate UserEntryInfo boolean isMultiple = rVes.length > 1; - List sequense = isMultiple ? new ArrayList<>(rVes.length) - : null; + List sequense = isMultiple ? new ArrayList<>(rVes.length) : null; for (OptionStringValue rVe : rVes) { ICLanguageSettingEntry entry = createUserEntry(option, rVe, flags, subst); entryList.add(new UserEntryInfo(entry, ve, rVe, sequense)); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/PathComparator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/PathComparator.java index 0729b097a0e..ba3c0dc083c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/PathComparator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/PathComparator.java @@ -113,8 +113,7 @@ public class PathComparator implements Comparator { //all children SortedMap> children = getChildPathMap(map, path, false, false); - SortedMap> result = new TreeMap<>( - INSTANCE); + SortedMap> result = new TreeMap<>(INSTANCE); for (Iterator>> iter = children.entrySet() .iterator(); iter.hasNext(); iter = children.entrySet().iterator()) { Map.Entry> entry = iter.next(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/TcModificationUtil.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/TcModificationUtil.java index d3c08b071bc..055a8cd90a5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/TcModificationUtil.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/TcModificationUtil.java @@ -213,8 +213,7 @@ public class TcModificationUtil { int[] types = new int[] { IRealBuildObjectAssociation.OBJECT_TOOLCHAIN, IRealBuildObjectAssociation.OBJECT_BUILDER, IRealBuildObjectAssociation.OBJECT_TOOL, }; - TreeMap> result = new TreeMap<>( - PathComparator.INSTANCE); + TreeMap> result = new TreeMap<>(PathComparator.INSTANCE); @SuppressWarnings("unchecked") TreeMap> clone = (TreeMap>) initialMap .clone(); @@ -572,8 +571,7 @@ public class TcModificationUtil { public static TreeMap> createPathMap( PerTypeMapStorage> storage) { int[] types = ObjectTypeBasedStorage.getSupportedObjectTypes(); - TreeMap> result = new TreeMap<>( - PathComparator.INSTANCE); + TreeMap> result = new TreeMap<>(PathComparator.INSTANCE); for (int i = 0; i < types.length; i++) { int type = types[i]; Map> map = storage.getMap(type, false); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/ToolListModification.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/ToolListModification.java index 6e89dc52a16..782954300da 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/ToolListModification.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/tcmodification/ToolListModification.java @@ -247,8 +247,7 @@ public abstract class ToolListModification implements IToolListModification { fOperations = new ModificationOperation[0]; } } else { - List opList = new ArrayList<>( - fCompatibleTools.size() + 1); + List opList = new ArrayList<>(fCompatibleTools.size() + 1); Set keySet = fCompatibleTools.keySet(); for (Tool tool : keySet) { if (tool == fRealTool) diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java index ccf3ebf3f6c..772f2198e4e 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java @@ -183,8 +183,8 @@ public class CodanCorePlugin extends Plugin { if (bundle != null) { BundleContext context = bundle.getBundleContext(); if (context != null) { - ServiceTracker tracker = new ServiceTracker<>( - context, DebugOptions.class.getName(), null); + ServiceTracker tracker = new ServiceTracker<>(context, + DebugOptions.class.getName(), null); try { tracker.open(); debugOptions = tracker.getService(); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java index 062014dafd3..50d9d2109b6 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsListenersTests.java @@ -534,16 +534,14 @@ public class LanguageSettingsListenersTests extends BaseTestCase { // add global provider which is not engaged ILanguageSettingsProvider provider = new MockListenerRegisterer(PROVIDER_CUSTOM_GLOBAL, PROVIDER_CUSTOM_GLOBAL_NAME); - List providers = new ArrayList<>( - workspaceProvidersOriginal); + List providers = new ArrayList<>(workspaceProvidersOriginal); providers.add(provider); LanguageSettingsManager.setWorkspaceProviders(providers); assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } { // remove global provider and restore original list - List providers = new ArrayList<>( - workspaceProvidersOriginal); + List providers = new ArrayList<>(workspaceProvidersOriginal); LanguageSettingsManager.setWorkspaceProviders(providers); assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } @@ -601,8 +599,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase { } { // remove global provider - List providers = new ArrayList<>( - workspaceProvidersOriginal); + List providers = new ArrayList<>(workspaceProvidersOriginal); LanguageSettingsManager.setWorkspaceProviders(providers); assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL)); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java index 9e55ac3dca8..3b864e88416 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/CProjectDescriptionDeltaTests.java @@ -598,8 +598,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase { assertNotNull(cfgDescription); // Modification SOURCE_ADDED - List sourceEntries = new ArrayList<>( - Arrays.asList(cfgDescription.getSourceEntries())); + List sourceEntries = new ArrayList<>(Arrays.asList(cfgDescription.getSourceEntries())); ICSourceEntry testSourceEntry = new CSourceEntry(project.getFullPath().append("test_src"), null, ICSettingEntry.RESOLVED); sourceEntries.add(testSourceEntry); @@ -648,8 +647,7 @@ public class CProjectDescriptionDeltaTests extends BaseTestCase { ICConfigurationDescription cfgDescription = prjDescription.getConfigurations()[0]; assertNotNull(cfgDescription); - List sourceEntries = new ArrayList<>( - Arrays.asList(cfgDescription.getSourceEntries())); + List sourceEntries = new ArrayList<>(Arrays.asList(cfgDescription.getSourceEntries())); sourceEntries.add(testSourceEntry); cfgDescription.setSourceEntries(sourceEntries.toArray(new ICSourceEntry[0])); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/ProjectLanguageConfiguration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/ProjectLanguageConfiguration.java index 14afe485448..d0fe1db6558 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/ProjectLanguageConfiguration.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/ProjectLanguageConfiguration.java @@ -244,8 +244,7 @@ public class ProjectLanguageConfiguration { * @param file */ public void setFileMappings(IFile file, Map mappings) { - fFileConfigurationMappings.put(file.getProjectRelativePath().toPortableString(), - new TreeMap<>(mappings)); + fFileConfigurationMappings.put(file.getProjectRelativePath().toPortableString(), new TreeMap<>(mappings)); } private Map> copyLanguageMappings(Map> mappings, diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 194f82d042f..02110ec446f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -1208,8 +1208,7 @@ public class LanguageSettingsProvidersSerializer { String[] ids = ((ILanguageSettingsProvidersKeeper) cfgDescription) .getDefaultLanguageSettingsProvidersIds(); if (ids != null) { - List providers = new ArrayList<>( - ids.length); + List providers = new ArrayList<>(ids.length); for (String id : ids) { if (LanguageSettingsExtensionManager.isPreferShared(id)) { providers.add(LanguageSettingsManager.getWorkspaceProvider(id)); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java index de82650c681..6a16807b649 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/xml/XmlProjectDescriptionStorage.java @@ -190,8 +190,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto /** A soft reference to the read-only project description * Volatile provides a memory barrier in Java 5+ */ - private volatile Reference fProjectDescription = new SoftReference<>( - null); + private volatile Reference fProjectDescription = new SoftReference<>(null); /** The last modification stamp of the .cproject project description file */ private volatile long projectModificaitonStamp = IResource.NULL_STAMP; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java index 4d7e4113b51..5b9485c5395 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java @@ -153,8 +153,7 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider content.createLink(new Path(location.getAbsolutePath()), IResource.NONE, null); // Setup path entries - List entries = new ArrayList<>( - Arrays.asList(CoreModel.getRawPathEntries(cproject))); + List entries = new ArrayList<>(Arrays.asList(CoreModel.getRawPathEntries(cproject))); // pre-include files for (String path : includeFiles) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/Profiler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/Profiler.java index 5bedde683a2..5dd2cdafa0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/Profiler.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/Profiler.java @@ -152,8 +152,7 @@ public class Profiler { } if (!profiler.counters.isEmpty()) { - List> keyList = new ArrayList<>( - profiler.counters.entrySet()); + List> keyList = new ArrayList<>(profiler.counters.entrySet()); Comparator> c2 = new Comparator>() { @Override public int compare(Entry o1, Entry o2) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java index e9889bd349a..21ccb7de47d 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java @@ -256,8 +256,7 @@ public class UserDefinedEnvironmentSupplier extends StorableEnvironmentLoader private IEnvironmentVariable[] combineVariables(IEnvironmentVariable[] oldVariables, IEnvironmentVariable[] newVariables) { - Map vars = new HashMap<>( - oldVariables.length + newVariables.length); + Map vars = new HashMap<>(oldVariables.length + newVariables.length); for (IEnvironmentVariable variable : oldVariables) vars.put(variable.getName(), variable); for (IEnvironmentVariable variable : newVariables) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java index 0fad01f43f8..3a089ff9f7b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java @@ -131,8 +131,7 @@ public class FoldingTest extends FoldingTestBase { } private void assertNoKeyCollisions() { - ProjectionAnnotationModel model = fEditor - .getAdapter(ProjectionAnnotationModel.class); + ProjectionAnnotationModel model = fEditor.getAdapter(ProjectionAnnotationModel.class); assertNotNull(model); int annotations = 0; Set keys = new HashSet<>(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTestBase.java index 2e738b1a860..fb8824b24dd 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTestBase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTestBase.java @@ -253,8 +253,7 @@ abstract public class FoldingTestBase extends BaseUITestCase { protected PositionAndCollapsed[] getFoldingPositions() { List positionAndCollapseds = new ArrayList<>(); - ProjectionAnnotationModel model = fEditor - .getAdapter(ProjectionAnnotationModel.class); + ProjectionAnnotationModel model = fEditor.getAdapter(ProjectionAnnotationModel.class); assertNotNull(model); for (Iterator iter = model.getAnnotationIterator(); iter.hasNext();) { Annotation ann = iter.next(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index f0b7ce3b2c2..183d606b182 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -1344,8 +1344,7 @@ public class CEditor extends TextEditor * AST reconciling listeners. * @since 4.0 */ - private final ListenerList fReconcilingListeners = new ListenerList<>( - ListenerList.IDENTITY); + private final ListenerList fReconcilingListeners = new ListenerList<>(ListenerList.IDENTITY); /** * Semantic highlighting manager diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/EclipsePreferencesAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/EclipsePreferencesAdapter.java index e5a265580dd..d3f916e79b6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/EclipsePreferencesAdapter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/EclipsePreferencesAdapter.java @@ -57,8 +57,7 @@ class EclipsePreferencesAdapter implements IPreferenceStore { } /** Listeners on on this adapter */ - private ListenerList fListeners = new ListenerList<>( - ListenerList.IDENTITY); + private ListenerList fListeners = new ListenerList<>(ListenerList.IDENTITY); /** Listener on the node */ private IEclipsePreferences.IPreferenceChangeListener fListener = new PreferenceChangeListener(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingWidget.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingWidget.java index 93a52254bf0..1d5c0324a2c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingWidget.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/ProjectLanguageMappingWidget.java @@ -253,8 +253,7 @@ public class ProjectLanguageMappingWidget extends LanguageMappingWidget { } if (fChild != null) { - Set overrides = new HashSet<>( - createWorkspaceContentTypeFilter(fConfigurationContentTypeMappings)); + Set overrides = new HashSet<>(createWorkspaceContentTypeFilter(fConfigurationContentTypeMappings)); fChild.setOverriddenContentTypes(overrides); fChild.refreshMappings(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index d085ab5de40..d1641995898 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -1190,8 +1190,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { IResource rc = getResource(); List oldProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription) .getLanguageSettingProviders(); - List newProviders = new ArrayList<>( - oldProviders.size()); + List newProviders = new ArrayList<>(oldProviders.size()); // clear entries for a given resource for all languages where applicable providers: for (ILanguageSettingsProvider provider : oldProviders) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/AbstractWorkingSetConfigsContribution.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/AbstractWorkingSetConfigsContribution.java index 617f67bda28..98b0ac8dc79 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/AbstractWorkingSetConfigsContribution.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/AbstractWorkingSetConfigsContribution.java @@ -74,8 +74,7 @@ abstract class AbstractWorkingSetConfigsContribution extends CompoundContributio } // sort the configurations by name - List configs = new java.util.ArrayList<>( - getWorkingSet().getConfigurations()); + List configs = new java.util.ArrayList<>(getWorkingSet().getConfigurations()); Collections.sort(configs, configOrdering); IContributionItem[] result = new IContributionItem[configs.size()]; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/IWorkingSetProjectConfigurationFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/IWorkingSetProjectConfigurationFactory.java index 728ed011d2b..b4604928832 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/IWorkingSetProjectConfigurationFactory.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/IWorkingSetProjectConfigurationFactory.java @@ -210,8 +210,7 @@ public interface IWorkingSetProjectConfigurationFactory { // first pass to populate the map with immediate requireds IWorkspace ws = ResourcesPlugin.getWorkspace(); for (IProjectNatureDescriptor next : ws.getNatureDescriptors()) { - result.put(next.getNatureId(), - new java.util.HashSet<>(Arrays.asList(next.getRequiredNatureIds()))); + result.put(next.getNatureId(), new java.util.HashSet<>(Arrays.asList(next.getRequiredNatureIds()))); } // now, iterate to add transitive requireds diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetConfiguration.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetConfiguration.java index e18a4ed0140..0feb2f13880 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetConfiguration.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/workingsets/WorkingSetConfiguration.java @@ -181,8 +181,7 @@ public class WorkingSetConfiguration implements IWorkingSetConfiguration { public IStatus build(IProgressMonitor monitor) { MultiStatus result = new MultiStatus(CUIPlugin.PLUGIN_ID, 0, WorkingSetMessages.WSConfig_build_problems, null); - List toBuild = new java.util.ArrayList<>( - getProjectConfigurations().size()); + List toBuild = new java.util.ArrayList<>(getProjectConfigurations().size()); for (IWorkingSetProjectConfiguration next : getProjectConfigurations()) { IProject project = next.resolveProject(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java index 3451e6d51ec..875559d81c7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java @@ -89,8 +89,7 @@ public class CHelpConfigurationPropertyPage extends PropertyPage implements IWor /* 0 */ CUIMessages.CHelpConfigurationPropertyPage_buttonLabels_CheckAll, /* 1 */ CUIMessages.CHelpConfigurationPropertyPage_buttonLabels_UncheckAll }; - fCHelpBookList = new CheckedListDialogField<>(null, buttonLabels, - new CHelpBookListLabelProvider()); + fCHelpBookList = new CheckedListDialogField<>(null, buttonLabels, new CHelpBookListLabelProvider()); fCHelpBookList.setLabelText(CUIMessages.CHelpConfigurationPropertyPage_HelpBooks); fCHelpBookList.setCheckAllButtonIndex(0); fCHelpBookList.setUncheckAllButtonIndex(1); diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java index 01e3dc822ea..1878c751f12 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/TemplateClassWizard.java @@ -81,8 +81,7 @@ public class TemplateClassWizard extends TemplatesChoiceWizard implements INewWi @Override public Template[] getTemplates() { - SortedSet templateList = new TreeSet<>( - TemplateCore.TEMPLATE_ID_CASE_INSENSITIVE_COMPARATOR); + SortedSet templateList = new TreeSet<>(TemplateCore.TEMPLATE_ID_CASE_INSENSITIVE_COMPARATOR); templateList.addAll(Arrays.asList(TemplateEngineUI.getDefault().getTemplates())); return templateList.toArray(new Template[templateList.size()]); } diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java index 393792abb4b..defa490adca 100644 --- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java +++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/pages/TemplateInputDialog.java @@ -100,7 +100,6 @@ public class TemplateInputDialog extends Dialog { setShellStyle(getShellStyle() | SWT.RESIZE); } - @Override protected void configureShell(Shell shell) { super.configureShell(shell); @@ -108,7 +107,6 @@ public class TemplateInputDialog extends Dialog { display = shell.getDisplay(); } - @Override protected Control createDialogArea(Composite parent) { @@ -216,7 +214,6 @@ public class TemplateInputDialog extends Dialog { aText.addModifyListener(mListener); } - @Override protected void okPressed() { if (option == TemplatePreferencePage.OPTION_ADD) { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Trace.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Trace.java index 6626d88cf29..7b813938c93 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Trace.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Trace.java @@ -127,8 +127,8 @@ public class Trace { if (bundle != null) { BundleContext context = bundle.getBundleContext(); if (context != null) { - ServiceTracker tracker = new ServiceTracker<>( - context, DebugOptions.class.getName(), null); + ServiceTracker tracker = new ServiceTracker<>(context, + DebugOptions.class.getName(), null); try { tracker.open(); DebugOptions debugOptions = tracker.getService(); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java index 17b5f678337..f1ef15d5607 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java @@ -313,8 +313,7 @@ public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor { private void addSourceMappingToDirector(String missingPath, IPath newSourcePath, AbstractSourceLookupDirector director) throws CoreException { - ArrayList containerList = new ArrayList<>( - Arrays.asList(director.getSourceContainers())); + ArrayList containerList = new ArrayList<>(Arrays.asList(director.getSourceContainers())); MappingSourceContainer foundMappings = null; for (ISourceContainer container : containerList) { if (container instanceof MappingSourceContainer) { diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/SourceFilesViewer.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/SourceFilesViewer.java index 1d52a2e3178..c9e0a9fed28 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/SourceFilesViewer.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/SourceFilesViewer.java @@ -77,8 +77,7 @@ public class SourceFilesViewer extends BaseViewer { /** Tradeoff expensiveness of checking filesystem against likelihood * that files will be added/removed/changed in the given time period */ static final long FILE_CHECK_DELTA = 30 * 1000; - private static LRUCache translationUnitInfoCache = new LRUCache<>( - 1024); + private static LRUCache translationUnitInfoCache = new LRUCache<>(1024); public SourceFilesViewer(ExecutablesView view, Composite parent, int style) { super(view, parent, style); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBPatternMatchingExpressions.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBPatternMatchingExpressions.java index 0783c3d8732..40da8bd16e1 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBPatternMatchingExpressions.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBPatternMatchingExpressions.java @@ -662,8 +662,7 @@ public class GDBPatternMatchingExpressions extends AbstractDsfService implements // Not only does selecting the element jump back and forth between the duplicates, // but children of duplicated elements are not always right. Because of this, we // remove all duplicates here. - LinkedHashSet uniqueSubExprSet = new LinkedHashSet<>( - subExprList); + LinkedHashSet uniqueSubExprSet = new LinkedHashSet<>(subExprList); subExprList.clear(); subExprList.addAll(uniqueSubExprSet); @@ -776,8 +775,7 @@ public class GDBPatternMatchingExpressions extends AbstractDsfService implements matchArrays(exprDmc, new ImmediateDataRequestMonitor>(rm) { @Override protected void handleSuccess() { - final List exprList = getData() != null ? getData() - : new ArrayList<>(); + final List exprList = getData() != null ? getData() : new ArrayList<>(); matchLocals(exprDmc, new ImmediateDataRequestMonitor>(rm) { @Override protected void handleSuccess() { @@ -865,8 +863,7 @@ public class GDBPatternMatchingExpressions extends AbstractDsfService implements final CountingRequestMonitor varNameCRM = new CountingRequestMonitor(getExecutor(), rm) { @Override public void handleSuccess() { - ArrayList matches = new ArrayList<>( - localsDMData.length); + ArrayList matches = new ArrayList<>(localsDMData.length); String fullExpr = globDmc.getExpression().trim(); if (fullExpr.startsWith(GLOB_EXPRESSION_PREFIX)) { diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java index 7bae81e398d..fd2afcd16d0 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0_NS.java @@ -2595,8 +2595,7 @@ public class GDBRunControl_7_0_NS extends AbstractDsfService Set specifiedExedDmcSet = new HashSet<>(Arrays.asList(contexts)); // A list that ignores threads for which the process is also present - List execDmcForOperationList = new ArrayList<>( - specifiedExedDmcSet.size()); + List execDmcForOperationList = new ArrayList<>(specifiedExedDmcSet.size()); // Check for the case of a process selected along with some of its threads for (IExecutionDMContext execDmc : specifiedExedDmcSet) { diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java index ea1c4fa5415..df37b5fdeac 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java @@ -170,8 +170,7 @@ public class SyncUtil { public static MIStoppedEvent step(final IExecutionDMContext dmc, final StepType stepType, boolean reverse, int massagedTimeout) throws Throwable { - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); if (!reverse) { fRunControl.getExecutor().submit(new Runnable() { @@ -280,8 +279,7 @@ public class SyncUtil { private static MIStoppedEvent resumeUntilStopped(final IExecutionDMContext dmc, int massagedTimeout) throws Throwable { - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); fRunControl.getExecutor().submit(new Runnable() { @Override @@ -308,8 +306,7 @@ public class SyncUtil { } public static MIRunningEvent resume(final IExecutionDMContext dmc, int massagedTimeout) throws Throwable { - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIRunningEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIRunningEvent.class); fRunControl.getExecutor().submit(new Runnable() { @Override @@ -378,8 +375,7 @@ public class SyncUtil { // if there is a sleep in the code between the resume and the time // it stops; this will give us plenty of time to call this method. public static MIStoppedEvent waitForStop(int timeout) throws Throwable { - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); // Wait for the execution to suspend return eventWaitor.waitForEvent(TestsPlugin.massageTimeout(timeout)); @@ -778,8 +774,7 @@ public class SyncUtil { } // Now wait for the stopped event of the restart - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); // Perform the restart Query query2 = new Query() { diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/CommandTimeoutTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/CommandTimeoutTest.java index 7555b477977..80834bc719b 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/CommandTimeoutTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/CommandTimeoutTest.java @@ -97,8 +97,8 @@ public class CommandTimeoutTest extends BaseParametrizedTestCase { doLaunch(); final DsfSession session = getGDBLaunch().getSession(); - ServiceEventWaitor shutdownEventWaitor = new ServiceEventWaitor<>( - session, ICommandControlShutdownDMEvent.class); + ServiceEventWaitor shutdownEventWaitor = new ServiceEventWaitor<>(session, + ICommandControlShutdownDMEvent.class); // Send the command that will timeout Query query = new Query() { diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java index 2436aab0cff..486e7e2e472 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java @@ -714,8 +714,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase // Now step backwards to make sure reverse was enabled - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); final int REVERSE_NUM_STEPS = 2; final IExecutionDMContext execDmc = stoppedEvent.getDMContext(); @@ -780,8 +779,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase frame.getFunction().equals("stopAtOther")); // Now step backwards all the way to the start to make sure reverse was enabled from the very start - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); final int REVERSE_NUM_STEPS = 3; Query query2 = new Query() { @@ -854,8 +852,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase frame.getFunction().equals("main") && frame.getLine() == LAST_LINE_IN_MAIN); // Now step backwards all the way to the start to make sure reverse was enabled from the very start - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, MIStoppedEvent.class); final int REVERSE_NUM_STEPS = 3; Query query2 = new Query() { diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java index 2eaac4b4c8d..8f5ad1a846f 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java @@ -1302,8 +1302,7 @@ public class MICatchpointsTest extends BaseParametrizedTestCase { assertEquals("Unexpected number of breakpoint-added events", 1, getBreakpointEventCount(BP_ADDED)); // Ensure the breakpoint service sees what we expect - List bkptsAfter = new LinkedList<>( - Arrays.asList(getBreakpoints(fBreakpointsDmc))); + List bkptsAfter = new LinkedList<>(Arrays.asList(getBreakpoints(fBreakpointsDmc))); assertEquals("Breakpoints service reports unexpected number of breakpoints", bkptsBefore.length + 1, bkptsAfter.size()); @@ -1361,8 +1360,7 @@ public class MICatchpointsTest extends BaseParametrizedTestCase { // Ensure the breakpoint service sees what we expect. Ask the breakpoint // service for the list of breakpoint against and make sure it differs // only by the newly added one - List bkptsAfter = new LinkedList<>( - Arrays.asList(getBreakpoints(fBreakpointsDmc))); + List bkptsAfter = new LinkedList<>(Arrays.asList(getBreakpoints(fBreakpointsDmc))); assertEquals("Breakpoints service reports unexpected number of breakpoints", bkptsBefore.length + 1, bkptsAfter.size()); ListIterator iter = bkptsAfter.listIterator(); diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIModifiedServicesTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIModifiedServicesTest.java index 10d47f175a5..57da9731567 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIModifiedServicesTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIModifiedServicesTest.java @@ -224,8 +224,8 @@ public class MIModifiedServicesTest extends BaseParametrizedTestCase { private void resumeContainerContextExe() throws InterruptedException, ExecutionException, TimeoutException { - final ServiceEventWaitor resumedWaitor = new ServiceEventWaitor<>( - getGDBLaunch().getSession(), IResumedDMEvent.class); + final ServiceEventWaitor resumedWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), + IResumedDMEvent.class); Query query = new Query() { @Override diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java index 3118defa988..ed14ac8825e 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java @@ -413,8 +413,8 @@ public class MIRegistersTest extends BaseParametrizedTestCase { */ private List writeRegisterWaitNotication(final IRegisterDMContext registerDmc, final String regValue, final String formatId) throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fSession, IRegistersChangedDMEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, + IRegistersChangedDMEvent.class); writeRegister(registerDmc, regValue, formatId); diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTargetAvailableTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTargetAvailableTest.java index 7c7671a07e0..58d7ba19f83 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTargetAvailableTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTargetAvailableTest.java @@ -372,8 +372,7 @@ public class MIRunControlTargetAvailableTest extends BaseParametrizedTestCase { // Wait up to 3 second for the target to suspend. Should happen within two seconds. suspendedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(3000)); - suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), - ISuspendedDMEvent.class); + suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), ISuspendedDMEvent.class); SyncUtil.resume(); @@ -575,8 +574,7 @@ public class MIRunControlTargetAvailableTest extends BaseParametrizedTestCase { suspendedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(3000)); // Now resume the target and check that we stop at all the breakpoints. - suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), - ISuspendedDMEvent.class); + suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), ISuspendedDMEvent.class); SyncUtil.resume(); } @@ -707,8 +705,7 @@ public class MIRunControlTargetAvailableTest extends BaseParametrizedTestCase { suspendedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(3000)); // Now resume the target and check that we stop at all the breakpoints. - suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), - ISuspendedDMEvent.class); + suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), ISuspendedDMEvent.class); SyncUtil.resume(); } @@ -835,8 +832,7 @@ public class MIRunControlTargetAvailableTest extends BaseParametrizedTestCase { suspendedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(3000)); // Now resume the target and check that we stop at all the breakpoints. - suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), - ISuspendedDMEvent.class); + suspendedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), ISuspendedDMEvent.class); SyncUtil.resume(); } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java index d19784ef8dc..4ec35480c88 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java @@ -580,8 +580,8 @@ public class MIRunControlTest extends BaseParametrizedTestCase { //TestsPlugin.debug("handleCompleted over"); } }; - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - getGDBLaunch().getSession(), IResumedDMEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), + IResumedDMEvent.class); final IContainerDMContext containerDmc = SyncUtil.getContainerContext(); @@ -629,8 +629,8 @@ public class MIRunControlTest extends BaseParametrizedTestCase { } }; - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - getGDBLaunch().getSession(), IResumedDMEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), + IResumedDMEvent.class); fRunCtrl.getExecutor().submit(new Runnable() { @Override diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/OperationsWhileTargetIsRunningTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/OperationsWhileTargetIsRunningTest.java index 2d5d7303c3f..e9aff95a70e 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/OperationsWhileTargetIsRunningTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/OperationsWhileTargetIsRunningTest.java @@ -215,8 +215,8 @@ public class OperationsWhileTargetIsRunningTest extends BaseParametrizedTestCase // then we terminate the process, and confirm that there are no more processes SyncUtil.resume(); - ServiceEventWaitor exitedEventWaitor = new ServiceEventWaitor<>( - getGDBLaunch().getSession(), IExitedDMEvent.class); + ServiceEventWaitor exitedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), + IExitedDMEvent.class); Query query = new Query() { @Override @@ -297,8 +297,8 @@ public class OperationsWhileTargetIsRunningTest extends BaseParametrizedTestCase // then we detach the process, and confirm that we are not longer running SyncUtil.resume(); - ServiceEventWaitor exitedEventWaitor = new ServiceEventWaitor<>( - getGDBLaunch().getSession(), IExitedDMEvent.class); + ServiceEventWaitor exitedEventWaitor = new ServiceEventWaitor<>(getGDBLaunch().getSession(), + IExitedDMEvent.class); Query query = new Query() { @Override diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java index 297b5f211b4..d0742df6dcb 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java @@ -353,8 +353,7 @@ public class SourceLookupTest extends BaseParametrizedTestCase { protected void addSourceContainer(AbstractSourceLookupDirector director, ISourceContainer container) throws CoreException { - ArrayList containerList = new ArrayList<>( - Arrays.asList(director.getSourceContainers())); + ArrayList containerList = new ArrayList<>(Arrays.asList(director.getSourceContainers())); container.init(director); containerList.add(container); director.setSourceContainers(containerList.toArray(new ISourceContainer[containerList.size()])); diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/StepIntoSelectionTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/StepIntoSelectionTest.java index d7fe5dd96cc..ddb9e54fe81 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/StepIntoSelectionTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/StepIntoSelectionTest.java @@ -186,8 +186,7 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase { */ private ISuspendedDMEvent triggerStepIntoSelection(final IExecutionDMContext exeContext, final String sourceName, final int targetLine, final IFunctionDeclaration function, final boolean skipBreakPoints) throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - ISuspendedDMEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, ISuspendedDMEvent.class); Query query = new Query() { @Override @@ -207,8 +206,7 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase { */ private ISuspendedDMEvent triggerRunToLine(final IExecutionDMContext exeContext, final String sourceName, final int targetLine, final boolean skipBreakPoints) throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, - ISuspendedDMEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fSession, ISuspendedDMEvent.class); Query query = new Query() { @Override diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/GDBMultiNonStopRunControlTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/GDBMultiNonStopRunControlTest.java index dce2138b3d1..53c64183834 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/GDBMultiNonStopRunControlTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/GDBMultiNonStopRunControlTest.java @@ -353,8 +353,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -463,8 +463,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -577,8 +577,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -696,8 +696,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IMIExecutionDMContext[] threads = SyncUtil.getExecutionContexts(); assertTrue("Expected a single thread but got " + threads.length, threads.length == 1); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -767,8 +767,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -777,8 +777,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IMIExecutionDMContext[] threads = SyncUtil.getExecutionContexts(); assertTrue("Expected two threads but got " + threads.length, threads.length == 2); - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -819,8 +819,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -829,8 +829,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IMIExecutionDMContext[] threads = SyncUtil.getExecutionContexts(); assertTrue("Expected two threads but got " + threads.length, threads.length == 2); - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -862,8 +862,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -876,8 +876,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IMIExecutionDMContext[] threads = SyncUtil.getExecutionContexts(); assertTrue("Expected two threads but got " + threads.length, threads.length == 2); - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -910,8 +910,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -927,8 +927,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IMIExecutionDMContext[] threads = SyncUtil.getExecutionContexts(); assertTrue("Expected two threads but got " + threads.length, threads.length == 2); - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -1000,8 +1000,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { }); assertFalse("expected no threads to be suspended, but found some", result); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -1031,8 +1031,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1069,8 +1069,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1113,8 +1113,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1169,8 +1169,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1444,8 +1444,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1553,8 +1553,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1666,8 +1666,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -1996,8 +1996,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2109,8 +2109,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2227,8 +2227,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2345,8 +2345,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2471,8 +2471,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2585,8 +2585,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2703,8 +2703,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2824,8 +2824,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { public void testResumeProcessOneThreadStopped() throws Throwable { final IExecutionDMContext[] processes = new IExecutionDMContext[] { SyncUtil.getContainerContext() }; - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -2894,8 +2894,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2903,8 +2903,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] processes = new IExecutionDMContext[] { SyncUtil.getContainerContext() }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -2936,8 +2936,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2949,8 +2949,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] processes = new IExecutionDMContext[] { SyncUtil.getContainerContext() }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -2983,8 +2983,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -2999,8 +2999,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] processes = new IExecutionDMContext[] { SyncUtil.getContainerContext() }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -3082,8 +3082,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { }); assertFalse("expected no process to be suspended, but found some", result); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -3113,8 +3113,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3162,8 +3162,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3217,8 +3217,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3302,8 +3302,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0) }; - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -3347,8 +3347,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { }); assertFalse("expected no contexts to be suspended, but found some", result); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running processes runAsyncCall(new AsyncRunnable() { @@ -3381,8 +3381,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3391,8 +3391,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -3427,8 +3427,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3441,8 +3441,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -3477,8 +3477,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3491,8 +3491,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(1) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -3526,8 +3526,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3543,8 +3543,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -3650,8 +3650,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { }); assertFalse("expected no process to be suspended, but found some", result); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -3682,8 +3682,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3733,8 +3733,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3790,8 +3790,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3847,8 +3847,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3937,8 +3937,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3947,8 +3947,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0), SyncUtil.getExecutionContext(1) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); runAsyncCall(new AsyncRunnable() { @Override @@ -3983,8 +3983,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -3997,8 +3997,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0), SyncUtil.getExecutionContext(1) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -4032,8 +4032,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -4049,8 +4049,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { final IExecutionDMContext[] execDmcs = new IExecutionDMContext[] { SyncUtil.getContainerContext(), SyncUtil.getExecutionContext(0), SyncUtil.getExecutionContext(1) }; - final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIRunningEvent.class); + final ServiceEventWaitor eventWaitorRunning = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIRunningEvent.class); // No error should be thrown, the call should ignore running threads runAsyncCall(new AsyncRunnable() { @@ -4086,8 +4086,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -4137,8 +4137,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitorStopped = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitorStopped.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop @@ -4194,8 +4194,8 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase { // Run program until both threads are stopped SyncUtil.addBreakpoint("firstBreakpoint", false); - final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRun.getSession(), MIStoppedEvent.class); + final ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRun.getSession(), + MIStoppedEvent.class); SyncUtil.resumeAll(); eventWaitor.waitForEvent(TestsPlugin.massageTimeout(2000)); // Wait for first thread to stop diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/ThreadStackFrameSyncTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/ThreadStackFrameSyncTest.java index 5b197e94896..3a41449987f 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/ThreadStackFrameSyncTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/nonstop/ThreadStackFrameSyncTest.java @@ -157,8 +157,8 @@ public class ThreadStackFrameSyncTest extends BaseParametrizedTestCase { */ @Test public void testChangingCurrentThreadCLINotification() throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRunControl.getSession(), MIStoppedEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRunControl.getSession(), + MIStoppedEvent.class); // add a breakpoint in main SyncUtil.addBreakpoint(SOURCE_NAME + ":" + getLineForTag("LINE_MAIN_ALL_THREADS_STARTED"), false); @@ -193,8 +193,8 @@ public class ThreadStackFrameSyncTest extends BaseParametrizedTestCase { */ @Test public void testChangingCurrentFrameCLINotification() throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRunControl.getSession(), MIStoppedEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRunControl.getSession(), + MIStoppedEvent.class); // add a breakpoint in main SyncUtil.addBreakpoint(SOURCE_NAME + ":" + getLineForTag("LINE_MAIN_ALL_THREADS_STARTED"), false); @@ -229,8 +229,8 @@ public class ThreadStackFrameSyncTest extends BaseParametrizedTestCase { */ @Test public void testGdbSyncServiceCanSwitchGDBThread() throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRunControl.getSession(), MIStoppedEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRunControl.getSession(), + MIStoppedEvent.class); // add a breakpoint in main SyncUtil.addBreakpoint(SOURCE_NAME + ":" + getLineForTag("LINE_MAIN_ALL_THREADS_STARTED"), false); @@ -270,8 +270,8 @@ public class ThreadStackFrameSyncTest extends BaseParametrizedTestCase { */ @Test public void testGdbSyncServiceCanSwitchGDBStackFrame() throws Throwable { - ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>( - fMultiRunControl.getSession(), MIStoppedEvent.class); + ServiceEventWaitor eventWaitor = new ServiceEventWaitor<>(fMultiRunControl.getSession(), + MIStoppedEvent.class); // add a breakpoint in main SyncUtil.addBreakpoint(SOURCE_NAME + ":" + getLineForTag("LINE_MAIN_ALL_THREADS_STARTED"), false); diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/DisassemblyColumnSupport.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/DisassemblyColumnSupport.java index ebe9233d677..a1124a14ca6 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/DisassemblyColumnSupport.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/DisassemblyColumnSupport.java @@ -202,8 +202,7 @@ class DisassemblyColumnSupport implements IColumnSupport { */ @Override public void dispose() { - for (Iterator iter = new ArrayList<>(fColumns).iterator(); iter - .hasNext();) + for (Iterator iter = new ArrayList<>(fColumns).iterator(); iter.hasNext();) removeColumn(getRuler(), iter.next()); fColumns.clear(); } diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMNode.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMNode.java index b6e9bae3b7f..100d8a1d377 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMNode.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMNode.java @@ -55,8 +55,7 @@ public class BreakpointVMNode extends AbstractBreakpointVMNode @Override public void update(ILabelUpdate[] updates) { - Map> delegatesMap = new HashMap<>( - 1, 1); + Map> delegatesMap = new HashMap<>(1, 1); for (final ILabelUpdate update : updates) { final IBreakpoint bp = ((BreakpointVMContext) update.getElement()).getBreakpoint(); @@ -164,8 +163,7 @@ public class BreakpointVMNode extends AbstractBreakpointVMNode @Override public void encodeElements(IElementMementoRequest[] updates) { - Map> delegatesMap = new HashMap<>( - 1, 1); + Map> delegatesMap = new HashMap<>(1, 1); for (final IElementMementoRequest update : updates) { final IBreakpoint bp = ((BreakpointVMContext) update.getElement()).getBreakpoint(); @@ -241,8 +239,7 @@ public class BreakpointVMNode extends AbstractBreakpointVMNode @Override public void compareElements(IElementCompareRequest[] updates) { - Map> delegatesMap = new HashMap<>( - 1, 1); + Map> delegatesMap = new HashMap<>(1, 1); for (final IElementCompareRequest update : updates) { final IBreakpoint bp = ((BreakpointVMContext) update.getElement()).getBreakpoint(); diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMProvider.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMProvider.java index 6caaed1dc79..a25654d5a04 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMProvider.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/breakpoints/BreakpointVMProvider.java @@ -144,8 +144,7 @@ public class BreakpointVMProvider extends AbstractVMProvider { } } - List vmcs = new ArrayList<>( - bpsLists.size()); + List vmcs = new ArrayList<>(bpsLists.size()); for (Map.Entry> entry : bpsLists.entrySet()) { List bpsList = entry.getValue(); IBreakpoint[] bpsArray = bpsList.toArray(new IBreakpoint[bpsList.size()]); diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueRetriever.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueRetriever.java index b3dbfc60a88..2f3507146e4 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueRetriever.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueRetriever.java @@ -424,10 +424,8 @@ public class FormattedValueRetriever { final Map availableFormatsMap, final Map elementFormatMap, final RequestMonitor rm) { final List outstandingUpdates = new ArrayList<>(updates.length); - final Map> requestedFormatsMap = new HashMap<>( - updates.length * 4 / 3); - final Map activeFormatsMap = new HashMap<>( - updates.length * 4 / 3); + final Map> requestedFormatsMap = new HashMap<>(updates.length * 4 / 3); + final Map activeFormatsMap = new HashMap<>(updates.length * 4 / 3); for (final IPropertiesUpdate update : updates) { String preferredFormat = FormattedValueVMUtil.getPreferredFormat(update.getPresentationContext()); diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator.java index 0516ceaa24e..b7c4b07d9f0 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator.java @@ -203,8 +203,7 @@ public class BreakpointsMediator extends AbstractDsfService implements IBreakpoi // We have to make a copy of the fPlatformBPs keys because uninstallBreakpoints() // modifies the map as it walks through it. - List platformBPKeysCopy = new ArrayList<>( - fPlatformBPs.size()); + List platformBPKeysCopy = new ArrayList<>(fPlatformBPs.size()); platformBPKeysCopy.addAll(0, fPlatformBPs.keySet()); for (IBreakpointsTargetDMContext dmc : platformBPKeysCopy) { stopTrackingBreakpoints(dmc, countingRm); @@ -567,8 +566,7 @@ public class BreakpointsMediator extends AbstractDsfService implements IBreakpoi } // Get the list of corresponding back-end breakpoints - final List oldBpContexts = new ArrayList<>( - breakpointIDs.get(breakpoint)); + final List oldBpContexts = new ArrayList<>(breakpointIDs.get(breakpoint)); // Calculate the list of attributes maps that have not changed. // Immediately add these to the list of new breakpoint contexts, diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator2.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator2.java index acc7b20781a..0edd50cd186 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator2.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/BreakpointsMediator2.java @@ -319,8 +319,7 @@ public class BreakpointsMediator2 extends AbstractDsfService implements IBreakpo // We have to make a copy of the fPlatformBPs keys because uninstallBreakpoints() // modifies the map as it walks through it. - List platformBPKeysCopy = new ArrayList<>( - fPlatformBPs.size()); + List platformBPKeysCopy = new ArrayList<>(fPlatformBPs.size()); platformBPKeysCopy.addAll(0, fPlatformBPs.keySet()); for (IBreakpointsTargetDMContext dmc : platformBPKeysCopy) { stopTrackingBreakpoints(dmc, countingRm); @@ -527,8 +526,7 @@ public class BreakpointsMediator2 extends AbstractDsfService implements IBreakpo targetBPsAttempted.add(new TargetBP(attrsList.get(i))); } - final ArrayList targetBPsInstalled = new ArrayList<>( - attrsList.size()); + final ArrayList targetBPsInstalled = new ArrayList<>(attrsList.size()); // Update the breakpoint status when all back-end breakpoints have been installed final CountingRequestMonitor installRM = new CountingRequestMonitor(getExecutor(), rm) { diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/command/CommandCache.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/command/CommandCache.java index e87663d3a11..9b70d91bacd 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/command/CommandCache.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/command/CommandCache.java @@ -287,8 +287,7 @@ public class CommandCache implements ICommandListener { * them to point to the new super command. */ - for (CommandInfo waitingEntry : new ArrayList<>( - fPendingQWaitingForCoalescedCompletion)) { + for (CommandInfo waitingEntry : new ArrayList<>(fPendingQWaitingForCoalescedCompletion)) { if (waitingEntry.getCoalescedCmd() == currentUnsentEntry) { /* @@ -469,8 +468,7 @@ public class CommandCache implements ICommandListener { * we create a new result from the coalesced command for it. */ - for (CommandInfo waitingEntry : new ArrayList<>( - fPendingQWaitingForCoalescedCompletion)) { + for (CommandInfo waitingEntry : new ArrayList<>(fPendingQWaitingForCoalescedCompletion)) { if (waitingEntry.getCoalescedCmd() == finalCachedCmd) { diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/service/DsfSession.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/service/DsfSession.java index 13d3c831bfc..65cf4066799 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/service/DsfSession.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/service/DsfSession.java @@ -485,29 +485,28 @@ public class DsfSession { Dictionary serviceProperties = (Dictionary) _serviceProperties; // Build a list of listeners; - SortedMap> listeners = new TreeMap<>( - new Comparator() { - @Override - public int compare(ListenerEntry o1, ListenerEntry o2) { - if (o1.fListener == o2.fListener) { - return 0; - } - if (o1.fListener instanceof IDsfService && !(o2.fListener instanceof IDsfService)) { - return -1; - } else if (o2.fListener instanceof IDsfService && !(o1.fListener instanceof IDsfService)) { - return 1; - } else if ((o1.fListener instanceof IDsfService) && (o2.fListener instanceof IDsfService)) { - return ((IDsfService) o1.fListener).getStartupNumber() - - ((IDsfService) o2.fListener).getStartupNumber(); - } - return 1; - } + SortedMap> listeners = new TreeMap<>(new Comparator() { + @Override + public int compare(ListenerEntry o1, ListenerEntry o2) { + if (o1.fListener == o2.fListener) { + return 0; + } + if (o1.fListener instanceof IDsfService && !(o2.fListener instanceof IDsfService)) { + return -1; + } else if (o2.fListener instanceof IDsfService && !(o1.fListener instanceof IDsfService)) { + return 1; + } else if ((o1.fListener instanceof IDsfService) && (o2.fListener instanceof IDsfService)) { + return ((IDsfService) o1.fListener).getStartupNumber() + - ((IDsfService) o2.fListener).getStartupNumber(); + } + return 1; + } - @Override - public boolean equals(Object obj) { - return obj == this; - } - }); + @Override + public boolean equals(Object obj) { + return obj == this; + } + }); // Build a list of listeners and methods that are registered for this event class. Class eventClass = event.getClass(); diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataGenerator.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataGenerator.java index b3ac142d568..2e663a2354f 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataGenerator.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataGenerator.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -46,205 +47,190 @@ import org.eclipse.core.runtime.CoreException; * invalidate their caches. *

*/ -public class ACPMSumDataGenerator - implements IDataGenerator, IDataGenerator.Listener -{ +public class ACPMSumDataGenerator implements IDataGenerator, IDataGenerator.Listener { - /** - * DSF executor used to serialize data access within this data generator. - */ - final private DsfExecutor fExecutor; + /** + * DSF executor used to serialize data access within this data generator. + */ + final private DsfExecutor fExecutor; - /** - * Data generators to retrieve original data to perform calculations on. - * The generators are accessed through the cache manager wrappers. - */ - final private DataGeneratorCacheManager[] fDataGeneratorCMs; + /** + * Data generators to retrieve original data to perform calculations on. + * The generators are accessed through the cache manager wrappers. + */ + final private DataGeneratorCacheManager[] fDataGeneratorCMs; - /** - * List of listeners for this data generator. - */ - final private List fListeners = new LinkedList(); + /** + * List of listeners for this data generator. + */ + final private List fListeners = new LinkedList(); - public ACPMSumDataGenerator(DsfExecutor executor, - IDataGenerator[] generators) - { - fExecutor = executor; + public ACPMSumDataGenerator(DsfExecutor executor, IDataGenerator[] generators) { + fExecutor = executor; - // Create wrappers for data generators and add ourselves as listener - // to their events. - fDataGeneratorCMs = new DataGeneratorCacheManager[generators.length]; - ImmediateInDsfExecutor immediateExecutor = - new ImmediateInDsfExecutor(fExecutor); - for (int i = 0; i < generators.length; i++) { - fDataGeneratorCMs[i] = new DataGeneratorCacheManager( - immediateExecutor, generators[i]); - generators[i].addListener(this); - } - } + // Create wrappers for data generators and add ourselves as listener + // to their events. + fDataGeneratorCMs = new DataGeneratorCacheManager[generators.length]; + ImmediateInDsfExecutor immediateExecutor = new ImmediateInDsfExecutor(fExecutor); + for (int i = 0; i < generators.length; i++) { + fDataGeneratorCMs[i] = new DataGeneratorCacheManager(immediateExecutor, generators[i]); + generators[i].addListener(this); + } + } - @Override + @Override public void getCount(final DataRequestMonitor rm) { - // Artificially delay the retrieval of the sum data to simulate - // real processing time. - fExecutor.schedule( new Runnable() { - @Override - public void run() { - // Create the transaction here to put all the ugly - // code in one place. - new Transaction() { - @Override - protected Integer process() - throws Transaction.InvalidCacheException, - CoreException - { - return processCount(this); - } - }.request(rm); - } - }, - PROCESSING_DELAY, TimeUnit.MILLISECONDS); - } + // Artificially delay the retrieval of the sum data to simulate + // real processing time. + fExecutor.schedule(new Runnable() { + @Override + public void run() { + // Create the transaction here to put all the ugly + // code in one place. + new Transaction() { + @Override + protected Integer process() throws Transaction.InvalidCacheException, CoreException { + return processCount(this); + } + }.request(rm); + } + }, PROCESSING_DELAY, TimeUnit.MILLISECONDS); + } - /** - * Perform the calculation to get the max count for the given transaction. - * @param transaction The ACPM transaction to use for calculation. - * @return Calculated count. - * @throws Transaction.InvalidCacheException {@link Transaction#process} - * @throws CoreException See {@link Transaction#process} - */ - private Integer processCount(Transaction transaction) - throws Transaction.InvalidCacheException, CoreException - { - // Assemble all needed count caches into a collection. - List> countCaches = - new ArrayList>(fDataGeneratorCMs.length); - for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { - countCaches.add(dataGeneratorCM.getCount()); - } - // Validate all count caches at once. This executes needed requests - // in parallel. - transaction.validate(countCaches); + /** + * Perform the calculation to get the max count for the given transaction. + * @param transaction The ACPM transaction to use for calculation. + * @return Calculated count. + * @throws Transaction.InvalidCacheException {@link Transaction#process} + * @throws CoreException See {@link Transaction#process} + */ + private Integer processCount(Transaction transaction) + throws Transaction.InvalidCacheException, CoreException { + // Assemble all needed count caches into a collection. + List> countCaches = new ArrayList>(fDataGeneratorCMs.length); + for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { + countCaches.add(dataGeneratorCM.getCount()); + } + // Validate all count caches at once. This executes needed requests + // in parallel. + transaction.validate(countCaches); - // Calculate the max value and return. - int maxCount = 0; - for (ICache countCache : countCaches) { - maxCount = Math.max(maxCount, countCache.getData()); - } - return maxCount; - } + // Calculate the max value and return. + int maxCount = 0; + for (ICache countCache : countCaches) { + maxCount = Math.max(maxCount, countCache.getData()); + } + return maxCount; + } - @Override - public void getValue(final int index, final DataRequestMonitor rm) - { - // Add a processing delay. - fExecutor.schedule( new Runnable() { - @Override - public void run() { - new Transaction() { - @Override - protected Integer process() - throws Transaction.InvalidCacheException, - CoreException - { - return processValue(this, index); - } - }.request(rm); - } - }, - PROCESSING_DELAY, TimeUnit.MILLISECONDS); - } + @Override + public void getValue(final int index, final DataRequestMonitor rm) { + // Add a processing delay. + fExecutor.schedule(new Runnable() { + @Override + public void run() { + new Transaction() { + @Override + protected Integer process() throws Transaction.InvalidCacheException, CoreException { + return processValue(this, index); + } + }.request(rm); + } + }, PROCESSING_DELAY, TimeUnit.MILLISECONDS); + } - /** - * Perform the calculation to get the sum of values at given index. - * @param transaction The ACPM transaction to use for calculation. - * @param index Index of value to calculate. - * @return Calculated value. - * @throws Transaction.InvalidCacheException {@link Transaction#process} - * @throws CoreException See {@link Transaction#process} - */ - private Integer processValue(Transaction transaction, int index) - throws Transaction.InvalidCacheException, CoreException - { - List> valueCaches = - new ArrayList>(fDataGeneratorCMs.length); - for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { - valueCaches.add(dataGeneratorCM.getValue(index)); - } - // Validate all value caches at once. This executes needed requests - // in parallel. - transaction.validate(valueCaches); + /** + * Perform the calculation to get the sum of values at given index. + * @param transaction The ACPM transaction to use for calculation. + * @param index Index of value to calculate. + * @return Calculated value. + * @throws Transaction.InvalidCacheException {@link Transaction#process} + * @throws CoreException See {@link Transaction#process} + */ + private Integer processValue(Transaction transaction, int index) + throws Transaction.InvalidCacheException, CoreException { + List> valueCaches = new ArrayList>(fDataGeneratorCMs.length); + for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { + valueCaches.add(dataGeneratorCM.getValue(index)); + } + // Validate all value caches at once. This executes needed requests + // in parallel. + transaction.validate(valueCaches); - int sum = 0; - for (ICache valueCache : valueCaches) { - sum += valueCache.getData(); - } - return sum; - } + int sum = 0; + for (ICache valueCache : valueCaches) { + sum += valueCache.getData(); + } + return sum; + } - @Override + @Override public void shutdown(final RequestMonitor rm) { - for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { - dataGeneratorCM.getDataGenerator().removeListener(this); - dataGeneratorCM.dispose(); - rm.done(); - } - rm.done(); - } + for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { + dataGeneratorCM.getDataGenerator().removeListener(this); + dataGeneratorCM.dispose(); + rm.done(); + } + rm.done(); + } - @Override + @Override public void addListener(final Listener listener) { - // Must access fListeners on executor thread. - try { - fExecutor.execute( new DsfRunnable() { - @Override + // Must access fListeners on executor thread. + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fListeners.add(listener); - } - }); - } catch (RejectedExecutionException e) {} - } + fListeners.add(listener); + } + }); + } catch (RejectedExecutionException e) { + } + } - @Override + @Override public void removeListener(final Listener listener) { - // Must access fListeners on executor thread. - try { - fExecutor.execute( new DsfRunnable() { - @Override + // Must access fListeners on executor thread. + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fListeners.remove(listener); - } - }); - } catch (RejectedExecutionException e) {} - } + fListeners.remove(listener); + } + }); + } catch (RejectedExecutionException e) { + } + } - @Override + @Override public void countChanged() { - // Must access fListeners on executor thread. - try { - fExecutor.execute( new DsfRunnable() { - @Override + // Must access fListeners on executor thread. + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - for (Listener listener : fListeners) { - listener.countChanged(); - } - } - }); - } catch (RejectedExecutionException e) {} - } + for (Listener listener : fListeners) { + listener.countChanged(); + } + } + }); + } catch (RejectedExecutionException e) { + } + } - @Override + @Override public void valuesChanged(final Set changed) { - // Must access fListeners on executor thread. - try { - fExecutor.execute( new DsfRunnable() { - @Override + // Must access fListeners on executor thread. + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - for (Object listener : fListeners) { - ((Listener)listener).valuesChanged(changed); - } - } - }); - } catch (RejectedExecutionException e) {} - } + for (Object listener : fListeners) { + ((Listener) listener).valuesChanged(changed); + } + } + }); + } catch (RejectedExecutionException e) { + } + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataViewer.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataViewer.java index 16f1060b63f..cccab46b2fb 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataViewer.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/ACPMSumDataViewer.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -62,431 +63,409 @@ import org.eclipse.swt.widgets.Table; *

*/ @ConfinedToDsfExecutor("fDisplayExecutor") -public class ACPMSumDataViewer implements ILazyContentProvider -{ - /** View update frequency interval. */ - final private static int UPDATE_INTERVAL = 10000; +public class ACPMSumDataViewer implements ILazyContentProvider { + /** View update frequency interval. */ + final private static int UPDATE_INTERVAL = 10000; - /** Executor to use instead of Display.asyncExec(). **/ - @ThreadSafe - final private DsfExecutor fDisplayExecutor; + /** Executor to use instead of Display.asyncExec(). **/ + @ThreadSafe + final private DsfExecutor fDisplayExecutor; - /** Executor to use when retrieving data from data providers */ - @ThreadSafe - final private ImmediateInDsfExecutor fDataExecutor; + /** Executor to use when retrieving data from data providers */ + @ThreadSafe + final private ImmediateInDsfExecutor fDataExecutor; - // The viewer and generator that this content provider using. - final private TableViewer fViewer; - final private DataGeneratorCacheManager[] fDataGeneratorCMs; - final private DataGeneratorCacheManager fSumGeneratorCM; + // The viewer and generator that this content provider using. + final private TableViewer fViewer; + final private DataGeneratorCacheManager[] fDataGeneratorCMs; + final private DataGeneratorCacheManager fSumGeneratorCM; - // Fields used in request cancellation logic. - private List fItemDataRequestMonitors = - new LinkedList(); - private Set fIndexesToCancel = new HashSet(); - private int fCancelCallsPending = 0; - private Future fRefreshFuture; + // Fields used in request cancellation logic. + private List fItemDataRequestMonitors = new LinkedList(); + private Set fIndexesToCancel = new HashSet(); + private int fCancelCallsPending = 0; + private Future fRefreshFuture; - public ACPMSumDataViewer(TableViewer viewer, - ImmediateInDsfExecutor dataExecutor, IDataGenerator[] generators, - IDataGenerator sumGenerator) - { - fViewer = viewer; - fDisplayExecutor = DisplayDsfExecutor.getDisplayDsfExecutor( - fViewer.getTable().getDisplay()); - fDataExecutor = dataExecutor; + public ACPMSumDataViewer(TableViewer viewer, ImmediateInDsfExecutor dataExecutor, IDataGenerator[] generators, + IDataGenerator sumGenerator) { + fViewer = viewer; + fDisplayExecutor = DisplayDsfExecutor.getDisplayDsfExecutor(fViewer.getTable().getDisplay()); + fDataExecutor = dataExecutor; - // Create wrappers for data generators. Don't need to register as - // listeners to generator events because the cache managers ensure data - // are already registered for them. - fDataGeneratorCMs = new DataGeneratorCacheManager[generators.length]; - for (int i = 0; i < generators.length; i++) { - fDataGeneratorCMs[i] = - new DataGeneratorCacheManager(fDataExecutor, generators[i]); - } - fSumGeneratorCM = - new DataGeneratorCacheManager(fDataExecutor, sumGenerator); + // Create wrappers for data generators. Don't need to register as + // listeners to generator events because the cache managers ensure data + // are already registered for them. + fDataGeneratorCMs = new DataGeneratorCacheManager[generators.length]; + for (int i = 0; i < generators.length; i++) { + fDataGeneratorCMs[i] = new DataGeneratorCacheManager(fDataExecutor, generators[i]); + } + fSumGeneratorCM = new DataGeneratorCacheManager(fDataExecutor, sumGenerator); - // Schedule a task to refresh the viewer periodically. - fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate( - new Runnable() { - @Override - public void run() { - queryItemCount(); - } - }, - UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS); - } + // Schedule a task to refresh the viewer periodically. + fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + queryItemCount(); + } + }, UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS); + } - @Override + @Override public void dispose() { - // Cancel the periodic task of refreshing the view. - fRefreshFuture.cancel(false); + // Cancel the periodic task of refreshing the view. + fRefreshFuture.cancel(false); - // Need to dispose cache managers that were created in this class. This - // needs to be done on the cache manager's thread. - Query disposeCacheManagersQuery = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fSumGeneratorCM.dispose(); - for (DataGeneratorCacheManager dataGeneratorCM : - fDataGeneratorCMs) - { - dataGeneratorCM.dispose(); - } - rm.setData(new Object()); - rm.done(); - } - }; - fDataExecutor.execute(disposeCacheManagersQuery); - try { - disposeCacheManagersQuery.get(); - } - catch (InterruptedException e) {} - catch (ExecutionException e) {} + // Need to dispose cache managers that were created in this class. This + // needs to be done on the cache manager's thread. + Query disposeCacheManagersQuery = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fSumGeneratorCM.dispose(); + for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { + dataGeneratorCM.dispose(); + } + rm.setData(new Object()); + rm.done(); + } + }; + fDataExecutor.execute(disposeCacheManagersQuery); + try { + disposeCacheManagersQuery.get(); + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } - // Cancel any outstanding data requests. - for (ValueRequestMonitor rm : fItemDataRequestMonitors) { - rm.cancel(); - } - fItemDataRequestMonitors.clear(); - } + // Cancel any outstanding data requests. + for (ValueRequestMonitor rm : fItemDataRequestMonitors) { + rm.cancel(); + } + fItemDataRequestMonitors.clear(); + } - @Override + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // Set the initial count to the viewer after the input is set. - queryItemCount(); - } + // Set the initial count to the viewer after the input is set. + queryItemCount(); + } - @Override + @Override public void updateElement(final int index) { - // Calculate the visible index range. - final int topIdx = fViewer.getTable().getTopIndex(); - final int botIdx = topIdx + getVisibleItemCount(topIdx); + // Calculate the visible index range. + final int topIdx = fViewer.getTable().getTopIndex(); + final int botIdx = topIdx + getVisibleItemCount(topIdx); - // Request the item for the given index. - queryValue(index); + // Request the item for the given index. + queryValue(index); - // Invoke a cancel task with a delay. The delay allows multiple cancel - // calls to be combined together improving performance of the viewer. - fCancelCallsPending++; - fDisplayExecutor.execute( - new Runnable() { @Override + // Invoke a cancel task with a delay. The delay allows multiple cancel + // calls to be combined together improving performance of the viewer. + fCancelCallsPending++; + fDisplayExecutor.execute(new Runnable() { + @Override public void run() { - cancelStaleRequests(topIdx, botIdx); - }}); - } + cancelStaleRequests(topIdx, botIdx); + } + }); + } - /** - * Calculates the number of visible items based on the top item index and - * table bounds. - * @param top Index of top item. - * @return calculated number of items in viewer - */ - private int getVisibleItemCount(int top) { - Table table = fViewer.getTable(); - int itemCount = table.getItemCount(); - return Math.min( - (table.getBounds().height / table.getItemHeight()) + 2, - itemCount - top); - } + /** + * Calculates the number of visible items based on the top item index and + * table bounds. + * @param top Index of top item. + * @return calculated number of items in viewer + */ + private int getVisibleItemCount(int top) { + Table table = fViewer.getTable(); + int itemCount = table.getItemCount(); + return Math.min((table.getBounds().height / table.getItemHeight()) + 2, itemCount - top); + } - /** - * Retrieve the current count. When a new count is set to viewer, the viewer - * will refresh all items as well. - */ - private void queryItemCount() { - // Create the request monitor to collect the count. This request - // monitor will be completed by the following transaction. - final DataRequestMonitor rm = - new DataRequestMonitor(fDisplayExecutor, null) - { - @Override - protected void handleSuccess() { - setCountToViewer(getData()); - } - @Override - protected void handleRejectedExecutionException() {} // Shutting down, ignore. - }; + /** + * Retrieve the current count. When a new count is set to viewer, the viewer + * will refresh all items as well. + */ + private void queryItemCount() { + // Create the request monitor to collect the count. This request + // monitor will be completed by the following transaction. + final DataRequestMonitor rm = new DataRequestMonitor(fDisplayExecutor, null) { + @Override + protected void handleSuccess() { + setCountToViewer(getData()); + } - // Use a transaction, even with a single cache. This will ensure that - // if the cache is reset during processing by an event. The request - // for data will be re-issued. - fDataExecutor.execute(new Runnable() { - @Override + @Override + protected void handleRejectedExecutionException() { + } // Shutting down, ignore. + }; + + // Use a transaction, even with a single cache. This will ensure that + // if the cache is reset during processing by an event. The request + // for data will be re-issued. + fDataExecutor.execute(new Runnable() { + @Override public void run() { - new Transaction() { - @Override - protected Integer process() - throws Transaction.InvalidCacheException, CoreException - { - return processCount(this); - } - }.request(rm); - } - }); - } + new Transaction() { + @Override + protected Integer process() throws Transaction.InvalidCacheException, CoreException { + return processCount(this); + } + }.request(rm); + } + }); + } - /** - * Perform the count retrieval from the sum data generator. - * @param transaction The ACPM transaction to use for calculation. - * @return Calculated count. - * @throws Transaction.InvalidCacheException {@link Transaction#process} - * @throws CoreException See {@link Transaction#process} - */ - private Integer processCount(Transaction transaction) - throws Transaction.InvalidCacheException, CoreException - { - ICache countCache = fSumGeneratorCM.getCount(); - transaction.validate(countCache); - return countCache.getData(); - } + /** + * Perform the count retrieval from the sum data generator. + * @param transaction The ACPM transaction to use for calculation. + * @return Calculated count. + * @throws Transaction.InvalidCacheException {@link Transaction#process} + * @throws CoreException See {@link Transaction#process} + */ + private Integer processCount(Transaction transaction) + throws Transaction.InvalidCacheException, CoreException { + ICache countCache = fSumGeneratorCM.getCount(); + transaction.validate(countCache); + return countCache.getData(); + } - /** - * Set the givne count to the viewer. This will cause the viewer will - * refresh all items' data as well. - *

Note: This method must be called in the display thread.

- * @param count New count to set to viewer. - */ - private void setCountToViewer(int count) { - if (!fViewer.getTable().isDisposed()) { - fViewer.setItemCount(count); - fViewer.getTable().clearAll(); - } - } + /** + * Set the givne count to the viewer. This will cause the viewer will + * refresh all items' data as well. + *

Note: This method must be called in the display thread.

+ * @param count New count to set to viewer. + */ + private void setCountToViewer(int count) { + if (!fViewer.getTable().isDisposed()) { + fViewer.setItemCount(count); + fViewer.getTable().clearAll(); + } + } - /** - * Retrieve the current value for given index. - */ - private void queryValue(final int index) { - // Create the request monitor to collect the value. This request - // monitor will be completed by the following transaction. - final ValueRequestMonitor rm = new ValueRequestMonitor(index) { - @Override - protected void handleCompleted() { - fItemDataRequestMonitors.remove(this); - if (isSuccess()) { - setValueToViewer(index, getData()); - } - } - @Override - protected void handleRejectedExecutionException() { - // Shutting down, ignore. - } - }; + /** + * Retrieve the current value for given index. + */ + private void queryValue(final int index) { + // Create the request monitor to collect the value. This request + // monitor will be completed by the following transaction. + final ValueRequestMonitor rm = new ValueRequestMonitor(index) { + @Override + protected void handleCompleted() { + fItemDataRequestMonitors.remove(this); + if (isSuccess()) { + setValueToViewer(index, getData()); + } + } - // Save the value request monitor, to cancel it if the view is - // scrolled. - fItemDataRequestMonitors.add(rm); + @Override + protected void handleRejectedExecutionException() { + // Shutting down, ignore. + } + }; - // Use a transaction, even with a single cache. This will ensure that - // if the cache is reset during processing by an event. The request - // for data will be re-issued. - fDataExecutor.execute(new Runnable() { - @Override + // Save the value request monitor, to cancel it if the view is + // scrolled. + fItemDataRequestMonitors.add(rm); + + // Use a transaction, even with a single cache. This will ensure that + // if the cache is reset during processing by an event. The request + // for data will be re-issued. + fDataExecutor.execute(new Runnable() { + @Override public void run() { - new Transaction() { - @Override - protected String process() - throws Transaction.InvalidCacheException, CoreException - { - return processValue(this, index); - } - }.request(rm); - } - }); - } + new Transaction() { + @Override + protected String process() throws Transaction.InvalidCacheException, CoreException { + return processValue(this, index); + } + }.request(rm); + } + }); + } - /** - * Write the view value to the viewer. - *

Note: This method must be called in the display thread.

- * @param index Index of value to set. - * @param value New value. - */ - private void setValueToViewer(int index, String value) { - if (!fViewer.getTable().isDisposed()) { - fViewer.replace(value, index); - } - } + /** + * Write the view value to the viewer. + *

Note: This method must be called in the display thread.

+ * @param index Index of value to set. + * @param value New value. + */ + private void setValueToViewer(int index, String value) { + if (!fViewer.getTable().isDisposed()) { + fViewer.replace(value, index); + } + } - /** - * Perform the calculation compose the string with data provider values - * and the sum. This implementation also validates the result. - * @param transaction The ACPM transaction to use for calculation. - * @param index Index of value to calculate. - * @return Calculated value. - * @throws Transaction.InvalidCacheException {@link Transaction#process} - * @throws CoreException See {@link Transaction#process} - */ - private String processValue(Transaction transaction, int index) - throws Transaction.InvalidCacheException, CoreException - { - List> valueCaches = - new ArrayList>(fDataGeneratorCMs.length); - for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { - valueCaches.add(dataGeneratorCM.getValue(index)); - } - // Validate all value caches at once. This executes needed requests - // in parallel. - transaction.validate(valueCaches); + /** + * Perform the calculation compose the string with data provider values + * and the sum. This implementation also validates the result. + * @param transaction The ACPM transaction to use for calculation. + * @param index Index of value to calculate. + * @return Calculated value. + * @throws Transaction.InvalidCacheException {@link Transaction#process} + * @throws CoreException See {@link Transaction#process} + */ + private String processValue(Transaction transaction, int index) + throws Transaction.InvalidCacheException, CoreException { + List> valueCaches = new ArrayList>(fDataGeneratorCMs.length); + for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) { + valueCaches.add(dataGeneratorCM.getValue(index)); + } + // Validate all value caches at once. This executes needed requests + // in parallel. + transaction.validate(valueCaches); - // TODO: evaluate sum generator cache in parallel with value caches. - ICache sumCache = fSumGeneratorCM.getValue(index); - transaction.validate(sumCache); + // TODO: evaluate sum generator cache in parallel with value caches. + ICache sumCache = fSumGeneratorCM.getValue(index); + transaction.validate(sumCache); - // Compose the string with values, sum, and validation result. - StringBuilder result = new StringBuilder(); - int calcSum = 0; - for (ICache valueCache : valueCaches) { - if (result.length() != 0) result.append(" + "); - result.append(valueCache.getData()); - calcSum += valueCache.getData(); - } - result.append(" = "); - result.append(sumCache.getData()); - if (calcSum != sumCache.getData()) { - result.append(" !INCORRECT! "); - } + // Compose the string with values, sum, and validation result. + StringBuilder result = new StringBuilder(); + int calcSum = 0; + for (ICache valueCache : valueCaches) { + if (result.length() != 0) + result.append(" + "); + result.append(valueCache.getData()); + calcSum += valueCache.getData(); + } + result.append(" = "); + result.append(sumCache.getData()); + if (calcSum != sumCache.getData()) { + result.append(" !INCORRECT! "); + } - return result.toString(); - } + return result.toString(); + } - /** - * Dedicated class for data item requests. This class holds the index - * argument so it can be examined when canceling stale requests. - */ - private class ValueRequestMonitor extends DataRequestMonitor { - /** Index is used when canceling stale requests. */ - int fIndex; + /** + * Dedicated class for data item requests. This class holds the index + * argument so it can be examined when canceling stale requests. + */ + private class ValueRequestMonitor extends DataRequestMonitor { + /** Index is used when canceling stale requests. */ + int fIndex; - ValueRequestMonitor(int index) { - super(fDisplayExecutor, null); - fIndex = index; - } + ValueRequestMonitor(int index) { + super(fDisplayExecutor, null); + fIndex = index; + } - @Override - protected void handleRejectedExecutionException() { - // Shutting down, ignore. - } - } + @Override + protected void handleRejectedExecutionException() { + // Shutting down, ignore. + } + } - /** - * Cancels any outstanding value requests for items which are no longer - * visible in the viewer. - * - * @param topIdx Index of top visible item in viewer. - * @param botIdx Index of bottom visible item in viewer. - */ - private void cancelStaleRequests(int topIdx, int botIdx) { - // Decrement the count of outstanding cancel calls. - fCancelCallsPending--; + /** + * Cancels any outstanding value requests for items which are no longer + * visible in the viewer. + * + * @param topIdx Index of top visible item in viewer. + * @param botIdx Index of bottom visible item in viewer. + */ + private void cancelStaleRequests(int topIdx, int botIdx) { + // Decrement the count of outstanding cancel calls. + fCancelCallsPending--; - // Must check again, in case disposed while re-dispatching. - if (fDataGeneratorCMs == null || fViewer.getTable().isDisposed()) { - return; - } + // Must check again, in case disposed while re-dispatching. + if (fDataGeneratorCMs == null || fViewer.getTable().isDisposed()) { + return; + } - // Go through the outstanding requests and cancel any that - // are not visible anymore. - for (Iterator itr = - fItemDataRequestMonitors.iterator(); itr.hasNext();) - { - ValueRequestMonitor item = itr.next(); - if (item.fIndex < topIdx || item.fIndex > botIdx) { - // Set the item to canceled status, so that the data provider - // will ignore it. - item.cancel(); + // Go through the outstanding requests and cancel any that + // are not visible anymore. + for (Iterator itr = fItemDataRequestMonitors.iterator(); itr.hasNext();) { + ValueRequestMonitor item = itr.next(); + if (item.fIndex < topIdx || item.fIndex > botIdx) { + // Set the item to canceled status, so that the data provider + // will ignore it. + item.cancel(); - // Add the item index to list of indexes that were canceled, - // which will be sent to the table widget. - fIndexesToCancel.add(item.fIndex); + // Add the item index to list of indexes that were canceled, + // which will be sent to the table widget. + fIndexesToCancel.add(item.fIndex); - // Remove the item from the outstanding cancel requests. - itr.remove(); - } - } - if (!fIndexesToCancel.isEmpty() && fCancelCallsPending == 0) { - Set canceledIdxs = fIndexesToCancel; - fIndexesToCancel = new HashSet(); + // Remove the item from the outstanding cancel requests. + itr.remove(); + } + } + if (!fIndexesToCancel.isEmpty() && fCancelCallsPending == 0) { + Set canceledIdxs = fIndexesToCancel; + fIndexesToCancel = new HashSet(); - // Clear the indexes of the canceled request, so that the - // viewer knows to request them again when needed. - // Note: clearing using TableViewer.clear(int) seems very - // inefficient, it's better to use Table.clear(int[]). - int[] canceledIdxsArray = new int[canceledIdxs.size()]; - int i = 0; - for (Integer index : canceledIdxs) { - canceledIdxsArray[i++] = index; - } - fViewer.getTable().clear(canceledIdxsArray); - } - } + // Clear the indexes of the canceled request, so that the + // viewer knows to request them again when needed. + // Note: clearing using TableViewer.clear(int) seems very + // inefficient, it's better to use Table.clear(int[]). + int[] canceledIdxsArray = new int[canceledIdxs.size()]; + int i = 0; + for (Integer index : canceledIdxs) { + canceledIdxsArray[i++] = index; + } + fViewer.getTable().clear(canceledIdxsArray); + } + } - /** - * The entry point for the example. - * @param args Program arguments. - */ - public static void main(String[] args) { - // Create the shell to hold the viewer. - Display display = new Display(); - Shell shell = new Shell(display, SWT.SHELL_TRIM); - shell.setLayout(new GridLayout()); - GridData data = new GridData(GridData.FILL_BOTH); - shell.setLayoutData(data); - Font font = new Font(display, "Courier", 10, SWT.NORMAL); + /** + * The entry point for the example. + * @param args Program arguments. + */ + public static void main(String[] args) { + // Create the shell to hold the viewer. + Display display = new Display(); + Shell shell = new Shell(display, SWT.SHELL_TRIM); + shell.setLayout(new GridLayout()); + GridData data = new GridData(GridData.FILL_BOTH); + shell.setLayoutData(data); + Font font = new Font(display, "Courier", 10, SWT.NORMAL); - // Create the table viewer. - TableViewer tableViewer = - new TableViewer(shell, SWT.BORDER | SWT.VIRTUAL); - tableViewer.getControl().setLayoutData(data); + // Create the table viewer. + TableViewer tableViewer = new TableViewer(shell, SWT.BORDER | SWT.VIRTUAL); + tableViewer.getControl().setLayoutData(data); - DsfExecutor executor = new DefaultDsfExecutor("Example executor"); + DsfExecutor executor = new DefaultDsfExecutor("Example executor"); - // Create the data generator. - final IDataGenerator[] generators = new IDataGenerator[5]; - for (int i = 0; i < generators.length; i++) { - generators[i] = new DataGeneratorWithExecutor(executor); - } - final IDataGenerator sumGenerator = - new ACPMSumDataGenerator(executor, generators); + // Create the data generator. + final IDataGenerator[] generators = new IDataGenerator[5]; + for (int i = 0; i < generators.length; i++) { + generators[i] = new DataGeneratorWithExecutor(executor); + } + final IDataGenerator sumGenerator = new ACPMSumDataGenerator(executor, generators); - // Create the content provider which will populate the viewer. - ACPMSumDataViewer contentProvider = new ACPMSumDataViewer( - tableViewer, new ImmediateInDsfExecutor(executor), - generators, sumGenerator); - tableViewer.setContentProvider(contentProvider); - tableViewer.setInput(new Object()); + // Create the content provider which will populate the viewer. + ACPMSumDataViewer contentProvider = new ACPMSumDataViewer(tableViewer, new ImmediateInDsfExecutor(executor), + generators, sumGenerator); + tableViewer.setContentProvider(contentProvider); + tableViewer.setInput(new Object()); - // Open the shell and service the display dispatch loop until user - // closes the shell. - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } + // Open the shell and service the display dispatch loop until user + // closes the shell. + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } - // The IDataGenerator.shutdown() method is asynchronous, this requires - // using a query again in order to wait for its completion. - Query shutdownQuery = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - CountingRequestMonitor crm = new CountingRequestMonitor( - ImmediateExecutor.getInstance(), rm); - for (int i = 0; i < generators.length; i++) { - generators[i].shutdown(crm); - } - sumGenerator.shutdown(crm); - crm.setDoneCount(generators.length); - } - }; + // The IDataGenerator.shutdown() method is asynchronous, this requires + // using a query again in order to wait for its completion. + Query shutdownQuery = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + CountingRequestMonitor crm = new CountingRequestMonitor(ImmediateExecutor.getInstance(), rm); + for (int i = 0; i < generators.length; i++) { + generators[i].shutdown(crm); + } + sumGenerator.shutdown(crm); + crm.setDoneCount(generators.length); + } + }; - executor.execute(shutdownQuery); - try { - shutdownQuery.get(); - } catch (Exception e) {} + executor.execute(shutdownQuery); + try { + shutdownQuery.get(); + } catch (Exception e) { + } - // Shut down the display. - font.dispose(); - display.dispose(); - } + // Shut down the display. + font.dispose(); + display.dispose(); + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncDataViewer.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncDataViewer.java index e95e78f2ba4..7d1b6b46eeb 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncDataViewer.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncDataViewer.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -57,255 +58,245 @@ import org.eclipse.swt.widgets.Table; *

*/ @ConfinedToDsfExecutor("fDisplayExecutor") -public class AsyncDataViewer - implements ILazyContentProvider, IDataGenerator.Listener -{ - // Executor to use instead of Display.asyncExec(). - @ThreadSafe - final private DsfExecutor fDisplayExecutor; +public class AsyncDataViewer implements ILazyContentProvider, IDataGenerator.Listener { + // Executor to use instead of Display.asyncExec(). + @ThreadSafe + final private DsfExecutor fDisplayExecutor; - // The viewer and generator that this content provider using. - final private TableViewer fViewer; - final private IDataGenerator fDataGenerator; + // The viewer and generator that this content provider using. + final private TableViewer fViewer; + final private IDataGenerator fDataGenerator; - // Fields used in request cancellation logic. - private List fItemDataRequestMonitors = - new LinkedList(); - private Set fIndexesToCancel = new HashSet(); - private int fCancelCallsPending = 0; + // Fields used in request cancellation logic. + private List fItemDataRequestMonitors = new LinkedList(); + private Set fIndexesToCancel = new HashSet(); + private int fCancelCallsPending = 0; - public AsyncDataViewer(TableViewer viewer, IDataGenerator generator) { - fViewer = viewer; - fDisplayExecutor = DisplayDsfExecutor.getDisplayDsfExecutor( - fViewer.getTable().getDisplay()); - fDataGenerator = generator; - fDataGenerator.addListener(this); - } + public AsyncDataViewer(TableViewer viewer, IDataGenerator generator) { + fViewer = viewer; + fDisplayExecutor = DisplayDsfExecutor.getDisplayDsfExecutor(fViewer.getTable().getDisplay()); + fDataGenerator = generator; + fDataGenerator.addListener(this); + } - @Override + @Override public void dispose() { - fDataGenerator.removeListener(this); - } + fDataGenerator.removeListener(this); + } - @Override + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // Set the initial count to the viewer after the input is set. - queryItemCount(); - } + // Set the initial count to the viewer after the input is set. + queryItemCount(); + } - @Override + @Override public void updateElement(final int index) { - // Calculate the visible index range. - final int topIdx = fViewer.getTable().getTopIndex(); - final int botIdx = topIdx + getVisibleItemCount(topIdx); + // Calculate the visible index range. + final int topIdx = fViewer.getTable().getTopIndex(); + final int botIdx = topIdx + getVisibleItemCount(topIdx); - // Request the item for the given index. - queryValue(index); + // Request the item for the given index. + queryValue(index); - // Invoke a cancel task with a delay. The delay allows multiple cancel - // calls to be combined together improving performance of the viewer. - fCancelCallsPending++; - fDisplayExecutor.schedule( - new Runnable() { @Override + // Invoke a cancel task with a delay. The delay allows multiple cancel + // calls to be combined together improving performance of the viewer. + fCancelCallsPending++; + fDisplayExecutor.schedule(new Runnable() { + @Override public void run() { - cancelStaleRequests(topIdx, botIdx); - }}, - 1, TimeUnit.MILLISECONDS); - } + cancelStaleRequests(topIdx, botIdx); + } + }, 1, TimeUnit.MILLISECONDS); + } - /** - * Calculates the number of visible items based on the top item index and - * table bounds. - * @param top Index of top item. - * @return calculated number of items in viewer - */ - private int getVisibleItemCount(int top) { - Table table = fViewer.getTable(); - int itemCount = table.getItemCount(); - return Math.min( - (table.getBounds().height / table.getItemHeight()) + 2, - itemCount - top); - } + /** + * Calculates the number of visible items based on the top item index and + * table bounds. + * @param top Index of top item. + * @return calculated number of items in viewer + */ + private int getVisibleItemCount(int top) { + Table table = fViewer.getTable(); + int itemCount = table.getItemCount(); + return Math.min((table.getBounds().height / table.getItemHeight()) + 2, itemCount - top); + } - @Override + @Override @ThreadSafe - public void countChanged() { - queryItemCount(); - } + public void countChanged() { + queryItemCount(); + } - @Override + @Override @ThreadSafe - public void valuesChanged(final Set indexes) { - // Mark the changed items in table viewer as dirty, this will - // trigger update requests for these indexes if they are - // visible in the viewer. - final TableViewer tableViewer = fViewer; - fDisplayExecutor.execute( new Runnable() { - @Override + public void valuesChanged(final Set indexes) { + // Mark the changed items in table viewer as dirty, this will + // trigger update requests for these indexes if they are + // visible in the viewer. + final TableViewer tableViewer = fViewer; + fDisplayExecutor.execute(new Runnable() { + @Override public void run() { - if (!fViewer.getTable().isDisposed()) { - for (Integer index : indexes) { - tableViewer.clear(index); - } - } - }}); - } + if (!fViewer.getTable().isDisposed()) { + for (Integer index : indexes) { + tableViewer.clear(index); + } + } + } + }); + } - /** - * Retrieve the up to date count. When a new count is set to viewer, the - * viewer will refresh all items as well. - */ - private void queryItemCount() { - // Request count from data provider. When the count is returned, we - // have to re-dispatch into the display thread to avoid calling - // the table widget on the DSF dispatch thread. - fIndexesToCancel.clear(); - fDataGenerator.getCount( - // Use the display executor to construct the request monitor, this - // will cause the handleCompleted() method to be automatically - // called on the display thread. - new DataRequestMonitor(fDisplayExecutor, null) { - @Override - protected void handleCompleted() { - if (!fViewer.getTable().isDisposed()) { - fViewer.setItemCount(getData()); - fViewer.getTable().clearAll(); - } - } - }); - } + /** + * Retrieve the up to date count. When a new count is set to viewer, the + * viewer will refresh all items as well. + */ + private void queryItemCount() { + // Request count from data provider. When the count is returned, we + // have to re-dispatch into the display thread to avoid calling + // the table widget on the DSF dispatch thread. + fIndexesToCancel.clear(); + fDataGenerator.getCount( + // Use the display executor to construct the request monitor, this + // will cause the handleCompleted() method to be automatically + // called on the display thread. + new DataRequestMonitor(fDisplayExecutor, null) { + @Override + protected void handleCompleted() { + if (!fViewer.getTable().isDisposed()) { + fViewer.setItemCount(getData()); + fViewer.getTable().clearAll(); + } + } + }); + } + /** + * Retrieves value of an element at given index. When complete the value + * is written to the viewer. + * @param index Index of value to retrieve. + */ + private void queryValue(final int index) { + ValueDataRequestMonitor rm = new ValueDataRequestMonitor(index); + fItemDataRequestMonitors.add(rm); + fDataGenerator.getValue(index, rm); + } - /** - * Retrieves value of an element at given index. When complete the value - * is written to the viewer. - * @param index Index of value to retrieve. - */ - private void queryValue(final int index) { - ValueDataRequestMonitor rm = new ValueDataRequestMonitor(index); - fItemDataRequestMonitors.add(rm); - fDataGenerator.getValue(index, rm); - } + /** + * Dedicated class for data item requests. This class holds the index + * argument so it can be examined when canceling stale requests. + */ + private class ValueDataRequestMonitor extends DataRequestMonitor { - /** - * Dedicated class for data item requests. This class holds the index - * argument so it can be examined when canceling stale requests. - */ - private class ValueDataRequestMonitor extends DataRequestMonitor { + /** Index is used when canceling stale requests. */ + int fIndex; - /** Index is used when canceling stale requests. */ - int fIndex; + ValueDataRequestMonitor(int index) { + super(fDisplayExecutor, null); + fIndex = index; + } - ValueDataRequestMonitor(int index) { - super(fDisplayExecutor, null); - fIndex = index; - } + @Override + protected void handleCompleted() { + fItemDataRequestMonitors.remove(this); - @Override - protected void handleCompleted() { - fItemDataRequestMonitors.remove(this); + // Check if the request completed successfully, otherwise ignore + // it. + if (isSuccess()) { + if (!fViewer.getTable().isDisposed()) { + fViewer.replace(getData(), fIndex); + } + } + } + } - // Check if the request completed successfully, otherwise ignore - // it. - if (isSuccess()) { - if (!fViewer.getTable().isDisposed()) { - fViewer.replace(getData(), fIndex); - } - } - } - } + private void cancelStaleRequests(int topIdx, int botIdx) { + // Decrement the count of outstanding cancel calls. + fCancelCallsPending--; - private void cancelStaleRequests(int topIdx, int botIdx) { - // Decrement the count of outstanding cancel calls. - fCancelCallsPending--; + // Must check again, in case disposed while re-dispatching. + if (fDataGenerator == null || fViewer.getTable().isDisposed()) + return; - // Must check again, in case disposed while re-dispatching. - if (fDataGenerator == null || fViewer.getTable().isDisposed()) return; + // Go through the outstanding requests and cancel any that + // are not visible anymore. + for (Iterator itr = fItemDataRequestMonitors.iterator(); itr.hasNext();) { + ValueDataRequestMonitor item = itr.next(); + if (item.fIndex < topIdx || item.fIndex > botIdx) { + // Set the item to canceled status, so that the data provider + // will ignore it. + item.cancel(); - // Go through the outstanding requests and cancel any that - // are not visible anymore. - for (Iterator itr = - fItemDataRequestMonitors.iterator(); - itr.hasNext();) - { - ValueDataRequestMonitor item = itr.next(); - if (item.fIndex < topIdx || item.fIndex > botIdx) { - // Set the item to canceled status, so that the data provider - // will ignore it. - item.cancel(); + // Add the item index to list of indexes that were canceled, + // which will be sent to the table widget. + fIndexesToCancel.add(item.fIndex); - // Add the item index to list of indexes that were canceled, - // which will be sent to the table widget. - fIndexesToCancel.add(item.fIndex); + // Remove the item from the outstanding cancel requests. + itr.remove(); + } + } + if (!fIndexesToCancel.isEmpty() && fCancelCallsPending == 0) { + Set canceledIdxs = fIndexesToCancel; + fIndexesToCancel = new HashSet(); - // Remove the item from the outstanding cancel requests. - itr.remove(); - } - } - if (!fIndexesToCancel.isEmpty() && fCancelCallsPending == 0) { - Set canceledIdxs = fIndexesToCancel; - fIndexesToCancel = new HashSet(); + // Clear the indexes of the canceled request, so that the + // viewer knows to request them again when needed. + // Note: clearing using TableViewer.clear(int) seems very + // inefficient, it's better to use Table.clear(int[]). + int[] canceledIdxsArray = new int[canceledIdxs.size()]; + int i = 0; + for (Integer index : canceledIdxs) { + canceledIdxsArray[i++] = index; + } + fViewer.getTable().clear(canceledIdxsArray); + } + } - // Clear the indexes of the canceled request, so that the - // viewer knows to request them again when needed. - // Note: clearing using TableViewer.clear(int) seems very - // inefficient, it's better to use Table.clear(int[]). - int[] canceledIdxsArray = new int[canceledIdxs.size()]; - int i = 0; - for (Integer index : canceledIdxs) { - canceledIdxsArray[i++] = index; - } - fViewer.getTable().clear(canceledIdxsArray); - } - } + public static void main(String[] args) { + // Create the shell to hold the viewer. + Display display = new Display(); + Shell shell = new Shell(display, SWT.SHELL_TRIM); + shell.setLayout(new GridLayout()); + GridData data = new GridData(GridData.FILL_BOTH); + shell.setLayoutData(data); + Font font = new Font(display, "Courier", 10, SWT.NORMAL); + // Create the table viewer. + TableViewer tableViewer = new TableViewer(shell, SWT.BORDER | SWT.VIRTUAL); + tableViewer.getControl().setLayoutData(data); - public static void main(String[] args) { - // Create the shell to hold the viewer. - Display display = new Display(); - Shell shell = new Shell(display, SWT.SHELL_TRIM); - shell.setLayout(new GridLayout()); - GridData data = new GridData(GridData.FILL_BOTH); - shell.setLayoutData(data); - Font font = new Font(display, "Courier", 10, SWT.NORMAL); + // Create the data generator. + final IDataGenerator generator = new DataGeneratorWithExecutor(); - // Create the table viewer. - TableViewer tableViewer = - new TableViewer(shell, SWT.BORDER | SWT.VIRTUAL); - tableViewer.getControl().setLayoutData(data); + // Create the content provider which will populate the viewer. + AsyncDataViewer contentProvider = new AsyncDataViewer(tableViewer, generator); + tableViewer.setContentProvider(contentProvider); + tableViewer.setInput(new Object()); - // Create the data generator. - final IDataGenerator generator = new DataGeneratorWithExecutor(); + // Open the shell and service the display dispatch loop until user + // closes the shell. + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } - // Create the content provider which will populate the viewer. - AsyncDataViewer contentProvider = - new AsyncDataViewer(tableViewer, generator); - tableViewer.setContentProvider(contentProvider); - tableViewer.setInput(new Object()); + // The IDataGenerator.shutdown() method is asynchronous, this requires + // using a query again in order to wait for its completion. + Query shutdownQuery = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + generator.shutdown(rm); + } + }; + ImmediateExecutor.getInstance().execute(shutdownQuery); + try { + shutdownQuery.get(); + } catch (Exception e) { + } - // Open the shell and service the display dispatch loop until user - // closes the shell. - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - - // The IDataGenerator.shutdown() method is asynchronous, this requires - // using a query again in order to wait for its completion. - Query shutdownQuery = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - generator.shutdown(rm); - } - }; - ImmediateExecutor.getInstance().execute(shutdownQuery); - try { - shutdownQuery.get(); - } catch (Exception e) {} - - // Shut down the display. - font.dispose(); - display.dispose(); - } + // Shut down the display. + font.dispose(); + display.dispose(); + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataGenerator.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataGenerator.java index 9f889c2399f..d86219b2299 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataGenerator.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataGenerator.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -38,144 +39,128 @@ import org.eclipse.cdt.dsf.concurrent.RequestMonitor; */ public class AsyncSumDataGenerator implements IDataGenerator { - /** - * DSF executor used to serialize data access within this data generator. - */ - final private DsfExecutor fExecutor; + /** + * DSF executor used to serialize data access within this data generator. + */ + final private DsfExecutor fExecutor; - /** - * Data generators to retrieve original data to perform calculations on. - */ - final private IDataGenerator[] fDataGenerators; + /** + * Data generators to retrieve original data to perform calculations on. + */ + final private IDataGenerator[] fDataGenerators; - public AsyncSumDataGenerator(DsfExecutor executor, - IDataGenerator[] generators) - { - fExecutor = executor; - fDataGenerators = generators; - } + public AsyncSumDataGenerator(DsfExecutor executor, IDataGenerator[] generators) { + fExecutor = executor; + fDataGenerators = generators; + } - @Override + @Override public void getCount(final DataRequestMonitor rm) { - // Artificially delay the retrieval of the sum data to simulate - // real processing time. - fExecutor.schedule( new Runnable() { - @Override - public void run() { - doGetCount(rm); - } - }, - PROCESSING_DELAY, TimeUnit.MILLISECONDS); - } + // Artificially delay the retrieval of the sum data to simulate + // real processing time. + fExecutor.schedule(new Runnable() { + @Override + public void run() { + doGetCount(rm); + } + }, PROCESSING_DELAY, TimeUnit.MILLISECONDS); + } - /** - * Performs the actual count retrieval and calculation. - * @param rm Request monitor to complete with data. - */ - private void doGetCount(final DataRequestMonitor rm) { - // Array to store counts retrieved asynchronously - final int[] counts = new int[fDataGenerators.length]; + /** + * Performs the actual count retrieval and calculation. + * @param rm Request monitor to complete with data. + */ + private void doGetCount(final DataRequestMonitor rm) { + // Array to store counts retrieved asynchronously + final int[] counts = new int[fDataGenerators.length]; - // Counting request monitor is called once all data is retrieved. - final CountingRequestMonitor crm = - new CountingRequestMonitor(fExecutor, rm) - { - @Override - protected void handleSuccess() { - // Pick the highest count value. - Arrays.sort(counts, 0, counts.length - 1); - int maxCount = counts[counts.length - 1]; - rm.setData(maxCount); - rm.done(); - }; - }; + // Counting request monitor is called once all data is retrieved. + final CountingRequestMonitor crm = new CountingRequestMonitor(fExecutor, rm) { + @Override + protected void handleSuccess() { + // Pick the highest count value. + Arrays.sort(counts, 0, counts.length - 1); + int maxCount = counts[counts.length - 1]; + rm.setData(maxCount); + rm.done(); + }; + }; - // Each call to data generator fills in one value in array. - for (int i = 0; i < fDataGenerators.length; i++) { - final int finalI = i; - fDataGenerators[i].getCount( - new DataRequestMonitor( - ImmediateExecutor.getInstance(), crm) - { - @Override - protected void handleSuccess() { - counts[finalI] = getData(); - crm.done(); - } - }); - } - crm.setDoneCount(fDataGenerators.length); - } + // Each call to data generator fills in one value in array. + for (int i = 0; i < fDataGenerators.length; i++) { + final int finalI = i; + fDataGenerators[i].getCount(new DataRequestMonitor(ImmediateExecutor.getInstance(), crm) { + @Override + protected void handleSuccess() { + counts[finalI] = getData(); + crm.done(); + } + }); + } + crm.setDoneCount(fDataGenerators.length); + } - @Override - public void getValue(final int index, final DataRequestMonitor rm) - { - // Artificially delay the retrieval of the sum data to simulate - // real processing time. - fExecutor.schedule( new Runnable() { - @Override - public void run() { - doGetValue(index, rm); - } - }, - PROCESSING_DELAY, TimeUnit.MILLISECONDS); - } + @Override + public void getValue(final int index, final DataRequestMonitor rm) { + // Artificially delay the retrieval of the sum data to simulate + // real processing time. + fExecutor.schedule(new Runnable() { + @Override + public void run() { + doGetValue(index, rm); + } + }, PROCESSING_DELAY, TimeUnit.MILLISECONDS); + } - /** - * Performs the actual value retrieval and calculation. - * @param rm Request monitor to complete with data. - */ - private void doGetValue(int index, final DataRequestMonitor rm) { - // Array to store counts retrieved asynchronously - final int[] values = new int[fDataGenerators.length]; + /** + * Performs the actual value retrieval and calculation. + * @param rm Request monitor to complete with data. + */ + private void doGetValue(int index, final DataRequestMonitor rm) { + // Array to store counts retrieved asynchronously + final int[] values = new int[fDataGenerators.length]; - // Counting request monitor is called once all data is retrieved. - final CountingRequestMonitor crm = - new CountingRequestMonitor(fExecutor, rm) - { - @Override - protected void handleSuccess() { - // Sum up values in array. - int sum = 0; - for (int value : values) { - sum += value; - } - rm.setData(sum); - rm.done(); - }; - }; + // Counting request monitor is called once all data is retrieved. + final CountingRequestMonitor crm = new CountingRequestMonitor(fExecutor, rm) { + @Override + protected void handleSuccess() { + // Sum up values in array. + int sum = 0; + for (int value : values) { + sum += value; + } + rm.setData(sum); + rm.done(); + }; + }; - // Each call to data generator fills in one value in array. - for (int i = 0; i < fDataGenerators.length; i++) { - final int finalI = i; - fDataGenerators[i].getValue( - index, - new DataRequestMonitor( - ImmediateExecutor.getInstance(), crm) - { - @Override - protected void handleSuccess() { - values[finalI] = getData(); - crm.done(); - } - }); - } - crm.setDoneCount(fDataGenerators.length); - } + // Each call to data generator fills in one value in array. + for (int i = 0; i < fDataGenerators.length; i++) { + final int finalI = i; + fDataGenerators[i].getValue(index, new DataRequestMonitor(ImmediateExecutor.getInstance(), crm) { + @Override + protected void handleSuccess() { + values[finalI] = getData(); + crm.done(); + } + }); + } + crm.setDoneCount(fDataGenerators.length); + } - @Override + @Override public void shutdown(RequestMonitor rm) { - rm.done(); - } + rm.done(); + } - @Override + @Override public void addListener(final Listener listener) { - // no events generated - } + // no events generated + } - @Override + @Override public void removeListener(Listener listener) { - // no events generated - } + // no events generated + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataViewer.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataViewer.java index 696b84a1e04..e8735bef270 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataViewer.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/AsyncSumDataViewer.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -65,354 +66,334 @@ import org.eclipse.swt.widgets.Table; *

*/ @ConfinedToDsfExecutor("fDisplayExecutor") -public class AsyncSumDataViewer implements ILazyContentProvider -{ - /** View update frequency interval. */ - final private static int UPDATE_INTERVAL = 10000; +public class AsyncSumDataViewer implements ILazyContentProvider { + /** View update frequency interval. */ + final private static int UPDATE_INTERVAL = 10000; - /** Executor to use instead of Display.asyncExec(). **/ - @ThreadSafe - final private DsfExecutor fDisplayExecutor; + /** Executor to use instead of Display.asyncExec(). **/ + @ThreadSafe + final private DsfExecutor fDisplayExecutor; - // The viewer and generator that this content provider using. - final private TableViewer fViewer; - final private IDataGenerator[] fDataGenerators; - final private IDataGenerator fSumGenerator; + // The viewer and generator that this content provider using. + final private TableViewer fViewer; + final private IDataGenerator[] fDataGenerators; + final private IDataGenerator fSumGenerator; - // Fields used in request cancellation logic. - private List fItemDataRequestMonitors = - new LinkedList(); - private Set fIndexesToCancel = new HashSet(); - private int fCancelCallsPending = 0; - private Future fRefreshFuture; + // Fields used in request cancellation logic. + private List fItemDataRequestMonitors = new LinkedList(); + private Set fIndexesToCancel = new HashSet(); + private int fCancelCallsPending = 0; + private Future fRefreshFuture; - public AsyncSumDataViewer(TableViewer viewer, - IDataGenerator[] generators, IDataGenerator sumGenerator) - { - fViewer = viewer; - fDisplayExecutor = DisplayDsfExecutor.getDisplayDsfExecutor( - fViewer.getTable().getDisplay()); - fDataGenerators = generators; - fSumGenerator = sumGenerator; + public AsyncSumDataViewer(TableViewer viewer, IDataGenerator[] generators, IDataGenerator sumGenerator) { + fViewer = viewer; + fDisplayExecutor = DisplayDsfExecutor.getDisplayDsfExecutor(fViewer.getTable().getDisplay()); + fDataGenerators = generators; + fSumGenerator = sumGenerator; - // Schedule a task to refresh the viewer periodically. - fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate( - new Runnable() { - @Override - public void run() { - queryItemCount(); - } - }, - UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS); - } - - @Override - public void dispose() { - // Cancel the periodic task of refreshing the view. - fRefreshFuture.cancel(false); - - // Cancel any outstanding data requests. - for (ValueCountingRequestMonitor rm : fItemDataRequestMonitors) { - rm.cancel(); - } - fItemDataRequestMonitors.clear(); - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // Set the initial count to the viewer after the input is set. - queryItemCount(); - } - - @Override - public void updateElement(final int index) { - // Calculate the visible index range. - final int topIdx = fViewer.getTable().getTopIndex(); - final int botIdx = topIdx + getVisibleItemCount(topIdx); - - // Request the item for the given index. - queryValue(index); - - // Invoke a cancel task with a delay. The delay allows multiple cancel - // calls to be combined together improving performance of the viewer. - fCancelCallsPending++; - fDisplayExecutor.execute( - new Runnable() { @Override + // Schedule a task to refresh the viewer periodically. + fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate(new Runnable() { + @Override public void run() { - cancelStaleRequests(topIdx, botIdx); - }}); - } + queryItemCount(); + } + }, UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS); + } - /** - * Calculates the number of visible items based on the top item index and - * table bounds. - * @param top Index of top item. - * @return calculated number of items in viewer - */ - private int getVisibleItemCount(int top) { - Table table = fViewer.getTable(); - int itemCount = table.getItemCount(); - return Math.min( - (table.getBounds().height / table.getItemHeight()) + 2, - itemCount - top); - } + @Override + public void dispose() { + // Cancel the periodic task of refreshing the view. + fRefreshFuture.cancel(false); - /** - * Retrieve the up to date count. - */ - private void queryItemCount() { - // Note:The count is retrieved from the sum generator only, the sum - // generator is responsible for calculating the count based on - // individual data providers' counts. - fIndexesToCancel.clear(); - fSumGenerator.getCount( - new DataRequestMonitor(fDisplayExecutor, null) { - @Override - protected void handleSuccess() { - setCountToViewer(getData()); - } - @Override - protected void handleRejectedExecutionException() { - // Shutting down, ignore. - } - }); - } + // Cancel any outstanding data requests. + for (ValueCountingRequestMonitor rm : fItemDataRequestMonitors) { + rm.cancel(); + } + fItemDataRequestMonitors.clear(); + } - /** - * Set the givne count to the viewer. This will cause the viewer will - * refresh all items' data as well. - * @param count New count to set to viewer. - */ - private void setCountToViewer(int count) { - if (!fViewer.getTable().isDisposed()) { - fViewer.setItemCount(count); - fViewer.getTable().clearAll(); - } - } + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // Set the initial count to the viewer after the input is set. + queryItemCount(); + } - /** - * Retrieves value of an element at given index. When complete the value - * is written to the viewer. - * @param index Index of value to retrieve. - */ - private void queryValue(final int index) { - // Values retrieved asynchronously from providers are stored in local - // arrays. - final int[] values = new int[fDataGenerators.length]; - final int[] sum = new int[1]; + @Override + public void updateElement(final int index) { + // Calculate the visible index range. + final int topIdx = fViewer.getTable().getTopIndex(); + final int botIdx = topIdx + getVisibleItemCount(topIdx); - // Counting request monitor is invoked when the required number of - // value requests is completed. - final ValueCountingRequestMonitor crm = - new ValueCountingRequestMonitor(index) - { - @Override - protected void handleCompleted() { - fItemDataRequestMonitors.remove(this); + // Request the item for the given index. + queryValue(index); - // Check if the request completed successfully, otherwise - // ignore it. - if (isSuccess()) { - StringBuilder result = new StringBuilder(); - int calcSum = 0; - for (int value : values) { - if (result.length() != 0) result.append(" + "); - result.append(value); - calcSum += value; - } - result.append(" = "); - result.append(sum[0]); - if (calcSum != sum[0]) { - result.append(" !INCORRECT! "); - } - setValueToViewer(fIndex, result.toString()); - } - }; - }; + // Invoke a cancel task with a delay. The delay allows multiple cancel + // calls to be combined together improving performance of the viewer. + fCancelCallsPending++; + fDisplayExecutor.execute(new Runnable() { + @Override + public void run() { + cancelStaleRequests(topIdx, botIdx); + } + }); + } - // Request data from each data generator. - for (int i = 0; i < fDataGenerators.length; i++) { - final int finalI = i; - fDataGenerators[i].getValue( - index, - // Use the display executor to construct the request monitor, - // this will cause the handleCompleted() method to be - // automatically called on the display thread. - new DataRequestMonitor( - ImmediateExecutor.getInstance(), crm) - { - @Override - protected void handleSuccess() { - values[finalI] = getData(); - crm.done(); - } - }); - } + /** + * Calculates the number of visible items based on the top item index and + * table bounds. + * @param top Index of top item. + * @return calculated number of items in viewer + */ + private int getVisibleItemCount(int top) { + Table table = fViewer.getTable(); + int itemCount = table.getItemCount(); + return Math.min((table.getBounds().height / table.getItemHeight()) + 2, itemCount - top); + } - // Separately request data from the sum data generator. - fSumGenerator.getValue( - index, - new DataRequestMonitor( - ImmediateExecutor.getInstance(), crm) - { - @Override - protected void handleSuccess() { - sum[0] = getData(); - crm.done(); - } - }); + /** + * Retrieve the up to date count. + */ + private void queryItemCount() { + // Note:The count is retrieved from the sum generator only, the sum + // generator is responsible for calculating the count based on + // individual data providers' counts. + fIndexesToCancel.clear(); + fSumGenerator.getCount(new DataRequestMonitor(fDisplayExecutor, null) { + @Override + protected void handleSuccess() { + setCountToViewer(getData()); + } - crm.setDoneCount(fDataGenerators.length + 1); - fItemDataRequestMonitors.add(crm); - } + @Override + protected void handleRejectedExecutionException() { + // Shutting down, ignore. + } + }); + } - /** - * Write the view value to the viewer. - *

Note: This method must be called in the display thread.

- * @param index Index of value to set. - * @param value New value. - */ - private void setValueToViewer(int index, String value) { - if (!fViewer.getTable().isDisposed()) { - fViewer.replace(value, index); - } - } + /** + * Set the givne count to the viewer. This will cause the viewer will + * refresh all items' data as well. + * @param count New count to set to viewer. + */ + private void setCountToViewer(int count) { + if (!fViewer.getTable().isDisposed()) { + fViewer.setItemCount(count); + fViewer.getTable().clearAll(); + } + } - /** - * Dedicated class for data item requests. This class holds the index - * argument so it can be examined when canceling stale requests. - */ - private class ValueCountingRequestMonitor extends CountingRequestMonitor { - /** Index is used when canceling stale requests. */ - int fIndex; + /** + * Retrieves value of an element at given index. When complete the value + * is written to the viewer. + * @param index Index of value to retrieve. + */ + private void queryValue(final int index) { + // Values retrieved asynchronously from providers are stored in local + // arrays. + final int[] values = new int[fDataGenerators.length]; + final int[] sum = new int[1]; - ValueCountingRequestMonitor(int index) { - super(fDisplayExecutor, null); - fIndex = index; - } + // Counting request monitor is invoked when the required number of + // value requests is completed. + final ValueCountingRequestMonitor crm = new ValueCountingRequestMonitor(index) { + @Override + protected void handleCompleted() { + fItemDataRequestMonitors.remove(this); - @Override - protected void handleRejectedExecutionException() { - // Shutting down, ignore. - } - } + // Check if the request completed successfully, otherwise + // ignore it. + if (isSuccess()) { + StringBuilder result = new StringBuilder(); + int calcSum = 0; + for (int value : values) { + if (result.length() != 0) + result.append(" + "); + result.append(value); + calcSum += value; + } + result.append(" = "); + result.append(sum[0]); + if (calcSum != sum[0]) { + result.append(" !INCORRECT! "); + } + setValueToViewer(fIndex, result.toString()); + } + }; + }; - /** - * Cancels any outstanding value requests for items which are no longer - * visible in the viewer. - * - * @param topIdx Index of top visible item in viewer. - * @param botIdx Index of bottom visible item in viewer. - */ - private void cancelStaleRequests(int topIdx, int botIdx) { - // Decrement the count of outstanding cancel calls. - fCancelCallsPending--; + // Request data from each data generator. + for (int i = 0; i < fDataGenerators.length; i++) { + final int finalI = i; + fDataGenerators[i].getValue(index, + // Use the display executor to construct the request monitor, + // this will cause the handleCompleted() method to be + // automatically called on the display thread. + new DataRequestMonitor(ImmediateExecutor.getInstance(), crm) { + @Override + protected void handleSuccess() { + values[finalI] = getData(); + crm.done(); + } + }); + } - // Must check again, in case disposed while re-dispatching. - if (fDataGenerators == null || fViewer.getTable().isDisposed()) return; + // Separately request data from the sum data generator. + fSumGenerator.getValue(index, new DataRequestMonitor(ImmediateExecutor.getInstance(), crm) { + @Override + protected void handleSuccess() { + sum[0] = getData(); + crm.done(); + } + }); - // Go through the outstanding requests and cancel any that - // are not visible anymore. - for (Iterator itr = - fItemDataRequestMonitors.iterator(); itr.hasNext();) - { - ValueCountingRequestMonitor item = itr.next(); - if (item.fIndex < topIdx || item.fIndex > botIdx) { - // Set the item to canceled status, so that the data provider - // will ignore it. - item.cancel(); + crm.setDoneCount(fDataGenerators.length + 1); + fItemDataRequestMonitors.add(crm); + } - // Add the item index to list of indexes that were canceled, - // which will be sent to the table widget. - fIndexesToCancel.add(item.fIndex); + /** + * Write the view value to the viewer. + *

Note: This method must be called in the display thread.

+ * @param index Index of value to set. + * @param value New value. + */ + private void setValueToViewer(int index, String value) { + if (!fViewer.getTable().isDisposed()) { + fViewer.replace(value, index); + } + } - // Remove the item from the outstanding cancel requests. - itr.remove(); - } - } - if (!fIndexesToCancel.isEmpty() && fCancelCallsPending == 0) { - Set canceledIdxs = fIndexesToCancel; - fIndexesToCancel = new HashSet(); + /** + * Dedicated class for data item requests. This class holds the index + * argument so it can be examined when canceling stale requests. + */ + private class ValueCountingRequestMonitor extends CountingRequestMonitor { + /** Index is used when canceling stale requests. */ + int fIndex; - // Clear the indexes of the canceled request, so that the - // viewer knows to request them again when needed. - // Note: clearing using TableViewer.clear(int) seems very - // inefficient, it's better to use Table.clear(int[]). - int[] canceledIdxsArray = new int[canceledIdxs.size()]; - int i = 0; - for (Integer index : canceledIdxs) { - canceledIdxsArray[i++] = index; - } - fViewer.getTable().clear(canceledIdxsArray); - } - } + ValueCountingRequestMonitor(int index) { + super(fDisplayExecutor, null); + fIndex = index; + } - /** - * The entry point for the example. - * @param args Program arguments. - */ - public static void main(String[] args) { - // Create the shell to hold the viewer. - Display display = new Display(); - Shell shell = new Shell(display, SWT.SHELL_TRIM); - shell.setLayout(new GridLayout()); - GridData data = new GridData(GridData.FILL_BOTH); - shell.setLayoutData(data); - Font font = new Font(display, "Courier", 10, SWT.NORMAL); + @Override + protected void handleRejectedExecutionException() { + // Shutting down, ignore. + } + } - // Create the table viewer. - TableViewer tableViewer = - new TableViewer(shell, SWT.BORDER | SWT.VIRTUAL); - tableViewer.getControl().setLayoutData(data); + /** + * Cancels any outstanding value requests for items which are no longer + * visible in the viewer. + * + * @param topIdx Index of top visible item in viewer. + * @param botIdx Index of bottom visible item in viewer. + */ + private void cancelStaleRequests(int topIdx, int botIdx) { + // Decrement the count of outstanding cancel calls. + fCancelCallsPending--; - // Single executor (and single thread) is used by all data generators, - // including the sum generator. - DsfExecutor executor = new DefaultDsfExecutor("Example executor"); + // Must check again, in case disposed while re-dispatching. + if (fDataGenerators == null || fViewer.getTable().isDisposed()) + return; - // Create the data generator. - final IDataGenerator[] generators = new IDataGenerator[5]; - for (int i = 0; i < generators.length; i++) { - generators[i] = new DataGeneratorWithExecutor(executor); - } - final IDataGenerator sumGenerator = - new AsyncSumDataGenerator(executor, generators); + // Go through the outstanding requests and cancel any that + // are not visible anymore. + for (Iterator itr = fItemDataRequestMonitors.iterator(); itr.hasNext();) { + ValueCountingRequestMonitor item = itr.next(); + if (item.fIndex < topIdx || item.fIndex > botIdx) { + // Set the item to canceled status, so that the data provider + // will ignore it. + item.cancel(); - // Create the content provider which will populate the viewer. - AsyncSumDataViewer contentProvider = - new AsyncSumDataViewer(tableViewer, generators, sumGenerator); - tableViewer.setContentProvider(contentProvider); - tableViewer.setInput(new Object()); + // Add the item index to list of indexes that were canceled, + // which will be sent to the table widget. + fIndexesToCancel.add(item.fIndex); - // Open the shell and service the display dispatch loop until user - // closes the shell. - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } + // Remove the item from the outstanding cancel requests. + itr.remove(); + } + } + if (!fIndexesToCancel.isEmpty() && fCancelCallsPending == 0) { + Set canceledIdxs = fIndexesToCancel; + fIndexesToCancel = new HashSet(); - // The IDataGenerator.shutdown() method is asynchronous, this requires - // using a query again in order to wait for its completion. - Query shutdownQuery = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - CountingRequestMonitor crm = new CountingRequestMonitor( - ImmediateExecutor.getInstance(), rm); - for (int i = 0; i < generators.length; i++) { - generators[i].shutdown(crm); - } - sumGenerator.shutdown(crm); - crm.setDoneCount(generators.length); - } - }; + // Clear the indexes of the canceled request, so that the + // viewer knows to request them again when needed. + // Note: clearing using TableViewer.clear(int) seems very + // inefficient, it's better to use Table.clear(int[]). + int[] canceledIdxsArray = new int[canceledIdxs.size()]; + int i = 0; + for (Integer index : canceledIdxs) { + canceledIdxsArray[i++] = index; + } + fViewer.getTable().clear(canceledIdxsArray); + } + } - executor.execute(shutdownQuery); - try { - shutdownQuery.get(); - } catch (Exception e) {} + /** + * The entry point for the example. + * @param args Program arguments. + */ + public static void main(String[] args) { + // Create the shell to hold the viewer. + Display display = new Display(); + Shell shell = new Shell(display, SWT.SHELL_TRIM); + shell.setLayout(new GridLayout()); + GridData data = new GridData(GridData.FILL_BOTH); + shell.setLayoutData(data); + Font font = new Font(display, "Courier", 10, SWT.NORMAL); - // Shut down the display. - font.dispose(); - display.dispose(); - } + // Create the table viewer. + TableViewer tableViewer = new TableViewer(shell, SWT.BORDER | SWT.VIRTUAL); + tableViewer.getControl().setLayoutData(data); + + // Single executor (and single thread) is used by all data generators, + // including the sum generator. + DsfExecutor executor = new DefaultDsfExecutor("Example executor"); + + // Create the data generator. + final IDataGenerator[] generators = new IDataGenerator[5]; + for (int i = 0; i < generators.length; i++) { + generators[i] = new DataGeneratorWithExecutor(executor); + } + final IDataGenerator sumGenerator = new AsyncSumDataGenerator(executor, generators); + + // Create the content provider which will populate the viewer. + AsyncSumDataViewer contentProvider = new AsyncSumDataViewer(tableViewer, generators, sumGenerator); + tableViewer.setContentProvider(contentProvider); + tableViewer.setInput(new Object()); + + // Open the shell and service the display dispatch loop until user + // closes the shell. + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + + // The IDataGenerator.shutdown() method is asynchronous, this requires + // using a query again in order to wait for its completion. + Query shutdownQuery = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + CountingRequestMonitor crm = new CountingRequestMonitor(ImmediateExecutor.getInstance(), rm); + for (int i = 0; i < generators.length; i++) { + generators[i].shutdown(crm); + } + sumGenerator.shutdown(crm); + crm.setDoneCount(generators.length); + } + }; + + executor.execute(shutdownQuery); + try { + shutdownQuery.get(); + } catch (Exception e) { + } + + // Shut down the display. + font.dispose(); + display.dispose(); + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorCacheManager.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorCacheManager.java index ad6f167be2e..39012a26749 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorCacheManager.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorCacheManager.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -36,135 +37,135 @@ import org.eclipse.core.runtime.Status; */ public class DataGeneratorCacheManager implements IDataGenerator.Listener { - /** Cache class for retrieving the data generator's count. */ - private class CountCache extends RequestCache { + /** Cache class for retrieving the data generator's count. */ + private class CountCache extends RequestCache { - public CountCache() { - super(fExecutor); - } + public CountCache() { + super(fExecutor); + } - @Override - protected void retrieve(DataRequestMonitor rm) { - fDataGenerator.getCount(rm); - } + @Override + protected void retrieve(DataRequestMonitor rm) { + fDataGenerator.getCount(rm); + } - /** - * Reset the cache when the count is changed. - */ - public void countChanged() { - // Make sure that if clients are currently waiting for a count, - // they are notified of the update (their request monitors will be - // completed with an error). They shoudl then re-request data - // from provider again. - setAndReset(null, new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Count changed")); - } - } + /** + * Reset the cache when the count is changed. + */ + public void countChanged() { + // Make sure that if clients are currently waiting for a count, + // they are notified of the update (their request monitors will be + // completed with an error). They shoudl then re-request data + // from provider again. + setAndReset(null, new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Count changed")); + } + } - /** Cache class for retrieving the data generator's values. */ - private class ValueCache extends RequestCache { - private int fIndex; + /** Cache class for retrieving the data generator's values. */ + private class ValueCache extends RequestCache { + private int fIndex; - public ValueCache(int index) { - super(fExecutor); - fIndex = index; - } + public ValueCache(int index) { + super(fExecutor); + fIndex = index; + } - @Override - protected void retrieve(org.eclipse.cdt.dsf.concurrent.DataRequestMonitor rm) { - fDataGenerator.getValue(fIndex, rm); - }; + @Override + protected void retrieve(org.eclipse.cdt.dsf.concurrent.DataRequestMonitor rm) { + fDataGenerator.getValue(fIndex, rm); + }; - /** - * @see CountCache#countChanged() - */ - public void valueChanged() { - setAndReset(null, new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Value changed")); - } - } + /** + * @see CountCache#countChanged() + */ + public void valueChanged() { + setAndReset(null, new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Value changed")); + } + } - /** - * Executor used to synchronize data access in this cache manager. - * It has to be the same executor that is used by the data generators in - * order to guarantee data consistency. - */ - private ImmediateInDsfExecutor fExecutor; + /** + * Executor used to synchronize data access in this cache manager. + * It has to be the same executor that is used by the data generators in + * order to guarantee data consistency. + */ + private ImmediateInDsfExecutor fExecutor; - /** - * Data generator that this cache manager is a wrapper for. - */ - private IDataGenerator fDataGenerator; + /** + * Data generator that this cache manager is a wrapper for. + */ + private IDataGenerator fDataGenerator; - /** Cache for data generator's count */ - private CountCache fCountCache; + /** Cache for data generator's count */ + private CountCache fCountCache; - /** - * Map of caches for retrieving values. Each value index has a separate - * cache value object. - */ - private Map fValueCaches = new HashMap(); + /** + * Map of caches for retrieving values. Each value index has a separate + * cache value object. + */ + private Map fValueCaches = new HashMap(); - public DataGeneratorCacheManager(ImmediateInDsfExecutor executor, IDataGenerator dataGenerator) { - fExecutor = executor; - fDataGenerator = dataGenerator; - fDataGenerator.addListener(this); - } + public DataGeneratorCacheManager(ImmediateInDsfExecutor executor, IDataGenerator dataGenerator) { + fExecutor = executor; + fDataGenerator = dataGenerator; + fDataGenerator.addListener(this); + } - public void dispose() { - fDataGenerator.removeListener(this); - } + public void dispose() { + fDataGenerator.removeListener(this); + } - /** - * Returns the data generator that this cache manager wraps. - */ - public IDataGenerator getDataGenerator() { - return fDataGenerator; - } + /** + * Returns the data generator that this cache manager wraps. + */ + public IDataGenerator getDataGenerator() { + return fDataGenerator; + } - /** - * Returns the cache for data generator count. - */ - public ICache getCount() { - if (fCountCache == null) { - fCountCache = new CountCache(); - } - return fCountCache; - } + /** + * Returns the cache for data generator count. + */ + public ICache getCount() { + if (fCountCache == null) { + fCountCache = new CountCache(); + } + return fCountCache; + } - /** - * Returns the cache for a value at given index. - * - * @param index Index of value to return. - * @return Cache object for given value. - */ - public ICache getValue(int index) { - ValueCache value = fValueCaches.get(index); - if (value == null) { - value = new ValueCache(index); - fValueCaches.put(index, value); - } + /** + * Returns the cache for a value at given index. + * + * @param index Index of value to return. + * @return Cache object for given value. + */ + public ICache getValue(int index) { + ValueCache value = fValueCaches.get(index); + if (value == null) { + value = new ValueCache(index); + fValueCaches.put(index, value); + } - return value; - } + return value; + } - @Override + @Override public void countChanged() { - // Reset the count cache and all the value caches. - if (fCountCache != null) { - fCountCache.countChanged(); - } - for (ValueCache value : fValueCaches.values()) { - value.valueChanged(); - } - } + // Reset the count cache and all the value caches. + if (fCountCache != null) { + fCountCache.countChanged(); + } + for (ValueCache value : fValueCaches.values()) { + value.valueChanged(); + } + } - @Override + @Override public void valuesChanged(Set indexes) { - // Reset selected value caches. - for (Integer index : indexes) { - ValueCache value = fValueCaches.get(index); - if (value != null) { - value.valueChanged(); - } - } - } + // Reset selected value caches. + for (Integer index : indexes) { + ValueCache value = fValueCaches.get(index); + if (value != null) { + value.valueChanged(); + } + } + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithExecutor.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithExecutor.java index 9b00cea4f9e..52260b43304 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithExecutor.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithExecutor.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -60,409 +61,399 @@ import org.eclipse.cdt.examples.dsf.DsfExamplesPlugin; //#endif public class DataGeneratorWithExecutor implements IDataGenerator { - // Request objects are used to serialize the interface calls into objects - // which can then be pushed into a queue. - //#ifdef exercises - // TODO Exercise 4 - Add an annotationindicating allowed concurrency access - // Hint: Request and its subclasses have all their fields declared as final. - //#else -//# @Immutable - //#endif - abstract class Request { - final RequestMonitor fRequestMonitor; + // Request objects are used to serialize the interface calls into objects + // which can then be pushed into a queue. + //#ifdef exercises + // TODO Exercise 4 - Add an annotationindicating allowed concurrency access + // Hint: Request and its subclasses have all their fields declared as final. + //#else + //# @Immutable + //#endif + abstract class Request { + final RequestMonitor fRequestMonitor; - Request(RequestMonitor rm) { - fRequestMonitor = rm; + Request(RequestMonitor rm) { + fRequestMonitor = rm; - rm.addCancelListener(new RequestMonitor.ICanceledListener() { - @Override + rm.addCancelListener(new RequestMonitor.ICanceledListener() { + @Override public void requestCanceled(RequestMonitor rm) { - fExecutor.execute(new DsfRunnable() { - @Override + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fQueue.remove(Request.this); - } - }); - } - }); - } - } + fQueue.remove(Request.this); + } + }); + } + }); + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @Immutable - //#endif - class CountRequest extends Request { - CountRequest(DataRequestMonitor rm) { - super(rm); - } - } + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @Immutable + //#endif + class CountRequest extends Request { + CountRequest(DataRequestMonitor rm) { + super(rm); + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @Immutable - //#endif - class ItemRequest extends Request { - final int fIndex; - ItemRequest(int index, DataRequestMonitor rm) { - super(rm); - fIndex = index; - } - } + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @Immutable + //#endif + class ItemRequest extends Request { + final int fIndex; - // The executor used to access all internal data of the generator. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - // Hint: If a member does not have an annotation, the programmer can assume - // that the concurrency rule that applies to the class also applies to this - // member. - //#endif - private DsfExecutor fExecutor; + ItemRequest(int index, DataRequestMonitor rm) { + super(rm); + fIndex = index; + } + } - // Main request queue of the data generator. The getValue(), getCount(), - // and shutdown() methods write into the queue, while the serviceQueue() - // method reads from it. - // The executor used to access all internal data of the generator. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private List fQueue = new LinkedList(); + // The executor used to access all internal data of the generator. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + // Hint: If a member does not have an annotation, the programmer can assume + // that the concurrency rule that applies to the class also applies to this + // member. + //#endif + private DsfExecutor fExecutor; - // List of listeners is not synchronized, it also has to be accessed - // using the executor. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private List fListeners = new LinkedList(); + // Main request queue of the data generator. The getValue(), getCount(), + // and shutdown() methods write into the queue, while the serviceQueue() + // method reads from it. + // The executor used to access all internal data of the generator. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private List fQueue = new LinkedList(); - // Current number of elements in this generator. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private int fCount = MIN_COUNT; + // List of listeners is not synchronized, it also has to be accessed + // using the executor. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private List fListeners = new LinkedList(); - // Counter used to determine when to reset the element count. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private int fCountResetTrigger = 0; + // Current number of elements in this generator. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private int fCount = MIN_COUNT; - // Elements which were modified since the last reset. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private Map fChangedValues = - new HashMap(); + // Counter used to determine when to reset the element count. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private int fCountResetTrigger = 0; - public DataGeneratorWithExecutor() { - // Create the executor - this(new DefaultDsfExecutor("Supplier Executor")); - } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#endif - public DataGeneratorWithExecutor(DsfExecutor executor) { - // Create the executor - fExecutor = executor; - final Random rand = new Random(); - // Schedule a runnable to make the random changes. - fExecutor.scheduleAtFixedRate( - new DsfRunnable() { - @Override - public void run() { - randomChanges(); - } - }, - rand.nextInt(RANDOM_CHANGE_INTERVAL), - RANDOM_CHANGE_INTERVAL, //Add a 10% variance to the interval. - TimeUnit.MILLISECONDS); - } + // Elements which were modified since the last reset. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private Map fChangedValues = new HashMap(); - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#endif - @Override + public DataGeneratorWithExecutor() { + // Create the executor + this(new DefaultDsfExecutor("Supplier Executor")); + } + + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#endif + public DataGeneratorWithExecutor(DsfExecutor executor) { + // Create the executor + fExecutor = executor; + final Random rand = new Random(); + // Schedule a runnable to make the random changes. + fExecutor.scheduleAtFixedRate(new DsfRunnable() { + @Override + public void run() { + randomChanges(); + } + }, rand.nextInt(RANDOM_CHANGE_INTERVAL), RANDOM_CHANGE_INTERVAL, //Add a 10% variance to the interval. + TimeUnit.MILLISECONDS); + } + + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#endif + @Override public void shutdown(final RequestMonitor rm) { - try { - fExecutor.execute( new DsfRunnable() { - @Override + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - // Empty the queue of requests and fail them. - for (Request request : fQueue) { - request.fRequestMonitor.setStatus(new Status( - IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - request.fRequestMonitor.done(); - } - fQueue.clear(); + // Empty the queue of requests and fail them. + for (Request request : fQueue) { + request.fRequestMonitor.setStatus( + new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + request.fRequestMonitor.done(); + } + fQueue.clear(); - // Kill executor. - fExecutor.shutdown(); - rm.done(); - } - }); - } catch (RejectedExecutionException e) { - rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - rm.done(); - } - } + // Kill executor. + fExecutor.shutdown(); + rm.done(); + } + }); + } catch (RejectedExecutionException e) { + rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + rm.done(); + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#endif - @Override + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#endif + @Override public void getCount(final DataRequestMonitor rm) { - try { - fExecutor.execute( new DsfRunnable() { - @Override + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fQueue.add(new CountRequest(rm)); - serviceQueue(); - } - }); - } catch (RejectedExecutionException e) { - rm.setStatus(new Status( - IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - rm.done(); - } - } + fQueue.add(new CountRequest(rm)); + serviceQueue(); + } + }); + } catch (RejectedExecutionException e) { + rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + rm.done(); + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#endif - @Override + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#endif + @Override public void getValue(final int index, final DataRequestMonitor rm) { - try { - fExecutor.execute( new DsfRunnable() { - @Override + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fQueue.add(new ItemRequest(index, rm)); - serviceQueue(); - } - }); - } catch (RejectedExecutionException e) { - rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - rm.done(); - } - } + fQueue.add(new ItemRequest(index, rm)); + serviceQueue(); + } + }); + } catch (RejectedExecutionException e) { + rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + rm.done(); + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#endif - @Override + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#endif + @Override public void addListener(final Listener listener) { - try { - fExecutor.execute( new DsfRunnable() { - @Override + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fListeners.add(listener); - } - }); - } catch (RejectedExecutionException e) {} - } + fListeners.add(listener); + } + }); + } catch (RejectedExecutionException e) { + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#endif - @Override + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#endif + @Override public void removeListener(final Listener listener) { - try { - fExecutor.execute( new DsfRunnable() { - @Override + try { + fExecutor.execute(new DsfRunnable() { + @Override public void run() { - fListeners.remove(listener); - } - }); - } catch (RejectedExecutionException e) {} - } + fListeners.remove(listener); + } + }); + } catch (RejectedExecutionException e) { + } + } - // Main processing function of this generator. - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void serviceQueue() { - fExecutor.schedule( - new DsfRunnable() { - @Override - public void run() { - doServiceQueue(); - } - }, - PROCESSING_DELAY, TimeUnit.MILLISECONDS); - } + // Main processing function of this generator. + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void serviceQueue() { + fExecutor.schedule(new DsfRunnable() { + @Override + public void run() { + doServiceQueue(); + } + }, PROCESSING_DELAY, TimeUnit.MILLISECONDS); + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void doServiceQueue() { - //#ifdef exercises - // TODO Exercise 3 - Add logic to discard cancelled requests from queue. - // Hint: Since serviceQueue() is called using the executor, and the - // fQueue list can only be modified when running in the executor - // thread. This method can safely iterate and modify fQueue without - // risk of race conditions or concurrent modification exceptions. - //#else -//# for (Iterator requestItr = fQueue.iterator(); requestItr.hasNext();) { -//# Request request = requestItr.next(); -//# if (request.fRequestMonitor.isCanceled()) { -//# request.fRequestMonitor.setStatus( -//# new Status(IStatus.CANCEL, DsfExamplesPlugin.PLUGIN_ID, "Request canceled")); -//# request.fRequestMonitor.done(); -//# requestItr.remove(); -//# } -//# } - //#endif + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void doServiceQueue() { + //#ifdef exercises + // TODO Exercise 3 - Add logic to discard cancelled requests from queue. + // Hint: Since serviceQueue() is called using the executor, and the + // fQueue list can only be modified when running in the executor + // thread. This method can safely iterate and modify fQueue without + // risk of race conditions or concurrent modification exceptions. + //#else + //# for (Iterator requestItr = fQueue.iterator(); requestItr.hasNext();) { + //# Request request = requestItr.next(); + //# if (request.fRequestMonitor.isCanceled()) { + //# request.fRequestMonitor.setStatus( + //# new Status(IStatus.CANCEL, DsfExamplesPlugin.PLUGIN_ID, "Request canceled")); + //# request.fRequestMonitor.done(); + //# requestItr.remove(); + //# } + //# } + //#endif - while (fQueue.size() != 0) { - // If there are requests to service, remove one from the queue and - // schedule a runnable to process the request after a processing - // delay. - Request request = fQueue.remove(0); - if (request instanceof CountRequest) { - processCountRequest((CountRequest)request); - } else if (request instanceof ItemRequest) { - processItemRequest((ItemRequest)request); - } - } - } + while (fQueue.size() != 0) { + // If there are requests to service, remove one from the queue and + // schedule a runnable to process the request after a processing + // delay. + Request request = fQueue.remove(0); + if (request instanceof CountRequest) { + processCountRequest((CountRequest) request); + } else if (request instanceof ItemRequest) { + processItemRequest((ItemRequest) request); + } + } + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void processCountRequest(CountRequest request) { - @SuppressWarnings("unchecked") // Suppress warning about lost type info. - DataRequestMonitor rm = - (DataRequestMonitor)request.fRequestMonitor; + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void processCountRequest(CountRequest request) { + @SuppressWarnings("unchecked") // Suppress warning about lost type info. + DataRequestMonitor rm = (DataRequestMonitor) request.fRequestMonitor; - rm.setData(fCount); - rm.done(); - } + rm.setData(fCount); + rm.done(); + } - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void processItemRequest(ItemRequest request) { - @SuppressWarnings("unchecked") // Suppress warning about lost type info. - DataRequestMonitor rm = - (DataRequestMonitor)request.fRequestMonitor; + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void processItemRequest(ItemRequest request) { + @SuppressWarnings("unchecked") // Suppress warning about lost type info. + DataRequestMonitor rm = (DataRequestMonitor) request.fRequestMonitor; - if (fChangedValues.containsKey(request.fIndex)) { - rm.setData(fChangedValues.get(request.fIndex)); - } else { - rm.setData(request.fIndex); - } - rm.done(); - } + if (fChangedValues.containsKey(request.fIndex)) { + rm.setData(fChangedValues.get(request.fIndex)); + } else { + rm.setData(request.fIndex); + } + rm.done(); + } - /** - * This method simulates changes in the supplier's data set. - */ - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void randomChanges() { - // Once every number of changes, reset the count, the rest of the - // times just change certain values. - if (++fCountResetTrigger % RANDOM_COUNT_CHANGE_INTERVALS == 0){ - randomCountReset(); - } else { - randomDataChange(); - } - } + /** + * This method simulates changes in the supplier's data set. + */ + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void randomChanges() { + // Once every number of changes, reset the count, the rest of the + // times just change certain values. + if (++fCountResetTrigger % RANDOM_COUNT_CHANGE_INTERVALS == 0) { + randomCountReset(); + } else { + randomDataChange(); + } + } - /** - * Calculates new size for provider's data set. - */ - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void randomCountReset() { - // Calculate the new count. - Random random = new java.util.Random(); - fCount = MIN_COUNT + random.nextInt(MAX_COUNT - MIN_COUNT); + /** + * Calculates new size for provider's data set. + */ + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void randomCountReset() { + // Calculate the new count. + Random random = new java.util.Random(); + fCount = MIN_COUNT + random.nextInt(MAX_COUNT - MIN_COUNT); - // Reset the changed values. - fChangedValues.clear(); + // Reset the changed values. + fChangedValues.clear(); - // Notify listeners - for (Listener listener : fListeners) { - listener.countChanged(); - } - } + // Notify listeners + for (Listener listener : fListeners) { + listener.countChanged(); + } + } - /** - * Invalidates a random range of indexes. - */ - //#ifdef exercises - // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) - // indicating allowed thread access to this class/method/member - //#else -//# @ConfinedToDsfExecutor("fExecutor") - //#endif - private void randomDataChange() { - // Calculate the indexes to change. - Random random = new java.util.Random(); - Map changed = new HashMap(); - for (int i = 0; i < fCount * RANDOM_CHANGE_SET_PERCENTAGE / 100; i++) { - int randomIndex = random.nextInt(fCount); - int randomValue = random.nextInt(fCount); - changed.put(randomIndex, randomValue); - } + /** + * Invalidates a random range of indexes. + */ + //#ifdef exercises + // TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor) + // indicating allowed thread access to this class/method/member + //#else + //# @ConfinedToDsfExecutor("fExecutor") + //#endif + private void randomDataChange() { + // Calculate the indexes to change. + Random random = new java.util.Random(); + Map changed = new HashMap(); + for (int i = 0; i < fCount * RANDOM_CHANGE_SET_PERCENTAGE / 100; i++) { + int randomIndex = random.nextInt(fCount); + int randomValue = random.nextInt(fCount); + changed.put(randomIndex, randomValue); + } - // Add the indexes to an overall set of changed indexes. - fChangedValues.putAll(changed); + // Add the indexes to an overall set of changed indexes. + fChangedValues.putAll(changed); - // Notify listeners - for (Object listener : fListeners) { - ((Listener)listener).valuesChanged(changed.keySet()); - } - } + // Notify listeners + for (Object listener : fListeners) { + ((Listener) listener).valuesChanged(changed.keySet()); + } + } } - diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithThread.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithThread.java index 6eae7503ef8..b5e3fb40f7b 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithThread.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/DataGeneratorWithThread.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -44,221 +45,208 @@ import org.eclipse.cdt.examples.dsf.DsfExamplesPlugin; * synchronization. *

*/ -public class DataGeneratorWithThread extends Thread - implements IDataGenerator -{ +public class DataGeneratorWithThread extends Thread implements IDataGenerator { - // Request objects are used to serialize the interface calls into objects - // which can then be pushed into a queue. - abstract class Request { - final RequestMonitor fRequestMonitor; + // Request objects are used to serialize the interface calls into objects + // which can then be pushed into a queue. + abstract class Request { + final RequestMonitor fRequestMonitor; - Request(RequestMonitor rm) { - fRequestMonitor = rm; - } - } + Request(RequestMonitor rm) { + fRequestMonitor = rm; + } + } - class CountRequest extends Request { - CountRequest(DataRequestMonitor rm) { - super(rm); - } - } + class CountRequest extends Request { + CountRequest(DataRequestMonitor rm) { + super(rm); + } + } - class ItemRequest extends Request { - final int fIndex; - ItemRequest(int index, DataRequestMonitor rm) { - super(rm); - fIndex = index; - } - } + class ItemRequest extends Request { + final int fIndex; - class ShutdownRequest extends Request { - ShutdownRequest(RequestMonitor rm) { - super(rm); - } - } + ItemRequest(int index, DataRequestMonitor rm) { + super(rm); + fIndex = index; + } + } - // Main request queue of the data generator. The getValue(), getCount(), - // and shutdown() methods write into the queue, while the run() method - // reads from it. - private final BlockingQueue fQueue = - new LinkedBlockingQueue(); + class ShutdownRequest extends Request { + ShutdownRequest(RequestMonitor rm) { + super(rm); + } + } - // ListenerList class provides thread safety. - private ListenerList fListeners = new ListenerList<>(); + // Main request queue of the data generator. The getValue(), getCount(), + // and shutdown() methods write into the queue, while the run() method + // reads from it. + private final BlockingQueue fQueue = new LinkedBlockingQueue(); - // Current number of elements in this generator. - private int fCount = MIN_COUNT; + // ListenerList class provides thread safety. + private ListenerList fListeners = new ListenerList<>(); - // Counter used to determine when to reset the element count. - private int fCountResetTrigger = 0; + // Current number of elements in this generator. + private int fCount = MIN_COUNT; - // Elements which were modified since the last reset. - private Map fChangedValues = - Collections.synchronizedMap(new HashMap()); + // Counter used to determine when to reset the element count. + private int fCountResetTrigger = 0; - // Used to determine when to make changes in data. - private long fLastChangeTime = System.currentTimeMillis(); + // Elements which were modified since the last reset. + private Map fChangedValues = Collections.synchronizedMap(new HashMap()); - // Flag indicating when the generator has been shut down. - private AtomicBoolean fShutdown = new AtomicBoolean(false); + // Used to determine when to make changes in data. + private long fLastChangeTime = System.currentTimeMillis(); - public DataGeneratorWithThread() { - // Immediately kick off the request processing thread. - start(); - } + // Flag indicating when the generator has been shut down. + private AtomicBoolean fShutdown = new AtomicBoolean(false); - @Override + public DataGeneratorWithThread() { + // Immediately kick off the request processing thread. + start(); + } + + @Override public void shutdown(RequestMonitor rm) { - // Mark the generator as shut down. After the fShutdown flag is set, - // all new requests should be shut down. - if (!fShutdown.getAndSet(true)) { - fQueue.add(new ShutdownRequest(rm)); - } else { - // - rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - rm.done(); - } - } + // Mark the generator as shut down. After the fShutdown flag is set, + // all new requests should be shut down. + if (!fShutdown.getAndSet(true)) { + fQueue.add(new ShutdownRequest(rm)); + } else { + // + rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + rm.done(); + } + } - @Override + @Override public void getCount(DataRequestMonitor rm) { - if (!fShutdown.get()) { - fQueue.add(new CountRequest(rm)); - } else { - rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - rm.done(); - } - } + if (!fShutdown.get()) { + fQueue.add(new CountRequest(rm)); + } else { + rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + rm.done(); + } + } - @Override + @Override public void getValue(int index, DataRequestMonitor rm) { - if (!fShutdown.get()) { - fQueue.add(new ItemRequest(index, rm)); - } else { - rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, - "Supplier shut down")); - rm.done(); - } - } + if (!fShutdown.get()) { + fQueue.add(new ItemRequest(index, rm)); + } else { + rm.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down")); + rm.done(); + } + } - @Override + @Override public void addListener(Listener listener) { - fListeners.add(listener); - } + fListeners.add(listener); + } - @Override + @Override public void removeListener(Listener listener) { - fListeners.remove(listener); - } + fListeners.remove(listener); + } - @Override - public void run() { - try { - while(true) { - // Get the next request from the queue. The time-out - // ensures that that the random changes get processed. - final Request request = fQueue.poll(100, TimeUnit.MILLISECONDS); + @Override + public void run() { + try { + while (true) { + // Get the next request from the queue. The time-out + // ensures that that the random changes get processed. + final Request request = fQueue.poll(100, TimeUnit.MILLISECONDS); - // If a request was dequeued, process it. - if (request != null) { - // Simulate a processing delay. + // If a request was dequeued, process it. + if (request != null) { + // Simulate a processing delay. - if (request instanceof CountRequest) { - processCountRequest((CountRequest)request); - } else if (request instanceof ItemRequest) { - processItemRequest((ItemRequest)request); - } else if (request instanceof ShutdownRequest) { - // If shutting down, just break out of the while(true) - // loop and thread will exit. - request.fRequestMonitor.done(); - break; - } - } else { - Thread.sleep(PROCESSING_DELAY); - } + if (request instanceof CountRequest) { + processCountRequest((CountRequest) request); + } else if (request instanceof ItemRequest) { + processItemRequest((ItemRequest) request); + } else if (request instanceof ShutdownRequest) { + // If shutting down, just break out of the while(true) + // loop and thread will exit. + request.fRequestMonitor.done(); + break; + } + } else { + Thread.sleep(PROCESSING_DELAY); + } - // Simulate data changes. - randomChanges(); - } - } - catch (InterruptedException x) {} - } + // Simulate data changes. + randomChanges(); + } + } catch (InterruptedException x) { + } + } - private void processCountRequest(CountRequest request) { - @SuppressWarnings("unchecked") // Suppress warning about lost type info. - DataRequestMonitor rm = - (DataRequestMonitor)request.fRequestMonitor; + private void processCountRequest(CountRequest request) { + @SuppressWarnings("unchecked") // Suppress warning about lost type info. + DataRequestMonitor rm = (DataRequestMonitor) request.fRequestMonitor; - rm.setData(fCount); - rm.done(); - } + rm.setData(fCount); + rm.done(); + } - private void processItemRequest(ItemRequest request) { - @SuppressWarnings("unchecked") // Suppress warning about lost type info. - DataRequestMonitor rm = - (DataRequestMonitor)request.fRequestMonitor; + private void processItemRequest(ItemRequest request) { + @SuppressWarnings("unchecked") // Suppress warning about lost type info. + DataRequestMonitor rm = (DataRequestMonitor) request.fRequestMonitor; - if (fChangedValues.containsKey(request.fIndex)) { - rm.setData(fChangedValues.get(request.fIndex)); - } else { - rm.setData(request.fIndex); - } - rm.done(); - } + if (fChangedValues.containsKey(request.fIndex)) { + rm.setData(fChangedValues.get(request.fIndex)); + } else { + rm.setData(request.fIndex); + } + rm.done(); + } + private void randomChanges() { + // Check if enough time is elapsed. + if (System.currentTimeMillis() > fLastChangeTime + RANDOM_CHANGE_INTERVAL) { + fLastChangeTime = System.currentTimeMillis(); - private void randomChanges() { - // Check if enough time is elapsed. - if (System.currentTimeMillis() > - fLastChangeTime + RANDOM_CHANGE_INTERVAL) - { - fLastChangeTime = System.currentTimeMillis(); + // Once every number of changes, reset the count, the rest of the + // times just change certain values. + if (++fCountResetTrigger % RANDOM_COUNT_CHANGE_INTERVALS == 0) { + randomCountReset(); + } else { + randomDataChange(); + } + } + } - // Once every number of changes, reset the count, the rest of the - // times just change certain values. - if (++fCountResetTrigger % RANDOM_COUNT_CHANGE_INTERVALS == 0) { - randomCountReset(); - } else { - randomDataChange(); - } - } - } + private void randomCountReset() { + // Calculate the new count. + Random random = new java.util.Random(); + fCount = MIN_COUNT + random.nextInt(MAX_COUNT - MIN_COUNT); - private void randomCountReset() { - // Calculate the new count. - Random random = new java.util.Random(); - fCount = MIN_COUNT + random.nextInt(MAX_COUNT - MIN_COUNT); + // Reset the changed values. + fChangedValues.clear(); - // Reset the changed values. - fChangedValues.clear(); + // Notify listeners + for (Object listener : fListeners.getListeners()) { + ((Listener) listener).countChanged(); + } + } - // Notify listeners - for (Object listener : fListeners.getListeners()) { - ((Listener)listener).countChanged(); - } - } + private void randomDataChange() { + // Calculate the indexes to change. + Random random = new java.util.Random(); + Map changed = new HashMap(); + for (int i = 0; i < fCount * RANDOM_CHANGE_SET_PERCENTAGE / 100; i++) { + int randomIndex = random.nextInt(fCount); + int randomValue = random.nextInt(fCount); + changed.put(randomIndex, randomValue); + } - private void randomDataChange() { - // Calculate the indexes to change. - Random random = new java.util.Random(); - Map changed = new HashMap(); - for (int i = 0; i < fCount * RANDOM_CHANGE_SET_PERCENTAGE / 100; i++) { - int randomIndex = random.nextInt(fCount); - int randomValue = random.nextInt(fCount); - changed.put(randomIndex, randomValue); - } + // Add the indexes to an overall set of changed indexes. + fChangedValues.putAll(changed); - // Add the indexes to an overall set of changed indexes. - fChangedValues.putAll(changed); - - // Notify listeners - for (Object listener : fListeners.getListeners()) { - ((Listener)listener).valuesChanged(changed.keySet()); - } - } + // Notify listeners + for (Object listener : fListeners.getListeners()) { + ((Listener) listener).valuesChanged(changed.keySet()); + } + } } - - diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/IDataGenerator.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/IDataGenerator.java index 5d0e835da3a..9408673056e 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/IDataGenerator.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/IDataGenerator.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -40,34 +41,36 @@ import org.eclipse.cdt.dsf.concurrent.RequestMonitor; //#endif public interface IDataGenerator { - // Constants which control the data generator behavior. - // Changing the count range can stress the scalability of the system, while - // changing of the process delay and random change interval can stress - // its performance. - final static int MIN_COUNT = 50; - final static int MAX_COUNT = 100; - final static int PROCESSING_DELAY = 500; - final static int RANDOM_CHANGE_INTERVAL = 4000; - final static int RANDOM_COUNT_CHANGE_INTERVALS = 5; - final static int RANDOM_CHANGE_SET_PERCENTAGE = 10; + // Constants which control the data generator behavior. + // Changing the count range can stress the scalability of the system, while + // changing of the process delay and random change interval can stress + // its performance. + final static int MIN_COUNT = 50; + final static int MAX_COUNT = 100; + final static int PROCESSING_DELAY = 500; + final static int RANDOM_CHANGE_INTERVAL = 4000; + final static int RANDOM_COUNT_CHANGE_INTERVALS = 5; + final static int RANDOM_CHANGE_SET_PERCENTAGE = 10; + // Listener interface that the view needs to implement to react + // to the changes in data. + public interface Listener { + void countChanged(); - // Listener interface that the view needs to implement to react - // to the changes in data. - public interface Listener { - void countChanged(); - void valuesChanged(Set indexes); - } + void valuesChanged(Set indexes); + } - // Data access methods. - void getCount(DataRequestMonitor rm); - void getValue(int index, DataRequestMonitor rm); + // Data access methods. + void getCount(DataRequestMonitor rm); - // Method used to shutdown the data generator including any threads that - // it may use. - void shutdown(RequestMonitor rm); + void getValue(int index, DataRequestMonitor rm); - // Methods for registering change listeners. - void addListener(Listener listener); - void removeListener(Listener listener); + // Method used to shutdown the data generator including any threads that + // it may use. + void shutdown(RequestMonitor rm); + + // Methods for registering change listeners. + void addListener(Listener listener); + + void removeListener(Listener listener); } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/SyncDataViewer.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/SyncDataViewer.java index b5ffa387273..0e671d5f62c 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/SyncDataViewer.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/dataviewer/SyncDataViewer.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.dataviewer; //#else + //#package org.eclipse.cdt.examples.dsf.dataviewer.answers; //#endif @@ -46,183 +47,174 @@ import org.eclipse.swt.widgets.Shell; * {@link Query} object. *

*/ -public class SyncDataViewer - implements IStructuredContentProvider, IDataGenerator.Listener -{ - // The viewer and generator that this content provider using. - final private TableViewer fViewer; - final private IDataGenerator fDataGenerator; +public class SyncDataViewer implements IStructuredContentProvider, IDataGenerator.Listener { + // The viewer and generator that this content provider using. + final private TableViewer fViewer; + final private IDataGenerator fDataGenerator; - public SyncDataViewer(TableViewer viewer, IDataGenerator generator) { - fViewer = viewer; - fDataGenerator = generator; - fDataGenerator.addListener(this); - } + public SyncDataViewer(TableViewer viewer, IDataGenerator generator) { + fViewer = viewer; + fDataGenerator = generator; + fDataGenerator.addListener(this); + } - @Override + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // Not used - } + // Not used + } - - @Override + @Override public Object[] getElements(Object inputElement) { - // Create the query object for reading data count. - Query countQuery = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fDataGenerator.getCount(rm); - } - }; + // Create the query object for reading data count. + Query countQuery = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fDataGenerator.getCount(rm); + } + }; - // Submit the query to be executed. A query implements a runnable - // interface and it has to be executed in order to do its work. - ImmediateExecutor.getInstance().execute(countQuery); - int count = 0; + // Submit the query to be executed. A query implements a runnable + // interface and it has to be executed in order to do its work. + ImmediateExecutor.getInstance().execute(countQuery); + int count = 0; - // Block until the query completes, which will happen when the request - // monitor of the execute() method is marked done. - try { - count = countQuery.get(); - } catch (Exception e) { - // InterruptedException and ExecutionException can be thrown here. - // ExecutionException containing a CoreException will be thrown - // if an error status is set to the Query's request monitor. - return new Object[0]; - } + // Block until the query completes, which will happen when the request + // monitor of the execute() method is marked done. + try { + count = countQuery.get(); + } catch (Exception e) { + // InterruptedException and ExecutionException can be thrown here. + // ExecutionException containing a CoreException will be thrown + // if an error status is set to the Query's request monitor. + return new Object[0]; + } - final int finalCount = count; - Query> valueQuery = new Query>() { - @Override - protected void execute(final DataRequestMonitor> rm) { - final Integer[] retVal = new Integer[finalCount]; - final CountingRequestMonitor crm = new CountingRequestMonitor( - ImmediateExecutor.getInstance(), rm) - { - @Override - protected void handleSuccess() { - rm.setData(Arrays.asList(retVal)); - rm.done(); - }; - }; - for (int i = 0; i < finalCount; i++) { - final int finalI = i; - fDataGenerator.getValue( - i, - new DataRequestMonitor( - ImmediateExecutor.getInstance(), crm) - { - @Override - protected void handleSuccess() { - retVal[finalI] = getData(); - crm.done(); - } - }); - } - crm.setDoneCount(finalCount); - } - }; - ImmediateExecutor.getInstance().execute(valueQuery); - try { - return valueQuery.get().toArray(new Integer[0]); - } catch (Exception e) { - } - return new Object[0]; - } + final int finalCount = count; + Query> valueQuery = new Query>() { + @Override + protected void execute(final DataRequestMonitor> rm) { + final Integer[] retVal = new Integer[finalCount]; + final CountingRequestMonitor crm = new CountingRequestMonitor(ImmediateExecutor.getInstance(), rm) { + @Override + protected void handleSuccess() { + rm.setData(Arrays.asList(retVal)); + rm.done(); + }; + }; + for (int i = 0; i < finalCount; i++) { + final int finalI = i; + fDataGenerator.getValue(i, new DataRequestMonitor(ImmediateExecutor.getInstance(), crm) { + @Override + protected void handleSuccess() { + retVal[finalI] = getData(); + crm.done(); + } + }); + } + crm.setDoneCount(finalCount); + } + }; + ImmediateExecutor.getInstance().execute(valueQuery); + try { + return valueQuery.get().toArray(new Integer[0]); + } catch (Exception e) { + } + return new Object[0]; + } - @Override + @Override public void dispose() { - fDataGenerator.removeListener(this); - } + fDataGenerator.removeListener(this); + } - @Override + @Override public void countChanged() { - // For any event from the generator, refresh the whole viewer. - refreshViewer(); - } + // For any event from the generator, refresh the whole viewer. + refreshViewer(); + } - @Override + @Override public void valuesChanged(Set indexes) { - // For any event from the generator, refresh the whole viewer. - refreshViewer(); - } + // For any event from the generator, refresh the whole viewer. + refreshViewer(); + } - private void refreshViewer() { - //#ifdef exercises - // TODO Exercise 5 - Add a call to getElements() to force a deadlock. - //#else -//# getElements(null); - //#endif + private void refreshViewer() { + //#ifdef exercises + // TODO Exercise 5 - Add a call to getElements() to force a deadlock. + //#else + //# getElements(null); + //#endif - // This method may be called on any thread, switch to the display - // thread before calling the viewer. - Display display = fViewer.getControl().getDisplay(); - display.asyncExec( new Runnable() { - @Override + // This method may be called on any thread, switch to the display + // thread before calling the viewer. + Display display = fViewer.getControl().getDisplay(); + display.asyncExec(new Runnable() { + @Override public void run() { - if (!fViewer.getControl().isDisposed()) { - fViewer.refresh(); - } - } - }); - } + if (!fViewer.getControl().isDisposed()) { + fViewer.refresh(); + } + } + }); + } - /** - * The entry point for the example. - * @param args Program arguments. - */ - public static void main(String[] args) { - // Create the shell to hold the viewer. - Display display = new Display(); - Shell shell = new Shell(display, SWT.SHELL_TRIM); - shell.setLayout(new GridLayout()); - GridData data = new GridData(GridData.FILL_BOTH); - shell.setLayoutData(data); - Font font = new Font(display, "Courier", 10, SWT.NORMAL); + /** + * The entry point for the example. + * @param args Program arguments. + */ + public static void main(String[] args) { + // Create the shell to hold the viewer. + Display display = new Display(); + Shell shell = new Shell(display, SWT.SHELL_TRIM); + shell.setLayout(new GridLayout()); + GridData data = new GridData(GridData.FILL_BOTH); + shell.setLayoutData(data); + Font font = new Font(display, "Courier", 10, SWT.NORMAL); - // Create the table viewer. - TableViewer tableViewer = new TableViewer(shell, SWT.BORDER); - tableViewer.getControl().setLayoutData(data); + // Create the table viewer. + TableViewer tableViewer = new TableViewer(shell, SWT.BORDER); + tableViewer.getControl().setLayoutData(data); - // Create the data generator. - //#ifdef exercises - // TODO Exercise 5 - Use the DataGeneratorWithExecutor() instead. - final IDataGenerator generator = new DataGeneratorWithThread(); - //#else -//# final IDataGenerator generator = new DataGeneratorWithExecutor(); - //#endif + // Create the data generator. + //#ifdef exercises + // TODO Exercise 5 - Use the DataGeneratorWithExecutor() instead. + final IDataGenerator generator = new DataGeneratorWithThread(); + //#else + //# final IDataGenerator generator = new DataGeneratorWithExecutor(); + //#endif - // Create the content provider which will populate the viewer. - SyncDataViewer contentProvider = - new SyncDataViewer(tableViewer, generator); - tableViewer.setContentProvider(contentProvider); - tableViewer.setInput(new Object()); + // Create the content provider which will populate the viewer. + SyncDataViewer contentProvider = new SyncDataViewer(tableViewer, generator); + tableViewer.setContentProvider(contentProvider); + tableViewer.setInput(new Object()); - // Open the shell and service the display dispatch loop until user - // closes the shell. - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } + // Open the shell and service the display dispatch loop until user + // closes the shell. + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } - // The IDataGenerator.shutdown() method is asynchronous, this requires - // using a query again in order to wait for its completion. - Query shutdownQuery = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - generator.shutdown(rm); - } - }; - ImmediateExecutor.getInstance().execute(shutdownQuery); - try { - shutdownQuery.get(); - } catch (Exception e) {} + // The IDataGenerator.shutdown() method is asynchronous, this requires + // using a query again in order to wait for its completion. + Query shutdownQuery = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + generator.shutdown(rm); + } + }; + ImmediateExecutor.getInstance().execute(shutdownQuery); + try { + shutdownQuery.get(); + } catch (Exception e) { + } - // Shut down the display. - font.dispose(); - display.dispose(); - } + // Shut down the display. + font.dispose(); + display.dispose(); + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/Async2Plus2.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/Async2Plus2.java index c6463c3de40..dabe34c9307 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/Async2Plus2.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/Async2Plus2.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.requestmonitor; //#else + //#package org.eclipse.cdt.examples.dsf.requestmonitor.answers; //#endif @@ -28,20 +29,19 @@ import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; */ public class Async2Plus2 { - public static void main(String[] args) { - Executor executor = ImmediateExecutor.getInstance(); - DataRequestMonitor rm = - new DataRequestMonitor(executor, null) { - @Override - protected void handleCompleted() { - System.out.println("2 + 2 = " + getData()); - } - }; - asyncAdd(2, 2, rm); - } + public static void main(String[] args) { + Executor executor = ImmediateExecutor.getInstance(); + DataRequestMonitor rm = new DataRequestMonitor(executor, null) { + @Override + protected void handleCompleted() { + System.out.println("2 + 2 = " + getData()); + } + }; + asyncAdd(2, 2, rm); + } - static void asyncAdd(int value1, int value2, DataRequestMonitor rm) { - rm.setData(value1 + value2); - rm.done(); - } + static void asyncAdd(int value1, int value2, DataRequestMonitor rm) { + rm.setData(value1 + value2); + rm.done(); + } } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncHelloWorld.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncHelloWorld.java index bf4594dfb66..512e5013397 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncHelloWorld.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncHelloWorld.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.requestmonitor; //#else + //#package org.eclipse.cdt.examples.dsf.requestmonitor.answers; //#endif @@ -32,34 +33,34 @@ import org.eclipse.cdt.dsf.concurrent.RequestMonitor; */ public class AsyncHelloWorld { - public static void main(String[] args) { - Executor executor = ImmediateExecutor.getInstance(); - RequestMonitor rm = new RequestMonitor(executor, null); - asyncHelloWorld(rm); - } + public static void main(String[] args) { + Executor executor = ImmediateExecutor.getInstance(); + RequestMonitor rm = new RequestMonitor(executor, null); + asyncHelloWorld(rm); + } - static void asyncHelloWorld(RequestMonitor rm) { - System.out.println("Hello world"); - //#ifdef exercises - // TODO Exercise 1: - Call the second async. "Hello world 2" method. - // Hint: Calling an asynchronous method requires passing to it a - // request monitor. A new request monitor can be constructed with - // a parent RequestMonitor as an argument argument. The parent gets - // completed automatically when the lower level request monitor is - // completed. - rm.done(); - //#else -//# RequestMonitor rm2 = new RequestMonitor(ImmediateExecutor.getInstance(), rm); -//# asyncHelloWorld2(rm2); - //#endif - } + static void asyncHelloWorld(RequestMonitor rm) { + System.out.println("Hello world"); + //#ifdef exercises + // TODO Exercise 1: - Call the second async. "Hello world 2" method. + // Hint: Calling an asynchronous method requires passing to it a + // request monitor. A new request monitor can be constructed with + // a parent RequestMonitor as an argument argument. The parent gets + // completed automatically when the lower level request monitor is + // completed. + rm.done(); + //#else + //# RequestMonitor rm2 = new RequestMonitor(ImmediateExecutor.getInstance(), rm); + //# asyncHelloWorld2(rm2); + //#endif + } - //#ifdef exercises - // TODO: Exercise 1 - Add a second async. "Hello world 2" method. - //#else -//# static void asyncHelloWorld2(RequestMonitor rm) { -//# System.out.println("Hello world 2"); -//# rm.done(); -//# } - //#endif + //#ifdef exercises + // TODO: Exercise 1 - Add a second async. "Hello world 2" method. + //#else + //# static void asyncHelloWorld2(RequestMonitor rm) { + //# System.out.println("Hello world 2"); + //# rm.done(); + //# } + //#endif } diff --git a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncQuicksort.java b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncQuicksort.java index 7e1d33c99c8..ecf83a90224 100644 --- a/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncQuicksort.java +++ b/dsf/org.eclipse.cdt.examples.dsf/src_preprocess/org/eclipse/cdt/examples/dsf/requestmonitor/AsyncQuicksort.java @@ -14,6 +14,7 @@ //#ifdef exercises package org.eclipse.cdt.examples.dsf.requestmonitor; //#else + //#package org.eclipse.cdt.examples.dsf.requestmonitor.answers; //#endif @@ -33,117 +34,113 @@ import org.eclipse.cdt.dsf.concurrent.RequestMonitor; */ public class AsyncQuicksort { - static Executor fgExecutor = ImmediateExecutor.getInstance(); + static Executor fgExecutor = ImmediateExecutor.getInstance(); - public static void main(String[] args) { - final int[] array = {5, 7, 8, 3, 2, 1, 9, 5, 4}; + public static void main(String[] args) { + final int[] array = { 5, 7, 8, 3, 2, 1, 9, 5, 4 }; - System.out.println("To sort: " + Arrays.toString(array)); - asyncQuicksort( - array, 0, array.length - 1, - new RequestMonitor(fgExecutor, null) { - @Override - protected void handleCompleted() { - System.out.println("Sorted: " + Arrays.toString(array)); - } - }); - } + System.out.println("To sort: " + Arrays.toString(array)); + asyncQuicksort(array, 0, array.length - 1, new RequestMonitor(fgExecutor, null) { + @Override + protected void handleCompleted() { + System.out.println("Sorted: " + Arrays.toString(array)); + } + }); + } - static void asyncQuicksort(final int[] array, final int left, - final int right, final RequestMonitor rm) - { - if (right > left) { - int pivot = left; - //#ifdef exercises - // TODO: Exercise 2 - Convert the call to partition into an - // asynchronous call to asyncPartition(). - // Hint: The rest of the code below should be executed inside - // the DataRequestMonitor.handleCompleted() overriding method. - int newPivot = partition(array, left, right, pivot); - printArray(array, left, right, newPivot); + static void asyncQuicksort(final int[] array, final int left, final int right, final RequestMonitor rm) { + if (right > left) { + int pivot = left; + //#ifdef exercises + // TODO: Exercise 2 - Convert the call to partition into an + // asynchronous call to asyncPartition(). + // Hint: The rest of the code below should be executed inside + // the DataRequestMonitor.handleCompleted() overriding method. + int newPivot = partition(array, left, right, pivot); + printArray(array, left, right, newPivot); - CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm); - asyncQuicksort(array, left, newPivot - 1, countingRm); - asyncQuicksort(array, newPivot + 1, right, countingRm); - countingRm.setDoneCount(2); - //#else -//# asyncPartition( -//# array, left, right, pivot, -//# new DataRequestMonitor(fgExecutor, rm) { -//# @Override -//# protected void handleCompleted() { -//# int newPivot = getData(); -//# printArray(array, left, right, newPivot); -//# -//# CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm); -//# asyncQuicksort(array, left, newPivot - 1, countingRm); -//# asyncQuicksort(array, newPivot + 1, right, countingRm); -//# countingRm.setDoneCount(2); -//# } -//# }); - //#endif - } else { - rm.done(); - } - } + CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm); + asyncQuicksort(array, left, newPivot - 1, countingRm); + asyncQuicksort(array, newPivot + 1, right, countingRm); + countingRm.setDoneCount(2); + //#else + //# asyncPartition( + //# array, left, right, pivot, + //# new DataRequestMonitor(fgExecutor, rm) { + //# @Override + //# protected void handleCompleted() { + //# int newPivot = getData(); + //# printArray(array, left, right, newPivot); + //# + //# CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm); + //# asyncQuicksort(array, left, newPivot - 1, countingRm); + //# asyncQuicksort(array, newPivot + 1, right, countingRm); + //# countingRm.setDoneCount(2); + //# } + //# }); + //#endif + } else { + rm.done(); + } + } - //#ifdef exercises - // TODO Exercise 2 - Convert partition to an asynchronous method. - // Hint: a DataRequestMonitor should be used to carry the - // return value to the caller. - static int partition(int[] array, int left, int right, int pivot) - //#else -//# static void asyncPartition(int[] array, int left, int right, int pivot, DataRequestMonitor rm) - //#endif - { - int pivotValue = array[pivot]; - array[pivot] = array[right]; - array[right] = pivotValue; - int store = left; - for (int i = left; i < right; i++) { - if (array[i] <= pivotValue) { - int tmp = array[store]; - array[store] = array[i]; - array[i] = tmp; - store++; - } - } - array[right] = array[store]; - array[store] = pivotValue; + //#ifdef exercises + // TODO Exercise 2 - Convert partition to an asynchronous method. + // Hint: a DataRequestMonitor should be used to carry the + // return value to the caller. + static int partition(int[] array, int left, int right, int pivot) + //#else + //# static void asyncPartition(int[] array, int left, int right, int pivot, DataRequestMonitor rm) + //#endif + { + int pivotValue = array[pivot]; + array[pivot] = array[right]; + array[right] = pivotValue; + int store = left; + for (int i = left; i < right; i++) { + if (array[i] <= pivotValue) { + int tmp = array[store]; + array[store] = array[i]; + array[i] = tmp; + store++; + } + } + array[right] = array[store]; + array[store] = pivotValue; - //#ifdef exercises - // TODO: Request Monitors Exercise 2 - Return the data to caller using - // a request monitor. - return store; - //#else -//# // Java 5 automatically converts the int type of the store variable -//# // to an Integer object. -//# rm.setData(store); -//# rm.done(); - //#endif - } + //#ifdef exercises + // TODO: Request Monitors Exercise 2 - Return the data to caller using + // a request monitor. + return store; + //#else + //# // Java 5 automatically converts the int type of the store variable + //# // to an Integer object. + //# rm.setData(store); + //# rm.done(); + //#endif + } - static void printArray(int[] array, int left, int right, int pivot) { - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < array.length; i++ ) { - if (i == left) { - buffer.append('>'); - } else if (i == pivot) { - buffer.append('-'); - } else { - buffer.append(' '); - } - buffer.append(array[i]); + static void printArray(int[] array, int left, int right, int pivot) { + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < array.length; i++) { + if (i == left) { + buffer.append('>'); + } else if (i == pivot) { + buffer.append('-'); + } else { + buffer.append(' '); + } + buffer.append(array[i]); - if (i == right) { - buffer.append('<'); - } else if (i == pivot) { - buffer.append('-'); - } else { - buffer.append(' '); - } - } + if (i == right) { + buffer.append('<'); + } else if (i == pivot) { + buffer.append('-'); + } else { + buffer.append(' '); + } + } - System.out.println(buffer); - } + System.out.println(buffer); + } } diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java index 032f4fb1ef6..de0a07630c4 100644 --- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java +++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java @@ -462,8 +462,7 @@ abstract public class FormattedValueTests extends TestCase ArrayList elementFormats1 = new ArrayList<>(map1.values()); HashMap expMap1 = new HashMap<>(); makeElementFormatSetting(fViewer, TreePath.EMPTY, format1, depth, 0, expMap1); - ArrayList expectElementFormats1 = new ArrayList<>( - expMap1.values()); + ArrayList expectElementFormats1 = new ArrayList<>(expMap1.values()); vmListenerLevel = depth; setFormatAndValidate(preferenceFormat, elementFormats1, expectElementFormats1, true, false, false); @@ -474,8 +473,7 @@ abstract public class FormattedValueTests extends TestCase ArrayList elementFormats2 = new ArrayList<>(map2.values()); HashMap expMap2 = new HashMap<>(); makeElementFormatSetting(fViewer, TreePath.EMPTY, format2, depth, 0, expMap2); - ArrayList expectElementFormats2 = new ArrayList<>( - expMap2.values()); + ArrayList expectElementFormats2 = new ArrayList<>(expMap2.values()); setFormatAndValidate(preferenceFormat, elementFormats2, expectElementFormats2, true, true, false); // Generate an event which will cause all cache entries to be marked dirty. @@ -491,8 +489,7 @@ abstract public class FormattedValueTests extends TestCase ArrayList elementFormats3 = new ArrayList<>(map3.values()); HashMap expMap3 = new HashMap<>(); makeElementFormatSetting(fViewer, TreePath.EMPTY, format3, depth, 0, expMap3); - ArrayList expectElementFormats3 = new ArrayList<>( - expMap3.values()); + ArrayList expectElementFormats3 = new ArrayList<>(expMap3.values()); setFormatAndValidate(preferenceFormat, elementFormats3, expectElementFormats3, true, true, true); } } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java index df485de6e84..3058f770e76 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java @@ -476,8 +476,7 @@ public class GoToAddressBarWidget { String id = UNKNOWN_CONTEXT_ID; if (context instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) context; - IRecurringDebugContext recurringDebugContext = adaptable - .getAdapter(IRecurringDebugContext.class); + IRecurringDebugContext recurringDebugContext = adaptable.getAdapter(IRecurringDebugContext.class); if (recurringDebugContext != null) { try { id = recurringDebugContext.getContextID(); diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java index 5ddc80b9105..46cdcf15de3 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java @@ -660,7 +660,6 @@ public class MemoryBrowser extends ViewPart label += ' ' + renderingType; - // Allow the memory block to customize the label. The platform's // Memory view support this (it was done in the call to // rendering.getLabel() above) @@ -1412,8 +1411,7 @@ public class MemoryBrowser extends ViewPart if (retrieval instanceof IMemoryBlockRetrievalExtension) { retrievalExtension = (IMemoryBlockRetrievalExtension) retrieval; } else if (retrieval instanceof IAdaptable) { - retrievalExtension = ((IAdaptable) retrieval) - .getAdapter(IMemoryBlockRetrievalExtension.class); + retrievalExtension = ((IAdaptable) retrieval).getAdapter(IMemoryBlockRetrievalExtension.class); } if (retrievalExtension != null) { if (retrievalExtension instanceof IMemorySpaceAwareMemoryBlockRetrieval) { diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeEnvInfo.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeEnvInfo.java index eb8e1f39923..0565d3d6ccc 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeEnvInfo.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeEnvInfo.java @@ -42,10 +42,8 @@ public final class QMakeEnvInfo { Collection sensitiveFiles) { this.proFile = proFile; this.qmakeFilePath = qmakeFilePath; - this.environment = environment != null ? new HashMap<>(environment) - : Collections.emptyMap(); - this.sensitiveFiles = sensitiveFiles != null ? new HashSet<>(sensitiveFiles) - : Collections.emptySet(); + this.environment = environment != null ? new HashMap<>(environment) : Collections.emptyMap(); + this.sensitiveFiles = sensitiveFiles != null ? new HashSet<>(sensitiveFiles) : Collections.emptySet(); } /** diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java index 4d744d59737..ce32f7e70ad 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QMakeInfo.java @@ -61,8 +61,7 @@ public final class QMakeInfo implements IQMakeInfo { this.qtVersion = QMakeVersion.create(queryMap.get(QMakeParser.KEY_QT_VERSION)); List tmpQtImportPaths = new ArrayList<>( QMakeParser.singleValue(queryMap, QMakeParser.KEY_QT_INSTALL_IMPORTS)); - List tmpQtQmlPaths = new ArrayList<>( - QMakeParser.singleValue(queryMap, QMakeParser.KEY_QT_INSTALL_QML)); + List tmpQtQmlPaths = new ArrayList<>(QMakeParser.singleValue(queryMap, QMakeParser.KEY_QT_INSTALL_QML)); this.qtDocPath = QMakeParser.singleValue(queryMap, QMakeParser.KEY_QT_INSTALL_DOCS); this.involvedQMakeFiles = QMakeParser.qmake3DecodeValueList(proMap, diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQObject.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQObject.java index 9707501aead..433699c0097 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQObject.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQObject.java @@ -76,8 +76,7 @@ public class QtPDOMQObject extends AbstractQtPDOMClass { // Store the array into the Database. long arrayRec = getDB().getRecPtr(Field.ClassInfos.getRecord(record)); - QtPDOMArray pdomArray = new QtPDOMArray<>(getQtLinkage(), ClassInfo.Codec, - arrayRec); + QtPDOMArray pdomArray = new QtPDOMArray<>(getQtLinkage(), ClassInfo.Codec, arrayRec); arrayRec = pdomArray.set(array); // Update the record that is stored in the receiver's field. @@ -89,8 +88,7 @@ public class QtPDOMQObject extends AbstractQtPDOMClass { // Read the array from the Database and insert the elements into the Map that is to be returned. long arrayRec = getDB().getRecPtr(Field.ClassInfos.getRecord(record)); - QtPDOMArray pdomArray = new QtPDOMArray<>(getQtLinkage(), ClassInfo.Codec, - arrayRec); + QtPDOMArray pdomArray = new QtPDOMArray<>(getQtLinkage(), ClassInfo.Codec, arrayRec); ClassInfo[] array = pdomArray.get(); if (array == null) diff --git a/testsrunner/org.eclipse.cdt.testsrunner/src/org/eclipse/cdt/testsrunner/internal/model/TestingSession.java b/testsrunner/org.eclipse.cdt.testsrunner/src/org/eclipse/cdt/testsrunner/internal/model/TestingSession.java index d9ce77fd76a..ff5c14f61cb 100644 --- a/testsrunner/org.eclipse.cdt.testsrunner/src/org/eclipse/cdt/testsrunner/internal/model/TestingSession.java +++ b/testsrunner/org.eclipse.cdt.testsrunner/src/org/eclipse/cdt/testsrunner/internal/model/TestingSession.java @@ -72,8 +72,7 @@ public class TestingSession implements ITestingSession { * statistics without model scanning. * */ - private Map statusCounters = new EnumMap<>( - ITestItem.Status.class); + private Map statusCounters = new EnumMap<>(ITestItem.Status.class); /** * The flag stores whether the testing session contains errors at the