diff --git a/bin/app/data/3rd_party_licenses/license_eclipse.txt b/bin/app/data/3rd_party_licenses/license_eclipse.txt new file mode 100644 index 00000000..2f4e46f9 --- /dev/null +++ b/bin/app/data/3rd_party_licenses/license_eclipse.txt @@ -0,0 +1,13 @@ +Eclipse Distribution License - v 1.0 + +Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/bin/app/data/3rd_party_licenses/license_guava.txt b/bin/app/data/3rd_party_licenses/license_guava.txt deleted file mode 100644 index 7a4a3ea2..00000000 --- a/bin/app/data/3rd_party_licenses/license_guava.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - 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. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/bin/app/data/3rd_party_licenses/license_java_symbol_solver.txt b/bin/app/data/3rd_party_licenses/license_java_symbol_solver.txt deleted file mode 100644 index d6456956..00000000 --- a/bin/app/data/3rd_party_licenses/license_java_symbol_solver.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - 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. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/bin/app/data/3rd_party_licenses/license_javaparser.txt b/bin/app/data/3rd_party_licenses/license_javaparser.txt deleted file mode 100644 index d6456956..00000000 --- a/bin/app/data/3rd_party_licenses/license_javaparser.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - 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. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/bin/app/data/3rd_party_licenses/license_javaslang.txt b/bin/app/data/3rd_party_licenses/license_javaslang.txt deleted file mode 100644 index 46e391d4..00000000 --- a/bin/app/data/3rd_party_licenses/license_javaslang.txt +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2014-2016 Javaslang, http://javaslang.io - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -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. -See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file diff --git a/bin/app/data/3rd_party_licenses/license_javassist.txt b/bin/app/data/3rd_party_licenses/license_javassist.txt deleted file mode 100644 index b11aaa6c..00000000 --- a/bin/app/data/3rd_party_licenses/license_javassist.txt +++ /dev/null @@ -1,141 +0,0 @@ -MOZILLA PUBLIC LICENSE -Version 1.1 -1. Definitions. - -1.0.1. "Commercial Use" means distribution or otherwise making the Covered Code available to a third party. -1.1. ''Contributor'' means each entity that creates or contributes to the creation of Modifications. - -1.2. ''Contributor Version'' means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor. - -1.3. ''Covered Code'' means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof. - -1.4. ''Electronic Distribution Mechanism'' means a mechanism generally accepted in the software development community for the electronic transfer of data. - -1.5. ''Executable'' means Covered Code in any form other than Source Code. - -1.6. ''Initial Developer'' means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A. - -1.7. ''Larger Work'' means a work which combines Covered Code or portions thereof with code not governed by the terms of this License. - -1.8. ''License'' means this document. - -1.8.1. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. - -1.9. ''Modifications'' means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a Modification is: - -A. Any addition to or deletion from the contents of a file containing Original Code or previous Modifications. -B. Any new file that contains any part of the Original Code or previous Modifications. - - -1.10. ''Original Code'' means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License. -1.10.1. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. - -1.11. ''Source Code'' means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control compilation and installation of an Executable, or source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor's choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge. - -1.12. "You'' (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, "You'' includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control'' means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. - -2. Source Code License. -2.1. The Initial Developer Grant. -The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims: -(a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, and/or as part of a Larger Work; and -(b) under Patents Claims infringed by the making, using or selling of Original Code, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Code (or portions thereof). - -(c) the licenses granted in this Section 2.1(a) and (b) are effective on the date Initial Developer first distributes Original Code under the terms of this License. -(d) Notwithstanding Section 2.1(b) above, no patent license is granted: 1) for code that You delete from the Original Code; 2) separate from the Original Code; or 3) for infringements caused by: i) the modification of the Original Code or ii) the combination of the Original Code with other software or devices. - - -2.2. Contributor Grant. -Subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license - -(a) under intellectual property rights (other than patent or trademark) Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger Work; and -(b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications made by that Contributor (or portions thereof); and 2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). - -(c) the licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first makes Commercial Use of the Covered Code. - -(d) Notwithstanding Section 2.2(b) above, no patent license is granted: 1) for any code that Contributor has deleted from the Contributor Version; 2) separate from the Contributor Version; 3) for infringements caused by: i) third party modifications of Contributor Version or ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or 4) under Patent Claims infringed by Covered Code in the absence of Modifications made by that Contributor. - - -3. Distribution Obligations. - -3.1. Application of License. -The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5. -3.2. Availability of Source Code. -Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party. - -3.3. Description of Modifications. -You must cause all Covered Code to which You contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code. - -3.4. Intellectual Property Matters - -(a) Third Party Claims. -If Contributor has knowledge that a license under a third party's intellectual property rights is required to exercise the rights granted by such Contributor under Sections 2.1 or 2.2, Contributor must include a text file with the Source Code distribution titled "LEGAL'' which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If Contributor obtains such knowledge after the Modification is made available as described in Section 3.2, Contributor shall promptly modify the LEGAL file in all copies Contributor makes available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained. -(b) Contributor APIs. -If Contributor's Modifications include an application programming interface and Contributor has knowledge of patent licenses which are reasonably necessary to implement that API, Contributor must also include this information in the LEGAL file. - - - (c) Representations. -Contributor represents that, except as disclosed pursuant to Section 3.4(a) above, Contributor believes that Contributor's Modifications are Contributor's original creation(s) and/or Contributor has sufficient rights to grant the rights conveyed by this License. - -3.5. Required Notices. -You must duplicate the notice in Exhibit A in each file of the Source Code. If it is not possible to put such notice in a particular Source Code file due to its structure, then You must include such notice in a location (such as a relevant directory) where a user would be likely to look for such a notice. If You created one or more Modification(s) You may add your name as a Contributor to the notice described in Exhibit A. You must also duplicate this License in any documentation for the Source Code where You describe recipients' rights or ownership rights relating to Covered Code. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. - -3.6. Distribution of Executable Versions. -You may distribute Covered Code in Executable form only if the requirements of Section 3.1-3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code or ownership rights under a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. - -3.7. Larger Works. -You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code. - -4. Inability to Comply Due to Statute or Regulation. -If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the LEGAL file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. -5. Application of this License. -This License applies to code to which the Initial Developer has attached the notice in Exhibit A and to related Covered Code. -6. Versions of the License. -6.1. New Versions. -Netscape Communications Corporation (''Netscape'') may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number. -6.2. Effect of New Versions. -Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Netscape. No one other than Netscape has the right to modify the terms applicable to Covered Code created under this License. - -6.3. Derivative Works. -If You create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), You must (a) rename Your license so that the phrases ''Mozilla'', ''MOZILLAPL'', ''MOZPL'', ''Netscape'', "MPL", ''NPL'' or any confusingly similar phrase do not appear in your license (except to note that your license differs from this License) and (b) otherwise make it clear that Your version of the license contains terms which differ from the Mozilla Public License and Netscape Public License. (Filling in the name of the Initial Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.) - -7. DISCLAIMER OF WARRANTY. -COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS'' BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. -8. TERMINATION. -8.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. -8.2. If You initiate litigation by asserting a patent infringement claim (excluding declatory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You file such action is referred to as "Participant") alleging that: - -(a) such Participant's Contributor Version directly or indirectly infringes any patent, then any and all rights granted by such Participant to You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively, unless if within 60 days after receipt of notice You either: (i) agree in writing to pay Participant a mutually agreeable reasonable royalty for Your past and future use of Modifications made by such Participant, or (ii) withdraw Your litigation claim with respect to the Contributor Version against such Participant. If within 60 days of notice, a reasonable royalty and payment arrangement are not mutually agreed upon in writing by the parties or the litigation claim is not withdrawn, the rights granted by Participant to You under Sections 2.1 and/or 2.2 automatically terminate at the expiration of the 60 day notice period specified above. - -(b) any software, hardware, or device, other than such Participant's Contributor Version, directly or indirectly infringes any patent, then any rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are revoked effective as of the date You first made, used, sold, distributed, or had made, Modifications made by that Participant. - -8.3. If You assert a patent infringement claim against Participant alleging that such Participant's Contributor Version directly or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license. - -8.4. In the event of termination under Sections 8.1 or 8.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or any distributor hereunder prior to termination shall survive termination. - -9. LIMITATION OF LIABILITY. -UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. -10. U.S. GOVERNMENT END USERS. -The Covered Code is a ''commercial item,'' as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of ''commercial computer software'' and ''commercial computer software documentation,'' as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein. -11. MISCELLANEOUS. -This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by California law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in the United States of America, any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California, with venue lying in Santa Clara County, California, with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys' fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. -12. RESPONSIBILITY FOR CLAIMS. -As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. -13. MULTIPLE-LICENSED CODE. -Initial Developer may designate portions of the Covered Code as "Multiple-Licensed". "Multiple-Licensed" means that the Initial Developer permits you to utilize portions of the Covered Code under Your choice of the MPL or the alternative licenses, if any, specified by the Initial Developer in the file described in Exhibit A. - -EXHIBIT A -Mozilla Public License. - -The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -http://www.mozilla.org/MPL/ -Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF -ANY KIND, either express or implied. See the License for the specific language governing rights and -limitations under the License. - -The Original Code is Javassist. - -The Initial Developer of the Original Code is Shigeru Chiba. Portions created by the Initial Developer are - Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. - -Contributor(s): __Bill Burke, Jason T. Greene______________. - -Alternatively, the contents of this software may be used under the terms of the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), or the Apache License Version 2.0 (the "AL"), in which case the provisions of the LGPL or the AL are applicable instead of those above. If you wish to allow use of your version of this software only under the terms of either the LGPL or the AL, and not to allow others to use your version of this software under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the LGPL or the AL. If you do not delete the provisions above, a recipient may use your version of this software under the terms of any one of the MPL, the LGPL or the AL. \ No newline at end of file diff --git a/bin/app/data/gui/installer/EULA.txt b/bin/app/data/gui/installer/EULA.txt index dafba8a8..6dd8bad2 100644 --- a/bin/app/data/gui/installer/EULA.txt +++ b/bin/app/data/gui/installer/EULA.txt @@ -5,7 +5,7 @@ Last date of change: 2017-06-19 BY INSTALLING OR USING THIS SOFTWARE, YOU ARE BECOMING A PARTY TO, AND ARE CONSENTING TO BE BOUND BY, THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL OF THE TERMS OF THIS AGREEMENT, DO NOT INSTALL OR USE THIS SOFTWARE. -DEFINITIONS +1. DEFINITIONS "SOFTWARE" means: • A version of the cross-platform source code explorer known as Sourcetrail in executable form. The version is defined by the two leading numbers of the version string (e.g. the version of Sourcetrail 2017.1.x is version 2017.1); @@ -32,7 +32,7 @@ DEFINITIONS • an employee or independent contractor who might at any time use the SOFTWARE, of the LICENSEE; for each ACTIVATION KEY an entity has as many AUTHORIZED USER(s) as defined by the amount of seats specified in the ACTIVATION KEY; if no amount of seats is specified in the ACTIVATION KEY the entity has one AUTHORIZED USER for this ACTIVATION KEY. -GRANT +2. GRANT Subject to the terms of this AGREEMENT, the LICENSOR hereby grants the LICENSEE a worldwide, non-transferable, non-exclusive, non-sub-licensable, limited LICENSE that allows: • the LICENSEE to distribute (an) ACTIVATION KEY(s) to AUTHORIZED USER(s); @@ -43,7 +43,7 @@ Subject to the terms of this AGREEMENT, the LICENSOR hereby grants the LICENSEE • LICENSEE to make a copy of the SOFTWARE for archival purposes provided the copy contains all of the proprietary notices of the SOFTWARE. -RESTRICTIONS AND CONFIDENTIALITY +3. RESTRICTIONS AND CONFIDENTIALITY The LICENSEE will not, and will have no right to: • modify, translate, reverse engineer, decompile, disassemble (except to the extent applicable laws specifically prohibit such restriction), create derivative works based on, or otherwise attempt to discover the source code or underlying ideas or algorithms of the SOFTWARE; @@ -56,37 +56,37 @@ AUTHORIZED USER(s) will not, and will have no right to: • use a Private/Academic License of the software for any commercial purposes. Unless a valid non-disclosure agreement exists between the Parties, in which case the terms of that non-disclosure agreement shall apply, the following terms shall: Except as necessary for its performance under the AGREEMENT or required by law, the LICENSOR shall not disclose to anyone any information furnished by the LICENSEE that is marked as confidential or proprietary. -TITLE AND COPYRIGHT +4. TITLE AND COPYRIGHT Title, ownership rights, intellectual property rights, and copyright to the SOFTWARE, and any copies or portions thereof, shall remain in LICENSOR. The SOFTWARE is protected by European copyright directives, Austrian copyright laws as well as United States copyright laws and international treaty provisions. -DISCLAIMER OF WARRANTY +5. DISCLAIMER OF WARRANTY THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND. LICENSOR HEREBY DISCLAIMS ALL EXPRESS OR IMPLIED WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS AGREEMENT. SOME U.S. STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE. LICENSEE MAY HAVE OTHER LEGAL RIGHTS THAT VARY FROM STATE TO STATE OR BY JURISDICTION. -LIMITATION OF LIABILITY +6. LIMITATION OF LIABILITY LICENSEE ASSUMES THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE. LICENSOR ASSUMES NO LIABILITY FOR THE COST OF ANY SERVICE OR REPAIR IF THE SOFTWARE IS DEFECTIVE. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, STRICT LIABILITY, OR OTHERWISE, SHALL LICENSOR, OR ITS LICENSORS, SUPPLIERS OR RESELLERS, BE LIABLE TO LICENSEE OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES. IN NO EVENT WILL LICENSOR BE LIABLE FOR ANY DAMAGES IN EXCESS OF THE MONEY PAID FOR THE SOFTWARE, EVEN IF LICENSOR SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. FURTHERMORE, SOME U.S. STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT APPLY TO LICENSEE. -TERMINATION +7. TERMINATION The license granted herein shall be perpetual. If LICENSEE fails to comply with any of the terms of this AGREEMENT, this AGREEMENT and the rights granted herein will terminate immediately. LICENSOR may, at its sole discretion and at any time, terminate this AGREEMENT. On termination, LICENSEE must cease using and destroy all copies of the SOFTWARE. -EXPORT CONTROLS +8. EXPORT CONTROLS LICENSEE shall comply with all export laws, restrictions and regulations of the United States, the Directive 2009/428/EC of the European Parliament and of the Council and the Austrian Außenwirtschaftsgesetz 2011, BGBl I No. 26/2011. LICENSEE shall not export, re-export or otherwise transfer the SOFTWARE to any country for which the United States or the European Union or Austria maintains an embargo, or to any person or entity on the U.S. Department of Treasury List of Specially Designated Nationals or the U.S. Department of Commerce Denied Persons List or Entity List. LICENSEE represents and warrants that licensee is not located in, under the control of, or a national or resident of any restricted country or on any such list. -THIRD PARTY CREDITS +9. THIRD PARTY CREDITS Portions of the SOFTWARE utilize or include third party software and other copyrighted materials. Credits, licensing terms, and disclaimers for such materials are contained in the installation directory for the SOFTWARE, and are accessible via the “3rd Party Licenses” dialog for the SOFTWARE. LICENSEE agrees that use of such copyrighted materials is governed by their respective terms. -ENTIRE AGREEMENT +10. ENTIRE AGREEMENT This AGREEMENT represents the complete agreement concerning this SOFTWARE between the PARTIES and supersedes all prior agreements and representations between them. It may be amended only in writing executed by both PARTIES. Coati Software OG reserves the exclusive right to periodically update this AGREEMENT at its discretion at any time, with reasonable notice to LICENSEE by posting the new AGREEMENT at the following URL: . Any action arising out of or relating to this AGREEMENT may be brought exclusively in Salzburg, Austria, and the PARTIES irrevocably consent to the jurisdiction of such courts and venue in Salzburg, Austria. diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index beadd1ee..2405a4c4 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -87,3 +87,17 @@ TextAccess.cpp WARNING: Line numbers start with one, is 0 INFO: Indexer - indexing source file: input.cc INFO: Indexer - indexing source file: input.cc INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc + INFO: Indexer - indexing source file: input.cc diff --git a/cmake/licenses.cmake b/cmake/licenses.cmake index 6e9578b2..d989edef 100644 --- a/cmake/licenses.cmake +++ b/cmake/licenses.cmake @@ -25,11 +25,7 @@ AddLicense("Boost" "http://www.boost.org" "${LICENSEFOLDER}/license_boost.txt") AddLicense("Botan" "http://botan.randombit.net/" "${LICENSEFOLDER}/license_botan.txt") AddLicense("Clang" "http://clang.llvm.org/" "${LICENSEFOLDER}/license_clang.txt") AddLicense("CppSQLite" "http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper-for-SQLite" "${LICENSEFOLDER}/license_cpp_sqlite.txt") -AddLicense("Guava" "https://github.com/google/guava" "${LICENSEFOLDER}/license_guava.txt") -AddLicense("JavaSymbolSolver" "https://github.com/ftomassetti/java-symbol-solver" "${LICENSEFOLDER}/license_java_symbol_solver.txt") -AddLicense("Javaparser" "http://javaparser.org/" "${LICENSEFOLDER}/license_javaparser.txt") -AddLicense("Javaslang" "http://www.javaslang.io/" "${LICENSEFOLDER}/license_javaslang.txt") -AddLicense("Javassist" "http://www.javassist.org/" "${LICENSEFOLDER}/license_javassist.txt") +AddLicense("Eclipse" "https://github.com/eclipse/eclipse.jdt.core" "${LICENSEFOLDER}/license_eclipse.txt") AddLicense("OpenSSL" "https://www.openssl.org/" "${LICENSEFOLDER}/license_openssl.txt") AddLicense("Qt" "http://qt.io" "${LICENSEFOLDER}/license_qt.txt") AddLicense("TinyXML" "http://www.grinninglizard.com/tinyxml2/" "${LICENSEFOLDER}/license_tinyxml.txt") diff --git a/deployment/windows/wixSetup/installDir.wxs b/deployment/windows/wixSetup/installDir.wxs index fbb81a4c..5df3b5ef 100644 --- a/deployment/windows/wixSetup/installDir.wxs +++ b/deployment/windows/wixSetup/installDir.wxs @@ -268,20 +268,8 @@ - - - - - - - - - - - - - - + + diff --git a/deployment/windows/wixSetup/sourcetrail.wxs b/deployment/windows/wixSetup/sourcetrail.wxs index 9cbe99c0..46ffe0d1 100644 --- a/deployment/windows/wixSetup/sourcetrail.wxs +++ b/deployment/windows/wixSetup/sourcetrail.wxs @@ -236,11 +236,7 @@ - - - - - + diff --git a/java_indexer/lib/java-symbol-solver-core.jar b/java_indexer/lib/java-symbol-solver-core.jar index c015a3bc..6f0ff967 100644 Binary files a/java_indexer/lib/java-symbol-solver-core.jar and b/java_indexer/lib/java-symbol-solver-core.jar differ diff --git a/java_indexer/lib/java-symbol-solver-logic.jar b/java_indexer/lib/java-symbol-solver-logic.jar index b4acb4d4..0e1f23a5 100644 Binary files a/java_indexer/lib/java-symbol-solver-logic.jar and b/java_indexer/lib/java-symbol-solver-logic.jar differ diff --git a/java_indexer/lib/java-symbol-solver-model.jar b/java_indexer/lib/java-symbol-solver-model.jar index 6cdc3c8a..0c7adbe7 100644 Binary files a/java_indexer/lib/java-symbol-solver-model.jar and b/java_indexer/lib/java-symbol-solver-model.jar differ diff --git a/java_indexer/pom.xml b/java_indexer/pom.xml index beee195d..3d612075 100644 --- a/java_indexer/pom.xml +++ b/java_indexer/pom.xml @@ -8,7 +8,6 @@ http://maven.apache.org 1.8 - x.x.x @@ -27,49 +26,9 @@ - org.dummy - java-symbol-solver-core - ${javasymbolsolver.version} - system - ${project.basedir}/lib/java-symbol-solver-core.jar - - - org.dummy - java-symbol-solver-logic - ${javasymbolsolver.version} - system - ${project.basedir}/lib/java-symbol-solver-logic.jar - - - org.dummy - java-symbol-solver-model - ${javasymbolsolver.version} - system - ${project.basedir}/lib/java-symbol-solver-model.jar - - - com.github.javaparser - javaparser-core - 3.3.0 - compile - - - org.javassist - javassist - 3.19.0-GA - compile - - - com.google.guava - guava - 21.0 - compile - - - io.javaslang - javaslang - 2.0.3 - compile + org.eclipse.jdt + org.eclipse.jdt.core + 3.12.3 diff --git a/java_indexer/src/main/java/com/sourcetrail/AccessKind.java b/java_indexer/src/main/java/com/sourcetrail/AccessKind.java index 6dca5a39..35745f2a 100644 --- a/java_indexer/src/main/java/com/sourcetrail/AccessKind.java +++ b/java_indexer/src/main/java/com/sourcetrail/AccessKind.java @@ -1,6 +1,6 @@ package com.sourcetrail; -import com.github.javaparser.ast.AccessSpecifier; +import org.eclipse.jdt.core.dom.Modifier; public enum AccessKind { // these values need to be the same as AccesKind in C++ code @@ -14,31 +14,23 @@ public enum AccessKind private final int m_value; - private AccessKind(int value) - { - this.m_value = value; - } - - public int getValue() - { - return m_value; - } - - public static AccessKind fromAccessSpecifier(AccessSpecifier specifier) - { - switch (specifier) - { - case PUBLIC: - return AccessKind.PUBLIC; - case PROTECTED: - return AccessKind.PROTECTED; - case PRIVATE: - return AccessKind.PRIVATE; - case DEFAULT: - return AccessKind.DEFAULT; - default: - return AccessKind.NONE; - } - } + private AccessKind(int value) + { + this.m_value = value; + } + + public int getValue() + { + return m_value; + } + + public static AccessKind fromModifiers(int modifiers) + { + if ((modifiers & Modifier.PUBLIC) != 0) { return AccessKind.PUBLIC; } + if ((modifiers & Modifier.PROTECTED) != 0) { return AccessKind.PROTECTED; } + if ((modifiers & Modifier.PRIVATE) != 0) { return AccessKind.PRIVATE; } + if ((modifiers & Modifier.DEFAULT) != 0) { return AccessKind.DEFAULT; } + return AccessKind.DEFAULT; + } } diff --git a/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java index 4dd1e0bb..c0eeda39 100644 --- a/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java +++ b/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java @@ -4,932 +4,746 @@ import java.io.File; import java.lang.String; import java.util.List; import java.util.Optional; +import java.util.Stack; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; +import org.eclipse.jdt.core.dom.ArrayInitializer; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.BlockComment; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ConstructorInvocation; +import org.eclipse.jdt.core.dom.CreationReference; +import org.eclipse.jdt.core.dom.EnumConstantDeclaration; +import org.eclipse.jdt.core.dom.EnumDeclaration; +import org.eclipse.jdt.core.dom.ExpressionMethodReference; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.IPackageBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.Javadoc; +import org.eclipse.jdt.core.dom.LineComment; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.NameQualifiedType; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.core.dom.PrimitiveType; +import org.eclipse.jdt.core.dom.QualifiedType; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; +import org.eclipse.jdt.core.dom.SuperConstructorInvocation; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.eclipse.jdt.core.dom.SuperMethodReference; +import org.eclipse.jdt.core.dom.SwitchStatement; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.TypeMethodReference; +import org.eclipse.jdt.core.dom.TypeParameter; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; + +import com.sourcetrail.name.JavaDeclName; +import com.sourcetrail.name.JavaFileName; +import com.sourcetrail.name.JavaSymbolName; +import com.sourcetrail.name.JavaTypeName; +import com.sourcetrail.name.NameHierarchy; +import com.sourcetrail.name.resolver.BindingNameResolver; +import com.sourcetrail.name.resolver.DeclNameResolver; import java.util.ArrayList; +import java.util.Arrays; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.comments.BlockComment; -import com.github.javaparser.ast.comments.LineComment; -import com.github.javaparser.ast.expr.ArrayInitializerExpr; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.SimpleName; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.SwitchStmt; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.PrimitiveType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.type.VoidType; -import com.github.javaparser.Position; -import com.github.javaparser.Range; -import com.github.javaparser.ast.ImportDeclaration; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserParameterDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.MethodAmbiguityException; -import com.github.javaparser.symbolsolver.model.declarations.ReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.ValueDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.resolution.UnsolvedSymbolException; -import com.github.javaparser.symbolsolver.model.typesystem.*; -import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic; -import com.sourcetrail.name.JavaDeclName; - -public class AstVisitor extends AstVisitorAdapter +public abstract class AstVisitor extends ASTVisitor { protected AstVisitorClient m_client = null; private File m_filePath; - private FileContent m_fileContent; - private TypeSolver m_typeSolver; - private List m_context = new ArrayList(); + private FileContent m_fileContent = null; + private CompilationUnit m_compilationUnit; + private Stack> m_contextStack = new Stack<>(); - public AstVisitor(AstVisitorClient client, String filePath, FileContent fileContent, TypeSolver typeSolver) + public AstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) { m_client = client; - m_filePath = new File(filePath); - m_fileContent = fileContent; - m_typeSolver = typeSolver; - - m_context.add(new DeclContext("/\tm" + filePath + "\ts\tp")); + m_filePath = filePath; + m_fileContent = new FileContent(fileContent); + m_compilationUnit = compilationUnit; + + m_contextStack.push(Arrays.asList(new JavaFileName(filePath))); } + protected abstract ReferenceKind getTypeReferenceKind(); + + // --- record declarations --- @Override - public Boolean visit(final PackageDeclaration n, final Void v) + public boolean visit(PackageDeclaration node) { - Name name = n.getName(); - - m_client.recordSymbolWithLocationAndScope( - JavaparserDeclNameResolver.getQualifiedName(name).toNameHierarchy().serialize(), - SymbolKind.PACKAGE, - name.getRange(), - n.getRange(), - AccessKind.NONE, - DefinitionKind.EXPLICIT - ); - - while (name.getQualifier().isPresent()) - { - name = name.getQualifier().get(); - m_client.recordSymbol( - JavaparserDeclNameResolver.getQualifiedName(name).toNameHierarchy().serialize(), - SymbolKind.PACKAGE, + m_client.recordSymbolWithLocation( + DeclNameResolver.getQualifiedName(node.getName()).toNameHierarchy(), + SymbolKind.PACKAGE, + getRange(node.getName()), AccessKind.NONE, - DefinitionKind.EXPLICIT - ); - } + DefinitionKind.EXPLICIT); + return true; + } + + + @Override + public boolean visit(TypeDeclaration node) + { + JavaDeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); + Range scopeRange = getRange(node); - return super.visit(n, v); + m_client.recordSymbolWithLocationAndScope( + symbolName.toNameHierarchy(), + node.isInterface() ? SymbolKind.INTERFACE : SymbolKind.CLASS, + getRange(node.getName()), + scopeRange, + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); + recordScope(scopeRange); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; } @Override - public Boolean visit(final ClassOrInterfaceDeclaration n, final Void v) + public void endVisit(TypeDeclaration node) { - SimpleName name = n.getName(); - - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - m_client.recordSymbolWithLocationAndScope( - qualifiedName, (n.isInterface() ? SymbolKind.INTERFACE : SymbolKind.CLASS), - name.getRange(), - n.getRange(), - AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), - DefinitionKind.EXPLICIT - ); - - if (n.getRange().isPresent()) - { - FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin()); - recordScope(Range.range(scopeStartLocation.line, scopeStartLocation.column, n.getRange().get().end.line, n.getRange().get().end.column)); - } - - List parentContext = m_context; - m_context = new ArrayList(); - m_context.add(new DeclContext(qualifiedName)); - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; + m_contextStack.pop(); } + @Override - public Boolean visit(final TypeParameter n, final Void v) + public boolean visit(TypeParameter node) { - // todo: test recording of typeargument of type parameter bound type?? - - - if (m_context.size() != 1) - { - // throw something! - } - - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - Optional range = Optional.empty(); - if (n.getBegin().isPresent()) - { - range = Optional.of(Range.range( - n.getBegin().get().line, - n.getBegin().get().column, - n.getBegin().get().line, - n.getBegin().get().column + n.getNameAsString().length() - 1 - )); - } + JavaDeclName symbolName = BindingNameResolver.getQualifiedName(node.resolveBinding(), m_filePath, m_compilationUnit).map(tn -> tn.toDeclName()).orElse(JavaDeclName.unsolved()); m_client.recordSymbolWithLocation( - qualifiedName, SymbolKind.TYPE_PARAMETER, - range, - AccessKind.TYPE_PARAMETER, - DefinitionKind.EXPLICIT - ); + symbolName.toNameHierarchy(), SymbolKind.TYPE_PARAMETER, + getRange(node.getName()), + AccessKind.TYPE_PARAMETER, + DefinitionKind.EXPLICIT); - List parentContext = m_context; - m_context = new ArrayList(); - m_context.add(new DeclContext(qualifiedName)); - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; + m_contextStack.push(Arrays.asList(symbolName)); + + return true; } @Override - public Boolean visit(final EnumDeclaration n, final Void v) + public void endVisit(TypeParameter node) { - SimpleName name = n.getName(); - - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - m_client.recordSymbolWithLocationAndScope( - qualifiedName, SymbolKind.ENUM, - name.getRange(), - n.getRange(), - AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), - DefinitionKind.EXPLICIT - ); - - if (n.getRange().isPresent()) - { - FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin()); - recordScope(Range.range(scopeStartLocation.line, scopeStartLocation.column, n.getRange().get().end.line, n.getRange().get().end.column)); - } - - List parentContext = m_context; - m_context = new ArrayList(); - m_context.add(new DeclContext(qualifiedName)); - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; + m_contextStack.pop(); } - @Override - public Boolean visit(final EnumConstantDeclaration n, final Void v) + + + @Override + public boolean visit(EnumDeclaration node) { - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); + JavaDeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); + Range scopeRange = getRange(node); + + m_client.recordSymbolWithLocationAndScope( + symbolName.toNameHierarchy(), + SymbolKind.ENUM, + getRange(node.getName()), + scopeRange, + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); + recordScope(scopeRange); + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override + public void endVisit(EnumDeclaration node) + { + m_contextStack.pop(); + } + + + public boolean visit(EnumConstantDeclaration node) + { + JavaDeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); + m_client.recordSymbolWithLocation( - qualifiedName, SymbolKind.ENUM_CONSTANT, - n.getRange(), - AccessKind.NONE, - DefinitionKind.EXPLICIT - ); + symbolName.toNameHierarchy(), + SymbolKind.ENUM_CONSTANT, + getRange(node.getName()), + AccessKind.NONE, + DefinitionKind.EXPLICIT); + + m_contextStack.push(Arrays.asList(symbolName)); - List parentContext = m_context; - m_context = new ArrayList(); - m_context.add(new DeclContext(qualifiedName)); - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; - } - - @Override - public Boolean visit(final ConstructorDeclaration n, final Void v) - { - SimpleName name = n.getName(); - - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - m_client.recordSymbolWithLocationAndScope( - qualifiedName, SymbolKind.METHOD, - name.getRange(), - n.getRange(), - AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), - DefinitionKind.EXPLICIT - ); - - List parentContext = m_context; - m_context = new ArrayList(); - m_context.add(new DeclContext(qualifiedName)); - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; + return true; } @Override - public Boolean visit(final MethodDeclaration n, final Void v) + public void endVisit(EnumConstantDeclaration node) + { + m_contextStack.pop(); + } + + + @Override + public boolean visit(MethodDeclaration node) { if (m_client.getInterrupted()) { - // return something that is not null in order to cancel AST traversal; return false; } - SimpleName name = n.getName(); - - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); + JavaDeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); m_client.recordSymbolWithLocationAndScope( - qualifiedName, SymbolKind.METHOD, - name.getRange(), - n.getRange(), - AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), - DefinitionKind.EXPLICIT - ); + symbolName.toNameHierarchy(), + SymbolKind.METHOD, + getRange(node.getName()), + getRange(node), + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); -// test this! - com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration overridden = getOverridden(n); - if (overridden != null) + Optional overriddenMethod = getOverriddenMethod(node.resolveBinding()); + if (overriddenMethod.isPresent()) { - String overriddenName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName( - overridden, m_filePath, m_typeSolver).toNameHierarchy().serialize(); + // We use the declaration to replace type arguments with the respective type parameters inside the signature. + IMethodBinding overriddenMethodDeclaration = overriddenMethod.get().getMethodDeclaration(); + + JavaDeclName overriddenMethodName = BindingNameResolver.getQualifiedName(overriddenMethodDeclaration, m_filePath, m_compilationUnit).orElse(JavaDeclName.unsolved()); + if (!overriddenMethodName.getIsUnsolved()) + { + m_client.recordSymbol(overriddenMethodName.toNameHierarchy(), SymbolKind.METHOD, AccessKind.NONE, DefinitionKind.NONE); + } m_client.recordReference( - ReferenceKind.OVERRIDE, overriddenName, qualifiedName, - name.getRange() - ); + ReferenceKind.OVERRIDE, + overriddenMethodName.toNameHierarchy(), + symbolName.toNameHierarchy(), + getRange(node.getName())); } - List parentContext = m_context; - m_context = new ArrayList(); - m_context.add(new DeclContext(qualifiedName)); - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; + m_contextStack.push(Arrays.asList(symbolName)); + + return true; } - private com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration getOverridden(MethodDeclaration overrider) + @Override + public void endVisit(MethodDeclaration node) { - com.github.javaparser.ast.body.TypeDeclaration scopeNode = overrider.getAncestorOfType(com.github.javaparser.ast.body.TypeDeclaration.class).get(); - if (scopeNode instanceof ClassOrInterfaceDeclaration) + m_contextStack.pop(); + } + + + @Override + public boolean visit(FieldDeclaration node) + { + ArrayList childContext = new ArrayList<>(); + + for (Object declarator: node.fragments()) { - List parameterTypes = new ArrayList<>(); - try + if (declarator instanceof VariableDeclarationFragment) { - for (Parameter parameter: overrider.getParameters()) - { - Type parameterType = parameter.getType(); - parameterTypes.add(JavaParserFacade.get(m_typeSolver).convert(parameterType, parameterType)); - } + VariableDeclarationFragment fragment = (VariableDeclarationFragment) declarator; - ReferenceTypeDeclaration scopeDecl = JavaParserFacade.get(m_typeSolver).getTypeDeclaration((ClassOrInterfaceDeclaration)scopeNode); - for (ReferenceType ancestor: scopeDecl.getAllAncestors()) - { - try - { - SymbolReference solvedMethod = MethodResolutionLogic.solveMethodInType( - ancestor.getTypeDeclaration(), - overrider.getNameAsString(), - parameterTypes, - m_typeSolver - ); - - if (solvedMethod.isSolved()) - { - return solvedMethod.getCorrespondingDeclaration(); - } - } - catch (UnsolvedSymbolException e) - { - // nothing to do here, just try to solve in the next ancestor - } - catch (Exception e) - { - // hmm, maybe we should handle these cases. soon.. - // don't do anything for parse exceptions. they are displayed as errors anyways. - } - } - } - catch (UnsolvedSymbolException e) - { - return null; - } - catch (ClassCastException e) - { - return null; - } - catch (Exception e) - { - return null; - } - } - return null; - } - - @Override - public Boolean visit(final FieldDeclaration n, final Void v) - { - List parentContext = m_context; - m_context = new ArrayList(); - - for (VariableDeclarator declarator: n.getVariables()) - { - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(declarator, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - SimpleName name = declarator.getName(); - m_client.recordSymbolWithLocation( - qualifiedName, SymbolKind.FIELD, - name.getRange(), - AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), - DefinitionKind.EXPLICIT - ); - - m_context.add(new DeclContext(qualifiedName)); - } - - Boolean result = super.visit(n, v); - m_context = parentContext; - return result; - } - - @Override - public Boolean visit(final VariableDeclarationExpr n, final Void v) - { - for (VariableDeclarator declarator: n.getVariables()) - { - SimpleName name = declarator.getName(); - - if (name.getBegin().isPresent()) - { - String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">"; + JavaDeclName symbolName = DeclNameResolver.getQualifiedDeclName(fragment, m_filePath, m_compilationUnit); - m_client.recordLocalSymbol(qualifiedName, name.getRange()); + m_client.recordSymbolWithLocation( + symbolName.toNameHierarchy(), SymbolKind.FIELD, + getRange(fragment.getName()), + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + childContext.add(symbolName); } } - // don't change the context here. - return super.visit(n, v); + m_contextStack.push(childContext); + + return true; } @Override - public Boolean visit(final Parameter n, final Void v) + public void endVisit(FieldDeclaration node) { - SimpleName name = n.getName(); - - if (name.getBegin().isPresent()) - { - String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">"; - - m_client.recordLocalSymbol(qualifiedName, name.getRange()); - } - - // don't change the context here. - return super.visit(n, v); + m_contextStack.pop(); } // --- record references --- @Override - public Boolean visit(final ImportDeclaration n, final Void v) + public boolean visit(final ImportDeclaration node) { - Name name = n.getName(); + JavaDeclName symbolName = JavaDeclName.unsolved(); + IBinding binding = node.resolveBinding(); + if (!binding.isRecovered()) + { + if (binding instanceof IPackageBinding) + { + symbolName = BindingNameResolver.getQualifiedName((IPackageBinding) binding, m_filePath, m_compilationUnit).orElse(JavaDeclName.unsolved()); + } + else if (binding instanceof ITypeBinding) + { + symbolName = BindingNameResolver.getQualifiedName((ITypeBinding) binding, m_filePath, m_compilationUnit).map(tn -> tn.toDeclName()).orElse(JavaDeclName.unsolved()); + } + else if (binding instanceof IMethodBinding) + { + symbolName = BindingNameResolver.getQualifiedName((IMethodBinding) binding, m_filePath, m_compilationUnit).orElse(JavaDeclName.unsolved()); + } + else if (binding instanceof IVariableBinding) + { + symbolName = BindingNameResolver.getQualifiedName((IVariableBinding) binding, m_filePath, m_compilationUnit); + } + } - if (n.isAsterisk()) + for (JavaSymbolName context: m_contextStack.peek()) { - String importedName = JavaparserDeclNameResolver.getQualifiedName(name).toNameHierarchy().serialize(); - for (DeclContext context: m_context) - { - m_client.recordReference( + m_client.recordReference( ReferenceKind.IMPORT, - importedName, context.getName(), - name.getRange() - ); - } + symbolName.toNameHierarchy(), context.toNameHierarchy(), + getRange(node.getName())); } - else + + Optional packageName = BindingNameResolver.getQualifiedName(getDeclaringPackage(binding), m_filePath, m_compilationUnit); + if (packageName.isPresent()) { - try - { - List importedDeclNames = new ArrayList<>(); - - SymbolReference solvedTypeDeclatarion = m_typeSolver.tryToSolveType(name.asString()); - if (solvedTypeDeclatarion.isSolved()) - { - importedDeclNames.add(JavaSymbolSolverDeclNameResolver.getQualifiedDeclName( - solvedTypeDeclatarion.getCorrespondingDeclaration(), m_filePath, m_typeSolver)); - } - else if (n.isStatic()) - { - String typeName = name.getQualifier().get().asString(); - String memberName = name.getIdentifier(); - - ReferenceTypeDeclaration solvedDecl = m_typeSolver.solveType(typeName); - - for (com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration methodDecl: solvedDecl.getDeclaredMethods()) // look for method - { - if (methodDecl.getName().equals(memberName)) - { - importedDeclNames.add( - JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(methodDecl, m_filePath, m_typeSolver)); - } - } - if (importedDeclNames.isEmpty() && solvedDecl.hasField(memberName)) // look for field - { - JavaDeclName importedTypeDeclName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(solvedDecl, m_filePath, m_typeSolver); - if (importedTypeDeclName != null) - { - JavaDeclName importedDeclName = new JavaDeclName(memberName); - importedDeclName.setParent(importedTypeDeclName); - importedDeclNames.add(importedDeclName); - } - } - } - - if (!importedDeclNames.isEmpty()) - { - for (JavaDeclName importedDeclName: importedDeclNames) - { - String nameHierarchy = importedDeclName.toNameHierarchy().serialize(); - for (DeclContext context: m_context) - { - m_client.recordReference( - ReferenceKind.IMPORT, - nameHierarchy, context.getName(), - n.getRange() - ); - } - } - } - else - { - m_client.recordError("Import not found: " + name, true, true, n.getRange()); - } - } - catch (Exception e) - { - recordException(e, n); - } + m_client.recordSymbol(packageName.get().toNameHierarchy(), + SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE); } - return super.visit(n, v); + + return true; } @Override - public Boolean visit(final ClassOrInterfaceType n, final Void v) + public boolean visit(SimpleType node) { - try + for (JavaSymbolName context: m_contextStack.peek()) { - for (DeclContext context: m_context) + ITypeBinding binding = node.resolveBinding(); + if (binding != null) { - String referencedName = JavaparserTypeNameResolver.getQualifiedTypeName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - Range range = Range.range(0, 0, 0, 0); - - if (n.getRange().isPresent()) - { - range = Range.range( - n.getRange().get().begin.line, - n.getRange().get().begin.column, - n.getRange().get().begin.line, - n.getRange().get().begin.column + n.getNameAsString().length() - 1 - ); - } - - Optional scope = n.getScope(); - if (scope.isPresent()) - { - Optional position = scope.get().getEnd(); - - if (position.isPresent()) - { - range = range.withEnd( - Position.pos(position.get().line, - position.get().column + n.getNameAsString().length() + 1 // +1 for separator - )); - } - } - - m_client.recordReference( - getTypeReferenceKind(), referencedName, context.getName(), range - ); + binding = binding.getTypeDeclaration(); } + + m_client.recordReference( + getTypeReferenceKind(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(JavaTypeName.unsolved()).toDeclName().toNameHierarchy(), + context.toNameHierarchy(), + getRange(node)); } - catch (Exception e) - { - recordException(e, n); - } - return super.visit(n, v); + return true; } - @Override - public Boolean visit(final PrimitiveType n, final Void v) + @Override + public boolean visit(QualifiedType node) { - try + for (JavaSymbolName context: m_contextStack.peek()) { - String referencedName = JavaparserTypeNameResolver.getQualifiedTypeName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); + ITypeBinding binding = node.resolveBinding(); + if (binding != null) + { + binding = binding.getTypeDeclaration(); + } - m_client.recordSymbol( + m_client.recordReference( + getTypeReferenceKind(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(JavaTypeName.unsolved()).toDeclName().toNameHierarchy(), + context.toNameHierarchy(), + getRange(node)); + } + return true; + } + + @Override + public boolean visit(NameQualifiedType node) + { + for (JavaSymbolName context: m_contextStack.peek()) + { + ITypeBinding binding = node.resolveBinding(); + if (binding != null) + { + binding = binding.getTypeDeclaration(); + } + + m_client.recordReference( + getTypeReferenceKind(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(JavaTypeName.unsolved()).toDeclName().toNameHierarchy(), + context.toNameHierarchy(), + getRange(node)); + } + return true; + } + + @Override + public boolean visit(final PrimitiveType node) + { + NameHierarchy referencedName = JavaTypeName.fromDotSeparatedString(node.getPrimitiveTypeCode().toString()).toDeclName().toNameHierarchy(); + + m_client.recordSymbol( referencedName, SymbolKind.BUILTIN_TYPE, AccessKind.NONE, - DefinitionKind.EXPLICIT - ); + DefinitionKind.EXPLICIT); + + for (JavaSymbolName context: m_contextStack.peek()) + { + m_client.recordReference( + getTypeReferenceKind(), + referencedName, + context.toNameHierarchy(), + getRange(node)); + } + return true; + } + + @Override + public boolean visit(SimpleName node) + { + IBinding binding = node.resolveBinding(); + if (binding instanceof IVariableBinding) + { + IVariableBinding variableBinding = ((IVariableBinding) binding).getVariableDeclaration(); + JavaDeclName declName = BindingNameResolver.getQualifiedName( + variableBinding, m_filePath, m_compilationUnit); - for (DeclContext context: m_context) - { - m_client.recordReference( - getTypeReferenceKind(), referencedName, context.getName(), - n.getRange() - ); + if (declName.getIsUnsolved() && variableBinding.getDeclaringClass() == null && variableBinding.getName().equals("length")) + { + // Do nothing. We ignore the case of unsolved symbols on array type } - } - catch (Exception e) - { - recordException(e, n); - } - - return super.visit(n, v); - } - - @Override - public Boolean visit(final VoidType n, final Void v) - { - try - { - String referencedName = JavaparserTypeNameResolver.getQualifiedTypeName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - m_client.recordSymbol( - referencedName, SymbolKind.BUILTIN_TYPE, AccessKind.NONE, DefinitionKind.EXPLICIT - ); - - for (DeclContext context: m_context) + else if (declName.getIsLocal() || declName.getIsGlobal()) { - m_client.recordReference( - getTypeReferenceKind(), referencedName, context.getName(), n.getRange() - ); - } - } - catch (Exception e) - { - recordException(e, n); - } - - return super.visit(n, v); - } - - @Override - public Boolean visit(final FieldAccessExpr n, final Void v) - { - SimpleName fieldName = n.getName(); - - try - { - SymbolReference ref = JavaParserFacade.get(m_typeSolver).solve(fieldName); - if (ref.isSolved()) - { - ValueDeclaration valueDecl = ref.getCorrespondingDeclaration(); - - Node wrappedNode = null; - if (valueDecl instanceof JavaParserFieldDeclaration) - { - wrappedNode = ((JavaParserFieldDeclaration)valueDecl).getWrappedNode(); - } - if (wrappedNode != null && wrappedNode instanceof FieldDeclaration) - { - - for (VariableDeclarator var: ((FieldDeclaration)wrappedNode).getVariables()) - { - if (var.getName().getIdentifier().equals(fieldName.getIdentifier())) - { - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(var, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - for (DeclContext context: m_context) - { - m_client.recordReference( - ReferenceKind.USAGE, qualifiedName, context.getName(), - fieldName.getRange() - ); - } - } - } - } - } - } - catch (Exception e) - { - recordException(e, n); - } - - return super.visit(n, v); - } - - @Override - public Boolean visit(final NameExpr n, final Void v) - { - try - { - SymbolReference ref = JavaParserFacade.get(m_typeSolver).solve(n); - if (ref.isSolved()) - { - ValueDeclaration valueDecl = ref.getCorrespondingDeclaration(); - - Node wrappedNode = null; - if (valueDecl instanceof JavaParserSymbolDeclaration) - { - wrappedNode = ((JavaParserSymbolDeclaration)valueDecl).getWrappedNode(); - } - else if (valueDecl instanceof JavaParserParameterDeclaration) - { - wrappedNode = ((JavaParserParameterDeclaration)valueDecl).getWrappedNode(); - } - else if (valueDecl instanceof JavaParserFieldDeclaration) - { - wrappedNode = ((JavaParserFieldDeclaration)valueDecl).getWrappedNode(); - } - - if (wrappedNode != null) - { - if (wrappedNode instanceof FieldDeclaration) - { - - for (VariableDeclarator var: ((FieldDeclaration)wrappedNode).getVariables()) - { - if (var.getName().getIdentifier().equals(n.getName().getIdentifier())) - { - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(var, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - for (DeclContext context: m_context) - { - m_client.recordReference( - ReferenceKind.USAGE, qualifiedName, context.getName(), - n.getName().getRange() - ); - } - } - } - } - else if (wrappedNode instanceof Parameter) - { - SimpleName name = ((Parameter)wrappedNode).getName(); - if (name.getBegin().isPresent()) - { - String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">"; - - m_client.recordLocalSymbol( - qualifiedName, - n.getRange() - ); - } - } - else if (wrappedNode instanceof VariableDeclarator) - { - if (wrappedNode.getAncestorOfType(FieldDeclaration.class).isPresent()) - { - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName((VariableDeclarator)wrappedNode, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - - for (DeclContext context: m_context) - { - m_client.recordReference( - ReferenceKind.USAGE, qualifiedName, context.getName(), - n.getRange() - ); - } - } - else - { - SimpleName name = ((VariableDeclarator)wrappedNode).getName(); - if (name.getBegin().isPresent()) - { - String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">"; - - m_client.recordLocalSymbol( - qualifiedName, - n.getRange() - ); - } - } - } - } - } - } - catch (Exception e) - { - recordException(e, n); - } - - return super.visit(n, v); - } - - @Override - public Boolean visit(final MethodCallExpr n, final Void v) - { - String qualifiedName = ""; - if (m_context.size() > 0) - { - try - { - SymbolReference solvedSymbol = JavaParserFacade.get(m_typeSolver).solve(n); - if (solvedSymbol.isSolved()) - { - qualifiedName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName( - solvedSymbol.getCorrespondingDeclaration(), m_filePath, m_typeSolver).toNameHierarchy().serialize(); - } - else - { - throw new UnsolvedSymbolException(n.getNameAsString()); - } - } - catch (UnsupportedOperationException e) - { - recordException(e, n); - } - catch (MethodAmbiguityException e) - { - recordException(e, n); - } - catch(StackOverflowError e) - { - recordError(e, n); - } - catch (Exception e) - { - recordException(e, n); - } - } - - if (!qualifiedName.isEmpty()) - { - SimpleName name = n.getName(); - for (DeclContext context: m_context) - { - m_client.recordReference( - ReferenceKind.CALL, qualifiedName, context.getName(), - name.getRange() - ); - } - } - - return super.visit(n, v); - } - - - private void recordException(Exception e, Node n) - { - recordExceptionOrError(e.getClass().getSimpleName(), n); - } - - private void recordError(Error e, Node n) - { - recordExceptionOrError(e.getClass().getSimpleName(), n); - } - - private void recordExceptionOrError(String e, Node n) - { - String beginLine = "?"; - String beginColumn = "?"; - - if (n.getBegin().isPresent()) - { - beginLine = n.getBegin().get().line + ""; - beginColumn = n.getBegin().get().column + ""; - } - - m_client.logError(e + " at " + m_filePath + "<"+ beginLine + ", " + beginColumn + ">"); - m_client.recordSymbolWithLocation( - JavaDeclName.unsolved().toNameHierarchy().serialize(), SymbolKind.TYPE_MAX, - n.getRange(), - AccessKind.DEFAULT, - DefinitionKind.EXPLICIT - ); - } - - @Override - public Boolean visit(final ObjectCreationExpr n, final Void v) - { - if (m_context.size() > 0) - { - if (n.getAnonymousClassBody().isPresent()) - { - String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_filePath, m_typeSolver).toNameHierarchy().serialize(); - m_client.recordSymbolWithLocationAndScope( - qualifiedName, SymbolKind.CLASS, - n.getType().getRange(), - n.getRange(), - AccessKind.NONE, - DefinitionKind.EXPLICIT - ); + m_client.recordLocalSymbol( + declName.toNameHierarchy(), getRange(node)); } else { - String qualifiedName = ""; - try + m_client.recordSymbol(declName.toNameHierarchy(), SymbolKind.FIELD, AccessKind.NONE, DefinitionKind.NONE); + + for (JavaSymbolName context: m_contextStack.peek()) { - SymbolReference solvedSymbol = JavaParserFacade.get(m_typeSolver).solve(n); - if (solvedSymbol.isSolved()) - { - qualifiedName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(solvedSymbol.getCorrespondingDeclaration(), m_filePath, m_typeSolver).toNameHierarchy().serialize(); - } - else - { - throw new UnsolvedSymbolException("constructor for " + n.getType().getNameAsString()); - } - } - catch (UnsupportedOperationException e) - { - recordException(e, n); - } - catch (MethodAmbiguityException e) - { - recordException(e, n); - } - catch(StackOverflowError e) - { - recordError(e, n); - } - catch (Exception e) - { - recordException(e, n); - } - - if (!qualifiedName.isEmpty()) - { - ClassOrInterfaceType type = n.getType(); - for (DeclContext context: m_context) - { - m_client.recordReference( - ReferenceKind.CALL, qualifiedName, context.getName(), - type.getRange() - ); - } + m_client.recordReference( + ReferenceKind.USAGE, + declName.toNameHierarchy(), + context.toNameHierarchy(), + getRange(node)); } } } - return super.visit(n, v); + return true; } @Override - public Boolean visit(final BlockStmt n, final Void v) + public boolean visit(MethodInvocation node) { - recordScope(n.getRange()); - return super.visit(n, v); + recordReferenceToMethodDeclaration(node.resolveMethodBinding(), getRange(node.getName()), ReferenceKind.CALL, m_contextStack.peek()); + return true; } @Override - public Boolean visit(final ArrayInitializerExpr n, final Void v) + public boolean visit(SuperMethodInvocation node) { - recordScope(n.getRange()); - return super.visit(n, v); + recordReferenceToMethodDeclaration(node.resolveMethodBinding(), getRange(node.getName()), ReferenceKind.CALL, m_contextStack.peek()); + return true; + } + + @Override + public boolean visit(ConstructorInvocation node) + { + recordReferenceToMethodDeclaration( + node.resolveConstructorBinding(), + m_fileContent.findRange("this", getRange(node).begin), + ReferenceKind.CALL, + m_contextStack.peek()); + + return true; + } + + @Override + public boolean visit(SuperConstructorInvocation node) + { + recordReferenceToMethodDeclaration( + node.resolveConstructorBinding(), + m_fileContent.findRange("super", getRange(node).begin), + ReferenceKind.CALL, + m_contextStack.peek()); + + return true; + } + + @Override + public boolean visit(CreationReference node) + { + recordReferenceToMethodDeclaration( + node.resolveMethodBinding(), + m_fileContent.findRange("new", getRange(node).begin), + ReferenceKind.USAGE, + m_contextStack.peek()); + return true; + } + + @Override + public boolean visit(ExpressionMethodReference node) + { + recordReferenceToMethodDeclaration( + node.resolveMethodBinding(), + getRange(node.getName()), + ReferenceKind.USAGE, + m_contextStack.peek()); + + return true; + } + + @Override + public boolean visit(SuperMethodReference node) + { + recordReferenceToMethodDeclaration( + node.resolveMethodBinding(), + getRange(node.getName()), + ReferenceKind.USAGE, + m_contextStack.peek()); + + return true; + } + + @Override + public boolean visit(TypeMethodReference node) + { + IMethodBinding binding = node.resolveMethodBinding(); + if (binding == null && node.getType() != null && node.getType().isArrayType()) + { + // Do nothing. We ignore the case of unsolved symbols on array type + } + else + { + recordReferenceToMethodDeclaration( + binding, + getRange(node.getName()), + ReferenceKind.USAGE, + m_contextStack.peek()); + } + + return true; + } + + @Override + public boolean visit(ClassInstanceCreation node) + { + if (node.getAnonymousClassDeclaration() != null) + { + // record anonymous class here instead of overriding visit(AnonymousClassDeclaration node) because + // the ClassInstanceCreation still contains the Type node. + + AnonymousClassDeclaration anonymousClassDeclaration = node.getAnonymousClassDeclaration(); + JavaDeclName symbolName = DeclNameResolver.getQualifiedDeclName(anonymousClassDeclaration, m_filePath, m_compilationUnit); + + Range anonymousClassScope = getRange(anonymousClassDeclaration); + + m_client.recordSymbolWithLocationAndScope( + symbolName.toNameHierarchy(), + SymbolKind.CLASS, + new Range(anonymousClassScope.begin, anonymousClassScope.begin), + anonymousClassScope, + AccessKind.NONE, + DefinitionKind.EXPLICIT); + + recordScope(anonymousClassScope); + + m_contextStack.push(Arrays.asList(symbolName)); + } + else + { + IMethodBinding constructorBinding = node.resolveConstructorBinding(); + if (constructorBinding != null) + { + constructorBinding = constructorBinding.getMethodDeclaration(); + } + + JavaDeclName referencedDeclName = BindingNameResolver.getQualifiedName(constructorBinding, m_filePath, m_compilationUnit).orElse(JavaDeclName.unsolved()); + if (!referencedDeclName.getIsUnsolved()) + { + m_client.recordSymbol(referencedDeclName.toNameHierarchy(), SymbolKind.METHOD, AccessKind.NONE, DefinitionKind.NONE); + } + + for (JavaSymbolName context: m_contextStack.peek()) + { + m_client.recordReference( + ReferenceKind.CALL, + referencedDeclName.toNameHierarchy(), + context.toNameHierarchy(), + getRange(node.getType())); + } + } + + return true; + } + + @Override + public void endVisit(ClassInstanceCreation node) + { + if (node.getAnonymousClassDeclaration() != null) + { + m_contextStack.pop(); + } + } + + @Override + public boolean visit(Block node) + { + recordScope(getRange(node)); + return true; + } + + @Override + public boolean visit(ArrayInitializer node) + { + recordScope(getRange(node)); + return true; } @Override - public Boolean visit(final SwitchStmt n, final Void v) + public boolean visit(SwitchStatement node) { - if (n.getRange().isPresent()) - { - FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin()); - recordScope(Range.range(scopeStartLocation.line, scopeStartLocation.column, n.getRange().get().end.line, n.getRange().get().end.column)); - } - return super.visit(n, v); + Range scopeRange = getRange(node); + scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); + recordScope(scopeRange); + + return true; } - private void recordScope(Optional range) + @Override + public boolean visit(LineComment node) { - if (range.isPresent()) + m_client.recordComment(getRange(node)); + return true; + } + + @Override + public boolean visit(BlockComment node) + { + m_client.recordComment(getRange(node)); + return true; + } + + @Override + public boolean visit(Javadoc node) + { + m_client.recordComment(getRange(node)); + return true; + } + + + // --- utility methods --- + + private void recordReferenceToMethodDeclaration(IMethodBinding methodBinding, Range range, ReferenceKind referenceKind, List contexts) + { + if (methodBinding != null) { - recordScope(range.get()); + // replacing type arguments of invocation with type variables of declaration + methodBinding = methodBinding.getMethodDeclaration(); + } + + JavaDeclName referencedDeclName = BindingNameResolver.getQualifiedName(methodBinding, m_filePath, m_compilationUnit).orElse(JavaDeclName.unsolved()); + if (!referencedDeclName.getIsUnsolved()) + { + m_client.recordSymbol(referencedDeclName.toNameHierarchy(), SymbolKind.METHOD, AccessKind.NONE, DefinitionKind.NONE); + } + + for (JavaSymbolName context: m_contextStack.peek()) + { + m_client.recordReference( + referenceKind, + referencedDeclName.toNameHierarchy(), + context.toNameHierarchy(), + range); } } private void recordScope(Range range) { - String qualifiedName = m_filePath + "<" + range.begin.line + ":" + range.begin.column + ">"; - m_client.recordLocalSymbol(qualifiedName, Range.range(range.begin, range.begin)); - m_client.recordLocalSymbol(qualifiedName, Range.range(range.end, range.end)); + NameHierarchy nameHierarchy = JavaDeclName.scope(m_filePath, range.begin).toNameHierarchy(); + m_client.recordLocalSymbol(nameHierarchy, new Range(range.begin, range.begin)); + m_client.recordLocalSymbol(nameHierarchy, new Range(range.end, range.end)); } - @Override - public Boolean visit(final LineComment n, final Void v) + protected Range getRange(ASTNode node) { - m_client.recordComment(n.getRange()); - return super.visit(n, v); + return Utility.getRange(node, m_compilationUnit); } - - @Override - public Boolean visit(final BlockComment n, final Void v) + + private IPackageBinding getDeclaringPackage(IBinding binding) { - m_client.recordComment(n.getRange()); - return super.visit(n, v); + if (binding instanceof IPackageBinding) + { + return (IPackageBinding) binding; + } + else if (binding != null) + { + return getDeclaringPackage(BindingNameResolver.getParentBinding(binding)); + } + return null; + } + + private Optional getOverriddenMethod(IMethodBinding method) + { + if (method != null) + { + for (ITypeBinding declaringClassAncestor: getAllAncestorTypes(method.getDeclaringClass())) + { + for (IMethodBinding potentiallyOverridden: declaringClassAncestor.getDeclaredMethods()) + { + if (method.overrides(potentiallyOverridden)) + { + return Optional.of(potentiallyOverridden); + } + } + } + } + + return Optional.empty(); + } + + private List getAllAncestorTypes(ITypeBinding type) + { + List allAncestorTypes = new ArrayList<>(); + + List directAncestorTypes = getDirectAncestorTypes(type); + allAncestorTypes.addAll(directAncestorTypes); + + for (ITypeBinding directAncestorType: directAncestorTypes) + { + allAncestorTypes.addAll(getAllAncestorTypes(directAncestorType)); + } + + return allAncestorTypes; + } + + private List getDirectAncestorTypes(ITypeBinding type) + { + List ancestorTypes = new ArrayList<>(); + + if (type != null) + { + ITypeBinding superclass = type.getSuperclass(); + if (superclass != null) + { + ancestorTypes.add(superclass); + } + + ancestorTypes.addAll(Arrays.asList(type.getInterfaces())); + } + + return ancestorTypes; } } \ No newline at end of file diff --git a/java_indexer/src/main/java/com/sourcetrail/AstVisitorAdapter.java b/java_indexer/src/main/java/com/sourcetrail/AstVisitorAdapter.java deleted file mode 100644 index fe20e55b..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/AstVisitorAdapter.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.sourcetrail; - -import com.github.javaparser.ast.visitor.GenericVisitorAdapter; - -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; - -import java.util.Stack; - -public abstract class AstVisitorAdapter extends GenericVisitorAdapter -{ - private Stack m_typeRefKind = new Stack(); - - protected ReferenceKind getTypeReferenceKind() - { - if (!m_typeRefKind.isEmpty()) - { - return m_typeRefKind.peek(); - } - return ReferenceKind.TYPE_USAGE; - } - - //- Compilation Unit ---------------------------------- - - @Override public Boolean visit(final CompilationUnit n, Void arg) - { - m_typeRefKind.push(ReferenceKind.TYPE_USAGE); - Boolean result = super.visit(n, arg); - m_typeRefKind.pop(); - return result; - } - - //- Body ---------------------------------------------- - - @Override public Boolean visit(ClassOrInterfaceDeclaration n, Void arg) - { - Boolean result; - { - result = n.getTypeParameters().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getMembers().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getName().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getAnnotations().accept(this, arg); - if (result != null) - return result; - } - if (n.getComment().isPresent()) { - result = n.getComment().get().accept(this, arg); - if (result != null) - return result; - } - - m_typeRefKind.push(ReferenceKind.INHERITANCE); - { - result = n.getExtendedTypes().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getImplementedTypes().accept(this, arg); - if (result != null) - return result; - } - m_typeRefKind.pop(); - - return null; - } - - @Override public Boolean visit(EnumDeclaration n, Void arg) - { - Boolean result; - { - result = n.getEntries().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getMembers().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getName().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getAnnotations().accept(this, arg); - if (result != null) - return result; - } - if (n.getComment().isPresent()) { - result = n.getComment().get().accept(this, arg); - if (result != null) - return result; - } - - m_typeRefKind.push(ReferenceKind.INHERITANCE); - { - result = n.getImplementedTypes().accept(this, arg); - if (result != null) - return result; - } - m_typeRefKind.pop(); - - return null; - } - - //- Type ---------------------------------------------- - - @Override public Boolean visit(ClassOrInterfaceType n, Void arg) - { - Boolean result; - { - result = n.getName().accept(this, arg); - if (result != null) - return result; - } - // don't visit the qualifier here. -// if (n.getScope().isPresent()) { -// result = n.getScope().get().accept(this, arg); -// if (result != null) -// return result; -// } - { - result = n.getAnnotations().accept(this, arg); - if (result != null) - return result; - } - if (n.getComment().isPresent()) { - result = n.getComment().get().accept(this, arg); - if (result != null) - return result; - } - - m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); - if (n.getTypeArguments().isPresent()) { - result = n.getTypeArguments().get().accept(this, arg); - if (result != null) - return result; - } - m_typeRefKind.pop(); - - return null; - } - - //- Expression ---------------------------------------- - - @Override public Boolean visit(MethodCallExpr n, Void arg) - { - Boolean result; - { - result = n.getArguments().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getName().accept(this, arg); - if (result != null) - return result; - } - if (n.getScope().isPresent()) { - result = n.getScope().get().accept(this, arg); - if (result != null) - return result; - } - if (n.getComment().isPresent()) { - result = n.getComment().get().accept(this, arg); - if (result != null) - return result; - } - - m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); - if (n.getTypeArguments().isPresent()) { - result = n.getTypeArguments().get().accept(this, arg); - if (result != null) - return result; - } - m_typeRefKind.pop(); - - return null; - } - - @Override public Boolean visit(ObjectCreationExpr n, Void arg) - { - Boolean result; - if (n.getAnonymousClassBody().isPresent()) { - result = n.getAnonymousClassBody().get().accept(this, arg); - if (result != null) - return result; - } - { - result = n.getArguments().accept(this, arg); - if (result != null) - return result; - } - if (n.getScope().isPresent()) { - result = n.getScope().get().accept(this, arg); - if (result != null) - return result; - } -// { -// result = n.getType().accept(this, arg); -// if (result != null) -// return result; -// } - if (n.getComment().isPresent()) { - result = n.getComment().get().accept(this, arg); - if (result != null) - return result; - } - - m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); - if (n.getTypeArguments().isPresent()) { - result = n.getTypeArguments().get().accept(this, arg); - if (result != null) - return result; - } - m_typeRefKind.pop(); - - return null; - } - - //- Statements ---------------------------------------- - - @Override public Boolean visit(ExplicitConstructorInvocationStmt n, Void arg) - { - Boolean result; - { - result = n.getArguments().accept(this, arg); - if (result != null) - return result; - } - if (n.getExpression().isPresent()) { - result = n.getExpression().get().accept(this, arg); - if (result != null) - return result; - } - if (n.getComment().isPresent()) { - result = n.getComment().get().accept(this, arg); - if (result != null) - return result; - } - - m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); - if (n.getTypeArguments().isPresent()) { - result = n.getTypeArguments().get().accept(this, arg); - if (result != null) - return result; - } - m_typeRefKind.pop(); - - return null; - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java b/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java index 674e643d..2ce24bbf 100644 --- a/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java +++ b/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java @@ -2,73 +2,63 @@ package com.sourcetrail; import java.util.Optional; -import com.github.javaparser.Range; +import com.sourcetrail.name.NameHierarchy; public abstract class AstVisitorClient { public void recordSymbolWithLocation( - String symbolName, SymbolKind symbolType, - Optional range, - AccessKind access, DefinitionKind definitionKind - ) + NameHierarchy symbolName, SymbolKind symbolKind, + Optional range, + AccessKind access, DefinitionKind definitionKind) { recordSymbolWithLocation( - symbolName, symbolType, - range.orElse(Range.range(0, 0, 0, 0)), - access, definitionKind - ); + symbolName, symbolKind, + range.orElse(new Range(0, 0, 0, 0)), + access, definitionKind); } public void recordSymbolWithLocationAndScope( - String symbolName, SymbolKind symbolType, - Optional range, - Optional scopeRange, - AccessKind access, DefinitionKind definitionKind - ) + NameHierarchy symbolName, SymbolKind symbolKind, + Optional range, + Optional scopeRange, + AccessKind access, DefinitionKind definitionKind) { recordSymbolWithLocationAndScope( - symbolName, symbolType, - range.orElse(Range.range(0, 0, 0, 0)), - scopeRange.orElse(Range.range(0, 0, 0, 0)), - access, definitionKind - ); + symbolName, symbolKind, + range.orElse(new Range(0, 0, 0, 0)), + scopeRange.orElse(new Range(0, 0, 0, 0)), + access, definitionKind); } public void recordReference( - ReferenceKind referenceKind, String referencedName, String contextName, - Optional range - ) + ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName, + Optional range) { recordReference( - referenceKind, referencedName, contextName, - range.orElse(Range.range(0, 0, 0, 0)) - ); + referenceKind, referencedName, contextName, + range.orElse(new Range(0, 0, 0, 0))); } public void recordLocalSymbol( - String symbolName, - Optional range - ) + NameHierarchy symbolName, + Optional range) { - recordLocalSymbol(symbolName, range.orElse(Range.range(0, 0, 0, 0))); + recordLocalSymbol(symbolName, range.orElse(new Range(0, 0, 0, 0))); } public void recordComment( - Optional range - ) + Optional range) { - recordComment(range.orElse(Range.range(0, 0, 0, 0))); + recordComment(range.orElse(new Range(0, 0, 0, 0))); } public void recordError( String message, boolean fatal, boolean indexed, - Optional range - ) + Optional range) { recordError( - message, fatal, indexed, - range.orElse(Range.range(0, 0, 0, 0)) - ); + message, fatal, indexed, + range.orElse(new Range(0, 0, 0, 0))); } public abstract boolean getInterrupted(); @@ -80,40 +70,33 @@ public abstract class AstVisitorClient public abstract void logError(String error); public abstract void recordSymbol( - String symbolName, SymbolKind symbolType, - AccessKind access, DefinitionKind definitionKind - ); + NameHierarchy symbolName, SymbolKind symbolKind, + AccessKind access, DefinitionKind definitionKind); public abstract void recordSymbolWithLocation( - String symbolName, SymbolKind symbolType, - Range range, - AccessKind access, DefinitionKind definitionKind - ); + NameHierarchy symbolName, SymbolKind symbolKind, + Range range, + AccessKind access, DefinitionKind definitionKind); public abstract void recordSymbolWithLocationAndScope( - String symbolName, SymbolKind symbolType, - Range range, - Range scopeRange, - AccessKind access, DefinitionKind definitionKind - ); + NameHierarchy symbolName, SymbolKind symbolKind, + Range range, + Range scopeRange, + AccessKind access, DefinitionKind definitionKind); public abstract void recordReference( - ReferenceKind referenceKind, String referencedName, String contextName, - Range range - ); + ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName, + Range range); public abstract void recordLocalSymbol( - String symbolName, - Range range - ); + NameHierarchy symbolName, + Range range); public abstract void recordComment( - Range range - ); + Range range); public abstract void recordError( - String message, boolean fatal, boolean indexed, - Range range - ); + String message, boolean fatal, boolean indexed, + Range range); } diff --git a/java_indexer/src/main/java/com/sourcetrail/CallableConstructorDecl.java b/java_indexer/src/main/java/com/sourcetrail/CallableConstructorDecl.java deleted file mode 100644 index 81d147e1..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/CallableConstructorDecl.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.sourcetrail; - -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.UnknownType; - -public class CallableConstructorDecl implements CallableDecl -{ - private ConstructorDeclaration m_decl; - - public CallableConstructorDecl(ConstructorDeclaration decl) - { - m_decl = decl; - } - - public BodyDeclaration getWrappedNode() - { - return m_decl; - } - - public boolean isMethod() - { - return false; - } - - public String getName() - { - return m_decl.getNameAsString(); - } - - public NodeList getTypeParameters() - { - return m_decl.getTypeParameters(); - } - - public NodeList getParameters() - { - return m_decl.getParameters(); - } - - public Type getType() - { - return new UnknownType(); - } - - public boolean isStatic() - { - return m_decl.isStatic(); - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/CallableDecl.java b/java_indexer/src/main/java/com/sourcetrail/CallableDecl.java deleted file mode 100644 index b0f6c3ab..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/CallableDecl.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.sourcetrail; - -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.type.Type; - -public interface CallableDecl -{ - public BodyDeclaration getWrappedNode(); - public boolean isMethod(); - public String getName(); - public NodeList getTypeParameters(); - public NodeList getParameters(); - public Type getType(); - public boolean isStatic(); -} diff --git a/java_indexer/src/main/java/com/sourcetrail/CallableMethodDecl.java b/java_indexer/src/main/java/com/sourcetrail/CallableMethodDecl.java deleted file mode 100644 index f55c6b0f..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/CallableMethodDecl.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.sourcetrail; - -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.type.Type; - -public class CallableMethodDecl implements CallableDecl -{ - private MethodDeclaration m_decl; - - public CallableMethodDecl(MethodDeclaration decl) - { - m_decl = decl; - } - - public BodyDeclaration getWrappedNode() - { - return m_decl; - } - - public boolean isMethod() - { - return true; - } - - public String getName() - { - return m_decl.getNameAsString(); - } - - public NodeList getTypeParameters() - { - return m_decl.getTypeParameters(); - } - - public NodeList getParameters() - { - return m_decl.getParameters(); - } - - public Type getType() - { - return m_decl.getType(); - } - - public boolean isStatic() - { - return m_decl.isStatic(); - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java new file mode 100644 index 00000000..344341a1 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java @@ -0,0 +1,387 @@ +package com.sourcetrail; + +import java.io.File; +import java.util.List; +import java.util.Stack; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ConstructorInvocation; +import org.eclipse.jdt.core.dom.CreationReference; +import org.eclipse.jdt.core.dom.EnumConstantDeclaration; +import org.eclipse.jdt.core.dom.EnumDeclaration; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.Javadoc; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.NameQualifiedType; +import org.eclipse.jdt.core.dom.ParameterizedType; +import org.eclipse.jdt.core.dom.QualifiedType; +import org.eclipse.jdt.core.dom.SuperConstructorInvocation; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.eclipse.jdt.core.dom.SuperMethodReference; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.TypeMethodReference; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; + +public class ContextAwareAstVisitor extends AstVisitor +{ + private Stack m_typeRefKind = new Stack<>(); + + public ContextAwareAstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) + { + super(client, filePath, fileContent, compilationUnit); + } + + @Override + public boolean visit(TypeDeclaration node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChild(node.getJavadoc()); + acceptChildren(node.modifiers()); + acceptChild(node.getName()); + acceptChildren(node.typeParameters()); + { + m_typeRefKind.push(ReferenceKind.INHERITANCE); + acceptChild(node.getSuperclassType()); + acceptChildren(node.superInterfaceTypes()); + m_typeRefKind.pop(); + } + acceptChildren(node.bodyDeclarations()); + } + + return false; + } + + @Override + public boolean visit(EnumDeclaration node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChild(node.getJavadoc()); + acceptChildren(node.modifiers()); + acceptChild(node.getName()); + { + m_typeRefKind.push(ReferenceKind.INHERITANCE); + acceptChildren(node.superInterfaceTypes()); + m_typeRefKind.pop(); + } + acceptChildren(node.enumConstants()); + acceptChildren(node.bodyDeclarations()); + } + + return false; + } + + @Override + public boolean visit(EnumConstantDeclaration node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + // we don't visit and record the name of enum constant declarations because + // this would create an unwanted self-reference. + acceptChild(node.getJavadoc()); + acceptChildren(node.modifiers()); + acceptChildren(node.arguments()); + acceptChild(node.getAnonymousClassDeclaration()); + } + + return false; + } + + @Override + public boolean visit(VariableDeclarationFragment node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + // we don't visit and record the name of field declarations because + // this would create an unwanted self-reference. + if (!(node.getParent() instanceof FieldDeclaration)) + { + acceptChild(node.getName()); + } + acceptChildren(node.extraDimensions()); + acceptChild(node.getInitializer()); + } + + return false; + } + + @Override + public boolean visit(ClassInstanceCreation node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChild(node.getExpression()); + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + + if (node.getAnonymousClassDeclaration() != null) + { + m_typeRefKind.push(ReferenceKind.INHERITANCE); + acceptChild(node.getType()); + m_typeRefKind.pop(); + } + else + { + acceptChild(node.getType()); + } + + acceptChildren(node.arguments()); + acceptChild(node.getAnonymousClassDeclaration()); + } + + return false; + } + + @Override + public boolean visit(ParameterizedType node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChild(node.getType()); + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + } + + return false; + } + + @Override + public boolean visit(QualifiedType node) + { + // We don't want to visit the qualifier right now. + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChildren(node.annotations()); + acceptChild(node.getName()); + } + + return false; + } + + @Override + public boolean visit(NameQualifiedType node) + { + // We don't want to visit the qualifier right now. + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChildren(node.annotations()); + acceptChild(node.getName()); + } + + return false; + } + + @Override + public boolean visit(final ImportDeclaration node) + { + // We don't want to visit the name of the ImportDeclaration because this could cause a self reference. + super.visit(node); + return false; + } + + + + + + @Override + public boolean visit(MethodInvocation node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChild(node.getExpression()); + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + acceptChild(node.getName()); + acceptChildren(node.arguments()); + } + + return false; + } + + @Override + public boolean visit(SuperMethodInvocation node) + { + // We don't want to visit the qualifier right now. + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + acceptChild(node.getName()); + acceptChildren(node.arguments()); + } + + return false; + } + + @Override + public boolean visit(ConstructorInvocation node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + acceptChildren(node.arguments()); + } + + return false; + } + + @Override + public boolean visit(SuperConstructorInvocation node) + { + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + acceptChild(node.getExpression()); + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + acceptChildren(node.arguments()); + } + + return false; + } + + + + + @Override + public boolean visit(CreationReference node) + { + // We don't want to visit the qualifying type right now. + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + } + + return false; + } + + @Override + public boolean visit(SuperMethodReference node) + { + // We don't want to visit qualifiers right now. + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + acceptChild(node.getName()); + } + + return false; + } + + @Override + public boolean visit(TypeMethodReference node) + { + // We don't want to visit the qualifying type right now. + boolean visitChildren = super.visit(node); + + if (visitChildren) + { + { + m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT); + acceptChildren(node.typeArguments()); + m_typeRefKind.pop(); + } + acceptChild(node.getName()); + } + + return false; + } + + @Override + public boolean visit(Javadoc node) + { + // We don't want to visit symbol references inside Javadoc right now. + super.visit( node); + return false; + } + + @Override + protected ReferenceKind getTypeReferenceKind() + { + if (!m_typeRefKind.isEmpty()) + { + return m_typeRefKind.peek(); + } + return ReferenceKind.TYPE_USAGE; + } + + private void acceptChild(ASTNode node) + { + if (node != null) + { + node.accept(this); + } + } + + private void acceptChildren(List nodes) + { + if (nodes != null) + { + for (Object node: nodes) + { + if (node instanceof ASTNode) + { + acceptChild((ASTNode) node); + } + } + } + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/ContextList.java b/java_indexer/src/main/java/com/sourcetrail/ContextList.java index 5ceeec39..bc5ef072 100644 --- a/java_indexer/src/main/java/com/sourcetrail/ContextList.java +++ b/java_indexer/src/main/java/com/sourcetrail/ContextList.java @@ -1,57 +1,33 @@ package com.sourcetrail; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.TypeParametrizable; +import org.eclipse.jdt.core.dom.IBinding; public class ContextList { - private List m_bodyDeclarations = new ArrayList<>(); - private List m_typeParameterizables = new ArrayList<>(); + private Set m_bindingKeys = new HashSet<>(); public ContextList copy() { ContextList contextList = new ContextList(); - contextList.m_bodyDeclarations = new ArrayList<>(m_bodyDeclarations); - contextList.m_typeParameterizables = new ArrayList<>(m_typeParameterizables); + contextList.m_bindingKeys = new HashSet<>(m_bindingKeys); return contextList; } - public void add(BodyDeclaration v) + public void add(IBinding v) { - m_bodyDeclarations.add(v); - } - - public boolean contains(BodyDeclaration v) - { - for (BodyDeclaration bodyDeclaration: m_bodyDeclarations) + if (v != null) { - if (bodyDeclaration.equals(v)) - { - return true; - } + m_bindingKeys.add(v.getKey()); } - return false; } - public void add(TypeParametrizable v) + public boolean contains(IBinding v) { - m_typeParameterizables.add(v); - } - - public boolean contains(TypeParametrizable v) - { - for (TypeParametrizable typeParameterizable: m_typeParameterizables) - { - if (typeParameterizable.toString().equals(v.toString())) - { - return true; - } - } - return false; + return v != null && m_bindingKeys.contains(v.getKey()); } } diff --git a/java_indexer/src/main/java/com/sourcetrail/DeclContext.java b/java_indexer/src/main/java/com/sourcetrail/DeclContext.java deleted file mode 100644 index cb3e4902..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/DeclContext.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sourcetrail; - -public class DeclContext -{ - private String m_name = null; - - public DeclContext(String name) - { - m_name = name; - } - - public String getName() - { - return m_name; - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/FileContent.java b/java_indexer/src/main/java/com/sourcetrail/FileContent.java index aecb14c7..83669ca0 100644 --- a/java_indexer/src/main/java/com/sourcetrail/FileContent.java +++ b/java_indexer/src/main/java/com/sourcetrail/FileContent.java @@ -2,24 +2,9 @@ package com.sourcetrail; import java.util.Arrays; import java.util.List; -import java.util.Optional; - -import com.github.javaparser.Position; public class FileContent { - public class Location - { - public int line; - public int column; - - Location(int line, int column) - { - this.line = line; - this.column = column; - } - } - private List m_lines; public FileContent(String text) @@ -27,17 +12,12 @@ public class FileContent m_lines = Arrays.asList(text.split("\\r?\\n")); } - public Location find(String s) + public Position findStartPosition(String s) { - return find(s, Position.pos(1, 1)); + return findStartPosition(s, new Position(1, 1)); } - public Location find(String s, Optional from) - { - return find(s, from.orElse(Position.pos(1, 1))); - } - - public Location find(String s, Position from) + public Position findStartPosition(String s, Position from) { int lineIndex = from.line - 1; int startColumn = from.column - 1; @@ -47,11 +27,25 @@ public class FileContent column = m_lines.get(lineIndex).indexOf(s, startColumn); if (column != -1) { - return new Location(lineIndex + 1, column + 1); + return new Position(lineIndex + 1, column + 1); } startColumn = 0; lineIndex++; } - return new Location(0, 0); + return new Position(0, 0); + } + + public Range findRange(String s) + { + return findRange(s, new Position(1, 1)); + } + + public Range findRange(String s, Position from) + { + Position startPosition = findStartPosition(s, from); + + return new Range( + startPosition, + new Position(startPosition.line, startPosition.column + s.length() - 1)); } } diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java b/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java index b2c6ce17..91f5944e 100644 --- a/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java +++ b/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java @@ -1,147 +1,128 @@ package com.sourcetrail; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Hashtable; -import com.github.javaparser.JavaParser; -import com.github.javaparser.ParseProblemException; -import com.github.javaparser.Position; -import com.github.javaparser.Problem; -import com.github.javaparser.Range; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.symbolsolver.javaparser.Navigator; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; -import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; - -import com.sourcetrail.typesolver.SynchronizedJavaParserTypeSolver; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.BlockComment; +import org.eclipse.jdt.core.dom.Comment; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.LineComment; +import org.eclipse.jdt.core.dom.PackageDeclaration; public class JavaIndexer -{ - private static Map typeSolvers = new HashMap<>(); - +{ public static void processFile(int address, String filePath, String fileContent, String classPath, int verbose) { - AstVisitorClient astVisitorClient = new JavaIndexerAstVisitorClient(address); - + processFile(new JavaIndexerAstVisitorClient(address), filePath, fileContent, classPath, verbose); + } + + public static void processFile(AstVisitorClient astVisitorClient, String filePath, String fileContent, String classPath, int verbose) + { astVisitorClient.logInfo("indexing source file: " + filePath); - try - { - CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver(); + Path path = Paths.get(filePath); + + ASTParser parser = ASTParser.newParser(AST.JLS8); + + parser.setResolveBindings(true); // solve "bindings" like the declatarion of the type used in a var decl + parser.setKind(ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit + parser.setBindingsRecovery(true); // also return bindings that are not resolved completely + parser.setStatementsRecovery(true); + + Hashtable options = JavaCore.getOptions(); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); + parser.setCompilerOptions(options); + + parser.setUnitName(path.getFileName().toString()); - combinedTypeSolver.add(new ReflectionTypeSolver()); - - synchronized (typeSolvers) + String sources = ""; + String classpath = ""; + + for (String classPathEntry: classPath.split("\\;")) + { + if (classPathEntry.endsWith(".jar")) { - for (String path: classPath.split("\\;")) + if (!classpath.isEmpty()) { - if (typeSolvers.containsKey(path)) - { - combinedTypeSolver.add(typeSolvers.get(path)); - } - else - { - try - { - TypeSolver typeSolver = null; - - if (path.endsWith(".jar")) - { - try - { - typeSolver = new JarTypeSolver(path); - } - catch (IOException e) - { - System.out.println("unable to add jar file: " + path); - } - } - else if (!path.isEmpty()) - { - typeSolver = new SynchronizedJavaParserTypeSolver(new File(path)); - } - - if (typeSolver != null) - { - typeSolvers.put(path, typeSolver); - combinedTypeSolver.add(typeSolver); - } - } - catch (Exception e) - { - astVisitorClient.logWarning("unable to add dependency: " + path); - } - } + classpath += ";"; } + classpath += classPathEntry; } - - CompilationUnit cu = JavaParser.parse(new StringReader(fileContent)); - - AstVisitor astVisitor = ( - verbose == 1 ? - new VerboseAstVisitor(astVisitorClient, filePath, new FileContent(fileContent), combinedTypeSolver) : - new AstVisitor(astVisitorClient, filePath, new FileContent(fileContent), combinedTypeSolver) - ); - - cu.accept(astVisitor, null); - } - catch (ParseProblemException e) - { - for (Problem problem: e.getProblems()) + else if (!classPathEntry.isEmpty()) { - // "Parse error. Found \"package\", expected one of \";\" \"@\" \"\\u001a\" \"abstract\" \"class\" \"default\" \"enum\" \"final\" \"import\" \"interface\" \"module\" \"native\" \"open\" \"private\" \"protected\" \"public\" \"static\" \"stric... - String message = problem.toString(); - if (message.startsWith("Parse error. Found ")) + if (!sources.isEmpty()) { - message = "Encountered unexpected token."; - } - - Range range = new Range(new Position(0, 0), new Position(0, 0)); - if (problem.getLocation().isPresent()) - { - range = problem.getLocation().get().toRange(); + sources += ";"; } - - astVisitorClient.recordError(message, true, true, range); + sources += classPathEntry; + } + } + + parser.setEnvironment(new String[] {classpath} , new String[] {sources}, new String[] {"UTF-8"}, true); + parser.setSource(fileContent.toCharArray()); + + CompilationUnit cu = (CompilationUnit) parser.createAST(null); + + ASTVisitor visitor; + if (verbose != 0) + { + visitor = new VerboseContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu); + } + else + { + visitor = new ContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu); + } + + cu.accept(visitor); + + for (IProblem problem: cu.getProblems()) + { + if (problem.isError()) + { + Range range = new Range( + cu.getLineNumber(problem.getSourceStart()), + cu.getColumnNumber(problem.getSourceStart() + 1), + cu.getLineNumber(problem.getSourceEnd()), + cu.getColumnNumber(problem.getSourceEnd()) + 1); + + astVisitorClient.recordError(problem.getMessage(), false, true, range); } } + + for (Object commentObject: cu.getCommentList()) + { + if ((commentObject instanceof LineComment) || (commentObject instanceof BlockComment)) + { + ((Comment) commentObject).accept(visitor); + } + } + } public static String getPackageName(String fileContent) { String packageName = ""; - try - { - CompilationUnit cu = JavaParser.parse(new StringReader(fileContent)); - PackageDeclaration pd = Navigator.findNodeOfGivenClass(cu, PackageDeclaration.class); - if (pd != null) - { - packageName = JavaparserDeclNameResolver.getQualifiedName(pd.getName()).toString(); - } - } - catch (ParseProblemException e) - { - // do nothing - } - catch (IllegalArgumentException e) - { - // do nothing - } + ASTParser parser = ASTParser.newParser(AST.JLS8); + parser.setKind(ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit + parser.setSource(fileContent.toCharArray()); + CompilationUnit cu = (CompilationUnit) parser.createAST(null); + PackageDeclaration packageDeclaration = cu.getPackage(); + if (packageDeclaration != null) + { + packageName = packageDeclaration.getName().getFullyQualifiedName(); + } return packageName; } public static void clearCaches() { - typeSolvers.clear(); - JavaParserFacade.clearInstances(); Runtime.getRuntime().gc(); } @@ -158,36 +139,30 @@ public class JavaIndexer static public native void logError(int address, String error); static public native void recordSymbol( - int address, String symbolName, int symbolType, - int access, int definitionKind - ); + int address, String symbolName, int symbolType, + int access, int definitionKind); static public native void recordSymbolWithLocation( - int address, String symbolName, int symbolType, - int beginLine, int beginColumn, int endLine, int endColumn, - int access, int definitionKind - ); + int address, String symbolName, int symbolType, + int beginLine, int beginColumn, int endLine, int endColumn, + int access, int definitionKind); static public native void recordSymbolWithLocationAndScope( - int address, String symbolName, int symbolType, - int beginLine, int beginColumn, int endLine, int endColumn, - int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn, - int access, int definitionKind + int address, String symbolName, int symbolType, + int beginLine, int beginColumn, int endLine, int endColumn, + int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn, + int access, int definitionKind ); static public native void recordReference( - int address, int referenceKind, String referencedName, String contextName, int beginLine, int beginColumn, int endLine, int endColumn - ); + int address, int referenceKind, String referencedName, String contextName, int beginLine, int beginColumn, int endLine, int endColumn); static public native void recordLocalSymbol( - int address, String symbolName, int beginLine, int beginColumn, int endLine, int endColumn - ); + int address, String symbolName, int beginLine, int beginColumn, int endLine, int endColumn); static public native void recordComment( - int address, int beginLine, int beginColumn, int endLine, int endColumn - ); + int address, int beginLine, int beginColumn, int endLine, int endColumn); static public native void recordError( - int address, String message, int fatal, int indexed, int beginLine, int beginColumn, int endLine, int endColumn - ); + int address, String message, int fatal, int indexed, int beginLine, int beginColumn, int endLine, int endColumn); } \ No newline at end of file diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java b/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java index 66c5ddf4..67b4a734 100644 --- a/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java +++ b/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java @@ -1,6 +1,6 @@ package com.sourcetrail; -import com.github.javaparser.Range; +import com.sourcetrail.name.NameHierarchy; public class JavaIndexerAstVisitorClient extends AstVisitorClient { @@ -37,76 +37,68 @@ public class JavaIndexerAstVisitorClient extends AstVisitorClient @Override public void recordSymbol( - String symbolName, SymbolKind symbolType, - AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, SymbolKind symbolKind, + AccessKind access, DefinitionKind definitionKind) { JavaIndexer.recordSymbol( - m_address, symbolName, symbolType.getValue(), - access.getValue(), definitionKind.getValue() - ); + m_address, symbolName.serialize(), symbolKind.getValue(), + access.getValue(), definitionKind.getValue()); } @Override public void recordSymbolWithLocation( - String symbolName, SymbolKind symbolType, Range range, - AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, SymbolKind symbolKind, Range range, + AccessKind access, DefinitionKind definitionKind) { JavaIndexer.recordSymbolWithLocation( - m_address, symbolName, symbolType.getValue(), - range.begin.line, range.begin.column, range.end.line, range.end.column, - access.getValue(), definitionKind.getValue() - ); + m_address, symbolName.serialize(), symbolKind.getValue(), + range.begin.line, range.begin.column, range.end.line, range.end.column, + access.getValue(), definitionKind.getValue()); } @Override public void recordSymbolWithLocationAndScope( - String symbolName, SymbolKind symbolType, Range range, - Range scopeRange, AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, SymbolKind symbolKind, Range range, + Range scopeRange, AccessKind access, DefinitionKind definitionKind) { JavaIndexer.recordSymbolWithLocationAndScope( - m_address, symbolName, symbolType.getValue(), - range.begin.line, range.begin.column, range.end.line, range.end.column, - scopeRange.begin.line, scopeRange.begin.column, scopeRange.end.line, scopeRange.end.column, - access.getValue(), definitionKind.getValue() - ); + m_address, symbolName.serialize(), symbolKind.getValue(), + range.begin.line, range.begin.column, range.end.line, range.end.column, + scopeRange.begin.line, scopeRange.begin.column, scopeRange.end.line, scopeRange.end.column, + access.getValue(), definitionKind.getValue()); } @Override public void recordReference( - ReferenceKind referenceKind, String referencedName, - String contextName, Range range) + ReferenceKind referenceKind, NameHierarchy referencedName, + NameHierarchy contextName, Range range) { JavaIndexer.recordReference( - m_address, referenceKind.getValue(), referencedName, contextName, - range.begin.line, range.begin.column, range.end.line, range.end.column - ); + m_address, referenceKind.getValue(), referencedName.serialize(), contextName.serialize(), + range.begin.line, range.begin.column, range.end.line, range.end.column); } @Override - public void recordLocalSymbol(String symbolName, Range range) + public void recordLocalSymbol(NameHierarchy symbolName, Range range) { JavaIndexer.recordLocalSymbol( - m_address, symbolName, - range.begin.line, range.begin.column, range.end.line, range.end.column - ); + m_address, symbolName.serialize(), + range.begin.line, range.begin.column, range.end.line, range.end.column); } @Override public void recordComment(Range range) { JavaIndexer.recordComment( - m_address, - range.begin.line, range.begin.column, range.end.line, range.end.column - ); + m_address, + range.begin.line, range.begin.column, range.end.line, range.end.column); } @Override public void recordError(String message, boolean fatal, boolean indexed, Range range) { JavaIndexer.recordError( - m_address, message, (fatal ? 1 : 0), (indexed ? 1 : 0), - range.begin.line, range.begin.column, range.end.line, range.end.column - ); + m_address, message, (fatal ? 1 : 0), (indexed ? 1 : 0), + range.begin.line, range.begin.column, range.end.line, range.end.column); } - } diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/JavaNameResolver.java deleted file mode 100644 index 3dcedc48..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/JavaNameResolver.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.sourcetrail; - -import java.io.File; - -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - -public abstract class JavaNameResolver -{ - File m_currentFile = null; - TypeSolver m_typeSolver = null; - ContextList m_ignoredContexts = null; - - public JavaNameResolver(File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - m_currentFile = currentFile; - m_typeSolver = typeSolver; - if (ignoredContexts != null) - { - m_ignoredContexts = ignoredContexts; - } - else - { - m_ignoredContexts = new ContextList(); - } - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaSymbolSolverDeclNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/JavaSymbolSolverDeclNameResolver.java deleted file mode 100644 index dc1438bc..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/JavaSymbolSolverDeclNameResolver.java +++ /dev/null @@ -1,239 +0,0 @@ -package com.sourcetrail; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserConstructorDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumConstantDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserParameterDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.Declaration; -import com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.MethodLikeDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.ReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.TypeParameterDeclaration; -import com.github.javaparser.symbolsolver.model.declarations.TypeParametrizable; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - -import com.sourcetrail.name.JavaDeclName; -import com.sourcetrail.name.JavaFunctionDeclName; -import com.sourcetrail.name.JavaTypeName; -import com.sourcetrail.name.JavaVariableDeclName; - -public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver -{ - public JavaSymbolSolverDeclNameResolver(File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - super(currentFile, typeSolver, ignoredContexts); - } - - public static JavaDeclName getQualifiedDeclName(Declaration decl, File currentFile, TypeSolver typeSolver) - { - return getQualifiedDeclName(decl, currentFile, typeSolver, null); - } - - public static JavaDeclName getQualifiedDeclName(Declaration decl, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaSymbolSolverDeclNameResolver resolver = new JavaSymbolSolverDeclNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedDeclName(decl); - } - - public JavaDeclName getQualifiedDeclName(Declaration decl) - { - JavaDeclName declName = null; - - if (decl instanceof JavaParserAnnotationDeclaration) - { - // TODO: implement - System.out.println("solving name of JavaParserAnnotationDeclaration not implemented"); - declName = JavaDeclName.unsolved(); - - } - if (decl instanceof JavaParserAnonymousClassDeclaration) - { - // TODO: implement maybe the case is new XXX { methods and stuff }.doSomething(); - System.out.println("solving name of JavaParserAnonymousClassDeclaration not implemented"); - declName = JavaDeclName.unsolved(); - } - else if (decl instanceof JavaParserClassDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserClassDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserConstructorDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserConstructorDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserEnumDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserEnumDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserEnumConstantDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserEnumConstantDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserFieldDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserFieldDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserInterfaceDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserInterfaceDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserMethodDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserMethodDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserParameterDeclaration) - { - System.out.println("solving name of JavaParserParameterDeclaration not implemented"); - declName = JavaDeclName.unsolved(); - } - else if (decl instanceof JavaParserSymbolDeclaration) - { - System.out.println("solving name of JavaParserSymbolDeclaration not implemented"); - declName = JavaDeclName.unsolved(); - } - else if (decl instanceof JavaParserTypeParameter) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserTypeParameter)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else if (decl instanceof JavaParserTypeVariableDeclaration) - { - declName = JavaparserDeclNameResolver.getQualifiedDeclName( - ((JavaParserTypeVariableDeclaration)decl).getWrappedNode(), m_currentFile, m_typeSolver, m_ignoredContexts); - } - else - { - String name = decl.getName(); - List typeParameters = new ArrayList<>(); - if (decl instanceof TypeParametrizable) - { - typeParameters = getTypeParameterNames((TypeParametrizable) decl); - } - - if (decl instanceof ReferenceTypeDeclaration) - { - declName = new JavaDeclName(name, typeParameters); - - Optional containerType = ((ReferenceTypeDeclaration) decl).containerType(); - if (containerType.isPresent()) - { - declName.setParent(getQualifiedDeclName(containerType.get(), m_currentFile, m_typeSolver, m_ignoredContexts)); - } - else - { - declName.setParent(JavaDeclName.fromDotSeparatedString(((ReferenceTypeDeclaration) decl).getPackageName())); - } - - } - else if (decl instanceof TypeParameterDeclaration) - { - declName = new JavaDeclName(name); - TypeParametrizable container = ((TypeParameterDeclaration) decl).getContainer(); - if (!m_ignoredContexts.contains(container)) - { - if (container instanceof ReferenceTypeDeclaration) - { - declName.setParent(getQualifiedDeclName((ReferenceTypeDeclaration) container, m_currentFile, m_typeSolver, m_ignoredContexts)); - } - if (container instanceof MethodLikeDeclaration) - { - declName.setParent(getQualifiedDeclName((MethodLikeDeclaration) container, m_currentFile, m_typeSolver, m_ignoredContexts)); - } - } - } - else if (decl instanceof MethodLikeDeclaration) - { - ContextList ignoredContextsForTypes = m_ignoredContexts.copy(); - ignoredContextsForTypes.add((MethodLikeDeclaration) decl); // adding own decl - - JavaTypeName returnTypeName = new JavaTypeName("", null); - boolean isStatic = false; - if (decl instanceof MethodDeclaration) - { - returnTypeName = JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(((MethodDeclaration)decl).getReturnType(), m_currentFile, m_typeSolver, ignoredContextsForTypes); - isStatic = ((MethodDeclaration)decl).isStatic(); - } - - declName = new JavaFunctionDeclName( - name, typeParameters, - returnTypeName, - getParameterTypeNames((MethodLikeDeclaration) decl, m_currentFile, m_typeSolver, ignoredContextsForTypes), - isStatic); - - declName.setParent( - getQualifiedDeclName(((MethodLikeDeclaration) decl).declaringType(), m_currentFile, m_typeSolver, m_ignoredContexts)); - - } - else if (decl instanceof com.github.javaparser.symbolsolver.model.declarations.FieldDeclaration) - { - com.github.javaparser.symbolsolver.model.declarations.FieldDeclaration fieldDecl = ((com.github.javaparser.symbolsolver.model.declarations.FieldDeclaration) decl); - declName = new JavaVariableDeclName( - name, - JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(fieldDecl.getType(), m_currentFile, m_typeSolver, m_ignoredContexts), - fieldDecl.isStatic()); - - declName.setParent( - getQualifiedDeclName( - fieldDecl.declaringType(), - m_currentFile, - m_typeSolver, - m_ignoredContexts)); - } - } - - if (declName == null) - { - System.out.println("Unable to resolve qualified declaration name of " + decl.getClass().toString() + ": " + decl.toString()); - declName = JavaDeclName.unsolved(); - } - - return declName; - } - - private static List getTypeParameterNames(TypeParametrizable decl) - { - List typeParameterNames = new ArrayList<>(); - List typeParameters = decl.getTypeParameters(); - if (typeParameters != null && typeParameters.size() > 0) - { - for (int i = 0; i < typeParameters.size(); i++) - { - typeParameterNames.add(typeParameters.get(i).getName()); - } - } - return typeParameterNames; - } - - private static List getParameterTypeNames(MethodLikeDeclaration decl, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - List typeTypeParameterNames = new ArrayList<>(); - for (int i = 0; i < decl.getNumberOfParams(); i++) - { - typeTypeParameterNames.add(JavaSymbolSolverTypeNameResolver.getQualifiedTypeName( - decl.getParam(i).getType(), currentFile, typeSolver, ignoredContexts - )); - } - return typeTypeParameterNames; - } - -} diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaSymbolSolverTypeNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/JavaSymbolSolverTypeNameResolver.java deleted file mode 100644 index e9eb7bf9..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/JavaSymbolSolverTypeNameResolver.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.sourcetrail; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter; -import com.github.javaparser.symbolsolver.logic.InferenceVariableType; -import com.github.javaparser.symbolsolver.model.declarations.TypeParameterDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; -import com.github.javaparser.symbolsolver.model.typesystem.ArrayType; -import com.github.javaparser.symbolsolver.model.typesystem.NullType; -import com.github.javaparser.symbolsolver.model.typesystem.PrimitiveType; -import com.github.javaparser.symbolsolver.model.typesystem.ReferenceType; -import com.github.javaparser.symbolsolver.model.typesystem.Type; -import com.github.javaparser.symbolsolver.model.typesystem.TypeVariable; -import com.github.javaparser.symbolsolver.model.typesystem.VoidType; -import com.github.javaparser.symbolsolver.model.typesystem.Wildcard; - -import com.sourcetrail.name.JavaDeclName; -import com.sourcetrail.name.JavaTypeName; - -public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver -{ - public JavaSymbolSolverTypeNameResolver(File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - super(currentFile, typeSolver, ignoredContexts); - } - - public static JavaTypeName getQualifiedTypeName(Type type, File currentFile, TypeSolver typeSolver) - { - return getQualifiedTypeName(type, currentFile, typeSolver, null); - } - - public static JavaTypeName getQualifiedTypeName(Type type, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaSymbolSolverTypeNameResolver resolver = new JavaSymbolSolverTypeNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedTypeName(type); - } - - public JavaTypeName getQualifiedTypeName(Type type) - { - if (type instanceof ArrayType) - { - return getQualifiedTypeName(((ArrayType)type).getComponentType()); - } - else if (type instanceof LambdaArgumentTypePlaceholder) - { - - } - else if (type instanceof InferenceVariableType) - { - - } - else if (type instanceof NullType) - { - return JavaTypeName.fromDotSeparatedString(type.describe()); - } - else if (type instanceof PrimitiveType) - { - return JavaTypeName.fromDotSeparatedString(type.describe()); - } - else if (type instanceof ReferenceType) - { - ReferenceType refTypeUsage = (ReferenceType)type; - - JavaDeclName declName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName( - refTypeUsage.getTypeDeclaration(), - m_currentFile, - m_typeSolver, - m_ignoredContexts); - return new JavaTypeName(declName.getName() + declName.getTypeParameterString(), new ArrayList(), declName.getParent()); - } - else if (type instanceof TypeVariable) - { - JavaDeclName declName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName( - ((TypeVariable)type).asTypeParameter(), - m_currentFile, - m_typeSolver, - m_ignoredContexts); - return new JavaTypeName(declName.getName(), new ArrayList(), declName.getParent()); - } - else if (type instanceof VoidType) - { - return JavaTypeName.fromDotSeparatedString(type.describe()); - } - else if (type instanceof Wildcard) - { - return new JavaTypeName("?", null); - } - - System.out.println("Unable to resolve qualified name of " + type.getClass().toString() + ": " + type.toString()); - - return JavaTypeName.unsolved(); - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaparserDeclNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/JavaparserDeclNameResolver.java deleted file mode 100644 index 11ff0631..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/JavaparserDeclNameResolver.java +++ /dev/null @@ -1,309 +0,0 @@ -package com.sourcetrail; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.github.javaparser.Position; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.Node; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.PackageDeclaration; -import com.github.javaparser.ast.body.AnnotationMemberDeclaration; -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.InitializerDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.TypeDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.expr.Name; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.type.TypeParameter; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - -import com.sourcetrail.name.JavaDeclName; -import com.sourcetrail.name.JavaFunctionDeclName; -import com.sourcetrail.name.JavaTypeName; -import com.sourcetrail.name.JavaVariableDeclName; - -public class JavaparserDeclNameResolver extends JavaNameResolver -{ - public JavaparserDeclNameResolver(File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - super(currentFile, typeSolver, ignoredContexts); - } - - public static JavaDeclName getQualifiedDeclName(VariableDeclarator decl, File currentFile, TypeSolver typeSolver) - { - return getQualifiedDeclName(decl, currentFile, typeSolver, null); - } - - public static JavaDeclName getQualifiedDeclName(VariableDeclarator decl, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedDeclName(decl); - } - - public JavaDeclName getQualifiedDeclName(VariableDeclarator decl) - { - JavaDeclName declName = JavaDeclName.unsolved(); - - if (decl != null) - { - declName = getDeclName(decl); - if (!declName.getIsUnsolved()) - { - declName.setParent(getQualifiedContextName(decl)); - } - } - return declName; - } - - public JavaDeclName getDeclName(VariableDeclarator decl) - { - JavaTypeName typeName = JavaparserTypeNameResolver.getQualifiedTypeName(decl.getType(), m_currentFile, m_typeSolver, m_ignoredContexts.copy()); - - boolean isStatic = false; - Optional fieldDeclaration = decl.getAncestorOfType(FieldDeclaration.class); - if (fieldDeclaration.isPresent()) - { - isStatic = fieldDeclaration.get().isStatic(); - } - - return new JavaVariableDeclName(decl.getNameAsString(), typeName, isStatic); - } - - public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, TypeSolver typeSolver) - { - return getQualifiedDeclName(decl, currentFile, typeSolver, null); - } - - public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedDeclName(decl); - } - - public JavaDeclName getQualifiedDeclName(BodyDeclaration decl) - { - JavaDeclName declName = JavaDeclName.unsolved(); - - if (decl != null) - { - declName = getDeclName(decl); - if (!declName.getIsUnsolved()) - { - declName.setParent(getQualifiedContextName(decl)); - } - } - - return declName; - } - - public JavaDeclName getDeclName(BodyDeclaration decl) - { - JavaDeclName declName = JavaDeclName.unsolved(); - - if (decl != null) - { - if (decl instanceof AnnotationMemberDeclaration) - { - declName = new JavaDeclName("AnnotationMemberDeclaration"); - } - else if (decl instanceof ConstructorDeclaration) - { - CallableConstructorDecl callableDecl = new CallableConstructorDecl((ConstructorDeclaration)decl); - declName = getDeclNameOfCallable(callableDecl); - } - else if (decl instanceof EnumConstantDeclaration) - { - declName = new JavaDeclName(((EnumConstantDeclaration)decl).getNameAsString()); - } - else if (decl instanceof FieldDeclaration) - { - throw new UnsupportedOperationException(); - } - else if (decl instanceof InitializerDeclaration) - { - declName = new JavaDeclName("InitializerDeclaration"); - } - else if (decl instanceof MethodDeclaration) - { - CallableMethodDecl callableDecl = new CallableMethodDecl((MethodDeclaration)decl); - declName = getDeclNameOfCallable(callableDecl); - } - else if (decl instanceof TypeDeclaration) - { - declName = new JavaDeclName(((TypeDeclaration)decl).getNameAsString(), getTypeParameterNames((TypeDeclaration)decl)); - } - } - - return declName; - } - - public static JavaDeclName getQualifiedDeclName(TypeParameter decl, File currentFile, TypeSolver typeSolver) - { - return getQualifiedDeclName(decl, currentFile, typeSolver, null); - } - - public static JavaDeclName getQualifiedDeclName(TypeParameter decl, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedDeclName(decl); - } - - public JavaDeclName getQualifiedDeclName(TypeParameter decl) - { - JavaDeclName declName = JavaDeclName.unsolved(); - - if (decl != null) - { - declName = getDeclName(decl); - - if (!declName.getIsUnsolved()) - { - declName.setParent(getQualifiedContextName(decl)); - } - } - return declName; - } - - public JavaDeclName getDeclName(TypeParameter decl) - { - return new JavaDeclName(decl.getName().asString()); - } - - public static JavaDeclName getQualifiedDeclName(ObjectCreationExpr anonymousClassDecl, File currentFile, TypeSolver typeSolver) - { - return getQualifiedDeclName(anonymousClassDecl, currentFile, typeSolver, null); - } - - public static JavaDeclName getQualifiedDeclName(ObjectCreationExpr anonymousClassDecl, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedDeclName(anonymousClassDecl); - } - - public JavaDeclName getQualifiedDeclName(ObjectCreationExpr anonymousClassDecl) - { - JavaDeclName declName = JavaDeclName.unsolved(); - - if (anonymousClassDecl != null) - { - declName = getDeclName(anonymousClassDecl); - if (!declName.getIsUnsolved()) - { - declName.setParent(getQualifiedContextName(anonymousClassDecl)); - } - } - return declName; - } - - public JavaDeclName getDeclName(ObjectCreationExpr anonymousClassDecl) - { - if (anonymousClassDecl.getAnonymousClassBody().isPresent()) - { - Position position = anonymousClassDecl.getBegin().orElse(new Position(0, 0)); - return JavaDeclName.anonymousClass(m_currentFile.getName(), position.line, position.column); - } - return JavaDeclName.unsolved(); - } - - private static List getTypeParameterNames(TypeDeclaration decl) - { - NodeList typeParameters = null; - if (decl instanceof ClassOrInterfaceDeclaration) - { - typeParameters = (NodeList) ((ClassOrInterfaceDeclaration)decl).getTypeParameters(); - } - - return getTypeParameterNames(typeParameters); - } - - private static List getTypeParameterNames(NodeList typeParameters) - { - List typeParameterNames = new ArrayList<>(); - if (typeParameters != null && typeParameters.size() > 0) - { - for (int i = 0; i < typeParameters.size(); i++) - { - typeParameterNames.add(typeParameters.get(i).getNameAsString()); - } - } - return typeParameterNames; - } - - public static JavaDeclName getQualifiedName(Name name) - { - JavaDeclName declName = new JavaDeclName(name.getId()); - if (name.getQualifier().isPresent()) - { - declName.setParent(getQualifiedName(name.getQualifier().get())); - } - return declName; - } - - private JavaDeclName getQualifiedContextName(Node decl) - { - Node parentNode = decl.getParentNode().orElse(null); - if (parentNode == null) - { - return null; - } - - if (parentNode instanceof BodyDeclaration && !(parentNode instanceof FieldDeclaration)) - { - if (m_ignoredContexts.contains((BodyDeclaration) parentNode)) - { - return null; - } - return getQualifiedDeclName((BodyDeclaration) parentNode); - } - else if (parentNode instanceof CompilationUnit) - { - Optional packageDecl = ((CompilationUnit) parentNode).getPackageDeclaration(); - if (packageDecl.isPresent()) - { - return getQualifiedName(packageDecl.get().getName()); - } - return null; - } - else if (parentNode instanceof ObjectCreationExpr && ((ObjectCreationExpr) parentNode).getAnonymousClassBody().isPresent()) - { - return getQualifiedDeclName((ObjectCreationExpr) parentNode); - } - - return getQualifiedContextName(parentNode); - } - - private JavaDeclName getDeclNameOfCallable(T decl) - { - ContextList ignoredContextsForTypes = m_ignoredContexts.copy(); - ignoredContextsForTypes.add(decl.getWrappedNode()); // adding own decl - - List parameterNames = new ArrayList<>(); - for (Parameter parameter: decl.getParameters()) - { - parameterNames.add(JavaparserTypeNameResolver.getQualifiedTypeName(parameter.getType(), m_currentFile, m_typeSolver, ignoredContextsForTypes)); - } - - JavaTypeName returnType = new JavaTypeName("", null); - if (decl.isMethod()) - { - returnType = JavaparserTypeNameResolver.getQualifiedTypeName(decl.getType(), m_currentFile, m_typeSolver, ignoredContextsForTypes); - } - - return new JavaFunctionDeclName( - decl.getName(), - getTypeParameterNames(decl.getTypeParameters()), - returnType, - parameterNames, - decl.isStatic() - ); - } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaparserTypeNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/JavaparserTypeNameResolver.java deleted file mode 100644 index edb31be2..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/JavaparserTypeNameResolver.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.sourcetrail; - -import java.io.File; - -import com.github.javaparser.ast.type.*; -import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - -import com.sourcetrail.name.JavaTypeName; - -public class JavaparserTypeNameResolver extends JavaNameResolver -{ - public JavaparserTypeNameResolver(File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - super(currentFile, typeSolver, ignoredContexts); - } - - public static JavaTypeName getQualifiedTypeName(Type type, File currentFile, TypeSolver typeSolver) - { - return getQualifiedTypeName(type, currentFile, typeSolver, null); - } - - public static JavaTypeName getQualifiedTypeName(Type type, File currentFile, TypeSolver typeSolver, ContextList ignoredContexts) - { - JavaparserTypeNameResolver resolver = new JavaparserTypeNameResolver(currentFile, typeSolver, ignoredContexts); - return resolver.getQualifiedTypeName(type); - } - - public JavaTypeName getQualifiedTypeName(Type type) - { - String fallbackTypeName = type.toString(); - - if (type instanceof ClassOrInterfaceType) - { - try - { - return JavaSymbolSolverTypeNameResolver.getQualifiedTypeName( - JavaParserFacade.get(m_typeSolver).convert(type, type), - m_currentFile, - m_typeSolver, - m_ignoredContexts - ); - } - catch (Exception e) - { - // log... - } - } - else if (type instanceof ArrayType) - { - ArrayType arrayType = (ArrayType)type; - - // TODO: regard array info! - return getQualifiedTypeName(arrayType.getComponentType()); - } - else if (type instanceof TypeParameter) - { - return JavaSymbolSolverTypeNameResolver.getQualifiedTypeName( - JavaParserFacade.get(m_typeSolver).convert(type, type), - m_currentFile, - m_typeSolver, - m_ignoredContexts - ); - } - else if (type instanceof IntersectionType) - { - // System.out.println(" IntersectionType: " + fallbackTypeName); - - return JavaTypeName.fromDotSeparatedString(type.toString()); - } - else if (type instanceof PrimitiveType) - { - return JavaTypeName.fromDotSeparatedString(type.toString()); - } - else if (type instanceof UnionType) - { - // System.out.println(" UnionType: " + fallbackTypeName); - return JavaTypeName.fromDotSeparatedString(type.toString()); - } - else if (type instanceof UnknownType) - { - // System.out.println(" UnknownType: " + fallbackTypeName); - return JavaTypeName.fromDotSeparatedString(type.toString()); - } - else if (type instanceof VoidType) - { - return JavaTypeName.fromDotSeparatedString(type.toString()); - } - else if (type instanceof WildcardType) - { - // System.out.println(" WildcardType: " + fallbackTypeName); - return JavaTypeName.fromDotSeparatedString(type.toString()); - } - - System.out.println("Unable to resolve qualified name of " + type.getClass().toString() + ": " + fallbackTypeName); - - return JavaTypeName.unsolved(); - } - - -} diff --git a/java_indexer/src/main/java/com/sourcetrail/Position.java b/java_indexer/src/main/java/com/sourcetrail/Position.java new file mode 100644 index 00000000..20e21635 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/Position.java @@ -0,0 +1,17 @@ +package com.sourcetrail; + +public class Position +{ + public int line = 0; + public int column = 0; + + public Position() + { + } + + public Position(int line, int column) + { + this.line = line; + this.column = column; + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/Range.java b/java_indexer/src/main/java/com/sourcetrail/Range.java new file mode 100644 index 00000000..1cb54973 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/Range.java @@ -0,0 +1,27 @@ +package com.sourcetrail; + +public class Range +{ + public Position begin = new Position(); + public Position end = new Position(); + + public Range() + { + } + + public Range(int beginLine, int beginColumn, int endLine, int endColumn) + { + this.begin.line = beginLine; + this.begin.column = beginColumn; + this.end.line = endLine; + this.end.column = endColumn; + } + + public Range(Position begin, Position end) + { + this.begin.line = begin.line; + this.begin.column = begin.column; + this.end.line = end.line; + this.end.column = end.column; + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/Utility.java b/java_indexer/src/main/java/com/sourcetrail/Utility.java new file mode 100644 index 00000000..f657ae70 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/Utility.java @@ -0,0 +1,27 @@ +package com.sourcetrail; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.BodyDeclaration; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.Javadoc; + +public class Utility +{ + public static Range getRange(ASTNode node, CompilationUnit compilationUnit) + { + int startPosition = node.getStartPosition() + 1; + int endPosition = node.getStartPosition() + node.getLength() - 1; + + if (node instanceof BodyDeclaration && ((BodyDeclaration) node).getJavadoc() != null) + { + Javadoc javadoc = ((BodyDeclaration) node).getJavadoc(); + startPosition = javadoc.getStartPosition() + javadoc.getLength() + 2; + } + + return new Range( + compilationUnit.getLineNumber(startPosition), + compilationUnit.getColumnNumber(startPosition), + compilationUnit.getLineNumber(endPosition), + compilationUnit.getColumnNumber(endPosition) + 1); + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/VerboseAstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/VerboseAstVisitor.java deleted file mode 100644 index 1841326e..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/VerboseAstVisitor.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.sourcetrail; - -import com.github.javaparser.ast.*; -import com.github.javaparser.ast.body.*; -import com.github.javaparser.ast.comments.*; -import com.github.javaparser.ast.expr.*; -import com.github.javaparser.ast.nodeTypes.NodeWithName; -import com.github.javaparser.ast.stmt.*; -import com.github.javaparser.ast.type.*; -import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; - -public class VerboseAstVisitor extends AstVisitor{ - - public VerboseAstVisitor(AstVisitorClient client, String filePath, FileContent fileContent, TypeSolver typeSolver) { - super(client, filePath, fileContent, typeSolver); - } - - int indent = 0; - String indentSymbol = "| "; - - private String obfuscate(final String s) - { - if (s.isEmpty()) - { - return ""; - } - else if (s.length() <= 2) - { - return s; - } - return s.substring(0, 1) + ".." + s.substring(s.length() - 1, s.length()); - } - - private void dump(Node n) - { - String line = ""; - - for (int i = 0; i < this.indent; i++) - { - line += this.indentSymbol; - } - - line += n.getClass().getName(); - if (n instanceof NodeWithName) - { - line += " [" + obfuscate(((NodeWithName)n).getNameAsString()) + "]"; - } - - if (n.getBegin().isPresent()) - { - line += " line: " + n.getBegin().get().line; - } - - m_client.logInfo(line); - } - - //- Compilation Unit ---------------------------------- - - public Boolean visit(CompilationUnit n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(PackageDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ImportDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(TypeParameter n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(LineComment n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(BlockComment n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - //- Body ---------------------------------------------- - - public Boolean visit(ClassOrInterfaceDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(EnumDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(EnumConstantDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(AnnotationDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(AnnotationMemberDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(FieldDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(VariableDeclarator n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ConstructorDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(MethodDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(Parameter n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(InitializerDeclaration n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(JavadocComment n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - //- Type ---------------------------------------------- - - public Boolean visit(ClassOrInterfaceType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(PrimitiveType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ArrayType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ArrayCreationLevel n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(IntersectionType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(UnionType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(VoidType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(WildcardType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(UnknownType n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - //- Expression ---------------------------------------- - - public Boolean visit(ArrayAccessExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ArrayCreationExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ArrayInitializerExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(AssignExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(BinaryExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(CastExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ClassExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ConditionalExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(EnclosedExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(FieldAccessExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(InstanceOfExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(StringLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(IntegerLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(LongLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(CharLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(DoubleLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(BooleanLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(NullLiteralExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(MethodCallExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(NameExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ObjectCreationExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ThisExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(SuperExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(UnaryExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(VariableDeclarationExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(MarkerAnnotationExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(SingleMemberAnnotationExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(NormalAnnotationExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(MemberValuePair n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - //- Statements ---------------------------------------- - - public Boolean visit(ExplicitConstructorInvocationStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(AssertStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(BlockStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(LabeledStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(EmptyStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ExpressionStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(SwitchStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(SwitchEntryStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(BreakStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ReturnStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(IfStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(WhileStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ContinueStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(DoStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ForeachStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ForStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(ThrowStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(SynchronizedStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(TryStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(CatchClause n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(LambdaExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(MethodReferenceExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(TypeExpr n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } - - public Boolean visit(UnparsableStmt n, Void v) { dump(n); indent++; Boolean result = super.visit(n, v); indent--; return result; } -} diff --git a/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java new file mode 100644 index 00000000..8e2d25f0 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java @@ -0,0 +1,28 @@ +package com.sourcetrail; + +import java.io.File; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.CompilationUnit; + +public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor +{ + private String indentation = ""; + + public VerboseContextAwareAstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) + { + super(client, filePath, fileContent, compilationUnit); + } + + public void preVisit(ASTNode node) + { + Range range = getRange(node); + m_client.logInfo(indentation + node.getClass().toString() + "[" + range.begin.line + ":" + range.begin.column + "|" + range.end.line + ":" + range.end.column + "]"); + indentation += "| "; + } + + public void postVisit(ASTNode node) + { + indentation = indentation.substring(0, indentation.length() - 2); + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/name/JavaDeclName.java b/java_indexer/src/main/java/com/sourcetrail/name/JavaDeclName.java index 031ebd9c..c64d054c 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/JavaDeclName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/JavaDeclName.java @@ -1,14 +1,19 @@ package com.sourcetrail.name; +import java.io.File; import java.util.List; -public class JavaDeclName +import com.sourcetrail.Position; + +public class JavaDeclName implements JavaSymbolName { private JavaDeclName m_parent = null; private String m_name = ""; private List m_typeParameterNames = null; private boolean m_isUnsolved = false; private boolean m_isAnonymous = false; + private boolean m_isLocal = false; + private boolean m_isGlobal = false; public static JavaDeclName unsolved() { @@ -17,13 +22,33 @@ public class JavaDeclName return declName; } - public static JavaDeclName anonymousClass(String fileName, int line, int col) + public static JavaDeclName anonymousClass(File filePath, int line, int col) { - JavaDeclName declName = new JavaDeclName("anonymous class (" + fileName + "<" + line + ":" + col + ">)"); + JavaDeclName declName = new JavaDeclName("anonymous class (" + filePath.getName() + "<" + line + ":" + col + ">)"); declName.m_isAnonymous = true; return declName; } + public static JavaDeclName localSymbol(JavaDeclName methodContextName, int id) + { + JavaDeclName declName = new JavaDeclName(methodContextName + "<" + id + ">"); + declName.m_isLocal = true; + return declName; + } + + public static JavaDeclName globalSymbol(File fileContext, int id) + { + JavaDeclName declName = new JavaDeclName(fileContext.getName() + "<" + id + ">"); + declName.m_isGlobal = true; + return declName; + } + + public static JavaDeclName scope(File fileContext, Position begin) + { + JavaDeclName declName = new JavaDeclName(fileContext.getName() + "<" + begin.line + ":" + begin.column + ">"); + return declName; + } + public static JavaDeclName fromDotSeparatedString(String s) { JavaDeclName declName = null; @@ -78,6 +103,16 @@ public class JavaDeclName return m_isAnonymous; } + public boolean getIsLocal() + { + return m_isLocal; + } + + public boolean getIsGlobal() + { + return m_isGlobal; + } + public NameHierarchy toNameHierarchy() { NameHierarchy nameHierarchy; @@ -129,4 +164,8 @@ public class JavaDeclName } return string; } + + public List getTypeParameterNames() { + return m_typeParameterNames; + } } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/JavaFileName.java b/java_indexer/src/main/java/com/sourcetrail/name/JavaFileName.java new file mode 100644 index 00000000..561b1d47 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/name/JavaFileName.java @@ -0,0 +1,29 @@ +package com.sourcetrail.name; + +import java.io.File; + +public class JavaFileName implements JavaSymbolName +{ + private File m_filePath = null; + + public JavaFileName(File filePath) + { + m_filePath = filePath; + } + + @Override + public NameHierarchy toNameHierarchy() + { + NameHierarchy nameHierarchy; + if (m_filePath != null) + { + nameHierarchy = new NameHierarchy(m_filePath.toString().replaceAll("\\\\", "/")); + } + else + { + nameHierarchy = new NameHierarchy("unsolved-file"); + } + nameHierarchy.setSeparator('/'); + return nameHierarchy; + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/name/JavaFunctionDeclName.java b/java_indexer/src/main/java/com/sourcetrail/name/JavaFunctionDeclName.java index bf4d9e47..e4d5e6a1 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/JavaFunctionDeclName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/JavaFunctionDeclName.java @@ -7,24 +7,24 @@ import java.util.Optional; public class JavaFunctionDeclName extends JavaDeclName { private JavaTypeName m_returnTypeName = null; - private List m_parameterNames = new ArrayList<>(); + private List m_parameterTypeNames = new ArrayList<>(); private boolean m_isStatic = false; - public JavaFunctionDeclName(String name, JavaTypeName returnTypeName, List parameterNames, boolean isStatic) + public JavaFunctionDeclName(String name, JavaTypeName returnTypeName, List parameterTypeNames, boolean isStatic) { super(name); m_returnTypeName = returnTypeName; - if (m_parameterNames != null) m_parameterNames = parameterNames; + if (parameterTypeNames != null) m_parameterTypeNames = parameterTypeNames; m_isStatic = isStatic; } - public JavaFunctionDeclName(String name, List typeParameterNames, JavaTypeName returnTypeName, List parameterNames, boolean isStatic) + public JavaFunctionDeclName(String name, List typeParameterNames, JavaTypeName returnTypeName, List parameterTypeNames, boolean isStatic) { super(name, typeParameterNames); m_returnTypeName = returnTypeName; - m_parameterNames = parameterNames; + if (parameterTypeNames != null) m_parameterTypeNames = parameterTypeNames; m_isStatic = isStatic; } @@ -60,15 +60,15 @@ public class JavaFunctionDeclName extends JavaDeclName private String getParameterString() { String string = "("; - if (m_parameterNames != null) + if (m_parameterTypeNames != null) { - for (int i = 0; i < m_parameterNames.size(); i++) + for (int i = 0; i < m_parameterTypeNames.size(); i++) { if (i != 0) { string += ", "; } - string += m_parameterNames.get(i).toString(); + string += m_parameterTypeNames.get(i).toString(); } } string += ")"; diff --git a/java_indexer/src/main/java/com/sourcetrail/name/JavaSymbolName.java b/java_indexer/src/main/java/com/sourcetrail/name/JavaSymbolName.java new file mode 100644 index 00000000..736e3c05 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/name/JavaSymbolName.java @@ -0,0 +1,6 @@ +package com.sourcetrail.name; + +public interface JavaSymbolName +{ + public NameHierarchy toNameHierarchy(); +} diff --git a/java_indexer/src/main/java/com/sourcetrail/name/JavaTypeName.java b/java_indexer/src/main/java/com/sourcetrail/name/JavaTypeName.java index c696616f..3feccf0f 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/JavaTypeName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/JavaTypeName.java @@ -2,15 +2,19 @@ package com.sourcetrail.name; import java.util.List; -public class JavaTypeName +public class JavaTypeName implements JavaSymbolName { private JavaDeclName m_parent = null; private String m_name = ""; - private List m_typeArgumentNames = null; + private List m_typeParameterNames = null; + private List m_typeArguments = null; + private boolean m_isUnsolved = false; public static JavaTypeName unsolved() { - return new JavaTypeName("unsolved-type", null); + JavaTypeName typeName = new JavaTypeName("unsolved-type", null); + typeName.m_isUnsolved = true; + return typeName; } public static JavaTypeName fromDotSeparatedString(String s) @@ -36,11 +40,12 @@ public class JavaTypeName m_name = name; } - public JavaTypeName(String name, List typeArgumentNames, JavaDeclName parent) + public JavaTypeName(String name, List typeParameterNames, List typeArguments, JavaDeclName parent) { m_parent = parent; m_name = name; - m_typeArgumentNames = typeArgumentNames; + m_typeParameterNames = typeParameterNames; + m_typeArguments = typeArguments; } public JavaDeclName getParent() @@ -53,6 +58,13 @@ public class JavaTypeName return m_name; } + public JavaDeclName toDeclName() + { + JavaDeclName declName = new JavaDeclName(m_name, m_typeParameterNames); + declName.setParent(m_parent); + return declName; + } + public NameHierarchy toNameHierarchy() { NameHierarchy nameHierarchy; @@ -89,16 +101,16 @@ public class JavaTypeName private String getTypeArgumentString() { String string = ""; - if (m_typeArgumentNames != null && !m_typeArgumentNames.isEmpty()) + if (m_typeArguments != null && !m_typeArguments.isEmpty()) { string += "<"; - for (int i = 0; i < m_typeArgumentNames.size(); i++) + for (int i = 0; i < m_typeArguments.size(); i++) { if (i != 0) { string += ", "; } - string += m_typeArgumentNames.get(i).toString(); + string += m_typeArguments.get(i).toString(); } string += ">"; } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java b/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java index dc163324..9ed20b04 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java @@ -7,6 +7,7 @@ import java.util.Optional; public class NameHierarchy { private List m_elements = new ArrayList<>(); + private char m_separatpr = '.'; public NameHierarchy() { @@ -27,6 +28,11 @@ public class NameHierarchy m_elements.addAll(names); } + public void setSeparator(char separator) + { + m_separatpr = separator; + } + public void push(NameElement element) { m_elements.add(element); @@ -51,7 +57,7 @@ public class NameHierarchy public String serialize() { - String serialized = ".\tm"; + String serialized = m_separatpr + "\tm"; for (int i = 0; i < m_elements.size(); i++) { diff --git a/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java new file mode 100644 index 00000000..ae198ae5 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java @@ -0,0 +1,341 @@ +package com.sourcetrail.name.resolver; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.IPackageBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.Modifier; + +import com.sourcetrail.ContextList; +import com.sourcetrail.name.JavaDeclName; +import com.sourcetrail.name.JavaFunctionDeclName; +import com.sourcetrail.name.JavaTypeName; +import com.sourcetrail.name.JavaVariableDeclName; + +public class BindingNameResolver extends NameResolver +{ + public static IBinding getParentBinding(IBinding binding) + { + if (binding instanceof ITypeBinding) + { + return getParentBinding((ITypeBinding) binding); + } + else if (binding instanceof IMethodBinding) + { + return ((IMethodBinding) binding).getDeclaringClass(); + } + else if (binding instanceof IVariableBinding) + { + return ((IVariableBinding) binding).getDeclaringClass(); + } + return null; + } + + public static IBinding getParentBinding(ITypeBinding binding) + { + if (binding.isLocal() || binding.isAnonymous()) + { + if (binding.getDeclaringMember() instanceof IVariableBinding) + { + IVariableBinding variableBinding = (IVariableBinding) binding.getDeclaringMember(); + if (variableBinding.getDeclaringClass() != null) + { + return variableBinding.getDeclaringClass(); + } + else + { + return variableBinding.getDeclaringMethod(); + } + } + else + { + return binding.getDeclaringMethod(); + } + } + else if (binding.isMember()) + { + return binding.getDeclaringClass(); + } + else if (binding.isTypeVariable()) + { + if (binding.getDeclaringClass() != null) + { + return binding.getDeclaringClass(); + } + else + { + return binding.getDeclaringMethod(); + } + } + else if (binding.isTopLevel()) + { + return binding.getPackage(); + } + + return null; // we don't have a parent (like void doesn't have a parent) + } + + public BindingNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + super(currentFile, compilationUnit, ignoredContexts); + } + + public static Optional getQualifiedName(ITypeBinding binding, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedName(binding, currentFile, compilationUnit, null); + } + + public static Optional getQualifiedName(ITypeBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedName(binding); + } + + public Optional getQualifiedName(ITypeBinding binding) + { + if (binding == null) + { + return Optional.empty(); + } + + if (binding.isArray()) + { + return getQualifiedName(binding.getElementType()); + } + else if (binding.isAnonymous()) + { + ASTNode node = m_compilationUnit.findDeclaringNode(binding); + if (node instanceof AnonymousClassDeclaration) + { + JavaDeclName decl = DeclNameResolver.getQualifiedDeclName((AnonymousClassDeclaration) node, m_currentFile, m_compilationUnit, m_ignoredContexts); + return Optional.of(new JavaTypeName(decl.getName(), decl.getTypeParameterNames(), null, decl.getParent())); + } + else + { + return Optional.empty(); + } + } + + if (binding.isParameterizedType()) + { + List typeArguments = new ArrayList<>(); + for (ITypeBinding typeArgumentBinding: binding.getTypeArguments()) + { + Optional typeArgument = getQualifiedName(typeArgumentBinding); + if (typeArgument.isPresent()) + { + typeArguments.add(typeArgument.get()); + } + } + + Optional typeName = getQualifiedName(binding.getTypeDeclaration()); + if (typeName.isPresent()) + { + JavaDeclName declName = typeName.get().toDeclName(); + return Optional.of(new JavaTypeName(declName.getName(), declName.getTypeParameterNames(), typeArguments, declName.getParent())); + } + else + { + return Optional.empty(); + } + } + + String name = binding.getName(); + List typeParameterNames = null; + if (binding.isGenericType()) + { + typeParameterNames = new ArrayList<>(); + for (ITypeBinding typeParameter: binding.getTypeParameters()) + { + typeParameterNames.add(typeParameter.getName()); + } + } + + JavaDeclName parentDeclName = getQualifiedContextName(binding); + if (parentDeclName != null && parentDeclName.getIsUnsolved()) + { + return Optional.empty(); + } + + // type arguments will be set in caller (which is this same method) + return Optional.of(new JavaTypeName(name, typeParameterNames, null, parentDeclName)); + } + + public static Optional getQualifiedName(IMethodBinding binding, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedName(binding, currentFile, compilationUnit, null); + } + + public static Optional getQualifiedName(IMethodBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedName(binding); + } + + public Optional getQualifiedName(IMethodBinding binding) + { + if (binding == null) + { + return Optional.empty(); + } + + String name = binding.getName(); + + List typeParameterNames = null; + if (binding.isGenericMethod()) + { + typeParameterNames = new ArrayList<>(); + for (ITypeBinding typeParameter: binding.getTypeParameters()) + { + typeParameterNames.add(typeParameter.getName()); + } + } + + ContextList ignoredContexts = m_ignoredContexts.copy(); + ignoredContexts.add(binding); + + JavaTypeName returnTypeName = binding.isConstructor() ? null : getQualifiedName(binding.getReturnType(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(JavaTypeName.unsolved()); + + List parameterTypeNames = new ArrayList<>(); + for (ITypeBinding parameterType: binding.getParameterTypes()) + { + parameterTypeNames.add(getQualifiedName(parameterType, m_currentFile, m_compilationUnit, ignoredContexts).orElse(JavaTypeName.unsolved())); + } + + boolean isStatic = Modifier.isStatic(binding.getModifiers()); + + JavaFunctionDeclName declName = new JavaFunctionDeclName(name, typeParameterNames, returnTypeName, parameterTypeNames, isStatic); + + JavaDeclName parentDeclName = getQualifiedContextName(binding); + if (parentDeclName != null) + { + if (!parentDeclName.getIsUnsolved()) + { + declName.setParent(parentDeclName); + } + else + { + return Optional.empty(); + } + } + + return Optional.of(declName); + } + + public static Optional getQualifiedName(IPackageBinding binding, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedName(binding, currentFile, compilationUnit, null); + } + + public static Optional getQualifiedName(IPackageBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedName(binding); + } + + public Optional getQualifiedName(IPackageBinding binding) + { + if (!binding.isUnnamed()) + { + return Optional.of(JavaDeclName.fromDotSeparatedString(binding.getName())); + } + return Optional.empty(); + } + + public static JavaDeclName getQualifiedName(IVariableBinding binding, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedName(binding, currentFile, compilationUnit, null); + } + + public static JavaDeclName getQualifiedName(IVariableBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedName(binding); + } + + public JavaDeclName getQualifiedName(IVariableBinding binding) + { + if (binding == null) + { + return JavaDeclName.unsolved(); + } + + if (binding.isField() || binding.isEnumConstant()) + { + JavaDeclName declName; + if (binding.isEnumConstant()) + { + declName = new JavaDeclName(binding.getName()); + } + else + { + JavaTypeName typeName = getQualifiedName(binding.getType()).orElse(JavaTypeName.unsolved()); + declName = new JavaVariableDeclName(binding.getName(), typeName, Modifier.isStatic(binding.getModifiers())); + } + + JavaDeclName parentDeclName = getQualifiedContextName(binding); + if (parentDeclName != null) + { + if (!parentDeclName.getIsUnsolved()) + { + declName.setParent(parentDeclName); + } + else + { + declName = JavaDeclName.unsolved(); + } + } + + return declName; + } + else + { + if (binding.getDeclaringMethod() != null) + { + return JavaDeclName.localSymbol(getQualifiedName(binding.getDeclaringMethod()).orElse(JavaDeclName.unsolved()), binding.getVariableId()); + } + else + { + return JavaDeclName.globalSymbol(m_currentFile, binding.getVariableId()); + } + } + } + + private JavaDeclName getQualifiedContextName(IBinding binding) + { + IBinding parentBinding = getParentBinding(binding); + + if (parentBinding == null || m_ignoredContexts.contains(parentBinding)) + { + return null; + } + + if (parentBinding instanceof ITypeBinding) + { + return getQualifiedName((ITypeBinding) parentBinding).map(tn ->tn.toDeclName()).orElse(JavaDeclName.unsolved()); + } + else if (parentBinding instanceof IMethodBinding) + { + return getQualifiedName((IMethodBinding) parentBinding).orElse(JavaDeclName.unsolved()); + } + else if (parentBinding instanceof IVariableBinding) + { + return getQualifiedName((IVariableBinding) parentBinding); + } + else if (parentBinding instanceof IPackageBinding) + { + return getQualifiedName((IPackageBinding) parentBinding).orElse(null); + } + + return null; + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java new file mode 100644 index 00000000..f9f7649d --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java @@ -0,0 +1,318 @@ +package com.sourcetrail.name.resolver; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; +import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; +import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; +import org.eclipse.jdt.core.dom.BodyDeclaration; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.EnumConstantDeclaration; +import org.eclipse.jdt.core.dom.EnumDeclaration; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.Initializer; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.core.dom.QualifiedName; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.TypeParameter; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; + +import com.sourcetrail.ContextList; +import com.sourcetrail.Position; +import com.sourcetrail.Utility; +import com.sourcetrail.name.JavaDeclName; +import com.sourcetrail.name.JavaFunctionDeclName; +import com.sourcetrail.name.JavaTypeName; +import com.sourcetrail.name.JavaVariableDeclName; + +public class DeclNameResolver extends NameResolver +{ + public DeclNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + super(currentFile, compilationUnit, ignoredContexts); + } + + public static JavaDeclName getQualifiedDeclName(VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedDeclName(decl, currentFile, compilationUnit, null); + } + + public static JavaDeclName getQualifiedDeclName(VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedDeclName(decl); + } + + public JavaDeclName getQualifiedDeclName(VariableDeclarationFragment decl) + { + JavaDeclName declName = JavaDeclName.unsolved(); + + if (decl != null) + { + declName = getDeclName(decl); + if (!declName.getIsUnsolved()) + { + JavaDeclName parentDeclName = getQualifiedContextName(decl); + if (parentDeclName != null) + { + if (!parentDeclName.getIsUnsolved()) + { + declName.setParent(parentDeclName); + } + else + { + declName = JavaDeclName.unsolved(); + } + } + } + } + return declName; + } + + public JavaDeclName getDeclName(VariableDeclarationFragment decl) + { + JavaTypeName typeName = JavaTypeName.unsolved(); + + boolean isStatic = false; + Optional fieldDeclaration = getAncestorOfType(decl, FieldDeclaration.class); + if (fieldDeclaration.isPresent()) + { + if (decl.resolveBinding() instanceof IVariableBinding) + { + isStatic = Modifier.isStatic(decl.resolveBinding().getModifiers()); + } + else + { + isStatic = Modifier.isStatic(fieldDeclaration.get().getModifiers()); + } + typeName = BindingNameResolver.getQualifiedName( + fieldDeclaration.get().getType().resolveBinding(), + m_currentFile, + m_compilationUnit, + m_ignoredContexts.copy()).orElse(JavaTypeName.unsolved()); + } + + return new JavaVariableDeclName(decl.getName().getIdentifier(), typeName, isStatic); + } + + public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedDeclName(decl, currentFile, compilationUnit, null); + } + + public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedDeclName(decl); + } + + public JavaDeclName getQualifiedDeclName(BodyDeclaration decl) + { + JavaDeclName declName = JavaDeclName.unsolved(); + + if (decl != null) + { + declName = getDeclName(decl); + if (!declName.getIsUnsolved()) + { + JavaDeclName parentDeclName = getQualifiedContextName(decl); + if (parentDeclName != null) + { + if (!parentDeclName.getIsUnsolved()) + { + declName.setParent(parentDeclName); + } + else + { + declName = JavaDeclName.unsolved(); + } + } + } + } + + return declName; + } + + public JavaDeclName getDeclName(BodyDeclaration decl) + { + JavaDeclName declName = JavaDeclName.unsolved(); + + if (decl != null) + { + if (decl instanceof AnnotationTypeDeclaration) + { + declName = new JavaDeclName("AnnotationTypeDeclaration"); + } + else if (decl instanceof EnumDeclaration) + { + declName = new JavaDeclName(((EnumDeclaration) decl).getName().getIdentifier()); + } + else if (decl instanceof TypeDeclaration) + { + TypeDeclaration typeDeclaration = (TypeDeclaration) decl; + + List typeParameterNames = new ArrayList<>(); + for (Object typeParameter: typeDeclaration.typeParameters()) + { + if (typeParameter instanceof TypeParameter) + { + typeParameterNames.add(((TypeParameter) typeParameter).getName().getIdentifier()); + } + } + + declName = new JavaDeclName(typeDeclaration.getName().getIdentifier(), typeParameterNames); + } + else if (decl instanceof AnnotationTypeMemberDeclaration) + { + declName = new JavaDeclName("AnnotationTypeMemberDeclaration"); + } + else if (decl instanceof EnumConstantDeclaration) + { + declName = new JavaDeclName(((EnumConstantDeclaration) decl).getName().getIdentifier()); + } + else if (decl instanceof FieldDeclaration) + { + declName = new JavaDeclName("FieldDeclaration"); + } + else if (decl instanceof Initializer) + { + declName = new JavaDeclName("Initializer"); + } + else if (decl instanceof MethodDeclaration) + { + MethodDeclaration methodDeclaration = (MethodDeclaration) decl; + + List typeParameterNames = new ArrayList<>(); + for (Object typeParameter: methodDeclaration.typeParameters()) + { + if (typeParameter instanceof TypeParameter) + { + typeParameterNames.add(((TypeParameter) typeParameter).getName().getIdentifier()); + } + } + + ContextList ignoredContexts = m_ignoredContexts.copy(); + ignoredContexts.add(((MethodDeclaration) decl).resolveBinding()); + + JavaTypeName returnTypeName = methodDeclaration.isConstructor() ? null : BindingNameResolver.getQualifiedName( + methodDeclaration.getReturnType2().resolveBinding(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(JavaTypeName.unsolved()); + + List parameterTypeNames = new ArrayList<>(); + for (Object parameter: methodDeclaration.parameters()) + { + if (parameter instanceof SingleVariableDeclaration) + { + parameterTypeNames.add(BindingNameResolver.getQualifiedName( + ((SingleVariableDeclaration) parameter).getType().resolveBinding(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(JavaTypeName.unsolved())); + } + } + + declName = new JavaFunctionDeclName( + methodDeclaration.getName().getIdentifier(), + typeParameterNames, + returnTypeName, + parameterTypeNames, + Modifier.isStatic(methodDeclaration.getModifiers())); + } + } + + return declName; + } + + public static JavaDeclName getQualifiedDeclName(AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit) + { + return getQualifiedDeclName(decl, currentFile, compilationUnit, null); + } + + public static JavaDeclName getQualifiedDeclName(AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts); + return resolver.getQualifiedDeclName(decl); + } + + public JavaDeclName getQualifiedDeclName(AnonymousClassDeclaration decl) + { + JavaDeclName declName = JavaDeclName.unsolved(); + + if (decl != null) + { + declName = getDeclName(decl); + if (!declName.getIsUnsolved()) + { + JavaDeclName parentDeclName = getQualifiedContextName(decl); + if (parentDeclName != null) + { + if (!parentDeclName.getIsUnsolved()) + { + declName.setParent(parentDeclName); + } + else + { + declName = JavaDeclName.unsolved(); + } + } + } + } + return declName; + } + + public JavaDeclName getDeclName(AnonymousClassDeclaration decl) + { + Position pos = Utility.getRange(decl, m_compilationUnit).begin; + return JavaDeclName.anonymousClass(m_currentFile, pos.line, pos.column); + } + + + public static JavaDeclName getQualifiedName(Name name) + { + if (name.isSimpleName()) + { + return new JavaDeclName(((SimpleName) name).getIdentifier()); + } + else + { + JavaDeclName declName = new JavaDeclName(((QualifiedName) name).getName().getIdentifier()); + declName.setParent(getQualifiedName(((QualifiedName) name).getQualifier())); + return declName; + } + } + + private JavaDeclName getQualifiedContextName(ASTNode decl) + { + ASTNode parentNode = decl.getParent(); + if (parentNode == null) + { + return null; + } + + if (parentNode instanceof BodyDeclaration && !(parentNode instanceof FieldDeclaration)) + { + return getQualifiedDeclName((BodyDeclaration) parentNode); + } + else if (parentNode instanceof AnonymousClassDeclaration) + { + return getQualifiedDeclName((AnonymousClassDeclaration) parentNode); + } + else if (parentNode instanceof CompilationUnit) + { + PackageDeclaration packageDecl = ((CompilationUnit) parentNode).getPackage(); + if (packageDecl != null) + { + return getQualifiedName(packageDecl.getName()); + } + return null; + } + + return getQualifiedContextName(parentNode); + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java b/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java new file mode 100644 index 00000000..c15a00b9 --- /dev/null +++ b/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java @@ -0,0 +1,45 @@ +package com.sourcetrail.name.resolver; + +import java.io.File; +import java.util.Optional; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.CompilationUnit; + +import com.sourcetrail.ContextList; + +public abstract class NameResolver +{ + protected File m_currentFile = null; + protected ContextList m_ignoredContexts = null; + protected CompilationUnit m_compilationUnit = null; + + static protected Optional getAncestorOfType(ASTNode node, Class classType) + { + ASTNode parent = node.getParent(); + while (parent != null) + { + if (classType.isAssignableFrom(parent.getClass())) + { + return Optional.of(classType.cast(parent)); + } + parent = parent.getParent(); + } + return Optional.empty(); + } + + public NameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + { + m_currentFile = currentFile; + m_compilationUnit = compilationUnit; + + if (ignoredContexts != null) + { + m_ignoredContexts = ignoredContexts; + } + else + { + m_ignoredContexts = new ContextList(); + } + } +} diff --git a/java_indexer/src/main/java/com/sourcetrail/typesolver/SynchronizedJavaParserTypeSolver.java b/java_indexer/src/main/java/com/sourcetrail/typesolver/SynchronizedJavaParserTypeSolver.java deleted file mode 100644 index b1dae652..00000000 --- a/java_indexer/src/main/java/com/sourcetrail/typesolver/SynchronizedJavaParserTypeSolver.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.sourcetrail.typesolver; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import com.github.javaparser.symbolsolver.model.declarations.ReferenceTypeDeclaration; -import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; -import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; - -public class SynchronizedJavaParserTypeSolver extends JavaParserTypeSolver -{ - private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - private Map> solvedTypes = new HashMap<>(); - - public SynchronizedJavaParserTypeSolver(File srcDir) - { - super(srcDir); - } - - @Override - public SymbolReference tryToSolveType(String name) - { - SymbolReference solvedType = SymbolReference.unsolved(ReferenceTypeDeclaration.class); - - { - lock.readLock().lock(); - if (solvedTypes.containsKey(name)) - { - solvedType = solvedTypes.get(name); - } - lock.readLock().unlock(); - } - - if (!solvedType.isSolved()) - { - solvedType = super.tryToSolveType(name); - - if (solvedType.isSolved()) - { - lock.writeLock().lock(); - if (!solvedTypes.containsKey(name)) - { - solvedTypes.put(name, solvedType); - } - lock.writeLock().unlock(); - } - } - - return solvedType; - } -} diff --git a/script/update_java_indexer.sh b/script/update_java_indexer.sh index 3611790f..f3bcc336 100755 --- a/script/update_java_indexer.sh +++ b/script/update_java_indexer.sh @@ -38,10 +38,4 @@ echo -e $INFO "copy jars" mkdir -p bin/app/data/java rm -rf bin/app/data/java/* cp -r java_indexer/target/java-indexer-1.0.jar bin/app/data/java/java-indexer.jar -cp -r java_indexer/target/dependency/guava*.jar bin/app/data/java -cp -r java_indexer/target/dependency/javaparser-core*.jar bin/app/data/java/javaparser-core.jar -cp -r java_indexer/target/dependency/javaslang*.jar bin/app/data/java -cp -r java_indexer/target/dependency/javassist*.jar bin/app/data/java -cp -r java_indexer/target/dependency/java-symbol-solver-core-x.x.x.jar bin/app/data/java/java-symbol-solver-core.jar -cp -r java_indexer/target/dependency/java-symbol-solver-logic-x.x.x.jar bin/app/data/java/java-symbol-solver-logic.jar -cp -r java_indexer/target/dependency/java-symbol-solver-model-x.x.x.jar bin/app/data/java/java-symbol-solver-model.jar +cp -r java_indexer/target/dependency/*.jar bin/app/data/java diff --git a/src/lib_java/data/parser/java/JavaParser.cpp b/src/lib_java/data/parser/java/JavaParser.cpp index 855c2e13..ac6502ae 100644 --- a/src/lib_java/data/parser/java/JavaParser.cpp +++ b/src/lib_java/data/parser/java/JavaParser.cpp @@ -16,14 +16,22 @@ std::vector JavaParser::getRequiredJarNames() { std::vector jarNames = { - "guava-21.0.jar", + "java-indexer.jar", - "javaparser-core.jar", - "javaslang-2.0.3.jar", - "javassist-3.19.0-GA.jar", - "java-symbol-solver-core.jar", - "java-symbol-solver-logic.jar", - "java-symbol-solver-model.jar" + "org.eclipse.core.commands-3.8.1.jar", + "org.eclipse.core.contenttype-3.5.100.jar", + "org.eclipse.core.expressions-3.5.100.jar", + "org.eclipse.core.filesystem-1.6.1.jar", + "org.eclipse.core.jobs-3.8.0.jar", + "org.eclipse.core.resources-3.11.1.jar", + "org.eclipse.core.runtime-3.12.0.jar", + "org.eclipse.equinox.app-1.3.400.jar", + "org.eclipse.equinox.common-3.8.0.jar", + "org.eclipse.equinox.preferences-3.6.1.jar", + "org.eclipse.equinox.registry-3.6.100.jar", + "org.eclipse.jdt.core-3.12.3.jar", + "org.eclipse.osgi-3.11.3.jar", + "org.eclipse.text-3.6.0.jar" }; return jarNames; } @@ -273,7 +281,7 @@ void JavaParser::doRecordReference( void JavaParser::doRecordLocalSymbol(jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn) { m_client->onLocalSymbolParsed( - m_javaEnvironment->toStdString(jSymbolName), + NameHierarchy::deserialize(m_javaEnvironment->toStdString(jSymbolName)).getQualifiedName(), ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn) ); } diff --git a/src/test/JavaParserTestSuite.h b/src/test/JavaParserTestSuite.h index a1179959..50f1965e 100644 --- a/src/test/JavaParserTestSuite.h +++ b/src/test/JavaParserTestSuite.h @@ -37,7 +37,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->packages, "foo <1:1 <1:9 1:11> 1:12>" + client->packages, "foo <1:9 1:11>" )); } @@ -120,7 +120,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->enumConstants, "foo.A.A_TEST <4:2 4:10>" + client->enumConstants, "foo.A.A_TEST <4:2 4:7>" )); } @@ -173,7 +173,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->classes, "foo.A.bar.anonymous class (input.cc<7:9>) <7:9 <7:13 7:13> 7:19>" + client->classes, "foo.A.bar.anonymous class (input.cc<7:17>) <7:17 <7:17 7:17> 7:19>" )); } @@ -197,7 +197,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->methods, "public void foo.A.bar.anonymous class (input.cc<9:9>).foo() <11:4 <11:16 11:18> 11:23>" + client->methods, "public void foo.A.bar.anonymous class (input.cc<10:3>).foo() <11:4 <11:16 11:18> 11:23>" )); } @@ -306,7 +306,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->localSymbols, "input.cc<4:15> <4:15 4:15>" + client->localSymbols, "foo.A.bar<0> <4:15 4:15>" )); } @@ -324,7 +324,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->localSymbols, "input.cc<6:7> <6:7 6:7>" + client->localSymbols, "foo.A.bar<0> <6:7 6:7>" )); } @@ -357,6 +357,20 @@ public: )); } + void test_java_parser_finds_field_of_interface_to_be_implicitly_static() + { + std::shared_ptr client = parseCode( + "public interface A\n" + "{\n" + " int b = 5;\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->fields, "default static int A.b <3:6 3:6>" + )); + } + void test_java_parser_finds_line_comment() { std::shared_ptr client = parseCode( @@ -365,7 +379,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->comments, "comment <1:1 1:26>" + client->comments, "comment <1:1 1:25>" )); } @@ -388,19 +402,20 @@ public: ); TS_ASSERT(utility::containsElement( - client->errors, "Encountered unexpected token. <0:0 0:0>" + client->errors, "Syntax error on token \"foo\", ; expected after this token <1:9 1:11>" )); } - //void _test_java_parser_finds_missing_import_as_error() - //{ - // std::shared_ptr client = parseCode( - // "import foo;\n" - // ); + void test_java_parser_finds_missing_import_as_error() + { + std::shared_ptr client = parseCode( + "import foo;\n" + ); - // TS_ASSERT_EQUALS(client->errors.size(), 1); - // TS_ASSERT_EQUALS(client->errors[0], "Import not found. <1:8 1:10>"); - //} + TS_ASSERT(utility::containsElement( + client->errors, "The import foo cannot be resolved <1:8 1:10>" + )); + } @@ -449,17 +464,6 @@ public: /////////////////////////////////////////////////////////////////////////////// // test finding usages of symbols - void test_java_parser_finds_name_of_package_imported_with_asterisk() - { - std::shared_ptr client = parseCode( - "import foo.bar.*;\n" - ); - - TS_ASSERT(utility::containsElement( - client->imports, "input.cc -> foo.bar <1:8 1:14>" - )); - } - void test_java_parser_finds_inheritance_using_extends_keyword() { std::shared_ptr client = parseCode( @@ -496,6 +500,29 @@ public: )); } + void test_java_parser_finds_inheritance_of_anonymous_class_declaration() + { + std::shared_ptr client = parseCode( + "public class A\n" + "{\n" + " public interface Base\n" + " {\n" + " }\n" + "\n" + " void foo()\n" + " {\n" + " Base b = new Base()\n" + " {\n" + " }\n" + " };\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->inheritances, "A.foo.anonymous class (input.cc<10:3>) -> A.Base <9:16 9:19>" + )); + } + void test_java_parser_finds_type_parameter_in_signature_of_method() { std::shared_ptr client = parseCode( @@ -508,10 +535,10 @@ public: ); TS_ASSERT(utility::containsElement( - client->typeUses, "A A.foo(A) -> A <3:9 3:9>" + client->typeUses, "A A.foo(A) -> A <3:9 3:9>" )); TS_ASSERT(utility::containsElement( - client->typeUses, "A A.foo(A) -> A <3:21 3:21>" + client->typeUses, "A A.foo(A) -> A <3:21 3:21>" )); } @@ -554,7 +581,7 @@ public: )); } - void test_java_parser_finds_method_call_to_super() + void test_java_parser_finds_super_method_invocation() { std::shared_ptr client = parseCode( "package foo;\n" @@ -582,6 +609,237 @@ public: )); } + void test_java_parser_finds_constructor_invocation() + { + std::shared_ptr client = parseCode( + "package foo;\n" + "public class Bar\n" + "{\n" + " public Bar()\n" + " {\n" + " }\n" + " \n" + " public Bar(int i)\n" + " {\n" + " this();\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->calls, "foo.Bar.Bar(int) -> foo.Bar.Bar() <10:3 10:6>" + )); + } + + void test_java_parser_finds_super_constructor_invocation() + { + std::shared_ptr client = parseCode( + "public class A\n" + "{\n" + " public class Base\n" + " {\n" + " }\n" + "\n" + " public class Derived extends Base\n" + " {\n" + " public Derived()\n" + " {\n" + " super();\n" + " }\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->calls, "A.Derived.Derived() -> A.Base.Base() <11:4 11:8>" + )); + } + + void test_java_parser_finds_invocation_of_method_of_anonymous_class() + { + std::shared_ptr client = parseCode( + "class Main {\n" + " public interface Interfaze {\n" + " public void foo();\n" + " }\n" + "\n" + " private Interfaze i = new Interfaze() {\n" + " public void foo() {\n" + " bar();\n" + " }\n" + "\n" + " private void bar() {\n" + " }\n" + " };\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->calls, "void Main.anonymous class (input.cc<6:40>).foo() -> void Main.anonymous class (input.cc<6:40>).bar() <8:4 8:6>" + )); + } + + void test_java_parser_finds_overridden_method_with_same_signature() + { + std::shared_ptr client = parseCode( + "class Main {\n" + " public interface Interfaze {\n" + " public void foo(int t);\n" + " }\n" + "\n" + " public class C implements Interfaze {\n" + " public void foo(int t) {\n" + " }\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->overrides, "void Main.C.foo(int) -> void Main.Interfaze.foo(int) <7:15 7:17>" + )); + } + + void test_java_parser_finds_overridden_method_with_generic_signature() + { + std::shared_ptr client = parseCode( + "class Main {\n" + " public interface Interfaze {\n" + " public void foo(T t);\n" + " }\n" + "\n" + " public class C implements Interfaze {\n" + " public void foo(X t) {\n" + " }\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->overrides, "void Main.C.foo(Main.X) -> void Main.Interfaze.foo(Main.Interfaze.T) <7:15 7:17>" + )); + } + + void test_java_parser_finds_method_usage_for_creation_reference() + { + std::shared_ptr client = parseCode( + "public class A\n" + "{\n" + " public interface Functor\n" + " {\n" + " public void doSomething();\n" + " }\n" + "\n" + " public class B\n" + " {\n" + " }\n" + "\n" + " void foo()\n" + " {\n" + " Functor method = B::new;\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->usages, "void A.foo() -> A.B.B() <14:23 14:25>" + )); + } + + void test_java_parser_finds_method_usage_for_expression_method_reference() + { + std::shared_ptr client = parseCode( + "public class A\n" + "{\n" + " public interface Functor\n" + " {\n" + " public void doSomething();\n" + " }\n" + "\n" + " public class B\n" + " {\n" + " void bar()\n" + " {\n" + " }\n" + " }\n" + "\n" + " void foo()\n" + " {\n" + " Functor method = B::bar;\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->usages, "void A.foo() -> void A.B.bar() <17:23 17:25>" + )); + } + + void test_java_parser_finds_method_usage_for_super_method_reference() + { + std::shared_ptr client = parseCode( + "public class A {\n" + " public interface Functor {\n" + " public void doSomething();\n" + " }\n" + "\n" + " public class B {\n" + " void bar() {\n" + " }\n" + " }\n" + "\n" + " public class C extends B {\n" + " void foo() {\n" + " Functor method = super::bar;\n" + " }\n" + " }\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->usages, "void A.C.foo() -> void A.B.bar() <13:28 13:30>" + )); + } + + void test_java_parser_finds_no_method_usage_for_type_method_reference() + { + std::shared_ptr client = parseCode( + "public class A {\n" + " void foo() {\n" + " Functor method = int []::clone;\n" + " }\n" + "}\n" + ); + + // finding method usage here may be implemented in the future. + TS_ASSERT_EQUALS(client->usages.size(), 0); + } + + void test_java_parser_finds_no_usage_of_field_within_that_fields_declaration() + { + std::shared_ptr client = parseCode( + "package foo;\n" + "public class X\n" + "{\n" + " private int t;\n" + "}\n" + ); + + TS_ASSERT_EQUALS(client->usages.size(), 0); + } + + void test_java_parser_finds_no_usage_of_enum_constant_within_that_enum_constants_declaration() + { + std::shared_ptr client = parseCode( + "package foo;\n" + "public enum X\n" + "{\n" + " OPTION_0;\n" + "}\n" + ); + + TS_ASSERT_EQUALS(client->usages.size(), 0); + } + void test_java_parser_finds_usage_of_field_with_same_name_as_method_parameter() { std::shared_ptr client = parseCode( @@ -608,7 +866,7 @@ public: "public class X\n" "{\n" " private int foo;\n" - " public foo()\n" + " public void foo()\n" " {\n" " this.foo = 5;\n" " }\n" @@ -616,11 +874,11 @@ public: ); TS_ASSERT(utility::containsElement( - client->usages, "foo.X.foo() -> int foo.X.foo <7:8 7:10>" + client->usages, "void foo.X.foo() -> int foo.X.foo <7:8 7:10>" )); } - void test_java_parser_finds_assignment_of_method_argument() + void test_java_parser_finds_assignment_of_method_parameter() { std::shared_ptr client = parseCode( "package foo;\n" @@ -634,7 +892,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->localSymbols, "input.cc<4:15> <6:3 6:3>" + client->localSymbols, "foo.A.bar<0> <6:3 6:3>" )); } @@ -653,7 +911,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->localSymbols, "input.cc<6:7> <7:3 7:3>" + client->localSymbols, "foo.A.bar<0> <7:3 7:3>" )); } @@ -789,6 +1047,32 @@ public: )); } + void test_java_parser_finds_scope_of_anonymous_class_declaration() + { + std::shared_ptr client = parseCode( + "public class A\n" + "{\n" + " public interface Base\n" + " {\n" + " }\n" + "\n" + " void foo()\n" + " {\n" + " Base b = new Base()\n" + " {\n" + " }\n" + " };\n" + "}\n" + ); + + TS_ASSERT(utility::containsElement( + client->localSymbols, "input.cc<10:3> <10:3 10:3>" + )); + TS_ASSERT(utility::containsElement( + client->localSymbols, "input.cc<10:3> <11:3 11:3>" + )); + } + void test_java_parser_finds_usage_of_type_parameter_of_class() { std::shared_ptr client = parseCode( @@ -827,7 +1111,7 @@ public: ); TS_ASSERT(utility::containsElement( - client->typeUses, "A A.t -> A <3:2 3:2>" + client->typeUses, "A A.t -> A <3:2 3:2>" )); } @@ -841,7 +1125,8 @@ public: TS_ASSERT(utility::containsElement( client->typeUses, "A.T -> java.lang.Void <1:27 1:30>" - )) + )); + system("PAUSE"); }