Skip to content

Commit

Permalink
[336] Resolve Sonar issues
Browse files Browse the repository at this point in the history
Bug 336

Change-Id: Ia124799a198c0f18efc94c7e5c8cf1732c9c2625
Signed-off-by: Ali Akar <ali.akar82@gmail.com>
  • Loading branch information
aliakar82 committed Jul 19, 2018
1 parent 6687393 commit 650f8ba
Show file tree
Hide file tree
Showing 40 changed files with 513 additions and 578 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -45,11 +45,11 @@

public class DefaultLocationHandler implements ILocationHandler {

HashMap<EObject, EObject> currentLocation = new HashMap<EObject, EObject>();
HashMap<EObject, EObject> currentLocation = new HashMap<>();

HashMap<CatalogElementLink, EObject> locations = new HashMap<CatalogElementLink, EObject>();
HashMap<CatalogElementLink, EObject> locations = new HashMap<>();

HashMap<CatalogElementLink, EObject> defaultLocations = new HashMap<CatalogElementLink, EObject>();
HashMap<CatalogElementLink, EObject> defaultLocations = new HashMap<>();

/**
* {@inheritDoc}
Expand Down Expand Up @@ -305,11 +305,9 @@ public EObject getDefaultLocation(CatalogElementLink link, CatalogElementLink op
}
}

if (targetFeature != null) {
if (AttachmentHelper.getInstance(context).isApplicable(targetContainer.eClass(), targetFeature)) {
if (targetFeature != null && AttachmentHelper.getInstance(context).isApplicable(targetContainer.eClass(), targetFeature)) {
defaultLocations.put(link, targetContainer);
return targetContainer;
}
}
}

Expand Down Expand Up @@ -365,10 +363,8 @@ protected EStructuralFeature getFeature(IRuleAttachment rule, EObject source, EO
}
if (rule != null) {
EStructuralFeature targetFeature = rule.retrieveTargetContainementFeature(source, target, currentLocation, context);
if (targetFeature != null) {
if (AttachmentHelper.getInstance(context).isApplicable(currentLocation.eClass(), targetFeature)) {
return targetFeature;
}
if (targetFeature != null && AttachmentHelper.getInstance(context).isApplicable(currentLocation.eClass(), targetFeature)) {
return targetFeature;
}
}
return source.eContainingFeature();
Expand All @@ -377,7 +373,7 @@ protected EStructuralFeature getFeature(IRuleAttachment rule, EObject source, EO

protected Iterator<EObject> retrieveDefaultContainers(CatalogElementLink link, CatalogElementLink oppositeLink, IContext context) {

Collection<Object> elementsContainers = new LinkedHashSet<Object>(); // order is important!
Collection<Object> elementsContainers = new LinkedHashSet<>(); // order is important!

retrieveDefaultContainersForComposite(link, elementsContainers, context);

Expand Down Expand Up @@ -482,7 +478,7 @@ private void retrieveDefaultContainersFromLocationSourceProperty(CatalogElementL
IProperty property = propertyContext.getProperties().getProperty(IReConstants.PROPERTY__LOCATION_SOURCE);
if (property != null) {
Object value = propertyContext.getCurrentValue(property);
if ((value != null) && (value instanceof EObject)) {
if (value instanceof EObject) {
elementsContainers.add((EObject) propertyContext.getCurrentValue(property));
}
}
Expand All @@ -493,7 +489,7 @@ private void retrieveDefaultContainersFromLocationSourceProperty(CatalogElementL
IProperty property = propertyContext.getProperties().getProperty(IReConstants.PROPERTY__LOCATION_TARGET);
if (property != null) {
Object value = propertyContext.getCurrentValue(property);
if ((value != null) && (value instanceof EObject)) {
if (value instanceof EObject) {
elementsContainers.add((EObject) propertyContext.getCurrentValue(property));
}
}
Expand All @@ -508,7 +504,7 @@ private void retrieveDefaultContainersFromSiblingLinks(CatalogElementLink link,
CatalogElement element = ReplicableElementHandlerHelper.getInstance(context).getInitialTarget(context);
Collection<CatalogElementLink> links = ReplicableElementHandlerHelper.getInstance(context).getElementsLinks(element);

Collection<EObject> siblings = new ArrayList<EObject>();
Collection<EObject> siblings = new ArrayList<>();

for (CatalogElementLink linkA : links) {
if ((linkA == null) || ((linkA.getOrigin() == null) || (linkA.getOrigin().getTarget() == null)) || (linkA.getOrigin().getTarget().eContainer() == null)) {
Expand All @@ -530,7 +526,7 @@ private void retrieveDefaultContainersFromSiblingLinks(CatalogElementLink link,
if (preferSameType) {
for (Iterator<EObject> it = siblings.iterator(); it.hasNext(); ) {
EObject next = it.next();
if (next.eClass() == link.getTarget().eClass()) {
if (link != null && next.eClass() == link.getTarget().eClass()) {
it.remove();
elementsContainers.add(next.eContainer());
}
Expand Down Expand Up @@ -623,7 +619,7 @@ public IRuleAttachment getRule(EObject target, IContext context) {
MappingPossibility mapping = ruleHandler.getApplicablePossibility(target);
if (mapping != null) {
IRule<?> rule = ruleHandler.getApplicablePossibility(target).getCompleteRule();
if ((rule != null) && (rule instanceof IRuleAttachment)) {
if (rule instanceof IRuleAttachment) {
arule = (IRuleAttachment) rule;
}
}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -99,7 +99,7 @@ public String getMessage() {
if ((candidateSize <= 1) || ((candidateSize > 1) && isMultiple)) {

for (String activityID : activitiesID) {
ActivityParameters activityParameters = workflowActivityParameters.getActivityParameters(activityID);
ActivityParameters activityParameters = workflowActivityParameters != null ? workflowActivityParameters.getActivityParameters(activityID) : null;
IStatus status = cadence(workflow_id, workflowElement_id, activityID, activityParameters, monitor);
if (status == null) {
// Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Activity : " + activityID + " has returned a null status."));
Expand Down Expand Up @@ -158,9 +158,7 @@ public IStatus cadence(final String workflow_id, final String workflowElement_id
monitor.subTask(activityName);
}

IStatus status = cadence(workflowElement, activityElement, activityParameters); // if is good candidate run it

return status;
return cadence(workflowElement, activityElement, activityParameters); // if is good candidate run it
}

private IStatus cadence(final IConfigurationElement workflowElement, final IConfigurationElement activityElement, final ActivityParameters activityParameters) {
Expand Down Expand Up @@ -211,5 +209,4 @@ private boolean matchParameters(IConfigurationElement workflowElement, ActivityP
public IConfigurationElement[] getWorkflowElementParameters(IConfigurationElement workflowElement) {
return workflowElement.getChildren(PARAMETER_DEFINITION);
}

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -35,9 +35,8 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredList;
import org.eclipse.ui.progress.WorkbenchJob;

import org.polarsys.capella.common.ui.toolkit.internal.StringMatcher;
import org.polarsys.capella.common.mdsofa.common.constant.ICommonConstants;
import org.polarsys.capella.common.ui.toolkit.internal.StringMatcher;

/**
* A composite widget which holds a list of elements for user selection. The elements are sorted alphabetically. Optionally, the elements can be filtered and
Expand Down Expand Up @@ -203,7 +202,7 @@ public boolean match(Object element) {

Label[] fLabels;

Vector<Image> fImages = new Vector<Image>();
Vector<Image> fImages = new Vector<>();

int[] fFoldedIndices;

Expand Down Expand Up @@ -353,7 +352,7 @@ public void setElements(Object[] elements) {
int length = fElements.length;
// fill labels
fLabels = new Label[length];
Set<Image> imageSet = new HashSet<Image>();
Set<Image> imageSet = new HashSet<>();
for (int i = 0; i != length; i++) {
String text = fLabelProvider.getText(fElements[i]);
Image image = fLabelProvider.getImage(fElements[i]);
Expand Down Expand Up @@ -544,7 +543,7 @@ public String getFilter() {
*/
public Object[] getFoldedElements(int index) {
if ((index < 0) || (index >= fFoldedCount)) {
return null;
return new Object[] {};
}
int start = fFoldedIndices[index];
int count = (index == fFoldedCount - 1) ? fFilteredCount - start : fFoldedIndices[index + 1] - start;
Expand Down Expand Up @@ -587,7 +586,9 @@ private int filter() {
if (((fFilter == null) || (fFilter.length() == 0)) && !fMatchEmptyString) {
return 0;
}
fFilterMatcher.setFilter(fFilter.trim(), fIgnoreCase, false);
if(fFilter != null) {
fFilterMatcher.setFilter(fFilter.trim(), fIgnoreCase, false);
}
int k = 0;
for (int i = 0; i != fElements.length; i++) {
if (fFilterMatcher.match(fElements[i])) {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -160,7 +160,7 @@ protected boolean checkState() {
result = false;
}

String txt = _textField.getText();
String txt = _textField != null ? _textField.getText() : "";
result = (txt.trim().length() > 0) || _emptyStringAllowed;

// Call hook for subclasses
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -86,8 +86,8 @@ public static void writeFile(File file, byte[] content) {
}
FileChannel channel = null;
// Try and open the resulting file.
try {
channel = new FileOutputStream(file).getChannel();
try (FileOutputStream fileOutputStream = new FileOutputStream(file)){
channel = fileOutputStream.getChannel();
// Write contents.
channel.write(ByteBuffer.wrap(content));
} catch (Exception exception) {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -60,7 +60,7 @@ public ArgumentAnalyzer(boolean strictMode) {

_strictMode = strictMode;

if (true == _strictMode) {
if (_strictMode) {
// We can not manage both unknown flags and ordered ones.
_unknownFlagAsError = true;
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ public void parse(String[] arguments) throws ArgumentAnalyzerException {
// Let's clean older result
_values.clear();

if ( true == _strictMode ) {
if (_strictMode) {
strictModeParsing(arguments);
} else {
defaultModeParsing(arguments);
Expand Down Expand Up @@ -232,7 +232,7 @@ protected boolean isFlagWithNameDefined(String flagName) {
* @return a {@link List} of flagId which are named flagName
*/
protected List<String> getFlagIdPerName(String flagName) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();

for (Entry<String, Flag> entry : _flags.entrySet()) {
if (entry.getValue().getName().equals(flagName)) {
Expand All @@ -248,8 +248,8 @@ protected void clearResult() {
}

protected void init() {
_flags = new LinkedHashMap<String, Flag>();
_values = new LinkedHashMap<String, List<String>>();
_flags = new LinkedHashMap<>();
_values = new LinkedHashMap<>();
}

/**
Expand Down Expand Up @@ -287,7 +287,7 @@ protected void defaultModeParsing(String[] arguments) throws ArgumentAnalyzerExc
i += args.size();

} else { // Undefined flag
if ( _unknownFlagAsError == true ) {
if (_unknownFlagAsError) {
// We directly exit on the first unknown flag.
// It will be quickly raised to too incomprehensible in case of flag with arguments...
throw new ArgumentAnalyzerException(
Expand All @@ -305,14 +305,14 @@ protected void defaultModeParsing(String[] arguments) throws ArgumentAnalyzerExc

Iterator<Entry<String, Flag>> it = _flags.entrySet().iterator();
String currentFlagId = null;
List<String> missingFlags = new ArrayList<String>();
List<String> missingFlags = new ArrayList<>();

while (it.hasNext()) {
Entry<String, Flag> entry = it.next();
currentFlagId = entry.getKey();
flag = entry.getValue();
if (
flag.isMandatory() == true &&
flag.isMandatory() &&
_values.containsKey(currentFlagId) == false
) {
missingFlags.add(currentFlagId);
Expand All @@ -323,7 +323,7 @@ protected void defaultModeParsing(String[] arguments) throws ArgumentAnalyzerExc
throw new ArgumentAnalyzerException(
NLS.bind(
Messages.mandatoryFlagNotFound,
new Object[] {flag.getName(), currentFlagId}
new Object[] {flag != null ? flag.getName() : "", currentFlagId}
)
);
}
Expand Down Expand Up @@ -400,7 +400,7 @@ protected void strictModeParsing(String[] arguments) throws ArgumentAnalyzerExce
*/
protected ArrayList<String> getArgumentData(String currentFlagId, String[] arguments, int currentIndex ) throws ArgumentAnalyzerException {

ArrayList<String> args = new ArrayList<String>();
ArrayList<String> args = new ArrayList<>();

int i = currentIndex + 1;

Expand Down Expand Up @@ -432,5 +432,4 @@ protected ArrayList<String> getArgumentData(String currentFlagId, String[] argum

return args;
}

}

0 comments on commit 650f8ba

Please sign in to comment.