├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── org.jsweet.feature ├── .project ├── build.properties └── feature.xml ├── org.jsweet.plugin ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── lib │ └── jsweet-transpiler-3.0.0-jar-with-dependencies.jar ├── plugin.xml └── src │ └── org │ └── jsweet │ └── plugin │ ├── JSweetPlugin.java │ ├── Log.java │ ├── builder │ ├── AddRemoveJSweetNatureHandler.java │ ├── BuildingContext.java │ ├── JSweetBuilder.java │ ├── JSweetConsts.java │ ├── JSweetNature.java │ └── JSweetTranspilationHandler.java │ └── preferences │ ├── FieldEditorProjectPreferencePage.java │ ├── JSweetPreferencePage.java │ ├── ListSelectorFieldEditor.java │ ├── PreferenceInitializer.java │ ├── Preferences.java │ └── ProjectPreferenceStore.java └── org.jsweet.update ├── .project └── site.xml /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | ## Your contributions 3 | 4 | Your contributions are most welcome. Bugs and features should be first reported in the Github issues space, so that we all know who is working on what, and so that we avoid duplicate efforts. 5 | 6 | ### Bug fixes 7 | 8 | Bug fixes should come with the corresponding test(s) if possible. 9 | 10 | ### Features 11 | 12 | Please make sure that contributed new features has been discussed thoroughly first (check out existing issues and the Wiki). It is important that they come with the appropriate test case(s) if possible. 13 | 14 | 15 | ## Contribution License Agreement 16 | 17 | By contributing through a pull request, you acknowledge that you fully own your Contribution and that you are legally entitled to make it available to the JSweet project under the terms and conditions of the Apache 2.0 license. This license implies that you grant the JSweet project, and those who receive the code directly or indirectly from the JSweet project, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the Contribution to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute your Contribution and such derivative works, and to sublicense any or all of the foregoing rights to third parties. 18 | 19 | Your execution and/or acceptance of this agreement does not influence any of your right and title to use and distribute your own Contribution. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Eclipse plugin for the [JSweet transpiler](https://github.com/cincheo/jsweet) 2 | 3 | ![screenshot](http://www.jsweet.org/wp-content/uploads/2015/11/Screen-Shot-2016-05-25-at-20.53.42.png) 4 | 5 | ## Installation 6 | 7 | - Under [Eclipse](https://eclipse.org/home/index.php), go to: `Help > Install New Software`. 8 | - Press the "Add..." button to add the JSweet.org update site. Update site URL: `http://eclipse-update-site.jsweet.org` 9 | - Follow the installation instructions (keep the default options) and restart Eclipse when prompted. 10 | 11 | ## How to start from the quick start project 12 | 13 | - Clone the [jsweet-quickstart](https://github.com/cincheo/jsweet-quickstart) project from Github and import it to your workspace. 14 | - Right click on your newly added project: `Properties > JSweet > Enable project specific settings`. Set the generated JavaScript folder to `target/js`. 15 | - Right click on your newly added project: `Configure > Enable JSweet builder`. 16 | - Clean the project: the `target/js` should be populated. 17 | - Right-click on `webapp/index.html` and choose `Open with > System editor`. If successful, your browser should popup an alert. 18 | 19 | -------------------------------------------------------------------------------- /org.jsweet.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jsweet.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.FeatureNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /org.jsweet.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml 2 | -------------------------------------------------------------------------------- /org.jsweet.feature/feature.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | JSweet is a way to create WEB applications using Javascript 11 | APIs with the Java syntax. 12 | 13 | 14 | 15 | Copyright 2014 Renaud Pawlak. 16 | 17 | 18 | 19 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 20 | You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 21 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and limitations under the License. 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /org.jsweet.plugin/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /org.jsweet.plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /org.jsweet.plugin/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jsweet.plugin 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /org.jsweet.plugin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | org.eclipse.jdt.core.formatter.align_type_members_on_columns=false 9 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 10 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 11 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 12 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 13 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 14 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 15 | org.eclipse.jdt.core.formatter.alignment_for_assignment=0 16 | org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 17 | org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 18 | org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 19 | org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 20 | org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 21 | org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 22 | org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 23 | org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 24 | org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 25 | org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 26 | org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 27 | org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 28 | org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 29 | org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 30 | org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 31 | org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 32 | org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 33 | org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 34 | org.eclipse.jdt.core.formatter.blank_lines_after_package=1 35 | org.eclipse.jdt.core.formatter.blank_lines_before_field=0 36 | org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 37 | org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 38 | org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 39 | org.eclipse.jdt.core.formatter.blank_lines_before_method=1 40 | org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 41 | org.eclipse.jdt.core.formatter.blank_lines_before_package=0 42 | org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 43 | org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 44 | org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line 45 | org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line 46 | org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line 47 | org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line 48 | org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line 49 | org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line 50 | org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line 51 | org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line 52 | org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line 53 | org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line 54 | org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line 55 | org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line 56 | org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false 57 | org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false 58 | org.eclipse.jdt.core.formatter.comment.format_block_comments=true 59 | org.eclipse.jdt.core.formatter.comment.format_header=false 60 | org.eclipse.jdt.core.formatter.comment.format_html=true 61 | org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true 62 | org.eclipse.jdt.core.formatter.comment.format_line_comments=true 63 | org.eclipse.jdt.core.formatter.comment.format_source_code=true 64 | org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true 65 | org.eclipse.jdt.core.formatter.comment.indent_root_tags=true 66 | org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert 67 | org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert 68 | org.eclipse.jdt.core.formatter.comment.line_length=80 69 | org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true 70 | org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true 71 | org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false 72 | org.eclipse.jdt.core.formatter.compact_else_if=true 73 | org.eclipse.jdt.core.formatter.continuation_indentation=2 74 | org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 75 | org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off 76 | org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on 77 | org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false 78 | org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true 79 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true 80 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true 81 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true 82 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true 83 | org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true 84 | org.eclipse.jdt.core.formatter.indent_empty_lines=false 85 | org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true 86 | org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true 87 | org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true 88 | org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false 89 | org.eclipse.jdt.core.formatter.indentation.size=4 90 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert 91 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert 92 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert 93 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert 94 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert 95 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert 96 | org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert 97 | org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert 98 | org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert 99 | org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert 100 | org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert 101 | org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert 102 | org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert 103 | org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert 104 | org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert 105 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert 106 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert 107 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert 108 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert 109 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert 110 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert 111 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert 112 | org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert 113 | org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert 114 | org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert 115 | org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert 116 | org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert 117 | org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert 118 | org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert 119 | org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert 120 | org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert 121 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert 122 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert 123 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert 124 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert 125 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert 126 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert 127 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert 128 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert 129 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert 130 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert 131 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert 132 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert 133 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert 134 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert 135 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert 136 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert 137 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert 138 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert 139 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert 140 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert 141 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert 142 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert 143 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert 144 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert 145 | org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert 146 | org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert 147 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert 148 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert 149 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert 150 | org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert 151 | org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert 152 | org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert 153 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert 154 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert 155 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert 156 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert 157 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert 158 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert 159 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert 160 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert 161 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert 162 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert 163 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert 164 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert 165 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert 166 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert 167 | org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert 168 | org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert 169 | org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert 170 | org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert 171 | org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert 172 | org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert 173 | org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert 174 | org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert 175 | org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert 176 | org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert 177 | org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert 178 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert 179 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert 180 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert 181 | org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert 182 | org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert 183 | org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert 184 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert 185 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert 186 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert 187 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert 188 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert 189 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert 190 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert 191 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert 192 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert 193 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert 194 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert 195 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert 196 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert 197 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert 198 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert 199 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert 200 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert 201 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert 202 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert 203 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert 204 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert 205 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert 206 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert 207 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert 208 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert 209 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert 210 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert 211 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert 212 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert 213 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert 214 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert 215 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert 216 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert 217 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert 218 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert 219 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert 220 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert 221 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert 222 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert 223 | org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert 224 | org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert 225 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert 226 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert 227 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert 228 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert 229 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert 230 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert 231 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert 232 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert 233 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert 234 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert 235 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert 236 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert 237 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert 238 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert 239 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert 240 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert 241 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert 242 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert 243 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert 244 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert 245 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert 246 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert 247 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert 248 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert 249 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert 250 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert 251 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert 252 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert 253 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert 254 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert 255 | org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert 256 | org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert 257 | org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert 258 | org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert 259 | org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert 260 | org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert 261 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert 262 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert 263 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert 264 | org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert 265 | org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert 266 | org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert 267 | org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert 268 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert 269 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert 270 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert 271 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert 272 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert 273 | org.eclipse.jdt.core.formatter.join_lines_in_comments=true 274 | org.eclipse.jdt.core.formatter.join_wrapped_lines=true 275 | org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false 276 | org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false 277 | org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false 278 | org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false 279 | org.eclipse.jdt.core.formatter.lineSplit=120 280 | org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false 281 | org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false 282 | org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 283 | org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 284 | org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true 285 | org.eclipse.jdt.core.formatter.tabulation.char=tab 286 | org.eclipse.jdt.core.formatter.tabulation.size=4 287 | org.eclipse.jdt.core.formatter.use_on_off_tags=false 288 | org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false 289 | org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true 290 | org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true 291 | org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true 292 | -------------------------------------------------------------------------------- /org.jsweet.plugin/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | formatter_profile=_JSweet 3 | formatter_settings_version=12 4 | -------------------------------------------------------------------------------- /org.jsweet.plugin/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: JSweet 4 | Bundle-SymbolicName: org.jsweet.plugin;singleton:=true 5 | Bundle-Version: 0.9.6.20190421 6 | Bundle-Activator: org.jsweet.plugin.JSweetPlugin 7 | Bundle-Vendor: JSweet 8 | Require-Bundle: org.eclipse.ui, 9 | org.eclipse.core.runtime, 10 | org.eclipse.core.resources, 11 | org.eclipse.jdt.core, 12 | org.eclipse.ui.ide, 13 | org.eclipse.jdt.ui 14 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 15 | Bundle-ActivationPolicy: lazy 16 | Bundle-ClassPath: lib/jsweet-transpiler-3.0.0-jar-with-dependencies.jar, 17 | external:$JAVA_HOME$/../lib/tools.jar, 18 | external:$JAVA_HOME$/lib/tools.jar, 19 | external:$JAVA_HOME$/../Classes/classes.jar, 20 | external:$JAVA_HOME$/Classes/classes.jar, 21 | external:$java.home$/../lib/tools.jar, 22 | external:$java.home$/lib/tools.jar, 23 | external:$java.home$/../Classes/classes.jar, 24 | external:$java.home$/Classes/classes.jar, 25 | . 26 | Eclipse-BundleShape: dir 27 | -------------------------------------------------------------------------------- /org.jsweet.plugin/build.properties: -------------------------------------------------------------------------------- 1 | output.. = bin/ 2 | bin.includes = plugin.xml,\ 3 | META-INF/,\ 4 | .,\ 5 | lib/jsweet-transpiler-3.0.0-jar-with-dependencies.jar 6 | source.. = src/ 7 | -------------------------------------------------------------------------------- /org.jsweet.plugin/lib/jsweet-transpiler-3.0.0-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cincheo/jsweet-eclipse-plugin/5aac78da9471f2665b299836a485d35dbf1c6b54/org.jsweet.plugin/lib/jsweet-transpiler-3.0.0-jar-with-dependencies.jar -------------------------------------------------------------------------------- /org.jsweet.plugin/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 11 | 13 | 14 | 15 | 16 | 20 | 21 | 23 | 24 | 25 | 27 | 28 | 29 | 31 | 34 | 35 | 40 | 41 | 42 | 44 | 46 | 50 | 52 | 54 | 56 | 57 | 58 | 60 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 73 | 75 | 77 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 100 | 102 | 103 | 105 | 106 | 107 | 109 | 113 | 114 | 115 | 117 | 119 | 120 | 121 | 123 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/JSweetPlugin.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin; 2 | 3 | import org.eclipse.jface.resource.ImageDescriptor; 4 | import org.eclipse.ui.plugin.AbstractUIPlugin; 5 | import org.osgi.framework.BundleContext; 6 | 7 | /** 8 | * The activator class controls the plug-in life cycle 9 | */ 10 | public class JSweetPlugin extends AbstractUIPlugin { 11 | 12 | // The plug-in ID 13 | public static final String ID = "org.jsweet.plugin"; //$NON-NLS-1$ 14 | 15 | // The shared instance 16 | private static JSweetPlugin plugin; 17 | 18 | /** 19 | * The constructor 20 | */ 21 | public JSweetPlugin() { 22 | } 23 | 24 | @Override 25 | public void start(BundleContext context) throws Exception { 26 | super.start(context); 27 | plugin = this; 28 | } 29 | 30 | @Override 31 | public void stop(BundleContext context) throws Exception { 32 | plugin = null; 33 | super.stop(context); 34 | } 35 | 36 | /** 37 | * Returns the shared instance 38 | * 39 | * @return the shared instance 40 | */ 41 | public static JSweetPlugin getDefault() { 42 | return plugin; 43 | } 44 | 45 | /** 46 | * Returns an image descriptor for the image file at the given plug-in 47 | * relative path 48 | * 49 | * @param path 50 | * the path 51 | * @return the image descriptor 52 | */ 53 | public static ImageDescriptor getImageDescriptor(String path) { 54 | return imageDescriptorFromPlugin(ID, path); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin; 17 | 18 | import org.eclipse.core.runtime.Status; 19 | 20 | public class Log { 21 | 22 | private Log() { 23 | } 24 | 25 | public static void info(String msg) { 26 | log(Status.INFO, msg, null); 27 | } 28 | 29 | public static void error(String msg, Throwable t) { 30 | log(Status.ERROR, msg, t); 31 | } 32 | 33 | public static void error(Throwable t) { 34 | log(Status.ERROR, t.getMessage(), t); 35 | } 36 | 37 | public static void error(String msg) { 38 | log(Status.ERROR, msg, null); 39 | } 40 | 41 | public static void warning(String msg, Throwable t) { 42 | log(Status.WARNING, msg, t); 43 | } 44 | 45 | public static void warning(Throwable t) { 46 | log(Status.WARNING, t.getMessage(), t); 47 | } 48 | 49 | public static void warning(String msg) { 50 | log(Status.WARNING, msg, null); 51 | } 52 | 53 | public static void log(int severity, String msg, Throwable t) { 54 | JSweetPlugin.getDefault().getLog().log(new Status(severity, JSweetPlugin.ID, Status.OK, msg, t)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/builder/AddRemoveJSweetNatureHandler.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin.builder; 2 | 3 | import java.util.Iterator; 4 | 5 | import org.eclipse.core.commands.AbstractHandler; 6 | import org.eclipse.core.commands.ExecutionEvent; 7 | import org.eclipse.core.commands.ExecutionException; 8 | import org.eclipse.core.resources.IProject; 9 | import org.eclipse.core.resources.IProjectDescription; 10 | import org.eclipse.core.runtime.CoreException; 11 | import org.eclipse.core.runtime.IAdaptable; 12 | import org.eclipse.jface.viewers.ISelection; 13 | import org.eclipse.jface.viewers.IStructuredSelection; 14 | import org.eclipse.ui.handlers.HandlerUtil; 15 | 16 | public class AddRemoveJSweetNatureHandler extends AbstractHandler { 17 | 18 | @Override 19 | public Object execute(ExecutionEvent event) throws ExecutionException { 20 | ISelection selection = HandlerUtil.getCurrentSelection(event); 21 | if (selection instanceof IStructuredSelection) { 22 | for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { 23 | Object element = it.next(); 24 | IProject project = null; 25 | if (element instanceof IProject) { 26 | project = (IProject) element; 27 | } else if (element instanceof IAdaptable) { 28 | project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); 29 | } 30 | if (project != null) { 31 | try { 32 | toggleNature(project); 33 | } catch (CoreException e) { 34 | throw new ExecutionException("Failed to toggle nature", e); 35 | } 36 | } 37 | } 38 | } 39 | 40 | return null; 41 | } 42 | 43 | /** 44 | * Toggles JSweet nature on a project 45 | * 46 | * @param project 47 | * to have JSweet nature added or removed 48 | */ 49 | private void toggleNature(IProject project) throws CoreException { 50 | // Shortcut: project not accessible 51 | if (!project.isAccessible()) 52 | return; 53 | 54 | IProjectDescription description = project.getDescription(); 55 | String[] natures = description.getNatureIds(); 56 | 57 | for (int i = 0; i < natures.length; ++i) { 58 | if (JSweetNature.ID.equals(natures[i])) { 59 | // Remove the nature 60 | String[] newNatures = new String[natures.length - 1]; 61 | System.arraycopy(natures, 0, newNatures, 0, i); 62 | System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1); 63 | description.setNatureIds(newNatures); 64 | project.setDescription(description, null); 65 | JSweetBuilder.clean(project, null); 66 | return; 67 | } 68 | } 69 | 70 | // Add the nature 71 | String[] newNatures = new String[natures.length + 1]; 72 | System.arraycopy(natures, 0, newNatures, 0, natures.length); 73 | newNatures[natures.length] = JSweetNature.ID; 74 | description.setNatureIds(newNatures); 75 | project.setDescription(description, null); 76 | JSweetBuilder.clean(project, null); 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/builder/BuildingContext.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin.builder; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.eclipse.core.resources.IProject; 8 | import org.jsweet.transpiler.JSweetTranspiler; 9 | import org.jsweet.transpiler.SourceFile; 10 | 11 | class BuildingContext { 12 | public final String profile; 13 | public final IProject project; 14 | // watch mode does not work (yet?) under Windows, so we do not use it 15 | public boolean useWatchMode = false; 16 | public final Map sourceFiles = new HashMap<>(); 17 | public JSweetTranspiler transpiler; 18 | 19 | public BuildingContext(final IProject project, final String profile) { 20 | this.project = project; 21 | this.profile = profile; 22 | } 23 | } -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/builder/JSweetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin.builder; 17 | 18 | import java.io.File; 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import org.apache.commons.io.FileUtils; 25 | import org.apache.commons.lang3.StringUtils; 26 | import org.eclipse.core.resources.IFile; 27 | import org.eclipse.core.resources.IProject; 28 | import org.eclipse.core.resources.IResource; 29 | import org.eclipse.core.resources.IResourceDelta; 30 | import org.eclipse.core.resources.IResourceDeltaVisitor; 31 | import org.eclipse.core.resources.IResourceVisitor; 32 | import org.eclipse.core.resources.IWorkspace; 33 | import org.eclipse.core.resources.IncrementalProjectBuilder; 34 | import org.eclipse.core.resources.ResourcesPlugin; 35 | import org.eclipse.core.runtime.CoreException; 36 | import org.eclipse.core.runtime.IPath; 37 | import org.eclipse.core.runtime.IProgressMonitor; 38 | import org.eclipse.core.runtime.IStatus; 39 | import org.eclipse.core.runtime.Status; 40 | import org.eclipse.core.runtime.jobs.Job; 41 | import org.eclipse.core.runtime.preferences.InstanceScope; 42 | import org.eclipse.jdt.core.IClasspathEntry; 43 | import org.eclipse.jdt.core.ICompilationUnit; 44 | import org.eclipse.jdt.core.IJavaProject; 45 | import org.eclipse.jdt.core.IPackageFragment; 46 | import org.eclipse.jdt.core.IType; 47 | import org.eclipse.jdt.core.JavaCore; 48 | import org.eclipse.jdt.core.JavaModelException; 49 | import org.eclipse.jdt.ui.PreferenceConstants; 50 | import org.eclipse.jface.preference.IPreferenceStore; 51 | import org.eclipse.ui.preferences.ScopedPreferenceStore; 52 | import org.jsweet.JSweetConfig; 53 | import org.jsweet.plugin.Log; 54 | import org.jsweet.plugin.preferences.Preferences; 55 | import org.jsweet.transpiler.EcmaScriptComplianceLevel; 56 | import org.jsweet.transpiler.JSweetFactory; 57 | import org.jsweet.transpiler.JSweetProblem; 58 | import org.jsweet.transpiler.JSweetTranspiler; 59 | import org.jsweet.transpiler.ModuleKind; 60 | import org.jsweet.transpiler.SourceFile; 61 | import org.jsweet.transpiler.util.Util.Static; 62 | 63 | public class JSweetBuilder extends IncrementalProjectBuilder { 64 | 65 | public static final String ID = "org.jsweet.plugin.jsweetBuilder"; 66 | 67 | private static boolean hasFile(File folder) { 68 | if (folder.isDirectory()) { 69 | File[] files = folder.listFiles(); 70 | if (files != null) { 71 | for (File file : folder.listFiles()) { 72 | if (file.isFile()) { 73 | return true; 74 | } else { 75 | return hasFile(file); 76 | } 77 | } 78 | } 79 | } 80 | return false; 81 | } 82 | 83 | private static void cleanFiles(BuildingContext context) throws CoreException { 84 | try { 85 | context.project.deleteMarkers(JSweetConsts.JSWEET_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_INFINITE); 86 | File tsOutDir = new File(context.project.getLocation().toFile(), 87 | Preferences.getTsOutputFolder(context.project, context.profile)); 88 | List files = new ArrayList<>(); 89 | if (tsOutDir.exists()) { 90 | Static.addFiles(".ts", tsOutDir, files); 91 | for (File f : files) { 92 | FileUtils.deleteQuietly(f); 93 | } 94 | if (!hasFile(tsOutDir)) { 95 | FileUtils.deleteQuietly(tsOutDir); 96 | } 97 | } 98 | files.clear(); 99 | File jsOutDir = new File(context.project.getLocation().toFile(), 100 | Preferences.getJsOutputFolder(context.project, context.profile)); 101 | if (jsOutDir.exists()) { 102 | Static.addFiles(".js", jsOutDir, files); 103 | Static.addFiles(".js.map", jsOutDir, files); 104 | for (File f : files) { 105 | FileUtils.deleteQuietly(f); 106 | } 107 | if (!hasFile(jsOutDir)) { 108 | FileUtils.deleteQuietly(jsOutDir); 109 | } 110 | } 111 | context.project.refreshLocal(IResource.DEPTH_INFINITE, null); 112 | } catch (NoClassDefFoundError e) { 113 | e.printStackTrace(); 114 | Log.error(e); 115 | } 116 | } 117 | 118 | public static void clean(IProject project, IProgressMonitor monitor) throws CoreException { 119 | // adds processed class directory to the build path to ensure that 120 | // mixins are available 121 | File tmp = project.getLocation().append(JSweetTranspiler.TMP_WORKING_DIR_NAME).toFile(); 122 | FileUtils.deleteQuietly(tmp); 123 | // delete markers set and files created 124 | for (String profile : Preferences.parseProfiles(project)) { 125 | cleanFiles(new BuildingContext(project, profile)); 126 | } 127 | } 128 | 129 | @Override 130 | protected void clean(final IProgressMonitor monitor) throws CoreException { 131 | clean(getProject(), monitor); 132 | } 133 | 134 | /** 135 | * Forces a full clean/rebuild of all the workspace projects that have the 136 | * JSweet nature. 137 | */ 138 | public static void rebuildWorkspace() { 139 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); 140 | rebuildProjects(Arrays.asList(workspace.getRoot().getProjects())); 141 | } 142 | 143 | /** 144 | * Forces a full clean of all the workspace projects that have the JSweet 145 | * nature. 146 | */ 147 | public static void cleanWorkspace() { 148 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); 149 | cleanProjects(Arrays.asList(workspace.getRoot().getProjects())); 150 | } 151 | 152 | /** 153 | * Forces a full clean rebuild of the given JSweet project. 154 | * 155 | * @param project 156 | */ 157 | public static void rebuildProject(IProject project) { 158 | rebuildProjects(Arrays.asList(project)); 159 | } 160 | 161 | /** 162 | * Forces a clean of the given JSweet project. 163 | * 164 | * @param project 165 | */ 166 | public static void cleanProject(IProject project) { 167 | rebuildProjects(Arrays.asList(project)); 168 | } 169 | 170 | private static void rebuildProjects(final List projects) { 171 | String name = "rebuild";// Resources.BUNDLE.getString("preferences.compiler.rebuild.job.name"); 172 | Job job = new Job(name) { 173 | @Override 174 | protected IStatus run(IProgressMonitor monitor) { 175 | try { 176 | for (IProject project : projects) { 177 | if (project.isAccessible() && project.hasNature(JSweetNature.ID)) { 178 | project.build(IncrementalProjectBuilder.CLEAN_BUILD, JSweetBuilder.ID, null, monitor); 179 | project.build(IncrementalProjectBuilder.FULL_BUILD, JSweetBuilder.ID, null, monitor); 180 | } 181 | } 182 | return Status.OK_STATUS; 183 | } catch (CoreException e) { 184 | return e.getStatus(); 185 | } 186 | } 187 | }; 188 | job.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); 189 | job.schedule(); 190 | } 191 | 192 | private static void cleanProjects(final List projects) { 193 | String name = "clean";// Resources.BUNDLE.getString("preferences.compiler.rebuild.job.name"); 194 | Job job = new Job(name) { 195 | @Override 196 | protected IStatus run(IProgressMonitor monitor) { 197 | try { 198 | for (IProject project : projects) { 199 | if (project.isOpen() && project.hasNature(JSweetNature.ID)) { 200 | project.build(IncrementalProjectBuilder.CLEAN_BUILD, JSweetBuilder.ID, null, monitor); 201 | } 202 | } 203 | return Status.OK_STATUS; 204 | } catch (CoreException e) { 205 | return e.getStatus(); 206 | } 207 | } 208 | }; 209 | job.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); 210 | job.schedule(); 211 | } 212 | 213 | class IncrementalGrabJavaFileVisitor implements IResourceDeltaVisitor { 214 | private IJavaProject project; 215 | private BuildingContext context; 216 | public List javaFiles = new ArrayList<>(); 217 | public List javaResourceFiles = new ArrayList<>(); 218 | 219 | public IncrementalGrabJavaFileVisitor(IJavaProject project, BuildingContext context) { 220 | this.project = project; 221 | this.context = context; 222 | } 223 | 224 | private void grabJavaFileHierarchy(IResource resource) throws JavaModelException, CoreException { 225 | IFile resourceFile = (IFile) resource; 226 | File file = new File(resource.getProject().getLocation().toFile(), 227 | resourceFile.getProjectRelativePath().toFile().toString()); 228 | if (!javaFiles.contains(file) // 229 | && isIncluded(context, resourceFile.getProjectRelativePath())) { 230 | javaFiles.add(file); 231 | javaResourceFiles.add(resourceFile); 232 | IPackageFragment packge = project.findPackageFragment(resource.getParent().getFullPath()); 233 | if (packge != null && packge.getCompilationUnits() != null) { 234 | for (ICompilationUnit cu : packge.getCompilationUnits()) { 235 | if (cu.getResource().equals(resource)) { 236 | for (IType t1 : cu.getAllTypes()) { 237 | for (IType t2 : t1.newTypeHierarchy(project, null).getAllTypes()) { 238 | IResource r = t2.getResource(); 239 | if (r instanceof IFile && resource.getName().endsWith(".java")) { 240 | resourceFile = (IFile) r; 241 | file = new File(r.getProject().getLocation().toFile(), 242 | resourceFile.getProjectRelativePath().toFile().toString()); 243 | if (!javaFiles.contains(file) // 244 | && isIncluded(context, r.getProjectRelativePath())) { 245 | javaFiles.add(file); 246 | javaResourceFiles.add(resourceFile); 247 | } 248 | } 249 | } 250 | 251 | } 252 | } 253 | } 254 | } 255 | } 256 | } 257 | 258 | @Override 259 | public boolean visit(IResourceDelta delta) throws CoreException { 260 | IResource resource = delta.getResource(); 261 | if (resource instanceof IFile && resource.getName().endsWith(".java")) { 262 | switch (delta.getKind()) { 263 | case IResourceDelta.ADDED: 264 | if (context.useWatchMode && context.transpiler != null) { 265 | context.transpiler.resetTscWatchMode(); 266 | } 267 | grabJavaFileHierarchy(resource); 268 | break; 269 | case IResourceDelta.REMOVED: 270 | deleteMarkers((IFile) resource); 271 | SourceFile sf; 272 | if (context.useWatchMode && context.transpiler != null) { 273 | File file = new File(resource.getProject().getLocation().toFile(), 274 | ((IFile) resource).getProjectRelativePath().toFile().toString()); 275 | sf = context.transpiler.getWatchedFile(file); 276 | context.transpiler.resetTscWatchMode(); 277 | } else { 278 | File file = new File(resource.getProject().getLocation().toFile(), 279 | ((IFile) resource).getProjectRelativePath().toFile().toString()); 280 | sf = context.sourceFiles.get(file); 281 | context.sourceFiles.remove(file); 282 | } 283 | if (sf != null) { 284 | File tsFile = sf.getTsFile(); 285 | File jsFile = sf.getJsFile(); 286 | File jsMapFile = sf.getJsFile(); 287 | FileUtils.deleteQuietly(tsFile); 288 | FileUtils.deleteQuietly(jsFile); 289 | FileUtils.deleteQuietly(jsMapFile); 290 | } 291 | break; 292 | case IResourceDelta.CHANGED: 293 | grabJavaFileHierarchy(resource); 294 | break; 295 | default: 296 | // return true to continue visiting children. 297 | return true; 298 | } 299 | } 300 | // return true to continue visiting children. 301 | return true; 302 | } 303 | } 304 | 305 | private static boolean isIncluded(BuildingContext context, IPath path) { 306 | if (!StringUtils.isBlank(Preferences.getSourceIncludeFilter(context.project, context.profile))) { 307 | if (!path.toString().matches(Preferences.getSourceIncludeFilter(context.project, context.profile))) { 308 | Log.info("excluded by included filer: " + path); 309 | return false; 310 | } 311 | } 312 | if (!StringUtils.isBlank(Preferences.getSourceExcludeFilter(context.project, context.profile))) { 313 | if (path.toString().matches(Preferences.getSourceExcludeFilter(context.project, context.profile))) { 314 | Log.info("excluded by excluded filer: " + path); 315 | return false; 316 | } 317 | } 318 | Log.info("include: " + path); 319 | return true; 320 | } 321 | 322 | private static class GrabJavaFilesVisitor implements IResourceVisitor { 323 | private BuildingContext context; 324 | public List javaFiles = new ArrayList<>(); 325 | public List sourceDirs; 326 | 327 | public GrabJavaFilesVisitor(BuildingContext context, List sourceDirs) { 328 | this.context = context; 329 | this.sourceDirs = sourceDirs; 330 | } 331 | 332 | @Override 333 | public boolean visit(IResource resource) { 334 | if (resource instanceof IFile && resource.getName().endsWith(".java")) { 335 | IFile file = (IFile) resource; 336 | if (file.getProjectRelativePath().segment(0).equals(JSweetTranspiler.TMP_WORKING_DIR_NAME)) { 337 | return true; 338 | } 339 | if (!sourceDirs.isEmpty()) { 340 | for (IPath sourcePath : sourceDirs) { 341 | if (sourcePath.isPrefixOf(file.getFullPath())) { 342 | IPath relativePath = file.getFullPath().makeRelativeTo(sourcePath); 343 | if (isIncluded(context, relativePath)) { 344 | javaFiles.add(new File(resource.getProject().getLocation().toFile(), 345 | file.getProjectRelativePath().toFile().toString())); 346 | } 347 | return true; 348 | } 349 | } 350 | } else { 351 | if (isIncluded(context, file.getProjectRelativePath())) { 352 | javaFiles.add(new File(resource.getProject().getLocation().toFile(), 353 | file.getProjectRelativePath().toFile().toString())); 354 | } 355 | } 356 | } 357 | // return true to continue visiting children. 358 | return true; 359 | } 360 | } 361 | 362 | @Override 363 | protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { 364 | // Only full builds are supported for now... incremental builds should 365 | // be supported later if possible 366 | 367 | // addResourceChangeListener(); 368 | // if (!USE_WATCH_MODE || kind == FULL_BUILD) { 369 | // fullBuild(monitor); 370 | // } else { 371 | // IResourceDelta delta = getDelta(getProject()); 372 | // if (delta == null) { 373 | // fullBuild(monitor); 374 | // } else { 375 | // incrementalBuild(delta, monitor); 376 | // } 377 | // } 378 | for (String profile : Preferences.parseProfiles(getProject())) { 379 | fullBuild(new BuildingContext(getProject(), profile), monitor); 380 | } 381 | forceStaticImports(); 382 | return null; 383 | } 384 | 385 | private void forceStaticImports() { 386 | try { 387 | IPreferenceStore s = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.jdt.ui"); 388 | String favorites = s.getString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS); 389 | for (String f : JSweetConsts.DEFAULT_FAVORITES) { 390 | if (!favorites.contains(f)) { 391 | if (!favorites.isEmpty()) { 392 | favorites += ";"; 393 | } 394 | favorites += f; 395 | } 396 | } 397 | Log.info("forcing favorite static members: " + favorites); 398 | s.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, favorites); 399 | } catch (Exception e) { 400 | Log.error(e); 401 | } 402 | } 403 | 404 | private void deleteMarkers(IFile... files) { 405 | try { 406 | for (IFile file : files) { 407 | file.deleteMarkers(JSweetConsts.JSWEET_PROBLEM_MARKER_TYPE, false, IResource.DEPTH_ZERO); 408 | } 409 | } catch (CoreException ce) { 410 | Log.error(ce); 411 | } 412 | } 413 | 414 | private void transpileFiles(BuildingContext context, File... files) { 415 | try { 416 | if (context.transpiler == null || files == null || files.length == 0) { 417 | return; 418 | } 419 | Log.info("compiling " + Arrays.asList(files)); 420 | SourceFile[] sfs = SourceFile.toSourceFiles(files); 421 | for (SourceFile sf : sfs) { 422 | context.sourceFiles.put(sf.getJavaFile(), sf); 423 | } 424 | context.transpiler.transpile(new JSweetTranspilationHandler(context), sfs); 425 | } catch (Throwable t) { 426 | Log.error("cannot compile", t); 427 | } 428 | } 429 | 430 | private void fullBuild(BuildingContext context, final IProgressMonitor monitor) throws CoreException { 431 | Log.info("JSweet: full build..."); 432 | context.project.deleteMarkers(JSweetConsts.JSWEET_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_INFINITE); 433 | List sourceDirs = new ArrayList<>(); 434 | if (!StringUtils.isEmpty(Preferences.getSourceFolders(context.project, context.profile))) { 435 | String[] names = Preferences.getSourceFolders(context.project, context.profile).split("[,;]"); 436 | try { 437 | for (String name : names) { 438 | sourceDirs.add(context.project.getFolder(name).getFullPath()); 439 | } 440 | } catch (Exception e) { 441 | e.printStackTrace(); 442 | Log.error(e); 443 | } 444 | } 445 | String jdkHome = null; 446 | boolean lookupSourceFolder = sourceDirs.isEmpty(); 447 | if (context.project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { 448 | IJavaProject javaProject = JavaCore.create(context.project); 449 | IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true); 450 | for (IClasspathEntry e : classPathEntries) { 451 | if (lookupSourceFolder && e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { 452 | sourceDirs.add(e.getPath()); 453 | } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { 454 | if (e.getPath().toString().endsWith("/lib/rt.jar") || e.getPath().toString().endsWith( 455 | "/lib/jrt-fs.jar")) { 456 | jdkHome = e.getPath().removeLastSegments(2).toString(); 457 | } 458 | } 459 | } 460 | } 461 | Log.info("source dirs: " + sourceDirs); 462 | GrabJavaFilesVisitor v = new GrabJavaFilesVisitor(context, sourceDirs); 463 | 464 | context.project.accept(v); 465 | context.sourceFiles.clear(); 466 | Log.info("init classpath, jdkHome: " + jdkHome); 467 | // TODO to fix? method removed 468 | // JSweetConfig.jinitClassPath(jdkHome); 469 | createJSweetTranspiler(context); 470 | transpileFiles(context, v.javaFiles.toArray(new File[0])); 471 | } 472 | 473 | private class CheckIfRemovedInDelta implements IResourceDeltaVisitor { 474 | public boolean result = false; 475 | 476 | @Override 477 | public boolean visit(IResourceDelta delta) throws CoreException { 478 | if (delta.getKind() == IResourceDelta.REMOVED) { 479 | result = true; 480 | } 481 | return true; 482 | } 483 | } 484 | 485 | protected void incrementalBuild(BuildingContext context, IResourceDelta delta, IProgressMonitor monitor) 486 | throws CoreException { 487 | if (context.project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { 488 | Log.info("JSweet: incremental build..."); 489 | CheckIfRemovedInDelta removed = new CheckIfRemovedInDelta(); 490 | delta.accept(removed); 491 | if (removed.result) { 492 | // we should delete only the removed file 493 | cleanFiles(context); 494 | fullBuild(context, monitor); 495 | } else { 496 | IJavaProject javaProject = JavaCore.create(context.project); 497 | IncrementalGrabJavaFileVisitor v = new IncrementalGrabJavaFileVisitor(javaProject, context); 498 | delta.accept(v); 499 | deleteMarkers(v.javaResourceFiles.toArray(new IFile[0])); 500 | context.project.deleteMarkers(JSweetConsts.JSWEET_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_ZERO); 501 | if (context.transpiler == null) { 502 | createJSweetTranspiler(context); 503 | } 504 | transpileFiles(context, v.javaFiles.toArray(new File[0])); 505 | } 506 | } else { 507 | // no support for incremental build 508 | fullBuild(context, monitor); 509 | } 510 | 511 | } 512 | 513 | private void createJSweetTranspiler(BuildingContext context) throws CoreException { 514 | if (context.useWatchMode && context.transpiler != null) { 515 | Log.info("stopping tsc watch mode"); 516 | context.transpiler.setTscWatchMode(false); 517 | Log.info("tsc watch mode stopped"); 518 | } 519 | StringBuilder classPath = new StringBuilder(); 520 | if (context.project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { 521 | IJavaProject javaProject = JavaCore.create(context.project); 522 | IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true); 523 | for (IClasspathEntry e : classPathEntries) { 524 | classPath.append(resolve(context.project, e.getPath()).toString()); 525 | classPath.append(File.pathSeparator); 526 | } 527 | } 528 | Log.info("compiling with classpath: " + classPath.toString()); 529 | File jsOutputFolder = new File(context.project.getLocation().toFile(), 530 | Preferences.getJsOutputFolder(context.project, context.profile)); 531 | try { 532 | JSweetFactory factory = new JSweetFactory(); 533 | Log.info("creating transpiler with configuration file: " 534 | + new File(context.project.getLocation().toFile(), "jsweetconfig.json")); 535 | context.transpiler = new JSweetTranspiler( 536 | new File(context.project.getLocation().toFile(), "jsweetconfig.json"), factory, 537 | new File(context.project.getLocation().toFile(), JSweetTranspiler.TMP_WORKING_DIR_NAME), 538 | new File(context.project.getLocation().toFile(), 539 | Preferences.getTsOutputFolder(context.project, context.profile)), 540 | jsOutputFolder, 541 | new File(context.project.getLocation().toFile(), 542 | Preferences.getCandyJsOutputFolder(context.project, context.profile)), 543 | classPath.toString()); 544 | context.transpiler.setGenerateJsFiles(!Preferences.getNoJs(context.project, context.profile)); 545 | context.transpiler.setDebugMode(Preferences.isDebugMode(context.project, context.profile)); 546 | String moduleString = Preferences.getModuleKind(context.project, context.profile); 547 | context.transpiler.setModuleKind( 548 | StringUtils.isBlank(moduleString) ? ModuleKind.none : ModuleKind.valueOf(moduleString)); 549 | 550 | String ecmaTargetVersionString = Preferences.getEcmaTargetVersion(context.project, context.profile); 551 | context.transpiler 552 | .setEcmaTargetVersion(StringUtils.isBlank(ecmaTargetVersionString) ? EcmaScriptComplianceLevel.ES5 553 | : EcmaScriptComplianceLevel.valueOf(ecmaTargetVersionString)); 554 | 555 | String bundleDirectory = Preferences.getBundlesDirectory(context.project, context.profile); 556 | if (!StringUtils.isBlank(bundleDirectory) && Preferences.getBundle(context.project, context.profile)) { 557 | File f = new File(bundleDirectory); 558 | if (!f.isAbsolute()) { 559 | f = new File(context.project.getLocation().toFile(), bundleDirectory); 560 | } 561 | context.transpiler.setJsOutputDir(f); 562 | } 563 | context.transpiler.setBundle(Preferences.getBundle(context.project, context.profile)); 564 | context.transpiler.setGenerateDeclarations(Preferences.getDeclaration(context.project, context.profile)); 565 | String declarationDirectory = Preferences.getDeclarationDirectory(context.project, context.profile); 566 | if (!StringUtils.isBlank(declarationDirectory)) { 567 | File f = new File(declarationDirectory); 568 | if (!f.isAbsolute()) { 569 | f = new File(context.project.getLocation().toFile(), declarationDirectory); 570 | } 571 | context.transpiler.setDeclarationsOutputDir(f); 572 | } 573 | 574 | // transpiler.setTsDefDirs(new 575 | // File(context.project.getLocation().toFile(), 576 | // Preferences 577 | // .getTsOutputFolder(context.project))); 578 | if (context.useWatchMode) { 579 | context.transpiler.setTscWatchMode(true); 580 | } 581 | Log.info("created JSweet transpiler: " + context.transpiler); 582 | } catch (NoClassDefFoundError error) { 583 | new JSweetTranspilationHandler(context).report(JSweetProblem.JAVA_COMPILER_NOT_FOUND, null, 584 | JSweetProblem.JAVA_COMPILER_NOT_FOUND.getMessage()); 585 | } 586 | } 587 | 588 | private static File resolve(IProject project, IPath path) { 589 | String string = path.toString(); 590 | if (path.isAbsolute()) { 591 | File f = new File(string); 592 | if (f.exists()) { 593 | return f; 594 | } else { 595 | return new File(project.getWorkspace().getRoot().getLocation().toFile(), string); 596 | } 597 | } else { 598 | return new File(project.getLocation().toFile(), string); 599 | } 600 | } 601 | 602 | } 603 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/builder/JSweetConsts.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin.builder; 2 | 3 | import org.jsweet.JSweetConfig; 4 | 5 | final class JSweetConsts { 6 | public static final String JSWEET_PROBLEM_MARKER_TYPE = "org.jsweet.plugin.jsweetProblem"; 7 | 8 | public static final String[] DEFAULT_FAVORITES = { 9 | JSweetConfig.LANG_PACKAGE + "." + JSweetConfig.GLOBALS_CLASS_NAME + ".*", 10 | JSweetConfig.UTIL_CLASSNAME + ".*", JSweetConfig.DOM_PACKAGE + "." + JSweetConfig.GLOBALS_CLASS_NAME + ".*", 11 | JSweetConfig.LIBS_PACKAGE + ".jquery." + JSweetConfig.GLOBALS_CLASS_NAME + ".*", 12 | JSweetConfig.LIBS_PACKAGE + ".underscore." + JSweetConfig.GLOBALS_CLASS_NAME + ".*" }; 13 | 14 | private JSweetConsts() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/builder/JSweetNature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin.builder; 17 | 18 | import org.eclipse.core.resources.ICommand; 19 | import org.eclipse.core.resources.IProject; 20 | import org.eclipse.core.resources.IProjectDescription; 21 | import org.eclipse.core.resources.IProjectNature; 22 | import org.eclipse.core.runtime.CoreException; 23 | import org.jsweet.plugin.Log; 24 | 25 | public class JSweetNature implements IProjectNature { 26 | 27 | /** 28 | * ID of this project nature 29 | */ 30 | public static final String ID = "org.jsweet.plugin.jsweetNature"; 31 | 32 | private IProject project; 33 | 34 | @Override 35 | public void configure() throws CoreException { 36 | Log.info("configure JSweet nature"); 37 | IProjectDescription desc = project.getDescription(); 38 | ICommand[] commands = desc.getBuildSpec(); 39 | 40 | for (int i = 0; i < commands.length; ++i) { 41 | if (commands[i].getBuilderName().equals(JSweetBuilder.ID)) { 42 | return; 43 | } 44 | } 45 | 46 | ICommand[] newCommands = new ICommand[commands.length + 1]; 47 | System.arraycopy(commands, 0, newCommands, 0, commands.length); 48 | ICommand command = desc.newCommand(); 49 | command.setBuilderName(JSweetBuilder.ID); 50 | newCommands[newCommands.length - 1] = command; 51 | desc.setBuildSpec(newCommands); 52 | project.setDescription(desc, null); 53 | } 54 | 55 | @Override 56 | public void deconfigure() throws CoreException { 57 | IProjectDescription description = getProject().getDescription(); 58 | ICommand[] commands = description.getBuildSpec(); 59 | for (int i = 0; i < commands.length; ++i) { 60 | if (commands[i].getBuilderName().equals(JSweetBuilder.ID)) { 61 | JSweetBuilder.clean(getProject(), null); 62 | ICommand[] newCommands = new ICommand[commands.length - 1]; 63 | System.arraycopy(commands, 0, newCommands, 0, i); 64 | System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); 65 | description.setBuildSpec(newCommands); 66 | project.setDescription(description, null); 67 | return; 68 | } 69 | } 70 | } 71 | 72 | @Override 73 | public IProject getProject() { 74 | return project; 75 | } 76 | 77 | @Override 78 | public void setProject(IProject project) { 79 | Log.info("JSweet nature: set project"); 80 | this.project = project; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/builder/JSweetTranspilationHandler.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin.builder; 2 | 3 | import org.eclipse.core.resources.IFile; 4 | import org.eclipse.core.resources.IMarker; 5 | import org.eclipse.core.resources.IResource; 6 | import org.eclipse.core.runtime.CoreException; 7 | import org.jsweet.plugin.Log; 8 | import org.jsweet.plugin.preferences.Preferences; 9 | import org.jsweet.transpiler.JSweetProblem; 10 | import org.jsweet.transpiler.JSweetTranspiler; 11 | import org.jsweet.transpiler.Severity; 12 | import org.jsweet.transpiler.SourceFile; 13 | import org.jsweet.transpiler.SourcePosition; 14 | import org.jsweet.transpiler.TranspilationHandler; 15 | 16 | class JSweetTranspilationHandler implements TranspilationHandler { 17 | 18 | private final BuildingContext context; 19 | 20 | public JSweetTranspilationHandler(BuildingContext context) { 21 | this.context = context; 22 | } 23 | 24 | @Override 25 | public void report(JSweetProblem problem, SourcePosition sourcePosition, String message) { 26 | if (problem == JSweetProblem.INTERNAL_JAVA_ERROR || isIgnoredErrorMessage(message)) { 27 | // ignore Java errors because they will be reported by Eclipse 28 | return; 29 | } 30 | String base = context.project.getLocation().toFile().getAbsolutePath(); 31 | if (sourcePosition == null || sourcePosition.getFile() == null) { 32 | addMarker(context.project, message, -1, -1, -1, 33 | problem.getSeverity() == Severity.ERROR ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING); 34 | } else { 35 | IFile f = null; 36 | try { 37 | final String sourcePosAbsolutePath = sourcePosition.getFile().getAbsolutePath(); 38 | if (base.length() + 1 < sourcePosAbsolutePath.length()) { 39 | f = (IFile) context.project.findMember(sourcePosAbsolutePath.substring(base.length() + 1)); 40 | } 41 | } catch (Exception e) { 42 | Log.error(message, e); 43 | // swallow 44 | } 45 | if (f == null) { 46 | try { 47 | f = (IFile) context.project.findMember(sourcePosition.getFile().getPath()); 48 | } catch (Exception e) { 49 | Log.error(message, e); 50 | // swallow 51 | } 52 | } 53 | if (f == null) { 54 | addMarker(context.project, message, -1, -1, -1, 55 | problem.getSeverity() == Severity.ERROR ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING); 56 | } else { 57 | addMarker(f, message, sourcePosition.getStartLine(), sourcePosition.getStartPosition().getPosition(), 58 | sourcePosition.getEndPosition().getPosition(), 59 | problem.getSeverity() == Severity.ERROR ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING); 60 | } 61 | } 62 | } 63 | 64 | private boolean isIgnoredErrorMessage(final String message) { 65 | final String msg = message.toLowerCase(); 66 | return msg.equals("duplicate identifier 'booleancondition'") 67 | || msg.startsWith("namespace 'java' has no exported member"); 68 | } 69 | 70 | @Override 71 | public void onCompleted(JSweetTranspiler transpiler, boolean fullPass, SourceFile[] files) { 72 | try { 73 | if (fullPass) { 74 | Log.info("refreshing worspace (full)"); 75 | context.project.refreshLocal(IResource.DEPTH_INFINITE, null); 76 | } else { 77 | // TODO: refresh only the resources that have changed (using 78 | // the files argument) 79 | Log.info("refreshing output directories (incremental)"); 80 | final IResource output = context.project 81 | .findMember(Preferences.getTsOutputFolder(context.project, context.profile)); 82 | final IResource jsOutput = context.project 83 | .findMember(Preferences.getJsOutputFolder(context.project, context.profile)); 84 | if (output != null || jsOutput != null) { 85 | new Thread() { 86 | @Override 87 | public void run() { 88 | try { 89 | if (output != null) { 90 | output.refreshLocal(IResource.DEPTH_INFINITE, null); 91 | } 92 | if (jsOutput != null && !jsOutput.equals(output)) { 93 | jsOutput.refreshLocal(IResource.DEPTH_INFINITE, null); 94 | } 95 | } catch (CoreException e) { 96 | Log.error("error while refreshing", e); 97 | } 98 | } 99 | }.start(); 100 | } 101 | } 102 | 103 | } catch (Exception e) { 104 | Log.error(e); 105 | } 106 | } 107 | 108 | private void addMarker(IResource resource, String message, int lineNumber, int charStart, int charEnd, 109 | int severity) { 110 | try { 111 | IMarker marker = resource.createMarker(JSweetConsts.JSWEET_PROBLEM_MARKER_TYPE); 112 | marker.setAttribute(IMarker.MESSAGE, message); 113 | marker.setAttribute(IMarker.SEVERITY, severity); 114 | if (lineNumber >= 0) { 115 | marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); 116 | } 117 | if (charStart >= 0) { 118 | marker.setAttribute(IMarker.CHAR_START, charStart); 119 | } 120 | if (charEnd >= 0) { 121 | marker.setAttribute(IMarker.CHAR_END, charEnd); 122 | } 123 | } catch (CoreException e) { 124 | Log.error(e); 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/preferences/FieldEditorProjectPreferencePage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin.preferences; 17 | 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import org.eclipse.core.resources.IProject; 25 | import org.eclipse.core.runtime.IAdaptable; 26 | import org.eclipse.jface.preference.FieldEditor; 27 | import org.eclipse.jface.preference.FieldEditorPreferencePage; 28 | import org.eclipse.jface.preference.IPreferenceNode; 29 | import org.eclipse.jface.preference.IPreferencePage; 30 | import org.eclipse.jface.preference.IPreferenceStore; 31 | import org.eclipse.jface.preference.PreferenceDialog; 32 | import org.eclipse.jface.preference.PreferenceManager; 33 | import org.eclipse.jface.preference.PreferenceNode; 34 | import org.eclipse.swt.SWT; 35 | import org.eclipse.swt.custom.BusyIndicator; 36 | import org.eclipse.swt.events.SelectionAdapter; 37 | import org.eclipse.swt.events.SelectionEvent; 38 | import org.eclipse.swt.layout.GridData; 39 | import org.eclipse.swt.layout.GridLayout; 40 | import org.eclipse.swt.widgets.Button; 41 | import org.eclipse.swt.widgets.Composite; 42 | import org.eclipse.swt.widgets.Control; 43 | import org.eclipse.swt.widgets.Label; 44 | import org.eclipse.swt.widgets.Link; 45 | import org.eclipse.ui.IWorkbenchPropertyPage; 46 | 47 | /** 48 | * A field editor preference page that can also be used as a property page. 49 | *

50 | * Adapted from 51 | * http://www.eclipse.org/articles/Article-Mutatis-mutandis/overlay-pages.html. 52 | *

53 | * Adapted from the TypeScript Eclipse plugin (author: dcicerone). 54 | */ 55 | abstract class FieldEditorProjectPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage { 56 | 57 | private final List fields = new ArrayList<>(); 58 | protected final Map fieldMap = new HashMap<>(); 59 | private Link configureWorkspaceLink; 60 | private IAdaptable element; 61 | private ProjectPreferenceStore projectPreferenceStore; 62 | private Button projectSpecificCheckbox; 63 | 64 | protected FieldEditorProjectPreferencePage(final int style) { 65 | super(style); 66 | } 67 | 68 | @Override 69 | public IAdaptable getElement() { 70 | return element; 71 | } 72 | 73 | @Override 74 | public void setElement(final IAdaptable element) { 75 | this.element = element; 76 | } 77 | 78 | protected abstract String getPreferenceNodeId(); 79 | 80 | protected abstract String getSentinelPropertyName(); 81 | 82 | @Override 83 | protected Control createContents(final Composite parent) { 84 | if (isPropertyPage()) { // properties page 85 | final Composite composite = new Composite(parent, SWT.NONE); 86 | final GridLayout layout = new GridLayout(2, false); 87 | layout.marginWidth = 0; 88 | layout.marginHeight = 0; 89 | composite.setLayout(layout); 90 | composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 91 | // enable project specific settings 92 | projectSpecificCheckbox = new Button(composite, SWT.CHECK); 93 | projectSpecificCheckbox.setFont(parent.getFont()); 94 | projectSpecificCheckbox.setSelection(projectPreferenceStore.getProjectSpecificSettings()); 95 | projectSpecificCheckbox.setText("Enable project specific settings"); 96 | projectSpecificCheckbox.addSelectionListener(new SelectionAdapter() { 97 | @Override 98 | public void widgetSelected(final SelectionEvent e) { 99 | final boolean projectSpecific = isProjectSpecific(); 100 | projectPreferenceStore.setProjectSpecificSettings(projectSpecific); 101 | configureWorkspaceLink.setEnabled(!projectSpecific); 102 | updateFieldEditors(); 103 | } 104 | }); 105 | // configure workspace settings 106 | configureWorkspaceLink = new Link(composite, SWT.NONE); 107 | configureWorkspaceLink.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); 108 | configureWorkspaceLink.setText("Configure Workspace Settings..."); 109 | configureWorkspaceLink.addSelectionListener(new SelectionAdapter() { 110 | @Override 111 | public void widgetSelected(final SelectionEvent e) { 112 | configureWorkspaceSettings(); 113 | } 114 | }); 115 | // horizontal separator 116 | final Label horizontalSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); 117 | horizontalSeparator.setLayoutData(new GridData(GridData.FILL, SWT.TOP, true, false, 2, 1)); 118 | } 119 | return super.createContents(parent); 120 | } 121 | 122 | @Override 123 | public void createControl(final Composite parent) { 124 | if (isPropertyPage()) { 125 | final IProject project = element.getAdapter(IProject.class); 126 | final String sentinelPropertyName = getSentinelPropertyName(); 127 | projectPreferenceStore = new ProjectPreferenceStore(project, super.getPreferenceStore(), 128 | sentinelPropertyName); 129 | } 130 | super.createControl(parent); 131 | if (isPropertyPage()) { 132 | updateFieldEditors(); 133 | } 134 | } 135 | 136 | @Override 137 | public IPreferenceStore getPreferenceStore() { 138 | if (projectPreferenceStore != null) 139 | return projectPreferenceStore; 140 | return super.getPreferenceStore(); 141 | } 142 | 143 | @Override 144 | protected void addField(final FieldEditor editor) { 145 | fields.add(editor); 146 | fieldMap.put(editor.getPreferenceName(), editor); 147 | super.addField(editor); 148 | } 149 | 150 | protected final boolean isPageEnabled() { 151 | return !isPropertyPage() || isProjectSpecific(); 152 | } 153 | 154 | protected final boolean isPropertyPage() { 155 | return element != null; 156 | } 157 | 158 | protected final boolean isProjectSpecific() { 159 | return isPropertyPage() && projectSpecificCheckbox.getSelection(); 160 | } 161 | 162 | @Override 163 | protected void performDefaults() { 164 | if (isPropertyPage()) { 165 | projectSpecificCheckbox.setSelection(false); 166 | configureWorkspaceLink.setEnabled(false); 167 | updateFieldEditors(); 168 | } 169 | super.performDefaults(); 170 | } 171 | 172 | protected void updateFieldEditors() { 173 | final boolean pageEnabled = isPageEnabled(); 174 | final Composite parent = getFieldEditorParent(); 175 | for (final FieldEditor field : fields) { 176 | field.setEnabled(pageEnabled, parent); 177 | } 178 | } 179 | 180 | private void configureWorkspaceSettings() { 181 | final String preferenceNodeId = getPreferenceNodeId(); 182 | final IPreferencePage preferencePage = newPreferencePage(); 183 | final IPreferenceNode preferenceNode = new PreferenceNode(preferenceNodeId, preferencePage); 184 | final PreferenceManager manager = new PreferenceManager(); 185 | manager.addToRoot(preferenceNode); 186 | final PreferenceDialog dialog = new PreferenceDialog(getControl().getShell(), manager); 187 | BusyIndicator.showWhile(this.getControl().getDisplay(), new Runnable() { 188 | @Override 189 | public void run() { 190 | dialog.create(); 191 | dialog.setMessage(preferenceNode.getLabelText()); 192 | dialog.open(); 193 | } 194 | }); 195 | } 196 | 197 | private IPreferencePage newPreferencePage() { 198 | try { 199 | final IPreferencePage preferencePage = this.getClass().getConstructor().newInstance(); 200 | preferencePage.setTitle(getTitle()); 201 | return preferencePage; 202 | } catch (IllegalAccessException e) { 203 | throw new RuntimeException(e); 204 | } catch (InstantiationException e) { 205 | throw new RuntimeException(e); 206 | } catch (IllegalArgumentException e) { 207 | throw new RuntimeException(e); 208 | } catch (InvocationTargetException e) { 209 | throw new RuntimeException(e); 210 | } catch (NoSuchMethodException e) { 211 | throw new RuntimeException(e); 212 | } catch (SecurityException e) { 213 | throw new RuntimeException(e); 214 | } 215 | } 216 | 217 | public List getFields() { 218 | return fields; 219 | } 220 | 221 | @SuppressWarnings("unchecked") 222 | public T getField(final String preferenceName) { 223 | return (T) fieldMap.get(preferenceName); 224 | } 225 | 226 | } 227 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/preferences/JSweetPreferencePage.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin.preferences; 2 | 3 | import static org.jsweet.plugin.preferences.Preferences.DEFAULT_PROFILE_NAME; 4 | 5 | import java.util.Map.Entry; 6 | 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.eclipse.core.resources.IProject; 9 | import org.eclipse.jface.dialogs.IDialogConstants; 10 | import org.eclipse.jface.dialogs.IInputValidator; 11 | import org.eclipse.jface.dialogs.InputDialog; 12 | import org.eclipse.jface.dialogs.MessageDialog; 13 | import org.eclipse.jface.preference.BooleanFieldEditor; 14 | import org.eclipse.jface.preference.ComboFieldEditor; 15 | import org.eclipse.jface.preference.FieldEditor; 16 | import org.eclipse.jface.preference.FieldEditorPreferencePage; 17 | import org.eclipse.jface.preference.IPreferenceStore; 18 | import org.eclipse.jface.preference.StringFieldEditor; 19 | import org.eclipse.jface.util.PropertyChangeEvent; 20 | import org.eclipse.jface.window.Window; 21 | import org.eclipse.swt.SWT; 22 | import org.eclipse.swt.events.SelectionAdapter; 23 | import org.eclipse.swt.events.SelectionEvent; 24 | import org.eclipse.swt.layout.GridData; 25 | import org.eclipse.swt.layout.RowLayout; 26 | import org.eclipse.swt.widgets.Button; 27 | import org.eclipse.swt.widgets.Composite; 28 | import org.eclipse.swt.widgets.Label; 29 | import org.eclipse.ui.IWorkbench; 30 | import org.eclipse.ui.IWorkbenchPreferencePage; 31 | import org.jsweet.plugin.JSweetPlugin; 32 | import org.jsweet.plugin.builder.JSweetBuilder; 33 | 34 | public final class JSweetPreferencePage extends FieldEditorProjectPreferencePage implements IWorkbenchPreferencePage { 35 | private boolean compilerPreferencesModified; 36 | private Button createProfile; 37 | private Button deleteProfile; 38 | private String currentProfile = DEFAULT_PROFILE_NAME; 39 | ListSelectorFieldEditor profileSelector; 40 | 41 | public JSweetPreferencePage() { 42 | super(FieldEditorPreferencePage.GRID); 43 | } 44 | 45 | @Override 46 | public void init(IWorkbench workbench) { 47 | } 48 | 49 | @Override 50 | public boolean performOk() { 51 | final boolean process; 52 | // offer to rebuild the workspace if the compiler preferences were 53 | // modified 54 | if (this.compilerPreferencesModified) { 55 | String title = "JSweet"; 56 | String message = "Changing configuration requires a full build. Do you want to start a build now?"; 57 | String[] buttonLabels = new String[] { IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL, 58 | IDialogConstants.YES_LABEL }; 59 | MessageDialog dialog = new MessageDialog(this.getShell(), title, null, message, MessageDialog.QUESTION, 60 | buttonLabels, 2); 61 | int result = dialog.open(); 62 | if (result == 1) { // cancel 63 | process = false; 64 | } else { 65 | // yes/no 66 | process = super.performOk(); 67 | // rebuild the workspace 68 | if (result == 2) { 69 | if (this.isPropertyPage()) { 70 | IProject project = (IProject) this.getElement().getAdapter(IProject.class); 71 | JSweetBuilder.cleanProject(project); 72 | } else { 73 | JSweetBuilder.cleanWorkspace(); 74 | } 75 | } 76 | } 77 | this.compilerPreferencesModified = false; 78 | } else { 79 | process = super.performOk(); 80 | } 81 | return process; 82 | } 83 | 84 | @Override 85 | public void propertyChange(PropertyChangeEvent event) { 86 | super.propertyChange(event); 87 | Object source = event.getSource(); 88 | if (event.getProperty().equals(FieldEditor.VALUE)) { 89 | this.updateFieldEditors(); 90 | } 91 | if (getFields().contains(source)) { 92 | this.compilerPreferencesModified = true; 93 | } 94 | } 95 | 96 | private void applyProfile(String profile) { 97 | currentProfile = profile; 98 | for (Entry entry : fieldMap.entrySet()) { 99 | if (Preferences.profiles().equals(entry.getKey())) { 100 | continue; 101 | } 102 | entry.getValue().setPreferenceName(Preferences.getProfilePrefix(currentProfile) + entry.getKey()); 103 | entry.getValue().load(); 104 | } 105 | } 106 | 107 | @Override 108 | protected void createFieldEditors() { 109 | if (this.isPropertyPage()) { 110 | this.addField(profileSelector = new ListSelectorFieldEditor(Preferences.profiles(), "Profile", 111 | getFieldEditorParent())); 112 | profileSelector.getCombo().addSelectionListener(new SelectionAdapter() { 113 | @Override 114 | public void widgetSelected(SelectionEvent e) { 115 | applyProfile(profileSelector.getCombo().getText()); 116 | updateFieldEditors(); 117 | } 118 | }); 119 | Composite composite = new Composite(getFieldEditorParent(), SWT.NONE); 120 | composite.setLayoutData(new GridData(GridData.END, SWT.TOP, true, true, 2, 1)); 121 | RowLayout rl = new RowLayout(); 122 | rl.marginBottom = rl.marginHeight = rl.marginLeft = rl.marginRight = 0; 123 | composite.setLayout(rl); 124 | createProfile = new Button(composite, SWT.PUSH); 125 | createProfile.setFont(getFieldEditorParent().getFont()); 126 | createProfile.setText("Create new profile"); 127 | createProfile.addSelectionListener(new SelectionAdapter() { 128 | @Override 129 | public void widgetSelected(SelectionEvent e) { 130 | InputDialog d = new InputDialog(null, "Create new profile", "Enter a profile name", "", 131 | new IInputValidator() { 132 | @Override 133 | public String isValid(String name) { 134 | if (name.matches("[a-zA-Z0-9]")) { 135 | return name; 136 | } else { 137 | return null; 138 | } 139 | } 140 | }); 141 | if (d.open() == Window.OK) { 142 | if (!StringUtils.isBlank(d.getValue())) { 143 | profileSelector.addValue(d.getValue()); 144 | applyProfile(d.getValue()); 145 | updateFieldEditors(); 146 | } 147 | } 148 | } 149 | }); 150 | deleteProfile = new Button(composite, SWT.PUSH); 151 | deleteProfile.setFont(getFieldEditorParent().getFont()); 152 | deleteProfile.setText("Delete current profile"); 153 | deleteProfile.addSelectionListener(new SelectionAdapter() { 154 | @Override 155 | public void widgetSelected(SelectionEvent e) { 156 | if (MessageDialog.openConfirm(null, "Delete current profile", 157 | "Do you really want to delete '" + currentProfile + "'?")) { 158 | profileSelector.removeValue(currentProfile); 159 | applyProfile(DEFAULT_PROFILE_NAME); 160 | updateFieldEditors(); 161 | } 162 | } 163 | }); 164 | 165 | Label horizontalSeparator = new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL); 166 | horizontalSeparator.setLayoutData(new GridData(GridData.FILL, SWT.TOP, true, false, 2, 1)); 167 | 168 | } 169 | 170 | addField(new StringFieldEditor(Preferences.srcDirs(DEFAULT_PROFILE_NAME), 171 | "Source folders (project ones if empty)", getFieldEditorParent())); 172 | addField(new StringFieldEditor(Preferences.srcIncludeFilter(DEFAULT_PROFILE_NAME), // 173 | "Include filter (regexp)", getFieldEditorParent())); 174 | addField(new StringFieldEditor(Preferences.srcExcludeFilter(DEFAULT_PROFILE_NAME), // 175 | "Exclude filter (regexp)", getFieldEditorParent())); 176 | addField(new StringFieldEditor(Preferences.tsOutputDir(DEFAULT_PROFILE_NAME), // 177 | "Generated TypeScript folder", getFieldEditorParent())); 178 | addField(new BooleanFieldEditor(Preferences.noJs(DEFAULT_PROFILE_NAME), // 179 | "Do not generate JavaScript", getFieldEditorParent())); 180 | addField(new StringFieldEditor(Preferences.jsOutputDir(DEFAULT_PROFILE_NAME), // 181 | "Generated Javascript folder", getFieldEditorParent())); 182 | addField(new StringFieldEditor(Preferences.candyJsOutputDir(DEFAULT_PROFILE_NAME), 183 | "Candies-extracted JavaScript folder", getFieldEditorParent())); 184 | addField(new BooleanFieldEditor(Preferences.bundle(DEFAULT_PROFILE_NAME), // 185 | "Create browser bundle", getFieldEditorParent())); 186 | addField(new StringFieldEditor(Preferences.bundlesDir(DEFAULT_PROFILE_NAME), 187 | "Bundle folder (in-place bundle if empty)", getFieldEditorParent())); 188 | addField(new BooleanFieldEditor(Preferences.declaration(DEFAULT_PROFILE_NAME), 189 | "Generate TypeScript definitions", getFieldEditorParent())); 190 | addField(new StringFieldEditor(Preferences.declarationDir(DEFAULT_PROFILE_NAME), 191 | "Definitions folder (in-place if empty)", getFieldEditorParent())); 192 | addField(new BooleanFieldEditor(Preferences.debugMode(DEFAULT_PROFILE_NAME), 193 | "Debug mode (generate '.js.map' files)", getFieldEditorParent())); 194 | addField(new ComboFieldEditor(Preferences.moduleKind(DEFAULT_PROFILE_NAME), // 195 | "Module kind", new String[][] { // 196 | new String[] { "none", "none" }, // 197 | new String[] { "es2015", "es2015" }, // 198 | new String[] { "commonjs", "commonjs" }, // 199 | new String[] { "amd", "amd" }, // 200 | new String[] { "system", "system" }, // 201 | new String[] { "umd", "umd" } }, // 202 | getFieldEditorParent())); 203 | 204 | addField(new ComboFieldEditor(Preferences.ecmaTargetVersion(DEFAULT_PROFILE_NAME), // 205 | "Target ECMA version", new String[][] { // 206 | new String[] { "ES6", "ES6" }, // 207 | new String[] { "ES5", "ES5" }, // 208 | new String[] { "ES3", "ES3" } // 209 | }, getFieldEditorParent())); 210 | } 211 | 212 | @Override 213 | protected IPreferenceStore doGetPreferenceStore() { 214 | return JSweetPlugin.getDefault().getPreferenceStore(); 215 | } 216 | 217 | @Override 218 | protected String getPreferenceNodeId() { 219 | return "org.jsweet.jsweetPreferencePage"; 220 | } 221 | 222 | @Override 223 | protected String getSentinelPropertyName() { 224 | return Preferences.tsOutputDir(DEFAULT_PROFILE_NAME); 225 | } 226 | 227 | @Override 228 | protected void initialize() { 229 | super.initialize(); 230 | this.updateFieldEditors(); 231 | } 232 | 233 | @Override 234 | protected void performDefaults() { 235 | super.performDefaults(); 236 | this.updateFieldEditors(); 237 | } 238 | 239 | @Override 240 | protected void updateFieldEditors() { 241 | super.updateFieldEditors(); 242 | // update editor states if needed 243 | if (isPageEnabled()) { 244 | Composite parent = getFieldEditorParent(); 245 | BooleanFieldEditor bundle = this.getField(Preferences.bundle(DEFAULT_PROFILE_NAME)); 246 | StringFieldEditor bundlesDirectory = this.getField(Preferences.bundlesDir(DEFAULT_PROFILE_NAME)); 247 | ComboFieldEditor module = this.getField(Preferences.moduleKind(DEFAULT_PROFILE_NAME)); 248 | if (bundle.getBooleanValue()) { 249 | getPreferenceStore().setValue(Preferences.moduleKind(currentProfile), "none"); 250 | module.load(); 251 | } 252 | module.setEnabled(!bundle.getBooleanValue(), parent); 253 | bundlesDirectory.setEnabled(bundle.getBooleanValue(), parent); 254 | 255 | BooleanFieldEditor declaration = this.getField(Preferences.declaration(DEFAULT_PROFILE_NAME)); 256 | StringFieldEditor declarationDirectory = this.getField(Preferences.declarationDir(DEFAULT_PROFILE_NAME)); 257 | declarationDirectory.setEnabled(declaration.getBooleanValue(), parent); 258 | 259 | } 260 | 261 | } 262 | 263 | } 264 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/preferences/ListSelectorFieldEditor.java: -------------------------------------------------------------------------------- 1 | package org.jsweet.plugin.preferences; 2 | 3 | import org.apache.commons.lang3.ArrayUtils; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.eclipse.jface.preference.FieldEditor; 6 | import org.eclipse.swt.SWT; 7 | import org.eclipse.swt.layout.GridData; 8 | import org.eclipse.swt.widgets.Combo; 9 | import org.eclipse.swt.widgets.Composite; 10 | import org.eclipse.swt.widgets.Control; 11 | 12 | /** 13 | * A field editor for a list of semicolon-separated strings, which allows for a 14 | * combo box selection. 15 | */ 16 | public class ListSelectorFieldEditor extends FieldEditor { 17 | 18 | private Combo combo; 19 | 20 | private String[] values; 21 | 22 | /** 23 | * Create the field editor. 24 | * 25 | * @param name 26 | * the name of the preference this field editor works on 27 | * @param labelText 28 | * the label text of the field editor 29 | * @param parent 30 | * the parent composite 31 | */ 32 | public ListSelectorFieldEditor(String name, String labelText, Composite parent) { 33 | init(name, labelText); 34 | createControl(parent); 35 | } 36 | 37 | /* 38 | * (non-Javadoc) 39 | * 40 | * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int) 41 | */ 42 | @Override 43 | protected void adjustForNumColumns(int numColumns) { 44 | if (numColumns > 1) { 45 | Control control = getLabelControl(); 46 | int left = numColumns; 47 | if (control != null) { 48 | ((GridData) control.getLayoutData()).horizontalSpan = 1; 49 | left = left - 1; 50 | } 51 | ((GridData) combo.getLayoutData()).horizontalSpan = left; 52 | } else { 53 | Control control = getLabelControl(); 54 | if (control != null) { 55 | ((GridData) control.getLayoutData()).horizontalSpan = 1; 56 | } 57 | ((GridData) combo.getLayoutData()).horizontalSpan = 1; 58 | } 59 | } 60 | 61 | /* 62 | * (non-Javadoc) 63 | * 64 | * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt. widgets.Composite, int) 65 | */ 66 | @Override 67 | protected void doFillIntoGrid(Composite parent, int numColumns) { 68 | int comboC = 1; 69 | if (numColumns > 1) { 70 | comboC = numColumns - 1; 71 | } 72 | Control control = getLabelControl(parent); 73 | GridData gd = new GridData(); 74 | gd.horizontalSpan = 1; 75 | control.setLayoutData(gd); 76 | control = getComboBoxControl(parent); 77 | gd = new GridData(); 78 | gd.horizontalSpan = comboC; 79 | gd.horizontalAlignment = GridData.FILL; 80 | control.setLayoutData(gd); 81 | control.setFont(parent.getFont()); 82 | } 83 | 84 | /* 85 | * (non-Javadoc) 86 | * 87 | * @see org.eclipse.jface.preference.FieldEditor#doLoad() 88 | */ 89 | @Override 90 | protected void doLoad() { 91 | updateComboForValue(getPreferenceStore().getString(getPreferenceName())); 92 | } 93 | 94 | /* 95 | * (non-Javadoc) 96 | * 97 | * @see org.eclipse.jface.preference.FieldEditor#doLoadDefault() 98 | */ 99 | @Override 100 | protected void doLoadDefault() { 101 | updateComboForValue(getPreferenceStore().getDefaultString(getPreferenceName())); 102 | } 103 | 104 | /* 105 | * (non-Javadoc) 106 | * 107 | * @see org.eclipse.jface.preference.FieldEditor#doStore() 108 | */ 109 | @Override 110 | protected void doStore() { 111 | if (values == null) { 112 | getPreferenceStore().setToDefault(getPreferenceName()); 113 | return; 114 | } 115 | getPreferenceStore().setValue(getPreferenceName(), StringUtils.join(values, ";")); 116 | } 117 | 118 | /* 119 | * (non-Javadoc) 120 | * 121 | * @see org.eclipse.jface.preference.FieldEditor#getNumberOfControls() 122 | */ 123 | @Override 124 | public int getNumberOfControls() { 125 | return 2; 126 | } 127 | 128 | /* 129 | * Lazily create and return the Combo control. 130 | */ 131 | private Combo getComboBoxControl(Composite parent) { 132 | if (combo == null) { 133 | combo = new Combo(parent, SWT.READ_ONLY); 134 | combo.setFont(parent.getFont()); 135 | fillComboFromValues(); 136 | } 137 | return combo; 138 | } 139 | 140 | private void fillComboFromValues() { 141 | combo.removeAll(); 142 | if (values != null) { 143 | for (int i = 0; i < values.length; i++) { 144 | combo.add(values[i], i); 145 | } 146 | combo.select(0); 147 | combo.setText(values[0]); 148 | } 149 | } 150 | 151 | public void addValue(String value) { 152 | String oldValue = StringUtils.join(values); 153 | values = ArrayUtils.add(values, value); 154 | combo.add(value); 155 | combo.select(values.length - 1); 156 | combo.setText(values[values.length - 1]); 157 | fireValueChanged(VALUE, oldValue, StringUtils.join(values)); 158 | } 159 | 160 | public void removeValue(String value) { 161 | int index = ArrayUtils.indexOf(values, value); 162 | if (index != -1) { 163 | String oldValue = StringUtils.join(values); 164 | values = ArrayUtils.remove(values, index); 165 | combo.remove(index); 166 | combo.select(0); 167 | combo.setText(values[0]); 168 | fireValueChanged(VALUE, oldValue, StringUtils.join(values)); 169 | } 170 | } 171 | 172 | /* 173 | * Set the name in the combo widget to match the specified value. 174 | */ 175 | private void updateComboForValue(String value) { 176 | values = value.split(";"); 177 | fillComboFromValues(); 178 | } 179 | 180 | /* 181 | * (non-Javadoc) 182 | * 183 | * @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean, 184 | * org.eclipse.swt.widgets.Composite) 185 | */ 186 | @Override 187 | public void setEnabled(boolean enabled, Composite parent) { 188 | super.setEnabled(enabled, parent); 189 | getComboBoxControl(parent).setEnabled(enabled); 190 | } 191 | 192 | public final Combo getCombo() { 193 | return combo; 194 | } 195 | 196 | } 197 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/preferences/PreferenceInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin.preferences; 17 | 18 | import static org.jsweet.plugin.preferences.Preferences.DEFAULT_PROFILE_NAME; 19 | 20 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; 21 | import org.eclipse.jface.preference.IPreferenceStore; 22 | import org.jsweet.plugin.JSweetPlugin; 23 | 24 | /** 25 | * Class used to initialize default preference values. 26 | */ 27 | public class PreferenceInitializer extends AbstractPreferenceInitializer { 28 | 29 | @Override 30 | public void initializeDefaultPreferences() { 31 | IPreferenceStore store = JSweetPlugin.getDefault().getPreferenceStore(); 32 | store.setDefault(Preferences.profiles(), "default"); 33 | store.setDefault(Preferences.tsOutputDir(DEFAULT_PROFILE_NAME), ".generated"); 34 | store.setDefault(Preferences.jsOutputDir(DEFAULT_PROFILE_NAME), "js"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/preferences/Preferences.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin.preferences; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.eclipse.core.resources.IProject; 20 | import org.eclipse.jface.preference.IPreferenceStore; 21 | 22 | /** 23 | * Constant definitions for plug-in preferences 24 | */ 25 | public class Preferences { 26 | 27 | public static final String DEFAULT_PROFILE_NAME = "default"; 28 | 29 | private static final String COMPILER_PROFILES = "compiler.profiles"; 30 | 31 | private static final String COMPILER_SOURCE_FOLDERS = "compiler.sourceFolders"; 32 | 33 | private static final String COMPILER_SOURCE_INCLUDE_FILTER = "compiler.sourceIncludeFilter"; 34 | 35 | private static final String COMPILER_SOURCE_EXCLUDE_FILTER = "compiler.sourceExcludeFilter"; 36 | 37 | private static final String COMPILER_TYPESCRIPT_FOLDER = "compiler.typescriptFolder"; 38 | 39 | private static final String COMPILER_JAVASCRIPT_FOLDER = "compiler.javascriptFolder"; 40 | 41 | private static final String COMPILER_CANDY_JS_FOLDER = "compiler.candyJsFolder"; 42 | 43 | private static final String COMPILER_BUNDLES_DIRECTORY = "compiler.bundlesDirectory"; 44 | 45 | private static final String COMPILER_BUNDLE = "compiler.bundle"; 46 | 47 | private static final String COMPILER_DECLARATION_DIRECTORY = "compiler.declarationDirectory"; 48 | 49 | private static final String COMPILER_DECLARATION = "compiler.declaration"; 50 | 51 | private static final String COMPILER_NO_JS = "compiler.nojs"; 52 | 53 | private static final String COMPILER_DEBUG_MODE = "compiler.debugMode"; 54 | 55 | private static final String COMPILER_MODULE_KIND = "compiler.moduleKind"; 56 | 57 | private static final String COMPILER_ECMA_TARGET_VERSION = "compiler.target"; 58 | 59 | public static String getProfilePrefix(String profile) { 60 | return StringUtils.isBlank(profile) || DEFAULT_PROFILE_NAME.equals(profile) ? "" : profile + "."; 61 | } 62 | 63 | public static String profiles() { 64 | return Preferences.COMPILER_PROFILES; 65 | } 66 | 67 | public static String getProfiles(IProject project) { 68 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 69 | return projectPreferenceStore.getString(Preferences.COMPILER_PROFILES); 70 | } 71 | 72 | public static String[] parseProfiles(IProject project) { 73 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 74 | String profiles = projectPreferenceStore.getString(Preferences.COMPILER_PROFILES); 75 | return (profiles == null ? "" : profiles).split(";"); 76 | } 77 | 78 | public static String srcDirs(final String profile) { 79 | return getProfilePrefix(profile) + Preferences.COMPILER_SOURCE_FOLDERS; 80 | } 81 | 82 | public static String getSourceFolders(IProject project, String profile) { 83 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 84 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_SOURCE_FOLDERS); 85 | } 86 | 87 | public static String srcIncludeFilter(final String profile) { 88 | return getProfilePrefix(profile) + Preferences.COMPILER_SOURCE_INCLUDE_FILTER; 89 | } 90 | 91 | public static String getSourceIncludeFilter(IProject project, String profile) { 92 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 93 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_SOURCE_INCLUDE_FILTER); 94 | } 95 | 96 | public static String srcExcludeFilter(final String profile) { 97 | return getProfilePrefix(profile) + Preferences.COMPILER_SOURCE_EXCLUDE_FILTER; 98 | } 99 | 100 | public static String getSourceExcludeFilter(IProject project, String profile) { 101 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 102 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_SOURCE_EXCLUDE_FILTER); 103 | } 104 | 105 | public static String tsOutputDir(final String profile) { 106 | return getProfilePrefix(profile) + Preferences.COMPILER_TYPESCRIPT_FOLDER; 107 | } 108 | 109 | public static String getTsOutputFolder(IProject project, String profile) { 110 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 111 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_TYPESCRIPT_FOLDER); 112 | } 113 | 114 | public static String candyJsOutputDir(final String profile) { 115 | return getProfilePrefix(profile) + Preferences.COMPILER_CANDY_JS_FOLDER; 116 | } 117 | 118 | public static String getCandyJsOutputFolder(IProject project, String profile) { 119 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 120 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_CANDY_JS_FOLDER); 121 | } 122 | 123 | public static String moduleKind(String profile) { 124 | return getProfilePrefix(profile) + Preferences.COMPILER_MODULE_KIND; 125 | } 126 | 127 | public static String getModuleKind(IProject project, String profile) { 128 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 129 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_MODULE_KIND); 130 | } 131 | 132 | public static String ecmaTargetVersion(String profile) { 133 | return getProfilePrefix(profile) + Preferences.COMPILER_ECMA_TARGET_VERSION; 134 | } 135 | 136 | public static String getEcmaTargetVersion(IProject project, String profile) { 137 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 138 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_ECMA_TARGET_VERSION); 139 | } 140 | 141 | public static String jsOutputDir(final String profile) { 142 | return getProfilePrefix(profile) + Preferences.COMPILER_JAVASCRIPT_FOLDER; 143 | } 144 | 145 | public static String getJsOutputFolder(IProject project, String profile) { 146 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 147 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_JAVASCRIPT_FOLDER); 148 | } 149 | 150 | public static String bundlesDir(final String profile) { 151 | return getProfilePrefix(profile) + Preferences.COMPILER_BUNDLES_DIRECTORY; 152 | } 153 | 154 | public static String getBundlesDirectory(IProject project, String profile) { 155 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 156 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_BUNDLES_DIRECTORY); 157 | } 158 | 159 | public static String bundle(String profile) { 160 | return getProfilePrefix(profile) + Preferences.COMPILER_BUNDLE; 161 | } 162 | 163 | public static boolean getBundle(IProject project, String profile) { 164 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 165 | return projectPreferenceStore.getBoolean(getProfilePrefix(profile) + Preferences.COMPILER_BUNDLE); 166 | } 167 | 168 | public static String declaration(String profile) { 169 | return getProfilePrefix(profile) + Preferences.COMPILER_DECLARATION; 170 | } 171 | 172 | public static boolean getDeclaration(IProject project, String profile) { 173 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 174 | return projectPreferenceStore.getBoolean(getProfilePrefix(profile) + Preferences.COMPILER_DECLARATION); 175 | } 176 | 177 | public static String declarationDir(final String profile) { 178 | return getProfilePrefix(profile) + Preferences.COMPILER_DECLARATION_DIRECTORY; 179 | } 180 | 181 | public static String getDeclarationDirectory(IProject project, String profile) { 182 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 183 | return projectPreferenceStore.getString(getProfilePrefix(profile) + Preferences.COMPILER_DECLARATION_DIRECTORY); 184 | } 185 | 186 | public static String debugMode(String profile) { 187 | return getProfilePrefix(profile) + Preferences.COMPILER_DEBUG_MODE; 188 | } 189 | 190 | public static boolean isDebugMode(IProject project, String profile) { 191 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 192 | return projectPreferenceStore.getBoolean(getProfilePrefix(profile) + Preferences.COMPILER_DEBUG_MODE); 193 | } 194 | 195 | public static String noJs(String profile) { 196 | return getProfilePrefix(profile) + Preferences.COMPILER_NO_JS; 197 | } 198 | 199 | public static boolean getNoJs(IProject project, String profile) { 200 | IPreferenceStore projectPreferenceStore = new ProjectPreferenceStore(project); 201 | return projectPreferenceStore.getBoolean(getProfilePrefix(profile) + Preferences.COMPILER_NO_JS); 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /org.jsweet.plugin/src/org/jsweet/plugin/preferences/ProjectPreferenceStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 CINCHEO SAS 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jsweet.plugin.preferences; 17 | 18 | import java.io.IOException; 19 | import java.io.OutputStream; 20 | 21 | import org.eclipse.core.resources.IProject; 22 | import org.eclipse.core.resources.ProjectScope; 23 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; 24 | import org.eclipse.core.runtime.preferences.IScopeContext; 25 | import org.eclipse.jface.preference.IPreferenceStore; 26 | import org.eclipse.jface.preference.PreferenceStore; 27 | import org.jsweet.plugin.JSweetPlugin; 28 | import org.osgi.service.prefs.BackingStoreException; 29 | 30 | /** 31 | * An adapter for {@link PreferenceStore} to allow a preference page to be used 32 | * as a property page. 33 | *

34 | * Adapted from 35 | * http://www.eclipse.org/articles/Article-Mutatis-mutandis/overlay-pages.html. 36 | *

37 | * Adapted from the Typescript Eclipse plugin (author: dcicerone). 38 | */ 39 | public final class ProjectPreferenceStore extends PreferenceStore { 40 | private final IProject project; 41 | private final IPreferenceStore preferenceStore; 42 | private boolean projectSpecificSettings; 43 | private transient boolean inserting; 44 | 45 | public ProjectPreferenceStore(IProject project) { 46 | this(project, JSweetPlugin.getDefault().getPreferenceStore(), ""); 47 | } 48 | 49 | public ProjectPreferenceStore(IProject project, IPreferenceStore preferenceStore, String sentinelPropertyName) { 50 | assert project != null; 51 | assert preferenceStore != null; 52 | assert sentinelPropertyName != null; 53 | this.project = project; 54 | this.preferenceStore = preferenceStore; 55 | IEclipsePreferences projectPreferences = this.getProjectPreferences(); 56 | this.projectSpecificSettings = (projectPreferences.get(sentinelPropertyName, null) != null); 57 | } 58 | 59 | @Override 60 | public boolean contains(String name) { 61 | return this.preferenceStore.contains(name); 62 | } 63 | 64 | @Override 65 | public boolean getDefaultBoolean(String name) { 66 | return this.preferenceStore.getDefaultBoolean(name); 67 | } 68 | 69 | @Override 70 | public double getDefaultDouble(String name) { 71 | return this.preferenceStore.getDefaultDouble(name); 72 | } 73 | 74 | @Override 75 | public float getDefaultFloat(String name) { 76 | return this.preferenceStore.getDefaultFloat(name); 77 | } 78 | 79 | @Override 80 | public int getDefaultInt(String name) { 81 | return this.preferenceStore.getDefaultInt(name); 82 | } 83 | 84 | @Override 85 | public long getDefaultLong(String name) { 86 | return this.preferenceStore.getDefaultLong(name); 87 | } 88 | 89 | @Override 90 | public String getDefaultString(String name) { 91 | return this.preferenceStore.getDefaultString(name); 92 | } 93 | 94 | @Override 95 | public boolean getBoolean(String name) { 96 | this.insertValue(name); 97 | return super.getBoolean(name); 98 | } 99 | 100 | @Override 101 | public double getDouble(String name) { 102 | this.insertValue(name); 103 | return super.getDouble(name); 104 | } 105 | 106 | @Override 107 | public float getFloat(String name) { 108 | this.insertValue(name); 109 | return super.getFloat(name); 110 | } 111 | 112 | @Override 113 | public int getInt(String name) { 114 | this.insertValue(name); 115 | return super.getInt(name); 116 | } 117 | 118 | @Override 119 | public long getLong(String name) { 120 | this.insertValue(name); 121 | return super.getLong(name); 122 | } 123 | 124 | @Override 125 | public String getString(String name) { 126 | this.insertValue(name); 127 | return super.getString(name); 128 | } 129 | 130 | @Override 131 | public boolean isDefault(String name) { 132 | String defaultValue = this.getDefaultString(name); 133 | if (defaultValue == null) { 134 | return false; 135 | } 136 | return defaultValue.equals(this.getString(name)); 137 | } 138 | 139 | public boolean getProjectSpecificSettings() { 140 | return this.projectSpecificSettings; 141 | } 142 | 143 | public void setProjectSpecificSettings(boolean projectSpecificSettings) { 144 | this.projectSpecificSettings = projectSpecificSettings; 145 | } 146 | 147 | @Override 148 | public void save() throws IOException { 149 | this.writeProperties(); 150 | } 151 | 152 | @Override 153 | public void save(OutputStream out, String header) throws IOException { 154 | this.writeProperties(); 155 | } 156 | 157 | @Override 158 | public void setToDefault(String name) { 159 | String defaultValue = this.getDefaultString(name); 160 | this.setValue(name, defaultValue); 161 | } 162 | 163 | private synchronized void insertValue(String name) { 164 | // check if an insertion is already in-progress 165 | if (this.inserting) { 166 | return; 167 | } 168 | if (this.projectSpecificSettings && super.contains(name)) { 169 | return; 170 | } 171 | this.inserting = true; 172 | try { 173 | IEclipsePreferences projectPreferences = this.getProjectPreferences(); 174 | String value = projectPreferences.get(name, null); 175 | if (value == null) { 176 | value = this.preferenceStore.getString(name); 177 | } 178 | if (value != null) { 179 | this.setValue(name, value); 180 | } 181 | } finally { 182 | this.inserting = false; 183 | } 184 | } 185 | 186 | private void writeProperties() throws IOException { 187 | IEclipsePreferences projectPreferences = this.getProjectPreferences(); 188 | for (String name : super.preferenceNames()) { 189 | if (this.projectSpecificSettings) { 190 | String value = this.getString(name); 191 | projectPreferences.put(name, value); 192 | } else { 193 | projectPreferences.remove(name); 194 | } 195 | } 196 | try { 197 | projectPreferences.flush(); 198 | } catch (BackingStoreException e) { 199 | throw new IOException(e); 200 | } 201 | } 202 | 203 | private IEclipsePreferences getProjectPreferences() { 204 | IScopeContext projectScope = new ProjectScope(this.project); 205 | return projectScope.getNode(JSweetPlugin.ID); 206 | } 207 | } -------------------------------------------------------------------------------- /org.jsweet.update/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jsweet.update 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.UpdateSiteBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.UpdateSiteNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /org.jsweet.update/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JSweet transpiler update site 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | The JSweet transpiler Eclipse plugin 63 | 64 | 65 | 66 | --------------------------------------------------------------------------------