compiler/tests/extras/PPCResources.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 11 May 2015 18:29:13 +0100
changeset 457 76de2febe7d2
parent 454 a9cd5ea7cc36
child 460 87a3d30ab570
permissions -rw-r--r--
Oops, merged lost Smalltalk/X compatibility fixes (again)

"{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"

"{ NameSpace: Smalltalk }"

TestResource subclass:#PPCResources
	instanceVariableNames:''
	classVariableNames:'javaCache'
	poolDictionaries:''
	category:'PetitCompiler-Extras-Tests-Support'
!


!PPCResources methodsFor:'java'!

javaInDirectory: directory
    | files |
    files := self readDirectory: directory.
    files := self files: files withExtension: 'java'.
    
    ^ files collect: [ :f | (FileStream fileNamed: f) contents ]
!

javaLangMath
    ^ (FileStream fileNamed: '../java-src/java/lang/Math.java') contents asString

    "Modified: / 10-05-2015 / 14:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaSourcesBig
    ^ self javaInDirectory: '../java-src/java/util'.
    "^ self workingJavaInDirectory: '../java-src/java/util'"
!

javaUtilTimer
    ^ (FileStream fileNamed: '../java-src/java/util/Timer.java') contents asString

    "Modified: / 10-05-2015 / 14:11:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

workingJavaInDirectory: directory
    | sources parser |
    "return only such a files, that can be parsed by PPJavaSyntax"

    javaCache ifNil: [ javaCache := Dictionary new ].
    
    ^ javaCache at: directory ifAbsentPut: [ 
        sources := self javaInDirectory: directory.
        parser := PPJavaSyntax new.
    
        sources select: [ :source | ([parser parse: source ] on: Error do: [ PPFailure new ]) isPetitFailure not ]	
    ]
! !

!PPCResources methodsFor:'private utilities'!

files: files withExtension: extension
     ( (Smalltalk respondsTo: #isSmalltalkX) and:[ Smalltalk isSmalltalkX ] ) ifTrue:[ 
        ^ files select: [ :f | f suffix = extension ] 
    ] ifFalse:[ 
        "Assuming Pharo..."   
        ^ files select: [ :f | f extension = extension ] 
    ]

    "Modified: / 11-05-2015 / 16:37:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

readDirectory: directory
    | file |

    ( (Smalltalk respondsTo: #isSmalltalkX) and:[ Smalltalk isSmalltalkX ] ) ifTrue:[ 
        file := directory asFilename.
        file exists ifFalse:[  
            self error: 'Directory does not exist'.
        ].
        ^ file recursiveDirectoryContentsAsFilenames select:[:each | each isRegularFile ]
    ] ifFalse:[ 
        "Assuming Pharo..."

        file := directory asFileReference.
        file exists ifFalse: [ 
            self error: 'Directory does not exist'.
        ].
        ^ file allFiles
    ]

    "Modified: / 10-05-2015 / 07:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPCResources methodsFor:'smalltalk'!

smalltalkClassMethods
    ^ self smalltalkInDirectory: '../smalltalk-src/Class/'
    
!

smalltalkInDirectory: directory
    | files |
    files := self readDirectory: directory.
    files := self files: files withExtension: 'st'.
    
    ^ files collect: [ :f | (FileStream fileNamed: f) contents asString ]

    "Modified: / 11-05-2015 / 16:38:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

smalltalkObjectMethods
    ^ self smalltalkInDirectory: '../smalltalk-src/Object/'
    
!

smalltalkSourcesBig
    ^ self smalltalkInDirectory: '../smalltalk-src/'
!

smalltalkSourcesSmall
    ^ (self smalltalkInDirectory: '../smalltalk-src/') copyFrom: 1 to: 5000.
! !

!PPCResources class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !