Need to migrate your PHP legacy system to a new framework quickly and without breaking the bank? Get in touch—I'd be happy to help.
package com.example.config;
import com.example.RuleList;
import com.example.SetList;
import com.example.rules.RuleInterface;
import com.example.sets.SetInterface;
import java.util.List;
public class JavaUpgraderConfig implements JavaUpgraderConfigInterface {
@Override
public List addSets() {
return List.of(SetList.NAMING_SET);
}
@Override
public List addRules() {
return List.of(RuleList.DEAD_CODE);
}
}
package com.example.rules.naming;
import com.example.model.UpgraderFileModel;
import com.example.rules.RuleInterface;
import com.github.javaparser.ast.body.FieldDeclaration;
public class ConstantNameToUpperSnakeCaseRule implements RuleInterface {
@Override
public void execute(UpgraderFileModel fileModel) {
fileModel.getAst().findAll(FieldDeclaration.class).forEach(fieldDeclaration -> {
if (fieldDeclaration.isFinal()) {
fieldDeclaration.getVariables().forEach(variable -> {
String oldName = variable.getNameAsString();
String newName = convertToUpperCase(oldName);
variable.setName(newName);
});
}
});
}
private String convertToUpperCase(String input) {
return input.toUpperCase();
}
@Override
public String getDescription() {
return "Converts constant names from snake_case to upper snake case";
}
@Override
public String getName() {
return "ConstantNameToUpperCaseConverter";
}
@Override
public String getBeforeState() {
return """
public class Example {
public static final int my_constant_value = 42;
}
""";
}
@Override
public String getAfterState() {
return """
public class Example {
public static final int MY_CONSTANT_VALUE = 42;
}
""";
}
}