0

I was trying to write a customized checkstyle check for indentation. During the process, I discovered that there are codes for indentation which has already been completed by checkstyle. However, when I copy,paste that code, and try to run that in my eclipse environment. It is unable to compile correctly. It shows me some compilation error such that "The method clearCreatedHandlers() from the type HandlerFactory is not visible" I have no idea how to fix this error. Here is the source that I got my code from

http://checkstyle.sourceforge.net/apidocs/src-html/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.html#line.81

It is really helpful if someone else could copy,paste the codes and try to compile it and let me know how they fix those errors. I have suffered for tons of tries.

Thanks in advance.

J.P.
  • 27
  • 7
  • 1
    [clearCreatedHandlers](http://checkstyle.sourceforge.net/apidocs/src-html/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.html#line.205) is not public – Hacketo Jul 07 '15 at 13:25
  • Not sure what you are trying to do here, but HandlerFactory.clearCreatedHandlers is pacakge private, so you have to use the same pacakge com.puppycrawl.tools.checkstyle.checks.indentation for your class – 6ton Jul 07 '15 at 13:25
  • How to use reflection ? I might be able to google this out. But feel free to send me link if you have a better explanation. Thanks a lot ! :) – J.P. Jul 07 '15 at 13:41

1 Answers1

3

HandlerFactory.clearCreatedHandlers() has default visibility. (The declaration is void clearCreatedHandlers() - note the absence of public, protected or private.) So if you are working on code in a different package, you won't be able to use that method.

You'll have to work in the same package or figure out another way to accomplish what that method does.

ETA: From @Hacketo's comment -- you could use reflection to invoke this method. (Thank you, Hacketo.)

dcsohl
  • 7,186
  • 1
  • 26
  • 44
  • 1
    or could use reflection to make it public at runtime. – Hacketo Jul 07 '15 at 13:29
  • @dcsohl Thanks for your answer and also Hacketo. I understand what you say. However, what does reflection mean here ? Does that mean I just need to import com.puppycrawl.tools.checkstyle.checks.indentation.*; to my own package like com.mytest; ? I tried this but did not solve the problem. I am curious about more details. Thank you very much – J.P. Jul 07 '15 at 13:39
  • A quick search of SO gives [the information you are looking for](http://stackoverflow.com/a/880400/2506382)... – dcsohl Jul 07 '15 at 13:42