Il 05/05/2013 11:25, Holger Hans Peter Freyther ha scritto: > The category of classes and extensions should match the package > name. Create a small class that is checking this on a package and > print the errors. > > 2013-03-30 Holger Hans Peter Freyther <[email protected]> > > * Lint/Monticello.st: Added Monticello class for linting. > * Parser/SourceClass.st: Reimplement >>#isSourceClass, >>#methodsToEmit, > >>#classMethodsToEmit, #>>isComplete. > * Parser/SourceEntity.st: Added >>#isSourceClass. > * Parser/Loader.st: Add >>#stuffToEmit selector. > * TODO: Add work item. > * package.xml: Add the Lint/Monticello.st.
A bit immature perhaps? But the Parser/* changes can go in. Paolo > --- > packages/tooling/ChangeLog | 10 ++ > packages/tooling/Lint/Monticello.st | 159 > +++++++++++++++++++++++++++++++ > packages/tooling/Makefile.frag | 2 +- > packages/tooling/Parser/Loader.st | 5 + > packages/tooling/Parser/SourceClass.st | 20 ++++ > packages/tooling/Parser/SourceEntity.st | 4 + > packages/tooling/TODO | 11 +++ > packages/tooling/package.xml | 2 + > 8 files changed, 212 insertions(+), 1 deletion(-) > create mode 100644 packages/tooling/Lint/Monticello.st > > diff --git a/packages/tooling/ChangeLog b/packages/tooling/ChangeLog > index d5d2a47..65b30a1 100644 > --- a/packages/tooling/ChangeLog > +++ b/packages/tooling/ChangeLog > @@ -1,5 +1,15 @@ > 2013-03-30 Holger Hans Peter Freyther <[email protected]> > > + * Lint/Monticello.st: Added Monticello class for linting. > + * Parser/SourceClass.st: Reimplement >>#isSourceClass, >>#methodsToEmit, > + >>#classMethodsToEmit, #>>isComplete. > + * Parser/SourceEntity.st: Added >>#isSourceClass. > + * Parser/Loader.st: Add >>#stuffToEmit selector. > + * TODO: Add work item. > + * package.xml: Add the Lint/Monticello.st. > + > +2013-03-30 Holger Hans Peter Freyther <[email protected]> > + > * Makefile.frag: Added. > * Parser/SourceClass.st: Added from scripts/Convert.st. > * Parser/SourceComments.st: Added from scripts/Convert.st. > diff --git a/packages/tooling/Lint/Monticello.st > b/packages/tooling/Lint/Monticello.st > new file mode 100644 > index 0000000..5bd2998 > --- /dev/null > +++ b/packages/tooling/Lint/Monticello.st > @@ -0,0 +1,159 @@ > +"====================================================================== > +| > +| Linting for Monticello export > +| > +| > + ======================================================================" > + > +"====================================================================== > +| > +| Copyright 2013 Free Software Foundation, Inc. > +| Written by Holger Hans Peter Freyther. > +| > +| This file is part of the GNU Smalltalk class library. > +| > +| The GNU Smalltalk class library is free software; you can redistribute it > +| and/or modify it under the terms of the GNU Lesser General Public License > +| as published by the Free Software Foundation; either version 2.1, or (at > +| your option) any later version. > +| > +| The GNU Smalltalk class library is distributed in the hope that it will be > +| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of > +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser > +| General Public License for more details. > +| > +| You should have received a copy of the GNU Lesser General Public License > +| along with the GNU Smalltalk class library; see the file COPYING.LIB. > +| If not, write to the Free Software Foundation, 59 Temple Place - Suite > +| 330, Boston, MA 02110-1301, USA. > +| > + ======================================================================" > + > + > +Tooling.SourceClass extend [ > + isComplete [ > + <category: 'accessing'> > + ^ isComplete > + ] > + > + methodsToEmit [ > + <category: 'accessing'> > + ^ methodsToEmit > + ] > + > + classMethodsToEmit [ > + <category: 'accessing'> > + ^ classMethodsToEmit > + ] > + > + isComplete [ > + <category: 'accessing'> > + ^ isComplete > + ] > +] > + > +Object subclass: Monticello [ > + | loader package errors | > + <category: 'Tooling-Lint-Monticello'> > + > + Monticello class >> lint: aPackage [ > + "Work on a given package." > + ^ self new > + loadPackage: aPackage; > + lint. > + ] > + > + loadPackage: aPackage [ > + package := aPackage. > + loader := Tooling.Loader new. > + > + self lintFiles: aPackage fileIns. > + aPackage test ifNotNil: [ > + self lintFiles: aPackage test fileIns]. > + ] > + > + lintFiles: aList [ > + | files | > + > + files := package fullPathsOf: aList. > + files do: [:each | | file | > + file := each open: FileStream read. > + loader parseSmalltalkStream: file with: STInST.GSTFileInParser. > + file close. > + ] > + ] > + > + loader [ > + <category: 'private'> > + ^ loader > + ] > + > + lint [ > + <category: 'lint'> > + "TODO: this should use the visitor..." > + loader stuffToEmit do: [:each | > + each isSourceClass ifTrue: [self lintClass: each]]. > + ] > + > + lintClass: aClass [ > + <category: 'lint'> > + aClass isComplete > + ifTrue: [self lintCompleteClass: aClass] > + ifFalse: [self lintExtension: aClass]. > + ] > + > + lintCompleteClass: aClass [ > + <category: 'lint'> > + "Check if the package name is in the category" > + (aClass forClass category isNil) > + ifTrue: [^self addError: 'Class does not have category' > + for: aClass forClass]. > + (aClass forClass category startsWith: package name) > + ifFalse: [self addError: 'Class category does not begin with > package name' > + for: aClass forClass]. > + ] > + > + lintExtension: aClass [ > + <category: 'lint'> > + > + aClass methodsToEmit do: [:each | > + self lintExtensionMethod: each on: aClass]. > + aClass classMethodsToEmit do: [:each | > + self lintExtensionMethod: each on: aClass ]. > + ] > + > + lintExtensionMethod: aSymbol on: aClass [ > + | method | > + <category: 'lint'> > + method := aClass forClass >> aSymbol. > + > + "Use aClass forClass asClass as ProxyClass>>#name will return nil" > + (method methodCategory isNil) > + ifTrue: [^self addError: 'Extension method needs category' > + for: aClass forClass asClass method: > aSymbol]. > + (method methodCategory asLowercase startsWith: ('*', package name > asLowercase)) > + ifFalse: [self addError: 'Method does not beging with > *package-name' > + for: aClass forClass asClass method: > aSymbol]. > + ] > + > + addError: aString for: aClass method: aMethod [ > + <category: 'error-handling'> > + self errors add: '%1 on %2>>%3' % {aString. aClass name asString. > aMethod}. > + ] > + > + addError: aString for: aClass [ > + <category: 'error-handling'> > + self errors add: '%1 on %2' % {aString. aClass name asString}. > + ] > + > + errors [ > + <category: 'error-handling'> > + ^ errors ifNil: [errors := OrderedCollection new]. > + ] > + > + printErrors [ > + <category: 'error-handling'> > + self errors do: [:each | > + Transcript nextPutAll: each; nl.] > + ] > +] > diff --git a/packages/tooling/Makefile.frag b/packages/tooling/Makefile.frag > index bb2a845..833b5a7 100644 > --- a/packages/tooling/Makefile.frag > +++ b/packages/tooling/Makefile.frag > @@ -1,5 +1,5 @@ > Tooling_FILES = \ > -packages/tooling/Parser/SourceEntity.st > packages/tooling/Parser/SourceClass.st > packages/tooling/Parser/SourceComments.st > packages/tooling/Parser/SourceEval.st packages/tooling/Parser/Loader.st > +packages/tooling/Parser/SourceEntity.st > packages/tooling/Parser/SourceClass.st > packages/tooling/Parser/SourceComments.st > packages/tooling/Parser/SourceEval.st packages/tooling/Parser/Loader.st > packages/tooling/Lint/Monticello.st > $(Tooling_FILES): > $(srcdir)/packages/tooling/stamp-classes: $(Tooling_FILES) > touch $(srcdir)/packages/tooling/stamp-classes > diff --git a/packages/tooling/Parser/Loader.st > b/packages/tooling/Parser/Loader.st > index 0c4e6a9..887e62b 100644 > --- a/packages/tooling/Parser/Loader.st > +++ b/packages/tooling/Parser/Loader.st > @@ -232,4 +232,9 @@ STInST.STClassLoader subclass: Loader [ > ifTrue: [ stuffToEmit last addMethod: aMethod ] > ifFalse: [ stuffToEmit add: ((SourceClass forExtension: > currentClass) addMethod: aMethod) ] > ] > + > + stuffToEmit [ > + <category: 'accessing'> > + ^ stuffToEmit > + ] > ] > diff --git a/packages/tooling/Parser/SourceClass.st > b/packages/tooling/Parser/SourceClass.st > index 4258356..776bcec 100644 > --- a/packages/tooling/Parser/SourceClass.st > +++ b/packages/tooling/Parser/SourceClass.st > @@ -82,4 +82,24 @@ SourceEntity subclass: SourceClass [ > completeFileOut: isComplete; > fileOutSelectors: methodsToEmit classSelectors: > classMethodsToEmit. > ] > + > + isSourceClass [ > + <category: 'accessing'> > + ^ true > + ] > + > + methodsToEmit [ > + <category: 'accessing'> > + ^ methodsToEmit > + ] > + > + classMethodsToEmit [ > + <category: 'accessing'> > + ^ classMethodsToEmit > + ] > + > + isComplete [ > + <category: 'accessing'> > + ^ isComplete > + ] > ] > diff --git a/packages/tooling/Parser/SourceEntity.st > b/packages/tooling/Parser/SourceEntity.st > index bbee944..c6c735c 100644 > --- a/packages/tooling/Parser/SourceEntity.st > +++ b/packages/tooling/Parser/SourceEntity.st > @@ -36,4 +36,8 @@ Object subclass: SourceEntity [ > emitTo: aStream filteredBy: aBlock [ > self subclassResponsibility > ] > + > + isSourceClass [ > + ^ false > + ] > ] > diff --git a/packages/tooling/TODO b/packages/tooling/TODO > index b1617dc..4014c0b 100644 > --- a/packages/tooling/TODO > +++ b/packages/tooling/TODO > @@ -2,3 +2,14 @@ > of the calls to emitTo:. > > * Remove "Emit" from variable names. > + > +* The following is shown as a a single class > + Object subclass: Foo [ > + signal [] > + ] > + > + Foo extend [ > + signalTwo [] > + ] > + > + It should be two SourceClass > diff --git a/packages/tooling/package.xml b/packages/tooling/package.xml > index f5b99d5..8359efe 100644 > --- a/packages/tooling/package.xml > +++ b/packages/tooling/package.xml > @@ -8,4 +8,6 @@ > <filein>Parser/SourceComments.st</filein> > <filein>Parser/SourceEval.st</filein> > <filein>Parser/Loader.st</filein> > + > + <filein>Lint/Monticello.st</filein> > </package> > _______________________________________________ help-smalltalk mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-smalltalk
