Commit 8f0cf40a authored by hequnying's avatar hequnying

lsp-java

parents
(source gnu)
(source melpa)
(package-file "lsp-java.el")
(files "*.el")
(depends-on "markdown-mode")
(development
(depends-on "spinner")
(depends-on "ecukes")
(depends-on "espuds"))
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
\ No newline at end of file
SHELL=/usr/bin/env bash
EMACS ?= emacs
CASK ?= cask
INIT="(progn \
(require 'package) \
(push '(\"melpa\" . \"https://melpa.org/packages/\") package-archives) \
(package-initialize) \
(package-refresh-contents))"
LINT="(progn \
(unless (package-installed-p 'package-lint) \
(package-install 'package-lint)) \
(require 'package-lint) \
(package-lint-batch-and-exit))"
build:
cask install
test: build compile checkdoc lint
compile:
@echo "Compiling..."
@$(CASK) $(EMACS) -Q --batch \
-L . \
--eval '(setq byte-compile-error-on-warn t)' \
-f batch-byte-compile \
*.el
lint:
@echo "package linting..."
@$(CASK) $(EMACS) -Q --batch \
-L . \
--eval $(INIT) \
--eval $(LINT) \
*.el
clean:
rm -rf .cask
.PHONY: build test compile checkdoc lint
[![MELPA](https://melpa.org/packages/lsp-java-badge.svg)](https://melpa.org/#/lsp-java)
[![Build Status](https://github.com/emacs-lsp/lsp-java/workflows/CI/badge.svg?branch=master)](https://github.com/emacs-lsp/lsp-java/actions)
[![Join the chat at https://gitter.im/emacs-lsp/lsp-mode](https://badges.gitter.im/emacs-lsp/lsp-mode.svg)](https://gitter.im/emacs-lsp/lsp-mode?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
lsp-java
========
Emacs Java IDE using [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls).
## Features
LSP java mode supports the following JDT Features:
* As you type reporting of parsing and compilation errors (via [flycheck](https://github.com/flycheck/flycheck)/[lsp-ui](https://github.com/emacs-lsp/lsp-ui))
* Code completion - using [company-lsp](https://github.com/tigersoldier/company-lsp) or builtin ```complete-at-point```
* Javadoc hovers - using [lsp-ui](https://github.com/emacs-lsp/lsp-ui)
* Code actions - using [lsp-ui](https://github.com/emacs-lsp/lsp-ui)
* Code outline - using builtin [imenu](https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html)
* Code navigation - using builtin [xref](https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html)
* Code lens (references/implementations) - using builtin [xref](https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html)
* Highlights
* Code formatting
* Maven pom.xml project support
* Limited Gradle support
* Visual debugger - [dap-mode](https://github.com/yyoncho/dap-mode/)
* Test runner - [dap-mode](https://github.com/yyoncho/dap-mode/)
* Project explorer integration - [treemacs](https://github.com/Alexander-Miller/treemacs)
* Integration with [Spring Initializr](https://start.spring.io/)
## Demo
Here it is a demo from EmacsConf2019 https://www.youtube.com/watch?v=Bbjxn9yVNJ8
## Screenshot
![demo](images/demo.png)
## Installation
### Spacemacs
[lsp-java](https://github.com/emacs-lsp/lsp-java) is included in spacemacs (for now only on the dev branch). If you are using the development version of
spacemacs you can simply add `(java :variables java-backend 'lsp)` to `dotspacemacs-configuration-layers`.
### Install via melpa
The recommended way to install LSP Java is via `package.el` - the built-in package
manager in Emacs. LSP Java is available on the two major `package.el` community
maintained repos - [MELPA Stable](http://stable.melpa.org) and [MELPA](http://melpa.org).
<kbd>M-x</kbd> `package-install` <kbd>[RET]</kbd> `lsp-java` <kbd>[RET]</kbd>
Then add the following lines to your `.emacs` and open a file from the any of the specified projects.
```emacs-lisp
(require 'lsp-java)
(add-hook 'java-mode-hook #'lsp)
```
### [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls)
[lsp-java](https://github.com/emacs-lsp/lsp-java) will automatically detect when the server is missing and it will download [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) before the first startup. The server installation will be in `lsp-java-server-install-dir`. It will detect whether [dap-mode](https://github.com/yyoncho/dap-mode/) is present and it will download the required server side plugins/components. If you want to update the server you can run `lsp-java-update-server`. To run specific version of [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) use `lsp-java-server-install-dir`.
### Quick start
Minimal configuration with [company-lsp](https://github.com/tigersoldier/company-lsp) and [lsp-ui](https://github.com/emacs-lsp/lsp-ui) and [dap-mode](https://github.com/yyoncho/dap-mode/). Now you can explore the methods under `lsp-java-*`, `dap-java-*`, `dap-*`, and `lsp-*`
```elisp
(require 'cc-mode)
(condition-case nil
(require 'use-package)
(file-error
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
(package-refresh-contents)
(package-install 'use-package)
(require 'use-package)))
(use-package projectile :ensure t)
(use-package yasnippet
:ensure t
:config (yas-global-mode))
(use-package lsp-mode :ensure t)
(use-package hydra :ensure t)
(use-package lsp-ui :ensure t)
(use-package lsp-java :ensure t
:config (add-hook 'java-mode-hook 'lsp))
(use-package dap-mode
:ensure t :after lsp-mode
:config
(dap-mode t)
(dap-ui-mode t))
(use-package dap-java :after (lsp-java))
```
## Supported commands
### LSP Mode commands
* `lsp-execute-code-action` - Execute code action.
* `lsp-rename` - Rename symbol at point
* `lsp-describe-thing-at-point` - Display help for the thing at point.
* `lsp-goto-type-definition` - Go to type definition
* `lsp-goto-implementation` - Go to implementation
* `lsp-restart-workspace` - Restart project
* `lsp-format-buffer` - Format current buffer
* `lsp-symbol-highlight` - Highlight all relevant references to the symbol under point.
* `lsp-workspace-folders-add` - Add workspace folder
* `lsp-workspace-folders-remove` - Remove workspace folder
* `lsp-workspace-folders-switch` - Switch workspace folder
### LSP Java commands
* `lsp-java-organize-imports` - Organize imports
* `lsp-java-build-project` - Perform partial or full build for the projects
* `lsp-java-update-project-configuration` - Update project configuration
* `lsp-java-actionable-notifications` - Resolve actionable notifications
* `lsp-java-update-user-settings` - Update user settings (Check the options in the table bellow.)
* `lsp-java-update-server` - Update server instalation.
* `lsp-java-generate-to-string` - Generate `toString` method.
* `lsp-java-generate-equals-and-hash-code` - Generate `equals` and `hashCode` methods.
* `lsp-java-generate-overrides` - Generate method `overrides`
* `lsp-java-generate-getters-and-setters` - Generate getters and setters.
#### Refactoring
LSP Java provides rich set of refactorings via [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) code actions and
some of them are bound to Emacs commands:
* `lsp-java-extract-to-constant` - Extract constant refactoring
* `lsp-java-add-unimplemented-methods` - Extract constant refactoring
* `lsp-java-create-parameter` - Create parameter refactoring
* `lsp-java-create-field` - Create field refactoring
* `lsp-java-create-local` - Create local refactoring
* `lsp-java-extract-method` - Extract method refactoring
* `lsp-java-add-import` - Add missing import
#### Dependency viewer
* `lsp-java-dependency-list` - View java dependencies
#### STS4 Integration (experimental)
LSP java has integration with [STS4](https://github.com/spring-projects/sts4/) providing the following functionality.
## Spring boot support (Experimental)
In addition to the integration with [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) [lsp-java](http://github.com/emacs-lsp/lsp-java) provides integration with [STS4](https://github.com/spring-projects/sts4/) which covers Spring Boot
`application.properties`, `application.yml` and `.java` files.
## Usage:
Make sure that you have configured `JAVA_HOME`. `lsp-java` will automatically download the [STS4](https://github.com/spring-projects/sts4/) when you call `lsp-java-update-server`. In order to enable [STS4](https://github.com/spring-projects/sts4/) integration add the following lines to your config:
``` emacs-lisp
(require 'lsp-java-boot)
;; to enable the lenses
(add-hook 'lsp-mode-hook #'lsp-lens-mode)
(add-hook 'java-mode-hook #'lsp-java-boot-lens-mode)
```
## Functionality for `.java`
### Navigating the source code - Go to symbol in file/workspace
Easy navigation to Spring-specific elements of your source code.
![Go to Symbol in workspace](images/java-navigation.png)
#### Commands
`lsp-workspace-symbol` - (works better usign [helm-lsp](https://github.com/yyoncho/helm-lsp))
#### Examples
* `@/` shows all defined request mappings (mapped path, request method, source location)
* `@+` shows all defined beans (bean name, bean type, source location)
* `@>` shows all functions (prototype implementation)
* `@` shows all Spring annotations in the code
### Quick-access for running apps
Easy navigation to the provided request mappings of running apps.
![accessing running apps quickly](images/running-apps.png)
#### Commands
`lsp-workspace-symbol` - (works better usign [helm-lsp](https://github.com/yyoncho/helm-lsp))
#### Examples
* `//` shows all request mappings of all running Spring Boot apps and opens a browser for the selected endpoint
### Live application information hovers
STS4 automatically detects JVM processes for running boot applications on your local machine.
For some types of information, STS 4 may also show a 'quick summary' as a codelens.
If there are multiple instances of the app running on your machine, the live data from all those instances will show up in the hover information.
``` emacs-lisp
(add-hook 'java-mode-hook #'lsp-java-boot-lens-mode)
```
![live data from running apps as hover on source code](images/live-hovers.png)
#### Examples
* `@Profile`: shows information about the active profiles on the running apps
* `@Component`, `@Bean`, `@Autowired`: shows detailed information about the beans and their wiring from the live app
* `@ContidionalOn...`: shows information about the conditions and their evaluation at runtime
### Code templates
Write Spring code with templates, available via regular code completion.
#### Examples
* `@GetMapping`
* `@PostMapping`
* `@PutMapping`
### Smart code completions
Additional code completions for Spring-specific annotations
![Smart code completion for boot properties](images/validation-completion.png)
## Functionality for `.properties` and `.yml`
This extension analyzes your project's classpath and parses and indexes any [Spring Boot
Properties Metadata](https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html) it finds. Both Maven and Gradle projects are supported.
The data in the index is used to provide validation, code completions and information
hovers while editing Spring Boot Properties in either `.properties` or `.yml` format.
### Validation and code completion in properties file
![application-properties-validation](images/validation-completion.png)
### Validation and code completion in yaml file
![application-properties-validation](images/yaml-completion-and-help.png)
#### Spring Initializr
`lsp-java` provides a frontend for [Spring Initializr](https://start.spring.io/) which simplifies the creation of Spring Boot projects directly from Emacs via `lsp-java-spring-initializr`.
![Create Spring boot project](images/boot.png)
## Supported settings
* `lsp-java-server-install-dir` -
"Install directory for eclipse.jdt.ls-server.
The slash is expected at the end."
* `lsp-java-jdt-download-url` - JDT JS download url.
Use http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server-latest.tar.gz if you want to use Eclipse Che JDT LS.
* `lsp-java-java-path` - Path of the java executable.
* `lsp-java-progress-string` - Java progress status as reported by the language server.
* `lsp-java-workspace-dir` - LSP java workspace directory.
* `lsp-java-workspace-cache-dir` - LSP java workspace cache directory.
* `lsp-java-themes-directory` - Directory containing themes.
* `lsp-java-theme` - Theme to use.
* `lsp-java-pop-buffer-function` - The function which will be used for showing the helper windows.
* `lsp-java-vmargs` - Specifies extra VM arguments used to launch the Java Language Server. Eg. use `-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication` to bypass class verification,increase the heap size to 1GB and enable String deduplication with the G1 Garbage collector
* `lsp-java-9-args` - Specifies arguments specific to java 9 and later.
* `lsp-java-errors-incomplete-classpath-severity` - Specifies the severity of the message when the classpath is incomplete for a Java file
* `lsp-java-configuration-check-project-settings-exclusions` - Checks if the extension-generated project settings files (.project, .classpath, .factorypath, .settings/) should be excluded from the file explorer.
* `lsp-java-configuration-update-build-configuration` - Specifies how modifications on build files update the Java classpath/configuration
* `lsp-java-trace-server` - Traces the communication between VS Code and the Java language server.
* `lsp-java-import-gradle-enabled` - Enable/disable the Gradle importer.
* `lsp-java-import-maven-enabled` - Enable/disable the Maven importer.
* `lsp-java-maven-download-sources` - Enable/disable eager download of Maven source artifacts.
* `lsp-java-references-code-lens-enabled` - Enable/disable the references code lens.
* `lsp-java-signature-help-enabled` - Enable/disable the signature help.
* `lsp-java-implementations-code-lens-enabled` - Enable/disable the implementations code lens.
* `lsp-java-configuration-maven-user-settings` - Path to Maven's settings.xml
* `lsp-java-format-enabled` - Enable/disable default Java formatter
* `lsp-java-save-actions-organize-imports ` - Enable/disable auto organize imports on save action
* `lsp-java-import-exclusions` - Configure glob patterns for excluding folders
* `lsp-java-content-provider-preferred` - Preferred content provider (a 3rd party decompiler id, usually). We support https://github.com/dgileadi/vscode-java-decompiler. To enable it, add:
```elisp
(setq lsp-java-content-provider-preferred "fernflower")
```
* `lsp-java-autobuild-enabled` - Enable/disable the 'auto build'
* `lsp-java-max-concurrent-builds` - Max simultaneous project builds
* `lsp-java-completion-enabled` - Enable/disable code completion support
* `lsp-java-completion-overwrite` - When set to true, code completion overwrites the current text. When set to false, code is simply added instead.
* `lsp-java-completion-guess-method-arguments` - When set to true, method arguments are guessed when a method is selected from as list of code assist proposals.
* `lsp-java-completion-favorite-static-members` - Defines a list of static members or types with static members. Content assist will propose those static members even if the import is missing.
* `lsp-java-completion-import-order` - Defines the sorting order of import statements. A package or type name prefix (e.g. 'org.eclipse') is a valid entry. An import is always added to the most specific group.
* `lsp-java-folding-range-enabled` - Enable/disable smart folding range support. If disabled, it will use the default indentation-based folding range provided by VS Code.
* `indentation-based` - [Experimental] Enable/disable progress reports from background processes on the server.
* `lsp-java-progress-reports-enabled` - [Experimental] Enable/disable progress reports from background processes on the server.
* `lsp-java-format-settings-url` - Specifies the url or file path to the [Eclipse formatter xml settings](https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings).
* `lsp-java-format-settings-profile` - Optional formatter profile name from the Eclipse formatter settings.
* `lsp-java-format-comments-enabled` - Includes the comments during code formatting.
* `lsp-java-format-on-type-enabled` - Enable/disable automatic block formatting when typing `;`, `<enter>` or `}`
* `lsp-java-bundles` - List of bundles that will be loaded in the JDT server.
* `lsp-java-code-generation-hash-code-equals-use-java7objects` - Use Objects.hash and Objects.equals when generating the hashCode and equals methods. This setting only applies to Java 7 and higher.
* `lsp-java-code-generation-hash-code-equals-use-instanceof` - Use 'instanceof' to compare types when generating the hashCode and equals methods.
* `lsp-java-code-generation-use-blocks` - Use blocks in 'if' statements when generating the methods.
* `lsp-java-code-generation-generate-comments` - Generate method comments when generating the methods.
* `lsp-java-code-generation-to-string-template` - The template for generating the toString method.
* `lsp-java-code-generation-to-string-code-style` - The code style for generating the toString method.
* `lsp-java-code-generation-to-string-skip-null-values` - Skip null values when generating the toString method.
* `lsp-java-code-generation-to-string-list-array-contents` - List contents of arrays instead of using native toString().
* `lsp-java-code-generation-to-string-limit-elements` - Limit number of items in arrays/collections/maps to list, if 0 then list all.
* `lsp-java-inhibit-message` - If non-nil, inhibit java messages echo via `inhibit-message'.
## Additional packages
* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) : Flycheck, documentation and code actions support.
* [company-lsp](https://github.com/tigersoldier/company-lsp) : LSP company backend.
* [treemacs](https://github.com/Alexander-Miller/treemacs) : Project viewer.
* [lsp-treemacs](https://github.com/emacs-lsp/lsp-treemacs) : `lsp-mode` GUI controls implemented using treemacs.
## FAQ
* LSP Java is showing to many debug messages, how to stop that?
Add the following configuration.
```emacs-lisp
(setq lsp-inhibit-message t)
```
* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) does not display all of the actions on the current point(e. g "Extract constant")?
LSP UI by default sends current line bounds for action region which breaks forces JDT server to return only "Extract method action."
```emacs-lisp
(setq lsp-ui-sideline-update-mode 'point)
```
* LSP Java does not provide completion, go to definition for some of the files?
When particular file is not part of imported project [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) could not calculate the current classpath.
* How do I change the version of java used by LSP?
Have a look at `~/.emacs.d/workspace/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml`. If you updated your local java path and want LSP to use the new version, try removing the `~/.emacs.d/workspace/` directory and relaunch LSP. Also see [#114](https://github.com/emacs-lsp/lsp-java/issues/114).
:root {
--md-primary-fg-color: #337699;
--md-accent-fg-color: #ED8B00;
--md-default-fg-color--light: #007396;
}
.md-footer {
--md-default-fg-color: #337699;
}
.md-grid {
max-width: 70rem;
}
.md-typeset a {
color: #007396;
}
Feature: Browse classpaths
@Classpath
Scenario: Organize imports
Given I have maven project "m" in "tmp"
And I add project "m" folder "tmp" to the list of workspace folders
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I insert:
"""
package temp;
import java.util.HashMap;
class App {
ArrayList<String> al = new ArrayList<>();
}
"""
And I call "save-buffer"
And I start lsp-java
And The server status must become "LSP::Started"
When I call "lsp-java-classpath-browse" and see:
"""
org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER
"""
Feature: Formatting
Scenario: Changing formatter
Given I have maven project "m" in "tmp"
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I add project "m" folder "tmp" to the list of workspace folders
And I clear the buffer
And I insert:
"""
package temp; import java.util.ArrayList; class App {ArrayList<String> al = new ArrayList<>();}
"""
And I call "save-buffer"
And I use formatter profile "profileName" from "testFormatter.xml"
And I start lsp-java
And The server status must become "LSP::Started"
When I indent buffer
And I call "save-buffer"
Then I should see:
"""
package temp;
import java.util.ArrayList;
class App
{
ArrayList<String> al = new ArrayList<>();
}
"""
Feature: Importing projects
Scenario: Maven projects
Given I have maven project "m" in "tmp"
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I add project "m" folder "tmp" to the list of workspace folders
And I start lsp-java
Then The server status must become "LSP::Started"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="13">
<profile kind="CodeFormatterProfile" name="profileName" version="13">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_parameters" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_module_statements" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="64"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="48"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_conditional_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines" value="2147483647"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="9"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="64"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="64"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_assignment_operator" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="9"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="52"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_arguments" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="9"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
</profile>
</profiles>
;;; lsp-java-steps.el --- Step definitions for lsp-java -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Ivan Yonchovski
;; Author: Ivan Yonchovski <ivan.yonchovski@tick42.com>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'f)
(require 's)
(require 'lsp-java)
(defun lsp-java-steps-async-wait (pred callback)
"Call CALLBACK when PRED becomes true."
(let (timer
(retry-count 0))
(setq timer (run-with-timer
1
1
(lambda (&rest rest)
(if (funcall pred)
(progn
(cancel-timer timer)
(funcall callback))
(setq retry-count (1+ retry-count))
(message "The function failed, attempt %s" retry-count)))))))
(Given "^I have maven project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
(lambda (project-name dir-name)
(setq default-directory lsp-java-test-root)
;; delete old directory
(when (file-exists-p dir-name)
(delete-directory dir-name t))
;; create directory structure
(mkdir (expand-file-name
(f-join dir-name project-name "src" "main" "java" "temp")) t)
;; add pom.xml
(with-temp-file (expand-file-name "pom.xml" (f-join dir-name project-name))
(insert "
<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test-project</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>test-project</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>"))))
(And "^I have a java file \"\\([^\"]+\\)\"$"
(lambda (file-name)
(setq default-directory lsp-java-test-root)
(find-file file-name)
(save-buffer)))
(And "^I add project \"\\([^\"]+\\)\" folder \"\\([^\"]+\\)\" to the list of workspace folders$"
(lambda (project dir-name)
(mkdir lsp-java-workspace-dir t)
(lsp-workspace-folders-add (f-join lsp-java-test-root dir-name project))))
(And "^I start lsp-java$"
(lambda () (lsp)))
(Then "^The server status must become \"\\([^\"]+\\)\"$"
(lambda (status callback)
(lsp-java-steps-async-wait
(lambda ()
(--some? (equal (lsp--workspace-status-string it) "::Started")
(lsp--session-workspaces (lsp-session))))
callback)))
(And "^I use formatter profile \"\\([^\"]+\\)\" from \"\\([^\"]+\\)\"$"
(lambda (formatter-name formatter-file)
(setq lsp-java-format-settings-url (lsp--path-to-uri
(f-join lsp-java-root-path "features/fixtures" formatter-file)))
(setq lsp-java-format-settings-profile formatter-name)))
(And "^There must be \"\\([^\"]+\\)\" actionable notification$"
(lambda (count callback)
(lsp-java-steps-async-wait
(lambda ()
(= (string-to-number count)
(hash-table-count (lsp-workspace-get-metadata "actionable-notifications"))))
callback)))
(When "^I indent buffer$"
(lambda ()
(indent-region (point-min) (point-marker))))
(When "^I invoke \"\\([^\"]+\\)\" I should see error message \"\\([^\"]+\\)\"$"
(lambda (command message)
(condition-case err
(funcall (intern command))
(error (cl-assert (string= message (error-message-string err)) t (error-message-string err))))))
(When "^I call \"\\([^\"]+\\)\" and see:$"
(lambda (command text callback)
(lsp-java-steps-async-wait
(lambda ()
(save-window-excursion
(funcall (intern command))
(s-contains? text (buffer-string) t)))
callback)))
(provide 'lsp-java-steps)
;;; lsp-java-steps.el ends here
(require 'f)
(let* ((features-directory
(file-name-directory
(directory-file-name (file-name-directory load-file-name))))
(project-directory
(file-name-directory
(directory-file-name features-directory))))
(defvar lsp-java-root-path project-directory)
(defvar lsp-java-test-root (f-join temporary-file-directory "tests")))
(defvar lsp-java-support-path
(f-dirname load-file-name))
(defvar lsp-java-features-path
(f-parent lsp-java-support-path))
(defvar lsp-java-root-path
(f-parent lsp-java-features-path))
(add-to-list 'load-path lsp-java-root-path)
;; Ensure that we don't load old byte-compiled versions
(let ((load-prefer-newer t))
(require 'espuds)
(require 'ert)
(require 'lsp-java))
(Setup
(unless (file-directory-p (expand-file-name "plugins" lsp-java-server-install-dir))
(lsp-java-update-server)))
(Before
(require 'lsp-java)
(setq lsp-java-workspace-dir (f-join lsp-java-test-root "workspace")
lsp-java-pop-buffer-function 'pop-to-buffer
lsp-print-io t
lsp-inhibit-message nil
lsp-java-workspace-cache-dir (f-join lsp-java-test-root "workspace-cache")
lsp-java-server-install-dir (locate-user-emacs-file "eclipse.jdt.ls/server/")
lsp-response-timeout 30)
(when (file-exists-p lsp-java-test-root)
(delete-directory lsp-java-test-root t))
(setq lsp--session (make-lsp-session)))
(After
(mapc 'kill-buffer
(seq-filter
(lambda (b)
(with-current-buffer b
(equal 'java-mode major-mode)))
(buffer-list))))
(Teardown
;; After when everything has been run
)
images/run.png

365 Bytes

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
\ No newline at end of file
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lsp-java</groupId>
<artifactId>lsp-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<root.install.dir>${user.home}/.emacs.d/eclipse.jdt.ls</root.install.dir>
</properties>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>download-server</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${jdt.download.url}</url>
<outputFileName>jdt-language-server-latest.tar.gz</outputFileName>
<skipCache>true</skipCache>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-spring-boot</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/Pivotal.vscode-spring-boot-1.6.0.vsix</url>
<outputFileName>vscode-extension.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-dependency</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/vscjava.vscode-java-dependency-0.5.1.vsix</url>
<outputFileName>java-dependency.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-di</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/dgileadi.java-decompiler-0.0.2.vsix</url>
<outputFileName>java-decompiler.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-test-dependency</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/vscode-java-test.zip</url>
<outputFileName>vscode-java-test.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>prepare</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<untar src="${project.build.directory}/jdt-language-server-latest.tar.gz" compression="gzip" dest="${jdt.js.server.root}" />
<unzip src="${project.build.directory}/vscode-extension.zip" dest="${project.build.directory}/vscode-extension-extracted" />
<unzip src="${project.build.directory}/java-dependency.zip" dest="${project.build.directory}/java-dependency" />
<unzip src="${project.build.directory}/vscode-java-test.zip" dest="${jdt.js.server.root}/java-test" />
<unzip src="${project.build.directory}/java-decompiler.zip" dest="${jdt.js.server.root}/java-decompiler" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.microsoft.java</groupId>
<artifactId>com.microsoft.java.debug.plugin</artifactId>
<version>0.24.0</version>
<outputDirectory>${java.debug.root}</outputDirectory>
<destFileName>java.debug.plugin.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>1.6.2</version>
<outputDirectory>${junit.runner.root}</outputDirectory>
<destFileName>${junit.runner.fileName}</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-boot-server</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/boot-server/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/vscode-extension-extracted/extension/jars/</directory>
<includes>
<include>spring-boot-language-server-*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-bundles</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/vscode-extension-extracted/extension/jars/</directory>
<includes>
<include>jdt-ls-extension.jar</include>
<include>jdt-ls-commons.jar</include>
<include>org.reactivestreams.reactive-streams.jar</include>
<include>io.projectreactor.reactor-core.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-decompiler </id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${jdt.js.server.root}/java-decompiler/extension/server</directory>
<includes>
<include>dg.jdt.ls.decompiler.*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-test-bundle</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${jdt.js.server.root}/java-test/server/</directory>
<includes>
<include>com.microsoft.java.test.plugin-0.19.0.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-test-data</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/java-dependency/extension/server/</directory>
<includes>
<include>com.microsoft.jdtls.ext.core-0.5.1.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
;;; lsp-java-boot.el --- Spring boot support for lsp-java -*- lexical-binding: t; -*-
;; Version: 2.0
;; Package-Requires: ((emacs "25.1") (lsp-mode "6.0") (markdown-mode "2.3") (dash "2.14.1") (f "0.20.0") (ht "2.0") (dash-functional "1.2.0") (request "0.3.0"))
;; Keywords: languague, tools
;; URL: https://github.com/emacs-lsp/lsp-java
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; LSP Java support for Spring Boot.
;;; Code:
(require 'dash)
(require 'cl-lib)
(require 'lsp-mode)
(require 'lsp-java)
(defcustom lsp-java-boot-enabled t
"If non-nil start the boot server when opening java files."
:group 'lsp-java-boot
:type 'boolean)
(defcustom lsp-java-boot-java-tools-jar nil
"Path to tools jar. If it is not specified it will be calculated using `JAVA_HOME'."
:group 'lsp-java-boot
:type 'file)
(defvar lsp-java-boot--callback nil)
(defun lsp-java-boot--find-tools-jar ()
"Calculate the path to tools.jar."
(let ((tools-jar (or lsp-java-boot-java-tools-jar
(f-join (getenv "JAVA_HOME") "lib/tools.jar"))))
(unless (f-exists? tools-jar)
(error "Please configure either JAVA_HOME or lsp-java-boot-java-tools-jar"))
tools-jar))
(defun lsp-java-boot--sts-javadoc-hover-link (_workspace params)
"Handler with PARAMS data for java doc hover."
(with-lsp-workspace (lsp-find-workspace 'jdtls nil)
(lsp-request "workspace/executeCommand"
(list :command "sts.java.addClasspathListener"
:arguments (gethash "callbackCommandId" params))
:no-wait t)))
(defun lsp-java-boot--sts-add-classpath-listener (_workspace params)
"Add classpath listener for WORKSPACE with PARAMS data."
(ignore
(with-lsp-workspace (lsp-find-workspace 'jdtls nil)
(lsp-request "workspace/executeCommand"
(list :command "sts.java.addClasspathListener"
:arguments (gethash "callbackCommandId" params))
:no-wait t))))
(defun lsp-java-boot--lens-backend (_ callback)
"Boot backend.
Store CALLBACK to use it `sts/highlight'."
(setq-local lsp-java-boot--callback callback))
;;;###autoload
(define-minor-mode lsp-java-boot-lens-mode
"Toggle code-lens overlays."
:group 'lsp-java-boot
:global nil
:init-value nil
:lighter "BLens"
(cond
(lsp-java-boot-lens-mode
(setq-local lsp-lens-backends (cl-pushnew 'lsp-java-boot--lens-backend lsp-lens-backends))
(lsp-lens-refresh t))
(t (setq-local lsp-lens-backends (delete 'lsp-java-boot--lens-backend lsp-lens-backends))
(setq-local lsp-java-boot--callback nil))))
(cl-defmethod lsp-execute-command
(_server (_command (eql sts.open.url)) params)
"Execute open url command from PARAMS data."
(browse-url (lsp-seq-first params)))
(cl-defmethod lsp-execute-command
(_server (_command (eql sts.showHoverAtPosition)) params)
"Execute show hover at position command with PARAMS data."
(goto-char (lsp--position-to-point (lsp-seq-first params)))
(lsp-describe-thing-at-point))
(defun lsp-java-boot--sts-hightlight (workspace params)
"WORKSPACE PARAMS."
(with-lsp-workspace workspace
(-let (((&hash "doc" (&hash "uri" "version") "codeLenses" code-lenses) params))
(when-let (buf (find-buffer-visiting (lsp--uri-to-path uri)))
(with-current-buffer buf
(when (and lsp-java-boot--callback lsp-java-boot-lens-mode)
(funcall lsp-java-boot--callback code-lenses version)))))))
(defun lsp-java-boot--server-jar ()
"Return the spring boot jar."
(or (-> lsp-java-server-install-dir
(expand-file-name)
(f-join "boot-server")
f-files
cl-first)
(lsp-log "Unable to find spring boot server jar.")))
(defun lsp-java-boot--ls-command (port)
"Create LS command for PORT."
(-filter 'identity
(list lsp-java-java-path
(unless (lsp-java--java-9-plus-p)
(format "-Dloader.path=%s" (lsp-java-boot--find-tools-jar)))
(format "-Dspring.lsp.client-port=%s" port)
(format "-Dserver.port=%s" port)
;; "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044,quiet=y"
"-Dsts.lsp.client=vscode"
(concat "-Dsts.log.file=" (make-temp-file "sts-log-file" nil ".log"))
(concat "-Dlogging.file=" (make-temp-file "logging-file" nil ".log"))
"-jar"
(lsp-java-boot--server-jar))))
(lsp-register-client
(make-lsp-client :new-connection
(lsp-tcp-server #'lsp-java-boot--ls-command)
:activation-fn (lambda (_filename mode)
(and lsp-java-boot-enabled
(memq mode '(java-mode conf-javaprop-mode yaml-mode))
(lsp-java-boot--server-jar)))
:request-handlers (ht ("sts/addClasspathListener" #'lsp-java-boot--sts-add-classpath-listener)
("sts/javadocHoverLink" #'lsp-java-boot--sts-javadoc-hover-link))
:notification-handlers (ht ("sts/highlight" #'lsp-java-boot--sts-hightlight)
("sts/progress" #'ignore))
:initialized-fn (lambda (workspace)
(puthash
"triggerCharacters"
'("." "@" "#" "*")
(gethash "completionProvider" (lsp--workspace-server-capabilities workspace))))
:multi-root t
:add-on? t
:server-id 'boot-ls
:completion-in-comments? t))
(provide 'lsp-java-boot)
;;; lsp-java-boot.el ends here
;;; lsp-java.el --- Java support for lsp-mode -*- lexical-binding: t; -*-
;; Version: 2.1
;; Package-Requires: ((emacs "25.1") (lsp-mode "6.0") (markdown-mode "2.3") (dash "2.14.1") (f "0.20.0") (ht "2.0") (dash-functional "1.2.0") (request "0.3.0") (treemacs "2.5"))
;; Keywords: languague, tools
;; URL: https://github.com/emacs-lsp/lsp-java
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Java specific adapter for LSP mode
;;; Code:
(require 'cc-mode)
(require 'lsp-mode)
(require 'markdown-mode)
(require 'dash)
(require 'ht)
(require 'f)
(require 'tree-widget)
(require 'request)
(require 'cl-lib)
(defgroup lsp-java nil
"JDT emacs frontend."
:prefix "lsp-java-"
:group 'applications
:link '(url-link :tag "GitHub" "https://github.com/emacs-lisp/lsp-java"))
(defcustom lsp-java-server-install-dir (f-join lsp-server-install-dir "eclipse.jdt.ls/")
"Install directory for eclipse.jdt.ls-server.
The slash is expected at the end."
:group 'lsp-java
:risky t
:type 'directory)
(defcustom lsp-java-jdt-download-url "https://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz"
"JDT JS download url.
Use http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server-latest.tar.gz if you want to use Eclipse Che JDT LS."
:group 'lsp-java
:type 'string)
(defcustom lsp-java-java-path "java"
"Path of the java executable."
:group 'lsp-java
:type 'string)
(defvar lsp-java-progress-string ""
"Java progress status as reported by the language server.")
(defface lsp-java-progress-face
'((t (:inherit 'success)))
"face for activity message"
:group 'lsp-java)
(defcustom lsp-java-workspace-dir (expand-file-name (locate-user-emacs-file "workspace/"))
"LSP java workspace directory."
:group 'lsp-java
:risky t
:type 'directory)
(defcustom lsp-java-workspace-cache-dir (expand-file-name ".cache/" lsp-java-workspace-dir)
"LSP java workspace cache directory."
:group 'lsp-java
:risky t
:type 'directory)
(defcustom lsp-java-themes-directory (f-join (f-dirname (or load-file-name buffer-file-name)) "icons")
"Directory containing themes."
:type 'directory
:group 'lsp-java)
(defcustom lsp-java-theme "vscode"
"Theme to use."
:type 'string
:group 'lsp-java)
(defcustom lsp-java-pop-buffer-function 'lsp-java-show-buffer
"The function which will be used for showing the helper windows."
:type 'function
:group 'lsp-java)
(defcustom lsp-java-vmargs '("-noverify" "-Xmx1G" "-XX:+UseG1GC" "-XX:+UseStringDeduplication")
"Specifies extra VM arguments used to launch the Java Language Server.
Eg. use `-noverify -Xmx1G -XX:+UseG1GC
-XX:+UseStringDeduplication` to bypass class
verification,increase the heap size to 1GB and enable String
deduplication with the G1 Garbage collector"
:group 'lsp-java
:risky t
:type '(repeat string))
(defcustom lsp-java-9-args '("--add-modules=ALL-SYSTEM" "--add-opens java.base/java.util=ALL-UNNAMED" "--add-opens java.base/java.lang=ALL-UNNAMED")
"Specifies arguments specific to java 9 and later."
:group 'lsp-java
:risky t
:type '(repeat string))
(defcustom lsp-java-errors-incomplete-classpath-severity "warning"
"Specifies the severity of the message when the classpath is
incomplete for a Java file"
:type '(choice (:tag "ignore" "info" "warning" "error")))
(defcustom lsp-java-dependency-package-representation "flat"
"Specifies the severity of the message when the classpath is
incomplete for a Java file"
:type '(choice (:tag "flat" "hierarchical")))
(defcustom lsp-java-configuration-check-project-settings-exclusions t
"Checks if the extension-generated project settings
files (.project, .classpath, .factorypath, .settings/) should be
excluded from the file explorer."
:type 'boolean)
(defcustom lsp-java-configuration-update-build-configuration "automatic"
"Specifies how modifications on build files update the Java
classpath/configuration"
:type '(choice (:tag "disabled" "interactive" "automatic")))
(defcustom lsp-java-trace-server "off"
"Traces the communication between VS Code and the Java language
server."
:type '(choice (:tag "off" "messages" "verbose")))
(defcustom lsp-java-import-gradle-enabled t
"Enable/disable the Gradle importer."
:type 'boolean)
(defcustom lsp-java-import-maven-enabled t
"Enable/disable the Maven importer."
:type 'boolean)
(defcustom lsp-java-maven-download-sources nil
"Enable/disable eager download of Maven source artifacts."
:type 'boolean)
(defcustom lsp-java-references-code-lens-enabled nil
"Enable/disable the references code lens."
:type 'boolean)
(defcustom lsp-java-signature-help-enabled t
"Enable/disable the signature help."
:type 'boolean)
(defcustom lsp-java-implementations-code-lens-enabled nil
"Enable/disable the implementations code lens."
:type 'boolean)
(defcustom lsp-java-configuration-maven-user-settings nil
"Path to Maven's settings.xml"
:type 'string)
(defcustom lsp-java-format-enabled t
"Enable/disable default Java formatter"
:type 'boolean)
(defcustom lsp-java-save-actions-organize-imports nil
"Enable/disable auto organize imports on save action"
:type 'boolean)
(defcustom lsp-java-import-exclusions ["**/node_modules/**" "**/.metadata/**" "**/archetype-resources/**" "**/META-INF/maven/**"]
"Configure glob patterns for excluding folders"
:type '(repeat string))
(defcustom lsp-java-content-provider-preferred nil
"Preferred content provider (a 3rd party decompiler id,
usually)"
:type 'string)
(defcustom lsp-java-autobuild-enabled t
"Enable/disable the 'auto build'"
:type 'boolean)
(defcustom lsp-java-selection-enabled t
"Enable/disable the 'auto build'"
:type 'boolean)
(defcustom lsp-java-max-concurrent-builds 1
"Max simultaneous project builds"
:type 'number)
(defcustom lsp-java-completion-enabled t
"Enable/disable code completion support"
:type 'boolean)
(defcustom lsp-java-completion-overwrite t
"When set to true, code completion overwrites the current text.
When set to false, code is simply added instead."
:type 'boolean)
(defcustom lsp-java-completion-guess-method-arguments t
"When set to true, method arguments are guessed when a method
is selected from as list of code assist proposals."
:type 'boolean)
(defcustom lsp-java-completion-favorite-static-members ["org.junit.Assert.*" "org.junit.Assume.*" "org.junit.jupiter.api.Assertions.*" "org.junit.jupiter.api.Assumptions.*" "org.junit.jupiter.api.DynamicContainer.*" "org.junit.jupiter.api.DynamicTest.*" "org.mockito.Mockito.*" "org.mockito.ArgumentMatchers.*" "org.mockito.Answers.*"]
"Defines a list of static members or types with static members.
Content assist will propose those static members even if the
import is missing."
:type '(repeat string))
(defcustom lsp-java-completion-import-order ["java" "javax" "com" "org"]
"Defines the sorting order of import statements. A package or
type name prefix (e.g. 'org.eclipse') is a valid entry. An import
is always added to the most specific group."
:type '(repeat string))
(defcustom lsp-java-folding-range-enabled t
"Enable/disable smart folding range support. If disabled, it
will use the default indentation-based folding range provided by
VS Code."
:type 'boolean)
(defcustom lsp-java-progress-reports-enabled t
"[Experimental] Enable/disable progress reports from background
processes on the server."
:type 'boolean)
(defcustom lsp-java-format-settings-url nil
"Specifies the url or file path to the [Eclipse formatter xml
settings](https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings)."
:type 'string)
(defcustom lsp-java-format-settings-profile nil
"Optional formatter profile name from the Eclipse formatter
settings."
:type 'string)
(defcustom lsp-java-format-comments-enabled t
"Includes the comments during code formatting."
:type 'boolean)
(defcustom lsp-java-format-on-type-enabled t
"Enable/disable automatic block formatting when typing `;`,
`<enter>` or `}`"
:type 'boolean)
(defcustom lsp-java-bundles nil
"List of bundles that will be loaded in the JDT server."
:group 'lsp-java
:type 'list)
(defcustom lsp-java-code-generation-hash-code-equals-use-java7objects nil
"Use Objects.hash and Objects.equals when generating the
hashCode and equals methods. This setting only applies to Java 7
and higher."
:type 'boolean)
(defcustom lsp-java-code-generation-hash-code-equals-use-instanceof nil
"Use 'instanceof' to compare types when generating the hashCode
and equals methods."
:type 'boolean)
(defcustom lsp-java-code-generation-use-blocks nil
"Use blocks in 'if' statements when generating the methods."
:type 'boolean)
(defcustom lsp-java-code-generation-generate-comments nil
"Generate method comments when generating the methods."
:type 'boolean)
(defcustom lsp-java-code-generation-to-string-template "${object.className} [${member.name()}=${member.value}, ${otherMembers}]"
"The template for generating the toString method."
:type 'string)
(defcustom lsp-java-code-generation-to-string-code-style "STRING_CONCATENATION"
"The code style for generating the toString method."
:type '(choice (:tag "STRING_CONCATENATION" "STRING_BUILDER" "STRING_BUILDER_CHAINED" "STRING_FORMAT")))
(defcustom lsp-java-code-generation-to-string-skip-null-values nil
"Skip null values when generating the toString method."
:type 'boolean)
(defcustom lsp-java-code-generation-to-string-list-array-contents t
"List contents of arrays instead of using native toString()."
:type 'boolean)
(defcustom lsp-java-code-generation-to-string-limit-elements 0
"Limit number of items in arrays/collections/maps to list, if 0
then list all."
:type 'number)
(defcustom lsp-java-completion-filtered-types ["java.awt.*" "com.sun.*"]
"Defines the type filters. All types whose fully qualified name
matches the selected filter strings will be ignored in content
assist or quick fix proposals and when organizing imports. For
example 'java.awt.*' will hide all types from the awt packages."
:type 'vector)
(declare-function dap-debug "ext:dap-mode")
(declare-function projectile-project-p "ext:projectile")
(declare-function projectile-project-root "ext:projectile")
(declare-function helm-make-source "ext:helm-source")
(lsp-register-custom-settings
'(("java.codeGeneration.toString.limitElements" lsp-java-code-generation-to-string-limit-elements)
("java.codeGeneration.toString.listArrayContents" lsp-java-code-generation-to-string-list-array-contents t)
("java.codeGeneration.toString.skipNullValues" lsp-java-code-generation-to-string-skip-null-values t)
("java.codeGeneration.toString.codeStyle" lsp-java-code-generation-to-string-code-style)
("java.codeGeneration.toString.template" lsp-java-code-generation-to-string-template)
("java.codeGeneration.generateComments" lsp-java-code-generation-generate-comments t)
("java.codeGeneration.useBlocks" lsp-java-code-generation-use-blocks t)
("java.codeGeneration.hashCodeEquals.useInstanceof" lsp-java-code-generation-hash-code-equals-use-instanceof t)
("java.codeGeneration.hashCodeEquals.useJava7Objects" lsp-java-code-generation-hash-code-equals-use-java7objects t)
("java.format.onType.enabled" lsp-java-format-on-type-enabled t)
("java.format.comments.enabled" lsp-java-format-comments-enabled t)
("java.format.settings.profile" lsp-java-format-settings-profile)
("java.format.settings.url" lsp-java-format-settings-url)
("java.progressReports.enabled" lsp-java-progress-reports-enabled t)
("java.foldingRange.enabled" lsp-java-folding-range-enabled t)
("java.completion.importOrder" lsp-java-completion-import-order)
("java.completion.favoriteStaticMembers" lsp-java-completion-favorite-static-members)
("java.completion.guessMethodArguments" lsp-java-completion-guess-method-arguments t)
("java.completion.overwrite" lsp-java-completion-overwrite t)
("java.completion.enabled" lsp-java-completion-enabled t)
("java.maxConcurrentBuilds" lsp-java-max-concurrent-builds)
("java.autobuild.enabled" lsp-java-autobuild-enabled t)
("java.selection.enabled" lsp-java-autobuild-enabled t)
("java.contentProvider.preferred" lsp-java-content-provider-preferred)
("java.import.exclusions" lsp-java-import-exclusions)
("java.saveActions.organizeImports" lsp-java-save-actions-organize-imports t)
("java.format.enabled" lsp-java-format-enabled t)
("java.configuration.maven.userSettings" lsp-java-configuration-maven-user-settings)
("java.implementationsCodeLens.enabled" lsp-java-implementations-code-lens-enabled t)
("java.signatureHelp.enabled" lsp-java-signature-help-enabled t)
("java.referencesCodeLens.enabled" lsp-java-references-code-lens-enabled t)
("java.maven.downloadSources" lsp-java-maven-download-sources t)
("java.import.maven.enabled" lsp-java-import-maven-enabled t)
("java.import.gradle.enabled" lsp-java-import-gradle-enabled t)
("java.trace.server" lsp-java-trace-server)
("java.configuration.updateBuildConfiguration" lsp-java-configuration-update-build-configuration)
("java.configuration.checkProjectSettingsExclusions" lsp-java-configuration-check-project-settings-exclusions t)
("java.errors.incompleteClasspath.severity" lsp-java-errors-incomplete-classpath-severity)
("java.dependency.packagePresentation" lsp-java-dependency-package-representation)
("java.completion.filteredTypes" lsp-java-completion-filtered-types)))
(defcustom lsp-java-inhibit-message t
"If non-nil, inhibit java messages echo via `inhibit-message'."
:type 'boolean
:group 'lsp-mode)
(defvar lsp-java--download-root "https://raw.githubusercontent.com/emacs-lsp/lsp-java/master/install/")
(defun lsp-java--json-bool (param)
"Return a PARAM for setting parsable by json.el for booleans."
(or param :json-false))
(defun lsp-java--list-or-empty (param)
"Return either PARAM or empty vector in case PARAM is nil."
(or param (vector)))
(defvar lsp-java-buffer-configurations
`(("*classpath*" . ((side . right) (slot . 10) (window-width . 0.20)))))
(defun lsp-java-show-buffer (buf)
"Show BUF according to defined rules."
(let ((win (display-buffer-in-side-window buf
(or (-> buf
buffer-name
(assoc lsp-java-buffer-configurations)
cl-rest)
'((side . right)
(slot . 1)
(window-width . 0.20))))))
(set-window-dedicated-p win t)
(select-window win)))
(defun lsp-java--locate-server-jar ()
"Return the jar file location of the language server.
The entry point of the language server is in `lsp-java-server-install-dir'/plugins/org.eclipse.equinox.launcher_`version'.jar."
(pcase (f-glob "org.eclipse.equinox.launcher_*.jar" (expand-file-name "plugins" lsp-java-server-install-dir))
(`(,single-entry) single-entry)
(`nil nil)
(server-jar-filenames
(error "Unable to find single point of entry %s" server-jar-filenames))))
(defun lsp-java--locate-server-config ()
"Return the server config based on OS."
(let ((config (cond
((string-equal system-type "windows-nt") ; Microsoft Windows
"config_win")
((string-equal system-type "darwin") ; Mac OS X
"config_mac")
(t "config_linux"))))
(let ((inhibit-message t))
(message (format "using config for %s" config)))
(expand-file-name config lsp-java-server-install-dir)))
(defun lsp-java--current-workspace-or-lose ()
"Look for the jdt-ls workspace."
(or lsp--cur-workspace
(lsp-find-workspace 'jdtls (buffer-file-name))
(error "Unable to find workspace")))
(defmacro lsp-java-with-jdtls (&rest body)
"Helper macro for invoking BODY against WORKSPACE context."
(declare (debug (form body))
(indent 0))
`(let ((lsp--cur-workspace (lsp-java--current-workspace-or-lose))) ,@body))
(defun lsp-java-build-project (&optional full)
"Perform project build action.
FULL specify whether full or incremental build will be performed."
(interactive "P" )
(lsp-java-with-jdtls
(lsp-request-async
"java/buildWorkspace"
(lsp-json-bool full)
(lambda (result)
(pcase result
(1 (lsp--info "Successfully build project."))
(2 (lsp--error "Failed to build project."))))
:mode 'detached)))
(defun lsp-java-update-project-configuration ()
"Update project configuration."
(interactive)
(let ((file-name (file-name-nondirectory (buffer-file-name))))
(if (or (string= file-name "pom.xml") (string-match "\\.gradle" file-name))
(lsp-java-with-jdtls
(lsp-notify "java/projectConfigurationUpdate"
(lsp--text-document-identifier)))
(error "Update configuration could be called only from build file(pom.xml or gradle build file)"))))
(defun lsp-java--ensure-dir (path)
"Ensure that directory PATH exists."
(unless (file-directory-p path)
(make-directory path t)))
(cl-defmethod lsp-execute-command
(_server (_command (eql java.show.references)) params)
(if-let (refs (seq-elt params 2))
(xref--show-xrefs (lsp--locations-to-xref-items refs) nil)
(user-error "No references")))
(cl-defmethod lsp-execute-command
(_server (_command (eql java.show.implementations)) params)
(if-let (refs (seq-elt params 2))
(xref--show-xrefs (lsp--locations-to-xref-items refs) nil)
(user-error "No implementations")))
(defun lsp-java--get-java-version ()
"Retrieve the java version from shell command."
(let* ((java-version-output (shell-command-to-string (concat lsp-java-java-path " -version")))
(version-string (nth 2 (split-string java-version-output))))
(string-to-number (replace-regexp-in-string "\"" "" version-string))))
(defun lsp-java--java-9-plus-p ()
"Check if java version is greater than or equal to 9."
(let ((java-version (lsp-java--get-java-version)))
(>= java-version 9)))
(defun lsp-java--ls-command ()
"LS startup command."
(let ((server-jar (lsp-java--locate-server-jar))
(server-config (lsp-java--locate-server-config))
(java-9-args (when (lsp-java--java-9-plus-p)
lsp-java-9-args)))
(lsp-java--ensure-dir lsp-java-workspace-dir)
`(,lsp-java-java-path
"-Declipse.application=org.eclipse.jdt.ls.core.id1"
"-Dosgi.bundles.defaultStartLevel=4"
"-Declipse.product=org.eclipse.jdt.ls.core.product"
"-Dlog.protocol=true"
"-Dlog.level=ALL"
,@lsp-java-vmargs
"-jar"
,server-jar
"-configuration"
,server-config
"-data"
,lsp-java-workspace-dir
,@java-9-args)))
(defun lsp-java--get-root ()
"Retrieves the root directory of the java project root if available.
The current directory is assumed to be the java project’s root otherwise."
(cond
;; the cache directory root
((string= default-directory lsp-java-workspace-cache-dir) default-directory)
((and (featurep 'projectile) (projectile-project-p)) (projectile-project-root))
((vc-backend default-directory) (expand-file-name (vc-root-dir)))
(t (let ((project-types '("pom.xml" "build.gradle" ".project")))
(or (seq-some (lambda (file) (locate-dominating-file default-directory file)) project-types)
default-directory)))))
(defun lsp-java--language-status-callback (workspace params)
"Callback for client initialized.
WORKSPACE is the currently active workspace.
PARAMS the parameters for language status notifications."
(let ((status (gethash "type" params))
(current-status (lsp-workspace-get-metadata "status" workspace)))
;; process the status message only if there is no status or if the status is
;; starting (workaround for bug https://github.com/eclipse/eclipse.jdt.ls/issues/651)
(when (not (and (or (string= current-status "Error" )
(string= current-status "Started" ))
(string= "Starting" status)))
(lsp-workspace-status status workspace)
(lsp-workspace-set-metadata "status" status workspace)
(let ((inhibit-message lsp-java-inhibit-message))
(lsp-log "%s[%s]" (gethash "message" params) (gethash "type" params))))))
(defun lsp-java--apply-workspace-edit (action)
"Callback for java/applyWorkspaceEdit.
ACTION is the action to execute."
(lsp--apply-workspace-edit (lsp-seq-first (gethash "arguments" action))))
(defun lsp-java--actionable-notification-callback (_workspace params)
"Handler for actionable notifications.
WORKSPACE is the currently active workspace.
PARAMS the parameters for actionable notifications."
(lsp--warn (gethash "message" params)))
(defun lsp-java--progress-report (_workspace params)
"Progress report handling.
PARAMS progress report notification data."
(-let [(&hash "status" "complete") params]
(setq lsp-java-progress-string (propertize status 'face 'lsp-java-progress-face))
(when complete
(run-with-idle-timer 0.8 nil (lambda ()
(setq lsp-java-progress-string nil))))))
(put 'lsp-java-progress-string 'risky-local-variable t)
(defun lsp-java--render-string (str)
"Render STR with `java-mode' syntax highlight."
(condition-case nil
(with-temp-buffer
(delay-mode-hooks (java-mode))
(insert str)
(font-lock-ensure)
(buffer-string))
(error str)))
(defun lsp-java--prepare-mvnw ()
"Download mvnw and return the invocation command."
(let ((mvn-executable (if (string-equal system-type "windows-nt")
"mvnw.cmd"
"mvnw"))
(downloader ".mvn/wrapper/MavenWrapperDownloader.java")
(properties ".mvn/wrapper/maven-wrapper.properties"))
(mkdir ".mvn/wrapper/" t)
(url-copy-file (concat lsp-java--download-root mvn-executable)
mvn-executable
t)
(url-copy-file (concat lsp-java--download-root downloader) downloader t)
(url-copy-file (concat lsp-java--download-root properties) properties t)
(if (string= system-type "windows-nt")
(list mvn-executable)
(list "sh" mvn-executable))))
(defun lsp-java--bundles-dir ()
"Get default bundles dir."
(concat (file-name-as-directory lsp-java-server-install-dir) "bundles"))
(defun lsp-java--ensure-server (_client callback error-callback _update?)
"Ensure that JDT server and the other configuration."
(let* ((default-directory (make-temp-file "lsp-java-install" t))
(installed-mvn (let ((mvn-executable (executable-find "mvn")))
;; Quote path to maven executable if it has spaces.
(if (and mvn-executable
(string-match "\s" mvn-executable))
(format "\"%s\"" mvn-executable)
mvn-executable)))
(mvn-command-and-options (if installed-mvn
(list installed-mvn)
(lsp-java--prepare-mvnw)))
(other-options
(list (format "-Djdt.js.server.root=%s"
(expand-file-name lsp-java-server-install-dir))
(format "-Djunit.runner.root=%s"
(expand-file-name
(if (boundp 'dap-java-test-runner)
(file-name-directory dap-java-test-runner)
(concat (file-name-directory lsp-java-server-install-dir)
"test-runner"))))
(format "-Djunit.runner.fileName=%s"
(if (boundp 'dap-java-test-runner)
(file-name-nondirectory (directory-file-name dap-java-test-runner))
"junit-platform-console-standalone.jar"))
(format "-Djava.debug.root=%s"
(expand-file-name (lsp-java--bundles-dir)))
"clean"
"package"
(format "-Djdt.download.url=%s" lsp-java-jdt-download-url))))
(url-copy-file (concat lsp-java--download-root "pom.xml") "pom.xml" t)
(apply #'lsp-async-start-process
callback
error-callback
(append mvn-command-and-options other-options))))
(defun lsp-java-update-server ()
(interactive)
(error "lsp-java-update-server is deprecated, use `C-u M-x lsp-install-server'"))
(defun lsp-java--workspace-notify (&rest _args)
"Workspace notify handler.")
(defun lsp-java--get-filename (url)
"Get the name of the buffer calculating it based on URL."
(or (save-match-data
(when (string-match "jdt://contents/\\(.*?\\)/\\(.*\\)\.class\\?" url)
(format "%s.java"
(replace-regexp-in-string "/" "." (match-string 2 url) t t))))
(-when-let ((_ file-name _ jar)
(s-match
"jdt://.*?/\\(.*?\\)\\?=\\(.*?\\)/.*/\\(.*\\)"
(url-unhex-string url)))
(format "%s(%s)" file-name
(->> jar
(s-replace "/" "")
(s-replace "\\" ""))))
(save-match-data
(when (string-match "chelib://\\(.*\\)" url)
(let ((matched (match-string 1 url)))
(replace-regexp-in-string (regexp-quote ".jar") "jar" matched t t))))
(error "Unable to match %s" url)))
(defun lsp-java--get-metadata-location (file-location)
"Given a FILE-LOCATION return the file containing the metadata for the file."
(format "%s.%s.metadata"
(file-name-directory file-location)
(file-name-base file-location)))
(defun lsp-java--resolve-uri (uri)
"Load a file corresponding to URI executing request to the jdt server."
(let* ((buffer-name (lsp-java--get-filename uri))
(file-location (concat lsp-java-workspace-cache-dir buffer-name)))
(unless (file-readable-p file-location)
(lsp-java--ensure-dir (file-name-directory file-location))
(with-lsp-workspace (lsp-find-workspace 'jdtls nil)
(let ((content (lsp-send-request (lsp-make-request
"java/classFileContents"
(list :uri uri)))))
(with-temp-file file-location
(insert content))
(with-temp-file (lsp-java--get-metadata-location file-location)
(insert uri)))))
file-location))
(defun lsp-java-actionable-notifications ()
"Lists current actionable notifications."
(interactive)
(when-let ((notifications (lsp-workspace-get-metadata "actionable-notifications"))
(selected-notification (completing-read
"Select notification to fix:"
notifications
nil
t))
(commands (gethash "commands"
(gethash selected-notification notifications))))
(lsp-execute-code-action (lsp--select-action commands))
(remhash selected-notification notifications)
(when (= (hash-table-count notifications) 0)
(lsp-workspace-status (concat "::" (lsp-workspace-get-metadata "status"))))))
(defun lsp-java-execute-matching-action (regexp &optional not-found-message)
"Execute the code action which title match the REGEXP.
NOT-FOUND-MESSAGE will be used if there is no matching action."
(let ((actions (cl-remove-if-not
(lambda (item) (string-match regexp (gethash "title" item)))
(lsp-get-or-calculate-code-actions))))
(pcase (length actions)
(0 (error (or not-found-message "Unable to find action")))
(1 (lsp-execute-code-action (car actions)))
(_ (lsp-execute-code-action (lsp--select-action actions))))))
(defun lsp-java-extract-to-local-variable (arg)
"Extract local variable refactoring.
The prefix ARG decide whether to act on all or only on the
current symbol."
(interactive "P")
(lsp-java-execute-matching-action
(if arg
"Extract to local variable$"
"Extract to local variable (replace all occurrences)")))
(defun lsp-java-convert-to-static-import (arg)
"Convert to static import.
The prefix ARG decide whether to act on all or only on the
current symbol."
(interactive "P")
(lsp-java-execute-matching-action
(if arg
"Convert to static import$"
"Convert to static import (replace all occurrences)$")))
(defun lsp-java-extract-to-constant ()
"Extract constant refactoring."
(interactive)
(lsp-java-execute-matching-action "Extract to constant"))
(defun lsp-java-add-throws ()
"Extract constant refactoring."
(interactive)
(lsp-java-execute-matching-action "Add throws declaration"))
(defun lsp-java-add-unimplemented-methods ()
"Extract constant refactoring."
(interactive)
(lsp-java-execute-matching-action "Add unimplemented methods"))
(defun lsp-java-create-parameter ()
"Create parameter refactoring."
(interactive)
(lsp-java-execute-matching-action "Create parameter '"))
(defun lsp-java-create-field ()
"Create field refactoring."
(interactive)
(lsp-java-execute-matching-action "Create field '"))
(defun lsp-java-create-local ()
"Create local refactoring."
(interactive)
(lsp-java-execute-matching-action "Create local variable"))
(defun lsp-java-extract-method ()
"Extract method refactoring."
(interactive)
(lsp-java-execute-matching-action "Extract to method"))
(defun lsp-java-assign-to-field ()
"Assign to new field."
(interactive)
(lsp-java-execute-matching-action "Assign parameter to new field"))
(defun lsp-java-assign-all ()
"Assign to new field."
(interactive)
(lsp-java-execute-matching-action "Assign all parameters to new fields"))
(defun lsp-java-add-import ()
"Add missing import."
(interactive)
(lsp-java-execute-matching-action "Import '.*'"))
(defun lsp-java--bundles ()
"Get lsp java bundles."
(let ((bundles-dir (lsp-java--bundles-dir)))
(append lsp-java-bundles (when (file-directory-p bundles-dir)
(apply 'vector (directory-files bundles-dir t "\\.jar$"))))))
(defun lsp-java--workspace-folders (_workspace)
"Return WORKSPACE folders."
(lsp-session-folders (lsp-session)))
(defun lsp-java--find-workspace (file-uri)
"Return the workspace corresponding FILE-URI."
(lsp-find-workspace 'jdtls (lsp--uri-to-path file-uri)))
(cl-defmethod lsp-execute-command
(_server (_command (eql java.show.references)) params)
(if-let (refs (cl-third (append params nil)))
(lsp-show-xrefs (lsp--locations-to-xref-items refs) nil t)
(user-error "No references")))
(cl-defmethod lsp-execute-command
(_server (_command (eql java.show.implementations)) params)
(if-let (refs (cl-third (append params nil)))
(lsp-show-xrefs (lsp--locations-to-xref-items refs) nil t)
(user-error "No implementations")))
(add-to-list 'global-mode-string (list '(t lsp-java-progress-string)))
(defun lsp-java-boot--workspace-execute-client-command (_jdt-ls-workspace params)
"PARAMS is the classpath info."
(-let (((&hash "command" "arguments") params))
(pcase command
("java.action.organizeImports.chooseImports"
(-let (([file-uri imports] (gethash "arguments" params)))
(with-current-buffer (find-file (lsp--uri-to-path file-uri))
(->> imports
(seq-map (-lambda ((&hash "candidates" "range"))
(-let (((beg . _end) (lsp--range-to-region range)))
(goto-char beg)
(recenter nil))
(lsp--completing-read "Select class to import: "
candidates
(-partial #'gethash "fullyQualifiedName"))))
(apply #'vector)))))
(_ (ignore
(with-lsp-workspace (lsp-find-workspace 'boot-ls nil)
(aset arguments 2 (if (seq-elt arguments 2) t :json-false))
(lsp-request "workspace/executeCommand"
(list :command command :arguments arguments))))))))
(defun lsp-java-generate-to-string ()
"Generate `toString' method."
(interactive)
(lsp-execute-code-action-by-kind "source.generate.toString"))
(defun lsp-java-generate-equals-and-hash-code ()
"Generate `hashCode' and `equals' methods."
(interactive)
(lsp-execute-code-action-by-kind "source.generate.hashCodeEquals"))
(defun lsp-java-generate-overrides ()
"Override methods."
(interactive)
(lsp-execute-code-action-by-kind "source.overrideMethods"))
(defun lsp-java-organize-imports ()
"Generate `toString' method."
(interactive)
(lsp-execute-code-action-by-kind "source.organizeImports"))
(defun lsp-java-generate-getters-and-setters ()
"Generate getter and setters with prompt."
(interactive)
(lsp-execute-code-action-by-kind "source.generate.accessors"))
(defun lsp-java-open-super-implementation ()
"Open super implementation."
(interactive)
(if-let ((locations (append (lsp-request "java/findLinks"
(list :type "superImplementation"
:position (lsp--text-document-position-params)))
nil)))
(lsp-show-xrefs (lsp--locations-to-xref-items locations) nil nil)
(user-error "No super implementations.")))
(defvar lsp-java--helm-result nil)
(defun lsp-java--completing-read-multiple (message items initial-selection)
(if (functionp 'helm)
(progn
(require 'helm-source)
(helm :sources (helm-make-source
message 'helm-source-sync :candidates items
:action '(("Identity" lambda (_)
(setq lsp-java--helm-result (helm-marked-candidates)))))
:buffer "*lsp-java select*"
:prompt message)
lsp-java--helm-result)
(if (functionp 'ivy-read)
(let (result)
(ivy-read message (mapcar #'car items)
:action (lambda (c) (setq result (list (cdr (assoc c items)))))
:multi-action
(lambda (canditates)
(setq result (mapcar (lambda (c) (cdr (assoc c items))) canditates))))
result)
(let ((deps initial-selection) dep)
(while (setq dep (cl-rest (lsp--completing-read
(if deps
(format "%s (selected %s): " message (length deps))
(concat message ": "))
items
(-lambda ((name . id))
(if (-contains? deps id)
(concat name " ✓")
name)))))
(if (-contains? deps dep)
(setq deps (remove dep deps))
(cl-pushnew dep deps)))
deps))))
(defun lsp-java--apply-document-changes (response)
"Apply document CHANGES."
(when response
(ht-amap (with-current-buffer (find-file-noselect (lsp--uri-to-path key))
(lsp--apply-text-edits value))
(gethash "changes" response))))
(defun lsp-java--action-generate-to-string (action)
(lsp-java-with-jdtls
(-let* ((context (lsp-seq-first (gethash "arguments" action)))
((&hash "fields" "exists") (lsp-request "java/checkToStringStatus" context))
(fields-data (-map (-lambda ((field &as &hash "name" "type"))
(cons (format "%s: %s" name type) field))
fields)))
(when (or (not exists) (y-or-n-p "The equals method already exists. Replace?") )
(let ((selected-fields (lsp-java--completing-read-multiple
"Select fields to include"
fields-data
(-map #'cl-rest fields-data))))
(lsp-java--apply-document-changes
(lsp-request "java/generateToString"
(list :fields (apply #'vector selected-fields)
:context context))))))))
(defun lsp-java--action-generate-equals-and-hash-code (action)
(lsp-java-with-jdtls
(-let* ((context (lsp-seq-first (gethash "arguments" action)))
((&hash "fields" "existingMethods" methods) (lsp-request "java/checkHashCodeEqualsStatus" context))
(fields-data (-map (-lambda ((field &as &hash "name" "type"))
(cons (format "%s: %s" name type) field))
fields)))
(when (or (seq-empty-p methods) (y-or-n-p (format "The %s method already exists. Replace?" methods)) )
(let* ((selected-fields (lsp-java--completing-read-multiple "Select fields to include"
fields-data (-map #'cl-rest fields-data))))
(lsp-java--apply-document-changes
(lsp-request "java/generateHashCodeEquals"
(list :fields (apply #'vector selected-fields)
:context context
:regenerate (not (null methods))))))))))
(defun lsp-java--action-organize-imports (action)
(lsp-java-with-jdtls
(let ((context (lsp-seq-first (gethash "arguments" action))))
(lsp-request-async
"java/organizeImports" context
(lambda (result)
(ht-amap (with-current-buffer (find-file-noselect (lsp--uri-to-path key))
(lsp--apply-text-edits value))
(gethash "changes" result)))
:mode 'detached))))
(defun lsp-java--override-methods-prompt (action)
(lsp-java-with-jdtls
(let* ((context (lsp-seq-first (gethash "arguments" action)))
(result (lsp-request "java/listOverridableMethods" context))
(methods-data (-map (-lambda ((field &as &hash "name" "parameters" "declaringClass" class))
(cons (format "%s(%s) class: %s" name (s-join ", " parameters) class) field))
(gethash "methods" result)))
(methods-to-override (lsp-java--completing-read-multiple
"Select methods to override"
methods-data
(-map #'cl-rest methods-data))))
(lsp-java--apply-document-changes
(lsp-request "java/addOverridableMethods"
(list :overridableMethods (apply #'vector methods-to-override)
:context context))))))
(defun lsp-java--generate-accessors-prompt (action)
(lsp-java-with-jdtls
(let* ((context (lsp-seq-first (gethash "arguments" action)))
(result (lsp-request "java/resolveUnimplementedAccessors" context))
(fields-data (-map (-lambda ((field &as &hash "fieldName" name))
(cons (format "%s" name) field))
result))
(to-generate (lsp-java--completing-read-multiple
"Select getters/setters to generate"
fields-data
(-map #'cl-rest fields-data))))
(lsp-java--apply-document-changes
(lsp-request "java/generateAccessors"
(list :accessors(apply #'vector to-generate)
:context context))))))
(defun lsp-java--generate-constructors-prompt (action)
(lsp-java-with-jdtls
(-let* ((context (lsp-seq-first (gethash "arguments" action)))
((all &as &hash "constructors" "fields") (lsp-request "java/checkConstructorsStatus" context))
(constructors (append constructors nil))
(selection-constructors (-map (-lambda ((field &as &hash "name" "parameters"))
(cons (format "%s(%s)" name (s-join ", " parameters)) field))
(append constructors nil)))
(to-generate (if (cl-rest selection-constructors)
(lsp-java--completing-read-multiple
"Select constructors to generate"
selection-constructors
(-map #'cl-rest selection-constructors))
(append constructors nil)))
(fields-source (-map (-lambda ((field &as &hash "name" "type"))
(cons (format "%s: %s" name type) field))
fields))
(fields (when fields-source
(lsp-java--completing-read-multiple
"Select fields"
fields-source
(-map #'cl-rest fields-source)))))
(lsp-java--apply-document-changes
(lsp-request "java/generateConstructors"
(list :fields (apply #'vector fields)
:constructors (apply #'vector to-generate)
:context context))))))
(defun lsp-java-move-file (move-uris)
(-let [destination (lsp--completing-read
(format "Select destination for %s: " (buffer-name))
(gethash "destinations"
(lsp-request "java/getMoveDestinations"
(list :moveKind "moveResource"
:sourceUris move-uris
:params nil)))
(-lambda ((&hash "displayName" display-name "path"))
(format "%s - %s" display-name path)))]
(when-let (move-uris (if-let (destination-folder (lsp--uri-to-path (gethash "uri" destination)))
(-let [(duplicated-files to-move)
(--split-with
(f-exists? (f-join destination-folder (f-filename it)))
(append move-uris nil))]
(when duplicated-files
(lsp-warn "The files %s already exist in the package %s. The move operation will ignore them."
duplicated-files destination-folder))
(apply #'vector to-move))
move-uris))
(lsp-java--apply-edit
(lsp-request "java/move"
(list :moveKind "moveResource"
:sourceUris move-uris
:destination destination
:updateReferences t))))))
(defun lsp-java--apply-edit (to-apply)
(-let [(&hash "edit" "message" "command") to-apply]
(when message
(lsp--error "%s" message))
(when edit
(lsp--apply-workspace-edit edit))
(when command
(lsp-execute-code-action command))))
(defun lsp-java--symbol-label (symbol)
(-let [(&hash "name" "containerName") symbol]
(format "%s.%s" containerName name)))
(defun lsp-java--move-type (context command-info)
(-let ((document-uri (->> context
(gethash "textDocument")
(gethash "uri")))
((&hash "enclosingTypeName" enclosing-type-name
"displayName" display-name
"projectName" project-name
"supportedDestinationKinds" supported-destination-kinds) command-info))
(lsp-java--apply-edit
(lsp-request "java/move"
(if (string= "newFile"
(lsp--completing-read "What would you like to do? "
supported-destination-kinds
(lambda (kind)
(if (string= kind "newFile")
(format "Move type %s to new file" display-name)
(format "Move type %s to another class" display-name)))
nil
t))
(list :moveKind "moveTypeToNewFile"
:sourceUris (vector document-uri)
:params context)
(list :moveKind "moveTypeToClass"
:sourceUris (vector document-uri)
:params context
:destination (lsp-java--select-destination-class
(list enclosing-type-name
(format "%s.%s" enclosing-type-name
display-name))
project-name)))))))
(defun lsp-java--select-destination-class (excluded project-name)
(lsp--completing-read
"Select class: "
(->> (lsp-request "java/searchSymbols"
(list :query "*"
:projectName project-name
:sourceOnly t))
(-filter (-lambda ((&hash "name" "containerName" container-name))
(not (-contains? excluded (format "%s.%s" container-name name)))))
(--sort (s-less? (gethash "name" it)
(gethash "name" other))))
#'lsp-java--symbol-label))
(defun lsp-java-move-static-member (context command-info)
(-let [(&hash? "enclosingTypeName" enclosing-type-name
"projectName" project-name) command-info]
(lsp-java--apply-edit
(lsp-request "java/move"
(list :moveKind "moveStaticMember"
:sourceUris (->> context
(gethash "textDocument")
(gethash "uri")
vector)
:params context
:destination (lsp-java--select-destination-class
(list enclosing-type-name) project-name))))))
(defun lsp-java--move-instance-method (context command-info)
(-let* ((document-uri (->> context
(gethash "textDocument")
(gethash "uri")))
((&hash "destinations" "errorMessage" message)
(lsp-request "java/getMoveDestinations"
(list :moveKind "moveInstanceMethod"
:sourceUris (vector document-uri)
:params context))))
(when message
(user-error message))
(when (seq-empty-p destinations)
(user-error "Cannot find possible class targets to move the selected method to."))
(lsp-java--apply-edit
(lsp-request
"java/move"
(list
:moveKind "moveInstanceMethod"
:params context
:sourceUris (vector )
:destination (lsp--completing-read
(format "Select the new class for the instance method %s"
(gethash "methodName" command-info))
destinations
(-lambda ((&hash "name" "type" "isField" field?))
(format "%s.%s (%s)" type name (if field?
"Field"
"Method Parameter")))
nil
t))))))
(defun lsp-java--apply-refactoring-command (action)
(lsp-java-with-jdtls
(-let [(command context command-info) (append (gethash "arguments" action) nil)]
(cond
((-contains? '("extractVariable"
"extractVariableAllOccurrence"
"extractConstant"
"extractMethod"
"extractField"
"convertVariableToField"
"invertVariable"
"convertAnonymousClassToNestedCommand")
command)
(-let ((arguments (when (memq command '("extractField" "convertVariableToField"))
(when-let (scope (pcase (append (gethash "initializedScopes" command-info) nil)
(`nil nil)
(`(,scope) scope)
(scopes (or (completing-read "Initialize the field in: " scopes nil t)
(user-error "Cancelled...")))))
(vector scope)))))
(lsp-java--apply-edit
(lsp-request
"java/getRefactorEdit"
(list :command command
:context context
:options (plist-get (lsp--make-document-formatting-params) :options)
:commandArguments arguments)))))
((string= command "moveFile") (lsp-java-move-file (vector (gethash "uri" command-info))))
((string= command "moveStaticMember") (lsp-java-move-static-member context command-info))
((string= command "moveInstanceMethod") (lsp-java--move-instance-method context command-info))
((string= command "moveType") (lsp-java--move-type context command-info))))))
(defun lsp-java--action-rename (action)
(-let* (([(&hash "uri" "offset" "length")] (gethash "arguments" action)))
(with-current-buffer (find-file (lsp--uri-to-path uri))
(deactivate-mark)
(goto-char (1+ offset))
(set-mark (point))
(goto-char (+ (point) length))
(call-interactively 'lsp-rename)
(deactivate-mark))))
(lsp-register-client
(make-lsp--client
:new-connection (lsp-stdio-connection #'lsp-java--ls-command
#'lsp-java--locate-server-jar)
:major-modes '(java-mode)
:server-id 'jdtls
:multi-root t
:notification-handlers (ht ("language/status" #'lsp-java--language-status-callback)
("language/actionableNotification" #'lsp-java--actionable-notification-callback)
("language/progressReport" #'lsp-java--progress-report)
("workspace/notify" #'lsp-java--workspace-notify))
:request-handlers (ht ("workspace/executeClientCommand" 'lsp-java-boot--workspace-execute-client-command))
:action-handlers (ht ("java.apply.workspaceEdit" #'lsp-java--apply-workspace-edit)
("java.action.generateToStringPrompt" #'lsp-java--action-generate-to-string)
("java.action.hashCodeEqualsPrompt" #'lsp-java--action-generate-equals-and-hash-code)
("java.action.organizeImports" #'lsp-java--action-organize-imports)
("java.action.overrideMethodsPrompt" #'lsp-java--override-methods-prompt)
("java.action.generateAccessorsPrompt" #'lsp-java--generate-accessors-prompt)
("java.action.generateConstructorsPrompt" #'lsp-java--generate-constructors-prompt)
("java.action.applyRefactoringCommand" #'lsp-java--apply-refactoring-command)
("java.action.rename" 'lsp-java--action-rename))
:uri-handlers (ht ("jdt" #'lsp-java--resolve-uri)
("chelib" #'lsp-java--resolve-uri))
:initialization-options (lambda ()
(list :settings (lsp-configuration-section "java")
:extendedClientCapabilities
(list :progressReportProvider (lsp-json-bool lsp-java-progress-reports-enabled)
:classFileContentsSupport t
:classFileContentsSupport t
:overrideMethodsPromptSupport t
:hashCodeEqualsPromptSupport t
:advancedOrganizeImportsSupport t
:generateConstructorsPromptSupport t
:generateToStringPromptSupport t
:advancedGenerateAccessorsSupport t
:advancedExtractRefactoringSupport t
:moveRefactoringSupport t)
:bundles (lsp-java--bundles)
:workspaceFolders (->> (lsp-session)
lsp-session-server-id->folders
(gethash 'jdtls)
(-uniq)
(-map #'lsp--path-to-uri)
(apply #'vector))))
:library-folders-fn (lambda (_workspace) (list lsp-java-workspace-cache-dir))
:before-file-open-fn (lambda (_workspace)
(let ((metadata-file-name (lsp-java--get-metadata-location buffer-file-name)))
(setq-local lsp-buffer-uri
(when (file-exists-p metadata-file-name)
(with-temp-buffer (insert-file-contents metadata-file-name)
(buffer-string))))))
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
(lsp--set-configuration (lsp-configuration-section "java"))
(lsp--server-register-capability
(ht ("id" "test-id")
("method" "workspace/didChangeWatchedFiles")
("registerOptions" (ht ("watchers"
(vector (ht ("globPattern" "**/*.java"))
(ht ("globPattern" "**/pom.xml"))
(ht ("globPattern" "**/*.gradle"))
(ht ("globPattern" "**/.project"))
(ht ("globPattern" "**/.classpath"))
(ht ("globPattern" "**/settings/*.prefs"))))))))))
:completion-in-comments? t
:download-server-fn #'lsp-java--ensure-server))
(defun lsp-java-spring-initializr ()
"Emacs frontend for https://start.spring.io/."
(interactive)
(let ((base-url "https://start.spring.io/"))
(message "Requesting spring initializr data...")
(request
base-url
:type "GET"
:parser (lambda () (let ((json-array-type 'list)) (json-read)))
:headers '(("Accept" . "application/vnd.initializr.v2.1+json"))
:success (cl-function
(lambda (&key data &allow-other-keys)
(cl-flet ((ask (message key) (alist-get 'id
(lsp--completing-read message
(alist-get 'values (alist-get key data))
(-partial 'alist-get 'name)))))
(condition-case _err
(-let* ((group-id (read-string "Enter group name: " "com.example"))
(artifact-id (read-string "Enter artifactId: " "demo"))
(_description (read-string "Enter description: " "Demo project for Spring Boot"))
(boot-version (ask "Select boot-version: " 'bootVersion))
(_java-version (ask "Select java-version: " 'javaVersion))
(language (ask "Select language: " 'language))
(packaging (ask "Select packaging: " 'packaging))
(base-url "https://start.spring.io/")
(_package-name (read-string "Select package name: " "com.example.demo"))
(type (ask "Select type: " 'type))
(target-directory (read-directory-name "Select project directory: " default-directory))
(dependenciles-list (->> data
(alist-get 'dependencies)
(alist-get 'values)
(-map (-lambda ((&alist 'name 'values))
(-map (-lambda ((&alist 'id 'name dep-name 'description))
(cons (format "%s / %s (%s)" name dep-name description) id)) values)))
(apply 'append)))
(temp-file (make-temp-file "spring-project" nil ".zip"))
(deps (lsp-java--completing-read-multiple "Select dependencies: " dependenciles-list nil)))
(let ((download-url (format "%sstarter.zip?type=%s&language=%s&groupId=%s&artifactId=%s&packaging=%s&bootVersion=%s&baseDir=%s&dependencies=%s"
base-url type language group-id artifact-id packaging boot-version artifact-id (s-join "," deps))))
(message "Downloading template from %s" download-url)
(if (executable-find "wget")
(shell-command (format "wget -O %s '%s' " temp-file download-url))
(if (executable-find "curl")
(shell-command (format "curl -o %s '%s' " temp-file download-url))
(url-copy-file download-url temp-file t)))
(if (executable-find "unzip")
(progn
(shell-command (format "unzip %s -d %s" temp-file target-directory))
(when (yes-or-no-p "Do you want to import the project?")
(lsp-workspace-folders-add (f-join target-directory artifact-id)))
(find-file (f-join target-directory artifact-id)))
(user-error "Unable to unzip tool - file %s cannot be extracted, extract it manually" temp-file))))
('quit))))))))
;; lsp-java run
;;;###autoload
(define-minor-mode lsp-java-lens-mode
"Toggle run/debug overlays."
:group 'lsp-java
:global nil
:init-value nil
:lighter nil
(cond
(lsp-java-lens-mode
(setq-local lsp-lens-backends (cl-pushnew #'lsp-java-lens-backend lsp-lens-backends))
(lsp-lens-refresh t))
(t (setq-local lsp-lens-backends (delete #'lsp-java-lens-backend lsp-lens-backends)))))
(defun lsp-java--start-main-class (lens no-debug?)
(-let [(&hash "mainClass" main-class
"projectName" project-name) lens]
(require 'dap-java)
(dap-debug (list :type "java"
:mainClass main-class
:projectName project-name
:noDebug no-debug?))))
(defun lsp-java-lens-backend (_modified? callback)
(when (lsp--find-workspaces-for "workspace/executeCommand")
(lsp-request-async
"workspace/executeCommand"
(list :command "vscode.java.resolveMainMethod"
:arguments (vector (lsp--buffer-uri)))
(lambda (result)
(funcall callback
(append
(-map
(lambda (lens)
(-doto lens
(ht-set "command" (ht ("title" "Run")
("command" (lambda ()
(interactive)
(lsp-java--start-main-class lens t)))))))
result)
(-map
(lambda (lens)
(-doto (ht-copy lens)
(ht-set "command" (ht ("title" "Debug")
("command" (lambda ()
(interactive)
(lsp-java--start-main-class lens nil)))))))
result))
lsp--cur-version))
:mode 'tick)))
;;;###autoload(with-eval-after-load 'lsp-mode (require 'lsp-java))
(provide 'lsp-java)
;;; lsp-java.el ends here
;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; End:
;;; lsp-jt.el --- Java test support -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Ivan Yonchovski
;; Version: 2.0
;; Author: Ivan Yonchovski <yyoncho@gmail.com>
;; Package-Requires: ((emacs "25.1") (lsp-mode "6.0"))
;; Keywords: language, tools
;; URL: https://github.com/emacs-lsp/lsp-java
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Emacs frontend of https://github.com/Microsoft/vscode-java-test
;;; Code:
(require 'cl-lib)
(require 'lsp-mode)
(require 'lsp-java)
(require 'treemacs)
(declare-function dap-debug "ext:dap-mode")
(defvar lsp-jt--last-result nil)
(defvar lsp-jt--state (ht))
(defvar lsp-jt--last-run-state (ht))
(defcustom lsp-jt-theme "Default"
"The `lsp-jt' theme."
:type 'string
:group 'lsp-java)
(defcustom lsp-jt-root (expand-file-name (locate-user-emacs-file "eclipse.jdt.ls/server/java-test/server"))
"The `lsp-jt' root."
:type 'string
:group 'lsp-java)
(defvar lsp-jt-browser-position-params
`((side . ,treemacs-position)
(slot . 4)
(window-width . ,treemacs-width)))
(defvar lsp-jt-report-position-params
`((side . right)
(slot . 5)
(window-width . ,treemacs-width)))
(defun lsp-jt--process-test-lens (lens)
(-let [(test-data &as &hash "location" (&hash "range") "children") lens]
(cons (-doto test-data
(ht-set "range" range))
(-mapcat #'lsp-jt--process-test-lens children))))
(defface lsp-jt-error-face
'((t :height 1.0 :inherit error))
"The face used for code lens overlays."
:group 'lsp-faces)
(defface lsp-jt-success-face
'((t :height 1.0 :inherit success))
"The face used for code lens overlays."
:group 'lsp-faces)
(defface lsp-jt-in-progress-face
'((t :height 1.0 :inherit warn))
"The face used for code lens overlays."
:group 'lsp-faces)
(defvar-local lsp-jt--last-callback nil)
(defun lsp-jt-lens-backend (_modified? callback)
(setq-local lsp-jt--last-callback callback)
(lsp-request-async
"workspace/executeCommand"
(list :command "vscode.java.test.search.codelens"
:arguments (vector (lsp--buffer-uri)))
(lambda (result)
(let* ((lenses (-mapcat #'lsp-jt--process-test-lens result))
(all-lenses (append
(-map
(lambda (lens)
(-doto lens
(ht-set "command" (ht ("title" "Debug test")
("command" (lambda ()
(interactive)
(lsp-jt--start-test lens nil)))))))
lenses)
(-map
(lambda (lens)
(-doto (ht-copy lens)
(ht-set "command" (ht ("title" "Run test")
("command" (lambda ()
(interactive)
(lsp-jt--start-test lens t)))))))
lenses)
(-keep
(-lambda ((lens &as &hash "fullName" full-name))
(when-let (lens-properties (lsp-jt--status full-name))
(-let [(title . face) lens-properties]
(-doto (ht-copy lens)
(ht-set "command" (ht ("title" title)
("face" face)
("command" #'lsp-jt-show-report)))))))
lenses))))
(funcall callback all-lenses lsp--cur-version)))
:mode 'detached))
;;;###autoload
(define-minor-mode lsp-jt-lens-mode
"Toggle code-lens overlays."
:group 'lsp-jt
:global nil
:init-value nil
:lighter nil
(cond
(lsp-jt-lens-mode
(setq-local lsp-lens-backends (cl-pushnew 'lsp-jt-lens-backend lsp-lens-backends))
(lsp-lens-refresh t))
(t (setq-local lsp-lens-backends (delete 'lsp-jt-lens-backend lsp-lens-backends)))))
(defun lsp-jt-search (root level full-name)
(lsp-java-with-jdtls
(lsp-send-execute-command
"vscode.java.test.search.items"
(vector (lsp--json-serialize `(:uri ,root
:level ,level
,@(when full-name (list :fullName full-name))))))))
(defun lsp-jt-goto (&rest _)
"Goto the symbol at point."
(interactive)
(-if-let ((&hash? "location" (&hash? "uri" "range" (&hash? "start"))) (-some-> (treemacs-node-at-point)
(button-get :item)))
(progn
(select-window (get-mru-window (selected-frame) nil :not-selected))
(find-file (lsp--uri-to-path uri))
(when start
(goto-char (lsp--position-to-point start))))
(user-error "No test under point.")))
(treemacs-define-expandable-node java-tests
:icon-open-form (lsp-jt--icon (-some-> (treemacs-node-at-point)
(treemacs-button-get :item))
t)
:icon-closed-form (lsp-jt--icon (-some-> (treemacs-node-at-point)
(treemacs-button-get :item))
nil)
:query-function (lsp-jt-search (treemacs-button-get node :key)
(or (treemacs-button-get node :level)
1)
(treemacs-button-get node :full-name))
:ret-action 'lsp-jt-goto
:render-action
(treemacs-render-node
:icon (lsp-jt--icon item nil)
:label-form (gethash "displayName" item)
:state treemacs-java-tests-closed-state
:key-form (->> item
(gethash "location")
(gethash "uri"))
:more-properties (:level (1+ (or (treemacs-button-get node :level)
1))
:full-name (gethash "fullName" item)
:item item)))
(defun lsp-jt--roots ()
(-uniq (gethash 'jdtls (lsp-session-server-id->folders (lsp-session)))))
(treemacs-modify-theme "Default"
:icon-directory (f-join (f-dirname (or load-file-name buffer-file-name)) "icons/vscode")
:config
(progn
(treemacs-create-icon :file "class.png" :extensions (java-test-class) :fallback "-")
(treemacs-create-icon :file "debug.png" :extensions (java-test-debug) :fallback "-")
(treemacs-create-icon :file "method.png" :extensions (java-test-method) :fallback "-")
(treemacs-create-icon :file "package.png" :extensions (java-test-package) :fallback "-")
(treemacs-create-icon :file "placeholder.png" :extensions (java-test-placeholder) :fallback "-")
(treemacs-create-icon :file "refresh.png" :extensions (java-test-refresh) :fallback "-")
(treemacs-create-icon :file "run.png" :extensions (java-test-run) :fallback "-")))
(defun lsp-jt-right-click (event)
(interactive "e")
(let* ((ec (event-start event))
(p1 (posn-point ec))
(w1 (posn-window ec)))
(select-window w1)
(goto-char p1)
(hl-line-highlight)
(run-with-idle-timer
0.001 nil
(lambda ()
(cl-labels ((check (value) (not (null value))))
(let* ((menu
(easy-menu-create-menu
nil
`(["Run Test" lsp-jt-run]
["Debug Test" lsp-jt-debug]
["Refresh" lsp-jt-refresh])))
(choice (x-popup-menu event menu)))
(when choice (call-interactively (lookup-key menu (apply 'vector choice))))
(hl-line-highlight)))))))
(defun lsp-jt--wrap-icon (icon open? has-children?)
(concat
(cond
((and open? has-children?) " ▾ ")
(has-children? " ▸ ")
(t " "))
icon))
(defun lsp-jt--icon (item open?)
(lsp-jt--wrap-icon
(if item
(cl-case (gethash "level" item)
(1 (treemacs-get-icon-value 'java-test-package nil lsp-jt-theme))
(2 (treemacs-get-icon-value 'java-test-package nil lsp-jt-theme))
(3 (treemacs-get-icon-value 'java-test-class nil lsp-jt-theme))
(4 (treemacs-get-icon-value 'java-test-method nil lsp-jt-theme)))
(treemacs-get-icon-value 'root nil lsp-jt-theme))
open?
(or (not item)
(not (eq (gethash "level" item) 4)))))
(defvar lsp-jt-mode-map
(-doto (make-sparse-keymap)
(define-key (kbd "x") #'lsp-jt-run)
(define-key (kbd "d") #'lsp-jt-debug)
(define-key (kbd "R") #'lsp-jt-refresh)
(define-key [mouse-1] #'treemacs-TAB-action)
(define-key [mouse-3] #'lsp-jt-right-click)
(define-key [double-mouse-1] #'treemacs-RET-action))
"Keymap for `lsp-jt-mode'.")
(define-minor-mode lsp-jt-mode "Java Test Mode"
nil nil lsp-jt-mode-map)
(treemacs-define-variadic-node java-tests-list
:query-function (lsp-jt--roots)
:render-action
(treemacs-render-node
:icon
(lsp-jt--icon (-some-> (treemacs-node-at-point)
(treemacs-button-get :item))
nil)
:label-form (f-filename item)
:state treemacs-java-tests-closed-state
:key-form (lsp--path-to-uri item))
:root-key-form 'LSP-Java-Tests)
(defun lsp-jt--start-from-browser (no-debug)
(if-let ((node (treemacs-node-at-point)))
(lsp-jt--start-test (or (treemacs-button-get node :item)
(ht ("project" (treemacs-button-get node :key))
("level" 1)
("location" (ht ("uri" (treemacs-button-get node :key))))))
no-debug)
(user-error "No test under point")))
(defun lsp-jt-run ()
"Run test under point."
(interactive)
(lsp-jt--start-from-browser nil))
(defun lsp-jt-debug ()
(interactive)
(lsp-jt--start-from-browser t))
(defun lsp-jt-refresh ()
(interactive)
(condition-case _err
(let ((inhibit-read-only t))
(with-current-buffer "*Java Tests*"
(treemacs-update-node '(:custom LSP-Java-Tests) t)))
(error)))
(defun lsp-jt--update-test-content (test-data test-state)
(-let [(&alist 'name state 'attributes (&alist 'name test-name)) test-data]
(when (and (-contains? '("testFailed"
"testFinished"
"testStarted"
"suiteTreeNode")
state)
(not (and (string= "testFinished" state)
(string= (gethash test-name test-state)
"testFailed"))))
(when (string= "suiteTreeNode" state)
(setq test-name (concat (->> lsp-jt--last-result
(-keep (-lambda ((&alist 'name 'attributes (&alist 'name test-name)))
(when (string= name "suiteTreeStarted")
test-name)))
(cl-first))
"#"
test-name)))
(puthash test-name state test-state))
(when (string= "testSuiteFinished" state)
(when (string= "suiteTreeNode" state)
(setq test-name (concat (->> lsp-jt--last-result
(-keep (-lambda ((&alist 'name 'attributes (&alist 'name test-name)))
(when (string= name "suiteTreeStarted")
test-name)))
(cl-first))
"#"
test-name)))
(puthash test-name state test-state))))
(defun lsp-jt--filter-function (line)
(let ((json (cl-second (s-match "@@<TestRunner-\\(.*\\)-TestRunner>" line))))
(cond
(json (-let [(test-data &as &alist 'name) (json-read-from-string json)]
(when (string= name "testReporterAttached")
(setq lsp-jt--last-result nil)
(setq lsp-jt--last-run-state (ht)))
(push test-data lsp-jt--last-result)
(lsp-jt--update-test-content test-data lsp-jt--state)
(lsp-jt--update-test-content test-data lsp-jt--last-run-state)
(lsp-jt--schedule-refresh-lens)
(lsp-jt--update-report)
nil))
((s-equals? "\n" line) nil)
(t line))))
(defvar lsp-jt--refresh-lens-timer nil)
(defun lsp-jt--do-refresh-lenses ()
(->>
(lsp-find-workspace 'jdtls nil)
(lsp--workspace-buffers)
(-map (lambda (buffer)
(with-current-buffer buffer
(when (and lsp-jt-lens-mode lsp-jt--last-callback)
(lsp-jt-lens-backend nil lsp-jt--last-callback)))))))
(defun lsp-jt--schedule-refresh-lens ()
(when lsp-jt--refresh-lens-timer
(cancel-timer lsp-jt--refresh-lens-timer))
(setq lsp-jt--refresh-lens-timer
(run-at-time 0.2 nil #'lsp-jt--do-refresh-lenses)))
(defconst lsp-jt-kind-root 0)
(defconst lsp-jt-kind-folder 1)
(defconst lsp-jt-kind-package 2)
(defconst lsp-jt-kind-class 3)
(defconst lsp-jt-kind-method 4)
(defun lsp-jt--get-tests (test)
(-let [(&hash "level" "location" (&hash? "uri") "fullName") test]
(cond
((or (eq level lsp-jt-kind-method)
(eq level lsp-jt-kind-class))
(gethash "fullName" test))
(t
(s-join " " (-map #'lsp-jt--get-tests (lsp-jt-search uri level fullName)))))))
(defun lsp-jt--start-test (test no-debug)
(with-lsp-workspace (lsp-find-workspace 'jdtls nil)
(require 'dap-java)
(dap-debug
`(
:type "java"
:name ,(format "Running %s" (gethash "displayName" test))
:mainClass "com.microsoft.java.test.runner.Launcher"
:projectName ,(gethash "project" test)
:output-filter-function lsp-jt--filter-function
:args ,(format "%s %s"
"junit"
(lsp-jt--get-tests test))
:cwd ,(->> test
(gethash "location")
(gethash "uri")
(lsp--uri-to-path)
(lsp-workspace-root))
:classPaths ,(apply #'vector
(cl-list*
(f-join lsp-jt-root "com.microsoft.java.test.runner.jar")
(f-join lsp-jt-root "/lib/")
(lsp-send-execute-command "vscode.java.test.runtime.classpath"
(->> test
(gethash "location")
(gethash "uri")
(lsp--uri-to-path)
(vector)
(vector)))))
,@(when no-debug `(:noDebug t))))))
;;;###autoload
(defun lsp-jt-browser ()
(interactive)
(if-let ((buf (get-buffer "*Java Tests*")))
(select-window (display-buffer-in-side-window buf lsp-jt-browser-position-params))
(let* ((buf (get-buffer-create "*Java Tests*"))
(window (display-buffer-in-side-window buf lsp-jt-browser-position-params)))
(select-window window)
(set-window-dedicated-p window t)
(treemacs-initialize)
(treemacs-JAVA-TESTS-LIST-extension)
(lsp-jt-mode)
(setq-local header-line-format "TEST EXPLORER: "))))
(defun lsp-jt--test-kind (path)
(if (s-contains? "#" path)
'java-test-method
'java-test-class))
(defun lsp-jt--duration (test)
(->> lsp-jt--last-result
(-keep (-lambda ((&alist 'name 'attributes (&alist 'duration 'name test-name)))
(when (and (or (string= name "testFinished")
(string= name "testFailed"))
(string= test-name test))
duration)))
cl-first))
(defun lsp-jt--trace (test)
(->> lsp-jt--last-result
(-keep (-lambda ((&alist 'name 'attributes (&alist 'trace 'name test-name)))
(when (and (string= name "testFailed")
(string= test-name test))
trace)))
cl-first))
(defun lsp-jt-report-open (&rest _rest)
(interactive)
(when-let (test (-some-> (treemacs-node-at-point)
(treemacs-button-get :key)))
(let ((buf (get-buffer-create "*Test Stack*")))
(let ((inhibit-read-only t))
(with-current-buffer buf
(erase-buffer)
(insert (lsp-jt--trace test))
(view-mode t)
(select-window (get-mru-window (selected-frame) nil :not-selected))
(switch-to-buffer buf))))))
(defun lsp-jt--status (test-name &optional state)
(setq state (or state lsp-jt--state))
(if (s-contains? "#" test-name)
(pcase (gethash test-name state)
("testFailed"
(cons "❌" 'lsp-jt-error-face))
("testFinished"
(cons "✔" 'lsp-jt-success-face))
("testStarted"
(cons "⌛" 'lsp-jt-in-progress-face))
("suiteTreeNode"
(cons "⌚" 'lsp-jt-in-progress-face))
(_
(cons "?" 'lsp-jt-in-progress-face)))
(let ((inner-test-status (-keep (-lambda ((method-name . test-status))
(when (s-starts-with?
(concat test-name "#")
method-name)
test-status))
(ht->alist state))))
(cond
((not inner-test-status) nil)
((-contains? inner-test-status "testFailed") (cons "❌" 'lsp-jt-error-face))
((-contains? inner-test-status "testStarted") (cons "⌛" 'lsp-jt-in-progress-face))
((-contains? inner-test-status "suiteTreeNode") (cons "⌚" 'lsp-jt-in-progress-face))
((-contains? inner-test-status "testFinished") (cons "✔" 'lsp-jt-success-face))))))
(treemacs-define-expandable-node java-test-report-node
:icon-open-form
(let ((kind (lsp-jt--test-kind
(treemacs-button-get node :key))))
(lsp-jt--wrap-icon
(treemacs-get-icon-value kind
nil
lsp-jt-theme)
t
(eq kind 'java-test-class)))
:ret-action 'lsp-jt-report-open
:icon-closed-form
(let ((kind (lsp-jt--test-kind
(treemacs-button-get node :key))))
(lsp-jt--wrap-icon
(treemacs-get-icon-value kind
nil
lsp-jt-theme)
nil
(eq kind 'java-test-class)))
:query-function
(let ((item (treemacs-button-get node :key)))
(->> lsp-jt--last-result
(reverse)
(-drop-while (-lambda ((&alist 'name 'attributes (&alist 'name node-name)))
(not (and (string= name "suiteTreeStarted")
(string= node-name item)))))
(cl-rest)
(-take-while (-lambda ((&alist 'name))
(string= name "suiteTreeNode")))
(-map (-lambda ((&alist 'attributes (&alist 'name node-name)))
node-name))))
:render-action
(treemacs-render-node
:icon (lsp-jt--wrap-icon
(treemacs-get-icon-value 'java-test-method
nil
lsp-jt-theme)
nil
nil)
:label-form (-let* ((test (concat (treemacs-button-get (treemacs-node-at-point) :key) "#" item))
((content . face) (lsp-jt--status test lsp-jt--last-run-state)))
(concat (propertize item 'face 'default)
(propertize " " 'face 'default)
(propertize content 'face face)
(condition-case err
(when-let (duration (lsp-jt--duration test))
(propertize (concat " " duration " ms")
'face 'default))
(error (message (error-message-string err))))))
:state treemacs-java-test-report-node-closed-state
:key-form (concat (treemacs-button-get (treemacs-node-at-point) :key) "#" item)))
(treemacs-define-variadic-node java-tests-report
:query-function (-keep (-lambda ((&alist 'name 'attributes (&alist 'name node-name)))
(when (string= name "suiteTreeStarted")
node-name))
(reverse lsp-jt--last-result))
:render-action
(treemacs-render-node
:icon (lsp-jt--wrap-icon
(treemacs-get-icon-value 'java-test-class nil lsp-jt-theme)
t
nil)
:label-form (-let [(content . face) (lsp-jt--status item lsp-jt--last-run-state)]
(concat (propertize item 'face 'default)
(propertize " " 'face 'default)
(propertize content 'face face)))
:state treemacs-java-test-report-node-closed-state
:key-form item)
:root-key-form 'LSP-Java-Test-Report)
(defun lsp-jt--expand-recursively (root)
(-map
(lambda (btn)
(unless (treemacs-is-node-expanded? btn)
(save-excursion
(goto-char (marker-position btn))
(funcall (alist-get (treemacs-button-get btn :state) treemacs-TAB-actions-config))))
(lsp-jt--expand-recursively btn))
(treemacs-collect-child-nodes root)))
(defun lsp-jt--expand (root-key)
(-when-let (root (treemacs-dom-node->position (treemacs-find-in-dom root-key)))
(treemacs-save-position
(lsp-jt--expand-recursively root))))
(defun lsp-jt--update-report-modeline ()
(setq-local mode-line-format
(or (->> lsp-jt--last-result
(-keep (-lambda ((&alist 'name 'attributes (&alist 'message)))
(when (string= "testSummary" name)
message)))
cl-first)
(->> lsp-jt--last-result
(-keep (-lambda ((&alist 'name 'attributes (&alist 'message)))
(when (string= "testSummary" name)
message)))
cl-first)
"Running...")))
(defun lsp-jt--update-report ()
(when (buffer-live-p (get-buffer "*Java Tests Results*"))
(condition-case _err
(let ((inhibit-read-only t))
(with-current-buffer "*Java Tests Results*"
;; (lsp-jt--update-report-modeline)
(treemacs-update-node '(:custom LSP-Java-Test-Report) t)
(lsp-jt--expand '(:custom LSP-Java-Test-Report))))
(error))))
;;;###autoload
(defun lsp-jt-show-report ()
(interactive)
(let* ((buf (get-buffer-create "*Java Tests Results*"))
(window (display-buffer-in-side-window buf lsp-jt-report-position-params)))
(select-window window)
(set-window-dedicated-p window t)
(treemacs-initialize)
(treemacs-JAVA-TESTS-REPORT-extension)
(setq-local header-line-format "TEST RESULTS: ")
(lsp-jt--update-report-modeline)
(lsp-jt--expand '(:custom LSP-Java-Test-Report))))
(provide 'lsp-jt)
;;; lsp-jt.el ends here
;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; End:
site_name: LSP Java
site_url: https://emacs-lsp.github.io/lsp-java
nav:
- Home: README.md
- LSP Mode:
- LSP Mode: https://emacs-lsp.github.io/lsp-mode
extra_css:
- stylesheets/extra.css
theme:
name: material
logo: images/logo.png
favicon: images/logo.png
icon:
repo: fontawesome/brands/github
features:
- tabs
extra:
social:
- icon: fontawesome/brands/github-alt
link: https://github.com/emacs-lsp
- icon: fontawesome/brands/twitter
link: https://twitter.com/yonchovski
- icon: fontawesome/brands/gitter
link: https://gitter.im/emacs-lsp/lsp-mode
repo_name: emacs-lsp/lsp-java
repo_url: https://github.com/emacs-lsp/lsp-java
markdown_extensions:
- pymdownx.superfences
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- codehilite
- toc:
permalink: '#'
plugins:
- search
- awesome-pages
- git-revision-date-localized
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment