Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #1232 Enum revivers and unused imports #1238

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
}
boolean containsExtensions = false;
ArrayList<List<CodegenProperty>> group = new ArrayList<List<CodegenProperty>>();
group.add(model.allVars);
group.add(model.vars);
group.add(model.requiredVars);
group.add(model.optionalVars);
Expand Down Expand Up @@ -632,6 +633,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
}
boolean nonObjectDefinition = false;
ArrayList<List<CodegenProperty>> group = new ArrayList<List<CodegenProperty>>();
group.add(model.allVars);
group.add(model.vars);
group.add(model.requiredVars);
group.add(model.optionalVars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,32 +426,33 @@ public RemoveUnusedImports() {
@Override public String formatFragment(String fragment) {
//Retrieve all the imported classes
List<String> allMatches = new ArrayList<String>();
Matcher m = Pattern.compile("import\\s\\{\\s?([A-z]+)\\s?\\}").matcher(fragment);
while (m.find()) {
allMatches.add(m.group(1));
Matcher importLinesMatcher = Pattern.compile("import\\s\\{(.*)}.*;").matcher(fragment);
while (importLinesMatcher.find()) {
Matcher importsMatcher = Pattern.compile("(\\w+)").matcher(importLinesMatcher.group(1));
while (importsMatcher.find()) {
allMatches.add(importsMatcher.group(1));
}
}
//For each class check if the import is used
ListIterator<String> litr = allMatches.listIterator();
while (litr.hasNext()) {
String importedClass = litr.next();
int count =0;
//Looking if the import is used in the fragment
Matcher m2 = Pattern.compile("^((?!\\s*import|\\s*\\*|\\/\\*))(.*[^\\w\\/]"+importedClass+"[^\\w\\/])",
Matcher m2 = Pattern.compile("^(?!(?:\\s*import\\s?\\{))(?:.*\\W)?"+ importedClass + "[^\\w\\/]",
Pattern
.MULTILINE)
.matcher
(fragment);
while (m2.find()) {
count++;
}
if (count == 0) {
if (!m2.find()) {
//Import unused found, removing it
fragment = Pattern.compile("^(\\s*import\\s\\{\\s?"+importedClass+"\\s*}[^;]*;?\\r?\\n?)",
Pattern.MULTILINE)
.matcher(fragment).replaceAll("");
fragment = Pattern.compile("(.*import\\s\\{(?:.*\\W)?)" + importedClass +",?\\s*(\\W.*)")
.matcher(fragment)
.replaceAll("$1$2");
}
}
return fragment;
//If an import is empty, remove it
return Pattern.compile("import\\s\\{(\\s,?)*}\\sfrom\\s.*;\n").matcher(fragment).replaceAll("");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ export function revive{{classname}}<T extends {{classname}} = {{classname}}>(dat
{{#allVars}}
{{^isPrimitiveType}}
{{#complexType}}
{{^isEnum}}
{{^isEnumRef}}
{{#isMap}}
{{#vendorExtensions}}
{{^nonObjectDefinition}}
Expand All @@ -145,8 +143,6 @@ export function revive{{classname}}<T extends {{classname}} = {{classname}}>(dat
{{/vendorExtensions}}
{{/isArray}}
{{/isMap}}
{{/isEnumRef}}
{{/isEnum}}
{{/complexType}}
{{^complexType}}
{{^isEnum}}
Expand Down