# HG changeset patch # User Jan Vrany # Date 1379170083 -3600 # Node ID ac412f6ea6d450cf45bde9887a582003c3ef51a5 # Parent 658220e93dc90bc099203ba2b63bd9de83bc7995 More support for method's source display. Not yet working. The behaviour can (whether to show full class source or just method's source) be now controlled by JavaMethod class>>showFullSource: More work has to be done to fully support this. diff -r 658220e93dc9 -r ac412f6ea6d4 JavaClass.st --- a/JavaClass.st Thu Sep 12 00:24:05 2013 +0100 +++ b/JavaClass.st Sat Sep 14 15:48:03 2013 +0100 @@ -29,6 +29,13 @@ category:'Languages-Java-Classes' ! +Array variableSubclass:#Attributes + instanceVariableNames:'' + classVariableNames:'Empty' + poolDictionaries:'' + privateIn:JavaClass +! + Object subclass:#JavaClassVersionDiedHandler instanceVariableNames:'' classVariableNames:'' @@ -657,6 +664,28 @@ ^ constantPool ! +enclosingClass + | enclosingMethodAttr | + + enclosingMethodAttr := self getAttribute: #EnclosingMethod. + enclosingMethodAttr isNil ifTrue:[ ^ nil ]. + ^ enclosingMethodAttr first resolve: false. + + "Created: / 13-09-2013 / 01:26:55 / Jan Vrany " +! + +enclosingMethod + | enclosingMethodAttr enclosingClass | + + enclosingMethodAttr := self getAttribute: #EnclosingMethod. + enclosingMethodAttr isNil ifTrue:[ ^ nil ]. + enclosingMethodAttr second isNil ifTrue:[ ^ nil ]. + enclosingClass := enclosingMethodAttr first resolve: false. + enclosingClass compiledMethodAt: enclosingMethodAttr second selector + + "Created: / 13-09-2013 / 01:28:46 / Jan Vrany " +! + ensureHasAnnotations annotations ifNil: [ annotations := JavaAnnotationContainer for: self ]. ^ annotations @@ -874,6 +903,32 @@ "Created: / 04-02-2011 / 12:35:18 / Jan Vrany " ! +topEnclosingClass + | current enclosing | + + current := enclosing := self enclosingClass. + [ current notNil ] whileTrue:[ + enclosing := current. + current := current enclosingClass. + ]. + ^ enclosing + + "Created: / 13-09-2013 / 11:22:24 / Jan Vrany " +! + +topEnclosingMethod + | current enclosing | + + current := enclosing := self enclosingMethod. + [ current notNil ] whileTrue:[ + enclosing := current. + current := current enclosingMethod. + ]. + ^ enclosing + + "Created: / 13-09-2013 / 11:22:37 / Jan Vrany " +! + topNameSpaceName "Return the nameSpace of my topOwningClass (if private) or my own nameSpace." @@ -2139,6 +2194,20 @@ "Created: 15.4.1996 / 16:42:52 / cg" ! +setAttributes: aSequenceableCollection + aSequenceableCollection isNil ifTrue:[ + attributes := Attributes empty. + ] ifFalse:[ + aSequenceableCollection class == Attributes ifTrue:[ + attributes := aSequenceableCollection + ] ifFalse:[ + attributes := Attributes withAll: aSequenceableCollection. + ] + ] + + "Created: / 13-09-2013 / 00:57:10 / Jan Vrany " +! + setClassfileBytes: aByteArray self assert: aByteArray isByteArray. classfileBytes := aByteArray @@ -2255,6 +2324,47 @@ "Modified: 22.8.1997 / 15:06:45 / cg" ! ! +!JavaClass methodsFor:'private-accessing'! + +attributes + "return the extra class attributes or nil" + ^ attributes + + "Created: / 13-09-2013 / 00:53:02 / Jan Vrany " +! + +attributes:aClassAttributesObject + self shouldNotImplement + + "Created: / 13-09-2013 / 00:52:41 / Jan Vrany " +! + +classAttributes + ^ self attributes + + "Created: / 13-09-2013 / 00:52:29 / Jan Vrany " +! + +classAttributes:aClassAttributesObject + self shouldNotImplement. + + "Created: / 13-09-2013 / 00:52:06 / Jan Vrany " +! + +getAttribute:key + "get an attribute (by symbolic key)" + + ^ attributes at: key + + "Created: / 13-09-2013 / 00:53:51 / Jan Vrany " +! + +setAttribute:key to:aValue + self shouldNotImplement + + "Created: / 13-09-2013 / 00:54:04 / Jan Vrany " +! ! + !JavaClass methodsFor:'private-changes management'! writingChangeWithTimeStamp:doStampIt do:aBlock @@ -2876,6 +2986,59 @@ "Created: / 14-04-2013 / 13:44:03 / Marcel Hlopko " ! ! +!JavaClass::Attributes class methodsFor:'accessing'! + +empty + ^ Empty + + "Created: / 13-09-2013 / 00:50:55 / Jan Vrany " +! ! + +!JavaClass::Attributes class methodsFor:'documentation'! + +documentation +" + A special container for class attributes allowing + for dense, memory-efficient storage. + + [author:] + Jan Vrany + + [instance variables:] + + [class variables:] + + [see also:] + +" +! ! + +!JavaClass::Attributes class methodsFor:'initialization'! + +initialize + "Invoked at system start or when the class is dynamically loaded." + + "/ please change as required (and remove this comment) + + Empty := self new:0. + + "Modified: / 13-09-2013 / 00:51:12 / Jan Vrany " +! ! + +!JavaClass::Attributes methodsFor:'accessing'! + +at: name + 1 to: self size by: 2 do:[:i| + (self basicAt: i) == name ifTrue:[ + ^ self basicAt: i + 1. + ] + ]. + ^ nil + + "Created: / 13-09-2013 / 00:31:52 / Jan Vrany " + "Modified: / 13-09-2013 / 02:07:03 / Jan Vrany " +! ! + !JavaClass::JavaClassVersionDiedHandler class methodsFor:'documentation'! history @@ -2918,3 +3081,4 @@ JavaClass initialize! +JavaClass::Attributes initialize! diff -r 658220e93dc9 -r ac412f6ea6d4 JavaClassReader.st --- a/JavaClassReader.st Thu Sep 12 00:24:05 2013 +0100 +++ b/JavaClassReader.st Sat Sep 14 15:48:03 2013 +0100 @@ -22,7 +22,7 @@ Object subclass:#JavaClassReader instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots - constSlot classBeingLoaded classLoader' + constSlot classBeingLoaded classLoader attributes' classVariableNames:'Verbose AnnotationsVerbose Silent AbsolutelySilent LazyClassLoading InvalidClassFormatSignal ClassLoaderQuerySignal JavaArchiveCache LastJavaArchive MaxContextSize @@ -669,6 +669,7 @@ self readMethodsFor: classBeingLoaded. self readAttributesFor: classBeingLoaded. + classBeingLoaded setAttributes: attributes. "/ "/ get extensions @@ -695,7 +696,7 @@ "Modified: / 15-10-2010 / 17:37:38 / Jan Kurs " "Modified: / 28-01-2011 / 15:09:48 / Marcel Hlopko " "Modified: / 18-05-2011 / 15:30:29 / Marcel Hlopko " - "Modified: / 02-05-2013 / 10:02:26 / Jan Vrany " + "Modified: / 13-09-2013 / 01:14:29 / Jan Vrany " ! readStream:aStream ignoring:classesBeingLoaded @@ -1027,13 +1028,14 @@ |attributes_count| attributes_count := inStream nextUnsignedShortMSB:msb. + attributes := OrderedCollection new: attributes_count * 2. 1 to:attributes_count do:[:i | - self readAttributeFor:something. + self readAttributeFor:something. ]. - "Modified: 15.4.1996 / 15:33:28 / cg" - "Created: 15.4.1996 / 15:40:17 / cg" + "Created: / 15-04-1996 / 15:40:17 / cg" + "Modified: / 13-09-2013 / 01:01:28 / Jan Vrany " ! readDeprecatedAttributeFor:aJavaMethodWithHandler @@ -1046,7 +1048,23 @@ readEnclosingMethodAttributeFor:something "/ ('JAVA [info]: unhandled attribute: EnclosingMethod') infoPrintCR. - self skipAttribute:'EnclosingMethod'. +"/ self skipAttribute:'EnclosingMethod'. + + |attribute_length class_index class_ref method_index method_ref | + + attribute_length := inStream nextUnsignedLongMSB:msb. + + class_index := inStream nextUnsignedShortMSB:msb. + class_ref := constants at: class_index. + + method_index := inStream nextUnsignedShortMSB:msb. + method_index ~~ 0 ifTrue:[ + method_ref := constants at: method_index. + ]. + + attributes add: #EnclosingMethod; add: (Array with: class_ref with: method_ref) + + "Modified: / 13-09-2013 / 01:07:38 / Jan Vrany " ! readInnerClassesAttributeFor:something @@ -1184,6 +1202,9 @@ readSyntheticAttributeFor:something "/ ('JAVA [info]: unhandled attribute: Synthetic') infoPrintCR. self skipAttribute:'Synthetic'. + attributes add: #Synthetic; add: true. + + "Modified: / 13-09-2013 / 01:08:54 / Jan Vrany " ! skipAttribute:attributeName @@ -1947,6 +1968,7 @@ field setDescriptor: (constants at: descriptor_index) asSymbol. field setConstantPool: constants. attributes_count := inStream nextUnsignedShortMSB: msb. + attributes := OrderedCollection new: attributes_count * 2. Verbose ifTrue: [ Transcript @@ -1966,7 +1988,7 @@ "Modified: / 15-10-1998 / 10:38:01 / cg" "Modified: / 17-12-2010 / 18:44:30 / Marcel Hlopko " "Modified: / 18-05-2011 / 14:11:37 / Marcel Hlopko " - "Modified: / 14-08-2011 / 19:40:13 / Jan Vrany " + "Modified: / 13-09-2013 / 02:03:31 / Jan Vrany " ! readFieldInfofields diff -r 658220e93dc9 -r ac412f6ea6d4 JavaContext.st --- a/JavaContext.st Thu Sep 12 00:24:05 2013 +0100 +++ b/JavaContext.st Sat Sep 14 15:48:03 2013 +0100 @@ -523,6 +523,26 @@ !JavaContext methodsFor:'printing & storing'! +printOn:aStream + "append a brief description (excl. arguments) of the receiver onto aStream" + + self printReceiverOn:aStream. + "/ aStream nextPutAll:' '. + aStream nextPutAll:' >> '. + + aStream bold. + self selector printOn:aStream. "show as string (as symbol looks too ugly in browser ...)" + "/ self selector storeOn:aStream. "show as symbol" + aStream normal. + aStream space. + (method notNil and:[method isWrapped]) ifTrue:[ + aStream nextPutAll:'(wrapped) ' + ]. + aStream nextPutAll:' ['; nextPutAll:(self method lineNumberForPC0: lineNr) printString; nextPutAll:']' . + + "Created: / 12-09-2013 / 23:02:33 / Jan Vrany " +! + receiverPrintString "return a string describing the receiver of the context" diff -r 658220e93dc9 -r ac412f6ea6d4 JavaLookup.st --- a/JavaLookup.st Thu Sep 12 00:24:05 2013 +0100 +++ b/JavaLookup.st Sat Sep 14 15:48:03 2013 +0100 @@ -728,12 +728,11 @@ candidates size == 1 ifTrue:[ ^candidates anElement ]. - - self halt: 'Unfinished - ambiguous' + ^ candidates first "Created: / 03-01-2012 / 21:40:23 / Jan Vrany " "Modified: / 03-04-2012 / 13:59:13 / Marcel Hlopko " - "Modified (format): / 20-04-2012 / 19:58:19 / Jan Vrany " + "Modified: / 14-09-2013 / 11:54:33 / Jan Vrany " ! type: actual matches: formal @@ -750,7 +749,13 @@ ]. "nil matches any formal type (to follow undocumented feature of JVM (also seen in CHECKCAST instruction :))" - actual == UndefinedObject ifTrue: [ ^ true ]. + actual == UndefinedObject ifTrue: [ ^ true ]. + + "char[] matches smalltal string..." + formal == Unicode16String ifTrue:[ + ^ actual inheritsFrom: CharacterArray + ]. + actual isJavaPrimitiveType ifTrue: [ ^ formal isJavaWrapperClass and: [ formal == actual javaWrapperClass ] ]. @@ -761,8 +766,8 @@ "Created: / 03-01-2012 / 22:36:19 / Jan Vrany " "Modified: / 03-04-2012 / 13:59:28 / Marcel Hlopko " - "Modified: / 29-10-2012 / 07:28:10 / Jan Vrany " "Modified: / 16-12-2012 / 11:44:17 / Marcel Hlopko " + "Modified: / 14-09-2013 / 11:05:55 / Jan Vrany " ! ! !JavaLookup::Smalltalk2Java methodsFor:'utilities (old)'! diff -r 658220e93dc9 -r ac412f6ea6d4 JavaMethod.st --- a/JavaMethod.st Thu Sep 12 00:24:05 2013 +0100 +++ b/JavaMethod.st Sat Sep 14 15:48:03 2013 +0100 @@ -72,7 +72,7 @@ UnresolvedClassSignal notifierString:'unresolved class'. ]. - ShowFullSource := false. + ShowFullSource := true. ForceByteCodeDisplay := false. A_PUBLIC := 16r0001. @@ -122,7 +122,7 @@ " "Modified: / 16-10-1998 / 01:29:48 / cg" - "Modified: / 11-09-2013 / 03:25:05 / Jan Vrany " + "Modified: / 14-09-2013 / 11:58:29 / Jan Vrany " ! reinitialize @@ -188,6 +188,14 @@ "Created: / 27.1.1998 / 21:50:05 / cg" ! ! +!JavaMethod class methodsFor:'accessing'! + +showFullSource + ^ ShowFullSource + + "Created: / 14-09-2013 / 11:56:04 / Jan Vrany " +! ! + !JavaMethod class methodsFor:'misc'! forceByteCodeDisplay @@ -946,6 +954,12 @@ "Created: / 15-04-2013 / 17:57:02 / Jan Vrany " ! +getSource + ^ source + + "Created: / 13-09-2013 / 01:41:33 / Jan Vrany " +! + getSourcePosition ^ 1 ! @@ -1301,8 +1315,7 @@ sourceString isNil ifTrue:[ ^ self decompiledSource. ]. - - + ShowFullSource ifTrue:[ ^ sourceString ]. source notNil ifTrue:[ ^ source readFrom: sourceString. ]. @@ -1314,7 +1327,7 @@ "/ see JavaSourceDocument | document | - ((document := self sourceDocument) notNil and:[document sourceTree notNil]) ifTrue:[ + ((document := self sourceDocument) notNil and:[document sourceTreeOrNilIfParsing notNil]) ifTrue:[ ^ source readFrom: sourceString. ] ]. @@ -1322,7 +1335,7 @@ "Modified: / 04-01-1998 / 13:48:35 / cg" "Modified: / 13-12-2010 / 11:06:51 / Jan Kurs " - "Modified: / 09-09-2013 / 12:44:19 / Jan Vrany " + "Modified: / 14-09-2013 / 12:01:49 / Jan Vrany " ! sourceDocument @@ -1920,9 +1933,11 @@ ! setSource:aJavaMethodSourceRef + self assert: aJavaMethodSourceRef class == JavaSourceRef. source := aJavaMethodSourceRef "Created: / 07-09-2013 / 01:44:47 / Jan Vrany " + "Modified: / 13-09-2013 / 02:19:50 / Jan Vrany " ! ! !JavaMethod methodsFor:'inspecting'! @@ -2414,7 +2429,7 @@ ShowFullSource ifFalse:[ source isNil ifTrue:[ "/ Fetch the source ref... - self sourceDocument sourceTree. + self sourceDocument sourceTreeOrNilIfParsing. source isNil ifTrue:[ ^ line0 - self firstInstructionLineNumber - 2. ]. @@ -2445,7 +2460,7 @@ ^ num "Modified: / 14-01-1998 / 13:30:54 / cg" - "Modified: / 11-09-2013 / 04:05:25 / Jan Vrany " + "Modified: / 13-09-2013 / 02:11:27 / Jan Vrany " ! messagesSent @@ -2498,29 +2513,6 @@ ^ javaClass package ! -quickLineNumberForPC:pc - |last| - - lineNumberTable notNil ifTrue:[ - lineNumberTable pairWiseDo:[:lPc :lNr | - lPc >= pc ifTrue:[ - lPc == pc ifTrue:[^ lNr]. - last isNil ifTrue:[^ lNr]. - ^ last. - ]. - last := lNr. - ]. - last notNil ifTrue:[ - ^ last - ]. - ^ lineNumberTable at:2 - ]. - ^ nil - - "Modified: / 14.1.1998 / 13:30:54 / cg" - "Created: / 10.11.1998 / 14:18:22 / cg" -! - referencesGlobal:aGlobalName "return true, if this method refers to a global named aGlobalName" @@ -2770,7 +2762,7 @@ ! version_SVN - ^ '§Id§' + ^ 'Id' ! ! diff -r 658220e93dc9 -r ac412f6ea6d4 Make.proto --- a/Make.proto Thu Sep 12 00:24:05 2013 +0100 +++ b/Make.proto Sat Sep 14 15:48:03 2013 +0100 @@ -34,7 +34,7 @@ # add the path(es) here:, # ********** OPTIONAL: MODIFY the next lines *** # LOCALINCLUDES=-Ifoo -Ibar -LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport/fdlibm -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libbasic3 -I$(INCLUDE_TOP)/stx/libbasic2 -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libview +LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport/fdlibm -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libbasic3 -I$(INCLUDE_TOP)/stx/libbasic2 -I$(INCLUDE_TOP)/stx/libview # if you need any additional defines for embedded C code, @@ -144,8 +144,6 @@ cd ../libbasic2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../libbasic3 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../libview && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../goodies/sunit && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" @@ -267,7 +265,7 @@ $(OUTDIR)ProxyMethodInvocationNode.$(O) ProxyMethodInvocationNode.$(H): ProxyMethodInvocationNode.st $(INCLUDE_TOP)/stx/libjava/ProxyMethodNode.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)ProxyMethodJavaFieldAccessor.$(O) ProxyMethodJavaFieldAccessor.$(H): ProxyMethodJavaFieldAccessor.st $(INCLUDE_TOP)/stx/libjava/ProxyMethodNode.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaByteCodePreresolver.$(O) JavaByteCodePreresolver.$(H): JavaByteCodePreresolver.st $(INCLUDE_TOP)/stx/libjava/JavaByteCodeProcessorAdapter.$(H) $(INCLUDE_TOP)/stx/libjava/JavaByteCodeProcessor.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) -$(OUTDIR)JavaClass.$(O) JavaClass.$(H): JavaClass.st $(INCLUDE_TOP)/stx/libjava/JavaConstants.$(H) $(INCLUDE_TOP)/stx/libjava/JavaBehavior.$(H) $(INCLUDE_TOP)/stx/libbasic/Class.$(H) $(INCLUDE_TOP)/stx/libbasic/ClassDescription.$(H) $(INCLUDE_TOP)/stx/libbasic/Behavior.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) +$(OUTDIR)JavaClass.$(O) JavaClass.$(H): JavaClass.st $(INCLUDE_TOP)/stx/libjava/JavaConstants.$(H) $(INCLUDE_TOP)/stx/libjava/JavaBehavior.$(H) $(INCLUDE_TOP)/stx/libbasic/Class.$(H) $(INCLUDE_TOP)/stx/libbasic/ClassDescription.$(H) $(INCLUDE_TOP)/stx/libbasic/Behavior.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libbasic/Array.$(H) $(INCLUDE_TOP)/stx/libbasic/ArrayedCollection.$(H) $(INCLUDE_TOP)/stx/libbasic/SequenceableCollection.$(H) $(INCLUDE_TOP)/stx/libbasic/Collection.$(H) $(STCHDR) $(OUTDIR)JavaClassPathBundle.$(O) JavaClassPathBundle.$(H): JavaClassPathBundle.st $(INCLUDE_TOP)/stx/libjava/JavaCodeBundle.$(H) $(INCLUDE_TOP)/stx/libjava/JavaCodeLibraryOrBundle.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaFieldRef2.$(O) JavaFieldRef2.$(H): JavaFieldRef2.st $(INCLUDE_TOP)/stx/libjava/JavaClassContentRef2.$(H) $(INCLUDE_TOP)/stx/libjava/JavaRef2.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaMethodAnalyzer.$(O) JavaMethodAnalyzer.$(H): JavaMethodAnalyzer.st $(INCLUDE_TOP)/stx/libjava/JavaByteCodeProcessorAdapter.$(H) $(INCLUDE_TOP)/stx/libjava/JavaByteCodeProcessor.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) diff -r 658220e93dc9 -r ac412f6ea6d4 abbrev.stc --- a/abbrev.stc Thu Sep 12 00:24:05 2013 +0100 +++ b/abbrev.stc Sat Sep 14 15:48:03 2013 +0100 @@ -37,6 +37,7 @@ JavaFieldRefTests JavaFieldRefTests stx:libjava 'Languages-Java-Tests-RuntimeConstantPool' 1 JavaFinalizationRegistry JavaFinalizationRegistry stx:libjava 'Languages-Java-Support' 0 JavaFreshlyInitializedResource JavaFreshlyInitializedResource stx:libjava 'Languages-Java-Tests' 1 +JavaInitializedResource JavaInitializedResource stx:libjava 'Languages-Java-Tests' 2 JavaInterfaceMethodRefTests JavaInterfaceMethodRefTests stx:libjava 'Languages-Java-Tests-RuntimeConstantPool' 1 JavaJUnitTests JavaJUnitTests stx:libjava 'Languages-Java-Tests-Libraries' 1 JavaLanguage JavaLanguage stx:libjava 'Languages-Java-Support' 1 @@ -113,7 +114,6 @@ JavaFieldAnnotationContainer JavaFieldAnnotationContainer stx:libjava 'Languages-Java-Annotations' 1 JavaFieldDescriptor JavaFieldDescriptor stx:libjava 'Languages-Java-Support' 0 JavaFieldDescriptorWithUnionType JavaFieldDescriptorWithUnionType stx:libjava 'Languages-Java-Support' 0 -JavaInitializedResource JavaInitializedResource stx:libjava 'Languages-Java-Tests' 2 JavaInvalidRefError JavaInvalidRefError stx:libjava 'Languages-Java-Support' 1 JavaMethod JavaMethod stx:libjava 'Languages-Java-Classes' 0 JavaMethodAnnotationContainer JavaMethodAnnotationContainer stx:libjava 'Languages-Java-Annotations' 1 diff -r 658220e93dc9 -r ac412f6ea6d4 bc.mak --- a/bc.mak Thu Sep 12 00:24:05 2013 +0100 +++ b/bc.mak Sat Sep 14 15:48:03 2013 +0100 @@ -34,7 +34,7 @@ -LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport\fdlibm -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libbasic3 -I$(INCLUDE_TOP)\stx\libbasic2 -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libview +LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport\fdlibm -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libbasic3 -I$(INCLUDE_TOP)\stx\libbasic2 -I$(INCLUDE_TOP)\stx\libview LOCALDEFINES= STCLOCALOPT=-package=$(PACKAGE) -I. $(LOCALINCLUDES) -headerDir=. $(STCLOCALOPTIMIZATIONS) $(STCWARNINGS) $(LOCALDEFINES) -varPrefix=$(LIBNAME) @@ -54,8 +54,6 @@ pushd ..\libbasic2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\libbasic3 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\libview & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\goodies\sunit & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " @@ -200,7 +198,7 @@ $(OUTDIR)ProxyMethodInvocationNode.$(O) ProxyMethodInvocationNode.$(H): ProxyMethodInvocationNode.st $(INCLUDE_TOP)\stx\libjava\ProxyMethodNode.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)ProxyMethodJavaFieldAccessor.$(O) ProxyMethodJavaFieldAccessor.$(H): ProxyMethodJavaFieldAccessor.st $(INCLUDE_TOP)\stx\libjava\ProxyMethodNode.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaByteCodePreresolver.$(O) JavaByteCodePreresolver.$(H): JavaByteCodePreresolver.st $(INCLUDE_TOP)\stx\libjava\JavaByteCodeProcessorAdapter.$(H) $(INCLUDE_TOP)\stx\libjava\JavaByteCodeProcessor.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) -$(OUTDIR)JavaClass.$(O) JavaClass.$(H): JavaClass.st $(INCLUDE_TOP)\stx\libjava\JavaConstants.$(H) $(INCLUDE_TOP)\stx\libjava\JavaBehavior.$(H) $(INCLUDE_TOP)\stx\libbasic\Class.$(H) $(INCLUDE_TOP)\stx\libbasic\ClassDescription.$(H) $(INCLUDE_TOP)\stx\libbasic\Behavior.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) +$(OUTDIR)JavaClass.$(O) JavaClass.$(H): JavaClass.st $(INCLUDE_TOP)\stx\libjava\JavaConstants.$(H) $(INCLUDE_TOP)\stx\libjava\JavaBehavior.$(H) $(INCLUDE_TOP)\stx\libbasic\Class.$(H) $(INCLUDE_TOP)\stx\libbasic\ClassDescription.$(H) $(INCLUDE_TOP)\stx\libbasic\Behavior.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libbasic\Array.$(H) $(INCLUDE_TOP)\stx\libbasic\ArrayedCollection.$(H) $(INCLUDE_TOP)\stx\libbasic\SequenceableCollection.$(H) $(INCLUDE_TOP)\stx\libbasic\Collection.$(H) $(STCHDR) $(OUTDIR)JavaClassPathBundle.$(O) JavaClassPathBundle.$(H): JavaClassPathBundle.st $(INCLUDE_TOP)\stx\libjava\JavaCodeBundle.$(H) $(INCLUDE_TOP)\stx\libjava\JavaCodeLibraryOrBundle.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaFieldRef2.$(O) JavaFieldRef2.$(H): JavaFieldRef2.st $(INCLUDE_TOP)\stx\libjava\JavaClassContentRef2.$(H) $(INCLUDE_TOP)\stx\libjava\JavaRef2.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaMethodAnalyzer.$(O) JavaMethodAnalyzer.$(H): JavaMethodAnalyzer.st $(INCLUDE_TOP)\stx\libjava\JavaByteCodeProcessorAdapter.$(H) $(INCLUDE_TOP)\stx\libjava\JavaByteCodeProcessor.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/JavaCompiler.st --- a/experiments/JavaCompiler.st Thu Sep 12 00:24:05 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,475 +0,0 @@ -" - 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:#JavaCompiler - instanceVariableNames:'analyzer className imports packageName sourceCode sourceDir - requestor classloader' - classVariableNames:'Problems' - poolDictionaries:'' - category:'Languages-Java-Support-Compiling' -! - -JavaParserII subclass:#ClassSourceAnalyzer - instanceVariableNames:'source package imports name terminator' - classVariableNames:'' - poolDictionaries:'' - privateIn:JavaCompiler -! - -!JavaCompiler 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. - -" -! - -documentation -" - An facade to Java compiler to compile Java classed from - source (given as string). - - Internally, it uses ECJ. See stx.libjava.compiler.ecj.CompilerAdapter. - - [author:] - Jan Vrany - Marcel Hlopko - - [instance variables:] - - [class variables:] - - [see also:] - -" -! - -history - - "Created: #dotJavaPathname / 13-12-2012 / 00:02:03 / Marcel Hlopko " -! ! - -!JavaCompiler class methodsFor:'initialization'! - -initialize - "Invoked at system start or when the class is dynamically loaded." - - "/ please change as required (and remove this comment) - - Problems := WeakIdentityDictionary new. - - "Modified: / 15-04-2013 / 21:40:23 / Jan Vrany " -! ! - -!JavaCompiler class methodsFor:'instance creation'! - -new - ^self basicNew initialize - - "Created: / 15-12-2012 / 16:48:31 / Jan Vrany " - "Modified: / 15-04-2013 / 20:43:51 / Jan Vrany " -! - -newAnalyzer - ^ClassSourceAnalyzer new - - "Created: / 15-12-2012 / 16:58:46 / Jan Vrany " -! ! - -!JavaCompiler class methodsFor:'accessing'! - -problems - ^Problems - - "Created: / 15-04-2013 / 21:39:36 / Jan Vrany " -! - -problemsForClass: aClass - ^Problems at: aClass ifAbsent:[#()]. - - "Created: / 15-04-2013 / 22:07:24 / Jan Vrany " -! ! - -!JavaCompiler class methodsFor:'compiler interface'! - -compile: source - "Compiles a new Groovy class given the source code" - - ^self new compile: source. - - "Created: / 27-02-2012 / 23:27:54 / Jan Vrany " -! - -compile:source forClass: class inCategory:cat notifying: requestor - ^ self compile:source forClass: class inCategory:cat notifying: requestor install: true. - - "Created: / 08-08-2013 / 23:48:59 / Jan Vrany " -! - -compile: source forClass: class inCategory: category notifying: requestor install: doInstall - "We allways compile whole class" - ^self compile: source register: true notifying: requestor - - "Created: / 21-02-2012 / 11:10:57 / Jan Vrany " - "Modified: / 03-04-2013 / 00:11:32 / Jan Vrany " -! - -compile:aString forClass:aClass inCategory:cat notifying:requestor - install:install skipIfSame:skipIfSame silent:silent - - "HACK. - Problem: - SmalltalkChunkFileReader always uses class's compiler to compile source. - However, when filing in Smalltalk extensions to Java classes, a Smalltalk - code is passed to me. - - See ClassCategoryReader>>fileInFrom:notifying:passChunk:single:silent: - - Workaround: - Detect such a situation and compile using Smalltalk compiler...bad, I know. - Better to move logic from Stream>>fileIn into SmalltalkChunkSourceFileReader. - " - - (requestor isKindOf: SourceFileLoader) ifTrue:[ - ^Compiler compile:aString forClass:aClass inCategory:cat notifying:requestor - install:install skipIfSame:skipIfSame silent:silent - ]. - - self breakPoint:#jv. - self error: 'Not (yet) supported' - - "Created: / 07-09-2012 / 10:35:43 / Jan Vrany " -! - -compile: source register: register notifying: requestor - "Called when a class is accepted" - | classes | - - classes := self new - requestor: requestor; - compile: source. - register ifTrue:[ - JavaVM registry registerClasses: classes andWait: true. - "/ Register class may eventually reload a class. When only methods are changed, - "/ reloader only updates method dictionary and constant pools and the new class - "/ is immediately thrown away. Thus, refetch classes... - classes := classes collect:[:cls|JavaVM registry classNamed: cls name loader: cls classLoader]. - ]. - ^classes first. - - "Created: / 03-04-2013 / 00:10:29 / Jan Vrany " - "Modified: / 04-08-2013 / 14:10:47 / Jan Vrany " -! - -evaluate: source notifying: requestor compile: doCompile - "Called when a class is accepted" - ^self compile: source register: true notifying: requestor - - "Created: / 04-04-2012 / 10:07:55 / Jan Vrany " - "Modified: / 03-04-2013 / 00:11:22 / Jan Vrany " -! ! - -!JavaCompiler methodsFor:'accessing'! - -requestor - ^ requestor -! - -requestor:anObject - requestor := anObject. -! ! - -!JavaCompiler methodsFor:'compiler interface'! - -compile:source in: class notifying: requestor ifFail: block - - requestor class == SourceFileLoader ifTrue:[ - ^Compiler compile:source in: class notifying: requestor ifFail: block - ]. - - self error:'Not yet supported'. - - "Created: / 04-09-2012 / 23:56:53 / Jan Vrany " -! ! - -!JavaCompiler methodsFor:'compiling'! - -compile:source - "Compiles a java class in given source code (passed as String). - Return an array of JavaClass which are not yet registered in Java - class registry nor initialiized. - - To make it accessible for Java code, caller must register returned - classes himself. - - Upon error, throws an exception" - - - | javac classfiles classes problems | - -"/ analyzer := self class newAnalyzer. -"/ analyzer analyze: source. -"/ analyzer fullName isNil ifTrue:[ -"/ self error:'Syntax error - cannot determine class name'. -"/ ^self. -"/ ]. - - classloader isNil ifTrue:[ - classloader := JavaClassReader classLoaderQuerySignal query. - classloader isNil ifTrue:[ - classloader := JavaVM systemClassLoader. - ] - ]. - - javac := (JavaVM classForName:'stx.libjava.tools.compiler.CompilerAdapter') new: - classloader. - - javac compile: source. - - "javac getResult hasErrors" - javac getClassFiles size == 0 ifTrue:[ - ^self error:'Compilation failed - nothing compiled' - ]. - - classfiles := javac getClassFiles. - classes := classfiles collect:[:each| - (JavaClassReader readStream: each getBytes readStream loader: classloader) - classLoader: classloader; - setSource: source; - setClassfileBytes: each getBytes; - yourself]. - - problems := javac getResult getProblems asNilIfEmpty. - classes do:[:each| - JavaCompilerProblemRegistry problemsFor: each put: problems - ]. - ^classes. - - "Created: / 15-12-2012 / 23:04:46 / Jan Vrany " - "Modified: / 16-12-2012 / 15:36:16 / Marcel Hlopko " - "Modified: / 11-09-2013 / 23:48:27 / Jan Vrany " -! ! - -!JavaCompiler::ClassSourceAnalyzer class methodsFor:'accessing'! - -ignoredNames - ^super ignoredNames , self instVarNames - - "Created: / 15-12-2012 / 17:17:22 / Jan Vrany " - "Modified: / 29-03-2013 / 23:08:54 / Jan Vrany " -! ! - -!JavaCompiler::ClassSourceAnalyzer 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 " - "Modified: #imports / 09-12-2012 / 09:21:09 / Marcel Hlopko " -! - -version_SVN - ^ '§Id:: §' -! ! - -!JavaCompiler::ClassSourceAnalyzer class methodsFor:'instance creation'! - -analyze: javaSourceCode - - ^ self new analyze: javaSourceCode. - - "Created: / 08-12-2012 / 18:47:26 / Marcel Hlopko " - "Modified (format): / 15-12-2012 / 16:59:36 / Jan Vrany " -! - -new - ^self newStartingAt: #compilationUnit - - "Created: / 15-12-2012 / 17:15:49 / Jan Vrany " -! ! - -!JavaCompiler::ClassSourceAnalyzer methodsFor:'accessing'! - -className - - ^ name - - "Created: / 08-12-2012 / 18:53:53 / Marcel Hlopko " - "Modified: / 15-12-2012 / 17:04:54 / Jan Vrany " -! - -fullName - ^package isNil - ifTrue:[name] - ifFalse:[package , '.' , name] - - "Created: / 29-03-2013 / 23:09:02 / Jan Vrany " -! - -imports - ^imports ? #() - - "Created: / 08-12-2012 / 20:01:41 / Marcel Hlopko " - "Modified: / 09-12-2012 / 09:21:09 / Marcel Hlopko " - "Modified: / 15-12-2012 / 17:20:06 / Jan Vrany " -! - -name - ^ name -! - -package - ^ package -! - -packageName - - ^package - - "Created: / 08-12-2012 / 18:50:26 / Marcel Hlopko " - "Modified: / 15-12-2012 / 17:56:22 / Jan Vrany " -! ! - -!JavaCompiler::ClassSourceAnalyzer methodsFor:'grammar'! - -importDeclaration -" - ^ ((self importKW) , (self staticKW) optional , qualifiedNameForImport - , (self tokenFor:';')). - " - ^ super importDeclaration ==> [:nodes | - imports isNil ifTrue:[imports := OrderedCollection new]. - imports add: (nodes at:3) value. - ]. - - "Created: / 15-12-2012 / 17:28:44 / Jan Vrany " -! - -packageDeclaration - -"/ ^ (self packageKW) , qualifiedName , (self tokenFor:';') - ^super packageDeclaration ==> [:nodes| package := nodes second ]. - - "Created: / 15-12-2012 / 22:44:08 / Jan Vrany " -! ! - -!JavaCompiler::ClassSourceAnalyzer methodsFor:'grammar-classes'! - -typeNameIdentifier - " - ^identifier - " - ^super typeNameIdentifier ==> [:ident | - name := ident. - terminator value - ] - - "Created: / 15-04-2013 / 21:24:37 / Jan Vrany " -! ! - -!JavaCompiler::ClassSourceAnalyzer methodsFor:'parsing'! - -analyze: aString - source := aString. - terminator := [ ^ self ]. - self parse: source. - - "Created: / 08-12-2012 / 18:48:56 / Marcel Hlopko " - "Modified: / 15-12-2012 / 17:04:18 / Jan Vrany " -! ! - -!JavaCompiler class methodsFor:'documentation'! - -version_CVS - ^ '$Header: /cvs/stx/stx/libjava/experiments/JavaCompiler.st,v 1.2 2013-02-25 11:15:34 vrany Exp $' -! - -version_HG - - ^ '$Changeset: $' -! - -version_SVN - ^ '§Id:: §' -! ! - - -JavaCompiler initialize! diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/Make.proto --- a/experiments/Make.proto Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/Make.proto Sat Sep 14 15:48:03 2013 +0100 @@ -34,7 +34,7 @@ # add the path(es) here:, # ********** OPTIONAL: MODIFY the next lines *** # LOCALINCLUDES=-Ifoo -Ibar -LOCALINCLUDES= -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/goodies/petitparser -I$(INCLUDE_TOP)/stx/libjava -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libjava/tools +LOCALINCLUDES= -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libjava # if you need any additional defines for embedded C code, @@ -134,20 +134,10 @@ # build all mandatory prerequisite packages (containing superclasses) for this package prereq: cd ../../libbasic && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../goodies/refactoryBrowser/parser && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../libbasic2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../libbasic3 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libcomp && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libui && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../libview && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../goodies/petitparser && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../ && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../goodies/sunit && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libwidg && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libwidg2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libtool && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../tools && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" @@ -168,7 +158,6 @@ # BEGINMAKEDEPEND --- do not remove this line; make depend needs it $(OUTDIR)JavaByteCodeInterpreter.$(O) JavaByteCodeInterpreter.$(H): JavaByteCodeInterpreter.st $(INCLUDE_TOP)/stx/libjava/JavaByteCodeProcessor.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) -$(OUTDIR)JavaCompiler.$(O) JavaCompiler.$(H): JavaCompiler.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaParserII.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaParserI.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPCompositeParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPDelegateParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPParser.$(H) $(STCHDR) $(OUTDIR)JavaCompilerProblemRegistry.$(O) JavaCompilerProblemRegistry.$(H): JavaCompilerProblemRegistry.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaMethodWrapperCompiler.$(O) JavaMethodWrapperCompiler.$(H): JavaMethodWrapperCompiler.st $(INCLUDE_TOP)/stx/libjava/Java.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)NoReflectionObject.$(O) NoReflectionObject.$(H): NoReflectionObject.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/Make.spec --- a/experiments/Make.spec Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/Make.spec Sat Sep 14 15:48:03 2013 +0100 @@ -51,7 +51,6 @@ COMMON_CLASSES= \ JavaByteCodeInterpreter \ - JavaCompiler \ JavaCompilerProblemRegistry \ JavaMethodWrapperCompiler \ NoReflectionObject \ @@ -66,7 +65,6 @@ COMMON_OBJS= \ $(OUTDIR_SLASH)JavaByteCodeInterpreter.$(O) \ - $(OUTDIR_SLASH)JavaCompiler.$(O) \ $(OUTDIR_SLASH)JavaCompilerProblemRegistry.$(O) \ $(OUTDIR_SLASH)JavaMethodWrapperCompiler.$(O) \ $(OUTDIR_SLASH)NoReflectionObject.$(O) \ diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/abbrev.stc --- a/experiments/abbrev.stc Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/abbrev.stc Sat Sep 14 15:48:03 2013 +0100 @@ -5,7 +5,6 @@ JavaByteCodeInterpreter JavaByteCodeInterpreter stx:libjava/experiments 'Languages-Java-Bytecode' 0 JavaByteCodeInterpreterTests JavaByteCodeInterpreterTests stx:libjava/experiments 'Languages-Java-Tests' 1 JavaClassReloadingTests JavaClassReloadingTests stx:libjava/experiments 'Languages-Java-Tests-ClassReloading' 1 -JavaCompiler JavaCompiler stx:libjava/experiments 'Languages-Java-Support-Compiling' 0 JavaCompilerProblemRegistry JavaCompilerProblemRegistry stx:libjava/experiments 'Languages-Java-Support-Compiling' 1 JavaCompilerTests JavaCompilerTests stx:libjava/experiments 'Languages-Java-Tests-Compiling' 1 JavaMethodWrapperCompiler JavaMethodWrapperCompiler stx:libjava/experiments 'Languages-Java-Experiments-Lookup' 0 diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/bc.mak --- a/experiments/bc.mak Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/bc.mak Sat Sep 14 15:48:03 2013 +0100 @@ -34,7 +34,7 @@ -LOCALINCLUDES= -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\goodies\petitparser -I$(INCLUDE_TOP)\stx\libjava -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libjava\tools +LOCALINCLUDES= -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libjava LOCALDEFINES= STCLOCALOPT=-package=$(PACKAGE) -I. $(LOCALINCLUDES) -headerDir=. $(STCLOCALOPTIMIZATIONS) $(STCWARNINGS) $(LOCALDEFINES) -varPrefix=$(LIBNAME) @@ -51,20 +51,10 @@ # build all mandatory prerequisite packages (containing superclasses) for this package prereq: pushd ..\..\libbasic & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\goodies\refactoryBrowser\parser & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\libbasic2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\libbasic3 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libcomp & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libui & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\libview & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\goodies\petitparser & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd .. & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\goodies\sunit & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libwidg & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libwidg2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libtool & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\tools & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " @@ -92,7 +82,6 @@ # BEGINMAKEDEPEND --- do not remove this line; make depend needs it $(OUTDIR)JavaByteCodeInterpreter.$(O) JavaByteCodeInterpreter.$(H): JavaByteCodeInterpreter.st $(INCLUDE_TOP)\stx\libjava\JavaByteCodeProcessor.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) -$(OUTDIR)JavaCompiler.$(O) JavaCompiler.$(H): JavaCompiler.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaParserII.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaParserI.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPCompositeParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPDelegateParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPParser.$(H) $(STCHDR) $(OUTDIR)JavaCompilerProblemRegistry.$(O) JavaCompilerProblemRegistry.$(H): JavaCompilerProblemRegistry.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaMethodWrapperCompiler.$(O) JavaMethodWrapperCompiler.$(H): JavaMethodWrapperCompiler.st $(INCLUDE_TOP)\stx\libjava\Java.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)NoReflectionObject.$(O) NoReflectionObject.$(H): NoReflectionObject.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/experiments.rc --- a/experiments/experiments.rc Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/experiments.rc Sat Sep 14 15:48:03 2013 +0100 @@ -25,7 +25,7 @@ VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2013\nCopyright eXept Software AG 1998-2013\0" VALUE "ProductName", "Smalltalk/X\0" VALUE "ProductVersion", "6.2.3.0\0" - VALUE "ProductDate", "Wed, 11 Sep 2013 23:09:06 GMT\0" + VALUE "ProductDate", "Sat, 14 Sep 2013 14:14:43 GMT\0" END END diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/libInit.cc --- a/experiments/libInit.cc Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/libInit.cc Sat Sep 14 15:48:03 2013 +0100 @@ -28,7 +28,6 @@ OBJ snd; struct __vmData__ *__pRT__; { __BEGIN_PACKAGE2__("libstx_libjava_experiments", _libstx_libjava_experiments_Init, "stx:libjava/experiments"); _JavaByteCodeInterpreter_Init(pass,__pRT__,snd); -_JavaCompiler_Init(pass,__pRT__,snd); _JavaCompilerProblemRegistry_Init(pass,__pRT__,snd); _JavaMethodWrapperCompiler_Init(pass,__pRT__,snd); _NoReflectionObject_Init(pass,__pRT__,snd); diff -r 658220e93dc9 -r ac412f6ea6d4 experiments/stx_libjava_experiments.st --- a/experiments/stx_libjava_experiments.st Thu Sep 12 00:24:05 2013 +0100 +++ b/experiments/stx_libjava_experiments.st Sat Sep 14 15:48:03 2013 +0100 @@ -76,11 +76,8 @@ (the browser has a menu function for that)" ^ #( - #'stx:goodies/petitparser' "PPCompositeParser - superclass of JavaCompiler::ClassSourceAnalyzer " - #'stx:goodies/sunit' "TestAsserter - superclass of JavaClassReloadingTests " #'stx:libbasic' "Autoload - superclass of Benchmarks::JavaLookup " #'stx:libjava' "Java - superclass of JavaMethodWrapperCompiler " - #'stx:libjava/tools' "JavaParserI - superclass of JavaCompiler::ClassSourceAnalyzer " ) ! @@ -111,7 +108,6 @@ exclude individual packages in the #excludedFromPreRequisites method." ^ #( - #'stx:libcomp' "SourceFileLoader - referenced by JavaCompiler class>>compile:forClass:inCategory:notifying:install:skipIfSame:silent: " ) ! @@ -188,7 +184,6 @@ JavaByteCodeInterpreter (JavaByteCodeInterpreterTests autoload) (JavaClassReloadingTests autoload) - JavaCompiler JavaCompilerProblemRegistry (JavaCompilerTests autoload) JavaMethodWrapperCompiler diff -r 658220e93dc9 -r ac412f6ea6d4 libjava.rc --- a/libjava.rc Thu Sep 12 00:24:05 2013 +0100 +++ b/libjava.rc Sat Sep 14 15:48:03 2013 +0100 @@ -25,7 +25,7 @@ VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\nCopyright Jan Vrany, Jan Kurs and Marcel Hlopko\n SWING Research Group, Czech Technical University In Prague\0" VALUE "ProductName", "Smalltalk/X\0" VALUE "ProductVersion", "6.2.3.0\0" - VALUE "ProductDate", "Wed, 11 Sep 2013 23:10:30 GMT\0" + VALUE "ProductDate", "Sat, 14 Sep 2013 14:15:46 GMT\0" END END diff -r 658220e93dc9 -r ac412f6ea6d4 stx_libjava.st --- a/stx_libjava.st Thu Sep 12 00:24:05 2013 +0100 +++ b/stx_libjava.st Sat Sep 14 15:48:03 2013 +0100 @@ -156,7 +156,6 @@ (the browser has a menu function for that)" ^ #( - #'stx:goodies/sunit' "TestAsserter - superclass of JavaAntProjectResource " #'stx:libbasic' "AbstractNumberVector - extended " #'stx:libbasic2' "BitArray - extended " #'stx:libbasic3' "WrappedMethod - extended " @@ -173,10 +172,11 @@ exclude individual packages in the #excludedFromPreRequisites method." ^ #( + #'stx:goodies/sunit' "TestSuite - referenced by JavaTestsLoader class>>buildSuiteFrom: " #'stx:libcomp' "BlockNode - referenced by JavaNativeMethod>>numberOfArgs: " #'stx:libhtml' "URL - referenced by JavaEmbeddedFrameView>>setupAppletFrameIn:initializeJava: " #'stx:libjava/experiments' "JavaByteCodeInterpreter - referenced by JavaMethod>>interpretWithReceiver:arguments: " - #'stx:libjava/tools' "JavaParser - referenced by GroovyLanguage>>parserClass " + #'stx:libjava/tools' "JavaCompiler - referenced by JavaClassReloader::SingleClassReloader>>updateOldClass " #'stx:libtool' "DebugView - referenced by Java class>>flushClasses " #'stx:libview2' "GIFReader - referenced by JavaNativeMethodImpl_OpenJDK6 class>>_GifImageDecoder_parseImage: " #'stx:libwidg' "Button - referenced by JavaNativeMethodImpl_OpenJDK6 class>>_WButtonPeer_create: " @@ -341,6 +341,7 @@ (JavaFieldRefTests autoload) JavaFinalizationRegistry (JavaFreshlyInitializedResource autoload) + (JavaInitializedResource autoload) (JavaInterfaceMethodRefTests autoload) (JavaJUnitTests autoload) JavaLanguage @@ -417,7 +418,6 @@ JavaFieldAnnotationContainer JavaFieldDescriptor JavaFieldDescriptorWithUnionType - (JavaInitializedResource autoload) JavaInvalidRefError JavaMethod JavaMethodAnnotationContainer diff -r 658220e93dc9 -r ac412f6ea6d4 tools/JavaCompiler.st --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/JavaCompiler.st Sat Sep 14 15:48:03 2013 +0100 @@ -0,0 +1,475 @@ +" + 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/tools' }" + +Object subclass:#JavaCompiler + instanceVariableNames:'analyzer className imports packageName sourceCode sourceDir + requestor classloader' + classVariableNames:'Problems' + poolDictionaries:'' + category:'Languages-Java-Support-Compiling' +! + +JavaParserII subclass:#ClassSourceAnalyzer + instanceVariableNames:'source package imports name terminator' + classVariableNames:'' + poolDictionaries:'' + privateIn:JavaCompiler +! + +!JavaCompiler 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. + +" +! + +documentation +" + An facade to Java compiler to compile Java classed from + source (given as string). + + Internally, it uses ECJ. See stx.libjava.compiler.ecj.CompilerAdapter. + + [author:] + Jan Vrany + Marcel Hlopko + + [instance variables:] + + [class variables:] + + [see also:] + +" +! + +history + + "Created: #dotJavaPathname / 13-12-2012 / 00:02:03 / Marcel Hlopko " +! ! + +!JavaCompiler class methodsFor:'initialization'! + +initialize + "Invoked at system start or when the class is dynamically loaded." + + "/ please change as required (and remove this comment) + + Problems := WeakIdentityDictionary new. + + "Modified: / 15-04-2013 / 21:40:23 / Jan Vrany " +! ! + +!JavaCompiler class methodsFor:'instance creation'! + +new + ^self basicNew initialize + + "Created: / 15-12-2012 / 16:48:31 / Jan Vrany " + "Modified: / 15-04-2013 / 20:43:51 / Jan Vrany " +! + +newAnalyzer + ^ClassSourceAnalyzer new + + "Created: / 15-12-2012 / 16:58:46 / Jan Vrany " +! ! + +!JavaCompiler class methodsFor:'accessing'! + +problems + ^Problems + + "Created: / 15-04-2013 / 21:39:36 / Jan Vrany " +! + +problemsForClass: aClass + ^Problems at: aClass ifAbsent:[#()]. + + "Created: / 15-04-2013 / 22:07:24 / Jan Vrany " +! ! + +!JavaCompiler class methodsFor:'compiler interface'! + +compile: source + "Compiles a new Groovy class given the source code" + + ^self new compile: source. + + "Created: / 27-02-2012 / 23:27:54 / Jan Vrany " +! + +compile:source forClass: class inCategory:cat notifying: requestor + ^ self compile:source forClass: class inCategory:cat notifying: requestor install: true. + + "Created: / 08-08-2013 / 23:48:59 / Jan Vrany " +! + +compile: source forClass: class inCategory: cat notifying: requestor install: doInstall + "We allways compile whole class" + ^self compile: source register: true notifying: requestor + + "Created: / 21-02-2012 / 11:10:57 / Jan Vrany " + "Modified: / 03-04-2013 / 00:11:32 / Jan Vrany " +! + +compile:aString forClass:aClass inCategory:cat notifying:requestor + install:install skipIfSame:skipIfSame silent:silent + + "HACK. + Problem: + SmalltalkChunkFileReader always uses class's compiler to compile source. + However, when filing in Smalltalk extensions to Java classes, a Smalltalk + code is passed to me. + + See ClassCategoryReader>>fileInFrom:notifying:passChunk:single:silent: + + Workaround: + Detect such a situation and compile using Smalltalk compiler...bad, I know. + Better to move logic from Stream>>fileIn into SmalltalkChunkSourceFileReader. + " + + (requestor isKindOf: SourceFileLoader) ifTrue:[ + ^Compiler compile:aString forClass:aClass inCategory:cat notifying:requestor + install:install skipIfSame:skipIfSame silent:silent + ]. + + self breakPoint:#jv. + self error: 'Not (yet) supported' + + "Created: / 07-09-2012 / 10:35:43 / Jan Vrany " +! + +compile: source register: register notifying: requestor + "Called when a class is accepted" + | classes | + + classes := self new + requestor: requestor; + compile: source. + register ifTrue:[ + JavaVM registry registerClasses: classes andWait: true. + "/ Register class may eventually reload a class. When only methods are changed, + "/ reloader only updates method dictionary and constant pools and the new class + "/ is immediately thrown away. Thus, refetch classes... + classes := classes collect:[:cls|JavaVM registry classNamed: cls name loader: cls classLoader]. + ]. + ^classes first. + + "Created: / 03-04-2013 / 00:10:29 / Jan Vrany " + "Modified: / 04-08-2013 / 14:10:47 / Jan Vrany " +! + +evaluate: source notifying: requestor compile: doCompile + "Called when a class is accepted" + ^self compile: source register: true notifying: requestor + + "Created: / 04-04-2012 / 10:07:55 / Jan Vrany " + "Modified: / 03-04-2013 / 00:11:22 / Jan Vrany " +! ! + +!JavaCompiler methodsFor:'accessing'! + +requestor + ^ requestor +! + +requestor:anObject + requestor := anObject. +! ! + +!JavaCompiler methodsFor:'compiler interface'! + +compile:source in: class notifying: requestor ifFail: block + + requestor class == SourceFileLoader ifTrue:[ + ^Compiler compile:source in: class notifying: requestor ifFail: block + ]. + + self error:'Not yet supported'. + + "Created: / 04-09-2012 / 23:56:53 / Jan Vrany " +! ! + +!JavaCompiler methodsFor:'compiling'! + +compile:source + "Compiles a java class in given source code (passed as String). + Return an array of JavaClass which are not yet registered in Java + class registry nor initialiized. + + To make it accessible for Java code, caller must register returned + classes himself. + + Upon error, throws an exception" + + + | javac classfiles classes problems | + +"/ analyzer := self class newAnalyzer. +"/ analyzer analyze: source. +"/ analyzer fullName isNil ifTrue:[ +"/ self error:'Syntax error - cannot determine class name'. +"/ ^self. +"/ ]. + + classloader isNil ifTrue:[ + classloader := JavaClassReader classLoaderQuerySignal query. + classloader isNil ifTrue:[ + classloader := JavaVM systemClassLoader. + ] + ]. + + javac := (JavaVM classForName:'stx.libjava.tools.compiler.CompilerAdapter') new: + classloader. + + javac compile: source. + + "javac getResult hasErrors" + javac getClassFiles size == 0 ifTrue:[ + ^self error:'Compilation failed - nothing compiled' + ]. + + classfiles := javac getClassFiles. + classes := classfiles collect:[:each| + (JavaClassReader readStream: each getBytes readStream loader: classloader) + classLoader: classloader; + setSource: source; + setClassfileBytes: each getBytes; + yourself]. + + problems := javac getResult getProblems asNilIfEmpty. + classes do:[:each| + JavaCompilerProblemRegistry problemsFor: each put: problems + ]. + ^classes. + + "Created: / 15-12-2012 / 23:04:46 / Jan Vrany " + "Modified: / 16-12-2012 / 15:36:16 / Marcel Hlopko " + "Modified: / 11-09-2013 / 23:48:27 / Jan Vrany " +! ! + +!JavaCompiler::ClassSourceAnalyzer class methodsFor:'accessing'! + +ignoredNames + ^super ignoredNames , self instVarNames + + "Created: / 15-12-2012 / 17:17:22 / Jan Vrany " + "Modified: / 29-03-2013 / 23:08:54 / Jan Vrany " +! ! + +!JavaCompiler::ClassSourceAnalyzer 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 " + "Modified: #imports / 09-12-2012 / 09:21:09 / Marcel Hlopko " +! + +version_SVN + ^ '§Id:: §' +! ! + +!JavaCompiler::ClassSourceAnalyzer class methodsFor:'instance creation'! + +analyze: javaSourceCode + + ^ self new analyze: javaSourceCode. + + "Created: / 08-12-2012 / 18:47:26 / Marcel Hlopko " + "Modified (format): / 15-12-2012 / 16:59:36 / Jan Vrany " +! + +new + ^self newStartingAt: #compilationUnit + + "Created: / 15-12-2012 / 17:15:49 / Jan Vrany " +! ! + +!JavaCompiler::ClassSourceAnalyzer methodsFor:'accessing'! + +className + + ^ name + + "Created: / 08-12-2012 / 18:53:53 / Marcel Hlopko " + "Modified: / 15-12-2012 / 17:04:54 / Jan Vrany " +! + +fullName + ^package isNil + ifTrue:[name] + ifFalse:[package , '.' , name] + + "Created: / 29-03-2013 / 23:09:02 / Jan Vrany " +! + +imports + ^imports ? #() + + "Created: / 08-12-2012 / 20:01:41 / Marcel Hlopko " + "Modified: / 09-12-2012 / 09:21:09 / Marcel Hlopko " + "Modified: / 15-12-2012 / 17:20:06 / Jan Vrany " +! + +name + ^ name +! + +package + ^ package +! + +packageName + + ^package + + "Created: / 08-12-2012 / 18:50:26 / Marcel Hlopko " + "Modified: / 15-12-2012 / 17:56:22 / Jan Vrany " +! ! + +!JavaCompiler::ClassSourceAnalyzer methodsFor:'grammar'! + +importDeclaration +" + ^ ((self importKW) , (self staticKW) optional , qualifiedNameForImport + , (self tokenFor:';')). + " + ^ super importDeclaration ==> [:nodes | + imports isNil ifTrue:[imports := OrderedCollection new]. + imports add: (nodes at:3) value. + ]. + + "Created: / 15-12-2012 / 17:28:44 / Jan Vrany " +! + +packageDeclaration + +"/ ^ (self packageKW) , qualifiedName , (self tokenFor:';') + ^super packageDeclaration ==> [:nodes| package := nodes second ]. + + "Created: / 15-12-2012 / 22:44:08 / Jan Vrany " +! ! + +!JavaCompiler::ClassSourceAnalyzer methodsFor:'grammar-classes'! + +typeNameIdentifier + " + ^identifier + " + ^super typeNameIdentifier ==> [:ident | + name := ident. + terminator value + ] + + "Created: / 15-04-2013 / 21:24:37 / Jan Vrany " +! ! + +!JavaCompiler::ClassSourceAnalyzer methodsFor:'parsing'! + +analyze: aString + source := aString. + terminator := [ ^ self ]. + self parse: source. + + "Created: / 08-12-2012 / 18:48:56 / Marcel Hlopko " + "Modified: / 15-12-2012 / 17:04:18 / Jan Vrany " +! ! + +!JavaCompiler class methodsFor:'documentation'! + +version_CVS + ^ '$Header: /cvs/stx/stx/libjava/experiments/JavaCompiler.st,v 1.2 2013-02-25 11:15:34 vrany Exp $' +! + +version_HG + + ^ '$Changeset: $' +! + +version_SVN + ^ '§Id:: §' +! ! + + +JavaCompiler initialize! diff -r 658220e93dc9 -r ac412f6ea6d4 tools/JavaSourceDocument.st --- a/tools/JavaSourceDocument.st Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/JavaSourceDocument.st Sat Sep 14 15:48:03 2013 +0100 @@ -143,6 +143,7 @@ ! sourceTree + "Return source tree for my class's compilation unit (i.e., CompilationUnitDeclaration)" sourceTree isNil ifTrue:[ sourceTreeLock notNil ifTrue:[ sourceTreeLock wait. @@ -151,6 +152,50 @@ ^ sourceTree "Modified: / 06-09-2013 / 22:58:26 / Jan Vrany " + "Modified (comment): / 13-09-2013 / 04:22:49 / Jan Vrany " +! + +sourceTreeForClass + "Returns a root node (i.e., instance of TypeDeclaration) for my javaClass" + + ^ self sourceTreeForClass: javaClass. + + "Created: / 13-09-2013 / 04:20:59 / Jan Vrany " + "Modified: / 13-09-2013 / 11:08:24 / Jan Vrany " +! + +sourceTreeForClass: aJavaClass + "Returns a root node (i.e., instance of TypeDeclaration) for my javaClass" + + | enclosingClass enclosingClassNode nm | + + enclosingClass := aJavaClass enclosingClass. + ^ enclosingClass notNil ifTrue:[ + nm := aJavaClass name copyFrom: enclosingClass name size + 2. + (nm conform: [:c|c isDigit]) ifTrue:[ + "/ Could only by anonymous class created in static initializer + self error: 'Should not happen' + ] ifFalse:[ + enclosingClassNode := self sourceTreeForClass: enclosingClass. + enclosingClassNode memberTypes detect: [:type | type name = nm ] ifNone:[self error:'No member type']. + ] + ] ifFalse:[ + nm := aJavaClass lastName. + sourceTree types detect: [:type | type name = nm] ifNone:[self error:'No type']. + ]. + + "Created: / 13-09-2013 / 11:06:53 / Jan Vrany " +! + +sourceTreeOrNilIfParsing + sourceTree isNil ifTrue:[ + sourceTreeLock notNil ifTrue:[ + ^ nil + ]. + ]. + ^ sourceTree + + "Created: / 12-09-2013 / 21:40:39 / Jan Vrany " ! ! !JavaSourceDocument methodsFor:'debugging'! @@ -183,22 +228,23 @@ !JavaSourceDocument methodsFor:'initialization-private'! initializeSourceRefsInMethods - | typeName typeNode | - - typeName := javaClass lastName. - (typeName includes: $$) ifTrue: [ - | components | + | enclosingMethod typeName typeNode | - components := typeName tokensBasedOn: $$. - typeNode := sourceTree types - detect: [:each | each name = components first ]. - 2 to: components size do: [:i | - typeNode := typeNode memberTypes - detect: [:each | each name = (components at: i) ]. + enclosingMethod := javaClass enclosingMethod. + (enclosingMethod isNil and:[javaClass isAnonymous]) ifTrue:[ + enclosingMethod := javaClass topEnclosingClass compiledMethodAt: #'()V'. + ]. + enclosingMethod notNil ifTrue:[ + javaClass methodDictionary keysAndValuesDo: [:selector :method | + method setSource: (enclosingMethod source; getSource). ]. - ] ifFalse: [ - typeNode := sourceTree types detect: [:each | each name = typeName ]. + ^ self ]. + + + + + typeNode := self sourceTreeForClass. javaClass methodDictionary keysAndValuesDo: [:selector :method | | descriptor methodName methodNodes methodNode source | @@ -286,34 +332,66 @@ ] "Created: / 07-09-2013 / 01:43:06 / Jan Vrany " - "Modified: / 11-09-2013 / 04:10:27 / Jan Vrany " + "Modified: / 13-09-2013 / 11:24:46 / Jan Vrany " ! initializeSourceTree + | task | + sourceTreeLock := Semaphore new. - Job - add: [ - [ - | source unit parser | + "Job add:" + task := [ + [ + | source unit parser | - source := javaClass theNonMetaclass source. - source notNil ifTrue: [ - unit := (Java classForName: 'stx.libjava.tools.Source') new. - unit setContents: source. - parser := (Java classForName: 'stx.libjava.tools.parser.Parser') - new. - sourceTree := parser parse: unit diet: true. - sourceLineEnds := parser scanner getLineEnds. - self initializeSourceRefsInMethods. - ]. - ] ensure: [ - sourceTreeLock signal. - sourceTreeLock := nil. - ] + source := javaClass theNonMetaclass source. + source notNil ifTrue: [ + unit := (Java classForName: 'stx.libjava.tools.Source') new. + unit setContents: source. + parser := (Java classForName: 'stx.libjava.tools.parser.Parser') + new. + sourceTree := parser parse: unit diet: true resolve: false. + sourceLineEnds := parser scanner getLineEnds. + self initializeSourceRefsInMethods. + ]. + ] ensure: [ + sourceTreeLock signal. + sourceTreeLock := nil. ] + ] newProcess. + task name: 'Parse task for ', javaClass name. + task resume. "Created: / 06-09-2013 / 17:50:54 / Jan Vrany " - "Modified: / 11-09-2013 / 22:50:27 / Jan Vrany " + "Modified: / 13-09-2013 / 17:35:37 / Jan Vrany " +! ! + +!JavaSourceDocument methodsFor:'printing & storing'! + +printOn:aStream + "append a printed representation if the receiver to the argument, aStream" + + super printOn:aStream. + aStream nextPutAll:'('. + javaClass printOn:aStream. + aStream nextPutAll:')'. + + "Modified: / 12-09-2013 / 01:04:02 / Jan Vrany " +! ! + +!JavaSourceDocument methodsFor:'resolving'! + +resolve + | resolver | + + self sourceTree. "/Ensure source is parsed. + sourceTree scope isNil ifTrue:[ + resolver := (Java classForName: 'stx.libjava.tools.environment.Resolver') new. + resolver resolve: sourceTree. + ]. + + "Created: / 12-09-2013 / 22:43:02 / Jan Vrany " + "Modified: / 13-09-2013 / 02:19:01 / Jan Vrany " ! ! !JavaSourceDocument class methodsFor:'documentation'! diff -r 658220e93dc9 -r ac412f6ea6d4 tools/JavaSourceHighlighter.st --- a/tools/JavaSourceHighlighter.st Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/JavaSourceHighlighter.st Sat Sep 14 15:48:03 2013 +0100 @@ -220,6 +220,11 @@ preferences isNil ifTrue:[ preferences := UserPreferences current. ]. + + JavaMethod showFullSource ifTrue:[ + ^self formatClassDefinition: source in: class + ]. + sourceText := source asText. self doLexicalHighlightingOnly ifTrue:[ @@ -231,7 +236,7 @@ ex ]. ] ifFalse:[ - | document parser marker nodes | + | document type parser marker nodes debug | document := JavaSourceDocument cachedDocumentFor: class theNonMetaclass. document isNil ifTrue:[ @@ -239,17 +244,24 @@ JavaSourceDocument cachedDocumentFor: class theNonMetaclass put: document. ]. + + document resolve. + type := document sourceTreeForClass: class theNonMetaclass. marker := Marker new. marker highlighter: self. - parser := (Java classForName:'stx.libjava.tools.source.JavaSourceHighlighter') new. + parser := (Java classForName:'stx.libjava.tools.text.Highlighter') new. parser setMarker: marker. - nodes := parser parseClassBodyDeclarations: source string from: 0 to: source size unit: document sourceTree. - nodes. + + debug := false. + nodes := parser parseClassBodyDeclarations: source string unit: document sourceTree copy type: type copy resolve: debug. + debug ifTrue:[ + nodes inspect. + ] ]. ^ sourceText "Created: / 04-08-2011 / 23:45:10 / Jan Vrany " - "Modified: / 09-09-2013 / 02:35:08 / Jan Vrany " + "Modified: / 14-09-2013 / 11:57:29 / Jan Vrany " ! formatMethod:mth source:source in:class using: prefs elementsInto: els @@ -322,9 +334,9 @@ ] on: Error do:[:ex| ]. ] ifFalse:[ - sourceUnit := (Java classForName:'stx.libjava.tools.source.JavaSource') new. + sourceUnit := (Java classForName:'stx.libjava.tools.Source') new. sourceUnit setContents: source string. - parser := (Java classForName:'stx.libjava.tools.source.JavaSourceHighlighter') new. + parser := (Java classForName:'stx.libjava.tools.text.Highlighter') new. parser setMarker: marker. parser parse: sourceUnit diet: false. ]. @@ -341,7 +353,7 @@ ] "Created: / 17-03-2012 / 14:02:24 / Jan Vrany " - "Modified: / 09-09-2013 / 10:26:43 / Jan Vrany " + "Modified: / 12-09-2013 / 01:02:47 / Jan Vrany " ! ! !JavaSourceHighlighter methodsFor:'queries'! diff -r 658220e93dc9 -r ac412f6ea6d4 tools/Make.proto --- a/tools/Make.proto Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/Make.proto Sat Sep 14 15:48:03 2013 +0100 @@ -141,9 +141,10 @@ cd ../../libui && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../libview && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../goodies/petitparser && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" + cd ../../libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" + cd ../../goodies/sunit && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" + cd ../../libwidg && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../ && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" - cd ../../libwidg && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../libwidg2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" cd ../../libtool && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)" @@ -191,6 +192,7 @@ $(OUTDIR)JavaParserII.$(O) JavaParserII.$(H): JavaParserII.st $(INCLUDE_TOP)/stx/libjava/tools/JavaParserI.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPCompositeParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPDelegateParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPParser.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaScanner.$(O) JavaScanner.$(H): JavaScanner.st $(INCLUDE_TOP)/stx/libjava/tools/JavaScannerBase.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaSourceFile.$(O) JavaSourceFile.$(H): JavaSourceFile.st $(INCLUDE_TOP)/stx/libjava/tools/JavaParseNode.$(H) $(INCLUDE_TOP)/stx/libcomp/ParseNode.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) +$(OUTDIR)JavaCompiler.$(O) JavaCompiler.$(H): JavaCompiler.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaParserII.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaParserI.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPCompositeParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPDelegateParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPParser.$(H) $(STCHDR) $(OUTDIR)JavaMethodLikeDeclarationNode.$(O) JavaMethodLikeDeclarationNode.$(H): JavaMethodLikeDeclarationNode.st $(INCLUDE_TOP)/stx/libjava/tools/JavaDeclarationNode.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaParseNode.$(H) $(INCLUDE_TOP)/stx/libcomp/ParseNode.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaParser.$(O) JavaParser.$(H): JavaParser.st $(INCLUDE_TOP)/stx/libjava/tools/JavaParserII.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaParserI.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPCompositeParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPDelegateParser.$(H) $(INCLUDE_TOP)/stx/goodies/petitparser/PPParser.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR) $(OUTDIR)JavaSourceHighlighter.$(O) JavaSourceHighlighter.$(H): JavaSourceHighlighter.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaScanner.$(H) $(INCLUDE_TOP)/stx/libjava/tools/JavaScannerBase.$(H) $(STCHDR) diff -r 658220e93dc9 -r ac412f6ea6d4 tools/Make.spec --- a/tools/Make.spec Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/Make.spec Sat Sep 14 15:48:03 2013 +0100 @@ -76,6 +76,7 @@ JavaParserII \ JavaScanner \ JavaSourceFile \ + JavaCompiler \ JavaMethodLikeDeclarationNode \ JavaParser \ JavaSourceHighlighter \ @@ -118,6 +119,7 @@ $(OUTDIR_SLASH)JavaParserII.$(O) \ $(OUTDIR_SLASH)JavaScanner.$(O) \ $(OUTDIR_SLASH)JavaSourceFile.$(O) \ + $(OUTDIR_SLASH)JavaCompiler.$(O) \ $(OUTDIR_SLASH)JavaMethodLikeDeclarationNode.$(O) \ $(OUTDIR_SLASH)JavaParser.$(O) \ $(OUTDIR_SLASH)JavaSourceHighlighter.$(O) \ diff -r 658220e93dc9 -r ac412f6ea6d4 tools/abbrev.stc --- a/tools/abbrev.stc Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/abbrev.stc Sat Sep 14 15:48:03 2013 +0100 @@ -8,7 +8,6 @@ JavaCompilerProblemService JavaCompilerProblemService stx:libjava/tools 'Languages-Java-Tools-Editor' 0 JavaListInspectorView JavaListInspectorView stx:libjava/tools 'Languages-Java-Tools-Inspectors' 2 JavaMapInspectorView JavaMapInspectorView stx:libjava/tools 'Languages-Java-Tools-Inspectors' 2 -JavaSourceRef JavaSourceRef stx:libjava/tools 'Languages-Java-Tools-Source' 0 JavaParseNode JavaParseNode stx:libjava/tools 'Languages-Java-Parser-AST' 0 JavaParseNodeBuilder JavaParseNodeBuilder stx:libjava/tools 'Languages-Java-Parser-AST' 0 JavaParserI JavaParserI stx:libjava/tools 'Languages-Java-Parser' 0 @@ -22,6 +21,7 @@ JavaSourcePartition JavaSourcePartition stx:libjava/tools 'Languages-Java-Parser-Utils' 0 JavaSourcePartitioner JavaSourcePartitioner stx:libjava/tools 'Languages-Java-Parser-Utils' 0 JavaSourcePartitionerTests JavaSourcePartitionerTests stx:libjava/tools 'Languages-Java-Tests-Parser' 1 +JavaSourceRef JavaSourceRef stx:libjava/tools 'Languages-Java-Tools-Source' 0 JavaSyntaxHighlighter_Eclipse JavaSyntaxHighlighter_Eclipse stx:libjava/tools 'Languages-Java-Tools-Eclipse' 0 JavaSyntaxHighlighter_Old JavaSyntaxHighlighter_Old stx:libjava/tools 'Languages-Java-Tools' 0 JavaToolbox JavaToolbox stx:libjava/tools 'Languages-Java-Tools' 0 @@ -33,6 +33,7 @@ JavaParserII JavaParserII stx:libjava/tools 'Languages-Java-Parser' 0 JavaScanner JavaScanner stx:libjava/tools 'Languages-Java-Parser' 3 JavaSourceFile JavaSourceFile stx:libjava/tools 'Languages-Java-Parser-AST' 0 +JavaCompiler JavaCompiler stx:libjava/tools 'Languages-Java-Support-Compiling' 0 JavaMethodLikeDeclarationNode JavaMethodLikeDeclarationNode stx:libjava/tools 'Languages-Java-Parser-AST' 0 JavaParser JavaParser stx:libjava/tools 'Languages-Java-Parser' 0 JavaSourceHighlighter JavaSourceHighlighter stx:libjava/tools 'Languages-Java-Tools-Source' 0 diff -r 658220e93dc9 -r ac412f6ea6d4 tools/bc.mak --- a/tools/bc.mak Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/bc.mak Sat Sep 14 15:48:03 2013 +0100 @@ -58,9 +58,10 @@ pushd ..\..\libui & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\libview & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\goodies\petitparser & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " + pushd ..\..\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " + pushd ..\..\goodies\sunit & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " + pushd ..\..\libwidg & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd .. & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " - pushd ..\..\libwidg & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\libwidg2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " pushd ..\..\libtool & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) " @@ -115,6 +116,7 @@ $(OUTDIR)JavaParserII.$(O) JavaParserII.$(H): JavaParserII.st $(INCLUDE_TOP)\stx\libjava\tools\JavaParserI.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPCompositeParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPDelegateParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPParser.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaScanner.$(O) JavaScanner.$(H): JavaScanner.st $(INCLUDE_TOP)\stx\libjava\tools\JavaScannerBase.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaSourceFile.$(O) JavaSourceFile.$(H): JavaSourceFile.st $(INCLUDE_TOP)\stx\libjava\tools\JavaParseNode.$(H) $(INCLUDE_TOP)\stx\libcomp\ParseNode.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) +$(OUTDIR)JavaCompiler.$(O) JavaCompiler.$(H): JavaCompiler.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaParserII.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaParserI.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPCompositeParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPDelegateParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPParser.$(H) $(STCHDR) $(OUTDIR)JavaMethodLikeDeclarationNode.$(O) JavaMethodLikeDeclarationNode.$(H): JavaMethodLikeDeclarationNode.st $(INCLUDE_TOP)\stx\libjava\tools\JavaDeclarationNode.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaParseNode.$(H) $(INCLUDE_TOP)\stx\libcomp\ParseNode.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaParser.$(O) JavaParser.$(H): JavaParser.st $(INCLUDE_TOP)\stx\libjava\tools\JavaParserII.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaParserI.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPCompositeParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPDelegateParser.$(H) $(INCLUDE_TOP)\stx\goodies\petitparser\PPParser.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR) $(OUTDIR)JavaSourceHighlighter.$(O) JavaSourceHighlighter.$(H): JavaSourceHighlighter.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaScanner.$(H) $(INCLUDE_TOP)\stx\libjava\tools\JavaScannerBase.$(H) $(STCHDR) diff -r 658220e93dc9 -r ac412f6ea6d4 tools/java/src/stx/libjava/tools/ast/ASTNodeComparator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/java/src/stx/libjava/tools/ast/ASTNodeComparator.java Sat Sep 14 15:48:03 2013 +0100 @@ -0,0 +1,44 @@ +package stx.libjava.tools.ast; + +import java.util.Arrays; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; + +public class ASTNodeComparator { + + public static boolean equals(TypeDeclaration t1, TypeDeclaration t2) { + return CharOperation.equals(t1.name, t2.name); + } + + public static boolean equals(FieldDeclaration f1, FieldDeclaration f2) { + return CharOperation.equals(f1.name, f2.name); + } + + + public static boolean equals( + AbstractMethodDeclaration m1, + AbstractMethodDeclaration m2) { + // TODO Auto-generated method stub + if (! CharOperation.equals(m1.selector, m2.selector) ) return false; + if (m1.arguments == null || m2.arguments == null) return m1.arguments == m2.arguments; + if (m1.arguments.length != m2.arguments.length) return false; + + for (int i = 0; i < m1.arguments.length; i++) { + if (! equals( m1.arguments[i].type, m2.arguments[i].type ) ) return false; + } + return true; + } + + private static boolean equals(TypeReference t1, TypeReference t2) { + char[][] n1 = t1.getTypeName(); + char[][] n2 = t2.getTypeName(); + + return Arrays.equals(n1[n1.length - 1],n2[n2.length - 2]); + + } + +} diff -r 658220e93dc9 -r ac412f6ea6d4 tools/java/src/stx/libjava/tools/ast/Utils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/java/src/stx/libjava/tools/ast/Utils.java Sat Sep 14 15:48:03 2013 +0100 @@ -0,0 +1,67 @@ +package stx.libjava.tools.ast; + +import java.lang.reflect.Array; +import java.util.ArrayList; + + +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; + +public class Utils { + + public static void addOrReplaceType(TypeDeclaration type, TypeDeclaration inner) { + if (type.memberTypes == null || type.memberTypes.length == 0) { + type.memberTypes = new TypeDeclaration[1]; + type.memberTypes[0] = inner; + return; + } + for (int i = 0; i < type.memberTypes.length; i++) { + if (ASTNodeComparator.equals(type.memberTypes[i], inner)) { + type.memberTypes[i] = inner; + return; + } + } + type.memberTypes = concat(type.memberTypes, inner); + } + + public static void addOrReplaceMethod(TypeDeclaration type, AbstractMethodDeclaration method) { + if (type.methods == null || type.memberTypes.length == 0) { + type.methods = new AbstractMethodDeclaration[1]; + type.methods[0] = method; + return; + } + for (int i = 0; i < type.methods.length; i++) { + if (ASTNodeComparator.equals(type.methods[i], method)) { + type.methods[i] = method; + return; + } + } + type.methods = concat(type.methods, method); + } + + public static void addOrReplaceField(TypeDeclaration type, FieldDeclaration field) { + if (type.fields == null || type.fields.length == 0) { + type.fields = new FieldDeclaration[1]; + type.fields[0] = field; + return; + } + for (int i = 0; i < type.fields.length; i++) { + if (ASTNodeComparator.equals(type.fields[i], field)) { + type.fields[i] = field; + return; + } + } + type.fields = concat(type.fields, field); + } + + + public static T[] concat(T[] array, T element) { + @SuppressWarnings("unchecked") + T[] result = (T[])Array.newInstance(array.getClass().getComponentType(), array.length + 1); + System.arraycopy(array, 0, result, 0, array.length); + result[array.length] = element; + return result; + } + +} diff -r 658220e93dc9 -r ac412f6ea6d4 tools/java/src/stx/libjava/tools/environment/Environment.java --- a/tools/java/src/stx/libjava/tools/environment/Environment.java Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/java/src/stx/libjava/tools/environment/Environment.java Sat Sep 14 15:48:03 2013 +0100 @@ -13,9 +13,19 @@ import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; public class Environment implements INameEnvironment { + + protected static Environment SHARED; protected ClassLoader classloader; public TypeRegistry types; + public static synchronized Environment shared() { + if (SHARED == null) { + SHARED = new Environment(); + }; + return SHARED; + } + + public Environment() { this(new TypeRegistry(), ClassLoader.getSystemClassLoader() ); } diff -r 658220e93dc9 -r ac412f6ea6d4 tools/java/src/stx/libjava/tools/environment/Resolver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/java/src/stx/libjava/tools/environment/Resolver.java Sat Sep 14 15:48:03 2013 +0100 @@ -0,0 +1,78 @@ +package stx.libjava.tools.environment; + +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.env.AccessRestriction; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.ISourceType; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.ITypeRequestor; +import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; +import org.eclipse.jdt.internal.compiler.lookup.MethodScope; +import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +public class Resolver implements ITypeRequestor { + ProblemReporter reporter; + LookupEnvironment environment; + + public Resolver() { + this(new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(), + new DefaultProblemFactory())); + } + + public Resolver(ProblemReporter reporter) { + this.reporter = reporter; + environment = new LookupEnvironment(this, reporter.options, reporter, Environment.shared()); + } + + public void resolve(CompilationUnitDeclaration cud) { + environment.buildTypeBindings(cud, null); + environment.completeTypeBindings(cud, true); + this.completeTypeBindings2(cud); + cud.resolve(); + } + + protected void completeTypeBindings2(CompilationUnitDeclaration cud) { + for (int i = 0; i < cud.types.length; i++) { + this.completeTypeBindings2(cud.types[i]); + } + } + + protected void completeTypeBindings2(TypeDeclaration td) { + if (td.memberTypes != null) { + for (int i = 0; i < td.memberTypes.length; i++) { + this.completeTypeBindings2(td.memberTypes[i]); + } + } + td.binding.methods(); + td.binding.fields(); + } + + @Override + public void accept(IBinaryType binaryType, + PackageBinding packageBinding, + AccessRestriction accessRestriction) { + environment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction); + } + + @Override + public void accept(ICompilationUnit unit, + AccessRestriction accessRestriction) { + } + + @Override + public void accept(ISourceType[] sourceType, + PackageBinding packageBinding, + AccessRestriction accessRestriction) { + // TODO Auto-generated method stub + + } + +} diff -r 658220e93dc9 -r ac412f6ea6d4 tools/java/src/stx/libjava/tools/parser/Parser.java --- a/tools/java/src/stx/libjava/tools/parser/Parser.java Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/java/src/stx/libjava/tools/parser/Parser.java Sat Sep 14 15:48:03 2013 +0100 @@ -1,13 +1,24 @@ package stx.libjava.tools.parser; +import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import stx.libjava.tools.ast.Utils; +import stx.libjava.tools.environment.Resolver; + public class Parser extends org.eclipse.jdt.internal.compiler.parser.Parser { @@ -27,13 +38,45 @@ options.docCommentSupport = true; javadocParser.checkDocComment = true; } + + public CompilationUnitDeclaration parse(ICompilationUnit cu, boolean diet, boolean resolve) { + CompilationUnitDeclaration cud; + if (diet) { + cud = dietParse(cu, new CompilationResult(cu, 1, 1, 1000)); + } else { + cud = parse(cu, new CompilationResult(cu, 1, 1, 1000 )); + } + if (resolve) { + Resolver resolver = new Resolver(problemReporter); + resolver.resolve(cud); + } + return cud; + } public CompilationUnitDeclaration parse(ICompilationUnit cu, boolean diet) { - if (diet) { - return dietParse(cu, new CompilationResult(cu, 1, 1, 1000)); - } else { - return parse(cu, new CompilationResult(cu, 1, 1, 1000 )); + return parse(cu, diet, false); + } + + public ASTNode[] parseClassBodyDeclarations(char[] source, CompilationUnitDeclaration unit, TypeDeclaration type, boolean resolve) { + ASTNode[] nodes = this.parseClassBodyDeclarations(source, 0, source.length, unit); + if (resolve) { + for (int i = 0; i < nodes.length; i++) { + ASTNode n = nodes[i]; + if (n instanceof TypeDeclaration) { + Utils.addOrReplaceType(type, (TypeDeclaration)n); + } else if (n instanceof AbstractMethodDeclaration) { + Utils.addOrReplaceMethod(type, (AbstractMethodDeclaration)n); + } else if (n instanceof FieldDeclaration) { + Utils.addOrReplaceField(type, (FieldDeclaration)n); + } + } + unit.types[0] = type; + Resolver resolver = new Resolver(problemReporter); + resolver.resolve(unit); } + return nodes; } + + } diff -r 658220e93dc9 -r ac412f6ea6d4 tools/libInit.cc --- a/tools/libInit.cc Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/libInit.cc Sat Sep 14 15:48:03 2013 +0100 @@ -53,6 +53,7 @@ _JavaParserII_Init(pass,__pRT__,snd); _JavaScanner_Init(pass,__pRT__,snd); _JavaSourceFile_Init(pass,__pRT__,snd); +_JavaCompiler_Init(pass,__pRT__,snd); _JavaMethodLikeDeclarationNode_Init(pass,__pRT__,snd); _JavaParser_Init(pass,__pRT__,snd); _JavaSourceHighlighter_Init(pass,__pRT__,snd); diff -r 658220e93dc9 -r ac412f6ea6d4 tools/stx_libjava_tools.st --- a/tools/stx_libjava_tools.st Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/stx_libjava_tools.st Sat Sep 14 15:48:03 2013 +0100 @@ -27,7 +27,7 @@ (the browser has a menu function for that)" ^ #( - #'stx:goodies/petitparser' "PPCompositeParser - superclass of JavaParser " + #'stx:goodies/petitparser' "PPCompositeParser - superclass of JavaCompiler::ClassSourceAnalyzer " #'stx:libbasic' "Autoload - superclass of JavaParserIITests " #'stx:libcomp' "ParseNode - superclass of JavaAnnotationDeclarationNode " #'stx:libjava' "JavaObject - extended " @@ -72,7 +72,7 @@ ^ #( #'jv:smallsense' "SmallSense::ParseNodeInspector - referenced by JavaSourceDocument>>inspector2TabParseTree " #'stx:libbasic2' "BackgroundQueueProcessingJob - referenced by JavaSourceDocument class>>initialize " - #'stx:libjava/experiments' "JavaCompiler - referenced by JavaCompilerProblemService>>syntaxHighlighter " + #'stx:libjava/experiments' "JavaCompilerProblemRegistry - referenced by JavaCompiler>>compile: " ) ! @@ -142,54 +142,54 @@ Each entry in the list may be: a single class-name (symbol), or an array-literal consisting of class name and attributes. Attributes are: #autoload or # where os is one of win32, unix,..." - - ^#( - " or ( attributes...) in load order" - #JavaCodeBundleEditor - #JavaCodeLibraryEditor - #JavaCompilerProblemHighlighter - #JavaCompilerProblemPopup - #JavaCompilerProblemService - #JavaListInspectorView - #JavaMapInspectorView - #JavaSourceRef - #JavaParseNode - #JavaParseNodeBuilder - #JavaParserI - #(JavaParserIITests autoload) - #(JavaParserITests autoload) - #'JavaParser_Eclipse' - #JavaScannerBase - #JavaSetInspectorView - #JavaSettingsApplication - #JavaSourceDocument - #JavaSourcePartition - #(JavaSourcePartitioner autoload) - #(JavaSourcePartitionerTests autoload) - #(#'JavaSyntaxHighlighter_Eclipse' autoload) - #(#'JavaSyntaxHighlighter_Old' autoload) - #JavaToolbox - #'stx_libjava_tools' - #JavaDeclarationNode - #JavaImportDeclarationNode - #JavaLiteralNode - #JavaPackageDeclarationNode - #JavaParserII - #JavaScanner - #JavaSourceFile - #JavaMethodLikeDeclarationNode - #JavaParser - #JavaSourceHighlighter - #JavaTypeDeclarationNode - #JavaVariableDeclarationNode - #JavaAnnotationDeclarationNode - #JavaClassDeclarationNode - #JavaConstructorDeclarationNode - #JavaEnumDeclarationNode - #JavaInterfaceDeclarationNode - #JavaMethodDeclarationNode ) - "Modified (format): / 09-09-2013 / 01:09:10 / Jan Vrany " + ^ #( + " or ( attributes...) in load order" + JavaCodeBundleEditor + JavaCodeLibraryEditor + JavaCompilerProblemHighlighter + JavaCompilerProblemPopup + JavaCompilerProblemService + JavaListInspectorView + JavaMapInspectorView + JavaParseNode + JavaParseNodeBuilder + JavaParserI + (JavaParserIITests autoload) + (JavaParserITests autoload) + #'JavaParser_Eclipse' + JavaScannerBase + JavaSetInspectorView + JavaSettingsApplication + JavaSourceDocument + JavaSourcePartition + (JavaSourcePartitioner autoload) + (JavaSourcePartitionerTests autoload) + JavaSourceRef + (#'JavaSyntaxHighlighter_Eclipse' autoload) + (#'JavaSyntaxHighlighter_Old' autoload) + JavaToolbox + #'stx_libjava_tools' + JavaDeclarationNode + JavaImportDeclarationNode + JavaLiteralNode + JavaPackageDeclarationNode + JavaParserII + JavaScanner + JavaSourceFile + JavaCompiler + JavaMethodLikeDeclarationNode + JavaParser + JavaSourceHighlighter + JavaTypeDeclarationNode + JavaVariableDeclarationNode + JavaAnnotationDeclarationNode + JavaClassDeclarationNode + JavaConstructorDeclarationNode + JavaEnumDeclarationNode + JavaInterfaceDeclarationNode + JavaMethodDeclarationNode + ) ! extensionMethodNames diff -r 658220e93dc9 -r ac412f6ea6d4 tools/tools.rc --- a/tools/tools.rc Thu Sep 12 00:24:05 2013 +0100 +++ b/tools/tools.rc Sat Sep 14 15:48:03 2013 +0100 @@ -25,7 +25,7 @@ VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\0" VALUE "ProductName", "Smalltalk/X\0" VALUE "ProductVersion", "6.2.3.0\0" - VALUE "ProductDate", "Wed, 11 Sep 2013 23:08:45 GMT\0" + VALUE "ProductDate", "Sat, 14 Sep 2013 14:14:03 GMT\0" END END