Skip to content

Commit

Permalink
Fix qulice warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kniazkov committed Oct 12, 2022
1 parent a2291ce commit 093b9b4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*
* @since 0.1.5
*/
@SuppressWarnings("PMD.TooManyMethods")
public class MatcherClassFiller {
/**
* The 'String' type name.
Expand Down Expand Up @@ -585,14 +586,15 @@ private void createMagicNumber(final String brief, final String name, final int
* @return Source code
*/
private String createExtractorWithTypedHoles() {
final StringBuilder extractor = new StringBuilder();
llist = true;
extractor.append("final LinkedList<Node> batch = new LinkedList<>(node.getChildrenList());\n");
final StringBuilder extractor = new StringBuilder(128);
this.llist = true;
extractor.append(
"final LinkedList<Node> batch = new LinkedList<>(node.getChildrenList());\n"
);
for (final Parameter parameter : this.descriptor.getParameters()) {
if (parameter instanceof Hole) {
extractor.append(this.formatIteratedHoleExtractor((Hole) parameter));
}
else if (parameter instanceof Descriptor) {
} else if (parameter instanceof Descriptor) {
final String subclass = this.generator.generate((Descriptor) parameter);
final List<String> code = Arrays.asList(
"if (result && !batch.isEmpty()) {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package org.uast;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.cqfn.astranaut.core.Matcher;
Expand Down Expand Up @@ -53,14 +53,14 @@ public final class Matcher0 implements Matcher {
private static final int FIRST_HOLE_ID = 1;

/**
* The number of the second hole.
* The type of the first hole.
*/
private static final int SECOND_HOLE_ID = 2;
private static final String FIRST_HOLE_TYPE = "CCC";

/**
* The index of the first child.
* The number of the second hole.
*/
private static final int FIRST_CHILD_ID = 2;
private static final int SECOND_HOLE_ID = 2;

/**
* Constructor.
Expand All @@ -72,22 +72,33 @@ public final class Matcher0 implements Matcher {
public boolean match(final Node node,
final Map<Integer, List<Node>> children,
final Map<Integer, String> data) {
final boolean result = node.belongsToGroup(Matcher0.EXPECTED_TYPE)
&& Matcher1.INSTANCE.match(node.getChild(0), children, data);
boolean result = node.belongsToGroup(Matcher0.EXPECTED_TYPE);
final LinkedList<Node> batch = new LinkedList<>(node.getChildrenList());
if (result && !batch.isEmpty()) {
result = Matcher1.INSTANCE.match(batch.pollFirst(), children, data);
} else {
result = false;
}
if (result) {
final int count = node.getChildCount();
final List<Node> list = new ArrayList<>(count - 1);
for (int index = 1; index < count; index = index + 1) {
final Node child = node.getChild(index);
if ("CCC".equals(child.getTypeName())) {
final List<Node> list = new LinkedList<>();
while (!batch.isEmpty()) {
final Node child = batch.pollFirst();
if (Matcher0.FIRST_HOLE_TYPE.equals(child.getTypeName())) {
list.add(child);
} else {
batch.addFirst(child);
break;
}
}
children.put(Matcher0.FIRST_HOLE_ID, list);
}
if (result && !batch.isEmpty()) {
children.put(
Matcher0.SECOND_HOLE_ID,
Collections.singletonList(node.getChild(Matcher0.FIRST_CHILD_ID))
Collections.singletonList(batch.pollFirst())
);
} else {
result = false;
}
return result;
}
Expand Down

0 comments on commit 093b9b4

Please sign in to comment.