Added DeclarationExtractor logic.

This commit is contained in:
Pavel Talanov
2011-11-10 14:06:15 +04:00
parent da1a1a3727
commit f4b18c277f
11 changed files with 624 additions and 398 deletions
+176 -173
View File
@@ -6,15 +6,17 @@
</component>
<component name="ChangeListManager">
<list default="true" id="f02ef53d-47a4-4f5e-a1aa-3df68aae9b20" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/translator/test_files/test_cases/accessToInstanceProperty.kt" />
<change type="MOVED" beforePath="C:\Dev\Projects\jet-contrib\k2js\translator\test_files\test_cases\mehodDeclarationAndCall.kt" afterPath="$PROJECT_DIR$/translator/test_files/test_cases/methodDeclarationAndCall.kt" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/DeclarationExtractor.java" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/ExtractionVisitor.java" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/BindingUtils.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsFunction.java" afterPath="$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsFunction.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/GenerationState.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/GenerationState.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/NamespaceTranslator.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/NamespaceTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslationContext.java" afterPath="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslationContext.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/ClassTest.java" afterPath="$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/ClassTest.java" />
</list>
<ignored path="k2js.iws" />
<ignored path=".idea/workspace.xml" />
@@ -39,7 +41,7 @@
</component>
<component name="DebuggerManager">
<line_breakpoints>
<breakpoint url="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" line="282" class="org.jetbrains.k2js.translate.ExpressionVisitor" package="org.jetbrains.k2js.translate">
<breakpoint url="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" line="283" class="org.jetbrains.k2js.translate.ExpressionVisitor" package="org.jetbrains.k2js.translate">
<option name="ENABLED" value="true" />
<option name="LOG_ENABLED" value="false" />
<option name="LOG_EXPRESSION_ENABLED" value="false" />
@@ -92,13 +94,13 @@
<favorites_list name="k2js" />
</component>
<component name="FileEditorManager">
<splitter split-orientation="horizontal" split-proportion="0.49043366">
<splitter split-orientation="horizontal" split-proportion="0.38839287">
<split-first>
<leaf>
<file leaf-file-name="ClassTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java">
<file leaf-file-name="DeclarationExtractor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/DeclarationExtractor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="43" column="62" selection-start="2003" selection-end="2003" vertical-scroll-proportion="0.0">
<state line="22" column="44" selection-start="720" selection-end="720" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -109,52 +111,56 @@
<file leaf-file-name="TranslationContext.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslationContext.java">
<provider selected="true" editor-type-id="text-editor">
<state line="60" column="46" selection-start="2250" selection-end="2250" vertical-scroll-proportion="0.0">
<state line="152" column="49" selection-start="5820" selection-end="5820" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="OperationTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/OperationTranslator.java">
<file leaf-file-name="NamespaceTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/NamespaceTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="13" column="19" selection-start="348" selection-end="348" vertical-scroll-proportion="0.0">
<state line="31" column="86" selection-start="1029" selection-end="1029" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ClassTest.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/ClassTest.java">
<file leaf-file-name="JsFunction.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsFunction.java">
<provider selected="true" editor-type-id="text-editor">
<state line="57" column="36" selection-start="1922" selection-end="1922" vertical-scroll-proportion="0.0">
<state line="235" column="41" selection-start="6010" selection-end="6010" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="TranslationTest.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/TranslationTest.java">
<provider selected="true" editor-type-id="text-editor">
<state line="15" column="13" selection-start="351" selection-end="351" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="NamespaceDescriptor.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java">
<file leaf-file-name="ExtractionVisitor.java" pinned="false" current="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/ExtractionVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="24" selection-start="472" selection-end="472" vertical-scroll-proportion="0.4524715">
<folding />
<state line="61" column="46" selection-start="2518" selection-end="2518" vertical-scroll-proportion="0.6551724">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="methodDeclarationAndCall.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/methodDeclarationAndCall.js">
<file leaf-file-name="Void.java" pinned="false" current="false" current-in-tab="false">
<entry file="jar://C:/Program Files/Java/jdk1.7.0_01/src.zip!/java/lang/Void.java">
<provider selected="true" editor-type-id="text-editor">
<state line="12" column="39" selection-start="216" selection-end="216" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="DeclarationDescriptor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="26" column="30" selection-start="998" selection-end="998" vertical-scroll-proportion="0.0">
<state line="36" column="6" selection-start="464" selection-end="464" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -163,26 +169,28 @@
<file leaf-file-name="DeclarationDescriptorVisitor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="14" column="23" selection-start="404" selection-end="404" vertical-scroll-proportion="0.0">
<state line="5" column="21" selection-start="94" selection-end="94" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="accessToInstanceProperty.kt" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/accessToInstanceProperty.kt">
<file leaf-file-name="DescriptorUtils.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="23" selection-start="120" selection-end="120" vertical-scroll-proportion="0.0">
<state line="17" column="13" selection-start="504" selection-end="504" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="classInstantiation.kt" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/classInstantiation.kt">
<file leaf-file-name="BindingUtils.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/BindingUtils.java">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="94" vertical-scroll-proportion="0.0">
<folding />
<state line="23" column="30" selection-start="864" selection-end="864" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
@@ -191,10 +199,10 @@
</split-first>
<split-second>
<leaf>
<file leaf-file-name="ExpressionVisitor.java" pinned="false" current="false" current-in-tab="true">
<file leaf-file-name="ExpressionVisitor.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="107" column="0" selection-start="4543" selection-end="4543" vertical-scroll-proportion="0.33333334">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -202,24 +210,6 @@
</provider>
</entry>
</file>
<file leaf-file-name="JsInvocation.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java">
<provider selected="true" editor-type-id="text-editor">
<state line="25" column="24" selection-start="706" selection-end="706" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="JsNameRef.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="19" selection-start="356" selection-end="356" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="JetQualifiedExpression.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetQualifiedExpression.java">
<provider selected="true" editor-type-id="text-editor">
@@ -250,7 +240,7 @@
<file leaf-file-name="ClassBodyVisitor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="36" column="92" selection-start="1286" selection-end="1286" vertical-scroll-proportion="0.0">
<state line="15" column="19" selection-start="379" selection-end="379" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -272,7 +262,29 @@
<file leaf-file-name="FunctionTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="74" selection-start="576" selection-end="576" vertical-scroll-proportion="0.0">
<state line="41" column="76" selection-start="1753" selection-end="1753" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="GenerationState.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/GenerationState.java">
<provider selected="true" editor-type-id="text-editor">
<state line="36" column="38" selection-start="1431" selection-end="1431" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ClassTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="50" column="65" selection-start="2440" selection-end="2440" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -305,22 +317,22 @@
<component name="IdeDocumentHistory">
<option name="changedFiles">
<list>
<option value="$PROJECT_DIR$/translator/test_files/test_cases/stringAssignment.kt" />
<option value="$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/FunctionTest.java" />
<option value="$PROJECT_DIR$/translator/test_files/test_cases/classInstantiation.js" />
<option value="$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsNew.java" />
<option value="$PROJECT_DIR$/translator/test_files/test_cases/mehodDeclarationAndCall.kt" />
<option value="$PROJECT_DIR$/translator/test_files/test_cases/methodDeclarationAndCall.kt" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslationContext.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java" />
<option value="$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptor.java" />
<option value="$PROJECT_DIR$/translator/test_files/test_cases/classInstantiation.kt" />
<option value="$PROJECT_DIR$/translator/test_files/test_cases/classWithProperties.kt" />
<option value="$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/ClassTest.java" />
<option value="$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/DeclarationExtractor.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/GenerationState.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/BindingUtils.java" />
<option value="$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsFunction.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslationContext.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/NamespaceTranslator.java" />
<option value="$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/ExtractionVisitor.java" />
</list>
</option>
</component>
@@ -381,24 +393,6 @@
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="k2js" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="translator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="test_files" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="test_cases" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="k2js" />
@@ -548,7 +542,7 @@
<recent name="C:\Dev\Projects\k2js\src\org\jetbrains\k2js\translate" />
</key>
</component>
<component name="RunManager" selected="JUnit.ClassTest">
<component name="RunManager" selected="JUnit.All in translator">
<configuration default="false" name="ClassTest.classInstantiation" type="JUnit" factoryName="JUnit" temporary="true">
<module name="translator" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@@ -788,7 +782,7 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1176" extended-state="6" />
<editor active="true" />
<editor active="false" />
<layout>
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32907662" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
@@ -804,7 +798,7 @@
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3997862" sideWeight="0.6705998" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.16149732" sideWeight="0.5699234" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.43007663" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.43007663" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
@@ -842,7 +836,7 @@
<option name="CHECK_COMMIT_MESSAGE_SPELLING" value="true" />
<option name="DEFAULT_PATCH_EXTENSION" value="patch" />
<option name="FORCE_NON_EMPTY_COMMENT" value="false" />
<option name="LAST_COMMIT_MESSAGE" value="Added constructor calls. Working on method logic." />
<option name="LAST_COMMIT_MESSAGE" value="Added simple method call support." />
<option name="MAKE_NEW_CHANGELIST_ACTIVE" value="true" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_FILES_UP_TO_DATE_BEFORE_COMMIT" value="false" />
@@ -863,6 +857,7 @@
<MESSAGE value="Added while/do while support" />
<MESSAGE value="Added string constant support." />
<MESSAGE value="Added constructor calls. Working on method logic." />
<MESSAGE value="Added simple method call support." />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
@@ -872,90 +867,119 @@
<option name="FILTER_TARGETS" value="false" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/TranslationTest.java">
<provider selected="true" editor-type-id="text-editor">
<state line="15" column="13" selection-start="351" selection-end="351" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java">
<provider selected="true" editor-type-id="text-editor">
<state line="25" column="24" selection-start="706" selection-end="706" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="19" selection-start="356" selection-end="356" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="13" selection-start="504" selection-end="504" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/JetScope.java">
<provider selected="true" editor-type-id="text-editor">
<state line="14" column="17" selection-start="374" selection-end="374" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="36" column="92" selection-start="1286" selection-end="1286" vertical-scroll-proportion="0.0">
<state line="15" column="19" selection-start="379" selection-end="379" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDotQualifiedExpression.java">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/BindingUtils.java">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="53" selection-start="190" selection-end="190" vertical-scroll-proportion="0.0">
<state line="23" column="30" selection-start="864" selection-end="864" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="16" column="17" selection-start="502" selection-end="502" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/backend/js/ast/JsFunction.java">
<provider selected="true" editor-type-id="text-editor">
<state line="235" column="41" selection-start="6010" selection-end="6010" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/GenerationState.java">
<provider selected="true" editor-type-id="text-editor">
<state line="36" column="38" selection-start="1431" selection-end="1431" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslationContext.java">
<provider selected="true" editor-type-id="text-editor">
<state line="152" column="49" selection-start="5820" selection-end="5820" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="41" column="76" selection-start="1753" selection-end="1753" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="43" column="62" selection-start="2003" selection-end="2003" vertical-scroll-proportion="0.0">
<state line="50" column="65" selection-start="2440" selection-end="2440" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/methodDeclarationAndCall.js">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/NamespaceTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="12" column="39" selection-start="216" selection-end="216" vertical-scroll-proportion="0.0">
<state line="31" column="86" selection-start="1029" selection-end="1029" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java">
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/declarations/ExtractionVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="48" column="14" selection-start="1890" selection-end="1890" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="26" column="30" selection-start="998" selection-end="998" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/testKotlinLib.js">
<provider selected="true" editor-type-id="text-editor">
<state line="12" column="58" selection-start="176" selection-end="176" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="14" column="23" selection-start="404" selection-end="404" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/TranslatorVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="0" selection-start="537" selection-end="537" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/classInstantiation.kt">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="94" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/accessToInstanceProperty.kt">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="23" selection-start="120" selection-end="120" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/src/com/google/dart/compiler/util/AstUtil.java">
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="23" selection-start="689" selection-end="694" vertical-scroll-proportion="-6.6538463">
<state line="61" column="46" selection-start="2518" selection-end="2518" vertical-scroll-proportion="0.6551724">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -964,34 +988,13 @@
</entry>
<entry file="file://$PROJECT_DIR$/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="107" column="0" selection-start="4543" selection-end="4543" vertical-scroll-proportion="0.33333334">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/test/org/jetbrains/k2js/test/ClassTest.java">
<provider selected="true" editor-type-id="text-editor">
<state line="57" column="36" selection-start="1922" selection-end="1922" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/translator/test_files/test_cases/methodDeclarationAndCall.kt">
<provider selected="true" editor-type-id="text-editor">
<state line="10" column="40" selection-start="157" selection-end="157" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="24" selection-start="472" selection-end="472" vertical-scroll-proportion="0.4524715">
<folding />
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>
@@ -14,211 +14,225 @@ import java.util.List;
*/
public final class JsFunction extends JsLiteral implements HasName {
private static void trace(String title, String code) {
System.out.println("---------------------------");
System.out.println(title + ":");
System.out.println("---------------------------");
System.out.println(code);
}
private static void trace(String title, String code) {
System.out.println("---------------------------");
System.out.println(title + ":");
System.out.println("---------------------------");
System.out.println(code);
}
protected JsBlock body;
protected final List<JsParameter> params = new ArrayList<JsParameter>();
protected final JsScope scope;
private boolean artificiallyRescued;
private boolean executeOnce;
private boolean fromDart;
private JsFunction impliedExecute;
private JsName name;
private boolean trace = false;
private boolean traceFirst = true;
private boolean hoisted = false;
private boolean constructor = false;
protected JsBlock body;
protected final List<JsParameter> params = new ArrayList<JsParameter>();
protected final JsScope scope;
private boolean artificiallyRescued;
private boolean executeOnce;
private boolean fromDart;
private JsFunction impliedExecute;
private JsName name;
private boolean trace = false;
private boolean traceFirst = true;
private boolean hoisted = false;
private boolean constructor = false;
/**
* Creates an anonymous function.
*/
public JsFunction(JsScope parent) {
this(parent, null, false);
}
/**
* Creates an anonymous function.
*/
public JsFunction(JsScope parent) {
this(parent, null, false);
}
/**
* Creates a function that is not derived from Dart source.
*/
public JsFunction(JsScope parent, JsName name) {
this(parent, name, false);
}
/**
* Creates a function that is not derived from Dart source.
*/
public JsFunction(JsScope parent, JsName name) {
this(parent, name, false);
}
/**
* Creates a named function, possibly derived from Dart source.
*/
public JsFunction(JsScope parent, JsName name, boolean fromDart) {
assert (parent != null);
this.fromDart = fromDart;
setName(name);
String scopeName = (name == null) ? "<anonymous>" : name.getIdent();
scopeName = "function " + scopeName;
this.scope = new JsScope(parent, scopeName);
}
/**
* Creates a named function, possibly derived from Dart source.
*/
public JsFunction(JsScope parent, JsName name, boolean fromDart) {
assert (parent != null);
this.fromDart = fromDart;
setName(name);
String scopeName = (name == null) ? "<anonymous>" : name.getIdent();
scopeName = "function " + scopeName;
this.scope = new JsScope(parent, scopeName);
}
public JsBlock getBody() {
return body;
}
public JsBlock getBody() {
return body;
}
/**
* If true, this indicates that only the first invocation of the function will
* have any effects. Subsequent invocations may be considered to be no-op
* calls whose return value is ignored.
*/
public boolean getExecuteOnce() {
return executeOnce;
}
/**
* If true, this indicates that only the first invocation of the function will
* have any effects. Subsequent invocations may be considered to be no-op
* calls whose return value is ignored.
*/
public boolean getExecuteOnce() {
return executeOnce;
}
public JsFunction getImpliedExecute() {
return impliedExecute;
}
public JsFunction getImpliedExecute() {
return impliedExecute;
}
@Override
public JsName getName() {
return name;
}
@Override
public JsName getName() {
return name;
}
public void setParameters(List<JsParameter> params) {
this.params.clear();
this.params.addAll(params);
}
public List<JsParameter> getParameters() {
return params;
}
public JsScope getScope() {
return scope;
}
@Override
public boolean hasSideEffects() {
// If there's a name, the name is assigned to.
return name != null;
}
public boolean isArtificiallyRescued() {
return artificiallyRescued;
}
@Override
public boolean isBooleanFalse() {
return false;
}
@Override
public boolean isBooleanTrue() {
return true;
}
@Override
public boolean isDefinitelyNotNull() {
return true;
}
@Override
public boolean isDefinitelyNull() {
return false;
}
public boolean isFromDart() {
return fromDart;
}
public void setArtificiallyRescued(boolean rescued) {
this.artificiallyRescued = rescued;
}
public void setBody(JsBlock body) {
this.body = body;
}
public void setExecuteOnce(boolean executeOnce) {
this.executeOnce = executeOnce;
}
public void setFromDart(boolean fromDart) {
this.fromDart = fromDart;
}
public void setImpliedExecute(JsFunction impliedExecute) {
this.impliedExecute = impliedExecute;
}
public void setName(JsName name) {
this.name = name;
if (name != null) {
if (isFromDart()) {
name.setStaticRef(this);
}
public List<JsParameter> getParameters() {
return params;
}
}
public void setTrace() {
this.trace = true;
}
@Override
public void traverse(JsVisitor v, JsContext ctx) {
String before = null;
if (trace && v instanceof JsModVisitor) {
before = this.toSource();
if (traceFirst) {
traceFirst = false;
trace("SCRIPT INITIAL", before);
}
public JsScope getScope() {
return scope;
}
if (v.visit(this, ctx)) {
v.acceptWithInsertRemove(params);
body = v.accept(body);
@Override
public boolean hasSideEffects() {
// If there's a name, the name is assigned to.
return name != null;
}
v.endVisit(this, ctx);
if (trace && v instanceof JsModVisitor) {
String after = this.toSource();
if (!after.equals(before)) {
String title = v.getClass().getSimpleName();
trace(title, after);
}
public boolean isArtificiallyRescued() {
return artificiallyRescued;
}
}
public void setHoisted() {
hoisted = true;
}
@Override
public boolean isBooleanFalse() {
return false;
}
/** Whether the function has been hoisted */
public boolean isHoisted() {
return hoisted;
}
@Override
public boolean isBooleanTrue() {
return true;
}
/**
* Rebase the function to a new scope.
* @param newScopeParent The scope to add the function to.
*/
public void rebaseScope(JsScope newScopeParent) {
this.scope.rebase(newScopeParent);
}
@Override
public boolean isDefinitelyNotNull() {
return true;
}
@Override
public JsFunction setSourceRef(SourceInfo info) {
super.setSourceRef(info);
return this;
}
@Override
public boolean isDefinitelyNull() {
return false;
}
public boolean isConstructor() {
return this.constructor;
}
public boolean isFromDart() {
return fromDart;
}
public boolean setIsConstructor(boolean constructor) {
return this.constructor = constructor;
}
public void setArtificiallyRescued(boolean rescued) {
this.artificiallyRescued = rescued;
}
@Override
public NodeKind getKind() {
return NodeKind.FUNCTION;
}
public void setBody(JsBlock body) {
this.body = body;
}
public void setExecuteOnce(boolean executeOnce) {
this.executeOnce = executeOnce;
}
public void setFromDart(boolean fromDart) {
this.fromDart = fromDart;
}
public void setImpliedExecute(JsFunction impliedExecute) {
this.impliedExecute = impliedExecute;
}
public void setName(JsName name) {
this.name = name;
if (name != null) {
if (isFromDart()) {
name.setStaticRef(this);
}
}
}
public void setTrace() {
this.trace = true;
}
@Override
public void traverse(JsVisitor v, JsContext ctx) {
String before = null;
if (trace && v instanceof JsModVisitor) {
before = this.toSource();
if (traceFirst) {
traceFirst = false;
trace("SCRIPT INITIAL", before);
}
}
if (v.visit(this, ctx)) {
v.acceptWithInsertRemove(params);
body = v.accept(body);
}
v.endVisit(this, ctx);
if (trace && v instanceof JsModVisitor) {
String after = this.toSource();
if (!after.equals(before)) {
String title = v.getClass().getSimpleName();
trace(title, after);
}
}
}
public void setHoisted() {
hoisted = true;
}
/**
* Whether the function has been hoisted
*/
public boolean isHoisted() {
return hoisted;
}
/**
* Rebase the function to a new scope.
*
* @param newScopeParent The scope to add the function to.
*/
public void rebaseScope(JsScope newScopeParent) {
this.scope.rebase(newScopeParent);
}
@Override
public JsFunction setSourceRef(SourceInfo info) {
super.setSourceRef(info);
return this;
}
public boolean isConstructor() {
return this.constructor;
}
public boolean setIsConstructor(boolean constructor) {
return this.constructor = constructor;
}
@Override
public NodeKind getKind() {
return NodeKind.FUNCTION;
}
// Pavel Talanov
// dummy parameter to distinguish from other constructors
private JsFunction(Void dummy, JsScope functionScope) {
this.fromDart = false;
this.scope = functionScope;
}
public static JsFunction getAnonymousFunctionWithScope(JsScope scope) {
return new JsFunction(null, scope);
}
}
@@ -0,0 +1,36 @@
package org.jetbrains.k2js.declarations;
import com.google.dart.compiler.backend.js.ast.JsScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import java.util.HashMap;
import java.util.Map;
/**
* @author Talanov Pavel
*/
public final class DeclarationExtractor {
private final Map<DeclarationDescriptor, JsScope> descriptorToScopeMap
= new HashMap<DeclarationDescriptor, JsScope>();
public DeclarationExtractor() {
}
public void extractDeclarations(@NotNull DeclarationDescriptor descriptor, JsScope rootScope) {
ExtractionVisitor visitor = new ExtractionVisitor(this);
descriptor.accept(visitor, rootScope);
}
@NotNull
public JsScope getScope(@NotNull DeclarationDescriptor descriptor) {
JsScope scope = descriptorToScopeMap.get(descriptor);
assert scope != null : "Unknown declaration";
return scope;
}
/*package*/ void put(@NotNull DeclarationDescriptor descriptor, @NotNull JsScope scope) {
descriptorToScopeMap.put(descriptor, scope);
}
}
@@ -0,0 +1,65 @@
package org.jetbrains.k2js.declarations;
import com.google.dart.compiler.backend.js.ast.JsName;
import com.google.dart.compiler.backend.js.ast.JsScope;
import com.intellij.codeInspection.ex.Descriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.k2js.translate.Namer;
/**
* @author Talanov Pavel
*/
public final class ExtractionVisitor extends DeclarationDescriptorVisitor<Void, JsScope> {
@NotNull private final DeclarationExtractor extractor;
/*package*/ ExtractionVisitor(@NotNull DeclarationExtractor extractor) {
this.extractor = extractor;
}
@Override
public Void visitClassDescriptor(ClassDescriptor descriptor, JsScope enclosingScope) {
String className = descriptor.getName();
enclosingScope.declareName(className);
JsScope classScope = new JsScope(enclosingScope, "Scope for class " + className);
extractor.put(descriptor, classScope);
for (DeclarationDescriptor memberDescriptor :
descriptor.getDefaultType().getMemberScope().getAllDescriptors()) {
memberDescriptor.accept(this, classScope);
}
return null;
}
@Override
public Void visitFunctionDescriptor(FunctionDescriptor descriptor, JsScope enclosingScope) {
String functionName = descriptor.getName();
enclosingScope.declareName(functionName);
JsScope functionScope = new JsScope(enclosingScope, "Scope for function " + functionName);
extractor.put(descriptor, functionScope);
return null;
}
@Override
public Void visitPropertyDescriptor(PropertyDescriptor descriptor, JsScope enclosingScope) {
String propertyName = descriptor.getName();
enclosingScope.declareName(Namer.getNameForSetter(propertyName));
enclosingScope.declareName(Namer.getNameForGetter(propertyName));
return null;
}
@Override
public Void visitNamespaceDescriptor(NamespaceDescriptor descriptor, JsScope enclosingScope) {
String namespaceName = descriptor.getName();
enclosingScope.declareName(namespaceName);
JsScope namespaceScope = new JsScope(enclosingScope, "Scope for namespace " + namespaceName);
extractor.put(descriptor, namespaceScope);
for (DeclarationDescriptor memberDescriptor :
descriptor.getMemberScope().getAllDescriptors()) {
memberDescriptor.accept(this, namespaceScope);
}
return null;
}
}
@@ -0,0 +1,54 @@
package org.jetbrains.k2js.translate;
import com.intellij.codeInsight.hint.ClassDeclarationRangeHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetNamespace;
import org.jetbrains.jet.lang.resolve.BindingContext;
import javax.xml.ws.Binding;
/**
* @author Talanov Pavel
*
* This class contains some code related to BindingContext use. Intention is not to pollute other classes.
*/
public final class BindingUtils {
private BindingUtils() {}
//TODO generalise methods?
@NotNull
static public ClassDescriptor getClassDescriptor(@NotNull BindingContext context, @NotNull JetClass declaration) {
DeclarationDescriptor descriptor
= context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
assert descriptor instanceof ClassDescriptor : "Class should have a descriptor" +
" of type ClassDescriptor";
return (ClassDescriptor)descriptor;
}
@NotNull
static public NamespaceDescriptor getNamespaceDescriptor(@NotNull BindingContext context,
@NotNull JetNamespace declaration) {
DeclarationDescriptor descriptor
= context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
assert descriptor instanceof NamespaceDescriptor : "Namespace should have a descriptor" +
" of type NamespaceDescriptor";
return (NamespaceDescriptor)descriptor;
}
@NotNull
static public FunctionDescriptor getFunctionDescriptor(@NotNull BindingContext context,
@NotNull JetNamedFunction declaration) {
DeclarationDescriptor descriptor =
context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
assert descriptor instanceof FunctionDescriptor : "JetNamedFunction should have" +
" descriptor of type FunctionDescriptor.";
return (FunctionDescriptor)descriptor;
}
}
@@ -6,6 +6,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.types.JetType;
import java.util.ArrayList;
@@ -46,7 +47,8 @@ public final class ClassTranslator extends AbstractTranslator {
private JsObjectLiteral translateClassDeclarations(JetClass classDeclaration) {
List<JsPropertyInitializer> propertyList = new ArrayList<JsPropertyInitializer>();
propertyList.add(generateInitializeMethod(classDeclaration));
propertyList.addAll(classDeclaration.accept(classBodyVisitor, translationContext().newClass()));
propertyList.addAll(classDeclaration.accept(classBodyVisitor,
translationContext().newClass(classDeclaration)));
return new JsObjectLiteral(propertyList);
}
@@ -276,6 +276,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
return null;
}
//TODO method too long
@Override
@NotNull
public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
@@ -3,10 +3,14 @@ package org.jetbrains.k2js.translate;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.util.AstUtil;
import com.sun.istack.internal.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.resolve.BindingContext;
import javax.xml.ws.Binding;
import java.util.ArrayList;
import java.util.List;
@@ -36,8 +40,9 @@ public final class FunctionTranslator extends AbstractTranslator {
@NotNull
private JsFunction generateFunctionObject(@NotNull JetNamedFunction jetFunction) {
JetExpression jetBodyExpression = jetFunction.getBodyExpression();
JsFunction result = new JsFunction(scope());
JsNode jsBody = (new ExpressionTranslator(functionBodyContext(result)))
JsFunction result = JsFunction.getAnonymousFunctionWithScope
(translationContext().getScopeForElement(jetFunction));
JsNode jsBody = (new ExpressionTranslator(functionContext(jetFunction)))
.translate(jetBodyExpression);
List<JsParameter> jsParameters = translateParameters(jetFunction.getValueParameters(), result.getScope());
result.setParameters(jsParameters);
@@ -46,8 +51,10 @@ public final class FunctionTranslator extends AbstractTranslator {
}
@NotNull
private TranslationContext functionBodyContext(@NotNull JsFunction function) {
return translationContext().newFunction(function);
private TranslationContext functionContext(@NotNull JetNamedFunction jetFunction) {
FunctionDescriptor descriptor =
BindingUtils.getFunctionDescriptor(translationContext().bindingContext(), jetFunction);
return translationContext().newFunction(descriptor);
}
@NotNull
@@ -6,12 +6,18 @@ package org.jetbrains.k2js.translate;
import com.google.dart.compiler.backend.js.ast.JsProgram;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
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.declarations.DeclarationExtractor;
import javax.print.attribute.standard.MediaSize;
import javax.xml.ws.Binding;
import java.beans.beancontext.BeanContext;
import java.util.Collections;
import java.util.List;
@@ -21,19 +27,19 @@ public final class GenerationState {
public GenerationState() {
}
// public void compile(JetFile psiFile) {
// final JetNamespace namespace = psiFile.getRootNamespace();
// final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY);
// AnalyzingUtils.throwExceptionOnErrors(bindingContext);
// compileCorrectNamespaces(bindingContext, Collections.singletonList(namespace));
// }
//TODO method too long
public JsProgram compileCorrectNamespaces(BindingContext bindingContext, List<JetNamespace> namespaces) {
//TODO hardcoded
JsProgram result = new JsProgram("main");
JetNamespace namespace = namespaces.get(0);
(new NamespaceTranslator(TranslationContext.rootContext(result, bindingContext))).generateAst(namespace);
NamespaceDescriptor descriptor = BindingUtils.getNamespaceDescriptor(bindingContext, namespace);
DeclarationExtractor extractor = new DeclarationExtractor();
extractor.extractDeclarations(descriptor, result.getRootScope());
(new NamespaceTranslator(TranslationContext.rootContext(result, bindingContext, extractor)))
.generateAst(namespace);
return result;
}
}
@@ -23,14 +23,16 @@ public final class NamespaceTranslator extends AbstractTranslator {
return program();
}
//TODO logic unclear
@NotNull
public JsBlock translate(@NotNull JetNamespace namespace) {
// TODO support multiple namespaces
JsBlock block = program().getFragmentBlock(0);
JsName namespaceName = scope().declareName(Namer.getNameForNamespace(namespace.getName()));
block.addStatement(namespaceInitStatement(namespaceName));
JsFunction dummyFunction = new JsFunction(scope());
TranslationContext newContext = translationContext().newNamespace(namespaceName, dummyFunction);
TranslationContext newContext = translationContext().newNamespace(namespace);
JsFunction dummyFunction = JsFunction.getAnonymousFunctionWithScope
(translationContext().getScopeForElement(namespace));
JsBlock namespaceDeclarations = translateDeclarations(namespace, newContext);
block.addStatement(AstUtil.convertToStatement(newNamespace(namespaceName, namespaceDeclarations, dummyFunction)));
return block;
@@ -4,7 +4,16 @@ import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetNamespace;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.declarations.DeclarationExtractor;
/**
* @author Talanov Pavel
@@ -25,64 +34,79 @@ public final class TranslationContext {
}
@NotNull
public static TranslationContext rootContext(JsProgram program, BindingContext bindingContext) {
public static TranslationContext rootContext(@NotNull JsProgram program, @NotNull BindingContext bindingContext,
@NotNull DeclarationExtractor extractor) {
JsScope rootScope = program.getRootScope();
Scopes scopes = new Scopes(rootScope, rootScope, rootScope);
return new TranslationContext(null,
program, bindingContext, scopes);
return new TranslationContext(null, program, bindingContext, scopes, extractor);
}
@NotNull private final JsProgram program;
@NotNull private final BindingContext bindingContext;
@NotNull private final Scopes scopes;
@Nullable private final JsName currentNamespace;
@Nullable private final JsName namespaceName;
@NotNull private final DeclarationExtractor extractor;
private TranslationContext(@Nullable JsName currentNamespace, @NotNull JsProgram program,
@NotNull BindingContext bindingContext, @NotNull Scopes scopes) {
private TranslationContext(@Nullable JsName namespaceName, @NotNull JsProgram program,
@NotNull BindingContext bindingContext, @NotNull Scopes scopes,
@NotNull DeclarationExtractor extractor) {
this.program = program;
this.bindingContext = bindingContext;
this.currentNamespace = currentNamespace;
this.namespaceName = namespaceName;
this.scopes = scopes;
this.extractor = extractor;
}
@NotNull
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);
public TranslationContext newNamespace(@NotNull JetNamespace declaration) {
return newNamespace(BindingUtils.getNamespaceDescriptor(bindingContext, declaration));
}
@NotNull
public TranslationContext newNamespace(@NotNull NamespaceDescriptor descriptor) {
JsScope namespaceScope = extractor.getScope(descriptor);
JsName namespaceName = scopes.enclosingScope.findExistingName(descriptor.getName());
Scopes newScopes = new Scopes(namespaceScope, namespaceScope, namespaceScope);
return new TranslationContext(namespaceName, program, bindingContext, newScopes, extractor);
}
@NotNull
public TranslationContext newBlock() {
Scopes newScopes = new Scopes(new JsScope
(scopes.enclosingScope, "Scope for a block"), scopes.classScope, scopes.namespaceScope);
return new TranslationContext(currentNamespace, program,
bindingContext, newScopes);
return new TranslationContext(namespaceName, program, bindingContext, newScopes, extractor);
}
@NotNull
public TranslationContext newClass() {
JsScope classDummyScope = new JsScope(namespaceScope(), "Scope for a class");
Scopes newScopes = new Scopes(classDummyScope, classDummyScope, scopes.namespaceScope);
return new TranslationContext(currentNamespace, program,
bindingContext, newScopes);
TranslationContext newClass(@NotNull JetClass declaration) {
return newClass(BindingUtils.getClassDescriptor(bindingContext, declaration));
}
@NotNull
public TranslationContext newFunction(@NotNull JsFunction function) {
JsScope functionScope = function.getScope();
public TranslationContext newClass(@NotNull ClassDescriptor descriptor) {
JsScope classScope = extractor.getScope(descriptor);
Scopes newScopes = new Scopes(classScope, classScope, scopes.namespaceScope);
return new TranslationContext(namespaceName, program, bindingContext, newScopes, extractor);
}
@NotNull
TranslationContext newFunction(@NotNull JetNamedFunction declaration) {
return newFunction(BindingUtils.getFunctionDescriptor(bindingContext, declaration));
}
@NotNull
public TranslationContext newFunction(@NotNull FunctionDescriptor descriptor) {
JsScope functionScope = extractor.getScope(descriptor);
Scopes newScopes = new Scopes(functionScope, scopes.classScope, scopes.namespaceScope);
return new TranslationContext(currentNamespace, program,
bindingContext, newScopes);
return new TranslationContext(namespaceName, program, bindingContext, newScopes, extractor);
}
@NotNull
public JsNameRef getNamespaceQualifiedReference(JsName name) {
if (currentNamespace != null) {
return AstUtil.newNameRef(currentNamespace.makeRef(), name);
if (namespaceName != null) {
return AstUtil.newNameRef(namespaceName.makeRef(), name);
}
return new JsNameRef(name);
}
@@ -98,22 +122,34 @@ public final class TranslationContext {
}
@NotNull
JsScope enclosingScope() {
public JsScope enclosingScope() {
return scopes.enclosingScope;
}
@NotNull
JsScope namespaceScope() {
public JsScope namespaceScope() {
return scopes.namespaceScope;
}
@NotNull
JsScope classScope() {
public JsScope classScope() {
return scopes.classScope;
}
@NotNull
JsName declareLocalName(@NotNull String name) {
public JsName declareLocalName(@NotNull String name) {
return scopes.enclosingScope.declareFreshName(name);
}
@NotNull
public JsScope getScopeForDescriptor(@NotNull DeclarationDescriptor descriptor) {
return extractor.getScope(descriptor);
}
@NotNull
public JsScope getScopeForElement(@NotNull JetElement element) {
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
assert descriptor != null : "Element should have a descriptor";
return getScopeForDescriptor(descriptor);
}
}