-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
support of noClassPath in getFields #780
Conversation
…hen the parent class is not found in noClassPath-Mode
thanks for this pull request! this changes the intended fail-fast semantics of |
Something like that? @Override
public Collection<CtFieldReference<?>> getAllFields() {
CtType<?> t = getDeclaration();
try {
if (t == null) {
return RtHelper.getAllFields(getActualClass(), getFactory());
} else {
return t.getAllFields();
}
} catch (SpoonClassNotFoundException cnfe) {
return handleParentNotFound(cnfe);
}
}
private Collection<CtFieldReference<?>> handleParentNotFound(SpoonClassNotFoundException cnfe) {
String msg = "cannot load class: " + getQualifiedName() + " with class loader "
+ Thread.currentThread().getContextClassLoader();
if (getFactory().getEnvironment().getNoClasspath()) {
// should not be thrown in 'noClasspath' environment (#775)
Launcher.LOGGER.warn(msg);
return Collections.emptyList();
} else {
throw cnfe;
}
} Maybe you have a suggestion for a better message name. Cheers. |
Furthermore getDeclaredFields has the same behaviour and maybe needs a try-catch too. But now getXXXFields will always return an empty list even if 'Foo' has a field. public class Foo extends Unknown {
private String s;
...
} |
exactly. should the try/catch be around the RtHelper call directly? |
Is it worth merging now? |
@@ -53,11 +55,17 @@ public void test() throws Exception { | |||
} | |||
assertNull(superclass.getDeclaration()); | |||
|
|||
Collection<CtFieldReference<?>> allFields = superclass.getAllFields(); | |||
System.out.println(allFields); | |||
System.out.println(superclass.getDeclaredFields()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these sout?
I incorporated all of your feedback. Sorry, I was in a hurry last time. |
Thanks @arturbosch for your last commit but it seems that you removed your call to Can you add an assert on this call to show we don't throw anymore an exception? After that, we'll merge your PR. |
Done. Is the comment ok or should I remove it ;) ? |
Thanks @arturbosch! :) |
…hen the parent class is not found in noClassPath-Mode
This tries to fix #775.