Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PMD Warning ReturnEmptyCollectionRatherThanNull
Browse files Browse the repository at this point in the history
rubenporras committed Nov 9, 2023
1 parent 8aae7a7 commit ffe114c
Showing 12 changed files with 23 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -26,6 +26,6 @@ public String getQualifiedCatalogName() {

@Override
public final ImmutableMap<String, String> getIssueCodeToLabelMap() {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
}
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@
import java.util.stream.Stream;

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl;
import com.avaloq.tools.ddk.check.runtime.registry.ICheckValidatorRegistry;
@@ -62,7 +62,7 @@ public String getLabel(final String issueCode) {

// Get the label
final String label = issueCodeToLabelMap.get().get(issueCode);

return label;
}

@@ -99,7 +99,7 @@ private static ImmutableMap<String, String> getIssueCodeToLabelMap(final ICheckV
return validator.getIssueCodeToLabelMap();
} catch (AbstractMethodError e) {
LOGGER.warn(String.format("Method not found: %1$s.getIssueCodeToLabelMap(). To fix this problem, recompile and deploy %1$s.", validator.getQualifiedCatalogName())); //$NON-NLS-1$
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
}

Original file line number Diff line number Diff line change
@@ -25,25 +25,21 @@
*/
public class NullXtextTargetPlatform implements IXtextTargetPlatform {

/** {@inheritDoc} */
@Override
public IResourceDescriptionsData getIResourceDescriptionsData() {
return new NullResourceDescriptionsData();
}

/** {@inheritDoc} */
@Override
public void open(final boolean clean, final IProgressMonitor monitor) {
// Nothing to do
}

/** {@inheritDoc} */
@Override
public void close(final IProgressMonitor monitor) {
// Nothing to do.
}

/** {@inheritDoc} */
@Override
public IIssueStore getIssueStore() {
return null;
@@ -59,13 +55,11 @@ public IBinaryModelStore getBinaryModelStore() {
return null;
}

/** {@inheritDoc} */
@Override
public Map<String, String> getMetadata(final Collection<String> keys, final IProgressMonitor monitor) {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}

/** {@inheritDoc} */
@Override
public void setMetadata(final Map<String, String> options) {
// Nothing to do.
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ protected Map<Object, ArrayList<String>> getHoverMap() {
if (obj instanceof Map<?, ?>) {
return (Map<Object, ArrayList<String>>) obj;
} else {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
}

Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public abstract class AbstractLabelingTest extends AbstractXtextTest {
* @return a list of pairs with the expected {@link ENamedElement} and the corresponding label string
*/
// TODO : make abstract when refactoring all tests (and change from Object to ENamedElement everywhere in this class). remove the suppresswarnings
@SuppressWarnings("PMD.EmptyMethodInAbstractClassShouldBeAbstract")
@SuppressWarnings({"PMD.EmptyMethodInAbstractClassShouldBeAbstract", "PMD.ReturnEmptyCollectionRatherThanNull"})
protected List<Pair<ENamedElement, String>> getExpectedElementLabels() {
return null;
}
@@ -87,7 +87,7 @@ private ILabelProvider getLabelProvider() {
* @return directory of semantic nodes indexed by the class of the represented semantic model node
*/

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "PMD.ReturnEmptyCollectionRatherThanNull"})
private Map<Object, ArrayList<String>> getLabelMap() {
Object obj = getTestInformation().getTestObject(AbstractLabelingTest.class);
if (obj instanceof Map<?, ?>) {
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public abstract class AbstractOutlineTest extends AbstractXtextEditorTest {
*/
// TODO : make this abstract once all tests have been refactored (and change all Object to ENamedElement in this class)
protected List<? extends ENamedElement> getExpectedElements() {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}

/**
@@ -69,7 +69,7 @@ public void testOutline() {
*
* @return directory of outline nodes indexed by the class of the represented semantic model node
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "PMD.ReturnEmptyCollectionRatherThanNull"})
private Map<Object, ArrayList<IOutlineNode>> getOutlineMap() {
Object obj = getTestInformation().getTestObject(IOutlineNode.class);
if (obj instanceof Map<?, ?>) {
Original file line number Diff line number Diff line change
@@ -402,24 +402,22 @@ private void init() {
size = 0;
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public Collection<T> get(final QualifiedName name) {
if (name.isEmpty()) {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
SegmentNode result = root.find(name, 0, true);
if (result != null && result.values != null) {
hits++;
return (Collection<T>) Arrays.asList(result.values);
} else {
misses++;
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
}

/** {@inheritDoc} */
@Override
public void removeMappings(final T value) {
root.accept(new Visitor() {
@@ -434,19 +432,16 @@ public void visit(final SegmentNode node) {
});
}

/** {@inheritDoc} */
@Override
public void clear() {
init();
}

/** {@inheritDoc} */
@Override
public Collection<T> get(final QualifiedNamePattern pattern, final boolean excludeDuplicates) {
return root.matches(pattern.lowerInclusive(), 0, root.find(pattern.upperExclusive(), 0, false), pattern.isRecursivePattern(), excludeDuplicates);
}

/** {@inheritDoc} */
@Override
public void put(final QualifiedName name, final T value) {
if (name == null || value == null) {
@@ -458,7 +453,6 @@ public void put(final QualifiedName name, final T value) {
root.merge(name, 0, values);
}

/** {@inheritDoc} */
@Override
public void putAll(final QualifiedName name, final Collection<T> values) {
if (name == null || values == null || values.contains(null)) {
@@ -469,7 +463,6 @@ public void putAll(final QualifiedName name, final Collection<T> values) {
root.merge(name, 0, values.toArray(ArrayUtils.newArray(values.size())));
}

/** {@inheritDoc} */
@Override
public void remove(final QualifiedName name, final T value) {
SegmentNode node = root.find(name, 0, true);
Original file line number Diff line number Diff line change
@@ -36,19 +36,16 @@ public class TreeSetLookup<T> implements QualifiedNameLookup<T> {
private long hits;
private long misses;

/** {@inheritDoc} */
@Override
public void putAll(final QualifiedName name, final Collection<T> values) {
lookupMap.put(name, ArrayUtils.addAll(lookupMap.get(name), values.toArray(ArrayUtils.newArray(values.size()))));
}

/** {@inheritDoc} */
@Override
public void clear() {
lookupMap.clear();
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public Collection<T> get(final QualifiedName name) {
@@ -58,11 +55,10 @@ public Collection<T> get(final QualifiedName name) {
return (Collection<T>) Lists.newArrayList(values);
} else {
misses++;
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
}

/** {@inheritDoc} */
@Override
public Collection<T> get(final QualifiedNamePattern pattern, final boolean excludeDuplicates) {
@SuppressWarnings("unchecked")
@@ -75,7 +71,6 @@ public Collection<T> get(final QualifiedNamePattern pattern, final boolean exclu
return result;
}

/** {@inheritDoc} */
@Override
public void removeMappings(final T value) {
Iterator<Map.Entry<QualifiedName, Object[]>> iter = lookupMap.entrySet().iterator();
@@ -96,13 +91,11 @@ public void removeMappings(final T value) {
}
}

/** {@inheritDoc} */
@Override
public void put(final QualifiedName name, final T value) {
lookupMap.put(name, ArrayUtils.add(lookupMap.get(name), value));
}

/** {@inheritDoc} */
@Override
public void remove(final QualifiedName name, final T value) {
Object[] values = lookupMap.get(name);
Original file line number Diff line number Diff line change
@@ -135,8 +135,8 @@ protected boolean isInterestedIn(final Delta delta) {
*
* @return a set of file extensions or <code>null</code> if all resources are interesting
*/
protected Set<String> getInterestingExtensions() { // NOPMD
return null;
protected Set<String> getInterestingExtensions() {
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}

@Override
@@ -467,8 +467,8 @@ public ResourceDescriptionDelta createDelta(final IResourceDescription oldState,
*
* @return all extensions ({@code null})
*/
protected static ImmutableSet<String> all() { // NOPMD
return null;
protected static ImmutableSet<String> all() {
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}

/**
Original file line number Diff line number Diff line change
@@ -51,7 +51,6 @@ public abstract class AbstractResourceDescriptionStrategy extends DefaultResourc
@Inject(optional = true)
private IFingerprintComputer fingerprintComputer;

/** {@inheritDoc} */
@Override
public boolean createEObjectDescriptions(final EObject from, final IAcceptor<IEObjectDescription> acceptor) {
final IQualifiedNameProvider nameProvider = getQualifiedNameProvider();
@@ -206,7 +205,6 @@ protected IReferenceDescription createReferenceDescription(final EObject owner,
return new ReferenceDescription(owner, target, eReference, exportedContainerURI, indexInList);
}

/** {@inheritDoc} */
protected boolean isIndexable(final EObject from, final EReference eReference) {
return !eReference.isContainment() && !eReference.isContainer();
}
@@ -234,7 +232,8 @@ protected boolean isResolvedAndExternal(final EObject from, final EReference eRe
* @return the set of types, or {@code null} if all types are allowed (or if no information available).
*/
public Set<EClass> getExportedEClasses(final Resource resource) {
return null; // TODO: once ASMD is regenerated, make this operation abstract.
// TODO: once ASMD is regenerated, make this operation abstract.
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}

}
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ private void emitTrailingTokens(final INode node) {
*/
private List<INode> getHiddenNodesBetween(final INode from, final INode to) {
if (from == null && to == null) {
return null;
return null;// NOPMD ReturnEmptyCollectionRatherThanNull
}

List<INode> out;
@@ -317,7 +317,7 @@ private List<INode> getHiddenNodesBetween(final INode from, final INode to) {
}

if (out.isEmpty()) {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
} else {
return filterNodesOfDeletedElements(out, deletedSemanticElements);
}
Original file line number Diff line number Diff line change
@@ -106,11 +106,11 @@ public static Object[] addAll(final Object[] array, final Object[] values) {
*/
public static Object[] remove(final Object[] array, final Object value) {
if (array == null) {
return null;
return null; // NOPMD ReturnEmptyCollectionRatherThanNull
}
int i = find(array, value);
if (i == 0 && array.length == 1) {
return null;
return null;// NOPMD ReturnEmptyCollectionRatherThanNull
}
if (i >= 0) {
// Found it: remove value. i is guaranteed to be < array.length here.

0 comments on commit ffe114c

Please sign in to comment.