Initial version of project checker
authorvrany
Thu, 26 Jul 2012 13:42:28 +0200
changeset 2853 b28d27ac2c67
parent 2852 9e670f6d2145
child 2854 b92e9c1273b9
Initial version of project checker
ProjectChecker.st
--- a/ProjectChecker.st	Thu Jul 26 12:20:26 2012 +0200
+++ b/ProjectChecker.st	Thu Jul 26 13:42:28 2012 +0200
@@ -12,7 +12,7 @@
 "{ Package: 'stx:libbasic3' }"
 
 Object subclass:#ProjectChecker
-	instanceVariableNames:'package packageDef classes methods problems'
+	instanceVariableNames:'package packageDef classes methods problems phase'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Support-Projects'
@@ -37,7 +37,10 @@
 documentation
 "
     A simple project checker that can search whole projects or individual
-    classes or methods for various problems. TBW...
+    classes or methods for various problems that may cause build problems such
+    as:
+        - inconsistent/messed up project definition class
+        - method code problems
 
     NOTE: Not yet finished. This code is meant as a single central entry for all the
     source code management tools like SCM Utilities, NewSystemBrowser ets. That code
@@ -51,6 +54,7 @@
     [class variables:]
 
     [see also:]
+        Tools::ProjectCheckerBrowser
 
 "
 !
@@ -64,6 +68,16 @@
     "
 ! !
 
+!ProjectChecker class methodsFor:'instance creation'!
+
+forPackage: packageId
+    ^self new
+        package: packageId;
+        yourself.
+
+    "Created: / 25-07-2012 / 18:00:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !ProjectChecker class methodsFor:'checking'!
 
 check: package
@@ -73,12 +87,6 @@
     "Created: / 11-01-2012 / 16:46:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!ProjectChecker class methodsFor:'others'!
-
-version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.4 2012-03-14 16:25:24 vrany Exp $'
-! !
-
 !ProjectChecker methodsFor:'accessing'!
 
 classes: aCollection
@@ -100,11 +108,13 @@
 !
 
 package:packageId
-    package := packageId.
+    package := packageId asSymbol.
+
+    "Modified: / 11-04-2012 / 16:00:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 problems
-    ^ problems ? #()
+    ^ problems
 
     "Modified: / 23-02-2012 / 15:14:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
@@ -113,6 +123,7 @@
 
 check
 
+    problems := OrderedCollection new.
     packageDef := ProjectDefinition definitionClassForPackage: package.
     packageDef isNil ifTrue:[
         self addProblem: 
@@ -271,9 +282,12 @@
     checker := [:cls|
         cls selectorsAndMethodsDo:[:sel :mth|
             (mth package isNil or:[mth package == PackageId noProjectID]) ifTrue:[
-                 self addProblem: 
-                    (ProjectProblem newMethodInNoPackage
-                        className: cls name selector: sel).                            
+                "Sigh, special hack for Expecco"
+                (cls name = 'Expecco::AbstractApplication class' and:[sel = 'flags']) ifFalse:[
+                    self addProblem: 
+                        (ProjectProblem newMethodInNoPackage
+                            className: cls name selector: sel).                            
+                ]
             ]
         ]
     ].
@@ -285,6 +299,97 @@
     ]
 
     "Created: / 13-02-2012 / 18:18:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+checkMethodCodingStyle: method
+    "Checks for various coding style violations such as 'self halt' or
+     improper indentation :-)"
+
+    "To be implemented"
+
+    "Created: / 11-04-2012 / 12:38:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+checkMethodSTCCompilability1: method into: problem
+    "Checks is the method can be compiled by STC based on Parser error/warnings"
+
+    | lang |
+    lang := method programmingLanguage.
+    lang isSmalltalk ifFalse:[ ^ self ].
+
+    lang compilerClass new
+        compile:method source
+        forClass:method mclass
+        inCategory:'others'
+        notifying:problem
+        install:false
+        skipIfSame:false
+        silent:false
+        foldConstants:true
+        ifFail:[ ]
+
+    "Created: / 11-04-2012 / 15:31:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+checkMethodSTCCompilability2: method into: problem
+    "Checks is the method can be compiled by STC based on selected lint rules"
+
+    "Not yet implemented"
+
+    "Created: / 11-04-2012 / 15:54:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+checkMethodSTCCompilability: method
+    "Checks is the method can be compiled by STC (since STC won't compile
+     everything bytecode compiler/jit compiler does, sigh"
+
+    | issue |
+
+    "No need to check the method if the class is autoloaded"
+    (packageDef autoloaded_classNames includes: method mclass theNonMetaclass name) ifTrue:[
+        ^ self
+    ].
+    
+    issue := ProjectProblem newMethodCompilabilityIssue.
+    issue method: method.
+    self checkMethodSTCCompilability1: method into: issue.
+    self checkMethodSTCCompilability2: method into: issue.
+    issue hasIssue ifTrue:[
+        self addProblem: issue
+    ]
+
+    "Created: / 11-04-2012 / 12:37:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+checkMethodSourceCode: method
+    "Checks, whether method's source code is both
+     available and parseable. Return true if the code
+     is syntactically corret, false otherwise"
+
+    | source |
+
+    [    
+        source := method source.
+    ] on: Error do:[
+        self addProblem:
+            (ProjectProblem newMethodSourceNotAvailable method: method).
+        ^false
+    ].
+    [
+        (Parser parseMethod: method source) == #Error ifTrue:[
+            self addProblem:
+                (ProjectProblem newMethodSourceCorrupted method: method).
+            ^false.
+        ]
+    ] on: Error do:[
+        self addProblem:
+            (ProjectProblem newMethodSourceCorrupted method: method).
+        ^false.
+    ].
+
+    ^true
+
+    "Created: / 11-04-2012 / 12:29:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ProjectChecker methodsFor:'checks-private'!
@@ -308,12 +413,43 @@
     "Created: / 13-02-2012 / 18:18:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+checkMethod: method
+
+    (self checkMethodSourceCode: method) ifTrue:[
+        "/OK, method's source is OK, perform further checks
+        self checkMethodSTCCompilability: method.
+        self checkMethodCodingStyle: method.
+    ]
+
+    "Created: / 11-04-2012 / 12:27:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 checkMethods
-    "Not yet implemented"
+
+    methods notEmptyOrNil ifTrue:[
+        self checkMethods: methods.
+        ^self.
+    ].
+
+    self checkMethods:
+        (Iterator on:[:whatToDo|
+            (classes notNil ifTrue:[classes] ifFalse:[Smalltalk allClasses]) do:[:cls|
+                cls theNonMetaclass withAllPrivateClassesDo:[:each |
+                    each instAndClassSelectorsAndMethodsDo:[:s :m | m package = package ifTrue:[whatToDo value:m]]
+                ].
+            ]
+        ])
 
     "Created: / 11-01-2012 / 16:55:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+checkMethods: methodsToCheck
+
+    methodsToCheck do:[:m|self checkMethod: m].
+
+    "Created: / 11-04-2012 / 12:16:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 checkPackage
 
     self checkClassListConsistency.
@@ -338,9 +474,13 @@
 !ProjectChecker class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.4 2012-03-14 16:25:24 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.5 2012-07-26 11:42:28 vrany Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.5 2012-07-26 11:42:28 vrany Exp $'
 !
 
 version_SVN
-    ^ '§Id: ProjectChecker.st 1886 2012-02-23 15:15:11Z vranyj1 §'
+    ^ '§Id: ProjectChecker.st 1938 2012-07-26 10:05:27Z vranyj1 §'
 ! !