From 733d4f5168fb54b0ea9820cc02e86c981cf320b8 Mon Sep 17 00:00:00 2001 From: Pavel Talanov Date: Wed, 9 Nov 2011 16:00:19 +0400 Subject: [PATCH] split code into modules and lots of other code changes --- .idea/modules.xml | 2 + .idea/workspace.xml | 690 +- js/js.iml | 12 + .../compiler/InternalCompilerException.java | 2 +- .../dart => js/src}/compiler/Source.java | 2 +- .../src}/compiler/backend/js/Cloner.java | 6 +- .../js/JsConstructExpressionVisitor.java | 4 +- .../backend/js/JsFirstExpressionVisitor.java | 4 +- .../src}/compiler/backend/js/JsNamer.java | 4 +- .../compiler/backend/js/JsNormalizer.java | 4 +- .../backend/js/JsParserException.java | 2 +- .../backend/js/JsPrecedenceVisitor.java | 6 +- .../compiler/backend/js/JsPrettyNamer.java | 10 +- .../backend/js/JsRequiresSemiVisitor.java | 4 +- .../backend/js/JsReservedIdentifiers.java | 2 +- .../backend/js/JsSourceGenerationVisitor.java | 12 +- .../js/JsToStringGenerationVisitor.java | 11 +- .../js/UncheckedJsParserException.java | 2 +- .../backend/js/ast/CanBooleanEval.java | 2 +- .../compiler/backend/js/ast/HasArguments.java | 2 +- .../compiler/backend/js/ast/HasCondition.java | 2 +- .../src}/compiler/backend/js/ast/HasName.java | 2 +- .../backend/js/ast/JsArrayAccess.java | 2 +- .../backend/js/ast/JsArrayLiteral.java | 2 +- .../backend/js/ast/JsBinaryOperation.java | 2 +- .../backend/js/ast/JsBinaryOperator.java | 2 +- .../src}/compiler/backend/js/ast/JsBlock.java | 2 +- .../backend/js/ast/JsBooleanLiteral.java | 2 +- .../src}/compiler/backend/js/ast/JsBreak.java | 2 +- .../src}/compiler/backend/js/ast/JsCase.java | 2 +- .../src}/compiler/backend/js/ast/JsCatch.java | 2 +- .../compiler/backend/js/ast/JsCatchScope.java | 2 +- .../backend/js/ast/JsConditional.java | 2 +- .../compiler/backend/js/ast/JsContext.java | 2 +- .../compiler/backend/js/ast/JsContinue.java | 2 +- .../compiler/backend/js/ast/JsDebugger.java | 2 +- .../compiler/backend/js/ast/JsDefault.java | 2 +- .../compiler/backend/js/ast/JsDoWhile.java | 2 +- .../src}/compiler/backend/js/ast/JsEmpty.java | 2 +- .../compiler/backend/js/ast/JsExprStmt.java | 2 +- .../compiler/backend/js/ast/JsExpression.java | 4 +- .../src}/compiler/backend/js/ast/JsFor.java | 4 +- .../src}/compiler/backend/js/ast/JsForIn.java | 2 +- .../compiler/backend/js/ast/JsFunction.java | 4 +- .../backend/js/ast/JsGlobalBlock.java | 2 +- .../src}/compiler/backend/js/ast/JsIf.java | 2 +- .../compiler/backend/js/ast/JsInvocation.java | 2 +- .../src}/compiler/backend/js/ast/JsLabel.java | 2 +- .../compiler/backend/js/ast/JsLiteral.java | 2 +- .../compiler/backend/js/ast/JsModVisitor.java | 4 +- .../src}/compiler/backend/js/ast/JsName.java | 4 +- .../compiler/backend/js/ast/JsNameRef.java | 2 +- .../src}/compiler/backend/js/ast/JsNew.java | 2 +- .../src}/compiler/backend/js/ast/JsNode.java | 12 +- .../backend/js/ast/JsNullLiteral.java | 2 +- .../backend/js/ast/JsNumberLiteral.java | 2 +- .../backend/js/ast/JsObjectLiteral.java | 2 +- .../compiler/backend/js/ast/JsOperator.java | 2 +- .../compiler/backend/js/ast/JsParameter.java | 2 +- .../backend/js/ast/JsPostfixOperation.java | 2 +- .../backend/js/ast/JsPrefixOperation.java | 2 +- .../compiler/backend/js/ast/JsProgram.java | 6 +- .../backend/js/ast/JsProgramFragment.java | 2 +- .../backend/js/ast/JsPropertyInitializer.java | 2 +- .../compiler/backend/js/ast/JsRegExp.java | 2 +- .../compiler/backend/js/ast/JsReturn.java | 2 +- .../compiler/backend/js/ast/JsRootScope.java | 4 +- .../src}/compiler/backend/js/ast/JsScope.java | 14 +- .../compiler/backend/js/ast/JsStatement.java | 2 +- .../backend/js/ast/JsStringLiteral.java | 2 +- .../compiler/backend/js/ast/JsSwitch.java | 2 +- .../backend/js/ast/JsSwitchMember.java | 2 +- .../compiler/backend/js/ast/JsThisRef.java | 2 +- .../src}/compiler/backend/js/ast/JsThrow.java | 2 +- .../src}/compiler/backend/js/ast/JsTry.java | 2 +- .../backend/js/ast/JsUnaryOperation.java | 2 +- .../backend/js/ast/JsUnaryOperator.java | 2 +- .../backend/js/ast/JsValueLiteral.java | 2 +- .../src}/compiler/backend/js/ast/JsVars.java | 4 +- .../compiler/backend/js/ast/JsVisitable.java | 2 +- .../compiler/backend/js/ast/JsVisitor.java | 8 +- .../src}/compiler/backend/js/ast/JsWhile.java | 2 +- .../compiler/backend/js/ast/NodeKind.java | 2 +- .../src}/compiler/common/AbstractNode.java | 4 +- .../src}/compiler/common/HasSourceInfo.java | 4 +- .../dart => js/src}/compiler/common/Name.java | 2 +- .../src}/compiler/common/NameFactory.java | 2 +- .../src}/compiler/common/SourceInfo.java | 4 +- .../compiler/util/AbstractTextOutput.java | 2 +- .../src}/compiler/util/AstUtil.java | 18 +- .../src}/compiler/util/DefaultTextOutput.java | 2 +- .../dart => js/src}/compiler/util/Hack.java | 2 +- .../dart => js/src}/compiler/util/Lists.java | 2 +- .../dart => js/src}/compiler/util/Maps.java | 2 +- .../dart => js/src}/compiler/util/Paths.java | 2 +- .../src}/compiler/util/TextOutput.java | 2 +- .../k2js/translate/ContextType$1.class | Bin 1023 -> 0 bytes .../k2js/translate/ContextType$2.class | Bin 1237 -> 0 bytes .../k2js/translate/ContextType$3.class | Bin 1239 -> 0 bytes .../k2js/translate/ContextType.class | Bin 1872 -> 0 bytes ...anslator$FunctionVariableDeclaration.class | Bin 2386 -> 0 bytes ...nslator$NamespacePropertyDeclaration.class | Bin 2920 -> 0 bytes .../DeclarationTranslator$State.class | Bin 724 -> 0 bytes .../compiler/backend/js/JsNameProvider.java | 85 - .../k2js/translate/ClassBodyVisitor.java | 101 - .../jetbrains/k2js/translate/ContextType.java | 24 - .../k2js/translate/DeclarationTranslator.java | 95 - .../k2js/translate/ExpressionVisitor.java | 135 - .../jetbrains/k2js/translate/K2JsVisitor.java | 17 - test/org/jetbrains/k2js/test/ClassTest.java | 50 + .../org/jetbrains/k2js/test/FunctionTest.java | 30 + .../jetbrains/k2js/test/TranslationTest.java | 66 + .../jetbrains/k2js/test/TranslatorTests.java | 74 - test_files/test_cases/assign.jet | 4 - test_files/test_cases/classInstantiation.kt | 9 + test_files/test_cases/comparison.kt | 9 + test_files/test_cases/incrementProperty.jet | 14 + test_files/test_cases/kotlin_lib.js | 288 + test_files/test_cases/localProperty.jet | 4 +- test_files/test_cases/prototype.js | 6008 +++++++++++++++++ test_files/test_cases/testKotlinLib.js | 12 + .../src}/k2js/K2JSTranslator.java | 6 +- .../src}/k2js/generate/CodeGenerator.java | 2 +- .../k2js/translate/AbstractTranslator.java | 14 +- .../src/k2js/translate/ClassBodyVisitor.java | 136 + .../src}/k2js/translate/ClassTranslator.java | 12 +- .../k2js/translate/DeclarationTranslator.java | 26 + .../k2js/translate/DeclarationVisitor.java | 63 + .../k2js/translate/ExpressionTranslator.java | 9 +- .../src/k2js/translate/ExpressionVisitor.java | 176 + .../k2js/translate/FunctionTranslator.java | 25 +- .../src}/k2js/translate/GenerationState.java | 25 +- .../src}/k2js/translate/Namer.java | 36 +- .../k2js/translate/NamespaceTranslator.java | 28 +- .../k2js/translate/OperationTranslator.java | 5 +- .../k2js/translate/TranslationContext.java | 89 +- .../src/k2js/translate/TranslatorVisitor.java | 29 + translator/translator.iml | 15 + 138 files changed, 7559 insertions(+), 1165 deletions(-) create mode 100644 js/js.iml rename {src/com/google/dart => js/src}/compiler/InternalCompilerException.java (92%) rename {src/com/google/dart => js/src}/compiler/Source.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/Cloner.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsConstructExpressionVisitor.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsFirstExpressionVisitor.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsNamer.java (88%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsNormalizer.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsParserException.java (98%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsPrecedenceVisitor.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsPrettyNamer.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsRequiresSemiVisitor.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsReservedIdentifiers.java (99%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsSourceGenerationVisitor.java (70%) rename {src/com/google/dart => js/src}/compiler/backend/js/JsToStringGenerationVisitor.java (99%) rename {src/com/google/dart => js/src}/compiler/backend/js/UncheckedJsParserException.java (93%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/CanBooleanEval.java (88%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/HasArguments.java (88%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/HasCondition.java (89%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/HasName.java (87%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsArrayAccess.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsArrayLiteral.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsBinaryOperation.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsBinaryOperator.java (98%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsBlock.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsBooleanLiteral.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsBreak.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsCase.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsCatch.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsCatchScope.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsConditional.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsContext.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsContinue.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsDebugger.java (91%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsDefault.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsDoWhile.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsEmpty.java (91%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsExprStmt.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsExpression.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsFor.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsForIn.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsFunction.java (98%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsGlobalBlock.java (89%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsIf.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsInvocation.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsLabel.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsLiteral.java (88%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsModVisitor.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsName.java (93%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsNameRef.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsNew.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsNode.java (77%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsNullLiteral.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsNumberLiteral.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsObjectLiteral.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsOperator.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsParameter.java (93%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsPostfixOperation.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsPrefixOperation.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsProgram.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsProgramFragment.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsPropertyInitializer.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsRegExp.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsReturn.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsRootScope.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsScope.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsStatement.java (91%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsStringLiteral.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsSwitch.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsSwitchMember.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsThisRef.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsThrow.java (94%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsTry.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsUnaryOperation.java (96%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsUnaryOperator.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsValueLiteral.java (91%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsVars.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsVisitable.java (92%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsVisitor.java (97%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/JsWhile.java (95%) rename {src/com/google/dart => js/src}/compiler/backend/js/ast/NodeKind.java (93%) rename {src/com/google/dart => js/src}/compiler/common/AbstractNode.java (96%) rename {src/com/google/dart => js/src}/compiler/common/HasSourceInfo.java (96%) rename {src/com/google/dart => js/src}/compiler/common/Name.java (98%) rename {src/com/google/dart => js/src}/compiler/common/NameFactory.java (99%) rename {src/com/google/dart => js/src}/compiler/common/SourceInfo.java (95%) rename {src/com/google/dart => js/src}/compiler/util/AbstractTextOutput.java (98%) rename {src/com/google/dart => js/src}/compiler/util/AstUtil.java (94%) rename {src/com/google/dart => js/src}/compiler/util/DefaultTextOutput.java (95%) rename {src/com/google/dart => js/src}/compiler/util/Hack.java (91%) rename {src/com/google/dart => js/src}/compiler/util/Lists.java (99%) rename {src/com/google/dart => js/src}/compiler/util/Maps.java (99%) rename {src/com/google/dart => js/src}/compiler/util/Paths.java (98%) rename {src/com/google/dart => js/src}/compiler/util/TextOutput.java (93%) delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/ContextType$1.class delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/ContextType$2.class delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/ContextType$3.class delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/ContextType.class delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$FunctionVariableDeclaration.class delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$NamespacePropertyDeclaration.class delete mode 100644 out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$State.class delete mode 100644 src/com/google/dart/compiler/backend/js/JsNameProvider.java delete mode 100644 src/org/jetbrains/k2js/translate/ClassBodyVisitor.java delete mode 100644 src/org/jetbrains/k2js/translate/ContextType.java delete mode 100644 src/org/jetbrains/k2js/translate/DeclarationTranslator.java delete mode 100644 src/org/jetbrains/k2js/translate/ExpressionVisitor.java delete mode 100644 src/org/jetbrains/k2js/translate/K2JsVisitor.java create mode 100644 test/org/jetbrains/k2js/test/ClassTest.java create mode 100644 test/org/jetbrains/k2js/test/FunctionTest.java create mode 100644 test/org/jetbrains/k2js/test/TranslationTest.java delete mode 100644 test/org/jetbrains/k2js/test/TranslatorTests.java create mode 100644 test_files/test_cases/classInstantiation.kt create mode 100644 test_files/test_cases/comparison.kt create mode 100644 test_files/test_cases/incrementProperty.jet create mode 100644 test_files/test_cases/kotlin_lib.js create mode 100644 test_files/test_cases/prototype.js create mode 100644 test_files/test_cases/testKotlinLib.js rename {src/org/jetbrains => translator/src}/k2js/K2JSTranslator.java (98%) rename {src/org/jetbrains => translator/src}/k2js/generate/CodeGenerator.java (96%) rename {src/org/jetbrains => translator/src}/k2js/translate/AbstractTranslator.java (64%) create mode 100644 translator/src/k2js/translate/ClassBodyVisitor.java rename {src/org/jetbrains => translator/src}/k2js/translate/ClassTranslator.java (88%) create mode 100644 translator/src/k2js/translate/DeclarationTranslator.java create mode 100644 translator/src/k2js/translate/DeclarationVisitor.java rename {src/org/jetbrains => translator/src}/k2js/translate/ExpressionTranslator.java (59%) create mode 100644 translator/src/k2js/translate/ExpressionVisitor.java rename {src/org/jetbrains => translator/src}/k2js/translate/FunctionTranslator.java (61%) rename {src/org/jetbrains => translator/src}/k2js/translate/GenerationState.java (73%) rename {src/org/jetbrains => translator/src}/k2js/translate/Namer.java (54%) rename {src/org/jetbrains => translator/src}/k2js/translate/NamespaceTranslator.java (65%) rename {src/org/jetbrains => translator/src}/k2js/translate/OperationTranslator.java (90%) rename {src/org/jetbrains => translator/src}/k2js/translate/TranslationContext.java (52%) create mode 100644 translator/src/k2js/translate/TranslatorVisitor.java create mode 100644 translator/translator.iml diff --git a/.idea/modules.xml b/.idea/modules.xml index f3a426e5e8c..53f7f727eea 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -6,7 +6,9 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a7593997c22..30ec5a0474a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,18 +6,144 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + @@ -42,20 +168,7 @@ - - - + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -122,82 +280,37 @@ - - + + - + - - + + - + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -207,38 +320,31 @@ + + + + + + + + + - + - + - - + + - - - - - - - - - - - - - - - - - - - - + + + + @@ -246,41 +352,43 @@ - + - - + + - + - - + + - + - - + + - - + + + + - - + + @@ -288,10 +396,19 @@ - + - + + + + + + + + + + @@ -313,22 +430,22 @@ @@ -371,22 +488,6 @@ - - - - - - - - - - - - @@ -415,11 +516,7 @@ @@ -433,21 +530,7 @@ + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -557,7 +604,7 @@ - + @@ -584,7 +631,7 @@ - + - - - - + - + - + - - - - + - - - @@ -795,10 +824,10 @@ - - - - + + + + localhost @@ -834,29 +863,29 @@ - + - + - + - + - + - + @@ -911,116 +940,116 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1078,12 +1107,11 @@ - k2js + translator diff --git a/js/js.iml b/js/js.iml new file mode 100644 index 00000000000..b88b4205c3d --- /dev/null +++ b/js/js.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/com/google/dart/compiler/InternalCompilerException.java b/js/src/compiler/InternalCompilerException.java similarity index 92% rename from src/com/google/dart/compiler/InternalCompilerException.java rename to js/src/compiler/InternalCompilerException.java index 5db265e920a..f2b21a7a5ba 100644 --- a/src/com/google/dart/compiler/InternalCompilerException.java +++ b/js/src/compiler/InternalCompilerException.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler; +package compiler; /** * Exception thrown when the compiler encounters an unexpected internal error. diff --git a/src/com/google/dart/compiler/Source.java b/js/src/compiler/Source.java similarity index 96% rename from src/com/google/dart/compiler/Source.java rename to js/src/compiler/Source.java index 13e6e16cbdd..b8828150f52 100644 --- a/src/com/google/dart/compiler/Source.java +++ b/js/src/compiler/Source.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler; +package compiler; import java.io.IOException; import java.io.Reader; diff --git a/src/com/google/dart/compiler/backend/js/Cloner.java b/js/src/compiler/backend/js/Cloner.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/Cloner.java rename to js/src/compiler/backend/js/Cloner.java index fa3447fe168..fcb78d3f262 100644 --- a/src/com/google/dart/compiler/backend/js/Cloner.java +++ b/js/src/compiler/backend/js/Cloner.java @@ -24,10 +24,10 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.InternalCompilerException; -import com.google.dart.compiler.backend.js.ast.*; +import compiler.InternalCompilerException; +import compiler.backend.js.ast.*; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java b/js/src/compiler/backend/js/JsConstructExpressionVisitor.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java rename to js/src/compiler/backend/js/JsConstructExpressionVisitor.java index a15af6b44ed..07449942efd 100644 --- a/src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java +++ b/js/src/compiler/backend/js/JsConstructExpressionVisitor.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.*; +import compiler.backend.js.ast.*; /** * Searches for method invocations in constructor expressions that would not diff --git a/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java b/js/src/compiler/backend/js/JsFirstExpressionVisitor.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java rename to js/src/compiler/backend/js/JsFirstExpressionVisitor.java index 0fdb8a5032b..b5e5af1f486 100644 --- a/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java +++ b/js/src/compiler/backend/js/JsFirstExpressionVisitor.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.*; +import compiler.backend.js.ast.*; /** * Determines if an expression statement needs to be surrounded by parentheses. diff --git a/src/com/google/dart/compiler/backend/js/JsNamer.java b/js/src/compiler/backend/js/JsNamer.java similarity index 88% rename from src/com/google/dart/compiler/backend/js/JsNamer.java rename to js/src/compiler/backend/js/JsNamer.java index 0c49ad05750..b4d497a6263 100644 --- a/src/com/google/dart/compiler/backend/js/JsNamer.java +++ b/js/src/compiler/backend/js/JsNamer.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.JsProgram; +import compiler.backend.js.ast.JsProgram; /** * A namer runs through a program and renames the short names of JsNames. diff --git a/src/com/google/dart/compiler/backend/js/JsNormalizer.java b/js/src/compiler/backend/js/JsNormalizer.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/JsNormalizer.java rename to js/src/compiler/backend/js/JsNormalizer.java index 04c5530cd42..b614b52a442 100644 --- a/src/com/google/dart/compiler/backend/js/JsNormalizer.java +++ b/js/src/compiler/backend/js/JsNormalizer.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.*; +import compiler.backend.js.ast.*; /** * Fixes any semantic errors introduced by JS AST gen. diff --git a/src/com/google/dart/compiler/backend/js/JsParserException.java b/js/src/compiler/backend/js/JsParserException.java similarity index 98% rename from src/com/google/dart/compiler/backend/js/JsParserException.java rename to js/src/compiler/backend/js/JsParserException.java index 79b53c1d69e..84432785c65 100644 --- a/src/com/google/dart/compiler/backend/js/JsParserException.java +++ b/js/src/compiler/backend/js/JsParserException.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; /** * Indicates inability to parse JavaScript source. diff --git a/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java b/js/src/compiler/backend/js/JsPrecedenceVisitor.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java rename to js/src/compiler/backend/js/JsPrecedenceVisitor.java index 2cc6a3b16ed..2fbed323e6b 100644 --- a/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java +++ b/js/src/compiler/backend/js/JsPrecedenceVisitor.java @@ -2,10 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; +import compiler.backend.js.ast.JsVars.JsVar; +import compiler.backend.js.ast.*; /** * Precedence indices from "JavaScript - The Definitive Guide" 4th Edition (page diff --git a/src/com/google/dart/compiler/backend/js/JsPrettyNamer.java b/js/src/compiler/backend/js/JsPrettyNamer.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/JsPrettyNamer.java rename to js/src/compiler/backend/js/JsPrettyNamer.java index 2c61e01f6b3..e0f5dafcc4a 100644 --- a/src/com/google/dart/compiler/backend/js/JsPrettyNamer.java +++ b/js/src/compiler/backend/js/JsPrettyNamer.java @@ -2,12 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.JsName; -import com.google.dart.compiler.backend.js.ast.JsProgram; -import com.google.dart.compiler.backend.js.ast.JsRootScope; -import com.google.dart.compiler.backend.js.ast.JsScope; +import compiler.backend.js.ast.JsName; +import compiler.backend.js.ast.JsProgram; +import compiler.backend.js.ast.JsRootScope; +import compiler.backend.js.ast.JsScope; import java.util.*; diff --git a/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java b/js/src/compiler/backend/js/JsRequiresSemiVisitor.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java rename to js/src/compiler/backend/js/JsRequiresSemiVisitor.java index f4095c5c822..23fd588a197 100644 --- a/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java +++ b/js/src/compiler/backend/js/JsRequiresSemiVisitor.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.*; +import compiler.backend.js.ast.*; /** * Determines if a statement at the end of a block requires a semicolon. diff --git a/src/com/google/dart/compiler/backend/js/JsReservedIdentifiers.java b/js/src/compiler/backend/js/JsReservedIdentifiers.java similarity index 99% rename from src/com/google/dart/compiler/backend/js/JsReservedIdentifiers.java rename to js/src/compiler/backend/js/JsReservedIdentifiers.java index 56ae5428a3d..1889766557c 100644 --- a/src/com/google/dart/compiler/backend/js/JsReservedIdentifiers.java +++ b/js/src/compiler/backend/js/JsReservedIdentifiers.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; import java.util.HashSet; import java.util.Set; diff --git a/src/com/google/dart/compiler/backend/js/JsSourceGenerationVisitor.java b/js/src/compiler/backend/js/JsSourceGenerationVisitor.java similarity index 70% rename from src/com/google/dart/compiler/backend/js/JsSourceGenerationVisitor.java rename to js/src/compiler/backend/js/JsSourceGenerationVisitor.java index ebb836a7228..b09031ae955 100644 --- a/src/com/google/dart/compiler/backend/js/JsSourceGenerationVisitor.java +++ b/js/src/compiler/backend/js/JsSourceGenerationVisitor.java @@ -2,13 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.JsBlock; -import com.google.dart.compiler.backend.js.ast.JsContext; -import com.google.dart.compiler.backend.js.ast.JsProgram; -import com.google.dart.compiler.backend.js.ast.JsProgramFragment; -import com.google.dart.compiler.util.TextOutput; +import compiler.backend.js.ast.JsContext; +import compiler.backend.js.ast.JsProgramFragment; +import compiler.util.TextOutput; +import compiler.backend.js.ast.JsBlock; +import compiler.backend.js.ast.JsProgram; /** * Generates JavaScript source from an AST. diff --git a/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java b/js/src/compiler/backend/js/JsToStringGenerationVisitor.java similarity index 99% rename from src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java rename to js/src/compiler/backend/js/JsToStringGenerationVisitor.java index b94d128895e..0c04444df5d 100644 --- a/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java +++ b/js/src/compiler/backend/js/JsToStringGenerationVisitor.java @@ -2,11 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; -import com.google.dart.compiler.util.TextOutput; +import compiler.util.TextOutput; +import compiler.backend.js.ast.*; import java.util.*; import java.util.regex.Pattern; @@ -880,7 +879,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsVar x, JsContext ctx) { + public boolean visit(JsVars.JsVar x, JsContext ctx) { _nameOf(x); JsExpression initExpr = x.getInitExpr(); if (initExpr != null) { @@ -899,7 +898,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { _var(); _space(); boolean sep = false; - for (JsVar var : x) { + for (JsVars.JsVar var : x) { sep = _sepCommaOptSpace(sep); accept(var); } diff --git a/src/com/google/dart/compiler/backend/js/UncheckedJsParserException.java b/js/src/compiler/backend/js/UncheckedJsParserException.java similarity index 93% rename from src/com/google/dart/compiler/backend/js/UncheckedJsParserException.java rename to js/src/compiler/backend/js/UncheckedJsParserException.java index c2db8120537..2958a181cc7 100644 --- a/src/com/google/dart/compiler/backend/js/UncheckedJsParserException.java +++ b/js/src/compiler/backend/js/UncheckedJsParserException.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js; +package compiler.backend.js; /** * An unchecked wrapper exception to interop with Rhino. diff --git a/src/com/google/dart/compiler/backend/js/ast/CanBooleanEval.java b/js/src/compiler/backend/js/ast/CanBooleanEval.java similarity index 88% rename from src/com/google/dart/compiler/backend/js/ast/CanBooleanEval.java rename to js/src/compiler/backend/js/ast/CanBooleanEval.java index 8f4364d94f2..6920c53c27c 100644 --- a/src/com/google/dart/compiler/backend/js/ast/CanBooleanEval.java +++ b/js/src/compiler/backend/js/ast/CanBooleanEval.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * An interface that describes the boolean evaluation of an expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/HasArguments.java b/js/src/compiler/backend/js/ast/HasArguments.java similarity index 88% rename from src/com/google/dart/compiler/backend/js/ast/HasArguments.java rename to js/src/compiler/backend/js/ast/HasArguments.java index 5a47c567606..ebcbf1aaa7b 100644 --- a/src/com/google/dart/compiler/backend/js/ast/HasArguments.java +++ b/js/src/compiler/backend/js/ast/HasArguments.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/HasCondition.java b/js/src/compiler/backend/js/ast/HasCondition.java similarity index 89% rename from src/com/google/dart/compiler/backend/js/ast/HasCondition.java rename to js/src/compiler/backend/js/ast/HasCondition.java index 082f4e15eb3..318476094c6 100644 --- a/src/com/google/dart/compiler/backend/js/ast/HasCondition.java +++ b/js/src/compiler/backend/js/ast/HasCondition.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Implemented by JavaScript objects with conditional execution. diff --git a/src/com/google/dart/compiler/backend/js/ast/HasName.java b/js/src/compiler/backend/js/ast/HasName.java similarity index 87% rename from src/com/google/dart/compiler/backend/js/ast/HasName.java rename to js/src/compiler/backend/js/ast/HasName.java index 8daed3769f4..31af4e91dcc 100644 --- a/src/com/google/dart/compiler/backend/js/ast/HasName.java +++ b/js/src/compiler/backend/js/ast/HasName.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Implemented by JavaScript objects that have a name. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java b/js/src/compiler/backend/js/ast/JsArrayAccess.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java rename to js/src/compiler/backend/js/ast/JsArrayAccess.java index 46df5108086..46a9f16b8c5 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java +++ b/js/src/compiler/backend/js/ast/JsArrayAccess.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a javascript expression for array access. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java b/js/src/compiler/backend/js/ast/JsArrayLiteral.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java rename to js/src/compiler/backend/js/ast/JsArrayLiteral.java index 8cb9f7e6d52..8dff0837657 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java +++ b/js/src/compiler/backend/js/ast/JsArrayLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java b/js/src/compiler/backend/js/ast/JsBinaryOperation.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java rename to js/src/compiler/backend/js/ast/JsBinaryOperation.java index b09d50c1d05..54dd2774d50 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java +++ b/js/src/compiler/backend/js/ast/JsBinaryOperation.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript binary operation. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperator.java b/js/src/compiler/backend/js/ast/JsBinaryOperator.java similarity index 98% rename from src/com/google/dart/compiler/backend/js/ast/JsBinaryOperator.java rename to js/src/compiler/backend/js/ast/JsBinaryOperator.java index b54647f3a46..dd5e9bb469f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperator.java +++ b/js/src/compiler/backend/js/ast/JsBinaryOperator.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents the operator in a JavaScript binary operation. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBlock.java b/js/src/compiler/backend/js/ast/JsBlock.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsBlock.java rename to js/src/compiler/backend/js/ast/JsBlock.java index 3d927a2bf7d..65c9c353e46 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBlock.java +++ b/js/src/compiler/backend/js/ast/JsBlock.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBooleanLiteral.java b/js/src/compiler/backend/js/ast/JsBooleanLiteral.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsBooleanLiteral.java rename to js/src/compiler/backend/js/ast/JsBooleanLiteral.java index 12238ddbb02..69f2487e0f2 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBooleanLiteral.java +++ b/js/src/compiler/backend/js/ast/JsBooleanLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript literal boolean expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBreak.java b/js/src/compiler/backend/js/ast/JsBreak.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsBreak.java rename to js/src/compiler/backend/js/ast/JsBreak.java index 363f294df78..da4ecc2044a 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBreak.java +++ b/js/src/compiler/backend/js/ast/JsBreak.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents the JavaScript break statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsCase.java b/js/src/compiler/backend/js/ast/JsCase.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsCase.java rename to js/src/compiler/backend/js/ast/JsCase.java index 43d2fc41230..67968695cbd 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsCase.java +++ b/js/src/compiler/backend/js/ast/JsCase.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents the JavaScript case statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsCatch.java b/js/src/compiler/backend/js/ast/JsCatch.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsCatch.java rename to js/src/compiler/backend/js/ast/JsCatch.java index f992545b944..c4693e60f32 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsCatch.java +++ b/js/src/compiler/backend/js/ast/JsCatch.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript catch clause. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java b/js/src/compiler/backend/js/ast/JsCatchScope.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java rename to js/src/compiler/backend/js/ast/JsCatchScope.java index 5e5a2f2f577..11b9da8ff56 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java +++ b/js/src/compiler/backend/js/ast/JsCatchScope.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsConditional.java b/js/src/compiler/backend/js/ast/JsConditional.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsConditional.java rename to js/src/compiler/backend/js/ast/JsConditional.java index b1171bac2c0..b62d3174277 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsConditional.java +++ b/js/src/compiler/backend/js/ast/JsConditional.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript conditional expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsContext.java b/js/src/compiler/backend/js/ast/JsContext.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsContext.java rename to js/src/compiler/backend/js/ast/JsContext.java index ddb170052d3..1f26369ed16 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsContext.java +++ b/js/src/compiler/backend/js/ast/JsContext.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * The context in which a JsNode visitation occurs. This represents the set of diff --git a/src/com/google/dart/compiler/backend/js/ast/JsContinue.java b/js/src/compiler/backend/js/ast/JsContinue.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsContinue.java rename to js/src/compiler/backend/js/ast/JsContinue.java index d761815fe76..8bbfc47f93e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsContinue.java +++ b/js/src/compiler/backend/js/ast/JsContinue.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents the JavaScript continue statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java b/js/src/compiler/backend/js/ast/JsDebugger.java similarity index 91% rename from src/com/google/dart/compiler/backend/js/ast/JsDebugger.java rename to js/src/compiler/backend/js/ast/JsDebugger.java index 34cfae43f48..7f6a92ab6cc 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java +++ b/js/src/compiler/backend/js/ast/JsDebugger.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript debugger statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDefault.java b/js/src/compiler/backend/js/ast/JsDefault.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsDefault.java rename to js/src/compiler/backend/js/ast/JsDefault.java index a76987a8e5d..16468f4362b 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDefault.java +++ b/js/src/compiler/backend/js/ast/JsDefault.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents the default option in a JavaScript swtich statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java b/js/src/compiler/backend/js/ast/JsDoWhile.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java rename to js/src/compiler/backend/js/ast/JsDoWhile.java index 1dd4a47e8d4..f26ce674d4d 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java +++ b/js/src/compiler/backend/js/ast/JsDoWhile.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript do..while statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java b/js/src/compiler/backend/js/ast/JsEmpty.java similarity index 91% rename from src/com/google/dart/compiler/backend/js/ast/JsEmpty.java rename to js/src/compiler/backend/js/ast/JsEmpty.java index c2ac99e3ac0..d76110ddaa6 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java +++ b/js/src/compiler/backend/js/ast/JsEmpty.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents an empty statement in JavaScript. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExprStmt.java b/js/src/compiler/backend/js/ast/JsExprStmt.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsExprStmt.java rename to js/src/compiler/backend/js/ast/JsExprStmt.java index 5b9fc1218c3..008a2858843 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExprStmt.java +++ b/js/src/compiler/backend/js/ast/JsExprStmt.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript expression statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExpression.java b/js/src/compiler/backend/js/ast/JsExpression.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsExpression.java rename to js/src/compiler/backend/js/ast/JsExpression.java index 43545ec98dc..d6eb37da784 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExpression.java +++ b/js/src/compiler/backend/js/ast/JsExpression.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; +import compiler.common.SourceInfo; /** * An abstract base class for all JavaScript expressions. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsFor.java b/js/src/compiler/backend/js/ast/JsFor.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsFor.java rename to js/src/compiler/backend/js/ast/JsFor.java index b980d4be1a2..683941f9f40 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFor.java +++ b/js/src/compiler/backend/js/ast/JsFor.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; +import compiler.common.SourceInfo; /** * A for statement. If specified at all, the initializer part is diff --git a/src/com/google/dart/compiler/backend/js/ast/JsForIn.java b/js/src/compiler/backend/js/ast/JsForIn.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsForIn.java rename to js/src/compiler/backend/js/ast/JsForIn.java index 646e349885c..3636732cd0f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsForIn.java +++ b/js/src/compiler/backend/js/ast/JsForIn.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript for..in statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsFunction.java b/js/src/compiler/backend/js/ast/JsFunction.java similarity index 98% rename from src/com/google/dart/compiler/backend/js/ast/JsFunction.java rename to js/src/compiler/backend/js/ast/JsFunction.java index 4563ca58bec..b2ce5c72e2c 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFunction.java +++ b/js/src/compiler/backend/js/ast/JsFunction.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; +import compiler.common.SourceInfo; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java b/js/src/compiler/backend/js/ast/JsGlobalBlock.java similarity index 89% rename from src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java rename to js/src/compiler/backend/js/ast/JsGlobalBlock.java index 9a14004e14c..39d08fe3991 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java +++ b/js/src/compiler/backend/js/ast/JsGlobalBlock.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represnts a JavaScript block in the global scope. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsIf.java b/js/src/compiler/backend/js/ast/JsIf.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsIf.java rename to js/src/compiler/backend/js/ast/JsIf.java index 478538235ab..f5b4bffd995 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsIf.java +++ b/js/src/compiler/backend/js/ast/JsIf.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript if statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java b/js/src/compiler/backend/js/ast/JsInvocation.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsInvocation.java rename to js/src/compiler/backend/js/ast/JsInvocation.java index 6704234df29..c2ab1f98d4a 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java +++ b/js/src/compiler/backend/js/ast/JsInvocation.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsLabel.java b/js/src/compiler/backend/js/ast/JsLabel.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsLabel.java rename to js/src/compiler/backend/js/ast/JsLabel.java index 7d026c3a6de..5c2e695d33a 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsLabel.java +++ b/js/src/compiler/backend/js/ast/JsLabel.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript label statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java b/js/src/compiler/backend/js/ast/JsLiteral.java similarity index 88% rename from src/com/google/dart/compiler/backend/js/ast/JsLiteral.java rename to js/src/compiler/backend/js/ast/JsLiteral.java index c87ae0c8af1..7157f2f19a8 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java +++ b/js/src/compiler/backend/js/ast/JsLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript string literal expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsModVisitor.java b/js/src/compiler/backend/js/ast/JsModVisitor.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsModVisitor.java rename to js/src/compiler/backend/js/ast/JsModVisitor.java index ef6e75ce994..bc021da81c4 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsModVisitor.java +++ b/js/src/compiler/backend/js/ast/JsModVisitor.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.util.Hack; +import compiler.util.Hack; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsName.java b/js/src/compiler/backend/js/ast/JsName.java similarity index 93% rename from src/com/google/dart/compiler/backend/js/ast/JsName.java rename to js/src/compiler/backend/js/ast/JsName.java index 2997bcfb546..e5c57f6f7b4 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsName.java +++ b/js/src/compiler/backend/js/ast/JsName.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.io.Serializable; @@ -24,7 +24,7 @@ public class JsName implements Serializable { /** * @param ident the unmangled ident to use for this name */ - public JsName(JsScope enclosing, String ident, String shortIdent, String originalName) { +JsName(JsScope enclosing, String ident, String shortIdent, String originalName) { this.enclosing = enclosing; this.ident = ident; this.shortIdent = shortIdent; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java b/js/src/compiler/backend/js/ast/JsNameRef.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsNameRef.java rename to js/src/compiler/backend/js/ast/JsNameRef.java index dc26c8fa61a..0104808b8a2 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java +++ b/js/src/compiler/backend/js/ast/JsNameRef.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript expression that references a name. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNew.java b/js/src/compiler/backend/js/ast/JsNew.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsNew.java rename to js/src/compiler/backend/js/ast/JsNew.java index 19b6f5d6c90..b6284fb34e7 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNew.java +++ b/js/src/compiler/backend/js/ast/JsNew.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNode.java b/js/src/compiler/backend/js/ast/JsNode.java similarity index 77% rename from src/com/google/dart/compiler/backend/js/ast/JsNode.java rename to js/src/compiler/backend/js/ast/JsNode.java index 0d4b7aaa714..02471539809 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNode.java +++ b/js/src/compiler/backend/js/ast/JsNode.java @@ -1,13 +1,13 @@ // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.backend.js.JsSourceGenerationVisitor; -import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor; -import com.google.dart.compiler.common.AbstractNode; -import com.google.dart.compiler.common.SourceInfo; -import com.google.dart.compiler.util.DefaultTextOutput; +import compiler.backend.js.JsSourceGenerationVisitor; +import compiler.backend.js.JsToStringGenerationVisitor; +import compiler.common.AbstractNode; +import compiler.common.SourceInfo; +import compiler.util.DefaultTextOutput; /** * Base class for all JS AST elements. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java b/js/src/compiler/backend/js/ast/JsNullLiteral.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java rename to js/src/compiler/backend/js/ast/JsNullLiteral.java index 506b2e3f330..e29251c471c 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java +++ b/js/src/compiler/backend/js/ast/JsNullLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript null literal. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java b/js/src/compiler/backend/js/ast/JsNumberLiteral.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java rename to js/src/compiler/backend/js/ast/JsNumberLiteral.java index 726c6b0ed27..1fb5c558ae9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java +++ b/js/src/compiler/backend/js/ast/JsNumberLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Represents a JavaScript literal decimal expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java b/js/src/compiler/backend/js/ast/JsObjectLiteral.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java rename to js/src/compiler/backend/js/ast/JsObjectLiteral.java index 749ed473c21..7743d2cdb64 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java +++ b/js/src/compiler/backend/js/ast/JsObjectLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsOperator.java b/js/src/compiler/backend/js/ast/JsOperator.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsOperator.java rename to js/src/compiler/backend/js/ast/JsOperator.java index e4440cbe9ab..8db5e1526e9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsOperator.java +++ b/js/src/compiler/backend/js/ast/JsOperator.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript operator. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsParameter.java b/js/src/compiler/backend/js/ast/JsParameter.java similarity index 93% rename from src/com/google/dart/compiler/backend/js/ast/JsParameter.java rename to js/src/compiler/backend/js/ast/JsParameter.java index 17581ce4084..c0e3b5793d1 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsParameter.java +++ b/js/src/compiler/backend/js/ast/JsParameter.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript parameter. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java b/js/src/compiler/backend/js/ast/JsPostfixOperation.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java rename to js/src/compiler/backend/js/ast/JsPostfixOperation.java index a33536f6c0d..d5548fa94b9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java +++ b/js/src/compiler/backend/js/ast/JsPostfixOperation.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript postfix operation. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java b/js/src/compiler/backend/js/ast/JsPrefixOperation.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java rename to js/src/compiler/backend/js/ast/JsPrefixOperation.java index 8ce12c7bacd..25f6a86c2d5 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java +++ b/js/src/compiler/backend/js/ast/JsPrefixOperation.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript prefix operation. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsProgram.java b/js/src/compiler/backend/js/ast/JsProgram.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsProgram.java rename to js/src/compiler/backend/js/ast/JsProgram.java index 1d2c902d27a..c37ed039990 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsProgram.java +++ b/js/src/compiler/backend/js/ast/JsProgram.java @@ -2,7 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; + +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -156,7 +158,7 @@ public final class JsProgram extends JsNode { } @Override - public void traverse(JsVisitor v, JsContext ctx) { + public void traverse(JsVisitor v, @Nullable JsContext ctx) { if (v.visit(this, ctx)) { for (JsProgramFragment fragment : fragments) { v.accept(fragment); diff --git a/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java b/js/src/compiler/backend/js/ast/JsProgramFragment.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java rename to js/src/compiler/backend/js/ast/JsProgramFragment.java index 3c6859e2150..183f1f29d61 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java +++ b/js/src/compiler/backend/js/ast/JsProgramFragment.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * One independently loadable fragment of a {@link JsProgram}. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java b/js/src/compiler/backend/js/ast/JsPropertyInitializer.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java rename to js/src/compiler/backend/js/ast/JsPropertyInitializer.java index d68d8d01af4..1431238c4c2 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java +++ b/js/src/compiler/backend/js/ast/JsPropertyInitializer.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Used in object literals to specify property values by name. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsRegExp.java b/js/src/compiler/backend/js/ast/JsRegExp.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsRegExp.java rename to js/src/compiler/backend/js/ast/JsRegExp.java index 158c7a5e092..5da7cab3b18 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsRegExp.java +++ b/js/src/compiler/backend/js/ast/JsRegExp.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript regular expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsReturn.java b/js/src/compiler/backend/js/ast/JsReturn.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsReturn.java rename to js/src/compiler/backend/js/ast/JsReturn.java index 16d90e4b353..b3ec46705d9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsReturn.java +++ b/js/src/compiler/backend/js/ast/JsReturn.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript return statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsRootScope.java b/js/src/compiler/backend/js/ast/JsRootScope.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsRootScope.java rename to js/src/compiler/backend/js/ast/JsRootScope.java index 33b71f26222..b53709a4257 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsRootScope.java +++ b/js/src/compiler/backend/js/ast/JsRootScope.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.backend.js.JsReservedIdentifiers; +import compiler.backend.js.JsReservedIdentifiers; /** * The root scope is the parent of every scope. All identifiers in this scope diff --git a/src/com/google/dart/compiler/backend/js/ast/JsScope.java b/js/src/compiler/backend/js/ast/JsScope.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsScope.java rename to js/src/compiler/backend/js/ast/JsScope.java index e5f0578fb49..04fcbac0117 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsScope.java +++ b/js/src/compiler/backend/js/ast/JsScope.java @@ -2,10 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.util.Lists; -import com.google.dart.compiler.util.Maps; +import compiler.util.Lists; +import compiler.util.Maps; import java.io.Serializable; import java.util.Collections; @@ -15,17 +15,17 @@ import java.util.Map; /** * A scope is a factory for creating and allocating - * {@link com.google.dart.compiler.backend.js.ast.JsName}s. A JavaScript AST is + * {@link JsName}s. A JavaScript AST is * built in terms of abstract name objects without worrying about obfuscation, * keyword/identifier blacklisting, and so on. *

*

*

* Scopes are associated with - * {@link com.google.dart.compiler.backend.js.ast.JsFunction}s, but the two are + * {@link JsFunction}s, but the two are * not equivalent. Functions have scopes, but a scope does not * necessarily have an associated Function. Examples of this include the - * {@link com.google.dart.compiler.backend.js.ast.JsRootScope} and synthetic + * {@link JsRootScope} and synthetic * scopes that might be created by a client. *

*

@@ -34,7 +34,7 @@ import java.util.Map; * identifiers for names. Specifically, names in child scopes are chosen such * that they do not conflict with names in their parent scopes. The ultimate * parent is usually the global scope (see - * {@link com.google.dart.compiler.backend.js.ast.JsProgram#getRootScope()}), + * {@link JsProgram#getRootScope()}), * but parentless scopes are useful for managing names that are always accessed * with a qualifier and could therefore never be confused with the global scope * hierarchy. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsStatement.java b/js/src/compiler/backend/js/ast/JsStatement.java similarity index 91% rename from src/com/google/dart/compiler/backend/js/ast/JsStatement.java rename to js/src/compiler/backend/js/ast/JsStatement.java index 82d37ca1185..9b2c6bba5eb 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsStatement.java +++ b/js/src/compiler/backend/js/ast/JsStatement.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Abstract base class for JavaScript statement objects. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java b/js/src/compiler/backend/js/ast/JsStringLiteral.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java rename to js/src/compiler/backend/js/ast/JsStringLiteral.java index 77e60c9b89a..9f0dbbc259f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java +++ b/js/src/compiler/backend/js/ast/JsStringLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript string literal expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java b/js/src/compiler/backend/js/ast/JsSwitch.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsSwitch.java rename to js/src/compiler/backend/js/ast/JsSwitch.java index 5a49624af42..dc256c394fc 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java +++ b/js/src/compiler/backend/js/ast/JsSwitch.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java b/js/src/compiler/backend/js/ast/JsSwitchMember.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java rename to js/src/compiler/backend/js/ast/JsSwitchMember.java index 0a748f60078..e2025e83a7e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java +++ b/js/src/compiler/backend/js/ast/JsSwitchMember.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsThisRef.java b/js/src/compiler/backend/js/ast/JsThisRef.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsThisRef.java rename to js/src/compiler/backend/js/ast/JsThisRef.java index 9adb6459488..3c38a5287c3 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsThisRef.java +++ b/js/src/compiler/backend/js/ast/JsThisRef.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript this reference. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsThrow.java b/js/src/compiler/backend/js/ast/JsThrow.java similarity index 94% rename from src/com/google/dart/compiler/backend/js/ast/JsThrow.java rename to js/src/compiler/backend/js/ast/JsThrow.java index 4616418fb6b..de5125c4847 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsThrow.java +++ b/js/src/compiler/backend/js/ast/JsThrow.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript throw statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsTry.java b/js/src/compiler/backend/js/ast/JsTry.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsTry.java rename to js/src/compiler/backend/js/ast/JsTry.java index 61357bcd406..ad7348e018b 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsTry.java +++ b/js/src/compiler/backend/js/ast/JsTry.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; import java.util.ArrayList; import java.util.List; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java b/js/src/compiler/backend/js/ast/JsUnaryOperation.java similarity index 96% rename from src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java rename to js/src/compiler/backend/js/ast/JsUnaryOperation.java index 00f103f35c9..ce296e8f601 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java +++ b/js/src/compiler/backend/js/ast/JsUnaryOperation.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript prefix or postfix operation. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperator.java b/js/src/compiler/backend/js/ast/JsUnaryOperator.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsUnaryOperator.java rename to js/src/compiler/backend/js/ast/JsUnaryOperator.java index 2b854d8313e..83e5ccc9285 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperator.java +++ b/js/src/compiler/backend/js/ast/JsUnaryOperator.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript unary operator. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsValueLiteral.java b/js/src/compiler/backend/js/ast/JsValueLiteral.java similarity index 91% rename from src/com/google/dart/compiler/backend/js/ast/JsValueLiteral.java rename to js/src/compiler/backend/js/ast/JsValueLiteral.java index f23ab5dbce4..06e80bed6a4 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsValueLiteral.java +++ b/js/src/compiler/backend/js/ast/JsValueLiteral.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript string literal expression. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsVars.java b/js/src/compiler/backend/js/ast/JsVars.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsVars.java rename to js/src/compiler/backend/js/ast/JsVars.java index aaf629259aa..2fbf0cbff75 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsVars.java +++ b/js/src/compiler/backend/js/ast/JsVars.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; +import compiler.common.SourceInfo; import java.util.ArrayList; import java.util.Iterator; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsVisitable.java b/js/src/compiler/backend/js/ast/JsVisitable.java similarity index 92% rename from src/com/google/dart/compiler/backend/js/ast/JsVisitable.java rename to js/src/compiler/backend/js/ast/JsVisitable.java index 626648af8ae..5d436e053dc 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsVisitable.java +++ b/js/src/compiler/backend/js/ast/JsVisitable.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * Abstracts the idea that a class can be traversed. diff --git a/src/com/google/dart/compiler/backend/js/ast/JsVisitor.java b/js/src/compiler/backend/js/ast/JsVisitor.java similarity index 97% rename from src/com/google/dart/compiler/backend/js/ast/JsVisitor.java rename to js/src/compiler/backend/js/ast/JsVisitor.java index a3417a02817..da05408b6e3 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsVisitor.java +++ b/js/src/compiler/backend/js/ast/JsVisitor.java @@ -2,9 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; - -import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; +package compiler.backend.js.ast; import java.util.List; @@ -227,7 +225,7 @@ public class JsVisitor { public void endVisit(JsTry x, JsContext ctx) { } - public void endVisit(JsVar x, JsContext ctx) { + public void endVisit(JsVars.JsVar x, JsContext ctx) { } public void endVisit(JsVars x, JsContext ctx) { @@ -392,7 +390,7 @@ public class JsVisitor { return true; } - public boolean visit(JsVar x, JsContext ctx) { + public boolean visit(JsVars.JsVar x, JsContext ctx) { return true; } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsWhile.java b/js/src/compiler/backend/js/ast/JsWhile.java similarity index 95% rename from src/com/google/dart/compiler/backend/js/ast/JsWhile.java rename to js/src/compiler/backend/js/ast/JsWhile.java index c40203bc1f1..0a4e8d64c21 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsWhile.java +++ b/js/src/compiler/backend/js/ast/JsWhile.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; /** * A JavaScript while statement. diff --git a/src/com/google/dart/compiler/backend/js/ast/NodeKind.java b/js/src/compiler/backend/js/ast/NodeKind.java similarity index 93% rename from src/com/google/dart/compiler/backend/js/ast/NodeKind.java rename to js/src/compiler/backend/js/ast/NodeKind.java index 614e4bb3bd9..60b38e43d34 100644 --- a/src/com/google/dart/compiler/backend/js/ast/NodeKind.java +++ b/js/src/compiler/backend/js/ast/NodeKind.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.backend.js.ast; +package compiler.backend.js.ast; public enum NodeKind { ARRAY_ACCESS, diff --git a/src/com/google/dart/compiler/common/AbstractNode.java b/js/src/compiler/common/AbstractNode.java similarity index 96% rename from src/com/google/dart/compiler/common/AbstractNode.java rename to js/src/compiler/common/AbstractNode.java index 5b70197dd13..de8522e3084 100644 --- a/src/com/google/dart/compiler/common/AbstractNode.java +++ b/js/src/compiler/common/AbstractNode.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.common; +package compiler.common; -import com.google.dart.compiler.Source; +import compiler.Source; /** * Abstract base class for nodes that carry source information. diff --git a/src/com/google/dart/compiler/common/HasSourceInfo.java b/js/src/compiler/common/HasSourceInfo.java similarity index 96% rename from src/com/google/dart/compiler/common/HasSourceInfo.java rename to js/src/compiler/common/HasSourceInfo.java index bda3da94996..ba81f974ca4 100644 --- a/src/com/google/dart/compiler/common/HasSourceInfo.java +++ b/js/src/compiler/common/HasSourceInfo.java @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.common; +package compiler.common; -import com.google.dart.compiler.Source; +import compiler.Source; /** * Abstract view of a class that has source info. diff --git a/src/com/google/dart/compiler/common/Name.java b/js/src/compiler/common/Name.java similarity index 98% rename from src/com/google/dart/compiler/common/Name.java rename to js/src/compiler/common/Name.java index 4697b491d96..7bff8269725 100644 --- a/src/com/google/dart/compiler/common/Name.java +++ b/js/src/compiler/common/Name.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.common; +package compiler.common; import java.io.*; import java.nio.charset.Charset; diff --git a/src/com/google/dart/compiler/common/NameFactory.java b/js/src/compiler/common/NameFactory.java similarity index 99% rename from src/com/google/dart/compiler/common/NameFactory.java rename to js/src/compiler/common/NameFactory.java index d305f290bf9..8139b2e984c 100644 --- a/src/com/google/dart/compiler/common/NameFactory.java +++ b/js/src/compiler/common/NameFactory.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.common; +package compiler.common; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.MapMaker; diff --git a/src/com/google/dart/compiler/common/SourceInfo.java b/js/src/compiler/common/SourceInfo.java similarity index 95% rename from src/com/google/dart/compiler/common/SourceInfo.java rename to js/src/compiler/common/SourceInfo.java index bb212e9c1bd..becdfa5b025 100644 --- a/src/com/google/dart/compiler/common/SourceInfo.java +++ b/js/src/compiler/common/SourceInfo.java @@ -2,8 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.common; -import com.google.dart.compiler.Source; +package compiler.common; +import compiler.Source; import java.io.Serializable; diff --git a/src/com/google/dart/compiler/util/AbstractTextOutput.java b/js/src/compiler/util/AbstractTextOutput.java similarity index 98% rename from src/com/google/dart/compiler/util/AbstractTextOutput.java rename to js/src/compiler/util/AbstractTextOutput.java index 9c8d2b1cd16..ab8fdc8634f 100644 --- a/src/com/google/dart/compiler/util/AbstractTextOutput.java +++ b/js/src/compiler/util/AbstractTextOutput.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; import java.io.PrintWriter; import java.util.Arrays; diff --git a/src/com/google/dart/compiler/util/AstUtil.java b/js/src/compiler/util/AstUtil.java similarity index 94% rename from src/com/google/dart/compiler/util/AstUtil.java rename to js/src/compiler/util/AstUtil.java index 826426b5557..f5aa7e7bc21 100644 --- a/src/com/google/dart/compiler/util/AstUtil.java +++ b/js/src/compiler/util/AstUtil.java @@ -2,12 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; -import com.google.dart.compiler.InternalCompilerException; -import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; -import com.google.dart.compiler.common.SourceInfo; +import compiler.InternalCompilerException; +import compiler.common.SourceInfo; +import compiler.backend.js.ast.*; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -125,7 +125,7 @@ public class AstUtil { } public static JsVars newVar(SourceInfo info, JsName name, JsExpression expr) { - JsVar var = new JsVar(name).setSourceRef(info); + JsVars.JsVar var = new JsVars.JsVar(name).setSourceRef(info); var.setInitExpr(expr); JsVars vars = new JsVars(); vars.add(var); @@ -133,7 +133,7 @@ public class AstUtil { } public static JsVars newVar(JsName name, JsExpression expr) { - JsVar var = new JsVar(name); + JsVars.JsVar var = new JsVars.JsVar(name); if (expr != null) { var.setInitExpr(expr); } @@ -170,7 +170,7 @@ public class AstUtil { } public static JsFunction newFunction( - JsScope scope, JsName name, List params, JsBlock body) { + JsScope scope, @Nullable JsName name, List params, JsBlock body) { JsFunction fn = new JsFunction(scope); if (name != null) { fn.setName(name); @@ -223,7 +223,7 @@ public class AstUtil { } public static JsNameRef nameref(SourceInfo src, JsName qualifier, String prop) { - return AstUtil.nameref(src, qualifier.makeRef().setSourceRef(src), prop); + return nameref(src, qualifier.makeRef().setSourceRef(src), prop); } public static JsNameRef nameref(SourceInfo src, JsExpression qualifier, String prop) { diff --git a/src/com/google/dart/compiler/util/DefaultTextOutput.java b/js/src/compiler/util/DefaultTextOutput.java similarity index 95% rename from src/com/google/dart/compiler/util/DefaultTextOutput.java rename to js/src/compiler/util/DefaultTextOutput.java index 2a064ff87fd..fe66e8d2ab4 100644 --- a/src/com/google/dart/compiler/util/DefaultTextOutput.java +++ b/js/src/compiler/util/DefaultTextOutput.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/src/com/google/dart/compiler/util/Hack.java b/js/src/compiler/util/Hack.java similarity index 91% rename from src/com/google/dart/compiler/util/Hack.java rename to js/src/compiler/util/Hack.java index 642f416394f..02526b87db7 100644 --- a/src/com/google/dart/compiler/util/Hack.java +++ b/js/src/compiler/util/Hack.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; /** * Utility to hack around untypable (or yet to be) code. diff --git a/src/com/google/dart/compiler/util/Lists.java b/js/src/compiler/util/Lists.java similarity index 99% rename from src/com/google/dart/compiler/util/Lists.java rename to js/src/compiler/util/Lists.java index b0ca023d280..5eca177a5e5 100644 --- a/src/com/google/dart/compiler/util/Lists.java +++ b/js/src/compiler/util/Lists.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; import java.util.*; diff --git a/src/com/google/dart/compiler/util/Maps.java b/js/src/compiler/util/Maps.java similarity index 99% rename from src/com/google/dart/compiler/util/Maps.java rename to js/src/compiler/util/Maps.java index 15274b04902..f70c9b4c144 100644 --- a/src/com/google/dart/compiler/util/Maps.java +++ b/js/src/compiler/util/Maps.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; import java.util.Collections; import java.util.HashMap; diff --git a/src/com/google/dart/compiler/util/Paths.java b/js/src/compiler/util/Paths.java similarity index 98% rename from src/com/google/dart/compiler/util/Paths.java rename to js/src/compiler/util/Paths.java index cdda910ccb1..35f63b6667d 100644 --- a/src/com/google/dart/compiler/util/Paths.java +++ b/js/src/compiler/util/Paths.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; import java.io.File; import java.net.URI; diff --git a/src/com/google/dart/compiler/util/TextOutput.java b/js/src/compiler/util/TextOutput.java similarity index 93% rename from src/com/google/dart/compiler/util/TextOutput.java rename to js/src/compiler/util/TextOutput.java index 99a465b1532..d5c7f08a8c7 100644 --- a/src/com/google/dart/compiler/util/TextOutput.java +++ b/js/src/compiler/util/TextOutput.java @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -package com.google.dart.compiler.util; +package compiler.util; /** * Interface used for printing text output. diff --git a/out/production/k2js/org/jetbrains/k2js/translate/ContextType$1.class b/out/production/k2js/org/jetbrains/k2js/translate/ContextType$1.class deleted file mode 100644 index f5d897422604f0b11f3b80a1e5f768da1279c82f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1023 zcmbVLU279T6g`t{vfDM-8r%5QYO4X$T3n4j2$52Z6$-IFBo=&}Y=(5=W@ee4Nc~wp z6%_Q{A0^(|MB0ZCY8Q6y2j`x>d+wdzf4=_&@B;M^W!&*`H^99R1+4qn@Nu7^{8}n$ z_ZVu8&WL~EQNqRKb!uywe7%;2^4Krk$Kq!LGyabK7o?V{W92XGzbV z$czCDl|!Y3X(v3(1Z8$R+6<$Suzka&%A(KBQ5IRlRhDooqPA96oZ8;kRMelh7&eB& zz7=u84YyLO-VCTs*Am>vCPOKA8PdjL>bW$n?JE@3^Dk0&;lIYUVR(53Cdbj$6BCPf z(rLMJ;s2kyIgsE7Do%7pb9gW8i5^toV~gSO`IJ7YY?7whSTXpJim6Zsr?E(#V#Il* z?WP>3A`xRj>gEg&8Fnr|2!_UG!9E@_yjqB!JBX>K3~%P`-(qDiXhu8Zc6DtIiOVc};jIk_~pAtg|z)Z#g2QvrGtwyhdjw_XD!a6wxqnb5_4c z)s8Xzfx@S1@eJNCiV8SqSjrh{Q`C%s@L0tfaTHO@@wafBte5wAoxCdHOJuPh;07L` G>aoA68y-ji diff --git a/out/production/k2js/org/jetbrains/k2js/translate/ContextType$2.class b/out/production/k2js/org/jetbrains/k2js/translate/ContextType$2.class deleted file mode 100644 index 26d4a350b881c6903f5f11c7233c4b60be7fa944..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1237 zcmbVL+iuf95IvJPaR^aLTL{n#mo`8y2-AQBQV^;ds8lJGheSnv+_rmPH-X#OI=UN!||tq)O|7V*|O3NT;U%H?M3IQ z(K4rANC2U9pp?`dUxcA#%j0gKht5cvffk+$osX?i=ol?j=nEsAPN0nZV)|dtWVO{M zY!0P)BVAu;VZ1=~r@%n>48v_~5puCgIIE>o&!uVC7jUY^H*$2vi@*a-c)kEr#L)}J z+LilWRLg6L{GUX9;DWzZt{;Tlhj-GP1}7!hsM>fyI83eN+;pq^W93GLyl7VfMOaVy zYvW-Fk5G%QuM--ncPFx_wg|P$f(b8Ep^0c`lQ8LqjRs+F-teZkB^l~YI~w%X|A)Yh zn=Q@z!AQD>P~g#x$DXiSt0%T9Hge}*EHyy83B}VHU36=flo^;IZv!k{rA{EVl4kc=D2zM1KAJfu)eV+gBeRX xW~oe&Qx^8Yb=+W{EGjYnCT_8`;yBB!ZLywXiQNL0v4$0km|+bYeA=Ga{{g=bV!QwV diff --git a/out/production/k2js/org/jetbrains/k2js/translate/ContextType$3.class b/out/production/k2js/org/jetbrains/k2js/translate/ContextType$3.class deleted file mode 100644 index 14b7059c19e77add25cacfd33b73813986bef375..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1239 zcmbVLYikoh6g`t{vN48M8;x31A9d9{#I=c_5RuZTP>8LNQ0d3Xc1SmFXTt1M?7z}4 z78Lve{wVS8CX)RSmYRj#d*|+%Gv_|$_n#lX0JPC8B9B`(ZWpnEJ4Ix0*Ty{?_Zjl9 zeCeCl43%1M%s+EC;Bw^ljrQfJvs*u4u)69;{g43+rClk7?gl&z1x23plpeWbVTPLfGIT$+#-VF8mtnw-aJxzx@x=_zCc_TGE8de)C*}k^(8hr@rk6a_)oaf49}Nfia7e} zRD0r`AJy_oBLAmRAE@AOr5C7>`tV+uV|7%54adeqhW*q^E=DY9h2b zOTZYaX}@heD&a9|k$^fwBlYw|9!{H~c2O|H%T#DW?tB)e{jkws*jY5b>5WNB-ReZ6 z-uizD)Vle#*&mLDXBY}Jyz$^Olxy|Gy^4d>`xncNEJ?h0^|!X4AxHN#VW`4 zHG9ueb+a1#7~ikPY)dt(hH7iEbj7r_V|(kO%X$vT%EAKRhp1f{qo3(>I&Dv7;3|bK##=?7s zm2iGvJyK(aYL;V)ZRut?5ot$UFkdOD#*S*~oZ96VO!a`m1pnn`@F#Usw^ta3nuN|p zb{GWvgHG9YD0Qug#QLp`0Y8QnO0hy3U)Zw?XTD-b6A&xFchf-^MW+IlN>DU-tsZ zn8YiGfv(+kL7@d1gBWTD5tlLC9%50(2uE~ZUKCzB5qXB?mP%VR2z6@7sF+m7fpDbZ zPzrndTFItTFE#d#)5nPhw~L#4RTJUj?JLSm(VKLD-mJpvC@&{KmWt$9N*(AO+@#U(>~a4|+;aVw;Bi(v`{9dzgZ~$N9N@VE zn4%TA?nVJ_JNwjE0k@zh1q6DMW-X%P>IEPy41U2@IA0jYBYiop)=8KhHmo#tT~wkm^ighp j3R=(bAs&&R2g{fxJ58QZJjV>>9iTb?B+9O(67cz7PWjJ% diff --git a/out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$FunctionVariableDeclaration.class b/out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$FunctionVariableDeclaration.class deleted file mode 100644 index a981cf1ce3228929df18f1592cfa5bdbda4da692..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2386 zcmbVOU2hvj6g}g*+17F5#Iz8aLQR_%$4;|pl74^-G~}Zsq*g^rr9Pp_dgQLNp0#$z zCHw&X0S|~@0TQGYNbrcnk1Cv9+cT~8gdvLFQRoFL|o zA)bX(0v8U2>x0fW~}JfPT~V){;%EZ)LY1{U5Hxb|vZhkcrb zX#uOQOjS0Oz&WBu`s*CSjtN{{XV`b}ZUz@|Nx*(J?0<5y@Sea#Ev_!L?K{%z0Id~Y z$4PR^Q4|upf|(31@9#yTQy3@I12cDg);|?8p+SVST?9kQS3fw(p}D zWoK64>QFtkjqBMfq4|=tg)&P`tFPIA1imjOP+@#N3G5H?Op*o?3;AK!F`vO4Y=KLC z^=x{cs!K1fhxL6&wIbbHxFPWEy{`BRO=X_?wZgHYIx<Z@Z3(aYp6&B#v5S|zoYqu1o?>b$I5Ah zn{2fG>0?>Amk2Eqk%dp${#X4Pn@~RP6TLh4 zQFQSN%K(@N;=`Y&axJ|XGpSht+rp_#rQhT=al{usGwsfU$IeN8v=(ycESyEnE=G9ZzDJ$21c}UEF5Ews& z(G{N#4KxW{K4h-$b!by=OM#K-rVS(ouABr~AQ8G3Nct}&; zaJTm~2Kv_0NTK;GVmOyZ8Z9Zr(IyZNUz^m~Wf?UrYu*7HBJk38u16UfTPPW_sWC z6XlfyD+G2O-6?#69)YXXJA@g#RFSsz+){;Q^<241=Xo{N8zG3H`KWm4jF3J>Zvd%J zASLs8MOXr~{r0{1EkNgO`dBjYEi|#N?r+rTcP`wL45X-u4zoQW(Z4b1v`b zZ5H)a=OAANijnT&6jY>lKX61KW4IFlxhrt3o^Ertt%}kPXPYWkFBlehL#{ zQ%I6t6`Q=cbGjG{H18LTFl+*inR9Fw2&Bu^UcFysh9dw7Q(oZWrdKQb!O5WlG8)lX zKyuc;O>d69vQA-vp<^@con{h1Ffb=@E1C{{8+gM0{{Cupga#Jaf8Jm7fY=5W*~F)r z7)-FR*sn>~k{h;K4F-YMtff`1Qrb{%^`wQ$`K<+6uI{^*E84e8YEExko<*gpddp-* zU2!UIUOi&xWvu74R_?SdJx_T|?HE5I0MXVKd|Pl817*;{af!Pz?qi&r`v-nSYyZG2 zwEr9mEptp$h<~92A8=mbFBzUZ;dmYws2G^|hYpgQv;DuIbr+Whc9Ge|jfLv=<}Uhk z!Fpg1Llg1N_@6j8*cso$?TN&XNDfXUIum;sU;hg&uQ9RSaqktr_~R$qYeInGG0X4> z*AFm-MBt^0CRjbhG?BF8K4vgWG+n&zBYa8e9`>8Z)QDr8NcVLE{8woW$WdpJ(o2+E zK|fac3|~=loh#rHn%-c{z`TL1f!x1{aa=a=6wml?@B$xlj$thv6VwDT1U4BF|_ Iz}dL?4^ZBdivR!s diff --git a/out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$State.class b/out/production/k2js/org/jetbrains/k2js/translate/DeclarationTranslator$State.class deleted file mode 100644 index 836a1ca7a3885b221a26d6e4613349d3e33e8208..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 724 zcmbVKO-lnY5PfOa)~;1szdufb2diL21;wftMNon`4MT8bnv!9>p|m`|??%#I zizuPYM8m`)xe->S@gNzbgc*jeJkeq(pK2}bQ6ij^l-~OXiRG*mX{mn8y|kt$t$$>= z{V9tk#1o-gyyp}@ll}`@uQg)R`Lva zYj|buZ7fd+$*}P2oY&jpL6k9sLK#KO7qP&w`}cMAg)&sqa(xjOQCr5IA-|GtV)O4c zgC#ntfUb*GDk(vF<-myLFxe7C+Z5->hpTJPV5=|4J!P1XY=JPq0Y=D{vv){-90-Uc Usu^w~vy&Jj9}*^y8H@((6Rp|KH~;_u diff --git a/src/com/google/dart/compiler/backend/js/JsNameProvider.java b/src/com/google/dart/compiler/backend/js/JsNameProvider.java deleted file mode 100644 index 5cdab3dc714..00000000000 --- a/src/com/google/dart/compiler/backend/js/JsNameProvider.java +++ /dev/null @@ -1,85 +0,0 @@ -//// Copyright 2011, the Dart project authors. All rights reserved. -//// Redistribution and use in source and binary forms, with or without -//// modification, are permitted provided that the following conditions are -//// met: -//// -//// * Redistributions of source code must retain the above copyright -//// notice, this list of conditions and the following disclaimer. -//// * Redistributions in binary form must reproduce the above -//// copyright notice, this list of conditions and the following -//// disclaimer in the documentation and/or other materials provided -//// with the distribution. -//// * Neither the name of Google Inc. nor the names of its -//// contributors may be used to endorse or promote products derived -//// from this software without specific prior written permission. -//// -//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -//// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -//// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -//// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -//// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -//// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -//// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 -//// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -//package com.google.dart.compiler.backend.js; -// -//import com.google.dart.compiler.backend.js.ast.JsName; -//import com.google.dart.compiler.backend.js.ast.JsProgram; -//import com.google.dart.compiler.backend.js.ast.JsScope; -//import com.google.dart.compiler.resolver.ClassElement; -//import com.google.dart.compiler.resolver.ElementKind; -// -//import java.util.HashMap; -//import java.util.Map; -// -///** -// * A helper class for managing global names. -// * @author johnlenz@google.com (John Lenz) -// */ -//class JsNameProvider { -// private final DartMangler mangler; -// private Map names = new HashMap(); -// private JsScope globalScope; -// -// JsNameProvider(JsProgram program, DartMangler mangler) { -// this.globalScope = program.getScope(); -// this.mangler = mangler; -// } -// -// /** -// * Returns the JsName for the given element. If the element is global and -// * hasn't been declared yet, it is done now. -// */ -// JsName getName(Symbol symbol) { -// JsName jsName = names.get(symbol); -// if (jsName != null) { -// assert !jsName.getShortIdent().equals("Object$Dart"); -// return jsName; -// } -// assert ElementKind.of(symbol).equals(ElementKind.CLASS) -// : "Only classes can be lazily declared. Undeclared: " -// + symbol.getOriginalSymbolName(); -// ClassElement classElement = (ClassElement) symbol; -// String name = classElement.getName(); -// String nativeName = classElement.getNativeName(); -// if (nativeName == null) { -// String mangledClassName = mangler.mangleClassName(classElement); -// jsName = globalScope.declareName(mangledClassName, mangledClassName, name); -// } else { -// jsName = globalScope.declareName(nativeName); -// } -// // Class names are globally accessible. -// jsName.setObfuscatable(false); -// names.put(symbol, jsName); -// assert !jsName.getShortIdent().equals("Object$Dart") : "unexpected " + ((ClassElement) symbol).getNode().getSource().getName(); -// return jsName; -// } -// -// void setName(Symbol symbol, JsName name) { -// names.put(symbol, name); -// } -//} diff --git a/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java b/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java deleted file mode 100644 index 5572f24304e..00000000000 --- a/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.k2js.translate; - -import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.util.AstUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetClass; -import org.jetbrains.jet.lang.psi.JetDeclaration; -import org.jetbrains.jet.lang.psi.JetProperty; -import org.jetbrains.jet.lang.psi.JetPropertyAccessor; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * @author Talanov Pavel - */ -public class ClassBodyVisitor extends K2JsVisitor> { - - @Override - @NotNull - public List visitClass(JetClass expression, TranslationContext context) { - List properties = new ArrayList(); - for (JetDeclaration declaration : expression.getDeclarations()) { - properties.addAll(declaration.accept(this, context)); - } - return properties; - } - - @Override - @NotNull - public List visitProperty(JetProperty expression, TranslationContext context) { - List methods = new ArrayList(); - if (expression.getSetter() != null) { - methods.addAll(expression.getSetter().accept(this, context)); - } else { - if (expression.isVar()) { - methods.add(generateDefaultSetter(expression, context)); - } - } - if (expression.getGetter() != null) { - methods.addAll(expression.getGetter().accept(this, context)); - } else { - methods.add(generateDefaultGetter(expression, context)); - } - return methods; - } - - @NotNull - private JsPropertyInitializer generateDefaultGetter(JetProperty expression, TranslationContext context) { - return AstUtil.newNamedMethod - (Namer.getNameForGetter(expression.getName()), generateDefaultGetterFunction(expression, context)); - } - - @NotNull - private JsFunction generateDefaultGetterFunction(JetProperty expression, TranslationContext context) { - JsNameRef backingFieldRef = Namer.getBackingFieldNameForProperty(expression.getName()).makeRef(); - JsReturn returnExpression = new JsReturn(backingFieldRef); - return AstUtil.newFunction - (context.enclosingScope(), null, Collections.EMPTY_LIST, AstUtil.convertToBlock(returnExpression)); - } - - - @NotNull - private JsPropertyInitializer generateDefaultSetter(JetProperty expression, TranslationContext context) { - return AstUtil.newNamedMethod( - Namer.getNameForAccessor(expression.getName(), null), generateDefaultSetterFunction(expression, context)); - } - - @NotNull - private JsFunction generateDefaultSetterFunction(JetProperty expression, TranslationContext context) { - JsFunction result = new JsFunction(context.enclosingScope()); - JsParameter defaultParameter = new JsParameter(context.enclosingScope().declareFreshName(Namer.DEFAULT_SETTER_PARAM_NAME)); - JsBinaryOperation assignExpression = new JsBinaryOperation(JsBinaryOperator.ASG); - assignExpression.setArg1(Namer.getBackingFieldNameForProperty(expression).makeRef()); - assignExpression.setArg2(defaultParameter.getName().makeRef()); - return result; - } - - @Override - @NotNull - public List visitPropertyAccessor - (JetPropertyAccessor expression, TranslationContext context) { - List methods = new ArrayList(); - JsPropertyInitializer namedMethod = generateMethodForAccessor(expression, context); - methods.add(namedMethod); - return methods; - } - - private JsPropertyInitializer generateMethodForAccessor(JetPropertyAccessor expression, TranslationContext context) { - JsFunction methodBody = new JsFunction(context.enclosingScope()); - ExpressionTranslator expressionTranslator = - new ExpressionTranslator(context.newFunction(methodBody)); - JsBlock methodBodyBlock = AstUtil.convertToBlock(expressionTranslator.translate(expression.getBodyExpression())); - methodBody.setBody(methodBodyBlock); - //TODO figure out naming pattern - return AstUtil.newNamedMethod(Namer.getNameForAccessor("nameForAccessor", expression), methodBody); - } - - -} diff --git a/src/org/jetbrains/k2js/translate/ContextType.java b/src/org/jetbrains/k2js/translate/ContextType.java deleted file mode 100644 index 50afc79f6a6..00000000000 --- a/src/org/jetbrains/k2js/translate/ContextType.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.jetbrains.k2js.translate; - -/** - * @author Talanov Pavel - */ -public enum ContextType { - CLASS_DECLARATION { - public DeclarationTranslator.State getDeclarationTranslatorState(DeclarationTranslator translator) { - throw new UnsupportedOperationException("Not impelemented"); - } - }, - FUNCTION_BODY { - public DeclarationTranslator.State getDeclarationTranslatorState(DeclarationTranslator translator) { - return translator.new FunctionVariableDeclaration(); - }; - }, - NAMESPACE_BODY { - public DeclarationTranslator.State getDeclarationTranslatorState(DeclarationTranslator translator) { - return translator.new NamespacePropertyDeclaration(); - }; - }; - - public abstract DeclarationTranslator.State getDeclarationTranslatorState(DeclarationTranslator translator); -} diff --git a/src/org/jetbrains/k2js/translate/DeclarationTranslator.java b/src/org/jetbrains/k2js/translate/DeclarationTranslator.java deleted file mode 100644 index 3bb19ebdeeb..00000000000 --- a/src/org/jetbrains/k2js/translate/DeclarationTranslator.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.jetbrains.k2js.translate; - -import com.google.dart.compiler.backend.js.ast.JsExpression; -import com.google.dart.compiler.backend.js.ast.JsName; -import com.google.dart.compiler.backend.js.ast.JsNameRef; -import com.google.dart.compiler.backend.js.ast.JsStatement; -import com.google.dart.compiler.util.AstUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.*; - -/** - * @author Talanov Pavel - */ -public class DeclarationTranslator extends AbstractTranslator { - - private final State state; - - public DeclarationTranslator(TranslationContext context) { - super(context); - state = context.type().getDeclarationTranslatorState(this); - } - - @NotNull - JsStatement translateDeclaration(JetDeclaration declaration) { - if (declaration instanceof JetProperty) { - return (translateProperty((JetProperty) declaration)); - } - if (declaration instanceof JetNamedFunction) { - return AstUtil.convertToStatement((new FunctionTranslator(translationContext())) - .translateFunction((JetNamedFunction) declaration)); - } - else if (declaration instanceof JetClass) { - ClassTranslator classTranslator = new ClassTranslator(translationContext()); - return classTranslator.translateClass((JetClass)declaration); - } - else if (declaration instanceof JetNamespace) { - // JetNamespace childNamespace = (JetNamespace) declaration; - // state.forNamespace(childNamespace).translate(childNamespace); - } - throw new RuntimeException("Unexpected declaration " + declaration.toString()); - } - - @NotNull - public JsStatement translateProperty(JetProperty declaration) { - return state.translateProperty(declaration); - } - - @Nullable - private JsExpression translateInitializer(JetProperty declaration) { - JsExpression jsInitExpression = null; - JetExpression initializer = declaration.getInitializer(); - if (initializer != null) { - // TODO hack alert - jsInitExpression = (JsExpression) - (new ExpressionTranslator(translationContext())).translate(initializer); - } - return jsInitExpression; - } - - public abstract class State { - public abstract JsStatement translateProperty(JetProperty declaration); - } - - public final class FunctionVariableDeclaration extends State { - @NotNull - public JsStatement translateProperty(JetProperty declaration) { - JsName jsPropertyName = translationContext().declareLocalName(declaration.getName()); - JsExpression jsInitExpression = translateInitializer(declaration); - return AstUtil.newVar(jsPropertyName, jsInitExpression); - } - - } - - public final class NamespacePropertyDeclaration extends State { - @NotNull - public JsStatement translateProperty(JetProperty declaration) { - JsName propertyName = translationContext().declareLocalName(declaration.getName()); - JsNameRef jsPropertyNameReference = - translationContext().getNamespaceQualifiedReference(propertyName); - JsExpression jsInitExpression = translateInitializer(declaration); - JsExpression result; - if (jsInitExpression != null) { - result = AstUtil.newAssignment(jsPropertyNameReference, jsInitExpression); - } - else { - result = jsPropertyNameReference; - } - return AstUtil.convertToStatement(result); - } - } - - - -} diff --git a/src/org/jetbrains/k2js/translate/ExpressionVisitor.java b/src/org/jetbrains/k2js/translate/ExpressionVisitor.java deleted file mode 100644 index a1a89bd3fbd..00000000000 --- a/src/org/jetbrains/k2js/translate/ExpressionVisitor.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.jetbrains.k2js.translate; - -import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.util.AstUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.calls.ExpressionValueArgument; -import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; -import org.jetbrains.jet.lexer.JetToken; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Talanov Pavel - */ -public class ExpressionVisitor extends K2JsVisitor { - - @Override - @NotNull - public JsNode visitConstantExpression(JetConstantExpression expression, TranslationContext context) { - JsExpression result = null; - Object value; - CompileTimeConstant compileTimeValue = context.bindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression); - assert compileTimeValue != null; - value = compileTimeValue.getValue(); - if (value instanceof Integer) { - result = context.program().getNumberLiteral((Integer) value); - } - if (value instanceof Boolean) { - return context.program().getBooleanLiteral((Boolean) value); - } - assert result != null; - return result; - } - - @Override - @NotNull - public JsNode visitBlockExpression(JetBlockExpression jetBlock, TranslationContext context) { - List jetElements = jetBlock.getStatements(); - JsBlock jsBlock = new JsBlock(); - TranslationContext newContext = context.newBlock(); - for (JetElement jetElement : jetElements) { - //TODO hack alert - JetExpression jetExpression = (JetExpression) jetElement; - JsNode jsNode = jetExpression.accept(this, newContext); - jsBlock.addStatement(AstUtil.convertToStatement(jsNode)); - } - assert jsBlock != null; - return jsBlock; - } - - @Override - @NotNull - public JsNode visitReturnExpression(JetReturnExpression jetReturnExpression, TranslationContext context) { - //TODO hack alert - if (jetReturnExpression.getReturnedExpression() != null) { - JsExpression jsExpression = (JsExpression) (jetReturnExpression.getReturnedExpression().accept(this, context)); - JsReturn jsReturnExpression = new JsReturn(jsExpression); - return jsReturnExpression; - } - return new JsReturn(); - } - - @Override - @NotNull - public JsNode visitParenthesizedExpression(JetParenthesizedExpression expression, TranslationContext context) { - return (expression.getExpression()).accept(this, context); - } - - @Override - @NotNull - public JsNode visitBinaryExpression(JetBinaryExpression expression, TranslationContext context) { - JsExpression left = AstUtil.convertToExpression(expression.getLeft().accept(this, context)); - JsExpression right = AstUtil.convertToExpression(expression.getRight().accept(this, context)); - //TODO cast dangerous? - JetToken jetOperationToken = (JetToken)expression.getOperationToken(); - JsBinaryOperation jsBinaryOperation = - new JsBinaryOperation(OperationTranslator.getBinaryOperator(jetOperationToken), left, right); - return jsBinaryOperation; - } - - //TODO think about recursive/non-recursive name look-up - @Override - @NotNull - public JsNode visitSimpleNameExpression(JetSimpleNameExpression expression, TranslationContext context) { - String referencedName = expression.getReferencedName(); - JsName jsName = context.enclosingScope().findExistingNameNoRecurse(referencedName); - if (jsName != null) { - return jsName.makeRef(); - } - jsName = context.functionScope().findExistingNameNoRecurse(referencedName); - if (jsName != null) { - return context.getNamespaceQualifiedReference(jsName); - } - jsName = context.namespaceScope().findExistingNameNoRecurse(referencedName); - if (jsName != null) { - return context.getNamespaceQualifiedReference(jsName); - } - throw new AssertionError("Unindentified name " + expression.getReferencedName()); - } - - @Override - @NotNull - public JsNode visitProperty(JetProperty expression, TranslationContext context) { - DeclarationTranslator translator = new DeclarationTranslator(context); - return translator.translateProperty(expression); - } - - @Override - @NotNull - public JsNode visitCallExpression(JetCallExpression expression, TranslationContext context) { - JsExpression callee = getCallee(expression, context); - List arguments = generateArgumentList(expression.getValueArguments(), context); - return AstUtil.newInvocation(callee, arguments); - } - - @NotNull - private JsExpression getCallee(JetCallExpression expression, TranslationContext context) { - JsNode jsCallee = expression.getCalleeExpression().accept(this, context); - return AstUtil.convertToExpression(jsCallee); - } - - @NotNull - private List generateArgumentList(List jetArguments, TranslationContext context) { - List jsArguments = new ArrayList(); - for (ValueArgument argument : jetArguments) { - JetExpression jetExpression = argument.getArgumentExpression(); - jsArguments.add(AstUtil.convertToExpression(jetExpression.accept(this, context))); - } - return jsArguments; - } - -} diff --git a/src/org/jetbrains/k2js/translate/K2JsVisitor.java b/src/org/jetbrains/k2js/translate/K2JsVisitor.java deleted file mode 100644 index ce248446966..00000000000 --- a/src/org/jetbrains/k2js/translate/K2JsVisitor.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.jetbrains.k2js.translate; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetElement; -import org.jetbrains.jet.lang.psi.JetVisitor; - -/** - * @author Talanov Pavel - */ -public class K2JsVisitor extends JetVisitor { - - @Override - @NotNull - public T visitJetElement(JetElement expression, TranslationContext context) { - throw new RuntimeException("Unexpected expression encountered:" + expression.toString()); - } -} diff --git a/test/org/jetbrains/k2js/test/ClassTest.java b/test/org/jetbrains/k2js/test/ClassTest.java new file mode 100644 index 00000000000..a5858f42e8a --- /dev/null +++ b/test/org/jetbrains/k2js/test/ClassTest.java @@ -0,0 +1,50 @@ +package org.jetbrains.k2js.test; + +import org.jetbrains.k2js.translate.TranslationContext; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; + +import java.io.FileReader; + +import static org.junit.Assert.assertTrue; + +/** + * @author Talanov Pavel + */ +public final class ClassTest extends TranslationTest { + + private final String KOTLIN_JS_LIB = TEST_DIR + "kotlin_lib.js"; + + @Override + protected void runWithRhino(String inputFile, String namespaceName, + String functionName, Object expectedResult) throws Exception { + Context cx = Context.enter(); + FileReader testFileReader = new FileReader(inputFile); + FileReader libReader = new FileReader(KOTLIN_JS_LIB); + try { + Scriptable scope = cx.initStandardObjects(); + cx.evaluateReader(scope, libReader, "lib", 1, null); + cx.evaluateReader(scope, testFileReader, "test case", 1, null); + Object result = extractAndCallFunctionObject(namespaceName, functionName, cx, scope); + assertTrue(result.equals(expectedResult)); + String report = namespaceName + "." + functionName + "() = " + Context.toString(result); + System.out.println(report); + + } finally { + Context.exit(); + testFileReader.close(); + } + } + + @Test + public void kotlinJsLibRunsWithRhino() throws Exception { + runWithRhino(TEST_DIR + "testKotlinLib.js", "foo", "box", true); + } + + @Test + public void classInstantiation() throws Exception { + testFooBoxIsTrue("classInstantiation.kt"); + } + +} diff --git a/test/org/jetbrains/k2js/test/FunctionTest.java b/test/org/jetbrains/k2js/test/FunctionTest.java new file mode 100644 index 00000000000..e32171bdf33 --- /dev/null +++ b/test/org/jetbrains/k2js/test/FunctionTest.java @@ -0,0 +1,30 @@ +package org.jetbrains.k2js.test; + +import org.junit.Test; + +/** + * @author Talanov Pavel + */ +public final class FunctionTest extends TranslationTest { + + @Test + public void currentTest() throws Exception { + testFooBoxIsTrue("test.kt"); + } + + @Test + public void testAssign() throws Exception { + performTest("assign.jet", "foo", "f", 2.0); + } + + @Test + public void namespaceProperties() throws Exception { + performTest("localProperty.jet", "foo", "box", 50); + } + + @Test + public void comparison() throws Exception { + testFooBoxIsTrue("comparison.kt"); + } + +} diff --git a/test/org/jetbrains/k2js/test/TranslationTest.java b/test/org/jetbrains/k2js/test/TranslationTest.java new file mode 100644 index 00000000000..ae4ca0d61b4 --- /dev/null +++ b/test/org/jetbrains/k2js/test/TranslationTest.java @@ -0,0 +1,66 @@ +package org.jetbrains.k2js.test; + +import org.jetbrains.k2js.K2JSTranslator; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Function; +import org.mozilla.javascript.NativeObject; +import org.mozilla.javascript.Scriptable; + +import java.io.FileReader; +import static org.junit.Assert.*; + + +/** + * @author Talanov Pavel + */ +public class TranslationTest { + + protected final static String TEST_DIR = "test_files/test_cases/"; + + protected void performTest(String inputFile, String namespaceName, + String functionName, Object expectedResult) throws Exception { + K2JSTranslator.Arguments args = new K2JSTranslator.Arguments(); + args.src = TEST_DIR + inputFile; + args.outputDir = getOutputFilename(TEST_DIR + inputFile); + K2JSTranslator.translate(args); + runWithRhino(args.outputDir, namespaceName, functionName, expectedResult); + } + + private String getOutputFilename(String inputFile) { + return inputFile.substring(0, inputFile.lastIndexOf('.')) + ".js"; + } + + protected void runWithRhino(String inputFile, String namespaceName, + String functionName, Object expectedResult) throws Exception { + Context cx = Context.enter(); + FileReader reader = new FileReader(inputFile); + try { + Scriptable scope = cx.initStandardObjects(); + cx.evaluateReader(scope, reader, "test case", 1, null); + Object result = extractAndCallFunctionObject(namespaceName, functionName, cx, scope); + assertTrue(result.equals(expectedResult)); + String report = namespaceName + "." + functionName + "() = " + Context.toString(result); + System.out.println(report); + + } finally { + Context.exit(); + reader.close(); + } + } + + protected Object extractAndCallFunctionObject(String namespaceName, String functionName, + Context cx, Scriptable scope) { + Object foo = scope.get(namespaceName, scope); + assertTrue(foo instanceof NativeObject); + NativeObject namespaceObject = (NativeObject)foo; + Object box = namespaceObject.get(functionName, namespaceObject); + assertTrue(box instanceof Function); + Object functionArgs[] = {}; + Function function = (Function)box; + return function.call(cx, scope, scope, functionArgs); + } + + protected void testFooBoxIsTrue(String filename) throws Exception { + performTest(filename, "foo", "box", true); + } +} diff --git a/test/org/jetbrains/k2js/test/TranslatorTests.java b/test/org/jetbrains/k2js/test/TranslatorTests.java deleted file mode 100644 index fa2e794097f..00000000000 --- a/test/org/jetbrains/k2js/test/TranslatorTests.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jetbrains.k2js.test; - -import org.jetbrains.k2js.K2JSTranslator; -import org.junit.Test; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Function; -import org.mozilla.javascript.NativeObject; -import org.mozilla.javascript.Scriptable; - -import java.io.FileReader; -import static org.junit.Assert.*; - - -/** - * @author Talanov Pavel - */ -public class TranslatorTests { - - private final static String TEST_DIR = "test_files/test_cases/"; - - private void performTest(String inputFile) throws Exception { - K2JSTranslator.Arguments args = new K2JSTranslator.Arguments(); - args.src = TEST_DIR + inputFile; - args.outputDir = getOutputFilename(TEST_DIR + inputFile); - K2JSTranslator.translate(args); - runWithRhino(args.outputDir); - } - - private String getOutputFilename(String inputFile) { - return inputFile.substring(0, inputFile.lastIndexOf('.')) + ".js"; - } - - private void runWithRhino(String inputFile) throws Exception { - Context cx = Context.enter(); - FileReader reader = new FileReader(inputFile); - try { - Scriptable scope = cx.initStandardObjects(); - cx.evaluateReader(scope, reader, "test case", 1, null); - - Object foo = scope.get("foo", scope); - assertTrue(foo instanceof NativeObject); - NativeObject namespaceObject = (NativeObject)foo; - Object box = namespaceObject.get("box", namespaceObject); - assertTrue(box instanceof Function); - Object functionArgs[] = {}; - Function function = (Function) box; - Object result = function.call(cx, scope, scope, functionArgs); - assertTrue(result instanceof Boolean); - assertTrue((Boolean)result == true); - String report = "foo.box() = " + Context.toString(result); - System.out.println(report); - - } finally { - Context.exit(); - reader.close(); - } - } - - @Test - public void test() throws Exception { - performTest("test.kt"); - } - - @Test - public void testAssign() throws Exception { - performTest("assign.jet"); - } - - @Test - public void namespaceProperties() throws Exception { - performTest("localProperty.jet"); - } - -} diff --git a/test_files/test_cases/assign.jet b/test_files/test_cases/assign.jet index 45948863891..75967d59a79 100644 --- a/test_files/test_cases/assign.jet +++ b/test_files/test_cases/assign.jet @@ -4,8 +4,4 @@ fun f(): Int { var x: Int = 1 x = x + 1 return x -} - -fun box() : Boolean { - return (true) } \ No newline at end of file diff --git a/test_files/test_cases/classInstantiation.kt b/test_files/test_cases/classInstantiation.kt new file mode 100644 index 00000000000..72b9f442679 --- /dev/null +++ b/test_files/test_cases/classInstantiation.kt @@ -0,0 +1,9 @@ +namespace foo + +class Test() { +} + +fun box() : Boolean { + var test = Test() + return true +} \ No newline at end of file diff --git a/test_files/test_cases/comparison.kt b/test_files/test_cases/comparison.kt new file mode 100644 index 00000000000..98ee81ba1ea --- /dev/null +++ b/test_files/test_cases/comparison.kt @@ -0,0 +1,9 @@ +namespace foo + +fun box() : Boolean { + val a = 2; + val b = 3; + var c = 4; + return (a < c) +} + diff --git a/test_files/test_cases/incrementProperty.jet b/test_files/test_cases/incrementProperty.jet new file mode 100644 index 00000000000..7fba26d1359 --- /dev/null +++ b/test_files/test_cases/incrementProperty.jet @@ -0,0 +1,14 @@ +class Slot() { + var vitality: Int = 10000 + + fun increaseVitality(delta: Int) { + vitality += delta + if (vitality > 65535) vitality = 65535; + } +} + +fun box(): Boolean { + val s = Slot() + s.increaseVitality(1000) + return (s.vitality == 11000) +} diff --git a/test_files/test_cases/kotlin_lib.js b/test_files/test_cases/kotlin_lib.js new file mode 100644 index 00000000000..d3c9482a8a7 --- /dev/null +++ b/test_files/test_cases/kotlin_lib.js @@ -0,0 +1,288 @@ +function $A(iterable) { + if (!iterable) return []; + if ('toArray' in Object(iterable)) return iterable.toArray(); + var length = iterable.length || 0, results = new Array(length); + while (length--) results[length] = iterable[length]; + return results; +} + +var emptyFunction = function() {} + +var Class = (function() { + + var IS_DONTENUM_BUGGY = (function(){ + for (var p in { toString: 1 }) { + if (p === 'toString') return false; + } + return true; + })(); + + function subclass() {}; + function create() { + var parent = null, properties = $A(arguments); + if (Object.isFunction(properties[0])) + parent = properties.shift(); + + function klass() { + this.initialize.apply(this, arguments); + } + + Object.extend(klass, Class.Methods); + klass.superclass = parent; + klass.subclasses = []; + + if (parent) { + subclass.prototype = parent.prototype; + klass.prototype = new subclass; + parent.subclasses.push(klass); + } + + for (var i = 0, length = properties.length; i < length; i++) + klass.addMethods(properties[i]); + + if (!klass.prototype.initialize) + klass.prototype.initialize = emptyFunction; + + klass.prototype.constructor = klass; + return klass; + } + + function addMethods(source) { + var ancestor = this.superclass && this.superclass.prototype, + properties = Object.keys(source); + + if (IS_DONTENUM_BUGGY) { + if (source.toString != Object.prototype.toString) + properties.push("toString"); + if (source.valueOf != Object.prototype.valueOf) + properties.push("valueOf"); + } + + for (var i = 0, length = properties.length; i < length; i++) { + var property = properties[i], value = source[property]; + if (ancestor && Object.isFunction(value) && + value.argumentNames()[0] == "$super") { + var method = value; + value = (function(m) { + return function() { return ancestor[m].apply(this, arguments); }; + })(property).wrap(method); + + value.valueOf = method.valueOf.bind(method); + value.toString = method.toString.bind(method); + } + this.prototype[property] = value; + } + + return this; + } + + return { + create: create, + Methods: { + addMethods: addMethods + } + }; +})(); + + + +(function() { + + var _toString = Object.prototype.toString, + NULL_TYPE = 'Null', + UNDEFINED_TYPE = 'Undefined', + BOOLEAN_TYPE = 'Boolean', + NUMBER_TYPE = 'Number', + STRING_TYPE = 'String', + OBJECT_TYPE = 'Object', + FUNCTION_CLASS = '[object Function]', + BOOLEAN_CLASS = '[object Boolean]', + NUMBER_CLASS = '[object Number]', + STRING_CLASS = '[object String]', + ARRAY_CLASS = '[object Array]', + DATE_CLASS = '[object Date]'; + + function Type(o) { + switch(o) { + case null: return NULL_TYPE; + case (void 0): return UNDEFINED_TYPE; + } + var type = typeof o; + switch(type) { + case 'boolean': return BOOLEAN_TYPE; + case 'number': return NUMBER_TYPE; + case 'string': return STRING_TYPE; + } + return OBJECT_TYPE; + } + + function extend(destination, source) { + for (var property in source) + destination[property] = source[property]; + return destination; + } + + function inspect(object) { + try { + if (isUndefined(object)) return 'undefined'; + if (object === null) return 'null'; + return object.inspect ? object.inspect() : String(object); + } catch (e) { + if (e instanceof RangeError) return '...'; + throw e; + } + } + + function toJSON(value) { + return Str('', { '': value }, []); + } + + function Str(key, holder, stack) { + var value = holder[key], + type = typeof value; + + if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + + var _class = _toString.call(value); + + switch (_class) { + case NUMBER_CLASS: + case BOOLEAN_CLASS: + case STRING_CLASS: + value = value.valueOf(); + } + + switch (value) { + case null: return 'null'; + case true: return 'true'; + case false: return 'false'; + } + + type = typeof value; + switch (type) { + case 'string': + return value.inspect(true); + case 'number': + return isFinite(value) ? String(value) : 'null'; + case 'object': + + for (var i = 0, length = stack.length; i < length; i++) { + if (stack[i] === value) { throw new TypeError(); } + } + stack.push(value); + + var partial = []; + if (_class === ARRAY_CLASS) { + for (var i = 0, length = value.length; i < length; i++) { + var str = Str(i, value, stack); + partial.push(typeof str === 'undefined' ? 'null' : str); + } + partial = '[' + partial.join(',') + ']'; + } else { + var keys = Object.keys(value); + for (var i = 0, length = keys.length; i < length; i++) { + var key = keys[i], str = Str(key, value, stack); + if (typeof str !== "undefined") { + partial.push(key.inspect(true)+ ':' + str); + } + } + partial = '{' + partial.join(',') + '}'; + } + stack.pop(); + return partial; + } + } + + function stringify(object) { + return JSON.stringify(object); + } + + function toQueryString(object) { + return $H(object).toQueryString(); + } + + function toHTML(object) { + return object && object.toHTML ? object.toHTML() : String.interpret(object); + } + + function keys(object) { + if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); } + var results = []; + for (var property in object) { + if (object.hasOwnProperty(property)) { + results.push(property); + } + } + return results; + } + + function values(object) { + var results = []; + for (var property in object) + results.push(object[property]); + return results; + } + + function clone(object) { + return extend({ }, object); + } + + function isElement(object) { + return !!(object && object.nodeType == 1); + } + + function isArray(object) { + return _toString.call(object) === ARRAY_CLASS; + } + + var hasNativeIsArray = (typeof Array.isArray == 'function') + && Array.isArray([]) && !Array.isArray({}); + + if (hasNativeIsArray) { + isArray = Array.isArray; + } + + function isHash(object) { + return object instanceof Hash; + } + + function isFunction(object) { + return _toString.call(object) === FUNCTION_CLASS; + } + + function isString(object) { + return _toString.call(object) === STRING_CLASS; + } + + function isNumber(object) { + return _toString.call(object) === NUMBER_CLASS; + } + + function isDate(object) { + return _toString.call(object) === DATE_CLASS; + } + + function isUndefined(object) { + return typeof object === "undefined"; + } + + extend(Object, { + extend: extend, + inspect: inspect, + toQueryString: toQueryString, + toHTML: toHTML, + keys: Object.keys || keys, + values: values, + clone: clone, + isElement: isElement, + isArray: isArray, + isHash: isHash, + isFunction: isFunction, + isString: isString, + isNumber: isNumber, + isDate: isDate, + isUndefined: isUndefined + }); +})(); \ No newline at end of file diff --git a/test_files/test_cases/localProperty.jet b/test_files/test_cases/localProperty.jet index 2e3600d5cf0..1f2f52fce72 100644 --- a/test_files/test_cases/localProperty.jet +++ b/test_files/test_cases/localProperty.jet @@ -9,7 +9,7 @@ fun f(a:Int) : Int { return y } -fun box() : Boolean +fun box() : Int { - return (f(3) == 50) + return f(y) } diff --git a/test_files/test_cases/prototype.js b/test_files/test_cases/prototype.js new file mode 100644 index 00000000000..9474d0e2189 --- /dev/null +++ b/test_files/test_cases/prototype.js @@ -0,0 +1,6008 @@ +/* Prototype JavaScript framework, version 1.7 + * (c) 2005-2010 Sam Stephenson + * + * Prototype is freely distributable under the terms of an MIT-style license. + * For details, see the Prototype web site: http://www.prototypejs.org/ + * + *--------------------------------------------------------------------------*/ + +var Prototype = { + + Version: '1.7', + + Browser: (function(){ + var ua = navigator.userAgent; + var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; + return { + IE: !!window.attachEvent && !isOpera, + Opera: isOpera, + WebKit: ua.indexOf('AppleWebKit/') > -1, + Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1, + MobileSafari: /Apple.*Mobile/.test(ua) + } + })(), + + BrowserFeatures: { + XPath: !!document.evaluate, + + SelectorsAPI: !!document.querySelector, + + ElementExtensions: (function() { + var constructor = window.Element || window.HTMLElement; + return !!(constructor && constructor.prototype); + })(), + SpecificElementExtensions: (function() { + if (typeof window.HTMLDivElement !== 'undefined') + return true; + + var div = document.createElement('div'), + form = document.createElement('form'), + isSupported = false; + + if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) { + isSupported = true; + } + + div = form = null; + + return isSupported; + })() + }, + + ScriptFragment: ']*>([\\S\\s]*?)<\/script>', + JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, + + emptyFunction: function() { }, + + K: function(x) { return x } +}; + +if (Prototype.Browser.MobileSafari) + Prototype.BrowserFeatures.SpecificElementExtensions = false; + + +var Abstract = { }; + + +var Try = { + these: function() { + var returnValue; + + for (var i = 0, length = arguments.length; i < length; i++) { + var lambda = arguments[i]; + try { + returnValue = lambda(); + break; + } catch (e) { } + } + + return returnValue; + } +}; + +/* Based on Alex Arnell's inheritance implementation. */ + + +(function() { + + var _toString = Object.prototype.toString, + NULL_TYPE = 'Null', + UNDEFINED_TYPE = 'Undefined', + BOOLEAN_TYPE = 'Boolean', + NUMBER_TYPE = 'Number', + STRING_TYPE = 'String', + OBJECT_TYPE = 'Object', + FUNCTION_CLASS = '[object Function]', + BOOLEAN_CLASS = '[object Boolean]', + NUMBER_CLASS = '[object Number]', + STRING_CLASS = '[object String]', + ARRAY_CLASS = '[object Array]', + DATE_CLASS = '[object Date]', + NATIVE_JSON_STRINGIFY_SUPPORT = window.JSON && + typeof JSON.stringify === 'function' && + JSON.stringify(0) === '0' && + typeof JSON.stringify(Prototype.K) === 'undefined'; + + function Type(o) { + switch(o) { + case null: return NULL_TYPE; + case (void 0): return UNDEFINED_TYPE; + } + var type = typeof o; + switch(type) { + case 'boolean': return BOOLEAN_TYPE; + case 'number': return NUMBER_TYPE; + case 'string': return STRING_TYPE; + } + return OBJECT_TYPE; + } + + function extend(destination, source) { + for (var property in source) + destination[property] = source[property]; + return destination; + } + + function inspect(object) { + try { + if (isUndefined(object)) return 'undefined'; + if (object === null) return 'null'; + return object.inspect ? object.inspect() : String(object); + } catch (e) { + if (e instanceof RangeError) return '...'; + throw e; + } + } + + function toJSON(value) { + return Str('', { '': value }, []); + } + + function Str(key, holder, stack) { + var value = holder[key], + type = typeof value; + + if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + + var _class = _toString.call(value); + + switch (_class) { + case NUMBER_CLASS: + case BOOLEAN_CLASS: + case STRING_CLASS: + value = value.valueOf(); + } + + switch (value) { + case null: return 'null'; + case true: return 'true'; + case false: return 'false'; + } + + type = typeof value; + switch (type) { + case 'string': + return value.inspect(true); + case 'number': + return isFinite(value) ? String(value) : 'null'; + case 'object': + + for (var i = 0, length = stack.length; i < length; i++) { + if (stack[i] === value) { throw new TypeError(); } + } + stack.push(value); + + var partial = []; + if (_class === ARRAY_CLASS) { + for (var i = 0, length = value.length; i < length; i++) { + var str = Str(i, value, stack); + partial.push(typeof str === 'undefined' ? 'null' : str); + } + partial = '[' + partial.join(',') + ']'; + } else { + var keys = Object.keys(value); + for (var i = 0, length = keys.length; i < length; i++) { + var key = keys[i], str = Str(key, value, stack); + if (typeof str !== "undefined") { + partial.push(key.inspect(true)+ ':' + str); + } + } + partial = '{' + partial.join(',') + '}'; + } + stack.pop(); + return partial; + } + } + + function stringify(object) { + return JSON.stringify(object); + } + + function toQueryString(object) { + return $H(object).toQueryString(); + } + + function toHTML(object) { + return object && object.toHTML ? object.toHTML() : String.interpret(object); + } + + function keys(object) { + if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); } + var results = []; + for (var property in object) { + if (object.hasOwnProperty(property)) { + results.push(property); + } + } + return results; + } + + function values(object) { + var results = []; + for (var property in object) + results.push(object[property]); + return results; + } + + function clone(object) { + return extend({ }, object); + } + + function isElement(object) { + return !!(object && object.nodeType == 1); + } + + function isArray(object) { + return _toString.call(object) === ARRAY_CLASS; + } + + var hasNativeIsArray = (typeof Array.isArray == 'function') + && Array.isArray([]) && !Array.isArray({}); + + if (hasNativeIsArray) { + isArray = Array.isArray; + } + + function isHash(object) { + return object instanceof Hash; + } + + function isFunction(object) { + return _toString.call(object) === FUNCTION_CLASS; + } + + function isString(object) { + return _toString.call(object) === STRING_CLASS; + } + + function isNumber(object) { + return _toString.call(object) === NUMBER_CLASS; + } + + function isDate(object) { + return _toString.call(object) === DATE_CLASS; + } + + function isUndefined(object) { + return typeof object === "undefined"; + } + + extend(Object, { + extend: extend, + inspect: inspect, + toJSON: NATIVE_JSON_STRINGIFY_SUPPORT ? stringify : toJSON, + toQueryString: toQueryString, + toHTML: toHTML, + keys: Object.keys || keys, + values: values, + clone: clone, + isElement: isElement, + isArray: isArray, + isHash: isHash, + isFunction: isFunction, + isString: isString, + isNumber: isNumber, + isDate: isDate, + isUndefined: isUndefined + }); +})(); +Object.extend(Function.prototype, (function() { + var slice = Array.prototype.slice; + + function update(array, args) { + var arrayLength = array.length, length = args.length; + while (length--) array[arrayLength + length] = args[length]; + return array; + } + + function merge(array, args) { + array = slice.call(array, 0); + return update(array, args); + } + + function argumentNames() { + var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1] + .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '') + .replace(/\s+/g, '').split(','); + return names.length == 1 && !names[0] ? [] : names; + } + + function bind(context) { + if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; + var __method = this, args = slice.call(arguments, 1); + return function() { + var a = merge(args, arguments); + return __method.apply(context, a); + } + } + + function bindAsEventListener(context) { + var __method = this, args = slice.call(arguments, 1); + return function(event) { + var a = update([event || window.event], args); + return __method.apply(context, a); + } + } + + function curry() { + if (!arguments.length) return this; + var __method = this, args = slice.call(arguments, 0); + return function() { + var a = merge(args, arguments); + return __method.apply(this, a); + } + } + + function delay(timeout) { + var __method = this, args = slice.call(arguments, 1); + timeout = timeout * 1000; + return window.setTimeout(function() { + return __method.apply(__method, args); + }, timeout); + } + + function defer() { + var args = update([0.01], arguments); + return this.delay.apply(this, args); + } + + function wrap(wrapper) { + var __method = this; + return function() { + var a = update([__method.bind(this)], arguments); + return wrapper.apply(this, a); + } + } + + function methodize() { + if (this._methodized) return this._methodized; + var __method = this; + return this._methodized = function() { + var a = update([this], arguments); + return __method.apply(null, a); + }; + } + + return { + argumentNames: argumentNames, + bind: bind, + bindAsEventListener: bindAsEventListener, + curry: curry, + delay: delay, + defer: defer, + wrap: wrap, + methodize: methodize + } +})()); + + + +(function(proto) { + + + function toISOString() { + return this.getUTCFullYear() + '-' + + (this.getUTCMonth() + 1).toPaddedString(2) + '-' + + this.getUTCDate().toPaddedString(2) + 'T' + + this.getUTCHours().toPaddedString(2) + ':' + + this.getUTCMinutes().toPaddedString(2) + ':' + + this.getUTCSeconds().toPaddedString(2) + 'Z'; + } + + + function toJSON() { + return this.toISOString(); + } + + if (!proto.toISOString) proto.toISOString = toISOString; + if (!proto.toJSON) proto.toJSON = toJSON; + +})(Date.prototype); + + +RegExp.prototype.match = RegExp.prototype.test; + +RegExp.escape = function(str) { + return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); +}; +var PeriodicalExecuter = Class.create({ + initialize: function(callback, frequency) { + this.callback = callback; + this.frequency = frequency; + this.currentlyExecuting = false; + + this.registerCallback(); + }, + + registerCallback: function() { + this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); + }, + + execute: function() { + this.callback(this); + }, + + stop: function() { + if (!this.timer) return; + clearInterval(this.timer); + this.timer = null; + }, + + onTimerEvent: function() { + if (!this.currentlyExecuting) { + try { + this.currentlyExecuting = true; + this.execute(); + this.currentlyExecuting = false; + } catch(e) { + this.currentlyExecuting = false; + throw e; + } + } + } +}); +Object.extend(String, { + interpret: function(value) { + return value == null ? '' : String(value); + }, + specialChar: { + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '\\': '\\\\' + } +}); + +Object.extend(String.prototype, (function() { + var NATIVE_JSON_PARSE_SUPPORT = window.JSON && + typeof JSON.parse === 'function' && + JSON.parse('{"test": true}').test; + + function prepareReplacement(replacement) { + if (Object.isFunction(replacement)) return replacement; + var template = new Template(replacement); + return function(match) { return template.evaluate(match) }; + } + + function gsub(pattern, replacement) { + var result = '', source = this, match; + replacement = prepareReplacement(replacement); + + if (Object.isString(pattern)) + pattern = RegExp.escape(pattern); + + if (!(pattern.length || pattern.source)) { + replacement = replacement(''); + return replacement + source.split('').join(replacement) + replacement; + } + + while (source.length > 0) { + if (match = source.match(pattern)) { + result += source.slice(0, match.index); + result += String.interpret(replacement(match)); + source = source.slice(match.index + match[0].length); + } else { + result += source, source = ''; + } + } + return result; + } + + function sub(pattern, replacement, count) { + replacement = prepareReplacement(replacement); + count = Object.isUndefined(count) ? 1 : count; + + return this.gsub(pattern, function(match) { + if (--count < 0) return match[0]; + return replacement(match); + }); + } + + function scan(pattern, iterator) { + this.gsub(pattern, iterator); + return String(this); + } + + function truncate(length, truncation) { + length = length || 30; + truncation = Object.isUndefined(truncation) ? '...' : truncation; + return this.length > length ? + this.slice(0, length - truncation.length) + truncation : String(this); + } + + function strip() { + return this.replace(/^\s+/, '').replace(/\s+$/, ''); + } + + function stripTags() { + return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, ''); + } + + function stripScripts() { + return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); + } + + function extractScripts() { + var matchAll = new RegExp(Prototype.ScriptFragment, 'img'), + matchOne = new RegExp(Prototype.ScriptFragment, 'im'); + return (this.match(matchAll) || []).map(function(scriptTag) { + return (scriptTag.match(matchOne) || ['', ''])[1]; + }); + } + + function evalScripts() { + return this.extractScripts().map(function(script) { return eval(script) }); + } + + function escapeHTML() { + return this.replace(/&/g,'&').replace(//g,'>'); + } + + function unescapeHTML() { + return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); + } + + + function toQueryParams(separator) { + var match = this.strip().match(/([^?#]*)(#.*)?$/); + if (!match) return { }; + + return match[1].split(separator || '&').inject({ }, function(hash, pair) { + if ((pair = pair.split('='))[0]) { + var key = decodeURIComponent(pair.shift()), + value = pair.length > 1 ? pair.join('=') : pair[0]; + + if (value != undefined) value = decodeURIComponent(value); + + if (key in hash) { + if (!Object.isArray(hash[key])) hash[key] = [hash[key]]; + hash[key].push(value); + } + else hash[key] = value; + } + return hash; + }); + } + + function toArray() { + return this.split(''); + } + + function succ() { + return this.slice(0, this.length - 1) + + String.fromCharCode(this.charCodeAt(this.length - 1) + 1); + } + + function times(count) { + return count < 1 ? '' : new Array(count + 1).join(this); + } + + function camelize() { + return this.replace(/-+(.)?/g, function(match, chr) { + return chr ? chr.toUpperCase() : ''; + }); + } + + function capitalize() { + return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); + } + + function underscore() { + return this.replace(/::/g, '/') + .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') + .replace(/([a-z\d])([A-Z])/g, '$1_$2') + .replace(/-/g, '_') + .toLowerCase(); + } + + function dasherize() { + return this.replace(/_/g, '-'); + } + + function inspect(useDoubleQuotes) { + var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) { + if (character in String.specialChar) { + return String.specialChar[character]; + } + return '\\u00' + character.charCodeAt().toPaddedString(2, 16); + }); + if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; + return "'" + escapedString.replace(/'/g, '\\\'') + "'"; + } + + function unfilterJSON(filter) { + return this.replace(filter || Prototype.JSONFilter, '$1'); + } + + function isJSON() { + var str = this; + if (str.blank()) return false; + str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'); + str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'); + str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); + return (/^[\],:{}\s]*$/).test(str); + } + + function evalJSON(sanitize) { + var json = this.unfilterJSON(), + cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + if (cx.test(json)) { + json = json.replace(cx, function (a) { + return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + try { + if (!sanitize || json.isJSON()) return eval('(' + json + ')'); + } catch (e) { } + throw new SyntaxError('Badly formed JSON string: ' + this.inspect()); + } + + function parseJSON() { + var json = this.unfilterJSON(); + return JSON.parse(json); + } + + function include(pattern) { + return this.indexOf(pattern) > -1; + } + + function startsWith(pattern) { + return this.lastIndexOf(pattern, 0) === 0; + } + + function endsWith(pattern) { + var d = this.length - pattern.length; + return d >= 0 && this.indexOf(pattern, d) === d; + } + + function empty() { + return this == ''; + } + + function blank() { + return /^\s*$/.test(this); + } + + function interpolate(object, pattern) { + return new Template(this, pattern).evaluate(object); + } + + return { + gsub: gsub, + sub: sub, + scan: scan, + truncate: truncate, + strip: String.prototype.trim || strip, + stripTags: stripTags, + stripScripts: stripScripts, + extractScripts: extractScripts, + evalScripts: evalScripts, + escapeHTML: escapeHTML, + unescapeHTML: unescapeHTML, + toQueryParams: toQueryParams, + parseQuery: toQueryParams, + toArray: toArray, + succ: succ, + times: times, + camelize: camelize, + capitalize: capitalize, + underscore: underscore, + dasherize: dasherize, + inspect: inspect, + unfilterJSON: unfilterJSON, + isJSON: isJSON, + evalJSON: NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON, + include: include, + startsWith: startsWith, + endsWith: endsWith, + empty: empty, + blank: blank, + interpolate: interpolate + }; +})()); + +var Template = Class.create({ + initialize: function(template, pattern) { + this.template = template.toString(); + this.pattern = pattern || Template.Pattern; + }, + + evaluate: function(object) { + if (object && Object.isFunction(object.toTemplateReplacements)) + object = object.toTemplateReplacements(); + + return this.template.gsub(this.pattern, function(match) { + if (object == null) return (match[1] + ''); + + var before = match[1] || ''; + if (before == '\\') return match[2]; + + var ctx = object, expr = match[3], + pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/; + + match = pattern.exec(expr); + if (match == null) return before; + + while (match != null) { + var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1]; + ctx = ctx[comp]; + if (null == ctx || '' == match[3]) break; + expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); + match = pattern.exec(expr); + } + + return before + String.interpret(ctx); + }); + } +}); +Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; + +var $break = { }; + +var Enumerable = (function() { + function each(iterator, context) { + var index = 0; + try { + this._each(function(value) { + iterator.call(context, value, index++); + }); + } catch (e) { + if (e != $break) throw e; + } + return this; + } + + function eachSlice(number, iterator, context) { + var index = -number, slices = [], array = this.toArray(); + if (number < 1) return array; + while ((index += number) < array.length) + slices.push(array.slice(index, index+number)); + return slices.collect(iterator, context); + } + + function all(iterator, context) { + iterator = iterator || Prototype.K; + var result = true; + this.each(function(value, index) { + result = result && !!iterator.call(context, value, index); + if (!result) throw $break; + }); + return result; + } + + function any(iterator, context) { + iterator = iterator || Prototype.K; + var result = false; + this.each(function(value, index) { + if (result = !!iterator.call(context, value, index)) + throw $break; + }); + return result; + } + + function collect(iterator, context) { + iterator = iterator || Prototype.K; + var results = []; + this.each(function(value, index) { + results.push(iterator.call(context, value, index)); + }); + return results; + } + + function detect(iterator, context) { + var result; + this.each(function(value, index) { + if (iterator.call(context, value, index)) { + result = value; + throw $break; + } + }); + return result; + } + + function findAll(iterator, context) { + var results = []; + this.each(function(value, index) { + if (iterator.call(context, value, index)) + results.push(value); + }); + return results; + } + + function grep(filter, iterator, context) { + iterator = iterator || Prototype.K; + var results = []; + + if (Object.isString(filter)) + filter = new RegExp(RegExp.escape(filter)); + + this.each(function(value, index) { + if (filter.match(value)) + results.push(iterator.call(context, value, index)); + }); + return results; + } + + function include(object) { + if (Object.isFunction(this.indexOf)) + if (this.indexOf(object) != -1) return true; + + var found = false; + this.each(function(value) { + if (value == object) { + found = true; + throw $break; + } + }); + return found; + } + + function inGroupsOf(number, fillWith) { + fillWith = Object.isUndefined(fillWith) ? null : fillWith; + return this.eachSlice(number, function(slice) { + while(slice.length < number) slice.push(fillWith); + return slice; + }); + } + + function inject(memo, iterator, context) { + this.each(function(value, index) { + memo = iterator.call(context, memo, value, index); + }); + return memo; + } + + function invoke(method) { + var args = $A(arguments).slice(1); + return this.map(function(value) { + return value[method].apply(value, args); + }); + } + + function max(iterator, context) { + iterator = iterator || Prototype.K; + var result; + this.each(function(value, index) { + value = iterator.call(context, value, index); + if (result == null || value >= result) + result = value; + }); + return result; + } + + function min(iterator, context) { + iterator = iterator || Prototype.K; + var result; + this.each(function(value, index) { + value = iterator.call(context, value, index); + if (result == null || value < result) + result = value; + }); + return result; + } + + function partition(iterator, context) { + iterator = iterator || Prototype.K; + var trues = [], falses = []; + this.each(function(value, index) { + (iterator.call(context, value, index) ? + trues : falses).push(value); + }); + return [trues, falses]; + } + + function pluck(property) { + var results = []; + this.each(function(value) { + results.push(value[property]); + }); + return results; + } + + function reject(iterator, context) { + var results = []; + this.each(function(value, index) { + if (!iterator.call(context, value, index)) + results.push(value); + }); + return results; + } + + function sortBy(iterator, context) { + return this.map(function(value, index) { + return { + value: value, + criteria: iterator.call(context, value, index) + }; + }).sort(function(left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }).pluck('value'); + } + + function toArray() { + return this.map(); + } + + function zip() { + var iterator = Prototype.K, args = $A(arguments); + if (Object.isFunction(args.last())) + iterator = args.pop(); + + var collections = [this].concat(args).map($A); + return this.map(function(value, index) { + return iterator(collections.pluck(index)); + }); + } + + function size() { + return this.toArray().length; + } + + function inspect() { + return '#'; + } + + + + + + + + + + return { + each: each, + eachSlice: eachSlice, + all: all, + every: all, + any: any, + some: any, + collect: collect, + map: collect, + detect: detect, + findAll: findAll, + select: findAll, + filter: findAll, + grep: grep, + include: include, + member: include, + inGroupsOf: inGroupsOf, + inject: inject, + invoke: invoke, + max: max, + min: min, + partition: partition, + pluck: pluck, + reject: reject, + sortBy: sortBy, + toArray: toArray, + entries: toArray, + zip: zip, + size: size, + inspect: inspect, + find: detect + }; +})(); + +function $A(iterable) { + if (!iterable) return []; + if ('toArray' in Object(iterable)) return iterable.toArray(); + var length = iterable.length || 0, results = new Array(length); + while (length--) results[length] = iterable[length]; + return results; +} + + +function $w(string) { + if (!Object.isString(string)) return []; + string = string.strip(); + return string ? string.split(/\s+/) : []; +} + +Array.from = $A; + + +(function() { + var arrayProto = Array.prototype, + slice = arrayProto.slice, + _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available + + function each(iterator, context) { + for (var i = 0, length = this.length >>> 0; i < length; i++) { + if (i in this) iterator.call(context, this[i], i, this); + } + } + if (!_each) _each = each; + + function clear() { + this.length = 0; + return this; + } + + function first() { + return this[0]; + } + + function last() { + return this[this.length - 1]; + } + + function compact() { + return this.select(function(value) { + return value != null; + }); + } + + function flatten() { + return this.inject([], function(array, value) { + if (Object.isArray(value)) + return array.concat(value.flatten()); + array.push(value); + return array; + }); + } + + function without() { + var values = slice.call(arguments, 0); + return this.select(function(value) { + return !values.include(value); + }); + } + + function reverse(inline) { + return (inline === false ? this.toArray() : this)._reverse(); + } + + function uniq(sorted) { + return this.inject([], function(array, value, index) { + if (0 == index || (sorted ? array.last() != value : !array.include(value))) + array.push(value); + return array; + }); + } + + function intersect(array) { + return this.uniq().findAll(function(item) { + return array.detect(function(value) { return item === value }); + }); + } + + + function clone() { + return slice.call(this, 0); + } + + function size() { + return this.length; + } + + function inspect() { + return '[' + this.map(Object.inspect).join(', ') + ']'; + } + + function indexOf(item, i) { + i || (i = 0); + var length = this.length; + if (i < 0) i = length + i; + for (; i < length; i++) + if (this[i] === item) return i; + return -1; + } + + function lastIndexOf(item, i) { + i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1; + var n = this.slice(0, i).reverse().indexOf(item); + return (n < 0) ? n : i - n - 1; + } + + function concat() { + var array = slice.call(this, 0), item; + for (var i = 0, length = arguments.length; i < length; i++) { + item = arguments[i]; + if (Object.isArray(item) && !('callee' in item)) { + for (var j = 0, arrayLength = item.length; j < arrayLength; j++) + array.push(item[j]); + } else { + array.push(item); + } + } + return array; + } + + Object.extend(arrayProto, Enumerable); + + if (!arrayProto._reverse) + arrayProto._reverse = arrayProto.reverse; + + Object.extend(arrayProto, { + _each: _each, + clear: clear, + first: first, + last: last, + compact: compact, + flatten: flatten, + without: without, + reverse: reverse, + uniq: uniq, + intersect: intersect, + clone: clone, + toArray: clone, + size: size, + inspect: inspect + }); + + var CONCAT_ARGUMENTS_BUGGY = (function() { + return [].concat(arguments)[0][0] !== 1; + })(1,2) + + if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat; + + if (!arrayProto.indexOf) arrayProto.indexOf = indexOf; + if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf; +})(); +function $H(object) { + return new Hash(object); +}; + +var Hash = Class.create(Enumerable, (function() { + function initialize(object) { + this._object = Object.isHash(object) ? object.toObject() : Object.clone(object); + } + + + function _each(iterator) { + for (var key in this._object) { + var value = this._object[key], pair = [key, value]; + pair.key = key; + pair.value = value; + iterator(pair); + } + } + + function set(key, value) { + return this._object[key] = value; + } + + function get(key) { + if (this._object[key] !== Object.prototype[key]) + return this._object[key]; + } + + function unset(key) { + var value = this._object[key]; + delete this._object[key]; + return value; + } + + function toObject() { + return Object.clone(this._object); + } + + + + function keys() { + return this.pluck('key'); + } + + function values() { + return this.pluck('value'); + } + + function index(value) { + var match = this.detect(function(pair) { + return pair.value === value; + }); + return match && match.key; + } + + function merge(object) { + return this.clone().update(object); + } + + function update(object) { + return new Hash(object).inject(this, function(result, pair) { + result.set(pair.key, pair.value); + return result; + }); + } + + function toQueryPair(key, value) { + if (Object.isUndefined(value)) return key; + return key + '=' + encodeURIComponent(String.interpret(value)); + } + + function toQueryString() { + return this.inject([], function(results, pair) { + var key = encodeURIComponent(pair.key), values = pair.value; + + if (values && typeof values == 'object') { + if (Object.isArray(values)) { + var queryValues = []; + for (var i = 0, len = values.length, value; i < len; i++) { + value = values[i]; + queryValues.push(toQueryPair(key, value)); + } + return results.concat(queryValues); + } + } else results.push(toQueryPair(key, values)); + return results; + }).join('&'); + } + + function inspect() { + return '#'; + } + + function clone() { + return new Hash(this); + } + + return { + initialize: initialize, + _each: _each, + set: set, + get: get, + unset: unset, + toObject: toObject, + toTemplateReplacements: toObject, + keys: keys, + values: values, + index: index, + merge: merge, + update: update, + toQueryString: toQueryString, + inspect: inspect, + toJSON: toObject, + clone: clone + }; +})()); + +Hash.from = $H; +Object.extend(Number.prototype, (function() { + function toColorPart() { + return this.toPaddedString(2, 16); + } + + function succ() { + return this + 1; + } + + function times(iterator, context) { + $R(0, this, true).each(iterator, context); + return this; + } + + function toPaddedString(length, radix) { + var string = this.toString(radix || 10); + return '0'.times(length - string.length) + string; + } + + function abs() { + return Math.abs(this); + } + + function round() { + return Math.round(this); + } + + function ceil() { + return Math.ceil(this); + } + + function floor() { + return Math.floor(this); + } + + return { + toColorPart: toColorPart, + succ: succ, + times: times, + toPaddedString: toPaddedString, + abs: abs, + round: round, + ceil: ceil, + floor: floor + }; +})()); + +function $R(start, end, exclusive) { + return new ObjectRange(start, end, exclusive); +} + +var ObjectRange = Class.create(Enumerable, (function() { + function initialize(start, end, exclusive) { + this.start = start; + this.end = end; + this.exclusive = exclusive; + } + + function _each(iterator) { + var value = this.start; + while (this.include(value)) { + iterator(value); + value = value.succ(); + } + } + + function include(value) { + if (value < this.start) + return false; + if (this.exclusive) + return value < this.end; + return value <= this.end; + } + + return { + initialize: initialize, + _each: _each, + include: include + }; +})()); + + + +var Ajax = { + getTransport: function() { + return Try.these( + function() {return new XMLHttpRequest()}, + function() {return new ActiveXObject('Msxml2.XMLHTTP')}, + function() {return new ActiveXObject('Microsoft.XMLHTTP')} + ) || false; + }, + + activeRequestCount: 0 +}; + +Ajax.Responders = { + responders: [], + + _each: function(iterator) { + this.responders._each(iterator); + }, + + register: function(responder) { + if (!this.include(responder)) + this.responders.push(responder); + }, + + unregister: function(responder) { + this.responders = this.responders.without(responder); + }, + + dispatch: function(callback, request, transport, json) { + this.each(function(responder) { + if (Object.isFunction(responder[callback])) { + try { + responder[callback].apply(responder, [request, transport, json]); + } catch (e) { } + } + }); + } +}; + +Object.extend(Ajax.Responders, Enumerable); + +Ajax.Responders.register({ + onCreate: function() { Ajax.activeRequestCount++ }, + onComplete: function() { Ajax.activeRequestCount-- } +}); +Ajax.Base = Class.create({ + initialize: function(options) { + this.options = { + method: 'post', + asynchronous: true, + contentType: 'application/x-www-form-urlencoded', + encoding: 'UTF-8', + parameters: '', + evalJSON: true, + evalJS: true + }; + Object.extend(this.options, options || { }); + + this.options.method = this.options.method.toLowerCase(); + + if (Object.isHash(this.options.parameters)) + this.options.parameters = this.options.parameters.toObject(); + } +}); +Ajax.Request = Class.create(Ajax.Base, { + _complete: false, + + initialize: function($super, url, options) { + $super(options); + this.transport = Ajax.getTransport(); + this.request(url); + }, + + request: function(url) { + this.url = url; + this.method = this.options.method; + var params = Object.isString(this.options.parameters) ? + this.options.parameters : + Object.toQueryString(this.options.parameters); + + if (!['get', 'post'].include(this.method)) { + params += (params ? '&' : '') + "_method=" + this.method; + this.method = 'post'; + } + + if (params && this.method === 'get') { + this.url += (this.url.include('?') ? '&' : '?') + params; + } + + this.parameters = params.toQueryParams(); + + try { + var response = new Ajax.Response(this); + if (this.options.onCreate) this.options.onCreate(response); + Ajax.Responders.dispatch('onCreate', this, response); + + this.transport.open(this.method.toUpperCase(), this.url, + this.options.asynchronous); + + if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1); + + this.transport.onreadystatechange = this.onStateChange.bind(this); + this.setRequestHeaders(); + + this.body = this.method == 'post' ? (this.options.postBody || params) : null; + this.transport.send(this.body); + + /* Force Firefox to handle ready state 4 for synchronous requests */ + if (!this.options.asynchronous && this.transport.overrideMimeType) + this.onStateChange(); + + } + catch (e) { + this.dispatchException(e); + } + }, + + onStateChange: function() { + var readyState = this.transport.readyState; + if (readyState > 1 && !((readyState == 4) && this._complete)) + this.respondToReadyState(this.transport.readyState); + }, + + setRequestHeaders: function() { + var headers = { + 'X-Requested-With': 'XMLHttpRequest', + 'X-Prototype-Version': Prototype.Version, + 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' + }; + + if (this.method == 'post') { + headers['Content-type'] = this.options.contentType + + (this.options.encoding ? '; charset=' + this.options.encoding : ''); + + /* Force "Connection: close" for older Mozilla browsers to work + * around a bug where XMLHttpRequest sends an incorrect + * Content-length header. See Mozilla Bugzilla #246651. + */ + if (this.transport.overrideMimeType && + (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) + headers['Connection'] = 'close'; + } + + if (typeof this.options.requestHeaders == 'object') { + var extras = this.options.requestHeaders; + + if (Object.isFunction(extras.push)) + for (var i = 0, length = extras.length; i < length; i += 2) + headers[extras[i]] = extras[i+1]; + else + $H(extras).each(function(pair) { headers[pair.key] = pair.value }); + } + + for (var name in headers) + this.transport.setRequestHeader(name, headers[name]); + }, + + success: function() { + var status = this.getStatus(); + return !status || (status >= 200 && status < 300) || status == 304; + }, + + getStatus: function() { + try { + if (this.transport.status === 1223) return 204; + return this.transport.status || 0; + } catch (e) { return 0 } + }, + + respondToReadyState: function(readyState) { + var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this); + + if (state == 'Complete') { + try { + this._complete = true; + (this.options['on' + response.status] + || this.options['on' + (this.success() ? 'Success' : 'Failure')] + || Prototype.emptyFunction)(response, response.headerJSON); + } catch (e) { + this.dispatchException(e); + } + + var contentType = response.getHeader('Content-type'); + if (this.options.evalJS == 'force' + || (this.options.evalJS && this.isSameOrigin() && contentType + && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i))) + this.evalResponse(); + } + + try { + (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON); + Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON); + } catch (e) { + this.dispatchException(e); + } + + if (state == 'Complete') { + this.transport.onreadystatechange = Prototype.emptyFunction; + } + }, + + isSameOrigin: function() { + var m = this.url.match(/^\s*https?:\/\/[^\/]*/); + return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({ + protocol: location.protocol, + domain: document.domain, + port: location.port ? ':' + location.port : '' + })); + }, + + getHeader: function(name) { + try { + return this.transport.getResponseHeader(name) || null; + } catch (e) { return null; } + }, + + evalResponse: function() { + try { + return eval((this.transport.responseText || '').unfilterJSON()); + } catch (e) { + this.dispatchException(e); + } + }, + + dispatchException: function(exception) { + (this.options.onException || Prototype.emptyFunction)(this, exception); + Ajax.Responders.dispatch('onException', this, exception); + } +}); + +Ajax.Request.Events = + ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; + + + + + + + + +Ajax.Response = Class.create({ + initialize: function(request){ + this.request = request; + var transport = this.transport = request.transport, + readyState = this.readyState = transport.readyState; + + if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) { + this.status = this.getStatus(); + this.statusText = this.getStatusText(); + this.responseText = String.interpret(transport.responseText); + this.headerJSON = this._getHeaderJSON(); + } + + if (readyState == 4) { + var xml = transport.responseXML; + this.responseXML = Object.isUndefined(xml) ? null : xml; + this.responseJSON = this._getResponseJSON(); + } + }, + + status: 0, + + statusText: '', + + getStatus: Ajax.Request.prototype.getStatus, + + getStatusText: function() { + try { + return this.transport.statusText || ''; + } catch (e) { return '' } + }, + + getHeader: Ajax.Request.prototype.getHeader, + + getAllHeaders: function() { + try { + return this.getAllResponseHeaders(); + } catch (e) { return null } + }, + + getResponseHeader: function(name) { + return this.transport.getResponseHeader(name); + }, + + getAllResponseHeaders: function() { + return this.transport.getAllResponseHeaders(); + }, + + _getHeaderJSON: function() { + var json = this.getHeader('X-JSON'); + if (!json) return null; + json = decodeURIComponent(escape(json)); + try { + return json.evalJSON(this.request.options.sanitizeJSON || + !this.request.isSameOrigin()); + } catch (e) { + this.request.dispatchException(e); + } + }, + + _getResponseJSON: function() { + var options = this.request.options; + if (!options.evalJSON || (options.evalJSON != 'force' && + !(this.getHeader('Content-type') || '').include('application/json')) || + this.responseText.blank()) + return null; + try { + return this.responseText.evalJSON(options.sanitizeJSON || + !this.request.isSameOrigin()); + } catch (e) { + this.request.dispatchException(e); + } + } +}); + +Ajax.Updater = Class.create(Ajax.Request, { + initialize: function($super, container, url, options) { + this.container = { + success: (container.success || container), + failure: (container.failure || (container.success ? null : container)) + }; + + options = Object.clone(options); + var onComplete = options.onComplete; + options.onComplete = (function(response, json) { + this.updateContent(response.responseText); + if (Object.isFunction(onComplete)) onComplete(response, json); + }).bind(this); + + $super(url, options); + }, + + updateContent: function(responseText) { + var receiver = this.container[this.success() ? 'success' : 'failure'], + options = this.options; + + if (!options.evalScripts) responseText = responseText.stripScripts(); + + if (receiver = $(receiver)) { + if (options.insertion) { + if (Object.isString(options.insertion)) { + var insertion = { }; insertion[options.insertion] = responseText; + receiver.insert(insertion); + } + else options.insertion(receiver, responseText); + } + else receiver.update(responseText); + } + } +}); + +Ajax.PeriodicalUpdater = Class.create(Ajax.Base, { + initialize: function($super, container, url, options) { + $super(options); + this.onComplete = this.options.onComplete; + + this.frequency = (this.options.frequency || 2); + this.decay = (this.options.decay || 1); + + this.updater = { }; + this.container = container; + this.url = url; + + this.start(); + }, + + start: function() { + this.options.onComplete = this.updateComplete.bind(this); + this.onTimerEvent(); + }, + + stop: function() { + this.updater.options.onComplete = undefined; + clearTimeout(this.timer); + (this.onComplete || Prototype.emptyFunction).apply(this, arguments); + }, + + updateComplete: function(response) { + if (this.options.decay) { + this.decay = (response.responseText == this.lastText ? + this.decay * this.options.decay : 1); + + this.lastText = response.responseText; + } + this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency); + }, + + onTimerEvent: function() { + this.updater = new Ajax.Updater(this.container, this.url, this.options); + } +}); + + +function $(element) { + if (arguments.length > 1) { + for (var i = 0, elements = [], length = arguments.length; i < length; i++) + elements.push($(arguments[i])); + return elements; + } + if (Object.isString(element)) + element = document.getElementById(element); + return Element.extend(element); +} + +if (Prototype.BrowserFeatures.XPath) { + document._getElementsByXPath = function(expression, parentElement) { + var results = []; + var query = document.evaluate(expression, $(parentElement) || document, + null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + for (var i = 0, length = query.snapshotLength; i < length; i++) + results.push(Element.extend(query.snapshotItem(i))); + return results; + }; +} + +/*--------------------------------------------------------------------------*/ + +if (!Node) var Node = { }; + +if (!Node.ELEMENT_NODE) { + Object.extend(Node, { + ELEMENT_NODE: 1, + ATTRIBUTE_NODE: 2, + TEXT_NODE: 3, + CDATA_SECTION_NODE: 4, + ENTITY_REFERENCE_NODE: 5, + ENTITY_NODE: 6, + PROCESSING_INSTRUCTION_NODE: 7, + COMMENT_NODE: 8, + DOCUMENT_NODE: 9, + DOCUMENT_TYPE_NODE: 10, + DOCUMENT_FRAGMENT_NODE: 11, + NOTATION_NODE: 12 + }); +} + + + +(function(global) { + function shouldUseCache(tagName, attributes) { + if (tagName === 'select') return false; + if ('type' in attributes) return false; + return true; + } + + var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){ + try { + var el = document.createElement(''); + return el.tagName.toLowerCase() === 'input' && el.name === 'x'; + } + catch(err) { + return false; + } + })(); + + var element = global.Element; + + global.Element = function(tagName, attributes) { + attributes = attributes || { }; + tagName = tagName.toLowerCase(); + var cache = Element.cache; + + if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) { + tagName = '<' + tagName + ' name="' + attributes.name + '">'; + delete attributes.name; + return Element.writeAttribute(document.createElement(tagName), attributes); + } + + if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName)); + + var node = shouldUseCache(tagName, attributes) ? + cache[tagName].cloneNode(false) : document.createElement(tagName); + + return Element.writeAttribute(node, attributes); + }; + + Object.extend(global.Element, element || { }); + if (element) global.Element.prototype = element.prototype; + +})(this); + +Element.idCounter = 1; +Element.cache = { }; + +Element._purgeElement = function(element) { + var uid = element._prototypeUID; + if (uid) { + Element.stopObserving(element); + element._prototypeUID = void 0; + delete Element.Storage[uid]; + } +} + +Element.Methods = { + visible: function(element) { + return $(element).style.display != 'none'; + }, + + toggle: function(element) { + element = $(element); + Element[Element.visible(element) ? 'hide' : 'show'](element); + return element; + }, + + hide: function(element) { + element = $(element); + element.style.display = 'none'; + return element; + }, + + show: function(element) { + element = $(element); + element.style.display = ''; + return element; + }, + + remove: function(element) { + element = $(element); + element.parentNode.removeChild(element); + return element; + }, + + update: (function(){ + + var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){ + var el = document.createElement("select"), + isBuggy = true; + el.innerHTML = ""; + if (el.options && el.options[0]) { + isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION"; + } + el = null; + return isBuggy; + })(); + + var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){ + try { + var el = document.createElement("table"); + if (el && el.tBodies) { + el.innerHTML = "test"; + var isBuggy = typeof el.tBodies[0] == "undefined"; + el = null; + return isBuggy; + } + } catch (e) { + return true; + } + })(); + + var LINK_ELEMENT_INNERHTML_BUGGY = (function() { + try { + var el = document.createElement('div'); + el.innerHTML = ""; + var isBuggy = (el.childNodes.length === 0); + el = null; + return isBuggy; + } catch(e) { + return true; + } + })(); + + var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY || + TABLE_ELEMENT_INNERHTML_BUGGY || LINK_ELEMENT_INNERHTML_BUGGY; + + var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () { + var s = document.createElement("script"), + isBuggy = false; + try { + s.appendChild(document.createTextNode("")); + isBuggy = !s.firstChild || + s.firstChild && s.firstChild.nodeType !== 3; + } catch (e) { + isBuggy = true; + } + s = null; + return isBuggy; + })(); + + + function update(element, content) { + element = $(element); + var purgeElement = Element._purgeElement; + + var descendants = element.getElementsByTagName('*'), + i = descendants.length; + while (i--) purgeElement(descendants[i]); + + if (content && content.toElement) + content = content.toElement(); + + if (Object.isElement(content)) + return element.update().insert(content); + + content = Object.toHTML(content); + + var tagName = element.tagName.toUpperCase(); + + if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) { + element.text = content; + return element; + } + + if (ANY_INNERHTML_BUGGY) { + if (tagName in Element._insertionTranslations.tags) { + while (element.firstChild) { + element.removeChild(element.firstChild); + } + Element._getContentFromAnonymousElement(tagName, content.stripScripts()) + .each(function(node) { + element.appendChild(node) + }); + } else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf(' -1) { + while (element.firstChild) { + element.removeChild(element.firstChild); + } + var nodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts(), true); + nodes.each(function(node) { element.appendChild(node) }); + } + else { + element.innerHTML = content.stripScripts(); + } + } + else { + element.innerHTML = content.stripScripts(); + } + + content.evalScripts.bind(content).defer(); + return element; + } + + return update; + })(), + + replace: function(element, content) { + element = $(element); + if (content && content.toElement) content = content.toElement(); + else if (!Object.isElement(content)) { + content = Object.toHTML(content); + var range = element.ownerDocument.createRange(); + range.selectNode(element); + content.evalScripts.bind(content).defer(); + content = range.createContextualFragment(content.stripScripts()); + } + element.parentNode.replaceChild(content, element); + return element; + }, + + insert: function(element, insertions) { + element = $(element); + + if (Object.isString(insertions) || Object.isNumber(insertions) || + Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML))) + insertions = {bottom:insertions}; + + var content, insert, tagName, childNodes; + + for (var position in insertions) { + content = insertions[position]; + position = position.toLowerCase(); + insert = Element._insertionTranslations[position]; + + if (content && content.toElement) content = content.toElement(); + if (Object.isElement(content)) { + insert(element, content); + continue; + } + + content = Object.toHTML(content); + + tagName = ((position == 'before' || position == 'after') + ? element.parentNode : element).tagName.toUpperCase(); + + childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); + + if (position == 'top' || position == 'after') childNodes.reverse(); + childNodes.each(insert.curry(element)); + + content.evalScripts.bind(content).defer(); + } + + return element; + }, + + wrap: function(element, wrapper, attributes) { + element = $(element); + if (Object.isElement(wrapper)) + $(wrapper).writeAttribute(attributes || { }); + else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes); + else wrapper = new Element('div', wrapper); + if (element.parentNode) + element.parentNode.replaceChild(wrapper, element); + wrapper.appendChild(element); + return wrapper; + }, + + inspect: function(element) { + element = $(element); + var result = '<' + element.tagName.toLowerCase(); + $H({'id': 'id', 'className': 'class'}).each(function(pair) { + var property = pair.first(), + attribute = pair.last(), + value = (element[property] || '').toString(); + if (value) result += ' ' + attribute + '=' + value.inspect(true); + }); + return result + '>'; + }, + + recursivelyCollect: function(element, property, maximumLength) { + element = $(element); + maximumLength = maximumLength || -1; + var elements = []; + + while (element = element[property]) { + if (element.nodeType == 1) + elements.push(Element.extend(element)); + if (elements.length == maximumLength) + break; + } + + return elements; + }, + + ancestors: function(element) { + return Element.recursivelyCollect(element, 'parentNode'); + }, + + descendants: function(element) { + return Element.select(element, "*"); + }, + + firstDescendant: function(element) { + element = $(element).firstChild; + while (element && element.nodeType != 1) element = element.nextSibling; + return $(element); + }, + + immediateDescendants: function(element) { + var results = [], child = $(element).firstChild; + while (child) { + if (child.nodeType === 1) { + results.push(Element.extend(child)); + } + child = child.nextSibling; + } + return results; + }, + + previousSiblings: function(element, maximumLength) { + return Element.recursivelyCollect(element, 'previousSibling'); + }, + + nextSiblings: function(element) { + return Element.recursivelyCollect(element, 'nextSibling'); + }, + + siblings: function(element) { + element = $(element); + return Element.previousSiblings(element).reverse() + .concat(Element.nextSiblings(element)); + }, + + match: function(element, selector) { + element = $(element); + if (Object.isString(selector)) + return Prototype.Selector.match(element, selector); + return selector.match(element); + }, + + up: function(element, expression, index) { + element = $(element); + if (arguments.length == 1) return $(element.parentNode); + var ancestors = Element.ancestors(element); + return Object.isNumber(expression) ? ancestors[expression] : + Prototype.Selector.find(ancestors, expression, index); + }, + + down: function(element, expression, index) { + element = $(element); + if (arguments.length == 1) return Element.firstDescendant(element); + return Object.isNumber(expression) ? Element.descendants(element)[expression] : + Element.select(element, expression)[index || 0]; + }, + + previous: function(element, expression, index) { + element = $(element); + if (Object.isNumber(expression)) index = expression, expression = false; + if (!Object.isNumber(index)) index = 0; + + if (expression) { + return Prototype.Selector.find(element.previousSiblings(), expression, index); + } else { + return element.recursivelyCollect("previousSibling", index + 1)[index]; + } + }, + + next: function(element, expression, index) { + element = $(element); + if (Object.isNumber(expression)) index = expression, expression = false; + if (!Object.isNumber(index)) index = 0; + + if (expression) { + return Prototype.Selector.find(element.nextSiblings(), expression, index); + } else { + var maximumLength = Object.isNumber(index) ? index + 1 : 1; + return element.recursivelyCollect("nextSibling", index + 1)[index]; + } + }, + + + select: function(element) { + element = $(element); + var expressions = Array.prototype.slice.call(arguments, 1).join(', '); + return Prototype.Selector.select(expressions, element); + }, + + adjacent: function(element) { + element = $(element); + var expressions = Array.prototype.slice.call(arguments, 1).join(', '); + return Prototype.Selector.select(expressions, element.parentNode).without(element); + }, + + identify: function(element) { + element = $(element); + var id = Element.readAttribute(element, 'id'); + if (id) return id; + do { id = 'anonymous_element_' + Element.idCounter++ } while ($(id)); + Element.writeAttribute(element, 'id', id); + return id; + }, + + readAttribute: function(element, name) { + element = $(element); + if (Prototype.Browser.IE) { + var t = Element._attributeTranslations.read; + if (t.values[name]) return t.values[name](element, name); + if (t.names[name]) name = t.names[name]; + if (name.include(':')) { + return (!element.attributes || !element.attributes[name]) ? null : + element.attributes[name].value; + } + } + return element.getAttribute(name); + }, + + writeAttribute: function(element, name, value) { + element = $(element); + var attributes = { }, t = Element._attributeTranslations.write; + + if (typeof name == 'object') attributes = name; + else attributes[name] = Object.isUndefined(value) ? true : value; + + for (var attr in attributes) { + name = t.names[attr] || attr; + value = attributes[attr]; + if (t.values[attr]) name = t.values[attr](element, value); + if (value === false || value === null) + element.removeAttribute(name); + else if (value === true) + element.setAttribute(name, name); + else element.setAttribute(name, value); + } + return element; + }, + + getHeight: function(element) { + return Element.getDimensions(element).height; + }, + + getWidth: function(element) { + return Element.getDimensions(element).width; + }, + + classNames: function(element) { + return new Element.ClassNames(element); + }, + + hasClassName: function(element, className) { + if (!(element = $(element))) return; + var elementClassName = element.className; + return (elementClassName.length > 0 && (elementClassName == className || + new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName))); + }, + + addClassName: function(element, className) { + if (!(element = $(element))) return; + if (!Element.hasClassName(element, className)) + element.className += (element.className ? ' ' : '') + className; + return element; + }, + + removeClassName: function(element, className) { + if (!(element = $(element))) return; + element.className = element.className.replace( + new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip(); + return element; + }, + + toggleClassName: function(element, className) { + if (!(element = $(element))) return; + return Element[Element.hasClassName(element, className) ? + 'removeClassName' : 'addClassName'](element, className); + }, + + cleanWhitespace: function(element) { + element = $(element); + var node = element.firstChild; + while (node) { + var nextNode = node.nextSibling; + if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) + element.removeChild(node); + node = nextNode; + } + return element; + }, + + empty: function(element) { + return $(element).innerHTML.blank(); + }, + + descendantOf: function(element, ancestor) { + element = $(element), ancestor = $(ancestor); + + if (element.compareDocumentPosition) + return (element.compareDocumentPosition(ancestor) & 8) === 8; + + if (ancestor.contains) + return ancestor.contains(element) && ancestor !== element; + + while (element = element.parentNode) + if (element == ancestor) return true; + + return false; + }, + + scrollTo: function(element) { + element = $(element); + var pos = Element.cumulativeOffset(element); + window.scrollTo(pos[0], pos[1]); + return element; + }, + + getStyle: function(element, style) { + element = $(element); + style = style == 'float' ? 'cssFloat' : style.camelize(); + var value = element.style[style]; + if (!value || value == 'auto') { + var css = document.defaultView.getComputedStyle(element, null); + value = css ? css[style] : null; + } + if (style == 'opacity') return value ? parseFloat(value) : 1.0; + return value == 'auto' ? null : value; + }, + + getOpacity: function(element) { + return $(element).getStyle('opacity'); + }, + + setStyle: function(element, styles) { + element = $(element); + var elementStyle = element.style, match; + if (Object.isString(styles)) { + element.style.cssText += ';' + styles; + return styles.include('opacity') ? + element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element; + } + for (var property in styles) + if (property == 'opacity') element.setOpacity(styles[property]); + else + elementStyle[(property == 'float' || property == 'cssFloat') ? + (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') : + property] = styles[property]; + + return element; + }, + + setOpacity: function(element, value) { + element = $(element); + element.style.opacity = (value == 1 || value === '') ? '' : + (value < 0.00001) ? 0 : value; + return element; + }, + + makePositioned: function(element) { + element = $(element); + var pos = Element.getStyle(element, 'position'); + if (pos == 'static' || !pos) { + element._madePositioned = true; + element.style.position = 'relative'; + if (Prototype.Browser.Opera) { + element.style.top = 0; + element.style.left = 0; + } + } + return element; + }, + + undoPositioned: function(element) { + element = $(element); + if (element._madePositioned) { + element._madePositioned = undefined; + element.style.position = + element.style.top = + element.style.left = + element.style.bottom = + element.style.right = ''; + } + return element; + }, + + makeClipping: function(element) { + element = $(element); + if (element._overflow) return element; + element._overflow = Element.getStyle(element, 'overflow') || 'auto'; + if (element._overflow !== 'hidden') + element.style.overflow = 'hidden'; + return element; + }, + + undoClipping: function(element) { + element = $(element); + if (!element._overflow) return element; + element.style.overflow = element._overflow == 'auto' ? '' : element._overflow; + element._overflow = null; + return element; + }, + + clonePosition: function(element, source) { + var options = Object.extend({ + setLeft: true, + setTop: true, + setWidth: true, + setHeight: true, + offsetTop: 0, + offsetLeft: 0 + }, arguments[2] || { }); + + source = $(source); + var p = Element.viewportOffset(source), delta = [0, 0], parent = null; + + element = $(element); + + if (Element.getStyle(element, 'position') == 'absolute') { + parent = Element.getOffsetParent(element); + delta = Element.viewportOffset(parent); + } + + if (parent == document.body) { + delta[0] -= document.body.offsetLeft; + delta[1] -= document.body.offsetTop; + } + + if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; + if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; + if (options.setWidth) element.style.width = source.offsetWidth + 'px'; + if (options.setHeight) element.style.height = source.offsetHeight + 'px'; + return element; + } +}; + +Object.extend(Element.Methods, { + getElementsBySelector: Element.Methods.select, + + childElements: Element.Methods.immediateDescendants +}); + +Element._attributeTranslations = { + write: { + names: { + className: 'class', + htmlFor: 'for' + }, + values: { } + } +}; + +if (Prototype.Browser.Opera) { + Element.Methods.getStyle = Element.Methods.getStyle.wrap( + function(proceed, element, style) { + switch (style) { + case 'height': case 'width': + if (!Element.visible(element)) return null; + + var dim = parseInt(proceed(element, style), 10); + + if (dim !== element['offset' + style.capitalize()]) + return dim + 'px'; + + var properties; + if (style === 'height') { + properties = ['border-top-width', 'padding-top', + 'padding-bottom', 'border-bottom-width']; + } + else { + properties = ['border-left-width', 'padding-left', + 'padding-right', 'border-right-width']; + } + return properties.inject(dim, function(memo, property) { + var val = proceed(element, property); + return val === null ? memo : memo - parseInt(val, 10); + }) + 'px'; + default: return proceed(element, style); + } + } + ); + + Element.Methods.readAttribute = Element.Methods.readAttribute.wrap( + function(proceed, element, attribute) { + if (attribute === 'title') return element.title; + return proceed(element, attribute); + } + ); +} + +else if (Prototype.Browser.IE) { + Element.Methods.getStyle = function(element, style) { + element = $(element); + style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize(); + var value = element.style[style]; + if (!value && element.currentStyle) value = element.currentStyle[style]; + + if (style == 'opacity') { + if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) + if (value[1]) return parseFloat(value[1]) / 100; + return 1.0; + } + + if (value == 'auto') { + if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none')) + return element['offset' + style.capitalize()] + 'px'; + return null; + } + return value; + }; + + Element.Methods.setOpacity = function(element, value) { + function stripAlpha(filter){ + return filter.replace(/alpha\([^\)]*\)/gi,''); + } + element = $(element); + var currentStyle = element.currentStyle; + if ((currentStyle && !currentStyle.hasLayout) || + (!currentStyle && element.style.zoom == 'normal')) + element.style.zoom = 1; + + var filter = element.getStyle('filter'), style = element.style; + if (value == 1 || value === '') { + (filter = stripAlpha(filter)) ? + style.filter = filter : style.removeAttribute('filter'); + return element; + } else if (value < 0.00001) value = 0; + style.filter = stripAlpha(filter) + + 'alpha(opacity=' + (value * 100) + ')'; + return element; + }; + + Element._attributeTranslations = (function(){ + + var classProp = 'className', + forProp = 'for', + el = document.createElement('div'); + + el.setAttribute(classProp, 'x'); + + if (el.className !== 'x') { + el.setAttribute('class', 'x'); + if (el.className === 'x') { + classProp = 'class'; + } + } + el = null; + + el = document.createElement('label'); + el.setAttribute(forProp, 'x'); + if (el.htmlFor !== 'x') { + el.setAttribute('htmlFor', 'x'); + if (el.htmlFor === 'x') { + forProp = 'htmlFor'; + } + } + el = null; + + return { + read: { + names: { + 'class': classProp, + 'className': classProp, + 'for': forProp, + 'htmlFor': forProp + }, + values: { + _getAttr: function(element, attribute) { + return element.getAttribute(attribute); + }, + _getAttr2: function(element, attribute) { + return element.getAttribute(attribute, 2); + }, + _getAttrNode: function(element, attribute) { + var node = element.getAttributeNode(attribute); + return node ? node.value : ""; + }, + _getEv: (function(){ + + var el = document.createElement('div'), f; + el.onclick = Prototype.emptyFunction; + var value = el.getAttribute('onclick'); + + if (String(value).indexOf('{') > -1) { + f = function(element, attribute) { + attribute = element.getAttribute(attribute); + if (!attribute) return null; + attribute = attribute.toString(); + attribute = attribute.split('{')[1]; + attribute = attribute.split('}')[0]; + return attribute.strip(); + }; + } + else if (value === '') { + f = function(element, attribute) { + attribute = element.getAttribute(attribute); + if (!attribute) return null; + return attribute.strip(); + }; + } + el = null; + return f; + })(), + _flag: function(element, attribute) { + return $(element).hasAttribute(attribute) ? attribute : null; + }, + style: function(element) { + return element.style.cssText.toLowerCase(); + }, + title: function(element) { + return element.title; + } + } + } + } + })(); + + Element._attributeTranslations.write = { + names: Object.extend({ + cellpadding: 'cellPadding', + cellspacing: 'cellSpacing' + }, Element._attributeTranslations.read.names), + values: { + checked: function(element, value) { + element.checked = !!value; + }, + + style: function(element, value) { + element.style.cssText = value ? value : ''; + } + } + }; + + Element._attributeTranslations.has = {}; + + $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' + + 'encType maxLength readOnly longDesc frameBorder').each(function(attr) { + Element._attributeTranslations.write.names[attr.toLowerCase()] = attr; + Element._attributeTranslations.has[attr.toLowerCase()] = attr; + }); + + (function(v) { + Object.extend(v, { + href: v._getAttr2, + src: v._getAttr2, + type: v._getAttr, + action: v._getAttrNode, + disabled: v._flag, + checked: v._flag, + readonly: v._flag, + multiple: v._flag, + onload: v._getEv, + onunload: v._getEv, + onclick: v._getEv, + ondblclick: v._getEv, + onmousedown: v._getEv, + onmouseup: v._getEv, + onmouseover: v._getEv, + onmousemove: v._getEv, + onmouseout: v._getEv, + onfocus: v._getEv, + onblur: v._getEv, + onkeypress: v._getEv, + onkeydown: v._getEv, + onkeyup: v._getEv, + onsubmit: v._getEv, + onreset: v._getEv, + onselect: v._getEv, + onchange: v._getEv + }); + })(Element._attributeTranslations.read.values); + + if (Prototype.BrowserFeatures.ElementExtensions) { + (function() { + function _descendants(element) { + var nodes = element.getElementsByTagName('*'), results = []; + for (var i = 0, node; node = nodes[i]; i++) + if (node.tagName !== "!") // Filter out comment nodes. + results.push(node); + return results; + } + + Element.Methods.down = function(element, expression, index) { + element = $(element); + if (arguments.length == 1) return element.firstDescendant(); + return Object.isNumber(expression) ? _descendants(element)[expression] : + Element.select(element, expression)[index || 0]; + } + })(); + } + +} + +else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) { + Element.Methods.setOpacity = function(element, value) { + element = $(element); + element.style.opacity = (value == 1) ? 0.999999 : + (value === '') ? '' : (value < 0.00001) ? 0 : value; + return element; + }; +} + +else if (Prototype.Browser.WebKit) { + Element.Methods.setOpacity = function(element, value) { + element = $(element); + element.style.opacity = (value == 1 || value === '') ? '' : + (value < 0.00001) ? 0 : value; + + if (value == 1) + if (element.tagName.toUpperCase() == 'IMG' && element.width) { + element.width++; element.width--; + } else try { + var n = document.createTextNode(' '); + element.appendChild(n); + element.removeChild(n); + } catch (e) { } + + return element; + }; +} + +if ('outerHTML' in document.documentElement) { + Element.Methods.replace = function(element, content) { + element = $(element); + + if (content && content.toElement) content = content.toElement(); + if (Object.isElement(content)) { + element.parentNode.replaceChild(content, element); + return element; + } + + content = Object.toHTML(content); + var parent = element.parentNode, tagName = parent.tagName.toUpperCase(); + + if (Element._insertionTranslations.tags[tagName]) { + var nextSibling = element.next(), + fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); + parent.removeChild(element); + if (nextSibling) + fragments.each(function(node) { parent.insertBefore(node, nextSibling) }); + else + fragments.each(function(node) { parent.appendChild(node) }); + } + else element.outerHTML = content.stripScripts(); + + content.evalScripts.bind(content).defer(); + return element; + }; +} + +Element._returnOffset = function(l, t) { + var result = [l, t]; + result.left = l; + result.top = t; + return result; +}; + +Element._getContentFromAnonymousElement = function(tagName, html, force) { + var div = new Element('div'), + t = Element._insertionTranslations.tags[tagName]; + + var workaround = false; + if (t) workaround = true; + else if (force) { + workaround = true; + t = ['', '', 0]; + } + + if (workaround) { + div.innerHTML = ' ' + t[0] + html + t[1]; + div.removeChild(div.firstChild); + for (var i = t[2]; i--; ) { + div = div.firstChild; + } + } + else { + div.innerHTML = html; + } + return $A(div.childNodes); +}; + +Element._insertionTranslations = { + before: function(element, node) { + element.parentNode.insertBefore(node, element); + }, + top: function(element, node) { + element.insertBefore(node, element.firstChild); + }, + bottom: function(element, node) { + element.appendChild(node); + }, + after: function(element, node) { + element.parentNode.insertBefore(node, element.nextSibling); + }, + tags: { + TABLE: ['', '
', 1], + TBODY: ['', '
', 2], + TR: ['', '
', 3], + TD: ['
', '
', 4], + SELECT: ['', 1] + } +}; + +(function() { + var tags = Element._insertionTranslations.tags; + Object.extend(tags, { + THEAD: tags.TBODY, + TFOOT: tags.TBODY, + TH: tags.TD + }); +})(); + +Element.Methods.Simulated = { + hasAttribute: function(element, attribute) { + attribute = Element._attributeTranslations.has[attribute] || attribute; + var node = $(element).getAttributeNode(attribute); + return !!(node && node.specified); + } +}; + +Element.Methods.ByTag = { }; + +Object.extend(Element, Element.Methods); + +(function(div) { + + if (!Prototype.BrowserFeatures.ElementExtensions && div['__proto__']) { + window.HTMLElement = { }; + window.HTMLElement.prototype = div['__proto__']; + Prototype.BrowserFeatures.ElementExtensions = true; + } + + div = null; + +})(document.createElement('div')); + +Element.extend = (function() { + + function checkDeficiency(tagName) { + if (typeof window.Element != 'undefined') { + var proto = window.Element.prototype; + if (proto) { + var id = '_' + (Math.random()+'').slice(2), + el = document.createElement(tagName); + proto[id] = 'x'; + var isBuggy = (el[id] !== 'x'); + delete proto[id]; + el = null; + return isBuggy; + } + } + return false; + } + + function extendElementWith(element, methods) { + for (var property in methods) { + var value = methods[property]; + if (Object.isFunction(value) && !(property in element)) + element[property] = value.methodize(); + } + } + + var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY = checkDeficiency('object'); + + if (Prototype.BrowserFeatures.SpecificElementExtensions) { + if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY) { + return function(element) { + if (element && typeof element._extendedByPrototype == 'undefined') { + var t = element.tagName; + if (t && (/^(?:object|applet|embed)$/i.test(t))) { + extendElementWith(element, Element.Methods); + extendElementWith(element, Element.Methods.Simulated); + extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]); + } + } + return element; + } + } + return Prototype.K; + } + + var Methods = { }, ByTag = Element.Methods.ByTag; + + var extend = Object.extend(function(element) { + if (!element || typeof element._extendedByPrototype != 'undefined' || + element.nodeType != 1 || element == window) return element; + + var methods = Object.clone(Methods), + tagName = element.tagName.toUpperCase(); + + if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]); + + extendElementWith(element, methods); + + element._extendedByPrototype = Prototype.emptyFunction; + return element; + + }, { + refresh: function() { + if (!Prototype.BrowserFeatures.ElementExtensions) { + Object.extend(Methods, Element.Methods); + Object.extend(Methods, Element.Methods.Simulated); + } + } + }); + + extend.refresh(); + return extend; +})(); + +if (document.documentElement.hasAttribute) { + Element.hasAttribute = function(element, attribute) { + return element.hasAttribute(attribute); + }; +} +else { + Element.hasAttribute = Element.Methods.Simulated.hasAttribute; +} + +Element.addMethods = function(methods) { + var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag; + + if (!methods) { + Object.extend(Form, Form.Methods); + Object.extend(Form.Element, Form.Element.Methods); + Object.extend(Element.Methods.ByTag, { + "FORM": Object.clone(Form.Methods), + "INPUT": Object.clone(Form.Element.Methods), + "SELECT": Object.clone(Form.Element.Methods), + "TEXTAREA": Object.clone(Form.Element.Methods), + "BUTTON": Object.clone(Form.Element.Methods) + }); + } + + if (arguments.length == 2) { + var tagName = methods; + methods = arguments[1]; + } + + if (!tagName) Object.extend(Element.Methods, methods || { }); + else { + if (Object.isArray(tagName)) tagName.each(extend); + else extend(tagName); + } + + function extend(tagName) { + tagName = tagName.toUpperCase(); + if (!Element.Methods.ByTag[tagName]) + Element.Methods.ByTag[tagName] = { }; + Object.extend(Element.Methods.ByTag[tagName], methods); + } + + function copy(methods, destination, onlyIfAbsent) { + onlyIfAbsent = onlyIfAbsent || false; + for (var property in methods) { + var value = methods[property]; + if (!Object.isFunction(value)) continue; + if (!onlyIfAbsent || !(property in destination)) + destination[property] = value.methodize(); + } + } + + function findDOMClass(tagName) { + var klass; + var trans = { + "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph", + "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList", + "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading", + "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote", + "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION": + "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD": + "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR": + "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET": + "FrameSet", "IFRAME": "IFrame" + }; + if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element'; + if (window[klass]) return window[klass]; + klass = 'HTML' + tagName + 'Element'; + if (window[klass]) return window[klass]; + klass = 'HTML' + tagName.capitalize() + 'Element'; + if (window[klass]) return window[klass]; + + var element = document.createElement(tagName), + proto = element['__proto__'] || element.constructor.prototype; + + element = null; + return proto; + } + + var elementPrototype = window.HTMLElement ? HTMLElement.prototype : + Element.prototype; + + if (F.ElementExtensions) { + copy(Element.Methods, elementPrototype); + copy(Element.Methods.Simulated, elementPrototype, true); + } + + if (F.SpecificElementExtensions) { + for (var tag in Element.Methods.ByTag) { + var klass = findDOMClass(tag); + if (Object.isUndefined(klass)) continue; + copy(T[tag], klass.prototype); + } + } + + Object.extend(Element, Element.Methods); + delete Element.ByTag; + + if (Element.extend.refresh) Element.extend.refresh(); + Element.cache = { }; +}; + + +document.viewport = { + + getDimensions: function() { + return { width: this.getWidth(), height: this.getHeight() }; + }, + + getScrollOffsets: function() { + return Element._returnOffset( + window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, + window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); + } +}; + +(function(viewport) { + var B = Prototype.Browser, doc = document, element, property = {}; + + function getRootElement() { + if (B.WebKit && !doc.evaluate) + return document; + + if (B.Opera && window.parseFloat(window.opera.version()) < 9.5) + return document.body; + + return document.documentElement; + } + + function define(D) { + if (!element) element = getRootElement(); + + property[D] = 'client' + D; + + viewport['get' + D] = function() { return element[property[D]] }; + return viewport['get' + D](); + } + + viewport.getWidth = define.curry('Width'); + + viewport.getHeight = define.curry('Height'); +})(document.viewport); + + +Element.Storage = { + UID: 1 +}; + +Element.addMethods({ + getStorage: function(element) { + if (!(element = $(element))) return; + + var uid; + if (element === window) { + uid = 0; + } else { + if (typeof element._prototypeUID === "undefined") + element._prototypeUID = Element.Storage.UID++; + uid = element._prototypeUID; + } + + if (!Element.Storage[uid]) + Element.Storage[uid] = $H(); + + return Element.Storage[uid]; + }, + + store: function(element, key, value) { + if (!(element = $(element))) return; + + if (arguments.length === 2) { + Element.getStorage(element).update(key); + } else { + Element.getStorage(element).set(key, value); + } + + return element; + }, + + retrieve: function(element, key, defaultValue) { + if (!(element = $(element))) return; + var hash = Element.getStorage(element), value = hash.get(key); + + if (Object.isUndefined(value)) { + hash.set(key, defaultValue); + value = defaultValue; + } + + return value; + }, + + clone: function(element, deep) { + if (!(element = $(element))) return; + var clone = element.cloneNode(deep); + clone._prototypeUID = void 0; + if (deep) { + var descendants = Element.select(clone, '*'), + i = descendants.length; + while (i--) { + descendants[i]._prototypeUID = void 0; + } + } + return Element.extend(clone); + }, + + purge: function(element) { + if (!(element = $(element))) return; + var purgeElement = Element._purgeElement; + + purgeElement(element); + + var descendants = element.getElementsByTagName('*'), + i = descendants.length; + + while (i--) purgeElement(descendants[i]); + + return null; + } +}); + +(function() { + + function toDecimal(pctString) { + var match = pctString.match(/^(\d+)%?$/i); + if (!match) return null; + return (Number(match[1]) / 100); + } + + function getPixelValue(value, property, context) { + var element = null; + if (Object.isElement(value)) { + element = value; + value = element.getStyle(property); + } + + if (value === null) { + return null; + } + + if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) { + return window.parseFloat(value); + } + + var isPercentage = value.include('%'), isViewport = (context === document.viewport); + + if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) { + var style = element.style.left, rStyle = element.runtimeStyle.left; + element.runtimeStyle.left = element.currentStyle.left; + element.style.left = value || 0; + value = element.style.pixelLeft; + element.style.left = style; + element.runtimeStyle.left = rStyle; + + return value; + } + + if (element && isPercentage) { + context = context || element.parentNode; + var decimal = toDecimal(value); + var whole = null; + var position = element.getStyle('position'); + + var isHorizontal = property.include('left') || property.include('right') || + property.include('width'); + + var isVertical = property.include('top') || property.include('bottom') || + property.include('height'); + + if (context === document.viewport) { + if (isHorizontal) { + whole = document.viewport.getWidth(); + } else if (isVertical) { + whole = document.viewport.getHeight(); + } + } else { + if (isHorizontal) { + whole = $(context).measure('width'); + } else if (isVertical) { + whole = $(context).measure('height'); + } + } + + return (whole === null) ? 0 : whole * decimal; + } + + return 0; + } + + function toCSSPixels(number) { + if (Object.isString(number) && number.endsWith('px')) { + return number; + } + return number + 'px'; + } + + function isDisplayed(element) { + var originalElement = element; + while (element && element.parentNode) { + var display = element.getStyle('display'); + if (display === 'none') { + return false; + } + element = $(element.parentNode); + } + return true; + } + + var hasLayout = Prototype.K; + if ('currentStyle' in document.documentElement) { + hasLayout = function(element) { + if (!element.currentStyle.hasLayout) { + element.style.zoom = 1; + } + return element; + }; + } + + function cssNameFor(key) { + if (key.include('border')) key = key + '-width'; + return key.camelize(); + } + + Element.Layout = Class.create(Hash, { + initialize: function($super, element, preCompute) { + $super(); + this.element = $(element); + + Element.Layout.PROPERTIES.each( function(property) { + this._set(property, null); + }, this); + + if (preCompute) { + this._preComputing = true; + this._begin(); + Element.Layout.PROPERTIES.each( this._compute, this ); + this._end(); + this._preComputing = false; + } + }, + + _set: function(property, value) { + return Hash.prototype.set.call(this, property, value); + }, + + set: function(property, value) { + throw "Properties of Element.Layout are read-only."; + }, + + get: function($super, property) { + var value = $super(property); + return value === null ? this._compute(property) : value; + }, + + _begin: function() { + if (this._prepared) return; + + var element = this.element; + if (isDisplayed(element)) { + this._prepared = true; + return; + } + + var originalStyles = { + position: element.style.position || '', + width: element.style.width || '', + visibility: element.style.visibility || '', + display: element.style.display || '' + }; + + element.store('prototype_original_styles', originalStyles); + + var position = element.getStyle('position'), + width = element.getStyle('width'); + + if (width === "0px" || width === null) { + element.style.display = 'block'; + width = element.getStyle('width'); + } + + var context = (position === 'fixed') ? document.viewport : + element.parentNode; + + element.setStyle({ + position: 'absolute', + visibility: 'hidden', + display: 'block' + }); + + var positionedWidth = element.getStyle('width'); + + var newWidth; + if (width && (positionedWidth === width)) { + newWidth = getPixelValue(element, 'width', context); + } else if (position === 'absolute' || position === 'fixed') { + newWidth = getPixelValue(element, 'width', context); + } else { + var parent = element.parentNode, pLayout = $(parent).getLayout(); + + newWidth = pLayout.get('width') - + this.get('margin-left') - + this.get('border-left') - + this.get('padding-left') - + this.get('padding-right') - + this.get('border-right') - + this.get('margin-right'); + } + + element.setStyle({ width: newWidth + 'px' }); + + this._prepared = true; + }, + + _end: function() { + var element = this.element; + var originalStyles = element.retrieve('prototype_original_styles'); + element.store('prototype_original_styles', null); + element.setStyle(originalStyles); + this._prepared = false; + }, + + _compute: function(property) { + var COMPUTATIONS = Element.Layout.COMPUTATIONS; + if (!(property in COMPUTATIONS)) { + throw "Property not found."; + } + + return this._set(property, COMPUTATIONS[property].call(this, this.element)); + }, + + toObject: function() { + var args = $A(arguments); + var keys = (args.length === 0) ? Element.Layout.PROPERTIES : + args.join(' ').split(' '); + var obj = {}; + keys.each( function(key) { + if (!Element.Layout.PROPERTIES.include(key)) return; + var value = this.get(key); + if (value != null) obj[key] = value; + }, this); + return obj; + }, + + toHash: function() { + var obj = this.toObject.apply(this, arguments); + return new Hash(obj); + }, + + toCSS: function() { + var args = $A(arguments); + var keys = (args.length === 0) ? Element.Layout.PROPERTIES : + args.join(' ').split(' '); + var css = {}; + + keys.each( function(key) { + if (!Element.Layout.PROPERTIES.include(key)) return; + if (Element.Layout.COMPOSITE_PROPERTIES.include(key)) return; + + var value = this.get(key); + if (value != null) css[cssNameFor(key)] = value + 'px'; + }, this); + return css; + }, + + inspect: function() { + return "#"; + } + }); + + Object.extend(Element.Layout, { + PROPERTIES: $w('height width top left right bottom border-left border-right border-top border-bottom padding-left padding-right padding-top padding-bottom margin-top margin-bottom margin-left margin-right padding-box-width padding-box-height border-box-width border-box-height margin-box-width margin-box-height'), + + COMPOSITE_PROPERTIES: $w('padding-box-width padding-box-height margin-box-width margin-box-height border-box-width border-box-height'), + + COMPUTATIONS: { + 'height': function(element) { + if (!this._preComputing) this._begin(); + + var bHeight = this.get('border-box-height'); + if (bHeight <= 0) { + if (!this._preComputing) this._end(); + return 0; + } + + var bTop = this.get('border-top'), + bBottom = this.get('border-bottom'); + + var pTop = this.get('padding-top'), + pBottom = this.get('padding-bottom'); + + if (!this._preComputing) this._end(); + + return bHeight - bTop - bBottom - pTop - pBottom; + }, + + 'width': function(element) { + if (!this._preComputing) this._begin(); + + var bWidth = this.get('border-box-width'); + if (bWidth <= 0) { + if (!this._preComputing) this._end(); + return 0; + } + + var bLeft = this.get('border-left'), + bRight = this.get('border-right'); + + var pLeft = this.get('padding-left'), + pRight = this.get('padding-right'); + + if (!this._preComputing) this._end(); + + return bWidth - bLeft - bRight - pLeft - pRight; + }, + + 'padding-box-height': function(element) { + var height = this.get('height'), + pTop = this.get('padding-top'), + pBottom = this.get('padding-bottom'); + + return height + pTop + pBottom; + }, + + 'padding-box-width': function(element) { + var width = this.get('width'), + pLeft = this.get('padding-left'), + pRight = this.get('padding-right'); + + return width + pLeft + pRight; + }, + + 'border-box-height': function(element) { + if (!this._preComputing) this._begin(); + var height = element.offsetHeight; + if (!this._preComputing) this._end(); + return height; + }, + + 'border-box-width': function(element) { + if (!this._preComputing) this._begin(); + var width = element.offsetWidth; + if (!this._preComputing) this._end(); + return width; + }, + + 'margin-box-height': function(element) { + var bHeight = this.get('border-box-height'), + mTop = this.get('margin-top'), + mBottom = this.get('margin-bottom'); + + if (bHeight <= 0) return 0; + + return bHeight + mTop + mBottom; + }, + + 'margin-box-width': function(element) { + var bWidth = this.get('border-box-width'), + mLeft = this.get('margin-left'), + mRight = this.get('margin-right'); + + if (bWidth <= 0) return 0; + + return bWidth + mLeft + mRight; + }, + + 'top': function(element) { + var offset = element.positionedOffset(); + return offset.top; + }, + + 'bottom': function(element) { + var offset = element.positionedOffset(), + parent = element.getOffsetParent(), + pHeight = parent.measure('height'); + + var mHeight = this.get('border-box-height'); + + return pHeight - mHeight - offset.top; + }, + + 'left': function(element) { + var offset = element.positionedOffset(); + return offset.left; + }, + + 'right': function(element) { + var offset = element.positionedOffset(), + parent = element.getOffsetParent(), + pWidth = parent.measure('width'); + + var mWidth = this.get('border-box-width'); + + return pWidth - mWidth - offset.left; + }, + + 'padding-top': function(element) { + return getPixelValue(element, 'paddingTop'); + }, + + 'padding-bottom': function(element) { + return getPixelValue(element, 'paddingBottom'); + }, + + 'padding-left': function(element) { + return getPixelValue(element, 'paddingLeft'); + }, + + 'padding-right': function(element) { + return getPixelValue(element, 'paddingRight'); + }, + + 'border-top': function(element) { + return getPixelValue(element, 'borderTopWidth'); + }, + + 'border-bottom': function(element) { + return getPixelValue(element, 'borderBottomWidth'); + }, + + 'border-left': function(element) { + return getPixelValue(element, 'borderLeftWidth'); + }, + + 'border-right': function(element) { + return getPixelValue(element, 'borderRightWidth'); + }, + + 'margin-top': function(element) { + return getPixelValue(element, 'marginTop'); + }, + + 'margin-bottom': function(element) { + return getPixelValue(element, 'marginBottom'); + }, + + 'margin-left': function(element) { + return getPixelValue(element, 'marginLeft'); + }, + + 'margin-right': function(element) { + return getPixelValue(element, 'marginRight'); + } + } + }); + + if ('getBoundingClientRect' in document.documentElement) { + Object.extend(Element.Layout.COMPUTATIONS, { + 'right': function(element) { + var parent = hasLayout(element.getOffsetParent()); + var rect = element.getBoundingClientRect(), + pRect = parent.getBoundingClientRect(); + + return (pRect.right - rect.right).round(); + }, + + 'bottom': function(element) { + var parent = hasLayout(element.getOffsetParent()); + var rect = element.getBoundingClientRect(), + pRect = parent.getBoundingClientRect(); + + return (pRect.bottom - rect.bottom).round(); + } + }); + } + + Element.Offset = Class.create({ + initialize: function(left, top) { + this.left = left.round(); + this.top = top.round(); + + this[0] = this.left; + this[1] = this.top; + }, + + relativeTo: function(offset) { + return new Element.Offset( + this.left - offset.left, + this.top - offset.top + ); + }, + + inspect: function() { + return "#".interpolate(this); + }, + + toString: function() { + return "[#{left}, #{top}]".interpolate(this); + }, + + toArray: function() { + return [this.left, this.top]; + } + }); + + function getLayout(element, preCompute) { + return new Element.Layout(element, preCompute); + } + + function measure(element, property) { + return $(element).getLayout().get(property); + } + + function getDimensions(element) { + element = $(element); + var display = Element.getStyle(element, 'display'); + + if (display && display !== 'none') { + return { width: element.offsetWidth, height: element.offsetHeight }; + } + + var style = element.style; + var originalStyles = { + visibility: style.visibility, + position: style.position, + display: style.display + }; + + var newStyles = { + visibility: 'hidden', + display: 'block' + }; + + if (originalStyles.position !== 'fixed') + newStyles.position = 'absolute'; + + Element.setStyle(element, newStyles); + + var dimensions = { + width: element.offsetWidth, + height: element.offsetHeight + }; + + Element.setStyle(element, originalStyles); + + return dimensions; + } + + function getOffsetParent(element) { + element = $(element); + + if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element)) + return $(document.body); + + var isInline = (Element.getStyle(element, 'display') === 'inline'); + if (!isInline && element.offsetParent) return $(element.offsetParent); + + while ((element = element.parentNode) && element !== document.body) { + if (Element.getStyle(element, 'position') !== 'static') { + return isHtml(element) ? $(document.body) : $(element); + } + } + + return $(document.body); + } + + + function cumulativeOffset(element) { + element = $(element); + var valueT = 0, valueL = 0; + if (element.parentNode) { + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + } while (element); + } + return new Element.Offset(valueL, valueT); + } + + function positionedOffset(element) { + element = $(element); + + var layout = element.getLayout(); + + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + if (element) { + if (isBody(element)) break; + var p = Element.getStyle(element, 'position'); + if (p !== 'static') break; + } + } while (element); + + valueL -= layout.get('margin-top'); + valueT -= layout.get('margin-left'); + + return new Element.Offset(valueL, valueT); + } + + function cumulativeScrollOffset(element) { + var valueT = 0, valueL = 0; + do { + valueT += element.scrollTop || 0; + valueL += element.scrollLeft || 0; + element = element.parentNode; + } while (element); + return new Element.Offset(valueL, valueT); + } + + function viewportOffset(forElement) { + element = $(element); + var valueT = 0, valueL = 0, docBody = document.body; + + var element = forElement; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + if (element.offsetParent == docBody && + Element.getStyle(element, 'position') == 'absolute') break; + } while (element = element.offsetParent); + + element = forElement; + do { + if (element != docBody) { + valueT -= element.scrollTop || 0; + valueL -= element.scrollLeft || 0; + } + } while (element = element.parentNode); + return new Element.Offset(valueL, valueT); + } + + function absolutize(element) { + element = $(element); + + if (Element.getStyle(element, 'position') === 'absolute') { + return element; + } + + var offsetParent = getOffsetParent(element); + var eOffset = element.viewportOffset(), + pOffset = offsetParent.viewportOffset(); + + var offset = eOffset.relativeTo(pOffset); + var layout = element.getLayout(); + + element.store('prototype_absolutize_original_styles', { + left: element.getStyle('left'), + top: element.getStyle('top'), + width: element.getStyle('width'), + height: element.getStyle('height') + }); + + element.setStyle({ + position: 'absolute', + top: offset.top + 'px', + left: offset.left + 'px', + width: layout.get('width') + 'px', + height: layout.get('height') + 'px' + }); + + return element; + } + + function relativize(element) { + element = $(element); + if (Element.getStyle(element, 'position') === 'relative') { + return element; + } + + var originalStyles = + element.retrieve('prototype_absolutize_original_styles'); + + if (originalStyles) element.setStyle(originalStyles); + return element; + } + + if (Prototype.Browser.IE) { + getOffsetParent = getOffsetParent.wrap( + function(proceed, element) { + element = $(element); + + if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element)) + return $(document.body); + + var position = element.getStyle('position'); + if (position !== 'static') return proceed(element); + + element.setStyle({ position: 'relative' }); + var value = proceed(element); + element.setStyle({ position: position }); + return value; + } + ); + + positionedOffset = positionedOffset.wrap(function(proceed, element) { + element = $(element); + if (!element.parentNode) return new Element.Offset(0, 0); + var position = element.getStyle('position'); + if (position !== 'static') return proceed(element); + + var offsetParent = element.getOffsetParent(); + if (offsetParent && offsetParent.getStyle('position') === 'fixed') + hasLayout(offsetParent); + + element.setStyle({ position: 'relative' }); + var value = proceed(element); + element.setStyle({ position: position }); + return value; + }); + } else if (Prototype.Browser.Webkit) { + cumulativeOffset = function(element) { + element = $(element); + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + if (element.offsetParent == document.body) + if (Element.getStyle(element, 'position') == 'absolute') break; + + element = element.offsetParent; + } while (element); + + return new Element.Offset(valueL, valueT); + }; + } + + + Element.addMethods({ + getLayout: getLayout, + measure: measure, + getDimensions: getDimensions, + getOffsetParent: getOffsetParent, + cumulativeOffset: cumulativeOffset, + positionedOffset: positionedOffset, + cumulativeScrollOffset: cumulativeScrollOffset, + viewportOffset: viewportOffset, + absolutize: absolutize, + relativize: relativize + }); + + function isBody(element) { + return element.nodeName.toUpperCase() === 'BODY'; + } + + function isHtml(element) { + return element.nodeName.toUpperCase() === 'HTML'; + } + + function isDocument(element) { + return element.nodeType === Node.DOCUMENT_NODE; + } + + function isDetached(element) { + return element !== document.body && + !Element.descendantOf(element, document.body); + } + + if ('getBoundingClientRect' in document.documentElement) { + Element.addMethods({ + viewportOffset: function(element) { + element = $(element); + if (isDetached(element)) return new Element.Offset(0, 0); + + var rect = element.getBoundingClientRect(), + docEl = document.documentElement; + return new Element.Offset(rect.left - docEl.clientLeft, + rect.top - docEl.clientTop); + } + }); + } +})(); +window.$$ = function() { + var expression = $A(arguments).join(', '); + return Prototype.Selector.select(expression, document); +}; + +Prototype.Selector = (function() { + + function select() { + throw new Error('Method "Prototype.Selector.select" must be defined.'); + } + + function match() { + throw new Error('Method "Prototype.Selector.match" must be defined.'); + } + + function find(elements, expression, index) { + index = index || 0; + var match = Prototype.Selector.match, length = elements.length, matchIndex = 0, i; + + for (i = 0; i < length; i++) { + if (match(elements[i], expression) && index == matchIndex++) { + return Element.extend(elements[i]); + } + } + } + + function extendElements(elements) { + for (var i = 0, length = elements.length; i < length; i++) { + Element.extend(elements[i]); + } + return elements; + } + + + var K = Prototype.K; + + return { + select: select, + match: match, + find: find, + extendElements: (Element.extend === K) ? K : extendElements, + extendElement: Element.extend + }; +})(); +Prototype._original_property = window.Sizzle; +/*! + * Sizzle CSS Selector Engine - v1.0 + * Copyright 2009, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){ + +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, + done = 0, + toString = Object.prototype.toString, + hasDuplicate = false, + baseHasDuplicate = true; + +[0, 0].sort(function(){ + baseHasDuplicate = false; + return 0; +}); + +var Sizzle = function(selector, context, results, seed) { + results = results || []; + var origContext = context = context || document; + + if ( context.nodeType !== 1 && context.nodeType !== 9 ) { + return []; + } + + if ( !selector || typeof selector !== "string" ) { + return results; + } + + var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context), + soFar = selector; + + while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) { + soFar = m[3]; + + parts.push( m[1] ); + + if ( m[2] ) { + extra = m[3]; + break; + } + } + + if ( parts.length > 1 && origPOS.exec( selector ) ) { + if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { + set = posProcess( parts[0] + parts[1], context ); + } else { + set = Expr.relative[ parts[0] ] ? + [ context ] : + Sizzle( parts.shift(), context ); + + while ( parts.length ) { + selector = parts.shift(); + + if ( Expr.relative[ selector ] ) + selector += parts.shift(); + + set = posProcess( selector, set ); + } + } + } else { + if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && + Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { + var ret = Sizzle.find( parts.shift(), context, contextXML ); + context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; + } + + if ( context ) { + var ret = seed ? + { expr: parts.pop(), set: makeArray(seed) } : + Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); + set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set; + + if ( parts.length > 0 ) { + checkSet = makeArray(set); + } else { + prune = false; + } + + while ( parts.length ) { + var cur = parts.pop(), pop = cur; + + if ( !Expr.relative[ cur ] ) { + cur = ""; + } else { + pop = parts.pop(); + } + + if ( pop == null ) { + pop = context; + } + + Expr.relative[ cur ]( checkSet, pop, contextXML ); + } + } else { + checkSet = parts = []; + } + } + + if ( !checkSet ) { + checkSet = set; + } + + if ( !checkSet ) { + throw "Syntax error, unrecognized expression: " + (cur || selector); + } + + if ( toString.call(checkSet) === "[object Array]" ) { + if ( !prune ) { + results.push.apply( results, checkSet ); + } else if ( context && context.nodeType === 1 ) { + for ( var i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { + results.push( set[i] ); + } + } + } else { + for ( var i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && checkSet[i].nodeType === 1 ) { + results.push( set[i] ); + } + } + } + } else { + makeArray( checkSet, results ); + } + + if ( extra ) { + Sizzle( extra, origContext, results, seed ); + Sizzle.uniqueSort( results ); + } + + return results; +}; + +Sizzle.uniqueSort = function(results){ + if ( sortOrder ) { + hasDuplicate = baseHasDuplicate; + results.sort(sortOrder); + + if ( hasDuplicate ) { + for ( var i = 1; i < results.length; i++ ) { + if ( results[i] === results[i-1] ) { + results.splice(i--, 1); + } + } + } + } + + return results; +}; + +Sizzle.matches = function(expr, set){ + return Sizzle(expr, null, null, set); +}; + +Sizzle.find = function(expr, context, isXML){ + var set, match; + + if ( !expr ) { + return []; + } + + for ( var i = 0, l = Expr.order.length; i < l; i++ ) { + var type = Expr.order[i], match; + + if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { + var left = match[1]; + match.splice(1,1); + + if ( left.substr( left.length - 1 ) !== "\\" ) { + match[1] = (match[1] || "").replace(/\\/g, ""); + set = Expr.find[ type ]( match, context, isXML ); + if ( set != null ) { + expr = expr.replace( Expr.match[ type ], "" ); + break; + } + } + } + } + + if ( !set ) { + set = context.getElementsByTagName("*"); + } + + return {set: set, expr: expr}; +}; + +Sizzle.filter = function(expr, set, inplace, not){ + var old = expr, result = [], curLoop = set, match, anyFound, + isXMLFilter = set && set[0] && isXML(set[0]); + + while ( expr && set.length ) { + for ( var type in Expr.filter ) { + if ( (match = Expr.match[ type ].exec( expr )) != null ) { + var filter = Expr.filter[ type ], found, item; + anyFound = false; + + if ( curLoop == result ) { + result = []; + } + + if ( Expr.preFilter[ type ] ) { + match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); + + if ( !match ) { + anyFound = found = true; + } else if ( match === true ) { + continue; + } + } + + if ( match ) { + for ( var i = 0; (item = curLoop[i]) != null; i++ ) { + if ( item ) { + found = filter( item, match, i, curLoop ); + var pass = not ^ !!found; + + if ( inplace && found != null ) { + if ( pass ) { + anyFound = true; + } else { + curLoop[i] = false; + } + } else if ( pass ) { + result.push( item ); + anyFound = true; + } + } + } + } + + if ( found !== undefined ) { + if ( !inplace ) { + curLoop = result; + } + + expr = expr.replace( Expr.match[ type ], "" ); + + if ( !anyFound ) { + return []; + } + + break; + } + } + } + + if ( expr == old ) { + if ( anyFound == null ) { + throw "Syntax error, unrecognized expression: " + expr; + } else { + break; + } + } + + old = expr; + } + + return curLoop; +}; + +var Expr = Sizzle.selectors = { + order: [ "ID", "NAME", "TAG" ], + match: { + ID: /#((?:[\w\u00c0-\uFFFF-]|\\.)+)/, + CLASS: /\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/, + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/, + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, + TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/, + CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/, + PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/ + }, + leftMatch: {}, + attrMap: { + "class": "className", + "for": "htmlFor" + }, + attrHandle: { + href: function(elem){ + return elem.getAttribute("href"); + } + }, + relative: { + "+": function(checkSet, part, isXML){ + var isPartStr = typeof part === "string", + isTag = isPartStr && !/\W/.test(part), + isPartStrNotTag = isPartStr && !isTag; + + if ( isTag && !isXML ) { + part = part.toUpperCase(); + } + + for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { + if ( (elem = checkSet[i]) ) { + while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} + + checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ? + elem || false : + elem === part; + } + } + + if ( isPartStrNotTag ) { + Sizzle.filter( part, checkSet, true ); + } + }, + ">": function(checkSet, part, isXML){ + var isPartStr = typeof part === "string"; + + if ( isPartStr && !/\W/.test(part) ) { + part = isXML ? part : part.toUpperCase(); + + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + var parent = elem.parentNode; + checkSet[i] = parent.nodeName === part ? parent : false; + } + } + } else { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + checkSet[i] = isPartStr ? + elem.parentNode : + elem.parentNode === part; + } + } + + if ( isPartStr ) { + Sizzle.filter( part, checkSet, true ); + } + } + }, + "": function(checkSet, part, isXML){ + var doneName = done++, checkFn = dirCheck; + + if ( !/\W/.test(part) ) { + var nodeCheck = part = isXML ? part : part.toUpperCase(); + checkFn = dirNodeCheck; + } + + checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); + }, + "~": function(checkSet, part, isXML){ + var doneName = done++, checkFn = dirCheck; + + if ( typeof part === "string" && !/\W/.test(part) ) { + var nodeCheck = part = isXML ? part : part.toUpperCase(); + checkFn = dirNodeCheck; + } + + checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML); + } + }, + find: { + ID: function(match, context, isXML){ + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + return m ? [m] : []; + } + }, + NAME: function(match, context, isXML){ + if ( typeof context.getElementsByName !== "undefined" ) { + var ret = [], results = context.getElementsByName(match[1]); + + for ( var i = 0, l = results.length; i < l; i++ ) { + if ( results[i].getAttribute("name") === match[1] ) { + ret.push( results[i] ); + } + } + + return ret.length === 0 ? null : ret; + } + }, + TAG: function(match, context){ + return context.getElementsByTagName(match[1]); + } + }, + preFilter: { + CLASS: function(match, curLoop, inplace, result, not, isXML){ + match = " " + match[1].replace(/\\/g, "") + " "; + + if ( isXML ) { + return match; + } + + for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { + if ( elem ) { + if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) { + if ( !inplace ) + result.push( elem ); + } else if ( inplace ) { + curLoop[i] = false; + } + } + } + + return false; + }, + ID: function(match){ + return match[1].replace(/\\/g, ""); + }, + TAG: function(match, curLoop){ + for ( var i = 0; curLoop[i] === false; i++ ){} + return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase(); + }, + CHILD: function(match){ + if ( match[1] == "nth" ) { + var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( + match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" || + !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); + + match[2] = (test[1] + (test[2] || 1)) - 0; + match[3] = test[3] - 0; + } + + match[0] = done++; + + return match; + }, + ATTR: function(match, curLoop, inplace, result, not, isXML){ + var name = match[1].replace(/\\/g, ""); + + if ( !isXML && Expr.attrMap[name] ) { + match[1] = Expr.attrMap[name]; + } + + if ( match[2] === "~=" ) { + match[4] = " " + match[4] + " "; + } + + return match; + }, + PSEUDO: function(match, curLoop, inplace, result, not){ + if ( match[1] === "not" ) { + if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { + match[3] = Sizzle(match[3], null, null, curLoop); + } else { + var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); + if ( !inplace ) { + result.push.apply( result, ret ); + } + return false; + } + } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { + return true; + } + + return match; + }, + POS: function(match){ + match.unshift( true ); + return match; + } + }, + filters: { + enabled: function(elem){ + return elem.disabled === false && elem.type !== "hidden"; + }, + disabled: function(elem){ + return elem.disabled === true; + }, + checked: function(elem){ + return elem.checked === true; + }, + selected: function(elem){ + elem.parentNode.selectedIndex; + return elem.selected === true; + }, + parent: function(elem){ + return !!elem.firstChild; + }, + empty: function(elem){ + return !elem.firstChild; + }, + has: function(elem, i, match){ + return !!Sizzle( match[3], elem ).length; + }, + header: function(elem){ + return /h\d/i.test( elem.nodeName ); + }, + text: function(elem){ + return "text" === elem.type; + }, + radio: function(elem){ + return "radio" === elem.type; + }, + checkbox: function(elem){ + return "checkbox" === elem.type; + }, + file: function(elem){ + return "file" === elem.type; + }, + password: function(elem){ + return "password" === elem.type; + }, + submit: function(elem){ + return "submit" === elem.type; + }, + image: function(elem){ + return "image" === elem.type; + }, + reset: function(elem){ + return "reset" === elem.type; + }, + button: function(elem){ + return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON"; + }, + input: function(elem){ + return /input|select|textarea|button/i.test(elem.nodeName); + } + }, + setFilters: { + first: function(elem, i){ + return i === 0; + }, + last: function(elem, i, match, array){ + return i === array.length - 1; + }, + even: function(elem, i){ + return i % 2 === 0; + }, + odd: function(elem, i){ + return i % 2 === 1; + }, + lt: function(elem, i, match){ + return i < match[3] - 0; + }, + gt: function(elem, i, match){ + return i > match[3] - 0; + }, + nth: function(elem, i, match){ + return match[3] - 0 == i; + }, + eq: function(elem, i, match){ + return match[3] - 0 == i; + } + }, + filter: { + PSEUDO: function(elem, match, i, array){ + var name = match[1], filter = Expr.filters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } else if ( name === "contains" ) { + return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0; + } else if ( name === "not" ) { + var not = match[3]; + + for ( var i = 0, l = not.length; i < l; i++ ) { + if ( not[i] === elem ) { + return false; + } + } + + return true; + } + }, + CHILD: function(elem, match){ + var type = match[1], node = elem; + switch (type) { + case 'only': + case 'first': + while ( (node = node.previousSibling) ) { + if ( node.nodeType === 1 ) return false; + } + if ( type == 'first') return true; + node = elem; + case 'last': + while ( (node = node.nextSibling) ) { + if ( node.nodeType === 1 ) return false; + } + return true; + case 'nth': + var first = match[2], last = match[3]; + + if ( first == 1 && last == 0 ) { + return true; + } + + var doneName = match[0], + parent = elem.parentNode; + + if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { + var count = 0; + for ( node = parent.firstChild; node; node = node.nextSibling ) { + if ( node.nodeType === 1 ) { + node.nodeIndex = ++count; + } + } + parent.sizcache = doneName; + } + + var diff = elem.nodeIndex - last; + if ( first == 0 ) { + return diff == 0; + } else { + return ( diff % first == 0 && diff / first >= 0 ); + } + } + }, + ID: function(elem, match){ + return elem.nodeType === 1 && elem.getAttribute("id") === match; + }, + TAG: function(elem, match){ + return (match === "*" && elem.nodeType === 1) || elem.nodeName === match; + }, + CLASS: function(elem, match){ + return (" " + (elem.className || elem.getAttribute("class")) + " ") + .indexOf( match ) > -1; + }, + ATTR: function(elem, match){ + var name = match[1], + result = Expr.attrHandle[ name ] ? + Expr.attrHandle[ name ]( elem ) : + elem[ name ] != null ? + elem[ name ] : + elem.getAttribute( name ), + value = result + "", + type = match[2], + check = match[4]; + + return result == null ? + type === "!=" : + type === "=" ? + value === check : + type === "*=" ? + value.indexOf(check) >= 0 : + type === "~=" ? + (" " + value + " ").indexOf(check) >= 0 : + !check ? + value && result !== false : + type === "!=" ? + value != check : + type === "^=" ? + value.indexOf(check) === 0 : + type === "$=" ? + value.substr(value.length - check.length) === check : + type === "|=" ? + value === check || value.substr(0, check.length + 1) === check + "-" : + false; + }, + POS: function(elem, match, i, array){ + var name = match[2], filter = Expr.setFilters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } + } + } +}; + +var origPOS = Expr.match.POS; + +for ( var type in Expr.match ) { + Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); + Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source ); +} + +var makeArray = function(array, results) { + array = Array.prototype.slice.call( array, 0 ); + + if ( results ) { + results.push.apply( results, array ); + return results; + } + + return array; +}; + +try { + Array.prototype.slice.call( document.documentElement.childNodes, 0 ); + +} catch(e){ + makeArray = function(array, results) { + var ret = results || []; + + if ( toString.call(array) === "[object Array]" ) { + Array.prototype.push.apply( ret, array ); + } else { + if ( typeof array.length === "number" ) { + for ( var i = 0, l = array.length; i < l; i++ ) { + ret.push( array[i] ); + } + } else { + for ( var i = 0; array[i]; i++ ) { + ret.push( array[i] ); + } + } + } + + return ret; + }; +} + +var sortOrder; + +if ( document.documentElement.compareDocumentPosition ) { + sortOrder = function( a, b ) { + if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { + if ( a == b ) { + hasDuplicate = true; + } + return 0; + } + + var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; + if ( ret === 0 ) { + hasDuplicate = true; + } + return ret; + }; +} else if ( "sourceIndex" in document.documentElement ) { + sortOrder = function( a, b ) { + if ( !a.sourceIndex || !b.sourceIndex ) { + if ( a == b ) { + hasDuplicate = true; + } + return 0; + } + + var ret = a.sourceIndex - b.sourceIndex; + if ( ret === 0 ) { + hasDuplicate = true; + } + return ret; + }; +} else if ( document.createRange ) { + sortOrder = function( a, b ) { + if ( !a.ownerDocument || !b.ownerDocument ) { + if ( a == b ) { + hasDuplicate = true; + } + return 0; + } + + var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); + aRange.setStart(a, 0); + aRange.setEnd(a, 0); + bRange.setStart(b, 0); + bRange.setEnd(b, 0); + var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange); + if ( ret === 0 ) { + hasDuplicate = true; + } + return ret; + }; +} + +(function(){ + var form = document.createElement("div"), + id = "script" + (new Date).getTime(); + form.innerHTML = ""; + + var root = document.documentElement; + root.insertBefore( form, root.firstChild ); + + if ( !!document.getElementById( id ) ) { + Expr.find.ID = function(match, context, isXML){ + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : []; + } + }; + + Expr.filter.ID = function(elem, match){ + var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); + return elem.nodeType === 1 && node && node.nodeValue === match; + }; + } + + root.removeChild( form ); + root = form = null; // release memory in IE +})(); + +(function(){ + + var div = document.createElement("div"); + div.appendChild( document.createComment("") ); + + if ( div.getElementsByTagName("*").length > 0 ) { + Expr.find.TAG = function(match, context){ + var results = context.getElementsByTagName(match[1]); + + if ( match[1] === "*" ) { + var tmp = []; + + for ( var i = 0; results[i]; i++ ) { + if ( results[i].nodeType === 1 ) { + tmp.push( results[i] ); + } + } + + results = tmp; + } + + return results; + }; + } + + div.innerHTML = ""; + if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && + div.firstChild.getAttribute("href") !== "#" ) { + Expr.attrHandle.href = function(elem){ + return elem.getAttribute("href", 2); + }; + } + + div = null; // release memory in IE +})(); + +if ( document.querySelectorAll ) (function(){ + var oldSizzle = Sizzle, div = document.createElement("div"); + div.innerHTML = "

"; + + if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { + return; + } + + Sizzle = function(query, context, extra, seed){ + context = context || document; + + if ( !seed && context.nodeType === 9 && !isXML(context) ) { + try { + return makeArray( context.querySelectorAll(query), extra ); + } catch(e){} + } + + return oldSizzle(query, context, extra, seed); + }; + + for ( var prop in oldSizzle ) { + Sizzle[ prop ] = oldSizzle[ prop ]; + } + + div = null; // release memory in IE +})(); + +if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){ + var div = document.createElement("div"); + div.innerHTML = "
"; + + if ( div.getElementsByClassName("e").length === 0 ) + return; + + div.lastChild.className = "e"; + + if ( div.getElementsByClassName("e").length === 1 ) + return; + + Expr.order.splice(1, 0, "CLASS"); + Expr.find.CLASS = function(match, context, isXML) { + if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { + return context.getElementsByClassName(match[1]); + } + }; + + div = null; // release memory in IE +})(); + +function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + var sibDir = dir == "previousSibling" && !isXML; + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + if ( sibDir && elem.nodeType === 1 ){ + elem.sizcache = doneName; + elem.sizset = i; + } + elem = elem[dir]; + var match = false; + + while ( elem ) { + if ( elem.sizcache === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 && !isXML ){ + elem.sizcache = doneName; + elem.sizset = i; + } + + if ( elem.nodeName === cur ) { + match = elem; + break; + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + var sibDir = dir == "previousSibling" && !isXML; + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + if ( sibDir && elem.nodeType === 1 ) { + elem.sizcache = doneName; + elem.sizset = i; + } + elem = elem[dir]; + var match = false; + + while ( elem ) { + if ( elem.sizcache === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 ) { + if ( !isXML ) { + elem.sizcache = doneName; + elem.sizset = i; + } + if ( typeof cur !== "string" ) { + if ( elem === cur ) { + match = true; + break; + } + + } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { + match = elem; + break; + } + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +var contains = document.compareDocumentPosition ? function(a, b){ + return a.compareDocumentPosition(b) & 16; +} : function(a, b){ + return a !== b && (a.contains ? a.contains(b) : true); +}; + +var isXML = function(elem){ + return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || + !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; +}; + +var posProcess = function(selector, context){ + var tmpSet = [], later = "", match, + root = context.nodeType ? [context] : context; + + while ( (match = Expr.match.PSEUDO.exec( selector )) ) { + later += match[0]; + selector = selector.replace( Expr.match.PSEUDO, "" ); + } + + selector = Expr.relative[selector] ? selector + "*" : selector; + + for ( var i = 0, l = root.length; i < l; i++ ) { + Sizzle( selector, root[i], tmpSet ); + } + + return Sizzle.filter( later, tmpSet ); +}; + + +window.Sizzle = Sizzle; + +})(); + +;(function(engine) { + var extendElements = Prototype.Selector.extendElements; + + function select(selector, scope) { + return extendElements(engine(selector, scope || document)); + } + + function match(element, selector) { + return engine.matches(selector, [element]).length == 1; + } + + Prototype.Selector.engine = engine; + Prototype.Selector.select = select; + Prototype.Selector.match = match; +})(Sizzle); + +window.Sizzle = Prototype._original_property; +delete Prototype._original_property; + +var Form = { + reset: function(form) { + form = $(form); + form.reset(); + return form; + }, + + serializeElements: function(elements, options) { + if (typeof options != 'object') options = { hash: !!options }; + else if (Object.isUndefined(options.hash)) options.hash = true; + var key, value, submitted = false, submit = options.submit, accumulator, initial; + + if (options.hash) { + initial = {}; + accumulator = function(result, key, value) { + if (key in result) { + if (!Object.isArray(result[key])) result[key] = [result[key]]; + result[key].push(value); + } else result[key] = value; + return result; + }; + } else { + initial = ''; + accumulator = function(result, key, value) { + return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + encodeURIComponent(value); + } + } + + return elements.inject(initial, function(result, element) { + if (!element.disabled && element.name) { + key = element.name; value = $(element).getValue(); + if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted && + submit !== false && (!submit || key == submit) && (submitted = true)))) { + result = accumulator(result, key, value); + } + } + return result; + }); + } +}; + +Form.Methods = { + serialize: function(form, options) { + return Form.serializeElements(Form.getElements(form), options); + }, + + getElements: function(form) { + var elements = $(form).getElementsByTagName('*'), + element, + arr = [ ], + serializers = Form.Element.Serializers; + for (var i = 0; element = elements[i]; i++) { + arr.push(element); + } + return arr.inject([], function(elements, child) { + if (serializers[child.tagName.toLowerCase()]) + elements.push(Element.extend(child)); + return elements; + }) + }, + + getInputs: function(form, typeName, name) { + form = $(form); + var inputs = form.getElementsByTagName('input'); + + if (!typeName && !name) return $A(inputs).map(Element.extend); + + for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) { + var input = inputs[i]; + if ((typeName && input.type != typeName) || (name && input.name != name)) + continue; + matchingInputs.push(Element.extend(input)); + } + + return matchingInputs; + }, + + disable: function(form) { + form = $(form); + Form.getElements(form).invoke('disable'); + return form; + }, + + enable: function(form) { + form = $(form); + Form.getElements(form).invoke('enable'); + return form; + }, + + findFirstElement: function(form) { + var elements = $(form).getElements().findAll(function(element) { + return 'hidden' != element.type && !element.disabled; + }); + var firstByIndex = elements.findAll(function(element) { + return element.hasAttribute('tabIndex') && element.tabIndex >= 0; + }).sortBy(function(element) { return element.tabIndex }).first(); + + return firstByIndex ? firstByIndex : elements.find(function(element) { + return /^(?:input|select|textarea)$/i.test(element.tagName); + }); + }, + + focusFirstElement: function(form) { + form = $(form); + var element = form.findFirstElement(); + if (element) element.activate(); + return form; + }, + + request: function(form, options) { + form = $(form), options = Object.clone(options || { }); + + var params = options.parameters, action = form.readAttribute('action') || ''; + if (action.blank()) action = window.location.href; + options.parameters = form.serialize(true); + + if (params) { + if (Object.isString(params)) params = params.toQueryParams(); + Object.extend(options.parameters, params); + } + + if (form.hasAttribute('method') && !options.method) + options.method = form.method; + + return new Ajax.Request(action, options); + } +}; + +/*--------------------------------------------------------------------------*/ + + +Form.Element = { + focus: function(element) { + $(element).focus(); + return element; + }, + + select: function(element) { + $(element).select(); + return element; + } +}; + +Form.Element.Methods = { + + serialize: function(element) { + element = $(element); + if (!element.disabled && element.name) { + var value = element.getValue(); + if (value != undefined) { + var pair = { }; + pair[element.name] = value; + return Object.toQueryString(pair); + } + } + return ''; + }, + + getValue: function(element) { + element = $(element); + var method = element.tagName.toLowerCase(); + return Form.Element.Serializers[method](element); + }, + + setValue: function(element, value) { + element = $(element); + var method = element.tagName.toLowerCase(); + Form.Element.Serializers[method](element, value); + return element; + }, + + clear: function(element) { + $(element).value = ''; + return element; + }, + + present: function(element) { + return $(element).value != ''; + }, + + activate: function(element) { + element = $(element); + try { + element.focus(); + if (element.select && (element.tagName.toLowerCase() != 'input' || + !(/^(?:button|reset|submit)$/i.test(element.type)))) + element.select(); + } catch (e) { } + return element; + }, + + disable: function(element) { + element = $(element); + element.disabled = true; + return element; + }, + + enable: function(element) { + element = $(element); + element.disabled = false; + return element; + } +}; + +/*--------------------------------------------------------------------------*/ + +var Field = Form.Element; + +var $F = Form.Element.Methods.getValue; + +/*--------------------------------------------------------------------------*/ + +Form.Element.Serializers = (function() { + function input(element, value) { + switch (element.type.toLowerCase()) { + case 'checkbox': + case 'radio': + return inputSelector(element, value); + default: + return valueSelector(element, value); + } + } + + function inputSelector(element, value) { + if (Object.isUndefined(value)) + return element.checked ? element.value : null; + else element.checked = !!value; + } + + function valueSelector(element, value) { + if (Object.isUndefined(value)) return element.value; + else element.value = value; + } + + function select(element, value) { + if (Object.isUndefined(value)) + return (element.type === 'select-one' ? selectOne : selectMany)(element); + + var opt, currentValue, single = !Object.isArray(value); + for (var i = 0, length = element.length; i < length; i++) { + opt = element.options[i]; + currentValue = this.optionValue(opt); + if (single) { + if (currentValue == value) { + opt.selected = true; + return; + } + } + else opt.selected = value.include(currentValue); + } + } + + function selectOne(element) { + var index = element.selectedIndex; + return index >= 0 ? optionValue(element.options[index]) : null; + } + + function selectMany(element) { + var values, length = element.length; + if (!length) return null; + + for (var i = 0, values = []; i < length; i++) { + var opt = element.options[i]; + if (opt.selected) values.push(optionValue(opt)); + } + return values; + } + + function optionValue(opt) { + return Element.hasAttribute(opt, 'value') ? opt.value : opt.text; + } + + return { + input: input, + inputSelector: inputSelector, + textarea: valueSelector, + select: select, + selectOne: selectOne, + selectMany: selectMany, + optionValue: optionValue, + button: valueSelector + }; +})(); + +/*--------------------------------------------------------------------------*/ + + +Abstract.TimedObserver = Class.create(PeriodicalExecuter, { + initialize: function($super, element, frequency, callback) { + $super(callback, frequency); + this.element = $(element); + this.lastValue = this.getValue(); + }, + + execute: function() { + var value = this.getValue(); + if (Object.isString(this.lastValue) && Object.isString(value) ? + this.lastValue != value : String(this.lastValue) != String(value)) { + this.callback(this.element, value); + this.lastValue = value; + } + } +}); + +Form.Element.Observer = Class.create(Abstract.TimedObserver, { + getValue: function() { + return Form.Element.getValue(this.element); + } +}); + +Form.Observer = Class.create(Abstract.TimedObserver, { + getValue: function() { + return Form.serialize(this.element); + } +}); + +/*--------------------------------------------------------------------------*/ + +Abstract.EventObserver = Class.create({ + initialize: function(element, callback) { + this.element = $(element); + this.callback = callback; + + this.lastValue = this.getValue(); + if (this.element.tagName.toLowerCase() == 'form') + this.registerFormCallbacks(); + else + this.registerCallback(this.element); + }, + + onElementEvent: function() { + var value = this.getValue(); + if (this.lastValue != value) { + this.callback(this.element, value); + this.lastValue = value; + } + }, + + registerFormCallbacks: function() { + Form.getElements(this.element).each(this.registerCallback, this); + }, + + registerCallback: function(element) { + if (element.type) { + switch (element.type.toLowerCase()) { + case 'checkbox': + case 'radio': + Event.observe(element, 'click', this.onElementEvent.bind(this)); + break; + default: + Event.observe(element, 'change', this.onElementEvent.bind(this)); + break; + } + } + } +}); + +Form.Element.EventObserver = Class.create(Abstract.EventObserver, { + getValue: function() { + return Form.Element.getValue(this.element); + } +}); + +Form.EventObserver = Class.create(Abstract.EventObserver, { + getValue: function() { + return Form.serialize(this.element); + } +}); +(function() { + + var Event = { + KEY_BACKSPACE: 8, + KEY_TAB: 9, + KEY_RETURN: 13, + KEY_ESC: 27, + KEY_LEFT: 37, + KEY_UP: 38, + KEY_RIGHT: 39, + KEY_DOWN: 40, + KEY_DELETE: 46, + KEY_HOME: 36, + KEY_END: 35, + KEY_PAGEUP: 33, + KEY_PAGEDOWN: 34, + KEY_INSERT: 45, + + cache: {} + }; + + var docEl = document.documentElement; + var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl + && 'onmouseleave' in docEl; + + + + var isIELegacyEvent = function(event) { return false; }; + + if (window.attachEvent) { + if (window.addEventListener) { + isIELegacyEvent = function(event) { + return !(event instanceof window.Event); + }; + } else { + isIELegacyEvent = function(event) { return true; }; + } + } + + var _isButton; + + function _isButtonForDOMEvents(event, code) { + return event.which ? (event.which === code + 1) : (event.button === code); + } + + var legacyButtonMap = { 0: 1, 1: 4, 2: 2 }; + function _isButtonForLegacyEvents(event, code) { + return event.button === legacyButtonMap[code]; + } + + function _isButtonForWebKit(event, code) { + switch (code) { + case 0: return event.which == 1 && !event.metaKey; + case 1: return event.which == 2 || (event.which == 1 && event.metaKey); + case 2: return event.which == 3; + default: return false; + } + } + + if (window.attachEvent) { + if (!window.addEventListener) { + _isButton = _isButtonForLegacyEvents; + } else { + _isButton = function(event, code) { + return isIELegacyEvent(event) ? _isButtonForLegacyEvents(event, code) : + _isButtonForDOMEvents(event, code); + } + } + } else if (Prototype.Browser.WebKit) { + _isButton = _isButtonForWebKit; + } else { + _isButton = _isButtonForDOMEvents; + } + + function isLeftClick(event) { return _isButton(event, 0) } + + function isMiddleClick(event) { return _isButton(event, 1) } + + function isRightClick(event) { return _isButton(event, 2) } + + function element(event) { + event = Event.extend(event); + + var node = event.target, type = event.type, + currentTarget = event.currentTarget; + + if (currentTarget && currentTarget.tagName) { + if (type === 'load' || type === 'error' || + (type === 'click' && currentTarget.tagName.toLowerCase() === 'input' + && currentTarget.type === 'radio')) + node = currentTarget; + } + + if (node.nodeType == Node.TEXT_NODE) + node = node.parentNode; + + return Element.extend(node); + } + + function findElement(event, expression) { + var element = Event.element(event); + + if (!expression) return element; + while (element) { + if (Object.isElement(element) && Prototype.Selector.match(element, expression)) { + return Element.extend(element); + } + element = element.parentNode; + } + } + + function pointer(event) { + return { x: pointerX(event), y: pointerY(event) }; + } + + function pointerX(event) { + var docElement = document.documentElement, + body = document.body || { scrollLeft: 0 }; + + return event.pageX || (event.clientX + + (docElement.scrollLeft || body.scrollLeft) - + (docElement.clientLeft || 0)); + } + + function pointerY(event) { + var docElement = document.documentElement, + body = document.body || { scrollTop: 0 }; + + return event.pageY || (event.clientY + + (docElement.scrollTop || body.scrollTop) - + (docElement.clientTop || 0)); + } + + + function stop(event) { + Event.extend(event); + event.preventDefault(); + event.stopPropagation(); + + event.stopped = true; + } + + + Event.Methods = { + isLeftClick: isLeftClick, + isMiddleClick: isMiddleClick, + isRightClick: isRightClick, + + element: element, + findElement: findElement, + + pointer: pointer, + pointerX: pointerX, + pointerY: pointerY, + + stop: stop + }; + + var methods = Object.keys(Event.Methods).inject({ }, function(m, name) { + m[name] = Event.Methods[name].methodize(); + return m; + }); + + if (window.attachEvent) { + function _relatedTarget(event) { + var element; + switch (event.type) { + case 'mouseover': + case 'mouseenter': + element = event.fromElement; + break; + case 'mouseout': + case 'mouseleave': + element = event.toElement; + break; + default: + return null; + } + return Element.extend(element); + } + + var additionalMethods = { + stopPropagation: function() { this.cancelBubble = true }, + preventDefault: function() { this.returnValue = false }, + inspect: function() { return '[object Event]' } + }; + + Event.extend = function(event, element) { + if (!event) return false; + + if (!isIELegacyEvent(event)) return event; + + if (event._extendedByPrototype) return event; + event._extendedByPrototype = Prototype.emptyFunction; + + var pointer = Event.pointer(event); + + Object.extend(event, { + target: event.srcElement || element, + relatedTarget: _relatedTarget(event), + pageX: pointer.x, + pageY: pointer.y + }); + + Object.extend(event, methods); + Object.extend(event, additionalMethods); + + return event; + }; + } else { + Event.extend = Prototype.K; + } + + if (window.addEventListener) { + Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__; + Object.extend(Event.prototype, methods); + } + + function _createResponder(element, eventName, handler) { + var registry = Element.retrieve(element, 'prototype_event_registry'); + + if (Object.isUndefined(registry)) { + CACHE.push(element); + registry = Element.retrieve(element, 'prototype_event_registry', $H()); + } + + var respondersForEvent = registry.get(eventName); + if (Object.isUndefined(respondersForEvent)) { + respondersForEvent = []; + registry.set(eventName, respondersForEvent); + } + + if (respondersForEvent.pluck('handler').include(handler)) return false; + + var responder; + if (eventName.include(":")) { + responder = function(event) { + if (Object.isUndefined(event.eventName)) + return false; + + if (event.eventName !== eventName) + return false; + + Event.extend(event, element); + handler.call(element, event); + }; + } else { + if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED && + (eventName === "mouseenter" || eventName === "mouseleave")) { + if (eventName === "mouseenter" || eventName === "mouseleave") { + responder = function(event) { + Event.extend(event, element); + + var parent = event.relatedTarget; + while (parent && parent !== element) { + try { parent = parent.parentNode; } + catch(e) { parent = element; } + } + + if (parent === element) return; + + handler.call(element, event); + }; + } + } else { + responder = function(event) { + Event.extend(event, element); + handler.call(element, event); + }; + } + } + + responder.handler = handler; + respondersForEvent.push(responder); + return responder; + } + + function _destroyCache() { + for (var i = 0, length = CACHE.length; i < length; i++) { + Event.stopObserving(CACHE[i]); + CACHE[i] = null; + } + } + + var CACHE = []; + + if (Prototype.Browser.IE) + window.attachEvent('onunload', _destroyCache); + + if (Prototype.Browser.WebKit) + window.addEventListener('unload', Prototype.emptyFunction, false); + + + var _getDOMEventName = Prototype.K, + translations = { mouseenter: "mouseover", mouseleave: "mouseout" }; + + if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED) { + _getDOMEventName = function(eventName) { + return (translations[eventName] || eventName); + }; + } + + function observe(element, eventName, handler) { + element = $(element); + + var responder = _createResponder(element, eventName, handler); + + if (!responder) return element; + + if (eventName.include(':')) { + if (element.addEventListener) + element.addEventListener("dataavailable", responder, false); + else { + element.attachEvent("ondataavailable", responder); + element.attachEvent("onlosecapture", responder); + } + } else { + var actualEventName = _getDOMEventName(eventName); + + if (element.addEventListener) + element.addEventListener(actualEventName, responder, false); + else + element.attachEvent("on" + actualEventName, responder); + } + + return element; + } + + function stopObserving(element, eventName, handler) { + element = $(element); + + var registry = Element.retrieve(element, 'prototype_event_registry'); + if (!registry) return element; + + if (!eventName) { + registry.each( function(pair) { + var eventName = pair.key; + stopObserving(element, eventName); + }); + return element; + } + + var responders = registry.get(eventName); + if (!responders) return element; + + if (!handler) { + responders.each(function(r) { + stopObserving(element, eventName, r.handler); + }); + return element; + } + + var i = responders.length, responder; + while (i--) { + if (responders[i].handler === handler) { + responder = responders[i]; + break; + } + } + if (!responder) return element; + + if (eventName.include(':')) { + if (element.removeEventListener) + element.removeEventListener("dataavailable", responder, false); + else { + element.detachEvent("ondataavailable", responder); + element.detachEvent("onlosecapture", responder); + } + } else { + var actualEventName = _getDOMEventName(eventName); + if (element.removeEventListener) + element.removeEventListener(actualEventName, responder, false); + else + element.detachEvent('on' + actualEventName, responder); + } + + registry.set(eventName, responders.without(responder)); + + return element; + } + + function fire(element, eventName, memo, bubble) { + element = $(element); + + if (Object.isUndefined(bubble)) + bubble = true; + + if (element == document && document.createEvent && !element.dispatchEvent) + element = document.documentElement; + + var event; + if (document.createEvent) { + event = document.createEvent('HTMLEvents'); + event.initEvent('dataavailable', bubble, true); + } else { + event = document.createEventObject(); + event.eventType = bubble ? 'ondataavailable' : 'onlosecapture'; + } + + event.eventName = eventName; + event.memo = memo || { }; + + if (document.createEvent) + element.dispatchEvent(event); + else + element.fireEvent(event.eventType, event); + + return Event.extend(event); + } + + Event.Handler = Class.create({ + initialize: function(element, eventName, selector, callback) { + this.element = $(element); + this.eventName = eventName; + this.selector = selector; + this.callback = callback; + this.handler = this.handleEvent.bind(this); + }, + + start: function() { + Event.observe(this.element, this.eventName, this.handler); + return this; + }, + + stop: function() { + Event.stopObserving(this.element, this.eventName, this.handler); + return this; + }, + + handleEvent: function(event) { + var element = Event.findElement(event, this.selector); + if (element) this.callback.call(this.element, event, element); + } + }); + + function on(element, eventName, selector, callback) { + element = $(element); + if (Object.isFunction(selector) && Object.isUndefined(callback)) { + callback = selector, selector = null; + } + + return new Event.Handler(element, eventName, selector, callback).start(); + } + + Object.extend(Event, Event.Methods); + + Object.extend(Event, { + fire: fire, + observe: observe, + stopObserving: stopObserving, + on: on + }); + + Element.addMethods({ + fire: fire, + + observe: observe, + + stopObserving: stopObserving, + + on: on + }); + + Object.extend(document, { + fire: fire.methodize(), + + observe: observe.methodize(), + + stopObserving: stopObserving.methodize(), + + on: on.methodize(), + + loaded: false + }); + + if (window.Event) Object.extend(window.Event, Event); + else window.Event = Event; +})(); + +(function() { + /* Support for the DOMContentLoaded event is based on work by Dan Webb, + Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */ + + var timer; + + function fireContentLoadedEvent() { + if (document.loaded) return; + if (timer) window.clearTimeout(timer); + document.loaded = true; + document.fire('dom:loaded'); + } + + function checkReadyState() { + if (document.readyState === 'complete') { + document.stopObserving('readystatechange', checkReadyState); + fireContentLoadedEvent(); + } + } + + function pollDoScroll() { + try { document.documentElement.doScroll('left'); } + catch(e) { + timer = pollDoScroll.defer(); + return; + } + fireContentLoadedEvent(); + } + + if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false); + } else { + document.observe('readystatechange', checkReadyState); + if (window == top) + timer = pollDoScroll.defer(); + } + + Event.observe(window, 'load', fireContentLoadedEvent); +})(); + +Element.addMethods(); + +/*------------------------------- DEPRECATED -------------------------------*/ + +Hash.toQueryString = Object.toQueryString; + +var Toggle = { display: Element.toggle }; + +Element.Methods.childOf = Element.Methods.descendantOf; + +var Insertion = { + Before: function(element, content) { + return Element.insert(element, {before:content}); + }, + + Top: function(element, content) { + return Element.insert(element, {top:content}); + }, + + Bottom: function(element, content) { + return Element.insert(element, {bottom:content}); + }, + + After: function(element, content) { + return Element.insert(element, {after:content}); + } +}; + +var $continue = new Error('"throw $continue" is deprecated, use "return" instead'); + +var Position = { + includeScrollOffsets: false, + + prepare: function() { + this.deltaX = window.pageXOffset + || document.documentElement.scrollLeft + || document.body.scrollLeft + || 0; + this.deltaY = window.pageYOffset + || document.documentElement.scrollTop + || document.body.scrollTop + || 0; + }, + + within: function(element, x, y) { + if (this.includeScrollOffsets) + return this.withinIncludingScrolloffsets(element, x, y); + this.xcomp = x; + this.ycomp = y; + this.offset = Element.cumulativeOffset(element); + + return (y >= this.offset[1] && + y < this.offset[1] + element.offsetHeight && + x >= this.offset[0] && + x < this.offset[0] + element.offsetWidth); + }, + + withinIncludingScrolloffsets: function(element, x, y) { + var offsetcache = Element.cumulativeScrollOffset(element); + + this.xcomp = x + offsetcache[0] - this.deltaX; + this.ycomp = y + offsetcache[1] - this.deltaY; + this.offset = Element.cumulativeOffset(element); + + return (this.ycomp >= this.offset[1] && + this.ycomp < this.offset[1] + element.offsetHeight && + this.xcomp >= this.offset[0] && + this.xcomp < this.offset[0] + element.offsetWidth); + }, + + overlap: function(mode, element) { + if (!mode) return 0; + if (mode == 'vertical') + return ((this.offset[1] + element.offsetHeight) - this.ycomp) / + element.offsetHeight; + if (mode == 'horizontal') + return ((this.offset[0] + element.offsetWidth) - this.xcomp) / + element.offsetWidth; + }, + + + cumulativeOffset: Element.Methods.cumulativeOffset, + + positionedOffset: Element.Methods.positionedOffset, + + absolutize: function(element) { + Position.prepare(); + return Element.absolutize(element); + }, + + relativize: function(element) { + Position.prepare(); + return Element.relativize(element); + }, + + realOffset: Element.Methods.cumulativeScrollOffset, + + offsetParent: Element.Methods.getOffsetParent, + + page: Element.Methods.viewportOffset, + + clone: function(source, target, options) { + options = options || { }; + return Element.clonePosition(target, source, options); + } +}; + +/*--------------------------------------------------------------------------*/ + +if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){ + function iter(name) { + return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]"; + } + + instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ? + function(element, className) { + className = className.toString().strip(); + var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className); + return cond ? document._getElementsByXPath('.//*' + cond, element) : []; + } : function(element, className) { + className = className.toString().strip(); + var elements = [], classNames = (/\s/.test(className) ? $w(className) : null); + if (!classNames && !className) return elements; + + var nodes = $(element).getElementsByTagName('*'); + className = ' ' + className + ' '; + + for (var i = 0, child, cn; child = nodes[i]; i++) { + if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) || + (classNames && classNames.all(function(name) { + return !name.toString().blank() && cn.include(' ' + name + ' '); + })))) + elements.push(Element.extend(child)); + } + return elements; + }; + + return function(className, parentElement) { + return $(parentElement || document.body).getElementsByClassName(className); + }; +}(Element.Methods); + +/*--------------------------------------------------------------------------*/ + +Element.ClassNames = Class.create(); +Element.ClassNames.prototype = { + initialize: function(element) { + this.element = $(element); + }, + + _each: function(iterator) { + this.element.className.split(/\s+/).select(function(name) { + return name.length > 0; + })._each(iterator); + }, + + set: function(className) { + this.element.className = className; + }, + + add: function(classNameToAdd) { + if (this.include(classNameToAdd)) return; + this.set($A(this).concat(classNameToAdd).join(' ')); + }, + + remove: function(classNameToRemove) { + if (!this.include(classNameToRemove)) return; + this.set($A(this).without(classNameToRemove).join(' ')); + }, + + toString: function() { + return $A(this).join(' '); + } +}; + +Object.extend(Element.ClassNames.prototype, Enumerable); + +/*--------------------------------------------------------------------------*/ + +(function() { + window.Selector = Class.create({ + initialize: function(expression) { + this.expression = expression.strip(); + }, + + findElements: function(rootElement) { + return Prototype.Selector.select(this.expression, rootElement); + }, + + match: function(element) { + return Prototype.Selector.match(element, this.expression); + }, + + toString: function() { + return this.expression; + }, + + inspect: function() { + return "#"; + } + }); + + Object.extend(Selector, { + matchElements: function(elements, expression) { + var match = Prototype.Selector.match, + results = []; + + for (var i = 0, length = elements.length; i < length; i++) { + var element = elements[i]; + if (match(element, expression)) { + results.push(Element.extend(element)); + } + } + return results; + }, + + findElement: function(elements, expression, index) { + index = index || 0; + var matchIndex = 0, element; + for (var i = 0, length = elements.length; i < length; i++) { + element = elements[i]; + if (Prototype.Selector.match(element, expression) && index === matchIndex++) { + return Element.extend(element); + } + } + }, + + findChildElements: function(element, expressions) { + var selector = expressions.toArray().join(', '); + return Prototype.Selector.select(selector, element || document); + } + }); +})(); diff --git a/test_files/test_cases/testKotlinLib.js b/test_files/test_cases/testKotlinLib.js new file mode 100644 index 00000000000..8455017a7de --- /dev/null +++ b/test_files/test_cases/testKotlinLib.js @@ -0,0 +1,12 @@ +foo = {}; +(function(foo){ + foo.Test = Class.create({initialize:function(){ + } + }); + foo.box = function(){ + var test = new foo.Test(); + return true; + } + ; +} +(foo)); diff --git a/src/org/jetbrains/k2js/K2JSTranslator.java b/translator/src/k2js/K2JSTranslator.java similarity index 98% rename from src/org/jetbrains/k2js/K2JSTranslator.java rename to translator/src/k2js/K2JSTranslator.java index 92336141801..5bdb9231782 100644 --- a/src/org/jetbrains/k2js/K2JSTranslator.java +++ b/translator/src/k2js/K2JSTranslator.java @@ -1,4 +1,4 @@ -package org.jetbrains.k2js; +package k2js; import com.google.common.base.Predicates; import com.google.common.collect.LinkedHashMultimap; @@ -12,6 +12,8 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.sampullara.cli.Argument; +import k2js.generate.CodeGenerator; +import k2js.translate.GenerationState; import org.jetbrains.jet.JetCoreEnvironment; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.diagnostics.Diagnostic; @@ -23,8 +25,6 @@ import org.jetbrains.jet.lang.psi.JetNamespace; import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; -import org.jetbrains.k2js.generate.CodeGenerator; -import org.jetbrains.k2js.translate.GenerationState; import java.io.File; import java.io.IOException; diff --git a/src/org/jetbrains/k2js/generate/CodeGenerator.java b/translator/src/k2js/generate/CodeGenerator.java similarity index 96% rename from src/org/jetbrains/k2js/generate/CodeGenerator.java rename to translator/src/k2js/generate/CodeGenerator.java index 7a05851f48e..fce9b65c725 100644 --- a/src/org/jetbrains/k2js/generate/CodeGenerator.java +++ b/translator/src/k2js/generate/CodeGenerator.java @@ -1,4 +1,4 @@ -package org.jetbrains.k2js.generate; +package k2js.generate; import com.google.dart.compiler.backend.js.JsSourceGenerationVisitor; import com.google.dart.compiler.backend.js.ast.JsProgram; diff --git a/src/org/jetbrains/k2js/translate/AbstractTranslator.java b/translator/src/k2js/translate/AbstractTranslator.java similarity index 64% rename from src/org/jetbrains/k2js/translate/AbstractTranslator.java rename to translator/src/k2js/translate/AbstractTranslator.java index 9046f80adb7..72c36ca3efa 100644 --- a/src/org/jetbrains/k2js/translate/AbstractTranslator.java +++ b/translator/src/k2js/translate/AbstractTranslator.java @@ -1,7 +1,5 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; -import com.google.dart.compiler.backend.js.ast.JsBlock; -import com.google.dart.compiler.backend.js.ast.JsName; import com.google.dart.compiler.backend.js.ast.JsProgram; import com.google.dart.compiler.backend.js.ast.JsScope; import org.jetbrains.annotations.NotNull; @@ -12,10 +10,9 @@ import org.jetbrains.jet.lang.resolve.BindingContext; */ public abstract class AbstractTranslator { - private final TranslationContext context; + @NotNull private final TranslationContext context; - public AbstractTranslator(TranslationContext context) { - assert context != null; + public AbstractTranslator(@NotNull TranslationContext context) { this.context = context; } @@ -34,11 +31,6 @@ public abstract class AbstractTranslator { return context.bindingContext(); } - @NotNull - protected JsName getJSName(String jetName) { - return context.getJSName(jetName); - } - @NotNull protected JsScope scope() { return context.enclosingScope(); diff --git a/translator/src/k2js/translate/ClassBodyVisitor.java b/translator/src/k2js/translate/ClassBodyVisitor.java new file mode 100644 index 00000000000..d9ebf991250 --- /dev/null +++ b/translator/src/k2js/translate/ClassBodyVisitor.java @@ -0,0 +1,136 @@ +package k2js.translate; + +import com.google.dart.compiler.util.AstUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetClass; +import org.jetbrains.jet.lang.psi.JetDeclaration; +import org.jetbrains.jet.lang.psi.JetProperty; +import org.jetbrains.jet.lang.psi.JetPropertyAccessor; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author Talanov Pavel + */ +public final class ClassBodyVisitor extends TranslatorVisitor> { + + @Override + @NotNull + public List visitClass(@NotNull JetClass expression, @NotNull TranslationContext context) { + List properties = new ArrayList(); + for (JetDeclaration declaration : expression.getDeclarations()) { + properties.addAll(declaration.accept(this, context)); + } + return properties; + } + + @Override + @NotNull + public List visitProperty(@NotNull JetProperty expression, @NotNull TranslationContext context) { + List methods = new ArrayList(); + addSetterToMethods(expression, context, methods); + addGetterToMethods(expression, context, methods); + return methods; + } + + private void addGetterToMethods(@NotNull JetProperty expression, @NotNull TranslationContext context, + @NotNull List methods) { + JetPropertyAccessor getter = expression.getGetter(); + if (getter != null) { + methods.addAll(getter.accept(this, context)); + } else { + methods.add(generateDefaultGetter(expression, context)); + } + } + + private void addSetterToMethods(@NotNull JetProperty expression, @NotNull TranslationContext context, + @NotNull List methods) { + JetPropertyAccessor setter = expression.getSetter(); + if (setter != null) { + methods.addAll(setter.accept(this, context)); + } else { + if (expression.isVar()) { + methods.add(generateDefaultSetter(expression, context)); + } + } + } + + @NotNull + private JsPropertyInitializer generateDefaultGetter(@NotNull JetProperty expression, @NotNull TranslationContext context) { + JsName getterName = context.classScope().declareName(Namer.getNameForGetter(expression.getName())); + return AstUtil.newNamedMethod(getterName, generateDefaultGetterFunction(expression, context)); + } + + @NotNull + private JsFunction generateDefaultGetterFunction(@NotNull JetProperty expression, + @NotNull TranslationContext context) { + JsNameRef backingFieldRef = declareOrGetBackingFieldName(getPropertyName(expression), context).makeRef(); + JsReturn returnExpression = new JsReturn(backingFieldRef); + return AstUtil.newFunction + (context.enclosingScope(), null, new ArrayList(), AstUtil.convertToBlock(returnExpression)); + } + + @NotNull + private JsName declareOrGetBackingFieldName(@NotNull String propertyName, @NotNull TranslationContext context) { + String backingFieldName = Namer.getBackingFieldNameForProperty(propertyName); + JsName jsBackingFieldName = context.classScope().findExistingName(backingFieldName); + if (jsBackingFieldName == null) { + jsBackingFieldName = context.classScope().declareName(backingFieldName); + } + return jsBackingFieldName; + } + + + @NotNull + private JsPropertyInitializer generateDefaultSetter(@NotNull JetProperty expression, + @NotNull TranslationContext context) { + JsName setterName = context.classScope().declareName(Namer.getNameForSetter(expression.getName())); + return AstUtil.newNamedMethod(setterName, generateDefaultSetterFunction(expression, context)); + } + + @NotNull + private JsFunction generateDefaultSetterFunction(@NotNull JetProperty expression, + @NotNull TranslationContext context) { + JsFunction result = new JsFunction(context.enclosingScope()); + JsParameter defaultParameter = new JsParameter(context.enclosingScope().declareTemporary()); + JsBinaryOperation assignment = assignmentToBackingFieldFromDefaultParameter + (expression, context, defaultParameter); + result.setParameters(Arrays.asList(defaultParameter)); + result.setBody(AstUtil.convertToBlock(assignment)); + return result; + } + + @NotNull + private JsBinaryOperation assignmentToBackingFieldFromDefaultParameter + (@NotNull JetProperty expression, @NotNull TranslationContext context, @NotNull JsParameter defaultParameter) { + JsNameRef backingFieldRef = declareOrGetBackingFieldName(getPropertyName(expression), context).makeRef(); + JsBinaryOperation assignExpression = new JsBinaryOperation(JsBinaryOperator.ASG); + assignExpression.setArg1(backingFieldRef); + assignExpression.setArg2(defaultParameter.getName().makeRef()); + return assignExpression; + } + +// @Override +// @NotNull +// public List visitPropertyAccessor +// (JetPropertyAccessor expression, TranslationContext context) { +// List methods = new ArrayList(); +// JsPropertyInitializer namedMethod = generateMethodForAccessor(expression, context); +// methods.add(namedMethod); +// return methods; +// } +// +// private JsPropertyInitializer generateMethodForAccessor(JetPropertyAccessor expression, TranslationContext context) { +// JsFunction methodBody = new JsFunction(context.enclosingScope()); +// ExpressionTranslator expressionTranslator = +// new ExpressionTranslator(context.newFunction(methodBody)); +// JsBlock methodBodyBlock = AstUtil.convertToBlock(expressionTranslator.translate(expression.getBodyExpression())); +// methodBody.setBody(methodBodyBlock); +// //TODO figure out naming pattern +// return AstUtil.newNamedMethod(Namer.getNameForAccessor("nameForAccessor", expression), methodBody); +// } + + +} diff --git a/src/org/jetbrains/k2js/translate/ClassTranslator.java b/translator/src/k2js/translate/ClassTranslator.java similarity index 88% rename from src/org/jetbrains/k2js/translate/ClassTranslator.java rename to translator/src/k2js/translate/ClassTranslator.java index 2e53af05302..b54673da35c 100644 --- a/src/org/jetbrains/k2js/translate/ClassTranslator.java +++ b/translator/src/k2js/translate/ClassTranslator.java @@ -1,6 +1,5 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; -import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.util.AstUtil; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; @@ -14,7 +13,8 @@ import java.util.List; /** * @author Talanov Pavel */ -public class ClassTranslator extends AbstractTranslator { +//TODO ClassTranslator needs heavy improvement +public final class ClassTranslator extends AbstractTranslator { private final ClassBodyVisitor classBodyVisitor = new ClassBodyVisitor(); @@ -29,9 +29,9 @@ public class ClassTranslator extends AbstractTranslator { jsClassDeclaration.getArguments().add(jsClassDescription); //getSuperClassName(classDeclaration); String className = classDeclaration.getName(); - JsStatement result = AstUtil.convertToStatement(AstUtil.newAssignment( - translationContext().getNamespaceQualifiedReference(getJSName(className)), jsClassDeclaration)); - return result; + JsName jsClassName = translationContext().namespaceScope().declareName(className); + return AstUtil.convertToStatement(AstUtil.newAssignment( + translationContext().getNamespaceQualifiedReference(jsClassName), jsClassDeclaration)); } private void getSuperClassName(JetClass classDeclaration) { diff --git a/translator/src/k2js/translate/DeclarationTranslator.java b/translator/src/k2js/translate/DeclarationTranslator.java new file mode 100644 index 00000000000..4489c689288 --- /dev/null +++ b/translator/src/k2js/translate/DeclarationTranslator.java @@ -0,0 +1,26 @@ +package k2js.translate; + +import com.google.dart.compiler.backend.js.ast.JsStatement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetDeclaration; + +/** + * @author Talanov Pavel + */ +public final class DeclarationTranslator extends AbstractTranslator { + + private DeclarationVisitor visitor = new DeclarationVisitor(); + + public DeclarationTranslator(TranslationContext context) { + super(context); + } + + @NotNull + JsStatement translateDeclaration(JetDeclaration declaration) { + return declaration.accept(visitor, translationContext()); + } + + + + +} diff --git a/translator/src/k2js/translate/DeclarationVisitor.java b/translator/src/k2js/translate/DeclarationVisitor.java new file mode 100644 index 00000000000..c55049078f8 --- /dev/null +++ b/translator/src/k2js/translate/DeclarationVisitor.java @@ -0,0 +1,63 @@ +package k2js.translate; + +import com.google.dart.compiler.backend.js.ast.JsExpression; +import com.google.dart.compiler.backend.js.ast.JsName; +import com.google.dart.compiler.backend.js.ast.JsNameRef; +import com.google.dart.compiler.backend.js.ast.JsStatement; +import com.google.dart.compiler.util.AstUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.psi.JetClass; +import org.jetbrains.jet.lang.psi.JetExpression; +import org.jetbrains.jet.lang.psi.JetNamedFunction; +import org.jetbrains.jet.lang.psi.JetProperty; + +/** + * @author Talanov Pavel + */ +public class DeclarationVisitor extends TranslatorVisitor { + + @NotNull + @Override + //TODO method too long + public JsStatement visitProperty(@NotNull JetProperty expression, @NotNull TranslationContext context) { + JsName propertyName = context.declareLocalName(getPropertyName(expression)); + JsNameRef jsPropertyNameReference = context.getNamespaceQualifiedReference(propertyName); + JsExpression jsInitExpression = translateInitializer(expression, context); + JsExpression result; + if (jsInitExpression != null) { + result = AstUtil.newAssignment(jsPropertyNameReference, jsInitExpression); + } + else { + result = jsPropertyNameReference; + } + return AstUtil.convertToStatement(result); + } + + //TODO duplicate code translateInitializer 1 + @Nullable + private JsExpression translateInitializer(@NotNull JetProperty declaration, @NotNull TranslationContext context) { + JsExpression jsInitExpression = null; + JetExpression initializer = declaration.getInitializer(); + if (initializer != null) { + jsInitExpression = AstUtil.convertToExpression( + (new ExpressionTranslator(context)).translate(initializer)); + } + return jsInitExpression; + } + + @NotNull + @Override + public JsStatement visitClass(@NotNull JetClass expression, @NotNull TranslationContext context) { + ClassTranslator translator = new ClassTranslator(context); + return translator.translateClass(expression); + } + + @NotNull + @Override + public JsStatement visitNamedFunction(@NotNull JetNamedFunction expression, @NotNull TranslationContext context) { + FunctionTranslator functionTranslator = new FunctionTranslator(context); + return AstUtil.convertToStatement(functionTranslator.translateFunction(expression)); + } + +} diff --git a/src/org/jetbrains/k2js/translate/ExpressionTranslator.java b/translator/src/k2js/translate/ExpressionTranslator.java similarity index 59% rename from src/org/jetbrains/k2js/translate/ExpressionTranslator.java rename to translator/src/k2js/translate/ExpressionTranslator.java index b121070fc50..1dab8c01262 100644 --- a/src/org/jetbrains/k2js/translate/ExpressionTranslator.java +++ b/translator/src/k2js/translate/ExpressionTranslator.java @@ -1,4 +1,4 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; import com.google.dart.compiler.backend.js.ast.JsNode; import org.jetbrains.annotations.NotNull; @@ -7,17 +7,16 @@ import org.jetbrains.jet.lang.psi.JetExpression; /** * @author Talanov Pavel */ -class ExpressionTranslator extends AbstractTranslator { +public final class ExpressionTranslator extends AbstractTranslator { final private ExpressionVisitor visitor = new ExpressionVisitor(); - public ExpressionTranslator(TranslationContext context) { + public ExpressionTranslator(@NotNull TranslationContext context) { super(context); } @NotNull - public JsNode translate(JetExpression jetExpression) { - assert jetExpression != null; + public JsNode translate(@NotNull JetExpression jetExpression) { return jetExpression.accept(visitor, translationContext()); } diff --git a/translator/src/k2js/translate/ExpressionVisitor.java b/translator/src/k2js/translate/ExpressionVisitor.java new file mode 100644 index 00000000000..3334daca2a3 --- /dev/null +++ b/translator/src/k2js/translate/ExpressionVisitor.java @@ -0,0 +1,176 @@ +package k2js.translate; + +import com.google.dart.compiler.util.AstUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; +import org.jetbrains.jet.lexer.JetToken; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Talanov Pavel + */ +public final class ExpressionVisitor extends TranslatorVisitor { + + + //TODO method too long + @Override + @NotNull + public JsNode visitConstantExpression(@NotNull JetConstantExpression expression, @NotNull TranslationContext context) { + JsExpression result = null; + Object value; + CompileTimeConstant compileTimeValue = context.bindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression); + assert compileTimeValue != null; + value = compileTimeValue.getValue(); + if (value instanceof Integer) { + result = context.program().getNumberLiteral((Integer) value); + } + if (value instanceof Boolean) { + return context.program().getBooleanLiteral((Boolean) value); + } + assert result != null; + return result; + } + + @Override + @NotNull + public JsNode visitBlockExpression(@NotNull JetBlockExpression jetBlock, @NotNull TranslationContext context) { + List jetElements = jetBlock.getStatements(); + JsBlock jsBlock = new JsBlock(); + TranslationContext newContext = context.newBlock(); + for (JetElement jetElement : jetElements) { + //TODO hack alert + JetExpression jetExpression = (JetExpression) jetElement; + JsNode jsNode = jetExpression.accept(this, newContext); + jsBlock.addStatement(AstUtil.convertToStatement(jsNode)); + } + return jsBlock; + } + + @Override + @NotNull + public JsNode visitReturnExpression(@NotNull JetReturnExpression jetReturnExpression, + @NotNull TranslationContext context) { + JetExpression returnedExpression = jetReturnExpression.getReturnedExpression(); + if (returnedExpression != null) { + JsExpression jsExpression = AstUtil.convertToExpression(returnedExpression.accept(this, context)); + return new JsReturn(jsExpression); + } + return new JsReturn(); + } + + @Override + @NotNull + public JsNode visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, + @NotNull TranslationContext context) { + JetExpression expressionInside = expression.getExpression(); + if (expressionInside != null) { + return expressionInside.accept(this, context); + } + return context.program().getEmptyStmt(); + } + + @Override + @NotNull + public JsNode visitBinaryExpression(@NotNull JetBinaryExpression expression, + @NotNull TranslationContext context) { + JsExpression left = AstUtil.convertToExpression(expression.getLeft().accept(this, context)); + JetExpression rightExpression = expression.getRight(); + if (rightExpression == null) { + throw new AssertionError("BinaryExpression with no right parameter"); + } + JsExpression right = AstUtil.convertToExpression(rightExpression.accept(this, context)); + //TODO cast dangerous? + JetToken jetOperationToken = (JetToken)expression.getOperationToken(); + return new JsBinaryOperation(OperationTranslator.getBinaryOperator(jetOperationToken), left, right); + } + + //TODO think about recursive/non-recursive name look-up + //TODO correct look-up logic + @Override + @NotNull + public JsNode visitSimpleNameExpression(JetSimpleNameExpression expression, TranslationContext context) { + String referencedName = expression.getReferencedName(); + JsName jsName = context.enclosingScope().findExistingNameNoRecurse(referencedName); + if (jsName != null) { + return jsName.makeRef(); + } + jsName = context.classScope().findExistingNameNoRecurse(referencedName); + if (jsName != null) { + return context.getNamespaceQualifiedReference(jsName); + } + jsName = context.namespaceScope().findExistingNameNoRecurse(referencedName); + if (jsName != null) { + return context.getNamespaceQualifiedReference(jsName); + } + throw new AssertionError("Unindentified name " + expression.getReferencedName()); + } + + @Override + @NotNull + // assume it is a local variable declaration + public JsNode visitProperty(JetProperty expression, TranslationContext context) { + JsName jsPropertyName = context.declareLocalName(getPropertyName(expression)); + JsExpression jsInitExpression = translateInitializer(expression, context); + return AstUtil.newVar(jsPropertyName, jsInitExpression); + } + + //TODO duplicate code translateInitializer 2 + @Nullable + private JsExpression translateInitializer(JetProperty declaration, TranslationContext context) { + JsExpression jsInitExpression = null; + JetExpression initializer = declaration.getInitializer(); + if (initializer != null) { + jsInitExpression = AstUtil.convertToExpression( + (new ExpressionTranslator(context)).translate(initializer)); + } + return jsInitExpression; + } + + + @Override + @NotNull + public JsNode visitCallExpression(JetCallExpression expression, TranslationContext context) { + ConstructorDescriptor constructorDescriptor = (context.bindingContext().get(BindingContext.CONSTRUCTOR, expression.getCalleeExpression())); + JetExpression calleeExpression = expression.getCalleeExpression(); + if (constructorDescriptor == null) { + JsExpression callee = getCallee(expression, context); + List arguments = generateArgumentList(expression.getValueArguments(), context); + return AstUtil.newInvocation(callee, arguments); + } + throw new AssertionError("Should generate constructor invocation"); + } + + @NotNull + private JsExpression getCallee(@NotNull JetCallExpression expression, @NotNull TranslationContext context) { + JetExpression jetCallee = expression.getCalleeExpression(); + if (jetCallee == null) { + throw new AssertionError("Call expression with no callee encountered!"); + } + JsNode jsCallee = jetCallee.accept(this, context); + return AstUtil.convertToExpression(jsCallee); + } + + @NotNull + private List generateArgumentList(@NotNull List jetArguments, + @NotNull TranslationContext context) { + List jsArguments = new ArrayList(); + for (ValueArgument argument : jetArguments) { + jsArguments.add(translateArgument(context, argument)); + } + return jsArguments; + } + + private JsExpression translateArgument(@NotNull TranslationContext context, @NotNull ValueArgument argument) { + JetExpression jetExpression = argument.getArgumentExpression(); + if (jetExpression == null) { + throw new AssertionError("Argument with no expression encountered!"); + } + return AstUtil.convertToExpression(jetExpression.accept(this, context)); + } + +} diff --git a/src/org/jetbrains/k2js/translate/FunctionTranslator.java b/translator/src/k2js/translate/FunctionTranslator.java similarity index 61% rename from src/org/jetbrains/k2js/translate/FunctionTranslator.java rename to translator/src/k2js/translate/FunctionTranslator.java index e1096e981b4..568835cfb99 100644 --- a/src/org/jetbrains/k2js/translate/FunctionTranslator.java +++ b/translator/src/k2js/translate/FunctionTranslator.java @@ -1,7 +1,8 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; -import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.util.AstUtil; +import com.sun.istack.internal.NotNull; +import compiler.backend.js.ast.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetNamedFunction; @@ -13,40 +14,44 @@ import java.util.List; /** * @author Talanov Pavel */ -public class FunctionTranslator extends AbstractTranslator { +public final class FunctionTranslator extends AbstractTranslator { - public FunctionTranslator(TranslationContext context) { + public FunctionTranslator(@NotNull TranslationContext context) { super(context); } @NotNull - public JsStatement translateFunction(JetNamedFunction jetFunction) { + public JsStatement translateFunction(@NotNull JetNamedFunction jetFunction) { JsName functionName = translationContext().namespaceScope().declareFreshName(jetFunction.getName()); JsFunction function = generateFunctionObject(jetFunction); return AstUtil.convertToStatement(AstUtil.newAssignment (translationContext().getNamespaceQualifiedReference(functionName), function)); } - private JsFunction generateFunctionObject(JetNamedFunction jetFunction) { + @NotNull + private JsFunction generateFunctionObject(@NotNull JetNamedFunction jetFunction) { JetExpression jetBodyExpression = jetFunction.getBodyExpression(); JsFunction result = new JsFunction(scope()); JsNode jsBody = (new ExpressionTranslator(functionBodyContext(result))) .translate(jetBodyExpression); - List jsParameters = translateParameters(jetFunction.getValueParameters()); + List jsParameters = translateParameters(jetFunction.getValueParameters(), result.getScope()); result.setParameters(jsParameters); result.setBody(AstUtil.convertToBlock(jsBody)); return result; } - private TranslationContext functionBodyContext(JsFunction function) { + @NotNull + private TranslationContext functionBodyContext(@NotNull JsFunction function) { return translationContext().newFunction(function); } @NotNull - private List translateParameters(List jetParameters) { + private List translateParameters(@NotNull List jetParameters, + @NotNull JsScope functionScope) { List jsParameters = new ArrayList(); for (JetParameter jetParameter : jetParameters) { - jsParameters.add(new JsParameter(getJSName(jetParameter.getName()))); + JsName parameterName = functionScope.declareName(jetParameter.getName()); + jsParameters.add(new JsParameter(parameterName)); } return jsParameters; } diff --git a/src/org/jetbrains/k2js/translate/GenerationState.java b/translator/src/k2js/translate/GenerationState.java similarity index 73% rename from src/org/jetbrains/k2js/translate/GenerationState.java rename to translator/src/k2js/translate/GenerationState.java index 5628f8dcca4..bae44dd74d6 100644 --- a/src/org/jetbrains/k2js/translate/GenerationState.java +++ b/translator/src/k2js/translate/GenerationState.java @@ -1,7 +1,7 @@ /* - * @author max + * @author Talanov Pavel */ -package org.jetbrains.k2js.translate; +package k2js.translate; import com.google.dart.compiler.backend.js.ast.JsProgram; import com.intellij.openapi.project.Project; @@ -11,40 +11,24 @@ import org.jetbrains.jet.lang.psi.JetNamespace; import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; -import org.jetbrains.jet.lang.types.JetStandardLibrary; import java.util.Collections; import java.util.List; -public class GenerationState { +public final class GenerationState { private final Project project; private BindingContext currentContext; - private final JetStandardLibrary standardLibrary; public GenerationState(Project project, boolean text) { this.project = project; - this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project); - } - - public Project getProject() { - return project; - } - - - public BindingContext getContext() { - return currentContext; } private void setContext(BindingContext context) { this.currentContext = context; } - public JetStandardLibrary getStandardLibrary() { - return standardLibrary; - } - public void compile(JetFile psiFile) { final JetNamespace namespace = psiFile.getRootNamespace(); final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY); @@ -56,7 +40,8 @@ public class GenerationState { this.currentContext = bindingContext; //TODO hardcoded JsProgram result = new JsProgram("main"); - (new NamespaceTranslator(TranslationContext.rootContext(result, bindingContext), namespaces.get(0))).generateAst(); + JetNamespace namespace = namespaces.get(0); + (new NamespaceTranslator(TranslationContext.rootContext(result, bindingContext))).generateAst(namespace); return result; } diff --git a/src/org/jetbrains/k2js/translate/Namer.java b/translator/src/k2js/translate/Namer.java similarity index 54% rename from src/org/jetbrains/k2js/translate/Namer.java rename to translator/src/k2js/translate/Namer.java index d8edac49f53..1ce039739ce 100644 --- a/src/org/jetbrains/k2js/translate/Namer.java +++ b/translator/src/k2js/translate/Namer.java @@ -1,9 +1,7 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; -import com.google.dart.compiler.backend.js.ast.JsName; import com.google.dart.compiler.backend.js.ast.JsNameRef; import com.google.dart.compiler.util.AstUtil; -import org.jetbrains.jet.lang.psi.JetProperty; import org.jetbrains.jet.lang.psi.JetPropertyAccessor; /** @@ -21,18 +19,18 @@ public final class Namer { public static final String INITIALIZE_METHOD_NAME = "initialize"; private static final String CLASS_OBJECT_NAME = "Class"; - private static final String CLASS_CREATE_METHOD_NAME = "create"; + //private static final String CLASS_CREATE_METHOD_NAME = "create"; private static final String SETTER_PREFIX = "_set_"; private static final String GETTER_PREFIX = "_get_"; private static final String BACKING_FIELD_PREFIX = "_$_"; - public static final String DEFAULT_SETTER_PARAM_NAME = "val"; + // public static final String DEFAULT_SETTER_PARAM_NAME = "val"; - public static JsName getClassObjectName() { + public static String getClassObjectName() { //TODO dummy representation - return new JsName(null, "Class", "Class", "Class"); + return CLASS_OBJECT_NAME; } - public static JsName getNameForAccessor(String propertyName, JetPropertyAccessor accessor) { + public static String getNameForAccessor(String propertyName, JetPropertyAccessor accessor) { if (accessor.isGetter()) { return getNameForGetter(propertyName); } @@ -42,30 +40,24 @@ public final class Namer { throw new AssertionError("accessor should be a getter or a setter!"); } - public static JsName getBackingFieldNameForProperty(String propertyName) { - String name = BACKING_FIELD_PREFIX + propertyName; - return new JsName(null, name, name, name); + public static String getBackingFieldNameForProperty(String propertyName) { + return getNameWithPrefix(propertyName, BACKING_FIELD_PREFIX); } - public static JsName getBackingFieldNameForProperty(JetProperty property) { - return getNameWithPrefix(property.getName(), BACKING_FIELD_PREFIX); - } - - public static JsName getNameForGetter(String propertyName) { + public static String getNameForGetter(String propertyName) { return getNameWithPrefix(propertyName, GETTER_PREFIX); } - public static JsName getNameForSetter(String propertyName) { + public static String getNameForSetter(String propertyName) { return getNameWithPrefix(propertyName, SETTER_PREFIX); } - private static JsName getNameWithPrefix(String name, String prefix) { - String resultingName = prefix + name; - return new JsName(null, resultingName, resultingName, resultingName); + private static String getNameWithPrefix(String name, String prefix) { + return prefix + name; } - public static JsName getNameForNamespace(String name) { - return new JsName(null, name, name, name); + public static String getNameForNamespace(String name) { + return name; } public static JsNameRef classObjectReference() { diff --git a/src/org/jetbrains/k2js/translate/NamespaceTranslator.java b/translator/src/k2js/translate/NamespaceTranslator.java similarity index 65% rename from src/org/jetbrains/k2js/translate/NamespaceTranslator.java rename to translator/src/k2js/translate/NamespaceTranslator.java index 910eac10dae..c7bd4a94e23 100644 --- a/src/org/jetbrains/k2js/translate/NamespaceTranslator.java +++ b/translator/src/k2js/translate/NamespaceTranslator.java @@ -1,6 +1,5 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; -import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.util.AstUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetDeclaration; @@ -12,34 +11,32 @@ import java.util.List; /** * @author Pavel.Talanov */ -public class NamespaceTranslator extends AbstractTranslator { +public final class NamespaceTranslator extends AbstractTranslator { - private final JetNamespace namespace; - - NamespaceTranslator(TranslationContext context, JetNamespace namespace) { + public NamespaceTranslator(@NotNull TranslationContext context) { super(context); - this.namespace = namespace; } - JsProgram generateAst() { + public JsProgram generateAst(@NotNull JetNamespace namespace) { translate(namespace); return program(); } - public JsBlock translate(JetNamespace namespace) { + @NotNull + public JsBlock translate(@NotNull JetNamespace namespace) { // TODO support multiple namespaces JsBlock block = program().getFragmentBlock(0); - JsName namespaceName = Namer.getNameForNamespace(namespace.getName()); + JsName namespaceName = scope().declareName(Namer.getNameForNamespace(namespace.getName())); block.addStatement(namespaceInitStatement(namespaceName)); JsFunction dummyFunction = new JsFunction(scope()); TranslationContext newContext = translationContext().newNamespace(namespaceName, dummyFunction); - JsBlock namespaceDeclarations = translateDeclaration(namespace, newContext); + JsBlock namespaceDeclarations = translateDeclarations(namespace, newContext); block.addStatement(AstUtil.convertToStatement(newNamespace(namespaceName, namespaceDeclarations, dummyFunction))); return block; } @NotNull - private JsBlock translateDeclaration(JetNamespace namespace, TranslationContext newContext) { + private JsBlock translateDeclarations(@NotNull JetNamespace namespace, @NotNull TranslationContext newContext) { DeclarationTranslator declarationTranslator = new DeclarationTranslator(newContext); JsBlock namespaceDeclarations = new JsBlock(); for (JetDeclaration declaration : namespace.getDeclarations()) { @@ -48,11 +45,14 @@ public class NamespaceTranslator extends AbstractTranslator { return namespaceDeclarations; } - private JsStatement namespaceInitStatement(JsName namespaceName) { + @NotNull + private JsStatement namespaceInitStatement(@NotNull JsName namespaceName) { return AstUtil.convertToStatement(AstUtil.newAssignment(namespaceName.makeRef(), new JsObjectLiteral())); } - public JsInvocation newNamespace(JsName name, JsBlock namespaceDeclarations, JsFunction dummyFunction) { + @NotNull + private JsInvocation newNamespace(@NotNull JsName name, @NotNull JsBlock namespaceDeclarations, + @NotNull JsFunction dummyFunction) { List params = new ArrayList(); params.add(new JsParameter(name)); dummyFunction.setParameters(params); diff --git a/src/org/jetbrains/k2js/translate/OperationTranslator.java b/translator/src/k2js/translate/OperationTranslator.java similarity index 90% rename from src/org/jetbrains/k2js/translate/OperationTranslator.java rename to translator/src/k2js/translate/OperationTranslator.java index 7b6c826bb47..f2174767e4d 100644 --- a/src/org/jetbrains/k2js/translate/OperationTranslator.java +++ b/translator/src/k2js/translate/OperationTranslator.java @@ -1,4 +1,4 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; import com.google.dart.compiler.backend.js.ast.JsBinaryOperator; import com.google.dart.compiler.backend.js.ast.JsOperator; @@ -15,6 +15,7 @@ public final class OperationTranslator { private static Map map = new HashMap(); + static { map.put(JetTokens.PLUS, JsBinaryOperator.ADD); map.put(JetTokens.MINUS, JsBinaryOperator.SUB); @@ -34,7 +35,7 @@ public final class OperationTranslator { if (result instanceof JsBinaryOperator) { return (JsBinaryOperator)result; } - throw new AssertionError("Invalid map: shoild containd token: " + token.toString()); + throw new AssertionError("Invalid map: should contain token: " + token.toString()); } diff --git a/src/org/jetbrains/k2js/translate/TranslationContext.java b/translator/src/k2js/translate/TranslationContext.java similarity index 52% rename from src/org/jetbrains/k2js/translate/TranslationContext.java rename to translator/src/k2js/translate/TranslationContext.java index 661cfc3f571..84f6bd4900b 100644 --- a/src/org/jetbrains/k2js/translate/TranslationContext.java +++ b/translator/src/k2js/translate/TranslationContext.java @@ -1,49 +1,26 @@ -package org.jetbrains.k2js.translate; +package k2js.translate; -import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.util.AstUtil; -import org.apache.velocity.runtime.directive.Scope; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.BindingContext; -import java.awt.peer.ScrollbarPeer; - /** * @author Talanov Pavel */ -public class TranslationContext { - - private final JsProgram program; - private final BindingContext bindingContext; - private final ContextType type; - private final Scopes scopes; - private final JsName currentNamespace; +public final class TranslationContext { private static class Scopes { - - public Scopes(JsScope enclosing, JsScope function, JsScope namespace) { - this.enclosingScope = enclosing; - this.functionScope = function; - this.namespaceScope = namespace; + public Scopes(@NotNull JsScope enclosingScope, @NotNull JsScope functionScope, @NotNull JsScope namespaceScope) { + this.enclosingScope = enclosingScope; + this.classScope = functionScope; + this.namespaceScope = namespaceScope; } - public final JsScope enclosingScope; - public final JsScope functionScope; - public final JsScope namespaceScope; - } - - private TranslationContext(JsName currentNamespace, JsProgram program, - BindingContext bindingContext, Scopes scopes, ContextType type) { - assert program != null; - assert bindingContext != null; - assert scopes != null; - assert type != null; - this.program = program; - this.bindingContext = bindingContext; - this.type = type; - this.currentNamespace = currentNamespace; - this.scopes = scopes; + @NotNull public final JsScope enclosingScope; + @NotNull public final JsScope classScope; + @NotNull public final JsScope namespaceScope; } @NotNull @@ -51,31 +28,47 @@ public class TranslationContext { JsScope rootScope = program.getRootScope(); Scopes scopes = new Scopes(rootScope, rootScope, rootScope); return new TranslationContext(null, - program, bindingContext, scopes, ContextType.NAMESPACE_BODY); + program, bindingContext, scopes); + } + + @NotNull private final JsProgram program; + @NotNull private final BindingContext bindingContext; + @NotNull private final Scopes scopes; + @Nullable private final JsName currentNamespace; + + + + private TranslationContext(@Nullable JsName currentNamespace, @NotNull JsProgram program, + @NotNull BindingContext bindingContext, @NotNull Scopes scopes) { + this.program = program; + this.bindingContext = bindingContext; + this.currentNamespace = currentNamespace; + this.scopes = scopes; } @NotNull - public TranslationContext newNamespace(JsName namespaceName, JsFunction namespaceDummyFunction) { + public TranslationContext newNamespace(@NotNull JsName namespaceName, @NotNull JsFunction namespaceDummyFunction) { JsScope newScope = namespaceDummyFunction.getScope(); Scopes newScopes = new Scopes(newScope, newScope, newScope); return new TranslationContext(namespaceName, program, - bindingContext, newScopes, ContextType.NAMESPACE_BODY); + bindingContext, newScopes); } @NotNull public TranslationContext newBlock() { Scopes newScopes = new Scopes(new JsScope - (scopes.enclosingScope, "dummy enclosingScope for a block"), scopes.functionScope, scopes.namespaceScope); + (scopes.enclosingScope, "dummy enclosingScope for a block"), scopes.classScope, scopes.namespaceScope); return new TranslationContext(currentNamespace, program, - bindingContext, newScopes, type); + bindingContext, newScopes); } + //TODO new Class? @NotNull - public TranslationContext newFunction(JsFunction function) { + public TranslationContext newFunction(@NotNull JsFunction function) { JsScope functionScope = function.getScope(); Scopes newScopes = new Scopes(functionScope, functionScope, scopes.namespaceScope); return new TranslationContext(currentNamespace, program, - bindingContext, newScopes, ContextType.FUNCTION_BODY); + bindingContext, newScopes); } @NotNull @@ -86,11 +79,6 @@ public class TranslationContext { return new JsNameRef(name); } - @NotNull - public JsName getJSName(String jetName) { - return new JsName(program().getScope(), jetName, jetName, jetName); - } - @NotNull public BindingContext bindingContext() { return bindingContext; @@ -112,17 +100,12 @@ public class TranslationContext { } @NotNull - JsScope functionScope() { - return scopes.functionScope; + JsScope classScope() { + return scopes.classScope; } @NotNull - JsName declareLocalName(String name) { + JsName declareLocalName(@NotNull String name) { return scopes.enclosingScope.declareFreshName(name); } - - @NotNull - ContextType type() { - return type; - } } diff --git a/translator/src/k2js/translate/TranslatorVisitor.java b/translator/src/k2js/translate/TranslatorVisitor.java new file mode 100644 index 00000000000..b535a64509b --- /dev/null +++ b/translator/src/k2js/translate/TranslatorVisitor.java @@ -0,0 +1,29 @@ +package k2js.translate; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetElement; +import org.jetbrains.jet.lang.psi.JetProperty; +import org.jetbrains.jet.lang.psi.JetVisitor; + +/** + * @author Talanov Pavel + * + * This class is a base class for all visitors. It contains code that is shared among them. + */ +public class TranslatorVisitor extends JetVisitor { + + @Override + @NotNull + public T visitJetElement(JetElement expression, TranslationContext context) { + throw new RuntimeException("Unsupported expression encountered:" + expression.toString()); + } + + @NotNull + protected String getPropertyName(@NotNull JetProperty expression) { + String propertyName = expression.getName(); + if (propertyName == null) { + throw new AssertionError("Property with no name encountered!"); + } + return propertyName; + } +} diff --git a/translator/translator.iml b/translator/translator.iml new file mode 100644 index 00000000000..6dbb4fe0499 --- /dev/null +++ b/translator/translator.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +