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

WIP refactor: code inspection - fix redundant local variable #2377

Closed
wants to merge 7 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ private static class QueryDriver implements CtScannerListener {

@Override
public ScanningMode enter(CtElement element) {
if (ignoredParent != null && element instanceof CtElement) {
CtElement ele = (CtElement) element;
if (ele.hasParent(ignoredParent)) {
return ScanningMode.SKIP_ALL;
}
if (element.hasParent(ignoredParent)) {
return ScanningMode.SKIP_ALL;
}
if (element instanceof CtType) {
nrOfNestedLocalClasses++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ private SnippetCompilationHelper() { }
private static final String WRAPPER_CLASS_NAME = "Wrapper";
private static final String WRAPPER_METHOD_NAME = "wrap";

public static void compileAndReplaceSnippetsIn(CtType<?> c) {
Factory f = c.getFactory();
CtType<?> workCopy = c;
public static void compileAndReplaceSnippetsIn(CtType<?> workType) {
Factory f = workType.getFactory();
Set<ModifierKind> backup = EnumSet.noneOf(ModifierKind.class);
backup.addAll(workCopy.getModifiers());
workCopy.removeModifier(ModifierKind.PUBLIC);
backup.addAll(workType.getModifiers());
workType.removeModifier(ModifierKind.PUBLIC);

try {
build(f, workCopy.toString());
build(f, workType.toString());
} finally {
// restore modifiers
c.setModifiers(backup);
workType.setModifiers(backup);
}
}

Expand Down Expand Up @@ -154,5 +153,4 @@ private static String createWrapperContent(final CtElement element, final Factor

return contents;
}

}
9 changes: 4 additions & 5 deletions src/main/java/spoon/support/visitor/ClassTypingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,18 +569,17 @@ private boolean isSubTypeByActualTypeArguments(CtTypeReference<?> superTypeRef,
//the raw type or not a generic type. Arguments are ignored in sub type detection
return true;
}
List<CtTypeReference<?>> subTypeArgs = expectedSuperTypeArguments;
if (subTypeArgs.isEmpty()) {
if (expectedSuperTypeArguments.isEmpty()) {
//the raw type or not a generic type
return true;
}
if (subTypeArgs.size() != superTypeArgs.size()) {
if (expectedSuperTypeArguments.size() != superTypeArgs.size()) {
//the number of arguments is not same - it should not happen ...
return false;
}
for (int i = 0; i < subTypeArgs.size(); i++) {
for (int i = 0; i < expectedSuperTypeArguments.size(); i++) {
CtTypeReference<?> superArg = superTypeArgs.get(i);
CtTypeReference<?> subArg = subTypeArgs.get(i);
CtTypeReference<?> subArg = expectedSuperTypeArguments.get(i);
if (isSubTypeArg(subArg, superArg) == false) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/spoon/generating/RoleHandlersGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ private CtTypeReference<?> fixValueType(CtTypeReference<?> valueType) {
}

private CtType<?> getTemplate(String templateQName) {
CtType<?> template = getFactory().Class().get(templateQName);
return template;
return getFactory().Class().get(templateQName);
}

private File file(String name) {
Expand Down