Skip to content

Commit

Permalink
use equivalent methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tenax66 committed Jul 31, 2023
1 parent 993d5a9 commit 07d0038
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/java/spoon/experimental/SpoonifierVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ && isLeafTypeReference(element.getParent())) {
} else if (o instanceof Set) {
handleContainer(element, parent, elementRoleInParent, variableName, "Set");
} else {
result.append(printTabs() + parentName.peek() + ".setValueByRole(CtRole." + elementRoleInParent.name() + ", " + variableName + ");\n");
result.append(printTabs() + parentName.getFirst() + ".setValueByRole(CtRole." + elementRoleInParent.name() + ", " + variableName + ");\n");
}
}

parentName.push(variableName);
roleContainer.push(new HashMap<>());
parentName.addFirst(variableName);
roleContainer.addFirst(new HashMap<>());
}

private String getVariableName(String className) {
Expand Down Expand Up @@ -189,12 +189,12 @@ private void handleContainer(CtElement element, CtElement parent, CtRole element
}

String containerName;
if (!roleContainer.peek().containsKey(elementRoleInParent)) {
containerName = parentName.peek() + elementRoleInParent.toString().substring(0, 1).toUpperCase() + elementRoleInParent.toString().substring(1) + "s";
roleContainer.peek().put(elementRoleInParent, containerName);
if (!roleContainer.getFirst().containsKey(elementRoleInParent)) {
containerName = parentName.getFirst() + elementRoleInParent.toString().substring(0, 1).toUpperCase() + elementRoleInParent.toString().substring(1) + "s";
roleContainer.getFirst().put(elementRoleInParent, containerName);
result.append(printTabs() + container + " " + containerName + " = new " + concreteClass + "();\n");
} else {
containerName = roleContainer.peek().get(elementRoleInParent);
containerName = roleContainer.getFirst().get(elementRoleInParent);
}

if (container.equals("Map")) {
Expand Down Expand Up @@ -223,20 +223,20 @@ public void exit(CtElement element) {
&& isLeafTypeReference(element.getParent())) {
return;
}
if (!roleContainer.peek().isEmpty()) {
for (CtRole role: roleContainer.peek().keySet()) {
String variableName = roleContainer.peek().get(role);
if (!roleContainer.getFirst().isEmpty()) {
for (CtRole role: roleContainer.getFirst().keySet()) {
String variableName = roleContainer.getFirst().get(role);
result.append(printTabs())
.append(parentName.peek())
.append(parentName.getFirst())
.append(".setValueByRole(CtRole.")
.append(role.name())
.append(", ")
.append(variableName)
.append(");\n");
}
}
parentName.pop();
roleContainer.pop();
parentName.removeFirst();
roleContainer.removeFirst();
tabs--;
}

Expand Down

0 comments on commit 07d0038

Please sign in to comment.