JavaPathElement.st
author vranyj1
Mon, 03 Dec 2012 19:28:28 +0000
branchdevelopment
changeset 1856 f2e8307a717f
parent 1818 2e5ed72e7dfd
child 1864 60a8dc26c8c6
permissions -rw-r--r--
Fix for JavaLookupTests>>testTypeOverloading

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ Package: 'stx:libjava' }"

Object subclass:#JavaPathElement
	instanceVariableNames:'name pathName enabled origin'
	classVariableNames:'OriginRelease OriginEnvironment OriginPackage OriginUser'
	poolDictionaries:''
	category:'Languages-Java-Support'
!

!JavaPathElement class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
!

documentation
"
    JavaPathElement represents a single element in 'java paths' (Java classPath and
    Java sourcePath). The aim is to support easy configuration of libjava and storing
    paths in preferences.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]
        name ...... human-readable name of the entry - displayed by the UI
        pathName .. path to the file/directory the element represents
        enable .... whether the elements should be used or not (allows for
                    keeping path elements in prefs but not using them)
        origin .... one of #jdk #package or #user
                    #release... this element is part of java release (such as rt.jar)
                    #env ...... this element comes from environment (CLASSPATH)
                    #package .. this element was defined by some smalltalk package
                                that uses libjava (see ProjectDefinition>>javaClassPath/javaSourcePath)
                    #user ..... user-defined element (only thise are stored in preferences

    [class variables:]

    [see also:]

"
! !

!JavaPathElement class methodsFor:'initialization'!

initialize
    "Invoked at system start or when the class is dynamically loaded."

    "/ please change as required (and remove this comment)

    OriginRelease := #release.
    OriginEnvironment := #environment.
    OriginPackage := #package.
    OriginUser := #user.

    "Modified: / 27-07-2012 / 11:51:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement class methodsFor:'accessing-constants'!

originEnvironment
    ^OriginEnvironment

    "Created: / 27-07-2012 / 11:51:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

originPackage
    ^OriginPackage

    "Created: / 27-07-2012 / 11:51:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

originRelease
    ^OriginRelease

    "Created: / 27-07-2012 / 11:51:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

originUser
    ^OriginUser

    "Created: / 27-07-2012 / 11:51:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement class methodsFor:'instance'!

new: pathName
    ^self new: pathName origin: OriginUser

    "Created: / 27-07-2012 / 11:42:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

new: pathName origin: origin
    ^self new
        pathName: pathName;
        origin: origin;
        yourself

    "Created: / 27-07-2012 / 11:42:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

new: pathName origin: origin name: name
    ^self new
        pathName: pathName;
        origin: origin;
        name: name;
        yourself

    "Created: / 10-08-2012 / 19:07:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

newFromEnvironment: pathName
    ^self new: pathName origin: OriginEnvironment

    "Created: / 27-07-2012 / 11:43:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

newFromPackage: pathName
    ^self new: pathName origin: OriginPackage

    "Created: / 27-07-2012 / 11:44:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

newFromRelease:pathName 
    ^ self new:pathName origin: OriginRelease

    "Created: / 27-07-2012 / 11:43:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

newFromUser: pathName
    ^self new: pathName origin: OriginUser

    "Created: / 27-07-2012 / 11:43:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement methodsFor:'accessing'!

enabled
    ^ enabled ? true "/ enabled by default

    "Modified (comment): / 27-07-2012 / 11:26:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

enabled:aBoolean
    enabled := aBoolean.
!

name
    ^ name notNil ifTrue:[name] ifFalse:[self nameDefault]

    "Modified: / 10-08-2012 / 19:21:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name:aString
    name := aString.
!

nameDefault
    ^ pathName ? '???'
"/    pathName isNil ifTrue:[ ^ '???' ].
"/    ^ pathName asFilename baseName

    "Created: / 10-08-2012 / 19:02:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

nameOrNil
    ^ name

    "Created: / 13-08-2012 / 22:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

origin
    ^ origin
!

origin: newOrigin
    self assert: origin isNil description: 'Trying to set origin twice'.
    self assert: (newOrigin == OriginRelease
                    or:[newOrigin == OriginEnvironment
                    or:[newOrigin == OriginPackage
                    or:[newOrigin == OriginUser]]]) description:'Unknown/Unssuported path element origin ' , newOrigin printString.

    origin := newOrigin.

    "Modified: / 27-07-2012 / 12:17:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

pathName
    ^ pathName
!

pathName:aString
"/    self assert: pathName isNil description: 'Trying to set pathName twice'.
    pathName := aString.

    "Modified: / 10-08-2012 / 19:14:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement methodsFor:'comparing'!

= another

    ^another class == self class
        and:[self nameOrNil = another nameOrNil
            and:[ pathName = another pathName
                and:[self enabled = another enabled
                    and:[origin = another origin]]]]

    "Created: / 02-08-2012 / 09:50:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hash
    ^name hash bitXor:(pathName hash bitXor:(enabled hash bitXor: origin hash))

    "Created: / 02-08-2012 / 09:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement methodsFor:'conversion'!

asFilename
    ^pathName asFilename

    "Created: / 27-07-2012 / 11:26:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

asString
    ^pathName

    "Created: / 27-07-2012 / 11:27:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement methodsFor:'printing & storing'!

printOn:aStream
    "append a printed representation if the receiver to the argument, aStream"

    self enabled ifTrue:[
        aStream nextPutAll:'[X] '
    ] ifFalse:[
           aStream nextPutAll:'[ ] '
    ].    
    pathName printOn:aStream.
    aStream space; nextPut:${.
    origin printOn:aStream.
    aStream nextPut:$}.

    "Modified: / 27-07-2012 / 12:25:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaPathElement class methodsFor:'documentation'!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !

JavaPathElement initialize!