summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Ballou <kballou@devnulllabs.io>2018-11-19 22:59:50 -0700
committerKenny Ballou <kballou@devnulllabs.io>2018-11-19 22:59:50 -0700
commitea3e1b949dcbdc09518f17eee0bcf21d41d76896 (patch)
tree7ec7a7fb4df67815a9b7bb0e4d95d67c4050e2a2
downloadopenjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.gz
openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.xz
OJ (aka OpenJava) modernization/mirroring
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
-rw-r--r--.gitignore3
-rw-r--r--COPYRIGHT25
-rw-r--r--README.org97
-rw-r--r--bin/ojc.bat1
-rwxr-xr-xbin/ojc.ksh47
-rwxr-xr-xbin/ojc.sh48
-rw-r--r--docs/BugNotes.txt59
-rw-r--r--docs/TODO41
-rw-r--r--docs/licenses/cpl-v10.html125
-rw-r--r--pom.xml121
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/AmbiguousClassesException.java30
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/AnonymousClassEnvironment.java53
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/CannotAlterException.java29
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/CannotExecuteException.java34
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/CannotInspectException.java35
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/ClassEnvironment.java183
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/ClosedEnvironment.java119
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/Environment.java153
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/FileEnvironment.java376
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/GlobalEnvironment.java108
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/MOPException.java58
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/MetaInfo.java172
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/Metaclass.java153
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/NoSuchMemberException.java34
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJClass.java3071
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJClassNotFoundException.java31
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJConstructor.java652
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJField.java810
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJMember.java32
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJMethod.java721
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJModifier.java246
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJPrimitive.java37
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/OJSystem.java218
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/Signature.java249
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/Toolbox.java912
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/edit/OJEditableClass.java61
-rw-r--r--src/main/java/io/devnulllabs/openjava/mop/package.html63
-rw-r--r--src/main/java/io/devnulllabs/openjava/ojc/CommandArguments.java226
-rw-r--r--src/main/java/io/devnulllabs/openjava/ojc/Compiler.java569
-rw-r--r--src/main/java/io/devnulllabs/openjava/ojc/JavaCompiler.java17
-rw-r--r--src/main/java/io/devnulllabs/openjava/ojc/Main.java54
-rw-r--r--src/main/java/io/devnulllabs/openjava/ojc/TranslatorThread.java39
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/AllocationExpression.java203
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java87
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ArrayAllocationExpression.java151
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ArrayInitializer.java152
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/AssignmentExpression.java158
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/BinaryExpression.java372
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Block.java71
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/BreakStatement.java69
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CaseGroup.java42
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CaseGroupList.java119
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CaseLabel.java39
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CaseLabelList.java119
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CastExpression.java103
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CatchBlock.java84
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CatchList.java119
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ClassDeclaration.java213
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ClassDeclarationList.java119
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ClassLiteral.java84
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/CompilationUnit.java151
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ConditionalExpression.java129
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ConstructorDeclaration.java231
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ConstructorInvocation.java85
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ContinueStatement.java68
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/DoWhileStatement.java81
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/EmptyStatement.java38
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Expression.java50
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ExpressionList.java129
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ExpressionObject.java83
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ExpressionStatement.java62
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/FieldAccess.java190
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/FieldDeclaration.java177
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ForStatement.java196
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/IfStatement.java121
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/InstanceofExpression.java115
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/LabeledStatement.java81
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Leaf.java158
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/List.java240
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Literal.java231
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/MemberDeclaration.java48
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/MemberDeclarationList.java120
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/MemberInitializer.java71
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/MethodCall.java219
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/MethodDeclaration.java190
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ModifierList.java232
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/NonLeaf.java381
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ObjectList.java129
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Parameter.java124
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ParameterList.java119
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ParseTree.java106
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ParseTreeException.java47
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ParseTreeObject.java267
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ReturnStatement.java67
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java105
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Statement.java63
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/StatementList.java129
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/SwitchStatement.java86
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/SynchronizedStatement.java83
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ThrowStatement.java60
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/TryStatement.java129
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/TypeName.java186
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/UnaryExpression.java240
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/Variable.java58
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/VariableDeclaration.java199
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/VariableDeclarator.java114
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/VariableInitializer.java32
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/WhileStatement.java84
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/ClassLiteralReplacer.java57
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/EvaluationShuttle.java1138
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/ExpansionApplier.java457
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/MemberAccessCorrector.java222
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/ParseTreeVisitor.java191
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/PartialParser.java330
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/ScopeHandler.java305
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/SourceCodeWriter.java1462
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/TypeNameQualifier.java107
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/util/VariableBinder.java115
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/AbstractSyntaxRule.java80
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/BlockRule.java52
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/CompositeRule.java70
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/DefaultListRule.java57
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/ExpressionListRule.java66
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/ExpressionRule.java68
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java79
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/IterationRule.java78
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/JavaSyntaxRules.java170
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/NameRule.java74
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/PrepPhraseRule.java51
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/RestorableTokenSource.java70
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java61
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/SeparatedListRule.java98
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/StatementRule.java55
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/SyntaxException.java49
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/SyntaxRule.java52
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/TokenID.java143
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java61
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/TokenSource.java35
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/TypeNameRule.java47
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/DebugOut.java167
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/WriterStack.java138
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/ASCII_UCodeESC_CharStream.java519
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/CustomTokenManager.java68
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/JavaCharStream.java546
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/Makefile35
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/ParseException.java192
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/Parser.java6327
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/Parser.jj3043
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/ParserConstants.java254
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java1820
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java.org1827
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/Token.java81
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/TokenIDPublisher.java122
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/TokenMgrError.java133
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/TokenSourceAdapter.java44
-rw-r--r--src/main/java/io/devnulllabs/openjava/tools/parser/patchParserTokenManager.pl11
-rw-r--r--src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java24
-rw-r--r--src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java46
-rw-r--r--src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java71
-rw-r--r--src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java57
-rw-r--r--src/test/java/antonio/Test.oj36
-rw-r--r--src/test/java/bryn/ArraySupport.oj62
-rw-r--r--src/test/java/bryn/ArrayTest.oj13
-rw-r--r--src/test/java/cristophe/SigPrintClass.oj22
-rw-r--r--src/test/java/cristophe/Test.oj24
-rw-r--r--src/test/java/cristophe2/MethodRemovingClass.oj20
-rw-r--r--src/test/java/cristophe2/Test.oj21
-rw-r--r--src/test/java/dardia/InterImpl.oj117
-rw-r--r--src/test/java/dardia/MIJava.oj109
-rw-r--r--src/test/java/dardia/MultiextendingClass.oj129
-rw-r--r--src/test/java/dardia/Person.oj17
-rw-r--r--src/test/java/dardia/Student.oj19
-rw-r--r--src/test/java/dardia/TA.oj16
-rw-r--r--src/test/java/demobug/Bug1.java8
-rw-r--r--src/test/java/demobug/DemoBug1.java58
-rw-r--r--src/test/java/demobug/DemoBug1Test.oj5
-rw-r--r--src/test/java/demobug/DemoBug2.java47
-rw-r--r--src/test/java/demobug/DemoBug2Test.oj5
-rw-r--r--src/test/java/demobug/InnerTest.oj29
-rw-r--r--src/test/java/demobug/InnerTest2.oj16
-rw-r--r--src/test/java/demobug/MetaTest.oj78
-rw-r--r--src/test/java/demobug/Mix.oj47
-rw-r--r--src/test/java/demobug/Normal.oj96
-rw-r--r--src/test/java/demobug/Simple.oj90
-rw-r--r--src/test/java/desell/MIJava.oj7
-rw-r--r--src/test/java/desell/TrivialSuperClass.oj7
-rw-r--r--src/test/java/fabio/Hello.oj12
-rw-r--r--src/test/java/fabio/HelloWithError.oj12
-rw-r--r--src/test/java/fabio/VerboseClass.oj21
-rw-r--r--src/test/java/inner/BIND3
-rw-r--r--src/test/java/inner/ImageMap.oj80
-rw-r--r--src/test/java/inner/VerboseClass.oj49
-rw-r--r--src/test/java/jarrett/NonPub.oj19
-rw-r--r--src/test/java/lionel/Hello.oj11
-rw-r--r--src/test/java/lionel/Hello2.oj11
-rw-r--r--src/test/java/lionel/Hello3.oj11
-rw-r--r--src/test/java/lionel/metabind2
-rw-r--r--src/test/java/lionel2/NonPubTest.oj36
-rw-r--r--src/test/java/lionel2/Printer.oj18
-rw-r--r--src/test/java/lionel2/SimpleConst.oj6
-rw-r--r--src/test/java/luciano/AutoConstructorClass.oj71
-rw-r--r--src/test/java/luciano/Test.oj4
-rw-r--r--src/test/java/maurizio/Test.oj7
-rw-r--r--src/test/java/maurizio/TestClass.oj15
-rw-r--r--src/test/java/maurizio/TestUser.oj11
-rw-r--r--src/test/java/maurizio2/Test.oj12
-rw-r--r--src/test/java/maurizio2/TestClass.oj23
-rw-r--r--src/test/java/maurizio2/TestUser.oj14
-rw-r--r--src/test/java/mazza/Test.oj6
-rw-r--r--src/test/java/mazza/TestClass.oj19
-rw-r--r--src/test/java/metatest/Meta2.java38
-rw-r--r--src/test/java/metatest/TestMetaclass.java37
-rw-r--r--src/test/java/nopub/Pub.oj7
-rw-r--r--src/test/java/nopub/Test.oj7
-rw-r--r--src/test/java/openjava/mop/OJSystemTest.java60
-rw-r--r--src/test/java/openjava/ptree/ClassDeclarationTest.java27
-rw-r--r--src/test/java/openjava/ptree/ModifierListTest.java30
-rw-r--r--src/test/java/packfld/Test.java14
-rw-r--r--src/test/java/pp/C.java44
-rw-r--r--src/test/java/pp/CTest.oj6
-rw-r--r--src/test/java/pp/SyncTest.oj8
-rw-r--r--src/test/java/schulz/A.oj9
-rw-r--r--src/test/java/schulz/Sample.oj18
-rw-r--r--src/test/java/smyth/BankAccount.oj25
-rw-r--r--src/test/java/smyth/MDistributed.oj111
-rw-r--r--src/test/java/smyth/Test.oj15
-rw-r--r--src/test/java/thorsten/MetaTest.oj21
-rw-r--r--src/test/java/thorsten/Test.oj6
-rw-r--r--src/test/java/walter/Test.oj15
-rw-r--r--src/test/java/walter/dummyClass.oj18
-rw-r--r--src/test/java/walter/multiTrig.oj65
-rw-r--r--src/test/java/walter2/ArraysTest.oj11
-rw-r--r--src/test/java/walter2/MyComp.oj9
-rw-r--r--src/test/java/walter2/StaticTest.oj11
-rw-r--r--src/test/java/walter2/StaticUtil.oj9
-rw-r--r--src/test/java/walter2/Test.oj26
-rw-r--r--tutorial/Adapter.html258
-rw-r--r--tutorial/AutoImpl.html150
-rw-r--r--tutorial/FreeArgs.html171
-rw-r--r--tutorial/Introduction.html96
-rw-r--r--tutorial/NewMethod.html209
-rw-r--r--tutorial/Override.html181
-rw-r--r--tutorial/Overview.html208
-rw-r--r--tutorial/Synchronize.html131
-rw-r--r--tutorial/Syntax.html171
-rw-r--r--tutorial/VerboseClass.html212
-rw-r--r--tutorial/examples/adapter/AdapterClass.java155
-rw-r--r--tutorial/examples/adapter/AdapterClass.oj152
-rw-r--r--tutorial/examples/adapter/Stack.java29
-rw-r--r--tutorial/examples/adapter/Stack.oj15
-rw-r--r--tutorial/examples/adapter/VectorStack.java68
-rw-r--r--tutorial/examples/adapter/VectorStack.oj24
-rw-r--r--tutorial/examples/autoimp/AutoImplementerClass.java78
-rw-r--r--tutorial/examples/autoimp/AutoImplementerClass.oj64
-rw-r--r--tutorial/examples/autoimp/InnerTest.java29
-rw-r--r--tutorial/examples/autoimp/InnerTest.oj15
-rw-r--r--tutorial/examples/autoimp/Test.java55
-rw-r--r--tutorial/examples/autoimp/Test.oj8
-rw-r--r--tutorial/examples/bca/AutoAdaptationClass.java53
-rw-r--r--tutorial/examples/bca/AutoAdaptationClass.oj48
-rw-r--r--tutorial/examples/bca/Printable.java7
-rw-r--r--tutorial/examples/bca/RTReflClass.java51
-rw-r--r--tutorial/examples/bca/Test.java24
-rw-r--r--tutorial/examples/bca/Test.oj13
-rw-r--r--tutorial/examples/bca/Test2.java18
-rw-r--r--tutorial/examples/bca/Test2.oj12
-rw-r--r--tutorial/examples/bca/Writable.java10
-rw-r--r--tutorial/examples/capsule/CapsuleClass.oj130
-rw-r--r--tutorial/examples/capsule/Point.oj22
-rw-r--r--tutorial/examples/capsule/PointUser.oj17
-rw-r--r--tutorial/examples/capsule/Test.oj47
-rw-r--r--tutorial/examples/capsule/TestUser.oj38
-rw-r--r--tutorial/examples/capsule/TestUser2.oj8
-rw-r--r--tutorial/examples/copy/CopiedClass.java43
-rw-r--r--tutorial/examples/copy/CopiedClass.oj37
-rw-r--r--tutorial/examples/copy/Test.java62
-rw-r--r--tutorial/examples/copy/Test.oj52
-rw-r--r--tutorial/examples/copy/TestShadow.java58
-rw-r--r--tutorial/examples/decorator/0UNDERCONSTRUCTION0
-rw-r--r--tutorial/examples/decorator/AdapterClass.oj152
-rw-r--r--tutorial/examples/decorator/ReturnSpecifier.java67
-rw-r--r--tutorial/examples/decorator/ReturnSpecifier.oj39
-rw-r--r--tutorial/examples/decorator/Test.java21
-rw-r--r--tutorial/examples/decorator/Test.oj21
-rw-r--r--tutorial/examples/facemake/FaceProvidedClass.java76
-rw-r--r--tutorial/examples/facemake/FaceProvidedClass.oj57
-rw-r--r--tutorial/examples/facemake/Test.java62
-rw-r--r--tutorial/examples/facemake/Test.oj52
-rw-r--r--tutorial/examples/facemake/TestFace.java516
-rw-r--r--tutorial/examples/freeargs/Collection.java61
-rw-r--r--tutorial/examples/freeargs/Collection.oj52
-rw-r--r--tutorial/examples/freeargs/FreeArgsClass.java117
-rw-r--r--tutorial/examples/freeargs/FreeArgsClass.oj95
-rw-r--r--tutorial/examples/freeargs/Test.java32
-rw-r--r--tutorial/examples/freeargs/Test.oj28
-rw-r--r--tutorial/examples/mixin/0UNDERCONSTRUCTION0
-rw-r--r--tutorial/examples/mixin/MixinedClass.java124
-rw-r--r--tutorial/examples/mixin/MixinedClass.oj115
-rw-r--r--tutorial/examples/mixin/Textbox.java23
-rw-r--r--tutorial/examples/mixin/Textbox.oj17
-rw-r--r--tutorial/examples/mixin/TextboxWithUndo.java22
-rw-r--r--tutorial/examples/mixin/TextboxWithUndo.oj8
-rw-r--r--tutorial/examples/mixin/Undo.java8
-rw-r--r--tutorial/examples/mixin/Undo.oj19
-rw-r--r--tutorial/examples/multimeta/CombinedClass.oj397
-rw-r--r--tutorial/examples/multimeta/MyPerson.oj15
-rw-r--r--tutorial/examples/multimeta/MyPerson2.oj15
-rw-r--r--tutorial/examples/multimeta/MyPerson3.oj14
-rw-r--r--tutorial/examples/multimethod/MultimethodClass.java169
-rw-r--r--tutorial/examples/multimethod/NoAddaptableMethodException.java24
-rw-r--r--tutorial/examples/multimethod/ParameterSetTree.java215
-rw-r--r--tutorial/examples/multimethod/Test.oj52
-rw-r--r--tutorial/examples/multimethod/Test2.oj20
-rw-r--r--tutorial/examples/operator/OperatorOverridable.oj7
-rw-r--r--tutorial/examples/operator/OperatorOverridableClass.oj97
-rw-r--r--tutorial/examples/orcheck/OverrideCheckerClass.java82
-rw-r--r--tutorial/examples/orcheck/OverridingClass.oj62
-rw-r--r--tutorial/examples/orcheck/Test.java15
-rw-r--r--tutorial/examples/orcheck/Test.oj9
-rw-r--r--tutorial/examples/orcheck/TestWithError.oj10
-rw-r--r--tutorial/examples/order/OrderKeeperClass.java65
-rw-r--r--tutorial/examples/order/OrderKeeperClass.oj46
-rw-r--r--tutorial/examples/order/Test.java21
-rw-r--r--tutorial/examples/order/Test.oj12
-rw-r--r--tutorial/examples/order2/Printer.java46
-rw-r--r--tutorial/examples/order2/Printer.oj33
-rw-r--r--tutorial/examples/order2/Test.java34
-rw-r--r--tutorial/examples/order2/Test.oj11
-rw-r--r--tutorial/examples/print/MyClass.java30
-rw-r--r--tutorial/examples/print/MyClass.oj21
-rw-r--r--tutorial/examples/print/Printer.java64
-rw-r--r--tutorial/examples/print/Test.java119
-rw-r--r--tutorial/examples/print/Test.oj107
-rw-r--r--tutorial/examples/print/TestPrinter.java99
-rw-r--r--tutorial/examples/rtrefl/Point.java107
-rw-r--r--tutorial/examples/rtrefl/Point.oj35
-rw-r--r--tutorial/examples/rtrefl/PointUser.java25
-rw-r--r--tutorial/examples/rtrefl/PointUser.oj19
-rw-r--r--tutorial/examples/rtrefl/RTMetaLevel.java6
-rw-r--r--tutorial/examples/rtrefl/RTMetaObject.java81
-rw-r--r--tutorial/examples/rtrefl/RTReflClass.java229
-rw-r--r--tutorial/examples/rtrefl/RTReflClass.oj247
-rw-r--r--tutorial/examples/rtrefl/VerboseRTMetaObject.java38
-rw-r--r--tutorial/examples/serialize/BIND5
-rw-r--r--tutorial/examples/serialize/Color.oj44
-rw-r--r--tutorial/examples/serialize/Colored3DPoint.oj19
-rw-r--r--tutorial/examples/serialize/ColoredPoint.oj28
-rw-r--r--tutorial/examples/serialize/Marshalable.java9
-rw-r--r--tutorial/examples/serialize/OIOTest.java56
-rw-r--r--tutorial/examples/serialize/ObjectIn.java34
-rw-r--r--tutorial/examples/serialize/ObjectOut.java36
-rw-r--r--tutorial/examples/serialize/Point.oj29
-rw-r--r--tutorial/examples/serialize/SerializableClass.oj121
-rw-r--r--tutorial/examples/syntax/ErrorTest.java97
-rw-r--r--tutorial/examples/syntax/ErrorTest.oj96
-rw-r--r--tutorial/examples/syntax/RichSyntaxClass.java129
-rw-r--r--tutorial/examples/syntax/RichSyntaxClass.oj102
-rw-r--r--tutorial/examples/syntax/Test.java97
-rw-r--r--tutorial/examples/syntax/Test.oj96
-rw-r--r--tutorial/examples/verbose/Hello.java22
-rw-r--r--tutorial/examples/verbose/Hello.oj13
-rw-r--r--tutorial/examples/verbose/Test.java98
-rw-r--r--tutorial/examples/verbose/Test.oj73
-rw-r--r--tutorial/examples/verbose/VerboseClass.java45
-rw-r--r--tutorial/examples/verbose/VerboseClass.oj30
-rw-r--r--tutorial/examples/verbose2/Test.java98
-rw-r--r--tutorial/examples/verbose2/Test.oj73
-rw-r--r--tutorial/examples/verbose2/VerboseClass.java50
-rw-r--r--tutorial/images/comflow.gifbin0 -> 2697 bytes
-rw-r--r--tutorial/index.html83
370 files changed, 51657 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1528963
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+target/
+.idea/
+**.iml
diff --git a/COPYRIGHT b/COPYRIGHT
new file mode 100644
index 0000000..3a4b6c2
--- /dev/null
+++ b/COPYRIGHT
@@ -0,0 +1,25 @@
+Copyright (c) 1997-2003 by Michiaki Tatsubori.
+All Rights Reserved.
+
+
+Permission to use, copy, and distribute this software and its documentation
+and to prepare derivative works based upon this software is hereby granted,
+provided that any copy of this software or of any derivative work must
+include the above copyright notice of Michiaki Tatsubori, this paragraph
+and the two after it.
+
+Michiaki Tatsubori disclaims all warranties with regard to this software,
+including all implied warranties of merchantability and fitness.
+In no event shall Michiaki Tatsubori be liable for any special, indirect
+or consequential damages or any damages whatsoever resulting from loss
+of use, data or profits, whether in an action of contract, negligence or
+other tortious action, arising out of or in connection with the use or
+performance of this software.
+
+JAVA(tm) and HOTJAVA(tm) web development products are owned and licensed
+exclusively by Sun Microsystems, Inc. Copyright(C) 1992-99 Sun Microsystems,
+Inc. All rights reserved. JAVA, HOTJAVA, the JAVA/HOTJAVA Logos, Sun, Sun
+Microsystems, and the Sun Logo are trademarks or registered trademarks of
+Sun Microsystems, Inc. in the U.S. and other countries.
+References to the Java programming language in relation to OpenJava are
+not meant to imply that Sun endorses this product.
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..dd7144d
--- /dev/null
+++ b/README.org
@@ -0,0 +1,97 @@
+#+LINK: oj-source-forge https://sourceforge.net/projects/openjava/
+README
+OpenJava 1.1 build 20030219
+Feb 19, 2003
+by Michiaki Tatsubori mich@acm.org
+
+
+OpenJava is an extensible language based on Java(TM). The OpenJava MOP
+(Metaobject Protocol) is the extension interface of the language.
+Through the MOP, the programmers can customize the language to
+implement a new language mechanism.
+
+OpenJava helps people who want to develop better Java libraries, that
+is, easy-to-use and efficient ones. It also helps people who are
+developing their own extended Java languages. OpenJava can be regarded
+as a toolkit for constructing a Java preprocessor.
+
+
+** How to set up OpenJava
+
+This directory contains the OpenJava version 1.0a release in both source
+and bytecode form. You should find the following files and subdirectories
+in this release:
+
+ README This file.
+ COPYRIGHT Copyright notices are described in this text file.
+ src/ OpenJava source files in Java-packaged form.
+ classes/ OpenJava bytecode files in Java-packaged form.
+ htdocs/ OpenJava API in HTML format.
+ bin/ Shell scripts useful to use OpenJava system.
+ tutorial/ Tutorial files in HTML format containing some examples of
+ meta-programming in the example subfolder.
+ docs/ Other notes.
+
+
+To set up, you must do either 1) or 2)
+1) Set CLASSPATH environment variable to include 'classes' directory.
+2) Use ojc (for solaris), ojc.sh (for unix), or ojc.exe (for windows
+with cygwin) command in bin directory.
+
+Additionally, make sure that your Java compiler is in your PATH as the
+name 'javac'. Otherwise OpenJava compiler fails to generate bytecode.
+
+
+** How to run
+
+The detailed explanation is shown in the programmer's guide above.
+The execution way is similar to :
+
+ $ java openjava.ojc.Main sourcecode.oj
+
+or :
+
+ solaris% bin/ojc.ksh sourcecode.oj
+ linux$ bin/ojc.sh sourcecode.oj
+ windows> bin/ojc.bat sourcecode.oj
+
+For example, type in the top directory,
+
+ $ java -classpath .:classes openjava.ojc.Main \
+ examples/verbose/VerboseClass.oj
+ $ java -classpath .:classes openjava.ojc.Main \
+ examples/verbose/Hello.oj
+
+
+** Contact
+
+This is an alpha-test release of the OpenJava and is designed to run
+under the JDK 1.1 or 1.2 and Java compiler. The detailed specifications
+of OpenJava might change in future. If you have any comment or find
+bugs, please contact the author at :
+
+ mich@acm.org
+
+The OpenJava home page, where the latest information regarding
+OpenJava and other documents around OpenJava are available, is at :
+
+ http://openjava.sourceforge.net/
+
+
+Enjoy,
+
+Michiaki Tatsubori
+mich@acm.org
+
+
+Java(TM) is a trademark of Sun Microsystems, Inc.
+
+** Maintenance
+
+This is a mostly unmodified version of the original code from
+[[oj-source-forge][OJ project on SourceForge]], however, slightly updated and
+hopefully eventually mirrored on Maven central.
+
+Bugs may be submitted, but it would be preferred if you can fix them and submit
+patches. I do not intend necessarily intend this to be a new home for this
+project.
diff --git a/bin/ojc.bat b/bin/ojc.bat
new file mode 100644
index 0000000..712e945
--- /dev/null
+++ b/bin/ojc.bat
@@ -0,0 +1 @@
+java -classpath .;c:%OPENJAVA_HOME%\classes openjava.ojc.Main %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
diff --git a/bin/ojc.ksh b/bin/ojc.ksh
new file mode 100755
index 0000000..9841c85
--- /dev/null
+++ b/bin/ojc.ksh
@@ -0,0 +1,47 @@
+#! /bin/ksh
+#
+# ojc
+#
+# This translates and compile the files into byte codes.
+#
+# Oct 25, 1997 by Michiaki Tatsubori
+
+# Please set up followings to be suitable for your enviroment.
+JVM=java
+
+
+# Get path to this program
+PRG=`whence $0` >/dev/null 2>&1
+# Resolve symlinks. See 4152645.
+while [ -h "$PRG" ]; do
+ ls=`/usr/bin/ls -ld "$PRG"`
+ link=`/usr/bin/expr "$ls" : '^.*-> \(.*\)$'`
+ if /usr/bin/expr "$link" : '^/' > /dev/null; then
+ prg="$link"
+ else
+ prg="`/usr/bin/dirname $PRG`/$link"
+ fi
+ PRG=`whence "$prg"` > /dev/null 2>&1
+done
+OPENJAVA_HOME=`dirname ${PRG}`/..
+
+CLASSPATH=${OPENJAVA_HOME}/classes:${CLASSPATH}
+export CLASSPATH
+
+
+# Pick out options for JVM
+# i.e. -J"-classpath /home/classes"
+JVMOPTS=
+OJARGS=
+for arg in $*; do
+ if [ ${arg} != ${arg#-J} ]; then
+ JVMOPTS="${JVMOPTS} ${arg#-J}"
+ else
+ OJARGS="${OJARGS} ${arg}"
+ fi
+done
+
+
+# Execute
+echo ${JVM} ${JVMOPTS} openjava.ojc.Main ${OJARGS}
+${JVM} ${JVMOPTS} openjava.ojc.Main ${OJARGS}
diff --git a/bin/ojc.sh b/bin/ojc.sh
new file mode 100755
index 0000000..a83cb73
--- /dev/null
+++ b/bin/ojc.sh
@@ -0,0 +1,48 @@
+#! /bin/sh
+#
+# ojc
+#
+# This translates and compile the files into byte codes.
+# This is a shell script for linux or some unix-like systems,
+# which do not have ksh.
+#
+# Sep 21, 2000 by Michiaki Tatsubori
+
+# Please set up followings to be suitable for your enviroment.
+JVM=java
+
+if [ "$OPENJAVA_HOME" = "" ] ; then
+ PRG=$0
+ progname=`basename $0`
+ while [ -L "$PRG" ]; do
+ ls=`/bin/ls -ld "$PRG"`
+ link=`/usr/bin/expr "$ls" : '.*-> \(.*\)$'`
+ if /usr/bin/expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`/usr/bin/dirname $PRG`/$link"
+ fi
+ done
+ OPENJAVA_HOME=`dirname ${PRG}`/..
+fi
+
+CLASSPATH=${OPENJAVA_HOME}/classes:${CLASSPATH}
+export CLASSPATH
+
+
+# Pick out options for JVM
+# i.e. -J"-classpath /home/classes"
+JVMOPTS=-classpath ${CLASSPATH}
+OJARGS=
+for arg in $*; do
+ if [ ${arg} != ${arg#-J} ]; then
+ JVMOPTS="${JVMOPTS} ${arg#-J}"
+ else
+ OJARGS="${OJARGS} ${arg}"
+ fi
+done
+
+
+# Execute
+echo ${JVM} ${JVMOPTS} openjava.ojc.Main ${OJARGS}
+${JVM} ${JVMOPTS} openjava.ojc.Main ${OJARGS}
diff --git a/docs/BugNotes.txt b/docs/BugNotes.txt
new file mode 100644
index 0000000..b26c8d6
--- /dev/null
+++ b/docs/BugNotes.txt
@@ -0,0 +1,59 @@
+Notes about bugs in OpenJava 1.0 alpha release
+Michiaki Tatsubori
+Last update Oct 10, 2000
+
+
+[Bug List and Bug-fix History]
+
+in build 20000905
+- Reporting NoSuchMemberException even for accessible innerclass's
+ or outerclass's member.
+ (fixed in 20001010)
+
+in build 20000627
+- Wrongly parsing an array-typed member fields declaration in which
+ brackets follows variable name.
+ (fixed in 20000905)
+
+in build 19990527
+- A constructor only with an explicit super constructor invocation
+ is failed to print.
+ (fixed in 20000627)
+
+in build 19990525
+- The ojc dosen't work for files without specifying its directory in
+ case of no -d option. (fixed in 19990527)
+- The class CommandArguments use a method only available in Java 2.
+ (fixed in 19990527)
+- The parser dosn't reconize any synchronized statement. (fixed in
+ 19990527)
+
+in build 19990505
+- The only way to find nested classes using forName is to dollarify
+ the name. (fixed in 1990507)
+
+
+[Thanks to Contributers]
+ Antonio Leitao
+ Anurag Mendhekar
+ Bryn Keller
+ Cees de Groot
+ Jesse N. Glick
+ Joseph Smyth
+ Juan-Carlos Ruiz-Garcia
+ Kenneth Kasajian
+ Kirk Abbott
+ Lee Jun-Sang
+ Lionel Seinturier
+ Luciano Garcia-Banuelos
+ Marc-Olivier Killijian
+ Maurizio Mazza
+ Olivier Jautzy
+ PhiHo Hoang
+ Schulz Arnaud
+ Shiro Kawai
+ Stanislav Chachkov
+ Teruo Koyanagi
+ Thorsten Sturm
+ Uwe Assmann
+ Walter Cazzola
diff --git a/docs/TODO b/docs/TODO
new file mode 100644
index 0000000..6240507
--- /dev/null
+++ b/docs/TODO
@@ -0,0 +1,41 @@
+* innerclasses
+* setInterface() ...
+* (String.class) -> (OJClass.forClass(String.class)) by Metaclass
+* setting up ClassEnvironment correctly
+* inheritance of fields in interface
+
+OJClass API
+ - Class loader API
+ - More customizablity in loading source code
+
+OJClass Bug
+ - Array objects must have interface like Serializable, Cloneable.
+ - Fails only for array whose elements' type is any source-based class.
+
+OJClass API
+ - getAllInterfaces() or getInterfaces() + getDeclaredInterfaces()
+ - The getInterfaces() returns all the interfaces now.
+
+OJField's lack of API
+ - constructor of OJField with field initializer
+
+ClassDeclaration Utility
+ - New class objects created by makeRecursiveCopy() needs
+ class-importing information
+
+OJC Utility
+ - Command line indication of metaclass
+
+OJClass Bug
+ - No metalevel information kept for newly generated classes.
+
+ModifierList API
+ - ModifierList.contains(String) may have better be sensitive
+ to regular Java modifiers like "public".
+
+OJClass's lack of API
+ - setModifiers()
+
+* OJClass Bug?
+ - interface should have a superclass java.lang.Object
+ * Interface is not a subclass of java.lang.Object.
diff --git a/docs/licenses/cpl-v10.html b/docs/licenses/cpl-v10.html
new file mode 100644
index 0000000..cb4e7b7
--- /dev/null
+++ b/docs/licenses/cpl-v10.html
@@ -0,0 +1,125 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+<HEAD>
+<TITLE>Common Public License - v 1.0</TITLE>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</HEAD>
+
+<BODY BGCOLOR="#FFFFFF" VLINK="#800000">
+
+
+<P ALIGN="CENTER"><B>Common Public License - v 1.0</B>
+<P><B></B><FONT SIZE="3"></FONT>
+<P><FONT SIZE="3"></FONT><FONT SIZE="2">THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>1. DEFINITIONS</B></FONT>
+<P><FONT SIZE="2">"Contribution" means:</FONT>
+
+<UL><FONT SIZE="2">a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and<BR CLEAR="LEFT">
+b) in the case of each subsequent Contributor:</FONT></UL>
+
+
+<UL><FONT SIZE="2">i) changes to the Program, and</FONT></UL>
+
+
+<UL><FONT SIZE="2">ii) additions to the Program;</FONT></UL>
+
+
+<UL><FONT SIZE="2">where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. </FONT><FONT SIZE="2">A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. </FONT><FONT SIZE="2">Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. </FONT></UL>
+
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Contributor" means any person or entity that distributes the Program.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. </FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">"Program" means the Contributions distributed in accordance with this Agreement.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.</FONT>
+<P><FONT SIZE="2"><B></B></FONT>
+<P><FONT SIZE="2"><B>2. GRANT OF RIGHTS</B></FONT>
+
+<UL><FONT SIZE="2"></FONT><FONT SIZE="2">a) </FONT><FONT SIZE="2">Subject to the terms of this Agreement, each Contributor hereby grants</FONT><FONT SIZE="2"> Recipient a non-exclusive, worldwide, royalty-free copyright license to</FONT><FONT SIZE="2" COLOR="#FF0000"> </FONT><FONT SIZE="2">reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.</FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT><FONT SIZE="2">b) Subject to the terms of this Agreement, each Contributor hereby grants </FONT><FONT SIZE="2">Recipient a non-exclusive, worldwide,</FONT><FONT SIZE="2" COLOR="#008000"> </FONT><FONT SIZE="2">royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. </FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2">c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.</FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2">d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. </FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+<P><FONT SIZE="2"><B>3. REQUIREMENTS</B></FONT>
+<P><FONT SIZE="2"><B></B>A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:</FONT>
+
+<UL><FONT SIZE="2">a) it complies with the terms and conditions of this Agreement; and</FONT></UL>
+
+
+<UL><FONT SIZE="2">b) its license agreement:</FONT></UL>
+
+
+<UL><FONT SIZE="2">i) effectively disclaims</FONT><FONT SIZE="2"> on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; </FONT></UL>
+
+
+<UL><FONT SIZE="2">ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; </FONT></UL>
+
+
+<UL><FONT SIZE="2">iii)</FONT><FONT SIZE="2"> states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and</FONT></UL>
+
+
+<UL><FONT SIZE="2">iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.</FONT><FONT SIZE="2" COLOR="#0000FF"> </FONT><FONT SIZE="2" COLOR="#FF0000"></FONT></UL>
+
+
+<UL><FONT SIZE="2" COLOR="#FF0000"></FONT><FONT SIZE="2"></FONT></UL>
+
+<P><FONT SIZE="2">When the Program is made available in source code form:</FONT>
+
+<UL><FONT SIZE="2">a) it must be made available under this Agreement; and </FONT></UL>
+
+
+<UL><FONT SIZE="2">b) a copy of this Agreement must be included with each copy of the Program. </FONT></UL>
+
+<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT>
+<P><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT><FONT SIZE="2">Contributors may not remove or alter any copyright notices contained within the Program. </FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. </FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>4. COMMERCIAL DISTRIBUTION</B></FONT>
+<P><FONT SIZE="2">Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"></FONT>
+<P><FONT SIZE="2" COLOR="#0000FF"></FONT><FONT SIZE="2"><B>5. NO WARRANTY</B></FONT>
+<P><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is</FONT><FONT SIZE="2"> solely responsible for determining the appropriateness of using and distributing </FONT><FONT SIZE="2">the Program</FONT><FONT SIZE="2"> and assumes all risks associated with its exercise of rights under this Agreement</FONT><FONT SIZE="2">, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, </FONT><FONT SIZE="2">programs or equipment, and unavailability or interruption of operations</FONT><FONT SIZE="2">. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"><B>6. DISCLAIMER OF LIABILITY</B></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES </FONT><FONT SIZE="2">(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT SIZE="2"> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>7. GENERAL</B></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to </FONT><FONT SIZE="2">publish new versions (including revisions) of this Agreement from time to </FONT><FONT SIZE="2">time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. </FONT><FONT SIZE="2">Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new </FONT><FONT SIZE="2">version. </FONT><FONT SIZE="2">Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, </FONT><FONT SIZE="2">by implication, estoppel or otherwise</FONT><FONT SIZE="2">.</FONT><FONT SIZE="2"> All rights in the Program not expressly granted under this Agreement are reserved.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+
+</BODY>
+
+</HTML>
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..80c9663
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>io.devnulllabs</groupId>
+ <artifactId>openjava</artifactId>
+ <version>0.1-SNAPSHOT</version>
+
+ <name>openjava</name>
+ <description>OJ (f.a.k.a. OpenJava) is an object-oriented macro system with a
+ compile time metaobject protocol for Java.</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </dependency>
+ <dependency>
+ <groupId>net.java.dev.javacc</groupId>
+ <artifactId>javacc</artifactId>
+ <version>4.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.0.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.7</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.9</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.0.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.20.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>2.5.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>3.0.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javacc-plugin</artifactId>
+ <version></version>
+ <executions>
+ <execution>
+ <id>jcc1</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>javacc</goal>
+ </goals>
+ <configuration>
+ <jdkVersion>${java.version}</jdkVersion>
+ <javadocFriendlyComments>true</javadocFriendlyComments>
+ <packageName>org.javacc.parser</packageName>
+ <sourceDirectory>${project.basedir}/src/main/java/io/devnulllabs/openjava/tools/parser</sourceDirectory>
+ <outputDirectory>${project.basedir}/src/main/java/io/devnulllabs/openjava/tools/parser</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/src/main/java/io/devnulllabs/openjava/mop/AmbiguousClassesException.java b/src/main/java/io/devnulllabs/openjava/mop/AmbiguousClassesException.java
new file mode 100644
index 0000000..ff37cbc
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/AmbiguousClassesException.java
@@ -0,0 +1,30 @@
+/*
+ * AmbiguousClassesException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+
+
+/**
+ * The exception <code>AmbiguousClassesException</code> is thrown if the
+ * additional <code>OJClass</code> object has the same name with another
+ * <code>OJClass</code> object's.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: AmbiguousClassesException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class AmbiguousClassesException extends MOPException {
+ public AmbiguousClassesException( String access ) {
+ super( access );
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/AnonymousClassEnvironment.java b/src/main/java/io/devnulllabs/openjava/mop/AnonymousClassEnvironment.java
new file mode 100644
index 0000000..4c927a2
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/AnonymousClassEnvironment.java
@@ -0,0 +1,53 @@
+/*
+ * AnonymousClassEnvironment.java
+ *
+ * Aug 2, 2002 by Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.mop;
+
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+
+public class AnonymousClassEnvironment extends ClassEnvironment
+{
+ private MemberDeclarationList members;
+ private String base;
+
+ public AnonymousClassEnvironment(Environment e, String baseClassName, MemberDeclarationList mdecls) {
+ super(e);
+ this.members = mdecls;
+ this.base = baseClassName;
+ }
+
+ public String getClassName() {
+ return "<anonymous class>";
+ }
+
+ public String toString() {
+ return super.toString();
+ }
+
+ public OJClass lookupBind(String name) {
+ for (int i = 0, len = members.size(); i < len; ++i) {
+ if (!(members.get(i) instanceof FieldDeclaration)) continue;
+ FieldDeclaration field = (FieldDeclaration) members.get(i);
+ if (! name.equals(field.getName())) continue;
+ return lookupClass(field.getName());
+ }
+ OJField field = pickupField(lookupClass(base), name);
+ if (field != null) return field.getType();
+ /* not a field name of this class */
+ return parent.lookupBind(name);
+ }
+
+ /**
+ * Returns the qualified class name.
+ *
+ * @return the qualified name of the class which organizes this
+ * environment.
+ */
+ public String currentClassName() {
+ return getClassName();
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/CannotAlterException.java b/src/main/java/io/devnulllabs/openjava/mop/CannotAlterException.java
new file mode 100644
index 0000000..8c657ed
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/CannotAlterException.java
@@ -0,0 +1,29 @@
+/*
+ * CannotAlterException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+
+
+/**
+ * CannotAlterException is thrown if the requested change cannot be
+ * performed on the class object, the method object, or the field object.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: CannotAlterException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class CannotAlterException extends MOPException {
+ public CannotAlterException( String access ) {
+ super( access );
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/CannotExecuteException.java b/src/main/java/io/devnulllabs/openjava/mop/CannotExecuteException.java
new file mode 100644
index 0000000..78105c0
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/CannotExecuteException.java
@@ -0,0 +1,34 @@
+/*
+ * CannotExecuteException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+
+
+/**
+ * CannotExecuteException is thrown if the requested introspection
+ * cannot be performed on the class object, the method object, or
+ * the field object, which needs a java's Class object not available.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: CannotExecuteException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class CannotExecuteException extends MOPException
+{
+ public CannotExecuteException() {
+ super();
+ }
+
+ public CannotExecuteException( String access ) {
+ super( access );
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/CannotInspectException.java b/src/main/java/io/devnulllabs/openjava/mop/CannotInspectException.java
new file mode 100644
index 0000000..ee2d1c1
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/CannotInspectException.java
@@ -0,0 +1,35 @@
+/*
+ * CannotInspectException.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+/**
+ * The exception <code>CannotInspectException</code> is thrown if the
+ * requested introspection cannot be performed on the class object,
+ * the method object, or the field object.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: CannotInspectException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class CannotInspectException extends MOPException {
+
+ public CannotInspectException() {
+ super();
+ }
+
+ public CannotInspectException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/ClassEnvironment.java b/src/main/java/io/devnulllabs/openjava/mop/ClassEnvironment.java
new file mode 100644
index 0000000..9c68f86
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/ClassEnvironment.java
@@ -0,0 +1,183 @@
+/*
+ * ClassEnvironment.java
+ *
+ * Jul 28, 1998 by mich
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Vector;
+
+
+public class ClassEnvironment extends ClosedEnvironment
+{
+ private OJClass clazz = null;
+ private String className = null;
+ private Vector memberClasses = new Vector();
+
+ public ClassEnvironment( Environment e, String name ) {
+ super( e );
+ className = toSimpleName( name );
+ }
+
+ public ClassEnvironment( Environment e ) {
+ super( e );
+ className = null;
+ }
+
+ public ClassEnvironment( Environment e, OJClass clazz ) {
+ super( e );
+ className = toSimpleName( clazz.getName() );
+ OJClass[] memclazz = clazz.getDeclaredClasses();
+ for (int i = 0; i < memclazz.length; ++i) {
+ memberClasses.addElement( memclazz[i].getSimpleName() );
+ }
+ }
+
+ public String getClassName() {
+ if (className != null) return className;
+ return "<unknown class>";
+ }
+
+ public Vector getMemberClasses() {
+ return memberClasses;
+ }
+
+ public String toString() {
+ StringWriter str_writer = new StringWriter();
+ PrintWriter out = new PrintWriter( str_writer );
+
+ out.println( "ClassEnvironment" );
+ out.println( "class : " + getClassName() );
+ out.println( "member classes : " + getMemberClasses() );
+ out.print( "parent env : " + parent );
+
+ out.flush();
+ return str_writer.toString();
+ }
+
+ public void recordClassName( String name ) {
+ this.className = toSimpleName( name );
+ }
+
+ public void recordMemberClass( String name ) {
+ memberClasses.addElement( name );
+ }
+
+ public OJClass lookupClass( String name ) {
+ /* should hold and return member classes
+ * Currently, the global environment holds all the top inner classes.
+ */
+ return parent.lookupClass( name );
+ }
+
+ public OJClass lookupBind(String name) {
+ String current = currentClassName();
+ OJClass declarer = lookupClass(current);
+ if (declarer == null) {
+ System.err.println( "unexpected error : unknown class " + current);
+ return parent.lookupBind(name);
+ }
+ OJField field = pickupField(declarer, name);
+ if (field != null) return field.getType();
+ /* not a field name of this class */
+ return parent.lookupBind(name);
+ }
+
+ public static OJField pickupField(OJClass reftype, String name) {
+ try {
+ return reftype.getField(name, reftype);
+ } catch ( NoSuchMemberException e ) {}
+ /* tries member fields of its inner classes */
+ return pickupField(reftype.getDeclaredClasses(), name);
+ }
+
+ public static OJField pickupField(OJClass[] reftypes, String name) {
+ for (int i = 0; i < reftypes.length; ++i) {
+ OJField result = pickupField(reftypes[i], name);
+ if (result != null) return result;
+ }
+ return null;
+ }
+
+ /**
+ * Obtains the fully-qualified name of the given class name.
+ *
+ * @param name a simple class name or a fully-qualified class name
+ * @return the fully-qualified name of the class
+ */
+ public String toQualifiedName( String name ) {
+ if (name == null) return null;
+ if (name.endsWith("[]")) {
+ String stripped = name.substring( 0, name.length() - 2 );
+ return toQualifiedName( stripped ) + "[]";
+ }
+ if (name.indexOf( "." ) != -1) {
+ /* may be simple name + innerclass */
+ String top = getFirst( name );
+ String qtop = toQualifiedName( top );
+ if (qtop == null || qtop.equals( top )) return name;
+ return qtop + "." + getRest( name );
+ }
+ if (name.equals( getClassName() )) {
+ if (isMostOuter()) {
+ /* most outer class */
+ String pack = getPackage();
+ if (pack == null || pack.equals( "" )) return name;
+ return pack + "." + name;
+ }
+ /* inner class */
+ String parentName = parentName();
+ if (parentName != null) return parentName() + "." + name;
+ /* anonymous/local class */
+ return name;
+ }
+ if (memberClasses.indexOf( name ) >= 0) {
+ return currentClassName() + "." + name;
+ }
+ return parent.toQualifiedName( name );
+ }
+
+ private static final String getFirst( String qname ) {
+ int dot = qname.indexOf( "." ) ;
+ if (dot == -1) return qname;
+ return qname.substring( 0, dot );
+ }
+ private static final String getRest( String qname ) {
+ int dot = qname.indexOf( "." ) ;
+ if (dot == -1) return qname;
+ return qname.substring( dot + 1 );
+ }
+ /*
+ private String parentName() {
+ Environment ancestor = parent;
+ while (ancestor != null && ! (ancestor instanceof ClassEnvironment)) {
+ ancestor = ancestor.parent;
+ }
+ if (ancestor == null) return null;
+ return ancestor.currentClassName();
+ }
+ */
+ private String parentName() {
+ if (parent == null || ! (parent instanceof ClassEnvironment)) {
+ return null;
+ }
+ return parent.currentClassName();
+ }
+ private boolean isMostOuter() {
+ return (parent instanceof FileEnvironment);
+ }
+
+ /**
+ * Returns the qualified class name.
+ *
+ * @return the qualified name of the class which organizes this
+ * environment.
+ */
+ public String currentClassName() {
+ return toQualifiedName( getClassName() );
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/ClosedEnvironment.java b/src/main/java/io/devnulllabs/openjava/mop/ClosedEnvironment.java
new file mode 100644
index 0000000..d4529e8
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/ClosedEnvironment.java
@@ -0,0 +1,119 @@
+/*
+ * ClosedEnvironment.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.tools.DebugOut;
+
+
+/**
+ * The class <code>ClosedEnvironment</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ClosedEnvironment.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class ClosedEnvironment extends Environment
+{
+ protected Hashtable table = new Hashtable();
+ protected Hashtable symbol_table = new Hashtable();
+
+ /**
+ *
+ *
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public ClosedEnvironment( Environment env ) {
+ parent = env;
+ }
+
+ public String toString() {
+ StringWriter str_writer = new StringWriter();
+ PrintWriter out = new PrintWriter( str_writer );
+
+ out.println( "ClosedEnvironment" );
+ out.println( "class object table : " + table );
+ out.println( "binding table : " + symbol_table );
+ out.println( "parent env : " + parent );
+
+ out.flush();
+ return str_writer.toString();
+ }
+
+ public void record( String name, OJClass clazz ) {
+ DebugOut.println( "ClosedEnvironment#record() : "
+ + name + " " + clazz.getName() );
+ Object result = table.put( name, clazz );
+ if (result != null) {
+ System.err.println( name + " is already binded on "
+ + result.toString() );
+ }
+ }
+
+ public OJClass lookupClass( String name ) {
+ OJClass result = (OJClass) table.get( name );
+ if (result != null) return result;
+ return parent.lookupClass( name );
+ }
+
+ /**
+ * binds a name to the class type.
+ *
+ * @param name the fully-qualified name of the class
+ * @param clazz the class object associated with that name
+ */
+ public void bindVariable( String name, OJClass clazz ) {
+ symbol_table.put( name, clazz );
+ }
+
+ public OJClass lookupBind( String name ) {
+ OJClass type = (OJClass) symbol_table.get( name );
+ if (type != null) return type;
+ if (parent == null) return null;
+ return parent.lookupBind( name );
+ }
+
+ /*
+ public String toQualifiedName(String name) {
+ if (name.indexOf('.') == -1) {
+ java.util.Enumeration ite = table.keys();
+ while (ite.hasMoreElements()) {
+ String qname = (String) ite.nextElement();
+ if (qname.endsWith("." + name)) return qname;
+ }
+ }
+ return parent.toQualifiedName(name);
+ }
+ */
+ public String toQualifiedName(String name) {
+ java.util.Enumeration ite = table.keys();
+ while (ite.hasMoreElements()) {
+ String qname = (String) ite.nextElement();
+ if (qname.equals(name)) return qname;
+ }
+ return parent.toQualifiedName(name);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/Environment.java b/src/main/java/io/devnulllabs/openjava/mop/Environment.java
new file mode 100644
index 0000000..635b22c
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/Environment.java
@@ -0,0 +1,153 @@
+/*
+ * Environment.java
+ *
+ *
+ * Jul 28, 1998 by mich
+ */
+package io.devnulllabs.openjava.mop;
+
+
+
+
+public abstract class Environment
+{
+
+ protected Environment parent;
+
+ public Environment() {
+ parent = null;
+ }
+
+ public Environment( Environment e ) {
+ parent = e;
+ }
+
+ public abstract String toString();
+
+ /**
+ * Gets the package name.
+ * @return Package name or null
+ */
+ public String getPackage()
+ {
+ if (parent == null) {
+ System.err.println( "Environment.getPackage() : not specified." );
+ return null;
+ }
+ return parent.getPackage();
+ }
+
+ /**
+ * Looks a class object up.
+ *
+ * @param name the name of the fully-qualified name of the class
+ * looked for
+ * @return Null or class found in lookup
+ */
+ public OJClass lookupClass( String name ) {
+ if (parent == null) {
+ System.err.println( "Environment.lookupClass() : not specified." );
+ return null;
+ }
+ return parent.lookupClass( name );
+ }
+
+ /**
+ * Records a class object.
+ *
+ * @param name the fully-qualified name of the class
+ * @param clazz the class object associated with that name
+ */
+ public abstract void record( String name, OJClass clazz );
+
+ /**
+ * Looks up a binded type of the given variable or field name.
+ *
+ * @param name the fully-qualified name of the class
+ * @param clazz the class object associated with that name
+ * @return Class bind lookup or null
+ */
+ public OJClass lookupBind( String name ) {
+ if (parent == null) return null;
+ return parent.lookupBind( name );
+ }
+
+ /**
+ * binds a name to the class type.
+ *
+ * @param name the fully-qualified name of the class
+ * @param clazz the class object associated with that name
+ */
+ public abstract void bindVariable( String name, OJClass clazz );
+
+ /**
+ * Obtains the fully-qualified name of the given class name.
+ *
+ * @param name a simple class name or a fully-qualified class name
+ * @return the fully-qualified name of the class
+ */
+ public String toQualifiedName( String name ) {
+ if (parent == null) return name;
+ return parent.toQualifiedName( name );
+ }
+
+ /**
+ * Tests if the given name is a qualified name or not.
+ * @param name String to test if qualified or not
+ * @return result
+ */
+ public static boolean isQualifiedName( String name ) {
+ return name.indexOf( '.' ) >= 0;
+ }
+
+ /**
+ * Converts a fully-qualified name to the corresponding simple-name.
+ *
+ * <pre>
+ * For example :
+ * toSimpleName( "java.lang.Class" ) returns "Class".
+ * </pre>
+ *
+ * @param qualified_name Name to convert
+ * @return the given name <I>as is</I> if it is not a qualified
+ * name
+ */
+ public static String toSimpleName( String qualified_name ) {
+ int index = qualified_name.lastIndexOf( '.' );
+ if (index < 0) {
+ return qualified_name;
+ } else {
+ return qualified_name.substring( index + 1 );
+ }
+ }
+
+ /**
+ * Converts a fully-qualified name to the corresponding package name.
+ *
+ * <pre>
+ * For example :
+ * toPackageName( "java.lang.Class" ) returns "java.lang".
+ * toPackageName( "MyClass" ) returns "".
+ * </pre>
+ *
+ * @param qualified_name Name to convert to package name
+ * @return the given name <I>as is</I> if it is not a qualified
+ * name
+ */
+ public static String toPackageName( String qualified_name ) {
+ int index = qualified_name.lastIndexOf( '.' );
+ return (index < 0) ? "" : qualified_name.substring( 0, index );
+ }
+
+ public String currentClassName() {
+ if (parent == null) return null;
+ return parent.currentClassName();
+ }
+
+ /******************************/
+ public boolean isRegisteredModifier( String str ) {
+ if (parent == null) return false;
+ return parent.isRegisteredModifier( str );
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/FileEnvironment.java b/src/main/java/io/devnulllabs/openjava/mop/FileEnvironment.java
new file mode 100644
index 0000000..04b1788
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/FileEnvironment.java
@@ -0,0 +1,376 @@
+/*
+ * FileEnvironment.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ *
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassDeclarationList;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The class <code>FileEnvironment</code>
+ * <p>
+ * For example
+ *
+ * <pre>
+ * </pre>
+ *
+ *
+ *
+ *
+ *
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: FileEnvironment.java,v 1.3 2003/11/14 13:52:02 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class FileEnvironment extends Environment {
+
+ private final File file;
+ private String packageName;
+ private String pubclassName;
+ private final Vector localClasses = new Vector(); /* not implemented */
+
+ private Vector importedClasses = new Vector();
+ private Vector importedPackages = new Vector();
+ private final Hashtable localClassTable = new Hashtable();
+
+ public FileEnvironment(Environment e, String pack, String name) {
+ this(e, pack, name, null);
+ }
+
+ public FileEnvironment(
+ Environment e,
+ String pack,
+ String name,
+ File file) {
+ super(e);
+ if (pack != null && pack.equals(""))
+ pack = null;
+ this.packageName = pack;
+ this.pubclassName = name;
+ this.file = file;
+ importPackage("java.lang");
+ }
+
+ public FileEnvironment(Environment e) {
+ this(e, null, null, null);
+ }
+
+ public FileEnvironment(
+ Environment e,
+ CompilationUnit comp_unit,
+ String mainname) {
+ this(e, comp_unit.getPackage(), mainname);
+ setCompilationUnit(comp_unit);
+ }
+
+ public String toString() {
+ StringWriter str_writer = new StringWriter();
+ PrintWriter out = new PrintWriter(str_writer);
+
+ out.println("FileEnvironment");
+ out.println("\tfile : " + file);
+ out.println("\tpackage : " + packageName);
+ out.println("\tmain class : " + file);
+ out.println("\tmain class : " + file);
+ out.print("\tlocal classes : ");
+ writeStringVector(out, localClasses);
+ out.println();
+ out.print("\timported classes : ");
+ writeStringVector(out, importedClasses);
+ out.println();
+ out.print("\timported packages : ");
+ writeStringVector(out, importedPackages);
+ out.println();
+ out.println("\tlocal class table : " + localClassTable);
+ out.println("parent env : " + parent);
+
+ out.flush();
+ return str_writer.toString();
+ }
+
+ private static void writeStringVector(PrintWriter out, Vector v) {
+ Enumeration e = v.elements();
+ while (e.hasMoreElements()) {
+ String str = (String) e.nextElement();
+ out.print(str + " ");
+ }
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Sets the package name.
+ */
+ public void setPackage(String pack) {
+ if (pack != null && pack.equals(""))
+ pack = null;
+ packageName = pack;
+ }
+
+ /**
+ * Gets the package name.
+ */
+ public String getPackage() {
+ if (packageName == "")
+ return null;
+ return packageName;
+ }
+
+ /**
+ * Internal use only.
+ *
+ * @param comp_unit
+ * compilation unit to initialize this environment.
+ */
+ public void setCompilationUnit(CompilationUnit comp_unit) {
+ packageName = comp_unit.getPackage();
+ try {
+ ClassDeclaration cd = comp_unit.getPublicClass();
+ if (cd != null)
+ pubclassName = cd.getName();
+ } catch (Exception ex) {
+ }
+
+ String[] imps = comp_unit.getDeclaredImports();
+ for (int i = 0; i < imps.length; ++i) {
+ if (CompilationUnit.isOnDemandImport(imps[i])) {
+ String imppack = CompilationUnit.trimOnDemand(imps[i]);
+ this.importPackage(imppack);
+ } else {
+ this.importClass(imps[i]);
+ }
+ }
+
+ ClassDeclarationList classdecls = comp_unit.getClassDeclarations();
+ for (int i = 0; i < classdecls.size(); ++i) {
+ ClassDeclaration cdecl = classdecls.get(i);
+ if (cdecl.getModifiers().contains(ModifierList.PUBLIC))
+ continue;
+ this.recordLocalClassName(cdecl.getName());
+ }
+
+ }
+
+ /**
+ * Looks a class object up.
+ *
+ * @param name
+ * the name of the fully-qualified name of the class looked for
+ */
+ public OJClass lookupClass(String name) {
+ OJClass clazz = (OJClass) localClassTable.get(name);
+ if (clazz != null)
+ return clazz;
+ try {
+ clazz = OJClass.forName(name);
+ } catch (OJClassNotFoundException e) {
+ return null;
+ }
+ return clazz;
+ }
+
+ /**
+ * Records a class object.
+ *
+ * @param name
+ * the fully-qualified name of the class
+ * @param clazz
+ * the class object associated with that name
+ */
+ public void record(String name, OJClass clazz) {
+ DebugOut.println("Fenv#record(): " + name + " " + clazz);
+ localClassTable.put(name, clazz);
+ }
+
+ /**
+ * Imports a class.
+ *
+ * @param name
+ * the fully-qualified name of the imported class
+ * @return false if the given name is already registered or if it is an
+ * ambiguous name.
+ */
+ public boolean importClass(String qualified_name) {
+ DebugOut.println("FileEnvironment#importClass() : " + qualified_name);
+ String simple_name = toSimpleName(qualified_name);
+ if (isAlreadyImportedClass(qualified_name)
+ || isCrashingClassName(simple_name)) {
+ return false;
+ } else {
+ importedClasses.addElement(qualified_name);
+ return true;
+ }
+ }
+
+ /**
+ * Imports a package.
+ *
+ * @param name
+ * the fully-qualified name of the imported package
+ */
+ public void importPackage(String name) {
+ DebugOut.println("FileEnvironment#importPackage() : " + name);
+ importedPackages.addElement(name);
+ }
+
+ /**
+ * Obtains the fully-qualified name of the given class name.
+ *
+ * @param name
+ * a simple class name or a fully-qualified class name
+ * @return the fully-qualified name of the class
+ */
+ public String toQualifiedName(String name) {
+ if (name == null || isPrimitiveType(name) || isQualifiedName(name)) {
+ return name;
+ }
+
+ if (name.endsWith("[]")) {
+ String stripped = name.substring(0, name.length() - 2);
+ return toQualifiedName(stripped) + "[]";
+ }
+
+ String sname = name;
+
+ if ((file != null && file.getName().endsWith(sname + ".oj"))
+ || localClasses.indexOf(sname) != -1) {
+ String pack = getPackage();
+ if (pack == null)
+ return sname;
+ return pack + "." + sname;
+ }
+
+ String qname;
+
+ qname = searchImportedClasses(sname);
+ if (qname != null)
+ return qname;
+
+ qname = searchImportedPackages(sname);
+ if (qname != null)
+ return qname;
+
+ return sname;
+ }
+
+ /**
+ * Register a simple name as a local class
+ */
+ public void recordLocalClassName(String name) {
+ DebugOut.println(
+ "FileEnvironment#recordLocalClassName() : " + toSimpleName(name));
+ localClasses.addElement(toSimpleName(name));
+ }
+
+ private static final boolean isPrimitiveType(String name) {
+ if (name == null)
+ return false;
+ return (
+ name.equals("boolean")
+ || name.equals("byte")
+ || name.equals("char")
+ || name.equals("double")
+ || name.equals("float")
+ || name.equals("int")
+ || name.equals("long")
+ || name.equals("short")
+ || name.equals("void"));
+ }
+
+ private String searchImportedClasses(String simple_name) {
+ String tail = "." + simple_name;
+ for (int i = 0, size = importedClasses.size(); i < size; ++i) {
+ String qname = (String) importedClasses.elementAt(i);
+ if (qname.endsWith(tail))
+ return qname;
+ }
+ return null;
+ }
+
+ private boolean isAlreadyImportedClass(String qualified_name) {
+ for (int i = 0, size = importedClasses.size(); i < size; ++i) {
+ String qname = (String) importedClasses.elementAt(i);
+ if (qname.equals(qualified_name))
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isCrashingClassName(String simple_name) {
+ return (searchImportedClasses(simple_name) != null);
+ }
+
+ private String searchImportedPackages(String simple_name) {
+ String found;
+
+ String packname = getPackage();
+ if (packname == null || packname.equals("")) {
+ found = simple_name;
+ } else {
+ found = packname + "." + simple_name;
+ }
+ if (theClassExists(found))
+ return found;
+
+ found = null;
+
+ /* the qualified name found last should be taken */
+ for (int i = 0, size = importedPackages.size(); i < size; ++i) {
+ packname = (String) importedPackages.elementAt(i);
+ String qname = packname + "." + simple_name;
+ if (theClassExists(qname))
+ found = qname;
+ }
+
+ /* this returns the qualified name found last. */
+ return found;
+ }
+
+ /*
+ * The use of Class.forName() costs too much time.
+ */
+ private boolean theClassExists(String class_name) {
+ return (lookupClass(class_name) != null);
+ }
+
+ /**
+ * binds a name to the class type.
+ *
+ * @param name
+ * the fully-qualified name of the class
+ * @param clazz
+ * the class object associated with that name
+ */
+ public void bindVariable(String name, OJClass clazz) {
+ System.err.println("error : illegal binding on FileEnvironment");
+ }
+
+ public OJClass lookupBind(String name) {
+ return null;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/GlobalEnvironment.java b/src/main/java/io/devnulllabs/openjava/mop/GlobalEnvironment.java
new file mode 100644
index 0000000..cb38d77
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/GlobalEnvironment.java
@@ -0,0 +1,108 @@
+/*
+ * GlobalEnvironment.java
+ *
+ * Initilializing must be done after loading classes.
+ *
+ * Jul 28, 1998 modified by mich
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import io.devnulllabs.openjava.tools.DebugOut;
+
+
+public class GlobalEnvironment
+ extends Environment
+{
+ private Hashtable table = new Hashtable();
+
+ public GlobalEnvironment() {
+ }
+
+ public String toString() {
+ StringWriter str_writer = new StringWriter();
+ PrintWriter out = new PrintWriter( str_writer );
+
+ out.println( "GlobalEnvironment" );
+ out.print( "class object table : " );
+ out.println( table.toString() );
+
+ out.flush();
+ return str_writer.toString();
+ }
+
+ private static void writeStringVector( PrintWriter out, Vector v ) {
+ Enumeration e = v.elements();
+ while (e.hasMoreElements()) {
+ String str = (String) e.nextElement();
+ out.print( str + " " );
+ }
+ }
+
+ /**
+ * Gets the package name.
+ */
+ public String getPackageName()
+ {
+ return null;
+ }
+
+ /**
+ * Looks a class object up.
+ *
+ * @param name the name of the fully-qualified name of
+ * the class looked for
+ */
+ public OJClass lookupClass( String name ) {
+ if (name == null) return null;
+ return (OJClass) table.get( name );
+ }
+
+ /**
+ * Records a class object.
+ *
+ * @param name the fully-qualified name of the class
+ * @param clazz the class object associated with that name
+ */
+ public void record( String name, OJClass clazz ) {
+ String str = null;
+ try {
+ str = clazz.toString();
+ } catch (Exception ex) {
+ str = "<" + ex.toString() + ">";
+ }
+ DebugOut.println("Genv#record(): " + name + " " + str);
+ table.put(name, clazz);
+ }
+
+ /**
+ * Obtains the fully-qualified name of the given class name.
+ *
+ * @param name a simple class name or a fully-qualified class name
+ * @return the fully-qualified name of the class
+ */
+ public String toQualifiedName( String name ) {
+ return name;
+ }
+
+ /**
+ * binds a name to the class type.
+ *
+ * @param name the fully-qualified name of the class
+ * @param clazz the class object associated with that name
+ */
+ public void bindVariable( String name, OJClass clazz ) {
+ System.err.println( "error : illegal binding on GlobalEnvironment" );
+ }
+
+ public OJClass lookupBind( String name ) {
+ return null;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/MOPException.java b/src/main/java/io/devnulllabs/openjava/mop/MOPException.java
new file mode 100644
index 0000000..f751498
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/MOPException.java
@@ -0,0 +1,58 @@
+/*
+ * MOPException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+
+/**
+ * MOPException is thrown if the requested introspection or intercession
+ * cannot be performed on the class, field, method or constructor object.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MOPException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class MOPException extends Exception
+{
+ private Exception ex = null;
+
+ public MOPException() {
+ }
+
+ public MOPException( Exception e ) {
+ super( e.getMessage() );
+ this.ex = e;
+ }
+
+ public MOPException( String message ) {
+ super( message );
+ }
+
+ public void printStackTrace( PrintWriter o ) {
+ if (ex != null) {
+ ex.printStackTrace( o );
+ } else {
+ super.printStackTrace( o );
+ }
+ }
+
+ public void printStackTrace( PrintStream o ) {
+ if (ex != null) {
+ ex.printStackTrace( o );
+ } else {
+ super.printStackTrace( o );
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/MetaInfo.java b/src/main/java/io/devnulllabs/openjava/mop/MetaInfo.java
new file mode 100644
index 0000000..863b400
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/MetaInfo.java
@@ -0,0 +1,172 @@
+/*
+ * MetaInfo.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+
+
+/**
+ * The class <code>MetaInfo</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MetaInfo.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class MetaInfo
+{
+
+ public static final String METACLASS_KEY = "instantiates";
+ public static final String DEFAULT_METACLASS = "openjava.mop.OJClass";
+ public static final String SUFFIX = "OJMI";
+ public static final String FIELD_NAME = "dict";
+
+ private Hashtable table = new Hashtable();
+ private String packname;
+ private String simpleclassname;
+
+ public MetaInfo( String metaclassname, String classname ) {
+ table.put( METACLASS_KEY, metaclassname );
+ this.simpleclassname = Environment.toSimpleName( classname );
+ this.packname = Environment.toPackageName( classname );
+ }
+
+ public MetaInfo(String classname) {
+ this(defaultMetaclass(classname), classname);
+ }
+
+ static String defaultMetaclass(String classname) {
+ Class mc = OJSystem.getMetabind(classname);
+ if (mc != null) return mc.getName();
+ return DEFAULT_METACLASS;
+ }
+
+ private String qualifiedClassName() {
+ if (packname == null || packname.equals( "" )) return simpleclassname;
+ return packname + "." + simpleclassname;
+ }
+
+ public MetaInfo( Class clazz ) {
+ this( clazz.getName() );
+ String minfoname = clazz.getName() + SUFFIX;
+ try {
+ Class minfo = Class.forName( minfoname );
+ Field f = minfo.getField( FIELD_NAME );
+ String[][] dict = (String[][]) f.get( null );
+ for (int i = 0; i < dict.length; ++i) {
+ table.put( dict[i][0], dict[i][1] );
+ }
+ } catch ( ClassNotFoundException e ) {
+ table.put(METACLASS_KEY, defaultMetaclass(clazz.getName()));
+ } catch ( Exception e ) {
+ System.err.println( "meta information class " + minfoname +
+ " has an illegal structure. : " + e );
+ table.put(METACLASS_KEY, defaultMetaclass(clazz.getName()));
+ }
+ }
+
+ public void write( Writer destout ) throws IOException {
+ PrintWriter out = new PrintWriter( destout );
+ out.println( "/*this file is generated by OpenJava system.*/" );
+ out.println( makePack() );
+ out.println( "public final class " + simpleclassname + SUFFIX );
+ out.println( "{" );
+ out.println( "public static final String[][] " + FIELD_NAME + "={" );
+
+ Enumeration key_i = keys();
+ Enumeration value_i = elements();
+ if (key_i.hasMoreElements()) {
+ out.print( " " );
+ printSet( out, key_i.nextElement(), value_i.nextElement() );
+ }
+ while (key_i.hasMoreElements()) {
+ out.print( "," );
+ printSet( out, key_i.nextElement(), value_i.nextElement() );
+ }
+
+ out.println( "};" );
+ out.println( "}" );
+
+ out.flush();
+ }
+
+ private String makePack() {
+ if (packname == null || packname.equals( "" )) return "";
+ return "package " + packname + ";";
+ }
+
+ private void printSet( PrintWriter out, Object keyobj, Object valueobj ) {
+ String key = (String) keyobj, value = (String) valueobj;
+ out.print( "{\"" );
+ out.print( toFlattenString( key ) );
+ out.print( "\",\"" );
+ out.print( toFlattenString( value ) );
+ out.println( "\"}" );
+ }
+
+ public String put( String key, String value ) {
+ return (String) table.put( key, value );
+ }
+
+ public String get( String key ) {
+ return (String) table.get( key );
+ }
+
+ public Enumeration keys() {
+ return table.keys();
+ }
+
+ public Enumeration elements() {
+ return table.elements();
+ }
+
+ public static String toFlattenString( String src_str ) {
+ StringBuffer result = null;
+
+ /* cancel double quotes and back slashs */
+ StringTokenizer canceller
+ = new StringTokenizer( src_str, "\\\"", true );
+ result = new StringBuffer();
+
+ while (canceller.hasMoreTokens()) {
+ String buf = canceller.nextToken();
+ if(buf.equals( "\\" ) || buf.equals( "\"" )){
+ result.append( "\\" );
+ }
+ result.append( buf );
+ }
+
+ /* remove new line chars */
+ StringTokenizer lnremover
+ = new StringTokenizer( result.toString(), "\n\r", false );
+ result = new StringBuffer();
+
+ while (lnremover.hasMoreTokens()) {
+ result.append( " " + lnremover.nextToken() );
+ }
+
+ return result.toString().trim();
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/Metaclass.java b/src/main/java/io/devnulllabs/openjava/mop/Metaclass.java
new file mode 100644
index 0000000..0be5694
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/Metaclass.java
@@ -0,0 +1,153 @@
+/*
+ * Metaclass.java
+ *
+ * It is used for some conveniences in writing metaclasses.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorInvocation;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.util.ClassLiteralReplacer;
+
+
+/**
+ * The class <code>Metaclass</code> is a metametaclass for metaclasses.
+ * You can write a metaclass easily using this class.
+ * <p>
+ * For example,
+ * <pre>
+ * public class MyClass instantiates Metaclass extends OJClass
+ * {
+ * convenient void f() {
+ * .. String.class ..;
+ * .. oldjavaclass.String.class ..;
+ * }
+ * void g() {
+ * .. String.class ..;
+ * }
+ * }
+ * </pre>
+ *
+ * <p>Here, you don't have to write constructors if your program don't
+ * concern. And class literal doesn't represent <b>java.lang.Class</b>
+ * object but <b>io.devnulllabs.openjava.mop.OJClass</b>.
+ *
+ * <p>The above code is to be translated into:
+ * <pre>
+ * public class MyClass instantiates Metaclass extends OJClass
+ * {
+ * void f() {
+ * .. io.devnulllabs.openjava.mop.OJClass.forClass( String.class ) ..;
+ * .. java.lang.String.class ..;
+ * }
+ * void g() {
+ * .. java.lang.String.class ..;
+ * }
+ * void translateDefinition() {
+ * OJClass c1 = io.devnulllabs.openjava.mop.OJClass.forClass( String.class );
+ * OJClass c2 = String.class;
+ * }
+ * public MyClass(Environment e, OJClass d, ClassDeclaration p) {
+ * super(e,d,p);
+ * }
+ * public MyClass(Class c, MetaInfo m) {
+ * super(c,m);
+ * }
+ * }
+ * </pre>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: Metaclass.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class Metaclass extends OJClass
+{
+ private static final String CONVENIENT = "convenient";
+
+ public void translateDefinition() throws MOPException {
+ /* automatic constructors */
+ OJConstructor src_constr = makeSrcConstr();
+ try {
+ getConstructor( src_constr.getParameterTypes() );
+ } catch ( NoSuchMemberException e ) {
+ addConstructor( src_constr );
+ }
+ OJConstructor byte_constr = makeByteConstr();
+ try {
+ getConstructor( byte_constr.getParameterTypes() );
+ } catch ( NoSuchMemberException e ) {
+ addConstructor( byte_constr );
+ }
+
+ /* class literal */
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( CONVENIENT )) continue;
+ try {
+ ClassLiteralReplacer rep
+ = new ClassLiteralReplacer( methods[i].getEnvironment() );
+ methods[i].getBody().accept( rep );
+ } catch ( ParseTreeException e ) {
+ System.err.println( e );
+ }
+ }
+ }
+
+ public static final boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( CONVENIENT )) return true;
+ return OJClass.isRegisteredModifier( keyword );
+ }
+
+ private OJConstructor makeSrcConstr() throws MOPException {
+ OJModifier modif = OJModifier.forModifier( OJModifier.PUBLIC );
+ OJClass[] paramtypes
+ = new OJClass[] {
+ OJClass.forClass( Environment . class ),
+ OJClass.forClass( OJClass . class ),
+ OJClass.forClass( ClassDeclaration . class ) };
+ OJConstructor result
+ = new OJConstructor( this, modif, paramtypes, null,
+ null, new StatementList() );
+ ConstructorInvocation ci
+ = new ConstructorInvocation( result.getParameterVariables(),
+ null );
+ result.setTransference( ci );
+ return result;
+ }
+
+ private OJConstructor makeByteConstr() throws MOPException {
+ OJModifier modif = OJModifier.forModifier( OJModifier.PUBLIC );
+ OJClass[] paramtypes
+ = new OJClass[] {
+ OJClass.forClass( Class . class ),
+ OJClass.forClass( MetaInfo . class ) };
+ OJConstructor result
+ = new OJConstructor( this, modif, paramtypes, null,
+ null, new StatementList() );
+ ConstructorInvocation ci
+ = new ConstructorInvocation( result.getParameterVariables(),
+ null );
+ result.setTransference( ci );
+ return result;
+ }
+
+ public Metaclass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree ) {
+ super( outer_env, declarer, ptree );
+ }
+
+ public Metaclass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/NoSuchMemberException.java b/src/main/java/io/devnulllabs/openjava/mop/NoSuchMemberException.java
new file mode 100644
index 0000000..cc79dcb
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/NoSuchMemberException.java
@@ -0,0 +1,34 @@
+/*
+ * NoSuchMemberException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+/**
+ * The exception <code>NoSuchMemberException</code> is thrown
+ * when the requested class object does not have the coressponding
+ * member.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: NoSuchMemberException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class NoSuchMemberException extends MOPException {
+ public NoSuchMemberException() {
+ super();
+ }
+
+ public NoSuchMemberException(Exception e) {
+ super(e);
+ }
+
+ public NoSuchMemberException(String access) {
+ super(access);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJClass.java b/src/main/java/io/devnulllabs/openjava/mop/OJClass.java
new file mode 100644
index 0000000..673e73e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJClass.java
@@ -0,0 +1,3071 @@
+/*
+ * OJClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayAccess;
+import io.devnulllabs.openjava.ptree.ArrayAllocationExpression;
+import io.devnulllabs.openjava.ptree.AssignmentExpression;
+import io.devnulllabs.openjava.ptree.CastExpression;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.MemberInitializer;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.ptree.util.PartialParser;
+import io.devnulllabs.openjava.ptree.util.TypeNameQualifier;
+import io.devnulllabs.openjava.syntax.SyntaxRule;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The <code>OJClass</code> class represents a class metaobject. If
+ * the class has its valid .class file in CLASSPATH, the metaobject can
+ * behave like <code>java.lang.Class</code>. If the class has its
+ * valid .oj file in the packages where some classes are being compiled
+ * by OpenJava system, or in the packages explicitly specified by
+ * something like OpenJava compiler option or environment variable, the
+ * metaobject can have information about source code just as
+ * stamements, expressions, and etc.
+ * <p>
+ * Additionaly, you can overrides the methods for introspection.
+ * <pre>
+ * OJClass[] getDeclaredClasses()
+ * OJMethod[] getDeclaredMethods()
+ * OJField[] getDeclaredFields()
+ * OJConstructor[] getDeclaredConstructors()
+ * OJMethod getAcceptableMethod(OJClass,String,OJClass[])
+ * OJMethod getAcceptableConstructor(OJClass,String,OJClass[])
+ * </pre>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: OJClass.java,v 1.3 2005/04/04 08:27:49 tatsubori Exp $
+ * @see java.lang.Class
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ * @see io.devnulllabs.openjava.mop.OJField
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ *
+ **/
+public class OJClass implements OJMember {
+
+ private OJClassImp substance;
+
+ /* -- constructors -- */
+
+ /**
+ * Generates a metaobject from source code.
+ * <p>
+ * This constructor will be invoked by the OpenJava system.
+ * In inheriting this class, you must call this consturctor
+ * from a constructor with the same signature in your class.
+ * <p>
+ * For example, in defining a subclass <code>YourClass</code>
+ * derived from this class, at least you have to write as follows:
+ * <pre>
+ * public YourClass( Environment outer_env, OJClass declarer,
+ * ClassDeclaration ptree ) {
+ * super( outer_env, declarer, ptree );
+ * }
+ * </pre>
+ *
+ * @param outer_env environment of this class metaobject
+ * @param declarer the class metaobject declaring this
+ * class metaobject.
+ * @param ptree the parse tree representing this class metaobject.
+ */
+ public OJClass(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ substance = new OJClassSourceCode(this, outer_env, declarer, ptree);
+ }
+
+ /**
+ * Generates a metaobject from byte code.
+ * <p>
+ * This constructor will be invoked only by the OpenJava system.
+ * In inheriting this class, you must call this consturctor
+ * from a constructor with the same signature in your class.
+ * <p>
+ * For example, in defining a subclass <code>YourClass</code>
+ * derived from this class, at least you have to write as follows:
+ * <pre>
+ * public YourClass( Class java_class, MetaInfo metainfo ) {
+ * super( java_class, metainfo );
+ * }
+ * </pre>
+ *
+ * @param outer_env environment of this class metaobject
+ * @param declarer the class metaobject declaring this
+ * class metaobject.
+ * @param ptree the parse tree representing this class metaobject.
+ */
+ public OJClass(Class java_class, MetaInfo metainfo) {
+ substance = new OJClassByteCode(java_class, metainfo);
+ }
+
+ /**
+ * For arrays
+ */
+ private OJClass(OJClass componentType) {
+ substance = new OJClassArray(componentType);
+ }
+
+ /**
+ * For dummy type of null object.
+ * This should be called only once by OJSystem.initConstants().
+ */
+ OJClass() {
+ substance = new OJClassNull();
+ }
+
+ /* -- Introspection Part -- */
+
+ /**
+ * Returns the <code>OJClass</code> object associated with the class
+ * with the given string name.
+ * Given the fully-qualified name for a class or interface, this
+ * method attempts to locate, load and link the class. If it
+ * succeeds, returns the Class object representing the class. If
+ * it fails, the method throws a OJClassNotFoundException.
+ * <p>
+ * For example, the following code fragment returns the runtime
+ * <code>OJClass</code> descriptor for the class named
+ * <code>java.lang.Thread</code>:
+ * <ul><code>
+ * OJClass t = OJClass.forName( "java.lang.Thread" );
+ * </code></ul>
+ *
+ * @param name the fully qualified name of the desired
+ * class.
+ * @return the <code>OJClass</code> descriptor for the class with
+ * the specified name.
+ * @exception OJClassNotFoundException if the class could not be
+ * found.
+ */
+ public static OJClass forName(String name)
+ throws OJClassNotFoundException {
+ DebugOut.println("OJClass.forName(\"" + name.toString() + "\")");
+
+ name = nameForJavaClassName(name);
+
+ OJClass result;
+
+ result = OJSystem.env.lookupClass(name);
+ if (result != null)
+ return result;
+
+ if (isArrayName(name)) {
+ OJClass component = forName(stripBrackets(name));
+ result = new OJClass(component);
+ OJSystem.env.record(name, result);
+ return result;
+ }
+
+ result = lookupFromByteCode(nameToJavaClassName(name));
+ if (result != null) {
+ OJSystem.env.record(name, result);
+ return result;
+ }
+
+ throw new OJClassNotFoundException(name);
+ }
+
+ private static final OJClass lookupFromByteCode(String name) {
+ OJClass result = null;
+ try {
+ Class javaClass = Class.forName(name);
+ result = forClass(javaClass);
+ if (result != null) {
+ OJSystem.env.record(name, result);
+ return result;
+ }
+ } catch (ClassNotFoundException e) {
+ int dot = name.lastIndexOf('.');
+ if (dot == -1)
+ return null;
+ String innername = replaceDotWithDoller(name, dot);
+ result = lookupFromByteCode(innername);
+ }
+ return result;
+ }
+
+ private static final String replaceDotWithDoller(String base, int i) {
+ return base.substring(0, i) + '$' + base.substring(i + 1);
+ }
+
+ private static final boolean isArrayName(String name) {
+ return (name.startsWith("[") || name.endsWith("[]"));
+ }
+
+ private static final String stripBrackets(String ojcname) {
+ return ojcname.substring(0, ojcname.length() - 2);
+ }
+
+ private static final String nameForJavaClassName(String jcname) {
+ return Toolbox.nameForJavaClassName(jcname);
+ }
+
+ private static final String nameToJavaClassName(String ojcname) {
+ return Toolbox.nameToJavaClassName(ojcname);
+ }
+
+ static OJClass[] arrayForClasses(Class[] jclasses) {
+ OJClass[] result = new OJClass[jclasses.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = forClass(jclasses[i]);
+ }
+ return result;
+ }
+
+ static Class[] toClasses(OJClass[] classes) {
+ Class[] result = new Class[classes.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = classes[i].getCompatibleJavaClass();
+ }
+ return result;
+ }
+
+ /**
+ * Converts a <code>OJClass</code> object to an <code>OJClass</code>
+ * object.
+ * <p>
+ * This method returns the same <code>OJClass</code> object
+ * whenever it is invoked for the same <code>Class</code>object.
+ * It gurantees one-to-one correspondence between <code>Class</code>
+ * and <code>OJClass</code>.
+ *
+ * @param javaClass Java Class to translate into OJClass
+ * @return OJClass of given Java class
+ */
+ public static OJClass forClass(Class javaClass) {
+ if (javaClass == null)
+ return null;
+
+ String name = nameForJavaClassName(javaClass.getName());
+
+ OJClass result = OJSystem.env.lookupClass(name);
+ if (result != null)
+ return result;
+
+ if (isArrayName(name)) {
+ try {
+ OJClass component = forName(stripBrackets(name));
+ result = new OJClass(component);
+ OJSystem.env.record(name, result);
+ return result;
+ } catch (Exception e) {
+ System.err.println("OJClass.forClass(" + name + ") : " + e);
+ /* continue as a non array */
+ }
+ }
+
+ result = lookupFromMetaInfo(javaClass);
+ OJSystem.env.record(name, result);
+
+ return result;
+ }
+
+ private static final OJClass lookupFromMetaInfo(Class javaClass) {
+ MetaInfo metainfo = new MetaInfo(javaClass);
+ String mcname = metainfo.get("instantiates");
+ DebugOut.println(javaClass + " is an instance of " + mcname);
+ try {
+ Class metaclazz = Class.forName(mcname);
+ Class[] paramtypes = new Class[] { Class.class, MetaInfo.class };
+ Constructor constr = metaclazz.getConstructor(paramtypes);
+ Object[] args = new Object[] { javaClass, metainfo };
+ return (OJClass) constr.newInstance(args);
+ } catch (ClassNotFoundException e) {
+ System.err.println(
+ "metaclass "
+ + mcname
+ + " for "
+ + javaClass
+ + " not found."
+ + " substituted by default metaclass.");
+ metainfo = new MetaInfo(javaClass.getName());
+ return new OJClass(javaClass, metainfo);
+ } catch (Exception e) {
+ System.err.println(
+ "metaclass "
+ + mcname
+ + " doesn't provide"
+ + " proper constructor for bytecode."
+ + " substituted by default metaclass. : "
+ + e);
+ metainfo = new MetaInfo(javaClass.getName());
+ return new OJClass(javaClass, metainfo);
+ }
+ }
+
+ /**
+ * Converts <code>ParseTree</code> objects to an <code>OJClass</code>
+ * object. The generated <code>OJClass</code> object is to be
+ * registered as globally asscessible class but not to appear as
+ * generated source code.
+ * <p>
+ *
+ * @param env Environment object
+ * @param declaringClass OJClass
+ * @param ptree Parse Tree for declaringClass
+ * @return OJClass
+ * @throws AmbiguousClassesException If there is already an
+ * OJClass, throws AmbiguousClassesException
+ * @throws ClassNotFoundException If not class is found
+ */
+ public static OJClass forParseTree(
+ Environment env,
+ OJClass declaringClass,
+ ClassDeclaration ptree)
+ throws AmbiguousClassesException, ClassNotFoundException {
+ String qname;
+ if (declaringClass == null) {
+ qname = env.toQualifiedName(ptree.getName());
+ } else {
+ qname = env.currentClassName() + "." + ptree.getName();
+ }
+
+ Class metaclazz = null;
+ if (ptree.getMetaclass() != null) {
+ String mcname = env.toQualifiedName(ptree.getMetaclass());
+ metaclazz = Class.forName(mcname);
+ } else {
+ metaclazz = OJSystem.getMetabind(qname);
+ }
+
+ OJClass result;
+ try {
+ Constructor constr =
+ metaclazz.getConstructor(
+ new Class[] {
+ Environment.class,
+ OJClass.class,
+ ClassDeclaration.class });
+ Object[] args = new Object[] { env, declaringClass, ptree };
+ result = (OJClass) constr.newInstance(args);
+ } catch (NoSuchMethodException ex) {
+ System.err.println(
+ "errors during gererating a metaobject for "
+ + ptree.getName()
+ + " : "
+ + ex);
+ result = new OJClass(env, declaringClass, ptree);
+ } catch (InvocationTargetException ex) {
+ System.err.println(
+ "errors during gererating a metaobject for "
+ + ptree.getName()
+ + " : "
+ + ex.getTargetException());
+ ex.printStackTrace();
+ result = new OJClass(env, declaringClass, ptree);
+ } catch (Exception ex) {
+ System.err.println(
+ "errors during gererating a metaobject for "
+ + ptree.getName()
+ + " : "
+ + ex);
+ result = new OJClass(env, declaringClass, ptree);
+ }
+
+ OJClass existing = OJSystem.env.lookupClass(qname);
+
+ if (existing != null) {
+ throw new AmbiguousClassesException(qname);
+ }
+
+ OJSystem.env.record(qname, result);
+ return result;
+ }
+
+ /**
+ * Generates a expression parse tree from a given
+ * <code>String</code> object under the given environment.
+ *
+ * @param env an environment for the source code.
+ * @param str a fragment of source code representing an expression.
+ * @return an expression parse tree
+ * @throws MOPException Introspection cannot be performed
+ */
+ protected static final Expression makeExpression(
+ Environment env,
+ String str)
+ throws MOPException {
+ return PartialParser.makeExpression(env, str);
+ }
+
+ /**
+ * Generates an expression parse tree from a given
+ * <code>String</code> object under the environment of
+ * this class object.
+ *
+ * @param str a fragment of source code representing an expression.
+ * @return an expression parse tree
+ * @throws MOPException Introspection cannot be performed
+ */
+ protected final Expression makeExpression(String str) throws MOPException {
+ return makeExpression(getEnvironment(), str);
+ }
+
+ /**
+ * Generates a statement parse tree from a given
+ * <code>String</code> object under the given environment.
+ *
+ * @param env an environment for the source code.
+ * @param str a fragment of source code representing a statement.
+ * @return a statement parse tree
+ * @throws MOPException Introspection cannot be performed
+ */
+ protected static final Statement makeStatement(Environment env, String str)
+ throws MOPException {
+ return PartialParser.makeStatement(env, str);
+ }
+
+ /**
+ * Generates a statement parse tree from a given
+ * <code>String</code> object under the environment of
+ * this class object.
+ *
+ * @param str a fragment of source code representing a statement.
+ * @return a statement parse tree
+ * @throws MOPException Introspection cannot be performed
+ */
+ protected final Statement makeStatement(String str) throws MOPException {
+ return makeStatement(getEnvironment(), str);
+ }
+
+ /**
+ * Generates a statement list parse tree from a given
+ * <code>String</code> object under the given environment.
+ *
+ * @param env an environment for the source code.
+ * @param str a fragment of source code representing a statement list.
+ * @return a statement list parse tree
+ * @throws MOPException Introspection cannot be performed
+ */
+ protected static final StatementList makeStatementList(
+ Environment env,
+ String str)
+ throws MOPException {
+ return PartialParser.makeStatementList(env, str);
+ }
+
+ /**
+ * Generates a statement list parse tree from a given
+ * <code>String</code> object under the environment of
+ * this class object.
+ *
+ * @param str a fragment of source code representing a statement list.
+ * @return a statement list parse tree
+ * @throws MOPException Introspection cannot be performed
+ */
+ protected final StatementList makeStatementList(String str)
+ throws MOPException {
+ return makeStatementList(getEnvironment(), str);
+ }
+
+ /**
+ * Converts the object to a string. The string representation is
+ * the string "class" or "interface", followed by a space, and then
+ * by the fully qualified name of the class in the format returned
+ * by <code>getName</code>. If this <code>OJClass</code> object
+ * represents a primitive type, this method returns the name of the
+ * primitive type. If this <code>OJClass</code> object represents
+ * void this method returns "void".
+ *
+ * @return a string representation of this class object.
+ */
+ public String toString() {
+ return substance.toString();
+ }
+
+ /**
+ * Obtains an environment of this class object.
+ * This environment has information about members and outr
+ * environments such as packages but not local information like
+ * local variable in methods of this class.
+ *
+ * @return an environment of this class object.
+ */
+ public Environment getEnvironment() {
+ return substance.getEnvironment();
+ }
+
+ /**
+ * Determines if the class or interface represented by this
+ * <code>OJClass</code> object is either the same as, or is a
+ * superclass or superinterface of, the class or interface
+ * represented by the specified <code>OJClass</code> parameter. It
+ * returns <code>true</code> if so; otherwise it returns
+ * <code>false</code>. If this <code>OJClass</code> object
+ * represents a primitive type, this method returns
+ * <code>true</code> if the type represented by this
+ * <code>OJClass</code> object can accept the type represented by
+ * the specified <code>OJClass</code> parameter; otherwise it
+ * returns <code>false</code>.
+ *
+ * <p> Specifically, this method tests whether the type
+ * represented by the specified <code>OJClass</code> parameter can
+ * be converted to the type represented by this
+ * <code>OJClass</code> object via an identity conversion or via a
+ * widening reference/primitive conversion. <p> The behavior
+ * about primitive types is different from the method of the same
+ * name of <code>java.lang.Class</code>.
+ *
+ * @param clazz Class to test
+ * @exception NullPointerException if the specified class
+ * parameter is null.
+ * @return Result of test
+ */
+ public boolean isAssignableFrom(OJClass clazz) {
+ if (clazz.toString() == OJSystem.NULLTYPE_NAME)
+ return true;
+ if (clazz == this) {
+ /* if it is exactly the same type */
+ return true;
+ }
+ if (this.isPrimitive()) {
+ /* the java.lang.Class's returns always false */
+ if (!clazz.isPrimitive())
+ return false;
+ if (clazz == OJSystem.CHAR) {
+ return (
+ primitiveTypeWidth(this)
+ > primitiveTypeWidth(OJSystem.SHORT));
+ }
+ if (primitiveTypeWidth(this) > primitiveTypeWidth(OJSystem.VOID)) {
+ return (primitiveTypeWidth(this) > primitiveTypeWidth(clazz));
+ }
+ return false;
+ } else {
+ if (clazz.isPrimitive())
+ return false;
+ }
+ /* now class is a reference type */
+ if (this == OJSystem.OBJECT)
+ return true;
+ if (this.isArray()) {
+ if (!clazz.isArray())
+ return false;
+ OJClass comp = this.getComponentType();
+ return comp.isAssignableFrom(clazz.getComponentType());
+ } else {
+ if (clazz.isArray())
+ return false;
+ }
+ /* getInterfaces() returns only the declared intefaces
+ * So the interfaces of the superclasses should be checked.
+ */
+ if (this.isInterface()) {
+ /* for an assigning class which is either interface or class */
+ OJClass[] faces = clazz.getInterfaces();
+ for (int i = 0; i < faces.length; ++i) {
+ if (isAssignableFrom(faces[i]))
+ return true;
+ }
+ }
+ /* now this is a class */
+ if (clazz.isInterface())
+ return false;
+ OJClass base = clazz.getSuperclass();
+ return (base == null) ? false : isAssignableFrom(base);
+ }
+
+ private static int primitiveTypeWidth(OJClass ptype) {
+ if (ptype == OJSystem.BYTE)
+ return 1;
+ if (ptype == OJSystem.SHORT)
+ return 2;
+ if (ptype == OJSystem.INT)
+ return 3;
+ if (ptype == OJSystem.LONG)
+ return 4;
+ if (ptype == OJSystem.FLOAT)
+ return 5;
+ if (ptype == OJSystem.DOUBLE)
+ return 5;
+ return -1;
+ }
+
+ /**
+ * Determines if the specified <code>OJClass</code> object represents
+ * an interface type.
+ *
+ * @return <code>true</code> if this object represents an interface;
+ * <code>false</code> otherwise.
+ */
+ public boolean isInterface() {
+ return substance.isInterface();
+ }
+
+ /**
+ * Determines if this <code>OJClass</code> object represents an
+ * array class.
+ *
+ * @return <code>true</code> if this object represents an array class;
+ * <code>false</code> otherwise.
+ */
+ public boolean isArray() {
+ return substance.isArray();
+ }
+
+ /**
+ * Determines if the specified <code>OJClass</code> object represents a
+ * primitive type.
+ *
+ * <p> There are nine predefined <code>OJClass</code> objects to represent
+ * the eight primitive types and void. These are created by the Java
+ * Virtual Machine, and have the same names as the primitive types that
+ * they represent, namely <code>boolean</code>, <code>byte</code>,
+ * <code>char</code>, <code>short</code>, <code>int</code>,
+ * <code>long</code>, <code>float</code>, and <code>double</code>.
+ *
+ * <p> These objects may be accessed via the following public static
+ * final variables, and are the only <code>OJClass</code> objects for
+ * which this method returns <code>true</code>.
+ *
+ * @see io.devnulllabs.openjava.mop.OJSystem#BOOLEAN
+ * @see io.devnulllabs.openjava.mop.OJSystem#CHAR
+ * @see io.devnulllabs.openjava.mop.OJSystem#BYTE
+ * @see io.devnulllabs.openjava.mop.OJSystem#SHORT
+ * @see io.devnulllabs.openjava.mop.OJSystem#INT
+ * @see io.devnulllabs.openjava.mop.OJSystem#LONG
+ * @see io.devnulllabs.openjava.mop.OJSystem#FLOAT
+ * @see io.devnulllabs.openjava.mop.OJSystem#DOUBLE
+ * @see io.devnulllabs.openjava.mop.OJSystem#VOID
+ *
+ * @return <code>true</code> if this object represents a primitive type;
+ * <code>false</code> otherwise.
+ */
+ public boolean isPrimitive() {
+ return substance.isPrimitive();
+ }
+
+ /**
+ * Determines if the specified <code>OJClass</code> object represents a
+ * wrapper class for a primitive type.
+ *
+ * @return <code>true</code> if this object represents a wrapper class
+ * for a primitive type; <code>false</code> otherwise.
+ */
+ public boolean isPrimitiveWrapper() {
+ return (this != unwrappedPrimitive());
+ }
+
+ /**
+ * Obtains the wrapper class if this class represents a primitive
+ * type.
+ * <p>
+ * For example this method returns java.lang.Integer for int.
+ *
+ * @return The wrapper class for this primitive type.
+ * <code>null</code> for void.
+ */
+ public OJClass primitiveWrapper() {
+ if (this == OJSystem.VOID)
+ return null;
+ if (this == OJSystem.BOOLEAN)
+ return OJClass.forClass(java.lang.Boolean.class);
+ if (this == OJSystem.BYTE)
+ return OJClass.forClass(java.lang.Byte.class);
+ if (this == OJSystem.CHAR)
+ return OJClass.forClass(java.lang.Character.class);
+ if (this == OJSystem.SHORT)
+ return OJClass.forClass(java.lang.Short.class);
+ if (this == OJSystem.INT)
+ return OJClass.forClass(java.lang.Integer.class);
+ if (this == OJSystem.LONG)
+ return OJClass.forClass(java.lang.Long.class);
+ if (this == OJSystem.FLOAT)
+ return OJClass.forClass(java.lang.Float.class);
+ if (this == OJSystem.DOUBLE)
+ return OJClass.forClass(java.lang.Double.class);
+ //otherwise returns as is
+ return this;
+ }
+
+ /**
+ * Obtains the real type class if this class represents a primitive
+ * wrapper type.
+ * <p>
+ * For example this method returns int for java.lang.Integer.
+ *
+ * @return The real primitive type for this primitive wrapper class.
+ */
+ public OJClass unwrappedPrimitive() {
+ if (this == OJClass.forClass(java.lang.Boolean.class))
+ return OJSystem.BOOLEAN;
+ if (this == OJClass.forClass(java.lang.Byte.class))
+ return OJSystem.BYTE;
+ if (this == OJClass.forClass(java.lang.Character.class))
+ return OJSystem.CHAR;
+ if (this == OJClass.forClass(java.lang.Short.class))
+ return OJSystem.SHORT;
+ if (this == OJClass.forClass(java.lang.Integer.class))
+ return OJSystem.INT;
+ if (this == OJClass.forClass(java.lang.Long.class))
+ return OJSystem.LONG;
+ if (this == OJClass.forClass(java.lang.Float.class))
+ return OJSystem.FLOAT;
+ if (this == OJClass.forClass(java.lang.Double.class))
+ return OJSystem.DOUBLE;
+ //otherwise returns as is
+ return this;
+ }
+
+ /**
+ * Returns the fully-qualified name of the entity (class,
+ * interface, array class, primitive type, or void) represented by
+ * this <code>OJClass</code> object, as a <code>String</code>.
+ *
+ * <p> If this <code>OJClass</code> object represents a class of
+ * arrays, then the internal form of the name consists of the name
+ * of the element type in Java signature format, followed by one
+ * or more "<tt>[]</tt>" characters representing the depth of array
+ * nesting. This representation differs from that of
+ * <code>java.lang.Class.forName()</code>. Thus:
+ *
+ * <blockquote><pre>
+ * OJClass.forClass( (new int[3][4]).getClass() ).getName()
+ * </pre></blockquote>
+ *
+ * returns "<code>java.lang.Object[]</code>" and:
+ *
+ * <blockquote><pre>
+ * OJClass.forClass( (new int[3][4]).getClass() ).getName()
+ * </pre></blockquote>
+ *
+ * returns "<code>int[][]</code>".
+ *
+ * <p> The class or interface name <tt><i>classname</i></tt> is
+ * given in fully qualified form as shown in the example above.
+ *
+ * @return the fully qualified name of the class or interface
+ * represented by this object.
+ */
+ public String getName() {
+ return substance.getName();
+ }
+
+ /**
+ * Returns the simple name of the class, interface or array class
+ * represented by this <code>OJClass</code> object, as a
+ * <code>String</code>. Thus:
+ *
+ * <blockquote><pre>
+ * OJClass.forClass( (new Object[3]).getClass() ).getName()
+ * </pre></blockquote>
+ *
+ * returns "<code>Object</code>".
+ *
+ * @return the simple name of the class or interface
+ * represented by this object.
+ */
+ public String getSimpleName() {
+ return Environment.toSimpleName(getName());
+ }
+
+ /**
+ * Gets the package name for this class as a <code>String</code>.
+ * Null is returned if its package was not specified in source code of
+ * this class.
+ *
+ * @return the package name of the class, or null if its package
+ * was not specified in source code.
+ */
+ public String getPackage() {
+ int last = getName().lastIndexOf('.');
+ if (last == -1)
+ return null;
+ return getName().substring(0, last);
+ }
+
+ /**
+ * Determines if the specified class object is in the same package
+ * as this class object.
+ *
+ * <p>If null is given, this method returns alway false.
+ *
+ * @param c the class object to test against this class object.
+ * @return true in case that both class is is the sample package.
+ */
+ public boolean isInSamePackage(OJClass c) {
+ if (c == null)
+ return false;
+ String pack = c.getPackage();
+ if (pack == null)
+ return (getPackage() == null);
+ return pack.equals(getPackage());
+ }
+
+ /**
+ * Returns the <code>OJClass</code> representing the superclass of
+ * the entity (class, interface, primitive type or void)
+ * represented by this <code>OJClass</code>. If this
+ * <code>OJClass</code> represents either the
+ * <code>java.lang.Object</code> class, an interface, a primitive
+ * type, or void, then null is returned. If this object
+ * represents an array class then the <code>OJClass</code> object
+ * representing the <code>java.lang.Object</code> class is
+ * returned.
+ *
+ * @return the superclass of the class represented by this object.
+ */
+ public OJClass getSuperclass() {
+ return substance.getSuperclass();
+ }
+
+ /**
+ * Determines the interfaces implemented by the class or interface
+ * represented by this object.
+ *
+ * <p> If this object represents a class, the return value is an array
+ * containing objects representing all interfaces implemented by the
+ * class. The order of the interface objects in the array corresponds to
+ * the order of the interface names in the <code>implements</code> clause
+ * of the declaration of the class represented by this object. For
+ * example, given the declaration:
+ * <blockquote><pre>
+ * class Shimmer implements FloorWax, DessertTopping { ... }
+ * </pre></blockquote>
+ * suppose the value of <code>clazz</code> is an class object for
+ * the class <code>Shimmer</code>; the value of the expression:
+ * <blockquote><pre>
+ * clazz.getInterfaces()[0]
+ * </pre></blockquote>
+ * is the <code>OJClass</code> object that represents interface
+ * <code>FloorWax</code>; and the value of:
+ * <blockquote><pre>
+ * clazz.getInterfaces()[1]
+ * </pre></blockquote>
+ * is the <code>OJClass</code> object that represents interface
+ * <code>DessertTopping</code>.
+ *
+ * <p> If this object represents an interface, the array contains
+ * objects representing all interfaces extended by the
+ * interface. The order of the interface objects in the array
+ * corresponds to the order of the interface names in the
+ * <code>extends</code> clause of the declaration of the interface
+ * represented by this object.</p>
+ *
+ * <p> If this object represents a class or interface that
+ * implements no interfaces, the method returns an array of length
+ * 0.</p>
+ *
+ * <p> If this object represents a primitive type or void, the
+ * method returns an array of length 0.</p>
+ *
+ * To be <code>getDeclaredInterfaces()<code>.
+ *
+ * @return an array of interfaces implemented by this class object.
+ */
+ public OJClass[] getInterfaces() {
+ return substance.getInterfaces();
+ }
+
+ /**
+ * Returns the <code>OJClass</code> representing the component type of an
+ * array. If this class does not represent an array class this method
+ * returns null.
+ *
+ * @return the class object representing the type of component of this
+ * array.
+ */
+ public OJClass getComponentType() {
+ return substance.getComponentType();
+ }
+
+ /**
+ * Returns the Java language modifiers and the user defined modifiers
+ * for this class or interface, as a <code>OJModifier</code> object.
+ *
+ * <p> If the underlying class is an array class, then its
+ * <code>public</code>, <code>private</code> and <code>protected</code>
+ * modifiers are the same as those of its component type. If this
+ * <code>OJClass</code> represents a primitive type or void, its
+ * <code>public</code> modifier is always <code>true</code>, and its
+ * <code>protected</code> and <code>private</code> modifers are always
+ * <code>false</code>. If this object represents an array class, a
+ * primitive type or void, then its <code>final</code> modifier is always
+ * <code>true</code> and its interface modifer is always
+ * <code>false</code>. The values of its other modifiers are not determined
+ * by this specification.
+ *
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ *
+ * @return the OJModifier object representing the modifiers of this class
+ * object
+ */
+ public OJModifier getModifiers() {
+ return substance.getModifiers();
+ }
+
+ /**
+ * Obtains an parse tree of suffix in extended syntax starting
+ * with the specified keyword. Returned
+ * <code>io.devnulllabs.openjava.ptree.ParseTree</code> object has a structure
+ * built by an <code>io.devnulllabs.openjava.syntax.SyntaxRule</code> object
+ * returned via the method <code>getDeclSuffixRule(String)</code>.
+ *
+ * @see io.devnulllabs.openjava.mop.OJClass#getDeclSuffixRule(String)
+ * @see io.devnulllabs.openjava.syntax.SyntaxRule
+ *
+ * @return the parse tree
+ */
+ public ParseTree getSuffix(String keyword) {
+ return substance.getSuffix(keyword);
+ }
+
+ /**
+ * If the class or interface represented by this
+ * <code>OJClass</code> object is a member of another class,
+ * returns the <code>OJClass</code> object representing the class
+ * in which it was declared. This method returns null if this
+ * class or interface is not a member of any other class. If this
+ * <code>OJClass</code> object represents an array class, a
+ * primitive type, or void, then this method returns null.
+ *
+ * @return the class object declaring this class object.
+ */
+ public OJClass getDeclaringClass() {
+ return substance.getDeclaringClass();
+ }
+
+ public final OJClass[] getAllClasses() {
+ return overridesOn(getDeclaredClasses(), getInheritedClasses());
+ }
+
+ public final OJField[] getAllFields() {
+ return overridesOn(getDeclaredFields(), getInheritedFields());
+ }
+
+ public final OJMethod[] getAllMethods() {
+ return overridesOn(getDeclaredMethods(), getInheritedMethods());
+ }
+
+ public OJClass[] getInheritedClasses() {
+ OJClass base = getSuperclass();
+ if (base == null) {
+ return new OJClass[0];
+ } else {
+ return base.getInheritableClasses(this);
+ }
+ }
+
+ public OJField[] getInheritedFields() {
+ OJClass base = getSuperclass();
+ OJField[] base_f;
+ if (base == null) {
+ base_f = new OJField[0];
+ } else {
+ base_f = base.getInheritableFields(this);
+ }
+ int len = base_f.length;
+ OJClass[] faces = getInterfaces();
+ OJField[][] face_fs = new OJField[faces.length][];
+ for (int i = 0; i < faces.length; ++i) {
+ face_fs[i] = faces[i].getInheritableFields(this);
+ len += face_fs[i].length;
+ }
+ OJField[] result = new OJField[len];
+ int count = 0;
+ for (int i = 0; i < faces.length; ++i) {
+ System.arraycopy(face_fs[i], 0, result, count, face_fs[i].length);
+ count += face_fs[i].length;
+ }
+ System.arraycopy(base_f, 0, result, count, base_f.length);
+ return result;
+ }
+
+ public final OJMethod[] getInheritedMethods() {
+ OJClass base = getSuperclass();
+ OJMethod[] base_m;
+ if (base == null) {
+ base_m = new OJMethod[0];
+ } else {
+ base_m = base.getInheritableMethods(this);
+ }
+ int len = base_m.length;
+ OJClass[] faces = getInterfaces();
+ OJMethod[][] face_ms = new OJMethod[faces.length][];
+ for (int i = 0; i < faces.length; ++i) {
+ face_ms[i] = faces[i].getInheritableMethods(this);
+ len += face_ms[i].length;
+ }
+ OJMethod[] result = new OJMethod[len];
+ int count = 0;
+ for (int i = 0; i < faces.length; ++i) {
+ System.arraycopy(face_ms[i], 0, result, count, face_ms[i].length);
+ count += face_ms[i].length;
+ }
+ System.arraycopy(base_m, 0, result, count, base_m.length);
+ return result;
+ }
+
+ /**
+ * Use <code>getInheritableClasses(OJClass)</code>
+ * @deprecated
+ * @see getInheritableClasses(OJClass)
+ */
+ public final OJClass[] getInheritableClasses() {
+ OJClass[] nonprivates = removeThePrivates(getAllClasses());
+ return removeTheDefaults(nonprivates);
+ }
+
+ /**
+ * Use <code>getInheritableFields(OJClass)</code>
+ * @deprecated
+ * @see getInheritableFields(OJClass)
+ */
+ public final OJField[] getInheritableFields() {
+ OJField[] nonprivates = removeThePrivates(getAllFields());
+ return removeTheDefaults(nonprivates);
+ }
+
+ /**
+ * Use <code>getInheritableMethods(OJClass)</code>
+ * @deprecated
+ * @see getInheritableMethodss(OJClass)
+ */
+ public final OJMethod[] getInheritableMethods() {
+ OJMethod[] nonprivates = removeThePrivates(getAllMethods());
+ return removeTheDefaults(nonprivates);
+ }
+
+ public OJClass[] getInheritableClasses(OJClass situation) {
+ OJClass[] result = removeThePrivates(getAllClasses());
+ if (isInSamePackage(situation))
+ return result;
+ return removeTheDefaults(result);
+ }
+
+ public OJField[] getInheritableFields(OJClass situation) {
+ OJField[] result = removeThePrivates(getAllFields());
+ if (isInSamePackage(situation))
+ return result;
+ return removeTheDefaults(result);
+ }
+
+ public OJMethod[] getInheritableMethods(OJClass situation) {
+ OJMethod[] result = removeThePrivates(getAllMethods());
+ if (isInSamePackage(situation))
+ return result;
+ return removeTheDefaults(result);
+ }
+
+ public OJConstructor[] getInheritableConstructors(OJClass situation) {
+ OJConstructor[] result = removeThePrivates(getDeclaredConstructors());
+ if (isInSamePackage(situation))
+ return result;
+ return removeTheDefaults(result);
+ }
+
+ private static final OJClass[] overridesOn(
+ OJClass[] declareds,
+ OJClass[] bases) {
+ return Toolbox.overridesOn(declareds, bases);
+ }
+
+ private static final OJField[] overridesOn(
+ OJField[] declareds,
+ OJField[] bases) {
+ return Toolbox.overridesOn(declareds, bases);
+ }
+
+ private static final OJMethod[] overridesOn(
+ OJMethod[] declareds,
+ OJMethod[] bases) {
+ return Toolbox.overridesOn(declareds, bases);
+ }
+
+ private static final OJClass[] removeThePrivates(OJClass[] src_classes) {
+ return Toolbox.removeThePrivates(src_classes);
+ }
+
+ private static final OJField[] removeThePrivates(OJField[] src_fields) {
+ return Toolbox.removeThePrivates(src_fields);
+ }
+
+ private static final OJMethod[] removeThePrivates(OJMethod[] src_methods) {
+ return Toolbox.removeThePrivates(src_methods);
+ }
+
+ private static final OJConstructor[] removeThePrivates(OJConstructor[] src_constrs) {
+ return Toolbox.removeThePrivates(src_constrs);
+ }
+
+ private static final OJClass[] removeTheDefaults(OJClass[] src_classes) {
+ return Toolbox.removeTheDefaults(src_classes);
+ }
+
+ private static final OJField[] removeTheDefaults(OJField[] src_fields) {
+ return Toolbox.removeTheDefaults(src_fields);
+ }
+
+ private static final OJMethod[] removeTheDefaults(OJMethod[] src_methods) {
+ return Toolbox.removeTheDefaults(src_methods);
+ }
+
+ private static final OJConstructor[] removeTheDefaults(OJConstructor[] src_constrs) {
+ return Toolbox.removeTheDefaults(src_constrs);
+ }
+
+ private static final OJClass[] removeTheNonPublics(OJClass[] src_classes) {
+ return Toolbox.removeTheNonPublics(src_classes);
+ }
+
+ private static final OJField[] removeTheNonPublics(OJField[] src_fields) {
+ return Toolbox.removeTheNonPublics(src_fields);
+ }
+
+ private static final OJMethod[] removeTheNonPublics(OJMethod[] src_methods) {
+ return Toolbox.removeTheNonPublics(src_methods);
+ }
+
+ private static final OJConstructor[] removeTheNonPublics(OJConstructor[] src_constrs) {
+ return Toolbox.removeTheNonPublics(src_constrs);
+ }
+
+ private static final OJMethod[] pickupMethodsByName(
+ OJMethod[] src_methods,
+ String name) {
+ return Toolbox.pickupMethodsByName(src_methods, name);
+ }
+
+ private static final OJField pickupField(
+ OJField[] src_fields,
+ String name) {
+ return Toolbox.pickupField(src_fields, name);
+ }
+
+ private static final OJMethod pickupMethod(
+ OJMethod[] src_methods,
+ String name,
+ OJClass[] parameterTypes) {
+ return Toolbox.pickupMethod(src_methods, name, parameterTypes);
+ }
+
+ private static final OJConstructor pickupConstructor(
+ OJConstructor[] src_constrs,
+ OJClass[] parameterTypes) {
+ return Toolbox.pickupConstructor(src_constrs, parameterTypes);
+ }
+
+ private static final OJMethod pickupAcceptableMethod(
+ OJMethod[] src_methods,
+ String name,
+ OJClass[] parameterTypes) {
+ return Toolbox.pickupAcceptableMethod(
+ src_methods,
+ name,
+ parameterTypes);
+ }
+
+ private static final OJConstructor pickupAcceptableConstructor(
+ OJConstructor[] src_constrs,
+ OJClass[] parameterTypes) {
+ return Toolbox.pickupAcceptableConstructor(src_constrs, parameterTypes);
+ }
+
+ /**
+ * Returns an array containing <code>OJClass</code> objects
+ * representing all the <em>public</em> classes and interfaces
+ * that are members of the class represented by this
+ * <code>OJClass</code> object. This includes public class and
+ * interface members inherited from superclasses and public class
+ * and interface members declared by the class. This method
+ * returns an array of length 0 if this <code>OJClass</code>
+ * object has no public member classes or interfaces. This method
+ * also returns an array of length 0 if this <code>OJClass</code>
+ * object represents a primitive type, an array class, or void.
+ *
+ */
+ public OJClass[] getClasses() {
+ return removeTheNonPublics(getAllClasses());
+ }
+
+ /**
+ * Returns an array containing <code>OJField</code> objects
+ * reflecting all the accessible <em>public</em> fields of the
+ * class or interface represented by this <code>OJClass</code>
+ * object. The elements in the array returned are not sorted and
+ * are not in any particular order. This method returns an array
+ * of length 0 if the class or interface has no accessible public
+ * fields, or if it represents an array class, a primitive type,
+ * or void.
+ *
+ * <p> Specifically, if this <code>OJClass</code> object
+ * represents a class, this method returns the public fields of
+ * this class and of all its superclasses. If this
+ * <code>OJClass</code> object represents an interface, this
+ * method returns the fields of this interface and of all its
+ * superinterfaces.
+ *
+ * <p> The implicit length field for array classs is reflected by this
+ * method.
+ *
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public OJField[] getFields() {
+ return removeTheNonPublics(getAllFields());
+ }
+
+ /**
+ * Returns an array containing <code>OJMethod</code> objects
+ * reflecting all the <em>public</em> member methods of the class
+ * or interface represented by this <code>OJClass</code> object,
+ * including those declared by the class or interface and and
+ * those inherited from superclasses and superinterfaces. The
+ * elements in the array returned are not sorted and are not in
+ * any particular order. This method returns an array of length 0
+ * if this <code>OJClass</code> object represents a class or
+ * interface that has no public member methods, or if this
+ * <code>OJClass</code> object represents an array class, primitive
+ * type, or void.
+ *
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public OJMethod[] getMethods() {
+ return removeTheNonPublics(getAllMethods());
+ }
+
+ /**
+ * Returns an array containing <code>OJConstructor</code> objects
+ * reflecting all the <em>public</em> constructors of the class
+ * represented by this <code>OJClass</code> object. An array of
+ * length 0 is returned if the class has no public constructors,
+ * or if the class is an array class, or if the class reflects a
+ * primitive type or void.
+ *
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ */
+ public OJConstructor[] getConstructors() {
+ return removeTheNonPublics(getDeclaredConstructors());
+ }
+
+ /**
+ * Returns a <code>OJField</code> object that reflects the
+ * specified <em>public</em> member field of the class or
+ * interface represented by this <code>OJClass</code> object. The
+ * <code>name</code> parameter is a <code>String</code> specifying
+ * the simple name of the desired field.
+ *
+ * @exception NoSuchMemberException if a field with the specified name is
+ * not found.
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public OJField getField(String name) throws NoSuchMemberException {
+ OJField field = pickupField(getFields(), name);
+ if (field != null)
+ return field;
+ throw new NoSuchMemberException(name);
+ }
+
+ /**
+ * Returns a <code>OJMethod</code> object that reflects the
+ * specified public member method of the class or interface
+ * represented by this <code>OJClass</code> object. The
+ * <code>name</code> parameter is a <code>String</code> specifying
+ * the simple name the desired method. The
+ * <code>parameterTypes</code> parameter is an array of
+ * <code>OJClass</code> objects that identify the method's formal
+ * parameter types, in declared order. If
+ * <code>parameterTypes</code> is <code>null</code>, it is treated
+ * as if it were an empty array.
+ *
+ * @exception NoSuchMemberException if a matching method is not found
+ * or if then name is "&lt;init>"or "&lt;clinit>".
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public OJMethod getMethod(String name, OJClass[] parameterTypes)
+ throws NoSuchMemberException {
+ OJMethod method = pickupMethod(getMethods(), name, parameterTypes);
+ if (method != null)
+ return method;
+ Signature sign = new Signature(name, parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /**
+ * Returns a <code>OJConstructor</code> object that reflects the
+ * specified public constructor of the class represented by this
+ * <code>OJClass</code> object. The <code>parameterTypes</code>
+ * parameter is an array of <code>OJClass</code> objects that
+ * identify the constructor's formal parameter types, in declared
+ * order.
+ *
+ * <p> The constructor to reflect is the public constructor of the
+ * class represented by this <code>OJClass</code> object whose
+ * formal parameter types match those specified by
+ * <code>parameterTypes</code>.
+ *
+ * @exception NoSuchMemberException if a matching method is not found.
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ */
+ public OJConstructor getConstructor(OJClass[] parameterTypes)
+ throws NoSuchMemberException {
+ OJConstructor constr =
+ pickupConstructor(getConstructors(), parameterTypes);
+ if (constr != null)
+ return constr;
+ Signature sign = new Signature(parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /**
+ * Returns an array containing <code>OJClass</code> objects
+ * representing all the classes and interfaces which are members
+ * of the class represented by this <code>OJClass</code> object,
+ * accessible from the situation represented by the given
+ * <code>OJClass</code> object. This includes class and interface
+ * members inherited from superclasses and declared class and
+ * interface members accessible from the given situation. This
+ * method returns an array of length 0 if this
+ * <code>OJClass</code> object has no public member classes or
+ * interfaces. This method also returns an array of length 0 if
+ * this <code>OJClass</code> object represents a primitive type,
+ * an array class, or void.
+ *
+ * <p>The accessiblity depends on the package of the class,
+ * modifiers of each members, and the package of the situation.
+ *
+ */
+ public final OJClass[] getClasses(OJClass situation) {
+ if (this == situation)
+ return getAllClasses();
+ if (isInSamePackage(situation)) {
+ return removeThePrivates(getAllClasses());
+ } else if (this.isAssignableFrom(situation)) {
+ return getInheritableClasses(situation);
+ }
+ return removeTheNonPublics(getAllClasses());
+ }
+
+ /**
+ * Returns an array containing <code>OJField</code> objects
+ * reflecting all the fields of the class or interface represented
+ * by this <code>OJClass</code> object, accessible from the
+ * situation represented by the given <code>OJClass</code> object.
+ * The elements in the array returned are not sorted and
+ * are not in any particular order. This method returns an array
+ * of length 0 if the class or interface has no accessible public
+ * fields, or if it represents an array class, a primitive type,
+ * or void.
+ *
+ * <p> Specifically, if this <code>OJClass</code> object
+ * represents a class, this method returns the public fields of
+ * this class and of all its superclasses. If this
+ * <code>OJClass</code> object represents an interface, this
+ * method returns the fields of this interface and of all its
+ * superinterfaces.
+ *
+ * <p>The accessiblity depends on the package of the class,
+ * modifiers of each members, and the package of the situation.
+ *
+ * <p> The implicit length field for array classs is reflected by this
+ * method.
+ *
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public final OJField[] getFields(OJClass situation) {
+ if (this == situation)
+ return getAllFields();
+ if (isInSamePackage(situation)) {
+ return removeThePrivates(getAllFields());
+ } else if (this.isAssignableFrom(situation)) {
+ return getInheritableFields(situation);
+ }
+ return removeTheNonPublics(getAllFields());
+ }
+
+ /**
+ * Returns an array containing <code>OJMethod</code> objects
+ * reflecting all the member methods of the class or interface
+ * represented by this <code>OJClass</code> object, accesible from
+ * the situation represented by the given <code>OJClass</code>
+ * object. Returned methods include those declared by the class
+ * or interface and and those inherited from superclasses and
+ * superinterfaces. The elements in the array returned are not
+ * sorted and are not in any particular order. This method
+ * returns an array of length 0 if this <code>OJClass</code>
+ * object represents a class or interface that has no public
+ * member methods, or if this <code>OJClass</code> object
+ * represents an array class, primitive type, or void.
+ *
+ * <p>The accessiblity depends on the package of the class,
+ * modifiers of each members, and the package of the situation.
+ *
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public final OJMethod[] getMethods(OJClass situation) {
+ if (this == situation)
+ return getAllMethods();
+ if (isInSamePackage(situation)) {
+ return removeThePrivates(getAllMethods());
+ } else if (this.isAssignableFrom(situation)) {
+ return getInheritableMethods(situation);
+ }
+ return removeTheNonPublics(getAllMethods());
+ }
+
+ /**
+ * Returns an array containing <code>OJConstructor</code> objects
+ * reflecting all the constructors of the class represented by
+ * this <code>OJClass</code> object, accesible from the situation
+ * represented by the given <code>OJClass</code> object. An array
+ * of length 0 is returned if the class has no public
+ * constructors, or if the class is an array class, or if the
+ * class reflects a primitive type or void.
+ *
+ * <p>The accessiblity depends on the package of the class,
+ * modifiers of each members, and the package of the situation.
+ *
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ */
+ public final OJConstructor[] getConstructors(OJClass situation) {
+ if (this == situation)
+ return getDeclaredConstructors();
+ if (isInSamePackage(situation)) {
+ return removeThePrivates(getDeclaredConstructors());
+ } else if (this.isAssignableFrom(situation)) {
+ return getInheritableConstructors(situation);
+ }
+ return removeTheNonPublics(getDeclaredConstructors());
+ }
+
+ /**
+ * Returns a <code>OJField</code> object that reflects the
+ * specified member field accesible from the situation represented
+ * by the given <code>OJClass</code> object. The
+ * <code>name</code> parameter is a <code>String</code> specifying
+ * the simple name of the desired field.
+ *
+ * @exception NoSuchMemberException if a field with the specified name is
+ * not found.
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public OJField getField(String name, OJClass situation)
+ throws NoSuchMemberException {
+ OJField field = pickupField(getFields(situation), name);
+ if (field != null)
+ return field;
+ throw new NoSuchMemberException(name);
+ }
+
+ /**
+ * Returns a <code>OJMethod</code> object that reflects the
+ * specified member method accesible from the situation
+ * represented by the given <code>OJClass</code> object. The
+ * <code>name</code> parameter is a <code>String</code> specifying
+ * the simple name the desired method. The
+ * <code>parameterTypes</code> parameter is an array of
+ * <code>OJClass</code> objects that identify the method's formal
+ * parameter types, in declared order. If
+ * <code>parameterTypes</code> is <code>null</code>, it is treated
+ * as if it were an empty array.
+ *
+ * @exception NoSuchMemberException if a matching method is not found.
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public OJMethod getMethod(
+ String name,
+ OJClass[] parameterTypes,
+ OJClass situation)
+ throws NoSuchMemberException {
+ OJMethod method =
+ pickupMethod(getMethods(situation), name, parameterTypes);
+ if (method != null)
+ return method;
+ Signature sign = new Signature(name, parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /**
+ * Returns a <code>OJConstructor</code> object that reflects the
+ * specified constructor accesible from the situation represented
+ * by the given <code>OJClass</code> object. The
+ * <code>parameterTypes</code> parameter is an array of
+ * <code>OJClass</code> objects that identify the constructor's
+ * formal parameter types, in declared order.
+ *
+ * <p> The constructor to reflect is the constructor of the
+ * class represented by this <code>OJClass</code> object whose
+ * formal parameter types match those specified by
+ * <code>parameterTypes</code>.
+ *
+ * @exception NoSuchMemberException if a matching method is not found.
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ */
+ public OJConstructor getConstructor(
+ OJClass[] parameterTypes,
+ OJClass situation)
+ throws NoSuchMemberException {
+ OJConstructor constr =
+ pickupConstructor(getConstructors(situation), parameterTypes);
+ if (constr != null)
+ return constr;
+ Signature sign = new Signature(parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /**
+ * Use <code>c.getField(name,c)</code>
+ * @deprecated
+ * @see getField(String,OJClass)
+ */
+ public final OJField getAllField(String name)
+ throws NoSuchMemberException {
+ OJField field = pickupField(getAllFields(), name);
+ if (field != null)
+ return field;
+ throw new NoSuchMemberException(name);
+ }
+
+ /**
+ * @deprecated
+ */
+ public final OJMethod[] getAllMethods(String name) {
+ return pickupMethodsByName(getAllMethods(), name);
+ }
+
+ /**
+ * Use <code>c.getMethod(name,ptypes,c)</code>
+ * @deprecated
+ * @see getMethod(String,OJClass[],OJClass)
+ */
+ public final OJMethod getAllMethod(String name, OJClass[] parameterTypes)
+ throws NoSuchMemberException {
+ OJMethod method = pickupMethod(getAllMethods(), name, parameterTypes);
+ if (method != null)
+ return method;
+ Signature sign = new Signature(name, parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /** Can be overriden */
+ public OJMethod getAcceptableMethod(
+ String name,
+ OJClass[] parameterTypes,
+ OJClass situation)
+ throws NoSuchMemberException {
+ OJMethod method =
+ pickupAcceptableMethod(getMethods(situation), name, parameterTypes);
+ if (method != null)
+ return method;
+ Signature sign = new Signature(name, parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /** Can be overriden */
+ public OJConstructor getAcceptableConstructor(
+ OJClass[] parameterTypes,
+ OJClass situation)
+ throws NoSuchMemberException {
+ OJConstructor constr =
+ pickupAcceptableConstructor(
+ getConstructors(situation),
+ parameterTypes);
+ if (constr != null)
+ return constr;
+ Signature sign = new Signature(parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /**
+ * Returns an array of <code>OJClass</code> objects reflecting all
+ * the classes and interfaces declared as members of the class
+ * represented by this <code>OJClass</code> object. This includes
+ * public, protected, default (package) access, and private
+ * classes and interfaces declared by the class, but excludes
+ * inherited classes and interfaces. This method returns an array
+ * of length 0 if the class declares no classes or interfaces as
+ * members, or if this <code>OJClass</code> object represents a
+ * primitive type, an array class, or void.
+ *
+ * <p>This method may be overriden to provide proper information
+ * in the extended language.
+ */
+ public OJClass[] getDeclaredClasses() {
+ return substance.getDeclaredClasses();
+ }
+
+ /**
+ * Returns an array of <code>OJField</code> objects reflecting all
+ * the fields declared by the class or interface represented by
+ * this <code>OJClass</code> object. This includes public,
+ * protected, default (package) access, and private fields, but
+ * excludes inherited fields. The elements in the array returned
+ * are not sorted and are not in any particular order. This
+ * method returns an array of length 0 if the class or interface
+ * declares no fields, or if this <code>OJClass</code> object
+ * represents a primitive type, an array class, or void.
+ *
+ * <p>This method may be overriden to provide proper information
+ * in the extended language.
+ *
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public OJField[] getDeclaredFields() {
+ return substance.getDeclaredFields();
+ }
+
+ /**
+ * Returns an array of <code>OJMethod</code> objects reflecting all
+ * the methods declared by the class or interface represented by
+ * this <code>OJClass</code> object. This includes public,
+ * protected, default (package) access, and private methods, but
+ * excludes inherited methods. The elements in the array returned
+ * are not sorted and are not in any particular order. This
+ * method returns an array of length 0 if the class or interface
+ * declares no methods, or if this <code>OJClass</code> object
+ * represents a primitive type, an array class, or void. The
+ * class initialization method <code>&lt;clinit&gt;</code> is not
+ * included in the returned array. If the class declares multiple
+ * public member methods with the same parameter types, they are
+ * all included in the returned array.
+ *
+ * <p>This method may be overriden to provide proper information
+ * in the extended language.
+ *
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public OJMethod[] getDeclaredMethods() {
+ return substance.getDeclaredMethods();
+ }
+
+ /**
+ * Returns an array of <code>OJConstructor</code> objects reflecting
+ * all the constructors declared by the class represented by this
+ * <code>OJClass</code> object. These are public, protected, default
+ * (package) access, and private constructors. The elements in
+ * the array returned are not sorted and are not in any particular
+ * order. If the class has a default constructor, it is included
+ * in the returned array. This method returns an array of length
+ * 0 if this <code>OJClass</code> object represents an interface, a
+ * primitive type, an array class, or void.
+ *
+ * <p>This method may be overriden to provide proper information
+ * in the extended language.
+ *
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ */
+ public OJConstructor[] getDeclaredConstructors() {
+ return substance.getDeclaredConstructors();
+ }
+
+ /**
+ * Returns a <code>OJField</code> object that reflects the specified
+ * declared field of the class or interface represented by this
+ * <code>OJClass</code> object. The <code>name</code> parameter is a
+ * <code>String</code> that specifies the simple name of the
+ * desired field. Note that this method will reflect the
+ * <code>length</code> field of an array class.
+ *
+ * @exception NoSuchMemberException if a field with the specified name is
+ * not found.
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public final OJField getDeclaredField(String name)
+ throws NoSuchMemberException {
+ OJField field = pickupField(getDeclaredFields(), name);
+ if (field != null)
+ return field;
+ throw new NoSuchMemberException(name);
+ }
+
+ /**
+ * Returns a <code>OJMethod</code> object that reflects the
+ * specified declared method of the class or interface represented
+ * by this <code>OJClass</code> object. The <code>name</code>
+ * parameter is a <code>String</code> that specifies the simple
+ * name of the desired method, and the <code>parameterTypes</code>
+ * parameter is an array of <code>OJClass</code> objects that
+ * identify the method's formal parameter types, in declared
+ * order. If more than one method with the same parameter types
+ * is declared in a class, and one of these methods has a return
+ * type that is more specific than any of the others, that method
+ * is returned; otherwise one of the methods is chosen
+ * arbitrarily.
+ *
+ * @exception NoSuchMemberException if a matching method is not found.
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public final OJMethod getDeclaredMethod(
+ String name,
+ OJClass[] parameterTypes)
+ throws NoSuchMemberException {
+ OJMethod method =
+ pickupMethod(getDeclaredMethods(), name, parameterTypes);
+ if (method != null)
+ return method;
+ Signature sign = new Signature(name, parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /**
+ * Returns a <code>OJConstructor</code> object that reflects the
+ * specified constructor of the class or interface represented by
+ * this <code>OJClass</code> object. The
+ * <code>parameterTypes</code> parameter is an array of
+ * <code>OJClass</code> objects that identify the constructor's
+ * formal parameter types, in declared order.
+ *
+ * @exception NoSuchMemberException if a matching method is not found.
+ * @see io.devnulllabs.openjava.mop.OJConstructor
+ */
+ public final OJConstructor getDeclaredConstructor(OJClass[] parameterTypes)
+ throws NoSuchMemberException {
+ OJConstructor constr =
+ pickupConstructor(getDeclaredConstructors(), parameterTypes);
+ if (constr != null)
+ return constr;
+ Signature sign = new Signature(parameterTypes);
+ throw new NoSuchMemberException(sign.toString());
+ }
+
+ /* -- the followings do not exist in regular Java -- */
+
+ /**
+ * Generate a copy of this class object with the specified name.
+ *
+ * @param qname a qualified name for the new copy.
+ */
+ public OJClass makeCopy(String qname) throws MOPException {
+ DebugOut.println(
+ "makeCopy() of " + getName() + " with a new name: " + qname);
+ try {
+ ClassDeclaration org = getSourceCode();
+ ClassDeclaration copy = (ClassDeclaration) org.makeRecursiveCopy();
+ String pack = Environment.toPackageName(qname);
+ String sname = Environment.toSimpleName(qname);
+ copy.setName(sname);
+ copy.accept(new TypeNameQualifier(getEnvironment(), sname));
+ FileEnvironment env =
+ new FileEnvironment(OJSystem.env, pack, sname);
+ return new OJClass(env, null, copy);
+ } catch (CannotAlterException ex1) {
+ return this;
+ } catch (ParseTreeException ex2) {
+ throw new MOPException(ex2);
+ }
+ }
+
+ public boolean isExecutable() {
+ return substance.isExecutable();
+ }
+
+ public boolean isAlterable() {
+ return substance.isAlterable();
+ }
+
+ public Class getByteCode() throws CannotExecuteException {
+ return substance.getByteCode();
+ }
+
+ public ClassDeclaration getSourceCode() throws CannotAlterException {
+ return substance.getSourceCode();
+ }
+
+ public Class getCompatibleJavaClass() {
+ return substance.getCompatibleJavaClass();
+ }
+
+ public Signature signature() {
+ return new Signature(this);
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass(OJClass parent) throws CannotAlterException {
+ substance.setDeclaringClass(parent);
+ }
+
+ /**
+ * Waits a callee-side translation on another class metaobject
+ * to be done.
+ *
+ * @param clazz a class metaobject to wait
+ */
+ public final void waitTranslation(OJClass clazz) throws MOPException {
+ if (!OJSystem.underConstruction.containsKey(clazz))
+ return;
+
+ synchronized (OJSystem.waitingPool) {
+ if (OJSystem.waitingPool.contains(clazz)) {
+ System.err.println(
+ "a dead lock detected between "
+ + getName()
+ + " and "
+ + clazz.getName());
+ return;
+ }
+ OJSystem.waitingPool.add(this);
+ }
+
+ OJSystem.waited = clazz;
+ Object lock = OJSystem.orderingLock;
+ try {
+ synchronized (lock) {
+ synchronized (this) {
+ this.notifyAll();
+ }
+ lock.wait();
+ }
+ } catch (InterruptedException e) {
+ throw new MOPException(e.toString());
+ } finally {
+ OJSystem.waitingPool.remove(this);
+ }
+ }
+
+ /* -- Modifications -- */
+
+ /** not implemented yet */
+ protected String setName(String simple_name) throws CannotAlterException {
+ throw new CannotAlterException("not implemented");
+ }
+
+ /**
+ * Under implementation.
+ * Modifiers of members should be considered carefully.
+ * @throws CannotAlterException
+ */
+ protected void beInterface() throws CannotAlterException {
+ //do nothing if this is an interface.
+ if (isInterface()) return;
+
+ ClassDeclaration d = getSourceCode();
+ d.beInterface(true);
+ }
+
+ /**
+ * Under implementation.
+ * Modifiers of members should be considered carefully.
+ * @throws CannotAlterException
+ */
+ protected void beClass() throws CannotAlterException {
+ //do nothing if this is a class.
+ if (!isInterface()) return;
+
+ ClassDeclaration d = getSourceCode();
+ d.beInterface(false);
+ }
+
+ protected OJClass setSuperclass(OJClass clazz)
+ throws CannotAlterException {
+ ClassDeclaration d = getSourceCode();
+ if (isInterface()) {
+ throw new CannotAlterException("cannot set a superclass of interface");
+ }
+ OJClass result = getSuperclass();
+ d.setBaseclass(TypeName.forOJClass(clazz));
+ return result;
+ }
+
+ protected OJClass[] setInterfaces(OJClass[] classes)
+ throws CannotAlterException {
+ ClassDeclaration d = getSourceCode();
+ OJClass[] result = getInterfaces();
+ if (isInterface()) {
+ d.setBaseclasses(Toolbox.TNsForOJClasses(classes));
+ } else {
+ d.setInterfaces(Toolbox.TNsForOJClasses(classes));
+ }
+ return result;
+ }
+
+ protected void addInterface(OJClass clazz) throws CannotAlterException {
+ OJClass[] org = getInterfaces();
+ OJClass[] result = new OJClass[org.length + 1];
+ System.arraycopy(org, 0, result, 0, org.length);
+ result[org.length] = clazz;
+ setInterfaces(result);
+ }
+
+ protected OJClass addClass(OJClass clazz) throws CannotAlterException {
+ return substance.addClass(clazz);
+ }
+
+ protected OJClass removeClass(OJClass clazz) throws CannotAlterException {
+ return substance.removeClass(clazz);
+ }
+
+ protected OJField addField(OJField field) throws CannotAlterException {
+ return substance.addField(field);
+ }
+
+ protected OJField removeField(OJField field) throws CannotAlterException {
+ return substance.removeField(field);
+ }
+
+ protected OJMethod addMethod(OJMethod method) throws CannotAlterException {
+ return substance.addMethod(method);
+ }
+
+ protected OJMethod removeMethod(OJMethod method)
+ throws CannotAlterException {
+ return substance.removeMethod(method);
+ }
+
+ protected OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ return substance.addConstructor(constr);
+ }
+
+ protected OJConstructor removeConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ return substance.removeConstructor(constr);
+ }
+
+ /* -- Translation (overridable) -- */
+
+ public void translateDefinition() throws MOPException {
+ ;
+ }
+
+ /* */
+
+ public ClassDeclaration translateDefinition(
+ Environment env,
+ ClassDeclaration decl)
+ throws MOPException {
+ OJClass base = getSuperclass();
+ if (base != null)
+ waitTranslation(base);
+ OJClass[] faces = getInterfaces();
+ for (int i = 0; i < faces.length; ++i) {
+ waitTranslation(faces[i]);
+ }
+ translateDefinition();
+ return decl;
+ }
+
+ public Expression expandFieldRead(Environment env, FieldAccess expr) {
+ return expr;
+ }
+
+ public Expression expandFieldWrite(
+ Environment env,
+ AssignmentExpression expr) {
+ return expr;
+ }
+
+ public Expression expandMethodCall(Environment env, MethodCall expr) {
+ return expr;
+ }
+
+ public TypeName expandTypeName(Environment env, TypeName expr) {
+ if (isArray()) {
+ return getComponentType().expandTypeName(env, expr);
+ }
+ return expr;
+ }
+
+ public Expression expandAllocation(
+ Environment env,
+ AllocationExpression expr) {
+ return expr;
+ }
+
+ public Expression expandArrayAllocation(
+ Environment env,
+ ArrayAllocationExpression expr) {
+ if (isArray()) {
+ return getComponentType().expandArrayAllocation(env, expr);
+ }
+ return expr;
+ }
+
+ public Expression expandArrayAccess(Environment env, ArrayAccess expr) {
+ if (isArray()) {
+ return getComponentType().expandArrayAccess(env, expr);
+ }
+ return expr;
+ }
+
+ public Expression expandAssignmentExpression(
+ Environment env,
+ AssignmentExpression expr) {
+ if (isArray()) {
+ return getComponentType().expandAssignmentExpression(env, expr);
+ }
+ return expr;
+ }
+
+ public Expression expandExpression(Environment env, Expression expr) {
+ if (isArray()) {
+ return getComponentType().expandExpression(env, expr);
+ }
+ return expr;
+ }
+
+ public Statement expandVariableDeclaration(
+ Environment env,
+ VariableDeclaration decl) {
+ if (isArray()) {
+ return getComponentType().expandVariableDeclaration(env, decl);
+ }
+ return decl;
+ }
+
+ public Expression expandCastExpression(
+ Environment env,
+ CastExpression decl) {
+ if (isArray()) {
+ return getComponentType().expandCastExpression(env, decl);
+ }
+ return decl;
+ }
+
+ public Expression expandCastedExpression(
+ Environment env,
+ CastExpression decl) {
+ if (isArray()) {
+ return getComponentType().expandCastedExpression(env, decl);
+ }
+ return decl;
+ }
+
+ /* -- error handling -- */
+
+ public OJField resolveException(NoSuchMemberException e, String name)
+ throws NoSuchMemberException {
+ System.err.println(
+ "no such " + new Signature(name) + " in " + toString());
+ throw e;
+ }
+
+ public OJMethod resolveException(
+ NoSuchMemberException e,
+ String name,
+ OJClass[] argtypes)
+ throws NoSuchMemberException {
+ System.err.println(
+ "no such " + new Signature(name, argtypes) + " in " + toString());
+ throw e;
+ }
+
+ /* -- syntax extensions -- */
+
+ public static boolean isRegisteredKeyword(String keyword) {
+ return false;
+ }
+
+ public static SyntaxRule getDeclSuffixRule(String keyword) {
+ return null;
+ }
+
+ public static SyntaxRule getTypeSuffixRule(String keyword) {
+ return null;
+ }
+
+ public static boolean isRegisteredModifier(String keyword) {
+ return false;
+ }
+
+ /* -- persistant metalevel information */
+
+ public final String getMetaInfo(String key) {
+ return substance.getMetaInfo(key);
+ }
+
+ public final Enumeration getMetaInfoKeys() {
+ return substance.getMetaInfoKeys();
+ }
+
+ public final Enumeration getMetaInfoElements() {
+ return substance.getMetaInfoElements();
+ }
+
+ protected final String putMetaInfo(String key, String value)
+ throws CannotAlterException {
+ return substance.putMetaInfo(key, value);
+ }
+
+ /** inner use only */
+ public final void writeMetaInfo(Writer out) throws IOException {
+ substance.writeMetaInfo(out);
+ }
+
+}
+
+/**
+ * The abstract class <code>OJClassImp</code> provides an interface to
+ * an implementation of OJClass.
+ */
+abstract class OJClassImp {
+ public abstract String toString();
+ abstract ClassEnvironment getEnvironment();
+ abstract boolean isInterface();
+ abstract boolean isArray();
+ abstract boolean isPrimitive();
+
+ abstract String getName();
+
+ abstract OJClass getSuperclass();
+ abstract OJClass[] getInterfaces();
+ abstract OJClass getComponentType();
+ abstract OJModifier getModifiers();
+ abstract ParseTree getSuffix(String keyword);
+ abstract OJClass getDeclaringClass();
+
+ abstract OJClass[] getDeclaredClasses();
+ abstract OJField[] getDeclaredFields();
+ abstract OJMethod[] getDeclaredMethods();
+ abstract OJConstructor[] getDeclaredConstructors();
+
+ abstract boolean isExecutable();
+ abstract boolean isAlterable();
+ abstract Class getByteCode() throws CannotExecuteException;
+ abstract ClassDeclaration getSourceCode() throws CannotAlterException;
+ abstract Class getCompatibleJavaClass();
+
+ abstract void setDeclaringClass(OJClass parent)
+ throws CannotAlterException;
+
+ abstract OJClass addClass(OJClass clazz) throws CannotAlterException;
+ abstract OJClass removeClass(OJClass clazz) throws CannotAlterException;
+ abstract OJField addField(OJField field) throws CannotAlterException;
+ abstract OJField removeField(OJField field) throws CannotAlterException;
+ abstract OJMethod addMethod(OJMethod method) throws CannotAlterException;
+ abstract OJMethod removeMethod(OJMethod method)
+ throws CannotAlterException;
+ abstract OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException;
+ abstract OJConstructor removeConstructor(OJConstructor constr)
+ throws CannotAlterException;
+
+ abstract String getMetaInfo(String key);
+ abstract Enumeration getMetaInfoKeys();
+ abstract Enumeration getMetaInfoElements();
+ abstract String putMetaInfo(String key, String value)
+ throws CannotAlterException;
+ abstract void writeMetaInfo(Writer out) throws IOException;
+
+ final OJClass forNameAnyway(String name) {
+ return Toolbox.forNameAnyway(getEnvironment(), name);
+ }
+
+ final OJClass[] arrayForNames(String[] names) {
+ return Toolbox.arrayForNames(getEnvironment(), names);
+ }
+
+ static final OJClass forClass(Class javaclass) {
+ return OJClass.forClass(javaclass);
+ }
+
+ static final String nameForJavaClassName(String javaname) {
+ return Toolbox.nameForJavaClassName(javaname);
+ }
+
+ static final String nameToJavaClassName(String ojname) {
+ return Toolbox.nameToJavaClassName(ojname);
+ }
+
+ static final OJField[] arrayForFields(Field[] fields) {
+ return OJField.arrayForFields(fields);
+ }
+
+ static final OJMethod[] arrayForMethods(Method[] methods) {
+ return OJMethod.arrayForMethods(methods);
+ }
+
+ static final OJConstructor[] arrayForConstructors(Constructor[] constrs) {
+ return OJConstructor.arrayForConstructors(constrs);
+ }
+
+}
+
+class OJClassByteCode extends OJClassImp {
+ private Class javaClass;
+
+ private MetaInfo metainfo;
+
+ OJClassByteCode(Class java_class, MetaInfo metainfo) {
+ this.javaClass = java_class;
+ this.metainfo = metainfo;
+ }
+
+ ClassEnvironment getEnvironment() {
+ int last = getName().lastIndexOf('.');
+ String pack = (last == -1) ? null : getName().substring(0, last);
+ String name = Environment.toSimpleName(getName());
+ FileEnvironment fenv = new FileEnvironment(OJSystem.env, pack, name);
+ return new ClassEnvironment(fenv, name);
+ }
+
+ public String toString() {
+ return (isPrimitive() ? getName() : "class " + getName());
+ }
+
+ boolean isInterface() {
+ return javaClass.isInterface();
+ }
+
+ boolean isArray() {
+ return javaClass.isArray();
+ }
+
+ boolean isPrimitive() {
+ return javaClass.isPrimitive();
+ }
+
+ String getName() {
+ return nameForJavaClassName(javaClass.getName());
+ }
+
+ ClassLoader getClassLoader() throws CannotInspectException {
+ return javaClass.getClassLoader();
+ }
+
+ OJClass getSuperclass() {
+ Class base = javaClass.getSuperclass();
+ return ((base == null) ? null : forClass(base));
+ }
+
+ OJClass[] getInterfaces() {
+ return OJClass.arrayForClasses(javaClass.getInterfaces());
+ }
+
+ OJClass getComponentType() {
+ Class comp = javaClass.getComponentType();
+ return ((comp == null) ? null : forClass(comp));
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forModifier(javaClass.getModifiers());
+ }
+
+ ParseTree getSuffix(String keyword) {
+ return null;
+ }
+
+ OJClass getDeclaringClass() {
+ Class declarer = javaClass.getDeclaringClass();
+ return ((declarer == null) ? null : forClass(declarer));
+ }
+
+ OJClass[] getDeclaredClasses() {
+ try {
+ return OJClass.arrayForClasses(javaClass.getDeclaredClasses());
+ } catch (SecurityException e) {
+ System.err.println(e);
+ return new OJClass[0];
+ }
+ }
+
+ OJField[] getDeclaredFields() {
+ try {
+ return arrayForFields(javaClass.getDeclaredFields());
+ } catch (SecurityException e) {
+ System.err.println(e);
+ return new OJField[0];
+ }
+ }
+
+ OJMethod[] getDeclaredMethods() {
+ try {
+ return arrayForMethods(javaClass.getDeclaredMethods());
+ } catch (SecurityException e) {
+ System.err.println(e);
+ return new OJMethod[0];
+ }
+ }
+
+ OJConstructor[] getDeclaredConstructors() {
+ try {
+ return arrayForConstructors(javaClass.getDeclaredConstructors());
+ } catch (SecurityException e) {
+ System.err.println(e);
+ return new OJConstructor[0];
+ }
+ }
+
+ /* -- the followings do not exist in regular Java -- */
+
+ boolean isExecutable() {
+ return true;
+ }
+
+ boolean isAlterable() {
+ return false;
+ }
+
+ Class getByteCode() throws CannotExecuteException {
+ return javaClass;
+ }
+
+ ClassDeclaration getSourceCode() throws CannotAlterException {
+ throw new CannotAlterException("getSourceCode()");
+ }
+
+ Class getCompatibleJavaClass() {
+ return javaClass;
+ }
+
+ void setDeclaringClass(OJClass parent) throws CannotAlterException {
+ throw new CannotAlterException("setDeclaringClass()");
+ }
+
+ OJClass addClass(OJClass clazz) throws CannotAlterException {
+ throw new CannotAlterException("addClass()");
+ }
+
+ OJClass removeClass(OJClass clazz) throws CannotAlterException {
+ throw new CannotAlterException("removeClass()");
+ }
+
+ OJField addField(OJField field) throws CannotAlterException {
+ throw new CannotAlterException("addField()");
+ }
+
+ OJField removeField(OJField field) throws CannotAlterException {
+ throw new CannotAlterException("removeField()");
+ }
+
+ OJMethod addMethod(OJMethod method) throws CannotAlterException {
+ throw new CannotAlterException("addMethod()");
+ }
+
+ OJMethod removeMethod(OJMethod method) throws CannotAlterException {
+ throw new CannotAlterException("removeMethod()");
+ }
+
+ OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ throw new CannotAlterException("addConstructor()");
+ }
+
+ OJConstructor removeConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ throw new CannotAlterException("removeConstructor()");
+ }
+
+ /* -- persistant metalevel information */
+
+ String getMetaInfo(String key) {
+ return metainfo.get(key);
+ }
+
+ Enumeration getMetaInfoKeys() {
+ return metainfo.keys();
+ }
+
+ Enumeration getMetaInfoElements() {
+ return metainfo.elements();
+ }
+
+ String putMetaInfo(String key, String value) throws CannotAlterException {
+ throw new CannotAlterException("putMetaInfo()");
+ }
+
+ void writeMetaInfo(Writer out) throws IOException {
+ }
+
+}
+
+class OJClassSourceCode extends OJClassImp {
+ private OJClass declarer;
+ private ClassDeclaration definition;
+ private ClassEnvironment env;
+
+ private Vector classes = new Vector();
+ private Vector fields = new Vector();
+ private Vector methods = new Vector();
+ private Vector constrs = new Vector();
+
+ private MetaInfo metainfo;
+
+ /* -- constructors -- */
+
+ OJClassSourceCode(
+ OJClass holder,
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ this.declarer = declarer;
+ this.definition = ptree;
+ String qname;
+ if (declarer == null) {
+ qname = outer_env.toQualifiedName(definition.getName());
+ //String pack = outer_env.getPackage();
+ //qname = ((pack == null) ? "" : pack + ".") + definition.getName();
+ } else {
+ qname = outer_env.currentClassName() + "." + definition.getName();
+ }
+ this.env = new ClassEnvironment(outer_env, qname);
+ metainfo = new MetaInfo(holder.getClass().getName(), qname);
+
+ MemberDeclarationList mdecls = ptree.getBody();
+ for (int i = 0, len = mdecls.size(); i < len; ++i) {
+ MemberDeclaration mdecl = mdecls.get(i);
+ if (mdecl instanceof ClassDeclaration) {
+ ClassDeclaration d = (ClassDeclaration) mdecl;
+ this.env.recordMemberClass(d.getName());
+ try {
+ OJClass clazz = OJClass.forParseTree(this.env, holder, d);
+ this.classes.addElement(clazz);
+ } catch (Exception ex) {
+ /***** here should be error-handling */
+ ex.printStackTrace();
+ }
+ } else if (mdecl instanceof FieldDeclaration) {
+ FieldDeclaration d = (FieldDeclaration) mdecl;
+ OJField field = new OJField(this.env, holder, d);
+ this.fields.addElement(field);
+ } else if (mdecl instanceof MethodDeclaration) {
+ MethodDeclaration d = (MethodDeclaration) mdecl;
+ OJMethod method = new OJMethod(this.env, holder, d);
+ this.methods.addElement(method);
+ } else if (mdecl instanceof ConstructorDeclaration) {
+ ConstructorDeclaration d = (ConstructorDeclaration) mdecl;
+ OJConstructor constr = new OJConstructor(this.env, holder, d);
+ this.constrs.addElement(constr);
+ } else if (mdecl instanceof MemberInitializer) {
+ /***********/;
+ }
+ }
+ }
+
+ public String toString() {
+ return ("class " + getName());
+ }
+
+ ClassEnvironment getEnvironment() {
+ return env;
+ }
+
+ boolean isInterface() {
+ return definition.isInterface();
+ }
+
+ boolean isArray() {
+ return false;
+ }
+
+ boolean isPrimitive() {
+ return false;
+ }
+
+ String getName() {
+ if (declarer == null) {
+ return env.toQualifiedName(definition.getName());
+ } else {
+ return declarer.getName() + "." + definition.getName();
+ }
+ }
+
+ OJClass getSuperclass() {
+ if (isInterface()) {
+ return null;
+ } else {
+ TypeName base = definition.getBaseclass();
+ String basename =
+ (base == null) ? "java.lang.Object" : base.toString();
+ return forNameAnyway(basename);
+ }
+ }
+
+ OJClass[] getInterfaces() {
+ TypeName[] types;
+ if (isInterface()) {
+ types = definition.getBaseclasses();
+ } else {
+ types = definition.getInterfaces();
+ }
+ String[] names = new String[types.length];
+ for (int i = 0; i < names.length; ++i) {
+ names[i] = types[i].toString();
+ }
+ return arrayForNames(names);
+ }
+
+ OJClass getComponentType() {
+ return null;
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forParseTree(definition.getModifiers());
+ }
+
+ ParseTree getSuffix(String keyword) {
+ Hashtable table = definition.getSuffixes();
+ if (table == null)
+ return null;
+ return (ParseTree) table.get(keyword);
+ }
+
+ OJClass getDeclaringClass() {
+ return declarer;
+ }
+
+ OJClass[] getDeclaredClasses() {
+ OJClass[] result = new OJClass[classes.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (OJClass) classes.elementAt(i);
+ }
+ return result;
+ }
+
+ OJField[] getDeclaredFields() {
+ OJField[] result = new OJField[fields.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (OJField) fields.elementAt(i);
+ }
+ return result;
+ }
+
+ OJMethod[] getDeclaredMethods() {
+ OJMethod[] result = new OJMethod[methods.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (OJMethod) methods.elementAt(i);
+ }
+ return result;
+ }
+
+ OJConstructor[] getDeclaredConstructors() {
+ OJConstructor[] result = new OJConstructor[constrs.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (OJConstructor) constrs.elementAt(i);
+ }
+ return result;
+ }
+
+ InputStream getResourceAsStream(String name)
+ throws CannotInspectException {
+ throw new CannotInspectException("getResourceAsStream()");
+ }
+
+ java.net.URL getResource(String name) throws CannotInspectException {
+ throw new CannotInspectException("getResource()");
+ }
+
+ /* -- the followings do not exist in regular Java -- */
+
+ boolean isExecutable() {
+ return false;
+ }
+
+ boolean isAlterable() {
+ return true;
+ }
+
+ Class getByteCode() throws CannotExecuteException {
+ throw new CannotExecuteException("getByteCode()");
+ }
+
+ ClassDeclaration getSourceCode() throws CannotAlterException {
+ return definition;
+ }
+
+ Class getCompatibleJavaClass() {
+ return getSuperclass().getCompatibleJavaClass();
+ }
+
+ void setDeclaringClass(OJClass parent) throws CannotAlterException {
+ this.declarer = parent;
+ }
+
+ OJClass addClass(OJClass clazz) throws CannotAlterException {
+ if (!clazz.isAlterable()) {
+ throw new CannotAlterException("cannot add by addClass()");
+ }
+ OJClass result = clazz;
+ /*ClassDeclaration result = clazz.makeCopy();*/
+ this.classes.addElement(result);
+ ClassDeclaration cdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ memdecls.add(cdecl);
+ return result;
+ }
+
+ OJClass removeClass(OJClass clazz) throws CannotAlterException {
+ if (!clazz.isAlterable()) {
+ throw new CannotAlterException("cannot remove by removeClass()");
+ }
+ if (!classes.removeElement(clazz))
+ return null;
+ OJClass result = clazz;
+ ClassDeclaration cdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ for (int i = 0; i < memdecls.size(); ++i) {
+ if (memdecls.get(i) == cdecl)
+ memdecls.remove(i--);
+ }
+ return result;
+ }
+
+ OJField addField(OJField field) throws CannotAlterException {
+ if (!field.isAlterable()) {
+ throw new CannotAlterException("cannot add by addField()");
+ }
+ OJField result = field;
+ /*FieldDeclaration result = field.makeCopy();*/
+ this.fields.addElement(result);
+ //result.set
+ FieldDeclaration fdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ memdecls.add(fdecl);
+ return result;
+ }
+
+ OJField removeField(OJField field) throws CannotAlterException {
+ if (!field.isAlterable()) {
+ throw new CannotAlterException("cannot remove by removeField()");
+ }
+ if (!fields.removeElement(field))
+ return null;
+ OJField result = field;
+ FieldDeclaration fdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ for (int i = 0; i < memdecls.size(); ++i) {
+ if (memdecls.get(i) == fdecl)
+ memdecls.remove(i--);
+ }
+ return result;
+ }
+
+ OJMethod addMethod(OJMethod method) throws CannotAlterException {
+ if (!method.isAlterable()) {
+ throw new CannotAlterException("cannot add by addMethod()");
+ }
+ OJMethod result = method;
+ /*MethodDeclaration result = field.makeCopy();*/
+ this.methods.addElement(result);
+ MethodDeclaration mdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ memdecls.add(mdecl);
+ return result;
+ }
+
+ OJMethod removeMethod(OJMethod method) throws CannotAlterException {
+ if (!method.isAlterable()) {
+ throw new CannotAlterException("cannot remove by removeMethod()");
+ }
+ if (!methods.removeElement(method))
+ return null;
+ OJMethod result = method;
+ MethodDeclaration fdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ for (int i = 0; i < memdecls.size(); ++i) {
+ if (memdecls.get(i) == fdecl)
+ memdecls.remove(i--);
+ }
+ return result;
+ }
+
+ OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ if (!constr.isAlterable()) {
+ throw new CannotAlterException("cannot add by addConstructor()");
+ }
+ OJConstructor result = constr;
+ /*ConstructorDeclaration result = constr.makeCopy();*/
+ this.constrs.addElement(result);
+ ConstructorDeclaration mdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ memdecls.add(mdecl);
+ return result;
+ }
+
+ OJConstructor removeConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ if (!constr.isAlterable()) {
+ throw new CannotAlterException("cannot remove by removeConstructor()");
+ }
+ if (!constrs.removeElement(constr))
+ return null;
+ OJConstructor result = constr;
+ ConstructorDeclaration fdecl = result.getSourceCode();
+ MemberDeclarationList memdecls = getSourceCode().getBody();
+ for (int i = 0; i < memdecls.size(); ++i) {
+ if (memdecls.get(i) == fdecl)
+ memdecls.remove(i--);
+ }
+ return result;
+ }
+
+ /* -- persistant metalevel information */
+
+ String getMetaInfo(String key) {
+ return metainfo.get(key);
+ }
+
+ Enumeration getMetaInfoKeys() {
+ return metainfo.keys();
+ }
+
+ Enumeration getMetaInfoElements() {
+ return metainfo.elements();
+ }
+
+ String putMetaInfo(String key, String value) throws CannotAlterException {
+ return metainfo.put(key, value);
+ }
+
+ void writeMetaInfo(Writer out) throws IOException {
+ metainfo.write(out);
+ }
+
+}
+
+class OJClassArray extends OJClassImp {
+ private OJClass componentType;
+ private OJClass[] classes = new OJClass[0];
+ private OJMethod[] methods = new OJMethod[0];
+ private OJConstructor[] constrs = new OJConstructor[0];
+ private Vector fields = new Vector();
+
+ private MetaInfo metainfo;
+
+ /* -- constructors -- */
+
+ OJClassArray(OJClass componentType) {
+ this.componentType = componentType;
+ fields.addElement(makeLengthField());
+ this.metainfo = new MetaInfo(componentType.getName() + "[]");
+ }
+
+ private final OJField makeLengthField() {
+ OJModifier modif = new OJModifier(OJModifier.PUBLIC | OJModifier.FINAL);
+ OJClass type = OJClass.forClass(int.class);
+ /* exactly not conmponent type */
+ return new OJField(componentType, modif, type, "length");
+ }
+
+ ClassEnvironment getEnvironment() {
+ return (ClassEnvironment) componentType.getEnvironment();
+ }
+
+ public String toString() {
+ return ("class " + componentType.getName() + "[]");
+ }
+
+ boolean isInterface() {
+ return false;
+ }
+
+ boolean isArray() {
+ return true;
+ }
+
+ boolean isPrimitive() {
+ return false;
+ }
+
+ String getName() {
+ return (componentType.getName() + "[]");
+ }
+
+ ClassLoader getClassLoader() throws CannotInspectException {
+ throw new CannotInspectException("getClassLoader()");
+ }
+
+ OJClass getSuperclass() {
+ return OJClass.forClass(Object[].class.getSuperclass());
+ }
+
+ OJClass[] getInterfaces() {
+ return OJClass.arrayForClasses(Object[].class.getInterfaces());
+ }
+
+ OJClass getComponentType() {
+ return componentType;
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forModifier(Object[].class.getModifiers());
+ }
+
+ ParseTree getSuffix(String keyword) {
+ return null;
+ }
+
+ OJClass getDeclaringClass() {
+ return null;
+ }
+
+ OJClass[] getDeclaredClasses() {
+ return classes;
+ }
+
+ OJField[] getDeclaredFields() {
+ OJField[] result = new OJField[fields.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (OJField) fields.elementAt(i);
+ }
+ return result;
+ }
+
+ OJMethod[] getDeclaredMethods() {
+ return methods;
+ }
+
+ OJConstructor[] getDeclaredConstructors() {
+ return constrs;
+ }
+
+ /* -- the followings do not exist in regular Java -- */
+
+ boolean isExecutable() {
+ return false;
+ }
+
+ boolean isAlterable() {
+ return false;
+ }
+
+ Class getByteCode() throws CannotExecuteException {
+ throw new CannotExecuteException("getByteCode()");
+ }
+
+ ClassDeclaration getSourceCode() throws CannotAlterException {
+ throw new CannotAlterException("getSourceCode()");
+ }
+
+ Class getCompatibleJavaClass() {
+ return getSuperclass().getCompatibleJavaClass();
+ }
+
+ void setDeclaringClass(OJClass parent) throws CannotAlterException {
+ throw new CannotAlterException("setDeclaringClass()");
+ }
+
+ OJClass addClass(OJClass clazz) throws CannotAlterException {
+ throw new CannotAlterException("addClass()");
+ }
+
+ OJClass removeClass(OJClass clazz) throws CannotAlterException {
+ throw new CannotAlterException("removeClass()");
+ }
+
+ OJField addField(OJField field) throws CannotAlterException {
+ throw new CannotAlterException("addField()");
+ }
+
+ OJField removeField(OJField field) throws CannotAlterException {
+ throw new CannotAlterException("removeField()");
+ }
+
+ OJMethod addMethod(OJMethod method) throws CannotAlterException {
+ throw new CannotAlterException("addMethod()");
+ }
+
+ OJMethod removeMethod(OJMethod method) throws CannotAlterException {
+ throw new CannotAlterException("removeMethod()");
+ }
+
+ OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ throw new CannotAlterException("addConstructor()");
+ }
+
+ OJConstructor removeConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ throw new CannotAlterException("removeConstructor()");
+ }
+
+ /* -- persistant metalevel information */
+
+ String getMetaInfo(String key) {
+ return null;
+ }
+
+ Enumeration getMetaInfoKeys() {
+ return new Vector().elements();
+ }
+
+ Enumeration getMetaInfoElements() {
+ return new Vector().elements();
+ }
+
+ String putMetaInfo(String key, String value) throws CannotAlterException {
+ throw new CannotAlterException("putMetaInfo()");
+ }
+
+ void writeMetaInfo(Writer out) throws IOException {
+ }
+
+}
+
+class OJClassNull extends OJClassImp {
+
+ OJClassNull() {
+ }
+
+ ClassEnvironment getEnvironment() {
+ return new ClassEnvironment(OJSystem.env, getName());
+ }
+
+ public String toString() {
+ return OJSystem.NULLTYPE_NAME;
+ }
+
+ boolean isInterface() {
+ return false;
+ }
+
+ boolean isArray() {
+ return false;
+ }
+
+ boolean isPrimitive() {
+ return false;
+ }
+
+ String getName() {
+ return null;
+ }
+
+ OJClass getSuperclass() {
+ return null;
+ }
+
+ OJClass[] getInterfaces() {
+ return null;
+ }
+
+ OJClass getComponentType() {
+ return null;
+ }
+
+ OJModifier getModifiers() {
+ return null;
+ }
+
+ ParseTree getSuffix(String keyword) {
+ return null;
+ }
+
+ OJClass getDeclaringClass() {
+ return null;
+ }
+
+ OJClass[] getDeclaredClasses() {
+ return null;
+ }
+
+ OJField[] getDeclaredFields() {
+ return null;
+ }
+
+ OJMethod[] getDeclaredMethods() {
+ return null;
+ }
+
+ OJConstructor[] getDeclaredConstructors() {
+ return null;
+ }
+
+ /* -- the followings do not exist in regular Java -- */
+
+ boolean isExecutable() {
+ return false;
+ }
+
+ boolean isAlterable() {
+ return false;
+ }
+
+ Class getByteCode() throws CannotExecuteException {
+ throw new CannotExecuteException("getByteCode()");
+ }
+
+ ClassDeclaration getSourceCode() throws CannotAlterException {
+ throw new CannotAlterException("getSourceCode()");
+ }
+
+ Class getCompatibleJavaClass() {
+ return null;
+ }
+
+ void setDeclaringClass(OJClass parent) throws CannotAlterException {
+ throw new CannotAlterException("setDeclaringClass()");
+ }
+
+ OJClass addClass(OJClass clazz) throws CannotAlterException {
+ throw new CannotAlterException("addClass()");
+ }
+
+ OJClass removeClass(OJClass clazz) throws CannotAlterException {
+ throw new CannotAlterException("removeClass()");
+ }
+
+ OJField addField(OJField field) throws CannotAlterException {
+ throw new CannotAlterException("addField()");
+ }
+
+ OJField removeField(OJField field) throws CannotAlterException {
+ throw new CannotAlterException("removeField()");
+ }
+
+ OJMethod addMethod(OJMethod method) throws CannotAlterException {
+ throw new CannotAlterException("addMethod()");
+ }
+
+ OJMethod removeMethod(OJMethod method) throws CannotAlterException {
+ throw new CannotAlterException("removeMethod()");
+ }
+
+ OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ throw new CannotAlterException("addConstructor()");
+ }
+
+ OJConstructor removeConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ throw new CannotAlterException("removeConstructor()");
+ }
+
+ /* -- persistant metalevel information */
+
+ String getMetaInfo(String key) {
+ return null;
+ }
+
+ Enumeration getMetaInfoKeys() {
+ return new Vector().elements();
+ }
+
+ Enumeration getMetaInfoElements() {
+ return new Vector().elements();
+ }
+
+ String putMetaInfo(String key, String value) throws CannotAlterException {
+ throw new CannotAlterException("putMetaInfo()");
+ }
+
+ void writeMetaInfo(Writer out) throws IOException {
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJClassNotFoundException.java b/src/main/java/io/devnulllabs/openjava/mop/OJClassNotFoundException.java
new file mode 100644
index 0000000..5c0f763
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJClassNotFoundException.java
@@ -0,0 +1,31 @@
+/*
+ * OJClassNotFoundException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+/**
+ * The exception <code>OJClassNotFoundException</code> is thrown
+ * when an application tries to load in a class through its
+ * string name using forName method in class OJClass. but no
+ * definition for the class with the specifed name could be found.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: OJClassNotFoundException.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class OJClassNotFoundException extends MOPException {
+ public OJClassNotFoundException() {
+ super();
+ }
+
+ public OJClassNotFoundException(String access) {
+ super(access);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJConstructor.java b/src/main/java/io/devnulllabs/openjava/mop/OJConstructor.java
new file mode 100644
index 0000000..4a5e0f2
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJConstructor.java
@@ -0,0 +1,652 @@
+/*
+ * OJConstructor.java
+ *
+ * Jul 28, 1998 by mich
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorInvocation;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.Variable;
+
+
+public final class OJConstructor implements OJMember
+{
+ private OJConstructorImp substance;
+
+ private static Hashtable table = new Hashtable();
+
+ OJConstructor( Constructor m ) {
+ this.substance = new OJConstructorByteCode( m );
+ }
+
+ public OJConstructor( OJClass declarer, OJModifier modif,
+ OJClass[] parameterTypes, OJClass[] exceptionTypes,
+ ConstructorInvocation ci, StatementList body )
+ {
+ this( declarer, modif,
+ Toolbox.generateParameters( parameterTypes ),
+ exceptionTypes, ci, body );
+ }
+
+ public OJConstructor( OJClass declarer, OJModifier modif,
+ OJClass[] parameterTypes, String[] parameterNames,
+ OJClass[] exceptionTypes,
+ ConstructorInvocation ci, StatementList body )
+ {
+ this( declarer, modif,
+ Toolbox.generateParameters( parameterTypes, parameterNames ),
+ exceptionTypes, ci, body );
+ }
+
+ public OJConstructor( OJClass declarer, OJModifier modif,
+ ParameterList params, OJClass[] exceptionTypes,
+ ConstructorInvocation ci, StatementList body )
+ {
+ Environment env = declarer.getEnvironment();
+ ModifierList modiflist = new ModifierList();
+ modiflist.add( modif.toModifier() );
+ ConstructorDeclaration d = new ConstructorDeclaration(
+ modiflist,
+ Environment.toSimpleName( declarer.getName() ),
+ params,
+ Toolbox.TNsForOJClasses( exceptionTypes ),
+ ci,
+ body
+ );
+ this.substance = new OJConstructorSourceCode( env, declarer, d );
+ }
+
+ public OJConstructor( Environment env, OJClass declarer,
+ ConstructorDeclaration d )
+ {
+ this.substance = new OJConstructorSourceCode( env, declarer, d );
+ }
+
+ public static OJConstructor forConstructor( Constructor java_constr ) {
+ if (java_constr == null) return null;
+ OJConstructor constr = (OJConstructor) table.get( java_constr );
+ if (constr == null) {
+ constr = new OJConstructor( java_constr );
+ table.put( java_constr, constr );
+ }
+ return constr;
+ }
+
+ public static OJConstructor[]
+ arrayForConstructors( Constructor[] jconstrs ) {
+ OJConstructor[] result = new OJConstructor[jconstrs.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = forConstructor( jconstrs[i] );
+ }
+ return result;
+ }
+
+ public Signature signature() {
+ return new Signature( this );
+ }
+
+ public OJClass getDeclaringClass() {
+ return substance.getDeclaringClass();
+ }
+
+ public String getName() {
+ /***********/
+ return substance.getName();
+ }
+
+ public String getIdentifiableName() {
+ return substance.getIdentifiableName();
+ }
+
+ public OJModifier getModifiers() {
+ return substance.getModifiers();
+ }
+
+ public OJClass[] getParameterTypes() {
+ return substance.getParameterTypes();
+ }
+
+ public OJClass[] getExceptionTypes() {
+ return substance.getExceptionTypes();
+ }
+
+ public ParseTree getSuffix( String keyword ) {
+ return substance.getSuffix( keyword );
+ }
+
+ /******************/
+ public ExpressionList getParameterVariables()
+ throws CannotAlterException
+ {
+ ConstructorDeclaration d = getSourceCode();
+ ParameterList params = d.getParameters();
+ ExpressionList result = new ExpressionList();
+ for (int i = 0, len = params.size(); i < len; ++i) {
+ result.add( new Variable( params.get( i ).getVariable() ) );
+ }
+ return result;
+ }
+
+ public String[] getParameters()
+ throws CannotAlterException
+ {
+ ConstructorDeclaration d = getSourceCode();
+ ParameterList params = d.getParameters();
+ String[] result = new String[params.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = params.get( i ).getVariable().toString();
+ }
+ return result;
+ }
+
+ /**
+ * Compares this method against the given object.
+ * The algorithm is borrowed by java.lang.reflect.Constructor.equals().
+ *
+ * @see java.lang.reflect.Constructor#equals
+ */
+ public boolean equals(Object obj) {
+ if (obj != null && obj instanceof OJConstructor) {
+ OJConstructor other = (OJConstructor) obj;
+ return ((getDeclaringClass() == other.getDeclaringClass())
+ && compareParameters( other ));
+ }
+
+ return false;
+ }
+
+ private boolean compareParameters( OJConstructor other ) {
+ return compareParameters( other.getParameterTypes() );
+ }
+
+ private boolean compareParameters( OJClass[] params2 ) {
+ OJClass[] params1 = getParameterTypes();
+ if (params1.length != params2.length) return false;
+ for (int i = 0; i < params1.length; ++i) {
+ if(params1[i] != params2[i]) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Computes a hashcode for this method. The algorithm is borrowed
+ * by java.lang.reflect.Constructor.hashCode().
+ *
+ * @see java.lang.reflect.Constructor#hashCode
+ */
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ public String toString() {
+ return substance.toString();
+ }
+
+ public Environment getEnvironment() {
+ return substance.getEnvironment();
+ }
+
+ /**
+ * Creates a new instance of the constructor's declaring class
+ *
+ * @exception CannotExecuteException if the constructor is not
+ * compiled yet.
+ */
+ public Object newInstance(Object[] initargs)
+ throws InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException,
+ InstantiationException, CannotExecuteException
+ {
+ return substance.newInstance( initargs );
+ }
+
+ /* -- methods java.lang.reflect.Constructor does not supply. -- */
+
+ public final boolean isExecutable() {
+ return substance.isExecutable();
+ }
+
+ public final boolean isAlterable() {
+ return substance.isAlterable();
+ }
+
+ public final Constructor getByteCode() throws CannotExecuteException {
+ return substance.getByteCode();
+ }
+
+ public final ConstructorDeclaration getSourceCode()
+ throws CannotAlterException
+ {
+ return substance.getSourceCode();
+ }
+
+ public final StatementList getBody() throws CannotAlterException {
+ return substance.getBody();
+ }
+
+ public final ConstructorInvocation getTransference()
+ throws CannotAlterException
+ {
+ return substance.getTransference();
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ substance.setDeclaringClass( parent );
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final public void setModifiers( int mods ) throws CannotAlterException {
+ substance.setModifiers( mods );
+ }
+
+ public final void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException
+ {
+ substance.setExceptionTypes( types );
+ }
+
+ public final void addExceptionType( OJClass type )
+ throws CannotAlterException
+ {
+ OJClass[] etypes = getExceptionTypes();
+ OJClass[] result = new OJClass[etypes.length + 1];
+ System.arraycopy( etypes, 0, result, 0, etypes.length );
+ result[etypes.length] = type;
+ setExceptionTypes( result );
+ }
+
+ public final ConstructorInvocation
+ setTransference( ConstructorInvocation invocation )
+ throws CannotAlterException
+ {
+ return substance.setTransference( invocation );
+ }
+
+ public final StatementList setBody( StatementList stmts )
+ throws CannotAlterException
+ {
+ return substance.setBody( stmts );
+ }
+
+}
+
+
+/**
+ * The abstract class <code>OJConstructorImp</code> provides an interface to
+ * an implementation of OJConstructor.
+ */
+abstract class OJConstructorImp
+{
+ public abstract String toString();
+ abstract Environment getEnvironment();
+ abstract OJClass getDeclaringClass();
+ abstract String getName();
+ abstract String getIdentifiableName();
+ abstract OJModifier getModifiers();
+ abstract OJClass[] getParameterTypes();
+ abstract OJClass[] getExceptionTypes();
+ abstract ParseTree getSuffix( String keyword );
+
+ abstract Object newInstance( Object[] initargs )
+ throws InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException,
+ InstantiationException, CannotExecuteException;
+
+ /* -- methods java.lang.reflect.Constructor does not supply. -- */
+
+ abstract boolean isExecutable();
+ abstract boolean isAlterable();
+ abstract Constructor getByteCode() throws CannotExecuteException;
+ abstract ConstructorDeclaration getSourceCode()
+ throws CannotAlterException;
+ abstract StatementList getBody() throws CannotAlterException;
+ abstract ConstructorInvocation getTransference()
+ throws CannotAlterException;
+
+ /* -- inner use only -- */
+ abstract void setDeclaringClass( OJClass parent )
+ throws CannotAlterException;
+
+ /* -- Translation (not overridable) -- */
+
+ abstract void setModifiers( int mods ) throws CannotAlterException;
+ abstract StatementList setBody( StatementList stmts )
+ throws CannotAlterException;
+ abstract void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException;
+ abstract ConstructorInvocation
+ setTransference( ConstructorInvocation invocation )
+ throws CannotAlterException;
+
+}
+
+
+class OJConstructorByteCode extends OJConstructorImp
+{
+
+ private Constructor javaConstructor = null;
+
+ OJConstructorByteCode( Constructor java_constr ) {
+ this.javaConstructor = java_constr;
+ }
+
+ public String toString() {
+ return javaConstructor.toString();
+ }
+
+ Environment getEnvironment() {
+ Environment result
+ = new ClosedEnvironment( getDeclaringClass().getEnvironment() );
+ return result;
+ }
+
+ OJClass getDeclaringClass() {
+ return OJClass.forClass( javaConstructor.getDeclaringClass() );
+ }
+
+ String getName() {
+ return javaConstructor.getName();
+ }
+
+ String getIdentifiableName() {
+ /***********/
+ return getDeclaringClass().getName() + "()";
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forModifier( javaConstructor.getModifiers() );
+ }
+
+ OJClass[] getParameterTypes() {
+ return OJClass.arrayForClasses( javaConstructor.getParameterTypes() );
+ }
+
+ OJClass[] getExceptionTypes() {
+ return OJClass.arrayForClasses( javaConstructor.getExceptionTypes() );
+ }
+
+ ParseTree getSuffix( String keyword ) {
+ return null;
+ }
+
+ Object newInstance( Object[] initargs )
+ throws InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException,
+ InstantiationException
+ {
+ return javaConstructor.newInstance( initargs );
+ }
+
+ /* -- methods java.lang.reflect.Constructor does not supply. -- */
+
+ boolean isExecutable() {
+ return true;
+ }
+
+ boolean isAlterable() {
+ return false;
+ }
+
+ Constructor getByteCode() throws CannotExecuteException {
+ return javaConstructor;
+ }
+
+ ConstructorDeclaration getSourceCode() throws CannotAlterException {
+ throw new CannotAlterException( "getSourceCode()" );
+ }
+
+ StatementList getBody() throws CannotAlterException {
+ throw new CannotAlterException( "getBody()" );
+ }
+
+ ConstructorInvocation getTransference()
+ throws CannotAlterException
+ {
+ throw new CannotAlterException( "getTransference()" );
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ throw new CannotAlterException( "setDeclaringClass()" );
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final void setName( String name ) throws CannotAlterException {
+ throw new CannotAlterException( "setName()" );
+ }
+
+ final void setModifiers( int mods ) throws CannotAlterException {
+ throw new CannotAlterException( "setModifiers()" );
+ }
+
+ final void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException
+ {
+ throw new CannotAlterException( "setExceptionTypes()" );
+ }
+
+ StatementList setBody( StatementList stmts )
+ throws CannotAlterException
+ {
+ throw new CannotAlterException( "setBody()" );
+ }
+
+ ConstructorInvocation setTransference( ConstructorInvocation invocation )
+ throws CannotAlterException
+ {
+ throw new CannotAlterException( "setTransference()" );
+ }
+
+}
+
+
+class OJConstructorSourceCode extends OJConstructorImp
+{
+
+ private static int idCounter = 0;
+ private int id;
+
+ private OJClass declarer;
+ private ConstructorDeclaration definition;
+ private Environment env;
+
+ OJConstructorSourceCode( Environment env, OJClass declarer,
+ ConstructorDeclaration ptree )
+ {
+ this.declarer = declarer;
+ this.definition = ptree;
+ this.env = env;
+ this.id = idCounter++;
+ }
+
+ public String toString() {
+ OJClass declarer = getDeclaringClass();
+ String declarername
+ = (declarer == null) ? "*" + id : declarer.getName();
+
+ StringBuffer buf = new StringBuffer();
+ String modif = getModifiers().toString();
+ if (! modif.equals( "" )) {
+ buf.append( modif );
+ buf.append( " " );
+ }
+ buf.append( getName() );
+ buf.append( "(" );
+ OJClass[] paramtypes = getParameterTypes();
+ if (paramtypes.length != 0) {
+ buf.append( paramtypes[0].getName() );
+ }
+ for (int i = 1; i < paramtypes.length; ++i) {
+ buf.append( "," );
+ buf.append( paramtypes[i].getName() );
+ }
+ buf.append( ")" );
+ return buf.toString();
+ }
+
+ Environment getEnvironment() {
+ Environment result
+ = new ClosedEnvironment( getDeclaringClass().getEnvironment() );
+ OJClass[] ptypes = getParameterTypes();
+ String[] pvars = getParameters();
+ for (int i = 0; i < ptypes.length; ++i) {
+ result.bindVariable( pvars[i], ptypes[i] );
+ }
+ return result;
+ }
+
+ OJClass getDeclaringClass() {
+ return this.declarer;
+ }
+
+ String getName() {
+ OJClass declarer = getDeclaringClass();
+ return (declarer == null) ? null : declarer.getName();
+ }
+
+ String getIdentifiableName() {
+ OJClass declarer = getDeclaringClass();
+ String declarername;
+ if (declarer == null) {
+ declarername = "*" + id;
+ } else {
+ declarername = declarer.getName();
+ }
+ /***************/
+ return declarername + "()";
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forParseTree( definition.getModifiers() );
+ }
+
+ OJClass[] getParameterTypes() {
+ return arrayForParameters( definition.getParameters() );
+ }
+
+ String[] getParameters() {
+ ParameterList params = definition.getParameters();
+ String[] result = new String[params.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = params.get( i ).getVariable().toString();
+ }
+ return result;
+ }
+
+ OJClass[] getExceptionTypes() {
+ return arrayForTypeNames( definition.getThrows() );
+ }
+
+ ParseTree getSuffix( String keyword ) {
+ Hashtable table = definition.getSuffixes();
+ if (table == null) return null;
+ return (ParseTree) table.get( keyword );
+ }
+
+ private final OJClass[] arrayForParameters( ParameterList params ) {
+ OJClass[] result = new OJClass[(params == null) ? 0 : params.size()];
+ for (int i = 0; i < result.length; ++i) {
+ String tname = params.get( i ).getTypeSpecifier().toString();
+ result[i] = Toolbox.forNameAnyway( env, tname );
+ }
+ return result;
+ }
+
+ private final OJClass[] arrayForTypeNames( TypeName[] typenames ) {
+ OJClass[] result
+ = new OJClass[(typenames == null) ? 0 : typenames.length];
+ for (int i = 0; i < result.length; ++i) {
+ String tname = typenames[i].toString();
+ result[i] = Toolbox.forNameAnyway( env, tname );
+ }
+ return result;
+ }
+
+ Object newInstance( Object[] initargs )
+ throws InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException,
+ InstantiationException, CannotExecuteException
+ {
+ throw new CannotExecuteException( "newInstance()" );
+ }
+
+ /* -- methods java.lang.reflect.Constructor does not supply. -- */
+
+ boolean isExecutable() {
+ return false;
+ }
+
+ boolean isAlterable() {
+ return true;
+ }
+
+ Constructor getByteCode() throws CannotExecuteException {
+ throw new CannotExecuteException( "getByteCode()" );
+ }
+
+ ConstructorDeclaration getSourceCode() throws CannotAlterException {
+ return definition;
+ }
+
+ StatementList getBody() throws CannotAlterException {
+ return definition.getBody();
+ }
+
+ ConstructorInvocation getTransference()
+ throws CannotAlterException
+ {
+ return definition.getConstructorInvocation();
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ this.declarer = parent;
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final void setModifiers( int mods ) throws CannotAlterException {
+ throw new CannotAlterException( "setModifiers()" );
+ }
+
+ final void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException
+ {
+ definition.setThrows( Toolbox.TNsForOJClasses( types ) );
+ }
+
+ StatementList setBody( StatementList stmts )
+ throws CannotAlterException
+ {
+ StatementList result = definition.getBody();
+ definition.setBody( stmts );
+ return result;
+ }
+
+ ConstructorInvocation setTransference( ConstructorInvocation invocation )
+ throws CannotAlterException
+ {
+ ConstructorInvocation result = definition.getConstructorInvocation();
+ definition.setConstructorInvocation( invocation );
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJField.java b/src/main/java/io/devnulllabs/openjava/mop/OJField.java
new file mode 100644
index 0000000..dc2e1b2
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJField.java
@@ -0,0 +1,810 @@
+/*
+ * OJField.java
+ *
+ * Jul 28, 1998 by mich
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.lang.reflect.Field;
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+
+public class OJField implements OJMember, Cloneable
+{
+
+ private OJFieldImp substance;
+
+ private static Hashtable table = new Hashtable();
+
+ OJField( Field java_field ) {
+ this.substance = new OJFieldByteCode( java_field );
+ }
+
+ public OJField( OJClass declarer,
+ OJModifier modif, OJClass type, String name )
+ {
+ Environment env = declarer.getEnvironment();
+ ModifierList modlist = new ModifierList();
+ TypeName tname = TypeName.forOJClass( type );
+ modlist.add( modif.toModifier() );
+ FieldDeclaration d
+ = new FieldDeclaration( modlist, tname, name, null );
+ this.substance = new OJFieldSourceCode( env, declarer, d );
+ }
+
+ public OJField( Environment env, OJClass declarer, FieldDeclaration d ) {
+ this.substance = new OJFieldSourceCode( env, declarer, d );
+ }
+
+ public static OJField forField( Field java_field ) {
+ OJField field = (OJField) table.get( java_field );
+ if (field == null) {
+ field = new OJField( java_field );
+ table.put( java_field, field );
+ }
+ return field;
+ }
+
+ public static OJField[] arrayForFields( Field[] jfields ) {
+ OJField[] result = new OJField[jfields.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = forField( jfields[i] );
+ }
+ return result;
+ }
+
+ public Signature signature() {
+ return new Signature( this );
+ }
+
+ public OJClass getDeclaringClass() {
+ return substance.getDeclaringClass();
+ }
+
+ public String getName() {
+ return substance.getName();
+ }
+
+ public String getIdentifiableName() {
+ return substance.getIdentifiableName();
+ }
+
+ public OJModifier getModifiers() {
+ return substance.getModifiers();
+ }
+
+ public OJClass getType() {
+ return substance.getType();
+ }
+
+ /**
+ * Compares this field against the given object.
+ * The algorithm is borrowed by java.lang.reflect.Field.equals().
+ *
+ * @see java.lang.reflect.Field#equals
+ */
+ public boolean equals( Object obj ) {
+ if(obj != null && obj instanceof OJField) {
+ OJField other = (OJField) obj;
+ return (getDeclaringClass() == other.getDeclaringClass())
+ && (getName().equals( other.getName() ))
+ && (getType() == other.getType());
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Computes a hashcode for this field.
+ *
+ * @return hash code.
+ */
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ public String toString() {
+ return substance.toString();
+ }
+
+ public Environment getEnvironment() {
+ return new ClosedEnvironment( getDeclaringClass().getEnvironment() );
+ }
+
+ /**
+ * Obtains the field value specified by this field object on
+ * the given object.
+ *
+ * @exception IllegalArgumentException if this field is not
+ * compiled yet.
+ **/
+ public Object get( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.get( obj );
+ }
+
+ public boolean getBoolean( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getBoolean( obj );
+ }
+
+ public byte getByte( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getByte( obj );
+ }
+
+ public char getChar( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getChar( obj );
+ }
+
+ public short getShort( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getShort( obj );
+ }
+
+ public int getInt( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getInt( obj );
+ }
+
+ public long getLong( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getLong( obj );
+ }
+
+ public float getFloat( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getFloat( obj );
+ }
+
+ public double getDouble( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return substance.getDouble( obj );
+ }
+
+ public void set( Object obj, Object value )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.set( obj, value );
+ }
+
+ public void setBoolean( Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setBoolean( obj, z );
+ }
+
+ public void setByte( Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setByte( obj, b );
+ }
+
+ public void setChar( Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setChar( obj, c );
+ }
+
+ public void setShort( Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setShort( obj, s );
+ }
+
+ public void setInt( Object obj, int i )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setInt( obj, i );
+ }
+
+ public void setLong( Object obj, long l )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setLong( obj, l );
+ }
+
+ public void setFloat( Object obj, float f )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setFloat( obj, f );
+ }
+
+ public void setDouble( Object obj, double d )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ substance.setDouble( obj, d );
+ }
+
+ /* -- methods java.lang.reflect.Field does not supply. -- */
+
+ public boolean isExecutable() {
+ return substance.isExecutable();
+ }
+
+ public boolean isAlterable() {
+ return substance.isAlterable();
+ }
+
+ public final Field getByteCode() throws CannotExecuteException {
+ return substance.getByteCode();
+ }
+
+ public final FieldDeclaration getSourceCode()
+ throws CannotAlterException
+ {
+ return substance.getSourceCode();
+ }
+
+ public OJField getCopy() {
+ /*if (isAlterable()) return substance.getCopy();*/
+ /*******************/
+ //return (FieldDeclaration) substance.clone () ;
+ try {
+
+ if (substance instanceof OJFieldByteCode) {
+ java.lang.reflect.Field field =
+ ((OJFieldByteCode)substance).getByteCode () ;
+ OJField result = (OJField)this.clone () ;
+ // On remplace du ByteCode par du SourceCode
+ FieldDeclaration fd = new FieldDeclaration (new ModifierList (field.getModifiers ()), TypeName.forOJClass (OJClass.forClass (field.getDeclaringClass ())), field.getName (), null) ;
+ Environment env = substance.getDeclaringClass ().getEnvironment () ;
+ result.substance =
+ new OJFieldSourceCode (env,
+ substance.getDeclaringClass (),
+ fd) ;
+ return result ;
+ } else if (substance instanceof OJFieldSourceCode) {
+ OJField result = (OJField)this.clone () ;
+ result.substance = new OJFieldSourceCode
+ (((OJFieldSourceCode)this.substance).getEnvironment (),
+ this.substance.getDeclaringClass (),
+ (FieldDeclaration)this.substance.getSourceCode ().
+ makeRecursiveCopy ()) ;
+ return result ;
+ }
+ } catch (Exception e) {
+ System.err.println ("Failed to copy " + this + ": " + e) ;
+ e.printStackTrace () ;
+ }
+ return null ;
+ }
+
+ /* -- inner use only -- */
+
+ public void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ substance.setDeclaringClass( parent );
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ public final void setName( String name )
+ throws CannotAlterException
+ {
+ substance.setName( name );
+ }
+
+ public final void setModifiers( int mods )
+ throws CannotAlterException
+ {
+ substance.setModifiers( mods );
+ }
+
+ public final void setModifiers( OJModifier mods )
+ throws CannotAlterException
+ {
+ setModifiers( mods.toModifier() );
+ }
+
+ public final void setType( OJClass type )
+ throws CannotAlterException
+ {
+ substance.setType( type );
+ }
+
+}
+
+
+/**
+ * The abstract class <code>OJFieldImp</code> provides an interface to
+ * an implementation of OJField.
+ */
+abstract class OJFieldImp
+{
+ public abstract String toString();
+ abstract OJClass getDeclaringClass();
+ abstract String getName();
+ abstract String getIdentifiableName();
+ abstract OJModifier getModifiers();
+ abstract OJClass getType();
+
+ abstract Object get( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract boolean getBoolean( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract byte getByte( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract char getChar( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract short getShort( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract int getInt( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract long getLong( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract float getFloat( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract double getDouble( Object obj )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void set( Object obj, Object value )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setBoolean( Object obj, boolean z )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setByte( Object obj, byte b )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setChar( Object obj, char c )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setShort( Object obj, short s )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setInt( Object obj, int i )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setLong( Object obj, long l )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setFloat( Object obj, float f )
+ throws IllegalArgumentException, IllegalAccessException;
+ abstract void setDouble( Object obj, double d )
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /* -- methods java.lang.reflect.Field does not supply. -- */
+
+ abstract boolean isExecutable();
+ abstract boolean isAlterable();
+ abstract Field getByteCode() throws CannotExecuteException;
+ abstract FieldDeclaration getSourceCode() throws CannotAlterException;
+
+ /* -- inner use only -- */
+
+ abstract void setDeclaringClass( OJClass parent )
+ throws CannotAlterException;
+
+ /* -- Translation (not overridable) -- */
+
+ abstract void setName( String name )
+ throws CannotAlterException;
+ abstract void setModifiers( int mods )
+ throws CannotAlterException;
+ abstract void setType( OJClass type )
+ throws CannotAlterException;
+
+}
+
+
+class OJFieldByteCode extends OJFieldImp
+{
+
+ private Field javaField;
+
+ OJFieldByteCode( Field f ) {
+ this.javaField = f;
+ }
+
+ public String toString() {
+ return javaField.toString();
+ }
+
+ OJClass getDeclaringClass() {
+ return OJClass.forClass( javaField.getDeclaringClass() );
+ }
+
+ String getName() {
+ return javaField.getName();
+ }
+
+ String getIdentifiableName() {
+ /***********/
+ return getDeclaringClass().getName() + "." + getName();
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forModifier( javaField.getModifiers() );
+ }
+
+ OJClass getType() {
+ return OJClass.forClass( javaField.getType() );
+ }
+
+ Object get( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.get( obj );
+ }
+
+ boolean getBoolean( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getBoolean( obj );
+ }
+
+ byte getByte( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getByte( obj );
+ }
+
+ char getChar( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getChar( obj );
+ }
+
+ short getShort( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getShort( obj );
+ }
+
+ int getInt( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getInt( obj );
+ }
+
+ long getLong( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getLong( obj );
+ }
+
+ float getFloat( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getFloat( obj );
+ }
+
+ double getDouble( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return javaField.getDouble( obj );
+ }
+
+ void set( Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.set( obj, value);
+ }
+
+ void setBoolean( Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setBoolean( obj, z);
+ }
+
+ void setByte( Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setByte( obj, b);
+ }
+
+ void setChar( Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setChar( obj, c);
+ }
+
+ void setShort( Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setShort( obj, s);
+ }
+
+ void setInt( Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setInt( obj, i);
+ }
+
+ void setLong( Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setLong( obj, l);
+ }
+
+ void setFloat( Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setFloat( obj, f);
+ }
+
+ void setDouble( Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ javaField.setDouble( obj, d);
+ }
+
+ /* -- methods java.lang.reflect.Field does not supply. -- */
+
+ final boolean isExecutable() {
+ return true;
+ }
+
+ final boolean isAlterable() {
+ return false;
+ }
+
+ final Field getByteCode() throws CannotExecuteException {
+ return javaField;
+ }
+
+ final FieldDeclaration getSourceCode() throws CannotAlterException {
+ throw new CannotAlterException( "getSourceCode()" );
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ throw new CannotAlterException( "setDeclaringClass()" );
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final void setName( String name ) throws CannotAlterException {
+ throw new CannotAlterException( "setName()" );
+ }
+
+ final void setModifiers( int mods ) throws CannotAlterException {
+ throw new CannotAlterException( "setModifiers()" );
+ }
+
+ final void setType( OJClass type ) throws CannotAlterException {
+ throw new CannotAlterException( "setType()" );
+ }
+
+}
+
+
+class OJFieldSourceCode extends OJFieldImp
+{
+
+ private static int idCounter = 0;
+ private int id;
+
+ private OJClass declarer;
+ private FieldDeclaration definition;
+ private Environment env;
+
+ OJFieldSourceCode( Environment env, OJClass declarer,
+ FieldDeclaration ptree )
+ {
+ this.declarer = declarer;
+ this.definition = ptree;
+ this.env = env;
+ this.id = idCounter++;
+ }
+
+ public String toString() {
+ OJClass declarer = getDeclaringClass();
+ String declarername = (declarer == null) ? "*" : declarer.getName();
+
+ StringBuffer buf = new StringBuffer();
+ String modif = getModifiers().toString();
+ if (! modif.equals( "" )) {
+ buf.append( modif );
+ buf.append( " " );
+ }
+ buf.append( getType().getName() );
+ buf.append( " " );
+ buf.append( declarername );
+ buf.append( "." );
+ buf.append( getName() );
+ return buf.toString();
+ }
+
+ OJClass getDeclaringClass() {
+ return declarer;
+ }
+
+ String getName() {
+ return definition.getName();
+ }
+
+ String getIdentifiableName() {
+ OJClass declarer = getDeclaringClass();
+ String declarername;
+ if (declarer == null) {
+ declarername = "*" + id;
+ } else {
+ declarername = declarer.getName();
+ }
+ return declarername + "." + getName();
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forParseTree( definition.getModifiers() );
+ }
+
+ OJClass getType() {
+ String type_name = definition.getTypeSpecifier().toString();
+ return Toolbox.forNameAnyway( env, type_name );
+ }
+
+ /**
+ * Obtains the field value specified by this field object on
+ * the given object.
+ *
+ * @exception IllegalArgumentException if this field is not
+ * compiled yet.
+ **/
+ Object get( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "get()" );
+ }
+
+ boolean getBoolean( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getBoolean()" );
+ }
+
+ byte getByte( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getByte()" );
+ }
+
+ char getChar( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getChar()" );
+ }
+
+ short getShort( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getShort()" );
+ }
+
+ int getInt( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getInt()" );
+ }
+
+ long getLong( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getLong()" );
+ }
+
+ float getFloat( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getFloat()" );
+ }
+
+ double getDouble( Object obj )
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "getDouble()" );
+ }
+
+ void set( Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "set()" );
+ }
+
+ void setBoolean( Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setBoolean()" );
+ }
+
+ void setByte( Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setByte()" );
+ }
+
+ void setChar( Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setChar()" );
+ }
+
+ void setShort( Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setShort()" );
+ }
+
+ void setInt( Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setInt()" );
+ }
+
+ void setLong( Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setLong()" );
+ }
+
+ void setFloat( Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setFloat()" );
+ }
+
+ void setDouble( Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throw new IllegalArgumentException( "setDouble()" );
+ }
+
+ /* -- methods java.lang.reflect.Field does not supply. -- */
+
+ boolean isExecutable() {
+ return false;
+ }
+
+ boolean isAlterable() {
+ return true;
+ }
+
+ final Field getByteCode() throws CannotExecuteException {
+ throw new CannotExecuteException( "getByteCode()" );
+ }
+
+ final FieldDeclaration getSourceCode()
+ throws CannotAlterException
+ {
+ return definition;
+ }
+
+ Environment getEnvironment ()
+ {
+ return this.env ;
+ }
+
+ final void setSourceCode (FieldDeclaration definition) {
+ this.definition = definition ;
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ this.declarer = parent;
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final void setName( String name ) throws CannotAlterException {
+ definition.setVariable( name );
+ }
+
+ final void setModifiers( int mods ) throws CannotAlterException {
+ definition.setModifiers( new ModifierList( mods ) );
+ }
+
+ final void setType( OJClass type ) throws CannotAlterException {
+ definition.setTypeSpecifier( TypeName.forOJClass( type ) );
+ }
+
+}
+
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJMember.java b/src/main/java/io/devnulllabs/openjava/mop/OJMember.java
new file mode 100644
index 0000000..3124f48
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJMember.java
@@ -0,0 +1,32 @@
+/*
+ * OJMember.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+
+/**
+ * The class <code>OJMember</code> is equivalent to Member
+ *
+ *
+ * @author Michiaki Tatsubori
+ * @version $Id: OJMember.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.reflect.Member
+ */
+public interface OJMember {
+ public static final int PUBLIC = 0;
+ public static final int DECLARED = 1;
+
+ public OJClass getDeclaringClass();
+ public String getName();
+ public OJModifier getModifiers();
+ public Signature signature();
+ public Environment getEnvironment();
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJMethod.java b/src/main/java/io/devnulllabs/openjava/mop/OJMethod.java
new file mode 100644
index 0000000..45e5547
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJMethod.java
@@ -0,0 +1,721 @@
+/*
+ * OJMethod.java
+ *
+ * Jul 28, 1998 by mich
+ */
+package io.devnulllabs.openjava.mop;
+
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.Variable;
+
+
+public final class OJMethod implements OJMember
+{
+ private OJMethodImp substance;
+
+ private static Hashtable table = new Hashtable();
+
+ OJMethod( Method m ) {
+ this.substance = new OJMethodByteCode( m );
+ }
+
+ /**
+ * Constructs a new <code>OJMethod</code> object.
+ * <p>
+ * This constructor automatically generates parameter variables.
+ */
+ public OJMethod( OJClass declarer, OJModifier modif, OJClass returnType,
+ String name, OJClass[] parameterTypes,
+ OJClass[] exceptionTypes, StatementList body )
+ {
+ this( declarer, modif, returnType, name,
+ Toolbox.generateParameters( parameterTypes ),
+ exceptionTypes, body );
+ }
+
+ /**
+ * Constructs a new <code>OJMethod</code> object.
+ */
+ public OJMethod( OJClass declarer, OJModifier modif, OJClass returnType,
+ String name, OJClass[] parameterTypes,
+ String[] parameterNames,
+ OJClass[] exceptionTypes, StatementList body )
+ {
+ this( declarer, modif, returnType, name,
+ Toolbox.generateParameters( parameterTypes, parameterNames ),
+ exceptionTypes, body );
+ }
+
+ /**
+ * Constructs a new <code>OJMethod</code> object.
+ */
+ public OJMethod( OJClass declarer, OJModifier modif, OJClass returnType,
+ String name, ParameterList params,
+ OJClass[] exceptionTypes, StatementList body )
+ {
+ Environment env = declarer.getEnvironment();
+ ModifierList modiflist = new ModifierList();
+ modiflist.add( modif.toModifier() );
+ MethodDeclaration d = new MethodDeclaration(
+ modiflist,
+ TypeName.forOJClass( returnType ),
+ name,
+ params,
+ Toolbox.TNsForOJClasses( exceptionTypes ),
+ body
+ );
+ this.substance = new OJMethodSourceCode( env, declarer, d );
+ }
+
+ public OJMethod( Environment env, OJClass declarer, MethodDeclaration d ) {
+ this.substance = new OJMethodSourceCode( env, declarer, d );
+ }
+
+ /**
+ * Generates a method object which has the same attributes as the
+ * model method except its body.
+ * <p>
+ * The body of generated method is to be set to null.
+ *
+ * @param original the base model for generating method object.
+ */
+ public static OJMethod makePrototype( OJMethod original ) {
+ return new OJMethod( original.getDeclaringClass(),
+ original.getModifiers(),
+ original.getReturnType(),
+ original.getName(),
+ original.getParameterTypes(),
+ original.getExceptionTypes(),
+ null
+ );
+ }
+
+ public static OJMethod forMethod( Method java_method ) {
+ if (java_method == null) return null;
+ OJMethod method = (OJMethod) table.get( java_method );
+ if (method == null) {
+ method = new OJMethod( java_method );
+ table.put( java_method, method );
+ }
+ return method;
+ }
+
+ public static OJMethod[] arrayForMethods( Method[] jmethods ) {
+ OJMethod[] result = new OJMethod[jmethods.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = forMethod( jmethods[i] );
+ }
+ return result;
+ }
+
+ public Signature signature() {
+ return new Signature( this );
+ }
+
+ public OJClass getDeclaringClass() {
+ return substance.getDeclaringClass();
+ }
+
+ public String getName() {
+ return substance.getName();
+ }
+
+ public String getIdentifiableName() {
+ return substance.getIdentifiableName();
+ }
+
+ public OJModifier getModifiers() {
+ return substance.getModifiers();
+ }
+
+ public OJClass getReturnType() {
+ return substance.getReturnType();
+ }
+
+ public OJClass[] getParameterTypes() {
+ return substance.getParameterTypes();
+ }
+
+ public OJClass[] getExceptionTypes() {
+ return substance.getExceptionTypes();
+ }
+
+ /******************/
+ public ExpressionList getParameterVariables()
+ throws CannotAlterException
+ {
+ MethodDeclaration d = getSourceCode();
+ ParameterList params = d.getParameters();
+ ExpressionList result = new ExpressionList();
+ for (int i = 0, len = params.size(); i < len; ++i) {
+ result.add( new Variable( params.get( i ).getVariable() ) );
+ }
+ return result;
+ }
+
+ public String[] getParameters()
+ throws CannotAlterException
+ {
+ MethodDeclaration d = getSourceCode();
+ ParameterList params = d.getParameters();
+ String[] result = new String[params.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = params.get( i ).getVariable().toString();
+ }
+ return result;
+ }
+
+ /**
+ * Obtains an parse tree of suffix in extended syntax starting
+ * with the specified keyword. Returned
+ * <code>io.devnulllabs.openjava.ptree.ParseTree</code> object has a structure
+ * built by an <code>io.devnulllabs.openjava.syntax.SyntaxRule</code> object
+ * returned via the method <code>getDeclSuffixRule(String)</code>.
+ *
+ * @see io.devnulllabs.openjava.mop.OJClass#getDeclSuffixRule(String)
+ * @see io.devnulllabs.openjava.syntax.SyntaxRule
+ *
+ * @return the parse tree
+ */
+ public ParseTree getSuffix( String keyword ) {
+ return substance.getSuffix( keyword );
+ }
+
+ /**
+ * Compares this method against the given object.
+ * The algorithm is borrowed by java.lang.reflect.Method.equals().
+ *
+ * @see java.lang.reflect.Method#equals
+ */
+ public boolean equals(Object obj) {
+ if (obj != null && obj instanceof OJMethod) {
+ OJMethod other = (OJMethod) obj;
+ return (getDeclaringClass() == other.getDeclaringClass())
+ && (getName().equals( other.getName() ))
+ && compareParameters( other );
+ }
+
+ return false;
+ }
+
+ private boolean compareParameters( OJMethod other ) {
+ return compareParameters( other.getParameterTypes() );
+ }
+
+ private boolean compareParameters( OJClass[] params2 ) {
+ OJClass[] params1 = getParameterTypes();
+ if (params1.length != params2.length) return false;
+ for (int i = 0; i < params1.length; ++i) {
+ if(params1[i] != params2[i]) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Computes a hashcode for this method. The algorithm is borrowed
+ * by java.lang.reflect.Method.hashCode().
+ *
+ * @see java.lang.reflect.Method#hashCode
+ */
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ public String toString() {
+ return substance.toString();
+ }
+
+ public Environment getEnvironment() {
+ return substance.getEnvironment();
+ }
+
+ /**
+ * Invokes this method on the given object with the given parameters.
+ *
+ * @exception CannotExecuteException if this method is not compiled yet.
+ */
+ public Object invoke( Object obj, Object[] args )
+ throws IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, CannotExecuteException
+ {
+ return substance.invoke( obj, args );
+ }
+
+ /* -- methods java.lang.reflect.Method does not supply. -- */
+
+ public final boolean isExecutable() {
+ return substance.isExecutable();
+ }
+
+ public final boolean isAlterable() {
+ return substance.isAlterable();
+ }
+
+ public final Method getByteCode() throws CannotExecuteException {
+ return substance.getByteCode();
+ }
+
+ public final MethodDeclaration getSourceCode()
+ throws CannotAlterException
+ {
+ return substance.getSourceCode();
+ }
+
+ public final StatementList getBody() throws CannotAlterException {
+ return substance.getBody();
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ substance.setDeclaringClass( parent );
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ public final void setName( String name ) throws CannotAlterException {
+ substance.setName( name );
+ }
+
+ public final void setModifiers( int mods ) throws CannotAlterException {
+ substance.setModifiers( mods );
+ }
+
+ public final void setModifiers( OJModifier mods )
+ throws CannotAlterException
+ {
+ setModifiers( mods.toModifier() );
+ }
+
+ public final void setReturnType( OJClass type )
+ throws CannotAlterException
+ {
+ substance.setReturnType( type );
+ }
+
+ public final void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException
+ {
+ substance.setExceptionTypes( types );
+ }
+
+ public final void addExceptionType( OJClass type )
+ throws CannotAlterException
+ {
+ OJClass[] etypes = getExceptionTypes();
+ OJClass[] result = new OJClass[etypes.length + 1];
+ System.arraycopy( etypes, 0, result, 0, etypes.length );
+ result[etypes.length] = type;
+ setExceptionTypes( result );
+ }
+
+ public final StatementList setBody( StatementList stmts )
+ throws CannotAlterException
+ {
+ return substance.setBody( stmts );
+ }
+
+}
+
+
+/**
+ * The abstract class <code>OJMethodImp</code> provides an interface to
+ * an implementation of OJMethod.
+ */
+abstract class OJMethodImp
+{
+ public abstract String toString();
+ abstract OJClass getDeclaringClass();
+ abstract String getName();
+ abstract String getIdentifiableName();
+ abstract OJModifier getModifiers();
+ abstract OJClass getReturnType();
+ abstract OJClass[] getParameterTypes();
+ abstract OJClass[] getExceptionTypes();
+ abstract ParseTree getSuffix( String keyword );
+
+ abstract Environment getEnvironment();
+
+ abstract Object invoke( Object obj, Object[] args )
+ throws IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, CannotExecuteException;
+
+ /* -- methods java.lang.reflect.Method does not supply. -- */
+
+ abstract boolean isAlterable();
+ abstract boolean isExecutable();
+ abstract Method getByteCode() throws CannotExecuteException;
+ abstract MethodDeclaration getSourceCode() throws CannotAlterException;
+ abstract StatementList getBody() throws CannotAlterException;
+
+ /* -- inner use only -- */
+
+ abstract void setDeclaringClass( OJClass parent )
+ throws CannotAlterException;
+
+ /* -- Translation (not overridable) -- */
+
+ abstract void setName( String name ) throws CannotAlterException;
+ abstract void setModifiers( int mods ) throws CannotAlterException;
+ abstract void setReturnType( OJClass type ) throws CannotAlterException;
+ abstract void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException;
+ abstract StatementList setBody( StatementList stmts )
+ throws CannotAlterException;
+
+}
+
+
+class OJMethodByteCode extends OJMethodImp
+{
+
+ private Method javaMethod = null;
+
+ OJMethodByteCode( Method java_method ) {
+ this.javaMethod = java_method;
+ }
+
+ public String toString() {
+ return javaMethod.toString();
+ }
+
+ OJClass getDeclaringClass() {
+ return OJClass.forClass( javaMethod.getDeclaringClass() );
+ }
+
+ String getName() {
+ return javaMethod.getName();
+ }
+
+ String getIdentifiableName() {
+ /***********/
+ return getDeclaringClass().getName() + "." + getName() + "()";
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forModifier( javaMethod.getModifiers() );
+ }
+
+ OJClass getReturnType() {
+ return OJClass.forClass( javaMethod.getReturnType() );
+ }
+
+ OJClass[] getParameterTypes() {
+ return OJClass.arrayForClasses( javaMethod.getParameterTypes() );
+ }
+
+ OJClass[] getExceptionTypes() {
+ return OJClass.arrayForClasses( javaMethod.getExceptionTypes() );
+ }
+
+ ParseTree getSuffix( String keyword ) {
+ return null;
+ }
+
+ Environment getEnvironment() {
+ Environment result
+ = new ClosedEnvironment( getDeclaringClass().getEnvironment() );
+ return result;
+ }
+
+ Object invoke( Object obj, Object[] args )
+ throws IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, CannotExecuteException
+ {
+ return javaMethod.invoke( obj, args );
+ }
+
+ /* -- methods java.lang.reflect.Method does not supply. -- */
+
+ boolean isAlterable() {
+ return false;
+ }
+
+ boolean isExecutable() {
+ return true;
+ }
+
+ Method getByteCode() throws CannotExecuteException {
+ return javaMethod;
+ }
+
+ MethodDeclaration getSourceCode() throws CannotAlterException {
+ throw new CannotAlterException( "getSourceCode()" );
+ }
+
+ StatementList getBody() throws CannotAlterException {
+ throw new CannotAlterException( "getBody()" );
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ throw new CannotAlterException( "setDeclaringClass()" );
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final void setName( String name ) throws CannotAlterException {
+ throw new CannotAlterException( "setName()" );
+ }
+
+ final void setModifiers( int mods ) throws CannotAlterException {
+ throw new CannotAlterException( "setModifiers()" );
+ }
+
+ final void setReturnType( OJClass type ) throws CannotAlterException {
+ throw new CannotAlterException( "setReturnType()" );
+ }
+
+ final void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException
+ {
+ throw new CannotAlterException( "setExceptionTypes()" );
+ }
+
+ StatementList setBody( StatementList stmts )
+ throws CannotAlterException
+ {
+ throw new CannotAlterException( "setBody()" );
+ }
+
+}
+
+
+class OJMethodSourceCode extends OJMethodImp
+{
+
+ private static int idCounter = 0;
+ private int id;
+
+ private OJClass declarer;
+ private MethodDeclaration definition;
+ private Environment env;
+
+ OJMethodSourceCode( Environment env, OJClass declarer,
+ MethodDeclaration ptree )
+ {
+ this.declarer = declarer;
+ this.definition = ptree;
+ this.env = env;
+ this.id = idCounter++;
+ }
+
+ public String toString() {
+ OJClass declarer = getDeclaringClass();
+ String declarername = (declarer == null) ? "*" : declarer.getName();
+
+ StringBuffer buf = new StringBuffer();
+ String modif = getModifiers().toString();
+ if (! modif.equals( "" )) {
+ buf.append( modif );
+ buf.append( " " );
+ }
+ buf.append( getReturnType().getName() );
+ buf.append( " " );
+ buf.append( declarername );
+ buf.append( "." );
+ buf.append( getName() );
+ buf.append( "(" );
+ OJClass[] paramtypes = getParameterTypes();
+ if (paramtypes.length != 0) {
+ buf.append( paramtypes[0].getName() );
+ }
+ for (int i = 1; i < paramtypes.length; ++i) {
+ buf.append( "," );
+ buf.append( paramtypes[i].getName() );
+ }
+ buf.append( ")" );
+ return buf.toString();
+ }
+
+ OJClass getDeclaringClass() {
+ return this.declarer;
+ }
+
+ String getName() {
+ return definition.getName();
+ }
+
+ String getIdentifiableName() {
+ OJClass declarer = getDeclaringClass();
+ String declarername;
+ if (declarer == null) {
+ declarername = "*" + id;
+ } else {
+ declarername = declarer.getName();
+ }
+ /***************/
+ return declarername + "." + getName() + "()";
+ }
+
+ OJModifier getModifiers() {
+ return OJModifier.forParseTree( definition.getModifiers() );
+ }
+
+ OJClass getReturnType() {
+ String type_name = definition.getReturnType().toString();
+ return Toolbox.forNameAnyway( env, type_name );
+ }
+
+ private OJClass[] ptypeCache = null;
+ private TypeName[] paramtypes = null;
+ private boolean isPtypeCacheDirty(TypeName[] paramtypes) {
+ if (ptypeCache == null) return true;
+ if (paramtypes.length != this.paramtypes.length) return true;
+ for (int i = 0; i < paramtypes.length; ++i) {
+ if (! paramtypes[i].equals(this.paramtypes[i])) return true;
+ }
+ return false;
+ }
+ private void refleshPtypeCache() {
+ ParameterList plist = definition.getParameters();
+ int psize = plist.size();
+ TypeName[] paramtypes = new TypeName[psize];
+ for (int i = 0; i < psize; ++i) {
+ paramtypes[i] = plist.get(i).getTypeSpecifier();
+ }
+ if (isPtypeCacheDirty(paramtypes)) {
+ ptypeCache = arrayForParameters(plist);
+ this.paramtypes = paramtypes;
+ }
+ }
+
+ /*
+ * This method was:
+ * return arrayForParameters(definition.getParameters());
+ * but is tuned up for time efficiency.
+ */
+ OJClass[] getParameterTypes() {
+ refleshPtypeCache();
+ OJClass[] result = new OJClass[ptypeCache.length];
+ for (int i = 0; i < result.length; ++i) result[i] = ptypeCache[i];
+ return result;
+ }
+
+ String[] getParameters() {
+ ParameterList params = definition.getParameters();
+ String[] result = new String[params.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = params.get( i ).getVariable().toString();
+ }
+ return result;
+ }
+
+ OJClass[] getExceptionTypes() {
+ return arrayForTypeNames( definition.getThrows() );
+ }
+
+ ParseTree getSuffix( String keyword ) {
+ Hashtable table = definition.getSuffixes();
+ if (table == null) return null;
+ return (ParseTree) table.get( keyword );
+ }
+
+ private final OJClass[] arrayForParameters( ParameterList params ) {
+ OJClass[] result = new OJClass[params.size()];
+ for (int i = 0; i < result.length; ++i) {
+ String tname = params.get( i ).getTypeSpecifier().toString();
+ result[i] = Toolbox.forNameAnyway( env, tname );
+ }
+ return result;
+ }
+
+ private final OJClass[] arrayForTypeNames( TypeName[] typenames ) {
+ OJClass[] result = new OJClass[typenames.length];
+ for (int i = 0; i < result.length; ++i) {
+ String tname = typenames[i].toString();
+ result[i] = Toolbox.forNameAnyway( env, tname );
+ }
+ return result;
+ }
+
+ Environment getEnvironment() {
+ Environment result
+ = new ClosedEnvironment( getDeclaringClass().getEnvironment() );
+ OJClass[] ptypes = getParameterTypes();
+ String[] pvars = getParameters();
+ for (int i = 0; i < ptypes.length; ++i) {
+ result.bindVariable( pvars[i], ptypes[i] );
+ }
+ return result;
+ }
+
+ /**
+ * Invokes this method on the given object with the given parameters.
+ *
+ * @exception CannotExecuteException if this method is not compiled yet.
+ */
+ Object invoke( Object obj, Object[] args )
+ throws IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, CannotExecuteException
+ {
+ throw new CannotExecuteException( "invoke()" );
+ }
+
+ /* -- methods java.lang.reflect.Method does not supply. -- */
+
+ boolean isAlterable() {
+ return true;
+ }
+
+ boolean isExecutable() {
+ return false;
+ }
+
+ Method getByteCode() throws CannotExecuteException {
+ throw new CannotExecuteException( "getByteCode()" );
+ }
+
+ MethodDeclaration getSourceCode() throws CannotAlterException {
+ return definition;
+ }
+
+ StatementList getBody() throws CannotAlterException {
+ return definition.getBody();
+ }
+
+ /* -- inner use only -- */
+
+ void setDeclaringClass( OJClass parent ) throws CannotAlterException {
+ this.declarer = parent;
+ }
+
+ /* -- Translation (not overridable) -- */
+
+ final void setName( String name ) throws CannotAlterException {
+ definition.setName( name );
+ }
+
+ final void setModifiers( int mods ) throws CannotAlterException {
+ definition.setModifiers( new ModifierList( mods ) );
+ }
+
+ final void setReturnType( OJClass type ) throws CannotAlterException {
+ definition.setReturnType( TypeName.forOJClass( type ) );
+ }
+
+ final void setExceptionTypes( OJClass[] types )
+ throws CannotAlterException
+ {
+ definition.setThrows( Toolbox.TNsForOJClasses( types ) );
+ }
+
+ StatementList setBody( StatementList stmts ) throws CannotAlterException {
+ StatementList result = definition.getBody();
+ definition.setBody( stmts );
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJModifier.java b/src/main/java/io/devnulllabs/openjava/mop/OJModifier.java
new file mode 100644
index 0000000..7d2cd45
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJModifier.java
@@ -0,0 +1,246 @@
+/*
+ * OJModifier.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+import java.lang.reflect.Modifier;
+
+import io.devnulllabs.openjava.ptree.ModifierList;
+
+/**
+ * The class <code>OJModifier</code> extends
+ * <code>java.lang.relfect.Modifier</code> to support user defined
+ * keywords.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.reflect.Modifier
+ **/
+public class OJModifier {
+ /*
+ * Access modifier flag constants from <em>The Java Virtual
+ * Machine Specification</em>, Table 4.1.
+ */
+ public static final int PUBLIC = Modifier.PUBLIC;
+ public static final int PRIVATE = Modifier.PRIVATE;
+ public static final int PROTECTED = Modifier.PROTECTED;
+ public static final int STATIC = Modifier.STATIC;
+ public static final int FINAL = Modifier.FINAL;
+ public static final int SYNCHRONIZED = Modifier.SYNCHRONIZED;
+ public static final int VOLATILE = Modifier.VOLATILE;
+ public static final int TRANSIENT = Modifier.TRANSIENT;
+ public static final int NATIVE = Modifier.NATIVE;
+ public static final int INTERFACE = Modifier.INTERFACE;
+ public static final int ABSTRACT = Modifier.ABSTRACT;
+
+ private int javaModifier = 0;
+ private String userModifiers[] = null;
+
+ private static OJModifier _constantEmpty = null;
+
+ OJModifier(int mod) {
+ javaModifier = mod;
+ userModifiers = new String[0];
+ }
+
+ OJModifier(int mod, String[] user_modifs) {
+ javaModifier = mod;
+ userModifiers = user_modifs;
+ }
+
+ public static final OJModifier constantEmpty() {
+ if (_constantEmpty == null)
+ _constantEmpty = new OJModifier(0);
+ return _constantEmpty;
+ }
+
+ /**
+ * Returns the specifier int for modifiers in regular Java.
+ *
+ * @return integer specifier
+ * @see java.lang.reflect.Modifier
+ */
+ public int toModifier() {
+ return javaModifier;
+ }
+
+ public static OJModifier forModifier(int mod) {
+ return new OJModifier(mod);
+ }
+
+ public static OJModifier forParseTree(ModifierList ptree) {
+ int regular_modifs = ptree.getRegular();
+ String[] oj_modifs = new String[ptree.size()];
+ for (int i = 0; i < ptree.size(); ++i) {
+ oj_modifs[i] = ptree.get(i);
+ }
+ return new OJModifier(regular_modifs, oj_modifs);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>public</tt>
+ * modifier.
+ */
+ public final boolean isPublic() {
+ return ((javaModifier & PUBLIC) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>private</tt>
+ * modifier.
+ */
+ public final boolean isPrivate() {
+ return ((javaModifier & PRIVATE) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>protected</tt>
+ * modifier.
+ */
+ public final boolean isProtected() {
+ return ((javaModifier & PROTECTED) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>static</tt>
+ * modifier.
+ */
+ public final boolean isStatic() {
+ return ((javaModifier & STATIC) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>final</tt>
+ * modifier.
+ */
+ public final boolean isFinal() {
+ return ((javaModifier & FINAL) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>synchronized</tt>
+ * modifier.
+ */
+ public final boolean isSynchronized() {
+ return ((javaModifier & SYNCHRONIZED) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>volatile</tt>
+ * modifier.
+ */
+ public final boolean isVolatile() {
+ return ((javaModifier & VOLATILE) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>transient</tt>
+ * modifier.
+ */
+ public final boolean isTransient() {
+ return ((javaModifier & TRANSIENT) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>native</tt>
+ * modifier.
+ */
+ public final boolean isNative() {
+ return ((javaModifier & NATIVE) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>interface</tt>
+ * modifier.
+ */
+ public final boolean isInterface() {
+ return ((javaModifier & INTERFACE) != 0);
+ }
+
+ /**
+ * Returns true if this modifier includes the <tt>abstract</tt>
+ * modifier.
+ */
+ public final boolean isAbstract() {
+ return ((javaModifier & ABSTRACT) != 0);
+ }
+
+ /**
+ *
+ */
+ public final boolean has(String str) {
+ for (int i = 0; i < userModifiers.length; ++i) {
+ if (userModifiers[i].equals(str))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Generates a string describing the access modifier flags
+ * without user modifiers.
+ * For example:
+ * <pre>
+ * public final synchronized
+ * private transient volatile
+ * </pre>
+ * The modifier names are return in canonical order, as
+ * specified by <em>The Java Language Specification<em>.
+ */
+ public String toString() {
+ return Modifier.toString(javaModifier);
+ }
+
+ private static final int ACCESS = PUBLIC | PROTECTED | PRIVATE;
+ private static final int INHERIT = ABSTRACT | FINAL;
+
+ public OJModifier add(int mods) {
+ if ((mods & ACCESS) != 0) {
+ return new OJModifier(removedModifier(ACCESS) | mods);
+ }
+ return new OJModifier(toModifier() | mods);
+ }
+
+ public OJModifier remove(int mods) {
+ return new OJModifier(removedModifier(mods));
+ }
+
+ private final int removedModifier(int mods) {
+ int toBeRemoved = this.toModifier() & mods;
+ return this.toModifier() - toBeRemoved;
+ }
+
+ public OJModifier setPublic() {
+ return new OJModifier(removedModifier(ACCESS) | PUBLIC);
+ }
+
+ public OJModifier setProtected() {
+ return new OJModifier(removedModifier(ACCESS) | PROTECTED);
+ }
+
+ public OJModifier setPrivate() {
+ return new OJModifier(removedModifier(ACCESS) | PRIVATE);
+ }
+
+ public OJModifier setPackaged() {
+ return new OJModifier(removedModifier(ACCESS));
+ }
+
+ public OJModifier setAbstract() {
+ return new OJModifier(removedModifier(INHERIT) | ABSTRACT);
+ }
+
+ public OJModifier setFinal() {
+ return new OJModifier(removedModifier(INHERIT) | FINAL);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJPrimitive.java b/src/main/java/io/devnulllabs/openjava/mop/OJPrimitive.java
new file mode 100644
index 0000000..4430acc
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJPrimitive.java
@@ -0,0 +1,37 @@
+/*
+ * OJPrimitive.java
+ *
+ * Now deprecated and replaced with io.devnulllabs.openjava.mop.OJSystem.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+/**
+ * The class <code>OJPrimitive</code>
+ * <p>
+ * Now deprecated and is replaced with io.devnulllabs.openjava.mop.OJSystem.
+ * <p>
+ *
+ * @deprecated
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: OJPrimitive.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see io.devnulllabs.openjava.mop.OJSystem
+ */
+public abstract class OJPrimitive {
+ public static final OJClass VOID = OJClass.forClass(void.class);
+ public static final OJClass BYTE = OJClass.forClass(byte.class);
+ public static final OJClass CHAR = OJClass.forClass(char.class);
+ public static final OJClass INT = OJClass.forClass(int.class);
+ public static final OJClass LONG = OJClass.forClass(long.class);
+ public static final OJClass FLOAT = OJClass.forClass(float.class);
+ public static final OJClass DOUBLE = OJClass.forClass(double.class);
+ public static final OJClass STRING = OJClass.forClass(String.class);
+ public static final OJClass OBJECT = OJClass.forClass(Object.class);
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/OJSystem.java b/src/main/java/io/devnulllabs/openjava/mop/OJSystem.java
new file mode 100644
index 0000000..ec97705
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/OJSystem.java
@@ -0,0 +1,218 @@
+/*
+ * OJSystem.java
+ *
+ * System environments.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import io.devnulllabs.openjava.ojc.JavaCompiler;
+import io.devnulllabs.openjava.tools.DebugOut;
+import io.devnulllabs.openjava.tools.parser.ParseException;
+
+/**
+ * The class <code>OJSystem</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: OJSystem.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class OJSystem {
+ /** class object for primitive type boolean */
+ public static OJClass BOOLEAN;
+ /** class object for primitive type byte */
+ public static OJClass BYTE;
+ /** class object for primitive type char */
+ public static OJClass CHAR;
+ /** class object for primitive type short */
+ public static OJClass SHORT;
+ /** class object for primitive type int */
+ public static OJClass INT;
+ /** class object for primitive type long */
+ public static OJClass LONG;
+ /** class object for primitive type float */
+ public static OJClass FLOAT;
+ /** class object for primitive type double */
+ public static OJClass DOUBLE;
+ /** class object for primitive type void */
+ public static OJClass VOID;
+
+ /** class object for java.lang.String */
+ public static OJClass STRING;
+ /** class object for java.lang.Object */
+ public static OJClass OBJECT;
+
+ /** class object for type of null literal */
+ public static OJClass NULLTYPE;
+
+ /** inner use only */
+ public static final void initConstants() {
+ BOOLEAN = OJClass.forClass(boolean.class);
+ BYTE = OJClass.forClass(byte.class);
+ CHAR = OJClass.forClass(char.class);
+ SHORT = OJClass.forClass(short.class);
+ INT = OJClass.forClass(int.class);
+ LONG = OJClass.forClass(long.class);
+ FLOAT = OJClass.forClass(float.class);
+ DOUBLE = OJClass.forClass(double.class);
+ VOID = OJClass.forClass(void.class);
+
+ STRING = OJClass.forClass(String.class);
+ OBJECT = OJClass.forClass(Object.class);
+
+ NULLTYPE = new OJClass();
+ env.record(NULLTYPE_NAME, NULLTYPE);
+ }
+
+ /**
+ * The system dependent newline string.
+ */
+ public static String NextLineChar;
+ static {
+ StringWriter strw = new StringWriter();
+ PrintWriter pw = new PrintWriter(strw);
+ pw.println();
+ pw.close();
+ NextLineChar = strw.toString();
+ }
+
+ /**
+ * The type name for null.
+ */
+ public static final String NULLTYPE_NAME = "<type>null";
+
+ /**
+ * The global system environment for all public classes.
+ */
+ public static final GlobalEnvironment env = new GlobalEnvironment();
+
+ private static final Vector additionalClasses = new Vector();
+
+ /**
+ * Adds an new public class to be generated.
+ */
+ public static void addNewClass(OJClass clazz) throws MOPException {
+ additionalClasses.addElement(clazz);
+ OJSystem.env.record(clazz.getName(), clazz);
+ }
+
+ /* internal uses */
+
+ private static JavaCompiler javac = null;
+
+ /** internal use only */
+ public static JavaCompiler getJavaCompiler() {
+ return javac;
+ }
+
+ /** internal use only */
+ public static void setJavaCompiler(JavaCompiler c) {
+ javac = c;
+ }
+
+ /** internal use only */
+ public static OJClass[] addedClasses() {
+ OJClass[] result = new OJClass[additionalClasses.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (OJClass) additionalClasses.elementAt(i);
+ }
+ return result;
+ }
+
+ private static Hashtable table = new Hashtable();
+ /** internal use only */
+ public static void metabind(String clazz, String metaclazz)
+ throws ParseException {
+ /* null - default */
+ if (metaclazz == null) {
+ if (table.get(clazz) != null)
+ return;
+ metaclazz = "io.devnulllabs.openjava.mop.OJClass";
+ }
+ Class c;
+ try {
+ c = Class.forName(metaclazz);
+ } catch (ClassNotFoundException e) {
+ throw new ParseException(e.toString());
+ }
+ DebugOut.println("class " + clazz + " : " + metaclazz);
+ table.put(clazz, c);
+ }
+ /** internal use only */
+ public static Class getMetabind(String clazz) {
+ Class result = searchMetaclassInTable(clazz);
+ if (result == null)
+ result = OJClass.class;
+ return result;
+ }
+
+ private static Class searchMetaclassInTable(String clazz) {
+ /* exactly specified name */ {
+ Class result = (Class) table.get(clazz);
+ if (result != null)
+ return result;
+ }
+ /* a name specified using "*" (all classes in a package)
+ * More specific indication has more priority.
+ * e.g. "java.lang.*" is stronger than "java.*"
+ */ {
+ Class result = (Class) table.get(toPackageSuffix(clazz) + "*");
+ if (result != null)
+ return result;
+ }
+ /* a name specified using "-" (all subpackages)
+ * More specific indication has more priority.
+ * e.g. "java.lang.-" is stronger than "java.-"
+ */ {
+ Class result = (Class) table.get(toPackageSuffix(clazz) + "-");
+ if (result != null)
+ return result;
+ }
+ for (String pack = toPackage(clazz);
+ pack != null;
+ pack = toPackage(pack)) {
+ Class result = (Class) table.get(toPackageSuffix(pack) + "-");
+ if (result != null)
+ return result;
+ }
+ /* nothing found */
+ return null;
+ }
+ /* returns "java.lang." for "java.lang.String" and "" for "String" */
+ private static String toPackageSuffix(String classname) {
+ int pack = classname.lastIndexOf(".") + 1;
+ return classname.substring(0, pack);
+ }
+ /* returns "java.lang" for "java.lang.String" and null for "String" */
+ private static String toPackage(String classname) {
+ int pack = classname.lastIndexOf(".");
+ if (pack == -1)
+ return null;
+ return classname.substring(0, pack);
+ }
+
+ /** internal use only */
+ public static Object orderingLock;
+ /** internal use only */
+ public static OJClass waited = null;
+ /** internal use only */
+ public static final Hashtable underConstruction = new Hashtable();
+ /** internal use only */
+ public static final Vector waitingPool = new Vector();
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/Signature.java b/src/main/java/io/devnulllabs/openjava/mop/Signature.java
new file mode 100644
index 0000000..1b7df83
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/Signature.java
@@ -0,0 +1,249 @@
+/*
+ * Signature.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+/**
+ * The class <code>Signature</code> represents a signature of members of
+ * class; innerclass, field, method, or constructor.
+ * <p>
+ * Objects are immutable.
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: Signature.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class Signature {
+ public static final int CLASS = 0;
+ public static final int FIELD = 1;
+ public static final int METHOD = 2;
+ public static final int CONSTRUCTOR = 3;
+
+ private int _kind;
+
+ private OJClass _returnType;
+ private String _name;
+ private OJClass[] _parameters;
+
+ public Signature(String name) {
+ _kind = FIELD;
+ /*_returnType = null;*/
+ _name = name;
+ _parameters = null;
+ }
+
+ public Signature(String name, OJClass[] paramtypes) {
+ if (paramtypes == null)
+ paramtypes = new OJClass[0];
+ _kind = METHOD;
+ _returnType = null;
+ _name = name;
+ _parameters = (OJClass[]) paramtypes.clone();
+ }
+
+ public Signature(OJClass[] paramtypes) {
+ if (paramtypes == null)
+ paramtypes = new OJClass[0];
+ _kind = CONSTRUCTOR;
+ _returnType = null;
+ _name = null;
+ _parameters = (OJClass[]) paramtypes.clone();
+ }
+
+ public Signature(OJClass clazz) {
+ _kind = CLASS;
+ /*_returnType = null;*/
+ _name = clazz.getName();
+ _parameters = null;
+ }
+
+ public Signature(OJField field) {
+ _kind = FIELD;
+ /*_returnType = field.getType();*/
+ _name = field.getName();
+ _parameters = null;
+ }
+
+ public Signature(OJMethod method) {
+ _kind = METHOD;
+ /*_returnType = method.getReturnType();*/
+ _name = method.getName();
+ _parameters = (OJClass[]) method.getParameterTypes().clone();
+ }
+
+ public Signature(OJConstructor constructor) {
+ _kind = CONSTRUCTOR;
+ /*_returnType = null;*/
+ _name = null;
+ _parameters = (OJClass[]) constructor.getParameterTypes().clone();
+ }
+
+ protected OJClass[] parameterTypes() {
+ return _parameters;
+ }
+
+ public int kind() {
+ return _kind;
+ }
+
+ /**
+ * Returns the <code>String</code> representation of this signature.
+ *
+ * @return the string representation of this signature.
+ */
+ public String toString() {
+ if (strCache == null)
+ strCache = getStringValue();
+ return strCache;
+ }
+
+ private String strCache = null;
+
+ private String getStringValue() {
+ StringBuffer buf = new StringBuffer();
+ switch (kind()) {
+ case CLASS :
+ buf.append("class ");
+ buf.append(getName());
+ break;
+ case FIELD :
+ buf.append("field ");
+ buf.append(getName());
+ break;
+ case METHOD :
+ buf.append("method ");
+ buf.append(getName());
+ buf.append("(");
+ if (parameterTypes().length != 0) {
+ buf.append(parameterTypes()[0]);
+ }
+ for (int i = 1; i < parameterTypes().length; ++i) {
+ buf.append(",");
+ buf.append(parameterTypes()[i].toString());
+ }
+ buf.append(")");
+ break;
+ case CONSTRUCTOR :
+ buf.append("constructor ");
+ buf.append("(");
+ if (parameterTypes().length != 0) {
+ buf.append(parameterTypes()[0]);
+ }
+ for (int i = 1; i < parameterTypes().length; ++i) {
+ buf.append(",");
+ buf.append(parameterTypes()[i].toString());
+ }
+ buf.append(")");
+ break;
+ }
+ return buf.toString();
+ }
+
+ public int hashCode() {
+ if (hashCodeCache == -1)
+ hashCodeCache = toString().hashCode();
+ return hashCodeCache;
+ }
+
+ private int hashCodeCache = -1;
+
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+ if (!(obj instanceof Signature))
+ return false;
+ return toString().equals(obj.toString());
+ }
+
+ private OJClass getReturnType() {
+ return _returnType;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public OJClass[] getParameterTypes() {
+ if (parameterTypes() == null)
+ return null;
+ return (OJClass[]) parameterTypes().clone();
+ }
+
+ public boolean equals(Signature sign) {
+ if (sign == null)
+ return false;
+ if (this.kind() != sign.kind())
+ return false;
+ switch (kind()) {
+ case CLASS :
+ return false;
+ case FIELD :
+ return false;
+ case METHOD :
+ return false;
+ case CONSTRUCTOR :
+ return compareParams(sign.parameterTypes());
+ }
+ return false;
+ }
+
+ public boolean strictlyEquals(Signature sign) {
+ /*********/
+ if (this == sign)
+ return true;
+ return false;
+ }
+
+ private final boolean compareParams(OJClass[] params) {
+ if (params == null)
+ return false;
+ if (parameterTypes().length != params.length)
+ return false;
+ for (int i = 0; i < params.length; ++i) {
+ if (parameterTypes()[i] != params[i])
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isClass() {
+ return (kind() == CLASS);
+ }
+ public boolean isConstructor() {
+ return (kind() == CONSTRUCTOR);
+ }
+ public boolean isField() {
+ return (kind() == FIELD);
+ }
+ public boolean isMethod() {
+ return (kind() == METHOD);
+ }
+
+ public static OJClass commonBaseType(OJClass a, OJClass b) {
+ if (a.isAssignableFrom(b))
+ return a;
+ if (b.isAssignableFrom(a))
+ return b;
+ return commonBaseType(a.getSuperclass(), b.getSuperclass());
+ }
+
+ public static OJClass[] commonBaseTypes(OJClass[] a, OJClass b[]) {
+ OJClass[] result = new OJClass[a.length];
+ for (int i = 0; i < a.length; ++i) {
+ result[i] = commonBaseType(a[i], b[i]);
+ }
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/Toolbox.java b/src/main/java/io/devnulllabs/openjava/mop/Toolbox.java
new file mode 100644
index 0000000..c278296
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/Toolbox.java
@@ -0,0 +1,912 @@
+/*
+ * Toolbox.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.mop;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+/**
+ * The class <code>Toolbox</code> is an utility class.
+ * <p>
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version $Id: Toolbox.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ */
+public abstract class Toolbox {
+ /**
+ * Generates an array of classes containing the declared classes and
+ * the based classes except the declared one.
+ *
+ * @param declareds declared classes to override
+ * @param bases based classes.
+ * @return classes which contains the declared classes and the based
+ * classes except the declared one.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJClass[] overridesOn(
+ OJClass[] declareds,
+ OJClass[] bases) {
+ Hashtable table = new Hashtable();
+ for (int i = 0; i < bases.length; ++i) {
+ table.put(bases[i].signature(), bases[i]);
+ }
+ for (int i = 0; i < declareds.length; ++i) {
+ table.put(declareds[i].signature(), declareds[i]);
+ }
+
+ OJClass[] result = new OJClass[table.size()];
+ Enumeration it = table.elements();
+ for (int i = 0; it.hasMoreElements(); ++i) {
+ result[i] = (OJClass) it.nextElement();
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of fields containing the declared fields and
+ * the based fields except the declared one.
+ *
+ * @param declareds declared fields to override
+ * @param bases based fields.
+ * @return fields which contains the declared fields and the based
+ * fields except the declared one.
+ * @see io.devnulllabs.openjava.mop.OJField
+ */
+ public static final OJField[] overridesOn(
+ OJField[] declareds,
+ OJField[] bases) {
+ Hashtable table = new Hashtable();
+ for (int i = 0; i < bases.length; ++i) {
+ table.put(bases[i].signature(), bases[i]);
+ }
+ for (int i = 0; i < declareds.length; ++i) {
+ table.put(declareds[i].signature(), declareds[i]);
+ }
+
+ OJField[] result = new OJField[table.size()];
+ Enumeration it = table.elements();
+ for (int i = 0; it.hasMoreElements(); ++i) {
+ result[i] = (OJField) it.nextElement();
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of methods containing the declared methods and
+ * the based methods except the declared one.
+ *
+ * @param declareds declared methods to override
+ * @param bases based methods.
+ * @return methods which contains the declared methods and the based
+ * methods except the declared one.
+ * @see io.devnulllabs.openjava.mop.OJMethod
+ */
+ public static final OJMethod[] overridesOn(
+ OJMethod[] declareds,
+ OJMethod[] bases) {
+ Hashtable table = new Hashtable();
+ for (int i = 0; i < bases.length; ++i) {
+ table.put(bases[i].signature(), bases[i]);
+ }
+ for (int i = 0; i < declareds.length; ++i) {
+ table.put(declareds[i].signature(), declareds[i]);
+ }
+
+ OJMethod[] result = new OJMethod[table.size()];
+ Enumeration it = table.elements();
+ for (int i = 0; it.hasMoreElements(); ++i) {
+ result[i] = (OJMethod) it.nextElement();
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of classes containing the source classes
+ * except ones with private access modifier.
+ *
+ * @param src_classes source classes.
+ * @return classes except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJClass[] removeThePrivates(OJClass[] src_classes) {
+ int dest_length = 0;
+ for (int i = 0; i < src_classes.length; ++i) {
+ OJModifier modif = src_classes[i].getModifiers();
+ if (!modif.isPrivate())
+ dest_length++;
+ }
+
+ OJClass[] result = new OJClass[dest_length];
+ for (int i = 0, count = 0; i < src_classes.length; ++i) {
+ OJModifier modif = src_classes[i].getModifiers();
+ if (!modif.isPrivate())
+ result[count++] = src_classes[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of fields containing the source fields
+ * except ones with private access modifier.
+ *
+ * @param src_fields source fields.
+ * @return fields except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJField[] removeThePrivates(OJField[] src_fields) {
+ int dest_length = 0;
+ for (int i = 0; i < src_fields.length; ++i) {
+ OJModifier modif = src_fields[i].getModifiers();
+ if (!modif.isPrivate())
+ dest_length++;
+ }
+
+ OJField[] result = new OJField[dest_length];
+ for (int i = 0, count = 0; i < src_fields.length; ++i) {
+ OJModifier modif = src_fields[i].getModifiers();
+ if (!modif.isPrivate())
+ result[count++] = src_fields[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of methods containing the source methods
+ * except ones with private access modifier.
+ *
+ * @param src_methods source methods.
+ * @return methods except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJMethod[] removeThePrivates(OJMethod[] src_methods) {
+ int dest_length = 0;
+ for (int i = 0; i < src_methods.length; ++i) {
+ OJModifier modif = src_methods[i].getModifiers();
+ if (!modif.isPrivate())
+ dest_length++;
+ }
+
+ OJMethod[] result = new OJMethod[dest_length];
+ for (int i = 0, count = 0; i < src_methods.length; ++i) {
+ OJModifier modif = src_methods[i].getModifiers();
+ if (!modif.isPrivate())
+ result[count++] = src_methods[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of constructors containing the source
+ * constructors except ones with private access modifier.
+ *
+ * @param src_constrs source constructors.
+ * @return constructors except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJConstructor[] removeThePrivates(OJConstructor[] src_constrs) {
+ int dest_length = 0;
+ for (int i = 0; i < src_constrs.length; ++i) {
+ OJModifier modif = src_constrs[i].getModifiers();
+ if (!modif.isPrivate())
+ dest_length++;
+ }
+
+ OJConstructor[] result = new OJConstructor[dest_length];
+ for (int i = 0, count = 0; i < src_constrs.length; ++i) {
+ OJModifier modif = src_constrs[i].getModifiers();
+ if (!modif.isPrivate())
+ result[count++] = src_constrs[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of classes containing the source classes
+ * except ones with private access modifier.
+ *
+ * @param src_classes source classes.
+ * @return classes except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJClass[] removeTheDefaults(OJClass[] src_classes) {
+ int dest_length = 0;
+ for (int i = 0; i < src_classes.length; ++i) {
+ OJModifier modif = src_classes[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ dest_length++;
+ }
+ }
+
+ OJClass[] result = new OJClass[dest_length];
+ for (int i = 0, count = 0; i < src_classes.length; ++i) {
+ OJModifier modif = src_classes[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ result[count++] = src_classes[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of fields containing the source fields
+ * except ones with private access modifier.
+ *
+ * @param src_fields source fields.
+ * @return fields except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJField[] removeTheDefaults(OJField[] src_fields) {
+ int dest_length = 0;
+ for (int i = 0; i < src_fields.length; ++i) {
+ OJModifier modif = src_fields[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ dest_length++;
+ }
+ }
+
+ OJField[] result = new OJField[dest_length];
+ for (int i = 0, count = 0; i < src_fields.length; ++i) {
+ OJModifier modif = src_fields[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ result[count++] = src_fields[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of methods containing the source methods
+ * except ones with private access modifier.
+ *
+ * @param src_methods source methods.
+ * @return methods except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJMethod[] removeTheDefaults(OJMethod[] src_methods) {
+ int dest_length = 0;
+ for (int i = 0; i < src_methods.length; ++i) {
+ OJModifier modif = src_methods[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ dest_length++;
+ }
+ }
+
+ OJMethod[] result = new OJMethod[dest_length];
+ for (int i = 0, count = 0; i < src_methods.length; ++i) {
+ OJModifier modif = src_methods[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ result[count++] = src_methods[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of constructors containing the source
+ * constructors except ones with private access modifier.
+ *
+ * @param src_constrs source constructors.
+ * @return constructors except ones with private access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJConstructor[] removeTheDefaults(OJConstructor[] src_constrs) {
+ int dest_length = 0;
+ for (int i = 0; i < src_constrs.length; ++i) {
+ OJModifier modif = src_constrs[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ dest_length++;
+ }
+ }
+
+ OJConstructor[] result = new OJConstructor[dest_length];
+ for (int i = 0, count = 0; i < src_constrs.length; ++i) {
+ OJModifier modif = src_constrs[i].getModifiers();
+ if (modif.isPrivate() || modif.isProtected() || modif.isPublic()) {
+ result[count++] = src_constrs[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of classes containing the source classes
+ * except ones with non-public access modifier;
+ * one of private, protected or package level access modifiers.
+ *
+ * @param src_classes source classes.
+ * @return classes except ones with non-public access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJClass[] removeTheNonPublics(OJClass[] src_classes) {
+ int dest_length = 0;
+ for (int i = 0; i < src_classes.length; ++i) {
+ OJModifier modif = src_classes[i].getModifiers();
+ if (modif.isPublic())
+ dest_length++;
+ }
+
+ OJClass[] result = new OJClass[dest_length];
+ for (int i = 0, count = 0; i < src_classes.length; ++i) {
+ OJModifier modif = src_classes[i].getModifiers();
+ if (modif.isPublic())
+ result[count++] = src_classes[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of fields containing the source fields
+ * except ones with non-public access modifier;
+ * one of private, protected or package level access modifiers.
+ *
+ * @param src_fields source fields.
+ * @return fields except ones with non-public access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJField[] removeTheNonPublics(OJField[] src_fields) {
+ int dest_length = 0;
+ for (int i = 0; i < src_fields.length; ++i) {
+ OJModifier modif = src_fields[i].getModifiers();
+ if (modif.isPublic())
+ dest_length++;
+ }
+
+ OJField[] result = new OJField[dest_length];
+ for (int i = 0, count = 0; i < src_fields.length; ++i) {
+ OJModifier modif = src_fields[i].getModifiers();
+ if (modif.isPublic())
+ result[count++] = src_fields[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of methods containing the source methods
+ * except ones with non-public access modifier;
+ * one of private, protected or package level access modifiers.
+ *
+ * @param src_methods source methods.
+ * @return methods except ones with non-public access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJMethod[] removeTheNonPublics(OJMethod[] src_methods) {
+ int dest_length = 0;
+ for (int i = 0; i < src_methods.length; ++i) {
+ OJModifier modif = src_methods[i].getModifiers();
+ if (modif.isPublic())
+ dest_length++;
+ }
+
+ OJMethod[] result = new OJMethod[dest_length];
+ for (int i = 0, count = 0; i < src_methods.length; ++i) {
+ OJModifier modif = src_methods[i].getModifiers();
+ if (modif.isPublic())
+ result[count++] = src_methods[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of constructors containing the source constructors
+ * except ones with non-public access modifier;
+ * one of private, protected or package level access modifiers.
+ *
+ * @param src_constrs source constructors.
+ * @return constructors except ones with non-public access modifier.
+ * @see io.devnulllabs.openjava.mop.OJModifier
+ */
+ public static final OJConstructor[] removeTheNonPublics(OJConstructor[] src_constrs) {
+ int dest_length = 0;
+ for (int i = 0; i < src_constrs.length; ++i) {
+ OJModifier modif = src_constrs[i].getModifiers();
+ if (modif.isPublic())
+ dest_length++;
+ }
+
+ OJConstructor[] result = new OJConstructor[dest_length];
+ for (int i = 0, count = 0; i < src_constrs.length; ++i) {
+ OJModifier modif = src_constrs[i].getModifiers();
+ if (modif.isPublic())
+ result[count++] = src_constrs[i];
+ }
+
+ return result;
+ }
+
+ /**
+ * Pick up a field with the specified name in the source array
+ * of fields.
+ *
+ * @param src_constrs source fields.
+ * @param name a name to specify.
+ * @return a field with the specified name.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJField pickupField(
+ OJField[] src_fields,
+ String name) {
+ for (int i = 0; i < src_fields.length; ++i) {
+ if (name.equals(src_fields[i].getName())) {
+ return src_fields[i];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Pick up a method with the specified signature in the source
+ * array of methods.
+ *
+ * @param src_methods source methods.
+ * @param name a name to specify.
+ * @param param_types parameter types to specify.
+ * @return a method with the specified signature.
+ * This returns null if it doesn't exist.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJMethod pickupMethod(
+ OJMethod[] src_methods,
+ String name,
+ OJClass[] param_types) {
+ src_methods = pickupMethodsByName(src_methods, name);
+ return pickupMethodByParameterTypes(src_methods, param_types);
+ }
+
+ /**
+ * Pick up a method with the signature acceptable the specified
+ * signature in the source array of methods.
+ *
+ * @param src_constrs source methods.
+ * @param name a name to specify.
+ * @param param_types parameter types to specify.
+ * @return a method with the specified signature.
+ * This returns null if it doesn't exist.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJMethod pickupAcceptableMethod(
+ OJMethod[] src_methods,
+ String name,
+ OJClass[] param_types) {
+ src_methods = pickupAcceptableMethods(src_methods, name, param_types);
+ return pickupMostSpecified(src_methods);
+ }
+
+ /**
+ * Generates an array of methods containing the methods with the
+ * signature acceptable the specified signature in the source
+ * array of methods.
+ *
+ * @param src_methods source methods.
+ * @param name a name to specify.
+ * @param param_types parameter types to specify.
+ * @return methods with the specified signature.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJMethod[] pickupAcceptableMethods(
+ OJMethod[] src_methods,
+ String name,
+ OJClass[] param_types) {
+ src_methods = pickupMethodsByName(src_methods, name);
+ return pickupAcceptableMethodsByParameterTypes(
+ src_methods,
+ param_types);
+ }
+
+ /**
+ * Pick up a constructor with the specified signature in the source
+ * array of constructors.
+ *
+ * @param src_constrs source constructors.
+ * @param name a name to specify.
+ * @param param_types parameter types to specify.
+ * @return a Constructor with the specified signature.
+ * This returns null if it doesn't exist.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJConstructor pickupConstructor(
+ OJConstructor[] src_constrs,
+ OJClass[] param_types) {
+ if (param_types == null)
+ param_types = new OJClass[0];
+ for (int i = 0; i < src_constrs.length; ++i) {
+ OJClass[] accepter = src_constrs[i].getParameterTypes();
+ if (isSame(accepter, param_types))
+ return src_constrs[i];
+ }
+ return null;
+ }
+
+ /**
+ * Pick up a constructor with the signature acceptable the specified
+ * signature in the source array of constructors.
+ *
+ * @param src_constrs source constructors.
+ * @param name a name to specify.
+ * @param param_types parameter types to specify.
+ * @return a constructor with the specified signature.
+ * This returns null if it doesn't exist.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJConstructor pickupAcceptableConstructor(
+ OJConstructor[] src_constrs,
+ OJClass[] param_types) {
+ src_constrs = pickupAcceptableConstructors(src_constrs, param_types);
+ return pickupMostSpecified(src_constrs);
+ }
+
+ /**
+ * Generates an array of constructors containing the constructors
+ * with the specified parameter types in the source array of
+ * constructors.
+ *
+ * @param src_constrs source constructors.
+ * @param param_types parameter types to specify.
+ * @return constructors acceptable the specified parameter types.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJConstructor[] pickupAcceptableConstructors(
+ OJConstructor[] src_constrs,
+ OJClass[] param_types) {
+ param_types = (param_types == null) ? new OJClass[0] : param_types;
+ int dest_length = 0;
+ for (int i = 0; i < src_constrs.length; ++i) {
+ OJClass[] accepter = src_constrs[i].getParameterTypes();
+ if (isAcceptable(accepter, param_types))
+ dest_length++;
+ }
+
+ OJConstructor[] result = new OJConstructor[dest_length];
+ for (int i = 0, count = 0; i < src_constrs.length; ++i) {
+ OJClass[] accepter = src_constrs[i].getParameterTypes();
+ if (isAcceptable(accepter, param_types)) {
+ result[count++] = src_constrs[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates an array of methods containing the methods with the
+ * specified name in the source array of methods.
+ *
+ * @param src_methods source methods.
+ * @param name a name to specify.
+ * @return methods with the specified name.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJMethod[] pickupMethodsByName(
+ OJMethod[] src_methods,
+ String name) {
+ int dest_length = 0;
+ for (int i = 0; i < src_methods.length; ++i) {
+ if (name.equals(src_methods[i].getName()))
+ dest_length++;
+ }
+
+ OJMethod[] result = new OJMethod[dest_length];
+ for (int i = 0, count = 0; i < src_methods.length; ++i) {
+ if (name.equals(src_methods[i].getName())) {
+ result[count++] = src_methods[i];
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Picks up a method with the specified parameter types in the source
+ * array of methods.
+ *
+ * @param src_methods source methods.
+ * @param param_types parameter types to specify.
+ * @return a method with the specified parameter types.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJMethod pickupMethodByParameterTypes(
+ OJMethod[] src_methods,
+ OJClass[] param_types) {
+ if (param_types == null)
+ param_types = new OJClass[0];
+ for (int i = 0; i < src_methods.length; ++i) {
+ OJClass[] accepter = src_methods[i].getParameterTypes();
+ if (isSame(accepter, param_types))
+ return src_methods[i];
+ }
+ return null;
+ }
+
+ /**
+ * Generates an array of methods containing the methods with the
+ * parameter types acceptable specified parameter types in the source
+ * array of methods.
+ *
+ * @param src_methods source methods.
+ * @param param_types parameter types to specify.
+ * @return methods acceptable the specified parameter types.
+ * @see io.devnulllabs.openjava.mop.OJClass
+ */
+ public static final OJMethod[] pickupAcceptableMethodsByParameterTypes(
+ OJMethod[] src_methods,
+ OJClass[] param_types) {
+ if (param_types == null)
+ param_types = new OJClass[0];
+ int dest_length = 0;
+ for (int i = 0; i < src_methods.length; ++i) {
+ OJClass[] accepter = src_methods[i].getParameterTypes();
+ if (isAcceptable(accepter, param_types))
+ dest_length++;
+ }
+
+ OJMethod[] result = new OJMethod[dest_length];
+ for (int i = 0, count = 0; i < src_methods.length; ++i) {
+ OJClass[] accepter = src_methods[i].getParameterTypes();
+ if (isAcceptable(accepter, param_types)) {
+ result[count++] = src_methods[i];
+ }
+ }
+
+ return result;
+ }
+
+ public static final boolean isSame(
+ OJClass[] accepter,
+ OJClass[] acceptee) {
+ if (accepter.length != acceptee.length)
+ return false;
+ for (int i = 0; i < acceptee.length; ++i) {
+ if (accepter[i] != acceptee[i])
+ return false;
+ }
+ return true;
+ }
+
+ public static final boolean isAcceptable(
+ OJClass[] accepter,
+ OJClass[] acceptee) {
+ if (accepter.length != acceptee.length)
+ return false;
+ for (int i = 0; i < acceptee.length; ++i) {
+ if (!accepter[i].isAssignableFrom(acceptee[i]))
+ return false;
+ }
+ return true;
+ }
+
+ public static final boolean isAdaptableTo(
+ OJClass[] adapter,
+ OJClass[] adaptee) {
+ if (adapter.length != adaptee.length)
+ return false;
+ for (int i = 0; i < adaptee.length; ++i) {
+ if (!adaptee[i].isAssignableFrom(adapter[i]))
+ return false;
+ }
+ return true;
+ }
+
+ public static final OJConstructor pickupMostSpecified(OJConstructor[] constrs) {
+ if (constrs.length == 0)
+ return null;
+ OJConstructor most = constrs[0];
+ for (int i = 0; i < constrs.length; ++i) {
+ OJClass[] adapter = most.getParameterTypes();
+ OJClass[] adaptee = constrs[i].getParameterTypes();
+ if (!isAdaptableTo(adapter, adaptee))
+ most = constrs[i];
+ }
+ return most;
+ }
+
+ public static final OJMethod pickupMostSpecified(OJMethod[] methods) {
+ if (methods.length == 0)
+ return null;
+ OJMethod most = methods[0];
+ for (int i = 0; i < methods.length; ++i) {
+ OJClass[] adapter = most.getParameterTypes();
+ OJClass[] adaptee = methods[i].getParameterTypes();
+ if (!isAdaptableTo(adapter, adaptee))
+ most = methods[i];
+ }
+ return most;
+ }
+
+ public static final OJClass[] append(OJClass[] a, OJClass[] b) {
+ OJClass[] result = new OJClass[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
+ }
+
+ public static final OJField[] append(OJField[] a, OJField[] b) {
+ OJField[] result = new OJField[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
+ }
+
+ public static final OJMethod[] append(OJMethod[] a, OJMethod[] b) {
+ OJMethod[] result = new OJMethod[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
+ }
+
+ public static final OJConstructor[] append(
+ OJConstructor[] a,
+ OJConstructor[] b) {
+ OJConstructor[] result = new OJConstructor[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
+ }
+
+ public static final String nameForJavaClassName(String jcname) {
+ if (!jcname.startsWith("["))
+ return jcname;
+
+ String stripped = stripHeadBracket(jcname);
+ String result;
+
+ if (stripped.startsWith("[")) {
+ /* array of array like "[[Ljava.lang.Object;" or "[[I" */
+ result = (nameForJavaClassName(stripped) + "[]");
+ } else if (stripped.endsWith(";")) {
+ /* array of class type like "[Ljava.lang.Object;" */
+ result = (stripped.substring(1, stripped.length() - 1) + "[]");
+ } else {
+ /* array of primitive type like "[I" */
+ switch (stripped.charAt(stripped.length() - 1)) {
+ case 'Z' :
+ return "boolean[]";
+ case 'B' :
+ return "byte[]";
+ case 'C' :
+ return "char[]";
+ case 'D' :
+ return "double[]";
+ case 'F' :
+ return "float[]";
+ case 'I' :
+ return "int[]";
+ case 'J' :
+ return "long[]";
+ case 'S' :
+ return "short[]";
+ default :
+ return "<unknown primitive type>";
+ }
+ }
+ return result.replace('$', '.');
+ }
+
+ public static final String nameToJavaClassName(String ojcname) {
+ if (!ojcname.endsWith("[]"))
+ return ojcname;
+
+ String stripped = stripBrackets(ojcname);
+
+ if (stripped.endsWith("[]")) {
+ /* array of array like "java.lang.Object[][]" or "int[][]" */
+ return ("[" + nameToJavaClassName(stripped));
+ } else if (stripped.equals("boolean")) {
+ return "[Z";
+ } else if (stripped.equals("byte")) {
+ return "[B";
+ } else if (stripped.equals("char")) {
+ return "[C";
+ } else if (stripped.equals("double")) {
+ return "[D";
+ } else if (stripped.equals("float")) {
+ return "[F";
+ } else if (stripped.equals("int")) {
+ return "[I";
+ } else if (stripped.equals("long")) {
+ return "[J";
+ } else if (stripped.equals("short")) {
+ return "[S";
+ } else {
+ return ("[L" + stripBrackets(ojcname) + ";");
+ }
+ }
+
+ private static final String stripHeadBracket(String jcname) {
+ return jcname.substring(1);
+ }
+
+ private static final String stripBrackets(String ojcname) {
+ return ojcname.substring(0, ojcname.length() - 2);
+ }
+
+ public static final OJClass forNameAnyway(Environment env, String name) {
+ name = env.toQualifiedName(name);
+ OJClass result = env.lookupClass(name);
+ if (result != null)
+ return result;
+ try {
+ return OJClass.forName(name);
+ } catch (OJClassNotFoundException e) {
+ System.err.println(
+ "OJClass.forNameAnyway() failed for : " + name + " " + e);
+ System.err.print(env);
+ return OJClass.forClass(Object.class);
+ }
+ }
+
+ public static final OJClass[] arrayForNames(
+ Environment env,
+ String[] names) {
+ OJClass[] result = new OJClass[names.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = forNameAnyway(env, names[i]);
+ }
+ return result;
+ }
+
+ public static final TypeName[] TNsForOJClasses(OJClass[] classes) {
+ TypeName[] result =
+ new TypeName[(classes == null) ? 0 : classes.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = TypeName.forOJClass(classes[i]);
+ }
+ return result;
+ }
+
+ private static final String PARAMETER_NAME = "oj_param";
+ public static final ParameterList generateParameters(OJClass[] parameterTypes) {
+ ParameterList result = new ParameterList();
+ if (parameterTypes == null)
+ return result;
+ for (int i = 0; i < parameterTypes.length; ++i) {
+ TypeName type = TypeName.forOJClass(parameterTypes[i]);
+ Parameter param = new Parameter(type, PARAMETER_NAME + i);
+ result.add(param);
+ }
+ return result;
+ }
+
+ public static final ParameterList generateParameters(
+ OJClass[] parameterTypes,
+ String[] parameterNames) {
+ ParameterList result = new ParameterList();
+ if (parameterTypes == null)
+ return result;
+ for (int i = 0; i < parameterTypes.length; ++i) {
+ TypeName type = TypeName.forOJClass(parameterTypes[i]);
+ Parameter param = new Parameter(type, parameterNames[i]);
+ result.add(param);
+ }
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/edit/OJEditableClass.java b/src/main/java/io/devnulllabs/openjava/mop/edit/OJEditableClass.java
new file mode 100644
index 0000000..f8f4b4e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/edit/OJEditableClass.java
@@ -0,0 +1,61 @@
+/*
+ * OJEditableClass.java
+ *
+ * Created on 2003/11/02 $Id: OJEditableClass.java,v 1.1 2003/11/03 00:45:10 tatsubori Exp $
+ */
+package io.devnulllabs.openjava.mop.edit;
+
+import io.devnulllabs.openjava.mop.CannotAlterException;
+import io.devnulllabs.openjava.mop.FileEnvironment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJConstructor;
+import io.devnulllabs.openjava.mop.OJField;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.mop.OJSystem;
+
+/**
+ * The type OJEditableClass.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0 2003/11/02
+ */
+public class OJEditableClass extends OJClass {
+
+ public OJEditableClass(OJClass original)
+ throws CannotAlterException {
+ super(
+ new FileEnvironment(
+ OJSystem.env,
+ original.getPackage(),
+ original.getSimpleName()),
+ original.getDeclaringClass(),
+ original.getSourceCode());
+ }
+
+ public OJClass addClass(OJClass clazz)
+ throws CannotAlterException {
+ return super.addClass(clazz);
+ }
+
+ public OJConstructor addConstructor(
+ OJConstructor constr)
+ throws CannotAlterException {
+ return super.addConstructor(constr);
+ }
+
+ public OJField addField(OJField field)
+ throws CannotAlterException {
+ return super.addField(field);
+ }
+
+ public void addInterface(OJClass clazz)
+ throws CannotAlterException {
+ super.addInterface(clazz);
+ }
+
+ public OJMethod addMethod(OJMethod method)
+ throws CannotAlterException {
+ return super.addMethod(method);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/mop/package.html b/src/main/java/io/devnulllabs/openjava/mop/package.html
new file mode 100644
index 0000000..f34cd8a
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/mop/package.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head></head>
+<body bgcolor="white">
+
+
+Provides classes that are fundamental to the design of the OpenJava
+Meta-Object Protocols (MOP).
+
+<p>OpenJava is an extensible language based on Java. The extended
+features of OpenJava are specified by a meta-level program given at
+compile time. For distinction, programs written in OpenJava are called
+base-level programs. If no meta-level program is given, OpenJava is
+identical to regular Java.
+
+<p>The meta-level program extends OpenJava through the interface
+called the OpenJava MOP (Metaobject Protocol). The OpenJava compiler
+consists of three stages: preprocessor, source-to-source translator
+from OpenJava to Java, and the back-end Java compiler. The OpenJava
+MOP is an interface to control the translator at the second stage. It
+allows to specify how an extended feature of OpenJava is translated
+into regular Java code.
+
+<p>An extended feature of OpenJava is supplied as an add-on software
+for the compiler. The add-on software consists of not only the
+meta-level program but runtime support code. The runtime support code
+provides classes used by the base-level program translated into
+Java. The base-level program in OpenJava is first translated into Java
+by the meta-level program and is dynamically linked with the runtime
+support code.
+
+<p>The meta-level program is written in Java, accurately in OpenJava
+because OpenJava is a self-reflective language. It defines new
+metaobjects to control source-to-source translation. The metaobjects
+are the meta-level representation of the base-level program and they
+perform the translation. Details of the metaobjects are specified by
+the OpenJava MOP. In the following, we go through a few examples so
+that we illustrate how the OpenJava MOP is used to implement language
+extensions.
+<p>
+
+
+
+<h2>Package Specification</h2>
+
+<ul>
+ <li><a href="">--</a>
+</ul>
+
+<h2>Related Documentation</h2>
+
+For overviews, tutorials, examples, guides, and tool documentation, please see:
+<ul>
+ <li><a href="http://www.csg.is.titech.ac.jp/~mich/openjava/">http://www.csg.is.titech.ac.jp/~mich/openjava/</a>
+</ul>
+
+<!-- Put @see and @since tags down here. -->
+
+@see java.lang.Class
+@see java.lang.reflect
+
+</body>
+</html>
diff --git a/src/main/java/io/devnulllabs/openjava/ojc/CommandArguments.java b/src/main/java/io/devnulllabs/openjava/ojc/CommandArguments.java
new file mode 100644
index 0000000..81bc063
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ojc/CommandArguments.java
@@ -0,0 +1,226 @@
+/*
+ * CommandArguments.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ojc;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * The class <code>CommandArguments</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: CommandArguments.java,v 1.4 2003/06/18 03:31:53 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class CommandArguments {
+ public static final int DEBUG_VERBOSE = 0x4;
+ public static final int DEBUG_CALLER = 0x8;
+
+ private final String[] originalArgs;
+ private Hashtable options = new Hashtable();
+ private File[] files;
+
+ public CommandArguments(String args[]) throws IOException {
+ originalArgs = args;
+ files = initFiles();
+ checkArguments();
+ }
+
+ public File[] getFiles() {
+ return files;
+ }
+
+ public File[] initFiles() {
+ if (originalArgs == null)
+ return new File[0];
+
+ //File[] result;
+ //int file_num = originalArgs.length - countUpOptions( originalArgs );
+ //result = new File[file_num];
+ Vector srcfiles = new Vector();
+
+ for (int i = 0, count = 0; i < originalArgs.length; ++i) {
+ if (isOption(originalArgs[i])) {
+ registerOption(originalArgs[i].substring(1));
+ } else {
+ //result[count++] = new File( originalArgs[i] );
+ addFiles(originalArgs[i], srcfiles);
+ }
+ }
+
+ File[] result = new File[srcfiles.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (File) srcfiles.elementAt(i);
+ }
+ return result;
+ }
+
+ private static void addFiles(String arg, Vector dest) {
+ if (!arg.startsWith("@")) {
+ dest.add(new File(arg));
+ return;
+ }
+ FileReader fin;
+ try {
+ fin = new FileReader(arg.substring(1));
+ } catch (IOException e) {
+ System.err.println("Bad file name ignored : " + arg);
+ return;
+ }
+ try {
+ BufferedReader reader = new BufferedReader(fin);
+ String line;
+ while ((line = reader.readLine()) != null) {
+ String filename = line.trim();
+ if (filename.equals(""))
+ break;
+ dest.add(new File(filename));
+ }
+ } catch (IOException e) {
+ System.err.println("Bad file format : " + arg);
+ return;
+ }
+ }
+
+ private static boolean isOption(String arg) {
+ return (arg != null && arg.startsWith("-"));
+ }
+
+ private static int countUpOptions(String[] args) {
+ if (args == null)
+ return 0;
+ int result = 0;
+ for (int i = 0; i < args.length; ++i) {
+ if (isOption(args[i]))
+ ++result;
+ }
+ return result;
+ }
+
+ public void registerOption(String str) {
+ Vector v = (Vector) options.get(optionKind(str));
+ if (v == null)
+ v = new Vector();
+ v.addElement(optionValue(str));
+ options.put(optionKind(str), v);
+ }
+
+ private static String optionKind(String str) {
+ int e = str.indexOf('=');
+ return (e == -1) ? str : str.substring(0, e).trim();
+ }
+
+ private static String optionValue(String str) {
+ int e = str.indexOf('=');
+ return (e == -1) ? "" : str.substring(e + 1).trim();
+ }
+
+ public String getOption(String option_name) {
+ Vector v = (Vector) options.get(option_name);
+ if (v == null || v.isEmpty())
+ return null;
+ return (String) v.elementAt(0);
+ }
+
+ public String[] getOptions(String option_name) {
+ Vector v = (Vector) options.get(option_name);
+ String[] result = new String[(v == null) ? 0 : v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (String) v.elementAt(i);
+ }
+ return result;
+ }
+
+ public String getOption(String opt1, String opt2) {
+ String result = getOption(opt1);
+ if (result == null)
+ result = getOption(opt2);
+ return result;
+ }
+
+ public int getDebugLevel() {
+ int debug_level = 0;
+
+ String level_str = getOption("g");
+ if (level_str != null) {
+ debug_level = Integer.valueOf(level_str).intValue();
+ }
+ if (getOption("verbose") != null)
+ debug_level |= DEBUG_VERBOSE;
+
+ return debug_level;
+ }
+
+ public JavaCompiler getJavaCompiler()
+ throws
+ ClassNotFoundException,
+ InstantiationException,
+ IllegalAccessException {
+ String compiler_name = getOption("compiler", "c");
+ if (compiler_name == null) {
+ compiler_name = "jp.ac.tsukuba.openjava.SunJavaCompiler";
+ }
+ Class clazz = Class.forName(compiler_name);
+ JavaCompiler result = (JavaCompiler) clazz.newInstance();
+ return result;
+ }
+
+ public boolean callerTranslation() {
+ if (getOption("calleroff") != null)
+ return false;
+ return true;
+ }
+
+ public boolean qualifyNameFirst() {
+ String qualifyname_flag = getOption("callerfast");
+ if (qualifyname_flag == null)
+ qualifyname_flag = "true";
+ if (qualifyname_flag.equals("false"))
+ return false;
+ return true;
+ }
+
+ private void checkArguments() throws IOException {
+ /* checks files */
+ File[] files = this.getFiles();
+ if (files.length == 0) {
+ System.err.println("Files are not specified.");
+ throw new IOException();
+ }
+ for (int i = 0; i < files.length; ++i) {
+ if (!files[i].canRead()) {
+ System.err.println("cannot find file " + files[i]);
+ throw new IOException();
+ }
+ if (!files[i].getName().endsWith(".oj")) {
+ System.err.println("illegal file name " + files[i]);
+ throw new IOException();
+ }
+ }
+ String diststr = getOption("d");
+ if (diststr != null && (!new File(diststr).isDirectory())) {
+ System.err.println("Directory does not exist : " + diststr);
+ throw new IOException();
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ojc/Compiler.java b/src/main/java/io/devnulllabs/openjava/ojc/Compiler.java
new file mode 100644
index 0000000..6e3abe5
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ojc/Compiler.java
@@ -0,0 +1,569 @@
+/*
+ * Compiler.java
+ *
+ *
+ */
+package io.devnulllabs.openjava.ojc;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.FileEnvironment;
+import io.devnulllabs.openjava.mop.MetaInfo;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJClassNotFoundException;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassDeclarationList;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.util.ExpansionApplier;
+import io.devnulllabs.openjava.ptree.util.MemberAccessCorrector;
+import io.devnulllabs.openjava.ptree.util.SourceCodeWriter;
+import io.devnulllabs.openjava.ptree.util.TypeNameQualifier;
+import io.devnulllabs.openjava.tools.DebugOut;
+import io.devnulllabs.openjava.tools.parser.ParseException;
+import io.devnulllabs.openjava.tools.parser.Parser;
+
+public class Compiler {
+ final CommandArguments arguments;
+ final File files[];
+ final FileEnvironment[] file_env;
+ final CompilationUnit[] comp_unit;
+
+ JavaCompiler java_compiler;
+ CompilationUnit[] added_cu = null;
+
+ Compiler(CommandArguments arguments) {
+ super();
+ this.arguments = arguments;
+ this.files = arguments.getFiles();
+ this.file_env = new FileEnvironment[files.length];
+ this.comp_unit = new CompilationUnit[files.length];
+
+ DebugOut.setDebugLevel(arguments.getDebugLevel());
+ initPrimitiveTypes();
+ try {
+ this.java_compiler = arguments.getJavaCompiler();
+ OJSystem.setJavaCompiler(this.java_compiler);
+ } catch (Exception e) {
+ System.err.println("illegal java compiler : " + e);
+ }
+ }
+
+ public void run() {
+ try {
+ configSpecifiedMetaBind();
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+
+ initFileEnv();
+
+ System.err.println("Generating parse tree.");
+ generateParseTree();
+ System.err.println("..done.");
+
+ System.err.println("Initializing parse tree.");
+ initParseTree();
+ System.err.println("..done.");
+
+ System.err.println("Translating callee side");
+ translateCalleeSide();
+ System.err.println("..done.");
+
+ System.err.println("Translating caller side");
+ if (arguments.callerTranslation()) {
+ translateCallerSide();
+ System.err.println("..done.");
+ } else {
+ System.err.println("..skipped.");
+ }
+
+ generateAdditionalCompilationUnit();
+
+ System.err.println("Printing parse tree.");
+ outputToFile();
+ System.err.println("..done.");
+
+ System.err.println("Compiling into bytecode.");
+ javac();
+ System.err.println("..done.");
+
+ System.err.flush();
+ }
+
+ void configSpecifiedMetaBind() throws Exception {
+ String[] cfile = arguments.getOptions("-default-meta");
+ for (int i = 0; i < cfile.length; ++i) {
+ BufferedReader reader =
+ new BufferedReader(new FileReader(cfile[i]));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ StringTokenizer tokenizer = new StringTokenizer(line);
+ try {
+ String mclazz = tokenizer.nextToken();
+ String bclazz = tokenizer.nextToken();
+ OJSystem.metabind(bclazz, mclazz);
+ } catch (java.util.NoSuchElementException e) {
+ /** ignore this line */
+ }
+ }
+ reader.close();
+ }
+ }
+
+ void initFileEnv() {
+ for (int i = 0; i < files.length; ++i) {
+ file_env[i] =
+ new FileEnvironment(OJSystem.env, null, null, files[i]);
+ }
+ }
+
+ void generateParseTree() {
+ for (int i = 0; i < files.length; ++i) {
+ DebugOut.println("parsing file " + files[i]);
+ try {
+ comp_unit[i] = parse(files[i]);
+ file_env[i].setCompilationUnit(comp_unit[i]);
+
+ ClassDeclarationList typedecls =
+ comp_unit[i].getClassDeclarations();
+ for (int j = 0; j < typedecls.size(); ++j) {
+ ClassDeclaration clazz_decl = typedecls.get(j);
+ /***********************************************************
+ * this may be ambiguos. there's OJClass.forParseTree()
+ */
+ OJClass c = makeOJClass(file_env[i], clazz_decl);
+ if (c.getModifiers().isPublic()) {
+ /* public/main class */
+ DebugOut.println("main class " + c.getName());
+ } else {
+ /* non-public class */
+ DebugOut.println("local class " + c.getName());
+ }
+ OJSystem.env.record(c.getName(), c);
+ /** * should consider private * */
+ recordInnerClasses(c);
+ }
+ } catch (Exception ex) {
+ System.err.println("errors during parsing. " + ex);
+ ex.printStackTrace();
+ }
+ DebugOut.println("file environment : ");
+ DebugOut.println(file_env[i]);
+ }
+
+ DebugOut.println("global environment : ");
+ DebugOut.println(OJSystem.env);
+ }
+
+ private static void recordInnerClasses(OJClass c) {
+ OJClass[] inners = c.getDeclaredClasses();
+ for (int i = 0; i < inners.length; ++i) {
+ OJSystem.env.record(inners[i].getName(), inners[i]);
+ recordInnerClasses(inners[i]);
+ }
+ }
+
+ void generateAdditionalCompilationUnit() {
+ OJClass[] added = OJSystem.addedClasses();
+ this.added_cu = new CompilationUnit[added.length];
+ for (int i = 0; i < added.length; ++i) {
+ ClassDeclarationList cdecls;
+ try {
+ cdecls = new ClassDeclarationList(added[i].getSourceCode());
+ } catch (Exception e) {
+ System.err.println("errors during generating " + added[i]);
+ e.printStackTrace();
+ continue;
+ }
+ String pack = added[i].getPackage();
+ added_cu[i] = new CompilationUnit(pack, null, cdecls);
+ }
+ }
+
+ /** -> to move to OJClass.forParseTree() * */
+ private OJClass makeOJClass(Environment env, ClassDeclaration cdecl) {
+ OJClass result;
+ String qname = env.toQualifiedName(cdecl.getName());
+ Class meta = OJSystem.getMetabind(qname);
+ try {
+ Constructor constr =
+ meta.getConstructor(
+ new Class[] {
+ Environment.class,
+ OJClass.class,
+ ClassDeclaration.class });
+ Object[] args = new Object[] { env, null, cdecl };
+ result = (OJClass) constr.newInstance(args);
+ } catch (Exception ex) {
+ System.err.println(
+ "errors during gererating a metaobject for " + qname);
+ ex.printStackTrace();
+ result = new OJClass(env, null, cdecl);
+ }
+
+ return result;
+ }
+
+ void initDebug() {
+ }
+
+ void outputToFile() {
+ for (int i = 0; i < comp_unit.length; ++i) {
+ if (comp_unit[i] == null)
+ continue;
+
+ File outfile = null;
+ try {
+ outfile =
+ getOutputFile(files[i], file_env[i], comp_unit[i], ".java");
+ FileWriter fout = new FileWriter(outfile);
+ PrintWriter out = new PrintWriter(fout);
+ SourceCodeWriter writer = new SourceCodeWriter(out);
+ writer.setDebugLevel(0);
+ comp_unit[i].accept(writer);
+ out.flush();
+ out.close();
+ } catch (IOException e) {
+ System.err.println("fails to create " + outfile);
+ } catch (ParseTreeException e) {
+ System.err.println("errors during printing " + outfile);
+ e.printStackTrace();
+ }
+
+ try {
+ outfile =
+ getOutputFile(
+ files[i],
+ null,
+ comp_unit[i],
+ MetaInfo.SUFFIX + ".java");
+ String qname = file_env[i].toQualifiedName(baseName(files[i]));
+ OJClass clazz = OJClass.forName(qname);
+ FileWriter fout = new FileWriter(outfile);
+ clazz.writeMetaInfo(fout);
+ fout.flush();
+ fout.close();
+ } catch (OJClassNotFoundException e) {
+ //System.err.println("The class object not found for " +
+ // outfile);
+ } catch (IOException e) {
+ System.err.println("fails to create " + outfile);
+ } catch (ParseTreeException e) {
+ System.err.println("errors during printing " + outfile);
+ e.printStackTrace();
+ }
+ }
+
+ for (int i = 0; i < added_cu.length; ++i) {
+ File outfile = null;
+ try {
+ outfile = getOutputFile(null, null, added_cu[i], ".java");
+ FileWriter fout = new FileWriter(outfile);
+ PrintWriter out = new PrintWriter(fout);
+ SourceCodeWriter writer = new SourceCodeWriter(out);
+ writer.setDebugLevel(0);
+ added_cu[i].accept(writer);
+ out.flush();
+ out.close();
+ } catch (IOException e) {
+ System.err.println("fails to create " + outfile);
+ } catch (ParseTreeException e) {
+ System.err.println("errors during printing " + outfile);
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static final String class2path(String cname) {
+ return cname.replace('.', File.separatorChar);
+ }
+
+ private static final String unknownClassName = "OJ_Unknown";
+ private static int nonpubclassid = 0;
+ private File getOutputFile(
+ File fin,
+ FileEnvironment file_env,
+ CompilationUnit comp_unit,
+ String suffix)
+ throws ParseTreeException {
+ String pack = comp_unit.getPackage();
+ String sname;
+ ClassDeclaration cd = comp_unit.getPublicClass();
+ if (cd != null) {
+ sname = cd.getName();
+ } else if (file_env != null) {
+ String path = file_env.getFile().getPath();
+ int suffix_index = path.lastIndexOf('.');
+ String javaPath = path.substring(0, suffix_index) + suffix;
+ return new File(javaPath);
+ } else {
+ sname = unknownClassName + nonpubclassid++;
+ }
+ return getOutputFile(fin, pack, sname, suffix);
+ }
+
+ private File getOutputFile(
+ File fin,
+ String pack,
+ String name,
+ String suffix) {
+ File dir; /* directory to put the file in */
+ String distbase = arguments.getOption("d");
+ if (distbase == null && fin != null) {
+ /* the same directory where source file is */
+ String dirname = fin.getParent();
+ if (dirname == null)
+ dirname = ".";
+ dir = new File(dirname);
+ } else {
+ if (distbase == null)
+ distbase = ".";
+ File basedir = new File(distbase);
+ if (pack == null || pack.equals("")) {
+ dir = basedir;
+ } else {
+ dir = new File(basedir, class2path(pack));
+ if ((!dir.isDirectory()) && (!dir.mkdirs())) {
+ System.err.println("fail to create dir : " + dir);
+ dir = new File(".");
+ }
+ }
+ }
+ return new File(dir, name + suffix);
+ }
+
+ private static String baseName(File file) {
+ String name = file.getName();
+ int index = name.lastIndexOf('.');
+ if (index == -1)
+ return name;
+ return name.substring(0, index);
+ }
+
+ void initParseTree() {
+ for (int i = 0; i < comp_unit.length; ++i) {
+ if (comp_unit[i] == null) {
+ System.err.println(files[i] + " is skipped.");
+ continue;
+ }
+ try {
+ if (arguments.callerTranslation()
+ && arguments.qualifyNameFirst()) {
+ comp_unit[i].accept(new TypeNameQualifier(file_env[i]));
+ }
+ MemberAccessCorrector corrector =
+ new MemberAccessCorrector(file_env[i]);
+ comp_unit[i].accept(corrector);
+ } catch (ParseTreeException e) {
+ System.err.println("Encountered errors during analysis.");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ void translateCalleeSide() {
+ Hashtable under_c = OJSystem.underConstruction;
+ for (int i = 0; i < comp_unit.length; ++i) {
+ if (comp_unit[i] == null) {
+ System.err.println(files[i] + " is skipped.");
+ continue;
+ }
+ ClassDeclarationList cdecls = comp_unit[i].getClassDeclarations();
+ for (int j = 0; j < cdecls.size(); ++j) {
+ ClassDeclaration cdecl = cdecls.get(j);
+ String qname = file_env[i].toQualifiedName(cdecl.getName());
+ OJClass clazz;
+ try {
+ clazz = OJClass.forName(qname);
+ } catch (OJClassNotFoundException ex) {
+ System.err.println("no " + qname + " : " + ex);
+ return;
+ }
+ translateClassDecls(under_c, clazz, file_env[i]);
+ }
+ }
+
+ try {
+ while (!under_c.isEmpty()) {
+ OJClass clazz = (OJClass) under_c.keys().nextElement();
+ resolveOrder(clazz);
+ }
+ } catch (InterruptedException e) {
+ System.err.println("translation failed : " + e);
+ }
+ }
+
+ private void translateClassDecls(
+ Hashtable table,
+ OJClass clazz,
+ Environment env) {
+ table.put(clazz, new TranslatorThread(env, clazz));
+
+ OJClass[] inners = clazz.getDeclaredClasses();
+ for (int i = 0; i < inners.length; ++i) {
+ translateClassDecls(table, inners[i], clazz.getEnvironment());
+ }
+ }
+
+ private void resolveOrder(OJClass clazz) throws InterruptedException {
+ /* lock for the given class metaobject */
+ Object lock = new Object();
+ Hashtable under_c = OJSystem.underConstruction;
+
+ synchronized (clazz) {
+ OJSystem.orderingLock = lock;
+ ((TranslatorThread) under_c.get(clazz)).start();
+
+ /*
+ * wait until the translation of the class is suspended or
+ * finished.
+ */
+ clazz.wait();
+ }
+
+ /*
+ * OJSystem.waited is set to null if the translation is finished.
+ * Otherwise the translation needs the translation of the class set in
+ * OJSystem.waited. It can be suspended for several times.
+ */
+ while (OJSystem.waited != null) {
+ resolveOrder(OJSystem.waited);
+
+ synchronized (clazz) {
+ OJSystem.orderingLock = lock;
+ synchronized (lock) {
+ lock.notifyAll();
+ }
+ clazz.wait();
+ }
+ }
+
+ under_c.remove(clazz);
+ }
+
+ void translateCallerSide() {
+ for (int i = 0; i < comp_unit.length; ++i) {
+ if (comp_unit[i] == null) {
+ System.err.println(files[i] + " is skipped.");
+ continue;
+ }
+ try {
+ ExpansionApplier expander = new ExpansionApplier(file_env[i]);
+ comp_unit[i].accept(expander);
+ } catch (ParseTreeException e) {
+ System.err.println(
+ "Encountered errors during translating caller side.");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static CompilationUnit parse(File file) {
+ Parser parser;
+
+ try {
+ parser = new Parser(new java.io.FileInputStream(file));
+ } catch (java.io.FileNotFoundException e) {
+ System.err.println("File " + file + " not found.");
+ return null;
+ }
+
+ CompilationUnit result;
+ try {
+ result = parser.CompilationUnit(OJSystem.env);
+ } catch (ParseException e) {
+ System.err.println("Encountered errors during parse.");
+ e.printStackTrace();
+ result = null;
+ }
+
+ return result;
+ }
+
+ private static void initPrimitiveTypes() {
+ OJSystem.initConstants();
+ /*
+ * OJClass.forClass( boolean . class ); OJClass.forClass( byte . class );
+ * OJClass.forClass( char . class ); OJClass.forClass( short . class );
+ * OJClass.forClass( int . class ); OJClass.forClass( long . class );
+ * OJClass.forClass( float . class ); OJClass.forClass( double . class );
+ * OJClass.forClass( void . class );
+ */
+ }
+
+ /**
+ * Compiles the generated files into byte codes
+ */
+ private void javac() {
+ ArrayList argsList = new ArrayList();
+
+ String[] options = arguments.getOptions("C");
+ for (int i = 0; i < options.length; ++i) {
+ argsList.add(options[i]);
+ }
+
+ try {
+ for (int i = 0; i < files.length; ++i) {
+ addCompiledFile(
+ argsList,
+ files[i],
+ file_env[i],
+ comp_unit[i],
+ ".java");
+ addCompiledFile(
+ argsList,
+ files[i],
+ null,
+ comp_unit[i],
+ MetaInfo.SUFFIX + ".java");
+ }
+ for (int i = 0; i < added_cu.length; ++i) {
+ addCompiledFile(argsList, files[i], null, added_cu[i], ".java");
+ addCompiledFile(
+ argsList,
+ files[i],
+ null,
+ added_cu[i],
+ MetaInfo.SUFFIX + ".java");
+ }
+
+ String[] args = new String[argsList.size()];
+ for (int i = 0; i < args.length; ++i) {
+ args[i] = (String) argsList.get(i);
+ }
+
+ java_compiler.compile(args);
+ } catch (Exception e) {
+ System.err.println("errors during compiling into bytecode.");
+ e.printStackTrace();
+ }
+ }
+
+ private void addCompiledFile(
+ ArrayList argsList,
+ File file,
+ FileEnvironment fenv,
+ CompilationUnit cu,
+ String suffix) {
+ try {
+ File javafile = getOutputFile(file, fenv, cu, suffix);
+ if (javafile.exists())
+ argsList.add(javafile.getPath());
+ } catch (ParseTreeException ex) {
+ System.err.println(ex.toString());
+ return;
+ }
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ojc/JavaCompiler.java b/src/main/java/io/devnulllabs/openjava/ojc/JavaCompiler.java
new file mode 100644
index 0000000..3892976
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ojc/JavaCompiler.java
@@ -0,0 +1,17 @@
+/*
+ * JavaCompiler.java
+ *
+ * Apr 16, 1999 Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ojc;
+
+/**
+ * The interface <code>JavaCompiler</code> represents an interface
+ * to invoke a regular Java compiler.
+ * Classes implementing this interface should accept the same arguments
+ * as Sun's javac.
+ *
+ */
+public interface JavaCompiler {
+ public void compile(String[] args);
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ojc/Main.java b/src/main/java/io/devnulllabs/openjava/ojc/Main.java
new file mode 100644
index 0000000..8c4d240
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ojc/Main.java
@@ -0,0 +1,54 @@
+/*
+ * Main.java
+ *
+ *
+ */
+package io.devnulllabs.openjava.ojc;
+
+import java.io.PrintStream;
+
+public class Main {
+
+ public static void main(String argc[]) {
+ System.err.println("OpenJava Compiler Version 1.1 " + "build 20031119");
+ CommandArguments arguments;
+ try {
+ arguments = new CommandArguments(argc);
+ } catch (Exception e) {
+ showUsage();
+ return;
+ }
+ new Compiler(arguments).run();
+ }
+
+ private static void showUsage() {
+ PrintStream o = System.err;
+ o.println("Usage : ojc <options> <source files>");
+ o.println("where <options> includes:");
+ o.println(
+ " -verbose "
+ + "Enable verbose output ");
+ o.println(
+ " -g=<number> "
+ + "Specify debugging info level ");
+ o.println(
+ " -d=<directory> "
+ + "Specify where to place generated files ");
+ o.println(
+ " -compiler=<class> "
+ + "Specify regular Java compiler ");
+ o.println(
+ " --default-meta=<file> "
+ + "Specify separated meta-binding configurations");
+ o.println(
+ " -calleroff "
+ + "Turn off caller-side translations ");
+ o.println(
+ " -C=<argument> "
+ + "Pass the argument to Java compiler ");
+ o.println(
+ " -J<argument> "
+ + "Pass the argument to JVM ");
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ojc/TranslatorThread.java b/src/main/java/io/devnulllabs/openjava/ojc/TranslatorThread.java
new file mode 100644
index 0000000..7036c74
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ojc/TranslatorThread.java
@@ -0,0 +1,39 @@
+/*
+ * TranslatorThread.java
+ *
+ */
+package io.devnulllabs.openjava.ojc;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+
+public class TranslatorThread extends Thread {
+ private final Environment env;
+ private final OJClass clazz;
+
+ public TranslatorThread(Environment env, OJClass clazz) {
+ this.env = env;
+ this.clazz = clazz;
+ }
+
+ public void run() {
+ try {
+ ClassDeclaration cdecl = clazz.getSourceCode();
+ ClassDeclaration newdecl = clazz.translateDefinition(env, cdecl);
+ if (newdecl != cdecl)
+ cdecl.replace(newdecl);
+ } catch (Exception ex) {
+ System.err.println(
+ "fail to translate " + clazz.getName() + " : " + ex);
+ ex.printStackTrace();
+ }
+
+ synchronized (clazz) {
+ OJSystem.waited = null;
+ clazz.notifyAll();
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/AllocationExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/AllocationExpression.java
new file mode 100644
index 0000000..3aea1e2
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/AllocationExpression.java
@@ -0,0 +1,203 @@
+/*
+ * AllocationExpression.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>AllocationExpression</code> class represents
+ * an expression which allocates a new object with its constructor.
+ * <br>
+ * This expression is like:
+ * <br><blockquote><pre>
+ * new String( "test" )
+ * </pre></blockquote><br>
+ * or:
+ * <br><blockquote><pre>
+ * new String( "test" ){
+ * public void hoge(){ ... }
+ * ...
+ * }
+ * </pre></blockquote><br>
+ * The latter is supported from JDK 1.1, is called an anoymous class
+ * of the inner class.
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ * @see io.devnulllabs.openjava.ptree.ExpressionList
+ * @see io.devnulllabs.openjava.ptree.MemberDeclarationList
+ */
+public class AllocationExpression extends NonLeaf implements Expression {
+
+ /**
+ * Allocates a new object with the class body.
+ *
+ * @param ctype a class name to be constructed
+ * @param args argument list of constructor
+ * @param mdlst the class body.
+ * If this is null, no class body will be provided
+ * this construct expression with.
+ */
+ public AllocationExpression(
+ Expression encloser,
+ TypeName typename,
+ ExpressionList args,
+ MemberDeclarationList mdlst) {
+ super();
+ if (args == null)
+ args = new ExpressionList();
+ /* an explicitly specified null has meaning of no body */
+ //if (mdlst == null) mdlst = new MemberDeclarationList();
+ set(typename, args, mdlst, encloser);
+ }
+
+ /**
+ * Allocates a new object with the class body.
+ *
+ * @param ctype a class name to be constructed
+ * @param args argument list of constructor
+ * @param mdlst the class body.
+ * If this is null, no class body will be provided
+ * this construct expression with.
+ */
+ public AllocationExpression(
+ TypeName typename,
+ ExpressionList args,
+ MemberDeclarationList mdlst) {
+ this(null, typename, args, mdlst);
+ }
+
+ /**
+ * Allocates a new object with the class body.
+ *
+ * @param ctype a class name to be constructed
+ * @param args argument list of constructor
+ * @param mdlst the class body.
+ * If this is null, no class body will be provided
+ * this construct expression with.
+ */
+ public AllocationExpression(
+ Expression encloser,
+ TypeName typename,
+ ExpressionList args) {
+ this(encloser, typename, args, null);
+ }
+
+ /**
+ * Allocates a new object without class body.
+ *
+ * @param ctype a class name to be constructed
+ * @param args argument list of constructor
+ */
+ public AllocationExpression(TypeName ctype, ExpressionList args) {
+ this(ctype, args, null);
+ }
+
+ public AllocationExpression(OJClass type, ExpressionList args) {
+ this(TypeName.forOJClass(type), args);
+ }
+
+ AllocationExpression() {
+ super();
+ }
+
+ /**
+ * Gets the expression of enclosing object.
+ *
+ * @return the expression of enclosing object
+ */
+ public Expression getEncloser() {
+ return (Expression) elementAt(3);
+ }
+
+ /**
+ * Sets the expression of enclosing object.
+ *
+ * @param encloser the expression of enclosing object
+ */
+ public void setEncloser(Expression encloser) {
+ setElementAt(encloser, 3);
+ }
+
+ /**
+ * Gets the class type of this constructor.
+ *
+ * @return the class type of this constructor.
+ */
+ public TypeName getClassType() {
+ return (TypeName) elementAt(0);
+ }
+
+ /**
+ * Sets the class type of this constructor.
+ *
+ * @param ctype the class body to set.
+ */
+ public void setClassType(TypeName ctype) {
+ setElementAt(ctype, 0);
+ }
+
+ /**
+ * Gets the arguments of this constructor.
+ *
+ * @return the arguments as an expressions list.
+ */
+ public ExpressionList getArguments() {
+ return (ExpressionList) elementAt(1);
+ }
+
+ /**
+ * Sets the arguments of this constructor.
+ *
+ * @return the expressions list of arguments.
+ */
+ public void setArguments(ExpressionList args) {
+ if (args == null) {
+ args = new ExpressionList();
+ }
+ setElementAt(args, 1);
+ }
+
+ /**
+ * Gets the class body of this constructor.
+ *
+ * @return the member declaration list as the class body of
+ * this constructor.
+ */
+ public MemberDeclarationList getClassBody() {
+ return (MemberDeclarationList) elementAt(2);
+ }
+
+ /**
+ * Sets the class body of this constructor.
+ *
+ * @param mdlist the member declaration list of the class body.
+ * If this is null, the class body will disappear.
+ */
+ public void setClassBody(MemberDeclarationList mdlist) {
+ setElementAt(mdlist, 2);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ String typename = env.toQualifiedName(getClassType().toString());
+ OJClass result = env.lookupClass(typename);
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java b/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java
new file mode 100644
index 0000000..9de3779
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java
@@ -0,0 +1,87 @@
+/*
+ * ArrayAccess.java 1.0
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ArrayAccess</code> represents
+ * an array access.
+ * <p>
+ * An array access is like :
+ * <br><blockquote><pre>
+ * a.m[i + 1]
+ * </pre></blockquote><br>
+ * In this array access expression,
+ * you can get <code>a.m</code> by <code>getReferenceExpr()</code>
+ * and can get <code>i + 1</code> by <code>getIndexExpr()</code> .
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class ArrayAccess extends NonLeaf implements Expression {
+ public ArrayAccess(Expression expr, Expression index_expr) {
+ super();
+ set(expr, index_expr);
+ }
+
+ ArrayAccess() {
+ super();
+ }
+
+ /**
+ * Gets the expression of array.
+ *
+ * @return the experssion accessed as array.
+ */
+ public Expression getReferenceExpr() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression accessed as array.
+ *
+ * @param expr the experssion of array.
+ */
+ public void setReferenceExpr(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the dimexpr list.
+ *
+ * @return the dimexpr list.
+ */
+ public Expression getIndexExpr() {
+ return (Expression) elementAt(1);
+ }
+
+ /**
+ * Sets the dimexpr list.
+ *
+ * @param dimexprs the dimexpr list.
+ */
+ public void setIndexExpr(Expression dimexprs) {
+ setElementAt(dimexprs, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ OJClass reftype = getReferenceExpr().getType(env);
+ return reftype.getComponentType();
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ArrayAllocationExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/ArrayAllocationExpression.java
new file mode 100644
index 0000000..f5ad74d
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ArrayAllocationExpression.java
@@ -0,0 +1,151 @@
+/*
+ * ArrayAllocationExpression.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ArrayAllocationExpression</code> class represents
+ * an expression which allocates a new array object.
+ * <br>
+ * This expression is like:
+ * <br><blockquote><pre>
+ * new Object[2][3]
+ * </pre></blockquote><br>
+ * or:
+ * <br><blockquote><pre>
+ * new String[]{ "this", "is", "a", "test" }
+ * </pre></blockquote><br>
+ * The latter is supported from JDK 1.1.
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ * @see io.devnulllabs.openjava.ptree.ExpressionList
+ * @see io.devnulllabs.openjava.ptree.ArrayInitializer
+ */
+public class ArrayAllocationExpression extends NonLeaf implements Expression {
+
+ /**
+ * Allocates a new ptree object.
+ *
+ * @param typename the type name.
+ * @param dimlist the dimension expression list.
+ */
+ public ArrayAllocationExpression(
+ TypeName typename,
+ ExpressionList dimlist) {
+ this(typename, dimlist, null);
+ }
+
+ /**
+ * Allocates a new ptree object.
+ *
+ * @param typename the type name.
+ * @param dimlist the dimension expression list.
+ * @param ainit the array initializer.
+ * If this is null, no initializer will be
+ * provided this allocation with.
+ */
+ public ArrayAllocationExpression(
+ TypeName typename,
+ ExpressionList dimlist,
+ ArrayInitializer ainit) {
+ super();
+ if (dimlist == null)
+ dimlist = new ExpressionList();
+ set(typename, dimlist, ainit);
+ }
+
+ public ArrayAllocationExpression(OJClass type, ExpressionList args) {
+ this(TypeName.forOJClass(type), args);
+ }
+
+ public ArrayAllocationExpression(
+ OJClass type,
+ ExpressionList args,
+ ArrayInitializer ainit) {
+ this(TypeName.forOJClass(type), args, ainit);
+ }
+
+ ArrayAllocationExpression() {
+ super();
+ }
+
+ /**
+ * Gets the type name of the array.
+ *
+ * @return the type name of the array.
+ */
+ public TypeName getTypeName() {
+ return (TypeName) elementAt(0);
+ }
+
+ /**
+ * Sets the type name of the array.
+ *
+ * @param typename the type name of the array.
+ */
+ public void setTypeName(TypeName typename) {
+ setElementAt(typename, 0);
+ }
+
+ /**
+ * Gets the dimexpr list of the array.
+ *
+ * @return the dimexpr list of the array.
+ */
+ public ExpressionList getDimExprList() {
+ return (ExpressionList) elementAt(1);
+ }
+
+ /**
+ * Sets the dimexpr list of the array.
+ *
+ * @param dimlist the dimexpr list of the array.
+ */
+ public void setDimExprList(ExpressionList dimlist) {
+ setElementAt(dimlist, 1);
+ }
+
+ /**
+ * Gets the initializer of this array allocation.
+ *
+ * @return the initializer.
+ */
+ public ArrayInitializer getInitializer() {
+ return (ArrayInitializer) elementAt(2);
+ }
+
+ /**
+ * Sets the initializer of this array allocation.
+ *
+ * @param ainit the initializer.
+ * If this is null, no initializer will be set.
+ */
+ public void setInitializer(ArrayInitializer ainit) {
+ setElementAt(ainit, 2);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ TypeName tname = getTypeName();
+ String dims = TypeName.stringFromDimension(getDimExprList().size());
+ return env.lookupClass(env.toQualifiedName(tname + dims));
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ArrayInitializer.java b/src/main/java/io/devnulllabs/openjava/ptree/ArrayInitializer.java
new file mode 100644
index 0000000..a1fb67e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ArrayInitializer.java
@@ -0,0 +1,152 @@
+/*
+ * ArrayInitializer.java 1.0
+ *
+ * Jun 11, 1997 by mich
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ArrayInitializer class presents initializer list of array elements.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.List
+ * @see io.devnulllabs.openjava.ptree.VariableInitializer
+ */
+public class ArrayInitializer extends List implements VariableInitializer {
+
+ private boolean _isRemainderOmitted = false;
+
+ /**
+ * Allocates a new ArrayInitializer.
+ *
+ * @param arrayinit prototype object
+ */
+ public ArrayInitializer() {
+ super(", ");
+ }
+
+ public ArrayInitializer(VariableInitializer vi) {
+ this();
+ add(vi);
+ }
+
+ public ArrayInitializer(ExpressionList exprs) {
+ this();
+ int len = exprs.size();
+ for (int i = 0; i < len; ++i) {
+ add(exprs.get(i));
+ }
+ }
+
+ public void omitRemainder(boolean is_omitted) {
+ this._isRemainderOmitted = is_omitted;
+ }
+
+ public void omitRemainder() {
+ this._isRemainderOmitted = true;
+ }
+
+ public boolean isRemainderOmitted() {
+ return this._isRemainderOmitted;
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public VariableInitializer get(int n) {
+ return (VariableInitializer) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p VariableInitializer to be inserted into the list
+ */
+ public void add(VariableInitializer p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p VariableInitializer to be inserted into the list
+ */
+ public void set(int index, VariableInitializer p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public VariableInitializer remove(int index) {
+ VariableInitializer removed =
+ (VariableInitializer) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(VariableInitializer p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(ArrayInitializer lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public ArrayInitializer subList(int from_index, int to_index) {
+ ArrayInitializer result = new ArrayInitializer();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/AssignmentExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/AssignmentExpression.java
new file mode 100644
index 0000000..9c4d538
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/AssignmentExpression.java
@@ -0,0 +1,158 @@
+/*
+ * AssignmentExpression.java 1.0
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>AssignmentExpression</code> class represents
+ * an assignment expression with an assignment operator.
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class AssignmentExpression extends NonLeaf implements Expression {
+ public final static int EQUALS = 0;
+ public final static int MULT = 1;
+ public final static int DIVIDE = 2;
+ public final static int MOD = 3;
+ public final static int ADD = 4;
+ public final static int SUB = 5;
+ public final static int SHIFT_L = 6;
+ public final static int SHIFT_R = 7;
+ public final static int SHIFT_RR = 8;
+ public final static int AND = 9;
+ public final static int XOR = 10;
+ public final static int OR = 11;
+
+ final static String opr_string[] =
+ {
+ "=",
+ "*=",
+ "/=",
+ "%=",
+ "+=",
+ "-=",
+ "<<=",
+ ">>=",
+ ">>>=",
+ "&=",
+ "^=",
+ "|=" };
+
+ private int opr = -1;
+
+ /**
+ * Allocates a new object.
+ *
+ * @param lexp the left expression.
+ * @param opr the id number of the operator.
+ * @param rexp the right expression.
+ */
+ public AssignmentExpression(Expression lexp, int opr, Expression rexp) {
+ super();
+ set((ParseTree) lexp, (ParseTree) rexp);
+ this.opr = opr;
+ }
+
+ public AssignmentExpression(Expression lexp, String opr, Expression rexp) {
+ this(lexp, 0, rexp);
+ for (int i = 0; i < opr_string.length; ++i) {
+ if (opr_string[i].equals(opr))
+ this.opr = i;
+ }
+ }
+
+ public AssignmentExpression() {
+ super();
+ }
+
+ public ParseTree makeRecursiveCopy() {
+ AssignmentExpression result =
+ (AssignmentExpression) super.makeRecursiveCopy();
+ result.opr = this.opr;
+ return result;
+ }
+
+ public ParseTree makeCopy() {
+ AssignmentExpression result = (AssignmentExpression) super.makeCopy();
+ result.opr = this.opr;
+ return result;
+ }
+
+ /**
+ * Gets the expression of the left operand.
+ *
+ * @return the left expression.
+ */
+ public Expression getLeft() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression of the left operand.
+ *
+ * @param lexpr the left expression.
+ */
+ public void setLeft(Expression lexpr) {
+ setElementAt(lexpr, 0);
+ }
+
+ /**
+ * Gets the expression of the right operand.
+ *
+ * @return the right expression.
+ */
+ public Expression getRight() {
+ return (Expression) elementAt(1);
+ }
+
+ /**
+ * Sets the expression of the right operand.
+ *
+ * @param rexpr the right expression.
+ */
+ public void setRight(Expression rexpr) {
+ setElementAt(rexpr, 1);
+ }
+
+ /**
+ * Gets the id number of the operator.
+ *
+ * @return the id number of the operator.
+ */
+ public int getOperator() {
+ return this.opr;
+ }
+
+ /**
+ * Sets the id number of the operator.
+ *
+ * @param opr the id number of the operator.
+ */
+ public void setOperator(int opr) {
+ this.opr = opr;
+ }
+
+ public String operatorString() {
+ return opr_string[getOperator()];
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ return getLeft().getType(env);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/BinaryExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/BinaryExpression.java
new file mode 100644
index 0000000..67ba1f4
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/BinaryExpression.java
@@ -0,0 +1,372 @@
+/*
+ * BinaryExpression.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>BinaryExpression</code> class represents
+ * an expression which consists of an operators and two operands.
+ * <br>
+ * This doesn't includes the expression whose operator is
+ * the <code>instanceof</code> operator
+ * nor the expression whose operator is one of the
+ * assignment operators.
+ * <br>
+ * If the operator in the expression of the left operand or
+ * the right operand has week unity,
+ * this automatically produces the code in which the left operand
+ * is enclosed by parenthesises.
+ * <br>
+ * In the case the left is <code>a + b</code>,
+ * the operator is <code>*</code>
+ * the right is <code>c + d</code>,
+ * this produces the code :
+ * <br><blockquote><pre>
+ * (a + b) * (c + d)
+ * </pre></blockquote><br>
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.InstanceofExpression
+ * @see io.devnulllabs.openjava.ptree.AssignmentExpression
+ */
+public class BinaryExpression extends NonLeaf implements Expression {
+ public static final int TIMES = 0;
+ public static final int DIVIDE = 1;
+ public static final int MOD = 2;
+ public static final int PLUS = 3;
+ public static final int MINUS = 4;
+ public static final int SHIFT_L = 5;
+ public static final int SHIFT_R = 6;
+ public static final int SHIFT_RR = 7;
+ public static final int LESS = 8;
+ public static final int GREATER = 9;
+ public static final int LESSEQUAL = 10;
+ public static final int GREATEREQUAL = 11;
+ public static final int INSTANCEOF = 12;
+ public static final int EQUAL = 13;
+ public static final int NOTEQUAL = 14;
+ public static final int BITAND = 15;
+ public static final int XOR = 16;
+ public static final int BITOR = 17;
+ public static final int LOGICAL_AND = 18;
+ public static final int LOGICAL_OR = 19;
+
+ static final String[] opr_string =
+ {
+ "*",
+ "/",
+ "%",
+ "+",
+ "-",
+ "<<",
+ ">>",
+ ">>>",
+ "<",
+ ">",
+ "<=",
+ ">=",
+ "instanceof",
+ "==",
+ "!=",
+ "&",
+ "^",
+ "|",
+ "&&",
+ "||" };
+
+ /** the operator */
+ private int opr = -1;
+
+ /**
+ * Allocates a new object.
+ *
+ * @param lexp the expression of the left operand.
+ * @param opr the id number of operator.
+ * @param rexp the expression of the right operand.
+ */
+ public BinaryExpression(Expression lexp, int opr, Expression rexp) {
+ super();
+ set((ParseTree) lexp, (ParseTree) rexp);
+ this.opr = opr;
+ }
+
+ public BinaryExpression(Expression lexp, String opr, Expression rexp) {
+ this(lexp, 0, rexp);
+ for (int i = 0; i < 20; ++i) {
+ if (opr_string[i].equals(opr))
+ this.opr = i;
+ }
+ }
+
+ BinaryExpression() {
+ super();
+ }
+
+ public ParseTree makeRecursiveCopy() {
+ BinaryExpression result = (BinaryExpression) super.makeRecursiveCopy();
+ result.opr = this.opr;
+ return result;
+ }
+
+ public ParseTree makeCopy() {
+ BinaryExpression result = (BinaryExpression) super.makeCopy();
+ result.opr = this.opr;
+ return result;
+ }
+
+ private final boolean needsLeftPar(Expression leftexpr) {
+ if (leftexpr instanceof AssignmentExpression
+ || leftexpr instanceof ConditionalExpression) {
+ return true;
+ }
+
+ int op = strength(getOperator());
+
+ if (leftexpr instanceof InstanceofExpression) {
+ if (op > strength(INSTANCEOF))
+ return true;
+ return false;
+ }
+
+ if (!(leftexpr instanceof BinaryExpression))
+ return false;
+
+ BinaryExpression lbexpr = (BinaryExpression) leftexpr;
+ if (op > strength(lbexpr.getOperator()))
+ return true;
+ return false;
+ }
+
+ private final boolean needsRightPar(Expression rightexpr) {
+ if (rightexpr instanceof AssignmentExpression
+ || rightexpr instanceof ConditionalExpression) {
+ return true;
+ }
+
+ int op = strength(getOperator());
+
+ if (rightexpr instanceof InstanceofExpression) {
+ if (op >= strength(INSTANCEOF))
+ return true;
+ return false;
+ }
+
+ if (!(rightexpr instanceof BinaryExpression))
+ return false;
+
+ BinaryExpression lbexpr = (BinaryExpression) rightexpr;
+ if (op >= strength(lbexpr.getOperator()))
+ return true;
+ return false;
+ }
+
+ /**
+ * Returns the strength of the union of the operator.
+ *
+ * @param op the id number of operator.
+ * @return the strength of the union.
+ */
+ protected static final int strength(int op) {
+ switch (op) {
+ case TIMES :
+ case DIVIDE :
+ case MOD :
+ return 40;
+ case PLUS :
+ case MINUS :
+ return 35;
+ case SHIFT_L :
+ case SHIFT_R :
+ case SHIFT_RR :
+ return 30;
+ case LESS :
+ case GREATER :
+ case LESSEQUAL :
+ case GREATEREQUAL :
+ case INSTANCEOF :
+ return 25;
+ case EQUAL :
+ case NOTEQUAL :
+ return 20;
+ case BITAND :
+ return 16;
+ case XOR :
+ return 14;
+ case BITOR :
+ return 12;
+ case LOGICAL_AND :
+ return 10;
+ case LOGICAL_OR :
+ return 8;
+ }
+ return 100;
+ }
+
+ /**
+ * Gets the expression of the left operand.
+ *
+ * @return the left expression.
+ */
+ public Expression getLeft() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression of the left operand.
+ *
+ * @param lexpr the left expression.
+ */
+ public void setLeft(Expression lexpr) {
+ setElementAt(lexpr, 0);
+ }
+
+ /**
+ * Gets the expression of the right operand.
+ *
+ * @return the right expression.
+ */
+ public Expression getRight() {
+ return (Expression) elementAt(1);
+ }
+
+ /**
+ * Sets the expression of the right operand.
+ *
+ * @param rexpr the right expression.
+ */
+ public void setRight(Expression rexpr) {
+ setElementAt(rexpr, 1);
+ }
+
+ /**
+ * Gets the id number of the operator.
+ *
+ * @return the id number of the operator.
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#TIMES
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#DIVIDE
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#MOD
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#PLUS
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#MINUS
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#SHIFT_L
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#SHIFT_R
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#SHIFT_RR
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LESS
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#GREATER
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LESSEQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#GREATEREQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#INSTANCEOF
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#EQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#NOTEQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#BITAND
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#XOR
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#BITOR
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LOGICAL_AND
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LOGICAL_OR
+ */
+ public int getOperator() {
+ return this.opr;
+ }
+
+ /**
+ * Sets the id number of the operator.
+ *
+ * @param opr the id number of the operator.
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#TIMES
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#DIVIDE
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#MOD
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#PLUS
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#MINUS
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#SHIFT_L
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#SHIFT_R
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#SHIFT_RR
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LESS
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#GREATER
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LESSEQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#GREATEREQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#INSTANCEOF
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#EQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#NOTEQUAL
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#BITAND
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#XOR
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#BITOR
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LOGICAL_AND
+ * @see io.devnulllabs.openjava.ptree.BinaryExpression#LOGICAL_OR
+ */
+ public void setOperator(int opr) {
+ this.opr = opr;
+ }
+
+ public String operatorString() {
+ return opr_string[getOperator()];
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ switch (this.opr) {
+ case LESS :
+ case GREATER :
+ case LESSEQUAL :
+ case GREATEREQUAL :
+ case EQUAL :
+ case NOTEQUAL :
+ case INSTANCEOF :
+ return OJSystem.BOOLEAN;
+ default :
+ return chooseType(
+ getLeft().getType(env),
+ getRight().getType(env));
+ }
+ }
+
+ static OJClass chooseType(OJClass left, OJClass right) {
+ int leftst = strength(left), rightst = strength(right);
+ if (leftst == OTHER && rightst == OTHER) {
+ if (left.isAssignableFrom(right))
+ return left;
+ if (right.isAssignableFrom(left))
+ return right;
+ return right;
+ }
+ return ((leftst > rightst) ? left : right);
+ }
+
+ private static final int STRING = 30;
+ private static final int OTHER = 4;
+ private static int strength(OJClass type) {
+ if (type == OJSystem.STRING)
+ return STRING;
+ if (type == OJSystem.DOUBLE)
+ return 20;
+ if (type == OJSystem.FLOAT)
+ return 18;
+ if (type == OJSystem.LONG)
+ return 16;
+ if (type == OJSystem.INT)
+ return 14;
+ if (type == OJSystem.CHAR)
+ return 12;
+ if (type == OJSystem.BYTE)
+ return 10;
+ if (type == OJSystem.NULLTYPE)
+ return 0; /*****/
+ return OTHER;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Block.java b/src/main/java/io/devnulllabs/openjava/ptree/Block.java
new file mode 100644
index 0000000..585a39b
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Block.java
@@ -0,0 +1,71 @@
+/*
+ * Block.java 1.0
+ *
+ * Jun 11, 1997 by mich
+ * Aug 29, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: Aug 29, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The Block class represents a node of parse tree
+ * of block statement like :
+ * <br><blockquote><pre>
+ * {
+ * int i = 0;
+ * i = f( i );
+ * }
+ * </pre></blockquote><br>
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class Block extends NonLeaf implements Statement {
+ /**
+ * Allocates a new object.
+ *
+ * @param stmts statement list.
+ */
+ public Block(StatementList stmts) {
+ super();
+ if (stmts == null)
+ stmts = new StatementList();
+ set(stmts);
+ }
+
+ /**
+ * Allocates a new object with an empty statement list.
+ *
+ */
+ public Block() {
+ this(new StatementList());
+ }
+
+ /**
+ * Gets the statement list of this block.
+ *
+ * @return the statement list.
+ */
+ public StatementList getStatements() {
+ return (StatementList) elementAt(0);
+ }
+
+ /**
+ * Sets the statement list of this block.
+ *
+ * @param stmts the statement list to set.
+ */
+ public void setStatements(StatementList stmts) {
+ setElementAt(stmts, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/BreakStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/BreakStatement.java
new file mode 100644
index 0000000..a7c01fb
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/BreakStatement.java
@@ -0,0 +1,69 @@
+/*
+ * BreakStatement.java 1.0
+ *
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>BreakStatement</code> class represents
+ * a break statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class BreakStatement extends NonLeaf implements Statement {
+
+ /**
+ * Allocates a new BreakStatement object.
+ *
+ * @param label the label of this break statemetn.
+ * if this is null, break statement has no label.
+ */
+ public BreakStatement(String label) {
+ super();
+ set(label);
+ }
+
+ /**
+ * Allocates a new BreakStatement object.
+ *
+ */
+ public BreakStatement() {
+ this(null);
+ }
+
+ /**
+ * Gets the label of this break statement.
+ *
+ * @return the label name.
+ * If there is no label then this method returns null.
+ */
+ public String getLabel() {
+ return (String) elementAt(0);
+ }
+
+ /**
+ * Sets the label of this break statement.
+ *
+ * @param label the label.
+ */
+ public void setLabel(String label) {
+ setElementAt(label, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CaseGroup.java b/src/main/java/io/devnulllabs/openjava/ptree/CaseGroup.java
new file mode 100644
index 0000000..3fc130a
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CaseGroup.java
@@ -0,0 +1,42 @@
+/*
+ * CaseGroupjava 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 29, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ *
+ */
+public class CaseGroup extends NonLeaf {
+
+ public CaseGroup(ExpressionList cll, StatementList bsl) {
+ super();
+ set(cll, bsl);
+ }
+
+ CaseGroup() {
+ super();
+ }
+
+ public ExpressionList getLabels() {
+ return (ExpressionList) elementAt(0);
+ }
+
+ public StatementList getStatements() {
+ return (StatementList) elementAt(1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CaseGroupList.java b/src/main/java/io/devnulllabs/openjava/ptree/CaseGroupList.java
new file mode 100644
index 0000000..8efb2cf
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CaseGroupList.java
@@ -0,0 +1,119 @@
+/*
+ * CaseGroupList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The CaseGroupList class presents for the node of parse tree
+ * of CaseGroup
+ *
+ */
+public class CaseGroupList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public CaseGroupList() {
+ super(LNLN);
+ }
+
+ public CaseGroupList(CaseGroup e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public CaseGroup get(int n) {
+ return (CaseGroup) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p CaseGroup to be inserted into the list
+ */
+ public void add(CaseGroup p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p CaseGroup to be inserted into the list
+ */
+ public void set(int index, CaseGroup p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public CaseGroup remove(int index) {
+ CaseGroup removed = (CaseGroup) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(CaseGroup p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(CaseGroupList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public CaseGroupList subList(int from_index, int to_index) {
+ CaseGroupList result = new CaseGroupList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CaseLabel.java b/src/main/java/io/devnulllabs/openjava/ptree/CaseLabel.java
new file mode 100644
index 0000000..eb4fdfb
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CaseLabel.java
@@ -0,0 +1,39 @@
+/*
+ * CaseLabel.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The CaseLabel class presents for the ptree-node like
+ * "case 1 :"
+ *
+ */
+public class CaseLabel extends NonLeaf {
+ public CaseLabel(Expression expr) {
+ super();
+ set((ParseTree) expr);
+ }
+
+ CaseLabel() {
+ super();
+ }
+
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CaseLabelList.java b/src/main/java/io/devnulllabs/openjava/ptree/CaseLabelList.java
new file mode 100644
index 0000000..8540d48
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CaseLabelList.java
@@ -0,0 +1,119 @@
+/*
+ * CaseLabelList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The CaseLabelList class presents for the node of parse tree
+ * of CaseLabel
+ *
+ */
+public class CaseLabelList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public CaseLabelList() {
+ super(LNLN);
+ }
+
+ public CaseLabelList(CaseLabel e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public CaseLabel get(int n) {
+ return (CaseLabel) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p CaseLabel to be inserted into the list
+ */
+ public void add(CaseLabel p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p CaseLabel to be inserted into the list
+ */
+ public void set(int index, CaseLabel p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public CaseLabel remove(int index) {
+ CaseLabel removed = (CaseLabel) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(CaseLabel p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(CaseLabelList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public CaseLabelList subList(int from_index, int to_index) {
+ CaseLabelList result = new CaseLabelList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CastExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/CastExpression.java
new file mode 100644
index 0000000..fe0f208
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CastExpression.java
@@ -0,0 +1,103 @@
+/*
+ * CastExpression.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>CastExpression</code> class represents
+ * a cast expression of parse tree.
+ * <br>
+ * If the operator in the expression of the right operand has week unity,
+ * this automatically produces the code in which the right operand
+ * is enclosed by parenthesises.
+ * <br>
+ * In the case the caster is <code>int</code> and
+ * the right operand to be casted is <code>p + q</code>,
+ * this produces the code :
+ * <br><blockquote><pre>
+ * (int) (p + q)
+ * </pre></blockquote><br>
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ */
+public class CastExpression extends NonLeaf implements Expression {
+ /**
+ * Allocates a new object.
+ *
+ * @param ts the type specifier to cast in this expression.
+ * @param expr the expression to be casted in this expression.
+ */
+ public CastExpression(TypeName ts, Expression expr) {
+ super();
+ set((ParseTree) ts, (ParseTree) expr);
+ }
+
+ public CastExpression(OJClass type, Expression expr) {
+ this(TypeName.forOJClass(type), expr);
+ }
+
+ CastExpression() {
+ super();
+ }
+
+ /**
+ * Gets the type specifier to cast in this expression.
+ *
+ * @return the type specifier.
+ */
+ public TypeName getTypeSpecifier() {
+ return (TypeName) elementAt(0);
+ }
+
+ /**
+ * Sets the type specifier to cast in this expression.
+ *
+ * @param tspec the type specifier.
+ */
+ public void setTypeSpecifier(TypeName tspec) {
+ setElementAt(tspec, 0);
+ }
+
+ /**
+ * Gets the expression of the operand to be casted in this expression.
+ *
+ * @return the expression.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(1);
+ }
+
+ /**
+ * Sets the expression of the operand to be casted in this expression.
+ *
+ * @param expr the expression.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ String qname = env.toQualifiedName(getTypeSpecifier().toString());
+ return env.lookupClass(qname);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CatchBlock.java b/src/main/java/io/devnulllabs/openjava/ptree/CatchBlock.java
new file mode 100644
index 0000000..49a1cb7
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CatchBlock.java
@@ -0,0 +1,84 @@
+/*
+ * CatchBlock.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The CatchBlock class presents catch node of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Parameter
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ */
+public class CatchBlock extends NonLeaf {
+ /**
+ * Allocates a new CatchBlock object.
+ *
+ * @param typespec the exception type specifier.
+ * @param name the exception variable name.
+ * @param stmts the statement list of the body.
+ */
+ public CatchBlock(Parameter param, StatementList stmts) {
+ super();
+ if (stmts == null) {
+ stmts = new StatementList();
+ }
+ set(param, stmts);
+ }
+
+ CatchBlock() {
+ super();
+ }
+
+ /**
+ * Gets the exception parameter of this catch block.
+ *
+ * @return the exception parameter.
+ */
+ public Parameter getParameter() {
+ return (Parameter) elementAt(0);
+ }
+
+ /**
+ * Sets the exception parameter of this catch block.
+ *
+ * @param tspec the exception parameter.
+ */
+ public void setParameter(Parameter param) {
+ setElementAt(param, 0);
+ }
+
+ /**
+ * Gets the body of this catch block.
+ *
+ * @return the statement list of the body.
+ */
+ public StatementList getBody() {
+ return (StatementList) elementAt(1);
+ }
+
+ /**
+ * Sets the body of this catch block.
+ *
+ * @param stmts the statement list of the body.
+ */
+ public void setBody(StatementList stmts) {
+ setElementAt(stmts, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CatchList.java b/src/main/java/io/devnulllabs/openjava/ptree/CatchList.java
new file mode 100644
index 0000000..939f590
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CatchList.java
@@ -0,0 +1,119 @@
+/*
+ * CatchList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The CatchList class presents for the node of parse tree
+ * of CatchBlock
+ *
+ */
+public class CatchList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public CatchList() {
+ super(LNLN);
+ }
+
+ public CatchList(CatchBlock e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public CatchBlock get(int n) {
+ return (CatchBlock) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p CatchBlock to be inserted into the list
+ */
+ public void add(CatchBlock p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p CatchBlock to be inserted into the list
+ */
+ public void set(int index, CatchBlock p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public CatchBlock remove(int index) {
+ CatchBlock removed = (CatchBlock) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(CatchBlock p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(CatchList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public CatchList subList(int from_index, int to_index) {
+ CatchList result = new CatchList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclaration.java b/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclaration.java
new file mode 100644
index 0000000..d5894f9
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclaration.java
@@ -0,0 +1,213 @@
+/*
+ * ClassDeclaration.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ClassDeclaration class presents class declaraton node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.TypeDeclaration
+ */
+public class ClassDeclaration extends NonLeaf implements Statement, MemberDeclaration, ParseTree {
+ private String[] metaclazz = null;
+ private Hashtable suffixes = null;
+ private boolean _isInterface = false;
+
+ /**
+ * Constructs ClassDeclaration from its elements.
+ *
+ * @param modiflist
+ * modifier list
+ * @param name
+ * class name
+ * @param zuper
+ * arg zuper is null means class decl has no super class
+ * @param interfacelist
+ * if class decl has no implemants, arg interfacelist should be
+ * set an empty list
+ * @param fieldlist
+ * field declaration list (body of new class)
+ */
+ public ClassDeclaration(ModifierList modiflist, String name, TypeName[] baseclasses, TypeName[] ifaces,
+ MemberDeclarationList fieldlist) {
+ this(modiflist, name, baseclasses, ifaces, fieldlist, true);
+ }
+
+ public ClassDeclaration(ModifierList modiflist, String name, TypeName[] baseclasses, TypeName[] ifaces,
+ MemberDeclarationList fieldlist, boolean is_class) {
+ super();
+ baseclasses = (baseclasses == null) ? new TypeName[0] : baseclasses;
+ ifaces = (ifaces == null) ? new TypeName[0] : ifaces;
+ set(modiflist, name, baseclasses, ifaces, fieldlist);
+ this._isInterface = (!is_class);
+ }
+
+ public boolean isInterface() {
+ return this._isInterface;
+ }
+
+ public void beInterface(boolean isInterface) {
+ this._isInterface = isInterface;
+ }
+
+ /**
+ * Gets modifier list
+ *
+ * @return there is no modifiers, getModifierList returns an empty list.
+ */
+ public ModifierList getModifiers() {
+ return (ModifierList) elementAt(0);
+ }
+
+ /**
+ * Sets modifier list
+ *
+ * @param modifs
+ * modifiers to set
+ */
+ public void setModifiers(ModifierList modifs) {
+ setElementAt(modifs, 0);
+ }
+
+ /**
+ * Gets the class name.
+ *
+ * @return class name
+ */
+ public String getName() {
+ return (String) elementAt(1);
+ }
+
+ /**
+ * Sets a class name in extends clause.
+ *
+ * @param name
+ * name to set
+ */
+ public void setName(String name) {
+ setElementAt(name, 1);
+ }
+
+ /**
+ * Gets the classes in 'extends' clause. This causes
+ *
+ * @return if class decl has no extends, this returns null otherwise returns
+ * the name of the super class.
+ */
+ public TypeName[] getBaseclasses() {
+ return (TypeName[]) elementAt(2);
+ }
+
+ /**
+ * Gets base classes in 'extends' clause.
+ *
+ * @return if class decl has no extends, this returns null otherwise returns
+ * the name of the super class.
+ */
+ public TypeName getBaseclass() {
+ TypeName[] bases = getBaseclasses();
+ if (bases.length == 0)
+ return null;
+ return bases[0];
+ }
+
+ /**
+ * Sets super class name
+ *
+ * @param ctypes
+ * class types to set
+ */
+ public void setBaseclasses(TypeName[] ctypes) {
+ setElementAt(ctypes, 2);
+ }
+
+ /**
+ * Sets super class name
+ *
+ * @param ctype
+ * class type to set
+ */
+ public void setBaseclass(TypeName ctype) {
+ setElementAt(new TypeName[] { ctype }, 2);
+ }
+
+ /**
+ * Gets interface name list
+ *
+ * @return there is no implemented class, getInterfaceList returns an empty
+ * list
+ */
+ public TypeName[] getInterfaces() {
+ return (TypeName[]) elementAt(3);
+ }
+
+ /**
+ * Sets interface name list
+ *
+ * @param ctlist
+ * class type list to set
+ */
+ public void setInterfaces(TypeName[] ctlist) {
+ setElementAt(ctlist, 3);
+ }
+
+ /**
+ * Gets class body
+ *
+ * @return return an field declaration list as this class body.
+ */
+ public MemberDeclarationList getBody() {
+ return (MemberDeclarationList) elementAt(4);
+ }
+
+ /**
+ * Sets class body
+ *
+ * @param body
+ * member declaration list to set as this class body.
+ */
+ public void setBody(MemberDeclarationList mdlist) {
+ setElementAt(mdlist, 4);
+ }
+
+ public void setSuffixes(Hashtable suffixes) {
+ this.suffixes = suffixes;
+ }
+
+ public Hashtable getSuffixes() {
+ return this.suffixes;
+ }
+
+ public void setMetaclass(String metaclazz) {
+ this.metaclazz = new String[] { metaclazz };
+ }
+
+ public void setMetaclass(String[] metaclazz) {
+ this.metaclazz = metaclazz;
+ }
+
+ public String getMetaclass() {
+ if (metaclazz == null || metaclazz.length == 0)
+ return null;
+ return this.metaclazz[0];
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclarationList.java b/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclarationList.java
new file mode 100644
index 0000000..9739fab
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclarationList.java
@@ -0,0 +1,119 @@
+/*
+ * ClassDeclarationList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ClassDeclarationList class presents for the node of parse tree
+ * of ClassDeclaration
+ *
+ */
+public class ClassDeclarationList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public ClassDeclarationList() {
+ super(LNLN);
+ }
+
+ public ClassDeclarationList(ClassDeclaration e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public ClassDeclaration get(int n) {
+ return (ClassDeclaration) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p ClassDeclaration to be inserted into the list
+ */
+ public void add(ClassDeclaration p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p ClassDeclaration to be inserted into the list
+ */
+ public void set(int index, ClassDeclaration p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public ClassDeclaration remove(int index) {
+ ClassDeclaration removed = (ClassDeclaration) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(ClassDeclaration p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(ClassDeclarationList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public ClassDeclarationList subList(int from_index, int to_index) {
+ ClassDeclarationList result = new ClassDeclarationList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ClassLiteral.java b/src/main/java/io/devnulllabs/openjava/ptree/ClassLiteral.java
new file mode 100644
index 0000000..a10b536
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ClassLiteral.java
@@ -0,0 +1,84 @@
+/*
+ * ClassLiteral.java 1.0
+ *
+ *
+ * Jun 20, 1997
+ * Oct 10, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 29, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+
+
+/**
+ * The <code>ClassLiteral</code> class represents
+ * an expression as a object of <code>Class</code> class,
+ * which is suppoted since JDK 1.1.
+ * This is like :
+ * <br><blockquote><pre>
+ * String.class
+ * </pre></blockquote><br>
+ * or :
+ * <br><blockquote><pre>
+ * int.class
+ * </pre></blockquote><br>
+ *
+ * @see java.lang.Class
+ * @see io.devnulllabs.openjava.ptree.Leaf
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ */
+public class ClassLiteral extends NonLeaf
+ implements Expression
+{
+
+ /**
+ * Allocates a new object.
+ *
+ */
+ public ClassLiteral( TypeName type ) {
+ super();
+ set(type);
+ }
+
+ public ClassLiteral( OJClass type ) {
+ this( TypeName.forOJClass( type ) );
+ }
+
+ /**
+ * Gets the type name of this class literal.
+ *
+ * @return the type name.
+ */
+ public TypeName getTypeName() {
+ return (TypeName) elementAt(0);
+ }
+
+ /**
+ * Sets the type name of this class literal.
+ *
+ * @param type the type name.
+ */
+ public void setTypeName(TypeName type) {
+ set(type);
+ }
+
+ public OJClass getType( Environment env )
+ throws Exception
+ {
+ return OJClass.forClass( Class . class );
+ }
+
+ public void accept( ParseTreeVisitor v ) throws ParseTreeException {
+ v.visit( this );
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/CompilationUnit.java b/src/main/java/io/devnulllabs/openjava/ptree/CompilationUnit.java
new file mode 100644
index 0000000..eb99b5a
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/CompilationUnit.java
@@ -0,0 +1,151 @@
+/*
+ * CompilationUnit.java 1.0
+ *
+ * This subclass of symbol represents (at least) terminal symbols returned
+ * by the scanner and placed on the parse stack. At present, this
+ * class does nothing more than its super class.
+ *
+ * Jun 11, 1997 by mich
+ * Sep 27, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 27, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The CompilationUnit class presents for the whole parse tree in a file.
+ *
+ * CompilationUnits consists of
+ * (package statement) (import statement list) (type declaration list)
+ * QualifiedName ImportStatementList ClassDeclarationList
+ *
+ * @see io.devnulllabs.openjava.ptree.ClassDeclarationList
+ */
+public class CompilationUnit extends NonLeaf {
+ /**
+ * Allocates this object with specified parse-tree elements.
+ *
+ */
+ public CompilationUnit(String e0, String[] e1, ClassDeclarationList e2) {
+ super();
+ if (e1 == null)
+ e1 = new String[0];
+ if (e2 == null)
+ e2 = new ClassDeclarationList();
+ set(e0, e1, e2);
+ }
+
+ /**
+ * Sets the package of this compilation unit
+ *
+ * @param qn the qualified name indicating this package
+ */
+ public void setPackage(String qn) {
+ setElementAt(qn, 0);
+ }
+
+ /**
+ * Obtains the package of this compilation unit
+ *
+ * @return the qualified name indicating this package
+ */
+ public String getPackage() {
+ return (String) elementAt(0);
+ }
+
+ /**
+ * Sets the import statement list of this compilation unit
+ *
+ * @param islst the import statement list of this compilation unit
+ */
+ public void setDeclaredImports(String[] islst) {
+ setElementAt(islst, 1);
+ }
+
+ /**
+ * Obtains the import statement list of this compilation unit
+ *
+ * @return the import statement list of this compilation unit
+ */
+ public String[] getDeclaredImports() {
+ return (String[]) elementAt(1);
+ }
+
+ /**
+ * Sets the type declaration list of this compilation unit
+ *
+ * @param tdlst the type declaration list of this compilation unit
+ */
+ public void setClassDeclarations(ClassDeclarationList tdlst) {
+ setElementAt(tdlst, 2);
+ }
+
+ /**
+ * Obtains the type declaration list of this compilation unit
+ *
+ * @return the type declaration list of this compilation unit
+ */
+ public ClassDeclarationList getClassDeclarations() {
+ return (ClassDeclarationList) elementAt(2);
+ }
+
+ /**
+ * Obtains the public class in this compilation unit.
+ *
+ * @return the public class
+ * @exception ParseTreeException if not one public class is declared.
+ */
+ public ClassDeclaration getPublicClass() throws ParseTreeException {
+ ClassDeclaration ret = null;
+
+ ClassDeclarationList tdecls = getClassDeclarations();
+ for (int i = 0, len = tdecls.size(); i < len; ++i) {
+ ClassDeclaration cdecl = tdecls.get(i);
+ if (cdecl.getModifiers().contains(ModifierList.PUBLIC)) {
+ if (ret != null) {
+ throw new ParseTreeException(
+ "getPublicClass() "
+ + "in CompileationUnit : "
+ + "multiple public class");
+ }
+ ret = cdecl;
+ }
+ }
+
+ return ret;
+ }
+
+ /**
+ * Tests if the declared import string represents on demand
+ * importation. For example, if the specified string is
+ * <code>java.lang.*</code>, this returns true, and if
+ * <code>java.lang.Object</code>, returns false;
+ *
+ * @param import_decl declared importation.
+ * @return true if the string ends with ".*".
+ **/
+ public static boolean isOnDemandImport(String import_decl) {
+ return (import_decl.endsWith(".*"));
+ }
+
+ /**
+ * Removes ".*" at tail if it exists.
+ *
+ * @param import_decl declared importation.
+ * @return a string trimmed ".*" off
+ **/
+ public static String trimOnDemand(String import_decl) {
+ if (isOnDemandImport(import_decl)) {
+ return import_decl.substring(0, import_decl.length() - 2);
+ }
+ return import_decl;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ConditionalExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/ConditionalExpression.java
new file mode 100644
index 0000000..424c416
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ConditionalExpression.java
@@ -0,0 +1,129 @@
+/*
+ * ConditionalExpression.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ConditionalExpression</code> class represents
+ * a conditional expression like:
+ * <br><blockquote><pre>
+ * (i == 1) ? 3 : 4
+ * </pre></blockquote><br>
+ * This consists of a conditional part, true case part, and
+ * false case part.
+ * Each part of them is an expression.
+ * <br>
+ * If the operator in the expression of the operands has week unity,
+ * this automatically produces the code in which the operands
+ * are enclosed by parenthesises.
+ * <br>
+ * In the case the conditional part is <code>f = f()</code>,
+ * the true case part is <code>"red"</code>
+ * and the false case part is <code>str = "blue"</code>
+ * this produces the code :
+ * <br><blockquote><pre>
+ * (f = f()) ? "red" : (str = "blue")
+ * </pre></blockquote><br>
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class ConditionalExpression extends NonLeaf implements Expression {
+ /**
+ * Allocates a new conditional expression object.
+ *
+ * @param condition the conditional part of this expression.
+ * @param truecase the expression to be evaluated when conditional
+ * part is true.
+ * @param falsecase the expression to be evaluated when conditional
+ * part is false.
+ */
+ public ConditionalExpression(
+ Expression condition,
+ Expression truecase,
+ Expression falsecase) {
+ super();
+ set(condition, truecase, falsecase);
+ }
+
+ ConditionalExpression() {
+ super();
+ }
+
+ /**
+ * Gets the conditional part of this conditional expression.
+ *
+ * @return the expression of this conditional part.
+ */
+ public Expression getCondition() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the conditional part of this conditional expression.
+ *
+ * @param expr the expression to set as this conditional part.
+ */
+ public void setCondition(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the true case part of this conditional expression.
+ *
+ * @return the expression of this true case part.
+ */
+ public Expression getTrueCase() {
+ return (Expression) elementAt(1);
+ }
+
+ /**
+ * Sets the true case part of this conditional expression.
+ *
+ * @param expr the expression to set as this true part.
+ */
+ public void setTrueCase(Expression expr) {
+ setElementAt(expr, 1);
+ }
+
+ /**
+ * Gets the false case part of this.
+ *
+ * @return the expression of this false case part.
+ */
+ public Expression getFalseCase() {
+ return (Expression) elementAt(2);
+ }
+
+ /**
+ * Sets the false case part of this.
+ *
+ * @param expr the expression to set as this false part.
+ */
+ public void setFalseCase(Expression expr) {
+ setElementAt(expr, 2);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ return BinaryExpression.chooseType(
+ getTrueCase().getType(env),
+ getFalseCase().getType(env));
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ConstructorDeclaration.java b/src/main/java/io/devnulllabs/openjava/ptree/ConstructorDeclaration.java
new file mode 100644
index 0000000..dacd01e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ConstructorDeclaration.java
@@ -0,0 +1,231 @@
+/*
+ * ConstructorDeclaration.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ConstructorDeclaration</code> class represents
+ * constructor declaration node of the parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.MemberDeclaration
+ * @see io.devnulllabs.openjava.ptree.ModifierList
+ * @see io.devnulllabs.openjava.ptree.ParameterList
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ * @see io.devnulllabs.openjava.ptree.ConstructorInvocation
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ */
+public class ConstructorDeclaration
+ extends NonLeaf
+ implements MemberDeclaration {
+
+ private Hashtable suffixes = null;
+
+ /**
+ * Constructs new ConstructorDeclaration from its elements.
+ *
+ * @param modiflist modifier list, if it has no modifier list
+ * then thes arg is set empty list.
+ * @param name name of this constructor.
+ * @param params parameter list
+ * @param throwlist throw type list, if there is no throws
+ * then this arg is set empty list
+ * @param scstmt statement which calls another constructor
+ * if this is null, it means no another constructor
+ * call exists.
+ * @param stmtlist statement list of this constructor body.
+ * if this is null, it means method body is with
+ * only semi colon.
+ */
+ public ConstructorDeclaration(
+ ModifierList modiflist,
+ String name,
+ ParameterList params,
+ TypeName[] throwlist,
+ ConstructorInvocation scstmt,
+ StatementList stmtlist) {
+ super();
+ if (modiflist == null)
+ modiflist = new ModifierList();
+ if (params == null)
+ params = new ParameterList();
+ if (throwlist == null)
+ throwlist = new TypeName[0];
+ set(modiflist, name, params, throwlist, scstmt, stmtlist);
+ }
+
+ /**
+ * Constructs new ConstructorDeclaration from its elements.
+ *
+ * @param modiflist modifier list, if it has no modifier list
+ * then thes arg is set empty list.
+ * @param name name of this constructor.
+ * @param params parameter list
+ * @param throwlist throw type list, if there is no throws
+ * then this arg is set empty list
+ * @param stmtlist statement list of this constructor body.
+ * if this is null, it means method body is with
+ * only semi colon.
+ */
+ public ConstructorDeclaration(
+ ModifierList modiflist,
+ String name,
+ ParameterList params,
+ TypeName[] throwlist,
+ StatementList stmtlist) {
+ this(modiflist, name, params, throwlist, null, stmtlist);
+ }
+
+ /** for recursive copy */
+ ConstructorDeclaration() {
+ super();
+ }
+
+ /**
+ * Gets modifier list.
+ *
+ * @return modifier list.
+ */
+ public ModifierList getModifiers() {
+ return (ModifierList) elementAt(0);
+ }
+
+ /**
+ * Sets modifier list.
+ *
+ * @param modifs modifier list.
+ */
+ public void setModifiers(ModifierList modifs) {
+ if (modifs == null) {
+ modifs = new ModifierList();
+ }
+ setElementAt(modifs, 0);
+ }
+
+ /**
+ * Gets the name of this constructor node.
+ *
+ * @return constructor declarator node.
+ */
+ public String getName() {
+ return (String) elementAt(1);
+ }
+
+ /**
+ * Sets the name of this constructor node.
+ *
+ * @param name the name to be set.
+ */
+ public void setName(String name) {
+ setElementAt(name, 1);
+ }
+
+ /**
+ * Gets the parameter list.
+ *
+ * @return parameter list for constructor.
+ */
+ public ParameterList getParameters() {
+ return (ParameterList) elementAt(2);
+ }
+
+ /**
+ * Sets the parameter list.
+ *
+ * @param params parameterlist for constructor declarator node.
+ */
+ public void setParameters(ParameterList params) {
+ if (params == null) {
+ params = new ParameterList();
+ }
+ setElementAt(params, 2);
+ }
+
+ /**
+ * Gets the class type list thrown by this constructor.
+ *
+ * @return class type list thrown by this constructor.
+ */
+ public TypeName[] getThrows() {
+ return (TypeName[]) elementAt(3);
+ }
+
+ /**
+ * Sets the class type list thrown by this constructor.
+ *
+ * @param ctlist class type list thrown by this constructor.
+ */
+ public void setThrows(TypeName[] ctlist) {
+ if (ctlist == null) {
+ ctlist = new TypeName[0];
+ }
+ setElementAt(ctlist, 3);
+ }
+
+ /**
+ * Gets the special call statement.
+ * Special call statement is like:
+ * <br><blockquote><pre>
+ * super();
+ * </pre></blockquote><br>
+ *
+ * @return special call statement
+ */
+ public ConstructorInvocation getConstructorInvocation() {
+ return (ConstructorInvocation) elementAt(4);
+ }
+
+ /**
+ * Sets the special call statement.
+ *
+ * @param scstmt the special call statement to set
+ * @see io.devnulllabs.openjava.ptree.ConstructorDeclaration#getConstructorInvocation()
+ */
+ public void setConstructorInvocation(ConstructorInvocation scstmt) {
+ setElementAt(scstmt, 4);
+ }
+
+ /**
+ * Gets the statement list of this constructor body.
+ *
+ * @return the statement list of this constructor body.
+ */
+ public StatementList getBody() {
+ return (StatementList) elementAt(5);
+ }
+
+ /**
+ * Sets the statement list of this constructor body.
+ *
+ * @return the statement list of this constructor body.
+ */
+ public void setBody(StatementList stmts) {
+ setElementAt(stmts, 5);
+ }
+
+ public void setSuffixes(Hashtable suffixes) {
+ this.suffixes = suffixes;
+ }
+
+ public Hashtable getSuffixes() {
+ return this.suffixes;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ConstructorInvocation.java b/src/main/java/io/devnulllabs/openjava/ptree/ConstructorInvocation.java
new file mode 100644
index 0000000..539142e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ConstructorInvocation.java
@@ -0,0 +1,85 @@
+/*
+ * ConstructorInvocation.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ConstructorInvocation class presents expression statement node
+ * of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.ExpressionList
+ */
+public class ConstructorInvocation extends NonLeaf {
+
+ private boolean _isSelfInvocation = true;
+
+ /**
+ * Constructs a new constructor invocation.
+ * i.e. <code>this(..)</code>
+ *
+ * @param exprs arguments for this constructor invocation
+ */
+ public ConstructorInvocation(ExpressionList exprs) {
+ super();
+ this._isSelfInvocation = true;
+ if (exprs == null)
+ exprs = new ExpressionList();
+ set(exprs);
+ }
+
+ /**
+ * Constructs a new constructor invocation.
+ * i.e. <code>super(..)</code>
+ *
+ * @param exprs arguments for this constructor invocation
+ * @param enclosing outerclass qualifier.
+ */
+ public ConstructorInvocation(ExpressionList exprs, Expression enclosing) {
+ super();
+ this._isSelfInvocation = false;
+ if (exprs == null)
+ exprs = new ExpressionList();
+ set(exprs, enclosing);
+ }
+
+ ConstructorInvocation() {
+ super();
+ }
+
+ /*********need modification for copy******/
+
+ public boolean isSelfInvocation() {
+ return _isSelfInvocation;
+ }
+
+ /**
+ * Gets the expressions as arguments for this invocation.
+ *
+ * @return the expressions.
+ */
+ public ExpressionList getArguments() {
+ return (ExpressionList) elementAt(0);
+ }
+
+ public Expression getEnclosing() {
+ return (Expression) elementAt(1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ContinueStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/ContinueStatement.java
new file mode 100644
index 0000000..71a7926
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ContinueStatement.java
@@ -0,0 +1,68 @@
+/*
+ * ContinueStatement.java 1.0
+ *
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ContinueStatement</code> class represents
+ * a continue statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class ContinueStatement extends NonLeaf implements Statement {
+
+ /**
+ * Allocates a new ContinueStatement object.
+ *
+ * @param label the label name.
+ */
+ public ContinueStatement(String label) {
+ super();
+ set(label);
+ }
+
+ /**
+ * Allocates a new ContinueStatement object.
+ *
+ */
+ public ContinueStatement() {
+ this(null);
+ }
+
+ /**
+ * Gets the label of this break statement.
+ *
+ * @return the label name.
+ * If there is no label then this method returns null.
+ */
+ public String getLabel() {
+ return (String) elementAt(0);
+ }
+
+ /**
+ * Sets the label of this break statement.
+ *
+ * @param label the label.
+ */
+ public void setLabel(String label) {
+ setElementAt(label, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/DoWhileStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/DoWhileStatement.java
new file mode 100644
index 0000000..e73cd34
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/DoWhileStatement.java
@@ -0,0 +1,81 @@
+/*
+ * DoWhileStatement.java 1.0
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 11, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>DoWhileStatement</code> class represents a do-while
+ * statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class DoWhileStatement extends NonLeaf implements Statement, ParseTree {
+ /**
+ * Allocates a new object.
+ *
+ * @param stmts the statement list of the body.
+ * @param expr the expression of the condition.
+ */
+ public DoWhileStatement(StatementList stmts, Expression expr) {
+ super();
+ set((ParseTree) stmts, (ParseTree) expr);
+ }
+
+ DoWhileStatement() {
+ super();
+ }
+
+ /**
+ * Gets the body of this do-while statement.
+ *
+ * @return the statement list of the body.
+ */
+ public StatementList getStatements() {
+ return (StatementList) elementAt(0);
+ }
+
+ /**
+ * Sets the body of this do-while statement.
+ *
+ * @param stmts the statement list of the body to set.
+ */
+ public void setStatements(StatementList stmts) {
+ setElementAt(stmts, 0);
+ }
+
+ /**
+ * Gets the condtion of this do-while statement.
+ *
+ * @return the expression of the condtion.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(1);
+ }
+
+ /**
+ * Sets the condtion of this do-while statement.
+ *
+ * @param expr the expression of the condtion to set.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/EmptyStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/EmptyStatement.java
new file mode 100644
index 0000000..e7021ce
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/EmptyStatement.java
@@ -0,0 +1,38 @@
+/*
+ * EmptyStatement.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 23, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 23, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The EmptyStatement class represents an empty statement node
+ * of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class EmptyStatement extends NonLeaf implements Statement {
+ /**
+ * Allocates a new object.
+ *
+ * @param statement prototype object
+ */
+ public EmptyStatement() {
+ super();
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Expression.java b/src/main/java/io/devnulllabs/openjava/ptree/Expression.java
new file mode 100644
index 0000000..aa90b6b
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Expression.java
@@ -0,0 +1,50 @@
+/*
+ * Expression.java 1.0
+ *
+ *
+ * Jun 20, 1997
+ * Sep 29, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 29, 1997
+ * @author Teruo -bv- Koyanagi
+ */
+package io.devnulllabs.openjava.ptree;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+
+
+
+/**
+ * The Expression interface presents common interface
+ * to access Expression node of parse tree
+ *
+ * this interface is implements by
+ * <pre>
+ * UnaryExpression
+ * BinaryExpression
+ * ConditionalExpression
+ * AssignmentExpression
+ * CastExpression
+ * AllocationExpression
+ * ArrayAllocationExpression
+ * Variable
+ * MethodCall
+ * SpecialName
+ * Literal
+ * ClassLiteral
+ * ArrayAccess
+ * FieldAccess
+ * </pre>
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.VariableInitializer
+ */
+public interface Expression extends ParseTree, VariableInitializer
+{
+ public OJClass getType( Environment env )
+ throws Exception;
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ExpressionList.java b/src/main/java/io/devnulllabs/openjava/ptree/ExpressionList.java
new file mode 100644
index 0000000..d5801dc
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ExpressionList.java
@@ -0,0 +1,129 @@
+/*
+ * ExpressionList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ExpressionList class presents for the node of parse tree
+ * of Expression
+ *
+ */
+public class ExpressionList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public ExpressionList() {
+ super(LNLN);
+ }
+
+ public ExpressionList(Expression e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ public ExpressionList(Expression e0, Expression e1) {
+ this(e0);
+ add(e1);
+ }
+
+ public ExpressionList(Expression e0, Expression e1, Expression e2) {
+ this(e0, e1);
+ add(e2);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public Expression get(int n) {
+ return (Expression) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Expression to be inserted into the list
+ */
+ public void add(Expression p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Expression to be inserted into the list
+ */
+ public void set(int index, Expression p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public Expression remove(int index) {
+ Expression removed = (Expression) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(Expression p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(ExpressionList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public ExpressionList subList(int from_index, int to_index) {
+ ExpressionList result = new ExpressionList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ExpressionObject.java b/src/main/java/io/devnulllabs/openjava/ptree/ExpressionObject.java
new file mode 100644
index 0000000..d4c4e75
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ExpressionObject.java
@@ -0,0 +1,83 @@
+/*
+ * ExpressionObject.java 1.0
+ *
+ *
+ * June 23, 2000
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: June 23, 2000
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+
+
+
+/**
+ * The Expression interface presents common interface
+ * to access Expression node of parse tree
+ *
+ * this interface is implements by
+ * <pre>
+ * UnaryExpression
+ * BinaryExpression
+ * ConditionalExpression
+ * AssignmentExpression
+ * CastExpression
+ * AllocationExpression
+ * ArrayAllocationExpression
+ * Variable
+ * MethodCall
+ * SpecialName
+ * Literal
+ * ClassLiteral
+ * ArrayAccess
+ * FieldAccess
+ * </pre>
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public abstract class ExpressionObject extends NonLeaf
+ implements Expression
+{
+ private OJClass cachedType = null;
+
+ void soilCache() {
+ cachedType = null;
+ ParseTree parent = getParent();
+ if (parent instanceof ExpressionObject) {
+ ExpressionObject pexp = (ExpressionObject) parent;
+ pexp.soilCache();
+ }
+ }
+
+ /**
+ * dirty implementation
+ */
+ public OJClass getCachedType(Environment env) throws Exception {
+ if (cachedType == null) cachedType = getType(env);
+ return cachedType;
+ }
+
+ public abstract OJClass getType(Environment env, boolean using_cache)
+ throws Exception;
+
+ public abstract OJClass getType(Environment env)
+ throws Exception;
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p ]
+ *
+ * @param p list's element
+ */
+ protected void set( Object[] ptrees ) {
+ soilCache();
+ super.set(ptrees);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ExpressionStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/ExpressionStatement.java
new file mode 100644
index 0000000..40c62a6
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ExpressionStatement.java
@@ -0,0 +1,62 @@
+/*
+ * ExpressionStatement.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ExpressionStatement class presents expression statement node
+ * of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class ExpressionStatement extends NonLeaf implements Statement {
+ /**
+ * Allocates a new object.
+ *
+ * @param statement prototype object
+ */
+ public ExpressionStatement(Expression expr) {
+ super();
+ set((ParseTree) expr);
+ }
+
+ ExpressionStatement() {
+ super();
+ }
+
+ /**
+ * Gets the expression of this statement.
+ *
+ * @return the expression.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression of this statement.
+ *
+ * @param the expression to set.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/FieldAccess.java b/src/main/java/io/devnulllabs/openjava/ptree/FieldAccess.java
new file mode 100644
index 0000000..6442242
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/FieldAccess.java
@@ -0,0 +1,190 @@
+/*
+ * FieldAccess.java 1.0
+ *
+ * Jun 20, 1997
+ * Sep 29, 1997
+ * Oct 10, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.NoSuchMemberException;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJField;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>FieldAccess</code> class represents
+ * a field access like :
+ * <br><blockquote><pre>
+ * f().str
+ * </pre></blockquote><br>
+ * In this field access,
+ * you can get <code>f()</code> by <code>getReferenceExpr()</code>
+ * and can get <code>str</code> by <code>getName()</code> .
+ * <br>
+ * Warning this class may has bugs around the expression.
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class FieldAccess extends NonLeaf implements Expression {
+
+ /**
+ * An access to the specified field of the given expression.
+ */
+ public FieldAccess(Expression expr, String name) {
+ super();
+ set(expr, name);
+ }
+
+ /**
+ * An access to the specified static field of the type.
+ */
+ public FieldAccess(TypeName typename, String name) {
+ super();
+ set(typename, name);
+ }
+
+ /**
+ * An access to the specified static field of the type.
+ */
+ public FieldAccess(OJClass clazz, String name) {
+ this(TypeName.forOJClass(clazz), name);
+ }
+
+ /**
+ * An access to the specified field of self.
+ */
+ public FieldAccess(String name) {
+ this((Expression) null, name);
+ }
+
+ FieldAccess() {
+ super();
+ }
+
+ public ParseTree getReference() {
+ return (ParseTree) elementAt(0);
+ }
+
+ public boolean isTypeReference() {
+ return (getReference() instanceof TypeName);
+ }
+
+ /**
+ * Gets the expression accessed.
+ *
+ * @return the expression accessed.
+ */
+ public Expression getReferenceExpr() {
+ if (isTypeReference())
+ return null;
+ return (Expression) getReference();
+ }
+
+ /**
+ * Sets the expression accessed.
+ *
+ * @param expr the expression accessed.
+ */
+ public void setReferenceExpr(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ public TypeName getReferenceType() {
+ if (!isTypeReference())
+ return null;
+ return (TypeName) getReference();
+ }
+
+ public void setReferenceType(TypeName typename) {
+ setElementAt(typename, 0);
+ }
+
+ /**
+ * Gets the field name.
+ *
+ * @return the field name.
+ */
+ public String getName() {
+ return (String) elementAt(1);
+ }
+
+ /**
+ * Sets the field name.
+ *
+ * @param name the field name.
+ */
+ public void setName(String name) {
+ setElementAt(name, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ OJClass selftype = env.lookupClass(env.currentClassName());
+
+ Expression refexpr = getReferenceExpr();
+ String name = getName();
+
+ OJClass reftype = null;
+
+ if (refexpr != null) {
+ reftype = refexpr.getType(env);
+ } else {
+ TypeName refname = getReferenceType();
+ if (refname != null) {
+ String qname = env.toQualifiedName(refname.toString());
+ reftype = env.lookupClass(qname);
+ }
+ }
+
+ OJField field = null;
+
+ if (reftype != null)
+ field = pickupField(reftype, name);
+ if (field != null)
+ return field.getType();
+
+ /* try to consult this class and outer classes */
+ if (reftype == null) {
+ OJClass declaring = selftype;
+ while (declaring != null) {
+ field = pickupField(declaring, name);
+ if (field != null)
+ return field.getType();
+
+ /* consult innerclasses */
+ OJClass[] inners = declaring.getDeclaredClasses();
+ for (int i = 0; i < inners.length; ++i) {
+ field = pickupField(inners[i], name);
+ if (field != null)
+ return field.getType();
+ }
+
+ declaring = declaring.getDeclaringClass();
+ }
+ reftype = selftype;
+ }
+
+ NoSuchMemberException e = new NoSuchMemberException(name);
+ field = reftype.resolveException(e, name);
+ return field.getType();
+ }
+
+ private static OJField pickupField(OJClass reftype, String name) {
+ try {
+ return reftype.getField(name, reftype);
+ } catch (NoSuchMemberException e) {
+ return null;
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/FieldDeclaration.java b/src/main/java/io/devnulllabs/openjava/ptree/FieldDeclaration.java
new file mode 100644
index 0000000..e629ef3
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/FieldDeclaration.java
@@ -0,0 +1,177 @@
+/*
+ * FieldDeclaration.java 1.0
+ *
+ * Jun 11, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 4, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The FieldDeclaration class presents for node of parse tree.
+ * FieldDeclaration
+ * := ModifierList TypeName VariableDeclarator SEMI
+ *
+ */
+public class FieldDeclaration extends NonLeaf implements MemberDeclaration {
+ private Hashtable suffixes = null;
+
+ /**
+ * Allocates this object
+ *
+ */
+ public FieldDeclaration(
+ ModifierList e0,
+ TypeName e1,
+ VariableDeclarator e2) {
+ super();
+ set(e0, e1, e2);
+ }
+
+ public FieldDeclaration(
+ ModifierList e0,
+ TypeName e1,
+ String e2,
+ VariableInitializer e3) {
+ super();
+ VariableDeclarator vd = new VariableDeclarator(e2, e3);
+ set(e0, e1, vd);
+ }
+
+ /**
+ * Is needed for recursive copy.
+ */
+ FieldDeclaration() {
+ super();
+ }
+
+ /**
+ * Gets modifier list of this field.
+ *
+ * @return modifier list. if there is no modifiers, this returns
+ * an empty list.
+ */
+ public ModifierList getModifiers() {
+ return (ModifierList) elementAt(0);
+ }
+
+ /**
+ * Sets modifier list of this field.
+ *
+ * @param modifs modifiers to set
+ */
+ public void setModifiers(ModifierList modifs) {
+ setElementAt(modifs, 0);
+ }
+
+ /**
+ * Gets type specifier of this field variable.
+ * Any modification on obtained objects is never reflected on
+ * this object.
+ *
+ * @return the type specifier for this field.
+ */
+ public TypeName getTypeSpecifier() {
+ TypeName result;
+ TypeName tn = (TypeName) elementAt(1);
+ VariableDeclarator vd = (VariableDeclarator) elementAt(2);
+ result = (TypeName) tn.makeCopy();
+ result.addDimension(vd.getDimension());
+ return result;
+ }
+
+ /**
+ * Sets type specifier of this field variable.
+ *
+ * @param tspec type specifier to set
+ */
+ public void setTypeSpecifier(TypeName tspec) {
+ setElementAt(tspec, 1);
+ }
+
+ /**
+ * Gets variable declarator of this field
+ *
+ * @return variable declarator
+ * @see io.devnulllabs.openjava.ptree.VariableDeclarator
+ * @deprecate
+ */
+ public VariableDeclarator getVariableDeclarator() {
+ return (VariableDeclarator) elementAt(2);
+ }
+
+ /**
+ * Sets type specifier of this field variable.
+ *
+ * @param vdeclr variable declarator to set
+ * @deprecate
+ */
+ public void setVariableDeclarator(VariableDeclarator vdeclr) {
+ setElementAt(vdeclr, 2);
+ }
+
+ /**
+ * Gets variable name of this field.
+ *
+ * @return identifier of field variable
+ */
+ public String getVariable() {
+ return (String) getVariableDeclarator().getVariable();
+ }
+
+ /**
+ * Gets variable name of this field.
+ *
+ * @return identifier of field variable
+ * @deprecate
+ */
+ public String getName() {
+ return (String) getVariableDeclarator().getVariable();
+ }
+
+ /**
+ * Sets variable name of this field.
+ *
+ * @param name identifier of field variable
+ */
+ public void setVariable(String name) {
+ getVariableDeclarator().setVariable(name);
+ }
+
+ /**
+ * Gets variable initializer of this field.
+ *
+ * @return variable initializer
+ */
+ public VariableInitializer getInitializer() {
+ return (VariableInitializer) getVariableDeclarator().getInitializer();
+ }
+
+ /**
+ * Gets variable initializer of this field.
+ *
+ * @return variable initializer
+ */
+ public void setInitializer(VariableInitializer vinit) {
+ getVariableDeclarator().setInitializer(vinit);
+ }
+
+ public void setSuffixes(Hashtable suffixes) {
+ this.suffixes = suffixes;
+ }
+
+ public Hashtable getSuffixes() {
+ return this.suffixes;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ForStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/ForStatement.java
new file mode 100644
index 0000000..d485451
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ForStatement.java
@@ -0,0 +1,196 @@
+/*
+ * ForStatement.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ForStatement</code> class represents a for statement
+ * node of parse tree.
+ * <br>
+ * The specification of the initialization part may be modified
+ * in the later version of OpenJava.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.ExpressionList
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ */
+public class ForStatement extends NonLeaf implements Statement, ParseTree {
+
+ /**
+ * Allocates a new ForStatement object.
+ *
+ */
+ ForStatement() {
+ super();
+ }
+
+ /**
+ * Allocates a new ForStatement object.
+ *
+ * @param init the initialization part.
+ * @param expr the condition part.
+ * @param iterator the increments part.
+ * @param stmts the stement list of the body.
+ */
+ public ForStatement(
+ ExpressionList init,
+ Expression expr,
+ ExpressionList iterator,
+ StatementList stmts) {
+ super();
+ if (iterator == null)
+ iterator = new ExpressionList();
+ if (stmts == null)
+ stmts = new StatementList();
+ set(null, null, init, expr, iterator, stmts);
+ }
+
+ public ForStatement(
+ TypeName tspec,
+ VariableDeclarator[] vdecls,
+ Expression expr,
+ ExpressionList iterator,
+ StatementList stmts) {
+ super();
+ if (stmts == null)
+ stmts = new StatementList();
+ if (tspec == null || vdecls == null || vdecls.length == 0) {
+ set(null, null, null, expr, iterator, stmts);
+ } else {
+ set(tspec, vdecls, null, expr, iterator, stmts);
+ }
+ }
+
+ /**
+ * Gets the initialization part of this for-statement.
+ *
+ * @return the initialization part.
+ */
+ public ExpressionList getInit() {
+ return (ExpressionList) elementAt(2);
+ }
+
+ /**
+ * Sets the initialization part of this for-statement.
+ *
+ * @param init the initialization part.
+ */
+ public void setInit(ExpressionList init) {
+ setElementAt(null, 0);
+ setElementAt(null, 1);
+ setElementAt(init, 2);
+ }
+
+ /**
+ * Gets the initialization part of this for-statement.
+ *
+ * @return the initialization part.
+ */
+ public TypeName getInitDeclType() {
+ return (TypeName) elementAt(0);
+ }
+
+ /**
+ * Gets the initialization part of this for-statement.
+ *
+ * @return the initialization part.
+ */
+ public VariableDeclarator[] getInitDecls() {
+ return (VariableDeclarator[]) elementAt(1);
+ }
+
+ /**
+ * Sets the initialization part of this for-statement.
+ *
+ * @param init the initialization part.
+ */
+ public void setInitDecl(
+ TypeName type_specifier,
+ VariableDeclarator[] init) {
+ if (type_specifier == null || init == null || init.length == 0) {
+ setElementAt(null, 0);
+ setElementAt(null, 1);
+ } else {
+ setElementAt(type_specifier, 0);
+ setElementAt(init, 1);
+ }
+ setElementAt(null, 2);
+ }
+
+ /**
+ * Gets the condition part of this for-statement.
+ *
+ * @return the expression of the condtion part.
+ */
+ public Expression getCondition() {
+ return (Expression) elementAt(3);
+ }
+
+ /**
+ * Sets the condition part of this for-statement.
+ *
+ * @param cond the expression of the condtion part.
+ */
+ public void setCondition(Expression cond) {
+ setElementAt(cond, 3);
+ }
+
+ /**
+ * Gets the increments part of this for-statement.
+ *
+ * @return the expression list of the increments part.
+ */
+ public ExpressionList getIncrement() {
+ return (ExpressionList) elementAt(4);
+ }
+
+ /**
+ * Sets the increments part of this for-statement.
+ *
+ * @param incs the expression list of the increments part.
+ */
+ public void setIncrement(ExpressionList incs) {
+ if (incs == null)
+ incs = new ExpressionList();
+ setElementAt(incs, 4);
+ }
+
+ /**
+ * Gets the body of this for-statement.
+ *
+ * @return the statement list of the body.
+ */
+ public StatementList getStatements() {
+ return (StatementList) elementAt(5);
+ }
+
+ /**
+ * Sets the body of this for-statement.
+ *
+ * @param stmts the statement list of the body.
+ */
+ public void setStatements(StatementList stmts) {
+ if (stmts == null)
+ stmts = new StatementList();
+ setElementAt(stmts, 5);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/IfStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/IfStatement.java
new file mode 100644
index 0000000..ac20264
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/IfStatement.java
@@ -0,0 +1,121 @@
+/*
+ * IfStatement.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>IfStatement</code> class represents a if statement node
+ * of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ */
+public class IfStatement extends NonLeaf implements Statement, ParseTree {
+
+ /**
+ * Constructs new IfStatement from prototype object
+ *
+ * @param expr the condition of this if statement.
+ * @param stmts the statement that is executed when expr is ture
+ * @param elsestmts the statement that is executed when expr is false.
+ * If there is no else part then statement list is
+ * empty.
+ */
+ public IfStatement(
+ Expression expr,
+ StatementList stmts,
+ StatementList elsestmts) {
+ super();
+ if (stmts == null)
+ stmts = new StatementList();
+ if (elsestmts == null)
+ elsestmts = new StatementList();
+ set(expr, stmts, elsestmts);
+ }
+
+ /**
+ * Constructs new IfStatement from prototype object
+ *
+ * @param expr the condition of this if statement.
+ * @param stmts the statement that is executed when expr is ture
+ */
+ public IfStatement(Expression expr, StatementList stmts) {
+ this(expr, stmts, null);
+ }
+
+ IfStatement() {
+ super();
+ }
+
+ /**
+ * Gets the condition of this if statement.
+ *
+ * @return the expression of the condition.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the condition of this if statement.
+ *
+ * @param expr the expression of the condition.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the then part of this if statement.
+ *
+ * @return the statement list of the then part.
+ */
+ public StatementList getStatements() {
+ return (StatementList) elementAt(1);
+ }
+
+ /**
+ * Sets the then part of this if statement.
+ *
+ * @param thenstmts the statement list of the then part.
+ */
+ public void setStatements(StatementList thenstmts) {
+ setElementAt(thenstmts, 1);
+ }
+
+ /**
+ * Gets the else part of this if statement.
+ *
+ * @return the statement list of the else part.
+ */
+ public StatementList getElseStatements() {
+ return (StatementList) elementAt(2);
+ }
+
+ /**
+ * Sets the else part of this if statement.
+ *
+ * @param elsestmts the statement list of the else part.
+ */
+ public void setElseStatements(StatementList elsestmts) {
+ setElementAt(elsestmts, 2);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/InstanceofExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/InstanceofExpression.java
new file mode 100644
index 0000000..5b21002
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/InstanceofExpression.java
@@ -0,0 +1,115 @@
+/*
+ * InstanceofExpression.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>InstanceofExpression</code> represents
+ * the expression like :
+ * <br><blockquote><pre>
+ * obj instanceof Object
+ * </pre></blockquote><br>
+ * If the operator in the expression of the left operand has week unity,
+ * this automatically produces the code in which the left operand
+ * is enclosed by parenthesises.
+ * <br>
+ * In the case the left is <code>obj = obj2</code> and
+ * the right is <code>String</code>,
+ * this produces the code :
+ * <br><blockquote><pre>
+ * (obj = obj2) instanceof String
+ * </pre></blockquote><br>
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ */
+public class InstanceofExpression extends NonLeaf implements Expression {
+
+ /**
+ * Allocates a new object.
+ *
+ * @param lexp the expression to test.
+ * @param tspec the typespecifier.
+ */
+ public InstanceofExpression(Expression lexp, TypeName tspec) {
+ super();
+ set(lexp, tspec);
+ }
+
+ InstanceofExpression() {
+ super();
+ }
+
+ private final boolean needsLeftPar(Expression lexpr) {
+ if (lexpr instanceof AssignmentExpression
+ || lexpr instanceof ConditionalExpression) {
+ return true;
+ }
+ /* this is too strict for + */
+ if (lexpr instanceof BinaryExpression) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets the expression of the left operand to be tested
+ * in this expression.
+ *
+ * @return the left expression.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression of the left operand to be tested
+ * in this expression.
+ *
+ * @param lexpr the left expression to set.
+ */
+ public void setLeft(Expression lexpr) {
+ setElementAt(lexpr, 0);
+ }
+
+ /**
+ * Gets the type specifier of the right operand to be tested
+ * in this expression.
+ *
+ * @return the type specifier.
+ */
+ public TypeName getTypeSpecifier() {
+ return (TypeName) elementAt(1);
+ }
+
+ /**
+ * Sets the type specifier of the right operand to be tested
+ * in this expression.
+ *
+ * @param tspec the type specifier to set.
+ */
+ public void setTypeSpecifier(TypeName tspec) {
+ setElementAt(tspec, 1);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ return OJClass.forClass(boolean.class);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/LabeledStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/LabeledStatement.java
new file mode 100644
index 0000000..f6788d1
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/LabeledStatement.java
@@ -0,0 +1,81 @@
+/*
+ * Parameter.java 1.0
+ *
+ * This interface is made to type ptree-node into
+ * the parameter in the body of class.
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The LabeledStatement class presents labeled statement node
+ * of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class LabeledStatement extends NonLeaf implements Statement {
+
+ /**
+ * Allocates a new object.
+ *
+ */
+ public LabeledStatement(String name, Statement statement) {
+ super();
+ set(name, (ParseTree) statement);
+ }
+
+ LabeledStatement() {
+ super();
+ }
+
+ /**
+ * Gets the label.
+ *
+ * @return the label.
+ */
+ public String getLabel() {
+ return (String) elementAt(0);
+ }
+
+ /**
+ * Sets the label.
+ *
+ * @param label the label to set.
+ */
+ public void setLabel(String label) {
+ setElementAt(label, 0);
+ }
+
+ /**
+ * Gets the statement of this labeled statement
+ *
+ * @return the statement.
+ */
+ public Statement getStatement() {
+ return (Statement) elementAt(1);
+ }
+
+ /**
+ * Sets the statement of this labeled statement
+ *
+ * @return stmt the statement to set.
+ */
+ public void setStatement(Statement stmt) {
+ setElementAt(stmt, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Leaf.java b/src/main/java/io/devnulllabs/openjava/ptree/Leaf.java
new file mode 100644
index 0000000..c4fdf16
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Leaf.java
@@ -0,0 +1,158 @@
+/*
+ * Leaf.java 1.0
+ *
+ * This subclass of symbol represents (at least) terminal symbols returned
+ * by the scanner and placed on the parse stack. At present, this
+ * class does nothing more than its super class.
+ *
+ * Jun 11, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.ParseTreeObject
+ * @version 1.0 last updated: Jun 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The Leaf class is a token-node in the parse tree of OpenJava.
+ * Any object of this class or subclasses must be immutable.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public class Leaf extends ParseTreeObject implements ParseTree {
+ protected void replaceChildWith(ParseTree dist, ParseTree replacement)
+ throws ParseTreeException {
+ throw new ParseTreeException("no child");
+ }
+
+ /** textString is the text of this token. */
+ private String textString = null;
+
+ /** tokenID is the identifer number of this token */
+ private int tokenID = 0;
+
+ /** line is the number of the line at which this token is. */
+ public int line = -1;
+
+ /** charBegin is the number of the character at which this token is. */
+ public int charBegin = -1;
+
+ /**
+ * Allocates a new leaf(token) with its text.
+ *
+ * @param term_num dummy parameter.
+ * @param str its text.
+ */
+ public Leaf(String str) {
+ this(-1, str, -1, -1);
+ }
+
+ /**
+ * Allocates a new leaf(token) with its text.
+ *
+ * @param term_num dummy parameter.
+ * @param str its text.
+ */
+ public Leaf(int term_num, String str) {
+ this(term_num, str, -1, -1);
+ }
+
+ /**
+ * Allocates a new leaf(token) with its text and where this is.
+ *
+ * @param term_num dummy parameter.
+ * @param str its text.
+ */
+ public Leaf(int term_num, String str, int line, int charBegin) {
+ tokenID = term_num;
+ textString = str;
+ this.line = line;
+ this.charBegin = charBegin;
+ }
+
+ /**
+ * Overrides to return its text as the string of this instance.
+ *
+ * @return the text of this token.
+ */
+ public String toString() {
+ return textString;
+ }
+
+ /**
+ * Makes a new copy of this leaf-node.
+ * This method equals to makeCopy().
+ *
+ * @return the copy of this nonleaf-node as a ptree-node.
+ */
+ public ParseTree makeRecursiveCopy() {
+ return (ParseTree) this.clone();
+ }
+
+ /**
+ * Makes a new copy of this leaf-node.
+ *
+ * @return the copy of this nonleaf-node as a ptree-node.
+ */
+ public ParseTree makeCopy() {
+ return (ParseTree) this.clone();
+ }
+
+ /**
+ * Tests if the specified ptree-node equals to this leaf-node.
+ *
+ * @param p the ptree-node to be tested.
+ * @return true if p equals to this leaf-node
+ */
+ public boolean equals(ParseTree p) {
+ if (p == null || !(p instanceof Leaf))
+ return false;
+ if (this == p)
+ return true;
+ return this.toString().equals(p.toString());
+ }
+
+ /**
+ * Tests if the specified string equals to this leaf-node's text.
+ *
+ * @param p the ptree-node to be tested.
+ * @return true if p equals to this leaf-node
+ */
+ public boolean equals(String str) {
+ if (str == null)
+ return false;
+ return this.toString().equals(str);
+ }
+
+ /**
+ * Returns the identifer-number of this token.
+ *
+ * @return the identifer-number of this token.
+ */
+ public int getTokenID() {
+ return tokenID;
+ }
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in the
+ * Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on each
+ * child <code>ParseTree</code> object with this visitor.
+ *
+ * @param visitor a visitor
+ **/
+ public void childrenAccept(ParseTreeVisitor visitor) {
+ return;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/List.java b/src/main/java/io/devnulllabs/openjava/ptree/List.java
new file mode 100644
index 0000000..4ee00ea
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/List.java
@@ -0,0 +1,240 @@
+/*
+ * List.java 1.0
+ *
+ * Jun 11, 1997 by mich
+ * Aug 20, 1997 by mich
+ * Sep 28, 1997 by mich
+ *
+ * @version 1.0 last updated: Sep 28, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The List class presents for the list of parse trees.
+ *
+ */
+public abstract class List extends ParseTreeObject implements ParseTree {
+
+ protected final void replaceChildWith(
+ ParseTree dist,
+ ParseTree replacement)
+ throws ParseTreeException {
+ DebugOut.println(
+ "List.replaceChildWith() " + dist + " with " + replacement);
+ for (int i = 0, size = contents.size(); i < size; ++i) {
+ if (contents_elementAt(i) == dist) {
+ contents_setElementAt(replacement, i);
+ return;
+ }
+ }
+ throw new ParseTreeException("no replacing target");
+ }
+
+ /** The ptreelist the list of parse-tree nodes */
+ private Vector contents = new Vector();
+ protected void contents_addElement(Object obj) {
+ contents.addElement(obj);
+ if (obj instanceof ParseTreeObject) {
+ ((ParseTreeObject) obj).setParent(this);
+ }
+ }
+ protected void contents_insertElementAt(Object obj, int index) {
+ contents.insertElementAt(obj, index);
+ if (obj instanceof ParseTreeObject) {
+ ((ParseTreeObject) obj).setParent(this);
+ }
+ }
+ protected void contents_setElementAt(Object obj, int index) {
+ contents.setElementAt(obj, index);
+ if (obj instanceof ParseTreeObject) {
+ ((ParseTreeObject) obj).setParent(this);
+ }
+ }
+ protected Object contents_elementAt(int index) {
+ return contents.elementAt(index);
+ }
+ protected void contents_removeElementAt(int index) {
+ contents.removeElementAt(index);
+ }
+ protected int contents_size() {
+ return contents.size();
+ }
+
+ private String delimiter = ParseTreeObject.LN;
+
+ /**
+ * Allocates this List
+ *
+ */
+ protected List() {
+ contents = new Vector();
+ }
+
+ /**
+ * Allocates this List
+ *
+ * @param p0 list's element
+ */
+ protected List(Object p) {
+ this();
+ contents_addElement(p);
+ }
+
+ /**
+ * Allocates this List
+ *
+ */
+ protected List(String delimiter) {
+ this();
+ this.delimiter = delimiter;
+ }
+
+ /**
+ * Allocates this List
+ *
+ * @param p0 list's element
+ */
+ protected List(String delimiter, Object p) {
+ this(delimiter);
+ contents_addElement(p);
+ }
+
+ /**
+ * Get contents
+ */
+ public Enumeration elements() {
+ return contents.elements();
+ }
+
+ /**
+ * Returns the length of this list.
+ *
+ * @return the length of this list
+ */
+ public int size() {
+ return contents.size();
+ }
+
+ /**
+ * Tests if this list is empty.
+ *
+ * @return true if this list is empty
+ */
+ public boolean isEmpty() {
+ return contents.isEmpty();
+ }
+
+ /**
+ * Removes an element at the specified point from this list
+ *
+ * @param n where to remove element.
+ */
+ public void removeAll() {
+ contents.removeAllElements();
+ }
+
+ /**
+ * Tests if any element representing the specified string is exist
+ * or not.
+ *
+ * @param str a string to test.
+ * @return true if any element representing the specified string
+ * is exist.
+ */
+ public boolean contains(String str) {
+ Enumeration it = contents.elements();
+ while (it.hasMoreElements()) {
+ Object elem = it.nextElement();
+ if (elem != null && elem.toString().equals(str))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Tests if this list-node's value equals to the specified
+ * ptree-node's.
+ *
+ * @return true if two values are same.
+ */
+ public boolean equals(ParseTree p) {
+ if (p == null)
+ return false;
+ if (this == p)
+ return true;
+ if (this.getClass() != p.getClass())
+ return false;
+
+ List nlp = (List) p;
+ int length = this.size();
+ if (nlp.size() != length)
+ return false;
+ for (int i = 0; i < length; ++i) {
+ Object a = contents.elementAt(i);
+ Object b = nlp.contents.elementAt(i);
+ if (a != null && b == null)
+ return false;
+ if (a == null && b != null)
+ return false;
+ if (a == null && b == null)
+ continue;
+ if (!a.equals(b))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Makes a new copy (another object) of this list-node.
+ * The objects contained by this object will also be copied
+ *
+ * @return the copy of this nonleaf-node as a ptree-node.
+ */
+ public ParseTree makeRecursiveCopy() {
+ List result = (List) clone();
+ result.contents = new Vector();
+
+ Enumeration it = contents.elements();
+ while (it.hasMoreElements()) {
+ Object elem = it.nextElement();
+ if (elem instanceof ParseTree) {
+ elem = ((ParseTree) elem).makeRecursiveCopy();
+ }
+ result.contents_addElement(elem);
+ }
+
+ return result;
+ }
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in the
+ * Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on each
+ * child <code>ParseTree</code> object with this visitor.
+ *
+ * @param visitor a visitor
+ **/
+ public void childrenAccept(ParseTreeVisitor visitor)
+ throws ParseTreeException {
+ if (contents == null)
+ return;
+ int length = contents.size();
+ for (int i = 0; i < length; ++i) {
+ Object obj = contents.elementAt(i);
+ if (obj instanceof ParseTree) {
+ ParseTree ptree = (ParseTree) obj;
+ ptree.accept(visitor);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Literal.java b/src/main/java/io/devnulllabs/openjava/ptree/Literal.java
new file mode 100644
index 0000000..8649689
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Literal.java
@@ -0,0 +1,231 @@
+/*
+ * Literal.java 1.0
+ *
+ * Jun 20, 1997
+ * Sep 29, 1997
+ * Oct 10, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>Literal class</code> represents
+ * a literal.
+ *
+ * @see io.devnulllabs.openjava.ptree.Leaf
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class Literal extends Leaf implements Expression {
+ /**
+ * @see io.devnulllabs.openjava.ptree.Literal#getLiteralType()
+ */
+ public static final int BOOLEAN = 0;
+ public static final int INTEGER = 1;
+ public static final int LONG = 2;
+ public static final int FLOAT = 3;
+ public static final int DOUBLE = 4;
+ public static final int CHARACTER = 5;
+ public static final int STRING = 6;
+ public static final int NULL = 7;
+
+ protected int id = -1;
+
+ private static Literal constantTrue_ = null;
+ private static Literal constantFalse_ = null;
+ private static Literal constantNull_ = null;
+ private static Literal constantEmptyString_ = null;
+ private static Literal constantZero_ = null;
+ private static Literal constantOne_ = null;
+
+ /**
+ * Allocates a new object.
+ * If you want to make <code>String</code> literal like
+ * <code>"test"</code>,
+ * call this constructor in the form :
+ * <br><blockquote><pre>
+ * new Literal( Literal.STRING, "\"test\"" )
+ * </pre></blockquote><br>
+ * or use makeLiteral() static method.
+ *
+ * @param id the id number of the literal.
+ * @param str the literal as a String.
+ * @see io.devnulllabs.openjava.ptree.Literal#makeLiteral(String)
+ */
+ public Literal(int id, String str) {
+ super(str);
+ this.id = id;
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the string.
+ *
+ * @param str the string.
+ */
+ public static Literal makeLiteral(String str) {
+ if ("".equals(str)) {
+ return constantEmptyString();
+ } else {
+ return new Literal(Literal.STRING, "\"" + str + "\"");
+ }
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the boolean.
+ *
+ * @param b the boolean.
+ */
+ public static Literal makeLiteral(boolean b) {
+ return (b ? constantTrue() : constantFalse());
+ }
+ public static Literal makeLiteral(Boolean b) {
+ return makeLiteral(b.booleanValue());
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the character.
+ *
+ * @param c the character.
+ */
+ public static Literal makeLiteral(char c) {
+ return new Literal(Literal.CHARACTER, "'" + c + "'");
+ }
+ public static Literal makeLiteral(Character c) {
+ return makeLiteral(c.charValue());
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the number.
+ *
+ * @param num the number.
+ */
+ public static Literal makeLiteral(int num) {
+ if (num == 0) {
+ return constantZero();
+ } else if (num == 1) {
+ return constantOne();
+ }
+ return new Literal(Literal.INTEGER, String.valueOf(num));
+ }
+ public static Literal makeLiteral(Integer n) {
+ return makeLiteral(n.intValue());
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the number.
+ *
+ * @param num the number.
+ */
+ public static Literal makeLiteral(long num) {
+ return new Literal(Literal.LONG, String.valueOf(num) + "l");
+ }
+ public static Literal makeLiteral(Long n) {
+ return makeLiteral(n.longValue());
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the number.
+ *
+ * @param num the number.
+ */
+ public static Literal makeLiteral(float num) {
+ return new Literal(Literal.FLOAT, String.valueOf(num) + "f");
+ }
+ public static Literal makeLiteral(Float f) {
+ return makeLiteral(f.floatValue());
+ }
+
+ /**
+ * Makes a new object of <code>Literal</code> class
+ * from the number.
+ *
+ * @param num the number.
+ */
+ public static Literal makeLiteral(double num) {
+ return new Literal(Literal.DOUBLE, String.valueOf(num) + "d");
+ }
+ public static Literal makeLiteral(Double d) {
+ return makeLiteral(d.doubleValue());
+ }
+
+ public int getLiteralType() {
+ return this.id;
+ }
+
+ public static Literal constantTrue() {
+ if (constantTrue_ == null) {
+ constantTrue_ = new Literal(Literal.BOOLEAN, "true");
+ }
+ return constantTrue_;
+ }
+ public static Literal constantFalse() {
+ if (constantFalse_ == null) {
+ constantFalse_ = new Literal(Literal.BOOLEAN, "false");
+ }
+ return constantFalse_;
+ }
+ public static Literal constantNull() {
+ if (constantNull_ == null) {
+ constantNull_ = new Literal(Literal.NULL, "null");
+ }
+ return constantNull_;
+ }
+ public static Literal constantEmptyString() {
+ if (constantEmptyString_ == null) {
+ constantEmptyString_ = new Literal(Literal.STRING, "\"\"");
+ }
+ return constantEmptyString_;
+ }
+ public static Literal constantZero() {
+ if (constantZero_ == null) {
+ constantZero_ = new Literal(Literal.INTEGER, "0");
+ }
+ return constantZero_;
+ }
+ public static Literal constantOne() {
+ if (constantOne_ == null) {
+ constantOne_ = new Literal(Literal.INTEGER, "1");
+ }
+ return constantOne_;
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ switch (getLiteralType()) {
+ case BOOLEAN :
+ return OJClass.forClass(boolean.class);
+ case INTEGER :
+ return OJClass.forClass(int.class);
+ case LONG :
+ return OJClass.forClass(long.class);
+ case FLOAT :
+ return OJClass.forClass(float.class);
+ case DOUBLE :
+ return OJClass.forClass(double.class);
+ case CHARACTER :
+ return OJClass.forClass(char.class);
+ case STRING :
+ return OJClass.forClass(String.class);
+ case NULL :
+ return OJClass.forName(OJSystem.NULLTYPE_NAME);
+ }
+ System.err.println("unknown literal : " + toString());
+ return null;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/MemberDeclaration.java b/src/main/java/io/devnulllabs/openjava/ptree/MemberDeclaration.java
new file mode 100644
index 0000000..f55fb9d
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/MemberDeclaration.java
@@ -0,0 +1,48 @@
+/*
+ * MemberDeclaration.java 1.0
+ *
+ * This interface is made to type ptree-node into the field
+ * declaration in the body of class.
+ *
+ * Jun 20, 1997
+ * Aug 20, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Aug 20, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+/**
+ * The MemberDeclaration interface types ptree-node into the member
+ * declaration in the body of class.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.FieldDeclaration
+ * @see io.devnulllabs.openjava.ptree.MethodDeclaration
+ * @see io.devnulllabs.openjava.ptree.ConstructorDeclaration
+ * @see io.devnulllabs.openjava.ptree.MemberInitializer
+ * @see io.devnulllabs.openjava.ptree.ClassDeclaration
+ */
+public interface MemberDeclaration extends ParseTree {
+ /** The FIELD is a kind of MemberDeclaration */
+ public static final int FIELD = 48;
+
+ /** The METHOD is a kind of MemberDeclaration */
+ public static final int METHOD = 49;
+
+ /** The CONSTRUCTOR is a kind of MemberDeclaration */
+ public static final int CONSTRUCTOR = 50;
+
+ /** The STATICINIT is a kind of MemberDeclaration */
+ public static final int STATICINIT = 32;
+
+ /** The TYPE is a kind of MemberDeclaration */
+ public static final int TYPE = 40;
+
+ /** This is same as STATICINIT */
+ public static final int STATICINITIALIZER = 32;
+
+ public boolean equals(ParseTree p);
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/MemberDeclarationList.java b/src/main/java/io/devnulllabs/openjava/ptree/MemberDeclarationList.java
new file mode 100644
index 0000000..b168e74
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/MemberDeclarationList.java
@@ -0,0 +1,120 @@
+/*
+ * MemberDeclarationList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The MemberDeclarationList class presents for the node of parse tree
+ * of MemberDeclaration
+ *
+ */
+public class MemberDeclarationList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public MemberDeclarationList() {
+ super(LNLN);
+ }
+
+ public MemberDeclarationList(MemberDeclaration e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public MemberDeclaration get(int n) {
+ return (MemberDeclaration) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p MemberDeclaration to be inserted into the list
+ */
+ public void add(MemberDeclaration p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p MemberDeclaration to be inserted into the list
+ */
+ public void set(int index, MemberDeclaration p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public MemberDeclaration remove(int index) {
+ MemberDeclaration removed =
+ (MemberDeclaration) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(MemberDeclaration p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(MemberDeclarationList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public MemberDeclarationList subList(int from_index, int to_index) {
+ MemberDeclarationList result = new MemberDeclarationList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/MemberInitializer.java b/src/main/java/io/devnulllabs/openjava/ptree/MemberInitializer.java
new file mode 100644
index 0000000..e4d5648
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/MemberInitializer.java
@@ -0,0 +1,71 @@
+/*
+ * MemberInitializer.java 1.0
+ *
+ * Jun 20, 1997
+ * Sep 29, 1997
+ * Oct 10, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The InstanceInitilizer class represents instance initializer block
+ * of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.MemberDeclaration
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ */
+public class MemberInitializer extends NonLeaf implements MemberDeclaration {
+ private boolean _isStatic = false;
+ /**
+ * Allocates a new object.
+ *
+ * @param stmts the statement list of this instance initializer block
+ */
+ public MemberInitializer(StatementList block) {
+ this(block, false);
+ }
+
+ public MemberInitializer(StatementList block, boolean is_static) {
+ super();
+ this._isStatic = is_static;
+ set(block);
+ }
+
+ public MemberInitializer() {
+ super();
+ }
+
+ public boolean isStatic() {
+ return _isStatic;
+ }
+
+ /**
+ * Gets the body of this instance initializer.
+ *
+ * @return statement list.
+ */
+ public StatementList getBody() {
+ return (StatementList) elementAt(0);
+ }
+
+ /**
+ * Sets the body of this instance initializer.
+ *
+ * @param stmts statement list to set.
+ */
+ public void setBody(StatementList stmts) {
+ setElementAt(stmts, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/MethodCall.java b/src/main/java/io/devnulllabs/openjava/ptree/MethodCall.java
new file mode 100644
index 0000000..86852a6
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/MethodCall.java
@@ -0,0 +1,219 @@
+/*
+ * MethodCall.java 1.0
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.NoSuchMemberException;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.mop.Signature;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>MethodCall</code> class represents
+ * a method call expression.
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class MethodCall extends NonLeaf implements Expression {
+
+ /**
+ * Allocates a new method call expression object.
+ *
+ * @param expr the expression which indicates an object or
+ * a class. This may be null for invocation on 'this'.
+ * @param name the method name.
+ * @param args the argumetns for this method.
+ */
+ public MethodCall(Expression expr, String name, ExpressionList args) {
+ super();
+ if (args == null)
+ args = new ExpressionList();
+ set(expr, null, name, args);
+ }
+
+ /**
+ * Allocates a new method call expression for 'this'.
+ * This is equivalent to:
+ * <pre>
+ * new MethodCall( (Expression) null, name, args )
+ * </pre>
+ *
+ * @param name the method name.
+ * @param args the argumetns for this method.
+ */
+ public MethodCall(String name, ExpressionList args) {
+ this((Expression) null, name, args);
+ }
+
+ /**
+ * Allocates a new method call expression object.
+ *
+ * @param name the method name.
+ * @param args the argumetns for this method.
+ */
+ public MethodCall(TypeName type, String name, ExpressionList args) {
+ super();
+ if (args == null)
+ args = new ExpressionList();
+ set(null, type, name, args);
+ }
+
+ public MethodCall(OJClass clazz, String name, ExpressionList args) {
+ this(TypeName.forOJClass(clazz), name, args);
+ }
+
+ MethodCall() {
+ super();
+ }
+
+ /**
+ * Gets the expression accessed.
+ *
+ * @return the expression accessed.
+ */
+ public Expression getReferenceExpr() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression accessed.
+ *
+ * @param expr the expression accessed.
+ */
+ public void setReferenceExpr(Expression expr) {
+ setElementAt(expr, 0);
+ setElementAt(null, 1);
+ }
+
+ public TypeName getReferenceType() {
+ return (TypeName) elementAt(1);
+ }
+
+ public void setReferenceType(TypeName type) {
+ setElementAt(null, 0);
+ setElementAt(type, 1);
+ }
+
+ /**
+ * Gets the method name.
+ *
+ * @return the method name.
+ */
+ public String getName() {
+ return (String) elementAt(2);
+ }
+
+ /**
+ * Sets the method name.
+ *
+ * @param name the method name.
+ */
+ public void setName(String name) {
+ setElementAt(name, 2);
+ }
+
+ /**
+ * Gets the arguments for this method.
+ *
+ * @return the expression list as the arguments.
+ */
+ public ExpressionList getArguments() {
+ return (ExpressionList) elementAt(3);
+ }
+
+ /**
+ * Sets the arguments for this method.
+ *
+ * @param exprs the expression list as the arguments.
+ */
+ public void setArguments(ExpressionList exprs) {
+ if (exprs == null)
+ exprs = new ExpressionList();
+ setElementAt(exprs, 3);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ OJClass selftype = env.lookupClass(env.currentClassName());
+
+ Expression refexpr = getReferenceExpr();
+ String name = getName();
+
+ OJClass reftype = null;
+
+ if (refexpr != null) {
+ reftype = refexpr.getType(env);
+ } else {
+ TypeName refname = getReferenceType();
+ if (refname != null) {
+ String qname = env.toQualifiedName(refname.toString());
+ reftype = env.lookupClass(qname);
+ }
+ }
+
+ ExpressionList args = getArguments();
+ OJClass[] argtypes = new OJClass[args.size()];
+ for (int i = 0; i < argtypes.length; ++i) {
+ argtypes[i] = args.get(i).getType(env);
+ }
+
+ OJMethod method = null;
+
+ if (reftype != null)
+ method = pickupMethod(reftype, name, argtypes);
+ if (method != null)
+ return method.getReturnType();
+
+ /* try to consult this class and outer classes */
+ if (reftype == null) {
+ OJClass declaring = selftype;
+ while (declaring != null) {
+ method = pickupMethod(declaring, name, argtypes);
+ if (method != null)
+ return method.getReturnType();
+
+ /* consult innerclasses */
+ OJClass[] inners = declaring.getDeclaredClasses();
+ for (int i = 0; i < inners.length; ++i) {
+ method = pickupMethod(inners[i], name, argtypes);
+ if (method != null)
+ return method.getReturnType();
+ }
+
+ declaring = declaring.getDeclaringClass();
+ }
+ reftype = selftype;
+ }
+
+ Signature sign = new Signature(name, argtypes);
+ NoSuchMemberException e = new NoSuchMemberException(sign.toString());
+ method = reftype.resolveException(e, name, argtypes);
+ return method.getReturnType();
+ }
+
+ private static OJMethod pickupMethod(
+ OJClass reftype,
+ String name,
+ OJClass[] argtypes) {
+ try {
+ return reftype.getAcceptableMethod(name, argtypes, reftype);
+ } catch (NoSuchMemberException e) {
+ return null;
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/MethodDeclaration.java b/src/main/java/io/devnulllabs/openjava/ptree/MethodDeclaration.java
new file mode 100644
index 0000000..0444f2c
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/MethodDeclaration.java
@@ -0,0 +1,190 @@
+/*
+ * MethodDeclaration.java 1.0
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ * Jul 29, 1998 by mich, Fixed makeCopy() which crushed.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The MethodDeclaration class presents method declaration node
+ * of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.FieldDeclaration
+ */
+public class MethodDeclaration extends NonLeaf implements MemberDeclaration {
+
+ private Hashtable suffixes = null;
+
+ /**
+ * Constructs new MethodDeclaration from its elements.
+ *
+ * @param modiflist modifier list. If it has no modifier list
+ * then thes arg is set empty list.
+ * @param typespec returning type specifier
+ * @param methoddecl method declarator
+ * @param throwlist throw type list. If there is no throws
+ * then this arg is set empty list
+ * @param block method block. if arg block is null, it means method
+ * body with only semi colon such as methods in interface
+ */
+ public MethodDeclaration(
+ ModifierList modiflist,
+ TypeName typespec,
+ String name,
+ ParameterList params,
+ TypeName[] throwlist,
+ StatementList block) {
+ super();
+ if (params == null)
+ params = new ParameterList();
+ if (throwlist == null)
+ throwlist = new TypeName[0];
+ set(modiflist, typespec, name, params, throwlist, block);
+ }
+
+ /**
+ * Is needed for recursive copy.
+ */
+ MethodDeclaration() {
+ super();
+ }
+
+ /**
+ * Gets modifierlist of this method.
+ *
+ * @return modifier list. Even if there is no modifiers, getModifiers
+ * returns empty list
+ */
+ public ModifierList getModifiers() {
+ return (ModifierList) elementAt(0);
+ }
+
+ /**
+ * Sets modifierlist of this method.
+ *
+ * @param modifs modifier list to set
+ */
+ public void setModifiers(ModifierList modifs) {
+ setElementAt(modifs, 0);
+ }
+
+ /**
+ * Gets type specifier of this method.
+ *
+ * @return type specifier node
+ */
+ public TypeName getReturnType() {
+ return (TypeName) elementAt(1);
+ }
+
+ /**
+ * Sets type specifier of this method.
+ *
+ * @param tspec type specifier to set
+ */
+ public void setReturnType(TypeName tspec) {
+ setElementAt(tspec, 1);
+ }
+
+ /**
+ * Gets name of this method.
+ *
+ * @return method declarator node
+ */
+ public String getName() {
+ return (String) elementAt(2);
+ }
+
+ /**
+ * Sets name of this method.
+ *
+ * @param name method's name
+ */
+ public void setName(String name) {
+ setElementAt(name, 2);
+ }
+
+ /**
+ * Gets parameter list of this method.
+ * Even if this method has no parameter, this returns
+ * an empty list of parameter.
+ *
+ * @return method's name
+ */
+ public ParameterList getParameters() {
+ return (ParameterList) elementAt(3);
+ }
+
+ /**
+ * Sets parameter list of this method.
+ *
+ * @param params parameter list to set
+ */
+ public void setParameters(ParameterList params) {
+ setElementAt(params, 3);
+ }
+
+ /**
+ * Gets throw type name list of this method.
+ * Even if there is no throws, this returns an empty list.
+ *
+ * @return class type list
+ */
+ public TypeName[] getThrows() {
+ return (TypeName[]) elementAt(4);
+ }
+
+ /**
+ * Sets throw type name list of this method.
+ *
+ * @param class type list to set
+ */
+ public void setThrows(TypeName[] thrwlist) {
+ setElementAt(thrwlist, 4);
+ }
+
+ /**
+ * Gets body of this method.
+ * If the body is only semi colon such as the methods' body of interface,
+ * this returns null.
+ *
+ * @return statement list
+ */
+ public StatementList getBody() {
+ return (StatementList) elementAt(5);
+ }
+
+ /**
+ * Sets body of this method.
+ *
+ * @param stmts statement list to set
+ */
+ public void setBody(StatementList stmts) {
+ setElementAt(stmts, 5);
+ }
+
+ public void setSuffixes(Hashtable suffixes) {
+ this.suffixes = suffixes;
+ }
+
+ public Hashtable getSuffixes() {
+ return this.suffixes;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ModifierList.java b/src/main/java/io/devnulllabs/openjava/ptree/ModifierList.java
new file mode 100644
index 0000000..48c7139
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ModifierList.java
@@ -0,0 +1,232 @@
+/*
+ * ModifierList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.lang.reflect.Modifier;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ModifierList class presents for the node of parse tree
+ * of qualified name.
+ * This is a List of String for extended modifiers.
+ */
+public class ModifierList extends List {
+
+ /*
+ * Access modifier flag constants from <em>The Java Virtual
+ * Machine Specification</em>, Table 4.1.
+ */
+ public static final int PUBLIC = Modifier.PUBLIC;
+ public static final int PROTECTED = Modifier.PROTECTED;
+ public static final int PRIVATE = Modifier.PRIVATE;
+ public static final int STATIC = Modifier.STATIC;
+ public static final int FINAL = Modifier.FINAL;
+ public static final int SYNCHRONIZED = Modifier.SYNCHRONIZED;
+ public static final int VOLATILE = Modifier.VOLATILE;
+ public static final int TRANSIENT = Modifier.TRANSIENT;
+ public static final int NATIVE = Modifier.NATIVE;
+ // public static final int INTERFACE = Modifier.INTERFACE;
+ public static final int ABSTRACT = Modifier.ABSTRACT;
+ // public static final int STRICT = Modifier.STRICT;
+ // public static final int EXPLICIT = Modifier.EXPLICIT;
+
+ public static final int EMPTY = 0;
+
+ private int mod = 0;
+
+ public ModifierList() {
+ super(" ");
+ }
+
+ public ModifierList(String e0) {
+ super(" ", e0);
+ }
+
+ public ModifierList(int mod) {
+ this();
+ this.mod = mod;
+ }
+
+ public String toString() {
+ return toString(this.getRegular());
+ }
+
+ /**
+ * Return a string describing the access modifier flags in
+ * the specified modifier. For example:
+ * <blockquote><pre>
+ * public final synchronized
+ * private transient volatile
+ * </pre></blockquote>
+ * The modifier names are return in canonical order, as
+ * specified by <em>The Java Language Specification</em>.
+ */
+ public static String toString(int mod) {
+ StringBuffer sb = new StringBuffer();
+ int len;
+
+ if ((mod & PUBLIC) != 0)
+ sb.append("public ");
+ if ((mod & PRIVATE) != 0)
+ sb.append("private ");
+ if ((mod & PROTECTED) != 0)
+ sb.append("protected ");
+
+ /* Canonical order */
+ if ((mod & ABSTRACT) != 0)
+ sb.append("abstract ");
+ if ((mod & STATIC) != 0)
+ sb.append("static ");
+ if ((mod & FINAL) != 0)
+ sb.append("final ");
+ if ((mod & TRANSIENT) != 0)
+ sb.append("transient ");
+ if ((mod & VOLATILE) != 0)
+ sb.append("volatile ");
+ if ((mod & NATIVE) != 0)
+ sb.append("native ");
+ if ((mod & SYNCHRONIZED) != 0)
+ sb.append("synchronized ");
+
+ // if ((mod & INTERFACE) != 0) sb.append( "interface " );
+
+ // if ((mod & STRICT) != 0) sb.append( "strict " );
+ // if ((mod & EXPLICIT) != 0) sb.append( "explicit " );
+
+ if ((len = sb.length()) > 0) /* trim trailing space */
+ return sb.toString().substring(0, len - 1);
+ return "";
+ }
+
+ public boolean isEmpty() {
+ return (super.isEmpty() && getRegular() == EMPTY);
+ }
+
+ public boolean isEmptyAsRegular() {
+ return (getRegular() == EMPTY);
+ }
+
+ public boolean contains(String str) {
+ if (str == null)
+ return false;
+ if (str.equals("public") && contains(PUBLIC))
+ return true;
+ if (str.equals("private") && contains(PRIVATE))
+ return true;
+ if (str.equals("protected") && contains(PROTECTED))
+ return true;
+ if (str.equals("abstract") && contains(ABSTRACT))
+ return true;
+ if (str.equals("static") && contains(STATIC))
+ return true;
+ if (str.equals("final") && contains(FINAL))
+ return true;
+ if (str.equals("transient") && contains(TRANSIENT))
+ return true;
+ if (str.equals("volatile") && contains(VOLATILE))
+ return true;
+ if (str.equals("native") && contains(NATIVE))
+ return true;
+ if (str.equals("synchronized") && contains(SYNCHRONIZED)) {
+ return true;
+ }
+ return super.contains(str);
+ }
+
+ public boolean contains(int mod) {
+ return ((this.mod & mod) != 0);
+ }
+
+ /**
+ * Gets the specified element at
+ *
+ * @param n
+ */
+ public String get(int n) {
+ return (String) contents_elementAt(n);
+ }
+
+ /**
+ * Sets the specified element at the specified place of the list
+ *
+ * @param p element
+ * @param n the number where to set element
+ */
+ public void set(int n, String p) {
+ contents_setElementAt(p, n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p a modifier to be inserted into the list
+ */
+ public void add(int mod) {
+ this.mod |= mod;
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p a modifier to be inserted into the list
+ */
+ public void add(String p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Removes an element at the specified point from this list
+ *
+ * @param n where to remove element.
+ */
+ public String remove(int n) {
+ String removed = (String) contents_elementAt(n);
+ contents_removeElementAt(n);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(String p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void append(ModifierList lst) {
+ this.mod |= lst.getRegular();
+ for (int i = 0; i < lst.size(); i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ public int getRegular() {
+ return this.mod;
+ }
+
+ public void setRegular(int mod) {
+ this.mod = mod;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/NonLeaf.java b/src/main/java/io/devnulllabs/openjava/ptree/NonLeaf.java
new file mode 100644
index 0000000..3974e49
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/NonLeaf.java
@@ -0,0 +1,381 @@
+/*
+ * NonLeaf.java 1.0
+ *
+ * This subclass of symbol represents (at least) terminal symbols returned
+ * by the scanner and placed on the parse stack. At present, this
+ * class does nothing more than its super class.
+ *
+ * Jun 11, 1997
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.ParseTreeObject
+ * @version 1.0 last updated: Jun 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The NonLeaf class presents for node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.Leaf
+ */
+public abstract class NonLeaf extends ParseTreeObject implements ParseTree {
+ private String comment = "";
+
+ protected final void replaceChildWith(
+ ParseTree dist,
+ ParseTree replacement)
+ throws ParseTreeException {
+ DebugOut.println(
+ "NonLeaf.replaceChildWith() " + dist + " with " + replacement);
+ for (int i = 0; i < contents.length; ++i) {
+ if (contents[i] == dist) {
+ contents[i] = replacement;
+ ((ParseTreeObject) replacement).setParent(this);
+ return;
+ }
+ }
+ throw new ParseTreeException(
+ "no replacing target "
+ + dist
+ + " for "
+ + replacement
+ + " in the source code : "
+ + toString());
+ }
+
+ /** contents is the array of the elements of this nonleaf-node. */
+ private Object[] contents = null;
+
+ /**
+ * Allocates a new non-leaf(cons-cell), where the first element has
+ * null and the second element has null.
+ *
+ */
+ public NonLeaf() {
+ contents = new Object[0];
+ }
+
+ /**
+ * Makes a new copy (another object) of this nonleaf-node recursively.
+ * The objects contained by this object will also be copied.
+ *
+ * @return the copy of this nonleaf-node as a ptree-node.
+ */
+ public ParseTree makeRecursiveCopy() {
+ NonLeaf result = (NonLeaf) makeCopy();
+
+ Object newc[] = new Object[contents.length];
+ for (int i = 0; i < contents.length; ++i) {
+ if (contents[i] instanceof ParseTree) {
+ ParseTree src = (ParseTree) contents[i];
+ newc[i] = (ParseTree) src.makeRecursiveCopy();
+ } else if (contents[i] instanceof String[]) {
+ String[] srcary = (String[]) contents[i];
+ String[] destary = new String[srcary.length];
+ System.arraycopy(srcary, 0, destary, 0, srcary.length);
+ newc[i] = destary;
+ } else if (contents[i] instanceof TypeName[]) {
+ TypeName[] srcary = (TypeName[]) contents[i];
+ TypeName[] destary = new TypeName[srcary.length];
+ for (int j = 0; j < srcary.length; ++j) {
+ destary[j] = (TypeName) srcary[j].makeRecursiveCopy();
+ }
+ newc[i] = destary;
+ } else if (contents[i] instanceof VariableDeclarator[]) {
+ VariableDeclarator[] srcary =
+ (VariableDeclarator[]) contents[i];
+ VariableDeclarator[] destary =
+ new VariableDeclarator[srcary.length];
+ for (int j = 0; j < srcary.length; ++j) {
+ //VariableDe
+ destary[j] =
+ (VariableDeclarator) srcary[j].makeRecursiveCopy();
+ }
+ newc[i] = destary;
+ } else if (contents[i] instanceof Object[]) {
+ System.err.println(
+ "makeRecursiveCopy() not supported in " + getClass());
+ newc[i] = contents[i];
+ } else {
+ newc[i] = contents[i];
+ }
+ }
+
+ result.set(newc);
+
+ return result;
+ }
+
+ /**
+ * Tests if this nonleaf-node's value equals to the specified
+ * ptree-node's.
+ *
+ * @return true if two values are same.
+ */
+ public boolean equals(ParseTree p) {
+ if (p == null || getClass() != p.getClass())
+ return false;
+ if (this == p)
+ return true;
+
+ NonLeaf nlp = (NonLeaf) p;
+ int len = this.getLength();
+ if (len != nlp.getLength())
+ return false;
+
+ System.err.println("equals() not supported in " + getClass().getName());
+ for (int i = 0; i < len; i++) {
+ /*if(! equal( this.elementAt( i ), nlp.elementAt( i ) ))
+ return false;
+ */
+ }
+ return true;
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p ]
+ *
+ * @param p list's element
+ */
+ protected void set(Object[] ptrees) {
+ contents = ptrees;
+ for (int i = 0; i < contents.length; ++i) {
+ if (contents[i] instanceof ParseTreeObject) {
+ ((ParseTreeObject) contents[i]).setParent(this);
+ }
+ }
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p ]
+ *
+ * @param p list's element
+ */
+ protected void set(Object p) {
+ set(new Object[] { p });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ */
+ protected void set(Object p0, Object p1) {
+ set(new Object[] { p0, p1 });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 p2 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ * @param p2 list's element
+ */
+ protected void set(Object p0, Object p1, Object p2) {
+ set(new Object[] { p0, p1, p2 });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 p2 p3 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ * @param p2 list's element
+ * @param p3 list's element
+ */
+ protected void set(Object p0, Object p1, Object p2, Object p3) {
+ set(new Object[] { p0, p1, p2, p3 });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 p2 p3 p4 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ * @param p2 list's element
+ * @param p3 list's element
+ * @param p4 list's element
+ */
+ protected void set(Object p0, Object p1, Object p2, Object p3, Object p4) {
+ set(new Object[] { p0, p1, p2, p3, p4 });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 p2 p3 p4 p5 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ * @param p2 list's element
+ * @param p3 list's element
+ * @param p4 list's element
+ */
+ protected void set(
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5) {
+ set(new Object[] { p0, p1, p2, p3, p4, p5 });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 p2 p3 p4 p5 p6 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ * @param p2 list's element
+ * @param p3 list's element
+ * @param p4 list's element
+ * @param p5 list's element
+ * @param p6 list's element
+ */
+ protected void set(
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6) {
+ set(new Object[] { p0, p1, p2, p3, p4, p5, p6 });
+ }
+
+ /**
+ * Makes this ptree a list presenting for
+ * [ p0 p1 p2 p3 p4 p5 p6 p7 ]
+ *
+ * @param p0 list's element
+ * @param p1 list's element
+ * @param p2 list's element
+ * @param p3 list's element
+ * @param p4 list's element
+ * @param p5 list's element
+ * @param p6 list's element
+ * @param p7 list's element
+ */
+ protected void set(
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7) {
+ set(new Object[] { p0, p1, p2, p3, p4, p5, p6, p7 });
+ }
+
+ /**
+ * Returns the specified element at the specified point of this
+ * nonleaf-node.
+ *
+ * @param i index
+ * @return the ptree object at the specified point
+ */
+ protected Object elementAt(int i) {
+ Object ret = null;
+
+ try {
+ ret = contents[i];
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ System.out.println(ex);
+ //throw new NonLeafException( ex.toString() );
+ }
+
+ return ret;
+ }
+
+ /**
+ * Sets the specified element at the specified point of this
+ * nonleaf-node.
+ *
+ * @param p ptree object to set
+ * @param i index
+ */
+ protected void setElementAt(Object p, int i) {
+ try {
+ contents[i] = p;
+ if (contents[i] instanceof ParseTreeObject) {
+ ((ParseTreeObject) contents[i]).setParent(this);
+ }
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ System.out.println(ex);
+ //throw new NonLeafException( ex.toString() );
+ }
+ }
+
+ /**
+ * Gets the contents of this nonleaf-node.
+ *
+ * @return contents
+ */
+ public Object[] getContents() {
+ /***********/
+ return contents;
+ }
+
+ /**
+ * getLength() returns the length of this nonleaf-node
+ *
+ * @return the length of the list
+ */
+ protected int getLength() {
+ return contents.length;
+ }
+
+ /**
+ * Sets the comment of javadoc format which explains this declaration.
+ *
+ * @param comment the Comment object to set
+ */
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ /**
+ * Obtains the comment of javadoc format which explains this declaration.
+ *
+ * @return the string of the comment
+ */
+ public String getComment() {
+ return this.comment;
+ }
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in the
+ * Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on each
+ * child <code>ParseTree</code> object with this visitor.
+ *
+ * @param visitor a visitor
+ **/
+ public void childrenAccept(ParseTreeVisitor visitor)
+ throws ParseTreeException {
+ if (contents == null)
+ return;
+ for (int i = 0; i < contents.length; ++i) {
+ if (contents[i] instanceof ParseTree) {
+ ParseTree ptree = (ParseTree) contents[i];
+ ptree.accept(visitor);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ObjectList.java b/src/main/java/io/devnulllabs/openjava/ptree/ObjectList.java
new file mode 100644
index 0000000..6e92d64
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ObjectList.java
@@ -0,0 +1,129 @@
+/*
+ * ObjectList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ObjectList</code> class presents for the node of parse tree
+ * of Objects
+ *
+ */
+public class ObjectList extends List {
+ public ObjectList() {
+ super(" ");
+ }
+
+ public ObjectList(Object e0) {
+ super(" ", e0);
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("OBJECTLIST {");
+ if (!isEmpty())
+ buf.append(get(0));
+ for (int i = 1, len = size(); i < len; ++i) {
+ buf.append(",");
+ buf.append(get(i));
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public Object get(int n) {
+ return (Object) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Object to be inserted into the list
+ */
+ public void add(Object p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Object to be inserted into the list
+ */
+ public void set(int index, Object p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public Object remove(int index) {
+ Object removed = (Object) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(Object p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(ObjectList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public ObjectList subList(int from_index, int to_index) {
+ ObjectList result = new ObjectList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Parameter.java b/src/main/java/io/devnulllabs/openjava/ptree/Parameter.java
new file mode 100644
index 0000000..71637a7
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Parameter.java
@@ -0,0 +1,124 @@
+/*
+ * Parameter.java 1.0
+ *
+ * This interface is made to type ptree-node into
+ * the parameter in the body of class.
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 29, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The Parameter class represents parameter node of parse tree.
+ * Modifiers of parameter are supported from JDK 1.1.
+ * The code like:
+ * <br><blockquote><pre>
+ * void test( final int i ){
+ * ....
+ * }
+ * </pre></blockquote><br>
+ * is allowed from JDK 1.1.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.ModifierList
+ */
+public class Parameter extends NonLeaf {
+
+ /**
+ * Allocates a new object.
+ *
+ * @param modfiers modifier list of the new parameter
+ * @param type_specifier type specifier includes array dimension info
+ * @param declname the parameter's name, including no array dim.
+ */
+ public Parameter(
+ ModifierList modiflist,
+ TypeName type_specifier,
+ String declname) {
+ super();
+ if (modiflist == null) {
+ modiflist = new ModifierList();
+ }
+ set(modiflist, type_specifier, declname);
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ *
+ * @param type_specifier type specifier includes array dimension info
+ * @param declname the parameter's name, also includes array dim
+ * arg modfier is null means parameter has no modifier
+ */
+ public Parameter(TypeName type_specifier, String declname) {
+ this(new ModifierList(), type_specifier, declname);
+ }
+
+ /**
+ * Gets the modifiers of this parameter.
+ *
+ * @return the modfiers.
+ */
+ public ModifierList getModifiers() {
+ return (ModifierList) elementAt(0);
+ }
+
+ /**
+ * Sets the modifiers of this parameter.
+ *
+ * @param modifs the modfiers to set.
+ */
+ public void setModifiers(ModifierList modifs) {
+ setElementAt(modifs, 0);
+ }
+
+ /**
+ * Gets the type specifier of this parameter.
+ *
+ * @return the type specifier.
+ */
+ public TypeName getTypeSpecifier() {
+ return (TypeName) elementAt(1);
+ }
+
+ /**
+ * Sets the type specifier of this parameter.
+ *
+ * @param tspec the type specifier to set.
+ */
+ public void setTypeSpecifier(TypeName tspec) {
+ setElementAt(tspec, 1);
+ }
+
+ /**
+ * Gets the variable name of this parameter.
+ *
+ * @return the variable name.
+ */
+ public String getVariable() {
+ return (String) elementAt(2);
+ }
+
+ /**
+ * Sets the variable name of this parameter.
+ *
+ * @param varname the variable name to set.
+ */
+ public void setVariable(String varname) {
+ setElementAt(varname, 2);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ParameterList.java b/src/main/java/io/devnulllabs/openjava/ptree/ParameterList.java
new file mode 100644
index 0000000..43f338b
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ParameterList.java
@@ -0,0 +1,119 @@
+/*
+ * ParameterList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ParameterList class presents for the node of parse tree
+ * of Parameter
+ *
+ */
+public class ParameterList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public ParameterList() {
+ super(LNLN);
+ }
+
+ public ParameterList(Parameter e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public Parameter get(int n) {
+ return (Parameter) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Parameter to be inserted into the list
+ */
+ public void add(Parameter p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Parameter to be inserted into the list
+ */
+ public void set(int index, Parameter p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public Parameter remove(int index) {
+ Parameter removed = (Parameter) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(Parameter p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(ParameterList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public ParameterList subList(int from_index, int to_index) {
+ ParameterList result = new ParameterList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ParseTree.java b/src/main/java/io/devnulllabs/openjava/ptree/ParseTree.java
new file mode 100644
index 0000000..89a4497
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ParseTree.java
@@ -0,0 +1,106 @@
+/*
+ * ParseTree.java 1.0
+ *
+ * This subclass of symbol represents (at least) terminal symbols returned
+ * by the scanner and placed on the parse stack. At present, this
+ * class does nothing more than its super class.
+ *
+ * Jun 11, 1997
+ * Sep 5, 1997
+ *
+ * @see java_cup.runtime.symbol
+ * @version 1.0 last updated: Sep 5, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The ParseTree class presents for the node of parse tree.
+ * This may be a token node, Leaf, or may be a nonterminal node, NonLeaf.
+ *
+ * @see io.devnulllabs.openjava.ptree.Leaf
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public interface ParseTree {
+
+ public void replace(ParseTree replacement) throws ParseTreeException;
+
+ /**
+ * Makes a new copy (another object) of this nonleaf-node recursively.
+ * The objects contained by this object will also be copied.
+ *
+ * @return the copy of this nonleaf-node as a ptree-node.
+ */
+ public ParseTree makeRecursiveCopy();
+
+ /**
+ * Makes a new copy of this nonleaf-node as a ptree-node.
+ * The objects contained by the new object are same as
+ * these contained by the original object.
+ *
+ * @return the copy of this nonleaf-node as a ptree-node.
+ */
+ public ParseTree makeCopy();
+
+ /**
+ * Tests if this parse-tree-node's value equals to the specified
+ * ptree-node's.
+ *
+ * @return true if two values are same.
+ */
+ public boolean equals(ParseTree p);
+
+ /**
+ * Generates string which presents for this parse-tree
+ *
+ * @return string which presents for this parse-tree
+ */
+ public String toString();
+
+ /**
+ * Generates the string expression from this node. Returned
+ * string doesn't have '"' without cancel ( \" ) and doesn't have
+ * newline.<p>
+ *
+ * This method is useful to embed ptree objects as a string literal
+ * in source code.
+ *
+ * @return the flatten string which this node represents
+ */
+ public String toFlattenString();
+
+ /**
+ * Returns the Identifier Number of this object
+ *
+ * @return the ID number of this object
+ */
+ public int getObjectID();
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in the
+ * Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on the
+ * accepted visitor.
+ *
+ * @param visitor a visitor
+ */
+ public void accept(ParseTreeVisitor visitor) throws ParseTreeException;
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in the
+ * Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on each
+ * child <code>ParseTree</code> object with this visitor.
+ *
+ * @param visitor a visitor
+ */
+ public void childrenAccept(ParseTreeVisitor visitor)
+ throws ParseTreeException;
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ParseTreeException.java b/src/main/java/io/devnulllabs/openjava/ptree/ParseTreeException.java
new file mode 100644
index 0000000..be546da
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ParseTreeException.java
@@ -0,0 +1,47 @@
+/** This subclass of symbol represents (at least) terminal symbols returned
+ * by the scanner and placed on the parse stack. At present, this
+ * class does nothing more than its super class.
+ *
+ * @see java_cup.runtime.symbol
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+
+public class ParseTreeException extends Exception
+{
+ private Exception ex = null;
+
+ public ParseTreeException() {
+ }
+
+ public ParseTreeException( Exception e ) {
+ super( e.getMessage() );
+ this.ex = e;
+ }
+
+ public ParseTreeException( String str ) {
+ super( str );
+ }
+
+ public void printStackTrace( PrintWriter o ) {
+ if (ex != null) {
+ ex.printStackTrace( o );
+ } else {
+ super.printStackTrace( o );
+ }
+ }
+
+ public void printStackTrace( PrintStream o ) {
+ if (ex != null) {
+ ex.printStackTrace( o );
+ } else {
+ super.printStackTrace( o );
+ }
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ParseTreeObject.java b/src/main/java/io/devnulllabs/openjava/ptree/ParseTreeObject.java
new file mode 100644
index 0000000..f52dec0
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ParseTreeObject.java
@@ -0,0 +1,267 @@
+/*
+ * ParseTreeObject.java 1.0
+ *
+ * This subclass of symbol represents (at least) terminal symbols returned
+ * by the scanner and placed on the parse stack. At present, this
+ * class does nothing more than its super class.
+ *
+ * Jun 11, 1997
+ * Sep 5, 1997
+ *
+ * @see java_cup.runtime.symbol
+ * @version 1.0 last updated: Sep 5, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.StringTokenizer;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+import io.devnulllabs.openjava.ptree.util.SourceCodeWriter;
+
+/**
+ * The ParseTree class presents for the node of parse tree.
+ * This may be a token node, Leaf, or may be a nonterminal node, NonLeaf.
+ *
+ * @see io.devnulllabs.openjava.ptree.Leaf
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public abstract class ParseTreeObject
+ extends Object
+ implements ParseTree, Cloneable {
+ /**
+ * Why this modifier is not final ?
+ * - Because of javac bug in excuting it with -O option.
+ */
+ protected static String LN;
+ static {
+ StringWriter strw = new StringWriter();
+ PrintWriter pw = new PrintWriter(strw);
+ pw.println();
+ pw.close();
+ LN = strw.toString();
+ }
+
+ private ParseTreeObject parent;
+ /*************/
+ public /*private*/
+ final ParseTreeObject getParent() {
+ return parent;
+ }
+ protected final void setParent(ParseTreeObject parent) {
+ this.parent = parent;
+ }
+ public final void replace(ParseTree replacement)
+ throws ParseTreeException {
+ ParseTreeObject p = getParent();
+ if (p == null)
+ throw new ParseTreeException("no parent");
+ p.replaceChildWith(this, replacement);
+ }
+ protected abstract void replaceChildWith(
+ ParseTree dist,
+ ParseTree replacement)
+ throws ParseTreeException;
+
+ /**
+ * Arrocates new parse-tree object and set identifier number
+ * on the object.
+ *
+ */
+ public ParseTreeObject() {
+ setObjectID();
+ }
+
+ /**
+ * clone() is fixed as a shallow copy.
+ *
+ * @return the copy of this ptree-node.
+ */
+ protected final Object clone() {
+ try {
+ ParseTreeObject result = (ParseTreeObject) super.clone();
+ result.setObjectID();
+ return result;
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+
+ /**
+ * shallow copy
+ */
+ public ParseTree makeCopy() {
+ return (ParseTree) clone();
+ }
+
+ /**
+ * deep copy
+ */
+ public abstract ParseTree makeRecursiveCopy();
+
+ /**
+ * Tests if this parse-tree-node's value equals to the specified
+ * ptree-node's.
+ *
+ * @return true if two values are same.
+ */
+ public abstract boolean equals(ParseTree p);
+
+ public int hashCode() {
+ return getObjectID();
+ }
+
+ /**
+ * Generates a string object of regular Java source code
+ * representing this parse-tree.
+ *
+ * @return string which represents this parse-tree
+ */
+ public String toString() {
+ StringWriter strwriter = new StringWriter();
+ PrintWriter out = new PrintWriter(strwriter);
+ SourceCodeWriter writer = new SourceCodeWriter(out);
+ try {
+ this.accept(writer);
+ } catch (ParseTreeException e) {
+ System.err.println("fail in toString()");
+ }
+ out.close();
+ return strwriter.toString();
+ }
+
+ /**
+ * May return true if two ptree-nodes don't refer to not the
+ * same objects but their contents are equivalent.
+ *
+ * @param p the node
+ * @param q the node to compare
+ * @return true if p equals c
+ */
+ public static final boolean equal(ParseTree p, ParseTree q) {
+ if (p == null && q == null)
+ return true;
+ if (p == null || q == null)
+ return false;
+ if (p == q)
+ return true;
+ return p.equals(q);
+ }
+
+ /**
+ * The object ID is object identifier number in order to determine
+ * two ptree variables refer to the same object.
+ */
+ private int objectID = -1;
+
+ /** The idCount counts up generated ptree objects */
+ private static int idCount = 0;
+
+ public static final int lastObjectID() {
+ return idCount;
+ }
+
+ /**
+ * Increments idCount class variable and set the instance's
+ * object identifier number to the number of idCount variable.
+ *
+ */
+ private synchronized final void setObjectID() {
+ idCount++;
+ objectID = idCount;
+ }
+
+ /**
+ * Returns
+ *
+ * @param id ID
+ * @return Name the ID represents
+ */
+ public final int getObjectID() {
+ return objectID;
+ }
+
+ /**
+ * Generates the string expression from this node. Returned
+ * string doesn't have '"' without cancel ( \" ) and doesn't have
+ * newline.<p>
+ *
+ * This method is useful to embed ptree objects as a string literal
+ * in source code.
+ *
+ * @return the flatten string which this node represents
+ */
+ public String toFlattenString() {
+ StringBuffer ret = null;
+
+ /* cancel double quotes and back slashs */
+ java.util.StringTokenizer canceller =
+ new StringTokenizer(this.toString(), "\\\"", true);
+ ret = new StringBuffer();
+
+ while (canceller.hasMoreTokens()) {
+ String buf = canceller.nextToken();
+ if (buf.equals("\\") || buf.equals("\"")) {
+ ret.append("\\");
+ }
+ ret.append(buf);
+ }
+
+ /* remove new line chars */
+ java.util.StringTokenizer lnremover =
+ new StringTokenizer(ret.toString(), "\n\r", false);
+ ret = new StringBuffer();
+
+ while (lnremover.hasMoreTokens()) {
+ ret.append(" " + lnremover.nextToken());
+ }
+
+ return ret.toString();
+ }
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in
+ * the Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on the
+ * accepted visitor.
+ *
+ * @param visitor a visitor
+ */
+ public abstract void accept(ParseTreeVisitor visitor)
+ throws ParseTreeException;
+
+ /*
+ public void accept( ParseTreeVisitor visitor ) throws ParseTreeException {
+ Class active_type = this.getClass();
+ Class visitor_clazz = visitor.getClass();
+ try {
+ Method visit_method
+ = visitor_clazz.getMethod( "visit",
+ new Class[]{ active_type } );
+ visit_method.invoke( visitor, new Object[]{ this } );
+ } catch ( Exception e ) {
+ System.err.println( e.toString() );
+ System.err.println( "\telement\t-" + active_type.toString() );
+ System.err.println( "\tvisitor\t-" + visitor_clazz.toString() );
+ }
+ }
+ */
+
+ /**
+ * Accepts a <code>ParseTreeVisitor</code> object as the role of a
+ * Visitor in the Visitor pattern, as the role of an Element in the
+ * Visitor pattern.<p>
+ *
+ * This invoke an appropriate <code>visit()</code> method on each
+ * child <code>ParseTree</code> object with this visitor.
+ *
+ * @param visitor a visitor
+ **/
+ public abstract void childrenAccept(ParseTreeVisitor visitor)
+ throws ParseTreeException;
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ReturnStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/ReturnStatement.java
new file mode 100644
index 0000000..f9b359f
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ReturnStatement.java
@@ -0,0 +1,67 @@
+/*
+ * ReturnStatement.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 11, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ReturnStatement</code> class represents
+ * a return statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class ReturnStatement extends NonLeaf implements Statement, ParseTree {
+ /**
+ * Allocates a new object.
+ *
+ * @param expr the expression to be returned by this statement.
+ * If this is null, nothing to be returned.
+ */
+ public ReturnStatement(Expression expr) {
+ super();
+ set((ParseTree) expr);
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ */
+ public ReturnStatement() {
+ this(null);
+ }
+
+ /**
+ * Gets the returned expression by this statement.
+ *
+ * @return the expression to be returned by this statement.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the returned expression by this statement.
+ *
+ * @param expr the expression to be returned by this statement.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java b/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java
new file mode 100644
index 0000000..95dbe70
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java
@@ -0,0 +1,105 @@
+/*
+ * SelfAccess.java 1.0
+ *
+ * Jun 20, 1997 by micn
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The class <code>SelfAccess</code> represents an access to
+ * <pre>this</pre> object.
+ * this or super
+ *
+ */
+public class SelfAccess extends Leaf implements Expression {
+ public static final int THIS = 0;
+ public static final int SUPER = 1;
+
+ private static SelfAccess _constantSuper = null;
+ private static SelfAccess _constantThis = null;
+
+ protected String qualifier = null;
+
+ int id = -1;
+
+ SelfAccess() {
+ this(null);
+ }
+
+ SelfAccess(String q) {
+ super(((q == null) ? "" : q + ".") + "this");
+ this.qualifier = q;
+ this.id = THIS;
+ }
+
+ SelfAccess(int id) {
+ super(id == SUPER ? "super" : "this");
+ this.id = id;
+ }
+
+ public String getQualifier() {
+ return this.qualifier;
+ }
+
+ public int getAccessType() {
+ return id;
+ }
+
+ public boolean isSuperAccess() {
+ return (id == SUPER);
+ }
+
+ public static SelfAccess makeSuper() {
+ return constantSuper();
+ }
+
+ public static SelfAccess makeThis() {
+ return constantThis();
+ }
+
+ public static SelfAccess makeThis(String qualifier) {
+ if (qualifier == null || qualifier.equals("")) {
+ return constantThis();
+ }
+ return new SelfAccess(qualifier);
+ }
+
+ public static SelfAccess constantSuper() {
+ if (_constantSuper == null) {
+ _constantSuper = new SelfAccess(SUPER);
+ }
+ return _constantSuper;
+ }
+
+ public static SelfAccess constantThis() {
+ if (_constantThis == null) {
+ _constantThis = new SelfAccess();
+ }
+ return _constantThis;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ OJClass current = env.lookupClass(env.currentClassName());
+ if (isSuperAccess())
+ return current.getSuperclass();
+ String qualifier = getQualifier();
+ if (qualifier == null)
+ return current;
+ return env.lookupClass(env.toQualifiedName(qualifier));
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Statement.java b/src/main/java/io/devnulllabs/openjava/ptree/Statement.java
new file mode 100644
index 0000000..438c109
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Statement.java
@@ -0,0 +1,63 @@
+/*
+ * Statement.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 11, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+
+
+
+
+/**
+ * The <code>Statement</code> class presents common statement interface
+ * of parse tree.
+ * <br>
+ * this interface is impelemented by
+ * <blockquote>
+ * EmptyStatement
+ * LabeledStatement
+ * ExpressionStatement
+ * (selection statement)
+ * IfStatement
+ * SwitchStatement
+ * (iteration statement)
+ * WhileStatement
+ * DoWhileStatement
+ * ForStatement
+ * (jump statement)
+ * BreakStatement
+ * ContinueStatement
+ * ReturnStatement
+ * ThrowStatement
+ * (guarding statement)
+ * SynchronizedStatement
+ * TryStatement
+ * </blockquote>
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.EmptyStatement
+ * @see io.devnulllabs.openjava.ptree.LabeledStatement
+ * @see io.devnulllabs.openjava.ptree.ExpressionStatement
+ * @see io.devnulllabs.openjava.ptree.IfStatement
+ * @see io.devnulllabs.openjava.ptree.SwitchStatement
+ * @see io.devnulllabs.openjava.ptree.WhileStatement
+ * @see io.devnulllabs.openjava.ptree.DoWhileStatement
+ * @see io.devnulllabs.openjava.ptree.ForStatement
+ * @see io.devnulllabs.openjava.ptree.BreakStatement
+ * @see io.devnulllabs.openjava.ptree.ContinueStatement
+ * @see io.devnulllabs.openjava.ptree.ReturnStatement
+ * @see io.devnulllabs.openjava.ptree.ThrowStatement
+ * @see io.devnulllabs.openjava.ptree.SynchronizedStatement
+ * @see io.devnulllabs.openjava.ptree.TryStatement
+ */
+public interface Statement extends ParseTree
+{
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/StatementList.java b/src/main/java/io/devnulllabs/openjava/ptree/StatementList.java
new file mode 100644
index 0000000..16cdd17
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/StatementList.java
@@ -0,0 +1,129 @@
+/*
+ * StatementList.java 1.0
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The StatementList class presents for the node of parse tree
+ * of Statement
+ *
+ */
+public class StatementList extends List {
+ private static final String LNLN = ParseTreeObject.LN + ParseTreeObject.LN;
+
+ public StatementList() {
+ super(LNLN);
+ }
+
+ public StatementList(Statement e0) {
+ super(LNLN, (ParseTree) e0);
+ }
+
+ public StatementList(Statement e0, Statement e1) {
+ this(e0);
+ add(e1);
+ }
+
+ public StatementList(Statement e0, Statement e1, Statement e2) {
+ this(e0, e1);
+ add(e2);
+ }
+
+ /**
+ * Gets the specified element at the index.
+ *
+ * @param n index
+ */
+ public Statement get(int n) {
+ return (Statement) contents_elementAt(n);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Statement to be inserted into the list
+ */
+ public void add(Statement p) {
+ contents_addElement(p);
+ }
+
+ /**
+ * Adds the specified element after the list
+ * This causes side-effect.
+ *
+ * @param p Statement to be inserted into the list
+ */
+ public void set(int index, Statement p) {
+ contents_setElementAt(p, index);
+ }
+
+ /**
+ * Removes the element at the specified position in this Vector.
+ * shifts any subsequent elements to the left (subtracts one from their
+ * indices). Returns the element that was removed from the Vector.
+ *
+ * @exception ArrayIndexOutOfBoundsException index out of range (index
+ * &lt; 0 || index &gt;= size()).
+ * @param index the index of the element to removed.
+ * @since JDK1.2
+ */
+ public Statement remove(int index) {
+ Statement removed = (Statement) contents_elementAt(index);
+ contents_removeElementAt(index);
+ return removed;
+ }
+
+ /**
+ * Inserts the specified element into the list
+ * before the specified element of the list.
+ * This causes side-effect.
+ *
+ * @param p the element to be inserted into the list
+ * @param n number of the element before which insertion ocuurs
+ */
+ public void insertElementAt(Statement p, int n) {
+ contents_insertElementAt(p, n);
+ }
+
+ /**
+ * Appends a list after this list.
+ *
+ * @param lst a list to be appended
+ */
+ public void addAll(StatementList lst) {
+ for (int i = 0, len = lst.size(); i < len; i++) {
+ contents_addElement(lst.get(i));
+ }
+ }
+
+ /**
+ * Returns a view of the portion of this List between fromIndex,
+ * inclusive, and toIndex, exclusive. The returned List is backed by this
+ * List, but changes in the returned List are not reflected in this List.
+ * <p>
+ *
+ * @param fromIndex low endpoint (inclusive) of the subList.
+ * @param toKey high endpoint (exclusive) of the subList.
+ * @return a view of the specified range within this List.
+ * @exception IndexOutOfBoundsException Illegal endpoint index value
+ * (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
+ */
+ public StatementList subList(int from_index, int to_index) {
+ StatementList result = new StatementList();
+ for (int i = from_index; i < to_index; ++i) {
+ result.add(this.get(i));
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/SwitchStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/SwitchStatement.java
new file mode 100644
index 0000000..c4d161f
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/SwitchStatement.java
@@ -0,0 +1,86 @@
+/*
+ * SwitchStatement.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>SwitchStatement</code> class represents switch statement node
+ * of parse tree.
+ * <br>
+ * The specification around <code>CaseGroupList</code> may be
+ * modified in the later version of OpenJava.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.CaseGroupList
+ */
+public class SwitchStatement extends NonLeaf implements Statement {
+
+ /**
+ * Allocates a new object.
+ *
+ * @param expr the condition of this switch statement.
+ * @param cglist the list of the group of case and statements.
+ */
+ public SwitchStatement(Expression expr, CaseGroupList cglist) {
+ super();
+ if (cglist == null)
+ cglist = new CaseGroupList();
+ set((ParseTree) expr, cglist);
+ }
+
+ SwitchStatement() {
+ }
+
+ /**
+ * Gets the expression of the condition to switch.
+ *
+ * @return the expression of the condition.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression of the condition to switch.
+ *
+ * @param expr the expression of the condition to set.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the case group list.
+ *
+ * @return the case group list.
+ */
+ public CaseGroupList getCaseGroupList() {
+ return (CaseGroupList) elementAt(1);
+ }
+
+ /**
+ * Sets the case group list.
+ *
+ * @param cglist the case group list.
+ */
+ public void setCaseGroupList(CaseGroupList cglist) {
+ setElementAt(cglist, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/SynchronizedStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/SynchronizedStatement.java
new file mode 100644
index 0000000..d5101c6
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/SynchronizedStatement.java
@@ -0,0 +1,83 @@
+/*
+ * Catch.java 1.0
+ *
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>SynchronizedStatement</code> class represents
+ * a synchronized statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class SynchronizedStatement
+ extends NonLeaf
+ implements Statement, ParseTree {
+ /**
+ * Allocates a new object.
+ *
+ * @param expr the expression to be synchronized.
+ * @param stmts the statements guarded by this synchronization.
+ */
+ public SynchronizedStatement(Expression expr, StatementList stmts) {
+ super();
+ set((ParseTree) expr, (ParseTree) stmts);
+ }
+
+ SynchronizedStatement() {
+ super();
+ }
+
+ /**
+ * Gets the expression to be synchronized.
+ *
+ * @return the expression to be synchronized.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression to be synchronized by this statement.
+ *
+ * @param expr the expression to be synchronized by this statement.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the statements guarded by this synchronization.
+ *
+ * @return the statements guarded by this synchronization.
+ */
+ public StatementList getStatements() {
+ return (StatementList) elementAt(1);
+ }
+
+ /**
+ * Sets the statements guarded by this synchronization.
+ *
+ * @param stmts the statements guarded by this synchronization.
+ */
+ public void setStatements(StatementList stmts) {
+ setElementAt(stmts, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ThrowStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/ThrowStatement.java
new file mode 100644
index 0000000..7cf1231
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ThrowStatement.java
@@ -0,0 +1,60 @@
+/*
+ * ThrowStatement.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 bv
+ * Oct 11, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>ThrowStatement</code> class represents
+ * a throw statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class ThrowStatement extends NonLeaf implements Statement {
+
+ /**
+ * Allocates a new ThrowStatement object.
+ *
+ * @param expr the expression to be throwed by this statement.
+ */
+ public ThrowStatement(Expression expr) {
+ set((ParseTree) expr);
+ }
+
+ ThrowStatement() {
+ }
+
+ /**
+ * Gets the returned expression by this statement.
+ *
+ * @return the expression to be returned by this statement.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the returned expression by this statement.
+ *
+ * @param expr the expression to be returned by this statement.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/TryStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/TryStatement.java
new file mode 100644
index 0000000..b1b3d25
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/TryStatement.java
@@ -0,0 +1,129 @@
+/*
+ * TryStatement.java 1.0
+ *
+ * Jun 20, 1997 mich
+ * Sep 29, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Sep 29, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>TryStatement</code> class represents
+ * a try statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ * @see io.devnulllabs.openjava.ptree.CatchList
+ */
+public class TryStatement extends NonLeaf implements Statement, ParseTree {
+
+ /**
+ * Allocates a new TryStatement object.
+ *
+ * @param the statement list of the body of this try statement.
+ * @param the catch block list of this try statement.
+ * @param the statement list of the finally block.
+ */
+ public TryStatement(
+ StatementList stmts,
+ CatchList catchlist,
+ StatementList finallee) {
+ super();
+ if (stmts == null)
+ stmts = new StatementList();
+ if (catchlist == null)
+ catchlist = new CatchList();
+ if (finallee == null)
+ finallee = new StatementList();
+ set(stmts, catchlist, finallee);
+ }
+
+ /**
+ * Allocates a new TryStatement object.
+ *
+ * @param the statement list of the body of this try statement.
+ * @param the catch block list of this try statement.
+ */
+ public TryStatement(StatementList stmts, CatchList catchlist) {
+ this(stmts, catchlist, new StatementList());
+ }
+
+ /**
+ * Allocates a new TryStatement object.
+ *
+ * @param the statement list of the body of this try statement.
+ * @param the statement list of the finally block.
+ */
+ public TryStatement(StatementList stmts, StatementList finallee) {
+ this(stmts, new CatchList(), finallee);
+ }
+
+ TryStatement() {
+ }
+
+ /**
+ * Gets the body of this try statement.
+ *
+ * @return the statement list of the body.
+ */
+ public StatementList getBody() {
+ return (StatementList) elementAt(0);
+ }
+
+ /**
+ * Sets the body of this try statement.
+ *
+ * @param stmts the statement list of the body to set.
+ */
+ public void setBody(StatementList stmts) {
+ setElementAt(stmts, 0);
+ }
+
+ /**
+ * Gets the catch block list.
+ *
+ * @return the catch block list.
+ */
+ public CatchList getCatchList() {
+ return (CatchList) elementAt(1);
+ }
+
+ /**
+ * Sets the catch block list.
+ *
+ * @param catchlist the catch block list.
+ */
+ public void setCatchList(CatchList catchlist) {
+ setElementAt(catchlist, 1);
+ }
+
+ /**
+ * Gets the finally body.
+ *
+ * @return the statement list of finally body.
+ */
+ public StatementList getFinallyBody() {
+ return (StatementList) elementAt(2);
+ }
+
+ /**
+ * Sets the finally body.
+ *
+ * @param finallee the statement list of finally body.
+ */
+ public void setFinallyBody(StatementList finallee) {
+ setElementAt(finallee, 2);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/TypeName.java b/src/main/java/io/devnulllabs/openjava/ptree/TypeName.java
new file mode 100644
index 0000000..e8849e0
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/TypeName.java
@@ -0,0 +1,186 @@
+/*
+ * TypeName.java 1.0
+ *
+ * This interface is made to type ptree-node into the type
+ * specifier in the body of class.
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 11, 1997 by mich
+ * Dec 27, 1998 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import java.util.Hashtable;
+
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>TypeName</code> class represents a type specifier
+ * node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public class TypeName extends NonLeaf {
+ Hashtable suffixes;
+
+ int dim;
+
+ public TypeName(String typename, int n, Hashtable suffixes) {
+ super();
+ set(typename);
+ setDimension(n);
+ this.suffixes = suffixes;
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param typename type name
+ * @param n array dimension
+ */
+ public TypeName(String typename, int n) {
+ this(typename, n, null);
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param typename type name
+ * @param n array dimension
+ */
+ public TypeName(String typename, Hashtable suffixes) {
+ this(typename, 0, suffixes);
+ }
+
+ /**
+ * Allocates a new object.
+ * No array dimension will set.
+ * <br><blockquote><pre>
+ * new TypeName( typename )
+ * </pre></blockquote><br>
+ * equals:
+ * <br><blockquote><pre>
+ * new TypeName( typename, 0 )
+ * </pre></blockquote><br>
+ *
+ * @param typename type name
+ */
+ public TypeName(String typename) {
+ this(typename, 0, null);
+ }
+
+ TypeName() {
+ super();
+ }
+
+ public static TypeName forOJClass(OJClass clazz) {
+ int demension = 0;
+ while (clazz.isArray()) {
+ ++demension;
+ clazz = clazz.getComponentType();
+ }
+ String name = clazz.getName();
+ return new TypeName(name, demension);
+ }
+
+ public ParseTree makeRecursiveCopy() {
+ TypeName result = (TypeName) super.makeRecursiveCopy();
+ result.dim = this.dim;
+ result.suffixes = this.suffixes;
+ return result;
+ }
+
+ public ParseTree makeCopy() {
+ TypeName result = (TypeName) super.makeCopy();
+ result.dim = this.dim;
+ result.suffixes = this.suffixes;
+ return result;
+ }
+
+ /**
+ * Gets array dimension of declarated type
+ *
+ * @return array dimension
+ */
+ public int getDimension() {
+ return dim;
+ }
+
+ /**
+ * Sets array dimension of declarated type
+ *
+ * @param dim array dimension
+ */
+ public void setDimension(int n) {
+ dim = n;
+ }
+
+ public void addDimension(int n) {
+ this.dim += n;
+ }
+
+ public void addDimension(String dimstr) {
+ this.addDimension(dimstr.length() / 2);
+ }
+
+ /**
+ * Gets the type name of this type specifier.
+ *
+ * @return the type name.
+ */
+ public String getName() {
+ return (String) elementAt(0);
+ }
+
+ /**
+ * Sets the type name of this type specifier.
+ *
+ * @param typename the type name to set.
+ * @deprecated
+ * @see io.devnulllabs.openjava.ptree.TypeName#setName(String)
+ */
+ public void setTypeName(String typename) {
+ setElementAt(typename, 0);
+ }
+
+ /**
+ * Sets the type name except array dimension of this type specifier.
+ *
+ * @param name the type name to set.
+ */
+ public void setName(String name) {
+ setElementAt(name, 0);
+ }
+
+ public static String stringFromDimension(int dimension) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < dimension; ++i) {
+ buf.append("[]");
+ }
+ return buf.toString();
+ }
+
+ public static int toDimension(String typename) {
+ int result = 0;
+ for (int i = typename.length() - 1; 0 < i; i -= 2) {
+ if (typename.lastIndexOf(']', i) != i
+ || typename.lastIndexOf('[', i) != i - 1) {
+ return result;
+ }
+ result++;
+ }
+ return result;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/UnaryExpression.java b/src/main/java/io/devnulllabs/openjava/ptree/UnaryExpression.java
new file mode 100644
index 0000000..64caa3e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/UnaryExpression.java
@@ -0,0 +1,240 @@
+/*
+ * UnaryExpression.java 1.0
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>UnaryExpression</code> class presents for an expression which
+ * consists of unary operator with one Expression.
+ * <br>
+ * The unary expressions are :
+ * <br><blockquote>
+ * <code>expr++</code>, <code>expr--</code>,
+ * <code>++expr</code>, <code>--expr</code>,
+ * <code>^expr</code>, <code>!expr</code>,
+ * <code>+expr</code> or <code>-expr</code>
+ * </blockquote><br>
+ * ,where <code>expr<code> is an expression.
+ * <br>
+ * If the operator in the expression of the operand has week unity,
+ * this automatically produces the code in which the operand
+ * is enclosed by parenthesises.
+ * <br>
+ * In the case the operand is <code>y = x</code> and
+ * the urary operator is <code>+</code>,
+ * this produces the code :
+ * <br><blockquote><pre>
+ * +(y = x)
+ * </pre></blockquote><br>
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Expression
+ */
+public class UnaryExpression extends NonLeaf implements Expression {
+ /**
+ * Post increment operator like:
+ * <br><blockquote><pre>
+ * i++
+ * </pre></blockquote><br>
+ */
+ public static final int POST_INCREMENT = 0;
+
+ /**
+ * Post decrement operator like:
+ * <br><blockquote><pre>
+ * i--
+ * </pre></blockquote><br>
+ */
+ public static final int POST_DECREMENT = 1;
+
+ /**
+ * Pre increment operator like:
+ * <br><blockquote><pre>
+ * ++i
+ * </pre></blockquote><br>
+ */
+ public static final int PRE_INCREMENT = 2;
+
+ /**
+ * Post increment operator like:
+ * <br><blockquote><pre>
+ * --i
+ * </pre></blockquote><br>
+ */
+ public static final int PRE_DECREMENT = 3;
+
+ /**
+ * Post increment operator like:
+ * <br><blockquote><pre>
+ * ~i
+ * </pre></blockquote><br>
+ */
+ public static final int BIT_NOT = 4;
+
+ /**
+ * Post increment operator like:
+ * <br><blockquote><pre>
+ * ! c
+ * </pre></blockquote><br>
+ */
+ public static final int NOT = 5;
+
+ /**
+ * Post increment operator like:
+ * <br><blockquote><pre>
+ * +i
+ * </pre></blockquote><br>
+ */
+ public static final int PLUS = 6;
+
+ /**
+ * Post increment operator like:
+ * <br><blockquote><pre>
+ * -i
+ * </pre></blockquote><br>
+ */
+ public static final int MINUS = 7;
+
+ private static final String opr_string[] =
+ { "++", "--", "++", "--", "~", "!", "+", "-" };
+
+ /** operator */
+ private int opr = -1;
+
+ /**
+ * Allocates a new object.
+ *
+ * @param opr the operator of this unary expression.
+ * @param expr the expression.
+ */
+ public UnaryExpression(int opr, Expression expr) {
+ super();
+ set((ParseTree) expr);
+ this.opr = opr;
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param expr the expression.
+ * @param opr the operator of this unary expression.
+ */
+ public UnaryExpression(Expression expr, int opr) {
+ super();
+ set((ParseTree) expr);
+ this.opr = opr;
+ }
+
+ UnaryExpression() {
+ super();
+ }
+
+ public ParseTree makeRecursiveCopy() {
+ UnaryExpression result = (UnaryExpression) super.makeRecursiveCopy();
+ result.opr = this.opr;
+ return result;
+ }
+
+ public ParseTree makeCopy() {
+ UnaryExpression result = (UnaryExpression) super.makeCopy();
+ result.opr = this.opr;
+ return result;
+ }
+
+ /**
+ * Gets the expression operated in this expression.
+ *
+ * @return the expression.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the expression operated in this expression.
+ *
+ * @param expr the expression to set.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the operator of this unary expression.
+ *
+ * @return the operator.
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#POST_INCREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#POST_DECREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#PRE_INCREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#PRE_DECREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#BIT_NOT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#NOT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#PLUS
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#MINUS
+ */
+ public int getOperator() {
+ return opr;
+ }
+
+ /**
+ * Sets the operator of this unary expression.
+ *
+ * @param opr the operator id to set.
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#POST_INCREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#POST_DECREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#PRE_INCREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#PRE_DECREMENT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#BIT_NOT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#NOT
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#PLUS
+ * @see io.devnulllabs.openjava.ptree.UnaryExpression#MINUS
+ */
+ public void setOperator(int opr) {
+ this.opr = opr;
+ }
+
+ /**
+ * Tests if the operator of unary expression is a postfix operator.
+ *
+ * @return true if the operator is postfix.
+ */
+ public boolean isPostfix() {
+ if (opr == POST_DECREMENT || opr == POST_INCREMENT)
+ return true;
+ return false;
+ }
+
+ /**
+ * Tests if the operator of unary expression is a prefix operator.
+ *
+ * @return true if the operator is prefix.
+ */
+ public boolean isPrefix() {
+ return !isPostfix();
+ }
+
+ public String operatorString() {
+ return opr_string[opr];
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ return getExpression().getType(env);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Variable.java b/src/main/java/io/devnulllabs/openjava/ptree/Variable.java
new file mode 100644
index 0000000..cca642f
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/Variable.java
@@ -0,0 +1,58 @@
+/*
+ * Variable.java 1.0
+ *
+ * This interface is made to type ptree-node into the type
+ * specifier in the body of class.
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 11, 1997 by mich
+ * Dec 27, 1998 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The <code>Variable</code> class represents a type specifier
+ * node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public class Variable extends Leaf implements Expression {
+ private static int variableID = 0;
+
+ /**
+ * Allocates a new object.
+ *
+ * @param name name of variable
+ */
+ public Variable(String name) {
+ super(name);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ return env.lookupBind(toString());
+ }
+
+ /**
+ * Generates an uniquely named variable
+ */
+ public static Variable generateUniqueVariable() {
+ String name = "oj_var" + variableID;
+ ++variableID;
+ return new Variable(name);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/VariableDeclaration.java b/src/main/java/io/devnulllabs/openjava/ptree/VariableDeclaration.java
new file mode 100644
index 0000000..e29afb3
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/VariableDeclaration.java
@@ -0,0 +1,199 @@
+/*
+ * VariableDeclaration.java 1.0
+ *
+ * This class is made to type ptree-node into the local variable
+ * declaration statement in the body of class.
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The VariableDeclaration class presents
+ * local variable declaration statement node of parse tree.
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.ModifierList
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ * @see io.devnulllabs.openjava.ptree.VariableDeclarator
+ * @see io.devnulllabs.openjava.ptree.VariableInitializer
+ */
+public class VariableDeclaration extends NonLeaf implements Statement {
+ /**
+ * Allocates a new object.
+ *
+ * @param modifs the modifier list of this variable declaration.
+ * @param typespec the type specifier.
+ * @param vdeclr the variable declarator.
+ */
+ public VariableDeclaration(
+ ModifierList modifs,
+ TypeName typespec,
+ VariableDeclarator vdeclr) {
+ super();
+ if (modifs == null) {
+ modifs = new ModifierList();
+ }
+ set(modifs, typespec, vdeclr);
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param typespec the type specifier.
+ * @param vdeclr the variable declarator.
+ */
+ public VariableDeclaration(TypeName typespec, VariableDeclarator vdeclr) {
+ this(new ModifierList(), typespec, vdeclr);
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param modifs the modifier list of this variable declaration.
+ * @param typespec the type specifier.
+ * @param vname the variable name.
+ * @param vinit the variable initializer.
+ */
+ public VariableDeclaration(
+ ModifierList modifs,
+ TypeName typespec,
+ String vname,
+ VariableInitializer vinit) {
+ this(modifs, typespec, new VariableDeclarator(vname, vinit));
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param modifs the modifier list of this variable declaration.
+ * @param typespec the type specifier.
+ * @param vname the variable name.
+ * @param vinit the variable initializer.
+ */
+ public VariableDeclaration(
+ TypeName typespec,
+ String vname,
+ VariableInitializer vinit) {
+ this(new ModifierList(), typespec, vname, vinit);
+ }
+
+ VariableDeclaration() {
+ super();
+ }
+
+ /**
+ * Gets the modifer list of this variable declaration.
+ *
+ * @return the modifier list.
+ */
+ public ModifierList getModifiers() {
+ return (ModifierList) elementAt(0);
+ }
+
+ /**
+ * Sets the modifer list of this variable declaration.
+ *
+ * @param modifs the modifier list to set.
+ */
+ public void setModifiers(ModifierList modifs) {
+ setElementAt(modifs, 0);
+ }
+
+ /**
+ * Gets the type specifier of this variable declaration.
+ * Any modification on obtained objects is never reflected on
+ * this object.
+ *
+ * @return the type specifier for this variable.
+ */
+ public TypeName getTypeSpecifier() {
+ TypeName result;
+ TypeName tn = (TypeName) elementAt(1);
+ VariableDeclarator vd = (VariableDeclarator) elementAt(2);
+ result = (TypeName) tn.makeCopy();
+ result.addDimension(vd.getDimension());
+ return result;
+ }
+
+ /**
+ * Sets the type specifier of this variable declaration.
+ *
+ * @param tspec the type specifier to set.
+ */
+ public void setTypeSpecifier(TypeName tspec) {
+ setElementAt(tspec, 1);
+ }
+
+ /**
+ * Gets the variable declarator of this variable declaration.
+ *
+ * @return the variable declarator.
+ */
+ public VariableDeclarator getVariableDeclarator() {
+ return (VariableDeclarator) elementAt(2);
+ }
+
+ /**
+ * Sets the variable declarator of this variable declaration.
+ *
+ * @param vdeclr the variable declarator to set.
+ */
+ public void setVariableDeclarator(VariableDeclarator vdeclr) {
+ setElementAt(vdeclr, 2);
+ }
+
+ /**
+ * Gets declarator name, declarator name includes variable name
+ * but its dimension.
+ *
+ * @return declarator name
+ */
+ public String getVariable() {
+ return getVariableDeclarator().getVariable();
+ }
+
+ /**
+ * Sets declarator name, declarator name includes variable name
+ * but its dimension.
+ *
+ * @param name declarator name to set.
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ */
+ public void setVariable(String name) {
+ getVariableDeclarator().setVariable(name);
+ }
+
+ /**
+ * Gets variable initializer.
+ *
+ * @return variable initializer.
+ */
+ public VariableInitializer getInitializer() {
+ return getVariableDeclarator().getInitializer();
+ }
+
+ /**
+ * Sets variable initializer.
+ *
+ * @param vinit the variable initializer to set.
+ */
+ public void setInitializer(VariableInitializer vinit) {
+ getVariableDeclarator().setInitializer(vinit);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/VariableDeclarator.java b/src/main/java/io/devnulllabs/openjava/ptree/VariableDeclarator.java
new file mode 100644
index 0000000..ee73516
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/VariableDeclarator.java
@@ -0,0 +1,114 @@
+/*
+ * VariableDeclarator.java 1.0
+ *
+ * This interface is made to type ptree-node into the variable
+ * declarator in the body of class.
+ *
+ * Jun 20, 1997 by mich
+ * Aug 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The VariableDeclarator class presents variable declarator node
+ * of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.VariableInitializer
+ */
+public class VariableDeclarator extends NonLeaf {
+ int dims = 0;
+
+ /**
+ * Allocates a new object.
+ *
+ * @param declname the declarator name.
+ * @param varinit the variable initializer.
+ */
+ public VariableDeclarator(
+ String declname,
+ int dims,
+ VariableInitializer varinit) {
+ super();
+ set(declname, varinit);
+ this.dims = dims;
+ }
+
+ /**
+ * Allocates a new object.
+ *
+ * @param declname the declarator name.
+ * @param varinit the variable initializer.
+ */
+ public VariableDeclarator(String declname, VariableInitializer varinit) {
+ this(declname, 0, varinit);
+ }
+
+ VariableDeclarator() {
+ super();
+ }
+
+ /**
+ * Gets declarator name, declarator name includes variable name
+ * but its dimension.
+ *
+ * @return declarator name
+ */
+ public String getVariable() {
+ return (String) elementAt(0);
+ }
+
+ /**
+ * Sets declarator name, declarator name includes variable name
+ * but its dimension.
+ *
+ * @param name declarator name to set.
+ * @see io.devnulllabs.openjava.ptree.TypeName
+ */
+ public void setVariable(String name) {
+ setElementAt(name, 0);
+ }
+
+ public int getDimension() {
+ return this.dims;
+ }
+
+ public String dimensionString() {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < getDimension(); ++i) {
+ buf.append("[]");
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Gets variable initializer.
+ *
+ * @return variable initializer.
+ */
+ public VariableInitializer getInitializer() {
+ return (VariableInitializer) elementAt(1);
+ }
+
+ /**
+ * Sets variable initializer.
+ *
+ * @param vinit the variable initializer to set.
+ */
+ public void setInitializer(VariableInitializer vinit) {
+ setElementAt(vinit, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/VariableInitializer.java b/src/main/java/io/devnulllabs/openjava/ptree/VariableInitializer.java
new file mode 100644
index 0000000..cb5156a
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/VariableInitializer.java
@@ -0,0 +1,32 @@
+/*
+ * VariableInitializer.java 1.0
+ *
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+
+
+
+
+/**
+ * The VariableInitializer class presents common interfaces
+ * to several initializer format
+ *
+ * interface VariableInitializer is implemented by
+ * Expression
+ * ArrayInitializer
+ *
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.ArrayInitializer
+ */
+public interface VariableInitializer extends ParseTree
+{
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/WhileStatement.java b/src/main/java/io/devnulllabs/openjava/ptree/WhileStatement.java
new file mode 100644
index 0000000..81c4eb3
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/WhileStatement.java
@@ -0,0 +1,84 @@
+/**
+ * The WhileStatement class presents while statement node
+ * of parse tree
+ *
+ * Jun 20, 1997 by mich
+ * Sep 29, 1997 by mich
+ * Oct 11, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 11, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The WhileStatement class presents while statement node
+ * of parse tree
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ * @see io.devnulllabs.openjava.ptree.Statement
+ */
+public class WhileStatement extends NonLeaf implements Statement, ParseTree {
+
+ /**
+ * Allocates a new object.
+ *
+ * @param expr the expression of the condition of this while
+ * statement.
+ * @param stmts the statement list of the body oof this while
+ * statement.
+ */
+ public WhileStatement(Expression expr, StatementList stmts) {
+ super();
+ set((ParseTree) expr, (ParseTree) stmts);
+ }
+
+ WhileStatement() {
+ super();
+ }
+
+ /**
+ * Gets the condtion of this while statement.
+ *
+ * @return the expression of the condtion.
+ */
+ public Expression getExpression() {
+ return (Expression) elementAt(0);
+ }
+
+ /**
+ * Sets the condtion of this while statement.
+ *
+ * @param expr the expression of the condtion to set.
+ */
+ public void setExpression(Expression expr) {
+ setElementAt(expr, 0);
+ }
+
+ /**
+ * Gets the body of this while statement.
+ *
+ * @return the statement list of the body.
+ */
+ public StatementList getStatements() {
+ return (StatementList) elementAt(1);
+ }
+
+ /**
+ * Sets the body of this while statement.
+ *
+ * @param stmts the statement list of the body to set.
+ */
+ public void setStatements(StatementList stmts) {
+ setElementAt(stmts, 1);
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/ClassLiteralReplacer.java b/src/main/java/io/devnulllabs/openjava/ptree/util/ClassLiteralReplacer.java
new file mode 100644
index 0000000..372343d
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/ClassLiteralReplacer.java
@@ -0,0 +1,57 @@
+/*
+ * ClassLiteralReplacer.java
+ *
+ * Make typenames qualified.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+/**
+ * The class <code>ClassLiteralReplacer</code>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ClassLiteralReplacer.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class ClassLiteralReplacer extends EvaluationShuttle {
+ public static final String OLDCLASS_PREFIX = "oldjavaclass.";
+
+ public ClassLiteralReplacer(Environment env) {
+ super(env);
+ }
+
+ public Expression evaluateDown(ClassLiteral ptree)
+ throws ParseTreeException {
+ TypeName type = ptree.getTypeName();
+
+ if (type.toString().startsWith(OLDCLASS_PREFIX)) {
+ String name = type.getName();
+ name = name.substring(OLDCLASS_PREFIX.length());
+ int dim = type.getDimension();
+ return new ClassLiteral(new TypeName(name, dim));
+ }
+
+ ExpressionList args = new ExpressionList(new ClassLiteral(type));
+ Expression result =
+ new MethodCall(OJClass.forClass(OJClass.class), "forClass", args);
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/EvaluationShuttle.java b/src/main/java/io/devnulllabs/openjava/ptree/util/EvaluationShuttle.java
new file mode 100644
index 0000000..b5f77bf
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/EvaluationShuttle.java
@@ -0,0 +1,1138 @@
+/*
+ * EvaluationShuttle.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayAccess;
+import io.devnulllabs.openjava.ptree.ArrayAllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayInitializer;
+import io.devnulllabs.openjava.ptree.AssignmentExpression;
+import io.devnulllabs.openjava.ptree.BinaryExpression;
+import io.devnulllabs.openjava.ptree.Block;
+import io.devnulllabs.openjava.ptree.BreakStatement;
+import io.devnulllabs.openjava.ptree.CaseGroup;
+import io.devnulllabs.openjava.ptree.CaseGroupList;
+import io.devnulllabs.openjava.ptree.CaseLabel;
+import io.devnulllabs.openjava.ptree.CaseLabelList;
+import io.devnulllabs.openjava.ptree.CastExpression;
+import io.devnulllabs.openjava.ptree.CatchBlock;
+import io.devnulllabs.openjava.ptree.CatchList;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassDeclarationList;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ConditionalExpression;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorInvocation;
+import io.devnulllabs.openjava.ptree.ContinueStatement;
+import io.devnulllabs.openjava.ptree.DoWhileStatement;
+import io.devnulllabs.openjava.ptree.EmptyStatement;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.ExpressionStatement;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.ForStatement;
+import io.devnulllabs.openjava.ptree.IfStatement;
+import io.devnulllabs.openjava.ptree.InstanceofExpression;
+import io.devnulllabs.openjava.ptree.LabeledStatement;
+import io.devnulllabs.openjava.ptree.Literal;
+import io.devnulllabs.openjava.ptree.MemberDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.MemberInitializer;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.ReturnStatement;
+import io.devnulllabs.openjava.ptree.SelfAccess;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.SwitchStatement;
+import io.devnulllabs.openjava.ptree.SynchronizedStatement;
+import io.devnulllabs.openjava.ptree.ThrowStatement;
+import io.devnulllabs.openjava.ptree.TryStatement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.UnaryExpression;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.ptree.VariableDeclarator;
+import io.devnulllabs.openjava.ptree.VariableInitializer;
+import io.devnulllabs.openjava.ptree.WhileStatement;
+
+/**
+ * The class <code>EvaluationShuttle</code> is a Visitor role
+ * in the Visitor pattern and this also visits each child
+ * <code>ParseTree</code> object from left to right.
+ * <p>
+ * The class <code>Evaluator</code> is an evaluator of each
+ * objects of <code>ParseTree</code> family. Each methods in
+ * this class is invoked from the class <code>EvaluationShuttle</code>.
+ * <p>
+ * The method <code>evaluateDown()</code> is invoked before evaluating
+ * the children of the parse tree object, and <code>evaluateUp()</code>
+ * is invoked after the evaluation.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: EvaluationShuttle.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.util.ParseTreeVisitor
+ */
+public abstract class EvaluationShuttle extends ParseTreeVisitor {
+ private Environment env;
+
+ public EvaluationShuttle(Environment env) {
+ this.env = env;
+ }
+
+ protected Environment getEnvironment() {
+ return env;
+ }
+
+ protected void setEnvironment(Environment env) {
+ this.env = env;
+ }
+
+ public Expression evaluateDown(AllocationExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(ArrayAccess p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(ArrayAllocationExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public VariableInitializer evaluateDown(ArrayInitializer p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(AssignmentExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(BinaryExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(Block p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(BreakStatement p) throws ParseTreeException {
+ return p;
+ }
+ public CaseGroup evaluateDown(CaseGroup p) throws ParseTreeException {
+ return p;
+ }
+ public CaseGroupList evaluateDown(CaseGroupList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public CaseLabel evaluateDown(CaseLabel p) throws ParseTreeException {
+ return p;
+ }
+ public CaseLabelList evaluateDown(CaseLabelList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(CastExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public CatchBlock evaluateDown(CatchBlock p) throws ParseTreeException {
+ return p;
+ }
+ public CatchList evaluateDown(CatchList p) throws ParseTreeException {
+ return p;
+ }
+ public ClassDeclaration evaluateDown(ClassDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public ClassDeclarationList evaluateDown(ClassDeclarationList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(ClassLiteral p) throws ParseTreeException {
+ return p;
+ }
+ public CompilationUnit evaluateDown(CompilationUnit p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(ConditionalExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateDown(ConstructorDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public ConstructorInvocation evaluateDown(ConstructorInvocation p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(ContinueStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(DoWhileStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(EmptyStatement p) throws ParseTreeException {
+ return p;
+ }
+ public ExpressionList evaluateDown(ExpressionList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(ExpressionStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(FieldAccess p) throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateDown(FieldDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(ForStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(IfStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(InstanceofExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(LabeledStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(Literal p) throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclarationList evaluateDown(MemberDeclarationList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateDown(MemberInitializer p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(MethodCall p) throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateDown(MethodDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public ModifierList evaluateDown(ModifierList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Parameter evaluateDown(Parameter p) throws ParseTreeException {
+ return p;
+ }
+ public ParameterList evaluateDown(ParameterList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(ReturnStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(SelfAccess p) throws ParseTreeException {
+ return p;
+ }
+ public StatementList evaluateDown(StatementList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(SwitchStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(SynchronizedStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(ThrowStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(TryStatement p) throws ParseTreeException {
+ return p;
+ }
+ public TypeName evaluateDown(TypeName p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(UnaryExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateDown(Variable p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(VariableDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public VariableDeclarator evaluateDown(VariableDeclarator p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateDown(WhileStatement p) throws ParseTreeException {
+ return p;
+ }
+
+ public Expression evaluateUp(AllocationExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(ArrayAccess p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(ArrayAllocationExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public VariableInitializer evaluateUp(ArrayInitializer p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(AssignmentExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(BinaryExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(Block p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(BreakStatement p) throws ParseTreeException {
+ return p;
+ }
+ public CaseGroup evaluateUp(CaseGroup p) throws ParseTreeException {
+ return p;
+ }
+ public CaseGroupList evaluateUp(CaseGroupList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public CaseLabel evaluateUp(CaseLabel p) throws ParseTreeException {
+ return p;
+ }
+ public CaseLabelList evaluateUp(CaseLabelList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(CastExpression p) throws ParseTreeException {
+ return p;
+ }
+ public CatchBlock evaluateUp(CatchBlock p) throws ParseTreeException {
+ return p;
+ }
+ public CatchList evaluateUp(CatchList p) throws ParseTreeException {
+ return p;
+ }
+ public ClassDeclaration evaluateUp(ClassDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public ClassDeclarationList evaluateUp(ClassDeclarationList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(ClassLiteral p) throws ParseTreeException {
+ return p;
+ }
+ public CompilationUnit evaluateUp(CompilationUnit p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(ConditionalExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateUp(ConstructorDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public ConstructorInvocation evaluateUp(ConstructorInvocation p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(ContinueStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(DoWhileStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(EmptyStatement p) throws ParseTreeException {
+ return p;
+ }
+ public ExpressionList evaluateUp(ExpressionList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(ExpressionStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(FieldAccess p) throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateUp(FieldDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(ForStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(IfStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(InstanceofExpression p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(LabeledStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(Literal p) throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclarationList evaluateUp(MemberDeclarationList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateUp(MemberInitializer p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(MethodCall p) throws ParseTreeException {
+ return p;
+ }
+ public MemberDeclaration evaluateUp(MethodDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public ModifierList evaluateUp(ModifierList p) throws ParseTreeException {
+ return p;
+ }
+ public Parameter evaluateUp(Parameter p) throws ParseTreeException {
+ return p;
+ }
+ public ParameterList evaluateUp(ParameterList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(ReturnStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(SelfAccess p) throws ParseTreeException {
+ return p;
+ }
+ public StatementList evaluateUp(StatementList p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(SwitchStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(SynchronizedStatement p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(ThrowStatement p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(TryStatement p) throws ParseTreeException {
+ return p;
+ }
+ public TypeName evaluateUp(TypeName p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(UnaryExpression p) throws ParseTreeException {
+ return p;
+ }
+ public Expression evaluateUp(Variable p) throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(VariableDeclaration p)
+ throws ParseTreeException {
+ return p;
+ }
+ public VariableDeclarator evaluateUp(VariableDeclarator p)
+ throws ParseTreeException {
+ return p;
+ }
+ public Statement evaluateUp(WhileStatement p) throws ParseTreeException {
+ return p;
+ }
+
+ public void visit(AllocationExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ArrayAccess p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ArrayAllocationExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ArrayInitializer p) throws ParseTreeException {
+ VariableInitializer newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(AssignmentExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(BinaryExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(Block p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(BreakStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CaseGroup p) throws ParseTreeException {
+ this.evaluateDown(p);
+ p.childrenAccept(this);
+ this.evaluateUp(p);
+ }
+
+ public void visit(CaseGroupList p) throws ParseTreeException {
+ CaseGroupList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CaseLabel p) throws ParseTreeException {
+ CaseLabel newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CaseLabelList p) throws ParseTreeException {
+ CaseLabelList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CastExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CatchBlock p) throws ParseTreeException {
+ CatchBlock newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CatchList p) throws ParseTreeException {
+ CatchList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ClassDeclaration p) throws ParseTreeException {
+ ClassDeclaration newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ClassDeclarationList p) throws ParseTreeException {
+ ClassDeclarationList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ClassLiteral p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(CompilationUnit p) throws ParseTreeException {
+ CompilationUnit newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ConditionalExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ConstructorDeclaration p) throws ParseTreeException {
+ MemberDeclaration newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ConstructorInvocation p) throws ParseTreeException {
+ ConstructorInvocation newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ContinueStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(DoWhileStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(EmptyStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ExpressionList p) throws ParseTreeException {
+ ExpressionList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ExpressionStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ /* if not same as original, do not continue */
+ public void visit(FieldAccess p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(FieldDeclaration p) throws ParseTreeException {
+ MemberDeclaration newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ForStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(IfStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(InstanceofExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(LabeledStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(Literal p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(MemberDeclarationList p) throws ParseTreeException {
+ MemberDeclarationList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(MemberInitializer p) throws ParseTreeException {
+ MemberDeclaration newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(MethodCall p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(MethodDeclaration p) throws ParseTreeException {
+ MemberDeclaration newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ModifierList p) throws ParseTreeException {
+ ModifierList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(Parameter p) throws ParseTreeException {
+ Parameter newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ParameterList p) throws ParseTreeException {
+ ParameterList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ReturnStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(SelfAccess p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(StatementList p) throws ParseTreeException {
+ StatementList newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(SwitchStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(SynchronizedStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(ThrowStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(TryStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(TypeName p) throws ParseTreeException {
+ TypeName newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(UnaryExpression p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(Variable p) throws ParseTreeException {
+ Expression newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(VariableDeclaration p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(VariableDeclarator p) throws ParseTreeException {
+ VariableDeclarator newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ public void visit(WhileStatement p) throws ParseTreeException {
+ Statement newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ return;
+ }
+ p.childrenAccept(this);
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/ExpansionApplier.java b/src/main/java/io/devnulllabs/openjava/ptree/util/ExpansionApplier.java
new file mode 100644
index 0000000..811cc32
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/ExpansionApplier.java
@@ -0,0 +1,457 @@
+/*
+ * ExpansionApplier.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayAccess;
+import io.devnulllabs.openjava.ptree.ArrayAllocationExpression;
+import io.devnulllabs.openjava.ptree.AssignmentExpression;
+import io.devnulllabs.openjava.ptree.BinaryExpression;
+import io.devnulllabs.openjava.ptree.CastExpression;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.ConditionalExpression;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.InstanceofExpression;
+import io.devnulllabs.openjava.ptree.Literal;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.SelfAccess;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.UnaryExpression;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The class <code>ExpansionApplier</code> is an evaluator of each
+ * objects of <code>ParseTree</code> family. Each methods in
+ * this class is invoked from the class <code>EvaluationShuttle</code>.
+ * <p>
+ * The method <code>evaluateDown()</code> is invoked before evaluating
+ * the children of the parse tree object, and <code>evaluateUp()</code>
+ * is invoked after the evaluation.
+ * <p>
+ * For a class <code>P</code> and a object <code>p</code> statically
+ * typed as P, the parts in source code each expantion will be applied
+ * are:
+ * <ul>
+ * <li>Allocation <code>new P()</code>
+ * <li>ArrayAllocation <code>new P[expr]</code>
+ * <li>MethodCall <code>P.m()</code>, <code>p.m()</code>
+ * <li>FieldRead <code>P.f</code>, <code>p.f</code> as a right side value
+ * <li>FieldWrite <code>P.f = expr</code>, <code>p.f = expr</code>
+ * <li>ArrayAccess <code>ap[expr]</code> for <code>P[] ap;</code>
+ * <li>Expression <code>p</code>
+ * </ul>
+ * in feature version:
+ * <ul>
+ * <li>CastExpression <code>(P) expr</code> including implicit cast
+ * <li>CastedExpression <code>(Q) p</code> including implicit cast
+ * </ul>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ExpansionApplier.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.util.EvaluationShuttle
+ */
+public class ExpansionApplier extends VariableBinder {
+ public ExpansionApplier(Environment env) {
+ super(env);
+ }
+
+ private OJClass getType(Expression p) throws ParseTreeException {
+ OJClass result = null;
+ try {
+ result = p.getType(getEnvironment());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ParseTreeException(e);
+ }
+ DebugOut.println("type eval - " + p + "\t: " + result);
+ if (result == null) {
+ System.err.println("cannot resolve the type of expression");
+ System.err.println(p.getClass() + " : " + p);
+ System.err.println(getEnvironment());
+ /*****DebugOut.println(getEnvironment().toString());*/
+ if (p instanceof ArrayAccess) {
+ ArrayAccess aaexpr = (ArrayAccess) p;
+ Expression refexpr = aaexpr.getReferenceExpr();
+ OJClass refexprtype = null;
+ OJClass comptype = null;
+ try {
+ refexprtype = refexpr.getType(getEnvironment());
+ comptype = refexprtype.getComponentType();
+ } catch (Exception ex) {
+ }
+ System.err.println(
+ refexpr + " : " + refexprtype + " : " + comptype);
+ }
+ }
+ return result;
+ }
+
+ private OJClass getSelfType() throws ParseTreeException {
+ OJClass result;
+ try {
+ Environment env = getEnvironment();
+ String selfname = env.currentClassName();
+ result = env.lookupClass(selfname);
+ } catch (Exception ex) {
+ throw new ParseTreeException(ex);
+ }
+ return result;
+ }
+
+ private OJClass getType(TypeName typename) throws ParseTreeException {
+ OJClass result = null;
+ try {
+ Environment env = getEnvironment();
+ String qname = env.toQualifiedName(typename.toString());
+ result = env.lookupClass(qname);
+ } catch (Exception ex) {
+ throw new ParseTreeException(ex);
+ }
+ DebugOut.println("type eval - class access : " + result);
+ if (result == null) {
+ System.err.println("unknown type for a type name : " + typename);
+ }
+ return result;
+ }
+
+ private OJClass computeRefType(TypeName typename, Expression expr)
+ throws ParseTreeException {
+ if (typename != null)
+ return getType(typename);
+ if (expr != null)
+ return getType(expr);
+ return getSelfType();
+ }
+
+ public void visit(AssignmentExpression p) throws ParseTreeException {
+ Expression left = p.getLeft();
+ if (!(left instanceof FieldAccess)) {
+ super.visit(p);
+ return;
+ }
+ FieldAccess fldac = (FieldAccess) left;
+ Expression refexpr = fldac.getReferenceExpr();
+ TypeName reftype = fldac.getReferenceType();
+ Expression value = p.getRight();
+ /* custom version of visit() skipping the field */
+ Expression newp;
+ newp = this.evaluateDown(p);
+ if (newp != p) {
+ p.replace(newp);
+ newp.accept(this);
+ return;
+ }
+
+ if (refexpr != null) {
+ refexpr.accept(this);
+ } else if (reftype != null) {
+ reftype.accept(this);
+ }
+ value.accept(this);
+
+ newp = this.evaluateUp(p);
+ if (newp != p)
+ p.replace(newp);
+ }
+
+ /**
+ * Includes expandAllocation() and expandExpression().
+ */
+ public Expression evaluateUp(AllocationExpression p)
+ throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandAllocation(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandArrayAccess() and expandExpression().
+ */
+ public Expression evaluateUp(ArrayAccess p) throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandArrayAccess(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandArrayAllocation() and expandExpression().
+ */
+ public Expression evaluateUp(ArrayAllocationExpression p)
+ throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandArrayAllocation(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandFieldWrite(), expandAssignmentExpression()
+ * and expandExpression().
+ */
+ public Expression evaluateUp(AssignmentExpression p)
+ throws ParseTreeException {
+ Expression left = p.getLeft();
+ if (left instanceof FieldAccess) {
+ FieldAccess fldac = (FieldAccess) left;
+ OJClass reftype =
+ computeRefType(
+ fldac.getReferenceType(),
+ fldac.getReferenceExpr());
+ if (reftype != getSelfType()) {
+ Expression newp = reftype.expandFieldWrite(getEnvironment(), p);
+ if (!(newp instanceof AssignmentExpression))
+ return newp;
+ p = (AssignmentExpression) newp;
+ }
+ }
+
+ OJClass type = getType(p);
+ if (type != getSelfType()) {
+ Expression newp =
+ type.expandAssignmentExpression(getEnvironment(), p);
+ if (!(newp instanceof AssignmentExpression))
+ return newp;
+ p = (AssignmentExpression) newp;
+ type = getType(p);
+ }
+ if (type != getSelfType()) {
+ Expression newp = type.expandExpression(getEnvironment(), p);
+ if (!(newp instanceof AssignmentExpression))
+ return newp;
+ p = (AssignmentExpression) newp;
+ }
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(BinaryExpression p)
+ throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandCastExpression(), expandCastedExpression() and
+ * expandExpression().
+ */
+ public Expression evaluateUp(CastExpression p) throws ParseTreeException {
+ OJClass type = getType(p);
+ OJClass orgType = getType(p.getExpression());
+ Expression newp;
+ newp = orgType.expandCastedExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ newp = type.expandCastExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(ClassLiteral p) throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(ConditionalExpression p)
+ throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandFieldRead() and expandExpression().
+ * Not to be applied for itself.
+ */
+ public Expression evaluateUp(FieldAccess p) throws ParseTreeException {
+ {
+ OJClass reftype =
+ computeRefType(p.getReferenceType(), p.getReferenceExpr());
+ if (reftype != getSelfType()) {
+ Expression newp = reftype.expandFieldRead(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ }
+ }
+ {
+ OJClass type = getType(p);
+ Expression newp = type.expandExpression(getEnvironment(), p);
+ if (!(newp instanceof FieldAccess))
+ return newp;
+ p = (FieldAccess) newp;
+ }
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(InstanceofExpression p)
+ throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(Literal p) throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandMethodCall() and expandExpression().
+ */
+ public Expression evaluateUp(MethodCall p) throws ParseTreeException {
+ {
+ OJClass reftype =
+ computeRefType(p.getReferenceType(), p.getReferenceExpr());
+ if (reftype != getSelfType()) {
+ Expression newp = reftype.expandMethodCall(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ }
+ }
+ {
+ OJClass type = getType(p);
+ Expression newp = type.expandExpression(getEnvironment(), p);
+ if (!(newp instanceof MethodCall))
+ return newp;
+ p = (MethodCall) newp;
+ }
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(SelfAccess p) throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandTypeName().
+ */
+ public TypeName evaluateUp(TypeName p) throws ParseTreeException {
+ OJClass type = getType(p);
+ TypeName newp;
+ newp = type.expandTypeName(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(UnaryExpression p) throws ParseTreeException {
+ OJClass type = getType(p);
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandExpression().
+ */
+ public Expression evaluateUp(Variable p) throws ParseTreeException {
+ OJClass type = getType(p);
+
+ /* special ignorance for variable ? */
+ if (type == null)
+ return p;
+
+ Expression newp;
+ newp = type.expandExpression(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+ /**
+ * Includes expandVariableDeclaration().
+ */
+ public Statement evaluateUp(VariableDeclaration p)
+ throws ParseTreeException {
+ OJClass type = getType(p.getTypeSpecifier());
+ Statement newp;
+ newp = type.expandVariableDeclaration(getEnvironment(), p);
+ if (newp != p)
+ return newp;
+ return super.evaluateUp(p);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/MemberAccessCorrector.java b/src/main/java/io/devnulllabs/openjava/ptree/util/MemberAccessCorrector.java
new file mode 100644
index 0000000..8c1a2d8
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/MemberAccessCorrector.java
@@ -0,0 +1,222 @@
+/*
+ * MemberAccessCorrector.java
+ *
+ * Firstly, the parser generates a temporal parse tree.
+ * This class correct them.
+ * <p>
+ *
+ * All the continuous field access are stored in a single Variable ptree
+ * object.
+ * [p.p.f.f].f [p.f].m() ([] a single Variable object)
+ * FieldAccess := Variable name
+ * MemberAccess := Variable name "(" .. ")"
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.NoSuchMemberException;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJClassNotFoundException;
+import io.devnulllabs.openjava.mop.OJField;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The class <code>MemberAccessCorrector</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MemberAccessCorrector.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class MemberAccessCorrector extends VariableBinder {
+
+ private String errorState = null;
+
+ public MemberAccessCorrector(Environment env) {
+ super(env);
+ }
+
+ public String getErrorState() {
+ return errorState;
+ }
+
+ public Expression evaluateDown(FieldAccess ptree)
+ throws ParseTreeException {
+ super.evaluateDown(ptree);
+
+ if (ptree.getReferenceType() != null)
+ return ptree;
+
+ Expression ref = ptree.getReferenceExpr();
+ String field_name = ptree.getName();
+
+ if (ref == null) {
+ if (isVariable(field_name)) {
+ /* this is a variable. */
+ DebugOut.println("MC variable - " + field_name);
+ return new Variable(field_name);
+ } else if (isField(field_name)) {
+ /* this is a field access */
+ DebugOut.println("MC field access - " + field_name);
+ } else {
+ /* unknown variable or field */
+ System.err.println("unknown field or variable : " + field_name);
+ System.err.println(getEnvironment());
+ }
+ } else if (ref instanceof Variable) {
+ FieldAccess fa = name2fieldaccess(ref.toString(), field_name);
+ TypeName typename = fa.getReferenceType();
+ Expression refexpr = fa.getReferenceExpr();
+ if (typename != null) {
+ ptree.setReferenceType(typename);
+ } else {
+ ptree.setReferenceExpr(refexpr);
+ }
+ }
+
+ return ptree;
+ }
+
+ public Expression evaluateDown(MethodCall ptree)
+ throws ParseTreeException {
+ super.evaluateDown(ptree);
+
+ if (ptree.getReferenceType() != null)
+ return ptree;
+
+ Expression ref = ptree.getReferenceExpr();
+ if (ref == null || !(ref instanceof Variable))
+ return ptree;
+ String method_name = ptree.getName();
+
+ if (ref instanceof Variable) {
+ FieldAccess fa = name2fieldaccess(ref.toString(), method_name);
+ TypeName typename = fa.getReferenceType();
+ Expression refexpr = fa.getReferenceExpr();
+ if (typename != null) {
+ ptree.setReferenceType(typename);
+ } else {
+ ptree.setReferenceExpr(refexpr);
+ }
+ }
+ return ptree;
+ }
+
+ private FieldAccess name2fieldaccess(String names, String field) {
+ Expression result_expr;
+ String first = getFirst(names);
+ String rest = getRest(names);
+
+ if (isVariable(first)) {
+ /* this is a variable */
+ DebugOut.println("MC variable - " + first);
+ result_expr = new Variable(first);
+ } else if (isField(first)) {
+ /* this is a field */
+ DebugOut.println("MC field - " + first);
+ result_expr = new FieldAccess((Variable) null, first);
+ } else {
+ /* this is a class */
+ while (rest != null && !isClass(first)) {
+ first = first + "." + getFirst(rest);
+ rest = getRest(rest);
+ }
+ while (isClass(first + "." + getFirst(rest))) {
+ first = first + "." + getFirst(rest);
+ rest = getRest(rest);
+ }
+ if (isClass(first)) {
+ DebugOut.println("MC class - " + first);
+ } else {
+ System.err.println("unknown class : " + first);
+ }
+
+ TypeName type = new TypeName(first);
+ if (rest == null) {
+ /* ref is a typename */
+ return new FieldAccess(type, field);
+ }
+ first = getFirst(rest);
+ rest = getRest(rest);
+ result_expr = new FieldAccess(type, first);
+ }
+
+ /* remainder is field access */
+ while (rest != null) {
+ first = getFirst(rest);
+ rest = getRest(rest);
+ result_expr = new FieldAccess(result_expr, first);
+ }
+
+ return new FieldAccess(result_expr, field);
+ }
+
+ private boolean isVariable(String name) {
+ Environment env = getEnvironment();
+ OJClass bindedtype = env.lookupBind(name);
+ return (bindedtype != null);
+ }
+
+ private boolean isField(String name) {
+ Environment env = getEnvironment();
+ String qcname = env.toQualifiedName(env.currentClassName());
+ OJClass declarer = env.lookupClass(qcname);
+ OJField field = null;
+ while (declarer != null && field == null) {
+ try {
+ field = declarer.getField(name, declarer);
+ } catch (NoSuchMemberException e) {
+ }
+ declarer = declarer.getDeclaringClass();
+ }
+ return (field != null);
+ }
+
+ private boolean isClass(String name) {
+ Environment env = getEnvironment();
+ String qname = env.toQualifiedName(name);
+ try {
+ OJClass.forName(qname);
+ return true;
+ } catch (OJClassNotFoundException e) {
+ }
+ OJClass clazz = env.lookupClass(qname);
+ return (clazz != null);
+ }
+
+ private static final String getFirst(String qname) {
+ if (qname == null)
+ return null;
+ int dot = qname.indexOf('.');
+ if (dot == -1)
+ return qname;
+ return qname.substring(0, dot);
+ }
+
+ private static final String getRest(String qname) {
+ if (qname == null)
+ return null;
+ int dot = qname.indexOf('.');
+ if (dot == -1)
+ return null;
+ return qname.substring(dot + 1);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/ParseTreeVisitor.java b/src/main/java/io/devnulllabs/openjava/ptree/util/ParseTreeVisitor.java
new file mode 100644
index 0000000..88a609f
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/ParseTreeVisitor.java
@@ -0,0 +1,191 @@
+/*
+ * ParseTreeVisitor.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayAccess;
+import io.devnulllabs.openjava.ptree.ArrayAllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayInitializer;
+import io.devnulllabs.openjava.ptree.AssignmentExpression;
+import io.devnulllabs.openjava.ptree.BinaryExpression;
+import io.devnulllabs.openjava.ptree.Block;
+import io.devnulllabs.openjava.ptree.BreakStatement;
+import io.devnulllabs.openjava.ptree.CaseGroup;
+import io.devnulllabs.openjava.ptree.CaseGroupList;
+import io.devnulllabs.openjava.ptree.CaseLabel;
+import io.devnulllabs.openjava.ptree.CaseLabelList;
+import io.devnulllabs.openjava.ptree.CastExpression;
+import io.devnulllabs.openjava.ptree.CatchBlock;
+import io.devnulllabs.openjava.ptree.CatchList;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassDeclarationList;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ConditionalExpression;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorInvocation;
+import io.devnulllabs.openjava.ptree.ContinueStatement;
+import io.devnulllabs.openjava.ptree.DoWhileStatement;
+import io.devnulllabs.openjava.ptree.EmptyStatement;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.ExpressionStatement;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.ForStatement;
+import io.devnulllabs.openjava.ptree.IfStatement;
+import io.devnulllabs.openjava.ptree.InstanceofExpression;
+import io.devnulllabs.openjava.ptree.LabeledStatement;
+import io.devnulllabs.openjava.ptree.Leaf;
+import io.devnulllabs.openjava.ptree.List;
+import io.devnulllabs.openjava.ptree.Literal;
+import io.devnulllabs.openjava.ptree.MemberDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.MemberInitializer;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.NonLeaf;
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.ParseTreeObject;
+import io.devnulllabs.openjava.ptree.ReturnStatement;
+import io.devnulllabs.openjava.ptree.SelfAccess;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.SwitchStatement;
+import io.devnulllabs.openjava.ptree.SynchronizedStatement;
+import io.devnulllabs.openjava.ptree.ThrowStatement;
+import io.devnulllabs.openjava.ptree.TryStatement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.UnaryExpression;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.ptree.VariableDeclarator;
+import io.devnulllabs.openjava.ptree.VariableInitializer;
+import io.devnulllabs.openjava.ptree.WhileStatement;
+
+/**
+ * The class <code>ParseTreeVisitor</code> is a Visitor role
+ * in the Visitor pattern and visits <code>ParseTree</code> objects
+ * as the role of Element.
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ParseTreeVisitor.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ */
+public abstract class ParseTreeVisitor {
+
+ public void visit(ParseTree p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(ParseTreeObject p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(NonLeaf p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(Leaf p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(MemberDeclaration p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(Statement p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(Expression p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(VariableInitializer p) throws ParseTreeException {
+ p.accept(this);
+ }
+ public void visit(List p) throws ParseTreeException {
+ p.accept(this);
+ }
+
+ public abstract void visit(AllocationExpression p)
+ throws ParseTreeException;
+ public abstract void visit(ArrayAccess p) throws ParseTreeException;
+ public abstract void visit(ArrayAllocationExpression p)
+ throws ParseTreeException;
+ public abstract void visit(ArrayInitializer p) throws ParseTreeException;
+ public abstract void visit(AssignmentExpression p)
+ throws ParseTreeException;
+ public abstract void visit(BinaryExpression p) throws ParseTreeException;
+ public abstract void visit(Block p) throws ParseTreeException;
+ public abstract void visit(BreakStatement p) throws ParseTreeException;
+ public abstract void visit(CaseGroup p) throws ParseTreeException;
+ public abstract void visit(CaseGroupList p) throws ParseTreeException;
+ public abstract void visit(CaseLabel p) throws ParseTreeException;
+ public abstract void visit(CaseLabelList p) throws ParseTreeException;
+ public abstract void visit(CastExpression p) throws ParseTreeException;
+ public abstract void visit(CatchBlock p) throws ParseTreeException;
+ public abstract void visit(CatchList p) throws ParseTreeException;
+ public abstract void visit(ClassDeclaration p) throws ParseTreeException;
+ public abstract void visit(ClassDeclarationList p)
+ throws ParseTreeException;
+ public abstract void visit(ClassLiteral p) throws ParseTreeException;
+ public abstract void visit(CompilationUnit p) throws ParseTreeException;
+ public abstract void visit(ConditionalExpression p)
+ throws ParseTreeException;
+ public abstract void visit(ConstructorDeclaration p)
+ throws ParseTreeException;
+ public abstract void visit(ConstructorInvocation p)
+ throws ParseTreeException;
+ public abstract void visit(ContinueStatement p) throws ParseTreeException;
+ public abstract void visit(DoWhileStatement p) throws ParseTreeException;
+ public abstract void visit(EmptyStatement p) throws ParseTreeException;
+ public abstract void visit(ExpressionList p) throws ParseTreeException;
+ public abstract void visit(ExpressionStatement p)
+ throws ParseTreeException;
+ public abstract void visit(FieldAccess p) throws ParseTreeException;
+ public abstract void visit(FieldDeclaration p) throws ParseTreeException;
+ public abstract void visit(ForStatement p) throws ParseTreeException;
+ public abstract void visit(IfStatement p) throws ParseTreeException;
+ public abstract void visit(InstanceofExpression p)
+ throws ParseTreeException;
+ public abstract void visit(LabeledStatement p) throws ParseTreeException;
+ public abstract void visit(Literal p) throws ParseTreeException;
+ public abstract void visit(MemberDeclarationList p)
+ throws ParseTreeException;
+ public abstract void visit(MemberInitializer p) throws ParseTreeException;
+ public abstract void visit(MethodCall p) throws ParseTreeException;
+ public abstract void visit(MethodDeclaration p) throws ParseTreeException;
+ public abstract void visit(ModifierList p) throws ParseTreeException;
+ public abstract void visit(Parameter p) throws ParseTreeException;
+ public abstract void visit(ParameterList p) throws ParseTreeException;
+ public abstract void visit(ReturnStatement p) throws ParseTreeException;
+ public abstract void visit(SelfAccess p) throws ParseTreeException;
+ public abstract void visit(StatementList p) throws ParseTreeException;
+ public abstract void visit(SwitchStatement p) throws ParseTreeException;
+ public abstract void visit(SynchronizedStatement p)
+ throws ParseTreeException;
+ public abstract void visit(ThrowStatement p) throws ParseTreeException;
+ public abstract void visit(TryStatement p) throws ParseTreeException;
+ public abstract void visit(TypeName p) throws ParseTreeException;
+ public abstract void visit(UnaryExpression p) throws ParseTreeException;
+ public abstract void visit(Variable p) throws ParseTreeException;
+ public abstract void visit(VariableDeclaration p)
+ throws ParseTreeException;
+ public abstract void visit(VariableDeclarator p) throws ParseTreeException;
+ public abstract void visit(WhileStatement p) throws ParseTreeException;
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/PartialParser.java b/src/main/java/io/devnulllabs/openjava/ptree/util/PartialParser.java
new file mode 100644
index 0000000..c6b2b28
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/PartialParser.java
@@ -0,0 +1,330 @@
+/*
+ * PartialParser.java 1.0
+ *
+ * This class can be used to make ptree objects from string.
+ *
+ * Jun 11, 1997 mich
+ * Oct 17, 1997 mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.ParseTreeObject
+ * @version 1.0 last updated: Oct 17, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import java.io.StringReader;
+
+import io.devnulllabs.openjava.mop.ClosedEnvironment;
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.MOPException;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.MemberDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.ObjectList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.tools.DebugOut;
+import io.devnulllabs.openjava.tools.parser.Parser;
+
+/**
+ * The <code>PartialParser</code> class is
+ * an utilty class to make ptree objects from string.
+ *
+ * @see io.devnulllabs.openjava.ptree.Ptree
+ * @see io.devnulllabs.openjava.ptree.Expression
+ * @see io.devnulllabs.openjava.ptree.Statement
+ * @see io.devnulllabs.openjava.ptree.StatementList
+ * @see io.devnulllabs.openjava.ptree.MemberDeclaration
+ * @see io.devnulllabs.openjava.ptree.MemberDeclarationList
+ * @see io.devnulllabs.openjava.ptree.TypeDeclaration
+ * @see io.devnulllabs.openjava.ptree.CompilationUnit
+ */
+public final class PartialParser {
+ /**
+ * Constructor should not be called.
+ *
+ */
+ protected PartialParser() {
+ }
+
+ private static ParseTree initialize(Environment env, ParseTree p)
+ throws ParseTreeException {
+ /* dummy wrapper in case replacement occurs */
+ ObjectList holder = new ObjectList(p);
+ p.accept(new MemberAccessCorrector(env));
+ return (ParseTree) holder.get(0);
+ }
+
+ /**
+ * Replaces "#s" "#EXPR" "#STMT" "#STMTS" in the given string with
+ * the given arguments.
+ * <p>
+ * "##" is replaced with "#".
+ * <p>
+ * <br><blockquote><pre>
+ * #s arg.toString()
+ * #EXPR ((Expression) arg).toString()
+ * #STMT ((Statement) arg).toString()
+ * #STMTS ((StatementList) arg).toString()
+ * </pre></blockquote><br>
+ *
+ */
+ public static final String replace(String base, Object[] args)
+ throws MOPException {
+ try {
+ StringBuffer result = new StringBuffer();
+
+ int arg_i = 0, index = 0, found;
+ while ((found = base.indexOf('#', index)) != -1) {
+ result.append(base.substring(index, found));
+ if (base.regionMatches(found, "#STMTS", 0, 6)) {
+ result.append((StatementList) args[arg_i++]);
+ index = found + 6;
+ } else if (base.regionMatches(found, "#STMT", 0, 5)) {
+ result.append((Statement) args[arg_i++]);
+ index = found + 5;
+ } else if (base.regionMatches(found, "#EXPR", 0, 5)) {
+ result.append((Expression) args[arg_i++]);
+ index = found + 5;
+ } else if (base.regionMatches(found, "#s", 0, 2)) {
+ result.append(args[arg_i++].toString());
+ index = found + 2;
+ } else if (base.regionMatches(found, "##", 0, 2)) {
+ result.append('#');
+ index = found + 2;
+ } else {
+ result.append('#');
+ index = found + 1;
+ }
+ }
+ result.append(base.substring(index));
+
+ return result.toString();
+ } catch (Exception e) {
+ /* special exception is better */
+ throw new MOPException(
+ "PartialParser.replace() : "
+ + "illegal format for arguments : "
+ + base);
+ }
+ }
+
+ public static final String replace(String base, Object a0)
+ throws MOPException {
+ return replace(base, new Object[] { a0 });
+ }
+
+ public static final String replace(String base, Object a0, Object a1)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1 });
+ }
+
+ public static final String replace(
+ String base,
+ Object a0,
+ Object a1,
+ Object a2)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1, a2 });
+ }
+
+ public static final String replace(
+ String base,
+ Object a0,
+ Object a1,
+ Object a2,
+ Object a3)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1, a2, a3 });
+ }
+
+ public static final String replace(
+ String base,
+ Object a0,
+ Object a1,
+ Object a2,
+ Object a3,
+ Object a4)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1, a2, a3, a4 });
+ }
+
+ public static final String replace(
+ String base,
+ Object a0,
+ Object a1,
+ Object a2,
+ Object a3,
+ Object a4,
+ Object a5)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1, a2, a3, a4, a5 });
+ }
+
+ public static final String replace(
+ String base,
+ Object a0,
+ Object a1,
+ Object a2,
+ Object a3,
+ Object a4,
+ Object a5,
+ Object a6)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1, a2, a3, a4, a5, a6 });
+ }
+
+ public static final String replace(
+ String base,
+ Object a0,
+ Object a1,
+ Object a2,
+ Object a3,
+ Object a4,
+ Object a5,
+ Object a6,
+ Object a7)
+ throws MOPException {
+ return replace(base, new Object[] { a0, a1, a2, a3, a4, a5, a6, a7 });
+ }
+
+ /**
+ * Makes a ptree node from the string like :
+ * <br><blockquote><pre>
+ * "i + 3"
+ * </pre></blockquote><br>
+ * or :
+ * <br><blockquote><pre>
+ * "f()"
+ * </pre></blockquote><br>
+ *
+ * @return the expression node which the specified string
+ * represents.
+ * @exception MOPException if any critical error occurs.
+ */
+ public static Expression makeExpression(Environment env, String str)
+ throws MOPException {
+ DebugOut.println("PP makeExpression() : " + str);
+ Parser parser = new Parser(new StringReader(str));
+ Expression result;
+ try {
+ result = parser.Expression(env);
+ result = (Expression) initialize(env, result);
+ } catch (Exception e) {
+ System.err.println("partial parsing failed for : " + str);
+ System.err.println(e);
+ System.err.println(env.toString());
+ throw new MOPException(e);
+ }
+ return result;
+ }
+
+ /**
+ * Makes a ptree node from the string like :
+ * <br><blockquote><pre>
+ * "i++;"
+ * </pre></blockquote><br>
+ * or :
+ * <br><blockquote><pre>
+ * "for(;;){ f(); }"
+ * </pre></blockquote><br>
+ * <p>
+ * But local variable declarations are not allowed.
+ *
+ * @return the statement node which the specified string
+ * represents.
+ * @exception MOPException if any critical error occurs.
+ */
+ public static Statement makeStatement(Environment env, String str)
+ throws MOPException {
+ DebugOut.println("PP makeStatement() : " + str);
+ Parser parser = new Parser(new StringReader(str));
+ Statement result;
+ try {
+ result = parser.Statement(env);
+ result = (Statement) initialize(env, result);
+ } catch (Exception e) {
+ System.err.println("partial parsing failed for : " + str);
+ System.err.println(e);
+ System.err.println(env.toString());
+ throw new MOPException(e);
+ }
+ return result;
+ }
+
+ /**
+ * Makes ptree node from the string like :
+ * <br><blockquote><pre>
+ * "i++; j = 3;"
+ * </pre></blockquote><br>
+ * <p>
+ * Local variable declarations like following can also be parsed.
+ * <br><blockquote><pre>
+ * "int n, m;"
+ * </pre></blockquote><br>
+ *
+ * @return the statements node which the specified string
+ * represents.
+ * @exception MOPException if any critical error occurs.
+ */
+ public static StatementList makeStatementList(Environment env, String str)
+ throws MOPException {
+ DebugOut.println("PP makeStatementList() : " + str);
+ Parser parser = new Parser(new StringReader(str));
+ env = new ClosedEnvironment(env);
+ StatementList result;
+ try {
+ result = parser.BlockOrStatementListOpt(env);
+ result = (StatementList) initialize(env, result);
+ } catch (Exception e) {
+ System.err.println("partial parsing failed for : " + str);
+ System.err.println(e);
+ System.err.println(env.toString());
+ throw new MOPException(e);
+ }
+ return result;
+ }
+
+ /**
+ * NOT IMPLEMENTED
+ * Makes ptree node from the string like :
+ * <br><blockquote><pre>
+ * "int f(){ return 1; }"
+ * </pre></blockquote><br>
+ * or :
+ * <br><blockquote><pre>
+ * "public String str;"
+ * </pre></blockquote><br>
+ *
+ * @return the statements node which the specified string
+ * represents.
+ * @exception MOPException if any critical error occurs.
+ */
+ public static MemberDeclaration makeMemberDeclaration(String str)
+ throws MOPException {
+ MemberDeclaration ret = null;
+ return ret;
+ }
+
+ /**
+ * NOT IMPLEMENTED
+ * Makes a ptree node from the string like :
+ * <br><blockquote><pre>
+ * "int f(){ return 1; }" +
+ * "public String str;"
+ * </pre></blockquote><br>
+ *
+ * @return the type declarations list node which the specified string
+ * represents.
+ * @exception MOPException if any critical error occurs.
+ */
+ public static MemberDeclarationList makeMemberDeclarationList(String str)
+ throws MOPException {
+ MemberDeclarationList ret = null;
+ return ret;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/ScopeHandler.java b/src/main/java/io/devnulllabs/openjava/ptree/util/ScopeHandler.java
new file mode 100644
index 0000000..0afb937
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/ScopeHandler.java
@@ -0,0 +1,305 @@
+/*
+ * ScopeHandler.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import java.util.Stack;
+
+import io.devnulllabs.openjava.mop.AnonymousClassEnvironment;
+import io.devnulllabs.openjava.mop.ClassEnvironment;
+import io.devnulllabs.openjava.mop.ClosedEnvironment;
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.FileEnvironment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.Block;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.DoWhileStatement;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ForStatement;
+import io.devnulllabs.openjava.ptree.IfStatement;
+import io.devnulllabs.openjava.ptree.MemberDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.MemberInitializer;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.SwitchStatement;
+import io.devnulllabs.openjava.ptree.SynchronizedStatement;
+import io.devnulllabs.openjava.ptree.TryStatement;
+import io.devnulllabs.openjava.ptree.WhileStatement;
+
+/**
+ * The class <code>ScopeHandler</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ScopeHandler.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.util.ParseTreeVisitor
+ * @see io.devnulllabs.openjava.ptree.util.EvaluationShuttle
+ */
+public abstract class ScopeHandler extends EvaluationShuttle {
+ private Stack env_nest = new Stack();
+
+ public ScopeHandler(Environment base_env) {
+ super(base_env);
+ }
+
+ protected final void pushClosedEnvironment() {
+ push(new ClosedEnvironment(getEnvironment()));
+ }
+
+ protected final void push(Environment env) {
+ env_nest.push(getEnvironment());
+ setEnvironment(env);
+ }
+
+ protected final void pop() {
+ setEnvironment((Environment) env_nest.pop());
+ }
+
+ /* in walking down through parse tree */
+
+ /* compilation unit */
+ public CompilationUnit evaluateDown(CompilationUnit ptree)
+ throws ParseTreeException {
+ ClassDeclaration pubclazz = ptree.getPublicClass();
+ String name =
+ (pubclazz != null) ? pubclazz.getName() : "<no public class>";
+ FileEnvironment fenv =
+ new FileEnvironment(getEnvironment(), ptree, name);
+
+ push(fenv);
+
+ return ptree;
+ }
+
+ /* class declaration */
+ public ClassDeclaration evaluateDown(ClassDeclaration ptree)
+ throws ParseTreeException {
+ /* records this class */
+ if (getEnvironment() instanceof ClosedEnvironment) {
+ recordLocalClass(ptree);
+ }
+
+ /* creates a new class environment */
+ ClassEnvironment env =
+ new ClassEnvironment(getEnvironment(), ptree.getName());
+ MemberDeclarationList mdecls = ptree.getBody();
+ for (int i = 0; i < mdecls.size(); ++i) {
+ MemberDeclaration m = mdecls.get(i);
+ if (!(m instanceof ClassDeclaration))
+ continue;
+ ClassDeclaration inner = (ClassDeclaration) m;
+ env.recordMemberClass(inner.getName());
+ }
+ push(env);
+
+ return ptree;
+ }
+
+ private void recordLocalClass(ClassDeclaration ptree) {
+ String classname = ptree.getName();
+ Environment outer_env = getEnvironment();
+ String qname = outer_env.toQualifiedName(classname);
+ if (outer_env.lookupClass(qname) != null)
+ return;
+ try {
+ OJClass out_clazz =
+ outer_env.lookupClass(outer_env.currentClassName());
+ /***** this will be recorded in global env */
+ //OJClass clazz = OJClass.forParseTree(outer_env, out_clazz, ptree);
+ OJClass clazz = new OJClass(outer_env, out_clazz, ptree);
+ outer_env.record(classname, clazz);
+ } catch (Exception ex) {
+ System.err.println("unknown error: " + ex);
+ return;
+ }
+ }
+
+ /* class body contents */
+ public MemberDeclaration evaluateDown(MethodDeclaration ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public MemberDeclaration evaluateDown(ConstructorDeclaration ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public MemberDeclaration evaluateDown(MemberInitializer ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ /* statements */
+ public Statement evaluateDown(Block ptree) throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(SwitchStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(IfStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(WhileStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(DoWhileStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(ForStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(TryStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Statement evaluateDown(SynchronizedStatement ptree)
+ throws ParseTreeException {
+ pushClosedEnvironment();
+ return ptree;
+ }
+
+ public Expression evaluateDown(AllocationExpression ptree)
+ throws ParseTreeException {
+ MemberDeclarationList cbody = ptree.getClassBody();
+ if (cbody != null) {
+ String baseName = ptree.getClassType().toString();
+ push(
+ new AnonymousClassEnvironment(
+ getEnvironment(),
+ baseName,
+ cbody));
+ } else {
+ pushClosedEnvironment();
+ }
+ return ptree;
+ }
+
+ /* in walking down through parse tree */
+
+ /* class declaration */
+ public CompilationUnit evaluateUp(CompilationUnit ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ /* class declaration */
+ public ClassDeclaration evaluateUp(ClassDeclaration ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ /* class body contents */
+ public MemberDeclaration evaluateUp(MethodDeclaration ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public MemberDeclaration evaluateUp(ConstructorDeclaration ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public MemberDeclaration evaluateUp(MemberInitializer ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ /* statements */
+ public Statement evaluateUp(Block ptree) throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(SwitchStatement ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(IfStatement ptree) throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(WhileStatement ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(DoWhileStatement ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(ForStatement ptree) throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(TryStatement ptree) throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Statement evaluateUp(SynchronizedStatement ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+ public Expression evaluateUp(AllocationExpression ptree)
+ throws ParseTreeException {
+ pop();
+ return ptree;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/SourceCodeWriter.java b/src/main/java/io/devnulllabs/openjava/ptree/util/SourceCodeWriter.java
new file mode 100644
index 0000000..571045e
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/SourceCodeWriter.java
@@ -0,0 +1,1462 @@
+/*
+ * SourceCodeWriter.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Enumeration;
+
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayAccess;
+import io.devnulllabs.openjava.ptree.ArrayAllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayInitializer;
+import io.devnulllabs.openjava.ptree.AssignmentExpression;
+import io.devnulllabs.openjava.ptree.BinaryExpression;
+import io.devnulllabs.openjava.ptree.Block;
+import io.devnulllabs.openjava.ptree.BreakStatement;
+import io.devnulllabs.openjava.ptree.CaseGroup;
+import io.devnulllabs.openjava.ptree.CaseGroupList;
+import io.devnulllabs.openjava.ptree.CaseLabel;
+import io.devnulllabs.openjava.ptree.CaseLabelList;
+import io.devnulllabs.openjava.ptree.CastExpression;
+import io.devnulllabs.openjava.ptree.CatchBlock;
+import io.devnulllabs.openjava.ptree.CatchList;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassDeclarationList;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ConditionalExpression;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorInvocation;
+import io.devnulllabs.openjava.ptree.ContinueStatement;
+import io.devnulllabs.openjava.ptree.DoWhileStatement;
+import io.devnulllabs.openjava.ptree.EmptyStatement;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.ExpressionStatement;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.ForStatement;
+import io.devnulllabs.openjava.ptree.IfStatement;
+import io.devnulllabs.openjava.ptree.InstanceofExpression;
+import io.devnulllabs.openjava.ptree.LabeledStatement;
+import io.devnulllabs.openjava.ptree.Leaf;
+import io.devnulllabs.openjava.ptree.List;
+import io.devnulllabs.openjava.ptree.Literal;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.MemberInitializer;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.NonLeaf;
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.ReturnStatement;
+import io.devnulllabs.openjava.ptree.SelfAccess;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.SwitchStatement;
+import io.devnulllabs.openjava.ptree.SynchronizedStatement;
+import io.devnulllabs.openjava.ptree.ThrowStatement;
+import io.devnulllabs.openjava.ptree.TryStatement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.UnaryExpression;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.ptree.VariableDeclarator;
+import io.devnulllabs.openjava.ptree.VariableInitializer;
+import io.devnulllabs.openjava.ptree.WhileStatement;
+
+/**
+ * The class <code>SourceCodeWriter</code> is a Visitor role
+ * in the Visitor pattern and this also visits each child
+ * <code>ParseTree</code> object from left to right.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: SourceCodeWriter.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @see io.devnulllabs.openjava.ptree.util.ParseTreeVisitor
+ */
+public class SourceCodeWriter extends ParseTreeVisitor {
+
+ protected PrintWriter out;
+
+ /**
+ * Why this modifier is not final ?
+ * - Because of javac bug in excuting it with -O option.
+ */
+ public static String NEWLINE;
+ static {
+ StringWriter strw = new StringWriter();
+ PrintWriter pw = new PrintWriter(strw);
+ pw.println();
+ pw.close();
+ NEWLINE = strw.toString();
+ }
+
+ /** to write debugging code */
+ private int debugLevel = 0;
+
+ /** to write debugging code */
+ private String tab = " ";
+ private int nest = 0;
+
+ /** to write debugging code */
+ public void setDebugLevel(int n) {
+ debugLevel = n;
+ }
+ public int getDebugLevel() {
+ return debugLevel;
+ }
+ public void setTab(String str) {
+ tab = str;
+ }
+ public String getTab() {
+ return tab;
+ }
+ public void setNest(int i) {
+ nest = i;
+ }
+ public int getNest() {
+ return nest;
+ }
+ public void pushNest() {
+ setNest(getNest() + 1);
+ }
+ public void popNest() {
+ setNest(getNest() - 1);
+ }
+
+ private final void writeDebugL(ParseTree ptree) {
+ if (getDebugLevel() > 0) {
+ out.print("[");
+ if (debugLevel > 1) {
+ String qname = ptree.getClass().getName();
+ String sname = qname.substring(qname.lastIndexOf('.') + 1);
+ out.print(sname + "#");
+ if (debugLevel > 2) {
+ out.print(ptree.getObjectID());
+ }
+ out.print(" ");
+ }
+ }
+ }
+
+ private final void writeDebugR() {
+ if (getDebugLevel() > 0)
+ out.print("]");
+ }
+
+ private final void writeDebugLR() {
+ if (getDebugLevel() > 0)
+ out.print("[]");
+ }
+
+ private final void writeDebugLln() {
+ if (getDebugLevel() > 0)
+ out.println("[");
+ }
+
+ private final void writeDebugRln() {
+ if (getDebugLevel() > 0)
+ out.println("]");
+ }
+
+ private final void writeDebugln() {
+ if (getDebugLevel() > 0)
+ out.println();
+ }
+
+ private final void writeDebug(String str) {
+ if (getDebugLevel() > 0)
+ out.print(str);
+ }
+
+ private final void writeTab() {
+ for (int i = 0; i < nest; i++)
+ out.print(getTab());
+ }
+
+ /**
+ * Allocates a source code writer.
+ *
+ */
+ public SourceCodeWriter(PrintWriter out) {
+ super();
+ this.out = out;
+ }
+
+ public void visit(AllocationExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression encloser = p.getEncloser();
+ if (encloser != null) {
+ encloser.accept(this);
+ out.print(" . ");
+ }
+
+ out.print("new ");
+
+ TypeName tn = p.getClassType();
+ tn.accept(this);
+
+ ExpressionList args = p.getArguments();
+ writeArguments(args);
+
+ MemberDeclarationList mdlst = p.getClassBody();
+ if (mdlst != null) {
+ out.println("{");
+ pushNest();
+ mdlst.accept(this);
+ popNest();
+ writeTab();
+ out.print("}");
+ }
+
+ writeDebugR();
+ }
+
+ public void visit(ArrayAccess p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression expr = p.getReferenceExpr();
+ if (expr instanceof Leaf
+ || expr instanceof ArrayAccess
+ || expr instanceof FieldAccess
+ || expr instanceof MethodCall
+ || expr instanceof Variable) {
+ expr.accept(this);
+ } else {
+ writeParenthesis(expr);
+ }
+
+ Expression index_expr = p.getIndexExpr();
+ out.print("[");
+ index_expr.accept(this);
+ out.print("]");
+
+ writeDebugR();
+ }
+
+ public void visit(ArrayAllocationExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ out.print("new ");
+
+ TypeName tn = p.getTypeName();
+ tn.accept(this);
+
+ ExpressionList dl = p.getDimExprList();
+ for (int i = 0; i < dl.size(); ++i) {
+ Expression expr = dl.get(i);
+ out.print("[");
+ if (expr != null) {
+ expr.accept(this);
+ }
+ out.print("]");
+ }
+
+ ArrayInitializer ainit = p.getInitializer();
+ if (ainit != null)
+ ainit.accept(this);
+ writeDebugR();
+ }
+
+ public void visit(ArrayInitializer p) throws ParseTreeException {
+ writeDebugL(p);
+
+ out.print("{ ");
+ writeListWithDelimiter(p, ", ");
+ if (p.isRemainderOmitted())
+ out.print(",");
+ out.print(" }");
+
+ writeDebugR();
+ }
+
+ public void visit(AssignmentExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression lexpr = p.getLeft();
+ if (lexpr instanceof AssignmentExpression) {
+ writeParenthesis(lexpr);
+ } else {
+ lexpr.accept(this);
+ }
+
+ String operator = p.operatorString();
+ out.print(" " + operator + " ");
+
+ Expression rexp = p.getRight();
+ rexp.accept(this);
+
+ writeDebugR();
+ }
+
+ public void visit(BinaryExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression lexpr = p.getLeft();
+ if (isOperatorNeededLeftPar(p.getOperator(), lexpr)) {
+ writeParenthesis(lexpr);
+ } else {
+ lexpr.accept(this);
+ }
+
+ String operator = p.operatorString();
+ out.print(" " + operator + " ");
+
+ Expression rexpr = p.getRight();
+ if (isOperatorNeededRightPar(p.getOperator(), rexpr)) {
+ writeParenthesis(rexpr);
+ } else {
+ rexpr.accept(this);
+ }
+
+ writeDebugR();
+ }
+
+ public void visit(Block p) throws ParseTreeException {
+ StatementList stmts = p.getStatements();
+ writeTab();
+ writeDebugL(p);
+ writeStatementsBlock(stmts);
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(BreakStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("break");
+
+ String label = p.getLabel();
+ if (label != null) {
+ out.print(" ");
+ out.print(label);
+ }
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(CaseGroup p) throws ParseTreeException {
+ ExpressionList labels = p.getLabels();
+ for (int i = 0; i < labels.size(); ++i) {
+ writeTab();
+ Expression label = labels.get(i);
+ if (label == null) {
+ out.print("default ");
+ } else {
+ out.print("case ");
+ label.accept(this);
+ }
+ out.println(" :");
+ }
+
+ pushNest();
+ StatementList stmts = p.getStatements();
+ stmts.accept(this);
+ popNest();
+ }
+
+ public void visit(CaseGroupList p) throws ParseTreeException {
+ writeListWithSuffix(p, NEWLINE);
+ }
+
+ public void visit(CaseLabel p) throws ParseTreeException {
+ Expression expr = p.getExpression();
+ if (expr != null) {
+ out.print("case ");
+ expr.accept(this);
+ } else {
+ out.print("default");
+ }
+ out.print(":");
+ }
+
+ public void visit(CaseLabelList p) throws ParseTreeException {
+ writeListWithSuffix(p, NEWLINE);
+ }
+
+ public void visit(CastExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ out.print("(");
+ TypeName ts = p.getTypeSpecifier();
+ ts.accept(this);
+ out.print(")");
+
+ out.print(" ");
+
+ Expression expr = p.getExpression();
+ if (expr instanceof AssignmentExpression
+ || expr instanceof ConditionalExpression
+ || expr instanceof BinaryExpression
+ || expr instanceof InstanceofExpression
+ || expr instanceof UnaryExpression) {
+ writeParenthesis(expr);
+ } else {
+ expr.accept(this);
+ }
+
+ writeDebugR();
+ }
+
+ public void visit(CatchBlock p) throws ParseTreeException {
+ out.print(" catch ");
+
+ out.print("( ");
+
+ Parameter param = p.getParameter();
+ param.accept(this);
+
+ out.print(" ) ");
+
+ StatementList stmts = p.getBody();
+ writeStatementsBlock(stmts);
+ }
+
+ public void visit(CatchList p) throws ParseTreeException {
+ writeList(p);
+ }
+
+ public void visit(ClassDeclaration p) throws ParseTreeException {
+ printComment(p);
+
+ writeTab();
+ writeDebugL(p);
+
+ /*ModifierList*/
+ ModifierList modifs = p.getModifiers();
+ if (modifs != null) {
+ modifs.accept(this);
+ if (!modifs.isEmptyAsRegular())
+ out.print(" ");
+ }
+
+ /*"class"*/
+ if (p.isInterface()) {
+ out.print("interface ");
+ } else {
+ out.print("class ");
+ }
+
+ String name = p.getName();
+ out.print(name);
+
+ /*"extends" TypeName*/
+ TypeName[] zuper = p.getBaseclasses();
+ if (zuper.length != 0) {
+ out.print(" extends ");
+ zuper[0].accept(this);
+ for (int i = 1; i < zuper.length; ++i) {
+ out.print(", ");
+ zuper[i].accept(this);
+ }
+ } else {
+ writeDebug(" ");
+ writeDebugLR();
+ }
+
+ /* "implements" ClassTypeList */
+ TypeName[] impl = p.getInterfaces();
+ if (impl.length != 0) {
+ out.print(" implements ");
+ impl[0].accept(this);
+ for (int i = 1; i < impl.length; ++i) {
+ out.print(", ");
+ impl[i].accept(this);
+ }
+ } else {
+ writeDebug(" ");
+ writeDebugLR();
+ }
+
+ out.println();
+
+ /* MemberDeclarationList */
+ MemberDeclarationList classbody = p.getBody();
+ writeTab();
+ out.println("{");
+ if (classbody.isEmpty()) {
+ classbody.accept(this);
+ } else {
+ out.println();
+ pushNest();
+ classbody.accept(this);
+ popNest();
+ out.println();
+ }
+ writeTab();
+ out.print("}");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ClassDeclarationList p) throws ParseTreeException {
+ writeListWithDelimiter(p, NEWLINE + NEWLINE);
+ }
+
+ public void visit(ClassLiteral p) throws ParseTreeException {
+ writeDebugL(p);
+ TypeName type = p.getTypeName();
+ type.accept(this);
+ out.print(".class");
+ writeDebugR();
+ }
+
+ public void visit(CompilationUnit p) throws ParseTreeException {
+ out.println("/*");
+ out.println(" * This code was generated by ojc.");
+ out.println(" */");
+
+ printComment(p);
+
+ /* package statement */
+ String qn = p.getPackage();
+ if (qn != null) {
+ writeDebugL(p);
+ out.print("package " + qn + ";");
+ writeDebugR();
+ out.println();
+
+ out.println();
+ out.println();
+ }
+
+ /* import statement list */
+ String[] islst = p.getDeclaredImports();
+ if (islst.length != 0) {
+ for (int i = 0; i < islst.length; ++i) {
+ out.println("import " + islst[i] + ";");
+ }
+ out.println();
+ out.println();
+ }
+
+ /* type declaration list */
+ ClassDeclarationList tdlst = p.getClassDeclarations();
+ tdlst.accept(this);
+ }
+
+ public void visit(ConditionalExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression condition = p.getCondition();
+ if (condition instanceof AssignmentExpression
+ || condition instanceof ConditionalExpression) {
+ writeParenthesis(condition);
+ } else {
+ condition.accept(this);
+ }
+
+ out.print(" ? ");
+
+ Expression truecase = p.getTrueCase();
+ if (truecase instanceof AssignmentExpression) {
+ writeParenthesis(truecase);
+ } else {
+ truecase.accept(this);
+ }
+
+ out.print(" : ");
+
+ Expression falsecase = p.getFalseCase();
+ if (falsecase instanceof AssignmentExpression) {
+ writeParenthesis(falsecase);
+ } else {
+ falsecase.accept(this);
+ }
+
+ writeDebugR();
+ }
+
+ public void visit(ConstructorDeclaration p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ /*ModifierList*/
+ ModifierList modifs = p.getModifiers();
+ if (modifs != null) {
+ modifs.accept(this);
+ if (!modifs.isEmptyAsRegular())
+ out.print(" ");
+ }
+
+ String name = p.getName();
+ out.print(name);
+
+ ParameterList params = p.getParameters();
+ out.print("(");
+ if (params.size() != 0) {
+ out.print(" ");
+ params.accept(this);
+ out.print(" ");
+ }
+ out.print(")");
+
+ TypeName[] tnl = p.getThrows();
+ if (tnl.length != 0) {
+ out.println();
+ writeTab();
+ writeTab();
+ out.print("throws ");
+ tnl[0].accept(this);
+ for (int i = 1; i < tnl.length; ++i) {
+ out.print(", ");
+ tnl[i].accept(this);
+ }
+ }
+
+ ConstructorInvocation sc = p.getConstructorInvocation();
+ StatementList body = p.getBody();
+ if (body == null && sc == null) {
+ out.println(";");
+ } else {
+ out.println();
+
+ writeTab();
+ out.println("{");
+ pushNest();
+
+ if (sc != null)
+ sc.accept(this);
+ if (body != null)
+ body.accept(this);
+
+ popNest();
+ writeTab();
+ out.print("}");
+ }
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ConstructorInvocation p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ if (p.isSelfInvocation()) {
+ out.print("this");
+ } else {
+ Expression enclosing = p.getEnclosing();
+ if (enclosing != null) {
+ enclosing.accept(this);
+ out.print(" . ");
+ }
+ out.print("super");
+ }
+
+ ExpressionList exprs = p.getArguments();
+ writeArguments(exprs);
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ContinueStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("continue");
+
+ String label = p.getLabel();
+ if (label != null) {
+ out.print(" " + label);
+ }
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(DoWhileStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("do ");
+
+ StatementList stmts = p.getStatements();
+
+ if (stmts.isEmpty()) {
+ out.print(" ; ");
+ } else {
+ writeStatementsBlock(stmts);
+ }
+
+ out.print(" while ");
+
+ out.print("(");
+ Expression expr = p.getExpression();
+ expr.accept(this);
+ out.print(")");
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(EmptyStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ExpressionList p) throws ParseTreeException {
+ writeListWithDelimiter(p, ", ");
+ }
+
+ public void visit(ExpressionStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ Expression expr = p.getExpression();
+ expr.accept(this);
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(FieldAccess p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression expr = p.getReferenceExpr();
+ TypeName typename = p.getReferenceType();
+ if (expr != null) {
+ if (expr instanceof Leaf
+ || expr instanceof ArrayAccess
+ || expr instanceof FieldAccess
+ || expr instanceof MethodCall
+ || expr instanceof Variable) {
+ expr.accept(this);
+ } else {
+ out.print("(");
+ expr.accept(this);
+ out.print(")");
+ }
+ out.print(".");
+ } else if (typename != null) {
+ typename.accept(this);
+ out.print(".");
+ }
+
+ String name = p.getName();
+ out.print(name);
+
+ writeDebugR();
+ }
+
+ public void visit(FieldDeclaration p) throws ParseTreeException {
+ printComment(p);
+
+ writeTab();
+ writeDebugL(p);
+
+ /*ModifierList*/
+ ModifierList modifs = p.getModifiers();
+ if (modifs != null) {
+ modifs.accept(this);
+ if (!modifs.isEmptyAsRegular())
+ out.print(" ");
+ }
+
+ /*TypeName*/
+ TypeName ts = p.getTypeSpecifier();
+ ts.accept(this);
+
+ out.print(" ");
+
+ /*Variable*/
+ String variable = p.getVariable();
+ out.print(variable);
+
+ /*"=" VariableInitializer*/
+ VariableInitializer initializer = p.getInitializer();
+ if (initializer != null) {
+ out.print(" = ");
+ initializer.accept(this);
+ }
+ /*";"*/
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ForStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("for ");
+
+ out.print("(");
+
+ ExpressionList init = p.getInit();
+ TypeName tspec = p.getInitDeclType();
+ VariableDeclarator[] vdecls = p.getInitDecls();
+ if (init != null && (!init.isEmpty())) {
+ init.get(0).accept(this);
+ for (int i = 1; i < init.size(); ++i) {
+ out.print(", ");
+ init.get(i).accept(this);
+ }
+ } else if (tspec != null && vdecls != null && vdecls.length != 0) {
+ tspec.accept(this);
+ out.print(" ");
+ vdecls[0].accept(this);
+ for (int i = 1; i < vdecls.length; ++i) {
+ out.print(", ");
+ vdecls[i].accept(this);
+ }
+ }
+
+ out.print(";");
+
+ Expression expr = p.getCondition();
+ if (expr != null) {
+ out.print(" ");
+ expr.accept(this);
+ }
+
+ out.print(";");
+
+ ExpressionList incr = p.getIncrement();
+ if (incr != null && (!incr.isEmpty())) {
+ out.print(" ");
+ incr.get(0).accept(this);
+ for (int i = 1; i < incr.size(); ++i) {
+ out.print(", ");
+ incr.get(i).accept(this);
+ }
+ }
+
+ out.print(") ");
+
+ StatementList stmts = p.getStatements();
+ if (stmts.isEmpty()) {
+ out.print(";");
+ } else {
+ writeStatementsBlock(stmts);
+ }
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(IfStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("if ");
+
+ out.print("(");
+ Expression expr = p.getExpression();
+ expr.accept(this);
+ out.print(") ");
+
+ /* then part */
+ StatementList stmts = p.getStatements();
+ writeStatementsBlock(stmts);
+
+ /* else part */
+ StatementList elsestmts = p.getElseStatements();
+ if (!elsestmts.isEmpty()) {
+ out.print(" else ");
+ writeStatementsBlock(elsestmts);
+ }
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(InstanceofExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ /* this is too strict for + or - */
+ Expression lexpr = p.getExpression();
+ if (lexpr instanceof AssignmentExpression
+ || lexpr instanceof ConditionalExpression
+ || lexpr instanceof BinaryExpression) {
+ writeParenthesis(lexpr);
+ } else {
+ lexpr.accept(this);
+ }
+
+ out.print(" instanceof ");
+
+ TypeName tspec = p.getTypeSpecifier();
+ tspec.accept(this);
+
+ writeDebugR();
+ }
+
+ public void visit(LabeledStatement p) throws ParseTreeException {
+ writeTab();
+
+ String name = p.getLabel();
+ out.print(name);
+
+ out.println(" : ");
+
+ Statement statement = p.getStatement();
+ statement.accept(this);
+ }
+
+ public void visit(Literal p) throws ParseTreeException {
+ out.print(p.toString());
+ }
+
+ public void visit(MemberDeclarationList p) throws ParseTreeException {
+ writeListWithDelimiter(p, NEWLINE);
+ }
+
+ public void visit(MemberInitializer p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ if (p.isStatic()) {
+ out.print("static ");
+ }
+
+ StatementList stmts = p.getBody();
+ writeStatementsBlock(stmts);
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(MethodCall p) throws ParseTreeException {
+ writeDebugL(p);
+
+ Expression expr = p.getReferenceExpr();
+ TypeName reftype = p.getReferenceType();
+ if (expr != null) {
+ if (expr instanceof Leaf
+ || expr instanceof ArrayAccess
+ || expr instanceof FieldAccess
+ || expr instanceof MethodCall
+ || expr instanceof Variable) {
+ expr.accept(this);
+ } else {
+ writeParenthesis(expr);
+ }
+ out.print(".");
+ } else if (reftype != null) {
+ reftype.accept(this);
+ out.print(".");
+ }
+
+ String name = p.getName();
+ out.print(name);
+
+ ExpressionList args = p.getArguments();
+ writeArguments(args);
+
+ writeDebugR();
+ }
+
+ public void visit(MethodDeclaration p) throws ParseTreeException {
+ printComment(p);
+
+ writeTab();
+ writeDebugL(p);
+
+ /*ModifierList*/
+ ModifierList modifs = p.getModifiers();
+ if (modifs != null) {
+ modifs.accept(this);
+ if (!modifs.isEmptyAsRegular())
+ out.print(" ");
+ }
+
+ TypeName ts = p.getReturnType();
+ ts.accept(this);
+
+ out.print(" ");
+
+ String name = p.getName();
+ out.print(name);
+
+ ParameterList params = p.getParameters();
+ out.print("(");
+ if (!params.isEmpty()) {
+ out.print(" ");
+ params.accept(this);
+ out.print(" ");
+ } else {
+ params.accept(this);
+ }
+ out.print(")");
+
+ TypeName[] tnl = p.getThrows();
+ if (tnl.length != 0) {
+ out.println();
+ writeTab();
+ writeTab();
+ out.print("throws ");
+ tnl[0].accept(this);
+ for (int i = 1; i < tnl.length; ++i) {
+ out.print(", ");
+ tnl[i].accept(this);
+ }
+ }
+
+ StatementList bl = p.getBody();
+ if (bl == null) {
+ out.print(";");
+ } else {
+ out.println();
+ writeTab();
+ out.print("{");
+ if (bl.isEmpty()) {
+ bl.accept(this);
+ } else {
+ out.println();
+ pushNest();
+ bl.accept(this);
+ popNest();
+ writeTab();
+ }
+ out.print("}");
+ }
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ModifierList p) throws ParseTreeException {
+ writeDebugL(p);
+
+ out.print(ModifierList.toString(p.getRegular()));
+
+ writeDebugR();
+ }
+
+ public void visit(Parameter p) throws ParseTreeException {
+ writeDebugL(p);
+
+ ModifierList modifs = p.getModifiers();
+ modifs.accept(this);
+ if (!modifs.isEmptyAsRegular())
+ out.print(" ");
+
+ TypeName typespec = p.getTypeSpecifier();
+ typespec.accept(this);
+
+ out.print(" ");
+
+ String declname = p.getVariable();
+ out.print(declname);
+
+ writeDebugR();
+ }
+
+ public void visit(ParameterList p) throws ParseTreeException {
+ writeListWithDelimiter(p, ", ");
+ }
+
+ public void visit(ReturnStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("return");
+
+ Expression expr = p.getExpression();
+ if (expr != null) {
+ out.print(" ");
+ expr.accept(this);
+ }
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(SelfAccess p) throws ParseTreeException {
+ out.print(p.toString());
+ }
+
+ public void visit(StatementList p) throws ParseTreeException {
+ writeList(p);
+ }
+
+ public void visit(SwitchStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("switch ");
+ out.print("(");
+ Expression expr = p.getExpression();
+ expr.accept(this);
+ out.print(")");
+
+ out.println(" {");
+
+ CaseGroupList casegrouplist = p.getCaseGroupList();
+ casegrouplist.accept(this);
+
+ writeTab();
+ out.print("}");
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(SynchronizedStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("synchronized ");
+
+ out.print("(");
+ Expression expr = p.getExpression();
+ expr.accept(this);
+ out.println(")");
+
+ StatementList stmts = p.getStatements();
+ writeStatementsBlock(stmts);
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(ThrowStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("throw ");
+
+ Expression expr = p.getExpression();
+ expr.accept(this);
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(TryStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("try ");
+
+ StatementList stmts = p.getBody();
+ writeStatementsBlock(stmts);
+
+ CatchList catchlist = p.getCatchList();
+ if (!catchlist.isEmpty()) {
+ catchlist.accept(this);
+ }
+
+ StatementList finstmts = p.getFinallyBody();
+ if (!finstmts.isEmpty()) {
+ out.println(" finally ");
+ writeStatementsBlock(finstmts);
+ }
+
+ writeDebugR();
+ out.println();
+ }
+
+ /******rough around innerclass********/
+ public void visit(TypeName p) throws ParseTreeException {
+ writeDebugL(p);
+
+ String typename = p.getName().replace('$', '.');
+ out.print(typename);
+
+ int dims = p.getDimension();
+ out.print(TypeName.stringFromDimension(dims));
+
+ writeDebugR();
+ }
+
+ public void visit(UnaryExpression p) throws ParseTreeException {
+ writeDebugL(p);
+
+ if (p.isPrefix()) {
+ String operator = p.operatorString();
+ out.print(operator);
+ }
+
+ Expression expr = p.getExpression();
+ if (expr instanceof AssignmentExpression
+ || expr instanceof ConditionalExpression
+ || expr instanceof BinaryExpression
+ || expr instanceof InstanceofExpression
+ || expr instanceof CastExpression
+ || expr instanceof UnaryExpression) {
+ writeParenthesis(expr);
+ } else {
+ expr.accept(this);
+ }
+
+ if (p.isPostfix()) {
+ String operator = p.operatorString();
+ out.print(operator);
+ }
+
+ writeDebugR();
+ }
+
+ public void visit(Variable p) throws ParseTreeException {
+ out.print(p.toString());
+ }
+
+ public void visit(VariableDeclaration p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ ModifierList modifs = p.getModifiers();
+ modifs.accept(this);
+ if (!modifs.isEmptyAsRegular())
+ out.print(" ");
+
+ TypeName typespec = p.getTypeSpecifier();
+ typespec.accept(this);
+
+ out.print(" ");
+
+ VariableDeclarator vd = p.getVariableDeclarator();
+ vd.accept(this);
+
+ out.print(";");
+
+ writeDebugR();
+ out.println();
+ }
+
+ public void visit(VariableDeclarator p) throws ParseTreeException {
+ String declname = p.getVariable();
+ out.print(declname);
+ for (int i = 0; i < p.getDimension(); ++i) {
+ out.print("[]");
+ }
+
+ VariableInitializer varinit = p.getInitializer();
+ if (varinit != null) {
+ out.print(" = ");
+ varinit.accept(this);
+ }
+ }
+
+ public void visit(WhileStatement p) throws ParseTreeException {
+ writeTab();
+ writeDebugL(p);
+
+ out.print("while ");
+
+ out.print("(");
+ Expression expr = p.getExpression();
+ expr.accept(this);
+ out.print(") ");
+
+ StatementList stmts = p.getStatements();
+ if (stmts.isEmpty()) {
+ out.print(" ;");
+ } else {
+ writeStatementsBlock(stmts);
+ }
+
+ writeDebugR();
+ out.println();
+ }
+
+ private final void writeArguments(ExpressionList args)
+ throws ParseTreeException {
+ out.print("(");
+ if (!args.isEmpty()) {
+ out.print(" ");
+ args.accept(this);
+ out.print(" ");
+ } else {
+ args.accept(this);
+ }
+ out.print(")");
+ }
+
+ private final void writeAnonymous(Object obj) throws ParseTreeException {
+ if (obj == null) {
+ writeDebug("#null");
+ } else if (obj instanceof ParseTree) {
+ ((ParseTree) obj).accept(this);
+ } else {
+ out.print(obj.toString());
+ }
+ }
+
+ private final void writeList(List list) throws ParseTreeException {
+ Enumeration it = list.elements();
+
+ while (it.hasMoreElements()) {
+ Object elem = it.nextElement();
+ writeAnonymous(elem);
+ }
+ }
+
+ private final void writeListWithDelimiter(List list, String delimiter)
+ throws ParseTreeException {
+ Enumeration it = list.elements();
+
+ if (!it.hasMoreElements())
+ return;
+
+ writeAnonymous(it.nextElement());
+ while (it.hasMoreElements()) {
+ out.print(delimiter);
+ writeAnonymous(it.nextElement());
+ }
+ }
+
+ private final void writeListWithSuffix(List list, String suffix)
+ throws ParseTreeException {
+ Enumeration it = list.elements();
+
+ while (it.hasMoreElements()) {
+ writeAnonymous(it.nextElement());
+ out.print(suffix);
+ }
+ }
+
+ private final void writeParenthesis(Expression expr)
+ throws ParseTreeException {
+ out.print("(");
+ expr.accept(this);
+ out.print(")");
+ }
+
+ private final void writeStatementsBlock(StatementList stmts)
+ throws ParseTreeException {
+ out.println("{");
+ pushNest();
+
+ stmts.accept(this);
+
+ popNest();
+ writeTab();
+ out.print("}");
+ }
+
+ private static final boolean isOperatorNeededLeftPar(
+ int operator,
+ Expression leftexpr) {
+ if (leftexpr instanceof AssignmentExpression
+ || leftexpr instanceof ConditionalExpression) {
+ return true;
+ }
+
+ int op = operatorStrength(operator);
+
+ if (leftexpr instanceof InstanceofExpression) {
+ return (op > operatorStrength(BinaryExpression.INSTANCEOF));
+ }
+
+ if (!(leftexpr instanceof BinaryExpression))
+ return false;
+
+ BinaryExpression lbexpr = (BinaryExpression) leftexpr;
+ return (op > operatorStrength(lbexpr.getOperator()));
+ }
+
+ private static final boolean isOperatorNeededRightPar(
+ int operator,
+ Expression rightexpr) {
+ if (rightexpr instanceof AssignmentExpression
+ || rightexpr instanceof ConditionalExpression) {
+ return true;
+ }
+
+ int op = operatorStrength(operator);
+
+ if (rightexpr instanceof InstanceofExpression) {
+ return (op >= operatorStrength(BinaryExpression.INSTANCEOF));
+ }
+
+ if (!(rightexpr instanceof BinaryExpression))
+ return false;
+
+ BinaryExpression lbexpr = (BinaryExpression) rightexpr;
+ return (op >= operatorStrength(lbexpr.getOperator()));
+ }
+
+ /**
+ * Returns the strength of the union of the operator.
+ *
+ * @param op the id number of operator.
+ * @return the strength of the union.
+ */
+ private static final int operatorStrength(int op) {
+ switch (op) {
+ case BinaryExpression.TIMES :
+ case BinaryExpression.DIVIDE :
+ case BinaryExpression.MOD :
+ return 40;
+ case BinaryExpression.PLUS :
+ case BinaryExpression.MINUS :
+ return 35;
+ case BinaryExpression.SHIFT_L :
+ case BinaryExpression.SHIFT_R :
+ case BinaryExpression.SHIFT_RR :
+ return 30;
+ case BinaryExpression.LESS :
+ case BinaryExpression.GREATER :
+ case BinaryExpression.LESSEQUAL :
+ case BinaryExpression.GREATEREQUAL :
+ case BinaryExpression.INSTANCEOF :
+ return 25;
+ case BinaryExpression.EQUAL :
+ case BinaryExpression.NOTEQUAL :
+ return 20;
+ case BinaryExpression.BITAND :
+ return 16;
+ case BinaryExpression.XOR :
+ return 14;
+ case BinaryExpression.BITOR :
+ return 12;
+ case BinaryExpression.LOGICAL_AND :
+ return 10;
+ case BinaryExpression.LOGICAL_OR :
+ return 8;
+ }
+ return 100;
+ }
+
+ private final void printComment(NonLeaf p) {
+ String comment = p.getComment();
+ if (comment != null) {
+ writeTab();
+ out.println(comment);
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/TypeNameQualifier.java b/src/main/java/io/devnulllabs/openjava/ptree/util/TypeNameQualifier.java
new file mode 100644
index 0000000..19db286
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/TypeNameQualifier.java
@@ -0,0 +1,107 @@
+/*
+ * TypeNameQualifier.java
+ *
+ * Make typenames qualified.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+/**
+ * The class <code>TypeNameQualifier</code> is a utility class
+ * to be usede for making a copy of ptree work well without import
+ * statements.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TypeNameQualifier.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class TypeNameQualifier extends ScopeHandler {
+ private String newName = null;
+
+ /**
+ * Constructs a new visitor for parse tree for qualifying
+ * each type name appearing there.
+ *
+ * @param env environment for qualifying type names.
+ */
+ public TypeNameQualifier(Environment env) {
+ this(env, null);
+ }
+
+ /**
+ * Constructs a new visitor for parse tree for qualifying
+ * each type name appearing there.
+ *
+ * @param env environment for qualifying type names.
+ * @param newClassName the class name for constructors.
+ * If <code>null</code> is specified, the name for constructors
+ * will remain as is.
+ */
+ public TypeNameQualifier(Environment env, String newClassName) {
+ super(env);
+ this.newName = newClassName;
+ }
+
+ private String qualify(String org) {
+ return getEnvironment().toQualifiedName(org);
+ }
+
+ private TypeName qualifyName(TypeName name) {
+ return new TypeName(qualify(name.getName()), name.getDimension());
+ }
+
+ private TypeName[] qualifyNames(TypeName[] names) {
+ for (int i = 0; i < names.length; ++i) {
+ names[i] = qualifyName(names[i]);
+ }
+ return names;
+ }
+
+ public void visit(ClassDeclaration c)
+ throws io.devnulllabs.openjava.ptree.ParseTreeException {
+ c.setBaseclasses(qualifyNames(c.getBaseclasses()));
+ c.setInterfaces(qualifyNames(c.getInterfaces()));
+ super.visit(c);
+ }
+
+ public void visit(ConstructorDeclaration c)
+ throws io.devnulllabs.openjava.ptree.ParseTreeException {
+ if (newName != null)
+ c.setName(newName);
+ c.setThrows(qualifyNames(c.getThrows()));
+ super.visit(c);
+ }
+
+ public void visit(MethodDeclaration m)
+ throws io.devnulllabs.openjava.ptree.ParseTreeException {
+ m.setThrows(qualifyNames(m.getThrows()));
+ super.visit(m);
+ }
+
+ public void visit(TypeName tname)
+ throws io.devnulllabs.openjava.ptree.ParseTreeException {
+ tname.setName(qualify(tname.getName()));
+ super.visit(tname);
+ }
+
+ /** This is needed because of a bug. */
+ public void visit(ClassLiteral clit)
+ throws io.devnulllabs.openjava.ptree.ParseTreeException {
+ clit.replace(new ClassLiteral(qualifyName(clit.getTypeName())));
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/util/VariableBinder.java b/src/main/java/io/devnulllabs/openjava/ptree/util/VariableBinder.java
new file mode 100644
index 0000000..05f03d7
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/util/VariableBinder.java
@@ -0,0 +1,115 @@
+/*
+ * VariableBinder.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.ptree.util;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJClassNotFoundException;
+import io.devnulllabs.openjava.ptree.ForStatement;
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.ptree.VariableDeclarator;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+/**
+ * The class <code>VariableBinder</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: VariableBinder.java,v 1.2 2003/02/19 02:55:00 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class VariableBinder extends ScopeHandler {
+
+ public VariableBinder(Environment env) {
+ super(env);
+ }
+
+ public Statement evaluateDown(VariableDeclaration ptree)
+ throws ParseTreeException {
+ super.evaluateDown(ptree);
+ bindLocalVariable(ptree, getEnvironment());
+
+ return ptree;
+ }
+
+ public Statement evaluateDown(ForStatement ptree)
+ throws ParseTreeException {
+ super.evaluateDown(ptree);
+ TypeName tspec = ptree.getInitDeclType();
+ if (tspec == null)
+ return ptree;
+ VariableDeclarator[] vdecls = ptree.getInitDecls();
+ bindForInit(tspec, vdecls, getEnvironment());
+
+ return ptree;
+ }
+
+ public Parameter evaluateDown(Parameter ptree) throws ParseTreeException {
+ super.evaluateDown(ptree);
+ bindParameter(ptree, getEnvironment());
+
+ return ptree;
+ }
+
+ private static void bindLocalVariable(
+ VariableDeclaration var_decl,
+ Environment env) {
+ String type = var_decl.getTypeSpecifier().toString();
+ String name = var_decl.getVariable();
+ bindName(env, type, name);
+ }
+
+ private static void bindForInit(
+ TypeName tspec,
+ VariableDeclarator[] vdecls,
+ Environment env) {
+ for (int i = 0; i < vdecls.length; ++i) {
+ String type = tspec.toString() + vdecls[i].dimensionString();
+ String name = vdecls[i].getVariable();
+ bindName(env, type, name);
+ }
+ }
+
+ private static void bindParameter(Parameter param, Environment env) {
+ String type = param.getTypeSpecifier().toString();
+ String name = param.getVariable();
+ bindName(env, type, name);
+ }
+
+ private static void bindName(Environment env, String type, String name) {
+ String qtypename = env.toQualifiedName(type);
+ try {
+ OJClass clazz = env.lookupClass(qtypename);
+ if (clazz == null)
+ clazz = OJClass.forName(qtypename);
+ env.bindVariable(name, clazz);
+ DebugOut.println("binds variable\t" + name + "\t: " + qtypename);
+ } catch (OJClassNotFoundException e) {
+ System.err.println(
+ "VariableBinder.bindName() "
+ + e.toString()
+ + " : "
+ + qtypename);
+ System.err.println(env);
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/AbstractSyntaxRule.java b/src/main/java/io/devnulllabs/openjava/syntax/AbstractSyntaxRule.java
new file mode 100644
index 0000000..33c6029
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/AbstractSyntaxRule.java
@@ -0,0 +1,80 @@
+/*
+ * AbstractSyntaxRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The interface <code>AbstractSyntaxRule</code> represents a syntax rule.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: AbstractSyntaxRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public abstract class AbstractSyntaxRule implements SyntaxRule
+{
+ /**
+ * Consumes tokens from the given token source following
+ * the rule. To be overridden.
+ *
+ * @param token_src token source to consume.
+ * @return a parse tree object consumed by following this rule.
+ */
+ public abstract ParseTree consume( TokenSource token_src )
+ throws SyntaxException;
+
+ /**
+ * Tests if the given token source follows this rule.
+ *
+ * @param token_src token source to consume.
+ * @return true if the given token source can be consumed safely.
+ */
+ public final boolean lookahead( TokenSource token_src ) {
+ try {
+ RestorableTokenSource dummy
+ = new RestorableTokenSource( token_src );
+ consume( dummy );
+ return true;
+ } catch (SyntaxException e) {
+ setSyntaxException( e );
+ return false;
+ }
+ }
+
+ private SyntaxException lastException = null;
+
+ /**
+ * Obtains the syntax exception at the last lookahead.
+ * through the method <tt>lookahead(TokenSource)</tt>.
+ *
+ * @return the syntax exception.
+ */
+ public final SyntaxException getSyntaxException() {
+ return lastException;
+ }
+
+ /**
+ * Sets the last syntax exception in consuming token source
+ * through the method <tt>consume(TokenSource)</tt>.
+ *
+ * @return the syntax exception.
+ */
+ private final void setSyntaxException( SyntaxException e ) {
+ lastException = e;
+ }
+
+}
+
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/BlockRule.java b/src/main/java/io/devnulllabs/openjava/syntax/BlockRule.java
new file mode 100644
index 0000000..f94b978
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/BlockRule.java
@@ -0,0 +1,52 @@
+/*
+ * BlockRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The class <code>BlockRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: BlockRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class BlockRule extends AbstractSyntaxRule
+{
+ private Environment env;
+
+ public BlockRule( Environment env ) {
+ this.env = env;
+ }
+
+ public BlockRule() {
+ this ( null );
+ }
+
+ public ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ ParseTree result = JavaSyntaxRules.consumeBlock( token_src, env );
+ if (result == null) throw JavaSyntaxRules.getLastException();
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/CompositeRule.java b/src/main/java/io/devnulllabs/openjava/syntax/CompositeRule.java
new file mode 100644
index 0000000..2f7c6a5
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/CompositeRule.java
@@ -0,0 +1,70 @@
+/*
+ * CompositeRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ObjectList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The class <code>CompositeRule</code> represents iterative syntax
+ * rule.
+ * <p>
+ * Suppose there's a syntax rules; A, B, C. This class can represents
+ * the syntax ( A B C ).
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: CompositeRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class CompositeRule extends AbstractSyntaxRule
+{
+ private SyntaxRule[] elementRules;
+
+ /**
+ * Allocates a new rule representing a composition of given rules.
+ *
+ * @param elementRules an array of rules
+ */
+ public CompositeRule( SyntaxRule[] elementRules ) {
+ this.elementRules = elementRules;
+ }
+
+ public CompositeRule( SyntaxRule e1, SyntaxRule e2 ) {
+ this( new SyntaxRule[] { e1, e2 } );
+ }
+
+ public CompositeRule( SyntaxRule e1, SyntaxRule e2, SyntaxRule e3 ) {
+ this( new SyntaxRule[] { e1, e2, e3 } );
+ }
+
+ /**
+ * Consumes token source.
+ *
+ * @param token_src token source.
+ * @return null if this fails to consume a syntax tree represented
+ * by this object. Otherwise it returns <code>ObjectList</code> object.
+ */
+ public ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ ObjectList result = new ObjectList();
+ for (int i = 0; i < elementRules.length; ++i) {
+ ParseTree elem = elementRules[i].consume( token_src );
+ result.add( elem );
+ }
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/DefaultListRule.java b/src/main/java/io/devnulllabs/openjava/syntax/DefaultListRule.java
new file mode 100644
index 0000000..ee1f577
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/DefaultListRule.java
@@ -0,0 +1,57 @@
+/*
+ * DefaultListRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ObjectList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The class <code>DefaultListRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: DefaultListRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class DefaultListRule extends SeparatedListRule
+{
+ private ObjectList list = null;
+
+ public DefaultListRule( SyntaxRule elementRule,
+ int separator_token, boolean allowsEmpty ) {
+ super( elementRule, separator_token, allowsEmpty );
+ }
+
+ public DefaultListRule( SyntaxRule elementRule, int separator_token ) {
+ this( elementRule, separator_token, false );
+ }
+
+ protected void initList() {
+ list = new ObjectList();
+ }
+
+ protected void addListElement( Object elem ) {
+ list.add( elem );
+ }
+
+ protected ParseTree getList() {
+ return list;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/ExpressionListRule.java b/src/main/java/io/devnulllabs/openjava/syntax/ExpressionListRule.java
new file mode 100644
index 0000000..0fd6351
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/ExpressionListRule.java
@@ -0,0 +1,66 @@
+/*
+ * ExpressionListRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The class <code>ExpressionListRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ExpressionListRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class ExpressionListRule extends SeparatedListRule
+{
+ private ExpressionList exprList = null;
+
+ public ExpressionListRule( ExpressionRule exprRule, boolean allowsEmpty ) {
+ super( exprRule, TokenID.COMMA, allowsEmpty );
+ }
+
+ public ExpressionListRule( ExpressionRule exprRule ) {
+ this( exprRule, false );
+ }
+
+ public ExpressionListRule( Environment env, boolean allowsEmpty ) {
+ this( new ExpressionRule( env ), allowsEmpty );
+ }
+
+ public ExpressionListRule( Environment env ) {
+ this( env, false );
+ }
+
+ protected void initList() {
+ exprList = new ExpressionList();
+ }
+
+ protected void addListElement( Object elem ) {
+ exprList.add( (Expression) elem );
+ }
+
+ protected ParseTree getList() {
+ return exprList;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/ExpressionRule.java b/src/main/java/io/devnulllabs/openjava/syntax/ExpressionRule.java
new file mode 100644
index 0000000..e6df0b8
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/ExpressionRule.java
@@ -0,0 +1,68 @@
+/*
+ * ExpressionRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The class <code>ExpressionRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: ExpressionRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class ExpressionRule extends AbstractSyntaxRule
+{
+ private Environment env;
+
+ public ExpressionRule( Environment env ) {
+ this.env = env;
+ }
+
+ public ExpressionRule() {
+ this( null );
+ }
+
+ public final ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ return this.consumeExpression( token_src );
+ }
+
+ /**
+ * Subclasses of this class can override this method to
+ * extend its returnable expressions.
+ *
+ * @param token_src token source
+ * @return expression
+ * @exception SyntaxException
+ */
+ public Expression consumeExpression( TokenSource token_src )
+ throws SyntaxException
+ {
+ Expression result
+ = JavaSyntaxRules.consumeExpression( token_src, env );
+ if (result == null) throw JavaSyntaxRules.getLastException();
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java b/src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java
new file mode 100644
index 0000000..facd82a
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java
@@ -0,0 +1,79 @@
+/*
+ * IdentifierRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+
+/**
+ * The class <code>IdentifierRule</code> represents syntax rule of
+ * Identifier.
+ * returns as <code>Variable</code>.
+ * <p>
+ * return
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: IdentifierRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class IdentifierRule extends AbstractSyntaxRule
+{
+
+ private String specifying;
+
+ /**
+ * For specified identifier.
+ *
+ * @param specifying a string value specifying the identifier
+ * to consume.
+ */
+ public IdentifierRule( String specifying ) {
+ this.specifying = specifying;
+ }
+
+ /**
+ * For any identifier.
+ *
+ */
+ public IdentifierRule() {
+ this( null );
+ }
+
+ public final ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ return consumeIdentifier( token_src );
+ }
+
+ public Variable consumeIdentifier( TokenSource token_src )
+ throws SyntaxException
+ {
+ Token t = token_src.getNextToken();
+ if (t.kind != IDENTIFIER) {
+ /***** to become specified error report */
+ throw new SyntaxException( "needs Identifier" );
+ }
+ if (specifying != null && ! specifying.equals( t.image )) {
+ /***** to become specified error report */
+ throw new SyntaxException( "needs " + specifying );
+ }
+ return new Variable( t.image );
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/IterationRule.java b/src/main/java/io/devnulllabs/openjava/syntax/IterationRule.java
new file mode 100644
index 0000000..5c7f75f
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/IterationRule.java
@@ -0,0 +1,78 @@
+/*
+ * IterationRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ObjectList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+
+/**
+ * The class <code>IterationRule</code> represents iterative syntax
+ * rule.
+ * <p>
+ * Suppose there's a syntax rule A. This class can represents
+ * the syntax ( A )* or ( A )+
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: IterationRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class IterationRule extends AbstractSyntaxRule
+{
+ private SyntaxRule elementRule;
+ private boolean allowsEmpty;
+
+ /**
+ * Allocates a new rule representing iterations of a given rule.
+ *
+ * @param elementRule a rule to iterate
+ * @param allowsEmpty a flag to allow 0 iteration if it is true.
+ */
+ public IterationRule( SyntaxRule elementRule, boolean allowsEmpty ) {
+ this.elementRule = elementRule;
+ this.allowsEmpty = allowsEmpty;
+ }
+
+ /**
+ * Allocates a new rule representing iterations of a given rule
+ * not allowing 0 iteration.
+ *
+ * @param elementRule a rule to iterate
+ */
+ public IterationRule( SyntaxRule elementRule ) {
+ this( elementRule, false );
+ }
+
+ /**
+ * Consumes token source.
+ *
+ * @param token_src token source.
+ * @return null if this fails to consume a syntax tree represented
+ * by this object. Otherwise it returns <code>ObjectList</code> object.
+ */
+ public ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ ObjectList result = new ObjectList();
+ if (! allowsEmpty) {
+ result.add( elementRule.consume( token_src ) );
+ }
+ while (elementRule.lookahead( token_src )) {
+ ParseTree elem = elementRule.consume( token_src );
+ result.add( elem );
+ }
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/JavaSyntaxRules.java b/src/main/java/io/devnulllabs/openjava/syntax/JavaSyntaxRules.java
new file mode 100644
index 0000000..76d38dc
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/JavaSyntaxRules.java
@@ -0,0 +1,170 @@
+/*
+ * JavaSyntaxRules.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.Block;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ObjectList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.util.MemberAccessCorrector;
+import io.devnulllabs.openjava.tools.parser.ParseException;
+import io.devnulllabs.openjava.tools.parser.Parser;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+
+/**
+ * The class <code>JavaSyntaxRules</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: JavaSyntaxRules.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class JavaSyntaxRules implements TokenID
+{
+ private JavaSyntaxRules() {}
+
+ private static ParseException lastException = null;
+ public static SyntaxException getLastException() {
+ return new SyntaxException( lastException );
+ }
+
+ private static ParseTree correct( ParseTree ptree, Environment env ) {
+ MemberAccessCorrector corrector
+ = new MemberAccessCorrector( env );
+ ObjectList holder = new ObjectList( ptree );
+ try {
+ ptree.accept( corrector );
+ } catch ( ParseTreeException e ) {
+ System.err.println( e.getMessage() );
+ }
+ return (ParseTree) holder.get( 0 );
+ }
+
+ private static void
+ adjustTokenSource( TokenSource token_src, Token last_token ) {
+ Token token = token_src.getToken( 0 );
+ while (token != last_token) {
+ token = token_src.getNextToken();
+ }
+ return;
+ }
+
+ /**
+ * Consumes a single expression from given token source.
+ *
+ * @param token_src token source
+ * @param env environment
+ * @return null if this fail, otherwise an expression.
+ */
+ public static final Expression
+ consumeExpression( TokenSource token_src, Environment env ) {
+ if (env == null) env = token_src.getEnvironment();
+ RestorableTokenSource dummy = new RestorableTokenSource( token_src );
+ Parser parser = new Parser( dummy );
+ try {
+ Expression ptree = parser.Expression( env );
+ adjustTokenSource( token_src, parser.getToken( 0 ) );
+ return (Expression) correct( ptree, env );
+ } catch ( ParseException e ) {
+ lastException = e;
+ return null;
+ }
+ }
+ public static final Expression
+ consumeExpression( TokenSource token_src ) {
+ return consumeExpression( token_src, null );
+ }
+
+ /**
+ * Consumes a statement.
+ * This consumes only a pure statement excluding local variable
+ * declarations and local class declarations.
+ *
+ * @param token_src token source
+ * @return null if this fail, otherwise a statement.
+ */
+ public static final Statement
+ consumeStatement( TokenSource token_src, Environment env ) {
+ if (env == null) env = token_src.getEnvironment();
+ RestorableTokenSource dummy = new RestorableTokenSource( token_src );
+ Parser parser = new Parser( dummy );
+ try {
+ Statement ptree = parser.Statement( env );
+ adjustTokenSource( token_src, parser.getToken( 0 ) );
+ return (Statement) correct( ptree, env );
+ } catch ( ParseException e ) {
+ lastException = e;
+ return null;
+ }
+ }
+ public static final Statement consumeStatement( TokenSource token_src ) {
+ return consumeStatement( token_src, token_src.getEnvironment() );
+ }
+
+ /**
+ * Consumes a block.
+ *
+ * @param token_src token source
+ * @return null if this fail, otherwise a block.
+ */
+ public static final Block
+ consumeBlock( TokenSource token_src, Environment env ) {
+ if (env == null) env = token_src.getEnvironment();
+ RestorableTokenSource dummy = new RestorableTokenSource( token_src );
+ Parser parser = new Parser( dummy );
+ try {
+ Block ptree = parser.Block( env );
+ adjustTokenSource( token_src, parser.getToken( 0 ) );
+ return (Block) correct( ptree, env );
+ } catch ( ParseException e ) {
+ lastException = e;
+ return null;
+ }
+ }
+ public static final Block consumeBlock( TokenSource token_src ) {
+ return consumeBlock( token_src, token_src.getEnvironment() );
+ }
+
+ /**
+ * Consumes a type name.
+ * Including primitive type and reference type.
+ *
+ * @param token_src token source
+ * @return null if this fail, otherwise a block.
+ */
+ public static final TypeName
+ consumeTypeName( TokenSource token_src ) {
+ Environment env = token_src.getEnvironment();
+ RestorableTokenSource dummy = new RestorableTokenSource( token_src );
+ Parser parser = new Parser( dummy );
+ try {
+ TypeName ptree = parser.Type( env );
+ adjustTokenSource( token_src, parser.getToken( 0 ) );
+ return (TypeName) correct( ptree, env );
+ } catch ( ParseException e ) {
+ lastException = e;
+ return null;
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java b/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java
new file mode 100644
index 0000000..5d7ffd0
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java
@@ -0,0 +1,74 @@
+/*
+ * NameRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+
+/**
+ * The interface <code>NameRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: NameRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class NameRule extends AbstractSyntaxRule
+{
+ /**
+ * Consumes a dot-separated name like <tt>java.lang.String</tt>.
+ *
+ * @param token_src token source
+ * @return a dummy <code>Variable</code> object.
+ * @see io.devnulllabs.openjava.ptree.Variable
+ */
+ public final ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ return consumeQualifiedName( token_src );
+ }
+
+ /**
+ * To override for modifying rule.
+ */
+ public Variable consumeQualifiedName( TokenSource token_src )
+ throws SyntaxException
+ {
+ IdentifierRule rule = new IdentifierRule();
+ Variable ident = rule.consumeIdentifier( token_src );
+ StringBuffer buf = new StringBuffer( ident.toString() );
+ while (lookaheadRest( token_src )) {
+ buf.append( token_src.getNextToken().image ); /* DOT */
+ buf.append( token_src.getNextToken().image ); /* IDENTIFIER */
+ }
+ return new Variable( buf.toString() );
+ }
+
+ /**
+ * A hard-coded lookahead for performance reason.
+ * (. <IDENTIFIER>)
+ */
+ protected static final boolean lookaheadRest( TokenSource token_src ) {
+ Token t1 = token_src.getToken( 1 );
+ Token t2 = token_src.getToken( 2 );
+ return (t1.kind == DOT && t2.kind == IDENTIFIER);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/PrepPhraseRule.java b/src/main/java/io/devnulllabs/openjava/syntax/PrepPhraseRule.java
new file mode 100644
index 0000000..d2289fb
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/PrepPhraseRule.java
@@ -0,0 +1,51 @@
+/*
+ * PrepPhraseRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+/**
+ * The class <code>PrepPhraseRule</code> represents the syntax rule
+ * of a prepositional phrase.
+ * Suppose there's a syntax rule <code>A</code> and a given identifier
+ * <code>i</code>. This class can represent the syntax:
+ * <pre>
+ * PrepPhraseRule := i A
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: PrepPhraseRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class PrepPhraseRule extends AbstractSyntaxRule {
+
+ private String prep;
+ private SyntaxRule words;
+
+ /**
+ * Allocates a new rule representing the syntax of a prepositional
+ * phrase consisting of a preposition and a syntax.
+ */
+ public PrepPhraseRule(String prep, SyntaxRule words) {
+ this.prep = prep;
+ this.words = words;
+ }
+
+ public ParseTree consume(TokenSource token_src) throws SyntaxException {
+ IdentifierRule ident = new IdentifierRule(prep);
+ ident.consume(token_src);
+ return words.consume(token_src);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/RestorableTokenSource.java b/src/main/java/io/devnulllabs/openjava/syntax/RestorableTokenSource.java
new file mode 100644
index 0000000..d82c5af
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/RestorableTokenSource.java
@@ -0,0 +1,70 @@
+/*
+ * RestorableTokenSource.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+/**
+ * The class <code>RestorableTokenSource</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: RestorableTokenSource.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class RestorableTokenSource implements TokenSource {
+ private TokenSource tokenSource;
+ private Environment env;
+ private int pointer = 0;
+ private int offset = 0;
+
+ public RestorableTokenSource(TokenSource src, Environment env) {
+ this.tokenSource = src;
+ this.env = env;
+ }
+
+ public RestorableTokenSource(TokenSource src) {
+ this(src, null);
+ }
+
+ public Environment getEnvironment() {
+ return ((env == null) ? tokenSource.getEnvironment() : env);
+ }
+
+ public void assume() {
+ offset = pointer;
+ }
+ public void restore() {
+ pointer = offset;
+ }
+ public void fix() {
+ for (int i = offset; i < pointer; ++i) {
+ tokenSource.getNextToken();
+ }
+ pointer = 0;
+ offset = 0;
+ }
+ public Token getNextToken() {
+ return tokenSource.getToken(++pointer);
+ }
+
+ public Token getToken(int i) {
+ return tokenSource.getToken(pointer + i);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java b/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java
new file mode 100644
index 0000000..763560d
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java
@@ -0,0 +1,61 @@
+/*
+ * SelectionRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+/**
+ * The class <code>SelectionRule</code> represents selective syntax
+ * rule.
+ * <p>
+ * Suppose there're several syntax rules; A, B, C. This class
+ * can represents the syntax ( A | B | C ).
+ * If both A and B are adaptable to token source, A is choosed since
+ * A is specified at lefter part than B's part.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: SelectionRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class SelectionRule extends AbstractSyntaxRule {
+ protected SyntaxRule[] elementRules;
+
+ /**
+ * Allocates a new rule representing a selection of given rules.
+ *
+ * @param elementRules an array of rules
+ */
+ public SelectionRule(SyntaxRule[] elementRules) {
+ this.elementRules = elementRules;
+ }
+
+ public SelectionRule(SyntaxRule e1, SyntaxRule e2) {
+ this(new SyntaxRule[] { e1, e2 });
+ }
+
+ public SelectionRule(SyntaxRule e1, SyntaxRule e2, SyntaxRule e3) {
+ this(new SyntaxRule[] { e1, e2, e3 });
+ }
+
+ public ParseTree consume(TokenSource token_src) throws SyntaxException {
+ for (int i = 0; i < elementRules.length; ++i) {
+ if (elementRules[i].lookahead(token_src)) {
+ ParseTree result = elementRules[i].consume(token_src);
+ return result;
+ }
+ }
+ /***** to become specifed error report */
+ throw new SyntaxException("neither of selection");
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/SeparatedListRule.java b/src/main/java/io/devnulllabs/openjava/syntax/SeparatedListRule.java
new file mode 100644
index 0000000..3ff5cc9
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/SeparatedListRule.java
@@ -0,0 +1,98 @@
+/*
+ * SeparatedListRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+/**
+ * The class <code>SeparatedListRule</code> represents the syntax
+ * rule of a list separated by an separator.
+ * <p>
+ * Suppose there's a syntax rule A and token t. This class can
+ * represents the syntax A ( t A )*.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: SeparatedListRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public abstract class SeparatedListRule extends AbstractSyntaxRule {
+ private SyntaxRule elementRule;
+ private int separator;
+ private boolean allowsEmpty;
+
+ protected abstract void initList();
+ protected abstract void addListElement(Object elem);
+ protected abstract ParseTree getList();
+
+ /**
+ * Allocates a new rule representing a list of a give rule
+ * separeted by a given separator.
+ *
+ * @param elementRule a rule of each element of the list
+ * @param separator_token the id of a token to be separator
+ * @param allowEmpty a flag to allow 0 iteration if it is true.
+ * @see io.devnulllabs.openjava.syntax.TokenID
+ */
+ public SeparatedListRule(
+ SyntaxRule elementRule,
+ int separator_token,
+ boolean allowsEmpty) {
+ this.elementRule = elementRule;
+ this.separator = separator_token;
+ this.allowsEmpty = allowsEmpty;
+ }
+
+ /**
+ * Allocates a new rule representing a list of a give rule
+ * separeted by a given separator.
+ *
+ * @param elementRule a rule of each element of the list
+ * @param separator_token the id of a token to be separator
+ * @see io.devnulllabs.openjava.syntax.TokenID
+ */
+ public SeparatedListRule(SyntaxRule elementRule, int separator_token) {
+ this(elementRule, separator_token, false);
+ }
+
+ /**
+ * Consumes token source.
+ *
+ * @param token_src token source.
+ * @return null if this fails to consume a syntax tree represented
+ * by this object. Otherwise it returns <code>ObjectList</code> object.
+ */
+ public final ParseTree consume(TokenSource token_src)
+ throws SyntaxException {
+ initList();
+ ParseTree elem;
+ if (!allowsEmpty) {
+ elem = elementRule.consume(token_src);
+ addListElement(elem);
+ }
+ CompositeRule spy =
+ new CompositeRule(new TokenRule(separator), elementRule);
+ while (spy.lookahead(token_src)) {
+ elem = consumeSepAndElem(token_src);
+ addListElement(elem);
+ }
+ return getList();
+ }
+
+ private ParseTree consumeSepAndElem(TokenSource token_src)
+ throws SyntaxException {
+ token_src.getNextToken(); /* separator */
+ return elementRule.consume(token_src);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/StatementRule.java b/src/main/java/io/devnulllabs/openjava/syntax/StatementRule.java
new file mode 100644
index 0000000..1207451
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/StatementRule.java
@@ -0,0 +1,55 @@
+/*
+ * StatementRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.Statement;
+
+/**
+ * The class <code>StatementRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: StatementRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class StatementRule extends AbstractSyntaxRule {
+ private Environment env;
+
+ public StatementRule(Environment env) {
+ this.env = env;
+ }
+
+ public StatementRule() {
+ this(null);
+ }
+
+ public final ParseTree consume(TokenSource token_src)
+ throws SyntaxException {
+ return consumeStatement(token_src);
+ }
+
+ public Statement consumeStatement(TokenSource token_src)
+ throws SyntaxException {
+ Statement result = JavaSyntaxRules.consumeStatement(token_src, env);
+ if (result == null)
+ throw JavaSyntaxRules.getLastException();
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/SyntaxException.java b/src/main/java/io/devnulllabs/openjava/syntax/SyntaxException.java
new file mode 100644
index 0000000..1dcf8b4
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/SyntaxException.java
@@ -0,0 +1,49 @@
+/*
+ * SyntaxException.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.tools.parser.ParseException;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+/**
+ * The class <code>SyntaxException</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: SyntaxException.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class SyntaxException extends ParseException {
+ public SyntaxException(ParseException e) {
+ super(e.currentToken, e.expectedTokenSequences, e.tokenImage);
+ }
+
+ public SyntaxException(
+ Token currentToken,
+ int[][] expectedToken,
+ String[] tokenImage) {
+ super(currentToken, expectedToken, tokenImage);
+ }
+
+ public SyntaxException() {
+ super();
+ }
+
+ public SyntaxException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/SyntaxRule.java b/src/main/java/io/devnulllabs/openjava/syntax/SyntaxRule.java
new file mode 100644
index 0000000..9d767bc
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/SyntaxRule.java
@@ -0,0 +1,52 @@
+/*
+ * SyntaxRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+/**
+ * The interface <code>SyntaxRule</code> represents a syntax rule.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: SyntaxRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public interface SyntaxRule extends TokenID {
+ /**
+ * Consumes tokens from the given token source following
+ * the rule.
+ *
+ * @param token_src token source to consume.
+ * @return null in case of fail to consume, otherwise a parse tree
+ * object consumed following this rule.
+ * @exception SyntaxException in case to fail to consume.
+ */
+ public ParseTree consume(TokenSource token_src) throws SyntaxException;
+
+ /**
+ * Tests if the given token source follows this rule.
+ *
+ * @param token_src token source to consume.
+ * @return true if the given token source can be consumed safely.
+ */
+ public boolean lookahead(TokenSource token_src);
+
+ /**
+ * Returns the last syntax exception in consuming token source
+ * through the method <tt>consume(TokenSource)</tt>.
+ *
+ * @return the syntax exception.
+ */
+ public SyntaxException getSyntaxException();
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/TokenID.java b/src/main/java/io/devnulllabs/openjava/syntax/TokenID.java
new file mode 100644
index 0000000..16de922
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/TokenID.java
@@ -0,0 +1,143 @@
+/*
+ * TokenID.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.tools.parser.TokenIDPublisher;
+
+/**
+ * The class <code>TokenID</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TokenID.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public interface TokenID {
+
+ public static final int EOF = TokenIDPublisher.EOF;
+
+ public static final int ABSTRACT = TokenIDPublisher.ABSTRACT;
+ public static final int BOOLEAN = TokenIDPublisher.BOOLEAN;
+ public static final int BREAK = TokenIDPublisher.BREAK;
+ public static final int BYTE = TokenIDPublisher.BYTE;
+ public static final int CASE = TokenIDPublisher.CASE;
+ public static final int CATCH = TokenIDPublisher.CATCH;
+ public static final int CHAR = TokenIDPublisher.CHAR;
+ public static final int CLASS = TokenIDPublisher.CLASS;
+ public static final int CONTINUE = TokenIDPublisher.CONTINUE;
+ public static final int DEFAULT = TokenIDPublisher.DEFAULT;
+ public static final int DO = TokenIDPublisher.DO;
+ public static final int DOUBLE = TokenIDPublisher.DOUBLE;
+ public static final int ELSE = TokenIDPublisher.ELSE;
+ public static final int EXTENDS = TokenIDPublisher.EXTENDS;
+ public static final int FALSE = TokenIDPublisher.FALSE;
+ public static final int FINAL = TokenIDPublisher.FINAL;
+ public static final int FINALLY = TokenIDPublisher.FINALLY;
+ public static final int FLOAT = TokenIDPublisher.FLOAT;
+ public static final int FOR = TokenIDPublisher.FOR;
+ public static final int IF = TokenIDPublisher.IF;
+ public static final int IMPLEMENTS = TokenIDPublisher.IMPLEMENTS;
+ public static final int IMPORT = TokenIDPublisher.IMPORT;
+ public static final int INSTANCEOF = TokenIDPublisher.INSTANCEOF;
+ public static final int INT = TokenIDPublisher.INT;
+ public static final int INTERFACE = TokenIDPublisher.INTERFACE;
+ public static final int LONG = TokenIDPublisher.LONG;
+ public static final int NATIVE = TokenIDPublisher.NATIVE;
+ public static final int NEW = TokenIDPublisher.NEW;
+ public static final int NULL = TokenIDPublisher.NULL;
+ public static final int PACKAGE = TokenIDPublisher.PACKAGE;
+ public static final int PRIVATE = TokenIDPublisher.PRIVATE;
+ public static final int PROTECTED = TokenIDPublisher.PROTECTED;
+ public static final int PUBLIC = TokenIDPublisher.PUBLIC;
+ public static final int RETURN = TokenIDPublisher.RETURN;
+ public static final int SHORT = TokenIDPublisher.SHORT;
+ public static final int STATIC = TokenIDPublisher.STATIC;
+ public static final int SUPER = TokenIDPublisher.SUPER;
+ public static final int SWITCH = TokenIDPublisher.SWITCH;
+ public static final int SYNCHRONIZED = TokenIDPublisher.SYNCHRONIZED;
+ public static final int THIS = TokenIDPublisher.THIS;
+ public static final int THROW = TokenIDPublisher.THROW;
+ public static final int THROWS = TokenIDPublisher.THROWS;
+ public static final int TRANSIENT = TokenIDPublisher.TRANSIENT;
+ public static final int TRUE = TokenIDPublisher.TRUE;
+ public static final int TRY = TokenIDPublisher.TRY;
+ public static final int VOID = TokenIDPublisher.VOID;
+ public static final int VOLATILE = TokenIDPublisher.VOLATILE;
+ public static final int WHILE = TokenIDPublisher.WHILE;
+ public static final int METACLASS = TokenIDPublisher.METACLASS;
+ public static final int INSTANTIATES = TokenIDPublisher.INSTANTIATES;
+
+ public static final int INTEGER_LITERAL = TokenIDPublisher.INTEGER_LITERAL;
+ public static final int LONG_LITERAL = TokenIDPublisher.LONG_LITERAL;
+ public static final int DOUBLE_LITERAL = TokenIDPublisher.DOUBLE_LITERAL;
+ public static final int FLOAT_LITERAL = TokenIDPublisher.FLOAT_LITERAL;
+ public static final int CHARACTER_LITERAL =
+ TokenIDPublisher.CHARACTER_LITERAL;
+ public static final int STRING_LITERAL = TokenIDPublisher.STRING_LITERAL;
+
+ public static final int IDENTIFIER = TokenIDPublisher.IDENTIFIER;
+
+ public static final int LPAREN = TokenIDPublisher.LPAREN;
+ public static final int RPAREN = TokenIDPublisher.RPAREN;
+ public static final int LBRACE = TokenIDPublisher.LBRACE;
+ public static final int RBRACE = TokenIDPublisher.RBRACE;
+ public static final int LBRACKET = TokenIDPublisher.LBRACKET;
+ public static final int RBRACKET = TokenIDPublisher.RBRACKET;
+ public static final int SEMICOLON = TokenIDPublisher.SEMICOLON;
+ public static final int COMMA = TokenIDPublisher.COMMA;
+ public static final int DOT = TokenIDPublisher.DOT;
+ public static final int ASSIGN = TokenIDPublisher.ASSIGN;
+ public static final int GREATER = TokenIDPublisher.GREATER;
+ public static final int LESS = TokenIDPublisher.LESS;
+ public static final int BANG = TokenIDPublisher.BANG;
+ public static final int TILDE = TokenIDPublisher.TILDE;
+ public static final int HOOK = TokenIDPublisher.HOOK;
+ public static final int COLON = TokenIDPublisher.COLON;
+ public static final int EQUAL = TokenIDPublisher.EQUAL;
+ public static final int LESS_EQUAL = TokenIDPublisher.LESS_EQUAL;
+ public static final int GREATER_EQUAL = TokenIDPublisher.GREATER_EQUAL;
+ public static final int NOT_EQUAL = TokenIDPublisher.NOT_EQUAL;
+ public static final int CONDITIONAL_OR = TokenIDPublisher.CONDITIONAL_OR;
+ public static final int CONDITIONAL_AND = TokenIDPublisher.CONDITIONAL_AND;
+ public static final int INCREMENT = TokenIDPublisher.INCREMENT;
+ public static final int DECREMENT = TokenIDPublisher.DECREMENT;
+ public static final int PLUS = TokenIDPublisher.PLUS;
+ public static final int MINUS = TokenIDPublisher.MINUS;
+ public static final int STAR = TokenIDPublisher.STAR;
+ public static final int SLASH = TokenIDPublisher.SLASH;
+ public static final int BIT_AND = TokenIDPublisher.BIT_AND;
+ public static final int BIT_OR = TokenIDPublisher.BIT_OR;
+ public static final int XOR = TokenIDPublisher.XOR;
+ public static final int REM = TokenIDPublisher.REM;
+ public static final int LSHIFT = TokenIDPublisher.LSHIFT;
+ public static final int RSIGNEDSHIFT = TokenIDPublisher.RSIGNEDSHIFT;
+ public static final int RUNSIGNEDSHIFT = TokenIDPublisher.RUNSIGNEDSHIFT;
+ public static final int PLUSASSIGN = TokenIDPublisher.PLUSASSIGN;
+ public static final int MINUSASSIGN = TokenIDPublisher.MINUSASSIGN;
+ public static final int STARASSIGN = TokenIDPublisher.STARASSIGN;
+ public static final int SLASHASSIGN = TokenIDPublisher.SLASHASSIGN;
+ public static final int ANDASSIGN = TokenIDPublisher.ANDASSIGN;
+ public static final int ORASSIGN = TokenIDPublisher.ORASSIGN;
+ public static final int XORASSIGN = TokenIDPublisher.XORASSIGN;
+ public static final int REMASSIGN = TokenIDPublisher.REMASSIGN;
+ public static final int LSHIFTASSIGN = TokenIDPublisher.LSHIFTASSIGN;
+ public static final int RSIGNEDSHIFTASSIGN =
+ TokenIDPublisher.RSIGNEDSHIFTASSIGN;
+ public static final int RUNSIGNEDSHIFTASSIGN =
+ TokenIDPublisher.RUNSIGNEDSHIFTASSIGN;
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java b/src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java
new file mode 100644
index 0000000..a55d3dc
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/TokenRule.java
@@ -0,0 +1,61 @@
+/*
+ * TokenRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.ptree.Leaf;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+/**
+ * The class <code>TokenRule</code> represents the syntax
+ * rule of a list separated by an separator.
+ * <p>
+ * Suppose there's a syntax rule A and token t. This class can
+ * represents the syntax A ( t A )*.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TokenRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class TokenRule extends AbstractSyntaxRule {
+ private int tokenID;
+
+ /**
+ * Allocates a new rule representing a specified token.
+ *
+ * @param separator_token the id of a token.
+ * @see io.devnulllabs.openjava.syntax.TokenID
+ */
+ public TokenRule(int token_id) {
+ this.tokenID = token_id;
+ }
+
+ /**
+ * Consumes token source.
+ *
+ * @param token_src token source.
+ * @return null if this fails to consume a syntax tree represented
+ * by this object. Otherwise it returns <code>ObjectList</code> object.
+ */
+ public final ParseTree consume(TokenSource token_src)
+ throws SyntaxException {
+ Token t = token_src.getNextToken();
+ if (t.kind != tokenID) {
+ /***** to become specifed error report */
+ throw new SyntaxException("un expected token");
+ }
+ return new Leaf(t.kind, t.image, t.beginLine, t.beginColumn);
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/TokenSource.java b/src/main/java/io/devnulllabs/openjava/syntax/TokenSource.java
new file mode 100644
index 0000000..1e1a777
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/TokenSource.java
@@ -0,0 +1,35 @@
+/*
+ * TokenSource.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+/**
+ * The class <code>TokenSource</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TokenSource.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public interface TokenSource {
+ public Environment getEnvironment();
+ public Token getNextToken();
+ public Token getToken(int i);
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/TypeNameRule.java b/src/main/java/io/devnulllabs/openjava/syntax/TypeNameRule.java
new file mode 100644
index 0000000..fd73be9
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/TypeNameRule.java
@@ -0,0 +1,47 @@
+/*
+ * TypeNameRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+/**
+ * The class <code>TypeNameRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TypeNameRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class TypeNameRule extends AbstractSyntaxRule {
+ public final ParseTree consume(TokenSource token_src)
+ throws SyntaxException {
+ return consumeTypeName(token_src);
+ }
+
+ public TypeName consumeTypeName(TokenSource token_src)
+ throws SyntaxException {
+ TypeName result = JavaSyntaxRules.consumeTypeName(token_src);
+ if (result == null)
+ throw JavaSyntaxRules.getLastException();
+ Environment env = token_src.getEnvironment();
+ result.setName(env.toQualifiedName(result.getName()));
+ return result;
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/DebugOut.java b/src/main/java/io/devnulllabs/openjava/tools/DebugOut.java
new file mode 100644
index 0000000..8b29a45
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/DebugOut.java
@@ -0,0 +1,167 @@
+/*
+ * DebugOut.java 1.0
+ *
+ * This class manages imported classes with statement
+ * "import foo.Bar;" and "import foo.*;".
+ *
+ * Apr 7, 1998
+ *
+ * @version 1.0 last updated: Apr 7, 1998
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.tools;
+
+
+import java.io.PrintStream;
+
+
+/**
+ * The DebugOut class is used to print something in debugging.
+ * No instance should be allocate and this class should be used statically.
+ *
+ * <p>This class implements most methods of public printing methods
+ * found in java.io.PrintWriter, as static methods.
+ *
+ * @version 1.0a1, 98/04/10
+ * @author Michiaki Tatsubori
+ * @since JDK1.1
+ * @see io.devnulllabs.openjava.ptree.NonLeaf
+ */
+public final class DebugOut
+{
+ private static int debugLevel = 0;
+
+ public static void setDebugLevel( int level ) {
+ debugLevel = level;
+ }
+
+ /**
+ * for debug
+ */
+ protected static PrintStream out = System.err;
+
+ /** Flush the stream. */
+ public static void flush() {
+ if (debugLevel > 2) out.flush();
+ }
+
+ /** Close the stream. */
+ public static void close() {
+ if (debugLevel > 2) out.close();
+ }
+
+ /**
+ * Flush the stream and check its error state. Errors are cumulative;
+ * once the stream encounters an error, this routine will return true on
+ * all successive calls.
+ *
+ * @return True if the print stream has encountered an error, either on
+ * the underlying output stream or during a format conversion.
+ */
+ public static boolean checkError() {
+ return out.checkError();
+ }
+
+ /* Methods that do not terminate lines */
+
+ /** Print a boolean. */
+ public static void print( boolean b ) {
+ if (debugLevel > 2) out.print( b );
+ }
+
+ /** Print a character. */
+ public static void print( char c ) {
+ if (debugLevel > 2) out.print( c );
+ }
+
+ /** Print an integer. */
+ public static void print( int i ) {
+ if (debugLevel > 2) out.print( i );
+ }
+
+ /** Print a long. */
+ public static void print( long l ) {
+ if (debugLevel > 2) out.print( l );
+ }
+
+ /** Print a float. */
+ public static void print( float f ) {
+ if (debugLevel > 2) out.print( f );
+ }
+
+ /** Print a double. */
+ public static void print( double d ) {
+ if (debugLevel > 2) out.print( d );
+ }
+
+ /** Print an array of chracters. */
+ public static void print( char s[] ) {
+ if (debugLevel > 2) out.print( s );
+ }
+
+ /** Print a String. */
+ public static void print( String s ) {
+ if (debugLevel > 2) out.print( s );
+ }
+
+ /** Print an object. */
+ public static void print( Object obj ) {
+ if (debugLevel > 2) out.print( obj );
+ }
+
+ /* Methods that do terminate lines */
+
+ /** Finish the line. */
+ public static void println() {
+ if (debugLevel > 2) out.println();
+ }
+
+ /** Print a boolean, and then finish the line. */
+ public static void println( boolean x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print a character, and then finish the line. */
+ public static void println( char x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print an integer, and then finish the line. */
+ public static void println( int x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print a long, and then finish the line. */
+ public static void println( long x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print a float, and then finish the line. */
+ public static void println( float x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print a double, and then finish the line. */
+ public static void println( double x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print an array of characters, and then finish the line. */
+ public static void println( char x[] ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print a String, and then finish the line. */
+ public static void println( String x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+ /** Print an Object, and then finish the line. */
+ public static void println( Object x ) {
+ if (debugLevel > 2) out.println( x );
+ }
+
+}
+
+
+
diff --git a/src/main/java/io/devnulllabs/openjava/tools/WriterStack.java b/src/main/java/io/devnulllabs/openjava/tools/WriterStack.java
new file mode 100644
index 0000000..a3d86d7
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/WriterStack.java
@@ -0,0 +1,138 @@
+/***
+ * WriterStack.java 1.0
+ * this is a stack for Writer.
+ * wrapper class of java.util.Stack
+ *
+ * @see java.io.Writer
+ * @see java.util.Stack
+ * @version last updated: 06/11/97
+ * @author Michiaki Tatsubori
+ ***/
+/* package */
+package io.devnulllabs.openjava.tools;
+
+
+/* import */
+import java.io.BufferedWriter;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.EmptyStackException;
+import java.util.Stack;
+
+
+/**
+ * Wrapper class of class Stack to specialize into Writer.
+ **/
+public class WriterStack
+{
+ private Stack stack = null;
+ private static PrintWriter defaultWriter
+ = new PrintWriter(
+ new BufferedWriter(
+ new OutputStreamWriter( System.out ) ) );
+
+ /**
+ * Constructs this stack with an element(standard output).
+ **/
+ public WriterStack() {
+ stack = new Stack();
+ stack.push( defaultWriter );
+ }
+
+ /**
+ * Constructs this stack with the specified print writer.
+ **/
+ public WriterStack( PrintWriter writer ) {
+ stack = new Stack();
+ stack.push( writer );
+ }
+
+ /**
+ * Constructs this stack with the specified writer.
+ **/
+ public WriterStack( Writer writer ) {
+ stack = new Stack();
+ stack.push( new PrintWriter( writer ) );
+ }
+
+ /**
+ * Constructs this stack with the specified output stream.
+ **/
+ public WriterStack( OutputStream out ) {
+ stack = new Stack();
+ stack.push( new PrintWriter( new OutputStreamWriter( out ) ) );
+ }
+
+ /**
+ * Looks at the print writer at the top of this stack
+ * without removing it from the stack.
+ *
+ * @return the print writer at the top of this stack.
+ **/
+ public PrintWriter peek() {
+ try{
+ return (PrintWriter)stack.peek();
+ }catch( EmptyStackException ex ){
+ System.err.println( ex );
+ return defaultWriter;
+ }
+ }
+
+ /**
+ * Removes the print writer at the top of this stack and
+ * returns that print writer as the value of this function.
+ *
+ * @return The object at the top of this stack.
+ **/
+ public PrintWriter pop() {
+ try{
+ return (PrintWriter)stack.pop();
+ }catch( EmptyStackException ex ){
+ System.err.println( ex );
+ return defaultWriter;
+ }
+ }
+
+ /**
+ * Pushes a print writer onto the top of this stack.
+ *
+ * @param writer the print writer to be pushed onto this stack.
+ * @return the item argument.
+ **/
+ public void push( PrintWriter writer ) {
+ stack.push( writer );
+ }
+
+ /**
+ * Pushes a print writer onto the top of this stack.
+ *
+ * @param writer the writer to be pushed onto this stack.
+ * @return the item argument.
+ **/
+ public void push( Writer writer ) {
+ stack.push( new PrintWriter( writer ) );
+ }
+
+ /**
+ * Pushes a print writer from the specified print stream
+ * onto the top of this stack.
+ *
+ * @param ostream the output stream to be pushed onto this stack.
+ * @return the item argument.
+ **/
+ public void push( OutputStream ostream ) {
+ stack.push( new PrintWriter( new OutputStreamWriter( ostream ) ) );
+ }
+
+ /**
+ * Tests if this stack is empty.
+ *
+ * @return true if this stack is empty; false otherwise.
+ **/
+ public boolean empty() {
+ return stack.empty();
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/ASCII_UCodeESC_CharStream.java b/src/main/java/io/devnulllabs/openjava/tools/parser/ASCII_UCodeESC_CharStream.java
new file mode 100644
index 0000000..5d5ab56
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/ASCII_UCodeESC_CharStream.java
@@ -0,0 +1,519 @@
+package io.devnulllabs.openjava.tools.parser;
+
+/**
+ * An implementation of interface CharStream, where the stream is assumed to
+ * contain only ASCII characters (with java-like unicode escape processing).
+ */
+
+public final class ASCII_UCodeESC_CharStream
+{
+ public static final boolean staticFlag = false;
+ static final int hexval(char c) throws java.io.IOException {
+ switch(c)
+ {
+ case '0' :
+ return 0;
+ case '1' :
+ return 1;
+ case '2' :
+ return 2;
+ case '3' :
+ return 3;
+ case '4' :
+ return 4;
+ case '5' :
+ return 5;
+ case '6' :
+ return 6;
+ case '7' :
+ return 7;
+ case '8' :
+ return 8;
+ case '9' :
+ return 9;
+
+ case 'a' :
+ case 'A' :
+ return 10;
+ case 'b' :
+ case 'B' :
+ return 11;
+ case 'c' :
+ case 'C' :
+ return 12;
+ case 'd' :
+ case 'D' :
+ return 13;
+ case 'e' :
+ case 'E' :
+ return 14;
+ case 'f' :
+ case 'F' :
+ return 15;
+ }
+
+ throw new java.io.IOException(); // Should never come here
+ }
+
+ public int bufpos = -1;
+ int bufsize;
+ int available;
+ int tokenBegin;
+ private int bufline[];
+ private int bufcolumn[];
+
+ private int column = 0;
+ private int line = 1;
+
+ private java.io.Reader inputStream;
+
+ private boolean prevCharIsCR = false;
+ private boolean prevCharIsLF = false;
+
+ private char[] nextCharBuf;
+ private char[] buffer;
+ private int maxNextCharInd = 0;
+ private int nextCharInd = -1;
+ private int inBuf = 0;
+
+ private final void ExpandBuff(boolean wrapAround)
+ {
+ char[] newbuffer = new char[bufsize + 2048];
+ int newbufline[] = new int[bufsize + 2048];
+ int newbufcolumn[] = new int[bufsize + 2048];
+
+ try
+ {
+ if (wrapAround)
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ System.arraycopy(buffer, 0, newbuffer,
+ bufsize - tokenBegin, bufpos);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
+ bufcolumn = newbufcolumn;
+
+ bufpos += (bufsize - tokenBegin);
+ }
+ else
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ bufcolumn = newbufcolumn;
+
+ bufpos -= tokenBegin;
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new Error(t.getMessage());
+ }
+
+ available = (bufsize += 2048);
+ tokenBegin = 0;
+ }
+
+ private final void FillBuff() throws java.io.IOException
+ {
+ int i;
+ if (maxNextCharInd == 4096)
+ maxNextCharInd = nextCharInd = 0;
+
+ try {
+ if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
+ 4096 - maxNextCharInd)) == -1)
+ {
+ inputStream.close();
+ throw new java.io.IOException();
+ }
+ else
+ maxNextCharInd += i;
+ return;
+ }
+ catch(java.io.IOException e) {
+ if (bufpos != 0)
+ {
+ --bufpos;
+ backup(0);
+ }
+ else
+ {
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+ throw e;
+ }
+ }
+
+ private final char ReadByte() throws java.io.IOException
+ {
+ if (++nextCharInd >= maxNextCharInd)
+ FillBuff();
+
+ return nextCharBuf[nextCharInd];
+ }
+
+ public final char BeginToken() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+ return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
+ : ++bufpos];
+ }
+
+ tokenBegin = 0;
+ bufpos = -1;
+
+ return readChar();
+ }
+
+ private final void AdjustBuffSize()
+ {
+ if (available == bufsize)
+ {
+ if (tokenBegin > 2048)
+ {
+ bufpos = 0;
+ available = tokenBegin;
+ }
+ else
+ ExpandBuff(false);
+ }
+ else if (available > tokenBegin)
+ available = bufsize;
+ else if ((tokenBegin - available) < 2048)
+ ExpandBuff(true);
+ else
+ available = tokenBegin;
+ }
+
+ private final void UpdateLineColumn(char c)
+ {
+ column++;
+
+ if (prevCharIsLF)
+ {
+ prevCharIsLF = false;
+ line += (column = 1);
+ }
+ else if (prevCharIsCR)
+ {
+ prevCharIsCR = false;
+ if (c == '\n')
+ {
+ prevCharIsLF = true;
+ }
+ else
+ line += (column = 1);
+ }
+
+ switch (c)
+ {
+ case '\r' :
+ prevCharIsCR = true;
+ break;
+ case '\n' :
+ prevCharIsLF = true;
+ break;
+ case '\t' :
+ column--;
+ column += (8 - (column & 07));
+ break;
+ default :
+ break;
+ }
+
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+
+ public final char readChar() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+ return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
+ }
+
+ char c;
+
+ if (++bufpos == available)
+ AdjustBuffSize();
+
+ if (((buffer[bufpos] = c = (char)((char)0xff & ReadByte())) == '\\'))
+ {
+ UpdateLineColumn(c);
+
+ int backSlashCnt = 1;
+
+ for (;;) // Read all the backslashes
+ {
+ if (++bufpos == available)
+ AdjustBuffSize();
+
+ try
+ {
+ if ((buffer[bufpos] = c = (char)((char)0xff & ReadByte())) != '\\')
+ {
+ UpdateLineColumn(c);
+ // found a non-backslash char.
+ if ((c == 'u') && ((backSlashCnt & 1) == 1))
+ {
+ if (--bufpos < 0)
+ bufpos = bufsize - 1;
+
+ break;
+ }
+
+ backup(backSlashCnt);
+ return '\\';
+ }
+ }
+ catch(java.io.IOException e)
+ {
+ if (backSlashCnt > 1)
+ backup(backSlashCnt);
+
+ return '\\';
+ }
+
+ UpdateLineColumn(c);
+ backSlashCnt++;
+ }
+
+ // Here, we have seen an odd number of backslash's followed by a 'u'
+ try
+ {
+ while ((c = (char)((char)0xff & ReadByte())) == 'u')
+ ++column;
+
+ buffer[bufpos] = c = (char)(hexval(c) << 12 |
+ hexval((char)((char)0xff & ReadByte())) << 8 |
+ hexval((char)((char)0xff & ReadByte())) << 4 |
+ hexval((char)((char)0xff & ReadByte())));
+
+ column += 4;
+ }
+ catch(java.io.IOException e)
+ {
+ throw new Error("Invalid escape character at line " + line +
+ " column " + column + ".");
+ }
+
+ if (backSlashCnt == 1)
+ return c;
+ else
+ {
+ backup(backSlashCnt - 1);
+ return '\\';
+ }
+ }
+ else
+ {
+ UpdateLineColumn(c);
+ return (c);
+ }
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndColumn
+ */
+
+ public final int getColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndLine
+ */
+
+ public final int getLine() {
+ return bufline[bufpos];
+ }
+
+ public final int getEndColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ public final int getEndLine() {
+ return bufline[bufpos];
+ }
+
+ public final int getBeginColumn() {
+ return bufcolumn[tokenBegin];
+ }
+
+ public final int getBeginLine() {
+ return bufline[tokenBegin];
+ }
+
+ public final void backup(int amount) {
+
+ inBuf += amount;
+ if ((bufpos -= amount) < 0)
+ bufpos += bufsize;
+ }
+
+ public ASCII_UCodeESC_CharStream(java.io.Reader dstream,
+ int startline, int startcolumn, int buffersize)
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+
+ public ASCII_UCodeESC_CharStream(java.io.Reader dstream,
+ int startline, int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.Reader dstream,
+ int startline, int startcolumn, int buffersize)
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ if (buffer == null || buffersize != buffer.length)
+ {
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+ prevCharIsLF = prevCharIsCR = false;
+ tokenBegin = inBuf = maxNextCharInd = 0;
+ nextCharInd = bufpos = -1;
+ }
+
+ public void ReInit(java.io.Reader dstream,
+ int startline, int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+ public ASCII_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+
+ public ASCII_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+
+ public final String GetImage()
+ {
+ if (bufpos >= tokenBegin)
+ return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
+ else
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+ new String(buffer, 0, bufpos + 1);
+ }
+
+ public final char[] GetSuffix(int len)
+ {
+ char[] ret = new char[len];
+
+ if ((bufpos + 1) >= len)
+ System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
+ else
+ {
+ System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
+ len - bufpos - 1);
+ System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
+ }
+
+ return ret;
+ }
+
+ public void Done()
+ {
+ nextCharBuf = null;
+ buffer = null;
+ bufline = null;
+ bufcolumn = null;
+ }
+
+ /**
+ * Method to adjust line and column numbers for the start of a token.<BR>
+ */
+ public void adjustBeginLineColumn(int newLine, int newCol)
+ {
+ int start = tokenBegin;
+ int len;
+
+ if (bufpos >= tokenBegin)
+ {
+ len = bufpos - tokenBegin + inBuf + 1;
+ }
+ else
+ {
+ len = bufsize - tokenBegin + bufpos + 1 + inBuf;
+ }
+
+ int i = 0, j = 0, k = 0;
+ int nextColDiff = 0, columnDiff = 0;
+
+ while (i < len &&
+ bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
+ {
+ bufline[j] = newLine;
+ nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
+ bufcolumn[j] = newCol + columnDiff;
+ columnDiff = nextColDiff;
+ i++;
+ }
+
+ if (i < len)
+ {
+ bufline[j] = newLine++;
+ bufcolumn[j] = newCol + columnDiff;
+
+ while (i++ < len)
+ {
+ if (bufline[j = start % bufsize] != bufline[++start % bufsize])
+ bufline[j] = newLine++;
+ else
+ bufline[j] = newLine;
+ }
+ }
+
+ line = bufline[j];
+ column = bufcolumn[j];
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/CustomTokenManager.java b/src/main/java/io/devnulllabs/openjava/tools/parser/CustomTokenManager.java
new file mode 100644
index 0000000..08967d9
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/CustomTokenManager.java
@@ -0,0 +1,68 @@
+/*
+ * CustomTokenManager.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.tools.parser;
+
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.syntax.TokenSource;
+
+
+/**
+ * The class <code>CustomTokenManager</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: CustomTokenManager.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class CustomTokenManager
+ extends ParserTokenManager
+ implements TokenSource
+{
+ private Parser parser;
+ private Environment env;
+
+ int pointer = 0;
+ int offset = 0;
+
+ public CustomTokenManager( Parser parser, Environment env ) {
+ super( null );
+ this.parser = parser;
+ this.env = env;
+ }
+
+ public Environment getEnvironment() {
+ return env;
+ }
+
+ public void assume() { offset = pointer; }
+ public void restore() { pointer = offset; }
+ public void fix() {
+ for (int i = offset; i < pointer; ++i) {
+ parser.getNextToken();
+ }
+ pointer = 0; offset = 0;
+ }
+ public Token getNextToken() {
+ return parser.getToken( ++pointer );
+ }
+
+ public Token getToken( int i ) {
+ return parser.getToken( pointer + i );
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/JavaCharStream.java b/src/main/java/io/devnulllabs/openjava/tools/parser/JavaCharStream.java
new file mode 100644
index 0000000..4f15719
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/JavaCharStream.java
@@ -0,0 +1,546 @@
+package io.devnulllabs.openjava.tools.parser;
+
+/**
+ * An implementation of interface CharStream, where the stream is assumed to
+ * contain only ASCII characters (with java-like unicode escape processing).
+ */
+
+public final class JavaCharStream
+{
+ public static final boolean staticFlag = false;
+ static final int hexval(char c) throws java.io.IOException {
+ switch(c)
+ {
+ case '0' :
+ return 0;
+ case '1' :
+ return 1;
+ case '2' :
+ return 2;
+ case '3' :
+ return 3;
+ case '4' :
+ return 4;
+ case '5' :
+ return 5;
+ case '6' :
+ return 6;
+ case '7' :
+ return 7;
+ case '8' :
+ return 8;
+ case '9' :
+ return 9;
+
+ case 'a' :
+ case 'A' :
+ return 10;
+ case 'b' :
+ case 'B' :
+ return 11;
+ case 'c' :
+ case 'C' :
+ return 12;
+ case 'd' :
+ case 'D' :
+ return 13;
+ case 'e' :
+ case 'E' :
+ return 14;
+ case 'f' :
+ case 'F' :
+ return 15;
+ }
+
+ throw new java.io.IOException(); // Should never come here
+ }
+
+ public int bufpos = -1;
+ int bufsize;
+ int available;
+ int tokenBegin;
+ private int bufline[];
+ private int bufcolumn[];
+
+ private int column = 0;
+ private int line = 1;
+
+ private boolean prevCharIsCR = false;
+ private boolean prevCharIsLF = false;
+
+ private java.io.Reader inputStream;
+
+ private char[] nextCharBuf;
+ private char[] buffer;
+ private int maxNextCharInd = 0;
+ private int nextCharInd = -1;
+ private int inBuf = 0;
+
+ private final void ExpandBuff(boolean wrapAround)
+ {
+ char[] newbuffer = new char[bufsize + 2048];
+ int newbufline[] = new int[bufsize + 2048];
+ int newbufcolumn[] = new int[bufsize + 2048];
+
+ try
+ {
+ if (wrapAround)
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ System.arraycopy(buffer, 0, newbuffer,
+ bufsize - tokenBegin, bufpos);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
+ bufcolumn = newbufcolumn;
+
+ bufpos += (bufsize - tokenBegin);
+ }
+ else
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ bufcolumn = newbufcolumn;
+
+ bufpos -= tokenBegin;
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new Error(t.getMessage());
+ }
+
+ available = (bufsize += 2048);
+ tokenBegin = 0;
+ }
+
+ private final void FillBuff() throws java.io.IOException
+ {
+ int i;
+ if (maxNextCharInd == 4096)
+ maxNextCharInd = nextCharInd = 0;
+
+ try {
+ if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
+ 4096 - maxNextCharInd)) == -1)
+ {
+ inputStream.close();
+ throw new java.io.IOException();
+ }
+ else
+ maxNextCharInd += i;
+ return;
+ }
+ catch(java.io.IOException e) {
+ if (bufpos != 0)
+ {
+ --bufpos;
+ backup(0);
+ }
+ else
+ {
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+ throw e;
+ }
+ }
+
+ private final char ReadByte() throws java.io.IOException
+ {
+ if (++nextCharInd >= maxNextCharInd)
+ FillBuff();
+
+ return nextCharBuf[nextCharInd];
+ }
+
+ public final char BeginToken() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+
+ if (++bufpos == bufsize)
+ bufpos = 0;
+
+ tokenBegin = bufpos;
+ return buffer[bufpos];
+ }
+
+ tokenBegin = 0;
+ bufpos = -1;
+
+ return readChar();
+ }
+
+ private final void AdjustBuffSize()
+ {
+ if (available == bufsize)
+ {
+ if (tokenBegin > 2048)
+ {
+ bufpos = 0;
+ available = tokenBegin;
+ }
+ else
+ ExpandBuff(false);
+ }
+ else if (available > tokenBegin)
+ available = bufsize;
+ else if ((tokenBegin - available) < 2048)
+ ExpandBuff(true);
+ else
+ available = tokenBegin;
+ }
+
+ private final void UpdateLineColumn(char c)
+ {
+ column++;
+
+ if (prevCharIsLF)
+ {
+ prevCharIsLF = false;
+ line += (column = 1);
+ }
+ else if (prevCharIsCR)
+ {
+ prevCharIsCR = false;
+ if (c == '\n')
+ {
+ prevCharIsLF = true;
+ }
+ else
+ line += (column = 1);
+ }
+
+ switch (c)
+ {
+ case '\r' :
+ prevCharIsCR = true;
+ break;
+ case '\n' :
+ prevCharIsLF = true;
+ break;
+ case '\t' :
+ column--;
+ column += (8 - (column & 07));
+ break;
+ default :
+ break;
+ }
+
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+
+ public final char readChar() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+
+ if (++bufpos == bufsize)
+ bufpos = 0;
+
+ return buffer[bufpos];
+ }
+
+ char c;
+
+ if (++bufpos == available)
+ AdjustBuffSize();
+
+ if ((buffer[bufpos] = c = ReadByte()) == '\\')
+ {
+ UpdateLineColumn(c);
+
+ int backSlashCnt = 1;
+
+ for (;;) // Read all the backslashes
+ {
+ if (++bufpos == available)
+ AdjustBuffSize();
+
+ try
+ {
+ if ((buffer[bufpos] = c = ReadByte()) != '\\')
+ {
+ UpdateLineColumn(c);
+ // found a non-backslash char.
+ if ((c == 'u') && ((backSlashCnt & 1) == 1))
+ {
+ if (--bufpos < 0)
+ bufpos = bufsize - 1;
+
+ break;
+ }
+
+ backup(backSlashCnt);
+ return '\\';
+ }
+ }
+ catch(java.io.IOException e)
+ {
+ if (backSlashCnt > 1)
+ backup(backSlashCnt);
+
+ return '\\';
+ }
+
+ UpdateLineColumn(c);
+ backSlashCnt++;
+ }
+
+ // Here, we have seen an odd number of backslash's followed by a 'u'
+ try
+ {
+ while ((c = ReadByte()) == 'u')
+ ++column;
+
+ buffer[bufpos] = c = (char)(hexval(c) << 12 |
+ hexval(ReadByte()) << 8 |
+ hexval(ReadByte()) << 4 |
+ hexval(ReadByte()));
+
+ column += 4;
+ }
+ catch(java.io.IOException e)
+ {
+ throw new Error("Invalid escape character at line " + line +
+ " column " + column + ".");
+ }
+
+ if (backSlashCnt == 1)
+ return c;
+ else
+ {
+ backup(backSlashCnt - 1);
+ return '\\';
+ }
+ }
+ else
+ {
+ UpdateLineColumn(c);
+ return (c);
+ }
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndColumn
+ */
+
+ public final int getColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndLine
+ */
+
+ public final int getLine() {
+ return bufline[bufpos];
+ }
+
+ public final int getEndColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ public final int getEndLine() {
+ return bufline[bufpos];
+ }
+
+ public final int getBeginColumn() {
+ return bufcolumn[tokenBegin];
+ }
+
+ public final int getBeginLine() {
+ return bufline[tokenBegin];
+ }
+
+ public final void backup(int amount) {
+
+ inBuf += amount;
+ if ((bufpos -= amount) < 0)
+ bufpos += bufsize;
+ }
+
+ public JavaCharStream(java.io.Reader dstream,
+ int startline, int startcolumn, int buffersize)
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+
+ public JavaCharStream(java.io.Reader dstream,
+ int startline, int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.Reader dstream)
+ {
+ this(dstream, 1, 1, 4096);
+ }
+ public void ReInit(java.io.Reader dstream,
+ int startline, int startcolumn, int buffersize)
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ if (buffer == null || buffersize != buffer.length)
+ {
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+ prevCharIsLF = prevCharIsCR = false;
+ tokenBegin = inBuf = maxNextCharInd = 0;
+ nextCharInd = bufpos = -1;
+ }
+
+ public void ReInit(java.io.Reader dstream,
+ int startline, int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+
+ public void ReInit(java.io.Reader dstream)
+ {
+ ReInit(dstream, 1, 1, 4096);
+ }
+ public JavaCharStream(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream)
+ {
+ this(dstream, 1, 1, 4096);
+ }
+
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream)
+ {
+ ReInit(dstream, 1, 1, 4096);
+ }
+
+ public final String GetImage()
+ {
+ if (bufpos >= tokenBegin)
+ return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
+ else
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+ new String(buffer, 0, bufpos + 1);
+ }
+
+ public final char[] GetSuffix(int len)
+ {
+ char[] ret = new char[len];
+
+ if ((bufpos + 1) >= len)
+ System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
+ else
+ {
+ System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
+ len - bufpos - 1);
+ System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
+ }
+
+ return ret;
+ }
+
+ public void Done()
+ {
+ nextCharBuf = null;
+ buffer = null;
+ bufline = null;
+ bufcolumn = null;
+ }
+
+ /**
+ * Method to adjust line and column numbers for the start of a token.<BR>
+ */
+ public void adjustBeginLineColumn(int newLine, int newCol)
+ {
+ int start = tokenBegin;
+ int len;
+
+ if (bufpos >= tokenBegin)
+ {
+ len = bufpos - tokenBegin + inBuf + 1;
+ }
+ else
+ {
+ len = bufsize - tokenBegin + bufpos + 1 + inBuf;
+ }
+
+ int i = 0, j = 0, k = 0;
+ int nextColDiff = 0, columnDiff = 0;
+
+ while (i < len &&
+ bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
+ {
+ bufline[j] = newLine;
+ nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
+ bufcolumn[j] = newCol + columnDiff;
+ columnDiff = nextColDiff;
+ i++;
+ }
+
+ if (i < len)
+ {
+ bufline[j] = newLine++;
+ bufcolumn[j] = newCol + columnDiff;
+
+ while (i++ < len)
+ {
+ if (bufline[j = start % bufsize] != bufline[++start % bufsize])
+ bufline[j] = newLine++;
+ else
+ bufline[j] = newLine;
+ }
+ }
+
+ line = bufline[j];
+ column = bufcolumn[j];
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/Makefile b/src/main/java/io/devnulllabs/openjava/tools/parser/Makefile
new file mode 100644
index 0000000..2b543aa
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/Makefile
@@ -0,0 +1,35 @@
+# Makefile
+# by Michiaki Tatsubori
+#
+#JJ_OPTION = -USER_TOKEN_MANAGER=true -BUILD_TOKEN_MANAGER=false
+#SCAN_OPTION = -BUILD_PARSER=false -BUILD_TOKEN_MANAGER=true
+JJ_OPTION := -BUILD_TOKEN_MANAGER=true
+
+PARSER_SRC := Parser.java ParserTokenManager.java \
+ ParseException.java CustomTokenManager.java \
+ TokenIDPublisher.java TokenSourceAdapter.java
+
+
+Parser: Parser.java
+
+
+#
+# WARNING:
+# A modification of patchParserTokenManager.pl may not be automatically
+# reflected. Modification of Parser.jj is also required in this case.
+#
+Parser.java: Parser.jj
+ javacc $(JJ_OPTION) $?
+ mv ParserTokenManager.java ParserTokenManager.java.org
+ ./patchParserTokenManager.pl < ParserTokenManager.java.org \
+ > ParserTokenManager.java\
+
+jjdoc: Parser.jj
+ jjdoc $?
+
+
+clean:
+ \rm -f *~ Parser.java ParserConstants.java \
+ ASCII_UCodeESC_CharStream.java \
+ Token.java TokenMgrError.java \
+ ParserTokenManager.java ParserTokenManager.java.org
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/ParseException.java b/src/main/java/io/devnulllabs/openjava/tools/parser/ParseException.java
new file mode 100644
index 0000000..2dd1580
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/ParseException.java
@@ -0,0 +1,192 @@
+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 2.1 */
+package io.devnulllabs.openjava.tools.parser;
+
+/**
+ * This exception is thrown when parse errors are encountered.
+ * You can explicitly create objects of this exception type by
+ * calling the method generateParseException in the generated
+ * parser.
+ *
+ * You can modify this class to customize your error reporting
+ * mechanisms so long as you retain the public fields.
+ */
+public class ParseException extends Exception {
+
+ /**
+ * This constructor is used by the method "generateParseException"
+ * in the generated parser. Calling this constructor generates
+ * a new object of this type with the fields "currentToken",
+ * "expectedTokenSequences", and "tokenImage" set. The boolean
+ * flag "specialConstructor" is also set to true to indicate that
+ * this constructor was used to create this object.
+ * This constructor calls its super class with the empty string
+ * to force the "toString" method of parent class "Throwable" to
+ * print the error message in the form:
+ * ParseException: <result of getMessage>
+ */
+ public ParseException(Token currentTokenVal,
+ int[][] expectedTokenSequencesVal,
+ String[] tokenImageVal
+ )
+ {
+ super("");
+ specialConstructor = true;
+ currentToken = currentTokenVal;
+ expectedTokenSequences = expectedTokenSequencesVal;
+ tokenImage = tokenImageVal;
+ }
+
+ /**
+ * The following constructors are for use by you for whatever
+ * purpose you can think of. Constructing the exception in this
+ * manner makes the exception behave in the normal way - i.e., as
+ * documented in the class "Throwable". The fields "errorToken",
+ * "expectedTokenSequences", and "tokenImage" do not contain
+ * relevant information. The JavaCC generated code does not use
+ * these constructors.
+ */
+
+ public ParseException() {
+ super();
+ specialConstructor = false;
+ }
+
+ public ParseException(String message) {
+ super(message);
+ specialConstructor = false;
+ }
+
+ /**
+ * This variable determines which constructor was used to create
+ * this object and thereby affects the semantics of the
+ * "getMessage" method (see below).
+ */
+ protected boolean specialConstructor;
+
+ /**
+ * This is the last token that has been consumed successfully. If
+ * this object has been created due to a parse error, the token
+ * followng this token will (therefore) be the first error token.
+ */
+ public Token currentToken;
+
+ /**
+ * Each entry in this array is an array of integers. Each array
+ * of integers represents a sequence of tokens (by their ordinal
+ * values) that is expected at this point of the parse.
+ */
+ public int[][] expectedTokenSequences;
+
+ /**
+ * This is a reference to the "tokenImage" array of the generated
+ * parser within which the parse error occurred. This array is
+ * defined in the generated ...Constants interface.
+ */
+ public String[] tokenImage;
+
+ /**
+ * This method has the standard behavior when this object has been
+ * created using the standard constructors. Otherwise, it uses
+ * "currentToken" and "expectedTokenSequences" to generate a parse
+ * error message and returns it. If this object has been created
+ * due to a parse error, and you do not catch it (it gets thrown
+ * from the parser), then this method is called during the printing
+ * of the final stack trace, and hence the correct error message
+ * gets displayed.
+ */
+ public String getMessage() {
+ if (!specialConstructor) {
+ return super.getMessage();
+ }
+ String expected = "";
+ int maxSize = 0;
+ for (int i = 0; i < expectedTokenSequences.length; i++) {
+ if (maxSize < expectedTokenSequences[i].length) {
+ maxSize = expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < expectedTokenSequences[i].length; j++) {
+ expected += tokenImage[expectedTokenSequences[i][j]] + " ";
+ }
+ if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
+ expected += "...";
+ }
+ expected += eol + " ";
+ }
+ String retval = "Encountered \"";
+ Token tok = currentToken.next;
+ for (int i = 0; i < maxSize; i++) {
+ if (i != 0) retval += " ";
+ if (tok.kind == 0) {
+ retval += tokenImage[0];
+ break;
+ }
+ retval += add_escapes(tok.image);
+ tok = tok.next;
+ }
+ retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
+ retval += "." + eol;
+ if (expectedTokenSequences.length == 1) {
+ retval += "Was expecting:" + eol + " ";
+ } else {
+ retval += "Was expecting one of:" + eol + " ";
+ }
+ retval += expected;
+ return retval;
+ }
+
+ /**
+ * The end of line string for this machine.
+ */
+ protected String eol = System.getProperty("line.separator", "\n");
+
+ /**
+ * Used to convert raw characters to their escaped version
+ * when these raw version cannot be used as part of an ASCII
+ * string literal.
+ */
+ protected String add_escapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/Parser.java b/src/main/java/io/devnulllabs/openjava/tools/parser/Parser.java
new file mode 100644
index 0000000..749fa53
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/Parser.java
@@ -0,0 +1,6327 @@
+package io.devnulllabs.openjava.tools.parser;
+
+
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import io.devnulllabs.openjava.mop.ClassEnvironment;
+import io.devnulllabs.openjava.mop.ClosedEnvironment;
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.FileEnvironment;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.AllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayAccess;
+import io.devnulllabs.openjava.ptree.ArrayAllocationExpression;
+import io.devnulllabs.openjava.ptree.ArrayInitializer;
+import io.devnulllabs.openjava.ptree.AssignmentExpression;
+import io.devnulllabs.openjava.ptree.BinaryExpression;
+import io.devnulllabs.openjava.ptree.Block;
+import io.devnulllabs.openjava.ptree.BreakStatement;
+import io.devnulllabs.openjava.ptree.CaseGroup;
+import io.devnulllabs.openjava.ptree.CaseGroupList;
+import io.devnulllabs.openjava.ptree.CastExpression;
+import io.devnulllabs.openjava.ptree.CatchBlock;
+import io.devnulllabs.openjava.ptree.CatchList;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ClassDeclarationList;
+import io.devnulllabs.openjava.ptree.ClassLiteral;
+import io.devnulllabs.openjava.ptree.CompilationUnit;
+import io.devnulllabs.openjava.ptree.ConditionalExpression;
+import io.devnulllabs.openjava.ptree.ConstructorDeclaration;
+import io.devnulllabs.openjava.ptree.ConstructorInvocation;
+import io.devnulllabs.openjava.ptree.ContinueStatement;
+import io.devnulllabs.openjava.ptree.DoWhileStatement;
+import io.devnulllabs.openjava.ptree.EmptyStatement;
+import io.devnulllabs.openjava.ptree.Expression;
+import io.devnulllabs.openjava.ptree.ExpressionList;
+import io.devnulllabs.openjava.ptree.ExpressionStatement;
+import io.devnulllabs.openjava.ptree.FieldAccess;
+import io.devnulllabs.openjava.ptree.FieldDeclaration;
+import io.devnulllabs.openjava.ptree.ForStatement;
+import io.devnulllabs.openjava.ptree.IfStatement;
+import io.devnulllabs.openjava.ptree.InstanceofExpression;
+import io.devnulllabs.openjava.ptree.LabeledStatement;
+import io.devnulllabs.openjava.ptree.Literal;
+import io.devnulllabs.openjava.ptree.MemberDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.MemberInitializer;
+import io.devnulllabs.openjava.ptree.MethodCall;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.ReturnStatement;
+import io.devnulllabs.openjava.ptree.SelfAccess;
+import io.devnulllabs.openjava.ptree.Statement;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.SwitchStatement;
+import io.devnulllabs.openjava.ptree.SynchronizedStatement;
+import io.devnulllabs.openjava.ptree.ThrowStatement;
+import io.devnulllabs.openjava.ptree.TryStatement;
+import io.devnulllabs.openjava.ptree.TypeName;
+import io.devnulllabs.openjava.ptree.UnaryExpression;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.ptree.VariableDeclaration;
+import io.devnulllabs.openjava.ptree.VariableDeclarator;
+import io.devnulllabs.openjava.ptree.VariableInitializer;
+import io.devnulllabs.openjava.ptree.WhileStatement;
+import io.devnulllabs.openjava.syntax.SyntaxRule;
+import io.devnulllabs.openjava.syntax.TokenSource;
+import io.devnulllabs.openjava.tools.DebugOut;
+
+
+public class Parser implements ParserConstants {
+ /**
+ * Allocates a new parser object who gets tokens from the given parser
+ * object.
+ *
+ * @param parser this is used to get tokens via <code>getToken()</code>
+ * or <code>getNextToken()</code>.
+ */
+ public Parser( Parser parser ) {
+ this( (ParserTokenManager) new CustomTokenManager( parser, OJSystem.env ) );
+ }
+
+ public Parser( TokenSource token_src ) {
+ this( new TokenSourceAdapter( token_src ) );
+ }
+
+ private final String getComment() {
+ Token token = getToken( 1 ).specialToken;
+ return ((token == null) ? null : token.image);
+ }
+
+
+ private final static int makeInt( String str ) {
+ if (str.length() == 1) {
+ return Integer.valueOf( str ).intValue();
+ } else if (str.startsWith( "0x" ) || str.startsWith( "0X" )) {
+ return Integer.valueOf( str.substring( 2 ), 16 ).intValue();
+ } else if (str.startsWith( "0" )) {
+ return Integer.valueOf( str.substring( 1 ), 8 ).intValue();
+ }
+ return Integer.valueOf( str ).intValue();
+ }
+ private final static long makeLong( String str ) {
+ if (str.length() == 1) {
+ return Long.valueOf( str ).longValue();
+ } else if (str.startsWith( "0x" ) || str.startsWith( "0X" )) {
+ str = str.substring( 2 );
+ if (str.endsWith( "l" ) || str.endsWith( "L" )) {
+ str = str.substring( 0, str.length() - 1 );
+ }
+ return Long.valueOf( str, 16 ).longValue();
+ } else if (str.startsWith( "0" )) {
+ str = str.substring( 1 );
+ if (str.endsWith( "l" ) || str.endsWith( "L" )) {
+ str = str.substring( 0, str.length() - 1 );
+ }
+ return Long.valueOf( str, 8 ).longValue();
+ }
+ return Long.valueOf( str ).longValue();
+ }
+
+ /**
+ * Detects class or interface name and metaclass
+ */
+ private final ClassEnvironment setClassEnvironment( Environment base_env )
+ throws ParseException
+ {
+ int ptr = 1;
+ for (; roughModifierCheck( getToken( ptr ) ) ; ++ptr) ;
+ Token c_or_i = getToken( ptr++ );
+ if (c_or_i.kind != CLASS && c_or_i.kind != INTERFACE) {
+ throw new ParseException( "'class' or 'interface' expected : "
+ + c_or_i.image );
+ }
+ Token cname = getToken( ptr++ );
+ if (cname.kind != IDENTIFIER) {
+ throw new ParseException( "class name expected : "
+ + c_or_i.image );
+ }
+ String classname = cname.image;
+
+ ClassEnvironment result = new ClassEnvironment(base_env, classname);
+
+ Token inst = getToken(ptr++);
+ if (inst.kind != INSTANTIATES) {
+ ptr++;
+ } else {
+ IntAndObj tmp = consumeMetaclassName(ptr); ptr = tmp.ptr;
+ String meta = base_env.toQualifiedName((String) tmp.obj);
+ OJSystem.metabind(result.toQualifiedName(classname), meta);
+ }
+
+ return result;
+ }
+
+ private IntAndObj consumeMetaclassName( int ptr ) throws ParseException {
+ Token token = getToken( ptr++ );
+ if (token.kind != IDENTIFIER) {
+ throw new ParseException( "metaclass name exptected : "
+ + token.image );
+ }
+ StringBuffer buf = new StringBuffer( token.image );
+ while (getToken( ptr ).kind == DOT
+ && getToken( ptr + 1 ).kind == IDENTIFIER) {
+ buf.append( "." ).append( getToken( ptr + 1 ).image );
+ ptr += 2;
+ }
+ return new IntAndObj( ptr, buf.toString() );
+ }
+
+ /**
+ * This is used to check io.devnulllabs.openjava user modifier semantically.
+ */
+ private final boolean OpenJavaModifierLookahead( Environment env ) {
+ return modifierCheck( env, getToken( 1 ) );
+ }
+
+ /**
+ * This is used to check OpenJava user modifier semantically.
+ */
+ private final boolean ModifierLookahead( Environment env ) {
+ return modifierCheck( env, getToken( 1 ) );
+ }
+
+ boolean DeclSuffixLookahead( Environment env ) {
+ String typename = env.currentClassName();
+ String keyword = consumeKeyword( 1 );
+ if (keyword == null) return false;
+ Class meta = toExecutable( env, typename );
+ return invokeOJClass_isRegisteredKeyword( meta, keyword );
+ }
+
+ boolean TypeSuffixLookahead( Environment env, String typename ) {
+ String keyword = consumeKeyword( 1 );
+ if (keyword == null) return false;
+ Class meta = toExecutable( env, typename );
+ return invokeOJClass_isRegisteredKeyword( meta, keyword );
+ }
+
+ private static final boolean modifierCheck( Environment env, Token t ) {
+ if (pureModifierCheck( t )) return true;
+ if (t.kind != IDENTIFIER) return false;
+ Class meta = toExecutable( env, env.currentClassName() );
+ if (meta == null) return false;
+ return invokeOJClass_isRegisteredModifier( meta, t.image );
+ }
+
+ private String consumeKeyword( int ptr ) {
+ Token token = getToken( ptr );
+ if (token.kind != IDENTIFIER) return null;
+ return token.image;
+ }
+
+ static final Class toExecutable( Environment env, String typename ) {
+ String qname = env.toQualifiedName( typename );
+ return OJSystem.getMetabind( qname );
+ }
+
+ static boolean invokeOJClass_isRegisteredKeyword( Class meta,
+ String keyword )
+ {
+ try {
+ Method m = meta.getMethod( "isRegisteredKeyword",
+ new Class[]{ String . class} );
+ Boolean b = (Boolean) m.invoke( null, new Object[]{ keyword } );
+ return b.booleanValue();
+ } catch ( Exception e ) {}
+ return false;
+ }
+
+ static SyntaxRule invokeOJClass_getDeclSuffixRule(Environment env,
+ Class meta,
+ String keyword)
+ {
+ SyntaxRule result = null;
+ try {
+ Method m = meta.getMethod("getDeclSuffixRule",
+ new Class[]{ Environment.class,
+ String.class });
+ result = (SyntaxRule) m.invoke(null, new Object[]{ env, keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ if (result != null) return result;
+ try {
+ Method m = meta.getMethod("getDeclSuffixRule",
+ new Class[]{ String.class });
+ result = (SyntaxRule) m.invoke(null, new Object[]{ keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ return result;
+ }
+
+ static SyntaxRule invokeOJClass_getTypeSuffixRule(Environment env,
+ Class meta,
+ String keyword)
+ {
+ SyntaxRule result = null;
+ try {
+ Method m = meta.getMethod("getTypeSuffixRule",
+ new Class[]{ Environment.class,
+ String.class });
+ result = (SyntaxRule) m.invoke(null, new Object[]{ env, keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ if (result != null) return result;
+ try {
+ Method m = meta.getMethod("getTypeSuffixRule",
+ new Class[]{ String.class});
+ result = (SyntaxRule) m.invoke(null, new Object[]{ keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ return result;
+ }
+
+ static boolean invokeOJClass_isRegisteredModifier( Class meta,
+ String keyword )
+ {
+ try {
+ Method m = meta.getMethod( "isRegisteredModifier",
+ new Class[]{ String . class} );
+ Boolean b = (Boolean) m.invoke( null, new Object[]{ keyword } );
+ return b.booleanValue();
+ } catch ( Exception e ) {}
+ return false;
+ }
+
+ /**
+ * This is used to check constructors semantically.
+ */
+ private final boolean ConstructorDeclarationLookahead(
+ ClassEnvironment env ) {
+ int ptr;
+ for (ptr = 1; modifierCheck( env, getToken( ptr ) ) ; ++ptr) ;
+ String simplename = Environment.toSimpleName( env.currentClassName() );
+ //if (! getToken( ptr ).image.equals( simplename )
+ // || getToken( ptr + 1 ).kind != LPAREN) {
+ // return false;
+ //}
+ //return true;
+ return (getToken(ptr + 1).kind == LPAREN);
+ }
+
+ /**
+ * This will used to check local variable declaration semantically.
+ */
+ private final boolean LocalVariableDeclarationLookahead(
+ Environment env ) {
+ int ptr;
+ for (ptr = 1; modifierCheck( env, getToken( ptr ) ) ; ++ptr) ;
+ int old_ptr = ptr;
+ ptr = consumePureResultType( old_ptr );
+ if (ptr != old_ptr && getToken( ptr ).kind == IDENTIFIER) {
+ return true;
+ }
+ return false;
+ }
+
+ private final boolean roughModifierCheck( Token t ) {
+ if (pureModifierCheck( t )) return true;
+ return (t.kind == IDENTIFIER);
+ }
+
+ private static final boolean pureModifierCheck( Token t ) {
+ switch (t.kind) {
+ case ABSTRACT : case FINAL : case PUBLIC : case PRIVATE :
+ case PROTECTED : case STATIC : case TRANSIENT : case VOLATILE :
+ case NATIVE : case SYNCHRONIZED :
+ return true;
+ }
+ return false;
+ }
+
+ private final boolean ConstructorInvocationLookahead() {
+ int ptr = 1;
+ while (getToken(ptr).kind != EOF) {
+ if (getToken(ptr).kind == SUPER
+ && getToken(ptr + 1).kind == LPAREN) {
+ return true;
+ }
+ if (getToken(ptr).kind == SEMICOLON) return false;
+ if (getToken(ptr).kind == RBRACE) return false;
+ ++ptr;
+ }
+ return false;
+ }
+
+ private final boolean AssignmentLookahead() {
+ int ptr = 1;
+ switch (getToken( ptr ).kind) {
+ case LPAREN :
+ ptr = consumeParenPair( ptr );
+ break;
+ case IDENTIFIER :
+ case THIS :
+ case SUPER :
+ ptr++;
+ break;
+ default :
+ return false;
+ }
+ for (boolean cont = true; cont;) {
+ switch (getToken( ptr ).kind) {
+ case LPAREN :
+ ptr = consumeParenPair( ptr );
+ break;
+ case LBRACKET :
+ ptr = consumeBracketPair( ptr );
+ break;
+ case DOT :
+ ptr++;
+ if (getToken( ptr ).kind != IDENTIFIER) return false;
+ ptr++;
+ break;
+ default :
+ cont = false;
+ }
+ }
+ return assignmentOperatorCheck( getToken( ptr ) );
+ }
+
+ private final int consumeParenPair( int ptr ) {
+ int nest = 1;
+ for (++ptr; nest > 0; ptr++) {
+ if (getToken( ptr ).kind == LPAREN) nest++;
+ if (getToken( ptr ).kind == RPAREN) nest--;
+ }
+ return ptr;
+ }
+
+ private final int consumeBracketPair( int ptr ) {
+ int nest = 1;
+ for (++ptr; nest > 0; ptr++) {
+ if (getToken( ptr ).kind == LBRACKET) nest++;
+ if (getToken( ptr ).kind == RBRACKET) nest--;
+ }
+ return ptr;
+ }
+
+ private static final boolean assignmentOperatorCheck( Token t ) {
+ if (t.kind == ASSIGN) return true;
+ if (t.kind == PLUSASSIGN) return true;
+ if (t.kind == MINUSASSIGN) return true;
+ if (t.kind == STARASSIGN) return true;
+ if (t.kind == SLASHASSIGN) return true;
+ if (t.kind == ANDASSIGN) return true;
+ if (t.kind == ORASSIGN) return true;
+ if (t.kind == XORASSIGN) return true;
+ if (t.kind == REMASSIGN) return true;
+ if (t.kind == LSHIFTASSIGN) return true;
+ if (t.kind == RSIGNEDSHIFTASSIGN) return true;
+ if (t.kind == RUNSIGNEDSHIFTASSIGN) return true;
+ return false;
+ }
+
+ private final boolean ClassLiteralLookahead() {
+ int ptr = 1;
+ ptr = consumePureResultType( ptr );
+ if (ptr == 1) return false;
+ /** here should be user suffix check **/
+ if (getToken( ptr ).kind != DOT) return false;
+ if (getToken( ptr + 1 ).kind != CLASS) return false;
+ return true;
+ }
+
+ private final int consumePureResultType( int ptr ) {
+ Token token = getToken( ptr );
+ if (primitiveTypeCheck( token )) {
+ ptr++;
+ } else if (token.kind == IDENTIFIER) {
+ ptr++;
+ while (getToken( ptr ).kind == DOT
+ && getToken( ptr + 1 ).kind == IDENTIFIER) {
+ ptr += 2;
+ }
+ } else {
+ return ptr;
+ }
+
+ while (getToken( ptr ).kind == LBRACKET
+ && getToken( ptr + 1 ).kind == RBRACKET) {
+ ptr += 2;
+ }
+
+ return ptr;
+ }
+
+ private final boolean primitiveTypeCheck( Token t ) {
+ if (t.kind == BOOLEAN || t.kind == CHAR || t.kind == BYTE
+ || t.kind == SHORT || t.kind == INT || t.kind == LONG
+ || t.kind == FLOAT || t.kind == DOUBLE || t.kind == VOID) {
+ return true;
+ }
+ return false;
+ }
+
+ void debug_message1() throws ParseException {
+ DebugOut.println( "debug1 : " + getToken( 0 ).image
+ + " , " + getToken( 1 ).image );
+ }
+
+ ParseTree UserDeclSuffix(Environment env, String keyword) throws ParseException {
+ String typename = env.currentClassName();
+ Class meta = toExecutable(env, typename);
+ SyntaxRule rule = invokeOJClass_getDeclSuffixRule(env, meta, keyword);
+ CustomTokenManager token_mgr = new CustomTokenManager(this, env);
+ token_mgr.assume();
+ ParseTree result = rule.consume(token_mgr);
+ token_mgr.fix();
+ return result;
+ }
+
+ ParseTree UserTypeSuffix(Environment env, String typename, String keyword) throws ParseException {
+ Class meta = toExecutable(env, typename);
+ SyntaxRule rule = invokeOJClass_getTypeSuffixRule(env, meta, keyword);
+ CustomTokenManager token_mgr = new CustomTokenManager(this, env);
+ token_mgr.assume();
+ ParseTree result = rule.consume(token_mgr);
+ token_mgr.fix();
+ return result;
+ }
+
+ void E() throws ParseException {
+ }
+
+/*****************************************
+ * Syntactical Descriptions *
+ *****************************************/
+
+/*
+ * Program structuring syntax follows.
+ */
+ final public CompilationUnit CompilationUnit(Environment base_env) throws ParseException {
+ CompilationUnit result;
+ FileEnvironment env = new FileEnvironment( base_env );
+ String p1;
+ String[] p2;
+ ClassDeclarationList p3;
+ /**/DebugOut.println( "#CompilationUnit()" );
+ String comment = getComment();
+ p1 = PackageDeclarationOpt();
+ p2 = ImportDeclarationListOpt();
+ env.setPackage( p1 );
+ for (int i = 0; i < p2.length; ++i) {
+ if (CompilationUnit.isOnDemandImport( p2[i] )) {
+ String pack_cls = CompilationUnit.trimOnDemand( p2[i] );
+ env.importPackage( pack_cls );
+ } else {
+ env.importClass( p2[i] );
+ }
+ }
+ label_1:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SEMICOLON:
+ ;
+ break;
+ default:
+ jj_la1[0] = jj_gen;
+ break label_1;
+ }
+ jj_consume_token(SEMICOLON);
+ }
+ p3 = TypeDeclarationListOpt(env);
+ jj_consume_token(0);
+ result = new CompilationUnit( p1, p2, p3 );
+ result.setComment( comment );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String PackageDeclarationOpt() throws ParseException {
+ String p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PACKAGE:
+ jj_consume_token(PACKAGE);
+ p1 = Name();
+ jj_consume_token(SEMICOLON);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[1] = jj_gen;
+ E();
+ {if (true) return null;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String[] ImportDeclarationListOpt() throws ParseException {
+ String[] result;
+ String p1;
+ Vector v = new Vector();
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case IMPORT:
+ label_2:
+ while (true) {
+ p1 = ImportDeclaration();
+ v.addElement( p1 );
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case IMPORT:
+ ;
+ break;
+ default:
+ jj_la1[2] = jj_gen;
+ break label_2;
+ }
+ }
+ result = new String[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (String) v.elementAt( i );
+ }
+ {if (true) return result;}
+ break;
+ default:
+ jj_la1[3] = jj_gen;
+ E();
+ {if (true) return new String[0];}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String ImportDeclaration() throws ParseException {
+ String p1;
+ StringBuffer strbuf = new StringBuffer();
+ jj_consume_token(IMPORT);
+ Identifier();
+ strbuf.append( getToken( 0 ).image );
+ label_3:
+ while (true) {
+ if (jj_2_1(2)) {
+ ;
+ } else {
+ break label_3;
+ }
+ jj_consume_token(DOT);
+ Identifier();
+ strbuf.append( "." + getToken( 0 ).image );
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case DOT:
+ jj_consume_token(DOT);
+ jj_consume_token(STAR);
+ strbuf.append( ".*" );
+ break;
+ default:
+ jj_la1[4] = jj_gen;
+ ;
+ }
+ jj_consume_token(SEMICOLON);
+ {if (true) return strbuf.toString();}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclarationList TypeDeclarationListOpt(Environment env) throws ParseException {
+ ClassEnvironment newenv;
+ ClassDeclarationList result = new ClassDeclarationList();
+ ClassDeclaration p1;
+ if ((getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF)) {
+ label_4:
+ while (true) {
+ newenv = setClassEnvironment( env );
+ p1 = TypeDeclaration(newenv);
+ label_5:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SEMICOLON:
+ ;
+ break;
+ default:
+ jj_la1[5] = jj_gen;
+ break label_5;
+ }
+ jj_consume_token(SEMICOLON);
+ }
+ result.add( p1 );
+ if ((getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF)) {
+ ;
+ } else {
+ break label_4;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration TypeDeclaration(ClassEnvironment env) throws ParseException {
+ ClassDeclaration result;
+ ClassDeclaration p1;
+ Token ctoken = getToken( 1 ).specialToken;
+ String comment = getComment();
+ if (jj_2_2(2147483647)) {
+ p1 = ClassDeclaration(env);
+ } else {
+ p1 = InterfaceDeclaration(env);
+ }
+ result = p1;
+ result.setComment( comment );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String Identifier() throws ParseException {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case IDENTIFIER:
+ jj_consume_token(IDENTIFIER);
+ {if (true) return getToken( 0 ).image;}
+ break;
+ case METACLASS:
+ jj_consume_token(METACLASS);
+ {if (true) return "metaclass";}
+ break;
+ default:
+ jj_la1[6] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String[] MetaclassesOpt(Environment env) throws ParseException {
+ String[] result;
+ String p1;
+ String p2;
+ Vector v = new Vector();
+ String qname;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ jj_consume_token(METACLASS);
+ p1 = Name();
+ qname = env.toQualifiedName( p1 );
+ v.addElement( qname );
+ /****/DebugOut.print( "metaclass " + qname );
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ jj_consume_token(COMMA);
+ p2 = Name();
+ qname = env.toQualifiedName( p2 );
+ /****/DebugOut.print( ", " + qname );
+ break;
+ default:
+ jj_la1[7] = jj_gen;
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COLON:
+ jj_consume_token(COLON);
+ break;
+ case SEMICOLON:
+ jj_consume_token(SEMICOLON);
+ break;
+ default:
+ jj_la1[8] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ /****/DebugOut.println( " :" );
+ result = new String[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (String) v.elementAt( i );
+ }
+ {if (true) return result;}
+ break;
+ default:
+ jj_la1[9] = jj_gen;
+ E();
+ {if (true) return new String[0];}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String InstantiatesPhraseOpt(ClassEnvironment env) throws ParseException {
+ String p1 = null;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INSTANTIATES:
+ jj_consume_token(INSTANTIATES);
+ p1 = Name();
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[10] = jj_gen;
+ E();
+ {if (true) return p1;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String OpenJavaModifier() throws ParseException {
+ String result;
+ jj_consume_token(IDENTIFIER);
+ result = getToken( 0 ).image;
+ DebugOut.println( "user modifier detected : " + result );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Hashtable OpenJavaDeclSuffixListOpt(Environment env) throws ParseException {
+ Hashtable result = new Hashtable();
+ String p1;
+ ParseTree p2;
+ if (DeclSuffixLookahead( env )) {
+ label_6:
+ while (true) {
+ p1 = Identifier();
+ p2 = UserDeclSuffix(env, p1);
+ DebugOut.println( "decl suffix : " + p1 + " " + p2 );
+ result.put( p1, p2 );
+ if (DeclSuffixLookahead( env )) {
+ ;
+ } else {
+ break label_6;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Hashtable OpenJavaTypeSuffixListOpt(Environment env, String typename) throws ParseException {
+ Hashtable result = new Hashtable();
+ String p1;
+ ParseTree p2;
+ if (TypeSuffixLookahead( env, typename )) {
+ label_7:
+ while (true) {
+ p1 = Identifier();
+ p2 = UserTypeSuffix(env, typename, p1);
+ DebugOut.println( "type suffix : " + p1 + " " + p2 );
+ result.put( p1, p2 );
+ if (TypeSuffixLookahead( env, typename )) {
+ ;
+ } else {
+ break label_7;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public int Modifier() throws ParseException {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ABSTRACT:
+ jj_consume_token(ABSTRACT);
+ {if (true) return ModifierList.ABSTRACT;}
+ break;
+ case FINAL:
+ jj_consume_token(FINAL);
+ {if (true) return ModifierList.FINAL;}
+ break;
+ case PUBLIC:
+ jj_consume_token(PUBLIC);
+ {if (true) return ModifierList.PUBLIC;}
+ break;
+ case PRIVATE:
+ jj_consume_token(PRIVATE);
+ {if (true) return ModifierList.PRIVATE;}
+ break;
+ case PROTECTED:
+ jj_consume_token(PROTECTED);
+ {if (true) return ModifierList.PROTECTED;}
+ break;
+ case STATIC:
+ jj_consume_token(STATIC);
+ {if (true) return ModifierList.STATIC;}
+ break;
+ case TRANSIENT:
+ jj_consume_token(TRANSIENT);
+ {if (true) return ModifierList.TRANSIENT;}
+ break;
+ case VOLATILE:
+ jj_consume_token(VOLATILE);
+ {if (true) return ModifierList.VOLATILE;}
+ break;
+ case NATIVE:
+ jj_consume_token(NATIVE);
+ {if (true) return ModifierList.NATIVE;}
+ break;
+ case SYNCHRONIZED:
+ jj_consume_token(SYNCHRONIZED);
+ {if (true) return ModifierList.SYNCHRONIZED;}
+ break;
+ default:
+ jj_la1[11] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+/*
+ * Declaration syntax follows.
+ */
+ final public ClassDeclaration ClassDeclaration(ClassEnvironment env) throws ParseException {
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#ClassDeclaration()" );
+ p1 = ClassModifiersOpt(env);
+ p2 = UnmodifiedClassDeclaration(env);
+ p2.setModifiers( p1 );
+ {if (true) return p2;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList ClassModifiersOpt(Environment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if ((getToken( 1 ).kind != CLASS)) {
+ label_8:
+ while (true) {
+ if (jj_2_3(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_8;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration UnmodifiedClassDeclaration(ClassEnvironment env) throws ParseException {
+ ClassDeclaration result;
+ String p1;
+ TypeName[] p2;
+ TypeName[] p3;
+ MemberDeclarationList p4;
+ String mm;
+ Hashtable sf;
+ jj_consume_token(CLASS);
+ p1 = Identifier();
+ mm = InstantiatesPhraseOpt(env);
+ p2 = ExtendsPhraseOpt(env);
+ p3 = ImplementsPhraseOpt(env);
+ sf = OpenJavaDeclSuffixListOpt(env);
+ p4 = ClassBody(env);
+ result = new ClassDeclaration( null, p1, p2, p3, p4 );
+ result.setSuffixes( sf );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName[] ExtendsPhraseOpt(Environment env) throws ParseException {
+ TypeName[] p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case EXTENDS:
+ jj_consume_token(EXTENDS);
+ p1 = TypeNameList(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[12] = jj_gen;
+ E();
+ {if (true) return null;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName[] ImplementsPhraseOpt(Environment env) throws ParseException {
+ TypeName[] p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case IMPLEMENTS:
+ jj_consume_token(IMPLEMENTS);
+ p1 = TypeNameList(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[13] = jj_gen;
+ E();
+ {if (true) return null;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList ClassBody(ClassEnvironment env) throws ParseException {
+ MemberDeclarationList p1;
+
+ DebugOut.println( "#ClassBody()" );
+ jj_consume_token(LBRACE);
+ label_9:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SEMICOLON:
+ ;
+ break;
+ default:
+ jj_la1[14] = jj_gen;
+ break label_9;
+ }
+ jj_consume_token(SEMICOLON);
+ }
+ p1 = ClassBodyDeclarationListOpt(env);
+ jj_consume_token(RBRACE);
+ {if (true) return p1;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList ClassBodyDeclarationListOpt(ClassEnvironment env) throws ParseException {
+ MemberDeclarationList result = new MemberDeclarationList();
+ MemberDeclarationList p1;
+ if ((getToken( 1 ).kind != RBRACE)) {
+ label_10:
+ while (true) {
+ p1 = ClassBodyDeclaration(env);
+ label_11:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SEMICOLON:
+ ;
+ break;
+ default:
+ jj_la1[15] = jj_gen;
+ break label_11;
+ }
+ jj_consume_token(SEMICOLON);
+ }
+ result.addAll( p1 );
+ if ((getToken( 1 ).kind != RBRACE)) {
+ ;
+ } else {
+ break label_10;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration NestedTypeDeclaration(ClassEnvironment env) throws ParseException {
+ ClassDeclaration result;
+ ClassDeclaration p1;
+ Token ctoken = getToken( 1 ).specialToken;
+ String comment = getComment();
+ if (jj_2_4(2147483647)) {
+ p1 = NestedClassDeclaration(env);
+ } else {
+ p1 = NestedInterfaceDeclaration(env);
+ }
+ result = p1;
+ result.setComment( comment );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration NestedClassDeclaration(ClassEnvironment env) throws ParseException {
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#NestedClassDeclaration()" );
+ p1 = NestedClassModifiersOpt(env);
+ p2 = UnmodifiedClassDeclaration(env);
+ p2.setModifiers( p1 );
+ {if (true) return p2;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList NestedClassModifiersOpt(ClassEnvironment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if ((getToken( 1 ).kind != CLASS)) {
+ label_12:
+ while (true) {
+ if (jj_2_5(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_12;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList ClassBodyDeclaration(ClassEnvironment env) throws ParseException {
+ ClassEnvironment newenv;
+ MemberDeclarationList result;
+ MemberDeclaration p1;
+ MemberDeclarationList p2;
+ if (jj_2_6(2147483647)) {
+ p1 = MemberInitializer(env);
+ result = new MemberDeclarationList( p1 );
+ {if (true) return result;}
+ } else if (jj_2_7(2147483647)) {
+ newenv = setClassEnvironment( env );
+ p1 = NestedTypeDeclaration(newenv);
+ result = new MemberDeclarationList( p1 );
+ {if (true) return result;}
+ } else if (ConstructorDeclarationLookahead( env )) {
+ p1 = ConstructorDeclaration(env);
+ result = new MemberDeclarationList( p1 );
+ {if (true) return result;}
+ } else {
+ p2 = MethodOrFieldDeclaration(env);
+ {if (true) return p2;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList MethodOrFieldDeclaration(Environment base_env) throws ParseException {
+ Environment env = new ClosedEnvironment( base_env );
+ MemberDeclarationList result = new MemberDeclarationList();
+ ModifierList p1;
+ TypeName p2;
+ String p3;
+ ParameterList p4;
+ int p5;
+ TypeName[] p6;
+ StatementList p7;
+ VariableDeclarator p8;
+ Hashtable sf;
+ Token ctoken = getToken( 1 ).specialToken;
+ String comment = getComment();
+ p1 = MemberModifiersOpt(base_env);
+ p2 = Type(base_env);
+ if (jj_2_8(2147483647)) {
+ p3 = Identifier();
+ p4 = FormalParameters(env);
+ p5 = EmptyBracketsOpt();
+ p6 = ThrowsPhraseOpt(base_env);
+ sf = OpenJavaDeclSuffixListOpt(env);
+ p7 = MethodBody(env);
+ p2.addDimension( p5 );
+ MethodDeclaration mthd
+ = new MethodDeclaration( p1, p2, p3, p4, p6, p7 );
+ mthd.setSuffixes( sf );
+ mthd.setComment( comment );
+ result.add( mthd );
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ case IDENTIFIER:
+ p8 = VariableDeclarator(base_env);
+ FieldDeclaration fld1 = new FieldDeclaration( p1, p2, p8 );
+ fld1.setComment( comment );
+ result.add( fld1 );
+ label_13:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[16] = jj_gen;
+ break label_13;
+ }
+ jj_consume_token(COMMA);
+ p8 = VariableDeclarator(env);
+ FieldDeclaration fld2 = new FieldDeclaration( p1, p2, p8 );
+ fld2.setComment( comment );
+ result.add( fld2 );
+ }
+ jj_consume_token(SEMICOLON);
+ break;
+ default:
+ jj_la1[17] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName[] ThrowsPhraseOpt(Environment env) throws ParseException {
+ TypeName[] p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case THROWS:
+ jj_consume_token(THROWS);
+ p1 = TypeNameList(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[18] = jj_gen;
+ E();
+ {if (true) return null;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public StatementList MethodBody(Environment env) throws ParseException {
+ StatementList p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p1 = BlockedBody(env);
+ {if (true) return p1;}
+ break;
+ case SEMICOLON:
+ jj_consume_token(SEMICOLON);
+ {if (true) return null;}
+ break;
+ default:
+ jj_la1[19] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList MemberModifiersOpt(Environment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if (modifierCheck( env, getToken( 1 ) )) {
+ label_14:
+ while (true) {
+ if (jj_2_9(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_14;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration InterfaceDeclaration(ClassEnvironment env) throws ParseException {
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#InterfaceDeclaration()" );
+ p1 = InterfaceModifiersOpt(env);
+ p2 = UnmodifiedInterfaceDeclaration(env);
+ p2.setModifiers( p1 );
+ {if (true) return p2;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList InterfaceModifiersOpt(Environment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if ((getToken( 1 ).kind != INTERFACE)) {
+ label_15:
+ while (true) {
+ if (jj_2_10(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_15;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration NestedInterfaceDeclaration(ClassEnvironment env) throws ParseException {
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#NestedInterfaceDeclaration()" );
+ p1 = NestedInterfaceModifiersOpt(env);
+ p2 = UnmodifiedInterfaceDeclaration(env);
+ p2.setModifiers( p1 );
+ {if (true) return p2;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList NestedInterfaceModifiersOpt(ClassEnvironment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if ((getToken( 1 ).kind != INTERFACE)) {
+ label_16:
+ while (true) {
+ if (jj_2_11(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_16;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassDeclaration UnmodifiedInterfaceDeclaration(ClassEnvironment env) throws ParseException {
+ ClassDeclaration result;
+ String p1;
+ TypeName[] p2;
+ MemberDeclarationList p3;
+ String mm;
+ Hashtable sf;
+ jj_consume_token(INTERFACE);
+ p1 = Identifier();
+ mm = InstantiatesPhraseOpt(env);
+ p2 = ExtendsPhraseOpt(env);
+ sf = OpenJavaDeclSuffixListOpt(env);
+ p3 = InterfaceBody(env);
+ result = new ClassDeclaration( null, p1, p2, null, p3, false );
+ result.setSuffixes( sf );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList InterfaceBody(ClassEnvironment env) throws ParseException {
+ MemberDeclarationList p1;
+ jj_consume_token(LBRACE);
+ p1 = InterfaceBodyDeclarationListOpt(env);
+ jj_consume_token(RBRACE);
+ {if (true) return p1;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList InterfaceBodyDeclarationListOpt(ClassEnvironment env) throws ParseException {
+ MemberDeclarationList result = new MemberDeclarationList();
+ MemberDeclarationList p1;
+ if ((getToken( 1 ).kind != RBRACE)) {
+ label_17:
+ while (true) {
+ p1 = InterfaceBodyDeclaration(env);
+ result.addAll( p1 );
+ if ((getToken( 1 ).kind != RBRACE)) {
+ ;
+ } else {
+ break label_17;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberDeclarationList InterfaceBodyDeclaration(ClassEnvironment env) throws ParseException {
+ ClassEnvironment newenv;
+ MemberDeclarationList result;
+ ClassDeclaration p1;
+ MemberDeclarationList p2;
+ if (jj_2_12(2147483647)) {
+ newenv = setClassEnvironment( env );
+ p1 = NestedTypeDeclaration(newenv);
+ result = new MemberDeclarationList( p1 );
+ {if (true) return result;}
+ } else {
+ p2 = MethodOrFieldDeclaration(env);
+ {if (true) return p2;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public VariableDeclarator VariableDeclarator(Environment env) throws ParseException {
+ String p1;
+ int p2;
+ VariableInitializer p3 = null;
+ p1 = Identifier();
+ p2 = EmptyBracketsOpt();
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ASSIGN:
+ jj_consume_token(ASSIGN);
+ p3 = VariableInitializer(env);
+ break;
+ default:
+ jj_la1[20] = jj_gen;
+ ;
+ }
+ {if (true) return new VariableDeclarator( p1, p2, p3 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public int EmptyBracketsOpt() throws ParseException {
+ int result = 0;
+ if (jj_2_14(2147483647)) {
+ label_18:
+ while (true) {
+ jj_consume_token(LBRACKET);
+ jj_consume_token(RBRACKET);
+ result++;
+ if (jj_2_13(2)) {
+ ;
+ } else {
+ break label_18;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public VariableInitializer VariableInitializer(Environment env) throws ParseException {
+ VariableInitializer p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p1 = ArrayInitializer(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[21] = jj_gen;
+ if (jj_2_15(1)) {
+ p1 = Expression(env);
+ {if (true) return p1;}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ArrayInitializer ArrayInitializer(Environment env) throws ParseException {
+ ArrayInitializer result = new ArrayInitializer();
+ VariableInitializer p1;
+ jj_consume_token(LBRACE);
+ if ((getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != COMMA)) {
+ p1 = VariableInitializer(env);
+ result.add( p1 );
+ label_19:
+ while (true) {
+ if ((getToken( 1 ).kind == COMMA
+ && getToken( 2 ).kind != RBRACE)) {
+ ;
+ } else {
+ break label_19;
+ }
+ jj_consume_token(COMMA);
+ p1 = VariableInitializer(env);
+ result.add( p1 );
+ }
+ } else {
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ jj_consume_token(COMMA);
+ result.omitRemainder( true );
+ break;
+ default:
+ jj_la1[22] = jj_gen;
+ ;
+ }
+ jj_consume_token(RBRACE);
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ParameterList FormalParameters(Environment env) throws ParseException {
+ ParameterList result = new ParameterList();
+ Parameter p1;
+
+ DebugOut.println( "#FormalParameters()" );
+ jj_consume_token(LPAREN);
+ if ((getToken( 1 ).kind != RPAREN)) {
+ p1 = FormalParameter(env);
+ result.add( p1 );
+ label_20:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[23] = jj_gen;
+ break label_20;
+ }
+ jj_consume_token(COMMA);
+ p1 = FormalParameter(env);
+ result.add( p1 );
+ }
+ } else {
+ ;
+ }
+ jj_consume_token(RPAREN);
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Parameter FormalParameter(Environment env) throws ParseException {
+ ModifierList p1;
+ TypeName p2;
+ String p3;
+ int p4;
+ DebugOut.println( "#FormalParameter()" );
+ p1 = FormalParameterModifiersOpt(env);
+ p2 = Type(env);
+ p3 = Identifier();
+ p4 = EmptyBracketsOpt();
+ p2.addDimension( p4 );
+ /* binds the parameter variable as the null type */
+ env.bindVariable(p3, OJSystem.NULLTYPE);
+ {if (true) return new Parameter( p1, p2, p3 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList FormalParameterModifiersOpt(Environment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if (modifierCheck( env, getToken( 1 ) )) {
+ label_21:
+ while (true) {
+ if (jj_2_16(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_21;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ConstructorDeclaration ConstructorDeclaration(Environment base_env) throws ParseException {
+ Environment env = new ClosedEnvironment( base_env );
+ ConstructorDeclaration result;
+ ModifierList p1;
+ String p2;
+ ParameterList p3;
+ TypeName[] p4;
+ ConstructorInvocation p5;
+ StatementList p6;
+ Hashtable sf;
+
+ DebugOut.println( "#ConstructorDeclaration()" );
+ p1 = ConstructorModifiersOpt(base_env);
+ p2 = Identifier();
+ p3 = FormalParameters(env);
+ p4 = ThrowsPhraseOpt(base_env);
+ sf = OpenJavaDeclSuffixListOpt(env);
+ jj_consume_token(LBRACE);
+ p5 = ExplicitConstructorInvocationOpt(env);
+ p6 = BlockOrStatementListOpt(env);
+ jj_consume_token(RBRACE);
+ result = new ConstructorDeclaration( p1, p2, p3, p4, p5, p6 );
+ result.setSuffixes( sf );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList ConstructorModifiersOpt(Environment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if (jj_2_17(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ label_22:
+ while (true) {
+ if (OpenJavaModifierLookahead( env )) {
+ ;
+ } else {
+ break label_22;
+ }
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ }
+ {if (true) return result;}
+ } else if (OpenJavaModifierLookahead( env )) {
+ label_23:
+ while (true) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ if (OpenJavaModifierLookahead( env )) {
+ ;
+ } else {
+ break label_23;
+ }
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ABSTRACT:
+ case FINAL:
+ case NATIVE:
+ case PRIVATE:
+ case PROTECTED:
+ case PUBLIC:
+ case STATIC:
+ case SYNCHRONIZED:
+ case TRANSIENT:
+ case VOLATILE:
+ p1 = Modifier();
+ result.add( p1 );
+ label_24:
+ while (true) {
+ if (OpenJavaModifierLookahead( env )) {
+ ;
+ } else {
+ break label_24;
+ }
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ }
+ break;
+ default:
+ jj_la1[24] = jj_gen;
+ ;
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ConstructorInvocation ExplicitConstructorInvocationOpt(Environment env) throws ParseException {
+ ExpressionList p1;
+ Expression p2 = null;
+
+ DebugOut.println( "#ExplicitConstructorInvocationOpt()" );
+ if (jj_2_18(2147483647)) {
+ jj_consume_token(THIS);
+ p1 = Arguments(env);
+ jj_consume_token(SEMICOLON);
+ {if (true) return new ConstructorInvocation( p1 );}
+ } else if (ConstructorInvocationLookahead()) {
+ if ((getToken( 1 ).kind != SUPER)) {
+ p2 = PrimaryExpression(env);
+ jj_consume_token(DOT);
+ } else {
+ ;
+ }
+ jj_consume_token(SUPER);
+ p1 = Arguments(env);
+ jj_consume_token(SEMICOLON);
+ {if (true) return new ConstructorInvocation( p1, p2 );}
+ } else {
+ E();
+ {if (true) return null;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public MemberInitializer MemberInitializer(Environment env) throws ParseException {
+ MemberInitializer result;
+ StatementList p1;
+ boolean is_static = false;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case STATIC:
+ jj_consume_token(STATIC);
+ is_static = true;
+ break;
+ default:
+ jj_la1[25] = jj_gen;
+ ;
+ }
+ p1 = BlockedBody(env);
+ if (is_static) {
+ result = new MemberInitializer( p1, true );
+ } else {
+ result = new MemberInitializer( p1 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+/*
+ * Type, name and expression syntax follows.
+ */
+ final public TypeName Type(Environment env) throws ParseException {
+ TypeName result;
+ String p1;
+ Hashtable p2;
+ int p3;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BOOLEAN:
+ case BYTE:
+ case CHAR:
+ case DOUBLE:
+ case FLOAT:
+ case INT:
+ case LONG:
+ case SHORT:
+ case VOID:
+ p1 = PrimitiveType();
+ break;
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = Name();
+ break;
+ default:
+ jj_la1[26] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = OpenJavaTypeSuffixListOpt(env, p1);
+ p3 = EmptyBracketsOpt();
+ result = new TypeName( p1, p3, p2 );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String PrimitiveType() throws ParseException {
+ String result;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BOOLEAN:
+ jj_consume_token(BOOLEAN);
+ break;
+ case CHAR:
+ jj_consume_token(CHAR);
+ break;
+ case BYTE:
+ jj_consume_token(BYTE);
+ break;
+ case SHORT:
+ jj_consume_token(SHORT);
+ break;
+ case INT:
+ jj_consume_token(INT);
+ break;
+ case LONG:
+ jj_consume_token(LONG);
+ break;
+ case FLOAT:
+ jj_consume_token(FLOAT);
+ break;
+ case DOUBLE:
+ jj_consume_token(DOUBLE);
+ break;
+ case VOID:
+ jj_consume_token(VOID);
+ break;
+ default:
+ jj_la1[27] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ result = getToken( 0 ).image;
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String Name() throws ParseException {
+ String p1;
+ StringBuffer strbuf = null;
+ p1 = Identifier();
+ strbuf = new StringBuffer( p1 );
+ label_25:
+ while (true) {
+ if (jj_2_19(2)) {
+ ;
+ } else {
+ break label_25;
+ }
+ jj_consume_token(DOT);
+ p1 = Identifier();
+ strbuf.append( "." + p1 );
+ }
+ {if (true) return strbuf.toString();}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName TypeName(Environment env) throws ParseException {
+ TypeName result;
+ String p1;
+ Hashtable p2;
+ p1 = Name();
+ p2 = OpenJavaTypeSuffixListOpt(env, p1);
+ result = new TypeName( p1, p2 );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName[] TypeNameList(Environment env) throws ParseException {
+ TypeName[] result;
+ TypeName p1;
+ Vector v = new Vector();
+ p1 = TypeName(env);
+ v.addElement( p1 );
+ label_26:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[28] = jj_gen;
+ break label_26;
+ }
+ jj_consume_token(COMMA);
+ p1 = TypeName(env);
+ v.addElement( p1 );
+ }
+ result = new TypeName[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (TypeName) v.elementAt( i );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName[] TypeNameListOpt(Environment env) throws ParseException {
+ TypeName[] result;
+ TypeName p1;
+ Vector v = new Vector();
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = TypeName(env);
+ v.addElement( p1 );
+ label_27:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[29] = jj_gen;
+ break label_27;
+ }
+ jj_consume_token(COMMA);
+ p1 = TypeName(env);
+ v.addElement( p1 );
+ }
+ result = new TypeName[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (TypeName) v.elementAt( i );
+ }
+ {if (true) return result;}
+ break;
+ default:
+ jj_la1[30] = jj_gen;
+ E();
+ {if (true) return new TypeName[0];}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+/*
+ * Expression syntax follows.
+ */
+ final public Expression Expression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2 = null;
+ Expression p3 = null;
+
+ DebugOut.println( "#Expression()" );
+ p1 = ConditionalExpression(env);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ASSIGN:
+ case PLUSASSIGN:
+ case MINUSASSIGN:
+ case STARASSIGN:
+ case SLASHASSIGN:
+ case ANDASSIGN:
+ case ORASSIGN:
+ case XORASSIGN:
+ case REMASSIGN:
+ case LSHIFTASSIGN:
+ case RSIGNEDSHIFTASSIGN:
+ case RUNSIGNEDSHIFTASSIGN:
+ p2 = AssignmentOperator();
+ p3 = Expression(env);
+ break;
+ default:
+ jj_la1[31] = jj_gen;
+ ;
+ }
+ if (p2 != null) {
+ result = new AssignmentExpression( p1, p2, p3 );
+ } else {
+ result = p1;
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public AssignmentExpression AssignmentExpression(Environment env) throws ParseException {
+ Expression p1;
+ String p2;
+ Expression p3;
+
+ DebugOut.println( "#AssignmentExpression()" );
+ p1 = PrimaryExpression(env);
+ p2 = AssignmentOperator();
+ p3 = Expression(env);
+ {if (true) return new AssignmentExpression( p1, p2, p3 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public String AssignmentOperator() throws ParseException {
+ String result;
+
+ DebugOut.println( "#AssignmentOperator()" );
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ASSIGN:
+ jj_consume_token(ASSIGN);
+ break;
+ case STARASSIGN:
+ jj_consume_token(STARASSIGN);
+ break;
+ case SLASHASSIGN:
+ jj_consume_token(SLASHASSIGN);
+ break;
+ case REMASSIGN:
+ jj_consume_token(REMASSIGN);
+ break;
+ case PLUSASSIGN:
+ jj_consume_token(PLUSASSIGN);
+ break;
+ case MINUSASSIGN:
+ jj_consume_token(MINUSASSIGN);
+ break;
+ case LSHIFTASSIGN:
+ jj_consume_token(LSHIFTASSIGN);
+ break;
+ case RSIGNEDSHIFTASSIGN:
+ jj_consume_token(RSIGNEDSHIFTASSIGN);
+ break;
+ case RUNSIGNEDSHIFTASSIGN:
+ jj_consume_token(RUNSIGNEDSHIFTASSIGN);
+ break;
+ case ANDASSIGN:
+ jj_consume_token(ANDASSIGN);
+ break;
+ case XORASSIGN:
+ jj_consume_token(XORASSIGN);
+ break;
+ case ORASSIGN:
+ jj_consume_token(ORASSIGN);
+ break;
+ default:
+ jj_la1[32] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ result = getToken( 0 ).image;
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression ConditionalExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ Expression p2 = null;
+ Expression p3 = null;
+ p1 = ConditionalOrExpression(env);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case HOOK:
+ jj_consume_token(HOOK);
+ p2 = Expression(env);
+ jj_consume_token(COLON);
+ p3 = ConditionalExpression(env);
+ break;
+ default:
+ jj_la1[33] = jj_gen;
+ ;
+ }
+ if (p2 != null) {
+ result = new ConditionalExpression( p1, p2, p3 );
+ } else {
+ result = p1;
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression ConditionalOrExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = ConditionalAndExpression(env);
+ result = p1;
+ label_28:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SC_OR:
+ ;
+ break;
+ default:
+ jj_la1[34] = jj_gen;
+ break label_28;
+ }
+ jj_consume_token(SC_OR);
+ p2 = getToken( 0 ).image;
+ p3 = ConditionalAndExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression ConditionalAndExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = InclusiveOrExpression(env);
+ result = p1;
+ label_29:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SC_AND:
+ ;
+ break;
+ default:
+ jj_la1[35] = jj_gen;
+ break label_29;
+ }
+ jj_consume_token(SC_AND);
+ p2 = getToken( 0 ).image;
+ p3 = InclusiveOrExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression InclusiveOrExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = ExclusiveOrExpression(env);
+ result = p1;
+ label_30:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BIT_OR:
+ ;
+ break;
+ default:
+ jj_la1[36] = jj_gen;
+ break label_30;
+ }
+ jj_consume_token(BIT_OR);
+ p2 = getToken( 0 ).image;
+ p3 = ExclusiveOrExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression ExclusiveOrExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = AndExpression(env);
+ result = p1;
+ label_31:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case XOR:
+ ;
+ break;
+ default:
+ jj_la1[37] = jj_gen;
+ break label_31;
+ }
+ jj_consume_token(XOR);
+ p2 = getToken( 0 ).image;
+ p3 = AndExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression AndExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = EqualityExpression(env);
+ result = p1;
+ label_32:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BIT_AND:
+ ;
+ break;
+ default:
+ jj_la1[38] = jj_gen;
+ break label_32;
+ }
+ jj_consume_token(BIT_AND);
+ p2 = getToken( 0 ).image;
+ p3 = EqualityExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression EqualityExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+
+ DebugOut.println( "#EqualityExpression()" );
+ p1 = InstanceofExpression(env);
+ result = p1;
+ label_33:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case EQ:
+ case NE:
+ ;
+ break;
+ default:
+ jj_la1[39] = jj_gen;
+ break label_33;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case EQ:
+ jj_consume_token(EQ);
+ break;
+ case NE:
+ jj_consume_token(NE);
+ break;
+ default:
+ jj_la1[40] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = getToken( 0 ).image;
+ p3 = InstanceofExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression InstanceofExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ TypeName p2 = null;
+ p1 = RelationalExpression(env);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INSTANCEOF:
+ jj_consume_token(INSTANCEOF);
+ p2 = Type(env);
+ break;
+ default:
+ jj_la1[41] = jj_gen;
+ ;
+ }
+ if (p2 != null) {
+ result = new InstanceofExpression( p1, p2 );
+ } else {
+ result = p1;
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression RelationalExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = ShiftExpression(env);
+ result = p1;
+ label_34:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case GT:
+ case LT:
+ case LE:
+ case GE:
+ ;
+ break;
+ default:
+ jj_la1[42] = jj_gen;
+ break label_34;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LT:
+ jj_consume_token(LT);
+ break;
+ case GT:
+ jj_consume_token(GT);
+ break;
+ case LE:
+ jj_consume_token(LE);
+ break;
+ case GE:
+ jj_consume_token(GE);
+ break;
+ default:
+ jj_la1[43] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = getToken( 0 ).image;
+ p3 = ShiftExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression ShiftExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = AdditiveExpression(env);
+ result = p1;
+ label_35:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LSHIFT:
+ case RSIGNEDSHIFT:
+ case RUNSIGNEDSHIFT:
+ ;
+ break;
+ default:
+ jj_la1[44] = jj_gen;
+ break label_35;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LSHIFT:
+ jj_consume_token(LSHIFT);
+ break;
+ case RSIGNEDSHIFT:
+ jj_consume_token(RSIGNEDSHIFT);
+ break;
+ case RUNSIGNEDSHIFT:
+ jj_consume_token(RUNSIGNEDSHIFT);
+ break;
+ default:
+ jj_la1[45] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = getToken( 0 ).image;
+ p3 = AdditiveExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression AdditiveExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = MultiplicativeExpression(env);
+ result = p1;
+ label_36:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PLUS:
+ case MINUS:
+ ;
+ break;
+ default:
+ jj_la1[46] = jj_gen;
+ break label_36;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PLUS:
+ jj_consume_token(PLUS);
+ break;
+ case MINUS:
+ jj_consume_token(MINUS);
+ break;
+ default:
+ jj_la1[47] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = getToken( 0 ).image;
+ p3 = MultiplicativeExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression MultiplicativeExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+ p1 = UnaryExpression(env);
+ result = p1;
+ label_37:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case STAR:
+ case SLASH:
+ case REM:
+ ;
+ break;
+ default:
+ jj_la1[48] = jj_gen;
+ break label_37;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case STAR:
+ jj_consume_token(STAR);
+ break;
+ case SLASH:
+ jj_consume_token(SLASH);
+ break;
+ case REM:
+ jj_consume_token(REM);
+ break;
+ default:
+ jj_la1[49] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = getToken( 0 ).image;
+ p3 = UnaryExpression(env);
+ result = new BinaryExpression( result, p2, p3 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression UnaryExpression(Environment env) throws ParseException {
+ int p1;
+ Expression p2;
+ if (jj_2_20(2147483647)) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case PLUS:
+ jj_consume_token(PLUS);
+ p1 = UnaryExpression.PLUS;
+ break;
+ case MINUS:
+ jj_consume_token(MINUS);
+ p1 = UnaryExpression.MINUS;
+ break;
+ default:
+ jj_la1[50] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = UnaryExpression(env);
+ {if (true) return new UnaryExpression( p1, p2 );}
+ } else if (jj_2_21(2147483647)) {
+ p2 = PreIncrementExpression(env);
+ {if (true) return p2;}
+ } else if (jj_2_22(1)) {
+ p2 = UnaryExpressionNotPlusMinus(env);
+ {if (true) return p2;}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression PreIncrementExpression(Environment env) throws ParseException {
+ int p1;
+ Expression p2;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INCR:
+ jj_consume_token(INCR);
+ p1 = UnaryExpression.PRE_INCREMENT;
+ break;
+ case DECR:
+ jj_consume_token(DECR);
+ p1 = UnaryExpression.PRE_DECREMENT;
+ break;
+ default:
+ jj_la1[51] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = PrimaryExpression(env);
+ {if (true) return new UnaryExpression( p1, p2 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression UnaryExpressionNotPlusMinus(Environment env) throws ParseException {
+ int p1;
+ Expression p2;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BANG:
+ case TILDE:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case TILDE:
+ jj_consume_token(TILDE);
+ p1 = UnaryExpression.BIT_NOT;
+ break;
+ case BANG:
+ jj_consume_token(BANG);
+ p1 = UnaryExpression.NOT;
+ break;
+ default:
+ jj_la1[52] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = UnaryExpression(env);
+ {if (true) return new UnaryExpression( p1, p2 );}
+ break;
+ default:
+ jj_la1[53] = jj_gen;
+ if (jj_2_23(2147483647)) {
+ p2 = CastExpression(env);
+ {if (true) return p2;}
+ } else if (jj_2_24(1)) {
+ p2 = PostfixExpression(env);
+ {if (true) return p2;}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public void CastLookahead(Environment env) throws ParseException {
+ if (jj_2_25(2)) {
+ jj_consume_token(LPAREN);
+ PrimitiveType();
+ } else if (jj_2_26(2147483647)) {
+ jj_consume_token(LPAREN);
+ Name();
+ jj_consume_token(LBRACKET);
+ jj_consume_token(RBRACKET);
+ } else if (jj_2_27(2147483647)) {
+ jj_consume_token(LPAREN);
+ Name();
+ jj_consume_token(RPAREN);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case TILDE:
+ jj_consume_token(TILDE);
+ break;
+ case BANG:
+ jj_consume_token(BANG);
+ break;
+ case LPAREN:
+ jj_consume_token(LPAREN);
+ break;
+ case METACLASS:
+ case IDENTIFIER:
+ Identifier();
+ break;
+ case THIS:
+ jj_consume_token(THIS);
+ break;
+ case SUPER:
+ jj_consume_token(SUPER);
+ break;
+ case NEW:
+ jj_consume_token(NEW);
+ break;
+ case FALSE:
+ case NULL:
+ case TRUE:
+ case INTEGER_LITERAL:
+ case LONG_LITERAL:
+ case DOUBLE_FLOATING_POINT_LITERAL:
+ case FLOATING_POINT_LITERAL:
+ case CHARACTER_LITERAL:
+ case STRING_LITERAL:
+ Literal();
+ break;
+ default:
+ jj_la1[54] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LPAREN:
+ jj_consume_token(LPAREN);
+ Name();
+ Identifier();
+ break;
+ default:
+ jj_la1[55] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ }
+
+ final public Expression PostfixExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ int p2 = -1;
+ p1 = PrimaryExpression(env);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INCR:
+ case DECR:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INCR:
+ jj_consume_token(INCR);
+ p2 = UnaryExpression.POST_INCREMENT;
+ break;
+ case DECR:
+ jj_consume_token(DECR);
+ p2 = UnaryExpression.POST_DECREMENT;
+ break;
+ default:
+ jj_la1[56] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ break;
+ default:
+ jj_la1[57] = jj_gen;
+ ;
+ }
+ if (p2 != -1) {
+ result = new UnaryExpression( p1, p2 );
+ } else {
+ result = p1;
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public CastExpression CastExpression(Environment env) throws ParseException {
+ TypeName p1;
+ Expression p2;
+
+ DebugOut.println( "#CastExpression()" );
+ if (jj_2_28(2147483647)) {
+ jj_consume_token(LPAREN);
+ p1 = Type(env);
+ jj_consume_token(RPAREN);
+ p2 = UnaryExpression(env);
+ {if (true) return new CastExpression( p1, p2 );}
+ } else if (jj_2_29(2147483647)) {
+ jj_consume_token(LPAREN);
+ p1 = Type(env);
+ jj_consume_token(RPAREN);
+ p2 = UnaryExpressionNotPlusMinus(env);
+ {if (true) return new CastExpression( p1, p2 );}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression SelfAccess(Environment env) throws ParseException {
+ Expression result;
+ String p1 = null;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = Name();
+ jj_consume_token(DOT);
+ break;
+ default:
+ jj_la1[58] = jj_gen;
+ ;
+ }
+ jj_consume_token(THIS);
+ if (p1 != null) {
+ result = SelfAccess.makeThis( p1 );
+ } else {
+ result = SelfAccess.constantThis();
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ClassLiteral ClassLiteral(Environment env) throws ParseException {
+ TypeName p1;
+ p1 = Type(env);
+ jj_consume_token(DOT);
+ jj_consume_token(CLASS);
+ {if (true) return new ClassLiteral( p1 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression PrimaryExpression(Environment env) throws ParseException {
+ Expression result;
+ Expression p1;
+ Expression p2;
+ Expression p3;
+ String p4;
+ ExpressionList p5;
+ p1 = PrimaryPrefix(env);
+ result = p1;
+ label_38:
+ while (true) {
+ if (jj_2_30(2147483647)) {
+ ;
+ } else {
+ break label_38;
+ }
+ if (jj_2_31(2147483647)) {
+ jj_consume_token(DOT);
+ p2 = AllocationExpression(env);
+ AllocationExpression alloc = (AllocationExpression) p2;
+ alloc.setEncloser( result );
+ result = alloc;
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACKET:
+ jj_consume_token(LBRACKET);
+ p3 = Expression(env);
+ jj_consume_token(RBRACKET);
+ result = new ArrayAccess( result, p3 );
+ break;
+ case DOT:
+ jj_consume_token(DOT);
+ p4 = Identifier();
+ result = new FieldAccess( result, p4 );
+ break;
+ case LPAREN:
+ p5 = Arguments(env);
+ FieldAccess base = (FieldAccess) result;
+ Expression expr = base.getReferenceExpr();
+ String name = base.getName();
+ result = new MethodCall( expr, name, p5 );
+ break;
+ default:
+ jj_la1[59] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression PrimaryPrefix(Environment env) throws ParseException {
+ Expression p1;
+ String p2;
+
+ DebugOut.println( "#PrimaryPrefix()" );
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case FALSE:
+ case NULL:
+ case TRUE:
+ case INTEGER_LITERAL:
+ case LONG_LITERAL:
+ case DOUBLE_FLOATING_POINT_LITERAL:
+ case FLOATING_POINT_LITERAL:
+ case CHARACTER_LITERAL:
+ case STRING_LITERAL:
+ p1 = Literal();
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[60] = jj_gen;
+ if (jj_2_32(2147483647)) {
+ p1 = SelfAccess(env);
+ {if (true) return p1;}
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case SUPER:
+ jj_consume_token(SUPER);
+ jj_consume_token(DOT);
+ p2 = Identifier();
+ {if (true) return new FieldAccess( SelfAccess.constantSuper(), p2 );}
+ break;
+ case LPAREN:
+ jj_consume_token(LPAREN);
+ p1 = Expression(env);
+ jj_consume_token(RPAREN);
+ {if (true) return p1;}
+ break;
+ case NEW:
+ p1 = AllocationExpression(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[61] = jj_gen;
+ if (ClassLiteralLookahead()) {
+ p1 = ClassLiteral(env);
+ {if (true) return p1;}
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = TempFieldAccess(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[62] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ }
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public FieldAccess TempFieldAccess(Environment env) throws ParseException {
+ FieldAccess result;
+ String p1;
+ StringBuffer strbuf = null;
+ p1 = Identifier();
+ label_39:
+ while (true) {
+ if (jj_2_33(2147483647)) {
+ ;
+ } else {
+ break label_39;
+ }
+ jj_consume_token(DOT);
+ if (strbuf == null) {
+ strbuf = new StringBuffer( p1 );
+ } else {
+ strbuf.append( "." + p1 );
+ }
+ p1 = Identifier();
+ }
+ if (strbuf == null || strbuf.length() == 0) {
+ result = new FieldAccess( (Variable) null, p1 );
+ } else {
+ Variable var = new Variable( strbuf.toString() );
+ result = new FieldAccess( var, p1 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Literal Literal() throws ParseException {
+ String p1;
+ Literal p2;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INTEGER_LITERAL:
+ jj_consume_token(INTEGER_LITERAL);
+ p1 = getToken( 0 ).image;
+ {if (true) return new Literal( Literal.INTEGER, p1 );}
+ break;
+ case LONG_LITERAL:
+ jj_consume_token(LONG_LITERAL);
+ p1 = getToken( 0 ).image;
+ {if (true) return new Literal( Literal.LONG, p1 );}
+ break;
+ case FLOATING_POINT_LITERAL:
+ jj_consume_token(FLOATING_POINT_LITERAL);
+ p1 = getToken( 0 ).image;
+ {if (true) return new Literal( Literal.FLOAT, p1 );}
+ break;
+ case DOUBLE_FLOATING_POINT_LITERAL:
+ jj_consume_token(DOUBLE_FLOATING_POINT_LITERAL);
+ p1 = getToken( 0 ).image;
+ {if (true) return new Literal( Literal.DOUBLE, p1 );}
+ break;
+ case CHARACTER_LITERAL:
+ jj_consume_token(CHARACTER_LITERAL);
+ p1 = getToken( 0 ).image;
+ {if (true) return new Literal( Literal.CHARACTER, p1 );}
+ break;
+ case STRING_LITERAL:
+ jj_consume_token(STRING_LITERAL);
+ p1 = getToken( 0 ).image;
+ {if (true) return new Literal( Literal.STRING, p1 );}
+ break;
+ case TRUE:
+ jj_consume_token(TRUE);
+ {if (true) return Literal.constantTrue();}
+ break;
+ case FALSE:
+ jj_consume_token(FALSE);
+ {if (true) return Literal.constantFalse();}
+ break;
+ case NULL:
+ jj_consume_token(NULL);
+ {if (true) return Literal.constantNull();}
+ break;
+ default:
+ jj_la1[63] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ExpressionList Arguments(Environment env) throws ParseException {
+ ExpressionList result = new ExpressionList();
+ Expression p1;
+
+ DebugOut.println( "#Arguments()" );
+ jj_consume_token(LPAREN);
+ if (jj_2_34(1)) {
+ p1 = Expression(env);
+ result.add( p1 );
+ label_40:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[64] = jj_gen;
+ break label_40;
+ }
+ jj_consume_token(COMMA);
+ p1 = Expression(env);
+ result.add( p1 );
+ }
+ } else {
+ ;
+ }
+ jj_consume_token(RPAREN);
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression AllocationExpression(Environment env) throws ParseException {
+ Expression result;
+ AllocationExpression aloc_result;
+ TypeName p1;
+ ArrayAllocationExpression p2;
+ ExpressionList p3;
+ MemberDeclarationList p4 = null;
+
+ DebugOut.println( "#AllocationExpression()" );
+ if (jj_2_36(2147483647)) {
+ jj_consume_token(NEW);
+ p1 = TypeWithoutDims(env);
+ p2 = ArrayDimsAndInits(env, p1);
+ result = p2;
+ {if (true) return result;}
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case NEW:
+ jj_consume_token(NEW);
+ p1 = TypeWithoutDims(env);
+ if (jj_2_35(2147483647)) {
+ p2 = ArrayDimsAndInits(env, p1);
+ result = p2;
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LPAREN:
+ p3 = Arguments(env);
+ aloc_result = new AllocationExpression( p1, p3, p4 );
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p4 = ClassBody(new ClassEnvironment( env ));
+ aloc_result.setClassBody( p4 );
+ break;
+ default:
+ jj_la1[65] = jj_gen;
+ ;
+ }
+ result = aloc_result;
+ break;
+ default:
+ jj_la1[66] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ {if (true) return result;}
+ break;
+ default:
+ jj_la1[67] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TypeName TypeWithoutDims(Environment env) throws ParseException {
+ String p1;
+ Hashtable p2;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BOOLEAN:
+ case BYTE:
+ case CHAR:
+ case DOUBLE:
+ case FLOAT:
+ case INT:
+ case LONG:
+ case SHORT:
+ case VOID:
+ p1 = PrimitiveType();
+ break;
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = Name();
+ break;
+ default:
+ jj_la1[68] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ p2 = OpenJavaTypeSuffixListOpt(env, p1);
+ {if (true) return new TypeName( p1, p2 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ArrayAllocationExpression ArrayDimsAndInits(Environment env, TypeName type) throws ParseException {
+ Expression p1;
+ int p2;
+ ArrayInitializer p3;
+ ExpressionList exprs = new ExpressionList();
+ if (jj_2_37(2147483647)) {
+ p2 = EmptyBracketsOpt();
+ p3 = ArrayInitializer(env);
+ for (int i = 0; i < p2; ++i) exprs.add( null );
+ {if (true) return new ArrayAllocationExpression( type, exprs, p3 );}
+ } else if (jj_2_38(2147483647)) {
+ label_41:
+ while (true) {
+ jj_consume_token(LBRACKET);
+ p1 = Expression(env);
+ exprs.add( p1 );
+ jj_consume_token(RBRACKET);
+ if ((getToken( 1 ).kind == LBRACKET
+ && getToken( 2 ).kind != RBRACKET)) {
+ ;
+ } else {
+ break label_41;
+ }
+ }
+ p2 = EmptyBracketsOpt();
+ for (int i = 0; i < p2; ++i) exprs.add( null );
+ {if (true) return new ArrayAllocationExpression( type, exprs );}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public StatementList BlockedBody(Environment env) throws ParseException {
+ StatementList p1;
+ jj_consume_token(LBRACE);
+ p1 = BlockOrStatementListOpt(env);
+ jj_consume_token(RBRACE);
+ {if (true) return p1;}
+ throw new Error("Missing return statement in function");
+ }
+
+/*
+ * Statement syntax follows.
+ */
+ final public Statement Statement(Environment env) throws ParseException {
+ Statement p1;
+ if (jj_2_39(2147483647)) {
+ p1 = LabeledStatement(env);
+ {if (true) return p1;}
+ } else {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p1 = Block(env);
+ {if (true) return p1;}
+ break;
+ case SEMICOLON:
+ p1 = EmptyStatement(env);
+ {if (true) return p1;}
+ break;
+ case SWITCH:
+ p1 = SwitchStatement(env);
+ {if (true) return p1;}
+ break;
+ case IF:
+ p1 = IfStatement(env);
+ {if (true) return p1;}
+ break;
+ case WHILE:
+ p1 = WhileStatement(env);
+ {if (true) return p1;}
+ break;
+ case DO:
+ p1 = DoWhileStatement(env);
+ {if (true) return p1;}
+ break;
+ case FOR:
+ p1 = ForStatement(env);
+ {if (true) return p1;}
+ break;
+ case BREAK:
+ p1 = BreakStatement(env);
+ {if (true) return p1;}
+ break;
+ case CONTINUE:
+ p1 = ContinueStatement(env);
+ {if (true) return p1;}
+ break;
+ case RETURN:
+ p1 = ReturnStatement(env);
+ {if (true) return p1;}
+ break;
+ case THROW:
+ p1 = ThrowStatement(env);
+ {if (true) return p1;}
+ break;
+ case SYNCHRONIZED:
+ p1 = SynchronizedStatement(env);
+ {if (true) return p1;}
+ break;
+ case TRY:
+ p1 = TryStatement(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[69] = jj_gen;
+ if (jj_2_40(1)) {
+ p1 = ExpressionStatement(env);
+ {if (true) return p1;}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public LabeledStatement LabeledStatement(Environment env) throws ParseException {
+ String p1;
+ Statement p2;
+
+ DebugOut.println( "#LabeledStatement()" );
+ p1 = Identifier();
+ jj_consume_token(COLON);
+ p2 = Statement(env);
+ {if (true) return new LabeledStatement( p1, p2 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Block Block(Environment env) throws ParseException {
+ StatementList p1;
+ DebugOut.println( "#Block()" );
+ jj_consume_token(LBRACE);
+ p1 = BlockOrStatementListOpt(env);
+ jj_consume_token(RBRACE);
+ {if (true) return new Block( p1 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public StatementList BlockOrStatementListOpt(Environment env) throws ParseException {
+ StatementList result = new StatementList();
+ StatementList p1;
+ if ((getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF
+ && getToken( 1 ).kind != CASE
+ && getToken( 1 ).kind != _DEFAULT )) {
+ label_42:
+ while (true) {
+ p1 = BlockOrStatement(env);
+ result.addAll( p1 );
+ if ((getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF
+ && getToken( 1 ).kind != CASE
+ && getToken( 1 ).kind != _DEFAULT )) {
+ ;
+ } else {
+ break label_42;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public StatementList BlockOrStatement(Environment env) throws ParseException {
+ Statement p1;
+ StatementList p2;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CLASS:
+ p1 = UnmodifiedClassDeclaration(new ClassEnvironment( env ));
+ {if (true) return new StatementList( p1 );}
+ break;
+ default:
+ jj_la1[70] = jj_gen;
+ if (LocalVariableDeclarationLookahead( env )) {
+ p2 = LocalVariableDeclaration(env);
+ jj_consume_token(SEMICOLON);
+ {if (true) return p2;}
+ } else if (jj_2_41(1)) {
+ p1 = Statement(env);
+ {if (true) return new StatementList( p1 );}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public StatementList LocalVariableDeclaration(Environment env) throws ParseException {
+ StatementList result = new StatementList();
+ ModifierList p1;
+ TypeName p2;
+ VariableDeclarator p3;
+ TypeName tspec;
+ String vname;
+ VariableInitializer vinit;
+ DebugOut.println( "#LocalVariableDeclaration()" );
+ p1 = VariableModifiersOpt(env);
+ p2 = Type(env);
+ p3 = VariableDeclarator(env);
+ tspec = (TypeName) p2.makeRecursiveCopy();
+ tspec.addDimension( p3.getDimension() );
+ vname = p3.getVariable();
+ vinit = p3.getInitializer();
+ result.add( new VariableDeclaration( p1, tspec, vname, vinit ) );
+ label_43:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[71] = jj_gen;
+ break label_43;
+ }
+ jj_consume_token(COMMA);
+ p3 = VariableDeclarator(env);
+ tspec = (TypeName) p2.makeRecursiveCopy();
+ tspec.addDimension( p3.getDimension() );
+ vname = p3.getVariable();
+ vinit = p3.getInitializer();
+ result.add( new VariableDeclaration( p1, tspec, vname, vinit ) );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ModifierList VariableModifiersOpt(Environment env) throws ParseException {
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+ if (modifierCheck( env, getToken( 1 ) )) {
+ label_44:
+ while (true) {
+ if (jj_2_42(2147483647)) {
+ p1 = Modifier();
+ result.add( p1 );
+ } else if (OpenJavaModifierLookahead( env )) {
+ p2 = OpenJavaModifier();
+ result.add( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ if (ModifierLookahead( env )) {
+ ;
+ } else {
+ break label_44;
+ }
+ }
+ {if (true) return result;}
+ } else {
+ E();
+ {if (true) return result;}
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public EmptyStatement EmptyStatement(Environment env) throws ParseException {
+ DebugOut.println( "#EmptyStatement()" );
+ jj_consume_token(SEMICOLON);
+ {if (true) return new EmptyStatement();}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ExpressionStatement ExpressionStatement(Environment env) throws ParseException {
+ Expression p1;
+
+ DebugOut.println( "#ExpressionStatement()" );
+ p1 = StatementExpression(env);
+ jj_consume_token(SEMICOLON);
+ {if (true) return new ExpressionStatement( p1 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression StatementExpression(Environment env) throws ParseException {
+ Expression p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INCR:
+ case DECR:
+ p1 = PreIncrementExpression(env);
+ {if (true) return p1;}
+ break;
+ default:
+ jj_la1[72] = jj_gen;
+ if (AssignmentLookahead()) {
+ p1 = AssignmentExpression(env);
+ {if (true) return p1;}
+ } else if (jj_2_43(1)) {
+ p1 = PostfixExpression(env);
+ {if (true) return p1;}
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public SwitchStatement SwitchStatement(Environment env) throws ParseException {
+ Expression p1;
+ Expression p2;
+ StatementList p3;
+ CaseGroupList cplist = new CaseGroupList();
+ ExpressionList exprs;
+
+ DebugOut.println( "#SwitchStatement()" );
+ jj_consume_token(SWITCH);
+ jj_consume_token(LPAREN);
+ p1 = Expression(env);
+ jj_consume_token(RPAREN);
+ jj_consume_token(LBRACE);
+ label_45:
+ while (true) {
+ if (jj_2_44(2147483647)) {
+ ;
+ } else {
+ break label_45;
+ }
+ exprs = new ExpressionList();
+ label_46:
+ while (true) {
+ p2 = SwitchLabel(env);
+ exprs.add( p2 );
+ if (jj_2_45(2147483647)) {
+ ;
+ } else {
+ break label_46;
+ }
+ }
+ p3 = BlockOrStatementListOpt(env);
+ cplist.add( new CaseGroup( exprs, p3 ) );
+ }
+ jj_consume_token(RBRACE);
+ {if (true) return new SwitchStatement( p1, cplist );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public Expression SwitchLabel(Environment env) throws ParseException {
+ Expression p1;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case CASE:
+ jj_consume_token(CASE);
+ p1 = Expression(env);
+ jj_consume_token(COLON);
+ {if (true) return p1;}
+ break;
+ case _DEFAULT:
+ jj_consume_token(_DEFAULT);
+ jj_consume_token(COLON);
+ {if (true) return null;}
+ break;
+ default:
+ jj_la1[73] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public IfStatement IfStatement(Environment env) throws ParseException {
+ IfStatement result;
+ Expression p1;
+ StatementList p2;
+ Statement p3;
+ StatementList true_part;
+ StatementList false_part = null;
+
+ DebugOut.println( "#IfStatement()" );
+ jj_consume_token(IF);
+ jj_consume_token(LPAREN);
+ p1 = Expression(env);
+ jj_consume_token(RPAREN);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p2 = BlockedBody(env);
+ true_part = p2;
+ break;
+ default:
+ jj_la1[74] = jj_gen;
+ if (jj_2_46(1)) {
+ p3 = Statement(env);
+ true_part = new StatementList( p3 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ELSE:
+ jj_consume_token(ELSE);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p2 = BlockedBody(env);
+ false_part = p2;
+ break;
+ default:
+ jj_la1[75] = jj_gen;
+ if (jj_2_47(1)) {
+ p3 = Statement(env);
+ false_part = new StatementList( p3 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ break;
+ default:
+ jj_la1[76] = jj_gen;
+ ;
+ }
+ {if (true) return new IfStatement( p1, true_part, false_part );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public WhileStatement WhileStatement(Environment env) throws ParseException {
+ Expression p1;
+ StatementList p2;
+ Statement p3;
+ StatementList body;
+
+ DebugOut.println( "#WhileStatement()" );
+ jj_consume_token(WHILE);
+ jj_consume_token(LPAREN);
+ p1 = Expression(env);
+ jj_consume_token(RPAREN);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p2 = BlockedBody(env);
+ body = p2;
+ break;
+ default:
+ jj_la1[77] = jj_gen;
+ if (jj_2_48(1)) {
+ p3 = Statement(env);
+ body = new StatementList( p3 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ {if (true) return new WhileStatement( p1, body );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public DoWhileStatement DoWhileStatement(Environment env) throws ParseException {
+ StatementList p1;
+ Statement p2;
+ Expression p3;
+ StatementList body;
+
+ DebugOut.println( "#DoWhileStatement()" );
+ jj_consume_token(DO);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p1 = BlockedBody(env);
+ body = p1;
+ break;
+ default:
+ jj_la1[78] = jj_gen;
+ if (jj_2_49(1)) {
+ p2 = Statement(env);
+ body = new StatementList( p2 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ jj_consume_token(WHILE);
+ jj_consume_token(LPAREN);
+ p3 = Expression(env);
+ jj_consume_token(RPAREN);
+ jj_consume_token(SEMICOLON);
+ {if (true) return new DoWhileStatement( body, p3 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ForStatement ForStatement(Environment env) throws ParseException {
+ ForStatement result;
+ TypeName p1 = null;
+ VariableDeclarator[] p2 = null;
+ ExpressionList p3 = null;
+ Expression p4 = null;
+ ExpressionList p5 = null;
+ StatementList p6;
+ Statement p7;
+ StatementList body;
+
+ DebugOut.println( "#ForStatement()" );
+ jj_consume_token(FOR);
+ jj_consume_token(LPAREN);
+ if ((getToken( 1 ).kind != SEMICOLON)) {
+ if (LocalVariableDeclarationLookahead( env )) {
+ p1 = Type(env);
+ p2 = VariableDeclaratorList(env);
+ } else if (jj_2_50(1)) {
+ p3 = StatementExpressionList(env);
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ } else {
+ ;
+ }
+ jj_consume_token(SEMICOLON);
+ if ((getToken( 1 ).kind != SEMICOLON)) {
+ p4 = Expression(env);
+ } else {
+ ;
+ }
+ jj_consume_token(SEMICOLON);
+ if ((getToken( 1 ).kind != RPAREN)) {
+ p5 = StatementExpressionList(env);
+ } else {
+ ;
+ }
+ jj_consume_token(RPAREN);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LBRACE:
+ p6 = BlockedBody(env);
+ body = p6;
+ break;
+ default:
+ jj_la1[79] = jj_gen;
+ if (jj_2_51(1)) {
+ p7 = Statement(env);
+ body = new StatementList( p7 );
+ } else {
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ }
+ if (p1 != null) {
+ result = new ForStatement( p1, p2, p4, p5, body );
+ } else if (p3 != null) {
+ result = new ForStatement( p3, p4, p5, body );
+ } else {
+ result = new ForStatement( new ExpressionList(), p4, p5, body );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public VariableDeclarator[] VariableDeclaratorList(Environment env) throws ParseException {
+ VariableDeclarator[] result;
+ VariableDeclarator p1;
+ Vector v = new Vector();
+
+ DebugOut.println( "#LocalVariableDeclaration()" );
+ p1 = VariableDeclarator(env);
+ v.addElement( p1 );
+ label_47:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[80] = jj_gen;
+ break label_47;
+ }
+ jj_consume_token(COMMA);
+ p1 = VariableDeclarator(env);
+ v.addElement( p1 );
+ }
+ result = new VariableDeclarator[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (VariableDeclarator) v.elementAt( i );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ExpressionList StatementExpressionList(Environment env) throws ParseException {
+ ExpressionList result = new ExpressionList();
+ Expression p1;
+ p1 = StatementExpression(env);
+ result.add( p1 );
+ label_48:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[81] = jj_gen;
+ break label_48;
+ }
+ jj_consume_token(COMMA);
+ p1 = StatementExpression(env);
+ result.add( p1 );
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public BreakStatement BreakStatement(Environment env) throws ParseException {
+ BreakStatement result;
+ String p1 = null;
+
+ DebugOut.println( "#BreakStatement()" );
+ jj_consume_token(BREAK);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = Identifier();
+ break;
+ default:
+ jj_la1[82] = jj_gen;
+ ;
+ }
+ jj_consume_token(SEMICOLON);
+ if (p1 != null) {
+ result = new BreakStatement( p1 );
+ } else {
+ result = new BreakStatement();
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ContinueStatement ContinueStatement(Environment env) throws ParseException {
+ ContinueStatement result;
+ String p1 = null;
+
+ DebugOut.println( "#ContinueStatement()" );
+ jj_consume_token(CONTINUE);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case METACLASS:
+ case IDENTIFIER:
+ p1 = Identifier();
+ break;
+ default:
+ jj_la1[83] = jj_gen;
+ ;
+ }
+ jj_consume_token(SEMICOLON);
+ if (p1 != null) {
+ result = new ContinueStatement( p1 );
+ } else {
+ result = new ContinueStatement();
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ReturnStatement ReturnStatement(Environment env) throws ParseException {
+ ReturnStatement result;
+ Expression p1 = null;
+
+ DebugOut.println( "#ReturnStatement()" );
+ jj_consume_token(RETURN);
+ if ((getToken(1).kind != SEMICOLON)) {
+ p1 = Expression(env);
+ } else {
+ ;
+ }
+ jj_consume_token(SEMICOLON);
+ if (p1 != null) {
+ result = new ReturnStatement( p1 );
+ } else {
+ result = new ReturnStatement();
+ }
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public ThrowStatement ThrowStatement(Environment env) throws ParseException {
+ Statement result;
+ Expression p1;
+
+ DebugOut.println( "#ThrowStatement()" );
+ jj_consume_token(THROW);
+ p1 = Expression(env);
+ jj_consume_token(SEMICOLON);
+ {if (true) return new ThrowStatement( p1 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public SynchronizedStatement SynchronizedStatement(Environment env) throws ParseException {
+ Expression p1;
+ StatementList p2;
+
+ DebugOut.println( "#SynchronizedStatement()" );
+ jj_consume_token(SYNCHRONIZED);
+ jj_consume_token(LPAREN);
+ p1 = Expression(env);
+ jj_consume_token(RPAREN);
+ p2 = BlockedBody(env);
+ {if (true) return new SynchronizedStatement( p1, p2 );}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public TryStatement TryStatement(Environment base_env) throws ParseException {
+ Environment env = new ClosedEnvironment( base_env );
+ TryStatement result;
+ StatementList p1;
+ Parameter p2;
+ StatementList p3;
+ StatementList p4 = null;
+ CatchList catches = new CatchList();
+
+ DebugOut.println( "#TryStatement()" );
+ jj_consume_token(TRY);
+ p1 = BlockedBody(env);
+ label_49:
+ while (true) {
+ if (jj_2_52(2147483647)) {
+ ;
+ } else {
+ break label_49;
+ }
+ env = new ClosedEnvironment( base_env );
+ jj_consume_token(CATCH);
+ jj_consume_token(LPAREN);
+ p2 = FormalParameter(env);
+ jj_consume_token(RPAREN);
+ p3 = BlockedBody(env);
+ catches.add( new CatchBlock( p2, p3 ) );
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case FINALLY:
+ jj_consume_token(FINALLY);
+ p4 = BlockedBody(new ClosedEnvironment( base_env ));
+ break;
+ default:
+ jj_la1[84] = jj_gen;
+ ;
+ }
+ result = new TryStatement( p1, catches, p4 );
+ {if (true) return result;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final private boolean jj_2_1(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_1();
+ jj_save(0, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_2(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_2();
+ jj_save(1, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_3(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_3();
+ jj_save(2, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_4(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_4();
+ jj_save(3, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_5(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_5();
+ jj_save(4, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_6(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_6();
+ jj_save(5, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_7(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_7();
+ jj_save(6, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_8(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_8();
+ jj_save(7, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_9(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_9();
+ jj_save(8, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_10(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_10();
+ jj_save(9, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_11(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_11();
+ jj_save(10, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_12(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_12();
+ jj_save(11, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_13(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_13();
+ jj_save(12, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_14(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_14();
+ jj_save(13, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_15(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_15();
+ jj_save(14, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_16(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_16();
+ jj_save(15, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_17(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_17();
+ jj_save(16, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_18(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_18();
+ jj_save(17, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_19(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_19();
+ jj_save(18, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_20(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_20();
+ jj_save(19, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_21(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_21();
+ jj_save(20, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_22(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_22();
+ jj_save(21, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_23(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_23();
+ jj_save(22, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_24(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_24();
+ jj_save(23, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_25(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_25();
+ jj_save(24, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_26(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_26();
+ jj_save(25, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_27(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_27();
+ jj_save(26, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_28(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_28();
+ jj_save(27, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_29(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_29();
+ jj_save(28, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_30(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_30();
+ jj_save(29, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_31(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_31();
+ jj_save(30, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_32(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_32();
+ jj_save(31, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_33(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_33();
+ jj_save(32, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_34(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_34();
+ jj_save(33, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_35(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_35();
+ jj_save(34, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_36(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_36();
+ jj_save(35, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_37(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_37();
+ jj_save(36, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_38(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_38();
+ jj_save(37, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_39(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_39();
+ jj_save(38, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_40(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_40();
+ jj_save(39, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_41(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_41();
+ jj_save(40, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_42(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_42();
+ jj_save(41, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_43(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_43();
+ jj_save(42, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_44(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_44();
+ jj_save(43, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_45(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_45();
+ jj_save(44, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_46(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_46();
+ jj_save(45, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_47(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_47();
+ jj_save(46, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_48(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_48();
+ jj_save(47, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_49(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_49();
+ jj_save(48, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_50(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_50();
+ jj_save(49, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_51(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_51();
+ jj_save(50, xla);
+ return retval;
+ }
+
+ final private boolean jj_2_52(int xla) {
+ jj_la = xla; jj_lastpos = jj_scanpos = token;
+ boolean retval = !jj_3_52();
+ jj_save(51, xla);
+ return retval;
+ }
+
+ final private boolean jj_3R_133() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_31() {
+ if (jj_scan_token(DOT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(NEW)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_14() {
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_101() {
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_30() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_100()) {
+ jj_scanpos = xsp;
+ if (jj_3R_101()) {
+ jj_scanpos = xsp;
+ if (jj_3R_102()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_100() {
+ if (jj_scan_token(DOT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_13() {
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_52() {
+ if (jj_scan_token(CATCH)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_132() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_135() {
+ if (jj_3R_166()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_86() {
+ if (jj_scan_token(INTERFACE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_141() {
+ if (jj_3R_178()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_194() {
+ if (jj_scan_token(TRY)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_85() {
+ if (jj_scan_token(CLASS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_84() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_131()) {
+ jj_scanpos = xsp;
+ if (jj_3R_132()) {
+ jj_scanpos = xsp;
+ if (jj_3R_133()) {
+ jj_scanpos = xsp;
+ if (jj_3R_134()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_131() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_12() {
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_84()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ xsp = jj_scanpos;
+ if (jj_3R_85()) {
+ jj_scanpos = xsp;
+ if (jj_3R_86()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_207() {
+ if (jj_3R_141()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_220() {
+ if (jj_3R_228()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_193() {
+ if (jj_scan_token(SYNCHRONIZED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_177() {
+ if (jj_3R_198()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_54() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_176() {
+ if (jj_scan_token(NEW)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_225() {
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_41() {
+ if (jj_3R_105()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_218() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_225()) jj_scanpos = xsp;
+ else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(THIS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_29() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_192() {
+ if (jj_scan_token(THROW)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_87() {
+ if (jj_3R_135()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_28() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_98()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_175() {
+ if (jj_scan_token(SUPER)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_83() {
+ if (jj_scan_token(PRIVATE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_197() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_52() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_3() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_52()) {
+ jj_scanpos = xsp;
+ if (jj_3R_53()) {
+ jj_scanpos = xsp;
+ if (jj_3R_54()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_80() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_196() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_169() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_196()) {
+ jj_scanpos = xsp;
+ if (jj_3R_197()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_174() {
+ if (jj_scan_token(THIS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_82() {
+ if (jj_scan_token(PROTECTED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_191() {
+ if (jj_scan_token(RETURN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_79() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_173() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_81() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_11() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_78()) {
+ jj_scanpos = xsp;
+ if (jj_3R_79()) {
+ jj_scanpos = xsp;
+ if (jj_3R_80()) {
+ jj_scanpos = xsp;
+ if (jj_3R_81()) {
+ jj_scanpos = xsp;
+ if (jj_3R_82()) {
+ jj_scanpos = xsp;
+ if (jj_3R_83()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_78() {
+ if (jj_scan_token(STATIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_172() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_182() {
+ if (jj_scan_token(LBRACE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_97() {
+ if (jj_3R_141()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_171() {
+ if (jj_scan_token(BANG)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_27() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_190() {
+ if (jj_scan_token(CONTINUE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_26() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_170() {
+ if (jj_scan_token(TILDE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_140() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_181() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_147() {
+ if (jj_scan_token(LONG)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_139() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_170()) {
+ jj_scanpos = xsp;
+ if (jj_3R_171()) {
+ jj_scanpos = xsp;
+ if (jj_3R_172()) {
+ jj_scanpos = xsp;
+ if (jj_3R_173()) {
+ jj_scanpos = xsp;
+ if (jj_3R_174()) {
+ jj_scanpos = xsp;
+ if (jj_3R_175()) {
+ jj_scanpos = xsp;
+ if (jj_3R_176()) {
+ jj_scanpos = xsp;
+ if (jj_3R_177()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_138() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_146() {
+ if (jj_scan_token(INT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_25() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_98()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_96() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3_25()) {
+ jj_scanpos = xsp;
+ if (jj_3R_138()) {
+ jj_scanpos = xsp;
+ if (jj_3R_139()) {
+ jj_scanpos = xsp;
+ if (jj_3R_140()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_23() {
+ if (jj_3R_96()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_77() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_40() {
+ if (jj_3R_104()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_189() {
+ if (jj_scan_token(BREAK)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_165() {
+ if (jj_3R_194()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_24() {
+ if (jj_3R_97()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_164() {
+ if (jj_3R_193()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_145() {
+ if (jj_scan_token(SHORT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_163() {
+ if (jj_3R_192()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_137() {
+ if (jj_3R_169()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_168() {
+ if (jj_scan_token(BANG)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_150() {
+ if (jj_scan_token(VOID)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_167() {
+ if (jj_scan_token(TILDE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_162() {
+ if (jj_3R_191()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_10() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_76()) {
+ jj_scanpos = xsp;
+ if (jj_3R_77()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_75() {
+ if (jj_scan_token(SYNCHRONIZED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_76() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_161() {
+ if (jj_3R_190()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_144() {
+ if (jj_scan_token(BYTE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_95() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_136()) {
+ jj_scanpos = xsp;
+ if (jj_3R_137()) {
+ jj_scanpos = xsp;
+ if (jj_3_24()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_136() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_167()) {
+ jj_scanpos = xsp;
+ if (jj_3R_168()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_160() {
+ if (jj_3R_189()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_110() {
+ if (jj_3R_151()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_19() {
+ if (jj_scan_token(DOT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_159() {
+ if (jj_3R_188()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_149() {
+ if (jj_scan_token(DOUBLE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_99() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3_19()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_158() {
+ if (jj_3R_187()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_74() {
+ if (jj_scan_token(NATIVE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_223() {
+ if (jj_scan_token(DECR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_143() {
+ if (jj_scan_token(CHAR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_222() {
+ if (jj_scan_token(INCR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_157() {
+ if (jj_3R_186()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_71() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_94() {
+ if (jj_scan_token(DECR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_68() {
+ if (jj_scan_token(PRIVATE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_231() {
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_156() {
+ if (jj_3R_185()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_206() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_222()) {
+ jj_scanpos = xsp;
+ if (jj_3R_223()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_148() {
+ if (jj_scan_token(FLOAT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_39() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(COLON)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_155() {
+ if (jj_3R_184()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_21() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_93()) {
+ jj_scanpos = xsp;
+ if (jj_3R_94()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_93() {
+ if (jj_scan_token(INCR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_154() {
+ if (jj_3R_183()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_142() {
+ if (jj_scan_token(BOOLEAN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_73() {
+ if (jj_scan_token(VOLATILE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_92() {
+ if (jj_scan_token(MINUS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_153() {
+ if (jj_3R_182()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_98() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_142()) {
+ jj_scanpos = xsp;
+ if (jj_3R_143()) {
+ jj_scanpos = xsp;
+ if (jj_3R_144()) {
+ jj_scanpos = xsp;
+ if (jj_3R_145()) {
+ jj_scanpos = xsp;
+ if (jj_3R_146()) {
+ jj_scanpos = xsp;
+ if (jj_3R_147()) {
+ jj_scanpos = xsp;
+ if (jj_3R_148()) {
+ jj_scanpos = xsp;
+ if (jj_3R_149()) {
+ jj_scanpos = xsp;
+ if (jj_3R_150()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_70() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_22() {
+ if (jj_3R_95()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_152() {
+ if (jj_3R_181()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_67() {
+ if (jj_scan_token(PROTECTED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_105() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_152()) {
+ jj_scanpos = xsp;
+ if (jj_3R_153()) {
+ jj_scanpos = xsp;
+ if (jj_3R_154()) {
+ jj_scanpos = xsp;
+ if (jj_3R_155()) {
+ jj_scanpos = xsp;
+ if (jj_3R_156()) {
+ jj_scanpos = xsp;
+ if (jj_3R_157()) {
+ jj_scanpos = xsp;
+ if (jj_3R_158()) {
+ jj_scanpos = xsp;
+ if (jj_3R_159()) {
+ jj_scanpos = xsp;
+ if (jj_3R_160()) {
+ jj_scanpos = xsp;
+ if (jj_3R_161()) {
+ jj_scanpos = xsp;
+ if (jj_3R_162()) {
+ jj_scanpos = xsp;
+ if (jj_3R_163()) {
+ jj_scanpos = xsp;
+ if (jj_3R_164()) {
+ jj_scanpos = xsp;
+ if (jj_3R_165()) {
+ jj_scanpos = xsp;
+ if (jj_3_40()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_20() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_91()) {
+ jj_scanpos = xsp;
+ if (jj_3R_92()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_91() {
+ if (jj_scan_token(PLUS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_240() {
+ if (jj_3R_206()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_242() {
+ if (jj_scan_token(MINUS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_241() {
+ if (jj_scan_token(PLUS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_230() {
+ if (jj_3R_98()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_72() {
+ if (jj_scan_token(TRANSIENT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_69() {
+ if (jj_scan_token(STATIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_228() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_230()) {
+ jj_scanpos = xsp;
+ if (jj_3R_231()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_66() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_9() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_66()) {
+ jj_scanpos = xsp;
+ if (jj_3R_67()) {
+ jj_scanpos = xsp;
+ if (jj_3R_68()) {
+ jj_scanpos = xsp;
+ if (jj_3R_69()) {
+ jj_scanpos = xsp;
+ if (jj_3R_70()) {
+ jj_scanpos = xsp;
+ if (jj_3R_71()) {
+ jj_scanpos = xsp;
+ if (jj_3R_72()) {
+ jj_scanpos = xsp;
+ if (jj_3R_73()) {
+ jj_scanpos = xsp;
+ if (jj_3R_74()) {
+ jj_scanpos = xsp;
+ if (jj_3R_75()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_239() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_241()) {
+ jj_scanpos = xsp;
+ if (jj_3R_242()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_238() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_239()) {
+ jj_scanpos = xsp;
+ if (jj_3R_240()) {
+ jj_scanpos = xsp;
+ if (jj_3_22()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_51() {
+ if (jj_3R_105()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_38() {
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_37() {
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_237() {
+ if (jj_3R_238()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_50() {
+ if (jj_3R_110()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_188() {
+ if (jj_scan_token(FOR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_18() {
+ if (jj_scan_token(THIS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_236() {
+ if (jj_3R_237()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_116() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_115() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_90() {
+ if (jj_scan_token(PRIVATE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_35() {
+ if (jj_scan_token(LBRACKET)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_49() {
+ if (jj_3R_105()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_235() {
+ if (jj_3R_236()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_36() {
+ if (jj_scan_token(NEW)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_98()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_89() {
+ if (jj_scan_token(PROTECTED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_187() {
+ if (jj_scan_token(DO)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_227() {
+ if (jj_scan_token(NEW)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_226() {
+ if (jj_scan_token(NEW)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_219() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_226()) {
+ jj_scanpos = xsp;
+ if (jj_3R_227()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_112() {
+ if (jj_scan_token(METACLASS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_17() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_88()) {
+ jj_scanpos = xsp;
+ if (jj_3R_89()) {
+ jj_scanpos = xsp;
+ if (jj_3R_90()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_88() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_234() {
+ if (jj_3R_235()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_48() {
+ if (jj_3R_105()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_51() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_113()) {
+ jj_scanpos = xsp;
+ if (jj_3R_114()) {
+ jj_scanpos = xsp;
+ if (jj_3R_115()) {
+ jj_scanpos = xsp;
+ if (jj_3R_116()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_50() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_111()) {
+ jj_scanpos = xsp;
+ if (jj_3R_112()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_111() {
+ if (jj_scan_token(IDENTIFIER)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_113() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_8() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_127() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_2() {
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_51()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ if (jj_scan_token(CLASS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_186() {
+ if (jj_scan_token(WHILE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_130() {
+ if (jj_scan_token(PRIVATE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_126() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_34() {
+ if (jj_3R_87()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_233() {
+ if (jj_3R_234()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_47() {
+ if (jj_3R_105()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_125() {
+ if (jj_scan_token(STATIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_129() {
+ if (jj_scan_token(PROTECTED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_65() {
+ if (jj_scan_token(INTERFACE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_46() {
+ if (jj_3R_105()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_217() {
+ if (jj_scan_token(NULL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_232() {
+ if (jj_3R_233()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_216() {
+ if (jj_scan_token(FALSE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_61() {
+ if (jj_scan_token(PRIVATE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_64() {
+ if (jj_scan_token(CLASS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_128() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_215() {
+ if (jj_scan_token(TRUE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_185() {
+ if (jj_scan_token(IF)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_58() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_63() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_124()) {
+ jj_scanpos = xsp;
+ if (jj_3R_125()) {
+ jj_scanpos = xsp;
+ if (jj_3R_126()) {
+ jj_scanpos = xsp;
+ if (jj_3R_127()) {
+ jj_scanpos = xsp;
+ if (jj_3R_128()) {
+ jj_scanpos = xsp;
+ if (jj_3R_129()) {
+ jj_scanpos = xsp;
+ if (jj_3R_130()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_124() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_214() {
+ if (jj_scan_token(STRING_LITERAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_7() {
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_63()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ xsp = jj_scanpos;
+ if (jj_3R_64()) {
+ jj_scanpos = xsp;
+ if (jj_3R_65()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_16() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_213() {
+ if (jj_scan_token(CHARACTER_LITERAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_62() {
+ if (jj_scan_token(STATIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_6() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_62()) jj_scanpos = xsp;
+ else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(LBRACE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_212() {
+ if (jj_scan_token(DOUBLE_FLOATING_POINT_LITERAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_60() {
+ if (jj_scan_token(PROTECTED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_211() {
+ if (jj_scan_token(FLOATING_POINT_LITERAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_109() {
+ if (jj_scan_token(_DEFAULT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_57() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_229() {
+ if (jj_3R_232()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_210() {
+ if (jj_scan_token(LONG_LITERAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_209() {
+ if (jj_scan_token(INTEGER_LITERAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_198() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_209()) {
+ jj_scanpos = xsp;
+ if (jj_3R_210()) {
+ jj_scanpos = xsp;
+ if (jj_3R_211()) {
+ jj_scanpos = xsp;
+ if (jj_3R_212()) {
+ jj_scanpos = xsp;
+ if (jj_3R_213()) {
+ jj_scanpos = xsp;
+ if (jj_3R_214()) {
+ jj_scanpos = xsp;
+ if (jj_3R_215()) {
+ jj_scanpos = xsp;
+ if (jj_3R_216()) {
+ jj_scanpos = xsp;
+ if (jj_3R_217()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_107() {
+ if (jj_scan_token(_DEFAULT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_1() {
+ if (jj_scan_token(DOT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_45() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_108()) {
+ jj_scanpos = xsp;
+ if (jj_3R_109()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_108() {
+ if (jj_scan_token(CASE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_59() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_56() {
+ if (jj_scan_token(STATIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_5() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_56()) {
+ jj_scanpos = xsp;
+ if (jj_3R_57()) {
+ jj_scanpos = xsp;
+ if (jj_3R_58()) {
+ jj_scanpos = xsp;
+ if (jj_3R_59()) {
+ jj_scanpos = xsp;
+ if (jj_3R_60()) {
+ jj_scanpos = xsp;
+ if (jj_3R_61()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_120() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_44() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_106()) {
+ jj_scanpos = xsp;
+ if (jj_3R_107()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_106() {
+ if (jj_scan_token(CASE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_224() {
+ if (jj_3R_229()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_33() {
+ if (jj_scan_token(DOT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_123() {
+ if (jj_scan_token(PRIVATE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_119() {
+ if (jj_scan_token(ABSTRACT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_184() {
+ if (jj_scan_token(SWITCH)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_221() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_118() {
+ if (jj_scan_token(STATIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_208() {
+ if (jj_3R_224()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_122() {
+ if (jj_scan_token(PROTECTED)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_43() {
+ if (jj_3R_97()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_180() {
+ if (jj_3R_207()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_121() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_205() {
+ if (jj_3R_221()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_55() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_117()) {
+ jj_scanpos = xsp;
+ if (jj_3R_118()) {
+ jj_scanpos = xsp;
+ if (jj_3R_119()) {
+ jj_scanpos = xsp;
+ if (jj_3R_120()) {
+ jj_scanpos = xsp;
+ if (jj_3R_121()) {
+ jj_scanpos = xsp;
+ if (jj_3R_122()) {
+ jj_scanpos = xsp;
+ if (jj_3R_123()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_117() {
+ if (jj_3R_50()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_179() {
+ if (jj_3R_206()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_151() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_179()) {
+ jj_scanpos = xsp;
+ lookingAhead = true;
+ jj_semLA = AssignmentLookahead();
+ lookingAhead = false;
+ if (!jj_semLA || jj_3R_180()) {
+ jj_scanpos = xsp;
+ if (jj_3_43()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_4() {
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_55()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ if (jj_scan_token(CLASS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_204() {
+ if (jj_3R_220()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_103() {
+ if (jj_3R_99()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(DOT)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_195() {
+ if (jj_3R_208()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_32() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_103()) jj_scanpos = xsp;
+ else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(THIS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_203() {
+ if (jj_3R_219()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_202() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_104() {
+ if (jj_3R_151()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_201() {
+ if (jj_scan_token(SUPER)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_200() {
+ if (jj_3R_218()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_199() {
+ if (jj_3R_198()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_178() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_199()) {
+ jj_scanpos = xsp;
+ if (jj_3R_200()) {
+ jj_scanpos = xsp;
+ if (jj_3R_201()) {
+ jj_scanpos = xsp;
+ if (jj_3R_202()) {
+ jj_scanpos = xsp;
+ if (jj_3R_203()) {
+ jj_scanpos = xsp;
+ lookingAhead = true;
+ jj_semLA = ClassLiteralLookahead();
+ lookingAhead = false;
+ if (!jj_semLA || jj_3R_204()) {
+ jj_scanpos = xsp;
+ if (jj_3R_205()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_183() {
+ if (jj_scan_token(SEMICOLON)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_166() {
+ if (jj_3R_195()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_134() {
+ if (jj_scan_token(PUBLIC)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_42() {
+ if (jj_scan_token(FINAL)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_102() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3_15() {
+ if (jj_3R_87()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ public ParserTokenManager token_source;
+ JavaCharStream jj_input_stream;
+ public Token token, jj_nt;
+ private int jj_ntk;
+ private Token jj_scanpos, jj_lastpos;
+ private int jj_la;
+ public boolean lookingAhead = false;
+ private boolean jj_semLA;
+ private int jj_gen;
+ final private int[] jj_la1 = new int[85];
+ final private int[] jj_la1_0 = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20002000,0x8000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20002000,0x0,0x82094000,0x82094000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10000000,0x0,0x0,0x0,0x0,0x0,0x10000000,0x0,0x0,0x10000000,0x0,0x0,0x0,0x0,0x82094000,0x1408000,0x100000,0x0,0x0,0x820000,0x0,0x0,0x4000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40000000,};
+ final private int[] jj_la1_1 = {0x0,0x1000,0x10,0x10,0x0,0x0,0x80000000,0x0,0x0,0x80000000,0x0,0x2224e200,0x0,0x8,0x0,0x0,0x0,0x80000000,0x1000000,0x0,0x0,0x0,0x0,0x0,0x2224e200,0x40000,0x90020140,0x10020140,0x0,0x0,0x80000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x84480c00,0x0,0x0,0x0,0x80000000,0x0,0x4000800,0x80400,0x80000000,0x4000800,0x0,0x0,0x0,0x400,0x90020140,0x48b10005,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80000000,0x80000000,0x0,};
+ final private int[] jj_la1_2 = {0x100000,0x0,0x0,0x0,0x400000,0x100000,0x800,0x200000,0x20100000,0x0,0x1,0x0,0x0,0x0,0x100000,0x100000,0x200000,0x800,0x0,0x110000,0x800000,0x10000,0x200000,0x200000,0x0,0x0,0x800,0x0,0x200000,0x200000,0x800,0x800000,0x800000,0x10000000,0x0,0x0,0x0,0x0,0x0,0x40000000,0x40000000,0x0,0x83000000,0x83000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc000000,0xc000000,0xc004ec6,0x4000,0x0,0x0,0x800,0x444000,0x6c6,0x4000,0x800,0x6c6,0x200000,0x10000,0x4000,0x0,0x800,0x110000,0x0,0x200000,0x0,0x0,0x10000,0x10000,0x0,0x10000,0x10000,0x10000,0x200000,0x200000,0x800,0x800,0x0,};
+ final private int[] jj_la1_3 = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xffe0000,0xffe0000,0x0,0x4,0x8,0x800,0x1000,0x400,0x2,0x2,0x0,0x1,0x1,0x1c000,0x1c000,0xc0,0xc0,0x2300,0x2300,0xc0,0x30,0x0,0x0,0x0,0x0,0x30,0x30,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x30,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
+ final private JJCalls[] jj_2_rtns = new JJCalls[52];
+ private boolean jj_rescan = false;
+ private int jj_gc = 0;
+
+ public Parser(java.io.InputStream stream) {
+ jj_input_stream = new JavaCharStream(stream, 1, 1);
+ token_source = new ParserTokenManager(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 85; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public void ReInit(java.io.InputStream stream) {
+ jj_input_stream.ReInit(stream, 1, 1);
+ token_source.ReInit(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 85; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public Parser(java.io.Reader stream) {
+ jj_input_stream = new JavaCharStream(stream, 1, 1);
+ token_source = new ParserTokenManager(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 85; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public void ReInit(java.io.Reader stream) {
+ jj_input_stream.ReInit(stream, 1, 1);
+ token_source.ReInit(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 85; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public Parser(ParserTokenManager tm) {
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 85; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ public void ReInit(ParserTokenManager tm) {
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 85; i++) jj_la1[i] = -1;
+ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
+ }
+
+ final private Token jj_consume_token(int kind) throws ParseException {
+ Token oldToken;
+ if ((oldToken = token).next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ if (token.kind == kind) {
+ jj_gen++;
+ if (++jj_gc > 100) {
+ jj_gc = 0;
+ for (int i = 0; i < jj_2_rtns.length; i++) {
+ JJCalls c = jj_2_rtns[i];
+ while (c != null) {
+ if (c.gen < jj_gen) c.first = null;
+ c = c.next;
+ }
+ }
+ }
+ return token;
+ }
+ token = oldToken;
+ jj_kind = kind;
+ throw generateParseException();
+ }
+
+ final private boolean jj_scan_token(int kind) {
+ if (jj_scanpos == jj_lastpos) {
+ jj_la--;
+ if (jj_scanpos.next == null) {
+ jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
+ } else {
+ jj_lastpos = jj_scanpos = jj_scanpos.next;
+ }
+ } else {
+ jj_scanpos = jj_scanpos.next;
+ }
+ if (jj_rescan) {
+ int i = 0; Token tok = token;
+ while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
+ if (tok != null) jj_add_error_token(kind, i);
+ }
+ return (jj_scanpos.kind != kind);
+ }
+
+ final public Token getNextToken() {
+ if (token.next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ jj_gen++;
+ return token;
+ }
+
+ final public Token getToken(int index) {
+ Token t = lookingAhead ? jj_scanpos : token;
+ for (int i = 0; i < index; i++) {
+ if (t.next != null) t = t.next;
+ else t = t.next = token_source.getNextToken();
+ }
+ return t;
+ }
+
+ final private int jj_ntk() {
+ if ((jj_nt=token.next) == null)
+ return (jj_ntk = (token.next=token_source.getNextToken()).kind);
+ else
+ return (jj_ntk = jj_nt.kind);
+ }
+
+ private java.util.Vector jj_expentries = new java.util.Vector();
+ private int[] jj_expentry;
+ private int jj_kind = -1;
+ private int[] jj_lasttokens = new int[100];
+ private int jj_endpos;
+
+ private void jj_add_error_token(int kind, int pos) {
+ if (pos >= 100) return;
+ if (pos == jj_endpos + 1) {
+ jj_lasttokens[jj_endpos++] = kind;
+ } else if (jj_endpos != 0) {
+ jj_expentry = new int[jj_endpos];
+ for (int i = 0; i < jj_endpos; i++) {
+ jj_expentry[i] = jj_lasttokens[i];
+ }
+ boolean exists = false;
+ for (java.util.Enumeration enum = jj_expentries.elements(); enum.hasMoreElements();) {
+ int[] oldentry = (int[])(enum.nextElement());
+ if (oldentry.length == jj_expentry.length) {
+ exists = true;
+ for (int i = 0; i < jj_expentry.length; i++) {
+ if (oldentry[i] != jj_expentry[i]) {
+ exists = false;
+ break;
+ }
+ }
+ if (exists) break;
+ }
+ }
+ if (!exists) jj_expentries.addElement(jj_expentry);
+ if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
+ }
+ }
+
+ final public ParseException generateParseException() {
+ jj_expentries.removeAllElements();
+ boolean[] la1tokens = new boolean[124];
+ for (int i = 0; i < 124; i++) {
+ la1tokens[i] = false;
+ }
+ if (jj_kind >= 0) {
+ la1tokens[jj_kind] = true;
+ jj_kind = -1;
+ }
+ for (int i = 0; i < 85; i++) {
+ if (jj_la1[i] == jj_gen) {
+ for (int j = 0; j < 32; j++) {
+ if ((jj_la1_0[i] & (1<<j)) != 0) {
+ la1tokens[j] = true;
+ }
+ if ((jj_la1_1[i] & (1<<j)) != 0) {
+ la1tokens[32+j] = true;
+ }
+ if ((jj_la1_2[i] & (1<<j)) != 0) {
+ la1tokens[64+j] = true;
+ }
+ if ((jj_la1_3[i] & (1<<j)) != 0) {
+ la1tokens[96+j] = true;
+ }
+ }
+ }
+ }
+ for (int i = 0; i < 124; i++) {
+ if (la1tokens[i]) {
+ jj_expentry = new int[1];
+ jj_expentry[0] = i;
+ jj_expentries.addElement(jj_expentry);
+ }
+ }
+ jj_endpos = 0;
+ jj_rescan_token();
+ jj_add_error_token(0, 0);
+ int[][] exptokseq = new int[jj_expentries.size()][];
+ for (int i = 0; i < jj_expentries.size(); i++) {
+ exptokseq[i] = (int[])jj_expentries.elementAt(i);
+ }
+ return new ParseException(token, exptokseq, tokenImage);
+ }
+
+ final public void enable_tracing() {
+ }
+
+ final public void disable_tracing() {
+ }
+
+ final private void jj_rescan_token() {
+ jj_rescan = true;
+ for (int i = 0; i < 52; i++) {
+ JJCalls p = jj_2_rtns[i];
+ do {
+ if (p.gen > jj_gen) {
+ jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
+ switch (i) {
+ case 0: jj_3_1(); break;
+ case 1: jj_3_2(); break;
+ case 2: jj_3_3(); break;
+ case 3: jj_3_4(); break;
+ case 4: jj_3_5(); break;
+ case 5: jj_3_6(); break;
+ case 6: jj_3_7(); break;
+ case 7: jj_3_8(); break;
+ case 8: jj_3_9(); break;
+ case 9: jj_3_10(); break;
+ case 10: jj_3_11(); break;
+ case 11: jj_3_12(); break;
+ case 12: jj_3_13(); break;
+ case 13: jj_3_14(); break;
+ case 14: jj_3_15(); break;
+ case 15: jj_3_16(); break;
+ case 16: jj_3_17(); break;
+ case 17: jj_3_18(); break;
+ case 18: jj_3_19(); break;
+ case 19: jj_3_20(); break;
+ case 20: jj_3_21(); break;
+ case 21: jj_3_22(); break;
+ case 22: jj_3_23(); break;
+ case 23: jj_3_24(); break;
+ case 24: jj_3_25(); break;
+ case 25: jj_3_26(); break;
+ case 26: jj_3_27(); break;
+ case 27: jj_3_28(); break;
+ case 28: jj_3_29(); break;
+ case 29: jj_3_30(); break;
+ case 30: jj_3_31(); break;
+ case 31: jj_3_32(); break;
+ case 32: jj_3_33(); break;
+ case 33: jj_3_34(); break;
+ case 34: jj_3_35(); break;
+ case 35: jj_3_36(); break;
+ case 36: jj_3_37(); break;
+ case 37: jj_3_38(); break;
+ case 38: jj_3_39(); break;
+ case 39: jj_3_40(); break;
+ case 40: jj_3_41(); break;
+ case 41: jj_3_42(); break;
+ case 42: jj_3_43(); break;
+ case 43: jj_3_44(); break;
+ case 44: jj_3_45(); break;
+ case 45: jj_3_46(); break;
+ case 46: jj_3_47(); break;
+ case 47: jj_3_48(); break;
+ case 48: jj_3_49(); break;
+ case 49: jj_3_50(); break;
+ case 50: jj_3_51(); break;
+ case 51: jj_3_52(); break;
+ }
+ }
+ p = p.next;
+ } while (p != null);
+ }
+ jj_rescan = false;
+ }
+
+ final private void jj_save(int index, int xla) {
+ JJCalls p = jj_2_rtns[index];
+ while (p.gen > jj_gen) {
+ if (p.next == null) { p = p.next = new JJCalls(); break; }
+ p = p.next;
+ }
+ p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
+ }
+
+ static final class JJCalls {
+ int gen;
+ Token first;
+ int arg;
+ JJCalls next;
+ }
+
+}
+
+class IntAndObj
+{
+ IntAndObj( int ptr, Object obj ) {
+ super(); this.ptr = ptr; this.obj = obj;
+ }
+ int ptr;
+ Object obj;
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/Parser.jj b/src/main/java/io/devnulllabs/openjava/tools/parser/Parser.jj
new file mode 100644
index 0000000..5da8c91
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/Parser.jj
@@ -0,0 +1,3043 @@
+/*
+ * OpenJava1.0.jj
+ *
+ * The parser for OpenJava 1.0 system.
+ * This parser is LL(k) leaded by semantics.
+ *
+ * @date Mar 30, 1998
+ * @auther Michiaki Tatsubori
+ * Apr 29, 1998 by mich
+ *
+ */
+options {
+ STATIC = false;
+ JAVA_UNICODE_ESCAPE = true;
+}
+
+
+PARSER_BEGIN(Parser)
+
+ package io.devnulllabs.openjava.tools.parser;
+
+
+import java.io.Reader;
+import java.util.Vector;
+import java.util.Hashtable;
+import java.lang.reflect.Method;
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.tools.DebugOut;
+import io.devnulllabs.openjava.syntax.SyntaxRule;
+import io.devnulllabs.openjava.syntax.TokenSource;
+
+
+public class Parser
+{
+ /**
+ * Allocates a new parser object who gets tokens from the given parser
+ * object.
+ *
+ * @param parser this is used to get tokens via <code>getToken()</code>
+ * or <code>getNextToken()</code>.
+ */
+ public Parser( Parser parser ) {
+ this((ParserTokenManager)new CustomTokenManager(parser, OJSystem.env));
+ }
+
+ public Parser( TokenSource token_src ) {
+ this( new TokenSourceAdapter( token_src ) );
+ }
+
+ private final String getComment() {
+ Token token = getToken( 1 ).specialToken;
+ return ((token == null) ? null : token.image);
+ }
+
+
+ private final static int makeInt( String str ) {
+ if (str.length() == 1) {
+ return Integer.valueOf( str ).intValue();
+ } else if (str.startsWith( "0x" ) || str.startsWith( "0X" )) {
+ return Integer.valueOf( str.substring( 2 ), 16 ).intValue();
+ } else if (str.startsWith( "0" )) {
+ return Integer.valueOf( str.substring( 1 ), 8 ).intValue();
+ }
+ return Integer.valueOf( str ).intValue();
+ }
+ private final static long makeLong( String str ) {
+ if (str.length() == 1) {
+ return Long.valueOf( str ).longValue();
+ } else if (str.startsWith( "0x" ) || str.startsWith( "0X" )) {
+ str = str.substring( 2 );
+ if (str.endsWith( "l" ) || str.endsWith( "L" )) {
+ str = str.substring( 0, str.length() - 1 );
+ }
+ return Long.valueOf( str, 16 ).longValue();
+ } else if (str.startsWith( "0" )) {
+ str = str.substring( 1 );
+ if (str.endsWith( "l" ) || str.endsWith( "L" )) {
+ str = str.substring( 0, str.length() - 1 );
+ }
+ return Long.valueOf( str, 8 ).longValue();
+ }
+ return Long.valueOf( str ).longValue();
+ }
+
+ /**
+ * Detects class or interface name and metaclass
+ */
+ private final ClassEnvironment setClassEnvironment( Environment base_env )
+ throws ParseException
+ {
+ int ptr = 1;
+ for (; roughModifierCheck( getToken( ptr ) ) ; ++ptr) ;
+ Token c_or_i = getToken( ptr++ );
+ if (c_or_i.kind != CLASS && c_or_i.kind != INTERFACE) {
+ throw new ParseException( "'class' or 'interface' expected : "
+ + c_or_i.image );
+ }
+ Token cname = getToken( ptr++ );
+ if (cname.kind != IDENTIFIER) {
+ throw new ParseException( "class name expected : "
+ + c_or_i.image );
+ }
+ String classname = cname.image;
+
+ ClassEnvironment result = new ClassEnvironment(base_env, classname);
+
+ Token inst = getToken(ptr++);
+ if (inst.kind != INSTANTIATES) {
+ ptr++;
+ } else {
+ IntAndObj tmp = consumeMetaclassName(ptr); ptr = tmp.ptr;
+ String meta = base_env.toQualifiedName((String) tmp.obj);
+ OJSystem.metabind(result.toQualifiedName(classname), meta);
+ }
+
+ return result;
+ }
+
+ private IntAndObj consumeMetaclassName( int ptr ) throws ParseException {
+ Token token = getToken( ptr++ );
+ if (token.kind != IDENTIFIER) {
+ throw new ParseException( "metaclass name exptected : "
+ + token.image );
+ }
+ StringBuffer buf = new StringBuffer( token.image );
+ while (getToken( ptr ).kind == DOT
+ && getToken( ptr + 1 ).kind == IDENTIFIER) {
+ buf.append( "." ).append( getToken( ptr + 1 ).image );
+ ptr += 2;
+ }
+ return new IntAndObj( ptr, buf.toString() );
+ }
+
+ /**
+ * This is used to check OpenJava user modifier semantically.
+ */
+ private final boolean OpenJavaModifierLookahead( Environment env ) {
+ return modifierCheck( env, getToken( 1 ) );
+ }
+
+ /**
+ * This is used to check OpenJava user modifier semantically.
+ */
+ private final boolean ModifierLookahead(Environment env) {
+ return modifierCheck( env, getToken(1) );
+ }
+
+ boolean DeclSuffixLookahead(Environment env) {
+ String typename = env.currentClassName();
+ String keyword = consumeKeyword(1);
+ if (keyword == null) return false;
+ Class meta = toExecutable( env, typename );
+ return invokeOJClass_isRegisteredKeyword(meta, keyword);
+ }
+
+ boolean TypeSuffixLookahead(Environment env, String typename) {
+ String keyword = consumeKeyword(1);
+ if (keyword == null) return false;
+ Class meta = toExecutable( env, typename );
+ return invokeOJClass_isRegisteredKeyword( meta, keyword );
+ }
+
+ private static final boolean modifierCheck(Environment env, Token t) {
+ if (pureModifierCheck(t)) return true;
+ if (t.kind != IDENTIFIER) return false;
+ Class meta = toExecutable( env, env.currentClassName() );
+ if (meta == null) return false;
+ return invokeOJClass_isRegisteredModifier(meta, t.image);
+ }
+
+ private String consumeKeyword(int ptr) {
+ Token token = getToken(ptr);
+ if (token.kind != IDENTIFIER) return null;
+ return token.image;
+ }
+
+ static final Class toExecutable( Environment env, String typename ) {
+ String qname = env.toQualifiedName( typename );
+ return OJSystem.getMetabind( qname );
+ }
+
+ static boolean invokeOJClass_isRegisteredKeyword( Class meta,
+ String keyword )
+ {
+ try {
+ Method m = meta.getMethod( "isRegisteredKeyword",
+ new Class[]{ String . class} );
+ Boolean b = (Boolean) m.invoke( null, new Object[]{ keyword } );
+ return b.booleanValue();
+ } catch ( Exception e ) {}
+ return false;
+ }
+
+ static SyntaxRule invokeOJClass_getDeclSuffixRule(Environment env,
+ Class meta,
+ String keyword)
+ {
+ SyntaxRule result = null;
+ try {
+ Method m = meta.getMethod("getDeclSuffixRule",
+ new Class[]{ Environment.class,
+ String.class });
+ result = (SyntaxRule) m.invoke(null, new Object[]{ env, keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ if (result != null) return result;
+ try {
+ Method m = meta.getMethod("getDeclSuffixRule",
+ new Class[]{ String.class });
+ result = (SyntaxRule) m.invoke(null, new Object[]{ keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ return result;
+ }
+
+ static SyntaxRule invokeOJClass_getTypeSuffixRule(Environment env,
+ Class meta,
+ String keyword)
+ {
+ SyntaxRule result = null;
+ try {
+ Method m = meta.getMethod("getTypeSuffixRule",
+ new Class[]{ Environment.class,
+ String.class });
+ result = (SyntaxRule) m.invoke(null, new Object[]{ env, keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ if (result != null) return result;
+ try {
+ Method m = meta.getMethod("getTypeSuffixRule",
+ new Class[]{ String.class});
+ result = (SyntaxRule) m.invoke(null, new Object[]{ keyword });
+ } catch (Exception e) {} /* ignore if the method not provided */
+ return result;
+ }
+
+ static boolean invokeOJClass_isRegisteredModifier( Class meta,
+ String keyword )
+ {
+ try {
+ Method m = meta.getMethod( "isRegisteredModifier",
+ new Class[]{ String . class} );
+ Boolean b = (Boolean) m.invoke( null, new Object[]{ keyword } );
+ return b.booleanValue();
+ } catch ( Exception e ) {}
+ return false;
+ }
+
+ /**
+ * This is used to check constructors semantically.
+ */
+ private final boolean ConstructorDeclarationLookahead(
+ ClassEnvironment env ) {
+ int ptr;
+ for (ptr = 1; modifierCheck( env, getToken( ptr ) ) ; ++ptr) ;
+ String simplename = Environment.toSimpleName( env.currentClassName() );
+ //if (! getToken( ptr ).image.equals( simplename )
+ // || getToken( ptr + 1 ).kind != LPAREN) {
+ // return false;
+ //}
+ //return true;
+ return (getToken(ptr + 1).kind == LPAREN);
+ }
+
+ /**
+ * This will used to check local variable declaration semantically.
+ */
+ private final boolean LocalVariableDeclarationLookahead(
+ Environment env ) {
+ int ptr;
+ for (ptr = 1; modifierCheck( env, getToken( ptr ) ) ; ++ptr) ;
+ int old_ptr = ptr;
+ ptr = consumePureResultType( old_ptr );
+ if (ptr != old_ptr && getToken( ptr ).kind == IDENTIFIER) {
+ return true;
+ }
+ return false;
+ }
+
+ private final boolean roughModifierCheck( Token t ) {
+ if (pureModifierCheck( t )) return true;
+ return (t.kind == IDENTIFIER);
+ }
+
+ private static final boolean pureModifierCheck( Token t ) {
+ switch (t.kind) {
+ case ABSTRACT : case FINAL : case PUBLIC : case PRIVATE :
+ case PROTECTED : case STATIC : case TRANSIENT : case VOLATILE :
+ case NATIVE : case SYNCHRONIZED :
+ return true;
+ }
+ return false;
+ }
+
+ private final boolean ConstructorInvocationLookahead() {
+ int ptr = 1;
+ while (getToken(ptr).kind != EOF) {
+ if (getToken(ptr).kind == SUPER
+ && getToken(ptr + 1).kind == LPAREN) {
+ return true;
+ }
+ if (getToken(ptr).kind == SEMICOLON) return false;
+ if (getToken(ptr).kind == RBRACE) return false;
+ ++ptr;
+ }
+ return false;
+ }
+
+ private final boolean AssignmentLookahead() {
+ int ptr = 1;
+ switch (getToken( ptr ).kind) {
+ case LPAREN :
+ ptr = consumeParenPair( ptr );
+ break;
+ case IDENTIFIER :
+ case THIS :
+ case SUPER :
+ ptr++;
+ break;
+ default :
+ return false;
+ }
+ for (boolean cont = true; cont;) {
+ switch (getToken( ptr ).kind) {
+ case LPAREN :
+ ptr = consumeParenPair( ptr );
+ break;
+ case LBRACKET :
+ ptr = consumeBracketPair( ptr );
+ break;
+ case DOT :
+ ptr++;
+ if (getToken( ptr ).kind != IDENTIFIER) return false;
+ ptr++;
+ break;
+ default :
+ cont = false;
+ }
+ }
+ return assignmentOperatorCheck( getToken( ptr ) );
+ }
+
+ private final int consumeParenPair( int ptr ) {
+ int nest = 1;
+ for (++ptr; nest > 0; ptr++) {
+ if (getToken( ptr ).kind == LPAREN) nest++;
+ if (getToken( ptr ).kind == RPAREN) nest--;
+ }
+ return ptr;
+ }
+
+ private final int consumeBracketPair( int ptr ) {
+ int nest = 1;
+ for (++ptr; nest > 0; ptr++) {
+ if (getToken( ptr ).kind == LBRACKET) nest++;
+ if (getToken( ptr ).kind == RBRACKET) nest--;
+ }
+ return ptr;
+ }
+
+ private static final boolean assignmentOperatorCheck( Token t ) {
+ if (t.kind == ASSIGN) return true;
+ if (t.kind == PLUSASSIGN) return true;
+ if (t.kind == MINUSASSIGN) return true;
+ if (t.kind == STARASSIGN) return true;
+ if (t.kind == SLASHASSIGN) return true;
+ if (t.kind == ANDASSIGN) return true;
+ if (t.kind == ORASSIGN) return true;
+ if (t.kind == XORASSIGN) return true;
+ if (t.kind == REMASSIGN) return true;
+ if (t.kind == LSHIFTASSIGN) return true;
+ if (t.kind == RSIGNEDSHIFTASSIGN) return true;
+ if (t.kind == RUNSIGNEDSHIFTASSIGN) return true;
+ return false;
+ }
+
+ private final boolean ClassLiteralLookahead() {
+ int ptr = 1;
+ ptr = consumePureResultType( ptr );
+ if (ptr == 1) return false;
+ /** here should be user suffix check **/
+ if (getToken( ptr ).kind != DOT) return false;
+ if (getToken( ptr + 1 ).kind != CLASS) return false;
+ return true;
+ }
+
+ private final int consumePureResultType( int ptr ) {
+ Token token = getToken( ptr );
+ if (primitiveTypeCheck( token )) {
+ ptr++;
+ } else if (token.kind == IDENTIFIER) {
+ ptr++;
+ while (getToken( ptr ).kind == DOT
+ && getToken( ptr + 1 ).kind == IDENTIFIER) {
+ ptr += 2;
+ }
+ } else {
+ return ptr;
+ }
+
+ while (getToken( ptr ).kind == LBRACKET
+ && getToken( ptr + 1 ).kind == RBRACKET) {
+ ptr += 2;
+ }
+
+ return ptr;
+ }
+
+ private final boolean primitiveTypeCheck( Token t ) {
+ if (t.kind == BOOLEAN || t.kind == CHAR || t.kind == BYTE
+ || t.kind == SHORT || t.kind == INT || t.kind == LONG
+ || t.kind == FLOAT || t.kind == DOUBLE || t.kind == VOID) {
+ return true;
+ }
+ return false;
+ }
+
+}
+
+class IntAndObj
+{
+ IntAndObj( int ptr, Object obj ) {
+ super(); this.ptr = ptr; this.obj = obj;
+ }
+ int ptr;
+ Object obj;
+}
+
+PARSER_END(Parser)
+
+
+/*****************************************
+ * Utility Codes for Semantical Analysis *
+ *****************************************/
+
+/* For Debug */
+ JAVACODE
+ void debug_message1() {
+ DebugOut.println( "debug1 : " + getToken( 0 ).image
+ + " , " + getToken( 1 ).image );
+}
+
+/* Declaration Suffix */
+JAVACODE
+ ParseTree UserDeclSuffix(Environment env, String keyword) {
+ String typename = env.currentClassName();
+ Class meta = toExecutable(env, typename);
+ SyntaxRule rule = invokeOJClass_getDeclSuffixRule(env, meta, keyword);
+ CustomTokenManager token_mgr = new CustomTokenManager(this, env);
+ token_mgr.assume();
+ ParseTree result = rule.consume(token_mgr);
+ token_mgr.fix();
+ return result;
+}
+
+/* Type Name Suffix */
+JAVACODE
+ ParseTree UserTypeSuffix(Environment env, String typename, String keyword) {
+ Class meta = toExecutable(env, typename);
+ SyntaxRule rule = invokeOJClass_getTypeSuffixRule(env, meta, keyword);
+ CustomTokenManager token_mgr = new CustomTokenManager(this, env);
+ token_mgr.assume();
+ ParseTree result = rule.consume(token_mgr);
+ token_mgr.fix();
+ return result;
+}
+
+/* Epsilon */
+JAVACODE
+ void E() {}
+
+
+/*****************************************
+ * Lexical Descriptions *
+ *****************************************/
+
+/* WHITE SPACE */
+
+SKIP :
+{
+ " "
+ | "\t"
+ | "\n"
+ | "\r"
+ | "\f"
+ }
+
+/* COMMENTS */
+
+MORE :
+{
+ <"/**" ~["/"]> : IN_FORMAL_COMMENT
+ }
+
+MORE :
+{
+ "//" : IN_SINGLE_LINE_COMMENT
+ |
+ "/*" : IN_MULTI_LINE_COMMENT
+ }
+
+<IN_SINGLE_LINE_COMMENT>
+ SPECIAL_TOKEN :
+{
+ <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT
+ }
+
+<IN_FORMAL_COMMENT>
+ SPECIAL_TOKEN :
+{
+ <FORMAL_COMMENT: "*/" > : DEFAULT
+ }
+
+<IN_MULTI_LINE_COMMENT>
+ SPECIAL_TOKEN :
+{
+ <MULTI_LINE_COMMENT: "*/" > : DEFAULT
+ }
+
+<IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
+ MORE :
+{
+ < ~[] >
+ }
+
+/* RESERVED WORDS AND LITERALS */
+
+TOKEN :
+{
+ < ABSTRACT: "abstract" >
+ | < BOOLEAN: "boolean" >
+ | < BREAK: "break" >
+ | < BYTE: "byte" >
+ | < CASE: "case" >
+ | < CATCH: "catch" >
+ | < CHAR: "char" >
+ | < CLASS: "class" >
+ | < CONST: "const" >
+ | < CONTINUE: "continue" >
+ | < _DEFAULT: "default" >
+ | < DO: "do" >
+ | < DOUBLE: "double" >
+ | < ELSE: "else" >
+ | < EXTENDS: "extends" >
+ | < FALSE: "false" >
+ | < FINAL: "final" >
+ | < FINALLY: "finally" >
+ | < FLOAT: "float" >
+ | < FOR: "for" >
+ | < GOTO: "goto" >
+ | < IF: "if" >
+ | < IMPLEMENTS: "implements" >
+ | < IMPORT: "import" >
+ | < INSTANCEOF: "instanceof" >
+ | < INT: "int" >
+ | < INTERFACE: "interface" >
+ | < LONG: "long" >
+ | < NATIVE: "native" >
+ | < NEW: "new" >
+ | < NULL: "null" >
+ | < PACKAGE: "package">
+ | < PRIVATE: "private" >
+ | < PROTECTED: "protected" >
+ | < PUBLIC: "public" >
+ | < RETURN: "return" >
+ | < SHORT: "short" >
+ | < STATIC: "static" >
+ | < SUPER: "super" >
+ | < SWITCH: "switch" >
+ | < SYNCHRONIZED: "synchronized" >
+ | < THIS: "this" >
+ | < THROW: "throw" >
+ | < THROWS: "throws" >
+ | < TRANSIENT: "transient" >
+ | < TRUE: "true" >
+ | < TRY: "try" >
+ | < VOID: "void" >
+ | < VOLATILE: "volatile" >
+ | < WHILE: "while" >
+ | < METACLASS: "metaclass" >
+ | < INSTANTIATES: "instantiates" >
+ }
+
+/* LITERALS */
+
+TOKEN :
+{
+ < INTEGER_LITERAL:
+ <DECIMAL_LITERAL>
+ | <HEX_LITERAL>
+ | <OCTAL_LITERAL>
+ >
+ |
+ < LONG_LITERAL:
+ <DECIMAL_LITERAL> ["l","L"]
+ | <HEX_LITERAL> ["l","L"]
+ | <OCTAL_LITERAL> ["l","L"]
+ >
+ |
+ < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+ |
+ < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+ |
+ < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+ |
+ < DOUBLE_FLOATING_POINT_LITERAL:
+ (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["d","D"])?
+ | "." (["0"-"9"])+ (<EXPONENT>)? ["d","D"]
+ | (["0"-"9"])+ <EXPONENT> ["d","D"]
+ | (["0"-"9"])+ (<EXPONENT>)? ["d","D"]
+ >
+ |
+ < FLOATING_POINT_LITERAL:
+ (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? ["f","F"]
+ | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F"])?
+ | (["0"-"9"])+ <EXPONENT> (["f","F"])?
+ | (["0"-"9"])+ (<EXPONENT>)? ["f","F"]
+ >
+ |
+ < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+ |
+ < CHARACTER_LITERAL:
+ "'"
+ ( (~["'","\\","\n","\r"])
+ | ("\\"
+ ( ["n","t","b","r","f","\\","'","\""]
+ | ["0"-"7"] ( ["0"-"7"] )?
+ | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+ )
+ )
+ )
+ "'"
+ >
+ |
+ < STRING_LITERAL:
+ "\""
+ ( (~["\"","\\","\n","\r"])
+ | ("\\"
+ ( ["n","t","b","r","f","\\","'","\""]
+ | ["0"-"7"] ( ["0"-"7"] )?
+ | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+ )
+ )
+ )*
+ "\""
+ >
+ }
+
+/* IDENTIFIERS */
+
+TOKEN :
+{
+ < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
+ |
+ < #LETTER:
+ [
+ "\u0024",
+ "\u0041"-"\u005a",
+ "\u005f",
+ "\u0061"-"\u007a",
+ "\u00c0"-"\u00d6",
+ "\u00d8"-"\u00f6",
+ "\u00f8"-"\u00ff",
+ "\u0100"-"\u1fff",
+ "\u3040"-"\u318f",
+ "\u3300"-"\u337f",
+ "\u3400"-"\u3d2d",
+ "\u4e00"-"\u9fff",
+ "\uf900"-"\ufaff"
+ ]
+ >
+ |
+ < #DIGIT:
+ [
+ "\u0030"-"\u0039",
+ "\u0660"-"\u0669",
+ "\u06f0"-"\u06f9",
+ "\u0966"-"\u096f",
+ "\u09e6"-"\u09ef",
+ "\u0a66"-"\u0a6f",
+ "\u0ae6"-"\u0aef",
+ "\u0b66"-"\u0b6f",
+ "\u0be7"-"\u0bef",
+ "\u0c66"-"\u0c6f",
+ "\u0ce6"-"\u0cef",
+ "\u0d66"-"\u0d6f",
+ "\u0e50"-"\u0e59",
+ "\u0ed0"-"\u0ed9",
+ "\u1040"-"\u1049"
+ ]
+ >
+ }
+
+/* SEPARATORS */
+
+TOKEN :
+{
+ < LPAREN: "(" >
+ | < RPAREN: ")" >
+ | < LBRACE: "{" >
+ | < RBRACE: "}" >
+ | < LBRACKET: "[" >
+ | < RBRACKET: "]" >
+ | < SEMICOLON: ";" >
+ | < COMMA: "," >
+ | < DOT: "." >
+ }
+
+/* OPERATORS */
+
+TOKEN :
+{
+ < ASSIGN: "=" >
+ | < GT: ">" >
+ | < LT: "<" >
+ | < BANG: "!" >
+ | < TILDE: "~" >
+ | < HOOK: "?" >
+ | < COLON: ":" >
+ | < EQ: "==" >
+ | < LE: "<=" >
+ | < GE: ">=" >
+ | < NE: "!=" >
+ | < SC_OR: "||" >
+ | < SC_AND: "&&" >
+ | < INCR: "++" >
+ | < DECR: "--" >
+ | < PLUS: "+" >
+ | < MINUS: "-" >
+ | < STAR: "*" >
+ | < SLASH: "/" >
+ | < BIT_AND: "&" >
+ | < BIT_OR: "|" >
+ | < XOR: "^" >
+ | < REM: "%" >
+ | < LSHIFT: "<<" >
+ | < RSIGNEDSHIFT: ">>" >
+ | < RUNSIGNEDSHIFT: ">>>" >
+ | < PLUSASSIGN: "+=" >
+ | < MINUSASSIGN: "-=" >
+ | < STARASSIGN: "*=" >
+ | < SLASHASSIGN: "/=" >
+ | < ANDASSIGN: "&=" >
+ | < ORASSIGN: "|=" >
+ | < XORASSIGN: "^=" >
+ | < REMASSIGN: "%=" >
+ | < LSHIFTASSIGN: "<<=" >
+ | < RSIGNEDSHIFTASSIGN: ">>=" >
+ | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
+ }
+
+
+/*****************************************
+ * Syntactical Descriptions *
+ *****************************************/
+
+/*
+ * Program structuring syntax follows.
+ */
+
+CompilationUnit CompilationUnit( Environment base_env ) :
+/* Any ";" around each type declaration must be ignored. */
+{
+ CompilationUnit result;
+ FileEnvironment env = new FileEnvironment( base_env );
+ String p1;
+ String[] p2;
+ ClassDeclarationList p3;
+ /**/DebugOut.println( "#CompilationUnit()" );
+ String comment = getComment();
+}
+{
+ p1=PackageDeclarationOpt()
+ p2=ImportDeclarationListOpt()
+ {
+ env.setPackage( p1 );
+ for (int i = 0; i < p2.length; ++i) {
+ if (CompilationUnit.isOnDemandImport( p2[i] )) {
+ String pack_cls = CompilationUnit.trimOnDemand( p2[i] );
+ env.importPackage( pack_cls );
+ } else {
+ env.importClass( p2[i] );
+ }
+ }
+ }
+ ( ";" )*
+ p3=TypeDeclarationListOpt( env )
+ <EOF>
+ {
+ result = new CompilationUnit( p1, p2, p3 );
+ result.setComment( comment );
+ return result;
+ }
+}
+
+String PackageDeclarationOpt() :
+{
+ String p1;
+}
+{
+ "package" p1=Name() ";"
+ { return p1; }
+ |
+ E()
+ { return null; }
+}
+
+String[] ImportDeclarationListOpt() :
+{
+ String[] result;
+ String p1;
+ Vector v = new Vector();
+}
+{
+ ( p1=ImportDeclaration() { v.addElement( p1 ); } )+
+ {
+ result = new String[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (String) v.elementAt( i );
+ }
+ }
+ { return result; }
+ |
+ E()
+ { return new String[0]; }
+}
+
+String ImportDeclaration() :
+{
+ String p1;
+ StringBuffer strbuf = new StringBuffer();
+}
+{
+ "import"
+ Identifier()
+ { strbuf.append( getToken( 0 ).image ); }
+ ( LOOKAHEAD(2)
+ "." Identifier()
+ { strbuf.append( "." + getToken( 0 ).image ); }
+ )*
+ [
+ "." "*"
+ { strbuf.append( ".*" ); }
+ ]
+ ";"
+ { return strbuf.toString(); }
+}
+
+ClassDeclarationList TypeDeclarationListOpt( Environment env ) :
+/* Must ignore ";"s */
+{
+ ClassEnvironment newenv;
+ ClassDeclarationList result = new ClassDeclarationList();
+ ClassDeclaration p1;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF) } )
+ ( LOOKAHEAD( { (getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF) } )
+ { newenv = setClassEnvironment( env ); }
+ p1=TypeDeclaration( newenv )
+ ( ";" )*
+ { result.add( p1 ); }
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ClassDeclaration TypeDeclaration( ClassEnvironment env ) :
+{
+ ClassDeclaration result;
+ ClassDeclaration p1;
+ Token ctoken = getToken( 1 ).specialToken;
+ String comment = getComment();
+}
+{
+ (
+ LOOKAHEAD( ( Identifier() | "abstract" | "final" | "public" )*
+ "class" )
+ p1=ClassDeclaration( env )
+ |
+ p1=InterfaceDeclaration( env )
+ )
+ {
+ result = p1;
+ result.setComment( comment );
+ return result;
+ }
+}
+
+String Identifier() :
+/* This enables it to use "metaclass" as identifier. */
+{}
+{
+ <IDENTIFIER>
+ { return getToken( 0 ).image; }
+ |
+ "metaclass"
+ { return "metaclass"; }
+}
+
+String[] MetaclassesOpt( Environment env ) :
+/* metaclass may have metametaclass */
+{
+ String[] result;
+ String p1;
+ String p2;
+ Vector v = new Vector();
+ String qname;
+}
+{
+ "metaclass"
+ p1=Name()
+ {
+ qname = env.toQualifiedName( p1 );
+ v.addElement( qname );
+ /****/DebugOut.print( "metaclass " + qname );
+ }
+ [
+ "," p2=Name()
+ {
+ qname = env.toQualifiedName( p2 );
+ /****/DebugOut.print( ", " + qname );
+ }
+ ]
+ ( ":" | ";" )
+ { /****/DebugOut.println( " :" ); }
+ {
+ result = new String[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (String) v.elementAt( i );
+ }
+ }
+ { return result; }
+ |
+ E()
+ { return new String[0]; }
+}
+
+String InstantiatesPhraseOpt( ClassEnvironment env ) :
+{
+ String p1 = null;
+}
+{
+ "instantiates" p1=Name()
+ { return p1; }
+ |
+ E()
+ { return p1; }
+}
+
+String OpenJavaModifier() :
+/* User modifiers must not be "metaclass" */
+{
+ String result;
+}
+{
+ <IDENTIFIER>
+ {
+ result = getToken( 0 ).image;
+ DebugOut.println( "user modifier detected : " + result );
+ }
+ { return result; }
+}
+
+Hashtable OpenJavaDeclSuffixListOpt( Environment env ) :
+{
+ Hashtable result = new Hashtable();
+ String p1;
+ ParseTree p2;
+}
+{
+ LOOKAHEAD( { DeclSuffixLookahead( env ) } )
+ ( LOOKAHEAD( { DeclSuffixLookahead( env ) } )
+ p1=Identifier()
+ p2=UserDeclSuffix( env, p1 )
+ {
+ DebugOut.println( "decl suffix : " + p1 + " " + p2 );
+ result.put( p1, p2 );
+ }
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+Hashtable OpenJavaTypeSuffixListOpt( Environment env, String typename ) :
+{
+ Hashtable result = new Hashtable();
+ String p1;
+ ParseTree p2;
+}
+{
+ LOOKAHEAD( { TypeSuffixLookahead( env, typename ) } )
+ ( LOOKAHEAD( { TypeSuffixLookahead( env, typename ) } )
+ p1=Identifier()
+ p2=UserTypeSuffix( env, typename, p1 )
+ {
+ DebugOut.println( "type suffix : " + p1 + " " + p2 );
+ result.put( p1, p2 );
+ }
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+int Modifier() :
+{}
+{
+ "abstract" { return ModifierList.ABSTRACT; }
+ | "final" { return ModifierList.FINAL; }
+ | "public" { return ModifierList.PUBLIC; }
+ | "private" { return ModifierList.PRIVATE; }
+ | "protected" { return ModifierList.PROTECTED; }
+ | "static" { return ModifierList.STATIC; }
+ | "transient" { return ModifierList.TRANSIENT; }
+ | "volatile" { return ModifierList.VOLATILE; }
+ | "native" { return ModifierList.NATIVE; }
+ | "synchronized" { return ModifierList.SYNCHRONIZED; }
+}
+
+/*
+ * Declaration syntax follows.
+ */
+
+ClassDeclaration ClassDeclaration( ClassEnvironment env ) :
+{
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#ClassDeclaration()" );
+}
+{
+ p1=ClassModifiersOpt( env )
+ p2=UnmodifiedClassDeclaration( env )
+ { p2.setModifiers( p1 ); }
+ { return p2; }
+}
+
+ModifierList ClassModifiersOpt( Environment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != CLASS) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "abstract" | "final" | "public" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ClassDeclaration UnmodifiedClassDeclaration( ClassEnvironment env ) :
+{
+ ClassDeclaration result;
+ String p1;
+ TypeName[] p2;
+ TypeName[] p3;
+ MemberDeclarationList p4;
+ String mm;
+ Hashtable sf;
+}
+{
+ "class" p1=Identifier()
+ mm=InstantiatesPhraseOpt( env )
+ p2=ExtendsPhraseOpt( env )
+ p3=ImplementsPhraseOpt( env )
+ sf=OpenJavaDeclSuffixListOpt( env )
+ p4=ClassBody( env )
+ {
+ result = new ClassDeclaration( null, p1, p2, p3, p4 );
+ result.setSuffixes( sf );
+ }
+ { return result; }
+}
+
+TypeName[] ExtendsPhraseOpt( Environment env ) :
+{
+ TypeName[] p1;
+}
+{
+ /* "extends" TypeName() */
+ "extends" p1=TypeNameList( env )
+ { return p1; }
+ |
+ E()
+ { return null; }
+}
+
+TypeName[] ImplementsPhraseOpt( Environment env ) :
+{
+ TypeName[] p1;
+}
+{
+ "implements" p1=TypeNameList( env )
+ { return p1; }
+ |
+ E()
+ { return null; }
+}
+
+MemberDeclarationList ClassBody( ClassEnvironment env ) :
+{
+ MemberDeclarationList p1;
+
+ DebugOut.println( "#ClassBody()" );
+}
+{
+ "{"
+ ( ";" )*
+ p1=ClassBodyDeclarationListOpt( env )
+ "}"
+ { return p1; }
+}
+
+MemberDeclarationList ClassBodyDeclarationListOpt( ClassEnvironment env ) :
+{
+ MemberDeclarationList result = new MemberDeclarationList();
+ MemberDeclarationList p1;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != RBRACE) } )
+ ( LOOKAHEAD( { (getToken( 1 ).kind != RBRACE) } )
+ p1=ClassBodyDeclaration( env )
+ ( ";" )*
+ { result.addAll( p1 ); }
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ClassDeclaration NestedTypeDeclaration( ClassEnvironment env ) :
+{
+ ClassDeclaration result;
+ ClassDeclaration p1;
+ Token ctoken = getToken( 1 ).specialToken;
+ String comment = getComment();
+}
+{
+ (
+ LOOKAHEAD( ( Identifier() | "static" | "abstract" | "final"
+ | "public" | "protected" | "private" )*
+ "class" )
+ p1=NestedClassDeclaration( env )
+ |
+ p1=NestedInterfaceDeclaration( env )
+ )
+ {
+ result = p1;
+ result.setComment( comment );
+ return result;
+ }
+}
+
+ClassDeclaration NestedClassDeclaration( ClassEnvironment env ) :
+{
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#NestedClassDeclaration()" );
+}
+{
+ p1=NestedClassModifiersOpt( env )
+ p2=UnmodifiedClassDeclaration( env )
+ { p2.setModifiers( p1 ); }
+ { return p2; }
+}
+
+ModifierList NestedClassModifiersOpt( ClassEnvironment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != CLASS) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "static" | "abstract" | "final"
+ | "public" | "protected" | "private" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+MemberDeclarationList ClassBodyDeclaration( ClassEnvironment env ) :
+{
+ ClassEnvironment newenv;
+ MemberDeclarationList result;
+ MemberDeclaration p1;
+ MemberDeclarationList p2;
+}
+{
+ LOOKAHEAD( [ "static" ] "{" )
+ p1=MemberInitializer( env )
+ { result = new MemberDeclarationList( p1 ); }
+ { return result; }
+ |
+ LOOKAHEAD( ( Identifier() | "static" | "abstract" | "final"
+ | "public" | "protected" | "private" )*
+ ( "class" | "interface" ) )
+ { newenv = setClassEnvironment( env ); }
+ p1=NestedTypeDeclaration( newenv )
+ { result = new MemberDeclarationList( p1 ); }
+ { return result; }
+ |
+ LOOKAHEAD( { ConstructorDeclarationLookahead( env ) } )
+ p1=ConstructorDeclaration( env )
+ { result = new MemberDeclarationList( p1 ); }
+ { return result; }
+ |
+ p2=MethodOrFieldDeclaration( env )
+ { return p2; }
+}
+
+MemberDeclarationList MethodOrFieldDeclaration( Environment base_env ) :
+{
+ Environment env = new ClosedEnvironment( base_env );
+ MemberDeclarationList result = new MemberDeclarationList();
+ ModifierList p1;
+ TypeName p2;
+ String p3;
+ ParameterList p4;
+ int p5;
+ TypeName[] p6;
+ StatementList p7;
+ VariableDeclarator p8;
+ Hashtable sf;
+ Token ctoken = getToken( 1 ).specialToken;
+ String comment = getComment();
+}
+{
+ p1=MemberModifiersOpt( base_env )
+ p2=Type( base_env )
+ (
+ LOOKAHEAD( Identifier() "(" )
+ p3=Identifier()
+ p4=FormalParameters( env )
+ p5=EmptyBracketsOpt()
+ p6=ThrowsPhraseOpt( base_env )
+ sf=OpenJavaDeclSuffixListOpt( env )
+ p7=MethodBody( env )
+ {
+ p2.addDimension( p5 );
+ MethodDeclaration mthd
+ = new MethodDeclaration( p1, p2, p3, p4, p6, p7 );
+ mthd.setSuffixes( sf );
+ mthd.setComment( comment );
+ result.add( mthd );
+ }
+ |
+ p8=VariableDeclarator( base_env )
+ {
+ FieldDeclaration fld1 = new FieldDeclaration( p1, p2, p8 );
+ fld1.setComment( comment );
+ result.add( fld1 );
+ }
+ (
+ ","
+ p8=VariableDeclarator( env )
+ {
+ FieldDeclaration fld2 = new FieldDeclaration( p1, p2, p8 );
+ fld2.setComment( comment );
+ result.add( fld2 );
+ }
+ )*
+ ";"
+ )
+ { return result; }
+}
+
+TypeName[] ThrowsPhraseOpt( Environment env ) :
+{
+ TypeName[] p1;
+}
+{
+ "throws" p1=TypeNameList( env )
+ { return p1; }
+ |
+ E()
+ { return null; }
+}
+
+StatementList MethodBody( Environment env ) :
+{
+ StatementList p1;
+}
+{
+ p1=BlockedBody( env )
+ { return p1; }
+ |
+ ";"
+ { return null; }
+}
+
+ModifierList MemberModifiersOpt( Environment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { modifierCheck( env, getToken( 1 ) ) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "public" | "protected" | "private"
+ | "static" | "abstract" | "final"
+ | "transient" | "volatile" | "native" | "synchronized" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ClassDeclaration InterfaceDeclaration( ClassEnvironment env ) :
+{
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#InterfaceDeclaration()" );
+}
+{
+ p1=InterfaceModifiersOpt( env )
+ p2=UnmodifiedInterfaceDeclaration( env )
+ { p2.setModifiers( p1 ); }
+ { return p2; }
+}
+
+ModifierList InterfaceModifiersOpt( Environment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != INTERFACE) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "abstract" | "public" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ClassDeclaration NestedInterfaceDeclaration( ClassEnvironment env ) :
+{
+ ModifierList p1;
+ ClassDeclaration p2;
+
+ DebugOut.println( "#NestedInterfaceDeclaration()" );
+}
+{
+ p1=NestedInterfaceModifiersOpt( env )
+ p2=UnmodifiedInterfaceDeclaration( env )
+ { p2.setModifiers( p1 ); }
+ { return p2; }
+}
+
+ModifierList NestedInterfaceModifiersOpt( ClassEnvironment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != INTERFACE) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "static" | "abstract" | "final"
+ | "public" | "protected" | "private" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ClassDeclaration UnmodifiedInterfaceDeclaration( ClassEnvironment env ) :
+{
+ ClassDeclaration result;
+ String p1;
+ TypeName[] p2;
+ MemberDeclarationList p3;
+ String mm;
+ Hashtable sf;
+}
+{
+ "interface" p1=Identifier()
+ mm=InstantiatesPhraseOpt( env )
+ p2=ExtendsPhraseOpt( env )
+ sf=OpenJavaDeclSuffixListOpt( env )
+ p3=InterfaceBody( env )
+ {
+ result = new ClassDeclaration( null, p1, p2, null, p3, false );
+ result.setSuffixes( sf );
+ }
+ { return result; }
+}
+
+MemberDeclarationList InterfaceBody( ClassEnvironment env ) :
+{
+ MemberDeclarationList p1;
+}
+{
+ "{" p1=InterfaceBodyDeclarationListOpt( env ) "}"
+ { return p1; }
+}
+
+MemberDeclarationList InterfaceBodyDeclarationListOpt( ClassEnvironment env ) :
+{
+ MemberDeclarationList result = new MemberDeclarationList();
+ MemberDeclarationList p1;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != RBRACE) } )
+ ( LOOKAHEAD( { (getToken( 1 ).kind != RBRACE) } )
+ p1=InterfaceBodyDeclaration( env )
+ { result.addAll( p1 ); }
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+MemberDeclarationList InterfaceBodyDeclaration( ClassEnvironment env ) :
+{
+ ClassEnvironment newenv;
+ MemberDeclarationList result;
+ ClassDeclaration p1;
+ MemberDeclarationList p2;
+}
+{
+ LOOKAHEAD( ( Identifier() | "abstract" | "final" | "public" )*
+ ( "class" | "interface" ) )
+ { newenv = setClassEnvironment( env ); }
+ p1=NestedTypeDeclaration( newenv )
+ { result = new MemberDeclarationList( p1 ); }
+ { return result; }
+ |
+ p2=MethodOrFieldDeclaration( env )
+ { return p2; }
+}
+
+VariableDeclarator VariableDeclarator( Environment env ) :
+{
+ String p1;
+ int p2;
+ VariableInitializer p3 = null;
+}
+{
+ p1=Identifier() p2=EmptyBracketsOpt() [ "=" p3=VariableInitializer( env ) ]
+ { return new VariableDeclarator( p1, p2, p3 ); }
+}
+
+int EmptyBracketsOpt() :
+{
+ int result = 0;
+}
+{
+ LOOKAHEAD( "[" "]" )
+ ( LOOKAHEAD(2) "[" "]" { result++; } )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+VariableInitializer VariableInitializer( Environment env ) :
+{
+ VariableInitializer p1;
+}
+{
+ p1=ArrayInitializer( env )
+ { return p1; }
+ |
+ p1=Expression( env )
+ { return p1; }
+}
+
+ArrayInitializer ArrayInitializer( Environment env ) :
+{
+ ArrayInitializer result = new ArrayInitializer();
+ VariableInitializer p1;
+}
+{
+ "{"
+ [ LOOKAHEAD( { (getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != COMMA) } )
+ p1=VariableInitializer( env )
+ { result.add( p1 ); }
+ ( LOOKAHEAD( { (getToken( 1 ).kind == COMMA
+ && getToken( 2 ).kind != RBRACE) } )
+ "," p1=VariableInitializer( env )
+ { result.add( p1 ); }
+ )*
+ ]
+ [ "," { result.omitRemainder( true ); } ]
+ "}"
+ { return result; }
+}
+
+ParameterList FormalParameters( Environment env ) :
+{
+ ParameterList result = new ParameterList();
+ Parameter p1;
+
+ DebugOut.println( "#FormalParameters()" );
+}
+{
+ "("
+ [ LOOKAHEAD( { (getToken( 1 ).kind != RPAREN) } )
+ p1=FormalParameter( env )
+ { result.add( p1 ); }
+ ( "," p1=FormalParameter( env ) { result.add( p1 ); } )*
+ ]
+ ")"
+ { return result; }
+}
+
+Parameter FormalParameter( Environment env ) :
+{
+ ModifierList p1;
+ TypeName p2;
+ String p3;
+ int p4;
+ DebugOut.println( "#FormalParameter()" );
+}
+{
+ p1=FormalParameterModifiersOpt( env ) p2=Type( env )
+ p3=Identifier() p4=EmptyBracketsOpt()
+ {
+ p2.addDimension( p4 );
+ /* binds the parameter variable as the null type */
+ env.bindVariable(p3, OJSystem.NULLTYPE);
+ }
+ { return new Parameter( p1, p2, p3 ); }
+}
+
+ModifierList FormalParameterModifiersOpt( Environment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { modifierCheck( env, getToken( 1 ) ) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "final" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ConstructorDeclaration ConstructorDeclaration( Environment base_env ) :
+{
+ Environment env = new ClosedEnvironment( base_env );
+ ConstructorDeclaration result;
+ ModifierList p1;
+ String p2;
+ ParameterList p3;
+ TypeName[] p4;
+ ConstructorInvocation p5;
+ StatementList p6;
+ Hashtable sf;
+
+ DebugOut.println( "#ConstructorDeclaration()" );
+}
+{
+ p1=ConstructorModifiersOpt( base_env )
+ p2=Identifier()
+ p3=FormalParameters( env )
+ p4=ThrowsPhraseOpt( base_env )
+ sf=OpenJavaDeclSuffixListOpt( env )
+ "{"
+ p5=ExplicitConstructorInvocationOpt( env )
+ p6=BlockOrStatementListOpt( env )
+ "}"
+ {
+ result = new ConstructorDeclaration( p1, p2, p3, p4, p5, p6 );
+ result.setSuffixes( sf );
+ return result;
+ }
+}
+
+ModifierList ConstructorModifiersOpt( Environment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( "public" | "protected" | "private" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ ( LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )*
+ { return result; }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ ( LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )+
+ [
+ p1=Modifier()
+ { result.add( p1 ); }
+ ( LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )*
+ ]
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+ConstructorInvocation ExplicitConstructorInvocationOpt( Environment env ) :
+{
+ ExpressionList p1;
+ Expression p2 = null;
+
+ DebugOut.println( "#ExplicitConstructorInvocationOpt()" );
+}
+{
+ LOOKAHEAD( "this" "(" )
+ "this" p1=Arguments( env ) ";"
+ { return new ConstructorInvocation( p1 ); }
+ |
+ LOOKAHEAD( { ConstructorInvocationLookahead() } )
+ [ LOOKAHEAD( { (getToken( 1 ).kind != SUPER) } )
+ p2=PrimaryExpression( env ) "."
+ ]
+ "super" p1=Arguments( env ) ";"
+ { return new ConstructorInvocation( p1, p2 ); }
+ |
+ E()
+ { return null; }
+}
+
+MemberInitializer MemberInitializer( Environment env ) :
+{
+ MemberInitializer result;
+ StatementList p1;
+ boolean is_static = false;
+}
+{
+ [ "static" { is_static = true; } ] p1=BlockedBody( env )
+ {
+ if (is_static) {
+ result = new MemberInitializer( p1, true );
+ } else {
+ result = new MemberInitializer( p1 );
+ }
+ }
+ { return result; }
+}
+
+
+/*
+ * Type, name and expression syntax follows.
+ */
+
+TypeName Type( Environment env ) :
+{
+ TypeName result;
+ String p1;
+ Hashtable p2;
+ int p3;
+}
+{
+ ( p1=PrimitiveType() | p1=Name() )
+ p2=OpenJavaTypeSuffixListOpt( env, p1 )
+ p3=EmptyBracketsOpt()
+ {
+ result = new TypeName( p1, p3, p2 );
+ }
+ { return result; }
+}
+
+String PrimitiveType() :
+{
+ String result;
+}
+{
+ ( "boolean" | "char" | "byte" | "short" | "int" | "long"
+ | "float" | "double" | "void"
+ )
+ { result = getToken( 0 ).image; }
+ { return result; }
+}
+
+String Name() :
+/*
+ * A lookahead of 2 is required below since "Name" can be followed
+ * by a ".*" when used in the context of an "ImportDeclaration".
+ */
+{
+ String p1;
+ StringBuffer strbuf = null;
+}
+{
+ p1=Identifier() { strbuf = new StringBuffer( p1 ); }
+ ( LOOKAHEAD(2)
+ "." p1=Identifier()
+ { strbuf.append( "." + p1 ); }
+ )*
+ { return strbuf.toString(); }
+}
+
+TypeName TypeName( Environment env ) :
+{
+ TypeName result;
+ String p1;
+ Hashtable p2;
+}
+{
+ p1=Name()
+ p2=OpenJavaTypeSuffixListOpt( env, p1 )
+ {
+ result = new TypeName( p1, p2 );
+ }
+ { return result; }
+}
+
+TypeName[] TypeNameList( Environment env ) :
+{
+ TypeName[] result;
+ TypeName p1;
+ Vector v = new Vector();
+}
+{
+ p1=TypeName( env ) { v.addElement( p1 ); }
+ (
+ ","
+ p1=TypeName( env ) { v.addElement( p1 ); }
+ )*
+ {
+ result = new TypeName[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (TypeName) v.elementAt( i );
+ }
+ }
+ { return result; }
+}
+
+TypeName[] TypeNameListOpt( Environment env ) :
+{
+ TypeName[] result;
+ TypeName p1;
+ Vector v = new Vector();
+}
+{
+ p1=TypeName( env ) { v.addElement( p1 ); }
+ (
+ ","
+ p1=TypeName( env ) { v.addElement( p1 ); }
+ )*
+ {
+ result = new TypeName[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (TypeName) v.elementAt( i );
+ }
+ }
+ { return result; }
+ |
+ E()
+ { return new TypeName[0]; }
+}
+
+
+/*
+ * Expression syntax follows.
+ */
+
+Expression Expression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2 = null;
+ Expression p3 = null;
+
+ DebugOut.println( "#Expression()" );
+}
+{
+ p1=ConditionalExpression( env )
+ [ p2=AssignmentOperator() p3=Expression( env ) ]
+ {
+ if (p2 != null) {
+ result = new AssignmentExpression( p1, p2, p3 );
+ } else {
+ result = p1;
+ }
+ }
+ { return result; }
+}
+
+AssignmentExpression AssignmentExpression( Environment env ) :
+{
+ Expression p1;
+ String p2;
+ Expression p3;
+
+ DebugOut.println( "#AssignmentExpression()" );
+}
+{
+ p1=PrimaryExpression( env ) p2=AssignmentOperator() p3=Expression( env )
+ { return new AssignmentExpression( p1, p2, p3 ); }
+}
+
+String AssignmentOperator() :
+{
+ String result;
+
+ DebugOut.println( "#AssignmentOperator()" );
+}
+{
+ ( "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>="
+ | "&=" | "^=" | "|=" )
+ { result = getToken( 0 ).image; }
+ { return result; }
+}
+
+Expression ConditionalExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ Expression p2 = null;
+ Expression p3 = null;
+}
+{
+ p1=ConditionalOrExpression( env )
+ [
+ "?" p2=Expression( env )
+ ":" p3=ConditionalExpression( env )
+ ]
+ {
+ if (p2 != null) {
+ result = new ConditionalExpression( p1, p2, p3 );
+ } else {
+ result = p1;
+ }
+ }
+ { return result; }
+}
+
+Expression ConditionalOrExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=ConditionalAndExpression( env )
+ { result = p1; }
+ (
+ "||" { p2 = getToken( 0 ).image; }
+ p3=ConditionalAndExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression ConditionalAndExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=InclusiveOrExpression( env )
+ { result = p1; }
+ (
+ "&&" { p2 = getToken( 0 ).image; }
+ p3=InclusiveOrExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression InclusiveOrExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=ExclusiveOrExpression( env )
+ { result = p1; }
+ (
+ "|" { p2 = getToken( 0 ).image; }
+ p3=ExclusiveOrExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression ExclusiveOrExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=AndExpression( env )
+ { result = p1; }
+ (
+ "^" { p2 = getToken( 0 ).image; }
+ p3=AndExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression AndExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=EqualityExpression( env )
+ { result = p1; }
+ (
+ "&" { p2 = getToken( 0 ).image; }
+ p3=EqualityExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression EqualityExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+
+ DebugOut.println( "#EqualityExpression()" );
+}
+{
+ p1=InstanceofExpression( env )
+ { result = p1; }
+ (
+ ( "==" | "!=" ) { p2 = getToken( 0 ).image; }
+ p3=InstanceofExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression InstanceofExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ TypeName p2 = null;
+}
+{
+ p1=RelationalExpression( env ) [ "instanceof" p2=Type( env ) ]
+ {
+ if (p2 != null) {
+ result = new InstanceofExpression( p1, p2 );
+ } else {
+ result = p1;
+ }
+ }
+ { return result; }
+}
+
+Expression RelationalExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=ShiftExpression( env )
+ { result = p1; }
+ (
+ ( "<" | ">" | "<=" | ">=" ) { p2 = getToken( 0 ).image; }
+ p3=ShiftExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression ShiftExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=AdditiveExpression( env )
+ { result = p1; }
+ (
+ ( "<<" | ">>" | ">>>" ) { p2 = getToken( 0 ).image; }
+ p3=AdditiveExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression AdditiveExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=MultiplicativeExpression( env )
+ { result = p1; }
+ (
+ ( "+" | "-" ) { p2 = getToken( 0 ).image; }
+ p3=MultiplicativeExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression MultiplicativeExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ String p2;
+ Expression p3;
+}
+{
+ p1=UnaryExpression( env )
+ { result = p1; }
+ (
+ ( "*" | "/" | "%" ) { p2 = getToken( 0 ).image; }
+ p3=UnaryExpression( env )
+ { result = new BinaryExpression( result, p2, p3 ); }
+ )*
+ { return result; }
+}
+
+Expression UnaryExpression( Environment env ) :
+{
+ int p1;
+ Expression p2;
+}
+{
+ LOOKAHEAD( "+" | "-" )
+ (
+ "+" { p1 = UnaryExpression.PLUS; }
+ |
+ "-" { p1 = UnaryExpression.MINUS; }
+ )
+ p2=UnaryExpression( env )
+ { return new UnaryExpression( p1, p2 ); }
+ |
+ LOOKAHEAD( "++" | "--" )
+ p2=PreIncrementExpression( env )
+ { return p2; }
+ |
+ p2=UnaryExpressionNotPlusMinus( env )
+ { return p2; }
+}
+
+Expression PreIncrementExpression( Environment env ) :
+{
+ int p1;
+ Expression p2;
+}
+{
+ (
+ "++" { p1 = UnaryExpression.PRE_INCREMENT; }
+ |
+ "--" { p1 = UnaryExpression.PRE_DECREMENT; }
+ )
+ p2=PrimaryExpression( env )
+ { return new UnaryExpression( p1, p2 ); }
+}
+
+Expression UnaryExpressionNotPlusMinus( Environment env ) :
+{
+ int p1;
+ Expression p2;
+}
+{
+ (
+ "~" { p1 = UnaryExpression.BIT_NOT; }
+ |
+ "!" { p1 = UnaryExpression.NOT; }
+ )
+ p2=UnaryExpression( env )
+ { return new UnaryExpression( p1, p2 ); }
+ |
+ LOOKAHEAD( CastLookahead() )
+ p2=CastExpression( env )
+ { return p2; }
+ |
+ p2=PostfixExpression( env )
+ { return p2; }
+}
+
+void CastLookahead( Environment env ) :
+ /* This method is lookahead only. */
+{}
+{
+ LOOKAHEAD(2)
+ "(" PrimitiveType()
+ |
+ LOOKAHEAD("(" Name() "[")
+ "(" Name() "[" "]"
+ |
+ LOOKAHEAD("(" Name() ")")
+ "(" Name() ")"
+ ( "~" | "!" | "(" | Identifier() | "this" | "super" | "new" | Literal() )
+ |
+ "(" Name() Identifier()
+ }
+
+Expression PostfixExpression( Environment env ) :
+{
+ Expression result;
+ Expression p1;
+ int p2 = -1;
+}
+{
+ p1=PrimaryExpression( env )
+ [
+ "++" { p2 = UnaryExpression.POST_INCREMENT; }
+ |
+ "--" { p2 = UnaryExpression.POST_DECREMENT; }
+ ]
+ {
+ if (p2 != -1) {
+ result = new UnaryExpression( p1, p2 );
+ } else {
+ result = p1;
+ }
+ }
+ { return result; }
+}
+
+CastExpression CastExpression( Environment env ) :
+{
+ TypeName p1;
+ Expression p2;
+
+ DebugOut.println( "#CastExpression()" );
+}
+{
+ LOOKAHEAD( "(" PrimitiveType() )
+ "(" p1=Type( env ) ")" p2=UnaryExpression( env )
+ { return new CastExpression( p1, p2 ); }
+ |
+ LOOKAHEAD( "(" Name() )
+ "(" p1=Type( env ) ")" p2=UnaryExpressionNotPlusMinus( env )
+ { return new CastExpression( p1, p2 ); }
+}
+
+Expression SelfAccess( Environment env ) :
+{
+ Expression result;
+ String p1 = null;
+}
+{
+ [ p1=Name() "." ] "this"
+ {
+ if (p1 != null) {
+ result = SelfAccess.makeThis( p1 );
+ } else {
+ result = SelfAccess.constantThis();
+ }
+ }
+ { return result; }
+}
+
+ClassLiteral ClassLiteral( Environment env ) :
+{
+ TypeName p1;
+}
+{
+ p1=Type( env ) "." "class"
+ { return new ClassLiteral( p1 ); }
+}
+
+Expression PrimaryExpression( Environment env ) :
+/* There must not be Name() . Identifier()
+ * There is a case that PrimaryPrefix is a Name() but is actualy
+ * FieldAccess(). This should be resolved later.
+ */
+{
+ Expression result;
+ Expression p1;
+ Expression p2;
+ Expression p3;
+ String p4;
+ ExpressionList p5;
+}
+{
+ p1=PrimaryPrefix( env )
+ { result = p1; }
+ ( LOOKAHEAD( "." | "[" | "(" )
+ (
+ LOOKAHEAD( "." "new" )
+ "." p2=AllocationExpression( env )
+ {
+ AllocationExpression alloc = (AllocationExpression) p2;
+ alloc.setEncloser( result );
+ result = alloc;
+ }
+ |
+ "[" p3=Expression( env ) "]"
+ { result = new ArrayAccess( result, p3 ); }
+ |
+ "." p4=Identifier()
+ { result = new FieldAccess( result, p4 ); }
+ |
+ p5=Arguments( env )
+ {
+ FieldAccess base = (FieldAccess) result;
+ Expression expr = base.getReferenceExpr();
+ String name = base.getName();
+ result = new MethodCall( expr, name, p5 );
+ }
+ )
+ )*
+ { return result; }
+}
+
+Expression PrimaryPrefix( Environment env ) :
+{
+ Expression p1;
+ String p2;
+
+ DebugOut.println( "#PrimaryPrefix()" );
+}
+{
+ p1=Literal()
+ { return p1; }
+ |
+ LOOKAHEAD( [ Name() "." ] "this" )
+ p1=SelfAccess( env )
+ { return p1; }
+ |
+ "super" "." p2=Identifier()
+ { return new FieldAccess( SelfAccess.constantSuper(), p2 ); }
+ |
+ "(" p1=Expression( env ) ")"
+ { return p1; }
+ |
+ p1=AllocationExpression( env )
+ { return p1; }
+ |
+ LOOKAHEAD( { ClassLiteralLookahead() } )
+ p1=ClassLiteral( env )
+ { return p1; }
+ |
+ p1=TempFieldAccess( env )
+ { return p1; }
+}
+
+FieldAccess TempFieldAccess( Environment env ) :
+/*
+ * Returns temporary expression as a field access;
+ * A field access without primary may be a variable.
+ * A variable may be qualified class name or field access.
+ */
+{
+ FieldAccess result;
+ String p1;
+ StringBuffer strbuf = null;
+}
+{
+ p1=Identifier()
+ ( LOOKAHEAD( "." Identifier() )
+ "."
+ {
+ if (strbuf == null) {
+ strbuf = new StringBuffer( p1 );
+ } else {
+ strbuf.append( "." + p1 );
+ }
+ }
+ p1=Identifier()
+ )*
+ {
+ if (strbuf == null || strbuf.length() == 0) {
+ result = new FieldAccess( (Variable) null, p1 );
+ } else {
+ Variable var = new Variable( strbuf.toString() );
+ result = new FieldAccess( var, p1 );
+ }
+ }
+ { return result; }
+}
+
+Literal Literal() :
+{
+ String p1;
+ Literal p2;
+}
+{
+ <INTEGER_LITERAL> { p1 = getToken( 0 ).image; }
+ { return new Literal( Literal.INTEGER, p1 ); }
+ |
+ <LONG_LITERAL> { p1 = getToken( 0 ).image; }
+ { return new Literal( Literal.LONG, p1 ); }
+ |
+ <FLOATING_POINT_LITERAL> { p1 = getToken( 0 ).image; }
+ { return new Literal( Literal.FLOAT, p1 ); }
+ |
+ <DOUBLE_FLOATING_POINT_LITERAL> { p1 = getToken( 0 ).image; }
+ { return new Literal( Literal.DOUBLE, p1 ); }
+ |
+ <CHARACTER_LITERAL> { p1 = getToken( 0 ).image; }
+ { return new Literal( Literal.CHARACTER, p1 ); }
+ |
+ <STRING_LITERAL> { p1 = getToken( 0 ).image; }
+ { return new Literal( Literal.STRING, p1 ); }
+ |
+ "true"
+ { return Literal.constantTrue(); }
+ |
+ "false"
+ { return Literal.constantFalse(); }
+ |
+ "null"
+ { return Literal.constantNull(); }
+}
+
+ExpressionList Arguments( Environment env ) :
+{
+ ExpressionList result = new ExpressionList();
+ Expression p1;
+
+ DebugOut.println( "#Arguments()" );
+}
+{
+ "("
+ [
+ p1=Expression( env )
+ { result.add( p1 ); }
+ (
+ "," p1=Expression( env )
+ { result.add( p1 ); }
+ )*
+ ]
+ ")"
+ { return result; }
+}
+
+Expression AllocationExpression( Environment env ) :
+{
+ Expression result;
+ AllocationExpression aloc_result;
+ TypeName p1;
+ ArrayAllocationExpression p2;
+ ExpressionList p3;
+ MemberDeclarationList p4 = null;
+
+ DebugOut.println( "#AllocationExpression()" );
+}
+{
+ LOOKAHEAD( "new" PrimitiveType() )
+ "new" p1=TypeWithoutDims( env )
+ p2=ArrayDimsAndInits( env, p1 )
+ { result = p2; }
+ { return result; }
+ |
+ "new" p1=TypeWithoutDims( env )
+ (
+ LOOKAHEAD( "[" )
+ p2=ArrayDimsAndInits( env, p1 )
+ { result = p2; }
+ |
+ p3=Arguments( env )
+ { aloc_result = new AllocationExpression( p1, p3, p4 ); }
+ [
+ p4=ClassBody( new ClassEnvironment( env ) )
+ { aloc_result.setClassBody( p4 ); }
+ ]
+ { result = aloc_result; }
+ )
+ { return result; }
+}
+
+TypeName TypeWithoutDims( Environment env ) :
+{
+ String p1;
+ Hashtable p2;
+}
+{
+ ( p1=PrimitiveType() | p1=Name() )
+ p2=OpenJavaTypeSuffixListOpt( env, p1 )
+ { return new TypeName( p1, p2 ); }
+}
+
+ArrayAllocationExpression ArrayDimsAndInits( Environment env, TypeName type ) :
+/*
+ * The first LOOKAHEAD specification below is to parse to PrimarySuffix
+ * if there is an expression between the "[...]".
+ */
+{
+ Expression p1;
+ int p2;
+ ArrayInitializer p3;
+ ExpressionList exprs = new ExpressionList();
+}
+{
+ LOOKAHEAD( "[" "]" )
+ p2=EmptyBracketsOpt() p3=ArrayInitializer( env )
+ { for (int i = 0; i < p2; ++i) exprs.add( null ); }
+ { return new ArrayAllocationExpression( type, exprs, p3 ); }
+ |
+ LOOKAHEAD( "[" )
+ ( LOOKAHEAD( { (getToken( 1 ).kind == LBRACKET
+ && getToken( 2 ).kind != RBRACKET) } )
+ "[" p1=Expression( env ) { exprs.add( p1 ); } "]"
+ )+
+ p2=EmptyBracketsOpt()
+ { for (int i = 0; i < p2; ++i) exprs.add( null ); }
+ { return new ArrayAllocationExpression( type, exprs ); }
+}
+
+StatementList BlockedBody( Environment env ) :
+/* See also Block. This is for bodys but for statement */
+{
+ StatementList p1;
+}
+{
+ "{" p1=BlockOrStatementListOpt( env ) "}"
+ { return p1; }
+}
+
+/*
+ * Statement syntax follows.
+ */
+
+Statement Statement( Environment env ) :
+{
+ Statement p1;
+}
+{
+ LOOKAHEAD( Identifier() ":" )
+ p1=LabeledStatement( env )
+ { return p1; }
+ |
+ p1=Block( env )
+ { return p1; }
+ |
+ p1=EmptyStatement( env )
+ { return p1; }
+ |
+ p1=SwitchStatement( env )
+ { return p1; }
+ |
+ p1=IfStatement( env )
+ { return p1; }
+ |
+ p1=WhileStatement( env )
+ { return p1; }
+ |
+ p1=DoWhileStatement( env )
+ { return p1; }
+ |
+ p1=ForStatement( env )
+ { return p1; }
+ |
+ p1=BreakStatement( env )
+ { return p1; }
+ |
+ p1=ContinueStatement( env )
+ { return p1; }
+ |
+ p1=ReturnStatement( env )
+ { return p1; }
+ |
+ p1=ThrowStatement( env )
+ { return p1; }
+ |
+ p1=SynchronizedStatement( env )
+ { return p1; }
+ |
+ p1=TryStatement( env )
+ { return p1; }
+ |
+ p1=ExpressionStatement( env )
+ { return p1; }
+}
+
+LabeledStatement LabeledStatement( Environment env ) :
+{
+ String p1;
+ Statement p2;
+
+ DebugOut.println( "#LabeledStatement()" );
+}
+{
+ p1=Identifier() ":" p2=Statement( env )
+ { return new LabeledStatement( p1, p2 ); }
+}
+
+Block Block( Environment env ) :
+/* See also BlockedBody. This is to be statement */
+{
+ StatementList p1;
+ DebugOut.println( "#Block()" );
+}
+{
+ "{" p1=BlockOrStatementListOpt( env ) "}"
+ { return new Block( p1 ); }
+}
+
+StatementList BlockOrStatementListOpt( Environment env ) :
+{
+ StatementList result = new StatementList();
+ StatementList p1;
+}
+{
+ LOOKAHEAD( { (getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF
+ && getToken( 1 ).kind != CASE
+ && getToken( 1 ).kind != _DEFAULT ) } )
+ ( LOOKAHEAD( { (getToken( 1 ).kind != RBRACE
+ && getToken( 1 ).kind != EOF
+ && getToken( 1 ).kind != CASE
+ && getToken( 1 ).kind != _DEFAULT ) } )
+ p1=BlockOrStatement( env )
+ { result.addAll( p1 ); }
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+StatementList BlockOrStatement( Environment env ) :
+{
+ Statement p1;
+ StatementList p2;
+}
+{
+ p1=UnmodifiedClassDeclaration( new ClassEnvironment( env ) )
+ { return new StatementList( p1 ); }
+ |
+ LOOKAHEAD( { LocalVariableDeclarationLookahead( env ) } )
+ p2=LocalVariableDeclaration( env ) ";"
+ { return p2; }
+ |
+ p1=Statement( env )
+ { return new StatementList( p1 ); }
+}
+
+StatementList LocalVariableDeclaration( Environment env ) :
+{
+ StatementList result = new StatementList();
+ ModifierList p1;
+ TypeName p2;
+ VariableDeclarator p3;
+ TypeName tspec;
+ String vname;
+ VariableInitializer vinit;
+ DebugOut.println( "#LocalVariableDeclaration()" );
+}
+{
+ p1=VariableModifiersOpt( env ) p2=Type( env )
+ p3=VariableDeclarator( env )
+ {
+ tspec = (TypeName) p2.makeRecursiveCopy();
+ tspec.addDimension( p3.getDimension() );
+ vname = p3.getVariable();
+ vinit = p3.getInitializer();
+ result.add( new VariableDeclaration( p1, tspec, vname, vinit ) );
+ }
+ (
+ "," p3=VariableDeclarator( env )
+ {
+ tspec = (TypeName) p2.makeRecursiveCopy();
+ tspec.addDimension( p3.getDimension() );
+ vname = p3.getVariable();
+ vinit = p3.getInitializer();
+ result.add( new VariableDeclaration( p1, tspec, vname, vinit ) );
+ }
+ )*
+ { return result; }
+}
+
+ModifierList VariableModifiersOpt( Environment env ) :
+{
+ ModifierList result = new ModifierList();
+ int p1;
+ String p2;
+}
+{
+ LOOKAHEAD( { modifierCheck( env, getToken( 1 ) ) } )
+ ( LOOKAHEAD( { ModifierLookahead( env ) } )
+ (
+ LOOKAHEAD( "final" )
+ p1=Modifier()
+ { result.add( p1 ); }
+ |
+ LOOKAHEAD( { OpenJavaModifierLookahead( env ) } )
+ p2=OpenJavaModifier()
+ { result.add( p2 ); }
+ )
+ )+
+ { return result; }
+ |
+ E()
+ { return result; }
+}
+
+EmptyStatement EmptyStatement( Environment env ) :
+{
+ DebugOut.println( "#EmptyStatement()" );
+}
+{
+ ";"
+ { return new EmptyStatement(); }
+}
+
+ExpressionStatement ExpressionStatement( Environment env ) :
+{
+ Expression p1;
+
+ DebugOut.println( "#ExpressionStatement()" );
+}
+{
+ p1=StatementExpression( env ) ";"
+ { return new ExpressionStatement( p1 ); }
+}
+
+Expression StatementExpression( Environment env ) :
+{
+ Expression p1;
+ /***********/
+}
+{
+ p1=PreIncrementExpression( env )
+ { return p1; }
+ |
+ /*LOOKAHEAD( PrimaryExpression( env ) AssignmentOperator() )*/
+ LOOKAHEAD( { AssignmentLookahead() } )
+ p1=AssignmentExpression( env )
+ { return p1; }
+ |
+ p1=PostfixExpression( env )
+ { return p1; }
+}
+
+SwitchStatement SwitchStatement( Environment env ) :
+{
+ Expression p1;
+ Expression p2;
+ StatementList p3;
+ CaseGroupList cplist = new CaseGroupList();
+ ExpressionList exprs;
+
+ DebugOut.println( "#SwitchStatement()" );
+}
+{
+ "switch" "(" p1=Expression( env ) ")" "{"
+ ( LOOKAHEAD( "case" | "default" )
+ { exprs = new ExpressionList(); }
+ ( LOOKAHEAD( "case" | "default" )
+ p2=SwitchLabel( env ) { exprs.add( p2 ); }
+ )+
+ p3=BlockOrStatementListOpt( env )
+ { cplist.add( new CaseGroup( exprs, p3 ) ); }
+ )*
+ "}"
+ { return new SwitchStatement( p1, cplist ); }
+}
+
+Expression SwitchLabel( Environment env ) :
+{
+ Expression p1;
+}
+{
+ "case" p1=Expression( env ) ":"
+ { return p1; }
+ |
+ "default" ":"
+ { return null; }
+}
+
+IfStatement IfStatement( Environment env ) :
+/*
+ * The disambiguating algorithm of JavaCC automatically binds dangling
+ * else's to the innermost if statement. The LOOKAHEAD specification
+ * is to tell JavaCC that we know what we are doing.
+ */
+{
+ IfStatement result;
+ Expression p1;
+ StatementList p2;
+ Statement p3;
+ StatementList true_part;
+ StatementList false_part = null;
+
+ DebugOut.println( "#IfStatement()" );
+}
+{
+ "if" "(" p1=Expression( env ) ")"
+ ( LOOKAHEAD(1)
+ p2=BlockedBody( env )
+ { true_part = p2; }
+ |
+ p3=Statement( env )
+ { true_part = new StatementList( p3 ); }
+ )
+ [ LOOKAHEAD(1)
+ "else"
+ ( LOOKAHEAD(1)
+ p2=BlockedBody( env )
+ { false_part = p2; }
+ |
+ p3=Statement( env )
+ { false_part = new StatementList( p3 ); }
+ )
+ ]
+ { return new IfStatement( p1, true_part, false_part ); }
+}
+
+WhileStatement WhileStatement( Environment env ) :
+{
+ Expression p1;
+ StatementList p2;
+ Statement p3;
+ StatementList body;
+
+ DebugOut.println( "#WhileStatement()" );
+}
+{
+ "while" "(" p1=Expression( env ) ")"
+ ( LOOKAHEAD(1)
+ p2=BlockedBody( env )
+ { body = p2; }
+ |
+ p3=Statement( env )
+ { body = new StatementList( p3 ); }
+ )
+ { return new WhileStatement( p1, body ); }
+}
+
+DoWhileStatement DoWhileStatement( Environment env ) :
+{
+ StatementList p1;
+ Statement p2;
+ Expression p3;
+ StatementList body;
+
+ DebugOut.println( "#DoWhileStatement()" );
+}
+{
+ "do"
+ ( LOOKAHEAD(1)
+ p1=BlockedBody( env )
+ { body = p1; }
+ |
+ p2=Statement( env )
+ { body = new StatementList( p2 ); }
+ )
+ "while" "(" p3=Expression( env ) ")" ";"
+ { return new DoWhileStatement( body, p3 ); }
+}
+
+ForStatement ForStatement( Environment env ) :
+{
+ ForStatement result;
+ TypeName p1 = null;
+ VariableDeclarator[] p2 = null;
+ ExpressionList p3 = null;
+ Expression p4 = null;
+ ExpressionList p5 = null;
+ StatementList p6;
+ Statement p7;
+ StatementList body;
+
+ DebugOut.println( "#ForStatement()" );
+}
+{
+ "for" "("
+ [ LOOKAHEAD( { (getToken( 1 ).kind != SEMICOLON) } )
+ (
+ LOOKAHEAD( { LocalVariableDeclarationLookahead( env ) } )
+ p1=Type( env )
+ p2=VariableDeclaratorList( env )
+ |
+ p3=StatementExpressionList( env )
+ )
+ ]
+ ";"
+ [ LOOKAHEAD( { (getToken( 1 ).kind != SEMICOLON) } )
+ p4=Expression( env )
+ ]
+ ";"
+ [ LOOKAHEAD( { (getToken( 1 ).kind != RPAREN) } )
+ p5=StatementExpressionList( env )
+ ]
+ ")"
+ (
+ LOOKAHEAD(1)
+ p6=BlockedBody( env )
+ { body = p6; }
+ |
+ p7=Statement( env )
+ { body = new StatementList( p7 ); }
+ )
+ {
+ if (p1 != null) {
+ result = new ForStatement( p1, p2, p4, p5, body );
+ } else if (p3 != null) {
+ result = new ForStatement( p3, p4, p5, body );
+ } else {
+ result = new ForStatement( new ExpressionList(), p4, p5, body );
+ }
+ }
+ { return result; }
+}
+
+VariableDeclarator[] VariableDeclaratorList( Environment env ) :
+{
+ VariableDeclarator[] result;
+ VariableDeclarator p1;
+ Vector v = new Vector();
+
+ DebugOut.println( "#LocalVariableDeclaration()" );
+}
+{
+ p1=VariableDeclarator( env )
+ { v.addElement( p1 ); }
+ (
+ "," p1=VariableDeclarator( env )
+ { v.addElement( p1 ); }
+ )*
+ {
+ result = new VariableDeclarator[v.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (VariableDeclarator) v.elementAt( i );
+ }
+ return result;
+ }
+}
+
+ExpressionList StatementExpressionList( Environment env ) :
+{
+ ExpressionList result = new ExpressionList();
+ Expression p1;
+}
+{
+ p1=StatementExpression( env )
+ { result.add( p1 ); }
+ (
+ "," p1=StatementExpression( env )
+ { result.add( p1 ); }
+ )*
+ { return result; }
+}
+
+BreakStatement BreakStatement( Environment env ) :
+{
+ BreakStatement result;
+ String p1 = null;
+
+ DebugOut.println( "#BreakStatement()" );
+}
+{
+ "break" [ p1=Identifier() ] ";"
+ {
+ if (p1 != null) {
+ result = new BreakStatement( p1 );
+ } else {
+ result = new BreakStatement();
+ }
+ }
+ { return result; }
+}
+
+ContinueStatement ContinueStatement( Environment env ) :
+{
+ ContinueStatement result;
+ String p1 = null;
+
+ DebugOut.println( "#ContinueStatement()" );
+}
+{
+ "continue" [ p1=Identifier() ] ";"
+ {
+ if (p1 != null) {
+ result = new ContinueStatement( p1 );
+ } else {
+ result = new ContinueStatement();
+ }
+ }
+ { return result; }
+}
+
+ReturnStatement ReturnStatement( Environment env ) :
+{
+ ReturnStatement result;
+ Expression p1 = null;
+
+ DebugOut.println( "#ReturnStatement()" );
+}
+{
+ "return"
+ [
+ LOOKAHEAD( { (getToken(1).kind != SEMICOLON)} )
+ p1=Expression( env )
+ ]
+ ";"
+ {
+ if (p1 != null) {
+ result = new ReturnStatement( p1 );
+ } else {
+ result = new ReturnStatement();
+ }
+ }
+ { return result; }
+}
+
+ThrowStatement ThrowStatement( Environment env ) :
+{
+ Statement result;
+ Expression p1;
+
+ DebugOut.println( "#ThrowStatement()" );
+}
+{
+ "throw" p1=Expression( env ) ";"
+ { return new ThrowStatement( p1 ); }
+}
+
+SynchronizedStatement SynchronizedStatement( Environment env ) :
+{
+ Expression p1;
+ StatementList p2;
+
+ DebugOut.println( "#SynchronizedStatement()" );
+}
+{
+ "synchronized" "(" p1=Expression( env ) ")" p2=BlockedBody( env )
+ { return new SynchronizedStatement( p1, p2 ); }
+}
+
+TryStatement TryStatement( Environment base_env ) :
+/*
+ * Semantic check required here to make sure that at least one
+ * finally/catch is present.
+ */
+{
+ Environment env = new ClosedEnvironment( base_env );
+ TryStatement result;
+ StatementList p1;
+ Parameter p2;
+ StatementList p3;
+ StatementList p4 = null;
+ CatchList catches = new CatchList();
+
+ DebugOut.println( "#TryStatement()" );
+}
+{
+ "try" p1=BlockedBody( env )
+ ( LOOKAHEAD( "catch" )
+ { env = new ClosedEnvironment( base_env ); }
+ "catch" "(" p2=FormalParameter( env ) ")" p3=BlockedBody( env )
+ { catches.add( new CatchBlock( p2, p3 ) ); }
+ )*
+ [
+ "finally" p4=BlockedBody( new ClosedEnvironment( base_env ) )
+ ]
+ { result = new TryStatement( p1, catches, p4 ); }
+ { return result; }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/ParserConstants.java b/src/main/java/io/devnulllabs/openjava/tools/parser/ParserConstants.java
new file mode 100644
index 0000000..ce28d57
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/ParserConstants.java
@@ -0,0 +1,254 @@
+/* Generated By:JavaCC: Do not edit this line. ParserConstants.java */
+package io.devnulllabs.openjava.tools.parser;
+
+public interface ParserConstants {
+
+ int EOF = 0;
+ int SINGLE_LINE_COMMENT = 9;
+ int FORMAL_COMMENT = 10;
+ int MULTI_LINE_COMMENT = 11;
+ int ABSTRACT = 13;
+ int BOOLEAN = 14;
+ int BREAK = 15;
+ int BYTE = 16;
+ int CASE = 17;
+ int CATCH = 18;
+ int CHAR = 19;
+ int CLASS = 20;
+ int CONST = 21;
+ int CONTINUE = 22;
+ int _DEFAULT = 23;
+ int DO = 24;
+ int DOUBLE = 25;
+ int ELSE = 26;
+ int EXTENDS = 27;
+ int FALSE = 28;
+ int FINAL = 29;
+ int FINALLY = 30;
+ int FLOAT = 31;
+ int FOR = 32;
+ int GOTO = 33;
+ int IF = 34;
+ int IMPLEMENTS = 35;
+ int IMPORT = 36;
+ int INSTANCEOF = 37;
+ int INT = 38;
+ int INTERFACE = 39;
+ int LONG = 40;
+ int NATIVE = 41;
+ int NEW = 42;
+ int NULL = 43;
+ int PACKAGE = 44;
+ int PRIVATE = 45;
+ int PROTECTED = 46;
+ int PUBLIC = 47;
+ int RETURN = 48;
+ int SHORT = 49;
+ int STATIC = 50;
+ int SUPER = 51;
+ int SWITCH = 52;
+ int SYNCHRONIZED = 53;
+ int THIS = 54;
+ int THROW = 55;
+ int THROWS = 56;
+ int TRANSIENT = 57;
+ int TRUE = 58;
+ int TRY = 59;
+ int VOID = 60;
+ int VOLATILE = 61;
+ int WHILE = 62;
+ int METACLASS = 63;
+ int INSTANTIATES = 64;
+ int INTEGER_LITERAL = 65;
+ int LONG_LITERAL = 66;
+ int DECIMAL_LITERAL = 67;
+ int HEX_LITERAL = 68;
+ int OCTAL_LITERAL = 69;
+ int DOUBLE_FLOATING_POINT_LITERAL = 70;
+ int FLOATING_POINT_LITERAL = 71;
+ int EXPONENT = 72;
+ int CHARACTER_LITERAL = 73;
+ int STRING_LITERAL = 74;
+ int IDENTIFIER = 75;
+ int LETTER = 76;
+ int DIGIT = 77;
+ int LPAREN = 78;
+ int RPAREN = 79;
+ int LBRACE = 80;
+ int RBRACE = 81;
+ int LBRACKET = 82;
+ int RBRACKET = 83;
+ int SEMICOLON = 84;
+ int COMMA = 85;
+ int DOT = 86;
+ int ASSIGN = 87;
+ int GT = 88;
+ int LT = 89;
+ int BANG = 90;
+ int TILDE = 91;
+ int HOOK = 92;
+ int COLON = 93;
+ int EQ = 94;
+ int LE = 95;
+ int GE = 96;
+ int NE = 97;
+ int SC_OR = 98;
+ int SC_AND = 99;
+ int INCR = 100;
+ int DECR = 101;
+ int PLUS = 102;
+ int MINUS = 103;
+ int STAR = 104;
+ int SLASH = 105;
+ int BIT_AND = 106;
+ int BIT_OR = 107;
+ int XOR = 108;
+ int REM = 109;
+ int LSHIFT = 110;
+ int RSIGNEDSHIFT = 111;
+ int RUNSIGNEDSHIFT = 112;
+ int PLUSASSIGN = 113;
+ int MINUSASSIGN = 114;
+ int STARASSIGN = 115;
+ int SLASHASSIGN = 116;
+ int ANDASSIGN = 117;
+ int ORASSIGN = 118;
+ int XORASSIGN = 119;
+ int REMASSIGN = 120;
+ int LSHIFTASSIGN = 121;
+ int RSIGNEDSHIFTASSIGN = 122;
+ int RUNSIGNEDSHIFTASSIGN = 123;
+
+ int DEFAULT = 0;
+ int IN_SINGLE_LINE_COMMENT = 1;
+ int IN_FORMAL_COMMENT = 2;
+ int IN_MULTI_LINE_COMMENT = 3;
+
+ String[] tokenImage = {
+ "<EOF>",
+ "\" \"",
+ "\"\\t\"",
+ "\"\\n\"",
+ "\"\\r\"",
+ "\"\\f\"",
+ "<token of kind 6>",
+ "\"//\"",
+ "\"/*\"",
+ "<SINGLE_LINE_COMMENT>",
+ "\"*/\"",
+ "\"*/\"",
+ "<token of kind 12>",
+ "\"abstract\"",
+ "\"boolean\"",
+ "\"break\"",
+ "\"byte\"",
+ "\"case\"",
+ "\"catch\"",
+ "\"char\"",
+ "\"class\"",
+ "\"const\"",
+ "\"continue\"",
+ "\"default\"",
+ "\"do\"",
+ "\"double\"",
+ "\"else\"",
+ "\"extends\"",
+ "\"false\"",
+ "\"final\"",
+ "\"finally\"",
+ "\"float\"",
+ "\"for\"",
+ "\"goto\"",
+ "\"if\"",
+ "\"implements\"",
+ "\"import\"",
+ "\"instanceof\"",
+ "\"int\"",
+ "\"interface\"",
+ "\"long\"",
+ "\"native\"",
+ "\"new\"",
+ "\"null\"",
+ "\"package\"",
+ "\"private\"",
+ "\"protected\"",
+ "\"public\"",
+ "\"return\"",
+ "\"short\"",
+ "\"static\"",
+ "\"super\"",
+ "\"switch\"",
+ "\"synchronized\"",
+ "\"this\"",
+ "\"throw\"",
+ "\"throws\"",
+ "\"transient\"",
+ "\"true\"",
+ "\"try\"",
+ "\"void\"",
+ "\"volatile\"",
+ "\"while\"",
+ "\"metaclass\"",
+ "\"instantiates\"",
+ "<INTEGER_LITERAL>",
+ "<LONG_LITERAL>",
+ "<DECIMAL_LITERAL>",
+ "<HEX_LITERAL>",
+ "<OCTAL_LITERAL>",
+ "<DOUBLE_FLOATING_POINT_LITERAL>",
+ "<FLOATING_POINT_LITERAL>",
+ "<EXPONENT>",
+ "<CHARACTER_LITERAL>",
+ "<STRING_LITERAL>",
+ "<IDENTIFIER>",
+ "<LETTER>",
+ "<DIGIT>",
+ "\"(\"",
+ "\")\"",
+ "\"{\"",
+ "\"}\"",
+ "\"[\"",
+ "\"]\"",
+ "\";\"",
+ "\",\"",
+ "\".\"",
+ "\"=\"",
+ "\">\"",
+ "\"<\"",
+ "\"!\"",
+ "\"~\"",
+ "\"?\"",
+ "\":\"",
+ "\"==\"",
+ "\"<=\"",
+ "\">=\"",
+ "\"!=\"",
+ "\"||\"",
+ "\"&&\"",
+ "\"++\"",
+ "\"--\"",
+ "\"+\"",
+ "\"-\"",
+ "\"*\"",
+ "\"/\"",
+ "\"&\"",
+ "\"|\"",
+ "\"^\"",
+ "\"%\"",
+ "\"<<\"",
+ "\">>\"",
+ "\">>>\"",
+ "\"+=\"",
+ "\"-=\"",
+ "\"*=\"",
+ "\"/=\"",
+ "\"&=\"",
+ "\"|=\"",
+ "\"^=\"",
+ "\"%=\"",
+ "\"<<=\"",
+ "\">>=\"",
+ "\">>>=\"",
+ };
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java b/src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java
new file mode 100644
index 0000000..648a1b1
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java
@@ -0,0 +1,1820 @@
+/* Generated By:JavaCC: Do not edit this line. ParserTokenManager.java */
+package io.devnulllabs.openjava.tools.parser;
+
+public class ParserTokenManager implements ParserConstants
+{
+ public java.io.PrintStream debugStream = System.out;
+ public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
+private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1)
+{
+ switch (pos)
+ {
+ case 0:
+ if ((active0 & 0x180L) != 0L || (active1 & 0x10020000000000L) != 0L)
+ return 2;
+ if ((active1 & 0x400000L) != 0L)
+ return 75;
+ if ((active0 & 0xffffffffffffe000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ return 23;
+ }
+ return -1;
+ case 1:
+ if ((active0 & 0x100L) != 0L)
+ return 0;
+ if ((active0 & 0x403000000L) != 0L)
+ return 23;
+ if ((active0 & 0xfffffffbfcffe000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ if (jjmatchedPos != 1)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 1;
+ }
+ return 23;
+ }
+ return -1;
+ case 2:
+ if ((active0 & 0x80004c100000000L) != 0L)
+ return 23;
+ if ((active0 & 0xf7fffb3afeffe000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ if (jjmatchedPos != 2)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 2;
+ }
+ return 23;
+ }
+ return -1;
+ case 3:
+ if ((active0 & 0xe3bff2b8faf4e000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 3;
+ return 23;
+ }
+ if ((active0 & 0x14400902040b0000L) != 0L)
+ return 23;
+ return -1;
+ case 4:
+ if ((active0 & 0x418a0000f0348000L) != 0L)
+ return 23;
+ if ((active0 & 0xa235f2b80ac06000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ if (jjmatchedPos != 4)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 4;
+ }
+ return 23;
+ }
+ return -1;
+ case 5:
+ if ((active0 & 0x115821002000000L) != 0L)
+ return 23;
+ if ((active0 & 0xa22070a848c06000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 5;
+ return 23;
+ }
+ return -1;
+ case 6:
+ if ((active0 & 0xa22040a800402000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 6;
+ return 23;
+ }
+ if ((active0 & 0x300048804000L) != 0L)
+ return 23;
+ return -1;
+ case 7:
+ if ((active0 & 0x822040a800000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 7;
+ return 23;
+ }
+ if ((active0 & 0x2000000000402000L) != 0L)
+ return 23;
+ return -1;
+ case 8:
+ if ((active0 & 0x8200408000000000L) != 0L)
+ return 23;
+ if ((active0 & 0x20002800000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 8;
+ return 23;
+ }
+ return -1;
+ case 9:
+ if ((active0 & 0x20000000000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 9;
+ return 23;
+ }
+ if ((active0 & 0x2800000000L) != 0L)
+ return 23;
+ return -1;
+ case 10:
+ if ((active0 & 0x20000000000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 10;
+ return 23;
+ }
+ return -1;
+ default :
+ return -1;
+ }
+}
+private final int jjStartNfa_0(int pos, long active0, long active1)
+{
+ return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1);
+}
+private final int jjStopAtPos(int pos, int kind)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ return pos + 1;
+}
+private final int jjStartNfaWithStates_0(int pos, int kind, int state)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return pos + 1; }
+ return jjMoveNfa_0(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_0()
+{
+ switch(curChar)
+ {
+ case 33:
+ jjmatchedKind = 90;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000L);
+ case 37:
+ jjmatchedKind = 109;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x100000000000000L);
+ case 38:
+ jjmatchedKind = 106;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x20000800000000L);
+ case 40:
+ return jjStopAtPos(0, 78);
+ case 41:
+ return jjStopAtPos(0, 79);
+ case 42:
+ jjmatchedKind = 104;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x8000000000000L);
+ case 43:
+ jjmatchedKind = 102;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x2001000000000L);
+ case 44:
+ return jjStopAtPos(0, 85);
+ case 45:
+ jjmatchedKind = 103;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x4002000000000L);
+ case 46:
+ return jjStartNfaWithStates_0(0, 86, 75);
+ case 47:
+ jjmatchedKind = 105;
+ return jjMoveStringLiteralDfa1_0(0x180L, 0x10000000000000L);
+ case 58:
+ return jjStopAtPos(0, 93);
+ case 59:
+ return jjStopAtPos(0, 84);
+ case 60:
+ jjmatchedKind = 89;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x200400080000000L);
+ case 61:
+ jjmatchedKind = 87;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x40000000L);
+ case 62:
+ jjmatchedKind = 88;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0xc01800100000000L);
+ case 63:
+ return jjStopAtPos(0, 92);
+ case 91:
+ return jjStopAtPos(0, 82);
+ case 93:
+ return jjStopAtPos(0, 83);
+ case 94:
+ jjmatchedKind = 108;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x80000000000000L);
+ case 97:
+ return jjMoveStringLiteralDfa1_0(0x2000L, 0x0L);
+ case 98:
+ return jjMoveStringLiteralDfa1_0(0x1c000L, 0x0L);
+ case 99:
+ return jjMoveStringLiteralDfa1_0(0x7e0000L, 0x0L);
+ case 100:
+ return jjMoveStringLiteralDfa1_0(0x3800000L, 0x0L);
+ case 101:
+ return jjMoveStringLiteralDfa1_0(0xc000000L, 0x0L);
+ case 102:
+ return jjMoveStringLiteralDfa1_0(0x1f0000000L, 0x0L);
+ case 103:
+ return jjMoveStringLiteralDfa1_0(0x200000000L, 0x0L);
+ case 105:
+ return jjMoveStringLiteralDfa1_0(0xfc00000000L, 0x1L);
+ case 108:
+ return jjMoveStringLiteralDfa1_0(0x10000000000L, 0x0L);
+ case 109:
+ return jjMoveStringLiteralDfa1_0(0x8000000000000000L, 0x0L);
+ case 110:
+ return jjMoveStringLiteralDfa1_0(0xe0000000000L, 0x0L);
+ case 112:
+ return jjMoveStringLiteralDfa1_0(0xf00000000000L, 0x0L);
+ case 114:
+ return jjMoveStringLiteralDfa1_0(0x1000000000000L, 0x0L);
+ case 115:
+ return jjMoveStringLiteralDfa1_0(0x3e000000000000L, 0x0L);
+ case 116:
+ return jjMoveStringLiteralDfa1_0(0xfc0000000000000L, 0x0L);
+ case 118:
+ return jjMoveStringLiteralDfa1_0(0x3000000000000000L, 0x0L);
+ case 119:
+ return jjMoveStringLiteralDfa1_0(0x4000000000000000L, 0x0L);
+ case 123:
+ return jjStopAtPos(0, 80);
+ case 124:
+ jjmatchedKind = 107;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x40000400000000L);
+ case 125:
+ return jjStopAtPos(0, 81);
+ case 126:
+ return jjStopAtPos(0, 91);
+ default :
+ return jjMoveNfa_0(3, 0);
+ }
+}
+private final int jjMoveStringLiteralDfa1_0(long active0, long active1)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(0, active0, active1);
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 38:
+ if ((active1 & 0x800000000L) != 0L)
+ return jjStopAtPos(1, 99);
+ break;
+ case 42:
+ if ((active0 & 0x100L) != 0L)
+ return jjStartNfaWithStates_0(1, 8, 0);
+ break;
+ case 43:
+ if ((active1 & 0x1000000000L) != 0L)
+ return jjStopAtPos(1, 100);
+ break;
+ case 45:
+ if ((active1 & 0x2000000000L) != 0L)
+ return jjStopAtPos(1, 101);
+ break;
+ case 47:
+ if ((active0 & 0x80L) != 0L)
+ return jjStopAtPos(1, 7);
+ break;
+ case 60:
+ if ((active1 & 0x400000000000L) != 0L)
+ {
+ jjmatchedKind = 110;
+ jjmatchedPos = 1;
+ }
+ return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x200000000000000L);
+ case 61:
+ if ((active1 & 0x40000000L) != 0L)
+ return jjStopAtPos(1, 94);
+ else if ((active1 & 0x80000000L) != 0L)
+ return jjStopAtPos(1, 95);
+ else if ((active1 & 0x100000000L) != 0L)
+ return jjStopAtPos(1, 96);
+ else if ((active1 & 0x200000000L) != 0L)
+ return jjStopAtPos(1, 97);
+ else if ((active1 & 0x2000000000000L) != 0L)
+ return jjStopAtPos(1, 113);
+ else if ((active1 & 0x4000000000000L) != 0L)
+ return jjStopAtPos(1, 114);
+ else if ((active1 & 0x8000000000000L) != 0L)
+ return jjStopAtPos(1, 115);
+ else if ((active1 & 0x10000000000000L) != 0L)
+ return jjStopAtPos(1, 116);
+ else if ((active1 & 0x20000000000000L) != 0L)
+ return jjStopAtPos(1, 117);
+ else if ((active1 & 0x40000000000000L) != 0L)
+ return jjStopAtPos(1, 118);
+ else if ((active1 & 0x80000000000000L) != 0L)
+ return jjStopAtPos(1, 119);
+ else if ((active1 & 0x100000000000000L) != 0L)
+ return jjStopAtPos(1, 120);
+ break;
+ case 62:
+ if ((active1 & 0x800000000000L) != 0L)
+ {
+ jjmatchedKind = 111;
+ jjmatchedPos = 1;
+ }
+ return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0xc01000000000000L);
+ case 97:
+ return jjMoveStringLiteralDfa2_0(active0, 0x120010060000L, active1, 0L);
+ case 98:
+ return jjMoveStringLiteralDfa2_0(active0, 0x2000L, active1, 0L);
+ case 101:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8001040000800000L, active1, 0L);
+ case 102:
+ if ((active0 & 0x400000000L) != 0L)
+ return jjStartNfaWithStates_0(1, 34, 23);
+ break;
+ case 104:
+ return jjMoveStringLiteralDfa2_0(active0, 0x41c2000000080000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa2_0(active0, 0x60000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa2_0(active0, 0x84100000L, active1, 0L);
+ case 109:
+ return jjMoveStringLiteralDfa2_0(active0, 0x1800000000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa2_0(active0, 0xe000000000L, active1, 0x1L);
+ case 111:
+ if ((active0 & 0x1000000L) != 0L)
+ {
+ jjmatchedKind = 24;
+ jjmatchedPos = 1;
+ }
+ return jjMoveStringLiteralDfa2_0(active0, 0x3000010302604000L, active1, 0L);
+ case 114:
+ return jjMoveStringLiteralDfa2_0(active0, 0xe00600000008000L, active1, 0L);
+ case 116:
+ return jjMoveStringLiteralDfa2_0(active0, 0x4000000000000L, active1, 0L);
+ case 117:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8880000000000L, active1, 0L);
+ case 119:
+ return jjMoveStringLiteralDfa2_0(active0, 0x10000000000000L, active1, 0L);
+ case 120:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8000000L, active1, 0L);
+ case 121:
+ return jjMoveStringLiteralDfa2_0(active0, 0x20000000010000L, active1, 0L);
+ case 124:
+ if ((active1 & 0x400000000L) != 0L)
+ return jjStopAtPos(1, 98);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(0, active0, active1);
+}
+private final int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(0, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(1, active0, active1);
+ return 2;
+ }
+ switch(curChar)
+ {
+ case 61:
+ if ((active1 & 0x200000000000000L) != 0L)
+ return jjStopAtPos(2, 121);
+ else if ((active1 & 0x400000000000000L) != 0L)
+ return jjStopAtPos(2, 122);
+ break;
+ case 62:
+ if ((active1 & 0x1000000000000L) != 0L)
+ {
+ jjmatchedKind = 112;
+ jjmatchedPos = 2;
+ }
+ return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x800000000000000L);
+ case 97:
+ return jjMoveStringLiteralDfa3_0(active0, 0x204000000180000L, active1, 0L);
+ case 98:
+ return jjMoveStringLiteralDfa3_0(active0, 0x800000000000L, active1, 0L);
+ case 99:
+ return jjMoveStringLiteralDfa3_0(active0, 0x100000000000L, active1, 0L);
+ case 101:
+ return jjMoveStringLiteralDfa3_0(active0, 0x8000L, active1, 0L);
+ case 102:
+ return jjMoveStringLiteralDfa3_0(active0, 0x800000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa3_0(active0, 0x5050200000000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2000080010000000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa3_0(active0, 0x20010060600000L, active1, 0L);
+ case 111:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2400080004000L, active1, 0L);
+ case 112:
+ return jjMoveStringLiteralDfa3_0(active0, 0x8001800000000L, active1, 0L);
+ case 114:
+ if ((active0 & 0x100000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 32, 23);
+ return jjMoveStringLiteralDfa3_0(active0, 0x180000000000000L, active1, 0L);
+ case 115:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2004022000L, active1, 0x1L);
+ case 116:
+ if ((active0 & 0x4000000000L) != 0L)
+ {
+ jjmatchedKind = 38;
+ jjmatchedPos = 2;
+ }
+ return jjMoveStringLiteralDfa3_0(active0, 0x8001028208050000L, active1, 0L);
+ case 117:
+ return jjMoveStringLiteralDfa3_0(active0, 0x400000002000000L, active1, 0L);
+ case 119:
+ if ((active0 & 0x40000000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 42, 23);
+ break;
+ case 121:
+ if ((active0 & 0x800000000000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 59, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(1, active0, active1);
+}
+private final int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(1, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(2, active0, active1);
+ return 3;
+ }
+ switch(curChar)
+ {
+ case 61:
+ if ((active1 & 0x800000000000000L) != 0L)
+ return jjStopAtPos(3, 123);
+ break;
+ case 97:
+ return jjMoveStringLiteralDfa4_0(active0, 0xa0000000e0808000L, active1, 0L);
+ case 98:
+ return jjMoveStringLiteralDfa4_0(active0, 0x2000000L, active1, 0L);
+ case 99:
+ return jjMoveStringLiteralDfa4_0(active0, 0x20000000040000L, active1, 0L);
+ case 100:
+ if ((active0 & 0x1000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 60, 23);
+ break;
+ case 101:
+ if ((active0 & 0x10000L) != 0L)
+ return jjStartNfaWithStates_0(3, 16, 23);
+ else if ((active0 & 0x20000L) != 0L)
+ return jjStartNfaWithStates_0(3, 17, 23);
+ else if ((active0 & 0x4000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 26, 23);
+ else if ((active0 & 0x400000000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 58, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x8008008000000L, active1, 0L);
+ case 103:
+ if ((active0 & 0x10000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 40, 23);
+ break;
+ case 105:
+ return jjMoveStringLiteralDfa4_0(active0, 0x20000000000L, active1, 0L);
+ case 107:
+ return jjMoveStringLiteralDfa4_0(active0, 0x100000000000L, active1, 0L);
+ case 108:
+ if ((active0 & 0x80000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 43, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x4000800800004000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa4_0(active0, 0x200000000000000L, active1, 0L);
+ case 111:
+ if ((active0 & 0x200000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 33, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x180001000000000L, active1, 0L);
+ case 114:
+ if ((active0 & 0x80000L) != 0L)
+ return jjStartNfaWithStates_0(3, 19, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x40000000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 54, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x10300000L, active1, 0L);
+ case 116:
+ return jjMoveStringLiteralDfa4_0(active0, 0x14402000402000L, active1, 0x1L);
+ case 117:
+ return jjMoveStringLiteralDfa4_0(active0, 0x1000000000000L, active1, 0L);
+ case 118:
+ return jjMoveStringLiteralDfa4_0(active0, 0x200000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(2, active0, active1);
+}
+private final int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(2, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(3, active0, active1);
+ return 4;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa5_0(active0, 0x302000000000L, active1, 0x1L);
+ case 99:
+ return jjMoveStringLiteralDfa5_0(active0, 0x8010000000000000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x10000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 28, 23);
+ else if ((active0 & 0x4000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 62, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x400800004000L, active1, 0L);
+ case 104:
+ if ((active0 & 0x40000L) != 0L)
+ return jjStartNfaWithStates_0(4, 18, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x20000000000000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa5_0(active0, 0x4800000400000L, active1, 0L);
+ case 107:
+ if ((active0 & 0x8000L) != 0L)
+ return jjStartNfaWithStates_0(4, 15, 23);
+ break;
+ case 108:
+ if ((active0 & 0x20000000L) != 0L)
+ {
+ jjmatchedKind = 29;
+ jjmatchedPos = 4;
+ }
+ return jjMoveStringLiteralDfa5_0(active0, 0x42000000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa5_0(active0, 0x8000000L, active1, 0L);
+ case 114:
+ if ((active0 & 0x8000000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 51, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x1009000002000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x100000L) != 0L)
+ return jjStartNfaWithStates_0(4, 20, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x200000000000000L, active1, 0L);
+ case 116:
+ if ((active0 & 0x200000L) != 0L)
+ return jjStartNfaWithStates_0(4, 21, 23);
+ else if ((active0 & 0x80000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 31, 23);
+ else if ((active0 & 0x2000000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 49, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x2000000000000000L, active1, 0L);
+ case 117:
+ return jjMoveStringLiteralDfa5_0(active0, 0x800000L, active1, 0L);
+ case 118:
+ return jjMoveStringLiteralDfa5_0(active0, 0x20000000000L, active1, 0L);
+ case 119:
+ if ((active0 & 0x80000000000000L) != 0L)
+ {
+ jjmatchedKind = 55;
+ jjmatchedPos = 4;
+ }
+ return jjMoveStringLiteralDfa5_0(active0, 0x100000000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(3, active0, active1);
+}
+private final int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(3, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(4, active0, active1);
+ return 5;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa6_0(active0, 0x6000L, active1, 0L);
+ case 99:
+ if ((active0 & 0x800000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 47, 23);
+ else if ((active0 & 0x4000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 50, 23);
+ return jjMoveStringLiteralDfa6_0(active0, 0x400000000000L, active1, 0L);
+ case 100:
+ return jjMoveStringLiteralDfa6_0(active0, 0x8000000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x2000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 25, 23);
+ else if ((active0 & 0x20000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 41, 23);
+ break;
+ case 102:
+ return jjMoveStringLiteralDfa6_0(active0, 0x8000000000L, active1, 0L);
+ case 103:
+ return jjMoveStringLiteralDfa6_0(active0, 0x100000000000L, active1, 0L);
+ case 104:
+ if ((active0 & 0x10000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 52, 23);
+ break;
+ case 105:
+ return jjMoveStringLiteralDfa6_0(active0, 0x2200000000000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa6_0(active0, 0x8000000040800000L, active1, 0L);
+ case 109:
+ return jjMoveStringLiteralDfa6_0(active0, 0x800000000L, active1, 0L);
+ case 110:
+ if ((active0 & 0x1000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 48, 23);
+ return jjMoveStringLiteralDfa6_0(active0, 0x2000400000L, active1, 0x1L);
+ case 114:
+ return jjMoveStringLiteralDfa6_0(active0, 0x20000000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x100000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 56, 23);
+ break;
+ case 116:
+ if ((active0 & 0x1000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 36, 23);
+ return jjMoveStringLiteralDfa6_0(active0, 0x200000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(4, active0, active1);
+}
+private final int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(4, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(5, active0, active1);
+ return 6;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa7_0(active0, 0x8000008000000000L, active1, 0L);
+ case 99:
+ return jjMoveStringLiteralDfa7_0(active0, 0x2000002000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x100000000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 44, 23);
+ else if ((active0 & 0x200000000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 45, 23);
+ return jjMoveStringLiteralDfa7_0(active0, 0x200000800000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000000L, active1, 0L);
+ case 110:
+ if ((active0 & 0x4000L) != 0L)
+ return jjStartNfaWithStates_0(6, 14, 23);
+ break;
+ case 111:
+ return jjMoveStringLiteralDfa7_0(active0, 0x20000000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x8000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 27, 23);
+ break;
+ case 116:
+ if ((active0 & 0x800000L) != 0L)
+ return jjStartNfaWithStates_0(6, 23, 23);
+ return jjMoveStringLiteralDfa7_0(active0, 0x400000000000L, active1, 0x1L);
+ case 117:
+ return jjMoveStringLiteralDfa7_0(active0, 0x400000L, active1, 0L);
+ case 121:
+ if ((active0 & 0x40000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 30, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(5, active0, active1);
+}
+private final int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(5, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(6, active0, active1);
+ return 7;
+ }
+ switch(curChar)
+ {
+ case 99:
+ return jjMoveStringLiteralDfa8_0(active0, 0x8000000000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x400000L) != 0L)
+ return jjStartNfaWithStates_0(7, 22, 23);
+ else if ((active0 & 0x2000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(7, 61, 23);
+ return jjMoveStringLiteralDfa8_0(active0, 0x402000000000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa8_0(active0, 0L, active1, 0x1L);
+ case 110:
+ return jjMoveStringLiteralDfa8_0(active0, 0x220000800000000L, active1, 0L);
+ case 115:
+ return jjMoveStringLiteralDfa8_0(active0, 0x8000000000000000L, active1, 0L);
+ case 116:
+ if ((active0 & 0x2000L) != 0L)
+ return jjStartNfaWithStates_0(7, 13, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(6, active0, active1);
+}
+private final int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(6, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(7, active0, active1);
+ return 8;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0x1L);
+ case 100:
+ if ((active0 & 0x400000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 46, 23);
+ break;
+ case 101:
+ if ((active0 & 0x8000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 39, 23);
+ break;
+ case 105:
+ return jjMoveStringLiteralDfa9_0(active0, 0x20000000000000L, active1, 0L);
+ case 111:
+ return jjMoveStringLiteralDfa9_0(active0, 0x2000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x8000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 63, 23);
+ break;
+ case 116:
+ if ((active0 & 0x200000000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 57, 23);
+ return jjMoveStringLiteralDfa9_0(active0, 0x800000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(7, active0, active1);
+}
+private final int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(7, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(8, active0, active1);
+ return 9;
+ }
+ switch(curChar)
+ {
+ case 102:
+ if ((active0 & 0x2000000000L) != 0L)
+ return jjStartNfaWithStates_0(9, 37, 23);
+ break;
+ case 115:
+ if ((active0 & 0x800000000L) != 0L)
+ return jjStartNfaWithStates_0(9, 35, 23);
+ break;
+ case 116:
+ return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x1L);
+ case 122:
+ return jjMoveStringLiteralDfa10_0(active0, 0x20000000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(8, active0, active1);
+}
+private final int jjMoveStringLiteralDfa10_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(8, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(9, active0, active1);
+ return 10;
+ }
+ switch(curChar)
+ {
+ case 101:
+ return jjMoveStringLiteralDfa11_0(active0, 0x20000000000000L, active1, 0x1L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(9, active0, active1);
+}
+private final int jjMoveStringLiteralDfa11_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(9, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(10, active0, active1);
+ return 11;
+ }
+ switch(curChar)
+ {
+ case 100:
+ if ((active0 & 0x20000000000000L) != 0L)
+ return jjStartNfaWithStates_0(11, 53, 23);
+ break;
+ case 115:
+ if ((active1 & 0x1L) != 0L)
+ return jjStartNfaWithStates_0(11, 64, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(10, active0, active1);
+}
+private final void jjCheckNAdd(int state)
+{
+ if (jjrounds[state] != jjround)
+ {
+ jjstateSet[jjnewStateCnt++] = state;
+ jjrounds[state] = jjround;
+ }
+}
+private final void jjAddStates(int start, int end)
+{
+ do {
+ jjstateSet[jjnewStateCnt++] = jjnextStates[start];
+ } while (start++ != end);
+}
+private final void jjCheckNAddTwoStates(int state1, int state2)
+{
+ jjCheckNAdd(state1);
+ jjCheckNAdd(state2);
+}
+private final void jjCheckNAddStates(int start, int end)
+{
+ do {
+ jjCheckNAdd(jjnextStates[start]);
+ } while (start++ != end);
+}
+private final void jjCheckNAddStates(int start)
+{
+ jjCheckNAdd(jjnextStates[start]);
+ jjCheckNAdd(jjnextStates[start + 1]);
+}
+static final long[] jjbitVec0 = {
+ 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec2 = {
+ 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec3 = {
+ 0x1ff00000fffffffeL, 0xffffffffffffc000L, 0xffffffffL, 0x600000000000000L
+};
+static final long[] jjbitVec4 = {
+ 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL
+};
+static final long[] jjbitVec5 = {
+ 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec6 = {
+ 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffL, 0x0L
+};
+static final long[] jjbitVec7 = {
+ 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L, 0x0L
+};
+static final long[] jjbitVec8 = {
+ 0x3fffffffffffL, 0x0L, 0x0L, 0x0L
+};
+private final int jjMoveNfa_0(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 75;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 75:
+ if ((0x3ff000000000000L & l) != 0L)
+ {
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddStates(0, 2);
+ }
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(3, 5);
+ break;
+ case 3:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(6, 19);
+ else if (curChar == 46)
+ jjCheckNAddTwoStates(29, 34);
+ else if (curChar == 36)
+ {
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ }
+ else if (curChar == 34)
+ jjCheckNAddStates(20, 22);
+ else if (curChar == 39)
+ jjAddStates(23, 24);
+ else if (curChar == 47)
+ jjstateSet[jjnewStateCnt++] = 2;
+ if ((0x3fe000000000000L & l) != 0L)
+ {
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(25, 27);
+ }
+ else if (curChar == 48)
+ {
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(28, 32);
+ }
+ break;
+ case 0:
+ if (curChar == 42)
+ jjstateSet[jjnewStateCnt++] = 1;
+ break;
+ case 1:
+ if ((0xffff7fffffffffffL & l) != 0L && kind > 6)
+ kind = 6;
+ break;
+ case 2:
+ if (curChar == 42)
+ jjstateSet[jjnewStateCnt++] = 0;
+ break;
+ case 4:
+ if (curChar == 39)
+ jjAddStates(23, 24);
+ break;
+ case 5:
+ if ((0xffffff7fffffdbffL & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 6:
+ if (curChar == 39 && kind > 73)
+ kind = 73;
+ break;
+ case 8:
+ if ((0x8400000000L & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 9:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(10, 6);
+ break;
+ case 10:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 11:
+ if ((0xf000000000000L & l) != 0L)
+ jjstateSet[jjnewStateCnt++] = 12;
+ break;
+ case 12:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAdd(10);
+ break;
+ case 13:
+ if (curChar == 34)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 14:
+ if ((0xfffffffbffffdbffL & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 16:
+ if ((0x8400000000L & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 17:
+ if (curChar == 34 && kind > 74)
+ kind = 74;
+ break;
+ case 18:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddStates(33, 36);
+ break;
+ case 19:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 20:
+ if ((0xf000000000000L & l) != 0L)
+ jjstateSet[jjnewStateCnt++] = 21;
+ break;
+ case 21:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAdd(19);
+ break;
+ case 22:
+ if (curChar != 36)
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 23:
+ if ((0x3ff001000000000L & l) == 0L)
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 24:
+ if ((0x3fe000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(25, 27);
+ break;
+ case 25:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAdd(25);
+ break;
+ case 26:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(26, 27);
+ break;
+ case 28:
+ if (curChar == 46)
+ jjCheckNAddTwoStates(29, 34);
+ break;
+ case 29:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(3, 5);
+ break;
+ case 31:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(32);
+ break;
+ case 32:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(32, 33);
+ break;
+ case 34:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddStates(0, 2);
+ break;
+ case 36:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(37);
+ break;
+ case 37:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddTwoStates(37, 38);
+ break;
+ case 39:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(6, 19);
+ break;
+ case 40:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(40, 41);
+ break;
+ case 41:
+ if (curChar != 46)
+ break;
+ if (kind > 70)
+ kind = 70;
+ jjCheckNAddStates(37, 39);
+ break;
+ case 42:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 70)
+ kind = 70;
+ jjCheckNAddStates(37, 39);
+ break;
+ case 44:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(45);
+ break;
+ case 45:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 70)
+ kind = 70;
+ jjCheckNAddTwoStates(45, 33);
+ break;
+ case 46:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(46, 47);
+ break;
+ case 48:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(49);
+ break;
+ case 49:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(49, 33);
+ break;
+ case 50:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(40, 42);
+ break;
+ case 52:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(53);
+ break;
+ case 53:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(53, 33);
+ break;
+ case 54:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(54, 55);
+ break;
+ case 55:
+ if (curChar == 46)
+ jjCheckNAddStates(43, 45);
+ break;
+ case 56:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(43, 45);
+ break;
+ case 58:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(59);
+ break;
+ case 59:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(59, 38);
+ break;
+ case 60:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(60, 61);
+ break;
+ case 62:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(63);
+ break;
+ case 63:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddTwoStates(63, 38);
+ break;
+ case 64:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(46, 48);
+ break;
+ case 66:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(67);
+ break;
+ case 67:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(67, 38);
+ break;
+ case 68:
+ if (curChar != 48)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(28, 32);
+ break;
+ case 70:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjstateSet[jjnewStateCnt++] = 70;
+ break;
+ case 71:
+ if ((0xff000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAdd(71);
+ break;
+ case 73:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(73, 27);
+ break;
+ case 74:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(74, 27);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 3:
+ case 23:
+ if ((0x7fffffe87fffffeL & l) == 0L)
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 1:
+ if (kind > 6)
+ kind = 6;
+ break;
+ case 5:
+ if ((0xffffffffefffffffL & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 7:
+ if (curChar == 92)
+ jjAddStates(49, 51);
+ break;
+ case 8:
+ if ((0x14404410000000L & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 14:
+ if ((0xffffffffefffffffL & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 15:
+ if (curChar == 92)
+ jjAddStates(52, 54);
+ break;
+ case 16:
+ if ((0x14404410000000L & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 27:
+ if ((0x100000001000L & l) != 0L && kind > 66)
+ kind = 66;
+ break;
+ case 30:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(55, 56);
+ break;
+ case 33:
+ if ((0x1000000010L & l) != 0L && kind > 70)
+ kind = 70;
+ break;
+ case 35:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(57, 58);
+ break;
+ case 38:
+ if ((0x4000000040L & l) != 0L && kind > 71)
+ kind = 71;
+ break;
+ case 43:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(59, 60);
+ break;
+ case 47:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(61, 62);
+ break;
+ case 51:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(63, 64);
+ break;
+ case 57:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(65, 66);
+ break;
+ case 61:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(67, 68);
+ break;
+ case 65:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(69, 70);
+ break;
+ case 69:
+ if ((0x100000001000000L & l) != 0L)
+ jjCheckNAdd(70);
+ break;
+ case 70:
+ if ((0x7e0000007eL & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAdd(70);
+ break;
+ case 72:
+ if ((0x100000001000000L & l) != 0L)
+ jjCheckNAdd(73);
+ break;
+ case 73:
+ if ((0x7e0000007eL & l) != 0L)
+ jjCheckNAddTwoStates(73, 27);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int hiByte = (int)(curChar >> 8);
+ int i1 = hiByte >> 6;
+ long l1 = 1L << (hiByte & 077);
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 3:
+ case 23:
+ if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 1:
+ if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 6)
+ kind = 6;
+ break;
+ case 5:
+ if (jjCanMove_0(hiByte, i1, i2, l1, l2))
+ jjstateSet[jjnewStateCnt++] = 6;
+ break;
+ case 14:
+ if (jjCanMove_0(hiByte, i1, i2, l1, l2))
+ jjAddStates(20, 22);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 75 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+private final int jjMoveStringLiteralDfa0_3()
+{
+ switch(curChar)
+ {
+ case 42:
+ return jjMoveStringLiteralDfa1_3(0x800L);
+ default :
+ return 1;
+ }
+}
+private final int jjMoveStringLiteralDfa1_3(long active0)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 47:
+ if ((active0 & 0x800L) != 0L)
+ return jjStopAtPos(1, 11);
+ break;
+ default :
+ return 2;
+ }
+ return 2;
+}
+private final int jjMoveStringLiteralDfa0_1()
+{
+ return jjMoveNfa_1(0, 0);
+}
+private final int jjMoveNfa_1(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 3;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ if ((0x2400L & l) != 0L)
+ {
+ if (kind > 9)
+ kind = 9;
+ }
+ if (curChar == 13)
+ jjstateSet[jjnewStateCnt++] = 1;
+ break;
+ case 1:
+ if (curChar == 10 && kind > 9)
+ kind = 9;
+ break;
+ case 2:
+ if (curChar == 13)
+ jjstateSet[jjnewStateCnt++] = 1;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int hiByte = (int)(curChar >> 8);
+ int i1 = hiByte >> 6;
+ long l1 = 1L << (hiByte & 077);
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+private final int jjMoveStringLiteralDfa0_2()
+{
+ switch(curChar)
+ {
+ case 42:
+ return jjMoveStringLiteralDfa1_2(0x400L);
+ default :
+ return 1;
+ }
+}
+private final int jjMoveStringLiteralDfa1_2(long active0)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 47:
+ if ((active0 & 0x400L) != 0L)
+ return jjStopAtPos(1, 10);
+ break;
+ default :
+ return 2;
+ }
+ return 2;
+}
+static final int[] jjnextStates = {
+ 34, 35, 38, 29, 30, 33, 40, 41, 46, 47, 50, 51, 33, 54, 55, 60,
+ 61, 64, 65, 38, 14, 15, 17, 5, 7, 25, 26, 27, 69, 71, 72, 74,
+ 27, 14, 15, 19, 17, 42, 43, 33, 50, 51, 33, 56, 57, 38, 64, 65,
+ 38, 8, 9, 11, 16, 18, 20, 31, 32, 36, 37, 44, 45, 48, 49, 52,
+ 53, 58, 59, 62, 63, 66, 67,
+};
+private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
+{
+ switch(hiByte)
+ {
+ case 0:
+ return ((jjbitVec2[i2] & l2) != 0L);
+ default :
+ if ((jjbitVec0[i1] & l1) != 0L)
+ return true;
+ return false;
+ }
+}
+private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2)
+{
+ switch(hiByte)
+ {
+ case 0:
+ return ((jjbitVec4[i2] & l2) != 0L);
+ case 48:
+ return ((jjbitVec5[i2] & l2) != 0L);
+ case 49:
+ return ((jjbitVec6[i2] & l2) != 0L);
+ case 51:
+ return ((jjbitVec7[i2] & l2) != 0L);
+ case 61:
+ return ((jjbitVec8[i2] & l2) != 0L);
+ default :
+ if ((jjbitVec3[i1] & l1) != 0L)
+ return true;
+ return false;
+ }
+}
+public static final String[] jjstrLiteralImages = {
+"", null, null, null, null, null, null, null, null, null, null, null, null,
+"\141\142\163\164\162\141\143\164", "\142\157\157\154\145\141\156", "\142\162\145\141\153", "\142\171\164\145",
+"\143\141\163\145", "\143\141\164\143\150", "\143\150\141\162", "\143\154\141\163\163",
+"\143\157\156\163\164", "\143\157\156\164\151\156\165\145", "\144\145\146\141\165\154\164",
+"\144\157", "\144\157\165\142\154\145", "\145\154\163\145",
+"\145\170\164\145\156\144\163", "\146\141\154\163\145", "\146\151\156\141\154",
+"\146\151\156\141\154\154\171", "\146\154\157\141\164", "\146\157\162", "\147\157\164\157", "\151\146",
+"\151\155\160\154\145\155\145\156\164\163", "\151\155\160\157\162\164", "\151\156\163\164\141\156\143\145\157\146",
+"\151\156\164", "\151\156\164\145\162\146\141\143\145", "\154\157\156\147",
+"\156\141\164\151\166\145", "\156\145\167", "\156\165\154\154", "\160\141\143\153\141\147\145",
+"\160\162\151\166\141\164\145", "\160\162\157\164\145\143\164\145\144", "\160\165\142\154\151\143",
+"\162\145\164\165\162\156", "\163\150\157\162\164", "\163\164\141\164\151\143", "\163\165\160\145\162",
+"\163\167\151\164\143\150", "\163\171\156\143\150\162\157\156\151\172\145\144", "\164\150\151\163",
+"\164\150\162\157\167", "\164\150\162\157\167\163", "\164\162\141\156\163\151\145\156\164",
+"\164\162\165\145", "\164\162\171", "\166\157\151\144", "\166\157\154\141\164\151\154\145",
+"\167\150\151\154\145", "\155\145\164\141\143\154\141\163\163",
+"\151\156\163\164\141\156\164\151\141\164\145\163", null, null, null, null, null, null, null, null, null, null, null, null, null,
+"\50", "\51", "\173", "\175", "\133", "\135", "\73", "\54", "\56", "\75", "\76",
+"\74", "\41", "\176", "\77", "\72", "\75\75", "\74\75", "\76\75", "\41\75",
+"\174\174", "\46\46", "\53\53", "\55\55", "\53", "\55", "\52", "\57", "\46", "\174",
+"\136", "\45", "\74\74", "\76\76", "\76\76\76", "\53\75", "\55\75", "\52\75",
+"\57\75", "\46\75", "\174\75", "\136\75", "\45\75", "\74\74\75", "\76\76\75",
+"\76\76\76\75", };
+public static final String[] lexStateNames = {
+ "DEFAULT",
+ "IN_SINGLE_LINE_COMMENT",
+ "IN_FORMAL_COMMENT",
+ "IN_MULTI_LINE_COMMENT",
+};
+public static final int[] jjnewLexState = {
+ -1, -1, -1, -1, -1, -1, 2, 1, 3, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+};
+static final long[] jjtoToken = {
+ 0xffffffffffffe001L, 0xfffffffffffcec7L,
+};
+static final long[] jjtoSkip = {
+ 0xe3eL, 0x0L,
+};
+static final long[] jjtoSpecial = {
+ 0xe00L, 0x0L,
+};
+static final long[] jjtoMore = {
+ 0x11c0L, 0x0L,
+};
+private JavaCharStream input_stream;
+private final int[] jjrounds = new int[75];
+private final int[] jjstateSet = new int[150];
+StringBuffer image;
+int jjimageLen;
+int lengthOfMatch;
+protected char curChar;
+public ParserTokenManager(JavaCharStream stream)
+{
+ if (JavaCharStream.staticFlag)
+ throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
+ input_stream = stream;
+}
+public ParserTokenManager(JavaCharStream stream, int lexState)
+{
+ this(stream);
+ SwitchTo(lexState);
+}
+public void ReInit(JavaCharStream stream)
+{
+ jjmatchedPos = jjnewStateCnt = 0;
+ curLexState = defaultLexState;
+ input_stream = stream;
+ ReInitRounds();
+}
+private final void ReInitRounds()
+{
+ int i;
+ jjround = 0x80000001;
+ for (i = 75; i-- > 0;)
+ jjrounds[i] = 0x80000000;
+}
+public void ReInit(JavaCharStream stream, int lexState)
+{
+ ReInit(stream);
+ SwitchTo(lexState);
+}
+public void SwitchTo(int lexState)
+{
+ if (lexState >= 4 || lexState < 0)
+ throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
+ else
+ curLexState = lexState;
+}
+
+private final Token jjFillToken()
+{
+ Token t = Token.newToken(jjmatchedKind);
+ t.kind = jjmatchedKind;
+ String im = jjstrLiteralImages[jjmatchedKind];
+ t.image = (im == null) ? input_stream.GetImage() : im;
+ t.beginLine = input_stream.getBeginLine();
+ t.beginColumn = input_stream.getBeginColumn();
+ t.endLine = input_stream.getEndLine();
+ t.endColumn = input_stream.getEndColumn();
+ return t;
+}
+
+int curLexState = 0;
+int defaultLexState = 0;
+int jjnewStateCnt;
+int jjround;
+int jjmatchedPos;
+int jjmatchedKind;
+
+public Token getNextToken()
+{
+ int kind;
+ Token specialToken = null;
+ Token matchedToken;
+ int curPos = 0;
+
+ EOFLoop :
+ for (;;)
+ {
+ try
+ {
+ curChar = input_stream.BeginToken();
+ }
+ catch(java.io.IOException e)
+ {
+ jjmatchedKind = 0;
+ matchedToken = jjFillToken();
+ matchedToken.specialToken = specialToken;
+ return matchedToken;
+ }
+ image = null;
+ jjimageLen = 0;
+
+ for (;;)
+ {
+ switch(curLexState)
+ {
+ case 0:
+ try { input_stream.backup(0);
+ while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L)
+ curChar = input_stream.BeginToken();
+ }
+ catch (java.io.IOException e1) { continue EOFLoop; }
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_0();
+ break;
+ case 1:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_1();
+ if (jjmatchedPos == 0 && jjmatchedKind > 12)
+ {
+ jjmatchedKind = 12;
+ }
+ break;
+ case 2:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_2();
+ if (jjmatchedPos == 0 && jjmatchedKind > 12)
+ {
+ jjmatchedKind = 12;
+ }
+ break;
+ case 3:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_3();
+ if (jjmatchedPos == 0 && jjmatchedKind > 12)
+ {
+ jjmatchedKind = 12;
+ }
+ break;
+ }
+ if (jjmatchedKind != 0x7fffffff)
+ {
+ if (jjmatchedPos + 1 < curPos)
+ input_stream.backup(curPos - jjmatchedPos - 1);
+ if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ matchedToken.specialToken = specialToken;
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ return matchedToken;
+ }
+ else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ if (specialToken == null)
+ specialToken = matchedToken;
+ else
+ {
+ matchedToken.specialToken = specialToken;
+ specialToken = (specialToken.next = matchedToken);
+ }
+ SkipLexicalActions(matchedToken);
+ }
+ else
+ SkipLexicalActions(null);
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ continue EOFLoop;
+ }
+ jjimageLen += jjmatchedPos + 1;
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ curPos = 0;
+ jjmatchedKind = 0x7fffffff;
+ try {
+ curChar = input_stream.readChar();
+ continue;
+ }
+ catch (java.io.IOException e1) { }
+ }
+ int error_line = input_stream.getEndLine();
+ int error_column = input_stream.getEndColumn();
+ String error_after = null;
+ boolean EOFSeen = false;
+ try { input_stream.readChar(); input_stream.backup(1); }
+ catch (java.io.IOException e1) {
+ EOFSeen = true;
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ if (curChar == '\n' || curChar == '\r') {
+ error_line++;
+ error_column = 0;
+ }
+ else
+ error_column++;
+ }
+ if (!EOFSeen) {
+ input_stream.backup(1);
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ }
+ throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
+ }
+ }
+}
+
+final void SkipLexicalActions(Token matchedToken)
+{
+ switch(jjmatchedKind)
+ {
+ default :
+ break;
+ }
+}
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java.org b/src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java.org
new file mode 100644
index 0000000..9877b11
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/ParserTokenManager.java.org
@@ -0,0 +1,1827 @@
+/* Generated By:JavaCC: Do not edit this line. ParserTokenManager.java */
+package io.devnulllabs.openjava.tools.parser;
+import java.io.Reader;
+import java.util.Vector;
+import java.util.Hashtable;
+import java.lang.reflect.Method;
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.tools.DebugOut;
+import io.devnulllabs.openjava.syntax.SyntaxRule;
+import io.devnulllabs.openjava.syntax.TokenSource;
+
+public class ParserTokenManager implements ParserConstants
+{
+private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1)
+{
+ switch (pos)
+ {
+ case 0:
+ if ((active0 & 0x180L) != 0L || (active1 & 0x10020000000000L) != 0L)
+ return 2;
+ if ((active1 & 0x400000L) != 0L)
+ return 75;
+ if ((active0 & 0xffffffffffffe000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ return 23;
+ }
+ return -1;
+ case 1:
+ if ((active0 & 0x100L) != 0L)
+ return 0;
+ if ((active0 & 0x403000000L) != 0L)
+ return 23;
+ if ((active0 & 0xfffffffbfcffe000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ if (jjmatchedPos != 1)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 1;
+ }
+ return 23;
+ }
+ return -1;
+ case 2:
+ if ((active0 & 0x80004c100000000L) != 0L)
+ return 23;
+ if ((active0 & 0xf7fffb3afeffe000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ if (jjmatchedPos != 2)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 2;
+ }
+ return 23;
+ }
+ return -1;
+ case 3:
+ if ((active0 & 0xe3bff2b8faf4e000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 3;
+ return 23;
+ }
+ if ((active0 & 0x14400902040b0000L) != 0L)
+ return 23;
+ return -1;
+ case 4:
+ if ((active0 & 0x418a0000f0348000L) != 0L)
+ return 23;
+ if ((active0 & 0xa235f2b80ac06000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ if (jjmatchedPos != 4)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 4;
+ }
+ return 23;
+ }
+ return -1;
+ case 5:
+ if ((active0 & 0x115821002000000L) != 0L)
+ return 23;
+ if ((active0 & 0xa22070a848c06000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 5;
+ return 23;
+ }
+ return -1;
+ case 6:
+ if ((active0 & 0xa22040a800402000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 6;
+ return 23;
+ }
+ if ((active0 & 0x300048804000L) != 0L)
+ return 23;
+ return -1;
+ case 7:
+ if ((active0 & 0x822040a800000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 7;
+ return 23;
+ }
+ if ((active0 & 0x2000000000402000L) != 0L)
+ return 23;
+ return -1;
+ case 8:
+ if ((active0 & 0x8200408000000000L) != 0L)
+ return 23;
+ if ((active0 & 0x20002800000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 8;
+ return 23;
+ }
+ return -1;
+ case 9:
+ if ((active0 & 0x20000000000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 9;
+ return 23;
+ }
+ if ((active0 & 0x2800000000L) != 0L)
+ return 23;
+ return -1;
+ case 10:
+ if ((active0 & 0x20000000000000L) != 0L || (active1 & 0x1L) != 0L)
+ {
+ jjmatchedKind = 75;
+ jjmatchedPos = 10;
+ return 23;
+ }
+ return -1;
+ default :
+ return -1;
+ }
+}
+private final int jjStartNfa_0(int pos, long active0, long active1)
+{
+ return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1);
+}
+private final int jjStopAtPos(int pos, int kind)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ return pos + 1;
+}
+private final int jjStartNfaWithStates_0(int pos, int kind, int state)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return pos + 1; }
+ return jjMoveNfa_0(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_0()
+{
+ switch(curChar)
+ {
+ case 33:
+ jjmatchedKind = 90;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000L);
+ case 37:
+ jjmatchedKind = 109;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x100000000000000L);
+ case 38:
+ jjmatchedKind = 106;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x20000800000000L);
+ case 40:
+ return jjStopAtPos(0, 78);
+ case 41:
+ return jjStopAtPos(0, 79);
+ case 42:
+ jjmatchedKind = 104;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x8000000000000L);
+ case 43:
+ jjmatchedKind = 102;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x2001000000000L);
+ case 44:
+ return jjStopAtPos(0, 85);
+ case 45:
+ jjmatchedKind = 103;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x4002000000000L);
+ case 46:
+ return jjStartNfaWithStates_0(0, 86, 75);
+ case 47:
+ jjmatchedKind = 105;
+ return jjMoveStringLiteralDfa1_0(0x180L, 0x10000000000000L);
+ case 58:
+ return jjStopAtPos(0, 93);
+ case 59:
+ return jjStopAtPos(0, 84);
+ case 60:
+ jjmatchedKind = 89;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x200400080000000L);
+ case 61:
+ jjmatchedKind = 87;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x40000000L);
+ case 62:
+ jjmatchedKind = 88;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0xc01800100000000L);
+ case 63:
+ return jjStopAtPos(0, 92);
+ case 91:
+ return jjStopAtPos(0, 82);
+ case 93:
+ return jjStopAtPos(0, 83);
+ case 94:
+ jjmatchedKind = 108;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x80000000000000L);
+ case 97:
+ return jjMoveStringLiteralDfa1_0(0x2000L, 0x0L);
+ case 98:
+ return jjMoveStringLiteralDfa1_0(0x1c000L, 0x0L);
+ case 99:
+ return jjMoveStringLiteralDfa1_0(0x7e0000L, 0x0L);
+ case 100:
+ return jjMoveStringLiteralDfa1_0(0x3800000L, 0x0L);
+ case 101:
+ return jjMoveStringLiteralDfa1_0(0xc000000L, 0x0L);
+ case 102:
+ return jjMoveStringLiteralDfa1_0(0x1f0000000L, 0x0L);
+ case 103:
+ return jjMoveStringLiteralDfa1_0(0x200000000L, 0x0L);
+ case 105:
+ return jjMoveStringLiteralDfa1_0(0xfc00000000L, 0x1L);
+ case 108:
+ return jjMoveStringLiteralDfa1_0(0x10000000000L, 0x0L);
+ case 109:
+ return jjMoveStringLiteralDfa1_0(0x8000000000000000L, 0x0L);
+ case 110:
+ return jjMoveStringLiteralDfa1_0(0xe0000000000L, 0x0L);
+ case 112:
+ return jjMoveStringLiteralDfa1_0(0xf00000000000L, 0x0L);
+ case 114:
+ return jjMoveStringLiteralDfa1_0(0x1000000000000L, 0x0L);
+ case 115:
+ return jjMoveStringLiteralDfa1_0(0x3e000000000000L, 0x0L);
+ case 116:
+ return jjMoveStringLiteralDfa1_0(0xfc0000000000000L, 0x0L);
+ case 118:
+ return jjMoveStringLiteralDfa1_0(0x3000000000000000L, 0x0L);
+ case 119:
+ return jjMoveStringLiteralDfa1_0(0x4000000000000000L, 0x0L);
+ case 123:
+ return jjStopAtPos(0, 80);
+ case 124:
+ jjmatchedKind = 107;
+ return jjMoveStringLiteralDfa1_0(0x0L, 0x40000400000000L);
+ case 125:
+ return jjStopAtPos(0, 81);
+ case 126:
+ return jjStopAtPos(0, 91);
+ default :
+ return jjMoveNfa_0(3, 0);
+ }
+}
+private final int jjMoveStringLiteralDfa1_0(long active0, long active1)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(0, active0, active1);
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 38:
+ if ((active1 & 0x800000000L) != 0L)
+ return jjStopAtPos(1, 99);
+ break;
+ case 42:
+ if ((active0 & 0x100L) != 0L)
+ return jjStartNfaWithStates_0(1, 8, 0);
+ break;
+ case 43:
+ if ((active1 & 0x1000000000L) != 0L)
+ return jjStopAtPos(1, 100);
+ break;
+ case 45:
+ if ((active1 & 0x2000000000L) != 0L)
+ return jjStopAtPos(1, 101);
+ break;
+ case 47:
+ if ((active0 & 0x80L) != 0L)
+ return jjStopAtPos(1, 7);
+ break;
+ case 60:
+ if ((active1 & 0x400000000000L) != 0L)
+ {
+ jjmatchedKind = 110;
+ jjmatchedPos = 1;
+ }
+ return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x200000000000000L);
+ case 61:
+ if ((active1 & 0x40000000L) != 0L)
+ return jjStopAtPos(1, 94);
+ else if ((active1 & 0x80000000L) != 0L)
+ return jjStopAtPos(1, 95);
+ else if ((active1 & 0x100000000L) != 0L)
+ return jjStopAtPos(1, 96);
+ else if ((active1 & 0x200000000L) != 0L)
+ return jjStopAtPos(1, 97);
+ else if ((active1 & 0x2000000000000L) != 0L)
+ return jjStopAtPos(1, 113);
+ else if ((active1 & 0x4000000000000L) != 0L)
+ return jjStopAtPos(1, 114);
+ else if ((active1 & 0x8000000000000L) != 0L)
+ return jjStopAtPos(1, 115);
+ else if ((active1 & 0x10000000000000L) != 0L)
+ return jjStopAtPos(1, 116);
+ else if ((active1 & 0x20000000000000L) != 0L)
+ return jjStopAtPos(1, 117);
+ else if ((active1 & 0x40000000000000L) != 0L)
+ return jjStopAtPos(1, 118);
+ else if ((active1 & 0x80000000000000L) != 0L)
+ return jjStopAtPos(1, 119);
+ else if ((active1 & 0x100000000000000L) != 0L)
+ return jjStopAtPos(1, 120);
+ break;
+ case 62:
+ if ((active1 & 0x800000000000L) != 0L)
+ {
+ jjmatchedKind = 111;
+ jjmatchedPos = 1;
+ }
+ return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0xc01000000000000L);
+ case 97:
+ return jjMoveStringLiteralDfa2_0(active0, 0x120010060000L, active1, 0L);
+ case 98:
+ return jjMoveStringLiteralDfa2_0(active0, 0x2000L, active1, 0L);
+ case 101:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8001040000800000L, active1, 0L);
+ case 102:
+ if ((active0 & 0x400000000L) != 0L)
+ return jjStartNfaWithStates_0(1, 34, 23);
+ break;
+ case 104:
+ return jjMoveStringLiteralDfa2_0(active0, 0x41c2000000080000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa2_0(active0, 0x60000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa2_0(active0, 0x84100000L, active1, 0L);
+ case 109:
+ return jjMoveStringLiteralDfa2_0(active0, 0x1800000000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa2_0(active0, 0xe000000000L, active1, 0x1L);
+ case 111:
+ if ((active0 & 0x1000000L) != 0L)
+ {
+ jjmatchedKind = 24;
+ jjmatchedPos = 1;
+ }
+ return jjMoveStringLiteralDfa2_0(active0, 0x3000010302604000L, active1, 0L);
+ case 114:
+ return jjMoveStringLiteralDfa2_0(active0, 0xe00600000008000L, active1, 0L);
+ case 116:
+ return jjMoveStringLiteralDfa2_0(active0, 0x4000000000000L, active1, 0L);
+ case 117:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8880000000000L, active1, 0L);
+ case 119:
+ return jjMoveStringLiteralDfa2_0(active0, 0x10000000000000L, active1, 0L);
+ case 120:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8000000L, active1, 0L);
+ case 121:
+ return jjMoveStringLiteralDfa2_0(active0, 0x20000000010000L, active1, 0L);
+ case 124:
+ if ((active1 & 0x400000000L) != 0L)
+ return jjStopAtPos(1, 98);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(0, active0, active1);
+}
+private final int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(0, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(1, active0, active1);
+ return 2;
+ }
+ switch(curChar)
+ {
+ case 61:
+ if ((active1 & 0x200000000000000L) != 0L)
+ return jjStopAtPos(2, 121);
+ else if ((active1 & 0x400000000000000L) != 0L)
+ return jjStopAtPos(2, 122);
+ break;
+ case 62:
+ if ((active1 & 0x1000000000000L) != 0L)
+ {
+ jjmatchedKind = 112;
+ jjmatchedPos = 2;
+ }
+ return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x800000000000000L);
+ case 97:
+ return jjMoveStringLiteralDfa3_0(active0, 0x204000000180000L, active1, 0L);
+ case 98:
+ return jjMoveStringLiteralDfa3_0(active0, 0x800000000000L, active1, 0L);
+ case 99:
+ return jjMoveStringLiteralDfa3_0(active0, 0x100000000000L, active1, 0L);
+ case 101:
+ return jjMoveStringLiteralDfa3_0(active0, 0x8000L, active1, 0L);
+ case 102:
+ return jjMoveStringLiteralDfa3_0(active0, 0x800000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa3_0(active0, 0x5050200000000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2000080010000000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa3_0(active0, 0x20010060600000L, active1, 0L);
+ case 111:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2400080004000L, active1, 0L);
+ case 112:
+ return jjMoveStringLiteralDfa3_0(active0, 0x8001800000000L, active1, 0L);
+ case 114:
+ if ((active0 & 0x100000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 32, 23);
+ return jjMoveStringLiteralDfa3_0(active0, 0x180000000000000L, active1, 0L);
+ case 115:
+ return jjMoveStringLiteralDfa3_0(active0, 0x2004022000L, active1, 0x1L);
+ case 116:
+ if ((active0 & 0x4000000000L) != 0L)
+ {
+ jjmatchedKind = 38;
+ jjmatchedPos = 2;
+ }
+ return jjMoveStringLiteralDfa3_0(active0, 0x8001028208050000L, active1, 0L);
+ case 117:
+ return jjMoveStringLiteralDfa3_0(active0, 0x400000002000000L, active1, 0L);
+ case 119:
+ if ((active0 & 0x40000000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 42, 23);
+ break;
+ case 121:
+ if ((active0 & 0x800000000000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 59, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(1, active0, active1);
+}
+private final int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(1, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(2, active0, active1);
+ return 3;
+ }
+ switch(curChar)
+ {
+ case 61:
+ if ((active1 & 0x800000000000000L) != 0L)
+ return jjStopAtPos(3, 123);
+ break;
+ case 97:
+ return jjMoveStringLiteralDfa4_0(active0, 0xa0000000e0808000L, active1, 0L);
+ case 98:
+ return jjMoveStringLiteralDfa4_0(active0, 0x2000000L, active1, 0L);
+ case 99:
+ return jjMoveStringLiteralDfa4_0(active0, 0x20000000040000L, active1, 0L);
+ case 100:
+ if ((active0 & 0x1000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 60, 23);
+ break;
+ case 101:
+ if ((active0 & 0x10000L) != 0L)
+ return jjStartNfaWithStates_0(3, 16, 23);
+ else if ((active0 & 0x20000L) != 0L)
+ return jjStartNfaWithStates_0(3, 17, 23);
+ else if ((active0 & 0x4000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 26, 23);
+ else if ((active0 & 0x400000000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 58, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x8008008000000L, active1, 0L);
+ case 103:
+ if ((active0 & 0x10000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 40, 23);
+ break;
+ case 105:
+ return jjMoveStringLiteralDfa4_0(active0, 0x20000000000L, active1, 0L);
+ case 107:
+ return jjMoveStringLiteralDfa4_0(active0, 0x100000000000L, active1, 0L);
+ case 108:
+ if ((active0 & 0x80000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 43, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x4000800800004000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa4_0(active0, 0x200000000000000L, active1, 0L);
+ case 111:
+ if ((active0 & 0x200000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 33, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x180001000000000L, active1, 0L);
+ case 114:
+ if ((active0 & 0x80000L) != 0L)
+ return jjStartNfaWithStates_0(3, 19, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x40000000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 54, 23);
+ return jjMoveStringLiteralDfa4_0(active0, 0x10300000L, active1, 0L);
+ case 116:
+ return jjMoveStringLiteralDfa4_0(active0, 0x14402000402000L, active1, 0x1L);
+ case 117:
+ return jjMoveStringLiteralDfa4_0(active0, 0x1000000000000L, active1, 0L);
+ case 118:
+ return jjMoveStringLiteralDfa4_0(active0, 0x200000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(2, active0, active1);
+}
+private final int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(2, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(3, active0, active1);
+ return 4;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa5_0(active0, 0x302000000000L, active1, 0x1L);
+ case 99:
+ return jjMoveStringLiteralDfa5_0(active0, 0x8010000000000000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x10000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 28, 23);
+ else if ((active0 & 0x4000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 62, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x400800004000L, active1, 0L);
+ case 104:
+ if ((active0 & 0x40000L) != 0L)
+ return jjStartNfaWithStates_0(4, 18, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x20000000000000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa5_0(active0, 0x4800000400000L, active1, 0L);
+ case 107:
+ if ((active0 & 0x8000L) != 0L)
+ return jjStartNfaWithStates_0(4, 15, 23);
+ break;
+ case 108:
+ if ((active0 & 0x20000000L) != 0L)
+ {
+ jjmatchedKind = 29;
+ jjmatchedPos = 4;
+ }
+ return jjMoveStringLiteralDfa5_0(active0, 0x42000000L, active1, 0L);
+ case 110:
+ return jjMoveStringLiteralDfa5_0(active0, 0x8000000L, active1, 0L);
+ case 114:
+ if ((active0 & 0x8000000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 51, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x1009000002000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x100000L) != 0L)
+ return jjStartNfaWithStates_0(4, 20, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x200000000000000L, active1, 0L);
+ case 116:
+ if ((active0 & 0x200000L) != 0L)
+ return jjStartNfaWithStates_0(4, 21, 23);
+ else if ((active0 & 0x80000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 31, 23);
+ else if ((active0 & 0x2000000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 49, 23);
+ return jjMoveStringLiteralDfa5_0(active0, 0x2000000000000000L, active1, 0L);
+ case 117:
+ return jjMoveStringLiteralDfa5_0(active0, 0x800000L, active1, 0L);
+ case 118:
+ return jjMoveStringLiteralDfa5_0(active0, 0x20000000000L, active1, 0L);
+ case 119:
+ if ((active0 & 0x80000000000000L) != 0L)
+ {
+ jjmatchedKind = 55;
+ jjmatchedPos = 4;
+ }
+ return jjMoveStringLiteralDfa5_0(active0, 0x100000000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(3, active0, active1);
+}
+private final int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(3, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(4, active0, active1);
+ return 5;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa6_0(active0, 0x6000L, active1, 0L);
+ case 99:
+ if ((active0 & 0x800000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 47, 23);
+ else if ((active0 & 0x4000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 50, 23);
+ return jjMoveStringLiteralDfa6_0(active0, 0x400000000000L, active1, 0L);
+ case 100:
+ return jjMoveStringLiteralDfa6_0(active0, 0x8000000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x2000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 25, 23);
+ else if ((active0 & 0x20000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 41, 23);
+ break;
+ case 102:
+ return jjMoveStringLiteralDfa6_0(active0, 0x8000000000L, active1, 0L);
+ case 103:
+ return jjMoveStringLiteralDfa6_0(active0, 0x100000000000L, active1, 0L);
+ case 104:
+ if ((active0 & 0x10000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 52, 23);
+ break;
+ case 105:
+ return jjMoveStringLiteralDfa6_0(active0, 0x2200000000000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa6_0(active0, 0x8000000040800000L, active1, 0L);
+ case 109:
+ return jjMoveStringLiteralDfa6_0(active0, 0x800000000L, active1, 0L);
+ case 110:
+ if ((active0 & 0x1000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 48, 23);
+ return jjMoveStringLiteralDfa6_0(active0, 0x2000400000L, active1, 0x1L);
+ case 114:
+ return jjMoveStringLiteralDfa6_0(active0, 0x20000000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x100000000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 56, 23);
+ break;
+ case 116:
+ if ((active0 & 0x1000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 36, 23);
+ return jjMoveStringLiteralDfa6_0(active0, 0x200000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(4, active0, active1);
+}
+private final int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(4, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(5, active0, active1);
+ return 6;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa7_0(active0, 0x8000008000000000L, active1, 0L);
+ case 99:
+ return jjMoveStringLiteralDfa7_0(active0, 0x2000002000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x100000000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 44, 23);
+ else if ((active0 & 0x200000000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 45, 23);
+ return jjMoveStringLiteralDfa7_0(active0, 0x200000800000000L, active1, 0L);
+ case 108:
+ return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000000L, active1, 0L);
+ case 110:
+ if ((active0 & 0x4000L) != 0L)
+ return jjStartNfaWithStates_0(6, 14, 23);
+ break;
+ case 111:
+ return jjMoveStringLiteralDfa7_0(active0, 0x20000000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x8000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 27, 23);
+ break;
+ case 116:
+ if ((active0 & 0x800000L) != 0L)
+ return jjStartNfaWithStates_0(6, 23, 23);
+ return jjMoveStringLiteralDfa7_0(active0, 0x400000000000L, active1, 0x1L);
+ case 117:
+ return jjMoveStringLiteralDfa7_0(active0, 0x400000L, active1, 0L);
+ case 121:
+ if ((active0 & 0x40000000L) != 0L)
+ return jjStartNfaWithStates_0(6, 30, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(5, active0, active1);
+}
+private final int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(5, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(6, active0, active1);
+ return 7;
+ }
+ switch(curChar)
+ {
+ case 99:
+ return jjMoveStringLiteralDfa8_0(active0, 0x8000000000L, active1, 0L);
+ case 101:
+ if ((active0 & 0x400000L) != 0L)
+ return jjStartNfaWithStates_0(7, 22, 23);
+ else if ((active0 & 0x2000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(7, 61, 23);
+ return jjMoveStringLiteralDfa8_0(active0, 0x402000000000L, active1, 0L);
+ case 105:
+ return jjMoveStringLiteralDfa8_0(active0, 0L, active1, 0x1L);
+ case 110:
+ return jjMoveStringLiteralDfa8_0(active0, 0x220000800000000L, active1, 0L);
+ case 115:
+ return jjMoveStringLiteralDfa8_0(active0, 0x8000000000000000L, active1, 0L);
+ case 116:
+ if ((active0 & 0x2000L) != 0L)
+ return jjStartNfaWithStates_0(7, 13, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(6, active0, active1);
+}
+private final int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(6, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(7, active0, active1);
+ return 8;
+ }
+ switch(curChar)
+ {
+ case 97:
+ return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0x1L);
+ case 100:
+ if ((active0 & 0x400000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 46, 23);
+ break;
+ case 101:
+ if ((active0 & 0x8000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 39, 23);
+ break;
+ case 105:
+ return jjMoveStringLiteralDfa9_0(active0, 0x20000000000000L, active1, 0L);
+ case 111:
+ return jjMoveStringLiteralDfa9_0(active0, 0x2000000000L, active1, 0L);
+ case 115:
+ if ((active0 & 0x8000000000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 63, 23);
+ break;
+ case 116:
+ if ((active0 & 0x200000000000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 57, 23);
+ return jjMoveStringLiteralDfa9_0(active0, 0x800000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(7, active0, active1);
+}
+private final int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(7, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(8, active0, active1);
+ return 9;
+ }
+ switch(curChar)
+ {
+ case 102:
+ if ((active0 & 0x2000000000L) != 0L)
+ return jjStartNfaWithStates_0(9, 37, 23);
+ break;
+ case 115:
+ if ((active0 & 0x800000000L) != 0L)
+ return jjStartNfaWithStates_0(9, 35, 23);
+ break;
+ case 116:
+ return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x1L);
+ case 122:
+ return jjMoveStringLiteralDfa10_0(active0, 0x20000000000000L, active1, 0L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(8, active0, active1);
+}
+private final int jjMoveStringLiteralDfa10_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(8, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(9, active0, active1);
+ return 10;
+ }
+ switch(curChar)
+ {
+ case 101:
+ return jjMoveStringLiteralDfa11_0(active0, 0x20000000000000L, active1, 0x1L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(9, active0, active1);
+}
+private final int jjMoveStringLiteralDfa11_0(long old0, long active0, long old1, long active1)
+{
+ if (((active0 &= old0) | (active1 &= old1)) == 0L)
+ return jjStartNfa_0(9, old0, old1);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(10, active0, active1);
+ return 11;
+ }
+ switch(curChar)
+ {
+ case 100:
+ if ((active0 & 0x20000000000000L) != 0L)
+ return jjStartNfaWithStates_0(11, 53, 23);
+ break;
+ case 115:
+ if ((active1 & 0x1L) != 0L)
+ return jjStartNfaWithStates_0(11, 64, 23);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(10, active0, active1);
+}
+private final void jjCheckNAdd(int state)
+{
+ if (jjrounds[state] != jjround)
+ {
+ jjstateSet[jjnewStateCnt++] = state;
+ jjrounds[state] = jjround;
+ }
+}
+private final void jjAddStates(int start, int end)
+{
+ do {
+ jjstateSet[jjnewStateCnt++] = jjnextStates[start];
+ } while (start++ != end);
+}
+private final void jjCheckNAddTwoStates(int state1, int state2)
+{
+ jjCheckNAdd(state1);
+ jjCheckNAdd(state2);
+}
+private final void jjCheckNAddStates(int start, int end)
+{
+ do {
+ jjCheckNAdd(jjnextStates[start]);
+ } while (start++ != end);
+}
+private final void jjCheckNAddStates(int start)
+{
+ jjCheckNAdd(jjnextStates[start]);
+ jjCheckNAdd(jjnextStates[start + 1]);
+}
+static final long[] jjbitVec0 = {
+ 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec2 = {
+ 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec3 = {
+ 0x1ff00000fffffffeL, 0xffffffffffffc000L, 0xffffffffL, 0x600000000000000L
+};
+static final long[] jjbitVec4 = {
+ 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL
+};
+static final long[] jjbitVec5 = {
+ 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec6 = {
+ 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffL, 0x0L
+};
+static final long[] jjbitVec7 = {
+ 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L, 0x0L
+};
+static final long[] jjbitVec8 = {
+ 0x3fffffffffffL, 0x0L, 0x0L, 0x0L
+};
+private final int jjMoveNfa_0(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 75;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 75:
+ if ((0x3ff000000000000L & l) != 0L)
+ {
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddStates(0, 2);
+ }
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(3, 5);
+ break;
+ case 3:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(6, 19);
+ else if (curChar == 46)
+ jjCheckNAddTwoStates(29, 34);
+ else if (curChar == 36)
+ {
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ }
+ else if (curChar == 34)
+ jjCheckNAddStates(20, 22);
+ else if (curChar == 39)
+ jjAddStates(23, 24);
+ else if (curChar == 47)
+ jjstateSet[jjnewStateCnt++] = 2;
+ if ((0x3fe000000000000L & l) != 0L)
+ {
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(25, 27);
+ }
+ else if (curChar == 48)
+ {
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(28, 32);
+ }
+ break;
+ case 0:
+ if (curChar == 42)
+ jjstateSet[jjnewStateCnt++] = 1;
+ break;
+ case 1:
+ if ((0xffff7fffffffffffL & l) != 0L && kind > 6)
+ kind = 6;
+ break;
+ case 2:
+ if (curChar == 42)
+ jjstateSet[jjnewStateCnt++] = 0;
+ break;
+ case 4:
+ if (curChar == 39)
+ jjAddStates(23, 24);
+ break;
+ case 5:
+ if ((0xffffff7fffffdbffL & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 6:
+ if (curChar == 39 && kind > 73)
+ kind = 73;
+ break;
+ case 8:
+ if ((0x8400000000L & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 9:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(10, 6);
+ break;
+ case 10:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 11:
+ if ((0xf000000000000L & l) != 0L)
+ jjstateSet[jjnewStateCnt++] = 12;
+ break;
+ case 12:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAdd(10);
+ break;
+ case 13:
+ if (curChar == 34)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 14:
+ if ((0xfffffffbffffdbffL & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 16:
+ if ((0x8400000000L & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 17:
+ if (curChar == 34 && kind > 74)
+ kind = 74;
+ break;
+ case 18:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddStates(33, 36);
+ break;
+ case 19:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 20:
+ if ((0xf000000000000L & l) != 0L)
+ jjstateSet[jjnewStateCnt++] = 21;
+ break;
+ case 21:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAdd(19);
+ break;
+ case 22:
+ if (curChar != 36)
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 23:
+ if ((0x3ff001000000000L & l) == 0L)
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 24:
+ if ((0x3fe000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(25, 27);
+ break;
+ case 25:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAdd(25);
+ break;
+ case 26:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(26, 27);
+ break;
+ case 28:
+ if (curChar == 46)
+ jjCheckNAddTwoStates(29, 34);
+ break;
+ case 29:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(3, 5);
+ break;
+ case 31:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(32);
+ break;
+ case 32:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(32, 33);
+ break;
+ case 34:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddStates(0, 2);
+ break;
+ case 36:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(37);
+ break;
+ case 37:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddTwoStates(37, 38);
+ break;
+ case 39:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(6, 19);
+ break;
+ case 40:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(40, 41);
+ break;
+ case 41:
+ if (curChar != 46)
+ break;
+ if (kind > 70)
+ kind = 70;
+ jjCheckNAddStates(37, 39);
+ break;
+ case 42:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 70)
+ kind = 70;
+ jjCheckNAddStates(37, 39);
+ break;
+ case 44:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(45);
+ break;
+ case 45:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 70)
+ kind = 70;
+ jjCheckNAddTwoStates(45, 33);
+ break;
+ case 46:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(46, 47);
+ break;
+ case 48:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(49);
+ break;
+ case 49:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(49, 33);
+ break;
+ case 50:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(40, 42);
+ break;
+ case 52:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(53);
+ break;
+ case 53:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(53, 33);
+ break;
+ case 54:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(54, 55);
+ break;
+ case 55:
+ if (curChar == 46)
+ jjCheckNAddStates(43, 45);
+ break;
+ case 56:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(43, 45);
+ break;
+ case 58:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(59);
+ break;
+ case 59:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(59, 38);
+ break;
+ case 60:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(60, 61);
+ break;
+ case 62:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(63);
+ break;
+ case 63:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 71)
+ kind = 71;
+ jjCheckNAddTwoStates(63, 38);
+ break;
+ case 64:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddStates(46, 48);
+ break;
+ case 66:
+ if ((0x280000000000L & l) != 0L)
+ jjCheckNAdd(67);
+ break;
+ case 67:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(67, 38);
+ break;
+ case 68:
+ if (curChar != 48)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAddStates(28, 32);
+ break;
+ case 70:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjstateSet[jjnewStateCnt++] = 70;
+ break;
+ case 71:
+ if ((0xff000000000000L & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAdd(71);
+ break;
+ case 73:
+ if ((0x3ff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(73, 27);
+ break;
+ case 74:
+ if ((0xff000000000000L & l) != 0L)
+ jjCheckNAddTwoStates(74, 27);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 3:
+ case 23:
+ if ((0x7fffffe87fffffeL & l) == 0L)
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 1:
+ if (kind > 6)
+ kind = 6;
+ break;
+ case 5:
+ if ((0xffffffffefffffffL & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 7:
+ if (curChar == 92)
+ jjAddStates(49, 51);
+ break;
+ case 8:
+ if ((0x14404410000000L & l) != 0L)
+ jjCheckNAdd(6);
+ break;
+ case 14:
+ if ((0xffffffffefffffffL & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 15:
+ if (curChar == 92)
+ jjAddStates(52, 54);
+ break;
+ case 16:
+ if ((0x14404410000000L & l) != 0L)
+ jjCheckNAddStates(20, 22);
+ break;
+ case 27:
+ if ((0x100000001000L & l) != 0L && kind > 66)
+ kind = 66;
+ break;
+ case 30:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(55, 56);
+ break;
+ case 33:
+ if ((0x1000000010L & l) != 0L && kind > 70)
+ kind = 70;
+ break;
+ case 35:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(57, 58);
+ break;
+ case 38:
+ if ((0x4000000040L & l) != 0L && kind > 71)
+ kind = 71;
+ break;
+ case 43:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(59, 60);
+ break;
+ case 47:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(61, 62);
+ break;
+ case 51:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(63, 64);
+ break;
+ case 57:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(65, 66);
+ break;
+ case 61:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(67, 68);
+ break;
+ case 65:
+ if ((0x2000000020L & l) != 0L)
+ jjAddStates(69, 70);
+ break;
+ case 69:
+ if ((0x100000001000000L & l) != 0L)
+ jjCheckNAdd(70);
+ break;
+ case 70:
+ if ((0x7e0000007eL & l) == 0L)
+ break;
+ if (kind > 65)
+ kind = 65;
+ jjCheckNAdd(70);
+ break;
+ case 72:
+ if ((0x100000001000000L & l) != 0L)
+ jjCheckNAdd(73);
+ break;
+ case 73:
+ if ((0x7e0000007eL & l) != 0L)
+ jjCheckNAddTwoStates(73, 27);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int hiByte = (int)(curChar >> 8);
+ int i1 = hiByte >> 6;
+ long l1 = 1L << (hiByte & 077);
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 3:
+ case 23:
+ if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
+ break;
+ if (kind > 75)
+ kind = 75;
+ jjCheckNAdd(23);
+ break;
+ case 1:
+ if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 6)
+ kind = 6;
+ break;
+ case 5:
+ if (jjCanMove_0(hiByte, i1, i2, l1, l2))
+ jjstateSet[jjnewStateCnt++] = 6;
+ break;
+ case 14:
+ if (jjCanMove_0(hiByte, i1, i2, l1, l2))
+ jjAddStates(20, 22);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 75 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+private final int jjMoveStringLiteralDfa0_3()
+{
+ switch(curChar)
+ {
+ case 42:
+ return jjMoveStringLiteralDfa1_3(0x800L);
+ default :
+ return 1;
+ }
+}
+private final int jjMoveStringLiteralDfa1_3(long active0)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 47:
+ if ((active0 & 0x800L) != 0L)
+ return jjStopAtPos(1, 11);
+ break;
+ default :
+ return 2;
+ }
+ return 2;
+}
+private final int jjMoveStringLiteralDfa0_1()
+{
+ return jjMoveNfa_1(0, 0);
+}
+private final int jjMoveNfa_1(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 3;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ if ((0x2400L & l) != 0L)
+ {
+ if (kind > 9)
+ kind = 9;
+ }
+ if (curChar == 13)
+ jjstateSet[jjnewStateCnt++] = 1;
+ break;
+ case 1:
+ if (curChar == 10 && kind > 9)
+ kind = 9;
+ break;
+ case 2:
+ if (curChar == 13)
+ jjstateSet[jjnewStateCnt++] = 1;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int hiByte = (int)(curChar >> 8);
+ int i1 = hiByte >> 6;
+ long l1 = 1L << (hiByte & 077);
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+private final int jjMoveStringLiteralDfa0_2()
+{
+ switch(curChar)
+ {
+ case 42:
+ return jjMoveStringLiteralDfa1_2(0x400L);
+ default :
+ return 1;
+ }
+}
+private final int jjMoveStringLiteralDfa1_2(long active0)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 47:
+ if ((active0 & 0x400L) != 0L)
+ return jjStopAtPos(1, 10);
+ break;
+ default :
+ return 2;
+ }
+ return 2;
+}
+static final int[] jjnextStates = {
+ 34, 35, 38, 29, 30, 33, 40, 41, 46, 47, 50, 51, 33, 54, 55, 60,
+ 61, 64, 65, 38, 14, 15, 17, 5, 7, 25, 26, 27, 69, 71, 72, 74,
+ 27, 14, 15, 19, 17, 42, 43, 33, 50, 51, 33, 56, 57, 38, 64, 65,
+ 38, 8, 9, 11, 16, 18, 20, 31, 32, 36, 37, 44, 45, 48, 49, 52,
+ 53, 58, 59, 62, 63, 66, 67,
+};
+private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
+{
+ switch(hiByte)
+ {
+ case 0:
+ return ((jjbitVec2[i2] & l2) != 0L);
+ default :
+ if ((jjbitVec0[i1] & l1) != 0L)
+ return true;
+ return false;
+ }
+}
+private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2)
+{
+ switch(hiByte)
+ {
+ case 0:
+ return ((jjbitVec4[i2] & l2) != 0L);
+ case 48:
+ return ((jjbitVec5[i2] & l2) != 0L);
+ case 49:
+ return ((jjbitVec6[i2] & l2) != 0L);
+ case 51:
+ return ((jjbitVec7[i2] & l2) != 0L);
+ case 61:
+ return ((jjbitVec8[i2] & l2) != 0L);
+ default :
+ if ((jjbitVec3[i1] & l1) != 0L)
+ return true;
+ return false;
+ }
+}
+public static final String[] jjstrLiteralImages = {
+"", null, null, null, null, null, null, null, null, null, null, null, null,
+"\141\142\163\164\162\141\143\164", "\142\157\157\154\145\141\156", "\142\162\145\141\153", "\142\171\164\145",
+"\143\141\163\145", "\143\141\164\143\150", "\143\150\141\162", "\143\154\141\163\163",
+"\143\157\156\163\164", "\143\157\156\164\151\156\165\145", "\144\145\146\141\165\154\164",
+"\144\157", "\144\157\165\142\154\145", "\145\154\163\145",
+"\145\170\164\145\156\144\163", "\146\141\154\163\145", "\146\151\156\141\154",
+"\146\151\156\141\154\154\171", "\146\154\157\141\164", "\146\157\162", "\147\157\164\157", "\151\146",
+"\151\155\160\154\145\155\145\156\164\163", "\151\155\160\157\162\164", "\151\156\163\164\141\156\143\145\157\146",
+"\151\156\164", "\151\156\164\145\162\146\141\143\145", "\154\157\156\147",
+"\156\141\164\151\166\145", "\156\145\167", "\156\165\154\154", "\160\141\143\153\141\147\145",
+"\160\162\151\166\141\164\145", "\160\162\157\164\145\143\164\145\144", "\160\165\142\154\151\143",
+"\162\145\164\165\162\156", "\163\150\157\162\164", "\163\164\141\164\151\143", "\163\165\160\145\162",
+"\163\167\151\164\143\150", "\163\171\156\143\150\162\157\156\151\172\145\144", "\164\150\151\163",
+"\164\150\162\157\167", "\164\150\162\157\167\163", "\164\162\141\156\163\151\145\156\164",
+"\164\162\165\145", "\164\162\171", "\166\157\151\144", "\166\157\154\141\164\151\154\145",
+"\167\150\151\154\145", "\155\145\164\141\143\154\141\163\163",
+"\151\156\163\164\141\156\164\151\141\164\145\163", null, null, null, null, null, null, null, null, null, null, null, null, null,
+"\50", "\51", "\173", "\175", "\133", "\135", "\73", "\54", "\56", "\75", "\76",
+"\74", "\41", "\176", "\77", "\72", "\75\75", "\74\75", "\76\75", "\41\75",
+"\174\174", "\46\46", "\53\53", "\55\55", "\53", "\55", "\52", "\57", "\46", "\174",
+"\136", "\45", "\74\74", "\76\76", "\76\76\76", "\53\75", "\55\75", "\52\75",
+"\57\75", "\46\75", "\174\75", "\136\75", "\45\75", "\74\74\75", "\76\76\75",
+"\76\76\76\75", };
+public static final String[] lexStateNames = {
+ "DEFAULT",
+ "IN_SINGLE_LINE_COMMENT",
+ "IN_FORMAL_COMMENT",
+ "IN_MULTI_LINE_COMMENT",
+};
+public static final int[] jjnewLexState = {
+ -1, -1, -1, -1, -1, -1, 2, 1, 3, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+};
+static final long[] jjtoToken = {
+ 0xffffffffffffe001L, 0xfffffffffffcec7L,
+};
+static final long[] jjtoSkip = {
+ 0xe3eL, 0x0L,
+};
+static final long[] jjtoSpecial = {
+ 0xe00L, 0x0L,
+};
+static final long[] jjtoMore = {
+ 0x11c0L, 0x0L,
+};
+private ASCII_UCodeESC_CharStream input_stream;
+private final int[] jjrounds = new int[75];
+private final int[] jjstateSet = new int[150];
+StringBuffer image;
+int jjimageLen;
+int lengthOfMatch;
+protected char curChar;
+public ParserTokenManager(ASCII_UCodeESC_CharStream stream)
+{
+ if (ASCII_UCodeESC_CharStream.staticFlag)
+ throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
+ input_stream = stream;
+}
+public ParserTokenManager(ASCII_UCodeESC_CharStream stream, int lexState)
+{
+ this(stream);
+ SwitchTo(lexState);
+}
+public void ReInit(ASCII_UCodeESC_CharStream stream)
+{
+ jjmatchedPos = jjnewStateCnt = 0;
+ curLexState = defaultLexState;
+ input_stream = stream;
+ ReInitRounds();
+}
+private final void ReInitRounds()
+{
+ int i;
+ jjround = 0x80000001;
+ for (i = 75; i-- > 0;)
+ jjrounds[i] = 0x80000000;
+}
+public void ReInit(ASCII_UCodeESC_CharStream stream, int lexState)
+{
+ ReInit(stream);
+ SwitchTo(lexState);
+}
+public void SwitchTo(int lexState)
+{
+ if (lexState >= 4 || lexState < 0)
+ throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
+ else
+ curLexState = lexState;
+}
+
+private final Token jjFillToken()
+{
+ Token t = Token.newToken(jjmatchedKind);
+ t.kind = jjmatchedKind;
+ String im = jjstrLiteralImages[jjmatchedKind];
+ t.image = (im == null) ? input_stream.GetImage() : im;
+ t.beginLine = input_stream.getBeginLine();
+ t.beginColumn = input_stream.getBeginColumn();
+ t.endLine = input_stream.getEndLine();
+ t.endColumn = input_stream.getEndColumn();
+ return t;
+}
+
+int curLexState = 0;
+int defaultLexState = 0;
+int jjnewStateCnt;
+int jjround;
+int jjmatchedPos;
+int jjmatchedKind;
+
+public final Token getNextToken()
+{
+ int kind;
+ Token specialToken = null;
+ Token matchedToken;
+ int curPos = 0;
+
+ EOFLoop :
+ for (;;)
+ {
+ try
+ {
+ curChar = input_stream.BeginToken();
+ }
+ catch(java.io.IOException e)
+ {
+ jjmatchedKind = 0;
+ matchedToken = jjFillToken();
+ matchedToken.specialToken = specialToken;
+ return matchedToken;
+ }
+ image = null;
+ jjimageLen = 0;
+
+ for (;;)
+ {
+ switch(curLexState)
+ {
+ case 0:
+ try { input_stream.backup(0);
+ while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L)
+ curChar = input_stream.BeginToken();
+ }
+ catch (java.io.IOException e1) { continue EOFLoop; }
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_0();
+ break;
+ case 1:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_1();
+ if (jjmatchedPos == 0 && jjmatchedKind > 12)
+ {
+ jjmatchedKind = 12;
+ }
+ break;
+ case 2:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_2();
+ if (jjmatchedPos == 0 && jjmatchedKind > 12)
+ {
+ jjmatchedKind = 12;
+ }
+ break;
+ case 3:
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_3();
+ if (jjmatchedPos == 0 && jjmatchedKind > 12)
+ {
+ jjmatchedKind = 12;
+ }
+ break;
+ }
+ if (jjmatchedKind != 0x7fffffff)
+ {
+ if (jjmatchedPos + 1 < curPos)
+ input_stream.backup(curPos - jjmatchedPos - 1);
+ if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ matchedToken.specialToken = specialToken;
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ return matchedToken;
+ }
+ else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ if (specialToken == null)
+ specialToken = matchedToken;
+ else
+ {
+ matchedToken.specialToken = specialToken;
+ specialToken = (specialToken.next = matchedToken);
+ }
+ SkipLexicalActions(matchedToken);
+ }
+ else
+ SkipLexicalActions(null);
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ continue EOFLoop;
+ }
+ jjimageLen += jjmatchedPos + 1;
+ if (jjnewLexState[jjmatchedKind] != -1)
+ curLexState = jjnewLexState[jjmatchedKind];
+ curPos = 0;
+ jjmatchedKind = 0x7fffffff;
+ try {
+ curChar = input_stream.readChar();
+ continue;
+ }
+ catch (java.io.IOException e1) { }
+ }
+ int error_line = input_stream.getEndLine();
+ int error_column = input_stream.getEndColumn();
+ String error_after = null;
+ boolean EOFSeen = false;
+ try { input_stream.readChar(); input_stream.backup(1); }
+ catch (java.io.IOException e1) {
+ EOFSeen = true;
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ if (curChar == '\n' || curChar == '\r') {
+ error_line++;
+ error_column = 0;
+ }
+ else
+ error_column++;
+ }
+ if (!EOFSeen) {
+ input_stream.backup(1);
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ }
+ throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
+ }
+ }
+}
+
+final void SkipLexicalActions(Token matchedToken)
+{
+ switch(jjmatchedKind)
+ {
+ default :
+ break;
+ }
+}
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/Token.java b/src/main/java/io/devnulllabs/openjava/tools/parser/Token.java
new file mode 100644
index 0000000..1cf7c60
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/Token.java
@@ -0,0 +1,81 @@
+/* Generated By:JavaCC: Do not edit this line. Token.java Version 2.1 */
+package io.devnulllabs.openjava.tools.parser;
+
+/**
+ * Describes the input token stream.
+ */
+
+public class Token {
+
+ /**
+ * An integer that describes the kind of this token. This numbering
+ * system is determined by JavaCCParser, and a table of these numbers is
+ * stored in the file ...Constants.java.
+ */
+ public int kind;
+
+ /**
+ * beginLine and beginColumn describe the position of the first character
+ * of this token; endLine and endColumn describe the position of the
+ * last character of this token.
+ */
+ public int beginLine, beginColumn, endLine, endColumn;
+
+ /**
+ * The string image of the token.
+ */
+ public String image;
+
+ /**
+ * A reference to the next regular (non-special) token from the input
+ * stream. If this is the last token from the input stream, or if the
+ * token manager has not read tokens beyond this one, this field is
+ * set to null. This is true only if this token is also a regular
+ * token. Otherwise, see below for a description of the contents of
+ * this field.
+ */
+ public Token next;
+
+ /**
+ * This field is used to access special tokens that occur prior to this
+ * token, but after the immediately preceding regular (non-special) token.
+ * If there are no such special tokens, this field is set to null.
+ * When there are more than one such special token, this field refers
+ * to the last of these special tokens, which in turn refers to the next
+ * previous special token through its specialToken field, and so on
+ * until the first special token (whose specialToken field is null).
+ * The next fields of special tokens refer to other special tokens that
+ * immediately follow it (without an intervening regular token). If there
+ * is no such token, this field is null.
+ */
+ public Token specialToken;
+
+ /**
+ * Returns the image.
+ */
+ public final String toString()
+ {
+ return image;
+ }
+
+ /**
+ * Returns a new Token object, by default. However, if you want, you
+ * can create and return subclass objects based on the value of ofKind.
+ * Simply add the cases to the switch for all those special cases.
+ * For example, if you have a subclass of Token called IDToken that
+ * you want to create if ofKind is ID, simlpy add something like :
+ *
+ * case MyParserConstants.ID : return new IDToken();
+ *
+ * to the following switch statement. Then you can cast matchedToken
+ * variable to the appropriate type and use it in your lexical actions.
+ */
+ public static final Token newToken(int ofKind)
+ {
+ switch(ofKind)
+ {
+ default : return new Token();
+ }
+ }
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/TokenIDPublisher.java b/src/main/java/io/devnulllabs/openjava/tools/parser/TokenIDPublisher.java
new file mode 100644
index 0000000..3214779
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/TokenIDPublisher.java
@@ -0,0 +1,122 @@
+package io.devnulllabs.openjava.tools.parser;
+
+
+public interface TokenIDPublisher {
+
+ public static final int EOF = ParserConstants.EOF;
+
+ public static final int ABSTRACT = ParserConstants.ABSTRACT;
+ public static final int BOOLEAN = ParserConstants.BOOLEAN;
+ public static final int BREAK = ParserConstants.BREAK;
+ public static final int BYTE = ParserConstants.BYTE;
+ public static final int CASE = ParserConstants.CASE;
+ public static final int CATCH = ParserConstants.CATCH;
+ public static final int CHAR = ParserConstants.CHAR;
+ public static final int CLASS = ParserConstants.CLASS;
+ public static final int CONTINUE = ParserConstants.CONTINUE;
+ public static final int DEFAULT = ParserConstants._DEFAULT;
+ public static final int DO = ParserConstants.DO;
+ public static final int DOUBLE = ParserConstants.DOUBLE;
+ public static final int ELSE = ParserConstants.ELSE;
+ public static final int EXTENDS = ParserConstants.EXTENDS;
+ public static final int FALSE = ParserConstants.FALSE;
+ public static final int FINAL = ParserConstants.FINAL;
+ public static final int FINALLY = ParserConstants.FINALLY;
+ public static final int FLOAT = ParserConstants.FLOAT;
+ public static final int FOR = ParserConstants.FOR;
+ public static final int IF = ParserConstants.IF;
+ public static final int IMPLEMENTS = ParserConstants.IMPLEMENTS;
+ public static final int IMPORT = ParserConstants.IMPORT;
+ public static final int INSTANCEOF = ParserConstants.INSTANCEOF;
+ public static final int INT = ParserConstants.INT;
+ public static final int INTERFACE = ParserConstants.INTERFACE;
+ public static final int LONG = ParserConstants.LONG;
+ public static final int NATIVE = ParserConstants.NATIVE;
+ public static final int NEW = ParserConstants.NEW;
+ public static final int NULL = ParserConstants.NULL;
+ public static final int PACKAGE = ParserConstants.PACKAGE;
+ public static final int PRIVATE = ParserConstants.PRIVATE;
+ public static final int PROTECTED = ParserConstants.PROTECTED;
+ public static final int PUBLIC = ParserConstants.PUBLIC;
+ public static final int RETURN = ParserConstants.RETURN;
+ public static final int SHORT = ParserConstants.SHORT;
+ public static final int STATIC = ParserConstants.STATIC;
+ public static final int SUPER = ParserConstants.SUPER;
+ public static final int SWITCH = ParserConstants.SWITCH;
+ public static final int SYNCHRONIZED = ParserConstants.SYNCHRONIZED;
+ public static final int THIS = ParserConstants.THIS;
+ public static final int THROW = ParserConstants.THROW;
+ public static final int THROWS = ParserConstants.THROWS;
+ public static final int TRANSIENT = ParserConstants.TRANSIENT;
+ public static final int TRUE = ParserConstants.TRUE;
+ public static final int TRY = ParserConstants.TRY;
+ public static final int VOID = ParserConstants.VOID;
+ public static final int VOLATILE = ParserConstants.VOLATILE;
+ public static final int WHILE = ParserConstants.WHILE;
+ public static final int METACLASS = ParserConstants.METACLASS;
+ public static final int INSTANTIATES = ParserConstants.INSTANTIATES;
+
+ public static final int INTEGER_LITERAL
+ = ParserConstants.INTEGER_LITERAL;
+ public static final int LONG_LITERAL
+ = ParserConstants.LONG_LITERAL;
+ public static final int DOUBLE_LITERAL
+ = ParserConstants.DOUBLE_FLOATING_POINT_LITERAL;
+ public static final int FLOAT_LITERAL
+ = ParserConstants.FLOATING_POINT_LITERAL;
+ public static final int CHARACTER_LITERAL
+ = ParserConstants.CHARACTER_LITERAL;
+ public static final int STRING_LITERAL
+ = ParserConstants.STRING_LITERAL;
+
+ public static final int IDENTIFIER = ParserConstants.IDENTIFIER;
+ public static final int LPAREN = ParserConstants.LPAREN;
+ public static final int RPAREN = ParserConstants.RPAREN;
+ public static final int LBRACE = ParserConstants.LBRACE;
+ public static final int RBRACE = ParserConstants.RBRACE;
+ public static final int LBRACKET = ParserConstants.LBRACKET;
+ public static final int RBRACKET = ParserConstants.RBRACKET;
+ public static final int SEMICOLON = ParserConstants.SEMICOLON;
+ public static final int COMMA = ParserConstants.COMMA;
+ public static final int DOT = ParserConstants.DOT;
+ public static final int ASSIGN = ParserConstants.ASSIGN;
+ public static final int GREATER = ParserConstants.GT;
+ public static final int LESS = ParserConstants.LT;
+ public static final int BANG = ParserConstants.BANG;
+ public static final int TILDE = ParserConstants.TILDE;
+ public static final int HOOK = ParserConstants.HOOK;
+ public static final int COLON = ParserConstants.COLON;
+ public static final int EQUAL = ParserConstants.EQ;
+ public static final int LESS_EQUAL = ParserConstants.LE;
+ public static final int GREATER_EQUAL = ParserConstants.GE;
+ public static final int NOT_EQUAL = ParserConstants.NE;
+ public static final int CONDITIONAL_OR = ParserConstants.SC_OR;
+ public static final int CONDITIONAL_AND = ParserConstants.SC_AND;
+ public static final int INCREMENT = ParserConstants.INCR;
+ public static final int DECREMENT = ParserConstants.DECR;
+ public static final int PLUS = ParserConstants.PLUS;
+ public static final int MINUS = ParserConstants.MINUS;
+ public static final int STAR = ParserConstants.STAR;
+ public static final int SLASH = ParserConstants.SLASH;
+ public static final int BIT_AND = ParserConstants.BIT_AND;
+ public static final int BIT_OR = ParserConstants.BIT_OR;
+ public static final int XOR = ParserConstants.XOR;
+ public static final int REM = ParserConstants.REM;
+ public static final int LSHIFT = ParserConstants.LSHIFT;
+ public static final int RSIGNEDSHIFT = ParserConstants.RSIGNEDSHIFT;
+ public static final int RUNSIGNEDSHIFT = ParserConstants.RUNSIGNEDSHIFT;
+ public static final int PLUSASSIGN = ParserConstants.PLUSASSIGN;
+ public static final int MINUSASSIGN = ParserConstants.MINUSASSIGN;
+ public static final int STARASSIGN = ParserConstants.STARASSIGN;
+ public static final int SLASHASSIGN = ParserConstants.SLASHASSIGN;
+ public static final int ANDASSIGN = ParserConstants.ANDASSIGN;
+ public static final int ORASSIGN = ParserConstants.ORASSIGN;
+ public static final int XORASSIGN = ParserConstants.XORASSIGN;
+ public static final int REMASSIGN = ParserConstants.REMASSIGN;
+ public static final int LSHIFTASSIGN = ParserConstants.LSHIFTASSIGN;
+ public static final int RSIGNEDSHIFTASSIGN
+ = ParserConstants.RSIGNEDSHIFTASSIGN;
+ public static final int RUNSIGNEDSHIFTASSIGN
+ = ParserConstants.RUNSIGNEDSHIFTASSIGN;
+
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/TokenMgrError.java b/src/main/java/io/devnulllabs/openjava/tools/parser/TokenMgrError.java
new file mode 100644
index 0000000..90eb662
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/TokenMgrError.java
@@ -0,0 +1,133 @@
+/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
+package io.devnulllabs.openjava.tools.parser;
+
+public class TokenMgrError extends Error
+{
+ /*
+ * Ordinals for various reasons why an Error of this type can be thrown.
+ */
+
+ /**
+ * Lexical error occured.
+ */
+ static final int LEXICAL_ERROR = 0;
+
+ /**
+ * An attempt wass made to create a second instance of a static token manager.
+ */
+ static final int STATIC_LEXER_ERROR = 1;
+
+ /**
+ * Tried to change to an invalid lexical state.
+ */
+ static final int INVALID_LEXICAL_STATE = 2;
+
+ /**
+ * Detected (and bailed out of) an infinite loop in the token manager.
+ */
+ static final int LOOP_DETECTED = 3;
+
+ /**
+ * Indicates the reason why the exception is thrown. It will have
+ * one of the above 4 values.
+ */
+ int errorCode;
+
+ /**
+ * Replaces unprintable characters by their espaced (or unicode escaped)
+ * equivalents in the given string
+ */
+ protected static final String addEscapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+ /**
+ * Returns a detailed message for the Error when it is thrown by the
+ * token manager to indicate a lexical error.
+ * Parameters :
+ * EOFSeen : indicates if EOF caused the lexicl error
+ * curLexState : lexical state in which this error occured
+ * errorLine : line number when the error occured
+ * errorColumn : column number when the error occured
+ * errorAfter : prefix that was seen before this error occured
+ * curchar : the offending character
+ * Note: You can customize the lexical error message by modifying this method.
+ */
+ private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
+ return("Lexical error at line " +
+ errorLine + ", column " +
+ errorColumn + ". Encountered: " +
+ (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
+ "after : \"" + addEscapes(errorAfter) + "\"");
+ }
+
+ /**
+ * You can also modify the body of this method to customize your error messages.
+ * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
+ * of end-users concern, so you can return something like :
+ *
+ * "Internal Error : Please file a bug report .... "
+ *
+ * from this method for such cases in the release version of your parser.
+ */
+ public String getMessage() {
+ return super.getMessage();
+ }
+
+ /*
+ * Constructors of various flavors follow.
+ */
+
+ public TokenMgrError() {
+ }
+
+ public TokenMgrError(String message, int reason) {
+ super(message);
+ errorCode = reason;
+ }
+
+ public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
+ this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/TokenSourceAdapter.java b/src/main/java/io/devnulllabs/openjava/tools/parser/TokenSourceAdapter.java
new file mode 100644
index 0000000..1d9e0f8
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/TokenSourceAdapter.java
@@ -0,0 +1,44 @@
+/*
+ * TokenSourceAdapter.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.tools.parser;
+
+import io.devnulllabs.openjava.syntax.TokenSource;
+
+/**
+ * The class <code>TokenSourceAdapter</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TokenSourceAdapter.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public final class TokenSourceAdapter extends ParserTokenManager {
+ private TokenSource token_src;
+
+ public TokenSourceAdapter(TokenSource token_src) {
+ super(null);
+ this.token_src = token_src;
+ }
+
+ public Token getNextToken() {
+ return token_src.getNextToken();
+ }
+
+ public Token getToken(int i) {
+ return token_src.getToken(i);
+ }
+}
diff --git a/src/main/java/io/devnulllabs/openjava/tools/parser/patchParserTokenManager.pl b/src/main/java/io/devnulllabs/openjava/tools/parser/patchParserTokenManager.pl
new file mode 100644
index 0000000..26dc274
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/tools/parser/patchParserTokenManager.pl
@@ -0,0 +1,11 @@
+#!/usr/local/bin/perl
+
+while (<>) {
+ print &removefinal($_);
+}
+
+sub removefinal {
+ local($_) = @_;
+ $_ =~ s/public final Token getNextToken/public Token getNextToken/;
+ return $_;
+}
diff --git a/src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java
new file mode 100644
index 0000000..8a1f179
--- /dev/null
+++ b/src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java
@@ -0,0 +1,24 @@
+/*
+ * NullCompiler.java
+ *
+ * Oct 10, 2000 Michiaki Tatsubori
+ */
+package jp.ac.tsukuba.openjava;
+
+import io.devnulllabs.openjava.ojc.JavaCompiler;
+
+/**
+ * The class <code>NullCompiler</code> does nothing.
+ * <p>
+ */
+public class NullCompiler implements JavaCompiler {
+ public NullCompiler() {
+ }
+
+ public static void main(String[] args) {
+ }
+
+ public void compile(String[] args) {
+ }
+
+}
diff --git a/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java
new file mode 100644
index 0000000..df890c3
--- /dev/null
+++ b/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java
@@ -0,0 +1,46 @@
+/*
+ * OldJavaCompiler.java
+ *
+ * Apr 16, 1999 Michiaki Tatsubori
+ */
+package jp.ac.tsukuba.openjava;
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+
+import io.devnulllabs.openjava.ojc.JavaCompiler;
+
+/**
+ * The class <code>OldJavaCompiler</code> is an adapter for Sun's javac.
+ *
+ */
+public class OldJavaCompiler implements JavaCompiler {
+ public static void main(String[] args) {
+ new OldJavaCompiler().compile(args);
+ }
+
+ public void compile(String[] args) {
+ /*sun.tools.javac.Main.main( args );*/
+ Runtime runtime = Runtime.getRuntime();
+ try {
+ Process p = runtime.exec("javac " + strs2str(args));
+ InputStream in = new BufferedInputStream(p.getErrorStream());
+ byte[] buf = new byte[1024];
+ for (int len = in.read(buf); len != -1; len = in.read(buf)) {
+ System.err.write(buf, 0, len);
+ }
+ p.waitFor();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static String strs2str(String[] strs) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < strs.length; ++i) {
+ buf.append(strs[i]).append(" ");
+ }
+ return buf.toString();
+ }
+
+}
diff --git a/src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java
new file mode 100644
index 0000000..ef9ba90
--- /dev/null
+++ b/src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java
@@ -0,0 +1,71 @@
+/*
+ * SunJavaCompiler.java
+ * Workaround for Runtime.exec() environment handling incompatibility..
+ *
+ * A work based on jp.ac.tsukuba.openjava.SunJavaCompiler
+ *
+ * Apr 16, 1999 Michiaki Tatsubori (mt@is.tsukuba.ac.jp)
+ * Oct 1, 1999 Shiro Kawai (shiro@squareusa.com)
+ * Nov 22, 1999 Michiaki Tatsubori
+ */
+package jp.ac.tsukuba.openjava;
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+
+import io.devnulllabs.openjava.ojc.JavaCompiler;
+
+/**
+ * The class <code>SunJavaCompiler</code> is an adapter for Sun's javac.
+ *
+ * Message-Id: 19990930154627G.shiro@squareusa.com
+ * <p>
+ * I tried OpenJava1.0a1 on my IRIX box w/ SGI's JDK1.2
+ * and had a problem to run ojc. Somehow, Runtime.exec()
+ * didn't pass all the environment variables to the invoked
+ * process (more specifically, it only passed TZ).
+ * Consequently the CLASSPATH env was not passed to javac kicked
+ * by JP.ac.tsukuba.openjava.SunJavaCompiler.complie(), which
+ * prevented ojc from finishing compilation.
+ * <p>
+ * So far I couldn't find exact specification about how the
+ * environment variables should be treated in Java specification
+ * and API documents. I guess it may depend on platforms.
+ * <p>
+ * We avoided the problem by explicitly passing CLASSPATH to
+ * the subprocess my modifying SunJavaCompiler class, but wondering
+ * if there'd be a better way to handle it...
+ */
+public class SunJavaCompiler implements JavaCompiler {
+ public static void main(String[] args) {
+ new SunJavaCompiler().compile(args);
+ }
+
+ public void compile(String[] args) {
+ Runtime runtime = Runtime.getRuntime();
+ try {
+ String classpath =
+ "CLASSPATH=" + System.getProperty("java.class.path");
+ String[] envp = new String[1];
+ envp[0] = classpath;
+ Process p = runtime.exec("javac " + strs2str(args), envp);
+ InputStream in = new BufferedInputStream(p.getErrorStream());
+ byte[] buf = new byte[1024];
+ for (int len = in.read(buf); len != -1; len = in.read(buf)) {
+ System.err.write(buf, 0, len);
+ }
+ p.waitFor();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static String strs2str(String[] strs) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < strs.length; ++i) {
+ buf.append(strs[i]).append(" ");
+ }
+ return buf.toString();
+ }
+
+}
diff --git a/src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java
new file mode 100644
index 0000000..f36454e
--- /dev/null
+++ b/src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java
@@ -0,0 +1,57 @@
+/*
+ * SunLibCompiler.java
+ *
+ * Apr 16, 1999 Michiaki Tatsubori
+ */
+package jp.ac.tsukuba.openjava;
+
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import io.devnulllabs.openjava.ojc.JavaCompiler;
+
+/**
+ * The class <code>SunLibCompiler</code> is an adapter for the compiler
+ * which invokes Sun's library javac.
+ * <p>
+ * The class path must includes lib/tools.jar in the jdk package.
+ *
+ * @since jdk1.2
+ */
+public class SunLibCompiler implements JavaCompiler {
+ Object sunJavac;
+ //sun.tools.javac.Main m;
+ Method compileMethod;
+
+ public SunLibCompiler() {
+ //m = new sun.tools.javac.Main(System.err, "javac");
+ try {
+ Class clazz = Class.forName("sun.tools.javac.Main");
+ Constructor cons =
+ clazz.getConstructor(
+ new Class[] { OutputStream.class, String.class });
+ sunJavac = cons.newInstance(new Object[] { System.err, "javac" });
+ compileMethod =
+ clazz.getMethod("compile", new Class[] { String[].class });
+ } catch (Exception ex) {
+ throw new RuntimeException(ex.toString());
+ }
+
+ }
+
+ public static void main(String[] args) {
+ new SunLibCompiler().compile(args);
+ }
+
+ public void compile(String[] args) {
+ //sun.tools.javac.Main.main( args );
+ //m.compile(args);
+ try {
+ compileMethod.invoke(sunJavac, new Object[] { args });
+ } catch (Exception ex) {
+ throw new RuntimeException(ex.toString());
+ }
+ }
+
+}
diff --git a/src/test/java/antonio/Test.oj b/src/test/java/antonio/Test.oj
new file mode 100644
index 0000000..b9c9c26
--- /dev/null
+++ b/src/test/java/antonio/Test.oj
@@ -0,0 +1,36 @@
+package antonio;
+
+import java.util.*;
+
+public class Test
+{
+ public int bbb() {
+ return 1;
+ }
+
+ class InnerVector extends Vector {
+ public int ff = 3;
+ public int aaa() {
+ return bbb();
+ }
+
+ public int ccc() {
+ return 0;
+ }
+ }
+
+ public void ddd() {
+ InnerVector v = new InnerVector() {
+ public int ccc() {
+ int j = ff;
+ return aaa();
+ }
+ };
+ System.err.println("Result:" + v.ccc());
+ }
+
+
+ public static void main(String[] args) {
+ (new Test()).ddd();
+ }
+}
diff --git a/src/test/java/bryn/ArraySupport.oj b/src/test/java/bryn/ArraySupport.oj
new file mode 100644
index 0000000..156ee50
--- /dev/null
+++ b/src/test/java/bryn/ArraySupport.oj
@@ -0,0 +1,62 @@
+package bryn;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+import io.devnulllabs.openjava.ptree.util.VariableBinder;
+
+public class ArraySupport instantiates Metaclass extends OJClass {
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ ArrayAccessReplace.run(methods[i]);
+ }
+ }
+
+ convenient public static boolean needed(OJClass type) {
+ return (type == java.util.ArrayList.class);
+ }
+
+}
+
+class ArrayAccessReplace extends VariableBinder {
+ public static void run(OJMethod method) throws MOPException {
+ ArrayAccessReplace replacer =
+ new ArrayAccessReplace(method.getEnvironment());
+ try {
+ method.getBody().accept(replacer);
+ } catch (ParseTreeException e) {
+ throw new MOPException(e);
+ }
+ }
+
+ public ArrayAccessReplace(Environment env) {
+ super(new ClosedEnvironment(env));
+ }
+
+ public Expression evaluateUp(ArrayAccess org_expr)
+ throws ParseTreeException {
+ /* "list" of "list[0]" */
+ Expression refexpr = org_expr.getReferenceExpr();
+
+ /* this is only for java.util.ArrayList instances */
+ try {
+ OJClass reftype = refexpr.getType(getEnvironment());
+ if (!ArraySupport.needed(reftype))
+ return org_expr;
+ } catch (Exception ex) {
+ throw new ParseTreeException(ex);
+ }
+
+ /* Creates arguments for method call */
+ ExpressionList args = new ExpressionList(org_expr.getIndexExpr());
+
+ /* returns "list.get(0)" from "list[0]" */
+ MethodCall result = new MethodCall(refexpr, "get", args);
+
+ System.err.println(org_expr + " -> " + result);
+ return result;
+ }
+
+}
diff --git a/src/test/java/bryn/ArrayTest.oj b/src/test/java/bryn/ArrayTest.oj
new file mode 100644
index 0000000..eceba8b
--- /dev/null
+++ b/src/test/java/bryn/ArrayTest.oj
@@ -0,0 +1,13 @@
+package bryn;
+
+import java.util.*;
+
+public class ArrayTest instantiates ArraySupport {
+ public static void main(String[] args) {
+ int[] il = new int[32];
+ ArrayList list = new ArrayList();
+ list.add("Hello");
+ list.add("World");
+ System.out.println(list[0] + " " + list[1] + " " + il[0]);
+ }
+}
diff --git a/src/test/java/cristophe/SigPrintClass.oj b/src/test/java/cristophe/SigPrintClass.oj
new file mode 100644
index 0000000..462f43b
--- /dev/null
+++ b/src/test/java/cristophe/SigPrintClass.oj
@@ -0,0 +1,22 @@
+import cristophe;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+
+/**
+ * The class <code>SigPrintClass</code> prints out the signature of
+ * public methods in the class metaobject.
+ */
+public class SigPrintClass instantiates Metaclass extends OJClass {
+ public ClassDeclaration translateDefinition(
+ Environment env,
+ ClassDeclaration decl) {
+ OJMethod[] m = getMethods();
+
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println(m[i].signature());
+ }
+
+ return decl;
+ }
+}
diff --git a/src/test/java/cristophe/Test.oj b/src/test/java/cristophe/Test.oj
new file mode 100644
index 0000000..accd283
--- /dev/null
+++ b/src/test/java/cristophe/Test.oj
@@ -0,0 +1,24 @@
+package cristophe;
+
+public class Test instantiates SigPrintClass
+{
+ public void f() {
+ }
+
+ public String g(String s, int i) {
+ return null;
+ }
+
+}
+
+
+class Test2 instantiates SigPrintClass
+{
+ public void f() {
+ }
+
+ public String g(String s, int i) {
+ return null;
+ }
+
+}
diff --git a/src/test/java/cristophe2/MethodRemovingClass.oj b/src/test/java/cristophe2/MethodRemovingClass.oj
new file mode 100644
index 0000000..2041dec
--- /dev/null
+++ b/src/test/java/cristophe2/MethodRemovingClass.oj
@@ -0,0 +1,20 @@
+package cristophe2;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+
+public class MethodRemovingClass instantiates Metaclass extends OJClass {
+ public ClassDeclaration translateDefinition(
+ Environment env,
+ ClassDeclaration decl)
+ throws MOPException {
+ OJMethod[] m = getDeclaredMethods();
+
+ if (m.length >= 1) {
+ System.out.println("Removing " + m[0].signature());
+ removeMethod(m[0]);
+ }
+
+ return decl;
+ }
+}
diff --git a/src/test/java/cristophe2/Test.oj b/src/test/java/cristophe2/Test.oj
new file mode 100644
index 0000000..80ea445
--- /dev/null
+++ b/src/test/java/cristophe2/Test.oj
@@ -0,0 +1,21 @@
+pacakge cristophe2;
+
+public class Test instantiates MethodRemovingClass {
+ public void f() {
+ }
+
+ public String g(String s, int i) {
+ return null;
+ }
+
+}
+
+class Test2 instantiates MethodRemovingClass {
+ public String g(String s, int i) {
+ return null;
+ }
+
+ public void f() {
+ }
+
+}
diff --git a/src/test/java/dardia/InterImpl.oj b/src/test/java/dardia/InterImpl.oj
new file mode 100644
index 0000000..1a36255
--- /dev/null
+++ b/src/test/java/dardia/InterImpl.oj
@@ -0,0 +1,117 @@
+package dardia;
+
+import java.lang.reflect.Modifier;
+
+import io.devnulllabs.openjava.mop.CannotAlterException;
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.FileEnvironment;
+import io.devnulllabs.openjava.mop.MOPException;
+import io.devnulllabs.openjava.mop.Metaclass;
+import io.devnulllabs.openjava.mop.MetaInfo;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJConstructor;
+import io.devnulllabs.openjava.mop.OJField;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.mop.OJModifier;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.MemberDeclarationList;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.ParseTreeException;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+public class InterImpl instantiates Metaclass extends openjava.mop.OJClass {
+
+ public void translateDefinition() throws MOPException {
+ EditableClass newClass =
+ new EditableClass(makeCopy(getName() + "Impl"));
+ OJSystem.addNewClass(newClass);
+
+ beInterface();
+ removeFieldsAndConstructors();
+ turnMethodsEmpty();
+
+ newClass.addInterface(this);
+ }
+
+ private void beInterface() throws MOPException {
+ ClassDeclaration orgDecl = getSourceCode();
+ ModifierList modifs = new ModifierList(Modifier.PUBLIC);
+ String name = orgDecl.getName();
+ TypeName[] bases = new TypeName[0];
+ TypeName[] faces = new TypeName[0];
+ MemberDeclarationList classBody = orgDecl.getBody();
+ ClassDeclaration newDecl =
+ new ClassDeclaration(modifs, name, bases, faces, classBody, false);
+ try {
+ orgDecl.replace(newDecl);
+ } catch (ParseTreeException e) {
+ throw new MOPException(e.toString());
+ }
+ }
+
+ private void removeFieldsAndConstructors() throws MOPException {
+ OJField[] f = getDeclaredFields();
+ for (int i = 0; i < f.length; ++i) {
+ removeField(f[i]);
+ }
+ OJConstructor[] cons = getDeclaredConstructors();
+ for (int i = 0; i < cons.length; ++i) {
+ removeConstructor(cons[i]);
+ }
+ }
+
+ private void turnMethodsEmpty() throws MOPException {
+ OJMethod[] m = getDeclaredMethods();
+ for (int i = 0; i < m.length; ++i) {
+ OJModifier modif = m[i].getModifiers();
+ if (!modif.isPublic() || modif.isStatic()) {
+ removeMethod(m[i]);
+ }
+ m[i].setModifiers(OJModifier.forModifier(OJModifier.PUBLIC));
+ m[i].setBody(null);
+ }
+ }
+
+}
+
+class EditableClass extends OJClass {
+
+ public EditableClass(OJClass original)
+ throws CannotAlterException {
+ super(
+ new FileEnvironment(
+ OJSystem.env,
+ original.getPackage(),
+ original.getSimpleName()),
+ original.getDeclaringClass(),
+ original.getSourceCode());
+ }
+
+ public OJClass addClass(OJClass clazz)
+ throws CannotAlterException {
+ return super.addClass(clazz);
+ }
+
+ public OJConstructor addConstructor(
+ OJConstructor constr)
+ throws CannotAlterException {
+ return super.addConstructor(constr);
+ }
+
+ public OJField addField(OJField field)
+ throws CannotAlterException {
+ return super.addField(field);
+ }
+
+ public void addInterface(OJClass clazz)
+ throws CannotAlterException {
+ super.addInterface(clazz);
+ }
+
+ public OJMethod addMethod(OJMethod method)
+ throws CannotAlterException {
+ return super.addMethod(method);
+ }
+
+}
diff --git a/src/test/java/dardia/MIJava.oj b/src/test/java/dardia/MIJava.oj
new file mode 100644
index 0000000..574b11c
--- /dev/null
+++ b/src/test/java/dardia/MIJava.oj
@@ -0,0 +1,109 @@
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+import java.util.*;
+
+public class MIJava instantiates Metaclass extends OJClass {
+
+ // The below logic performs conflict resolution by not overwriting any methods already existing.
+ // This means that if in the TA multiextends Staff, Student example both Staff and Student have a field or
+ // a method with the same name, the field/method that is copied into TA's body is the one from the base
+ // class that occurs earlier in the argument list to multiextends.
+ public void translateDefinition() throws MOPException {
+ transformMultiextendingClass();
+ }
+
+ public void transformMultiextendingClass() throws MOPException {
+ ObjectList extendedClasses = (ObjectList)getSuffix("multiextends");
+
+ Collection existingSignatures = new Vector();
+ OJMethod[] currentMethods = getDeclaredMethods();
+ for (int i = 0; i < currentMethods.length; i++) {
+ existingSignatures.add((currentMethods[i].signature()).toString());
+ }
+
+ Collection existingFields = new Vector();
+ OJField[] currentFields = getDeclaredFields();
+ for (int i = 0; i < currentFields.length; i++) {
+ existingFields.add((currentFields[i].signature()).toString());
+ }
+
+ if (extendedClasses != null) {
+ for (int i = 0; i < extendedClasses.size(); i++) {
+ try {
+ OJClass currentExtendedClass = OJClass.forName((extendedClasses.get(i)).toString());
+
+ // open each class that we multiextended and copy its methods into a local variable
+ OJMethod[] currentExtendedClassMethods = currentExtendedClass.getDeclaredMethods();
+
+ // copy all of the methods for the current extended class into the output if they don't already exist
+ for (int j = 0; j < currentExtendedClassMethods.length; j++) {
+ if (!existingSignatures.contains((currentExtendedClassMethods[j].signature()).toString())) {
+ // if we don't currently have this method, add it
+ //addMethod(currentExtendedClassMethods[j]);
+
+ // Because the above addMethod() causes odd CannotAlterExceptions to be thrown, I do
+ // the below to describe what is happening in the multiextending class and where its
+ // methods come from.
+
+ StatementList statementsToInsert = new StatementList();
+ Statement cameFromStatement = makeStatement("System.out.println(\"this body would come from " + (extendedClasses.get(i)).toString() + "\\n\");");
+ statementsToInsert.add(cameFromStatement);
+
+
+ OJMethod methodToInsert = new OJMethod((OJClass)this,
+ currentExtendedClassMethods[j].getModifiers(),
+ currentExtendedClassMethods[j].getReturnType(),
+ currentExtendedClassMethods[j].getName(),
+ currentExtendedClassMethods[j].getParameterTypes(),
+ currentExtendedClassMethods[j].getExceptionTypes(),
+ statementsToInsert);
+
+ addMethod(methodToInsert);
+
+ // make note that we added a mehtod with some signature so we don't put multiple methods
+ // with the same signature into the class. this would be invalid Java code and unlogical.
+ existingSignatures.add((methodToInsert.signature()).toString());
+ } // else, a method with the same signature already exists, skip it
+ }
+
+
+ // open each class and copy its fields into local variable
+ OJField[] currentExtendedClassFields = currentExtendedClass.getDeclaredFields();
+
+ // copy all of the fields for the current extended class into the output if they don't already exist
+ for (int j = 0; j < currentExtendedClassFields.length; j++) {
+ if (!existingFields.contains((currentExtendedClassFields[j].signature()).toString())) {
+ // if we don't currently have this field, add it
+ addField(currentExtendedClassFields[j]);
+ existingFields.add((currentExtendedClassFields[j].signature()).toString());
+ }
+ }
+
+ } catch (OJClassNotFoundException e) {
+ System.err.println(e);
+ System.exit(-1);
+ }
+ }
+ }
+ }
+
+ // new class modifier: "multiextends".
+ public static boolean isRegisteredKeyword(String str) {
+ if (str.equals("multiextends")) {
+ return(true);
+ }
+
+ return OJClass.isRegisteredKeyword(str);
+ }
+
+ // overridden to let OpenJava know how multiextends arguments are separated.
+ public static SyntaxRule getDeclSuffixRule(String str) {
+ if (str.equals("multiextends")) {
+ return new DefaultListRule(new TypeNameRule(), TokenID.COMMA );
+ }
+
+ return null;
+ }
+}
diff --git a/src/test/java/dardia/MultiextendingClass.oj b/src/test/java/dardia/MultiextendingClass.oj
new file mode 100644
index 0000000..51bdccf
--- /dev/null
+++ b/src/test/java/dardia/MultiextendingClass.oj
@@ -0,0 +1,129 @@
+package dardia;
+
+import io.devnulllabs.openjava.mop.CannotAlterException;
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.MOPException;
+import io.devnulllabs.openjava.mop.Metaclass;
+import io.devnulllabs.openjava.mop.MetaInfo;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJConstructor;
+import io.devnulllabs.openjava.mop.OJField;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.mop.OJModifier;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.ObjectList;
+import io.devnulllabs.openjava.syntax.DefaultListRule;
+import io.devnulllabs.openjava.syntax.SyntaxRule;
+import io.devnulllabs.openjava.syntax.TokenID;
+import io.devnulllabs.openjava.syntax.TypeNameRule;
+
+public class InterImpl instantiates Metaclass extends OJClass {
+
+ public void translateDefinition() throws io.devnulllabs.openjava.mop.MOPException {
+ ObjectList extendedClasses =
+ (openjava.ptree.ObjectList) getSuffix("multiextends");
+ if (extendedClasses == null)
+ return;
+
+ EditableClass newClass =
+ new EditableClass(makeCopy(getName() + "Impl"));
+ for (int i = 0; i < extendedClasses.size(); ++i) {
+ OJClass extendedInterface =
+ OJClass.forName(extendedClasses.get(i).toString());
+ addImplementation(newClass, extendedInterface);
+ }
+
+ beInterface();
+ for (int i = 0; i < extendedClasses.size(); ++i) {
+ OJClass extendedInterface =
+ OJClass.forName(extendedClasses.get(i).toString());
+ addInterface(extendedInterface);
+ }
+
+ newClass.addInterface(this);
+ OJSystem.addNewClass(newClass);
+ }
+
+ public void addImplementation(
+ EditableClass newClass,
+ OJClass extendedInterface)
+ throws MOPException {
+ newClass.addInterface(extendedInterface);
+ OJClass extendedImpl =
+ OJClass.forName(extendedInterface.getName() + "Impl");
+ OJMethod[] methodImpls = extendedImpl.getDeclaredMethods();
+ for (int i = 0; i < methodImpls.length; ++i) {
+ newClass.addMethod(methodImpls[i]);
+ }
+ }
+
+ public void beInterface() throws MOPException {
+ getModifiers().add(OJModifier.INTERFACE);
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ methods[i].getModifiers().setAbstract();
+ methods[i].setBody(null);
+ }
+ }
+
+ public InterImpl(
+ Environment oj_param0,
+ OJClass oj_param1,
+ ClassDeclaration oj_param2) {
+ super(oj_param0, oj_param1, oj_param2);
+ }
+
+ public InterImpl(Class oj_param0, MetaInfo oj_param1) {
+ super(oj_param0, oj_param1);
+ }
+
+ // new class modifier: "multiextends".
+ public static boolean isRegisteredKeyword(String str) {
+ if (str.equals("multiextends")) {
+ return (true);
+ }
+ return OJClass.isRegisteredKeyword(str);
+ }
+
+ // overridden to let OpenJava know how multiextends arguments are
+ // separated.
+ public static SyntaxRule getDeclSuffixRule(String str) {
+ if (str.equals("multiextends")) {
+ return new DefaultListRule(new TypeNameRule(), TokenID.COMMA);
+ }
+ return OJClass.getDeclSuffixRule(str);
+ }
+}
+
+class EditableClass extends io.devnulllabs.openjava.mop.OJClass {
+ public EditableClass(OJClass original) throws CannotAlterException {
+ super(
+ original.getEnvironment(),
+ original.getDeclaringClass(),
+ original.getSourceCode());
+ }
+
+ public OJClass addClass(openjava.mop.OJClass clazz)
+ throws CannotAlterException {
+ return super.addClass(clazz);
+ }
+
+ public OJConstructor addConstructor(OJConstructor constr)
+ throws CannotAlterException {
+ return super.addConstructor(constr);
+ }
+
+ public OJField addField(OJField field) throws CannotAlterException {
+ return super.addField(field);
+ }
+
+ public void addInterface(OJClass clazz) throws CannotAlterException {
+ super.addInterface(clazz);
+ }
+
+ public OJMethod addMethod(OJMethod method) throws CannotAlterException {
+ return super.addMethod(method);
+ }
+
+}
diff --git a/src/test/java/dardia/Person.oj b/src/test/java/dardia/Person.oj
new file mode 100644
index 0000000..0f43577
--- /dev/null
+++ b/src/test/java/dardia/Person.oj
@@ -0,0 +1,17 @@
+/*
+ * Person.java
+ *
+ * Created on 2003/11/02
+ * $Id$
+ */
+package dardia;
+
+/**
+ * The type Person.
+ * @author Michiaki Tatsubori
+ * @version 1.0 2003/11/02
+ */
+public class Person instantiates InterImpl {
+ public String getName() {
+ }
+}
diff --git a/src/test/java/dardia/Student.oj b/src/test/java/dardia/Student.oj
new file mode 100644
index 0000000..2a4e07d
--- /dev/null
+++ b/src/test/java/dardia/Student.oj
@@ -0,0 +1,19 @@
+package dardia;
+
+public class Student instantiates InterImpl {
+ public Double GPA;
+
+ public Double getGPA() {
+ System.out.println("Student's getGPA() invoked!");
+ return GPA;
+ }
+
+ public void setGPA(Double _GPA) {
+ System.out.println("Student's setGPA() invoked!");
+ GPA = _GPA;
+ }
+
+ public String toString() {
+ return "Student's toString (GPA=" + GPA.toString() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/test/java/dardia/TA.oj b/src/test/java/dardia/TA.oj
new file mode 100644
index 0000000..ce0ccb2
--- /dev/null
+++ b/src/test/java/dardia/TA.oj
@@ -0,0 +1,16 @@
+/********************************************************
+| Art Dardia <dardia@rpi.edu> [10-27-2003]
+|
+| CSCI-4430 Programming Languages
+| Carlos Varela
+| Mon.,Thurs. @ 12-1:50pm
+|
+| filename: TA.oj
+| descrip.:
+********************************************************/
+
+// no imports
+
+public class TA instantiates MIJava multiextends Student, Staff {
+
+} \ No newline at end of file
diff --git a/src/test/java/demobug/Bug1.java b/src/test/java/demobug/Bug1.java
new file mode 100644
index 0000000..dca6c4a
--- /dev/null
+++ b/src/test/java/demobug/Bug1.java
@@ -0,0 +1,8 @@
+package demobug;
+
+public class Bug1 {
+ int a;
+ public static final class Bug2 {
+ static int bug = 12;
+ };
+};
diff --git a/src/test/java/demobug/DemoBug1.java b/src/test/java/demobug/DemoBug1.java
new file mode 100644
index 0000000..f0b10f2
--- /dev/null
+++ b/src/test/java/demobug/DemoBug1.java
@@ -0,0 +1,58 @@
+package demobug;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.MOPException;
+import io.devnulllabs.openjava.mop.MetaInfo;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.mop.OJModifier;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.StatementList;
+
+public class DemoBug1 extends OJClass {
+
+ public void translateDefinition() throws MOPException {
+
+ // Must load some classes
+ String[] toFind = new String[] { "Bug1", "Bug1$Bug2", "Bug1.Bug2" };
+ for (int i = 0; i < toFind.length; ++i) {
+ try {
+ forName("examples.test." + toFind[i]);
+ } catch (io.devnulllabs.openjava.mop.OJClassNotFoundException ex) {
+ System.err.println(toFind[i] + " not found !");
+ }
+ }
+ String body =
+ "{\n"
+ + "\t int i=Bug1.Bug2.bug;"
+ + "\t Integer I=new Integer(i);\n"
+ + "\t System.out.println(\"Here's the famous value : \"+I);\n"
+ + "}\n";
+
+ OJMethod buggy =
+ new OJMethod(
+ this,
+ OJModifier.forModifier(OJModifier.PUBLIC),
+ OJSystem.VOID,
+ "Buggy",
+ new OJClass[] {
+ }, null, null);
+ StatementList StBody =
+ new StatementList(makeStatement(buggy.getEnvironment(), body));
+ buggy.setBody(StBody);
+ addMethod(buggy);
+
+ }
+
+ public DemoBug1(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public DemoBug1(Class javaclass, MetaInfo minfo) {
+ super(javaclass, minfo);
+ }
+};
diff --git a/src/test/java/demobug/DemoBug1Test.oj b/src/test/java/demobug/DemoBug1Test.oj
new file mode 100644
index 0000000..992e48f
--- /dev/null
+++ b/src/test/java/demobug/DemoBug1Test.oj
@@ -0,0 +1,5 @@
+package demobug;
+
+public class DemoBug1Test instantiates DemoBug1 {
+ int a;
+};
diff --git a/src/test/java/demobug/DemoBug2.java b/src/test/java/demobug/DemoBug2.java
new file mode 100644
index 0000000..aa5058e
--- /dev/null
+++ b/src/test/java/demobug/DemoBug2.java
@@ -0,0 +1,47 @@
+package demobug;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.MOPException;
+import io.devnulllabs.openjava.mop.MetaInfo;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.mop.OJModifier;
+import io.devnulllabs.openjava.mop.OJSystem;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.StatementList;
+
+public class DemoBug2 extends OJClass {
+
+ public void translateDefinition() throws MOPException {
+
+ String body =
+ "{\n"
+ + "\t String Michi=\"My name is Tatsubori ... Michi Tatsubori\";\n"
+ + "\t System.out.println(\"Here's the famous sentence from 009 : \"+Michi);\n"
+ + "}\n";
+
+ OJMethod buggy =
+ new OJMethod(
+ this,
+ OJModifier.forModifier(OJModifier.PUBLIC),
+ OJSystem.VOID,
+ "Buggy",
+ new OJClass[] {
+ }, null, null);
+ StatementList StBody =
+ new StatementList(makeStatement(buggy.getEnvironment(), body));
+ buggy.setBody(StBody);
+ addMethod(buggy);
+ }
+
+ public DemoBug2(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public DemoBug2(Class javaclass, MetaInfo minfo) {
+ super(javaclass, minfo);
+ }
+}
diff --git a/src/test/java/demobug/DemoBug2Test.oj b/src/test/java/demobug/DemoBug2Test.oj
new file mode 100644
index 0000000..fe6de4c
--- /dev/null
+++ b/src/test/java/demobug/DemoBug2Test.oj
@@ -0,0 +1,5 @@
+package demobug;
+
+public class DemoBug2Test instantiates DemoBug2 {
+ int a;
+}
diff --git a/src/test/java/demobug/InnerTest.oj b/src/test/java/demobug/InnerTest.oj
new file mode 100644
index 0000000..e3f5ed3
--- /dev/null
+++ b/src/test/java/demobug/InnerTest.oj
@@ -0,0 +1,29 @@
+/*
+ * InterTest.java
+ *
+ * May 4, 1999 by Michiaki Tatsubori
+ */
+package demobug;
+
+import java.lang.System;
+
+public class InnerTest {
+ public JJCalls jj;
+
+ public static void main(String[] argv) {
+ /*
+ System.out.println( JJCalls.gen );
+ JJCalls dummy = new JJCalls();
+ JJCalls[] test = new JJCalls[53];
+ */
+ JJCalls hoge = InnerTest.JJCalls.next;
+
+ //InnerTest u = new InnerTest();
+ //hoge = u.JJCalls.next;
+ }
+
+ static final class JJCalls {
+ static int gen = 0;
+ static JJCalls next;
+ }
+}
diff --git a/src/test/java/demobug/InnerTest2.oj b/src/test/java/demobug/InnerTest2.oj
new file mode 100644
index 0000000..2fb2916
--- /dev/null
+++ b/src/test/java/demobug/InnerTest2.oj
@@ -0,0 +1,16 @@
+/*
+ * InterTest.java
+ *
+ * May 4, 1999 by Michiaki Tatsubori
+ */
+package demobug;
+
+public class InnerTest2 {
+ public static void main(String[] argv) {
+ Runnable r = new Runnable() {
+ public void run() {
+ }
+ };
+ String s = new String("");
+ }
+}
diff --git a/src/test/java/demobug/MetaTest.oj b/src/test/java/demobug/MetaTest.oj
new file mode 100644
index 0000000..acbefdb
--- /dev/null
+++ b/src/test/java/demobug/MetaTest.oj
@@ -0,0 +1,78 @@
+/*
+ * MetaTest.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package demobug;
+
+import java.lang.Object;
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.syntax.*;
+
+/**
+ * The class <code>MetaTest</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class MetaTest extends OJClass {
+ public MetaTest(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public ClassDeclaration translateDefinition(
+ Environment env,
+ ClassDeclaration decl) {
+ OJMethod[] m = getAllMethods();
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println(m[i].toString());
+ }
+ return decl;
+ }
+
+ public static boolean isRegisteredKeyword(String keyword) {
+ if (keyword.equals("likes"))
+ return true;
+ if (keyword.equals("hates"))
+ return true;
+ if (keyword.equals("loves"))
+ return true;
+ if (keyword.equals("forwards"))
+ return true;
+ return false;
+ }
+
+ public static SyntaxRule getDeclSuffixRule(String keyword) {
+ return new NameListRule();
+ }
+
+ public static SyntaxRule getTypeSuffixRule(String keyword) {
+ return new NameListRule();
+ }
+
+ public static boolean isRegisteredModifier(String keyword) {
+ if (keyword.equals("remote"))
+ return true;
+ if (keyword.equals("crazy"))
+ return true;
+ return false;
+ }
+
+}
diff --git a/src/test/java/demobug/Mix.oj b/src/test/java/demobug/Mix.oj
new file mode 100644
index 0000000..54a92a3
--- /dev/null
+++ b/src/test/java/demobug/Mix.oj
@@ -0,0 +1,47 @@
+package demobug;
+
+import java.awt.*;
+import examples.capsule.Point;
+import examples.capsule.Test;
+import examples.multimethod.MultimethodClass;
+
+public class Mix instantiates MultimethodClass extends Point {
+
+ Point test;
+
+ private Mix() {
+ super("Mix's", 0, 0);
+ this.test = new Point("Mix's", 0, 0);
+ }
+
+ public String toString() {
+ System.out.println(test.name.toString());
+ System.out.println("(" + test.x + "," + test.y + ")");
+ return super.toString();
+ }
+
+ public multiform String bar(Panel a, Button b) {
+ return "panel";
+ }
+
+ public multiform String bar(Button a, Button b) {
+ return "button";
+ }
+
+ public multiform String bar(Canvas a, Panel b) {
+ return "canvas";
+ }
+
+ public static void main(String[] argv) {
+ Point p = new Mix();
+ }
+
+ public multiform void bar(Panel a, Window b) {
+ System.out.println("panel");
+ String s = ((String) Test.NAME).toString();
+ String sa = Test.NAME + "_ALPHA";
+ String ss = (Test.NAME).toString();
+ return;
+ }
+
+}
diff --git a/src/test/java/demobug/Normal.oj b/src/test/java/demobug/Normal.oj
new file mode 100644
index 0000000..cece63a
--- /dev/null
+++ b/src/test/java/demobug/Normal.oj
@@ -0,0 +1,96 @@
+/*
+ * Normal.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package demobug;
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+/**
+ * The class <code>Normal</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class Normal extends Panel {
+ private int iii = 0;
+
+ private Normal n = null;
+
+ private String str;
+
+ protected Normal(String str) {
+ super();
+ this.str = str;
+ n = null;
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main(String[] argv) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println("Hello" + " " + "World");
+ Normal n = new Normal(null);
+ java.lang.System.err.println("done");
+
+ for (int index = 0; index < argv.length; ++index) {
+ System.out.println(index);
+ }
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println(l.foo);
+ System.out.println(l.bar.str);
+ }
+
+ public int foo() {
+ int[] ia = { 0, 0x0, 0x82094000 };
+ return JJCalls.gen;
+ }
+
+ public String toString() {
+ if (n == null)
+ return str;
+ return str + n;
+ }
+
+ static final class JJCalls {
+ static int gen = 0;
+ JJCalls next;
+ }
+}
+
+class Local {
+ Local() {
+ }
+ String foo = null;
+ Local2 bar = new Local2();
+}
+
+class Local2 {
+ Local2() {
+ }
+ String str = "" + "TEST";
+}
diff --git a/src/test/java/demobug/Simple.oj b/src/test/java/demobug/Simple.oj
new file mode 100644
index 0000000..199ae48
--- /dev/null
+++ b/src/test/java/demobug/Simple.oj
@@ -0,0 +1,90 @@
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package demobug;
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+/**
+ * The class <code>Simple</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class Simple instantiates MetaTest likes Apple, Macintosh hates Windows
+ extends Panel {
+ private int iii = 0;
+ ;
+ ;
+
+ private Simple n = null;
+
+ private String str = "string";
+
+ public Simple() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main(String[] argv) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println("Hello" + " " + "World");
+ Simple n = new Simple();
+ java.lang.System.err.println("done");
+ }
+
+ public void hoge() {
+ SLocal l = new SLocal();
+ System.out.println(l.foo);
+ System.out.println(l.bar.str);
+ }
+
+ public Simple(String str) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null)
+ return str;
+ return str + n;
+ };
+ ;
+
+}
+
+class SLocal {
+ String foo = null;
+ SLocal2 bar = new SLocal2();
+}
+
+class SLocal2 {
+ String str = "" + "TEST";
+}
diff --git a/src/test/java/desell/MIJava.oj b/src/test/java/desell/MIJava.oj
new file mode 100644
index 0000000..81498d2
--- /dev/null
+++ b/src/test/java/desell/MIJava.oj
@@ -0,0 +1,7 @@
+package desell;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+public class MIJava instantiates Metaclass extends OJClass {
+}
diff --git a/src/test/java/desell/TrivialSuperClass.oj b/src/test/java/desell/TrivialSuperClass.oj
new file mode 100644
index 0000000..d408101
--- /dev/null
+++ b/src/test/java/desell/TrivialSuperClass.oj
@@ -0,0 +1,7 @@
+package desell;
+
+public class TrivialSuperClass instantiates MIJava {
+ public void hello_world() {
+ System.out.println("Hello, World!");
+ }
+} \ No newline at end of file
diff --git a/src/test/java/fabio/Hello.oj b/src/test/java/fabio/Hello.oj
new file mode 100644
index 0000000..518faf4
--- /dev/null
+++ b/src/test/java/fabio/Hello.oj
@@ -0,0 +1,12 @@
+package fabio;
+
+public class Hello instantiates VerboseClass
+{
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/src/test/java/fabio/HelloWithError.oj b/src/test/java/fabio/HelloWithError.oj
new file mode 100644
index 0000000..350be40
--- /dev/null
+++ b/src/test/java/fabio/HelloWithError.oj
@@ -0,0 +1,12 @@
+package fabio;
+
+public class Hello instantiates VerboseClazz /* typo */
+{
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/src/test/java/fabio/VerboseClass.oj b/src/test/java/fabio/VerboseClass.oj
new file mode 100644
index 0000000..a361896
--- /dev/null
+++ b/src/test/java/fabio/VerboseClass.oj
@@ -0,0 +1,21 @@
+package fabio;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+public class VerboseClass instantiates Metaclass extends OJClass {
+ /* overrides for translation */
+ //public void translateDefinition() throws MOPException {
+ public void translatioDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Statement printer =
+ makeStatement(
+ "System.out.println( \""
+ + methods[i].toString()
+ + " is called.\" );");
+ methods[i].getBody().insertElementAt(printer, 0);
+ }
+ }
+}
diff --git a/src/test/java/inner/BIND b/src/test/java/inner/BIND
new file mode 100644
index 0000000..07180c5
--- /dev/null
+++ b/src/test/java/inner/BIND
@@ -0,0 +1,3 @@
+inner.VerboseClass inner.ImageMap.Timer
+inner.VerboseClass inner.ImageMap$Tool
+inner.VerboseClass inner.ImageMap
diff --git a/src/test/java/inner/ImageMap.oj b/src/test/java/inner/ImageMap.oj
new file mode 100644
index 0000000..50334c2
--- /dev/null
+++ b/src/test/java/inner/ImageMap.oj
@@ -0,0 +1,80 @@
+package inner;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import javax.swing.*;
+import javax.swing.event.*;
+//import java.util.*;
+
+public class ImageMap extends JPanel {
+
+ Timer polyTimer;
+ Tool tool;
+
+ public ImageMap(Image image, String imagePath) {
+ tool = new Tool(this);
+ addMouseListener(tool);
+ addMouseMotionListener(tool);
+ polyTimer = new Timer(this);
+ polyTimer.start();
+ repaint();
+ }
+
+ public void paint(Graphics g) {
+ }
+
+ class Tool extends MouseAdapter implements MouseMotionListener {
+ ImageMap map;
+
+ Color color = Color.blue;
+
+ public Tool(ImageMap map) {
+ this.map = map;
+ }
+
+ public void showPolyPopup() {
+ }
+
+ public void mousePressed(MouseEvent e) {
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ repaint();
+ }
+ }
+
+ class Timer extends Thread {
+ ImageMap map;
+ boolean active = false;
+ String command;
+ int x,y,node;
+ MouseEvent e;
+
+ public Timer(ImageMap map) {
+ this.map = map;
+ }
+
+ public void run() {
+ while (true) {
+ try {
+ sleep(900);
+ if (this.command=="poly") {
+ map.tool.showPolyPopup();
+ }
+ }
+ catch (InterruptedException e) { }
+ suspend();
+ }
+ }
+ }
+
+}
+
+
+
+
+
diff --git a/src/test/java/inner/VerboseClass.oj b/src/test/java/inner/VerboseClass.oj
new file mode 100644
index 0000000..3cfe7a8
--- /dev/null
+++ b/src/test/java/inner/VerboseClass.oj
@@ -0,0 +1,49 @@
+/*
+ * VerboseClass.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package inner;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+public class VerboseClass instantiates Metaclass extends OJClass {
+
+ public VerboseClass(
+ Environment env,
+ openjava.mop.OJClass declaring,
+ ClassDeclaration cd) {
+ super(env, declaring, cd);
+ System.out.println(
+ "A class metaobject for "
+ + cd.getName()
+ + " created from source code.");
+ }
+
+ public VerboseClass(Class javaclazz, MetaInfo minfo) {
+ super(javaclazz, minfo);
+ System.out.println(
+ "A class metaobject for "
+ + javaclazz.getName()
+ + " created from byte code.");
+ }
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Statement printer =
+ makeStatement(
+ "java.lang.System.out.println( \""
+ + methods[i].toString()
+ + " was called\" );");
+ methods[i].getBody().insertElementAt(printer, 0);
+ }
+ }
+}
diff --git a/src/test/java/jarrett/NonPub.oj b/src/test/java/jarrett/NonPub.oj
new file mode 100644
index 0000000..b8b80ba
--- /dev/null
+++ b/src/test/java/jarrett/NonPub.oj
@@ -0,0 +1,19 @@
+/*
+ * This code was generated by ojc.
+ */
+package jarrett;
+
+
+class NonPub1
+{
+}
+
+
+class NonPub2
+{
+}
+
+
+class NonPub3
+{
+}
diff --git a/src/test/java/lionel/Hello.oj b/src/test/java/lionel/Hello.oj
new file mode 100644
index 0000000..48fa88a
--- /dev/null
+++ b/src/test/java/lionel/Hello.oj
@@ -0,0 +1,11 @@
+package lionel;
+
+public class Hello {
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/src/test/java/lionel/Hello2.oj b/src/test/java/lionel/Hello2.oj
new file mode 100644
index 0000000..7c2718d
--- /dev/null
+++ b/src/test/java/lionel/Hello2.oj
@@ -0,0 +1,11 @@
+package lionel;
+
+public class Hello2 {
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/src/test/java/lionel/Hello3.oj b/src/test/java/lionel/Hello3.oj
new file mode 100644
index 0000000..c5fd6ce
--- /dev/null
+++ b/src/test/java/lionel/Hello3.oj
@@ -0,0 +1,11 @@
+package lionel;
+
+public class Hello3 {
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/src/test/java/lionel/metabind b/src/test/java/lionel/metabind
new file mode 100644
index 0000000..621ff16
--- /dev/null
+++ b/src/test/java/lionel/metabind
@@ -0,0 +1,2 @@
+examples.verbose.VerboseClass lionel.Hello
+examples.verbose.VerboseClass lionel.Hello3
diff --git a/src/test/java/lionel2/NonPubTest.oj b/src/test/java/lionel2/NonPubTest.oj
new file mode 100644
index 0000000..727bd3b
--- /dev/null
+++ b/src/test/java/lionel2/NonPubTest.oj
@@ -0,0 +1,36 @@
+package lionel2;
+
+public class NonPubTest instantiates Printer
+{
+ NonPubTest(String s) {}
+
+ public String toString() {
+ NonPubTest t = new NonPubTest("at NonPubTest");
+ A a = new A("at NonPubTest");
+ B b = new B("at NonPubTest");
+ return super.toString();
+ }
+}
+
+
+class A instantiates Printer
+{
+ A(String s) {}
+
+ public void foo() {
+ NonPubTest t = new NonPubTest("at A");
+ A a = new A("at A");
+ B b = new B("at A");
+ }
+}
+
+class B instantiates Printer
+{
+ B(String s) {}
+
+ public void bar() {
+ NonPubTest t = new NonPubTest("at B");
+ A a = new A("at B");
+ B b = new B("at B");
+ }
+}
diff --git a/src/test/java/lionel2/Printer.oj b/src/test/java/lionel2/Printer.oj
new file mode 100644
index 0000000..b196798
--- /dev/null
+++ b/src/test/java/lionel2/Printer.oj
@@ -0,0 +1,18 @@
+package lionel2;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+
+public class Printer instantiates Metaclass extends OJClass {
+ public void translateDefinition() throws MOPException {
+ System.out.println("translateDefinition() of " + getName());
+ }
+
+ public Expression expandAllocation(
+ Environment env,
+ AllocationExpression expr) {
+ System.out.println(
+ "expandAllocation() of " + getName() + " for " + expr.toString());
+ return expr;
+ }
+}
diff --git a/src/test/java/lionel2/SimpleConst.oj b/src/test/java/lionel2/SimpleConst.oj
new file mode 100644
index 0000000..7641a6e
--- /dev/null
+++ b/src/test/java/lionel2/SimpleConst.oj
@@ -0,0 +1,6 @@
+package lionel2;
+
+public class SimpleConst {
+ public SimpleConst() {
+ }
+}
diff --git a/src/test/java/luciano/AutoConstructorClass.oj b/src/test/java/luciano/AutoConstructorClass.oj
new file mode 100644
index 0000000..65f04ad
--- /dev/null
+++ b/src/test/java/luciano/AutoConstructorClass.oj
@@ -0,0 +1,71 @@
+import luciano;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+import io.devnulllabs.openjava.ptree.util.VariableBinder;
+
+/**
+ * This metaclass appends a constructor of a String parameter.
+ * It makes no sense but shows an example of adding a special
+ * statement of calling super constructor.
+ */
+public class AutoConstructorClass instantiates Metaclass extends OJClass {
+ public convenient void translateDefinition() throws MOPException {
+ System.out.println("translateDefinition() of " + getName());
+ if (doesClassHaveStringCons())
+ return;
+ if (!doesSuperHaveDefaultCons())
+ return;
+
+ OJConstructor con =
+ new OJConstructor(
+ this,
+ OJModifier.forModifier(OJModifier.PUBLIC),
+ new OJClass[] { String.class },
+ new OJClass[0],
+ null,
+ null /* temporally */
+ );
+
+ ExpressionList conargs = con.getParameterVariables();
+ Expression conarg = conargs.get(0);
+
+ /* "super()" */
+ ConstructorInvocation ci =
+ new ConstructorInvocation(new ExpressionList(), null);
+
+ /* other part of constructors' body */
+ StatementList body =
+ makeStatementList(
+ con.getEnvironment(),
+ "/* test */" + "java.lang.System.out.println(" + conarg + ");");
+
+ con.setTransference(ci);
+ con.setBody(body);
+
+ addConstructor(con);
+ }
+
+ private convenient boolean doesClassHaveStringCons() {
+ try {
+ this.getConstructor(new OJClass[] { String.class }, this);
+ return true;
+ } catch (NoSuchMemberException ex) {
+ return false;
+ }
+ }
+
+ private boolean doesSuperHaveDefaultCons() {
+ OJClass baseclazz = this.getSuperclass();
+ if (baseclazz == null)
+ return false;
+ try {
+ baseclazz.getConstructor(new OJClass[0], this);
+ return true;
+ } catch (NoSuchMemberException ex) {
+ return false;
+ }
+ }
+
+}
diff --git a/src/test/java/luciano/Test.oj b/src/test/java/luciano/Test.oj
new file mode 100644
index 0000000..3f624e0
--- /dev/null
+++ b/src/test/java/luciano/Test.oj
@@ -0,0 +1,4 @@
+import luciano;
+
+public class Test instantiates AutoConstructorClass {
+}
diff --git a/src/test/java/maurizio/Test.oj b/src/test/java/maurizio/Test.oj
new file mode 100644
index 0000000..829cd18
--- /dev/null
+++ b/src/test/java/maurizio/Test.oj
@@ -0,0 +1,7 @@
+import maurizio;
+
+public class Test instantiates TestClass {
+ public String toString() {
+ return super.toString();
+ }
+}
diff --git a/src/test/java/maurizio/TestClass.oj b/src/test/java/maurizio/TestClass.oj
new file mode 100644
index 0000000..60c8ffa
--- /dev/null
+++ b/src/test/java/maurizio/TestClass.oj
@@ -0,0 +1,15 @@
+import maurizio;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+import io.devnulllabs.openjava.ptree.util.VariableBinder;
+
+public class TestClass instantiates Metaclass extends OJClass {
+ public TypeName expandTypeName(Environment env, TypeName type) {
+ System.out.println("I'm into expandTypeName");
+ TypeName result = new TypeName("java.lang.String", 0);
+ return super.expandTypeName(env, result);
+ }
+
+}
diff --git a/src/test/java/maurizio/TestUser.oj b/src/test/java/maurizio/TestUser.oj
new file mode 100644
index 0000000..9ad64af
--- /dev/null
+++ b/src/test/java/maurizio/TestUser.oj
@@ -0,0 +1,11 @@
+import maurizio;
+
+public class TestUser {
+ public static void main(String[] args) {
+ Test t = new Test();
+ Object o = t;
+ Test t2 = (Test) o;
+ System.out.println(Test.class);
+ System.out.println(t);
+ }
+}
diff --git a/src/test/java/maurizio2/Test.oj b/src/test/java/maurizio2/Test.oj
new file mode 100644
index 0000000..9c9c071
--- /dev/null
+++ b/src/test/java/maurizio2/Test.oj
@@ -0,0 +1,12 @@
+import maurizio2;
+
+public class Test instantiates TestClass {
+ public void foo(short a1, int a2) {
+ }
+
+ public void foo(int[] a1, short[] a2) {
+ }
+
+ public void foo(short[] a1, int[] a2) {
+ }
+}
diff --git a/src/test/java/maurizio2/TestClass.oj b/src/test/java/maurizio2/TestClass.oj
new file mode 100644
index 0000000..e15ce86
--- /dev/null
+++ b/src/test/java/maurizio2/TestClass.oj
@@ -0,0 +1,23 @@
+import maurizio2;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+import io.devnulllabs.openjava.ptree.util.VariableBinder;
+
+public class TestClass instantiates Metaclass extends OJClass {
+ public Expression expandMethodCall(Environment env, MethodCall expr) {
+ System.out.println("Argument Types of : " + expr.toString());
+ ExpressionList args = expr.getArguments();
+ OJClass[] argtypes = new OJClass[args.size()];
+ try {
+ for (int i = 0; i < argtypes.length; ++i) {
+ argtypes[i] = args.get(i).getType(env);
+ System.out.println("\t" + argtypes[i]);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return super.expandMethodCall(env, expr);
+ }
+}
diff --git a/src/test/java/maurizio2/TestUser.oj b/src/test/java/maurizio2/TestUser.oj
new file mode 100644
index 0000000..830569a
--- /dev/null
+++ b/src/test/java/maurizio2/TestUser.oj
@@ -0,0 +1,14 @@
+import maurizio2;
+
+public class TestUser {
+ static short s = 0;
+ static short as[] = null;
+ static int o = 0;
+ static int os[] = null;
+
+ public static void main(String[] args) {
+ Test t = new Test();
+ t.foo(s, o);
+ t.foo(as, os);
+ }
+}
diff --git a/src/test/java/mazza/Test.oj b/src/test/java/mazza/Test.oj
new file mode 100644
index 0000000..520e129
--- /dev/null
+++ b/src/test/java/mazza/Test.oj
@@ -0,0 +1,6 @@
+import mazza;
+
+public class Test instantiates TestClass {
+ public void foo() {
+ }
+}
diff --git a/src/test/java/mazza/TestClass.oj b/src/test/java/mazza/TestClass.oj
new file mode 100644
index 0000000..2f4b23a
--- /dev/null
+++ b/src/test/java/mazza/TestClass.oj
@@ -0,0 +1,19 @@
+import mazza;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+
+public class TestClass instantiates Metaclass extends OJClass {
+ public void translateDefinition() throws MOPException {
+ OJClass dummy = OJClass.forClass(String.class);
+ OJSystem.env.record("NonExisting", dummy);
+
+ FieldDeclaration fd =
+ new FieldDeclaration(
+ new ModifierList(ModifierList.PUBLIC),
+ new TypeName("NonExisting"),
+ new VariableDeclarator("sender", null));
+ OJField field = new OJField(getEnvironment(), this, fd);
+ addField(field);
+ }
+}
diff --git a/src/test/java/metatest/Meta2.java b/src/test/java/metatest/Meta2.java
new file mode 100644
index 0000000..e584e61
--- /dev/null
+++ b/src/test/java/metatest/Meta2.java
@@ -0,0 +1,38 @@
+/*
+ * Meta2.java
+ * Michiaki Tatsubori
+ *
+ */
+package metatest;
+
+
+/**
+ * This code is
+ */
+public class Meta2
+{
+
+ static String[] userModifiers
+ = {};
+ static String[] userKeywords
+ = { "from", "to" };
+
+ public static boolean isRegisteredModifier( String name )
+ {
+ if(name == null || userModifiers == null) return false;
+ for( int i = 0; i < userModifiers.length; i++ ){
+ if(name.equals( userModifiers[i] )) return true;
+ }
+ return false;
+ }
+
+ public static boolean isRegisteredKeyword( String name )
+ {
+ if(name == null || userKeywords == null) return false;
+ for( int i = 0; i < userKeywords.length; i++ ){
+ if(name.equals( userKeywords[i] )) return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/test/java/metatest/TestMetaclass.java b/src/test/java/metatest/TestMetaclass.java
new file mode 100644
index 0000000..8ef3d54
--- /dev/null
+++ b/src/test/java/metatest/TestMetaclass.java
@@ -0,0 +1,37 @@
+/*
+ * TestMetaclass.java
+ * Michiaki Tatsubori
+ *
+ */
+package metatest;
+
+/**
+ * This code is
+ */
+public class TestMetaclass {
+
+ static String[] userModifiers =
+ { "changable", "persistant", "distributed", "nop" };
+ static String[] userKeywords = { "on", "of", "with" };
+
+ public static boolean isRegisteredModifier(String name) {
+ if (name == null || userModifiers == null)
+ return false;
+ for (int i = 0; i < userModifiers.length; i++) {
+ if (name.equals(userModifiers[i]))
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isRegisteredKeyword(String name) {
+ if (name == null || userKeywords == null)
+ return false;
+ for (int i = 0; i < userKeywords.length; i++) {
+ if (name.equals(userKeywords[i]))
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/test/java/nopub/Pub.oj b/src/test/java/nopub/Pub.oj
new file mode 100644
index 0000000..43b20ed
--- /dev/null
+++ b/src/test/java/nopub/Pub.oj
@@ -0,0 +1,7 @@
+import nopub;
+
+public class Pub {
+}
+
+class B {
+}
diff --git a/src/test/java/nopub/Test.oj b/src/test/java/nopub/Test.oj
new file mode 100644
index 0000000..3c54e46
--- /dev/null
+++ b/src/test/java/nopub/Test.oj
@@ -0,0 +1,7 @@
+import nopub;
+
+class Test {
+}
+
+class A {
+}
diff --git a/src/test/java/openjava/mop/OJSystemTest.java b/src/test/java/openjava/mop/OJSystemTest.java
new file mode 100644
index 0000000..3cdf610
--- /dev/null
+++ b/src/test/java/openjava/mop/OJSystemTest.java
@@ -0,0 +1,60 @@
+/*
+ * OJSystemTest.java
+ *
+ * Created on 2003/11/02 $Id: OJSystemTest.java,v 1.2 2003/11/14 13:52:02 tatsubori Exp $
+ */
+package io.devnulllabs.openjava.mop;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+import io.devnulllabs.openjava.mop.edit.OJEditableClass;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.StatementList;
+
+/**
+ * The type OJSystemTest.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0 2003/11/02
+ */
+public class OJSystemTest extends TestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(OJSystemTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ OJSystem.initConstants();
+ }
+
+ class TestFileEnvironment extends FileEnvironment {
+ public TestFileEnvironment(Environment env) {
+ super(env);
+ }
+ public String getPackage() {
+ return "test";
+ }
+ public File getFile() {
+ return new File("test", "A.oj");
+ }
+ public String currentClassName() {
+ return "A";
+ }
+ }
+
+ public void testAddNewClasses() throws MOPException {
+ FileEnvironment fenv = new TestFileEnvironment(OJSystem.env);
+ StatementList stmts =
+ OJClass.makeStatementList(OJSystem.env, "class A { }");
+ ClassDeclaration cdecl = (ClassDeclaration) stmts.get(0);
+
+ OJEditableClass newClass =
+ new OJEditableClass(new OJClass(OJSystem.env, null, cdecl));
+ OJSystem.addNewClass(newClass);
+ }
+
+}
diff --git a/src/test/java/openjava/ptree/ClassDeclarationTest.java b/src/test/java/openjava/ptree/ClassDeclarationTest.java
new file mode 100644
index 0000000..b0a8b1d
--- /dev/null
+++ b/src/test/java/openjava/ptree/ClassDeclarationTest.java
@@ -0,0 +1,27 @@
+/*
+ * ClassDeclarationTest.java
+ * Created on 2005/04/04 by Michiaki Tatsubori
+ * @version $Id$
+ */
+package io.devnulllabs.openjava.ptree;
+
+import junit.framework.TestCase;
+
+/**
+ * ClassDeclarationTest
+ * @author mich
+ */
+public class ClassDeclarationTest extends TestCase {
+
+ public void testBeInterface() {
+ ModifierList modifs = new ModifierList(ModifierList.PUBLIC);
+ MemberDeclarationList members = new MemberDeclarationList();
+ ClassDeclaration cd = new ClassDeclaration(modifs, "Dummy", null, null, members);
+ assertFalse(cd.isInterface());
+ System.out.println(cd.toString());
+ cd.beInterface(true);
+ assertTrue(cd.isInterface());
+ System.out.println(cd.toString());
+ }
+
+}
diff --git a/src/test/java/openjava/ptree/ModifierListTest.java b/src/test/java/openjava/ptree/ModifierListTest.java
new file mode 100644
index 0000000..77458db
--- /dev/null
+++ b/src/test/java/openjava/ptree/ModifierListTest.java
@@ -0,0 +1,30 @@
+/*
+ * ModifierListTest.java
+ * Created on 2005/04/04 by Michiaki Tatsubori
+ * @version $Id$
+ */
+package io.devnulllabs.openjava.ptree;
+
+import junit.framework.TestCase;
+
+/**
+ * ModifierListTest
+ * @author mich
+ */
+public class ModifierListTest extends TestCase {
+
+ /*
+ * Class under test for void ModifierList()
+ */
+ public void testModifierList() {
+ ModifierList modifs = new ModifierList();
+ assertEquals(0, modifs.size());
+ modifs.add(ModifierList.PUBLIC);
+ assertEquals("public", modifs.toString());
+ // standard modifiers do not affect the size of the list
+ assertEquals(0, modifs.size());
+ assertTrue(modifs.contains(ModifierList.PUBLIC));
+ assertTrue(modifs.contains("public"));
+ }
+
+}
diff --git a/src/test/java/packfld/Test.java b/src/test/java/packfld/Test.java
new file mode 100644
index 0000000..8613686
--- /dev/null
+++ b/src/test/java/packfld/Test.java
@@ -0,0 +1,14 @@
+package packfld;
+
+/*
+ * This code was generated by ojc.
+ */
+public class Test {
+ static final int HSIZE = 50000;
+}
+
+class A {
+ public static void main(java.lang.String[] args) {
+ System.err.println(Test.HSIZE);
+ }
+}
diff --git a/src/test/java/pp/C.java b/src/test/java/pp/C.java
new file mode 100644
index 0000000..b0c7416
--- /dev/null
+++ b/src/test/java/pp/C.java
@@ -0,0 +1,44 @@
+package pp;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.MOPException;
+import io.devnulllabs.openjava.mop.MetaInfo;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.mop.OJMethod;
+import io.devnulllabs.openjava.ptree.ClassDeclaration;
+import io.devnulllabs.openjava.ptree.MethodDeclaration;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.ptree.Parameter;
+import io.devnulllabs.openjava.ptree.ParameterList;
+import io.devnulllabs.openjava.ptree.StatementList;
+import io.devnulllabs.openjava.ptree.TypeName;
+
+public class C extends OJClass {
+
+ public void translateDefinition() throws MOPException {
+ ModifierList ml;
+ TypeName tn;
+ ParameterList pl;
+ StatementList sl;
+ Environment env;
+ MethodDeclaration md;
+
+ ml = new ModifierList();
+ tn = new TypeName("boolean");
+ pl = new ParameterList(new Parameter(new TypeName("int"), "ind"));
+
+ env = getEnvironment();
+ sl = makeStatementList(env, "System.out.println(ind); return true;");
+
+ md = new MethodDeclaration(ml, tn, "myMeth", pl, null, sl);
+ addMethod(new OJMethod(getEnvironment(), getDeclaringClass(), md));
+ }
+
+ public C(Environment p0, OJClass p1, ClassDeclaration p2) {
+ super(p0, p1, p2);
+ }
+
+ public C(Class p0, MetaInfo p1) {
+ super(p0, p1);
+ }
+}
diff --git a/src/test/java/pp/CTest.oj b/src/test/java/pp/CTest.oj
new file mode 100644
index 0000000..4cb1289
--- /dev/null
+++ b/src/test/java/pp/CTest.oj
@@ -0,0 +1,6 @@
+package pp;
+
+public class CTest instantiates C
+{
+ void f( int i, int j ) {}
+}
diff --git a/src/test/java/pp/SyncTest.oj b/src/test/java/pp/SyncTest.oj
new file mode 100644
index 0000000..e1fba1d
--- /dev/null
+++ b/src/test/java/pp/SyncTest.oj
@@ -0,0 +1,8 @@
+package pp;
+
+public class SyncTest
+{
+ void f() {
+ synchronized (this) {}
+ }
+}
diff --git a/src/test/java/schulz/A.oj b/src/test/java/schulz/A.oj
new file mode 100644
index 0000000..16e7d3a
--- /dev/null
+++ b/src/test/java/schulz/A.oj
@@ -0,0 +1,9 @@
+import schulz;
+
+public class A instantiates Sample {
+
+ public A() {
+ super();
+ }
+
+}
diff --git a/src/test/java/schulz/Sample.oj b/src/test/java/schulz/Sample.oj
new file mode 100644
index 0000000..780851a
--- /dev/null
+++ b/src/test/java/schulz/Sample.oj
@@ -0,0 +1,18 @@
+import schulz;
+
+import io.devnulllabs.openjava.mop.*;
+
+public class Sample instantiates Metaclass extends OJClass {
+
+ public void translateDefinition() throws MOPException {
+
+ OJConstructor[] tabCons = getConstructors();
+
+ if (tabCons.length > 0) {
+ tabCons[0].addExceptionType(
+ OJClass.forName("java.lang.ArithmeticException"));
+ tabCons[0].addExceptionType(
+ OJClass.forName("java.lang.ArrayStoreException"));
+ }
+ }
+}
diff --git a/src/test/java/smyth/BankAccount.oj b/src/test/java/smyth/BankAccount.oj
new file mode 100644
index 0000000..d2402af
--- /dev/null
+++ b/src/test/java/smyth/BankAccount.oj
@@ -0,0 +1,25 @@
+import smyth;
+
+public distributed class BankAccount instantiates MDistributed {
+ private int balance = 100;
+
+ public BankAccount() {
+ super();
+ }
+
+ public int getBalance() {
+ return balance;
+ }
+
+ public void deposit(int d) {
+ System.out.println(d);
+ balance += d;
+ System.out.println(d + " has been deposited in your account.");
+ }
+
+ public void withdraw(int w) {
+ System.out.println(w);
+ balance -= w;
+ System.out.println(w + " has been withdrawn from your account.");
+ }
+}
diff --git a/src/test/java/smyth/MDistributed.oj b/src/test/java/smyth/MDistributed.oj
new file mode 100644
index 0000000..c9d50be
--- /dev/null
+++ b/src/test/java/smyth/MDistributed.oj
@@ -0,0 +1,111 @@
+package smyth;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+import java.util.*;
+
+public class MDistributed instantiates Metaclass extends OJClass {
+ /**
+ * Class Declarations
+ */
+ public static final String DISTRIBUTED = "distributed";
+ public static final String SUFFIX = "Inner";
+
+ private OJClass inner = null;
+
+ /**
+ * Overide the isRegistered method for DISTRIUBTED
+ */
+ public static boolean isRegisteredModifier(String keyword) {
+ if (keyword.equals(DISTRIBUTED))
+ return true;
+ return false;
+ }
+
+ /**
+ * Main method - translateDefinition
+ */
+ public void translateDefinition() throws MOPException {
+ if (getModifiers().has(DISTRIBUTED)) {
+ System.out.println("makeInnerClass()");
+ makeInnerClass();
+ System.out.println("changeOutterFields()");
+ changeOutterFields();
+ System.out.println("changeOutterConstructors()");
+ changeOutterConstructors();
+ } else {
+ System.out.println(
+ "You must attach the class modifier 'distributed' = for translation to take place.");
+ }
+ }
+
+ /**
+ * This method makes an innerclass from the outter class.
+ *
+ * The outter class then acts as a wrapper for this inner class.
+ *
+ */
+ public void makeInnerClass() throws openjava.mop.CannotAlterException {
+ /* Declarations */
+ ClassDeclaration clsdecl;
+ MemberDeclarationList memlist;
+
+ /* Make the ClassDeclaration from the OJClass */
+ clsdecl = (ClassDeclaration) getSourceCode().makeRecursiveCopy();
+
+ /* Change the name of ClassDeclaration */
+ clsdecl.setName(clsdecl.getName() + SUFFIX);
+
+ /* Change the name of the Constructors to match new name */
+ memlist = clsdecl.getBody();
+
+ for (int i = 0; i < memlist.size(); i++) {
+ if (memlist.get(i) instanceof ConstructorDeclaration) {
+ ((ConstructorDeclaration) memlist.get(i)).setName(
+ clsdecl.getName());
+ }
+ }
+
+ /* Add the inner class */
+ /*original (getSourceCode().getBody()).add(clsdecl);*/
+ inner = new OJClass(getEnvironment(), this, clsdecl);
+ OJSystem.env.record(inner.getName(), inner);
+ inner = addClass(inner);
+ }
+
+ /**
+ * This method is to remove the fields from the outter (wrapper) class.
+ *
+ * It is also to add a field of the type of the (new) innner class.
+ */
+ public void changeOutterFields() throws MOPException {
+ /* Remove the fields from the outter (wrapper) class */
+ OJField[] ojfld = getDeclaredFields();
+ for (int i = 0; i < ojfld.length; ++i) {
+ removeField(ojfld[i]);
+ }
+
+ /* Add the new field of type of the new inner class */
+ /* At the moment this is just given the variable name 'inner' */
+ OJModifier modif = OJModifier.forModifier(OJModifier.PRIVATE);
+ addField(new OJField(this, modif, inner, "inner"));
+ }
+
+ /* Change the constructors */
+ public void changeOutterConstructors() throws MOPException {
+ OJConstructor[] ojconstr = getConstructors();
+ for (int i = 0; i < ojconstr.length; ++i) {
+ StatementList body =
+ makeStatementList(
+ "inner=new "
+ + inner.getName()
+ + "("
+ + ojconstr[i].getParameterVariables()
+ + ");");
+ ojconstr[i].setBody(body);
+ }
+ }
+
+}
diff --git a/src/test/java/smyth/Test.oj b/src/test/java/smyth/Test.oj
new file mode 100644
index 0000000..c1451ce
--- /dev/null
+++ b/src/test/java/smyth/Test.oj
@@ -0,0 +1,15 @@
+package smyth;
+
+public distributed class Test instantiates MDistributed {
+ private int balance = 100;
+
+ public Test() {
+ super();
+ }
+
+ public int f() {
+ return 0;
+ }
+ public void g() {
+ }
+}
diff --git a/src/test/java/thorsten/MetaTest.oj b/src/test/java/thorsten/MetaTest.oj
new file mode 100644
index 0000000..ca6ec45
--- /dev/null
+++ b/src/test/java/thorsten/MetaTest.oj
@@ -0,0 +1,21 @@
+package thorsten;
+
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+public class MetaTest instantiates Metaclass extends OJClass {
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ //StatementList metStmts = makeStatementList(
+ // "String str = \"test\";"
+ //);
+ Statement metStmt = makeStatement("System.out.println( \"test\" );");
+ //Statement metStmt = makeStatement(
+ // "String str = \"test\";"
+ //);
+ }
+}
diff --git a/src/test/java/thorsten/Test.oj b/src/test/java/thorsten/Test.oj
new file mode 100644
index 0000000..b1bc24b
--- /dev/null
+++ b/src/test/java/thorsten/Test.oj
@@ -0,0 +1,6 @@
+package thorsten;
+
+public class Test instantiates MetaTest {
+ public static void main(String[] args) {
+ }
+}
diff --git a/src/test/java/walter/Test.oj b/src/test/java/walter/Test.oj
new file mode 100644
index 0000000..f238bda
--- /dev/null
+++ b/src/test/java/walter/Test.oj
@@ -0,0 +1,15 @@
+package walter;
+
+public class Test instantiates multiTrig {
+
+ public multi_trig void dummyMethod() {
+ System.out.println("dummyMethod was called");
+ }
+
+ public static void main(String[] argv) {
+ int i = 0;
+ Test dC = new Test();
+ for (; i <= 100; i++)
+ dC.dummyMethod();
+ }
+}
diff --git a/src/test/java/walter/dummyClass.oj b/src/test/java/walter/dummyClass.oj
new file mode 100644
index 0000000..97333e1
--- /dev/null
+++ b/src/test/java/walter/dummyClass.oj
@@ -0,0 +1,18 @@
+package walter;
+
+public class dummyClass instantiates multiTrig {
+
+ public dummyClass() {
+ }
+
+ public multi_trig void dummyMethod(int i) {
+ System.out.println("dummyMethod was called " + i + " times!");
+ }
+
+ public static void main(String[] argv) {
+ int i = 0;
+ dummyClass dC = new dummyClass();
+ for (; i <= 100; i++)
+ dC.dummyMethod(i);
+ }
+}
diff --git a/src/test/java/walter/multiTrig.oj b/src/test/java/walter/multiTrig.oj
new file mode 100644
index 0000000..18c194a
--- /dev/null
+++ b/src/test/java/walter/multiTrig.oj
@@ -0,0 +1,65 @@
+package walter;
+
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.ptree.ModifierList;
+import io.devnulllabs.openjava.mop.*;
+
+public class multiTrig instantiates Metaclass extends OJClass {
+
+ private static final String MULTI_TRIG = "multi_trig";
+ private final int triggerValue = 10;
+
+ public static boolean isRegisteredModifier(String keyword) {
+ if (keyword.equals(MULTI_TRIG))
+ return true;
+ return OJClass.isRegisteredModifier(keyword);
+ }
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().has(MULTI_TRIG))
+ continue;
+ String name = methods[i].getName(); // is a multi-trigged method
+ ModifierList ml = new ModifierList(ModifierList.PRIVATE);
+ TypeName tn = new TypeName("int");
+ /* inserts a field for counting the method calls
+ private int <method name>Counter = 0 */
+ String counterName = name + "Counter";
+ VariableInitializer vi = Literal.makeLiteral(0);
+ FieldDeclaration fd = new FieldDeclaration(ml, tn, counterName, vi);
+ OJField field = new OJField(getEnvironment(), this, fd);
+ addField(field);
+
+ /* inserts a field keeping the trigger value
+ private int <method name>Trigger = 10 */
+ String triggerName = name + "Trigger";
+ vi = Literal.makeLiteral(triggerValue);
+ fd = new FieldDeclaration(ml, tn, triggerName, vi);
+ field = new OJField(getEnvironment(), this, fd);
+ addField(field);
+
+ /* inserts a precondition on the execution of the method body
+ if (<method name>Counter == <method name>Trigger) {
+ and a post action
+ <method body>
+ <method name>Counter = 0;
+ } <method name>Counter++; */
+ StatementList newBody =
+ makeStatementList(
+ methods[i].getEnvironment(),
+ "if ("
+ + counterName
+ + " == "
+ + triggerName
+ + ") {"
+ + methods[i].getBody().toString()
+ + counterName
+ + "=0;}; "
+ + counterName
+ + "++;");
+ methods[i].setBody(newBody);
+ }
+ }
+
+}
diff --git a/src/test/java/walter2/ArraysTest.oj b/src/test/java/walter2/ArraysTest.oj
new file mode 100644
index 0000000..4c76f7e
--- /dev/null
+++ b/src/test/java/walter2/ArraysTest.oj
@@ -0,0 +1,11 @@
+package walter2;
+
+import java.util.*;
+
+public class ArraysTest {
+
+ public static void main(String[] args) {
+ Arrays.sort(args, new MyComp());
+ }
+
+}
diff --git a/src/test/java/walter2/MyComp.oj b/src/test/java/walter2/MyComp.oj
new file mode 100644
index 0000000..5afc869
--- /dev/null
+++ b/src/test/java/walter2/MyComp.oj
@@ -0,0 +1,9 @@
+package walter2;
+
+import java.util.*;
+
+public class MyComp implements Comparator {
+ public int compare(Object o1, Object o2) {
+ return ((String) o2).length() - ((String) o1).length();
+ }
+}
diff --git a/src/test/java/walter2/StaticTest.oj b/src/test/java/walter2/StaticTest.oj
new file mode 100644
index 0000000..cbc23a0
--- /dev/null
+++ b/src/test/java/walter2/StaticTest.oj
@@ -0,0 +1,11 @@
+package walter2;
+
+import java.util.*;
+
+public class StaticTest {
+
+ public void main(String[] args) {
+ StaticUtil.foo(args, new MyComp());
+ }
+
+}
diff --git a/src/test/java/walter2/StaticUtil.oj b/src/test/java/walter2/StaticUtil.oj
new file mode 100644
index 0000000..affc0bc
--- /dev/null
+++ b/src/test/java/walter2/StaticUtil.oj
@@ -0,0 +1,9 @@
+package walter2;
+
+import java.util.*;
+
+public class StaticUtil {
+ public static boolean foo(String[] args, Comparator c) {
+ return true;
+ }
+}
diff --git a/src/test/java/walter2/Test.oj b/src/test/java/walter2/Test.oj
new file mode 100644
index 0000000..660585c
--- /dev/null
+++ b/src/test/java/walter2/Test.oj
@@ -0,0 +1,26 @@
+package walter2;
+
+import sun.applet.*;
+import java.applet.*;
+import java.lang.*;
+import java.net.*;
+import java.util.*;
+
+public class Test {
+
+ public static void main(String argv[]) throws Exception {
+ System.out.println(Object[].class.isAssignableFrom(String[].class));
+ System.out.println(Float.class.isAssignableFrom(Integer.class));
+ System.out.println(float.class.isAssignableFrom(int.class));
+ System.out.println(int.class.isAssignableFrom(float.class));
+ System.out.println(float.class.isAssignableFrom(double.class));
+ System.out.println(double.class.isAssignableFrom(float.class));
+ System.out.println(int.class.isAssignableFrom(long.class));
+ System.out.println(long.class.isAssignableFrom(int.class));
+
+ foo(1);
+ }
+
+ public static void foo(double i) {
+ }
+}
diff --git a/tutorial/Adapter.html b/tutorial/Adapter.html
new file mode 100644
index 0000000..ae333a2
--- /dev/null
+++ b/tutorial/Adapter.html
@@ -0,0 +1,258 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>6. <font color="blue">Callee-side Translation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>callee-side</i>
+is described.
+
+
+<h3>6.1. What the base-level program should look like</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class <font color=black>VectorStack</font> <b>instantiates <font color=black>AdapterClass</font></b>
+ <b>adapts <font color=black>Vector</font> in v to <font color=black>Stack</font></b>
+{
+ <font color=black>Vector</font> v;
+ public <font color=black>VectorStack</font>( <font color=black>Vector</font> v ) {
+ this.v = v;
+ }
+ public <font color=black>void</font> push( <font color=black>Object</font> o ) {
+ v.addElement( o );
+ }
+ public <font color=black>Object</font> pop() {
+ <font color=black>Object</font> result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+ public <font color=black>Object</font> peek() {
+ return v.elementAt( v.size() - 1 );
+ }
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public interface <font color=black>Stack</font>
+{
+ public <font color=black>int</font> size();
+ public <font color=black>boolean</font> isEmpty();
+ public <font color=black>Enumeration</font> elements();
+ public <font color=black>Object[]</font> toArray();
+ public <font color=black>int</font> hashCode();
+ public <font color=black>void</font> push( <font color=black>Object</font> o );
+ public <font color=black>Object</font> pop();
+ public <font color=black>Object</font> peek();
+}
+</font></pre></blockquote>
+
+
+<h3>6.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class <font color=black>VectorStack</font> implements <font color=black>Stack</font>
+{
+ <font color=black>Vector</font> v;
+ public <font color=black>VectorStack</font>( <font color=black>Vector</font> v ) {
+ this.v = v;
+ }
+ public <font color=black>void</font> push( <font color=black>Object</font> o ) {
+ v.addElement( o );
+ }
+ public <font color=black>Object</font> pop() {
+ <font color=black>Object</font> result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+ public <font color=black>Object</font> peek() {
+ return v.elementAt( v.size() - 1 );
+ }
+ <b>public <font color=black>Object[]</font> toArray() {</b>
+ <b>return v.toArray();</b>
+ <b>}</b>
+ <b>public <font color=black>int</font> size() {</b>
+ <b>return v.size();</b>
+ <b>}</b>
+ <b>public <font color=black>Enumeration</font> elements() {</b>
+ <b>return v.elements();</b>
+ <b>}</b>
+ <b>public <font color=black>boolean</font> isEmpty() {</b>
+ <b>return v.isEmpty();</b>
+ <b>}</b>
+ <b>public <font color=black>int</font> hashCode() {</b>
+ <b>return v.hashCode();</b>
+ <b>}</b>
+}
+</font></pre></blockquote>
+
+
+<h3>6.3. Write a meta-level program</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ */
+public class AdapterClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass target = getTarget(), adaptee = getAdaptee();
+ if (target == null || adaptee == null) return;
+
+ /* implicit forwarding to the same signature's */
+ OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ /* picks up the method with same signature */
+ OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(),
+ adapteds[i].getParameterTypes(),
+ this );
+ } catch ( NoSuchMemberException e ) { /* not match */ continue; }
+
+ /* generate a forwarding method with forwarded's name */
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private OJMethod makeForwardingMethod( String name, OJMethod forwarded )
+ throws MOPException
+ {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod(
+ this,
+ forwarded.getModifiers().remove( OJModifier.ABSTRACT ),
+ forwarded.getReturnType(),
+ name,
+ forwarded.getParameterTypes(),
+ forwarded.getExceptionTypes(),
+ null
+ );
+
+ /* generates a method call and return statement */
+ ExpressionList params = result.getParameterVariables();
+ Expression expr = new MethodCall( getContainer(), name, params );
+ StatementList body = new StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new ExpressionStatement( expr ) );
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( expr ) );
+ }
+
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+
+ private OJClass getAdaptee() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private Variable getContainer() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return new Variable( suffix.get( 1 ).toString() );
+ }
+
+ private OJClass getTarget() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new CompositeRule(
+ new TypeNameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new TypeNameRule() ) );
+ }
+ return null;
+ }
+
+}
+
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/AutoImpl.html b/tutorial/AutoImpl.html
new file mode 100644
index 0000000..9fd017f
--- /dev/null
+++ b/tutorial/AutoImpl.html
@@ -0,0 +1,150 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>5. <font color="blue">Automatic Methods Implementation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>callee-side</i>
+is described.
+
+<p>The callee-side of a class is whole the declration source code of the
+class. Metaprogram in the metaclass for that class (base class)
+introspects that class definition in <code>this</code> class object
+through the inheriting <code>OJClass</code> interface.
+
+<p>Imagine an utility metaclass which automatically implements
+empty methods in its base classes according to their interfaces.
+
+<h3>5.1. What the base-level program should look like</h3>
+
+<p>A base class <code>QuickTest</code> has to implement an interface
+<code>java.awt.event.WindowListener</code>, which has several methods
+to have to be implemented, but we want to make most of these methods
+to have empty body, i.e. do nothing.
+
+<br><blockquote><pre><font color=darkblue>
+import java.awt.event.*;
+public class <font color=black>QuickTest</font> <b>instantiates <font color=black>AutoImplementerClass</font></b>
+ implements <font color=black>WindowListener</font>
+{
+ public <font color=black>void</font> windowClosed( <font color=black>WindowEvent</font> e ) { <font color=black>System</font>.exit( 0 ); }
+}
+</font></pre></blockquote>
+
+
+<h3>5.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>QuickTest</font> instantiates <font color=black>AutoImplementerClass</font>
+ implements <font color=black>WindowListener</font>
+{
+ public <font color=black>void</font> windowClosed( <font color=black>WindowEvent</font> e ) { <font color=black>System</font>.exit( 0 ); }
+ <b>public <font color=black>void</font> windowIconified( <font color=black>WindowEvent</font> e ) { return; }</b>
+ <b>public <font color=black>void</font> windowDeactivated( <font color=black>WindowEvent</font> e ) { return; }</b>
+ ....
+}
+</font></pre></blockquote>
+
+
+<h3>5.3. Write a meta-level program</h3>
+
+<p>So.
+
+<br><blockquote><pre><font color=darkblue>
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+public class AutoImplementerClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getInheritedMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().isAbstract()
+ || methods[i].getReturnType() != OJSystem.VOID
+ || hasDeclaredMethod( methods[i] )) continue;
+ addMethod( makeEmptyMethod( methods[i] ) );
+ }
+ }
+ ....
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+ private boolean hasDeclaredMethod( OJMethod m ) {
+ try {
+ getDeclaredMethod( m.getName(), m.getParameterTypes() );
+ return true;
+ } catch ( NoSuchMemberException e ) {
+ return false;
+ }
+ }
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+ private OJMethod makeEmptyMethod( OJMethod m ) throws MOPException {
+ /* generates a new method without body */
+ return new OJMethod( this,
+ m.getModifiers().remove( OJModifier.ABSTRACT ),
+ m.getReturnType(), m.getName(), m.getParameterTypes(),
+ m.getExceptionTypes(),
+ new StatementList( new ReturnStatement() )
+ );
+ }
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/FreeArgs.html b/tutorial/FreeArgs.html
new file mode 100644
index 0000000..43c9cb9
--- /dev/null
+++ b/tutorial/FreeArgs.html
@@ -0,0 +1,171 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>6. <font color="blue">Callee-side Translation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>caller-side</i>
+is described.
+
+<h3>6.1. What the base-level program should look like</h3>
+
+<p>Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class <font color=black>StringCollection</font> <b>instantiates <font color=black>FreeArgsClass</font></b>
+{
+ <font color=black>Vector</font> contents = new <font color=black>Vector</font>();
+ public <b>generous</b> <font color=black>void</font> addAll( <font color=black>String[]</font> args ) {
+ for (<font color=black>int</font> i = 0; i < args.length; ++i) contents.addElement( args[i] );
+ }
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Test</font>
+{
+ void test() {
+ <font color=black>StringCollection</font> strs = new <font color=black>StringCollection</font>();
+ strs.addAll( <b>"one", "two", "three"</b> );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Test</font>
+{
+ void test() {
+ <font color=black>StringCollection</font> strs = new <font color=black>StringCollection</font>();
+ strs.addAll( <b>new <font color=black>String</font>[]{ "one", "two", "three" }</b> );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.3. Write a meta-level program</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+public class FreeArgsClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Introduction.html b/tutorial/Introduction.html
new file mode 100644
index 0000000..fdec2c2
--- /dev/null
+++ b/tutorial/Introduction.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>1. <font color="blue">Introduction</font></h2>
+
+
+<p>OpenJava is an extensible language based on Java. The extended
+features of OpenJava are specified by a meta-level program given at
+compile time. For distinction, programs written in OpenJava are called
+base-level programs. If no meta-level program is given, OpenJava is
+identical to regular Java.
+
+<p>The meta-level program extends OpenJava through the interface
+called the OpenJava MOP (Metaobject Protocol). The OpenJava compiler
+consists of three stages: preprocessor, source-to-source translator
+from OpenJava to Java, and the back-end Java compiler. The OpenJava
+MOP is an interface to control the translator at the second stage. It
+allows to specify how an extended feature of OpenJava is translated
+into regular Java code.
+
+<p>An extended feature of OpenJava is supplied as an add-on software
+for the compiler. The add-on software consists of not only the
+meta-level program but runtime support code. The runtime support code
+provides classes used by the base-level program translated into
+Java. The base-level program in OpenJava is first translated into Java
+by the meta-level program and is dynamically linked with the runtime
+support code. This flow is illustrated by Figure 1.
+
+<center>
+<img src="images/comflow.gif"><br>
+Figure 1 : Data Flow of OpenJava Compiler
+</center>
+
+<p>The meta-level program is written in Java, accurately in OpenJava
+because OpenJava is a self-reflective language. It defines new
+metaobjects to control source-to-source translation. The metaobjects
+are the meta-level representation of the base-level program and they
+perform the translation. Details of the metaobjects are specified by
+the OpenJava MOP. In the following, we go through a few examples so
+that we illustrate how the OpenJava MOP is used to implement language
+extensions.
+<p>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/NewMethod.html b/tutorial/NewMethod.html
new file mode 100644
index 0000000..efa7192
--- /dev/null
+++ b/tutorial/NewMethod.html
@@ -0,0 +1,209 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+4. <font color="blue">Generating New Methods</font>
+</h2>
+<p>
+
+A MOP version of "hello world" is verbose objects, which print a message
+for every method call.
+We choose them as our first example.
+<p>
+The MOP programming in OpenJava is done through three steps :
+(1) decide what the base-level program should look like,
+(2) figure out what it should be translated into and what runtime support
+code is needed,
+and (3) write a meta-level program to perform the translation and also
+write the runtime support code.
+We implement the verbose objects through these steps.
+<p>
+
+
+<h3>2.1. What the base-level program should look like</h3>
+<p>
+
+Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+<br><blockquote><pre>
+public class <b>Hello</b> instantiates <b>VerboseClass</b> {
+ public static void main( String[] args ) {
+ hello();
+ }
+ static void hello() {
+ System.out.println( "<i>Hello, world.</i>" );
+ }
+}
+</pre></blockquote>
+
+This is an ordinary source code except for the first line.
+The annotation in the first line :
+
+<br><blockquote><pre>
+instantiates <b>VerboseClass</b>
+</pre></blockquote>
+
+is a special annotation for OpenJava, and means that the semantics of
+the class <b>Hello</b>, called metaobject, is specified to be extended
+by the class <b>VerboseClass</b>, called metaclass. In practice, the
+source code of the class <b>Hello</b> is translated by the object of
+the metaclass <b>VerboseClass</b>.
+
+<p>
+
+
+<h3>2.2. What the base-level program should be translated</h3>
+<p>
+
+In this example, consider the metaclass <b>VerboseClass</b> to extend
+the metaobjects to show messages for every call for its methods. In
+practice, the statement in order to put the message into system
+standard output is to be inserted at the first line of each methods'
+body in the class <b>Hello</b> via the metaclass <b>VerboseClass</b>. Then
+the first source code of class <b>Hello</b> should be translated into:
+
+<br><blockquote><pre>
+public class Hello {
+ public static void main( String[] args ) {
+ System.out.println( "<i>main is called.</i>" );
+ hello();
+ }
+ static void hello() {
+ System.out.println( "<i>hello is called.</i>" );
+ System.out.println( "<i>Hello, world.</i>" );
+ }
+}
+</pre></blockquote>
+
+<p>
+
+
+<h3>2.3. Write a meta-level program</h3>
+<p>
+
+Now, we write a meta-level program. What we should do is to translate
+only method member in the class <b>Hello</b> in the way shown above.
+We can easily do that if we use the MOP.
+<p>
+
+In OpenJava, classes are objects as in Smalltalk. We call them class
+metaobjects when we refer to their meta-level representation. A
+unique feature of OpenJava is that a class metaobject translates the
+source code defining the class at compile time. For example, the
+class metaobject for <b>Hello</b> translates a method declaration
+<b>hello()</b>.
+<p>
+
+By default, class metaobjects are identity functions; they do not change
+the program. So, to implement our translation, we define a new metaclass
+- a new class for class metaobjects - and use it to make the class
+metaobject for <b>Hello</b>.
+<p>
+
+Such a metaclass <b>VerboseClass</b> has been compiled and is similar
+to in form to:
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+public class <font color=black>VerboseClass</font> instantiates <font
+color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ public <font color=black>void</font> translatioDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJMethod</font>[] methods = getDeclaredMethods();
+ for (<font color=black>int</font> i = 0; i < methods.length; ++i) {
+ <font color=black>Statement</font> printer = makeStatement(
+ "<font color=gray><i>System.out.println( \"</i></font>" + methods[i].getName() +
+ "<font color=gray><i> is called.\" );</i></font>"
+ );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+}
+</font></pre></blockquote>
+
+The metaclass <b>VerboseClass</b> is just a regular Java class. It
+inherits from <b>openjava.mop.OJClass</b> and overrides one member
+function. <b>translateMethodDeclaration</b> takes an object of the
+class <b>MethodDeclaration</b> and returns the translated one. Both
+the given expression and the translated one are represented in the
+form of parse tree.
+<p>
+
+
+<h3>2.4. Compile, debug, and run</h3>
+<p>
+
+On a Sun workstation, the first class, stored in the file
+<tt>Hello.oj</tt>, can be translated into Java source code file named
+<tt>Hello.java</tt> and the generated source code can be compiled into
+byte code file named <tt>Hello.class</tt> by giving the commands :
+
+<br><blockquote><pre>
+% ojc VerboseClass.oj
+% ojc Hello.oj
+</pre></blockquote>
+<p>
+
+Execution of its bytecode on JVM (Java Virtual Machine) produces the
+output :
+
+<br><blockquote><pre>
+main is called.
+hello is called.
+Hello, world.
+</pre></blockquote>
+<p>
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Override.html b/tutorial/Override.html
new file mode 100644
index 0000000..32dbbb0
--- /dev/null
+++ b/tutorial/Override.html
@@ -0,0 +1,181 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+4. <font color="blue">Custom Modifiers</font>
+</h2>
+
+<p>OpenJava allows meta-programmer to extend the syntax of language in
+limited way. The easiest part of the syntax extension is adding
+new modifiers for class declaration or member declarations.
+
+<p>In this section, suppose an example of syntax extension for method
+declarations which explicitly describes the modified method should
+override the methed in superclasses. With this extension, base-level
+programmers can detect errors at compile-time. Otherwise,
+the regular Java compiler doesn't complain about it because it's
+proper method declaration defining a new method in the class.
+
+
+<h3>2.1. What the base-level program should look like</h3>
+
+<p>In defining a new class which must override some methods in
+superclasses, programmers would add the modifier <tt>overriding</tt>
+to each method overriding the corresponding method in superclasses.
+Here, we define a new class <b>MyObject</b> which surely overrides
+the method <tt>toString()</tt> in the superclass <b>java.lang.Object</b>:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>MyObject</font> instantiates <font color=black>OverrideCheckerClass</font> {
+ public <b>overriding</b> <font color=black>String</font> toString() {
+ return "<i>MyString</i>";
+ }
+}
+</font></pre></blockquote>
+
+<p>OpenJava compiler doesn't show any error message for this source code
+as it overrides the supermethod properly. But the system should
+show some error messages if the source code is as follows:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>MyObjectWithError</font> instantiates <font color=black>OverrideCheckerClass</font> {
+ public <b>overriding</b> <font color=black>String</font> toStr<b>u</b>ng() {
+ return "<i>MyString</i>";
+ }
+}
+</font></pre></blockquote>
+
+because there is no <tt>toStrung()</tt> method in the superclasses
+of the class <b>MyObjectWithError</b>.
+
+
+<h3>2.2. What the base-level program should be translated</h3>
+
+<p>In this example, only the error checking is performed thus no translation
+of source code are performed by the metaclass. Thus the system
+should produce the source code in the regular Java like following for
+the class <b>MyObject</b>:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>MyObject</font> {
+ public <font color=black>String</font> toString() {
+ return "<i>MyString</i>";
+ }
+}
+</font></pre></blockquote>
+
+<p>Only the difference from the original is the absense of the
+extended modifier <tt>overriding</tt>.
+
+
+<h3>2.3. Write a meta-level program</h3>
+
+<p>Extended modifiers are automatically removed by the
+system in generating source code. Thus we do not have to care about
+it here.
+
+We should define such a metaclass <b>OverrideCheckerClass</b>
+to override two methods. The first method:
+
+<br><blockquote><pre><font color=darkblue>
+public static boolean isRegisteredModifier(String)
+</font></pre></blockquote>
+is for the purpose of allowing the custom modifier <tt>overriding</tt>.
+
+<p>And the second method is:
+
+<br><blockquote><pre><font color=darkblue>
+public void translateDefinition()
+</font></pre></blockquote>
+
+Though there are no translation, we must show alert in case of missing
+overriding.
+
+<p>The source code following is a such implementation.
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+public class <font color=black>OverrideCheckerClass</font> instantiates <font color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ private static final <font color=black>String</font> OVERRIDING = "overriding";
+
+ public static <font color=black>boolean</font> isRegisteredModifier( <font color=black>String</font> keyword ) {
+ if (keyword.equals( OVERRIDING )) return true;
+ return <font color=black>OJClass</font>.isRegisteredModifier( keyword );
+ }
+
+ public <font color=black>void</font> translateDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJMethod</font>[] methods = getDeclaredMethods();
+ for (<font color=black>int</font> i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( OVERRIDING )) continue;
+ <font color=black>String</font> name = methods[i].getName();
+ <font color=black>OJClass</font>[] ptypes = methods[i].getParameterTypes();
+ try {
+ getSuperclass().getMethod( name, ptypes, this );
+ } catch (<font color=black>NoSuchMemberException</font> e) {
+ <font color=black>System</font>.err.println( "<i>warning: </i> " + methods[i] + "<i> doesn't </i>" +
+ "<i>override any method in the superclasses.</i>" );
+ }
+ }
+ }
+
+}
+</font></pre></blockquote>
+
+<p>In order to add a new modifier, we override the method
+<tt>isRegisteredModifier()</tt> and make it return true for the
+<b>String</b> object <tt>"overriding"</tt>.
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Overview.html b/tutorial/Overview.html
new file mode 100644
index 0000000..2ebb0b6
--- /dev/null
+++ b/tutorial/Overview.html
@@ -0,0 +1,208 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+3. <font color="blue">API and Framework at a Glance</font>
+</h2>
+<p>
+
+<h3>3.1. Overriding for Translation</h3>
+
+<p>As already describe before, we define a translation on a class by
+defining a new subclass of the metaclass <b>openjava.mop.OJClass</b>.
+The new metaclass overrides some methods in <b>OJClass</b> to change
+how to translate sourcecode related to the base class.
+
+<p>The main part of translation may be the translation on class
+definition. We call this kind of translation <i>callee-side
+translation</i>. For the convenience of explanation, suppose a base
+class <b>MyObject</b> extended by a metaclass <b>MyClass</b>, like
+following:
+
+<br><blockquote><pre><font color=darkblue>
+public class MyObject instantiates MyClass
+{
+ public String str;
+ public int f() { return 1; }
+}
+</font></pre></blockquote>
+
+<p>To modify the source code at the callee-side of classes, we should
+override the following method:
+
+<br><blockquote><pre>
+public void translateDefinition()
+ throws MOPException
+</pre></blockquote>
+
+in the metaclass<b>MyClass</b>, which is a subclass of the
+metaclass<b>OJClass</b>.
+
+<p>Furthermore, the part possible to translate is where the class is
+used. There are several part related to the use of class.
+i.e. object allocations, method calls, field accesses, .. We call
+this kind of translation <i>caller-side translation</i>. Similarly to
+callee-side translation, we should override appropriate methods in
+<b>OJClass</b>.
+
+<p>The following methods are for translation of object allocation parts.
+
+<br><blockquote><pre>
+public Expression expandAllocation(Evnironment,AllocationExpression)
+ throws MOPException
+</pre></blockquote>
+
+is applied to explessions like: <code><font color=darkblue>new
+MyObject()</font></code>, and
+
+<br><blockquote><pre>
+public Expression expandArrayAllocation(Evnironment,ArrayAllocationExpression)
+ throws MOPException
+</pre></blockquote>
+is applied for explessions like: <code><font color=darkblue>new
+MyObject[10]</font></code> or <code><font color=darkblue>new
+MyObject[]{ null, null }</font></code>
+
+<p>Here, suppose a variable <code><font color=darkblue>obj</font>
+</code> is declared somewhere as follows:
+
+<br><blockquote><pre><font color=darkblue>
+MyObject obj;
+</font></pre></blockquote>
+
+<p>The following methods are for translation of member access on either
+class or object.
+
+<br><blockquote><pre>
+public Expression expandFieldRead(Evnironment,FieldAccess)
+ throws MOPException
+</pre></blockquote>
+
+is applied to explessions like: <code><font
+color=darkblue>obj.str</font></code>,
+
+<br><blockquote><pre>
+public Expression expandMethodCall(Evnironment,MethodCall)
+ throws MOPException
+</pre></blockquote>
+
+is applied to explessions like: <code><font
+color=darkblue>obj.f()</font></code>, and
+
+<br><blockquote><pre>
+public Expression expandFieldWrite(Evnironment,AssignmentExpression)
+ throws MOPException
+</pre></blockquote>
+is applied to explessions like: <code><font color=darkblue>obj.str =
+"Hello"</font></code>
+
+
+<p>The following methods are for translation of where the name of the
+class appears.
+
+<br><blockquote><pre>
+public Expression expandTypeName(Evnironment,TypeName)
+ throws MOPException
+</pre></blockquote>
+
+<p>
+<br><blockquote><pre>
+public Expression expandArrayAccess(Evnironment,ArrayAccess)
+ throws MOPException
+public Expression expandAssignmentExpression(Evnironment,AssignmentExpression)
+ throws MOPException
+public Expression expandExpression(Evnironment,Expression)
+ throws MOPException
+public Statement expandVariableDeclaration(Evnironment,VariableDeclaration)
+ throws MOPException
+</pre></blockquote>
+<p>
+
+<h3>3.2. Getting Information of Class Metaobjects</h3>
+
+<p>In the overriding methods, we can get information about the class by
+using the methods defined in <b>OJClass</b> such as follows:
+<ul>
+<li><pre>public String getName()</pre>
+<li><pre>public OJClass getSuperclass()</pre>
+<li><pre>public OJClass[] getInterfaces()</pre>
+<li><pre>public OJField[] getDeclaredFields()</pre>
+<li><pre>public OJField[] getFields(OJClass situation)</pre>
+<li><pre>public OJMethod[] getDeclaredMethods()</pre>
+<li><pre>public OJMethod[] getMethods(OJClass situation)</pre>
+<li><pre>public OJConstructor[] getDeclaredConstructors()</pre>
+<li><pre>public OJConstructor[] getConstructors(OJClass situation)</pre>
+<li><pre>public OJField getField(String name)</pre>
+<li><pre>public OJMethod getMethod(String name,OJClass[] parameterTypes)</pre>
+<li><pre>public OJConstructor getConstructor(OJClass[] parameterTypes)</pre>
+</ul>
+
+<h3>3.3. Modifying a Class Metaobject</h3>
+
+<p>In the overriding <tt>translateDefinition()</tt> method, we can modify
+the class definition by using the methods defined in <b>OJClass</b>
+such as follows:
+
+<ul>
+<li><pre>protected OJField addField(OJField field)</pre>
+<li><pre>protected OJField removeField(OJField field)</pre>
+<li><pre>protected OJMethod addMethod(OJMethod method)</pre>
+<li><pre>protected OJMethod removeMethod(OJMethod method)</pre>
+<li><pre>protected OJConstructor addConstructor(OJConstructor constr)</pre>
+<li><pre>protected OJConstructor removeConstructor(OJConstructor constr)</pre>
+</ul>
+
+<p>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Synchronize.html b/tutorial/Synchronize.html
new file mode 100644
index 0000000..6385a6b
--- /dev/null
+++ b/tutorial/Synchronize.html
@@ -0,0 +1,131 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+7. <font color="blue">Synchronization of Translation</font>
+</h2>
+<p>
+
+As the default behavior of OpenJava compiler, there is no assurance of
+callee-side translation ordering. In the case that we make it sure to
+translate a class <b>SubMyObject</b> after a class <b>MyObject</b>, we
+can use the method <code>waitTranslation()</code> in
+<b>java.lang.OJClass</b>.
+
+<br><blockquote><pre>
+public void waitTranslation(OJClass)
+ throws MOPException
+</pre></blockquote>
+
+At the invocation of this method, the translation on the current
+class declaration stops and it return to continue after the
+translation on the class given as the argument finished.
+
+<h3>7.1. Simple Examples</h3>
+<p>
+
+Furthermore, the part where that class is used comes. There are
+several part related to the use of class. i.e. object allocations,
+method calls, field accesses, .. We call this kind of translation
+<i>caller-side translation</i>.
+<p>
+
+For the convenience of explanation, suppose a base class
+<b>MyObject</b> extended by a metaclass <b>MyClass</b>, like
+following:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>SubMyObject</font> instantiates <font color=black>SyncClass</font> extends <font color=black>MyObject</font>
+{}
+class <font color=black>MyObject</font> instantiates <font color=black>AnotherClass</font>
+{}
+class <font color=black>SubSubMyObject</font> instantiates <font color=black>SyncClass</font> extends <font color=black>SubMyObject</font>
+{}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>SyncClass</font> instantiates <font color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ void translateDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJClass</font> baseclazz = getSuperclass();
+ <font color=black>System</font>.out.println( getName() + "<i> is waiting for </i>" + base.getName() );
+ waitTranslation( baseclazz );
+ <font color=black>System</font>.out.println( getName() + "<i> finished</i>" );
+ }
+}
+</font></pre></blockquote>
+
+We can see the following messages in running OpenJava compiler.
+<br><blockquote><pre><font color=darkred>
+MyObject is waiting for java.lang.Object
+MyObject finished
+SubSubMyObject is waiting for SubMyObject
+SubMyObject is waiting for MyObject
+SubMyObject finished
+SubSubMyObject finished
+</font></pre></blockquote>
+<p>
+
+<h3>7.2. Deadlocks</h3>
+<p>
+
+In the case of the system detects some deadlocks,
+<code>waitTranslation()</code> throws an exception
+<code>MOPException</code>. If already the translation of
+a class <b>A</b> were waiting for the translation of a class <b>B</b>,
+the invocation of <code>waitTranslation()</code> on the translation
+of the class <b>B</b> would not block but throw an exception.
+<p>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Syntax.html b/tutorial/Syntax.html
new file mode 100644
index 0000000..ca1fb2f
--- /dev/null
+++ b/tutorial/Syntax.html
@@ -0,0 +1,171 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>6. <font color="blue">Callee-side Translation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>callee-side</i>
+is described.
+
+
+<h3>6.1. What the base-level program should look like</h3>
+
+<p>Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class StringCollection instantiates FreeArgsClass
+{
+ Vector contents = new Vector();
+ public generous void addAll( String[] args ) {
+ for (int i = 0; i < args.length; ++i) contents.addElement( args[i] );
+ }
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public class Test
+{
+ void test() {
+ StringCollection strs = new StringCollection();
+ strs.addAll( "one", "two", "three" );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+<br><blockquote><pre><font color=darkblue>
+public class Test
+{
+ void test() {
+ StringCollection strs = new StringCollection();
+ strs.addAll( new String[]{ "one", "two", "three" } );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.3. Write a meta-level program</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+public class FreeArgsClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/VerboseClass.html b/tutorial/VerboseClass.html
new file mode 100644
index 0000000..43e0637
--- /dev/null
+++ b/tutorial/VerboseClass.html
@@ -0,0 +1,212 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>2. <font color="blue">Hello World</font></h2>
+
+
+<p>A MOP version of "hello world" is verbose objects, which print a message
+for every method call.
+We choose them as our first example.
+
+<p>The MOP programming in OpenJava is done through three steps :
+<ul>
+<li>(1) decide what the base-level program should look like,
+<li>(2) figure out what it should be translated into and what runtime support
+code is needed,
+</ul>
+and
+<ul>
+<li>(3) write a meta-level program to perform the translation and also
+write the runtime support code.
+</ul>
+We implement the verbose objects through these steps.
+
+
+<h3>2.1. What the base-level program should look like</h3>
+
+<p>Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Hello</font> <b>instantiates <font color=black>VerboseClass</font></b> {
+ public static <font color=black>void</font> main( <font color=black>String</font>[] args ) {
+ hello();
+ }
+ static <font color=black>void</font> hello() {
+ <font color=black>System</font>.out.println( "<font color=gray><i>Hello, world.</i></font>" );
+ }
+}
+</font></pre></blockquote>
+
+<p>This is an ordinary source code except for the first line.
+The annotation in the first line :
+
+<br><blockquote><pre><font color=darkblue>
+instantiates <font color=black>VerboseClass</font>
+</font></pre></blockquote>
+
+is a special annotation for OpenJava, and means that the semantics of
+the class <b>Hello</b>, called metaobject, is specified to be extended
+by the class <b>VerboseClass</b>, called metaclass. In practice, the
+source code of the class <b>Hello</b> is translated by the object of
+the metaclass <b>VerboseClass</b>.
+
+
+<h3>2.2. What the base-level program should be translated</h3>
+
+<p>In this example, consider the metaclass <b>VerboseClass</b> to extend
+the metaobjects to show messages for every call for its methods. In
+practice, the statement in order to put the message into system
+standard output is to be inserted at the first line of each methods'
+body in the class <b>Hello</b> via the metaclass <b>VerboseClass</b>. Then
+the first source code of class <b>Hello</b> should be translated into:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Hello</font> {
+ public static <font color=black>void</font> main( <font color=black>String</font>[] args ) {
+ <b><font color=black>System</font>.out.println( "<i>main is called.</i>" );</b>
+ hello();
+ }
+ static <font color=black>void</font> hello() {
+ <b><font color=black>System</font>.out.println( "<i>hello is called.</i>" );</b>
+ <font color=black>System</font>.out.println( "<i>Hello, world.</i>" );
+ }
+}
+</font></pre></blockquote>
+
+
+
+<h3>2.3. Write a meta-level program</h3>
+
+<p>Now, we write a meta-level program. What we should do is to
+translate only method member in the class <b>Hello</b> in the way
+shown above. We can easily do that if we use the MOP.
+
+<p>In OpenJava, classes are objects as in Smalltalk. We call them class
+metaobjects when we refer to their meta-level representation. A
+unique feature of OpenJava is that a class metaobject translates the
+source code defining the class at compile time. For example, the
+class metaobject for <b>Hello</b> translates a method declaration
+<b>hello()</b>.
+
+<p>By default, class metaobjects are identity functions; they do not
+change the program. So, to implement our translation, we define a new
+metaclass - a new class for class metaobjects - and use it to make the
+class metaobject for <b>Hello</b>. Such a metaclass
+<b>VerboseClass</b> has been compiled and is similar to in form to:
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+public class <font color=black>VerboseClass</font> instantiates <font
+color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ public <font color=black>void</font> translateDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJMethod</font>[] methods = getDeclaredMethods();
+ for (<font color=black>int</font> i = 0; i < methods.length; ++i) {
+ <font color=black>Statement</font> printer = makeStatement(
+ "<font color=gray><i>System.out.println( \"</i></font>" + methods[i] +
+ "<font color=gray><i> is called.\" );</i></font>"
+ );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+}
+</font></pre></blockquote>
+
+<p>Here, the metaclass <b>VerboseClass</b> is a base-level class of
+OpenJava from the view point of meta programming and in fact it
+declares its metaclass as <b>openjava.mop.Metaclass</b> though could
+be written in the regular Java. It inherits from
+<b>openjava.mop.OJClass</b> and overrides one member function.
+
+<p>In order to translate the definition part (callee-side) of the base
+class <b>Hello</b>, we should override the method
+<tt>translateMethodDeclaration()</tt>, which is to be invoked by the
+system automatically. In the method
+<tt>translateMethodDeclaration()</tt>, we can obtain all the method
+objects which are declared in the base-level class by invoking the
+method <tt>getDeclaredMethods()</tt> on the class object
+<tt>this</tt>.
+
+The method <tt>makeStatement()</tt> is the partial parser which
+produces a <b>openjava.ptree.Statement</b> object from a
+<b>java.lang.String</b> object. Here we produces a statement which
+print that the method is called, then inserts it at the body for each
+method.
+
+
+<h3>2.4. Compile, debug, and run</h3>
+
+<p>On a Sun workstation, the first class, stored in the file
+<tt>Hello.oj</tt>, can be translated into Java source code file named
+<tt>Hello.java</tt> and the generated source code can be compiled into
+byte code file named <tt>Hello.class</tt> by giving the commands:
+
+<br><blockquote><pre>
+% ojc VerboseClass.oj
+% ojc Hello.oj
+</pre></blockquote>
+
+<p>Execution of its bytecode on JVM (Java Virtual Machine) produces
+the output :
+
+<br><blockquote><pre><font color=darkred>
+void Hello.main(String[]) is called.
+void Hello.hello() is called.
+Hello, world.
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/examples/adapter/AdapterClass.java b/tutorial/examples/adapter/AdapterClass.java
new file mode 100644
index 0000000..0b2e60c
--- /dev/null
+++ b/tutorial/examples/adapter/AdapterClass.java
@@ -0,0 +1,155 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * AdapterClass.oj
+ *
+ * An OpenJava example to support programming with the Adapter pattern.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.adapter;
+
+
+import java.lang.Object;
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ * <p>
+ * For example, the class <code>VectorStack</code>:
+ * <pre>
+ * public class VectorStack instantiates AdapterClass
+ * adapts Vector in v to Stack
+ * {
+ * Vector v;
+ * public VectorStack( Vector v ) {
+ * this.v = v;
+ * }
+ * public void push( Object o ) {
+ * v.addElement( o );
+ * }
+ * public Object pop() {
+ * return v.removeElementAt( v.size() - 1 );
+ * }
+ * }
+ * </pre>
+ * would be automatically implemented with the forwarding methods
+ * size(), isEmpty(), hashCode(), etc, which are found in both
+ * the class Vector(adaptee) and the class Stack(target).
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: AdapterClass.java,v 1.2 2003/02/19 02:55:02 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class AdapterClass extends io.devnulllabs.openjava.mop.OJClass
+{
+
+ public static final java.lang.String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.mop.OJClass target = getTarget();
+ io.devnulllabs.openjava.mop.OJClass adaptee = getAdaptee();
+ if (target == null || adaptee == null) {
+ return;
+ }
+ io.devnulllabs.openjava.mop.OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ io.devnulllabs.openjava.mop.OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(), adapteds[i].getParameterTypes(), this );
+ } catch ( io.devnulllabs.openjava.mop.NoSuchMemberException e ) {
+ continue;
+ }
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private io.devnulllabs.openjava.mop.OJMethod makeForwardingMethod( java.lang.String name, io.devnulllabs.openjava.mop.OJMethod forwarded )
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.mop.OJMethod result = new io.devnulllabs.openjava.mop.OJMethod( this, forwarded.getModifiers().remove( OJModifier.ABSTRACT ), forwarded.getReturnType(), name, forwarded.getParameterTypes(), forwarded.getExceptionTypes(), null );
+ io.devnulllabs.openjava.ptree.ExpressionList params = result.getParameterVariables();
+ io.devnulllabs.openjava.ptree.Expression expr = new io.devnulllabs.openjava.ptree.MethodCall( getContainer(), name, params );
+ io.devnulllabs.openjava.ptree.StatementList body = new io.devnulllabs.openjava.ptree.StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new io.devnulllabs.openjava.ptree.ExpressionStatement( expr ) );
+ body.add( new io.devnulllabs.openjava.ptree.ReturnStatement() );
+ } else {
+ body.add( new io.devnulllabs.openjava.ptree.ReturnStatement( expr ) );
+ }
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+ private io.devnulllabs.openjava.mop.OJClass getAdaptee()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.ptree.ObjectList suffix = (io.devnulllabs.openjava.ptree.ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private io.devnulllabs.openjava.ptree.Variable getContainer()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.ptree.ObjectList suffix = (io.devnulllabs.openjava.ptree.ObjectList) getSuffix( KEY_ADAPTS );
+ return new io.devnulllabs.openjava.ptree.Variable( suffix.get( 1 ).toString() );
+ }
+
+ private io.devnulllabs.openjava.mop.OJClass getTarget()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.ptree.ObjectList suffix = (io.devnulllabs.openjava.ptree.ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( java.lang.String keyword )
+ {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static io.devnulllabs.openjava.syntax.SyntaxRule getDeclSuffixRule( java.lang.String keyword )
+ {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new io.devnulllabs.openjava.syntax.CompositeRule( new io.devnulllabs.openjava.syntax.TypeNameRule(), new io.devnulllabs.openjava.syntax.PrepPhraseRule( "in", new io.devnulllabs.openjava.syntax.NameRule() ), new io.devnulllabs.openjava.syntax.PrepPhraseRule( "to", new io.devnulllabs.openjava.syntax.TypeNameRule() ) );
+ }
+ return null;
+ }
+
+ public AdapterClass( io.devnulllabs.openjava.mop.Environment oj_param0, io.devnulllabs.openjava.mop.OJClass oj_param1, io.devnulllabs.openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public AdapterClass( java.lang.Class oj_param0, io.devnulllabs.openjava3.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/adapter/AdapterClass.oj b/tutorial/examples/adapter/AdapterClass.oj
new file mode 100644
index 0000000..c0f9763
--- /dev/null
+++ b/tutorial/examples/adapter/AdapterClass.oj
@@ -0,0 +1,152 @@
+/*
+ * AdapterClass.oj
+ *
+ * An OpenJava example to support programming with the Adapter pattern.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.adapter;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ * <p>
+ * For example, the class <code>VectorStack</code>:
+ * <pre>
+ * public class VectorStack instantiates AdapterClass
+ * adapts Vector in v to Stack
+ * {
+ * Vector v;
+ * public VectorStack( Vector v ) {
+ * this.v = v;
+ * }
+ * public void push( Object o ) {
+ * v.addElement( o );
+ * }
+ * public Object pop() {
+ * return v.removeElementAt( v.size() - 1 );
+ * }
+ * }
+ * </pre>
+ * would be automatically implemented with the forwarding methods
+ * size(), isEmpty(), hashCode(), etc, which are found in both
+ * the class Vector(adaptee) and the class Stack(target).
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class AdapterClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass target = getTarget(), adaptee = getAdaptee();
+ if (target == null || adaptee == null) return;
+
+ /* implicit forwarding to the same signature's */
+ OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ /* picks up the method with same signature */
+ OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(),
+ adapteds[i].getParameterTypes(),
+ this );
+ } catch ( NoSuchMemberException e ) { /* not match */ continue; }
+
+ /* generate a forwarding method with forwarded's name */
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private OJMethod makeForwardingMethod( String name, OJMethod forwarded )
+ throws MOPException
+ {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod(
+ this,
+ forwarded.getModifiers().remove( OJModifier.ABSTRACT ),
+ forwarded.getReturnType(),
+ name,
+ forwarded.getParameterTypes(),
+ forwarded.getExceptionTypes(),
+ null
+ );
+
+ /* generates a method call and return statement */
+ ExpressionList params = result.getParameterVariables();
+ Expression expr = new MethodCall( getContainer(), name, params );
+ StatementList body = new StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new ExpressionStatement( expr ) );
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( expr ) );
+ }
+
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+
+ private OJClass getAdaptee() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private Variable getContainer() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return new Variable( suffix.get( 1 ).toString() );
+ }
+
+ private OJClass getTarget() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new CompositeRule(
+ new TypeNameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new TypeNameRule() ) );
+ }
+ return null;
+ }
+
+}
+
diff --git a/tutorial/examples/adapter/Stack.java b/tutorial/examples/adapter/Stack.java
new file mode 100644
index 0000000..37f4035
--- /dev/null
+++ b/tutorial/examples/adapter/Stack.java
@@ -0,0 +1,29 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.adapter;
+
+
+import java.util.Enumeration;
+
+
+public interface Stack
+{
+
+ public int size();
+
+ public boolean isEmpty();
+
+ public java.util.Enumeration elements();
+
+ public java.lang.Object[] toArray();
+
+ public int hashCode();
+
+ public void push( java.lang.Object o );
+
+ public java.lang.Object pop();
+
+ public java.lang.Object peek();
+
+}
diff --git a/tutorial/examples/adapter/Stack.oj b/tutorial/examples/adapter/Stack.oj
new file mode 100644
index 0000000..2ef6f27
--- /dev/null
+++ b/tutorial/examples/adapter/Stack.oj
@@ -0,0 +1,15 @@
+package examples.adapter;
+
+import java.util.Enumeration;
+
+public interface Stack
+{
+ public int size();
+ public boolean isEmpty();
+ public Enumeration elements();
+ public Object[] toArray();
+ public int hashCode();
+ public void push( Object o );
+ public Object pop();
+ public Object peek();
+}
diff --git a/tutorial/examples/adapter/VectorStack.java b/tutorial/examples/adapter/VectorStack.java
new file mode 100644
index 0000000..9f14a60
--- /dev/null
+++ b/tutorial/examples/adapter/VectorStack.java
@@ -0,0 +1,68 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.adapter;
+
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+
+public class VectorStack implements examples.adapter.Stack
+{
+
+ java.util.Vector v;
+
+ public VectorStack( java.util.Vector v )
+ {
+ this.v = v;
+ }
+
+ public void push( java.lang.Object o )
+ {
+ v.addElement( o );
+ }
+
+ public java.lang.Object pop()
+ {
+ java.lang.Object result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+
+ public java.lang.Object peek()
+ {
+ return v.elementAt( v.size() - 1 );
+ }
+
+
+ public java.lang.Object[] toArray()
+ {
+ return v.toArray();
+ }
+
+
+ public int size()
+ {
+ return v.size();
+ }
+
+
+ public java.util.Enumeration elements()
+ {
+ return v.elements();
+ }
+
+
+ public boolean isEmpty()
+ {
+ return v.isEmpty();
+ }
+
+
+ public int hashCode()
+ {
+ return v.hashCode();
+ }
+
+}
diff --git a/tutorial/examples/adapter/VectorStack.oj b/tutorial/examples/adapter/VectorStack.oj
new file mode 100644
index 0000000..7306e98
--- /dev/null
+++ b/tutorial/examples/adapter/VectorStack.oj
@@ -0,0 +1,24 @@
+package examples.adapter;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class VectorStack instantiates AdapterClass
+ adapts Vector in v to examples.adapter.Stack
+{
+ Vector v;
+ public VectorStack( Vector v ) {
+ this.v = v;
+ }
+ public void push( Object o ) {
+ v.addElement( o );
+ }
+ public Object pop() {
+ Object result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+ public Object peek() {
+ return v.elementAt( v.size() - 1 );
+ }
+}
diff --git a/tutorial/examples/autoimp/AutoImplementerClass.java b/tutorial/examples/autoimp/AutoImplementerClass.java
new file mode 100644
index 0000000..11f5040
--- /dev/null
+++ b/tutorial/examples/autoimp/AutoImplementerClass.java
@@ -0,0 +1,78 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * AutoImplementerClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.autoimp;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AutoImprementerClass</code> provides classes
+ * with a facility automatically implementing null methods for
+ * not implemented methods.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class AutoImplementerClass extends OJClass
+{
+
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJMethod[] methods = getInheritedMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().isAbstract() || hasDeclaredMethod( methods[i] )) {
+ continue;
+ }
+ addMethod( makeNullMethod( methods[i] ) );
+ }
+ }
+
+ private boolean hasDeclaredMethod( OJMethod m )
+ {
+ try {
+ getDeclaredMethod( m.getName(), m.getParameterTypes() );
+ return true;
+ } catch ( NoSuchMemberException e ) {
+ return false;
+ }
+ }
+
+ private OJMethod makeNullMethod( OJMethod m )
+ throws MOPException
+ {
+ OJMethod result = new OJMethod( this, m.getModifiers().remove( OJModifier.ABSTRACT ), m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes(), null );
+ StatementList body = new StatementList();
+ if (m.getReturnType() == OJSystem.VOID) {
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( Literal.constantNull() ) );
+ }
+ result.setBody( body );
+ return result;
+ }
+
+ public AutoImplementerClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public AutoImplementerClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/autoimp/AutoImplementerClass.oj b/tutorial/examples/autoimp/AutoImplementerClass.oj
new file mode 100644
index 0000000..29ca2b2
--- /dev/null
+++ b/tutorial/examples/autoimp/AutoImplementerClass.oj
@@ -0,0 +1,64 @@
+/*
+ * AutoImplementerClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.autoimp;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AutoImprementerClass</code> provides classes
+ * with a facility automatically implementing null methods for
+ * not implemented methods.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class AutoImplementerClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getInheritedMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().isAbstract()
+ || hasDeclaredMethod( methods[i] )) continue;
+ addMethod( makeNullMethod( methods[i] ) );
+ }
+ }
+
+ private boolean hasDeclaredMethod( OJMethod m ) {
+ try {
+ getDeclaredMethod( m.getName(), m.getParameterTypes() );
+ return true;
+ } catch ( NoSuchMemberException e ) {
+ return false;
+ }
+ }
+
+ private OJMethod makeNullMethod( OJMethod m ) throws MOPException {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod( this,
+ m.getModifiers().remove( OJModifier.ABSTRACT ),
+ m.getReturnType(), m.getName(), m.getParameterTypes(),
+ m.getExceptionTypes(), null
+ );
+ /* generates a return statement */
+ StatementList body = new StatementList();
+ if (m.getReturnType() == OJSystem.VOID) {
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( Literal.constantNull() ) );
+ }
+ result.setBody( body );
+ return result;
+ }
+
+}
diff --git a/tutorial/examples/autoimp/InnerTest.java b/tutorial/examples/autoimp/InnerTest.java
new file mode 100644
index 0000000..f97f1d8
--- /dev/null
+++ b/tutorial/examples/autoimp/InnerTest.java
@@ -0,0 +1,29 @@
+/*
+ * This code was generated by ojc.
+ */
+/* quick implementation! */
+package examples.autoimp;
+
+
+import java.awt.event.*;
+
+
+public class InnerTest
+{
+
+ public static void main( String[] args )
+ {
+ WindowListener tmp = new MyWindowListener();
+ }
+
+ static class MyWindowListener implements WindowListener
+ {
+
+ public void windowClosed( WindowEvent e )
+ {
+ System.exit( 0 );
+ }
+
+ }
+
+}
diff --git a/tutorial/examples/autoimp/InnerTest.oj b/tutorial/examples/autoimp/InnerTest.oj
new file mode 100644
index 0000000..926ce48
--- /dev/null
+++ b/tutorial/examples/autoimp/InnerTest.oj
@@ -0,0 +1,15 @@
+/* quick implementation! */
+package examples.autoimp;
+import java.awt.event.*;
+public class InnerTest
+{
+ public static void main( String[] args ) {
+ WindowListener tmp = new MyWindowListener();
+ }
+
+ static class MyWindowListener instantiates AutoImplementerClass
+ implements WindowListener
+ {
+ public void windowClosed( WindowEvent e ) { System.exit( 0 ); }
+ }
+}
diff --git a/tutorial/examples/autoimp/Test.java b/tutorial/examples/autoimp/Test.java
new file mode 100644
index 0000000..6fa37b4
--- /dev/null
+++ b/tutorial/examples/autoimp/Test.java
@@ -0,0 +1,55 @@
+/*
+ * This code was generated by ojc.
+ */
+/* quick implementation! */
+package examples.autoimp;
+
+
+import java.awt.event.*;
+
+
+public class Test implements WindowListener
+{
+
+ public void windowClosed( WindowEvent e )
+ {
+ System.exit( 0 );
+ }
+
+
+ public void windowIconified( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowDeactivated( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowActivated( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowOpened( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowDeiconified( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowClosing( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+}
diff --git a/tutorial/examples/autoimp/Test.oj b/tutorial/examples/autoimp/Test.oj
new file mode 100644
index 0000000..9f22972
--- /dev/null
+++ b/tutorial/examples/autoimp/Test.oj
@@ -0,0 +1,8 @@
+/* quick implementation! */
+package examples.autoimp;
+import java.awt.event.*;
+public class Test instantiates AutoImplementerClass
+ implements WindowListener
+{
+ public void windowClosed( WindowEvent e ) { System.exit( 0 ); }
+}
diff --git a/tutorial/examples/bca/AutoAdaptationClass.java b/tutorial/examples/bca/AutoAdaptationClass.java
new file mode 100644
index 0000000..5e088bc
--- /dev/null
+++ b/tutorial/examples/bca/AutoAdaptationClass.java
@@ -0,0 +1,53 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * AUtoAdaptationClass.oj
+ *
+ * Source Code Adaptation example.
+ * (Not real Binary Code Adaptation)
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.bca;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> patches the class
+ * implementing <code>Writable</code> to implement <code>Printable</code>.
+ */
+public class AutoAdaptationClass extends OJClass
+{
+
+ /** Overrides to translate definition */
+ public void translateDefinition()
+ throws MOPException
+ {
+ if (!openjava.mop.OJClass.forClass( Writable.class ).isAssignableFrom( this )) {
+ return;
+ }
+ OJClass newface = openjava.mop.OJClass.forClass( Printable.class );
+ addInterface( newface );
+ OJMethod facemtd = newface.getMethod( "print", new OJClass[0] );
+ OJMethod impmtd = new OJMethod( this, facemtd.getModifiers().remove( OJModifier.ABSTRACT ), facemtd.getReturnType(), facemtd.getName(), facemtd.getParameterTypes(), facemtd.getExceptionTypes(), null );
+ addMethod( impmtd );
+ StatementList body = makeStatementList( "this.write(java.lang.System.out);" );
+ impmtd.setBody( body );
+ }
+
+ public AutoAdaptationClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public AutoAdaptationClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/bca/AutoAdaptationClass.oj b/tutorial/examples/bca/AutoAdaptationClass.oj
new file mode 100644
index 0000000..9819bc2
--- /dev/null
+++ b/tutorial/examples/bca/AutoAdaptationClass.oj
@@ -0,0 +1,48 @@
+/*
+ * AUtoAdaptationClass.oj
+ *
+ * Source Code Adaptation example.
+ * (Not real Binary Code Adaptation)
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.bca;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> patches the class
+ * implementing <code>Writable</code> to implement <code>Printable</code>.
+ */
+public class AutoAdaptationClass instantiates Metaclass extends OJClass
+{
+ /** Overrides to translate definition */
+ public convenient void translateDefinition() throws MOPException {
+ /* only the case this class implements Writable */
+ if (! Writable.class.isAssignableFrom( this )) return;
+
+ OJClass newface = Printable.class;
+
+ addInterface( newface );
+
+ OJMethod facemtd = newface.getMethod( "print", new OJClass[0] );
+
+ OJMethod impmtd = new OJMethod( this,
+ facemtd.getModifiers().remove( OJModifier.ABSTRACT ),
+ facemtd.getReturnType(),
+ facemtd.getName(), facemtd.getParameterTypes(),
+ facemtd.getExceptionTypes(),
+ null
+ );
+ addMethod( impmtd );
+
+ StatementList body = makeStatementList(
+ "this.write(java.lang.System.out);"
+ );
+ impmtd.setBody( body );
+ }
+}
diff --git a/tutorial/examples/bca/Printable.java b/tutorial/examples/bca/Printable.java
new file mode 100644
index 0000000..296850e
--- /dev/null
+++ b/tutorial/examples/bca/Printable.java
@@ -0,0 +1,7 @@
+package examples.bca;
+
+
+public interface Printable
+{
+ public void print();
+}
diff --git a/tutorial/examples/bca/RTReflClass.java b/tutorial/examples/bca/RTReflClass.java
new file mode 100644
index 0000000..429b241
--- /dev/null
+++ b/tutorial/examples/bca/RTReflClass.java
@@ -0,0 +1,51 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * RTReflClass.oj
+ *
+ * Source Code Adaptation example.
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.bca;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> patches the class
+ * implementing <code>Writable</code> to implement <code>Printable</code>.
+ */
+public class RTReflClass extends OJClass
+{
+
+ /** Overrides to translate definition */
+ public void translateDefinition()
+ throws MOPException
+ {
+ if (!openjava.mop.OJClass.forClass( Writable.class ).isAssignableFrom( this )) {
+ return;
+ }
+ addInterface( openjava.mop.OJClass.forClass( Printable.class ) );
+ OJMethod facemtd = getMethod( "write", new OJClass[]{ openjava.mop.OJClass.forClass( java.io.PrintStream.class ) } );
+ OJMethod impmtd = new OJMethod( this, facemtd.getModifiers(), facemtd.getReturnType(), facemtd.getName(), facemtd.getParameterTypes(), facemtd.getExceptionTypes(), null );
+ addMethod( impmtd );
+ StatementList body = makeStatementList( "this.write(java.lang.System.out);" );
+ impmtd.setBody( body );
+ }
+
+ public RTReflClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public RTReflClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/bca/Test.java b/tutorial/examples/bca/Test.java
new file mode 100644
index 0000000..5de77d0
--- /dev/null
+++ b/tutorial/examples/bca/Test.java
@@ -0,0 +1,24 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test implements examples.bca.Writable, examples.bca.Printable
+{
+
+ public void write( PrintStream out )
+ {
+ out.println( "Hello" );
+ }
+
+
+ public void print()
+ {
+ this.write( java.lang.System.out );
+ }
+
+}
diff --git a/tutorial/examples/bca/Test.oj b/tutorial/examples/bca/Test.oj
new file mode 100644
index 0000000..2514028
--- /dev/null
+++ b/tutorial/examples/bca/Test.oj
@@ -0,0 +1,13 @@
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test instantiates AutoAdaptationClass
+ implements Writable
+{
+ public void write(PrintStream out) {
+ out.println( "Hello" );
+ }
+}
diff --git a/tutorial/examples/bca/Test2.java b/tutorial/examples/bca/Test2.java
new file mode 100644
index 0000000..013c360
--- /dev/null
+++ b/tutorial/examples/bca/Test2.java
@@ -0,0 +1,18 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test2
+{
+
+ public void write( PrintStream out )
+ {
+ out.println( "Hello" );
+ }
+
+}
diff --git a/tutorial/examples/bca/Test2.oj b/tutorial/examples/bca/Test2.oj
new file mode 100644
index 0000000..ca72a4c
--- /dev/null
+++ b/tutorial/examples/bca/Test2.oj
@@ -0,0 +1,12 @@
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test2 instantiates AutoAdaptationClass
+{
+ public void write(PrintStream out) {
+ out.println( "Hello" );
+ }
+}
diff --git a/tutorial/examples/bca/Writable.java b/tutorial/examples/bca/Writable.java
new file mode 100644
index 0000000..f8df297
--- /dev/null
+++ b/tutorial/examples/bca/Writable.java
@@ -0,0 +1,10 @@
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public interface Writable
+{
+ public void write(PrintStream out);
+}
diff --git a/tutorial/examples/capsule/CapsuleClass.oj b/tutorial/examples/capsule/CapsuleClass.oj
new file mode 100644
index 0000000..9d54fe3
--- /dev/null
+++ b/tutorial/examples/capsule/CapsuleClass.oj
@@ -0,0 +1,130 @@
+/*
+ * CapsuleClass.oj
+ *
+ * Apr 23, 1999 by Michiaki Tatsubori
+ */
+package examples.capsule;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>CapsuleClass</code> is a metaclass which
+ * hides all the fields in the class and provides reader and writer
+ * methods corresponding to each field. Furthermore, accesses
+ * to fields of the class is to be replaced with these methods.
+ */
+public class CapsuleClass instantiates Metaclass extends OJClass
+{
+ /** Overrides to translate definition */
+ public void translateDefinition() throws MOPException {
+ /* Detect public fields in superclass */
+ OJField[] inherited_flds = getSuperclass().getFields();
+ if (inherited_flds.length > 0) {
+ System.err.println( "WARNING: Leak Possibilities" );
+ for (int i = 0; i < inherited_flds.length; ++i)
+ System.err.println( inherited_flds[i].toString() );
+ }
+
+ /* Get all declared fields and hide it */
+ OJField[] fields = getDeclaredFields();
+ for (int i = 0; i < fields.length; ++i) {
+ OJModifier modif = fields[i].getModifiers();
+ if (! modif.isPrivate()) hideField( fields[i] );
+ }
+ }
+
+ private void hideField( OJField field ) throws MOPException {
+ System.err.println( "Hiding a field : " + field.toString() );
+ generateReaderMethod( field );
+ generateWriterMethod( field );
+ field.setModifiers( field.getModifiers().setPrivate() );
+ }
+
+ private void generateReaderMethod( OJField field ) throws MOPException {
+ StatementList body = makeStatementList(
+ "return " + field.getName() + ";"
+ );
+ OJMethod reader = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldReaderName( field.getName() ),
+ (OJClass[]) null, null, body
+ );
+ addMethod( reader );
+ }
+
+ private void generateWriterMethod( OJField field ) throws MOPException {
+ OJMethod writer = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldWriterName( field.getName() ),
+ new OJClass[]{ field.getType() }, null, null
+ );
+ String param = writer.getParameters()[0];
+ StatementList body = makeStatementList( writer.getEnvironment(),
+ "return " + field.getName() + "=" + param + ";"
+ );
+ writer.setBody( body );
+ addMethod( writer );
+ }
+
+ private static final String fieldReaderName( String name ) {
+ return "read_" + name;
+ }
+
+ private static final String fieldWriterName( String name ) {
+ return "write_" + name;
+ }
+
+ /* overrides */
+
+ /** Allows references to private fields */
+ public OJField resolveException( NoSuchMemberException e, String name )
+ throws NoSuchMemberException
+ {
+ try {
+ return getDeclaredField( name );
+ } catch ( NoSuchMemberException e2 ) {}
+ return super.resolveException( e, name );
+ }
+
+ /** Overrides to expand fields to be read */
+ public Expression expandFieldRead(
+ Environment env,
+ FieldAccess expr )
+ {
+ Expression ref = expr.getReferenceExpr();
+ String name = fieldReaderName( expr.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, null );
+ } else {
+ result = new MethodCall( expr.getReferenceType(), name, null );
+ }
+ System.err.println( "Patch FR : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ /** Overrides to expand fields to be written */
+ public Expression expandFieldWrite(
+ Environment env,
+ AssignmentExpression expr )
+ {
+ FieldAccess fldac = (FieldAccess) expr.getLeft();
+ ExpressionList args = new ExpressionList( expr.getRight() );
+ Expression ref = fldac.getReferenceExpr();
+ String name = fieldWriterName( fldac.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, args );
+ } else {
+ result = new MethodCall( fldac.getReferenceType(), name, args );
+ }
+ System.err.println( "Patch FW : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+}
diff --git a/tutorial/examples/capsule/Point.oj b/tutorial/examples/capsule/Point.oj
new file mode 100644
index 0000000..a74f566
--- /dev/null
+++ b/tutorial/examples/capsule/Point.oj
@@ -0,0 +1,22 @@
+/*
+ * Point.oj
+ */
+package examples.capsule;
+
+
+public class Point instantiates CapsuleClass
+{
+ public int x, y;
+ protected String name;
+
+ public Point( String name, int x, int y ) {
+ this.x = x;
+ this.y = y;
+ this.name = name;
+ }
+
+ public Point( int x, int y ) {
+ this( "DefaultName", x, y );
+ }
+
+}
diff --git a/tutorial/examples/capsule/PointUser.oj b/tutorial/examples/capsule/PointUser.oj
new file mode 100644
index 0000000..f81a335
--- /dev/null
+++ b/tutorial/examples/capsule/PointUser.oj
@@ -0,0 +1,17 @@
+/*
+ * PointUser.oj
+ */
+package examples.capsule;
+
+
+public class PointUser
+{
+
+ public static void main( String[] args ) {
+ Point p = new Point( 1, 2 );
+ p.name = "MyFavorite";
+ int x = p.x + 1;
+ p.y = x * 2 + p.y;
+ }
+
+}
diff --git a/tutorial/examples/capsule/Test.oj b/tutorial/examples/capsule/Test.oj
new file mode 100644
index 0000000..4b25816
--- /dev/null
+++ b/tutorial/examples/capsule/Test.oj
@@ -0,0 +1,47 @@
+package examples.capsule;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates CapsuleClass
+{
+ private int iii = 0;
+
+ protected Test n = null;
+
+ public String str = "string";
+
+ public static String NAME = "Test";
+
+ public Test() {
+ super();
+ }
+
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/capsule/TestUser.oj b/tutorial/examples/capsule/TestUser.oj
new file mode 100644
index 0000000..1aa85b6
--- /dev/null
+++ b/tutorial/examples/capsule/TestUser.oj
@@ -0,0 +1,38 @@
+package examples.capsule;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class TestUser
+{
+ Test test;
+
+ public static void main( String[] argv ) {
+ TestUser user = new TestUser();
+ Test test = new Test();
+ System.out.println( test.str.toString() );
+ System.out.println( test.n.toString() );
+ test.foo();
+ }
+
+ private TestUser() {
+ this.test = new Test();
+ }
+
+ public void run() {
+ test.n = test;
+ java.lang.System.out.println( test.n = test );
+ System.out.println( (test.n = test).toString() );
+ }
+
+ public void print() {
+ System.out.println( test.n.str );
+ String s = ((String) Test.NAME).toString();
+ String sa = Test.NAME + "_ALPHA";
+ String ss = (Test.NAME).toString();
+ return;
+ }
+}
diff --git a/tutorial/examples/capsule/TestUser2.oj b/tutorial/examples/capsule/TestUser2.oj
new file mode 100644
index 0000000..931f279
--- /dev/null
+++ b/tutorial/examples/capsule/TestUser2.oj
@@ -0,0 +1,8 @@
+package examples.capsule;
+
+public class TestUser2
+{
+ public static void main( String[] argv ) {
+ Test.NAME.toString();
+ }
+}
diff --git a/tutorial/examples/copy/CopiedClass.java b/tutorial/examples/copy/CopiedClass.java
new file mode 100644
index 0000000..e709187
--- /dev/null
+++ b/tutorial/examples/copy/CopiedClass.java
@@ -0,0 +1,43 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * CopiedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.copy;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import openjava.ptree.util.TypeNameQualifier;
+
+
+public class CopiedClass extends OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws MOPException
+ {
+ String newqname = getName() + "Shadow";
+ OJClass shadow = makeCopy( newqname );
+ OJSystem.addNewClass( shadow );
+ }
+
+ public CopiedClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public CopiedClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/copy/CopiedClass.oj b/tutorial/examples/copy/CopiedClass.oj
new file mode 100644
index 0000000..7799f59
--- /dev/null
+++ b/tutorial/examples/copy/CopiedClass.oj
@@ -0,0 +1,37 @@
+/*
+ * CopiedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.copy;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import openjava.ptree.util.TypeNameQualifier;
+
+
+public class CopiedClass instantiates Metaclass extends OJClass
+{
+ /* overrides for translation */
+ public convenient void translateDefinition() throws MOPException {
+ String newqname = getName() + "Shadow";
+ OJClass shadow = makeCopy( newqname );
+ /***
+ ClassDeclaration org = getSourceCode();
+ ClassDeclaration copy = (ClassDeclaration) org.makeRecursiveCopy();
+ String pack = Environment.toPackageName( newqname );
+ String sname = Environment.toSimpleName( newqname );
+ copy.setName( sname );
+ copy.accept( new TypeNameQualifier( getEnvironment(), sname ) );
+ FileEnvironment env = new FileEnvironment( OJSystem.env, pack, sname );
+ OJClass shadow = new OJClass( env, null, copy );
+ ***/
+ OJSystem.addNewClass( shadow );
+ }
+
+}
diff --git a/tutorial/examples/copy/Test.java b/tutorial/examples/copy/Test.java
new file mode 100644
index 0000000..2a37ecf
--- /dev/null
+++ b/tutorial/examples/copy/Test.java
@@ -0,0 +1,62 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.copy;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel
+{
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv )
+ {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ return iii;
+ }
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/copy/Test.oj b/tutorial/examples/copy/Test.oj
new file mode 100644
index 0000000..f0db01d
--- /dev/null
+++ b/tutorial/examples/copy/Test.oj
@@ -0,0 +1,52 @@
+package examples.copy;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates CopiedClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/copy/TestShadow.java b/tutorial/examples/copy/TestShadow.java
new file mode 100644
index 0000000..dc07b66
--- /dev/null
+++ b/tutorial/examples/copy/TestShadow.java
@@ -0,0 +1,58 @@
+/*
+ * This code was generated by ojc.
+ */
+
+package examples.copy;
+
+
+public class TestShadow extends java.awt.Panel
+{
+
+ private int iii = 0;
+
+ private examples.copy.Test n = null;
+
+ private java.lang.String str = "string";
+
+ public TestShadow()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( java.lang.String[] argv )
+ {
+ java.io.PrintStream out = java.lang.System.out;
+ java.io.PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ examples.copy.Test n = new examples.copy.Test();
+ java.lang.System.err.println( "done. " );
+ examples.copy.Test test = new examples.copy.Test();
+ test.foo();
+ }
+
+ public TestShadow( java.lang.String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ return iii;
+ }
+
+ public java.lang.String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/decorator/0UNDERCONSTRUCTION b/tutorial/examples/decorator/0UNDERCONSTRUCTION
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tutorial/examples/decorator/0UNDERCONSTRUCTION
diff --git a/tutorial/examples/decorator/AdapterClass.oj b/tutorial/examples/decorator/AdapterClass.oj
new file mode 100644
index 0000000..c0f9763
--- /dev/null
+++ b/tutorial/examples/decorator/AdapterClass.oj
@@ -0,0 +1,152 @@
+/*
+ * AdapterClass.oj
+ *
+ * An OpenJava example to support programming with the Adapter pattern.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.adapter;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ * <p>
+ * For example, the class <code>VectorStack</code>:
+ * <pre>
+ * public class VectorStack instantiates AdapterClass
+ * adapts Vector in v to Stack
+ * {
+ * Vector v;
+ * public VectorStack( Vector v ) {
+ * this.v = v;
+ * }
+ * public void push( Object o ) {
+ * v.addElement( o );
+ * }
+ * public Object pop() {
+ * return v.removeElementAt( v.size() - 1 );
+ * }
+ * }
+ * </pre>
+ * would be automatically implemented with the forwarding methods
+ * size(), isEmpty(), hashCode(), etc, which are found in both
+ * the class Vector(adaptee) and the class Stack(target).
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class AdapterClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass target = getTarget(), adaptee = getAdaptee();
+ if (target == null || adaptee == null) return;
+
+ /* implicit forwarding to the same signature's */
+ OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ /* picks up the method with same signature */
+ OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(),
+ adapteds[i].getParameterTypes(),
+ this );
+ } catch ( NoSuchMemberException e ) { /* not match */ continue; }
+
+ /* generate a forwarding method with forwarded's name */
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private OJMethod makeForwardingMethod( String name, OJMethod forwarded )
+ throws MOPException
+ {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod(
+ this,
+ forwarded.getModifiers().remove( OJModifier.ABSTRACT ),
+ forwarded.getReturnType(),
+ name,
+ forwarded.getParameterTypes(),
+ forwarded.getExceptionTypes(),
+ null
+ );
+
+ /* generates a method call and return statement */
+ ExpressionList params = result.getParameterVariables();
+ Expression expr = new MethodCall( getContainer(), name, params );
+ StatementList body = new StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new ExpressionStatement( expr ) );
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( expr ) );
+ }
+
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+
+ private OJClass getAdaptee() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private Variable getContainer() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return new Variable( suffix.get( 1 ).toString() );
+ }
+
+ private OJClass getTarget() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new CompositeRule(
+ new TypeNameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new TypeNameRule() ) );
+ }
+ return null;
+ }
+
+}
+
diff --git a/tutorial/examples/decorator/ReturnSpecifier.java b/tutorial/examples/decorator/ReturnSpecifier.java
new file mode 100644
index 0000000..031958b
--- /dev/null
+++ b/tutorial/examples/decorator/ReturnSpecifier.java
@@ -0,0 +1,67 @@
+package examples.decorator;
+
+
+import java.io.Writer;
+import java.io.IOException;
+
+
+/*
+ * Here assumes there's no implementation in Writer
+ * like 'implements Writer'
+ */
+public class ReturnSpecifier
+ extends Writer
+{
+ private static final char[] mark = { ' ', '<' };
+
+ private Writer out;
+
+ public ReturnSpecifier(Writer out) {
+ this.out = out;
+ }
+
+ public void write(char cbuf[], int off, int len)
+ throws IOException
+ {
+ int done = off;
+ for (int i = done; i < off + len; ++i) {
+ if (cbuf[i] == Character.LINE_SEPARATOR
+ || cbuf[i] == '\n')
+ {
+ out.write(cbuf, done, i - done);
+ // print a mark for carriage return
+ out.write(mark, 0, mark.length);
+ // print a carriage return
+ out.write(cbuf, i, 1);
+ done = i + 1;
+ }
+ }
+ out.write(cbuf, done, off + len - done);
+ }
+
+ public void close() throws IOException {
+ out.close();
+ }
+
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+/*****
+ public void write(char[] cbuf) throws IOException {
+ out.write(cbuf);
+ }
+
+ public void write(int c) throws IOException {
+ out.write(c);
+ }
+
+ public void write(String str) throws IOException {
+ out.write(str);
+ }
+
+ public void write(String str, int off, int len) throws IOException {
+ out.write(str, off, len);
+ }
+*****/
+}
diff --git a/tutorial/examples/decorator/ReturnSpecifier.oj b/tutorial/examples/decorator/ReturnSpecifier.oj
new file mode 100644
index 0000000..e1e4f73
--- /dev/null
+++ b/tutorial/examples/decorator/ReturnSpecifier.oj
@@ -0,0 +1,39 @@
+package exampls.decorator;
+
+
+import java.io.Writer;
+import java.io.IOException;
+
+
+public class ReturnSpecifier instantiates DecoratorClass
+ decorates Writer in out
+{
+ private static final char[] mark = { '\\', '<' };
+
+ private Writer out;
+
+ public ReturnSpecifier(Writer out) {
+ this.out = out;
+ }
+
+ public void write(char cbuf[], int off, int len)
+ throws IOException
+ {
+ int done = off;
+ for (int i = done; i < off + len; ++i) {
+ if (cbuf[i] == Character.LINE_SEPARATOR
+ || cbuf[i] == '\n')
+ {
+ out.write(cbuf, done, i - done);
+ // print a mark for carriage return
+ out.write(mark, 0, mark.length);
+ // print a carriage return
+ out.write(cbuf, i, 1);
+ done = i + 1;
+ }
+ }
+ out.write(cbuf, done, off + len - done);
+ }
+
+
+}
diff --git a/tutorial/examples/decorator/Test.java b/tutorial/examples/decorator/Test.java
new file mode 100644
index 0000000..9f7b450
--- /dev/null
+++ b/tutorial/examples/decorator/Test.java
@@ -0,0 +1,21 @@
+package examples.decorator;
+
+
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+
+public class Test
+{
+ public static void main(String[] args) {
+ Writer baseout
+ = new ReturnSpecifier(new OutputStreamWriter(System.out));
+ PrintWriter out = new PrintWriter(baseout);
+ out.println( "Hi there." );
+ out.println( "This is a test." );
+ out.println( "Thank you." );
+ out.flush();
+ }
+
+}
diff --git a/tutorial/examples/decorator/Test.oj b/tutorial/examples/decorator/Test.oj
new file mode 100644
index 0000000..3989a56
--- /dev/null
+++ b/tutorial/examples/decorator/Test.oj
@@ -0,0 +1,21 @@
+package examples.decorator;
+
+
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+
+public class Test
+{
+ public static void main(String[] args) {
+ Writer baseout
+ = new ReturnSpecifier(System.out) decorates OutputStreamWriter;
+ PrintWriter out = new PrintWriter(baseout);
+ out.println( "Hi there." );
+ out.println( "This is a test." );
+ out.println( "Thank you." );
+ out.flush();
+ }
+
+}
diff --git a/tutorial/examples/facemake/FaceProvidedClass.java b/tutorial/examples/facemake/FaceProvidedClass.java
new file mode 100644
index 0000000..e2d15df
--- /dev/null
+++ b/tutorial/examples/facemake/FaceProvidedClass.java
@@ -0,0 +1,76 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * FaceProvidedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.facemake;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class FaceProvidedClass extends OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJMethod[] methods = getMethods();
+ String fname = getName() + "Face";
+ FaceProvidedClass face = createEmptyInterface( fname );
+ OJSystem.addNewClass( face );
+ for (int i = 0; i < methods.length; ++i) {
+ OJMethod fmtd = OJMethod.makePrototype( methods[i] );
+ OJModifier modif = fmtd.getModifiers();
+ if (modif.isStatic()) {
+ continue;
+ }
+ if (isMethodOfObject( methods[i] )) {
+ continue;
+ }
+ fmtd.setModifiers( OJModifier.PUBLIC );
+ face.addMethod( fmtd );
+ }
+ addInterface( face );
+ }
+
+ public static FaceProvidedClass createEmptyInterface( String qname )
+ {
+ String pack = Environment.toPackageName( qname );
+ String sname = Environment.toSimpleName( qname );
+ ClassDeclaration cd = new ClassDeclaration( new ModifierList( ModifierList.PUBLIC ), sname, new TypeName[0], new TypeName[0], new MemberDeclarationList(), false );
+ FileEnvironment env = new FileEnvironment( OJSystem.env, pack, sname );
+ return new FaceProvidedClass( env, null, cd );
+ }
+
+ public static boolean isMethodOfObject( OJMethod m )
+ {
+ try {
+ OJClass clazz = OJSystem.OBJECT;
+ clazz.getMethod( m.getName(), m.getParameterTypes(), clazz );
+ return true;
+ } catch ( NoSuchMemberException ex ) {
+ return false;
+ }
+ }
+
+ public FaceProvidedClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public FaceProvidedClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/facemake/FaceProvidedClass.oj b/tutorial/examples/facemake/FaceProvidedClass.oj
new file mode 100644
index 0000000..8d0857f
--- /dev/null
+++ b/tutorial/examples/facemake/FaceProvidedClass.oj
@@ -0,0 +1,57 @@
+/*
+ * FaceProvidedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.facemake;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class FaceProvidedClass instantiates Metaclass extends OJClass
+{
+ /* overrides for translation */
+ public convenient void translateDefinition() throws MOPException {
+ OJMethod[] methods = getMethods();
+ String fname = getName() + "Face";
+ FaceProvidedClass face = createEmptyInterface(fname);
+ OJSystem.addNewClass(face);
+ for (int i = 0; i < methods.length; ++i) {
+ OJMethod fmtd = OJMethod.makePrototype(methods[i]);
+ OJModifier modif = fmtd.getModifiers();
+ if (modif.isStatic()) continue; /* non-static only */
+ if (isMethodOfObject(methods[i])) continue;
+ fmtd.setModifiers( OJModifier.PUBLIC );
+ face.addMethod(fmtd);
+ }
+ addInterface(face);
+ }
+
+ public static FaceProvidedClass createEmptyInterface(String qname) {
+ String pack = Environment.toPackageName(qname);
+ String sname = Environment.toSimpleName(qname);
+ ClassDeclaration cd
+ = new ClassDeclaration(new ModifierList(ModifierList.PUBLIC),
+ sname, new TypeName[0], new TypeName[0],
+ new MemberDeclarationList(), false );
+ FileEnvironment env = new FileEnvironment(OJSystem.env, pack, sname);
+ return new FaceProvidedClass(env, null, cd);
+ }
+
+ public static boolean isMethodOfObject(OJMethod m) {
+ try {
+ OJClass clazz = OJSystem.OBJECT;
+ clazz.getMethod(m.getName(), m.getParameterTypes(), clazz);
+ return true;
+ } catch (NoSuchMemberException ex) {
+ return false;
+ }
+ }
+
+}
diff --git a/tutorial/examples/facemake/Test.java b/tutorial/examples/facemake/Test.java
new file mode 100644
index 0000000..96f738d
--- /dev/null
+++ b/tutorial/examples/facemake/Test.java
@@ -0,0 +1,62 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.facemake;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel implements examples.facemake.TestFace
+{
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv )
+ {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ return iii;
+ }
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/facemake/Test.oj b/tutorial/examples/facemake/Test.oj
new file mode 100644
index 0000000..03f7dbe
--- /dev/null
+++ b/tutorial/examples/facemake/Test.oj
@@ -0,0 +1,52 @@
+package examples.facemake;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates FaceProvidedClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/facemake/TestFace.java b/tutorial/examples/facemake/TestFace.java
new file mode 100644
index 0000000..878d91d
--- /dev/null
+++ b/tutorial/examples/facemake/TestFace.java
@@ -0,0 +1,516 @@
+/*
+ * This code was generated by ojc.
+ */
+
+package examples.facemake;
+
+
+
+public interface TestFace
+{
+
+
+ public void print( java.awt.Graphics oj_param0 );
+
+
+ public void layout();
+
+
+ public void setLocation( java.awt.Point oj_param0 );
+
+
+ public java.awt.Dimension getPreferredSize();
+
+
+ public java.awt.Dimension getSize( java.awt.Dimension oj_param0 );
+
+
+ public boolean isShowing();
+
+
+ public void repaint( long oj_param0 );
+
+
+ public java.awt.Point getLocationOnScreen();
+
+
+ public void update( java.awt.Graphics oj_param0 );
+
+
+ public java.awt.Dimension minimumSize();
+
+
+ public int getHeight();
+
+
+ public void reshape( int oj_param0, int oj_param1, int oj_param2, int oj_param3 );
+
+
+ public java.awt.Insets insets();
+
+
+ public boolean keyUp( java.awt.Event oj_param0, int oj_param1 );
+
+
+ public void show();
+
+
+ public boolean contains( java.awt.Point oj_param0 );
+
+
+ public boolean action( java.awt.Event oj_param0, java.lang.Object oj_param1 );
+
+
+ public boolean mouseDown( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void addMouseMotionListener( java.awt.event.MouseMotionListener oj_param0 );
+
+
+ public boolean isEnabled();
+
+
+ public void setFont( java.awt.Font oj_param0 );
+
+
+ public boolean prepareImage( java.awt.Image oj_param0, int oj_param1, int oj_param2, java.awt.image.ImageObserver oj_param3 );
+
+
+ public boolean mouseEnter( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void addFocusListener( java.awt.event.FocusListener oj_param0 );
+
+
+ public void setBounds( java.awt.Rectangle oj_param0 );
+
+
+ public boolean inside( int oj_param0, int oj_param1 );
+
+
+ public void setBounds( int oj_param0, int oj_param1, int oj_param2, int oj_param3 );
+
+
+ public float getAlignmentX();
+
+
+ public boolean contains( int oj_param0, int oj_param1 );
+
+
+ public java.awt.peer.ComponentPeer getPeer();
+
+
+ public java.awt.Component[] getComponents();
+
+
+ public java.awt.Component findComponentAt( int oj_param0, int oj_param1 );
+
+
+ public void setComponentOrientation( java.awt.ComponentOrientation oj_param0 );
+
+
+ public java.awt.Component getComponentAt( int oj_param0, int oj_param1 );
+
+
+ public java.awt.Component getComponent( int oj_param0 );
+
+
+ public void removeContainerListener( java.awt.event.ContainerListener oj_param0 );
+
+
+ public void remove( int oj_param0 );
+
+
+ public void remove( java.awt.MenuComponent oj_param0 );
+
+
+ public java.awt.Cursor getCursor();
+
+
+ public java.awt.Component getComponentAt( java.awt.Point oj_param0 );
+
+
+ public void move( int oj_param0, int oj_param1 );
+
+
+ public java.awt.Dimension preferredSize();
+
+
+ public java.awt.Image createImage( int oj_param0, int oj_param1 );
+
+
+ public void removeInputMethodListener( java.awt.event.InputMethodListener oj_param0 );
+
+
+ public int getComponentCount();
+
+
+ public void removeComponentListener( java.awt.event.ComponentListener oj_param0 );
+
+
+ public void setForeground( java.awt.Color oj_param0 );
+
+
+ public void addPropertyChangeListener( java.lang.String oj_param0, java.beans.PropertyChangeListener oj_param1 );
+
+
+ public int foo();
+
+
+ public void setLocale( java.util.Locale oj_param0 );
+
+
+ public java.awt.Point getLocation( java.awt.Point oj_param0 );
+
+
+ public void list( java.io.PrintStream oj_param0, int oj_param1 );
+
+
+ public int checkImage( java.awt.Image oj_param0, java.awt.image.ImageObserver oj_param1 );
+
+
+ public java.awt.Dimension size();
+
+
+ public boolean isVisible();
+
+
+ public java.awt.Dimension getMinimumSize();
+
+
+ public void doLayout();
+
+
+ public boolean gotFocus( java.awt.Event oj_param0, java.lang.Object oj_param1 );
+
+
+ public void addInputMethodListener( java.awt.event.InputMethodListener oj_param0 );
+
+
+ public int getY();
+
+
+ public java.awt.Component add( java.awt.Component oj_param0, int oj_param1 );
+
+
+ public boolean isOpaque();
+
+
+ public boolean isValid();
+
+
+ public void removeKeyListener( java.awt.event.KeyListener oj_param0 );
+
+
+ public boolean isDisplayable();
+
+
+ public void setName( java.lang.String oj_param0 );
+
+
+ public java.awt.Toolkit getToolkit();
+
+
+ public java.awt.ComponentOrientation getComponentOrientation();
+
+
+ public void setLocation( int oj_param0, int oj_param1 );
+
+
+ public void addNotify();
+
+
+ public java.awt.Dimension getMaximumSize();
+
+
+ public java.lang.String getName();
+
+
+ public void setSize( int oj_param0, int oj_param1 );
+
+
+ public void add( java.awt.PopupMenu oj_param0 );
+
+
+ public void list( java.io.PrintWriter oj_param0 );
+
+
+ public int countComponents();
+
+
+ public java.awt.Point getLocation();
+
+
+ public void resize( java.awt.Dimension oj_param0 );
+
+
+ public java.util.Locale getLocale();
+
+
+ public void removePropertyChangeListener( java.beans.PropertyChangeListener oj_param0 );
+
+
+ public void resize( int oj_param0, int oj_param1 );
+
+
+ public boolean mouseDrag( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public java.awt.Point location();
+
+
+ public java.awt.image.ColorModel getColorModel();
+
+
+ public void removeNotify();
+
+
+ public void repaint( long oj_param0, int oj_param1, int oj_param2, int oj_param3, int oj_param4 );
+
+
+ public void removePropertyChangeListener( java.lang.String oj_param0, java.beans.PropertyChangeListener oj_param1 );
+
+
+ public void removeMouseListener( java.awt.event.MouseListener oj_param0 );
+
+
+ public int checkImage( java.awt.Image oj_param0, int oj_param1, int oj_param2, java.awt.image.ImageObserver oj_param3 );
+
+
+ public void paintComponents( java.awt.Graphics oj_param0 );
+
+
+ public void list();
+
+
+ public void dispatchEvent( java.awt.AWTEvent oj_param0 );
+
+
+ public java.lang.Object getTreeLock();
+
+
+ public void printAll( java.awt.Graphics oj_param0 );
+
+
+ public void nextFocus();
+
+
+ public boolean mouseExit( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void addComponentListener( java.awt.event.ComponentListener oj_param0 );
+
+
+ public void deliverEvent( java.awt.Event oj_param0 );
+
+
+ public void requestFocus();
+
+
+ public void disable();
+
+
+ public void setEnabled( boolean oj_param0 );
+
+
+ public void repaint();
+
+
+ public void setVisible( boolean oj_param0 );
+
+
+ public java.awt.FontMetrics getFontMetrics( java.awt.Font oj_param0 );
+
+
+ public java.awt.Color getBackground();
+
+
+ public java.awt.Rectangle getBounds();
+
+
+ public void invalidate();
+
+
+ public boolean hasFocus();
+
+
+ public void show( boolean oj_param0 );
+
+
+ public java.awt.Dimension getSize();
+
+
+ public java.awt.Font getFont();
+
+
+ public boolean mouseUp( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public boolean imageUpdate( java.awt.Image oj_param0, int oj_param1, int oj_param2, int oj_param3, int oj_param4, int oj_param5 );
+
+
+ public boolean prepareImage( java.awt.Image oj_param0, java.awt.image.ImageObserver oj_param1 );
+
+
+ public java.awt.Image createImage( java.awt.image.ImageProducer oj_param0 );
+
+
+ public void add( java.awt.Component oj_param0, java.lang.Object oj_param1, int oj_param2 );
+
+
+ public int getX();
+
+
+ public java.awt.Container getParent();
+
+
+ public java.awt.dnd.DropTarget getDropTarget();
+
+
+ public boolean lostFocus( java.awt.Event oj_param0, java.lang.Object oj_param1 );
+
+
+ public void enable( boolean oj_param0 );
+
+
+ public void addKeyListener( java.awt.event.KeyListener oj_param0 );
+
+
+ public void setSize( java.awt.Dimension oj_param0 );
+
+
+ public void paint( java.awt.Graphics oj_param0 );
+
+
+ public java.awt.Rectangle getBounds( java.awt.Rectangle oj_param0 );
+
+
+ public void removeFocusListener( java.awt.event.FocusListener oj_param0 );
+
+
+ public void removeAll();
+
+
+ public float getAlignmentY();
+
+
+ public boolean isFocusTraversable();
+
+
+ public void enable();
+
+
+ public java.awt.Rectangle bounds();
+
+
+ public java.awt.Component locate( int oj_param0, int oj_param1 );
+
+
+ public java.awt.im.InputContext getInputContext();
+
+
+ public boolean keyDown( java.awt.Event oj_param0, int oj_param1 );
+
+
+ public void addPropertyChangeListener( java.beans.PropertyChangeListener oj_param0 );
+
+
+ public java.awt.Component add( java.awt.Component oj_param0 );
+
+
+ public void printComponents( java.awt.Graphics oj_param0 );
+
+
+ public java.awt.LayoutManager getLayout();
+
+
+ public void paintAll( java.awt.Graphics oj_param0 );
+
+
+ public void addMouseListener( java.awt.event.MouseListener oj_param0 );
+
+
+ public java.awt.Component add( java.lang.String oj_param0, java.awt.Component oj_param1 );
+
+
+ public void add( java.awt.Component oj_param0, java.lang.Object oj_param1 );
+
+
+ public void addContainerListener( java.awt.event.ContainerListener oj_param0 );
+
+
+ public void hide();
+
+
+ public void list( java.io.PrintStream oj_param0 );
+
+
+ public void enableInputMethods( boolean oj_param0 );
+
+
+ public void transferFocus();
+
+
+ public java.awt.im.InputMethodRequests getInputMethodRequests();
+
+
+ public java.awt.Insets getInsets();
+
+
+ public void setCursor( java.awt.Cursor oj_param0 );
+
+
+ public boolean mouseMove( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void setBackground( java.awt.Color oj_param0 );
+
+
+ public void setDropTarget( java.awt.dnd.DropTarget oj_param0 );
+
+
+ public boolean isLightweight();
+
+
+ public void repaint( int oj_param0, int oj_param1, int oj_param2, int oj_param3 );
+
+
+ public void remove( java.awt.Component oj_param0 );
+
+
+ public boolean isAncestorOf( java.awt.Component oj_param0 );
+
+
+ public boolean postEvent( java.awt.Event oj_param0 );
+
+
+ public boolean isDoubleBuffered();
+
+
+ public int getWidth();
+
+
+ public java.awt.Component findComponentAt( java.awt.Point oj_param0 );
+
+
+ public boolean handleEvent( java.awt.Event oj_param0 );
+
+
+ public java.awt.Graphics getGraphics();
+
+
+ public void validate();
+
+
+ public java.awt.Color getForeground();
+
+
+ public void list( java.io.PrintWriter oj_param0, int oj_param1 );
+
+
+ public void removeMouseMotionListener( java.awt.event.MouseMotionListener oj_param0 );
+
+
+ public void setLayout( java.awt.LayoutManager oj_param0 );
+
+}
diff --git a/tutorial/examples/freeargs/Collection.java b/tutorial/examples/freeargs/Collection.java
new file mode 100644
index 0000000..74fff0f
--- /dev/null
+++ b/tutorial/examples/freeargs/Collection.java
@@ -0,0 +1,61 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Collection.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import examples.freeargs.FreeArgsClass;
+import examples.print.*;
+
+
+/**
+ * The class <code>Collection</code> represents a collection of objects.
+ */
+public class Collection
+{
+
+ private java.lang.Object[] contents;
+
+ public Collection()
+ {
+ contents = new java.lang.Object[0];
+ }
+
+ public boolean isEmpty()
+ {
+ return contents.length == 0;
+ }
+
+ /** Accepts any number of arguments. */
+ public void set( java.lang.Object[] args )
+ {
+ contents = new java.lang.Object[args.length];
+ System.arraycopy( args, 0, contents, 0, args.length );
+ }
+
+ /** Accepts any number of arguments. */
+ public void add( java.lang.Object[] args )
+ {
+ java.lang.Object[] old = contents;
+ contents = new java.lang.Object[old.length + args.length];
+ System.arraycopy( old, 0, contents, 0, old.length );
+ System.arraycopy( args, 0, contents, old.length, args.length );
+ }
+
+ public int size()
+ {
+ return contents.length;
+ }
+
+ /** Obtains a specified object. */
+ public java.lang.Object get( int i )
+ {
+ return contents[i];
+ }
+
+}
diff --git a/tutorial/examples/freeargs/Collection.oj b/tutorial/examples/freeargs/Collection.oj
new file mode 100644
index 0000000..77e4c81
--- /dev/null
+++ b/tutorial/examples/freeargs/Collection.oj
@@ -0,0 +1,52 @@
+/*
+ * Collection.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import examples.freeargs.FreeArgsClass;
+import examples.print.*;
+
+
+/**
+ * The class <code>Collection</code> represents a collection of objects.
+ */
+public class Collection instantiates FreeArgsClass
+{
+
+ private Object[] contents;
+
+ public Collection() {
+ contents = new Object[0];
+ }
+
+ public boolean isEmpty() {
+ return (contents.length == 0);
+ }
+
+ /** Accepts any number of arguments. */
+ public generous void set( Object[] args ) {
+ contents = new Object[args.length];
+ System.arraycopy( args, 0, contents, 0, args.length );
+ }
+
+ /** Accepts any number of arguments. */
+ public generous void add( Object[] args ) {
+ Object[] old = contents;
+ contents = new Object[old.length + args.length];
+ System.arraycopy( old, 0, contents, 0, old.length );
+ System.arraycopy( args, 0, contents, old.length, args.length );
+ }
+
+ public int size() {
+ return contents.length;
+ }
+
+ /** Obtains a specified object. */
+ public Object get( int i ) {
+ return contents[i];
+ }
+
+}
diff --git a/tutorial/examples/freeargs/FreeArgsClass.java b/tutorial/examples/freeargs/FreeArgsClass.java
new file mode 100644
index 0000000..2349869
--- /dev/null
+++ b/tutorial/examples/freeargs/FreeArgsClass.java
@@ -0,0 +1,117 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * FreeArgsClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>FreeArgsClass</code> provides classes with
+ * a facility of methods to accept unknown number of arguments.
+ * <p>
+ * For example, for the class:
+ * <pre>
+ * class MyCollection instantiates FreeArgsClass {
+ * public generous add( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * We can use the class above as follows:
+ * <pre>
+ * MyCollection collection = ..;
+ * collection.add( a, b, null, c, d );
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class FreeArgsClass extends openjava.mop.OJClass
+{
+
+ private static final java.lang.String GENEROUS = "generous";
+
+ /** Translates definition */
+ public void translateDefinition()
+ throws openjava.mop.MOPException
+ {
+ openjava.mop.OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().has( GENEROUS )) {
+ continue;
+ }
+ System.err.println( methods[i] );
+ openjava.mop.OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || !paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public openjava.mop.OJMethod resolveException( openjava.mop.NoSuchMemberException e, java.lang.String name, openjava.mop.OJClass[] params )
+ throws openjava.mop.NoSuchMemberException
+ {
+ try {
+ java.lang.String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ openjava.mop.OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new openjava.mop.OJClass[]{ paramtype }, this );
+ }
+ } catch ( openjava.mop.OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public openjava.ptree.Expression expandMethodCall( openjava.mop.Environment env, openjava.ptree.MethodCall expr )
+ {
+ java.lang.String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) {
+ return expr;
+ }
+ openjava.mop.OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( openjava.mop.OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ openjava.ptree.ExpressionList dim = new openjava.ptree.ExpressionList( null );
+ openjava.ptree.ArrayInitializer ainit = new openjava.ptree.ArrayInitializer( expr.getArguments() );
+ openjava.ptree.ArrayAllocationExpression carrier = new openjava.ptree.ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new openjava.ptree.ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( java.lang.String keyword )
+ {
+ if (keyword.equals( GENEROUS )) {
+ return true;
+ }
+ return false;
+ }
+
+ public FreeArgsClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public FreeArgsClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/freeargs/FreeArgsClass.oj b/tutorial/examples/freeargs/FreeArgsClass.oj
new file mode 100644
index 0000000..aba5b41
--- /dev/null
+++ b/tutorial/examples/freeargs/FreeArgsClass.oj
@@ -0,0 +1,95 @@
+/*
+ * FreeArgsClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>FreeArgsClass</code> provides classes with
+ * a facility of methods to accept unknown number of arguments.
+ * <p>
+ * For example, for the class:
+ * <pre>
+ * class MyCollection instantiates FreeArgsClass {
+ * public generous add( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * We can use the class above as follows:
+ * <pre>
+ * MyCollection collection = ..;
+ * collection.add( a, b, null, c, d );
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class FreeArgsClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/freeargs/Test.java b/tutorial/examples/freeargs/Test.java
new file mode 100644
index 0000000..7f2c928
--- /dev/null
+++ b/tutorial/examples/freeargs/Test.java
@@ -0,0 +1,32 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Test.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import java.lang.Object;
+
+
+/**
+ * Just a test.
+ */
+public class Test
+{
+
+ /**
+ * This is main method.
+ */
+ public static void main( java.lang.String[] args )
+ {
+ examples.freeargs.Collection c = new examples.freeargs.Collection();
+ c.set( new java.lang.Object[]{ new java.lang.Integer( args.length ), args[0], args[1] } );
+ c.add( new java.lang.Object[]{ new java.lang.Integer( args.length ), args[0], args[1] } );
+ System.out.println( c.size() );
+ }
+
+}
diff --git a/tutorial/examples/freeargs/Test.oj b/tutorial/examples/freeargs/Test.oj
new file mode 100644
index 0000000..86a6cc9
--- /dev/null
+++ b/tutorial/examples/freeargs/Test.oj
@@ -0,0 +1,28 @@
+/*
+ * Test.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import java.lang.Object;
+
+
+/**
+ * Just a test.
+ */
+public class Test
+{
+
+ /**
+ * This is main method.
+ */
+ public static void main( String[] args ) {
+ Collection c = new Collection();
+ c.set( new Integer( args.length ), args[0], args[1] );
+ c.add( new Integer( args.length ), args[0], args[1] );
+ System.out.println( c.size() );
+ }
+
+}
diff --git a/tutorial/examples/mixin/0UNDERCONSTRUCTION b/tutorial/examples/mixin/0UNDERCONSTRUCTION
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tutorial/examples/mixin/0UNDERCONSTRUCTION
diff --git a/tutorial/examples/mixin/MixinedClass.java b/tutorial/examples/mixin/MixinedClass.java
new file mode 100644
index 0000000..c281fb9
--- /dev/null
+++ b/tutorial/examples/mixin/MixinedClass.java
@@ -0,0 +1,124 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * MixinedClass.oj
+ *
+ * An OpenJava example for incorporating mixin mechanism.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.mixin;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>MixinedClass</code> supports classes
+ * using mixin.
+ * <p>
+ * For example, the class <code>MixinedClass</code>:
+ * <pre>
+ * public class TextboxWithUndo instantiates MixinedClass
+ * extends Textbox mixs Undo
+ * {
+ * }
+ * </pre>
+ * would be automatically implemented.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MixinedClass.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class MixinedClass extends OJClass
+{
+
+ public static final String KEY_MIXES = "mixes";
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJClass[] mixinClasses = getMixins();
+ for (int i = 0; i < mixinClasses.length; ++i) {
+ incorporateMixin( mixinClasses[i] );
+ }
+ }
+
+ public void incorporateMixin( OJClass mixinClazz )
+ throws MOPException
+ {
+ addInterface( mixinClazz );
+ OJMethod[] mixeds = mixinClazz.getMethods();
+ for (int i = 0; i < mixeds.length; ++i) {
+ addMethod( makeEmptyMethod( mixeds[i] ) );
+ }
+ }
+
+ /**
+ * Generates a empty method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated empty method.
+ */
+ private OJMethod makeEmptyMethod( OJMethod implementee )
+ throws MOPException
+ {
+ StatementList body = new StatementList();
+ if (implementee.getReturnType() == OJSystem.VOID) {
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( Literal.constantNull() ) );
+ }
+ return new OJMethod( this, implementee.getModifiers().remove( OJModifier.ABSTRACT ), implementee.getReturnType(), implementee.getName(), implementee.getParameterTypes(), implementee.getExceptionTypes(), body );
+ }
+
+ /* extended information */
+ private OJClass[] getMixins()
+ throws MOPException
+ {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_MIXES );
+ OJClass[] result = new OJClass[suffix.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = OJClass.forName( suffix.get( i ).toString() );
+ }
+ return result;
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword )
+ {
+ return keyword.equals( KEY_MIXES );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword )
+ {
+ if (keyword.equals( KEY_MIXES )) {
+ return new DefaultListRule( new TypeNameRule(), TokenID.COMMA );
+ }
+ return null;
+ }
+
+ public MixinedClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public MixinedClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/mixin/MixinedClass.oj b/tutorial/examples/mixin/MixinedClass.oj
new file mode 100644
index 0000000..8883948
--- /dev/null
+++ b/tutorial/examples/mixin/MixinedClass.oj
@@ -0,0 +1,115 @@
+/*
+ * MixinedClass.oj
+ *
+ * An OpenJava example for incorporating mixin mechanism.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.mixin;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>MixinedClass</code> supports classes
+ * using mixin.
+ * <p>
+ * For example, the class <code>MixinedClass</code>:
+ * <pre>
+ * public class TextboxWithUndo instantiates MixinedClass
+ * extends Textbox mixs Undo
+ * {
+ * }
+ * </pre>
+ * would be automatically implemented.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class MixinedClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_MIXES = "mixes";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass[] mixinClasses = getMixins();
+
+ for (int i = 0; i < mixinClasses.length; ++i) {
+ incorporateMixin(mixinClasses[i]);
+ }
+ }
+
+ public void incorporateMixin(OJClass mixinClazz) throws MOPException {
+ /* implicit forwarding to the same signature's */
+ addInterface(mixinClazz);
+ OJMethod[] mixeds = mixinClazz.getMethods();
+ for (int i = 0; i < mixeds.length; ++i) {
+ /* generate a forwarding method with forwarded's name */
+ addMethod(makeEmptyMethod(mixeds[i]));
+ }
+ }
+
+ /**
+ * Generates a empty method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated empty method.
+ */
+ private OJMethod makeEmptyMethod(OJMethod implementee)
+ throws MOPException
+ {
+ /* generates a return statement */
+ StatementList body = new StatementList();
+ if (implementee.getReturnType() == OJSystem.VOID) {
+ body.add(new ReturnStatement());
+ } else {
+ body.add(new ReturnStatement(Literal.constantNull()));
+ }
+
+ /* generates a new method without body */
+ return new OJMethod( this,
+ implementee.getModifiers().remove(OJModifier.ABSTRACT),
+ implementee.getReturnType(), implementee.getName(),
+ implementee.getParameterTypes(), implementee.getExceptionTypes(),
+ body );
+ }
+
+ /* extended information */
+
+ private OJClass[] getMixins() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix(KEY_MIXES);
+ OJClass[] result = new OJClass[suffix.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = OJClass.forName(suffix.get(i).toString());
+ }
+ return result;
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_MIXES );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_MIXES )) {
+ return new DefaultListRule(new TypeNameRule(), TokenID.COMMA);
+ }
+ return null;
+ }
+
+}
+
diff --git a/tutorial/examples/mixin/Textbox.java b/tutorial/examples/mixin/Textbox.java
new file mode 100644
index 0000000..5b0e06b
--- /dev/null
+++ b/tutorial/examples/mixin/Textbox.java
@@ -0,0 +1,23 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.mixin;
+
+
+public class Textbox extends java.awt.Component
+{
+
+ String text = null;
+
+ /* ..... */
+ public String getText()
+ {
+ return text;
+ }
+
+ public void setText( String s )
+ {
+ text = s;
+ }
+
+}
diff --git a/tutorial/examples/mixin/Textbox.oj b/tutorial/examples/mixin/Textbox.oj
new file mode 100644
index 0000000..a3313d0
--- /dev/null
+++ b/tutorial/examples/mixin/Textbox.oj
@@ -0,0 +1,17 @@
+package examples.mixin;
+
+
+public class Textbox extends java.awt.Component
+{
+ String text = null;
+
+ /* ..... */
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String s) {
+ text = s;
+ }
+}
diff --git a/tutorial/examples/mixin/TextboxWithUndo.java b/tutorial/examples/mixin/TextboxWithUndo.java
new file mode 100644
index 0000000..9772e62
--- /dev/null
+++ b/tutorial/examples/mixin/TextboxWithUndo.java
@@ -0,0 +1,22 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.mixin;
+
+
+public class TextboxWithUndo extends Textbox implements examples.mixin.Undo
+{
+
+
+ public void setText( java.lang.String oj_param0 )
+ {
+ return;
+ }
+
+
+ public void undo()
+ {
+ return;
+ }
+
+}
diff --git a/tutorial/examples/mixin/TextboxWithUndo.oj b/tutorial/examples/mixin/TextboxWithUndo.oj
new file mode 100644
index 0000000..cc04f88
--- /dev/null
+++ b/tutorial/examples/mixin/TextboxWithUndo.oj
@@ -0,0 +1,8 @@
+package examples.mixin;
+
+
+public class TextboxWithUndo instantiates MixinedClass
+ extends Textbox
+ mixes Undo
+{
+}
diff --git a/tutorial/examples/mixin/Undo.java b/tutorial/examples/mixin/Undo.java
new file mode 100644
index 0000000..a7f6bfb
--- /dev/null
+++ b/tutorial/examples/mixin/Undo.java
@@ -0,0 +1,8 @@
+package examples.mixin;
+
+
+public interface Undo
+{
+ public void setText(String s);
+ public void undo();
+}
diff --git a/tutorial/examples/mixin/Undo.oj b/tutorial/examples/mixin/Undo.oj
new file mode 100644
index 0000000..66ad9a9
--- /dev/null
+++ b/tutorial/examples/mixin/Undo.oj
@@ -0,0 +1,19 @@
+package examples.mixin;
+
+
+public class Undo
+{
+ inherited String getText();
+ inherited void setText(String s);
+
+ String lastText;
+
+ public void setText(String s) {
+ lastText = getText();
+ super.setText(s);
+ }
+
+ public void undo() {
+ super.setText(lastText);
+ }
+}
diff --git a/tutorial/examples/multimeta/CombinedClass.oj b/tutorial/examples/multimeta/CombinedClass.oj
new file mode 100644
index 0000000..703f871
--- /dev/null
+++ b/tutorial/examples/multimeta/CombinedClass.oj
@@ -0,0 +1,397 @@
+/*
+ * CombinedClass.oj
+ *
+ * Oct 24, 2000 by Michiaki Tatsubori
+ */
+package examples.multimeta;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import java.util.*;
+import java.lang.reflect.*;
+
+
+/**
+ * The metaclass <code>CombinedClass</code> provides a class to be
+ * bound to more than one metaclass.
+ * <p>
+ * An usage are:
+ * <pre>
+ * class MyPerson instantiates CombinedClass
+ * extends Object implements Runnable
+ * obeys PersistableClass, TransactionableClass
+ * {
+ * ...
+ * }
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class CombinedClass instantiates Metaclass extends OJClass
+{
+ private static final String KEYWORD_OBEYS = "obeys";
+
+ /**
+ * Composing class metaobjects.
+ */
+ protected OJClass[] substances = null;
+
+ public CombinedClass(Class javaclazz, MetaInfo metainfo) {
+ super(javaclazz, metainfo);
+ initializeSubstantialMetaclasses(javaclazz, metainfo);
+ }
+
+ /**
+ * Initializes the substantial class metaobjects, which were specified
+ * by the "obeys" phrase in the class declaration.
+ */
+ private void initializeSubstantialMetaclasses(Class javaclazz,
+ MetaInfo metainfo) {
+ int cnum = 0;
+ while (metainfo.get(KEYWORD_OBEYS + cnum) != null) ++cnum;
+ substances = new OJClass[cnum];
+ for (int i = 0; i < substances.length; ++i) {
+ String cname = metainfo.get(KEYWORD_OBEYS + i);
+ /* Do not use OJClass.forClass() here. It would changes
+ * the bind of the metaclass to the class name.
+ * The substantial class metaobjects must be created directly.
+ */
+ try {
+ Class clazz = Class.forName(cname);
+ Constructor cons = clazz.getConstructor(new Class[] {
+ Class.class, MetaInfo.class });
+ substances[i] = (OJClass) cons.newInstance(new Object[] {
+ javaclazz, metainfo});
+ } catch (Exception ex) {
+ throw new Error(ex.toString());
+ }
+ }
+ }
+
+ public CombinedClass(Environment env, OJClass declaring,
+ ClassDeclaration cdecl) {
+ super(env, declaring, cdecl);
+ }
+
+ /**
+ * Translates the declaration part of base classes.
+ */
+ public void translateDefinition() throws MOPException {
+ initializeSubstantialMetaclasses();
+
+ System.out.println("The class " + getName() +
+ " obeys the specified substantial metaclass/es :");
+ for (int i = 0; i < substances.length; ++i) {
+ System.out.println(substances[i].getClass().getName());
+ substances[i].translateDefinition();
+ }
+ }
+
+ /**
+ * Initializes the substantial class metaobjects, which are specified
+ * by the "obeys" phrase.
+ */
+ private void initializeSubstantialMetaclasses() throws MOPException {
+ String[] metaclazz = getSubstantialMetaclasses();
+
+ for (int i = 0; i < metaclazz.length; ++i) {
+ putMetaInfo(KEYWORD_OBEYS + i, metaclazz[i]);
+ }
+
+ substances = new OJClass[metaclazz.length];
+ for (int i = 0; i < substances.length; ++i) {
+ String cname = metaclazz[i];
+ /* Do not use OJClass.forParseTree() here. It would changes
+ * the bind of the metaclass to the class name
+ * The substantial class metaobjects must be created directly.
+ */
+ try {
+ Class clazz = Class.forName(cname);
+ Constructor cons = clazz.getConstructor(new Class[] {
+ Environment.class, OJClass.class,
+ ClassDeclaration.class });
+ Environment env = getEnvironment();
+ OJClass declaring = getDeclaringClass();
+ ClassDeclaration cdecl = getSourceCode();
+ substances[i] = (OJClass) cons.newInstance(new Object[] {
+ env, declaring, cdecl});
+ } catch (Exception ex) {
+ throw new Error(ex.toString());
+ }
+ }
+ }
+
+ private String[] getSubstantialMetaclasses() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix(KEYWORD_OBEYS);
+ String[] result = new String[suffix.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = suffix.get(i).toString();
+ }
+ return result;
+ }
+
+ private static Vector modifVec = new Vector();
+ private static Hashtable keyTable = new Hashtable();
+
+ /**
+ * Metaclasses of the parsing class declaration.
+ */
+ private static Class[] metaclasses = null;
+
+ /* Extends syntax for custom modifiers */
+ public static boolean isRegisteredModifier(String keyword) {
+ if (metaclasses == null) {
+ System.err.println("No consultant for modifiers!");
+ return false;
+ }
+
+ for (int i = 0; i < metaclasses.length; ++i) {
+ Class c = metaclasses[i];
+ System.err.println("Consulting " + c +
+ " for the syntax of modifiers");
+ try {
+ Method m = c.getMethod("isRegisteredModifier",
+ new Class[] {String.class});
+ Boolean result
+ = (Boolean) m.invoke(null, new Object[] {keyword});
+ if (result.booleanValue() == true) return true;
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ return false;
+ }
+
+ /* Extends syntax for custom suffix phrases */
+ public static boolean isRegisteredKeyword(String keyword) {
+ if (keyword.equals(KEYWORD_OBEYS)) return true;
+
+ if (metaclasses == null) {
+ System.err.println("No consultant for suffix phrases!");
+ return false;
+ }
+
+ for (int i = 0; i < metaclasses.length; ++i) {
+ Class c = metaclasses[i];
+ System.err.println("Consulting " + c +
+ " for the syntax of suffix phrases");
+ try {
+ Method m = c.getMethod("isRegisteredKeyword",
+ new Class[] {String.class});
+ Boolean result
+ = (Boolean) m.invoke(null, new Object[] {keyword});
+ if (result.booleanValue() == true) return true;
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ return false;
+ }
+
+ /* Extends syntax for custom suffix phrases */
+ public static SyntaxRule getDeclSuffixRule(String keyword) {
+ if (keyword.equals(KEYWORD_OBEYS)) {
+ /* The returned rule object is hacked to call back and register
+ * type names them.
+ */
+ System.err.println("Consultants dismissed");
+ metaclasses = null;
+ return new HackedTypeNameListRule(new TypeNameParsingListener() {
+ public void addTypeName(String tname) {
+ System.err.println("Found a consultant " + tname);
+
+ Class[] old = metaclasses;
+ if (old == null) {
+ metaclasses = new Class[1];
+ } else {
+ metaclasses = new Class[old.length + 1];
+ for (int i = 0; i < old.length; ++i) {
+ metaclasses[i] = old[i];
+ }
+ }
+ try {
+ Class mc = Class.forName(tname);
+ metaclasses[metaclasses.length - 1] = mc;
+ } catch (ClassNotFoundException ex) {
+ System.err.println(ex);
+ metaclasses = old;
+ }
+ }
+ });
+ }
+
+ if (metaclasses == null) {
+ System.err.println("No consultant for suffix phrases!");
+ return null;
+ }
+
+ for (int i = 0; i < metaclasses.length; ++i) {
+ Class c = metaclasses[i];
+ System.err.println("Consulting " + c +
+ " for the syntax of suffix phrases");
+ try {
+ Method m = c.getMethod("getDeclSuffixRule",
+ new Class[] {String.class});
+ SyntaxRule result
+ = (SyntaxRule) m.invoke(null, new Object[] {keyword});
+ if (result != null) return result;
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ return null;
+ }
+
+ /* -- Caller-side expansions -- */
+
+ public Expression expandFieldRead(Environment env, FieldAccess expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandFieldRead(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandFieldRead(env, expr);
+ }
+
+ public Expression expandFieldWrite(Environment env,
+ AssignmentExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandFieldWrite(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandFieldWrite(env, expr);
+ }
+
+ public Expression expandMethodCall(Environment env,
+ MethodCall expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandMethodCall(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandMethodCall(env, expr);
+ }
+
+ public TypeName expandTypeName(Environment env, TypeName tname) {
+ TypeName result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandTypeName(env, tname);
+ if (result != tname) return result;
+ }
+ return super.expandTypeName(env, tname);
+ }
+
+ public Expression expandAllocation(Environment env,
+ AllocationExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandAllocation(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandAllocation(env, expr);
+ }
+
+ public Expression expandArrayAllocation(Environment env,
+ ArrayAllocationExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandArrayAllocation(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandArrayAllocation(env, expr);
+ }
+
+ public Expression expandArrayAccess(Environment env, ArrayAccess expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandArrayAccess(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandArrayAccess(env, expr);
+ }
+
+ public Expression expandAssignmentExpression(Environment env,
+ AssignmentExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandAssignmentExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandAssignmentExpression(env, expr);
+ }
+
+ public Expression expandExpression(Environment env,
+ Expression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandExpression(env, expr);
+ }
+
+ public Statement expandVariableDeclaration(Environment env,
+ VariableDeclaration decl) {
+ Statement result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandVariableDeclaration(env, decl);
+ if (result != decl) return result;
+ }
+ return super.expandVariableDeclaration(env, decl);
+ }
+
+ public Expression expandCastExpression(Environment env,
+ CastExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandCastExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandCastExpression(env, expr);
+ }
+
+ public Expression expandCastedExpression(Environment env,
+ CastExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandCastedExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandCastedExpression(env, expr);
+ }
+
+ /* -- Error handlings -- */
+
+ public OJField resolveException(NoSuchMemberException nmex, String name)
+ throws NoSuchMemberException
+ {
+ for (int i = 0; i < substances.length; ++i) {
+ try {
+ return substances[i].resolveException(nmex, name);
+ } catch (NoSuchMemberException ex) {}
+ }
+ return super.resolveException(nmex, name);
+ }
+
+ public OJMethod resolveException( NoSuchMemberException nmex,
+ String name, OJClass[] argtypes)
+ throws NoSuchMemberException
+ {
+ for (int i = 0; i < substances.length; ++i) {
+ try {
+ return substances[i].resolveException(nmex, name, argtypes);
+ } catch (NoSuchMemberException ex) {}
+ }
+ return super.resolveException(nmex, name, argtypes);
+ }
+
+}
diff --git a/tutorial/examples/multimeta/MyPerson.oj b/tutorial/examples/multimeta/MyPerson.oj
new file mode 100644
index 0000000..2fccfa0
--- /dev/null
+++ b/tutorial/examples/multimeta/MyPerson.oj
@@ -0,0 +1,15 @@
+package examples.multimeta;
+
+
+import examples.verbose.VerboseClass;
+import examples.capsule.CapsuleClass;
+
+
+public class MyPerson instantiates CombinedClass
+ extends Object implements Runnable
+ obeys VerboseClass, CapsuleClass
+{
+ public String name;
+ public int age;
+ public void run() {}
+}
diff --git a/tutorial/examples/multimeta/MyPerson2.oj b/tutorial/examples/multimeta/MyPerson2.oj
new file mode 100644
index 0000000..3a13f8c
--- /dev/null
+++ b/tutorial/examples/multimeta/MyPerson2.oj
@@ -0,0 +1,15 @@
+package examples.multimeta;
+
+
+import examples.verbose.VerboseClass;
+import examples.orcheck.OverridingClass;
+
+
+public class MyPerson2 instantiates CombinedClass
+ extends Object implements Runnable
+ obeys VerboseClass, OverridingClass
+{
+ public String name;
+ public int age;
+ public overriding void run() {}
+}
diff --git a/tutorial/examples/multimeta/MyPerson3.oj b/tutorial/examples/multimeta/MyPerson3.oj
new file mode 100644
index 0000000..484e003
--- /dev/null
+++ b/tutorial/examples/multimeta/MyPerson3.oj
@@ -0,0 +1,14 @@
+package examples.multimeta;
+
+
+import examples.verbose.VerboseClass;
+
+
+public class MyPerson3 instantiates CombinedClass
+ extends Object implements Runnable
+ obeys VerboseClass, VerboseClass, VerboseClass, VerboseClass
+{
+ public String name;
+ public int age;
+ public void run() {}
+}
diff --git a/tutorial/examples/multimethod/MultimethodClass.java b/tutorial/examples/multimethod/MultimethodClass.java
new file mode 100644
index 0000000..4a81938
--- /dev/null
+++ b/tutorial/examples/multimethod/MultimethodClass.java
@@ -0,0 +1,169 @@
+/*
+ * MultimethodClass.oj
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.multimethod;
+
+
+import java.util.*;
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+/**
+ * The class <code>MultimethodClass</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MultimethodClass.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class MultimethodClass extends OJClass
+{
+ private static final String MULTIFORM = "multiform";
+ private static final String RUNTIME_EXCEPTION
+ = "examples.multimethod.NoAddaptableMethodException";
+
+ public void translateDefinition() throws MOPException {
+ Hashtable table = new Hashtable();
+ OJMethod[] m = getDeclaredMethods();
+
+ for (int i = 0; i < m.length; ++i) {
+ if (! m[i].getModifiers().has( MULTIFORM )) continue;
+ ParameterSetTree set
+ = (ParameterSetTree) table.get( makeHashkey( m[i] ) );
+ if (set != null) {
+ set.add( m[i] );
+ } else {
+ set = new ParameterSetTree( m[i].getParameterTypes(), m[i] );
+ }
+ table.put( makeHashkey( m[i] ), set );
+ }
+
+ Enumeration ite = table.elements();
+ while (ite.hasMoreElements()) {
+ ParameterSetTree set = (ParameterSetTree) ite.nextElement();
+ modifyToBeGeneric( set );
+ System.out.println( set );
+ }
+ }
+
+ private void modifyToBeGeneric( ParameterSetTree set )
+ throws MOPException
+ {
+ if (! set.hasChildren()) return;
+
+ OJMethod method = set.getValue();
+ if (method == null) addMethod( (method = genSelector( set )) );
+
+ StatementList result = new StatementList();
+ ParameterSetTree[] children = set.getChildren();
+ for (int i = 0; i < children.length; ++i) {
+ Expression cond
+ = makeCond( method, children[i].getParameterTypes() );
+ StatementList ifbody
+ = makeQualifiedCall( method, children[i].getParameterTypes() );
+ result.add( new IfStatement( cond, ifbody ) );
+ modifyToBeGeneric( children[i] );
+ }
+ result.addAll( method.getBody() );
+ method.addExceptionType( OJClass.forName( RUNTIME_EXCEPTION ) );
+ method.setBody( result );
+ }
+
+ /* generates a method only for testing params to invoke another */
+ private OJMethod genSelector( ParameterSetTree set )
+ throws MOPException
+ {
+ /* representer of other features such as throwing exceptions */
+ OJMethod rep = pickupOne( set );
+ return new OJMethod(
+ this, rep.getModifiers(), rep.getReturnType(), rep.getName(),
+ set.getParameterTypes(), rep.getExceptionTypes(),
+ makeStatementList( "throw new " + RUNTIME_EXCEPTION + "();" )
+ );
+ }
+
+ private static Expression makeCond( OJMethod holder, OJClass[] ptypes )
+ throws MOPException
+ {
+ String[] params = holder.getParameters();
+ StringBuffer strbuf = new StringBuffer();
+ for (int i = 0; i < ptypes.length; ++i) {
+ if (i != 0) strbuf.append( " && " );
+ strbuf.append( "(" );
+ strbuf.append( params[i] );
+ strbuf.append( " instanceof " );
+ strbuf.append( ptypes[i].getName() );
+ strbuf.append( ")" );
+ }
+ return makeExpression( holder.getEnvironment(), strbuf.toString() );
+ }
+
+ private static StatementList
+ makeQualifiedCall( OJMethod holder, OJClass[] ptypes )
+ throws MOPException
+ {
+ String[] params = holder.getParameters();
+ StringBuffer strbuf = new StringBuffer();
+ strbuf.append( "this." ).append( holder.getName() ).append( "( " );
+ for (int i = 0; i < ptypes.length; ++i) {
+ if (i != 0) strbuf.append( ", " );
+ strbuf.append( "(" ).append( ptypes[i].getName() ).append( ") " );
+ strbuf.append( params[i] );
+ }
+ strbuf.append( " )" );
+ Expression mtdcall
+ = makeExpression( holder.getEnvironment(), strbuf.toString() );
+
+ StatementList result = new StatementList();
+ if (holder.getReturnType() == OJSystem.VOID) {
+ result.add( new ExpressionStatement( mtdcall ) );
+ result.add( new ReturnStatement() );
+ } else {
+ result.add( new ReturnStatement( mtdcall ) );
+ }
+ return result;
+ }
+
+ private static String makeHashkey( OJMethod method ) {
+ return method.getReturnType().getName() + "%" + method.getName() +
+ "%" + method.getParameterTypes().length;
+ }
+
+ private static OJMethod pickupOne( ParameterSetTree set ) {
+ while (set.getChildren().length != 0) set = set.getChildren()[0];
+ return set.getValue();
+ }
+
+ /* syntax extension */
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ return keyword.equals( MULTIFORM );
+ }
+
+ /* constructors */
+
+ public MultimethodClass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree )
+ {
+ super( outer_env, declarer, ptree );
+ }
+
+ public MultimethodClass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+}
diff --git a/tutorial/examples/multimethod/NoAddaptableMethodException.java b/tutorial/examples/multimethod/NoAddaptableMethodException.java
new file mode 100644
index 0000000..c51b2c0
--- /dev/null
+++ b/tutorial/examples/multimethod/NoAddaptableMethodException.java
@@ -0,0 +1,24 @@
+/*
+ * NoAddaptableMethodException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.multimethod;
+
+
+import java.lang.Exception;
+
+
+/**
+ * The exception <code>NoAddaptableMethodException</code> is thrown
+ * in case that there is no method addaptable to given parameters.
+ * <p>
+ *
+ * @see examples.multimethod.MultiMethodClass
+ */
+public class NoAddaptableMethodException extends Exception
+{}
diff --git a/tutorial/examples/multimethod/ParameterSetTree.java b/tutorial/examples/multimethod/ParameterSetTree.java
new file mode 100644
index 0000000..ad2845b
--- /dev/null
+++ b/tutorial/examples/multimethod/ParameterSetTree.java
@@ -0,0 +1,215 @@
+/*
+ * ParameterSetTree.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.multimethod;
+
+
+import java.util.*;
+import java.io.*;
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+/**
+ * The class <code>ParameterSetTree</code> sorts parameters set of method
+ * and hold it.
+ *
+ * @author Michiaki Tatsubori
+ * @see openjava.mop.OJMethod
+ */
+public class ParameterSetTree implements Cloneable
+{
+ private OJClass[] params;
+ private OJMethod value = null;
+ private ParameterSetTree[] children = new ParameterSetTree[0];
+
+ public ParameterSetTree( OJClass[] params, OJMethod value ) {
+ this.params = params;
+ this.value = value;
+ }
+
+ ParameterSetTree( OJClass[] params ) {
+ this( params, null );
+ }
+
+ public OJClass[] getParameterTypes() {
+ OJClass[] result = new OJClass[params.length];
+ System.arraycopy( params, 0, result, 0, params.length );
+ return result;
+ }
+
+ public OJMethod getValue() {
+ return value;
+ }
+
+ public ParameterSetTree[] getChildren() {
+ if (children.length == 0) return children;
+ ParameterSetTree[] result = new ParameterSetTree[children.length];
+ System.arraycopy( children, 0, result, 0, children.length );
+ return result;
+ }
+
+ public boolean hasChildren() {
+ return children.length != 0;
+ }
+
+ public String toString() {
+ StringWriter str_writer = new StringWriter();
+ PrintWriter out = new PrintWriter( str_writer );
+ writeState( out );
+ out.flush();
+ return str_writer.toString();
+ }
+
+ public void writeState( PrintWriter out ) {
+ writeState( out, 0 );
+ }
+
+ private void writeState( PrintWriter out, int level ) {
+ for (int i = 0; i < level; ++i) out.print( " " );
+
+ out.print( "{ ");
+ out.print( params[0].getName() );
+ for (int i = 1; i < params.length; ++i) {
+ out.print( "," );
+ out.print( params[i].getName() );
+ }
+ out.print( " } " );
+ out.println( value != null );
+
+ for (int i = 0; i < children.length; ++i) {
+ children[i].writeState( out, level + 1 );
+ }
+ }
+
+ /* must adjust tree */
+ OJMethod add( OJMethod method ) {
+ OJClass[] params = method.getParameterTypes();
+
+ if (this.isSameAs( params )) {
+ /* exactly same */
+ OJMethod result = this.value;
+ this.value = method;
+ return result;
+ }
+ if (this.isAssignableFrom( params )) {
+ /* a subset of this */
+ for (int i = 0; i < children.length; ++i) {
+ if (children[i].isAssignableFrom( params )) {
+ /* a subset of one of children */
+ return children[i].add( method );
+ }
+ }
+ addChild( new ParameterSetTree( params, method ) );
+ return null;
+ }
+
+ /* a superset or an independent order set of this */
+ ParameterSetTree copy = shallowCopy();
+ OJClass[] common = commonBaseTypes( this.params, params );
+ this.params = common;
+ this.value = null;
+ if (isAssignable( params, common )) {
+ /* a superset */
+ this.params = params;
+ this.value = method;
+ this.children = new ParameterSetTree[]{ copy };
+ } else {
+ /* a subset of the common superset */
+ this.params = common;
+ this.value = null;
+ this.children = new ParameterSetTree[]{
+ copy,
+ new ParameterSetTree( params, method ) };
+ }
+ return null;
+ }
+
+ private ParameterSetTree shallowCopy() {
+ try {
+ return (ParameterSetTree) clone();
+ } catch ( CloneNotSupportedException e ){
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Childrens must not have any smaller common set than this set.
+ */
+ private void addChild( ParameterSetTree newbie ) {
+ int tobelong = 0;
+ OJClass[] subcommon = null;
+
+ for (; tobelong < children.length; ++tobelong) {
+ subcommon = commonBaseTypes( newbie.params,
+ children[tobelong].params );
+ if (! isSameAs( subcommon )) break;
+ }
+
+ if (tobelong == children.length) {
+ /* simply add */
+ ParameterSetTree[] result
+ = new ParameterSetTree[children.length + 1];
+ System.arraycopy( children, 0, result, 0, children.length );
+ result[children.length] = newbie;
+ children = result;
+ return;
+ }
+
+ /* at least two has a sub common signature */
+ if (children[tobelong].isSameAs( subcommon )) {
+ /* newbie is a subset */
+ children[tobelong].addChild( newbie );
+ } else {
+ ParameterSetTree common_set = new ParameterSetTree( subcommon );
+ common_set.addChild( children[tobelong] );
+ common_set.addChild( newbie );
+ children[tobelong] = common_set;
+ }
+ }
+
+ public boolean isAssignableFrom( OJClass[] params ) {
+ return isAssignable( this.params, params );
+ }
+
+ public boolean isSameAs( OJClass[] params ) {
+ if (this.params.length != params.length) return false;
+ for (int i = 0; i < this.params.length; ++i) {
+ if (this.params[i] != params[i]) return false;
+ }
+ return true;
+ }
+
+ private static boolean isAssignable( OJClass[] p1, OJClass[] p2 ) {
+ if (p1.length != p2.length) return false;
+ for (int i = 0; i < p1.length; ++i) {
+ if (! p1[i].isAssignableFrom( p2[i] )) return false;
+ }
+ return true;
+ }
+
+ private static OJClass[] commonBaseTypes( OJClass[] a, OJClass b[] ) {
+ OJClass[] result = new OJClass[a.length];
+ for (int i = 0; i < a.length; ++i) {
+ result[i] = commonBaseType( a[i], b[i] );
+ }
+ return result;
+ }
+
+ /**
+ * this is also available in the class <code>Signature</code>
+ */
+ private static OJClass commonBaseType( OJClass a, OJClass b ) {
+ if (a.isAssignableFrom( b )) return a;
+ if (b.isAssignableFrom( a )) return b;
+ return commonBaseType( a.getSuperclass(), b.getSuperclass() );
+ }
+
+}
diff --git a/tutorial/examples/multimethod/Test.oj b/tutorial/examples/multimethod/Test.oj
new file mode 100644
index 0000000..49521a9
--- /dev/null
+++ b/tutorial/examples/multimethod/Test.oj
@@ -0,0 +1,52 @@
+package examples.multimethod;
+
+import java.awt.*;
+
+public class Test instantiates MultimethodClass
+{
+
+ public multiform void foo( Panel a ) {
+ System.out.println( "panel" );
+ }
+
+ public multiform void foo( Button a ) {
+ System.out.println( "button" );
+ }
+
+ public multiform void foo( Canvas a ) {
+ System.out.println( "canvas" );
+ }
+
+ public String toString() {
+ return super.toString();
+ }
+
+ public multiform String bar( Panel a, Button b ) {
+ return "panel";
+ }
+
+ public multiform String bar( Button a, Button b ) {
+ return "button";
+ }
+
+ public multiform String bar( Canvas a, Panel b ) {
+ return "canvas";
+ }
+
+ public multiform void foo( Panel a, Window b ) {
+ System.out.println( "panel" );
+ }
+
+ public multiform void foo( Button a, Dialog b ) {
+ System.out.println( "button" );
+ }
+
+ public multiform void foo( Canvas a, Dialog b ) {
+ System.out.println( "canvas" );
+ }
+
+ public multiform void foo( Canvas a, FileDialog b ) {
+ System.out.println( "canvas" );
+ }
+
+}
diff --git a/tutorial/examples/multimethod/Test2.oj b/tutorial/examples/multimethod/Test2.oj
new file mode 100644
index 0000000..e714e89
--- /dev/null
+++ b/tutorial/examples/multimethod/Test2.oj
@@ -0,0 +1,20 @@
+package examples.multimethod;
+
+import java.awt.*;
+
+public class Test2 instantiates MultimethodClass
+{
+
+ public multiform void foo( Panel a ) {
+ System.out.println( "panel" );
+ }
+
+ public multiform void foo( Button a ) {
+ System.out.println( "button" );
+ }
+
+ public multiform void foo( Canvas a ) {
+ System.out.println( "canvas" );
+ }
+
+}
diff --git a/tutorial/examples/operator/OperatorOverridable.oj b/tutorial/examples/operator/OperatorOverridable.oj
new file mode 100644
index 0000000..de952cf
--- /dev/null
+++ b/tutorial/examples/operator/OperatorOverridable.oj
@@ -0,0 +1,7 @@
+public interface
+{
+ public Object operateAdd(Object right);
+ public Object operateSubtract(Object right);
+ public Object operateMultiply(Object right);
+ public Object operateDivide(Object right);
+}
diff --git a/tutorial/examples/operator/OperatorOverridableClass.oj b/tutorial/examples/operator/OperatorOverridableClass.oj
new file mode 100644
index 0000000..e5d6abc
--- /dev/null
+++ b/tutorial/examples/operator/OperatorOverridableClass.oj
@@ -0,0 +1,97 @@
+/*
+ * FreeArgsClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>OperatorOverridableClass</code> provides its
+ * base classes with an ability of overriding its operation like
+ * '+', '-', '*' and '/'.
+ *
+ * <p>
+ * For example, for the class:
+ * <pre>
+ * class MyCollection instantiates FreeArgsClass {
+ * public generous add( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * We can use the class above as follows:
+ * <pre>
+ * MyCollection collection = ..;
+ * collection.add( a, b, null, c, d );
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class OperatorOverridableClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/orcheck/OverrideCheckerClass.java b/tutorial/examples/orcheck/OverrideCheckerClass.java
new file mode 100644
index 0000000..6631dc6
--- /dev/null
+++ b/tutorial/examples/orcheck/OverrideCheckerClass.java
@@ -0,0 +1,82 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * OverrideCheckerClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.orcheck;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>OverloadCheckerClass</code> provides classes
+ * with a facility of checking if a method overrides the method of
+ * its superclass.
+ * <p>
+ * The class <code>MyObject</code> following is a use-case of
+ * this metaclass:
+ * <pre>
+ * class MyObject instantiates OverrideCheckerClass {
+ * public overriding tostring( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * Here, you intend to override the method <tt>toString()</tt> surely.
+ * Compilation of this class shows warning that you do not
+ * override any method. This can help you to become aware of potential
+ * bugs.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class OverrideCheckerClass extends OJClass
+{
+
+ private static final String OVERRIDING = "overriding";
+
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().has( OVERRIDING )) {
+ continue;
+ }
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ String name = methods[i].getName();
+ OJClass[] ptypes = methods[i].getParameterTypes();
+ try {
+ getSuperclass().getMethod( name, ptypes, this );
+ } catch ( Exception e ) {
+ System.err.println( "WARNING: " + methods[i] + " doesn't " + "override any method in superclasses." );
+ }
+ }
+ }
+
+ public static boolean isRegisteredModifier( String keyword )
+ {
+ if (keyword.equals( OVERRIDING )) {
+ return true;
+ }
+ return false;
+ }
+
+ public OverrideCheckerClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public OverrideCheckerClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/orcheck/OverridingClass.oj b/tutorial/examples/orcheck/OverridingClass.oj
new file mode 100644
index 0000000..2743ad4
--- /dev/null
+++ b/tutorial/examples/orcheck/OverridingClass.oj
@@ -0,0 +1,62 @@
+/*
+ * OverridingClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.orcheck;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>OverloadCheckerClass</code> provides classes
+ * with a facility of checking if a method overrides the method of
+ * its superclass.
+ * <p>
+ * The class <code>MyObject</code> following is a use-case of
+ * this metaclass:
+ * <pre>
+ * class MyObject instantiates OverridingClass {
+ * public overriding tostring( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * Here, you intend to override the method <tt>toString()</tt> surely.
+ * Compilation of this class shows warning that you do not
+ * override any method. This can help you to become aware of potential
+ * bugs.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class OverridingClass instantiates Metaclass extends OJClass
+{
+ private static final String OVERRIDING = "overriding";
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( OVERRIDING )) continue;
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ String name = methods[i].getName();
+ OJClass[] ptypes = methods[i].getParameterTypes();
+ try {
+ getSuperclass().getMethod( name, ptypes, this );
+ } catch (Exception e) {
+ System.err.println( "WARNING: " + methods[i] + " doesn't " +
+ "override any method in superclasses." );
+ }
+ }
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( OVERRIDING )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/orcheck/Test.java b/tutorial/examples/orcheck/Test.java
new file mode 100644
index 0000000..bbf1460
--- /dev/null
+++ b/tutorial/examples/orcheck/Test.java
@@ -0,0 +1,15 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.orcheck;
+
+
+public class Test
+{
+
+ public String toString()
+ {
+ return "Hello";
+ }
+
+}
diff --git a/tutorial/examples/orcheck/Test.oj b/tutorial/examples/orcheck/Test.oj
new file mode 100644
index 0000000..cd8e6a0
--- /dev/null
+++ b/tutorial/examples/orcheck/Test.oj
@@ -0,0 +1,9 @@
+package examples.orcheck;
+
+
+public class Test instantiates OverrideCheckerClass
+{
+ public overriding String toString() {
+ return "Hello";
+ }
+}
diff --git a/tutorial/examples/orcheck/TestWithError.oj b/tutorial/examples/orcheck/TestWithError.oj
new file mode 100644
index 0000000..2a59d45
--- /dev/null
+++ b/tutorial/examples/orcheck/TestWithError.oj
@@ -0,0 +1,10 @@
+package examples.orcheck;
+
+
+public class TestWithError instantiates OverrideCheckerClass
+{
+ /** typemiss! */
+ public overriding String tostring() {
+ return "Hello";
+ }
+}
diff --git a/tutorial/examples/order/OrderKeeperClass.java b/tutorial/examples/order/OrderKeeperClass.java
new file mode 100644
index 0000000..90460b5
--- /dev/null
+++ b/tutorial/examples/order/OrderKeeperClass.java
@@ -0,0 +1,65 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * OrderKeeperClass.oj
+ *
+ */
+package examples.order;
+
+
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+
+public class OrderKeeperClass extends openjava.mop.OJClass
+{
+
+ private static final java.lang.String DEPEND = "dependsOn";
+
+ public void translateDefinition()
+ throws openjava.mop.MOPException
+ {
+ openjava.mop.OJClass base = getDepended();
+ System.out.println( "I'm " + getName() + ". " + "After You, " + base.getName() + "." );
+ try {
+ waitTranslation( base );
+ } catch ( java.lang.Exception e ) {
+ System.err.println( e.toString() );
+ }
+ System.out.println( getName() + " is finished." );
+ }
+
+ private openjava.mop.OJClass getDepended()
+ throws openjava.mop.MOPException
+ {
+ return OJClass.forName( getSuffix( DEPEND ).toString() );
+ }
+
+ public static boolean isRegisteredKeyword( java.lang.String keyword )
+ {
+ return keyword.equals( DEPEND );
+ }
+
+ public static openjava.syntax.SyntaxRule getDeclSuffixRule( java.lang.String keyword )
+ {
+ return keyword.equals( DEPEND ) ? new openjava.syntax.TypeNameRule() : null;
+ }
+
+ public java.lang.String toString()
+ {
+ return super.toString() + "(mc : OrderKeeper)";
+ }
+
+ public OrderKeeperClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public OrderKeeperClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/order/OrderKeeperClass.oj b/tutorial/examples/order/OrderKeeperClass.oj
new file mode 100644
index 0000000..dca208f
--- /dev/null
+++ b/tutorial/examples/order/OrderKeeperClass.oj
@@ -0,0 +1,46 @@
+/*
+ * OrderKeeperClass.oj
+ *
+ */
+package examples.order;
+
+
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+
+public class OrderKeeperClass instantiates Metaclass extends OJClass
+{
+ private static final String DEPEND = "dependsOn";
+
+ public void translateDefinition() throws MOPException {
+ OJClass base = getDepended();
+ System.out.println( "I'm " + getName() + ". " +
+ "After You, " + base.getName() + "." );
+ try {
+ waitTranslation( base );
+ } catch ( Exception e ) {
+ System.err.println( e.toString() );
+ }
+
+ System.out.println( getName() + " is finished." );
+ }
+
+ private OJClass getDepended() throws MOPException {
+ return OJClass.forName( getSuffix( DEPEND ).toString() );
+ }
+
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( DEPEND );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ return keyword.equals( DEPEND ) ? new TypeNameRule() : null;
+ }
+
+ public String toString() {
+ return super.toString() + "(mc : OrderKeeper)";
+ }
+
+}
diff --git a/tutorial/examples/order/Test.java b/tutorial/examples/order/Test.java
new file mode 100644
index 0000000..3714254
--- /dev/null
+++ b/tutorial/examples/order/Test.java
@@ -0,0 +1,21 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.order;
+
+
+public class Test
+{
+}
+
+
+class B
+{
+}
+
+
+//class C instantiates OrderKeeperClass dependsOn B {}
+
+class A
+{
+}
diff --git a/tutorial/examples/order/Test.oj b/tutorial/examples/order/Test.oj
new file mode 100644
index 0000000..a4a00f1
--- /dev/null
+++ b/tutorial/examples/order/Test.oj
@@ -0,0 +1,12 @@
+package examples.order;
+
+public class Test instantiates OrderKeeperClass
+ dependsOn java.util.Vector
+{
+}
+
+
+class B instantiates OrderKeeperClass dependsOn A {}
+//class C instantiates OrderKeeperClass dependsOn B {}
+class A instantiates OrderKeeperClass dependsOn Test {}
+//class D instantiates OrderKeeperClass dependsOn C {}
diff --git a/tutorial/examples/order2/Printer.java b/tutorial/examples/order2/Printer.java
new file mode 100644
index 0000000..5e2994d
--- /dev/null
+++ b/tutorial/examples/order2/Printer.java
@@ -0,0 +1,46 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Printer.java
+ *
+ */
+package examples.order2;
+
+
+import openjava.mop.*;
+
+
+public class Printer extends openjava.mop.OJClass
+{
+
+ public void translateDefinition()
+ {
+ openjava.mop.OJClass base = getSuperclass();
+ System.out.println( "I'm " + getName() + "." );
+ System.out.println( getName() + " finished." );
+ }
+
+ public void translateDefinition0()
+ {
+ openjava.mop.OJClass base = getSuperclass();
+ System.out.println( "I'm " + getName() + "." + " " + "After You, " + base.getName() + "." );
+ try {
+ waitTranslation( base );
+ } catch ( java.lang.Exception e ) {
+ System.err.println( e.toString() );
+ }
+ System.out.println( getName() + " finished." );
+ }
+
+ public Printer( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public Printer( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/order2/Printer.oj b/tutorial/examples/order2/Printer.oj
new file mode 100644
index 0000000..2bb433e
--- /dev/null
+++ b/tutorial/examples/order2/Printer.oj
@@ -0,0 +1,33 @@
+/*
+ * Printer.java
+ *
+ */
+package examples.order2;
+
+
+import openjava.mop.*;
+
+
+public class Printer instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() {
+ OJClass base = getSuperclass();
+ System.out.println("I'm " + getName() + ".");
+
+ System.out.println(getName() + " finished.");
+ }
+
+ public void translateDefinition0() {
+ OJClass base = getSuperclass();
+ System.out.println( "I'm " + getName() + "." + " " +
+ "After You, " + base.getName() + "." );
+
+ try {
+ waitTranslation( base );
+ } catch ( Exception e ) {
+ System.err.println( e.toString() );
+ }
+
+ System.out.println( getName() + " finished." );
+ }
+}
diff --git a/tutorial/examples/order2/Test.java b/tutorial/examples/order2/Test.java
new file mode 100644
index 0000000..81cb268
--- /dev/null
+++ b/tutorial/examples/order2/Test.java
@@ -0,0 +1,34 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.order2;
+
+
+public class Test extends examples.order2.E
+{
+}
+
+
+class B extends examples.order2.A
+{
+}
+
+
+class E extends examples.order2.D
+{
+}
+
+
+class C extends examples.order2.B
+{
+}
+
+
+class D extends examples.order2.C
+{
+}
+
+
+class A extends java.lang.Object
+{
+}
diff --git a/tutorial/examples/order2/Test.oj b/tutorial/examples/order2/Test.oj
new file mode 100644
index 0000000..0d3284a
--- /dev/null
+++ b/tutorial/examples/order2/Test.oj
@@ -0,0 +1,11 @@
+package examples.order2;
+
+public class Test instantiates Printer extends E
+{
+}
+
+class B instantiates Printer extends A {}
+class E instantiates Printer extends D {}
+class C instantiates Printer extends B {}
+class D instantiates Printer extends C {}
+class A extends Object {}
diff --git a/tutorial/examples/print/MyClass.java b/tutorial/examples/print/MyClass.java
new file mode 100644
index 0000000..bbd1481
--- /dev/null
+++ b/tutorial/examples/print/MyClass.java
@@ -0,0 +1,30 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.print;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+public class MyClass extends OJClass
+{
+
+ public MyClass( Environment outer_env, OJClass declarer, ClassDeclaration ptree )
+ {
+ super( outer_env, declarer, ptree );
+ }
+
+ public MyClass( Class javaclass, MetaInfo minfo )
+ {
+ super( javaclass, minfo );
+ }
+
+ protected void pro()
+ {}
+
+ public void pub()
+ {}
+
+}
diff --git a/tutorial/examples/print/MyClass.oj b/tutorial/examples/print/MyClass.oj
new file mode 100644
index 0000000..0b689ea
--- /dev/null
+++ b/tutorial/examples/print/MyClass.oj
@@ -0,0 +1,21 @@
+package examples.print;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+public class MyClass instantiates TestPrinter extends OJClass
+{
+ public MyClass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree ) {
+ super( outer_env, declarer, ptree );
+ }
+
+ public MyClass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+ protected void pro() {}
+ public void pub() {}
+}
diff --git a/tutorial/examples/print/Printer.java b/tutorial/examples/print/Printer.java
new file mode 100644
index 0000000..4de9203
--- /dev/null
+++ b/tutorial/examples/print/Printer.java
@@ -0,0 +1,64 @@
+/*
+ * Printer.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+/**
+ * The class <code>Printer</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: Printer.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class Printer extends OJClass {
+ public void translateDefinition() throws MOPException {
+ System.out.println("CONSTRUCTORS");
+ OJConstructor[] c = getConstructors();
+ for (int i = 0; i < c.length; ++i) {
+ System.out.println(c[i].toString());
+ }
+
+ System.out.println("FIELDS");
+ OJField[] f = getAllFields();
+ for (int i = 0; i < f.length; ++i) {
+ System.out.println(f[i].toString());
+ }
+
+ System.out.println("METHODS");
+ OJMethod[] m = getAllMethods();
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println(m[i].toString());
+ }
+ }
+
+ public Printer(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public Printer(Class javaclass, MetaInfo minfo) {
+ super(javaclass, minfo);
+ }
+
+}
diff --git a/tutorial/examples/print/Test.java b/tutorial/examples/print/Test.java
new file mode 100644
index 0000000..77238e9
--- /dev/null
+++ b/tutorial/examples/print/Test.java
@@ -0,0 +1,119 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Test.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+/**
+ * The class <code>Test</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: Test.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class Test extends Panel {
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main(String[] argv) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println("Hello" + " " + "World");
+ Test n = new Test();
+ java.lang.System.err.println("done");
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println(l.foo);
+ System.out.println(l.bar.str);
+ }
+
+ public Test(String str) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo(int iii) {
+ switch (iii) {
+ case 0 :
+ return 0;
+
+ case 1 :
+ {
+ String str = null;
+ }
+
+ case 2 :
+ case 3 :
+ case 4 :
+ {
+ String ppp = null;
+ }
+
+ default :
+
+ }
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
+
+class Local {
+
+ String foo = null;
+
+ Local2 bar = new Local2();
+
+ public final String getFoo(Integer i) {
+ return foo;
+ }
+
+}
+
+class Local2 {
+
+ String str = "" + "TEST";
+
+}
diff --git a/tutorial/examples/print/Test.oj b/tutorial/examples/print/Test.oj
new file mode 100644
index 0000000..7b1061a
--- /dev/null
+++ b/tutorial/examples/print/Test.oj
@@ -0,0 +1,107 @@
+/*
+ * Test.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+/**
+ * The class <code>Test</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class Test instantiates Printer
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done" );
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo( int iii ) {
+ switch (iii) {
+ case 0:
+ return 0;
+ case 1: {
+ String str = null;
+ }
+ case 2:
+ case 3:
+ case 4: {
+ String ppp = null;
+ }
+ default:
+ }
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
+
+class Local instantiates Printer
+{
+ String foo = null;
+ Local2 bar = new Local2();
+ public final String getFoo( Integer i ) {
+ return foo;
+ }
+}
+
+class Local2
+{
+ String str = "" + "TEST";
+}
diff --git a/tutorial/examples/print/TestPrinter.java b/tutorial/examples/print/TestPrinter.java
new file mode 100644
index 0000000..bd6d359
--- /dev/null
+++ b/tutorial/examples/print/TestPrinter.java
@@ -0,0 +1,99 @@
+/*
+ * TestPrinter.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+/**
+ * The class <code>TestPrinter</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TestPrinter.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class TestPrinter extends OJClass {
+ public void translateDefinition() throws MOPException {
+ OJMethod[] m;
+
+ /*
+ System.out.println( "SELF" );
+ m = getInheritedMethods();
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println( m[i].toString() );
+ }
+ */
+
+ System.out.println("STATEMENTLIST");
+ OJClass clazz = OJClass.forName("openjava.ptree.StatementList");
+
+ m = clazz.getMethods(this);
+ /*
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println( m[i].toString() );
+ }
+ */
+
+ System.out.println("INSERTELEMENTAT");
+ OJMethod method;
+ try {
+ OJClass[] params =
+ new OJClass[] {
+ OJClass.forName("openjava.ptree.Statement"),
+ OJClass.forName("int")};
+ method = clazz.getMethod("insertElementAt", params);
+ m = Toolbox.pickupMethodsByName(m, "insertElementAt");
+ System.out.println("name matches : " + m.length);
+ System.err.println(m[0].toString());
+ OJClass[] mparams = m[0].getParameterTypes();
+ System.err.println("M " + mparams[0] + " " + mparams[1]);
+ System.err.println("P " + params[0] + " " + params[1]);
+ boolean assign0 = mparams[0].isAssignableFrom(params[0]);
+ System.out.println("assignable0 : " + assign0);
+ boolean assign1 = mparams[1].isAssignableFrom(params[1]);
+ System.out.println("assignable1 : " + assign1);
+ System.out.println("equality : " + (mparams[0] == params[0]));
+
+ boolean isa = Toolbox.isAcceptable(mparams, params);
+ System.out.println("acceptable : " + isa);
+ m = Toolbox.pickupAcceptableMethodsByParameterTypes(m, params);
+ System.out.println("param matches : " + m.length);
+ } catch (NoSuchMethodException e) {
+ method = null;
+ }
+ if (method == null) {
+ System.out.println("NOT FOUND");
+ } else {
+ System.out.println(method.toString());
+ }
+ }
+
+ public TestPrinter(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public TestPrinter(Class javaclass, MetaInfo minfo) {
+ super(javaclass, minfo);
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/Point.java b/tutorial/examples/rtrefl/Point.java
new file mode 100644
index 0000000..708c5ea
--- /dev/null
+++ b/tutorial/examples/rtrefl/Point.java
@@ -0,0 +1,107 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Point.oj
+ */
+package examples.rtrefl;
+
+
+public class Point implements examples.rtrefl.RTMetaLevel
+{
+
+ public int x;
+
+ public int y;
+
+ public String name;
+
+ public Point( String name, int x, int y )
+ {
+ this.x = x;
+ this.y = y;
+ this.name = name;
+ }
+
+ public Point( int x, int y )
+ {
+ this( "DefaultName", x, y );
+ }
+
+ public String org_toString()
+ {
+ return "(" + x + "," + y + ")";
+ }
+
+ public void org_move( int dx, int dy )
+ {
+ x += dx;
+ y += dy;
+ }
+
+ public double org_distanceFromOrigin()
+ {
+ return Math.sqrt( (double) x * x + y * y );
+ }
+
+
+ public examples.rtrefl.RTMetaObject mt;
+
+
+ public java.lang.String toString()
+ {
+ return (java.lang.String) mt.trapMethodCall( "org_toString", new java.lang.Class[]{ }, new java.lang.Object[]{ } );
+ }
+
+
+ public void move( int oj_param0, int oj_param1 )
+ {
+ mt.trapMethodCall( "org_move", new java.lang.Class[]{ int.class, int.class }, new java.lang.Object[]{ new java.lang.Integer( oj_param0 ), new java.lang.Integer( oj_param1 ) } );
+ }
+
+
+ public double distanceFromOrigin()
+ {
+ return ((java.lang.Double) mt.trapMethodCall( "org_distanceFromOrigin", new java.lang.Class[]{ }, new java.lang.Object[]{ } )).doubleValue();
+ }
+
+
+ public int read_x()
+ {
+ return ((java.lang.Integer) mt.trapFieldRead( "x" )).intValue();
+ }
+
+
+ public int write_x( int oj_param0 )
+ {
+ mt.trapFieldWrite( "x", new java.lang.Integer( oj_param0 ) );
+ return oj_param0;
+ }
+
+
+ public int read_y()
+ {
+ return ((java.lang.Integer) mt.trapFieldRead( "y" )).intValue();
+ }
+
+
+ public int write_y( int oj_param0 )
+ {
+ mt.trapFieldWrite( "y", new java.lang.Integer( oj_param0 ) );
+ return oj_param0;
+ }
+
+
+ public java.lang.String read_name()
+ {
+ return (java.lang.String) mt.trapFieldRead( "name" );
+ }
+
+
+ public java.lang.String write_name( java.lang.String oj_param0 )
+ {
+ mt.trapFieldWrite( "name", oj_param0 );
+ return oj_param0;
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/Point.oj b/tutorial/examples/rtrefl/Point.oj
new file mode 100644
index 0000000..e15b607
--- /dev/null
+++ b/tutorial/examples/rtrefl/Point.oj
@@ -0,0 +1,35 @@
+/*
+ * Point.oj
+ */
+package examples.rtrefl;
+
+
+public class Point instantiates RTReflClass
+{
+ public int x, y;
+ public String name;
+
+ public Point( String name, int x, int y ) {
+ this.x = x;
+ this.y = y;
+ this.name = name;
+ }
+
+ public Point( int x, int y ) {
+ this( "DefaultName", x, y );
+ }
+
+ public String toString() {
+ return "(" + x + "," + y + ")";
+ }
+
+ public void move( int dx, int dy ) {
+ x += dx;
+ y += dy;
+ }
+
+ public double distanceFromOrigin() {
+ return Math.sqrt( (double) x * x + y * y );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/PointUser.java b/tutorial/examples/rtrefl/PointUser.java
new file mode 100644
index 0000000..42ddee8
--- /dev/null
+++ b/tutorial/examples/rtrefl/PointUser.java
@@ -0,0 +1,25 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * PointUser.oj
+ */
+package examples.rtrefl;
+
+
+public class PointUser
+{
+
+ public static void main( String[] args )
+ {
+ Point p = new Point( 1, 2 ){
+ };
+ p.mt = new VerboseRTMetaObject( p ){
+ };
+ p.write_name( "MyFavorite" );
+ int x = p.read_x() + 1;
+ p.write_y( x * 2 + p.read_y() );
+ System.out.println( "distance = " + p.distanceFromOrigin() );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/PointUser.oj b/tutorial/examples/rtrefl/PointUser.oj
new file mode 100644
index 0000000..3ab9edc
--- /dev/null
+++ b/tutorial/examples/rtrefl/PointUser.oj
@@ -0,0 +1,19 @@
+/*
+ * PointUser.oj
+ */
+package examples.rtrefl;
+
+
+public class PointUser
+{
+
+ public static void main( String[] args ) {
+ Point p = new Point( 1, 2 );
+ p.mt = new VerboseRTMetaObject( p );
+ p.name = "MyFavorite";
+ int x = p.x + 1;
+ p.y = x * 2 + p.y;
+ System.out.println( "distance = " + p.distanceFromOrigin() );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/RTMetaLevel.java b/tutorial/examples/rtrefl/RTMetaLevel.java
new file mode 100644
index 0000000..0daf0be
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTMetaLevel.java
@@ -0,0 +1,6 @@
+package examples.rtrefl;
+
+
+public interface RTMetaLevel
+{
+}
diff --git a/tutorial/examples/rtrefl/RTMetaObject.java b/tutorial/examples/rtrefl/RTMetaObject.java
new file mode 100644
index 0000000..13486ae
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTMetaObject.java
@@ -0,0 +1,81 @@
+package examples.rtrefl;
+
+
+import java.lang.reflect.*;
+
+
+/**
+ * The class RTMetaObject
+ * Exception handling is not implemented.
+ */
+public class RTMetaObject
+{
+ private RTMetaLevel baseObj;
+
+ public RTMetaObject(RTMetaLevel base_obj) {
+ this.baseObj = base_obj;
+ }
+
+ public Object trapMethodCall(String name, Class[] paramTypes, Object[] args)
+ {
+ try {
+ Method method = baseObj.getClass().getMethod(name, paramTypes);
+ return method.invoke(baseObj, args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public Object trapFieldRead(String name) {
+ try {
+ Field field = baseObj.getClass().getField(name);
+ return field.get(baseObj);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public void trapFieldWrite(String name, Object rvalue) {
+ try {
+ Field field = baseObj.getClass().getField(name);
+ field.set(baseObj, rvalue);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+
+
+/*****
+class Foo {
+ int f(int a) {}
+ int l;
+}
+...
+Foo foo; foo.l = expr; a = foo.l;
+
+->
+
+class Foo implements Metalevel {
+ public examples.rtrefl.RTMetaObject mt;
+ int org_f(int a) {}
+ int f(int a) {
+ Object[] args = new Object[]{ new Integer(a) };
+ Class[] argTypes = new Class[]{ int.class };
+ Object result = mt.trapMethodCall("org_f", argTypes, args);
+ return ((Integer) result).intValue();
+ }
+ int read_l() {
+ Object result = mt.trapFieldRead("l");
+ return ((Integer) result).intValue();
+ }
+ int write_l(int rvalue) {
+ mt.trapFieldWrite("l", new Integer(rvalue));
+ return rvalue;
+ }
+}
+...
+Foo foo; foo.write_l(expr); a = foo.read_l();
+*****/
diff --git a/tutorial/examples/rtrefl/RTReflClass.java b/tutorial/examples/rtrefl/RTReflClass.java
new file mode 100644
index 0000000..4486241
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTReflClass.java
@@ -0,0 +1,229 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * RTReflClass.oj
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.rtrefl;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> is a metaclass which
+ * provides hooks for runtime class metaobject.
+ * <p>
+ * All the fields in the class are hidden instead the readers and
+ * writers methods for fields are provided. Furthermore, accesses
+ * to fields of the class is to be replaced with these methods.
+ * Note that member accesses in its class body are not captured.
+ */
+public class RTReflClass extends OJClass
+{
+
+ protected static String RTMETAOBJ_FIELD = "mt";
+
+ protected static Expression METAFIELD_ACCESS = new FieldAccess( RTMETAOBJ_FIELD );
+
+ protected static final String originalMethodName( String name )
+ {
+ return "org_" + name;
+ }
+
+ protected static final String fieldReaderName( String name )
+ {
+ return "read_" + name;
+ }
+
+ protected static final String fieldWriterName( String name )
+ {
+ return "write_" + name;
+ }
+
+ /** Overrides to translate definition */
+ public void translateDefinition()
+ throws MOPException
+ {
+ addInterface( openjava.mop.OJClass.forClass( RTMetaLevel.class ) );
+ OJMethod[] methods = getDeclaredMethods();
+ OJField[] fields = getDeclaredFields();
+ OJField rtmobj_field = new OJField( this, OJModifier.forModifier( OJModifier.PUBLIC ), openjava.mop.OJClass.forClass( RTMetaObject.class ), RTMETAOBJ_FIELD );
+ addField( rtmobj_field );
+ for (int i = 0; i < methods.length; ++i) {
+ OJModifier modif = methods[i].getModifiers();
+ if (modif.isPublic()) {
+ provideMethod( methods[i] );
+ }
+ }
+ for (int i = 0; i < fields.length; ++i) {
+ OJModifier modif = fields[i].getModifiers();
+ if (modif.isPublic()) {
+ provideField( fields[i] );
+ }
+ }
+ }
+
+ private void provideMethod( OJMethod method )
+ throws MOPException
+ {
+ System.err.println( "Providing a method : " + method.toString() );
+ OJMethod trapper = OJMethod.makePrototype( method );
+ method.setName( originalMethodName( method.getName() ) );
+ addMethod( trapper );
+ Expression trapexpr = generateTrappingMethodCall( trapper );
+ StatementList body = new StatementList();
+ OJClass retType = trapper.getReturnType();
+ if (retType == OJSystem.VOID) {
+ body.add( new ExpressionStatement( trapexpr ) );
+ } else {
+ Expression unwrapexpr = generateUnwrapping( retType, trapexpr );
+ body.add( new ReturnStatement( unwrapexpr ) );
+ }
+ trapper.setBody( body );
+ }
+
+ private static MethodCall generateTrappingMethodCall( OJMethod method )
+ throws MOPException
+ {
+ ExpressionList params = method.getParameterVariables();
+ OJClass[] paramTypes = method.getParameterTypes();
+ ExpressionList typeinfo_args = new ExpressionList();
+ ExpressionList args = new ExpressionList();
+ for (int i = 0; i < paramTypes.length; ++i) {
+ typeinfo_args.add( new ClassLiteral( paramTypes[i] ) );
+ args.add( generateWrapping( paramTypes[i], params.get( i ) ) );
+ }
+ Expression namearg = Literal.makeLiteral( originalMethodName( method.getName() ) );
+ Expression mrsld_typearg = new ArrayAllocationExpression( openjava.mop.OJClass.forClass( java.lang.Class.class ), new ExpressionList( null ), new ArrayInitializer( typeinfo_args ) );
+ Expression mrsld_arg = new ArrayAllocationExpression( openjava.mop.OJClass.forClass( java.lang.Object.class ), new ExpressionList( null ), new ArrayInitializer( args ) );
+ ExpressionList metaargs = new ExpressionList( namearg, mrsld_typearg, mrsld_arg );
+ return new MethodCall( METAFIELD_ACCESS, "trapMethodCall", metaargs );
+ }
+
+ private void provideField( OJField field )
+ throws MOPException
+ {
+ System.err.println( "Providing a field : " + field.toString() );
+ generateReaderMethod( field );
+ generateWriterMethod( field );
+ }
+
+ /**
+ * int read_l() {
+ * return ((Integer) mt.trapFieldRead("l")).intValue();
+ * }
+ */
+ private void generateReaderMethod( OJField field )
+ throws MOPException
+ {
+ Expression metafld = new FieldAccess( RTMETAOBJ_FIELD );
+ ExpressionList args = new ExpressionList( Literal.makeLiteral( field.getName() ) );
+ Expression trapexpr = new MethodCall( METAFIELD_ACCESS, "trapFieldRead", args );
+ Expression unwrapping = generateUnwrapping( field.getType(), trapexpr );
+ OJMethod reader = new OJMethod( this, field.getModifiers(), field.getType(), fieldReaderName( field.getName() ), (OJClass[]) null, null, new StatementList( new ReturnStatement( unwrapping ) ) );
+ addMethod( reader );
+ }
+
+ /**
+ * int write_l(int rvalue) {
+ * mt.trapFieldWrite("l", new Integer(rvalue));
+ * return rvalue;
+ * }
+ */
+ private void generateWriterMethod( OJField field )
+ throws MOPException
+ {
+ OJMethod writer = new OJMethod( this, field.getModifiers(), field.getType(), fieldWriterName( field.getName() ), new OJClass[]{ field.getType() }, null, null );
+ Expression param = writer.getParameterVariables().get( 0 );
+ ExpressionList args = new ExpressionList( Literal.makeLiteral( field.getName() ), generateWrapping( field.getType(), param ) );
+ Expression trapexpr = new MethodCall( METAFIELD_ACCESS, "trapFieldWrite", args );
+ StatementList body = new StatementList( new ExpressionStatement( trapexpr ), new ReturnStatement( param ) );
+ writer.setBody( body );
+ addMethod( writer );
+ }
+
+ /** new Integer(expr) for expr */
+ private static Expression generateWrapping( OJClass realType, Expression expr )
+ {
+ if (!realType.isPrimitive()) {
+ return expr;
+ }
+ OJClass wrapperType = realType.primitiveWrapper();
+ return new AllocationExpression( wrapperType, new ExpressionList( expr ) );
+ }
+
+ /** ((Integer) expr).intValue() for expr */
+ private static Expression generateUnwrapping( OJClass realType, Expression expr )
+ {
+ expr = new CastExpression( realType.primitiveWrapper(), expr );
+ if (!realType.isPrimitive()) {
+ return expr;
+ }
+ return new MethodCall( expr, realType.getName() + "Value", null );
+ }
+
+ /** Allows references to private fields */
+ public OJField resolveException( NoSuchMemberException e, String name )
+ throws NoSuchMemberException
+ {
+ try {
+ return getDeclaredField( name );
+ } catch ( NoSuchMemberException e2 ) {
+ }
+ return super.resolveException( e, name );
+ }
+
+ /** Overrides to expand fields to be read */
+ public Expression expandFieldRead( Environment env, FieldAccess expr )
+ {
+ if (expr.getName().equals( RTMETAOBJ_FIELD )) {
+ return expr;
+ }
+ Expression ref = expr.getReferenceExpr();
+ String name = fieldReaderName( expr.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, null );
+ } else {
+ result = new MethodCall( expr.getReferenceType(), name, null );
+ }
+ System.err.println( "Patch FR : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ /** Overrides to expand fields to be written */
+ public Expression expandFieldWrite( Environment env, AssignmentExpression expr )
+ {
+ FieldAccess fldac = (FieldAccess) expr.getLeft();
+ if (fldac.getName().equals( RTMETAOBJ_FIELD )) {
+ return expr;
+ }
+ ExpressionList args = new ExpressionList( expr.getRight() );
+ Expression ref = fldac.getReferenceExpr();
+ String name = fieldWriterName( fldac.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, args );
+ } else {
+ result = new MethodCall( fldac.getReferenceType(), name, args );
+ }
+ System.err.println( "Patch FW : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ public RTReflClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public RTReflClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/RTReflClass.oj b/tutorial/examples/rtrefl/RTReflClass.oj
new file mode 100644
index 0000000..a75760b
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTReflClass.oj
@@ -0,0 +1,247 @@
+/*
+ * RTReflClass.oj
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.rtrefl;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> is a metaclass which
+ * provides hooks for runtime class metaobject.
+ * <p>
+ * All the fields in the class are hidden instead the readers and
+ * writers methods for fields are provided. Furthermore, accesses
+ * to fields of the class is to be replaced with these methods.
+ * Note that member accesses in its class body are not captured.
+ */
+public class RTReflClass instantiates Metaclass extends OJClass
+{
+ protected static String RTMETAOBJ_FIELD = "mt";
+ protected static Expression METAFIELD_ACCESS
+ = new FieldAccess( RTMETAOBJ_FIELD );
+
+ protected static final String originalMethodName( String name ) {
+ return "org_" + name;
+ }
+
+ protected static final String fieldReaderName( String name ) {
+ return "read_" + name;
+ }
+
+ protected static final String fieldWriterName( String name ) {
+ return "write_" + name;
+ }
+
+ /** Overrides to translate definition */
+ public convenient void translateDefinition() throws MOPException {
+ addInterface( RTMetaLevel.class );
+
+ /* Gets all the declared fields and methods */
+ OJMethod[] methods = getDeclaredMethods();
+ OJField[] fields = getDeclaredFields();
+
+ OJField rtmobj_field
+ = new OJField( this, OJModifier.forModifier( OJModifier.PUBLIC ),
+ RTMetaObject.class, RTMETAOBJ_FIELD );
+ addField( rtmobj_field );
+
+ /* Generates trapping methods for each public method */
+ for (int i = 0; i < methods.length; ++i) {
+ OJModifier modif = methods[i].getModifiers();
+ if (modif.isPublic()) provideMethod( methods[i] );
+ }
+
+ /* Generates wrappers for each public field */
+ for (int i = 0; i < fields.length; ++i) {
+ OJModifier modif = fields[i].getModifiers();
+ if (modif.isPublic()) provideField( fields[i] );
+ }
+ }
+
+ private void provideMethod( OJMethod method ) throws MOPException {
+ System.err.println( "Providing a method : " + method.toString() );
+ OJMethod trapper = OJMethod.makePrototype( method );
+ method.setName( originalMethodName( method.getName() ) );
+ addMethod( trapper );
+
+ /* marshalling and trapping */
+ Expression trapexpr = generateTrappingMethodCall( trapper );
+
+ StatementList body = new StatementList();
+ OJClass retType = trapper.getReturnType();
+ if (retType == OJSystem.VOID) {
+ body.add( new ExpressionStatement( trapexpr ) );
+ } else {
+ Expression unwrapexpr = generateUnwrapping( retType, trapexpr );
+ body.add( new ReturnStatement( unwrapexpr ) );
+ }
+ trapper.setBody( body );
+ }
+
+ private static convenient MethodCall
+ generateTrappingMethodCall( OJMethod method ) throws MOPException {
+ ExpressionList params = method.getParameterVariables();
+ OJClass[] paramTypes = method.getParameterTypes();
+
+ /* wrapping arguments */
+ ExpressionList typeinfo_args = new ExpressionList();
+ ExpressionList args = new ExpressionList();
+ for (int i = 0; i < paramTypes.length; ++i) {
+ typeinfo_args.add( new ClassLiteral( paramTypes[i] ) );
+ args.add( generateWrapping( paramTypes[i], params.get( i ) ));
+ }
+
+ /* marshalling arguments */
+ Expression namearg
+ = Literal.makeLiteral( originalMethodName( method.getName() ) );
+ Expression mrsld_typearg = new ArrayAllocationExpression(
+ java.lang.Class.class, new ExpressionList( null ),
+ new ArrayInitializer( typeinfo_args )
+ );
+ Expression mrsld_arg = new ArrayAllocationExpression(
+ java.lang.Object.class, new ExpressionList( null ),
+ new ArrayInitializer( args )
+ );
+
+ ExpressionList metaargs
+ = new ExpressionList( namearg, mrsld_typearg, mrsld_arg );
+ return new MethodCall( METAFIELD_ACCESS, "trapMethodCall", metaargs );
+ }
+
+ private void provideField( OJField field ) throws MOPException {
+ System.err.println( "Providing a field : " + field.toString() );
+ generateReaderMethod( field );
+ generateWriterMethod( field );
+ }
+
+ /**
+ * int read_l() {
+ * return ((Integer) mt.trapFieldRead("l")).intValue();
+ * }
+ */
+ private void generateReaderMethod( OJField field ) throws MOPException {
+ //Expression trapexpr = makeExpression(
+ // "mt.trapFieldRead(\"" + field.getName() + "\")"
+ //);
+ Expression metafld = new FieldAccess( RTMETAOBJ_FIELD );
+ ExpressionList args = new ExpressionList(
+ Literal.makeLiteral( field.getName() )
+ );
+ Expression trapexpr
+ = new MethodCall( METAFIELD_ACCESS, "trapFieldRead", args );
+ Expression unwrapping
+ = generateUnwrapping( field.getType(), trapexpr );
+ OJMethod reader = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldReaderName( field.getName() ),
+ (OJClass[]) null, null,
+ new StatementList( new ReturnStatement( unwrapping ) )
+ );
+ addMethod( reader );
+ }
+
+ /**
+ * int write_l(int rvalue) {
+ * mt.trapFieldWrite("l", new Integer(rvalue));
+ * return rvalue;
+ * }
+ */
+ private void generateWriterMethod( OJField field ) throws MOPException {
+ OJMethod writer = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldWriterName( field.getName() ),
+ new OJClass[]{ field.getType() }, null, null
+ );
+ Expression param = writer.getParameterVariables().get( 0 );
+ //StatementList body = makeStatementList( writer.getEnvironment(),
+ // "mt.trapFieldWrite(\"" + field.getName() + "\");" +
+ // "return " + field.getName() + "=" + param + ";"
+ // );
+ ExpressionList args = new ExpressionList(
+ Literal.makeLiteral( field.getName() ),
+ generateWrapping( field.getType(), param )
+ );
+ Expression trapexpr
+ = new MethodCall( METAFIELD_ACCESS, "trapFieldWrite", args );
+ StatementList body = new StatementList(
+ new ExpressionStatement( trapexpr ),
+ new ReturnStatement( param )
+ );
+ writer.setBody( body );
+ addMethod( writer );
+ }
+
+ /** new Integer(expr) for expr */
+ private static Expression
+ generateWrapping(OJClass realType, Expression expr) {
+ if (! realType.isPrimitive()) return expr;
+ OJClass wrapperType = realType.primitiveWrapper();
+ return new AllocationExpression( wrapperType,
+ new ExpressionList( expr ) );
+ }
+
+ /** ((Integer) expr).intValue() for expr */
+ private static Expression
+ generateUnwrapping(OJClass realType, Expression expr) {
+ expr = new CastExpression( realType.primitiveWrapper(), expr );
+ if (! realType.isPrimitive()) return expr;
+ return new MethodCall( expr, realType.getName() + "Value", null );
+ }
+
+ /* overrides */
+
+ /** Allows references to private fields */
+ public OJField resolveException(NoSuchMemberException e, String name)
+ throws NoSuchMemberException
+ {
+ try {
+ return getDeclaredField( name );
+ } catch ( NoSuchMemberException e2 ) {}
+ return super.resolveException( e, name );
+ }
+
+ /** Overrides to expand fields to be read */
+ public Expression expandFieldRead(
+ Environment env,
+ FieldAccess expr )
+ {
+ if (expr.getName().equals( RTMETAOBJ_FIELD )) return expr;
+ Expression ref = expr.getReferenceExpr();
+ String name = fieldReaderName( expr.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, null );
+ } else {
+ result = new MethodCall( expr.getReferenceType(), name, null );
+ }
+ System.err.println( "Patch FR : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ /** Overrides to expand fields to be written */
+ public Expression expandFieldWrite(
+ Environment env,
+ AssignmentExpression expr )
+ {
+ FieldAccess fldac = (FieldAccess) expr.getLeft();
+ if (fldac.getName().equals( RTMETAOBJ_FIELD )) return expr;
+ ExpressionList args = new ExpressionList( expr.getRight() );
+ Expression ref = fldac.getReferenceExpr();
+ String name = fieldWriterName( fldac.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, args );
+ } else {
+ result = new MethodCall( fldac.getReferenceType(), name, args );
+ }
+ System.err.println( "Patch FW : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/VerboseRTMetaObject.java b/tutorial/examples/rtrefl/VerboseRTMetaObject.java
new file mode 100644
index 0000000..2870eab
--- /dev/null
+++ b/tutorial/examples/rtrefl/VerboseRTMetaObject.java
@@ -0,0 +1,38 @@
+package examples.rtrefl;
+
+
+import java.lang.reflect.*;
+
+
+/**
+ * The class VerboseRTMetaObject
+ * Exception handling is not implemented.
+ */
+public class VerboseRTMetaObject extends RTMetaObject
+{
+ RTMetaLevel baseObj;
+
+ public VerboseRTMetaObject(RTMetaLevel base_obj) {
+ super(base_obj);
+ this.baseObj = base_obj;
+ }
+
+ public Object trapMethodCall(String name, Class[] paramTypes, Object[] args)
+ {
+ System.out.println(baseObj.getClass().getName() + "." +
+ name + "()" + " is called." );
+ return super.trapMethodCall(name, paramTypes, args);
+ }
+
+ public Object trapFieldRead(String name) {
+ System.out.println(baseObj.getClass().getName() + "." +
+ name + " is read." );
+ return super.trapFieldRead(name);
+ }
+
+ public void trapFieldWrite(String name, Object rvalue) {
+ System.out.println(baseObj.getClass().getName() + "." +
+ name + " is written." );
+ super.trapFieldWrite(name, rvalue);
+ }
+}
diff --git a/tutorial/examples/serialize/BIND b/tutorial/examples/serialize/BIND
new file mode 100644
index 0000000..7a57297
--- /dev/null
+++ b/tutorial/examples/serialize/BIND
@@ -0,0 +1,5 @@
+examples.serialize.SerializableClass examples.serialize.Point
+examples.serialize.SerializableClass examples.serialize.Color
+examples.serialize.SerializableClass examples.serialize.ColoredPoint
+examples.serialize.SerializableClass examples.serialize.Colored3DPoint
+examples.serialize.SerializableClass examples.serialize.*
diff --git a/tutorial/examples/serialize/Color.oj b/tutorial/examples/serialize/Color.oj
new file mode 100644
index 0000000..dbce37f
--- /dev/null
+++ b/tutorial/examples/serialize/Color.oj
@@ -0,0 +1,44 @@
+package examples.serialize;
+
+import java.io.*;
+
+public class Color
+{
+ public Color(byte r, byte g, byte b) {
+ this.r = r; this.g = g; this.b = b;
+ }
+ byte r;
+ byte g;
+ byte b;
+}
+
+/*
+public class Color implements Marshalable
+{
+ byte r;
+ byte g;
+ byte b;
+
+ public Color(byte r, byte g, byte b) {
+ this.r = r; this.g = g; this.b = b;
+ }
+
+ public Color() {
+ }
+
+ public void readObject(ObjectIn is) throws IOException {
+ r = is.readByte();
+ g = is.readByte();
+ b = is.readByte();
+ }
+
+ public void writeObject(ObjectOut os) throws IOException {
+ os.writeUTF("Color");
+ os.writeByte(r);
+ os.writeByte(g);
+ os.writeByte(b);
+ }
+
+}
+*/
+
diff --git a/tutorial/examples/serialize/Colored3DPoint.oj b/tutorial/examples/serialize/Colored3DPoint.oj
new file mode 100644
index 0000000..54c0db0
--- /dev/null
+++ b/tutorial/examples/serialize/Colored3DPoint.oj
@@ -0,0 +1,19 @@
+package examples.serialize;
+
+public class Colored3DPoint
+{
+ public Color color = new Color((byte) 0, (byte) 0, (byte) 0);
+ public int x;
+ public int y;
+ public int z;
+}
+
+/*
+public class Colored3DPoint
+{
+ public Color color = new Color((byte) 0, (byte) 0, (byte) 0);
+ private int x;
+ private int y;
+ private int z;
+}
+*/
diff --git a/tutorial/examples/serialize/ColoredPoint.oj b/tutorial/examples/serialize/ColoredPoint.oj
new file mode 100644
index 0000000..30e534c
--- /dev/null
+++ b/tutorial/examples/serialize/ColoredPoint.oj
@@ -0,0 +1,28 @@
+package examples.serialize;
+
+import java.io.*;
+
+public class ColoredPoint
+{
+ public Color color = new Color((byte) 0, (byte) 0, (byte) 0);
+ public Point point = new Point();
+}
+
+/*
+public class ColoredPoint implements Marshalable
+{
+ public Color color = new Color((byte) 1, (byte) 3, (byte) 5);
+ public Point point = new Point();
+
+ public void writeObject(ObjectOut os) throws IOException {
+ os.writeUTF("ColoredPoint");
+ os.writeObject(color);
+ os.writeObject(point);
+ }
+
+ public void readObject(ObjectIn is) throws IOException {
+ color = (Color) is.readObject();
+ point = (Point) is.readObject();
+ }
+}
+*/
diff --git a/tutorial/examples/serialize/Marshalable.java b/tutorial/examples/serialize/Marshalable.java
new file mode 100644
index 0000000..5924c4b
--- /dev/null
+++ b/tutorial/examples/serialize/Marshalable.java
@@ -0,0 +1,9 @@
+package examples.serialize;
+
+import java.io.*;
+
+public interface Marshalable
+{
+ void readObject(ObjectIn is) throws IOException;
+ void writeObject(ObjectOut os) throws IOException;
+}
diff --git a/tutorial/examples/serialize/OIOTest.java b/tutorial/examples/serialize/OIOTest.java
new file mode 100644
index 0000000..717707f
--- /dev/null
+++ b/tutorial/examples/serialize/OIOTest.java
@@ -0,0 +1,56 @@
+package examples.serialize;
+
+import javax.microedition.midlet.MIDlet;
+import java.io.*;
+
+public class OIOTest extends MIDlet
+{
+
+ public void startApp() {
+ try {
+ main();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public static void main() throws IOException {
+ ColoredPoint p = new ColoredPoint();
+ p.point.x = 10; p.point.y = 20;
+
+ /* Writes objects */
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOut oos = new ObjectOut(baos);
+
+ oos.writeObject(p);
+ p.color.g = (byte)2;
+ oos.writeObject(p);
+ oos.flush();
+
+ byte[] buf = baos.toByteArray();
+
+ /* Reads objects */
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf);
+ ObjectIn ois = new ObjectIn(bais);
+
+ ColoredPoint p2 = (ColoredPoint) ois.readObject();
+ ColoredPoint p3 = (ColoredPoint) ois.readObject();
+
+ System.out.println("p2.color.r = " + p2.color.r);
+ System.out.println("p2.color.g = " + p2.color.g);
+ System.out.println("p2.color.b = " + p2.color.b);
+ System.out.println("p2.point.x = " + p2.point.x);
+ System.out.println("p2.point.y = " + p2.point.y);
+ System.out.println("p3.color.r = " + p3.color.r);
+ System.out.println("p3.color.g = " + p3.color.g);
+ System.out.println("p3.color.b = " + p3.color.b);
+
+ }
+
+ public void pauseApp() {
+ }
+
+ public void destroyApp(boolean unconditional) {
+ }
+
+}
diff --git a/tutorial/examples/serialize/ObjectIn.java b/tutorial/examples/serialize/ObjectIn.java
new file mode 100644
index 0000000..4a3e1f1
--- /dev/null
+++ b/tutorial/examples/serialize/ObjectIn.java
@@ -0,0 +1,34 @@
+package examples.serialize;
+
+import java.io.*;
+import java.util.*;
+
+public class ObjectIn extends DataInputStream
+{
+ private Vector readObjects = new Vector();
+
+ public ObjectIn(InputStream is) {
+ super(is);
+ }
+
+ public Marshalable readObject() throws IOException {
+ int id = readInt();
+ if (id == -1) return null; /* -1 implies null */
+ if (id == -2) {
+ id = readInt();
+ return (Marshalable) readObjects.elementAt(id);
+ }
+
+ String classname = readUTF();
+ Marshalable obj;
+ try {
+ obj = (Marshalable) Class.forName(classname).newInstance();
+ } catch (Exception ex) {
+ throw new IOException(ex.toString());
+ }
+ readObjects.addElement(obj);
+ obj.readObject(this);
+
+ return obj;
+ }
+}
diff --git a/tutorial/examples/serialize/ObjectOut.java b/tutorial/examples/serialize/ObjectOut.java
new file mode 100644
index 0000000..eb482c2
--- /dev/null
+++ b/tutorial/examples/serialize/ObjectOut.java
@@ -0,0 +1,36 @@
+package examples.serialize;
+
+import java.io.*;
+import java.util.*;
+
+class ObjectOut extends DataOutputStream
+{
+ private Vector writtenObjects = new Vector();
+
+ public ObjectOut(OutputStream os) {
+ super(os);
+ }
+
+ public void writeObject(Marshalable obj) throws IOException {
+ if (obj == null) {
+ writeInt(-1);
+ } else {
+ int id = 0;
+ int size = writtenObjects.size();
+ for (; id < size; ++id) {
+ if (writtenObjects.elementAt(id) == obj) break;
+ }
+ if (id < size) {
+ /* this object is already written to this stream */
+ writeInt(-2);
+ writeInt(id);
+ } else {
+ /* this object is not regisered in the table */
+ writeInt(id);
+ writtenObjects.addElement(obj);
+ obj.writeObject(this);
+ }
+ }
+ }
+
+}
diff --git a/tutorial/examples/serialize/Point.oj b/tutorial/examples/serialize/Point.oj
new file mode 100644
index 0000000..e7db5f9
--- /dev/null
+++ b/tutorial/examples/serialize/Point.oj
@@ -0,0 +1,29 @@
+package examples.serialize;
+
+import java.io.*;
+
+public class Point
+{
+ int x;
+ int y;
+}
+
+/*
+public class Point implements Marshalable
+{
+ int x;
+ int y;
+
+ public void readObject(ObjectIn is) throws IOException {
+ x = is.readInt();
+ y = is.readInt();
+ }
+
+ public void writeObject(ObjectOut os) throws IOException {
+ os.writeUTF("Point");
+ os.writeInt(x);
+ os.writeInt(y);
+
+ }
+}
+*/
diff --git a/tutorial/examples/serialize/SerializableClass.oj b/tutorial/examples/serialize/SerializableClass.oj
new file mode 100644
index 0000000..b054a78
--- /dev/null
+++ b/tutorial/examples/serialize/SerializableClass.oj
@@ -0,0 +1,121 @@
+package examples.serialize;
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>CapsuleClass</code> is a metaclass which
+ * adds methods for serialization of the instances of the class.
+ */
+public class SerializableClass instantiates Metaclass extends OJClass
+{
+ /** Overrides to translate definition of the class */
+ public void translateDefinition() throws MOPException {
+ OJClass baseClass = getSuperclass();
+
+ OJField[] fields = getDeclaredFields();
+
+ addReaderMethod(fields);
+ addWriterMethod(fields);
+ }
+
+ convenient void addReaderMethod(OJField[] fieldsToWrite)
+ throws MOPException
+ {
+ OJClass declaringClass = this;
+ OJModifier modifier = OJModifier.constantEmpty().setPublic();
+ OJClass returnType = OJSystem.VOID;
+ String methodName = "readObject";
+ OJClass[] paramTypes = new OJClass[]{ObjectIn.class};
+ String[] paramNames = new String[]{"in"};
+ OJClass[] exepTypes = new OJClass[]{java.io.IOException.class};
+ OJMethod reader
+ = new OJMethod(this, modifier, returnType, methodName,
+ paramTypes, paramNames, exepTypes, null);
+ addMethod(reader);
+
+ Environment env = reader.getEnvironment();
+ StatementList body = new StatementList();
+ for (int i = 0; i < fieldsToWrite.length; ++i) {
+ body.add(createReadExprFor(env, fieldsToWrite[i]));
+ }
+ reader.setBody(body);
+ }
+
+ Statement createReadExprFor(Environment env, OJField field)
+ throws MOPException
+ {
+ OJClass type = field.getType();
+ String name = field.getName();
+ if (type == OJSystem.STRING) {
+ return makeStatement(env, name + " = in.readUTF();");
+ } else if (type == OJSystem.BYTE) {
+ return makeStatement(env, name + " = in.readByte();");
+ } else if (type == OJSystem.BOOLEAN) {
+ return makeStatement(env, name + " = in.readBoolean();");
+ } else if (type == OJSystem.CHAR) {
+ return makeStatement(env, name + " = in.readChar();");
+ } else if (type == OJSystem.INT) {
+ return makeStatement(env, name + " = in.readInt();");
+ } else if (type == OJSystem.LONG) {
+ return makeStatement(env, name + " = in.readLong();");
+ } else if (type.isArray()) {
+ return null; /* not implemented yet. */
+ } else if (! type.isPrimitive()) {
+ return makeStatement(env, name + " = in.readObject();");
+ }
+ return null;
+ }
+
+ convenient void addWriterMethod(OJField[] fieldsToWrite)
+ throws MOPException
+ {
+ OJClass declaringClass = this;
+ OJModifier modifier = OJModifier.constantEmpty().setPublic();
+ OJClass returnType = OJSystem.VOID;
+ String methodName = "writeObject";
+ OJClass[] paramTypes = new OJClass[]{ObjectOut.class};
+ String[] paramNames = new String[]{"out"};
+ OJClass[] exepTypes = new OJClass[]{java.io.IOException.class};
+ OJMethod writer
+ = new OJMethod(this, modifier, returnType, methodName,
+ paramTypes, paramNames, exepTypes, null);
+ addMethod(writer);
+
+ Environment env = writer.getEnvironment();
+ StatementList body = new StatementList();
+ body.add(makeStatement(env, "out.writeUTF(\"" + getName() + "\");"));
+ for (int i = 0; i < fieldsToWrite.length; ++i) {
+ body.add(createWriteExprFor(env, fieldsToWrite[i]));
+ }
+ writer.setBody(body);
+ }
+
+ Statement createWriteExprFor(Environment env, OJField field)
+ throws MOPException
+ {
+ OJClass type = field.getType();
+ String name = field.getName();
+ if (type == OJSystem.STRING) {
+ return makeStatement(env, "out.writeUTF(" + name + ");");
+ } else if (type == OJSystem.BYTE) {
+ return makeStatement(env, "out.writeByte(" + name + ");");
+ } else if (type == OJSystem.BOOLEAN) {
+ return makeStatement(env, "out.writeBoolean(" + name + ");");
+ } else if (type == OJSystem.CHAR) {
+ return makeStatement(env, "out.writeChar(" + name + ");");
+ } else if (type == OJSystem.INT) {
+ return makeStatement(env, "out.writeInt(" + name + ");");
+ } else if (type == OJSystem.LONG) {
+ return makeStatement(env, "out.writeLong(" + name + ");");
+ } else if (type.isArray()) {
+ return null; /* not implemented yet. */
+ } else if (! type.isPrimitive()) {
+ return makeStatement(env, "out.writeObject(" + name + ");");
+ }
+ return null;
+ }
+
+}
diff --git a/tutorial/examples/syntax/ErrorTest.java b/tutorial/examples/syntax/ErrorTest.java
new file mode 100644
index 0000000..2dbff68
--- /dev/null
+++ b/tutorial/examples/syntax/ErrorTest.java
@@ -0,0 +1,97 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class ErrorTest extends Panel
+{
+
+ private int iii = 0;
+
+ private Vector v;
+
+ private ErrorTest n = null;
+
+ private String str = "string";
+
+ private static final String DEF = "<default>";
+
+ public ErrorTest()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] args )
+ {}
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+ public void hoge()
+ throws Exception
+ {}
+
+ public void hoge1()
+ {}
+
+ public void hoge2()
+ {}
+
+ public void hoge2( String[] args )
+ {}
+
+ public void f()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1()
+ {}
+
+ public void g2()
+ {}
+
+}
diff --git a/tutorial/examples/syntax/ErrorTest.oj b/tutorial/examples/syntax/ErrorTest.oj
new file mode 100644
index 0000000..78b54b7
--- /dev/null
+++ b/tutorial/examples/syntax/ErrorTest.oj
@@ -0,0 +1,96 @@
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class ErrorTest instantiates RichSyntaxClass
+ extends Panel
+ loves CreamPuff[]
+ hates Pimento/*, Apple*/
+ adapts Vector in v to Stack
+{
+ private int iii = 0;
+ private Vector v;
+
+ private ErrorTest n = null;
+
+ private String str = "string";
+ private final static String DEF = "<default>";
+
+ public ErrorTest() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static remote void main( String[] args ) loves Apple
+ {
+ }
+
+ public String toString() forwards Apple Power Macintosh {
+ if (n == null) return str;
+ return str + n;
+ }
+
+ public void hoge() throws Exception keeps (iii == 0) {}
+ public void hoge1() keeps DEF.equals( "string" ) {}
+ public void hoge2() keeps ErrorTest.DEF.equals( "string" ) {}
+ public void hoge2( String[] args ) keeps (args.length == 1) {}
+
+ public void f() {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ before {
+ System.out.println( "before" );
+ . errorhere;
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ after {
+ System.out.println( "after" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ after {
+ System.out.println( "after" );
+ }
+ before {
+ System.out.println( "before" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1() chooses { System.out.println( "ErrorTest" ); }
+ {}
+
+ public void g2() chooses Object[]
+ {}
+
+}
diff --git a/tutorial/examples/syntax/RichSyntaxClass.java b/tutorial/examples/syntax/RichSyntaxClass.java
new file mode 100644
index 0000000..ca22914
--- /dev/null
+++ b/tutorial/examples/syntax/RichSyntaxClass.java
@@ -0,0 +1,129 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * RichSyntaxClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class RichSyntaxClass extends OJClass
+{
+
+ public void translateDefinition()
+ {
+ String[] str = new String[]{ "hates", "loves", "keeps", "forwards", "before", "after", "chooses", "adapts" };
+ for (int i = 0; i < str.length; ++i) {
+ ParseTree suffix;
+ suffix = this.getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( this.toString() + " involves a suffix " + " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ OJMethod[] methods = getDeclaredMethods();
+ for (int j = 0; j < methods.length; ++j) {
+ suffix = methods[j].getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( methods[j].toString() + " involves a suffix " + " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ }
+ }
+ }
+
+ public static boolean isRegisteredKeyword( String keyword )
+ {
+ if (keyword.equals( "hates" )) {
+ return true;
+ }
+ if (keyword.equals( "loves" )) {
+ return true;
+ }
+ if (keyword.equals( "keeps" )) {
+ return true;
+ }
+ if (keyword.equals( "forwards" )) {
+ return true;
+ }
+ if (keyword.equals( "before" )) {
+ return true;
+ }
+ if (keyword.equals( "after" )) {
+ return true;
+ }
+ if (keyword.equals( "chooses" )) {
+ return true;
+ }
+ if (keyword.equals( "adapts" )) {
+ return true;
+ }
+ return OJClass.isRegisteredKeyword( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword )
+ {
+ if (keyword.equals( "hates" )) {
+ return new NameRule();
+ }
+ if (keyword.equals( "loves" )) {
+ return new TypeNameRule();
+ }
+ if (keyword.equals( "keeps" )) {
+ return new ExpressionRule();
+ }
+ if (keyword.equals( "forwards" )) {
+ return new IterationRule( new TypeNameRule(), false );
+ }
+ if (keyword.equals( "before" ) || keyword.equals( "after" )) {
+ return new BlockRule();
+ }
+ if (keyword.equals( "chooses" ) || keyword.equals( "after" )) {
+ return new SelectionRule( new TypeNameRule(), new BlockRule() );
+ }
+ if (keyword.equals( "adapts" ) || keyword.equals( "after" )) {
+ return new CompositeRule( new NameRule(), new PrepPhraseRule( "in", new NameRule() ), new PrepPhraseRule( "to", new NameRule() ) );
+ }
+ return OJClass.getDeclSuffixRule( keyword );
+ }
+
+ public static SyntaxRule getTypeSuffixRule( String keyword )
+ {
+ return OJClass.getTypeSuffixRule( keyword );
+ }
+
+ public static boolean isRegisteredModifier( String keyword )
+ {
+ if (keyword.equals( "remote" )) {
+ return true;
+ }
+ if (keyword.equals( "crazy" )) {
+ return true;
+ }
+ return false;
+ }
+
+ public RichSyntaxClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public RichSyntaxClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/syntax/RichSyntaxClass.oj b/tutorial/examples/syntax/RichSyntaxClass.oj
new file mode 100644
index 0000000..61005a7
--- /dev/null
+++ b/tutorial/examples/syntax/RichSyntaxClass.oj
@@ -0,0 +1,102 @@
+/*
+ * RichSyntaxClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class RichSyntaxClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() {
+ String[] str = new String[] {
+ "hates", "loves", "keeps", "forwards", "before", "after",
+ "chooses", "adapts", "pre" };
+ for (int i = 0; i < str.length; ++i) {
+ ParseTree suffix;
+ suffix = this.getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( this.toString() + " involves a suffix " +
+ " \"" + str[i] + "\" :" );
+ System.out.println( "\t" + suffix );
+ }
+ OJMethod[] methods = getDeclaredMethods();
+ for (int j = 0; j < methods.length; ++j) {
+ suffix = methods[j].getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( methods[j].toString() +
+ " involves a suffix " +
+ " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ }
+ }
+ }
+
+ public static boolean isRegisteredKeyword( String keyword ) {
+ if (keyword.equals( "replacedBy" )) return true;
+ if (keyword.equals( "hates" )) return true;
+ if (keyword.equals( "loves" )) return true;
+ if (keyword.equals( "keeps" )) return true;
+ if (keyword.equals( "forwards" )) return true;
+ if (keyword.equals( "before" )) return true;
+ if (keyword.equals( "after" )) return true;
+ if (keyword.equals( "chooses" )) return true;
+ if (keyword.equals( "adapts" )) return true;
+ if (keyword.equals( "pre" )) return true;
+ return OJClass.isRegisteredKeyword( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( "hates" )) return new NameRule();
+ if (keyword.equals( "loves" )) return new TypeNameRule();
+ if (keyword.equals( "keeps" )) return new ExpressionRule();
+ if (keyword.equals( "forwards" )) {
+ return new IterationRule( new TypeNameRule(), false );
+ }
+ if (keyword.equals( "before" ) || keyword.equals( "after" )) {
+ return new BlockRule();
+ }
+ if (keyword.equals( "chooses" ) || keyword.equals( "after" )) {
+ return new SelectionRule( new TypeNameRule(), new BlockRule() );
+ }
+ if (keyword.equals( "adapts" ) || keyword.equals( "after" )) {
+ return new CompositeRule(
+ new NameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new NameRule() ) );
+ }
+ return OJClass.getDeclSuffixRule( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule(Environment env,
+ String keyword)
+ {
+ if (keyword.equals("pre")) return new ExpressionRule(env);
+ return OJClass.getDeclSuffixRule(env, keyword);
+ }
+
+ public static SyntaxRule getTypeSuffixRule( String keyword ) {
+ if (keyword.equals( "replacedBy" )) return new TypeNameRule();
+ return OJClass.getTypeSuffixRule( keyword );
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( "remote" )) return true;
+ if (keyword.equals( "crazy" )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/syntax/Test.java b/tutorial/examples/syntax/Test.java
new file mode 100644
index 0000000..f9ad1c5
--- /dev/null
+++ b/tutorial/examples/syntax/Test.java
@@ -0,0 +1,97 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel
+{
+
+ private int iii = 0;
+
+ private Vector v;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ private static final String DEF = "<default>";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] args )
+ {}
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+ public void hoge()
+ throws Exception
+ {}
+
+ public void hoge1()
+ {}
+
+ public void hoge2()
+ {}
+
+ public void hoge2( String[] args )
+ {}
+
+ public void f()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1()
+ {}
+
+ public void g2()
+ {}
+
+}
diff --git a/tutorial/examples/syntax/Test.oj b/tutorial/examples/syntax/Test.oj
new file mode 100644
index 0000000..763945a
--- /dev/null
+++ b/tutorial/examples/syntax/Test.oj
@@ -0,0 +1,96 @@
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates RichSyntaxClass
+ extends Panel
+ loves CreamPuff[]
+ hates Pimento/*, Apple*/
+ adapts Vector in v to Stack
+{
+ private int iii = 0;
+ private Vector v;
+
+ private Test n = null;
+
+ private String str = "string";
+ private final static String DEF = "<default>";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static remote void main( String[] args ) loves Apple
+ {
+ }
+
+ public String toString() forwards Apple Power Macintosh {
+ if (n == null) return str;
+ return str + n;
+ }
+
+ public void hoge() throws Exception keeps (iii == 0) {}
+ public void hoge1() keeps DEF.equals( "string" ) {}
+ public void hoge2() keeps Test.DEF.equals( "string" ) {}
+ public void hoge2( String[] args ) keeps (args.length == 1) {}
+ public void hoge3(int arg) pre arg > 1 {}
+
+ public void f() {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ before {
+ System.out.println( "before" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ after {
+ System.out.println( "after" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ before {
+ System.out.println( "before" );
+ }
+ after {
+ System.out.println( "after" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1() chooses { System.out.println( "Test" ); }
+ {}
+
+ public void g2() chooses Object[]
+ {}
+
+}
diff --git a/tutorial/examples/verbose/Hello.java b/tutorial/examples/verbose/Hello.java
new file mode 100644
index 0000000..4f6cebb
--- /dev/null
+++ b/tutorial/examples/verbose/Hello.java
@@ -0,0 +1,22 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.verbose;
+
+
+public class Hello
+{
+
+ public static void main( java.lang.String[] argv )
+ {
+ java.lang.System.out.println( "public static void examples.verbose.Hello.main(java.lang.String[]) was called" );
+ hello();
+ }
+
+ static void hello()
+ {
+ java.lang.System.out.println( "static void examples.verbose.Hello.hello() was called" );
+ System.out.println( "Hello, world." );
+ }
+
+}
diff --git a/tutorial/examples/verbose/Hello.oj b/tutorial/examples/verbose/Hello.oj
new file mode 100644
index 0000000..0267289
--- /dev/null
+++ b/tutorial/examples/verbose/Hello.oj
@@ -0,0 +1,13 @@
+package examples.verbose;
+
+
+public class Hello instantiates VerboseClass
+{
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/tutorial/examples/verbose/Test.java b/tutorial/examples/verbose/Test.java
new file mode 100644
index 0000000..7b60da7
--- /dev/null
+++ b/tutorial/examples/verbose/Test.java
@@ -0,0 +1,98 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.verbose;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends java.awt.Panel
+{
+
+ private int iii = 0;
+
+ private examples.verbose.Test n = null;
+
+ private java.lang.String str = "string";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( java.lang.String[] argv )
+ {
+ java.lang.System.out.println( "public static void examples.verbose.Test.main(java.lang.String[]) was called" );
+ java.io.PrintStream out = System.out;
+ java.io.PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ examples.verbose.Test n = new examples.verbose.Test();
+ java.lang.System.err.println( "done. " );
+ examples.verbose.Test test = new examples.verbose.Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge()
+ {
+ java.lang.System.out.println( "public void examples.verbose.Test.hoge() was called" );
+ examples.verbose.Local l = new examples.verbose.Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( java.lang.String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ java.lang.System.out.println( "public int examples.verbose.Test.foo() was called" );
+ return iii;
+ }
+
+ public java.lang.String toString()
+ {
+ java.lang.System.out.println( "public java.lang.String examples.verbose.Test.toString() was called" );
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
+
+
+class Local
+{
+
+ java.lang.String foo = null;
+
+ examples.verbose.Local2 bar = new examples.verbose.Local2();
+
+ public final java.lang.String getFoo( java.lang.Integer i )
+ {
+ java.lang.System.out.println( "public final java.lang.String examples.verbose.Local.getFoo(java.lang.Integer) was called" );
+ return foo;
+ }
+
+}
+
+
+class Local2
+{
+
+ java.lang.String str = "" + "TEST";
+
+}
diff --git a/tutorial/examples/verbose/Test.oj b/tutorial/examples/verbose/Test.oj
new file mode 100644
index 0000000..24de2ea
--- /dev/null
+++ b/tutorial/examples/verbose/Test.oj
@@ -0,0 +1,73 @@
+package examples.verbose;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates VerboseClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
+
+class Local instantiates VerboseClass
+{
+ String foo = null;
+ Local2 bar = new Local2();
+ public final String getFoo( Integer i ) {
+ return foo;
+ }
+}
+
+class Local2
+{
+ String str = "" + "TEST";
+}
diff --git a/tutorial/examples/verbose/VerboseClass.java b/tutorial/examples/verbose/VerboseClass.java
new file mode 100644
index 0000000..ef74480
--- /dev/null
+++ b/tutorial/examples/verbose/VerboseClass.java
@@ -0,0 +1,45 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * VerboseClass.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.verbose;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class VerboseClass extends openjava.mop.OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws openjava.mop.MOPException
+ {
+ openjava.mop.OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ openjava.ptree.Statement printer = makeStatement( "java.lang.System.out.println( \"" + methods[i].toString() + " was called\" );" );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+
+ public VerboseClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public VerboseClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/verbose/VerboseClass.oj b/tutorial/examples/verbose/VerboseClass.oj
new file mode 100644
index 0000000..a6ac099
--- /dev/null
+++ b/tutorial/examples/verbose/VerboseClass.oj
@@ -0,0 +1,30 @@
+/*
+ * VerboseClass.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.verbose;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class VerboseClass instantiates Metaclass extends OJClass
+{
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Statement printer = makeStatement(
+ "java.lang.System.out.println( \"" +
+ methods[i].toString() + " was called\" );" );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+}
diff --git a/tutorial/examples/verbose2/Test.java b/tutorial/examples/verbose2/Test.java
new file mode 100644
index 0000000..50848fb
--- /dev/null
+++ b/tutorial/examples/verbose2/Test.java
@@ -0,0 +1,98 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.verbose2;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel
+{
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv )
+ {
+ java.lang.System.out.println( "main is called." );
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge()
+ {
+ java.lang.System.out.println( "hoge is called." );
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ java.lang.System.out.println( "foo is called." );
+ return iii;
+ }
+
+ public String toString()
+ {
+ java.lang.System.out.println( "toString is called." );
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
+
+
+class Local
+{
+
+ String foo = null;
+
+ Local2 bar = new Local2();
+
+ public final String getFoo( Integer i )
+ {
+ java.lang.System.out.println( "getFoo is called." );
+ return foo;
+ }
+
+}
+
+
+class Local2
+{
+
+ String str = "" + "TEST";
+
+}
diff --git a/tutorial/examples/verbose2/Test.oj b/tutorial/examples/verbose2/Test.oj
new file mode 100644
index 0000000..c882183
--- /dev/null
+++ b/tutorial/examples/verbose2/Test.oj
@@ -0,0 +1,73 @@
+package examples.verbose2;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates VerboseClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
+
+class Local instantiates VerboseClass
+{
+ String foo = null;
+ Local2 bar = new Local2();
+ public final String getFoo( Integer i ) {
+ return foo;
+ }
+}
+
+class Local2
+{
+ String str = "" + "TEST";
+}
diff --git a/tutorial/examples/verbose2/VerboseClass.java b/tutorial/examples/verbose2/VerboseClass.java
new file mode 100644
index 0000000..1e6cdf0
--- /dev/null
+++ b/tutorial/examples/verbose2/VerboseClass.java
@@ -0,0 +1,50 @@
+/*
+ * VerboseClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.verbose2;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import openjava.ptree.util.PartialParser;
+
+
+public class VerboseClass extends OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ StatementList body = methods[i].getBody();
+ String str = PartialParser.replace(
+ "java.lang.System.out.println( \"#s\" );",
+ methods[i].getName() + " is called."
+ );
+ Statement printer = makeStatement( str );
+ body.insertElementAt( printer, 0 );
+ }
+ }
+
+ /* constructor */
+
+ public VerboseClass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree ) {
+ super( outer_env, declarer, ptree );
+ }
+
+ public VerboseClass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+}
+
diff --git a/tutorial/images/comflow.gif b/tutorial/images/comflow.gif
new file mode 100644
index 0000000..f995bb2
--- /dev/null
+++ b/tutorial/images/comflow.gif
Binary files differ
diff --git a/tutorial/index.html b/tutorial/index.html
new file mode 100644
index 0000000..353f999
--- /dev/null
+++ b/tutorial/index.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+<h2><font color="blue">Index</font></h2>
+
+
+<ul>
+<li><a href="Introduction.html"
+ >1. Introduction</a><br>
+<li><a href="VerboseClass.html"
+ >2. Hello World</a><br>
+<li><a href="Overview.html"
+ >3. API and Framework at a Glance</a><br>
+<li><a href="Override.html"
+ >4. Example : Override Checker</a><br>
+ A simple syntax extension example of custom modifiers.
+<li><a href="AutoImpl.html"
+ >5. Example : Automatic Methods Implementation</a><br>
+ A callee-side translation example.
+<li><a href="FreeArgs.html"
+ >6. (Under Construction) Example : Free Arguments</a><br>
+ A caller-side translation example.
+<li><a href="Synchronize.html"
+ >7. Synchronization of Translation</a><br>
+ A synchronization of translation among several class metaobjects.
+<li><a href="Syntax.html"
+ >8. (Not Written) Syntax Customization</a><br>
+<li><a href="Adapter.html"
+ >9. (Not Written) Example : Adapter Pattern Support</a><br>
+</ul>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>