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

add override method which don't try to load the class in the FastClasspathScanner #6

Closed
He-Pin opened this issue Mar 31, 2015 · 6 comments

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Mar 31, 2015

like this

    public FastClasspathScanner matchClassesWithAnnotation(final Class<?> annotation,
            final ClassAnnotationMatchProcessor classAnnotationMatchProcessor) {
        if (!annotation.isAnnotation()) {
            throw new IllegalArgumentException("Class " + annotation.getName() + " is not an annotation");
        }
        classMatchers.add(new ClassMatcher() {
            @Override
            public void lookForMatches() {
                // For all classes with the given annotation
                for (String classWithAnnotation : classGraphBuilder.getClassesWithAnnotation(annotation.getName())) {
                    try {
                        // Load class
                        Class<?> klass = Class.forName(classWithAnnotation);

                        // Process match
                        classAnnotationMatchProcessor.processMatch(klass);

                    } catch (ClassNotFoundException | NoClassDefFoundError e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        return this;
    }

for the line here

                        // Load class
                        Class<?> klass = Class.forName(classWithAnnotation);

we may provide a new type of processor with just accept string.

with this,we may don't need to provide method which allow us to specify the classloader.

@He-Pin
Copy link
Contributor Author

He-Pin commented Mar 31, 2015

and theforNamemethod call will cause the class been initialized ,which may no what we want

@lukehutch
Copy link
Member

I'm all for not loading classes unless absolutely necessary. But what will you do with a class, if it's not to load it eventually? Are you saying you just want a list of strings back of matching fully-qualified class names, and then you'll decide yourself whether to load them or not?

lukehutch added a commit that referenced this issue Apr 1, 2015
classloader to be called. Thanks to hepin1989. Closes issue #6.
@lukehutch
Copy link
Member

Fixed, please see the version I just pushed. Thanks for the suggestion!

@He-Pin
Copy link
Contributor Author

He-Pin commented Apr 1, 2015

@lukehutch yes,I may want to load but don't initialized it.another issue I will check when I am free is that,currently,this library could not find the classpath,if I am using sbt or package the classpath in a classpath.jar.

thanks :P

@lukehutch
Copy link
Member

Hi @hepin1989, this library should be able to scan within JAR files, but if it's not working, please narrow down the problem and open another bug. Thanks!

@He-Pin
Copy link
Contributor Author

He-Pin commented Apr 1, 2015

@lukehutch will later :),thanks too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants