Skip to content

Commit

Permalink
dsldevkit#22: SCA configuration - final PMD cleanup
Browse files Browse the repository at this point in the history
 - Cleanup less trivial PMD warnings

Issue: dsldevkit#22
  • Loading branch information
[email protected] authored and [email protected] committed Dec 21, 2017
1 parent 6abd547 commit 314500b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected void internalCreateChildren(final DocumentRootNode parentNode, final E
* @param modelElement
* a valid {@link EObject}
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "PMD.NPathComplexity"})
@Override
protected void internalCreateChildren(final IOutlineNode parentNode, final EObject modelElement) {
// from all structural features, select only those which are set and retrieve the text location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Objects;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.AbstractRule;
Expand Down Expand Up @@ -298,7 +299,7 @@ public int getColumn(final ExtendedLineEntry entry) {
public int getOffset(final ExtendedLineEntry entry) {
int column = 0;
for (ExtendedLineEntry lineEntry : getEntries()) {
if (entry == lineEntry) {
if (Objects.equals(entry, lineEntry)) {
break;
}
int charactersInLastLine = lineEntry.countCharactersInLastLine();
Expand Down Expand Up @@ -393,7 +394,8 @@ public int getAbsoluteLineLength(final ExtendedLineEntry entry) {
*/
private boolean existsIndirectColumnAlignedPredecessor(final ExtendedLineEntry entry, final ExtendedLineEntry previousEntry) {
for (ExtendedLineEntry lineEntry : lineEntries) {
if (lineEntry != previousEntry && lineEntry != entry && (lineEntry.isFixedLocatorClosing() || lineEntry.isFixedLocatorOpening())) {
if (!Objects.equals(lineEntry, previousEntry) && !Objects.equals(lineEntry, entry)
&& (lineEntry.isFixedLocatorClosing() || lineEntry.isFixedLocatorOpening())) {
return true;
}
}
Expand Down Expand Up @@ -596,7 +598,7 @@ protected ExtendedLineEntry getLastBreakableLineEntry() {
public ExtendedLineEntry getPrecedingLineEntry(final ExtendedLineEntry entry) {
ExtendedLineEntry result = null;
for (ExtendedLineEntry le : getEntries()) {
if (le != entry) {
if (!Objects.equals(le, entry)) {
result = le;
} else {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static Set<URI> getAllURIs(final IResourceDescriptions descriptions) {
* match policy
* @return An {@link Iterable} of all {@link IResourceDescription}s that reference any of the objects.
*/
@SuppressWarnings("PMD.NPathComplexity")
public static Iterable<IResourceDescription> findReferencesToResources(final IResourceDescriptions descriptions, final Set<IResourceDescription> targetResources, final ReferenceMatchPolicy matchPolicy) {
if (targetResources.isEmpty()) {
return ImmutableSet.of();
Expand All @@ -84,25 +85,22 @@ public static Iterable<IResourceDescription> findReferencesToResources(final IRe
}
}

return Iterables.filter(descriptions.getAllResourceDescriptions(), new Predicate<IResourceDescription>() {
@Override
public boolean apply(final IResourceDescription input) {
if (matchNames) {
for (QualifiedName name : input.getImportedNames()) {
if (exportedNames.contains(name.toLowerCase())) { // NOPMD
return true;
}
return Iterables.filter(descriptions.getAllResourceDescriptions(), input -> {
if (matchNames) {
for (QualifiedName name : input.getImportedNames()) {
if (exportedNames.contains(name.toLowerCase())) { // NOPMD
return true;
}
}
if (matchPolicy.includes(ReferenceMatchPolicy.REFERENCES)) {
for (IReferenceDescription ref : input.getReferenceDescriptions()) {
if (targetUris.contains(ref.getTargetEObjectUri().trimFragment())) {
return true;
}
}
if (matchPolicy.includes(ReferenceMatchPolicy.REFERENCES)) {
for (IReferenceDescription ref : input.getReferenceDescriptions()) {
if (targetUris.contains(ref.getTargetEObjectUri().trimFragment())) {
return true;
}
}
return false;
}
return false;
});
}

Expand All @@ -117,6 +115,7 @@ public boolean apply(final IResourceDescription input) {
* match policy
* @return all resources containing outgoing references to one of the objects
*/
@SuppressWarnings("PMD.NPathComplexity")
public static Iterable<IResourceDescription> findExactReferencingResources(final IResourceDescriptions descriptions, final Set<IEObjectDescription> targetObjects, final ReferenceMatchPolicy matchPolicy) {
if (targetObjects.isEmpty()) {
return ImmutableSet.of();
Expand All @@ -134,25 +133,22 @@ public static Iterable<IResourceDescription> findExactReferencingResources(final
}
}

return Iterables.filter(descriptions.getAllResourceDescriptions(), new Predicate<IResourceDescription>() {
@Override
public boolean apply(final IResourceDescription input) {
if (matchPolicy.includes(ReferenceMatchPolicy.IMPORTED_NAMES) || matchPolicy.includes(ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
for (QualifiedName name : input.getImportedNames()) {
if (exportedNames.contains(name)) {
return true;
}
return Iterables.filter(descriptions.getAllResourceDescriptions(), input -> {
if (matchPolicy.includes(ReferenceMatchPolicy.IMPORTED_NAMES) || matchPolicy.includes(ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
for (QualifiedName name : input.getImportedNames()) {
if (exportedNames.contains(name)) {
return true;
}
}
if (matchPolicy.includes(ReferenceMatchPolicy.REFERENCES)) {
for (IReferenceDescription ref : input.getReferenceDescriptions()) {
if (targetUris.contains(ref.getTargetEObjectUri())) {
return true;
}
}
if (matchPolicy.includes(ReferenceMatchPolicy.REFERENCES)) {
for (IReferenceDescription ref : input.getReferenceDescriptions()) {
if (targetUris.contains(ref.getTargetEObjectUri())) {
return true;
}
}
return false;
}
return false;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ContainerBasedScope(final String id, final IScope parent, final IContaine
}

// Using QualifiedName#toLowerCase() not String#toLowerCase()
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
@SuppressWarnings({"PMD.UseLocaleWithCaseConversions", "PMD.NPathComplexity"})
@Override
public synchronized IEObjectDescription getSingleElement(final QualifiedName name) {
if (nameFunctions != null && nameFunctions.contains(NameFunctions.exportNameFunction())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public static String getParsedString(final EObject object, final String featureN
* @return the parsed string from the node model
*/
public static String getParsedStringUnchecked(final EObject object, final EStructuralFeature feature, final boolean convert) {
for (INode node : NodeModelUtils.findNodesForFeature(object, feature)) {
INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);
if (node != null) {
if (convert) {
final LazyLinkingResource res = (LazyLinkingResource) object.eResource();
EObject grammarElement = node.getGrammarElement();
Expand Down

0 comments on commit 314500b

Please sign in to comment.