Page 1 of 1

Source code inspection tool

Posted: Mon Jan 21, 2008 11:13 pm
by ManUnderground
I was thinking about creating a tool which would scan source code and check for constraints. Specifically, the end-user would place metadata throughout his class definition and the tool would work off that. One use case that I believe would be useful would be an @Override annotation (like that found in Java) which would signify that a method overrides a parent's implementation.

I wanted to raise the issue here to see if anyone knew of such a tool and to gauge interest. Additionally, I'd like to start a discussion on how to best design the tool in a manner which allows for future constraints to be checked (This last part will probably need a new thread in the appropriate forum later).

Thanks for any feedback!

Re: Source code inspection tool

Posted: Tue Jan 22, 2008 12:04 am
by Chris Corbyn
You'll likely have to use Reflection for something like this. The Reflection API does allow the parsing of documentation comments so you can do things like this.

Code: Select all

class Foo extends Bar {
 
  /**
    * @Override
    * @SupressWarnings
    */
  public function doSomething() {
 
  }
 
}
I'm not overly sure of this usefulness of this in PHP however.

Re: Source code inspection tool

Posted: Tue Jan 22, 2008 12:28 am
by alex.barylski
Nothing in PHP like is seems to ever take off...Java and C/C++ how a much larger community around such projects...

I've been working on a documentation project myself (but have put it on hold breifly) which would attempt to determine such constraints through syntactic/static analysis rather than reflection...

The problem with reflection (so I determined anyways) is that you need to actually include the class into the current executing context...my biggest concern was that of namespace collisions and that of possible performance issues. For that reason I started on a parser framework.

What other kind of inspections did you have in mind?

Personally, I fail to see why you would need to manually indicate whether a method overrides it's parent. Short of being easier for a parser to process, I see this, more as a short coming than a bonus. I'd rather see source code parsed completely and have those kind of constraints auto-detected.

Cheers :)