From 4ca8827b06ff0605a785f72ebdff284c525c3a93 Mon Sep 17 00:00:00 2001 From: Arnaud Dieumegard Date: Thu, 20 Jan 2022 09:17:27 +0100 Subject: [PATCH] [sonar] Fix issues Change-Id: I0000000000000000000000000000000000000000 Signed-off-by: Arnaud Dieumegard --- .../sirius/ted/SiriusSessionFactory.java | 4 +- .../prefs/SemanticModelPreferences.java | 4 +- .../CommandsPreferencesInitializer.java | 2 +- .../core/ui/search/CapellaSearchQuery.java | 108 +++++++++--------- .../core/ui/search/CapellaSearchSettings.java | 2 +- ...ExportValidationPreferenceInitializer.java | 2 +- 6 files changed, 63 insertions(+), 59 deletions(-) diff --git a/common/plugins/org.polarsys.capella.common.platform.sirius.ted/src/org/polarsys/capella/common/platform/sirius/ted/SiriusSessionFactory.java b/common/plugins/org.polarsys.capella.common.platform.sirius.ted/src/org/polarsys/capella/common/platform/sirius/ted/SiriusSessionFactory.java index ef6eeef1ce..c0213da5eb 100644 --- a/common/plugins/org.polarsys.capella.common.platform.sirius.ted/src/org/polarsys/capella/common/platform/sirius/ted/SiriusSessionFactory.java +++ b/common/plugins/org.polarsys.capella.common.platform.sirius.ted/src/org/polarsys/capella/common/platform/sirius/ted/SiriusSessionFactory.java @@ -123,9 +123,9 @@ public Collection getDerivedSemanticResources(TransactionalEditingDoma protected List getAllDerivedSemanticResourceProviders() { if (null == _derivedSemanticResourceProviders) { _derivedSemanticResourceProviders = new ArrayList(); - List BQProvider = Arrays + List providers = Arrays .asList(ExtensionPointHelper.getConfigurationElements(FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), DERIVED_SEMANTIC_RESOURCE_PROVIDER_EXTENSION_ID)); - for (IConfigurationElement configurationElement : BQProvider) { + for (IConfigurationElement configurationElement : providers) { IDerivedSemanticResourceProvider contrib = (IDerivedSemanticResourceProvider) ExtensionPointHelper .createInstance(configurationElement, ExtensionPointHelper.ATT_CLASS); if (contrib != null) { diff --git a/core/plugins/org.polarsys.capella.core.model.semantic/src/org/polarsys/capella/core/model/semantic/prefs/SemanticModelPreferences.java b/core/plugins/org.polarsys.capella.core.model.semantic/src/org/polarsys/capella/core/model/semantic/prefs/SemanticModelPreferences.java index 977675123f..16987cabb6 100644 --- a/core/plugins/org.polarsys.capella.core.model.semantic/src/org/polarsys/capella/core/model/semantic/prefs/SemanticModelPreferences.java +++ b/core/plugins/org.polarsys.capella.core.model.semantic/src/org/polarsys/capella/core/model/semantic/prefs/SemanticModelPreferences.java @@ -27,14 +27,14 @@ public class SemanticModelPreferences extends AbstractPreferenceInitializer impl */ @Override public void initializeDefaultPreferences() { - new DefaultScope().getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()).putBoolean(ISemanticModelPreferences.KEY_SEMANTIC_MODE, true); + DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()).putBoolean(ISemanticModelPreferences.KEY_SEMANTIC_MODE, true); } /** * {@inheritDoc} */ public void setSemanticMode(boolean enabled_p) { - new InstanceScope().getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()).putBoolean(ISemanticModelPreferences.KEY_SEMANTIC_MODE, enabled_p); + InstanceScope.INSTANCE.getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()).putBoolean(ISemanticModelPreferences.KEY_SEMANTIC_MODE, enabled_p); } /** diff --git a/core/plugins/org.polarsys.capella.core.preferences/src/org/polarsys/capella/core/commands/preferences/CommandsPreferencesInitializer.java b/core/plugins/org.polarsys.capella.core.preferences/src/org/polarsys/capella/core/commands/preferences/CommandsPreferencesInitializer.java index 6c94eb9bd1..e49842c655 100644 --- a/core/plugins/org.polarsys.capella.core.preferences/src/org/polarsys/capella/core/commands/preferences/CommandsPreferencesInitializer.java +++ b/core/plugins/org.polarsys.capella.core.preferences/src/org/polarsys/capella/core/commands/preferences/CommandsPreferencesInitializer.java @@ -37,7 +37,7 @@ public void initializeDefaultPreferences() { Collection constraints = PreferencesItemsRegistry.getInstance().getAllDescriptors(); - IEclipsePreferences eclipsePreferenceNode = new DefaultScope().getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()); + IEclipsePreferences eclipsePreferenceNode = DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()); for (IItemDescriptor capellaPreferenceNode : constraints) { eclipsePreferenceNode.put(capellaPreferenceNode.getId(), String.valueOf(capellaPreferenceNode.isEnabledByDefault())); diff --git a/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchQuery.java b/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchQuery.java index 2050cd8404..9bcc9fef15 100644 --- a/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchQuery.java +++ b/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchQuery.java @@ -157,67 +157,71 @@ private void search(Pattern pattern, Object element, IProject project) { protected void searchForAttribute(Pattern pattern, IProject project, EObject inputObject, SearchForAttributeItem attributeItem) { Object searchAttribute = attributeItem.getAttributeFor(inputObject); - if (searchAttribute != null) { - Object searchData = attributeItem.getRelevantSearchData(inputObject); - - if (searchData instanceof String) { - String searchText = (String) searchData; - String[] searchTextLines = searchText.split("\n"); - - if (searchTextLines.length == 1) { - if (isMatchOccurrences(pattern, searchText)) { - SearchMatch result = new SearchMatch(inputObject, searchText, project, searchAttribute); - capellaSearchResult.addMatch(result); - capellaSearchResult.getTreeData().addElement(inputObject); - } - } else { - SearchMatch parentSearchMatch = new SearchMatch(inputObject, null, project, searchAttribute); - boolean matched = false; - for (int number = 0; number < searchTextLines.length; number++) { - String searchTextLine = searchTextLines[number]; - - if (isMatchOccurrences(pattern, searchTextLine)) { - LineSearchMatchChild childSearchMatch = new LineSearchMatchChild(inputObject, searchTextLine, project, parentSearchMatch, number); - - parentSearchMatch.getChildren().add(childSearchMatch); - capellaSearchResult.addMatch(childSearchMatch); - matched = true; - } - } + if (searchAttribute == null) { + return; + } - if (matched) { - capellaSearchResult.addMatch(parentSearchMatch); - capellaSearchResult.getTreeData().addElement(inputObject); - } - } + Object searchData = attributeItem.getRelevantSearchData(inputObject); + if (searchData instanceof String) { + searchForAttributeInStringSearchData(pattern, project, inputObject, searchAttribute, searchData); + } - } + else if (searchData instanceof List) { + searchForAttributeInListSearchData(pattern, project, inputObject, searchAttribute, searchData); + } + } - else if (searchData instanceof List) { - List searchDataList = ((List) searchData); - SearchMatch parentSearchMatch = new SearchMatch(inputObject, null, project, searchAttribute); - boolean matched = false; + private void searchForAttributeInListSearchData(Pattern pattern, IProject project, EObject inputObject, Object searchAttribute, Object searchData) { + List searchDataList = ((List) searchData); + SearchMatch parentSearchMatch = new SearchMatch(inputObject, null, project, searchAttribute); + boolean matched = false; - for (int index = 0; index < searchDataList.size(); index++) { - Object searchElement = searchDataList.get(index); + for (int index = 0; index < searchDataList.size(); index++) { + Object searchElement = searchDataList.get(index); - if (searchElement instanceof String) { - String searchText = (String) searchDataList.get(index); + if (searchElement instanceof String && isMatchOccurrences(pattern, (String) searchElement)) { + ListElementSearchMatchChild childSearchMatch = new ListElementSearchMatchChild(inputObject, (String) searchElement, project, parentSearchMatch, index); + parentSearchMatch.getChildren().add(childSearchMatch); + capellaSearchResult.addMatch(childSearchMatch); + matched = true; + } + } - if (isMatchOccurrences(pattern, searchText)) { - ListElementSearchMatchChild childSearchMatch = new ListElementSearchMatchChild(inputObject, searchText, project, parentSearchMatch, index); - parentSearchMatch.getChildren().add(childSearchMatch); - capellaSearchResult.addMatch(childSearchMatch); - matched = true; - } - } - } + if (matched) { + capellaSearchResult.addMatch(parentSearchMatch); + capellaSearchResult.getTreeData().addElement(inputObject); + } + } - if (matched) { - capellaSearchResult.addMatch(parentSearchMatch); - capellaSearchResult.getTreeData().addElement(inputObject); + private void searchForAttributeInStringSearchData(Pattern pattern, IProject project, EObject inputObject, Object searchAttribute, Object searchData) { + String searchText = (String) searchData; + String[] searchTextLines = searchText.split("\n"); + + if (searchTextLines.length == 1) { + if (isMatchOccurrences(pattern, searchText)) { + SearchMatch result = new SearchMatch(inputObject, searchText, project, searchAttribute); + capellaSearchResult.addMatch(result); + capellaSearchResult.getTreeData().addElement(inputObject); + } + } else { + SearchMatch parentSearchMatch = new SearchMatch(inputObject, null, project, searchAttribute); + boolean matched = false; + for (int number = 0; number < searchTextLines.length; number++) { + String searchTextLine = searchTextLines[number]; + + if (isMatchOccurrences(pattern, searchTextLine)) { + LineSearchMatchChild childSearchMatch = new LineSearchMatchChild(inputObject, searchTextLine, project, parentSearchMatch, number); + + parentSearchMatch.getChildren().add(childSearchMatch); + capellaSearchResult.addMatch(childSearchMatch); + matched = true; } } + + if (matched) { + capellaSearchResult.addMatch(parentSearchMatch); + capellaSearchResult.getTreeData().addElement(inputObject); + } } } diff --git a/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchSettings.java b/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchSettings.java index d8e8a5eac4..f1955ac3c4 100644 --- a/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchSettings.java +++ b/core/plugins/org.polarsys.capella.core.ui.search/src/org/polarsys/capella/core/ui/search/CapellaSearchSettings.java @@ -172,7 +172,7 @@ public IStatus validate() { return new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), CapellaSearchConstants.CapellaSearchPage_Validation_Message_SearchMetaClass_Selection); } - if (searchAttributeItems.isEmpty() && !searchMetaClassItems.stream().anyMatch(SearchForNoteItem.class::isInstance)) { + if (searchAttributeItems.isEmpty() && searchMetaClassItems.stream().noneMatch(SearchForNoteItem.class::isInstance)) { return new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), CapellaSearchConstants.CapellaSearchPage_Validation_Message_SearchAttribute_Selection); } diff --git a/core/plugins/org.polarsys.capella.core.validation/src/org/polarsys/capella/core/validation/prefs/ExportValidationPreferenceInitializer.java b/core/plugins/org.polarsys.capella.core.validation/src/org/polarsys/capella/core/validation/prefs/ExportValidationPreferenceInitializer.java index 99fae790e5..ae6fd69cdd 100644 --- a/core/plugins/org.polarsys.capella.core.validation/src/org/polarsys/capella/core/validation/prefs/ExportValidationPreferenceInitializer.java +++ b/core/plugins/org.polarsys.capella.core.validation/src/org/polarsys/capella/core/validation/prefs/ExportValidationPreferenceInitializer.java @@ -30,7 +30,7 @@ public ExportValidationPreferenceInitializer() { public void initializeDefaultPreferences() { - IEclipsePreferences node = new DefaultScope().getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()); + IEclipsePreferences node = DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(this.getClass()).getSymbolicName()); node.put( IExportValidationConstants.EXPORT_ONLY_CAPELLA_PREF_ID,