"
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
SWING Research Group, Czech Technical University
in Prague
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libjava/experiments' }"
Object subclass:#JavaSourceCodeAnalyzer
instanceVariableNames:'source tokens'
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Support-Compiling'
!
!JavaSourceCodeAnalyzer class methodsFor:'documentation'!
copyright
"
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
SWING Research Group, Czech Technical University
in Prague
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
!
history
"Created: #imports / 08-12-2012 / 20:01:41 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
"Modified: #imports / 09-12-2012 / 09:21:09 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaSourceCodeAnalyzer class methodsFor:'instance creation'!
analyze: javaSourceCode
^ self new analyze: javaSourceCode.
"Created: / 08-12-2012 / 18:47:26 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaSourceCodeAnalyzer methodsFor:'initialization'!
analyze: javaSourceCode
source := javaSourceCode.
tokens := (JavaParserI parse: javaSourceCode) at: 1.
^ self.
"Created: / 08-12-2012 / 18:48:56 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaSourceCodeAnalyzer methodsFor:'queries'!
className
| seenClass className |
seenClass := false.
className := '' writeStream.
tokens do: [
:token |
seenClass ifTrue: [ ^ token value ].
token = 'class' ifTrue: [ seenClass := true ].
].
self error: 'Class name was not found in the source file.'
"Created: / 08-12-2012 / 18:53:53 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!
imports
| imports importStarted importEnded currentImport |
importStarted := false.
currentImport := '' writeStream.
imports := Array new writeStream.
tokens do: [
:token |
token = 'class' ifTrue: [ ^ imports contents ].
(token = $; and: [ importStarted ]) ifTrue: [
| import |
import := currentImport contents.
imports nextPut: (import withoutSuffix: '.*').
importStarted := false.
currentImport reset.
].
(importStarted and: [ token value printString ~= 'static' ]) ifTrue: [
currentImport nextPutAll: token value printString
].
token = 'import' ifTrue: [ importStarted := true ].
].
self error: 'this source code does not contain class keyword?? weird..'.
"Created: / 08-12-2012 / 20:01:41 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
"Modified: / 09-12-2012 / 09:21:09 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!
packageName
| seenPackage package |
seenPackage := false.
package := '' writeStream.
tokens do: [
:token |
token = 'class' ifTrue: [ ^ nil ].
(token = $; and: [ seenPackage ]) ifTrue: [ ^ package contents ].
seenPackage ifTrue: [ package nextPutAll: token value printString ].
token = 'package' ifTrue: [ seenPackage := true ].
].
^ nil.
"Created: / 08-12-2012 / 18:50:26 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaSourceCodeAnalyzer class methodsFor:'documentation'!
version_SVN
^ '$Id:: $'
! !