diff --git a/app/src/main/java/org/jd/gui/OsxApp.java b/app/src/main/java/org/jd/gui/OsxApp.java index b8ac598b..886faf69 100644 --- a/app/src/main/java/org/jd/gui/OsxApp.java +++ b/app/src/main/java/org/jd/gui/OsxApp.java @@ -8,20 +8,30 @@ package org.jd.gui; import com.apple.eawt.Application; +import org.jd.gui.util.JavaUtil; + +import java.awt.*; public class OsxApp extends App { - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "Since15"}) public static void main(String[] args) { - // Create an instance of the mac OSX Application class - Application application = Application.getApplication(); - - App.main(args); + if (JavaUtil.runtimeVersion() <= 8) { + // This method has been deprecated + // https://bugs.openjdk.org/browse/JDK-8160437 + // Create an instance of the mac OSX Application class + Application application = Application.getApplication(); - // Add an handle invoked when the application is asked to open a list of files - application.setOpenFileHandler(e -> controller.openFiles(e.getFiles())); + // Add an handle invoked when the application is asked to open a list of files + application.setOpenFileHandler(e -> controller.openFiles(e.getFiles())); - // Add an handle invoked when the application is asked to quit - application.setQuitHandler((e, r) -> System.exit(0)); + // Add an handle invoked when the application is asked to quit + application.setQuitHandler((e, r) -> System.exit(0)); + } else { + Desktop desktop = Desktop.getDesktop(); + desktop.setOpenFileHandler(e -> controller.openFiles(e.getFiles())); + desktop.setQuitHandler((e, r) -> System.exit(0)); + } + App.main(args); } } diff --git a/app/src/main/java/org/jd/gui/util/JavaUtil.java b/app/src/main/java/org/jd/gui/util/JavaUtil.java new file mode 100644 index 00000000..2c174873 --- /dev/null +++ b/app/src/main/java/org/jd/gui/util/JavaUtil.java @@ -0,0 +1,20 @@ +package org.jd.gui.util; + +public class JavaUtil { + /** + * Retrieves the "major" Java version + * 1.8.0_211 == 8, 9.0.1 = 9 + * From a post in + * https://stackoverflow.com/questions/2591083/getting-java-version-at-runtime + * @return an integer representing the major Java version of the runtime. + */ + public static int runtimeVersion() { + String version = System.getProperty("java.version"); + if(version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if(dot != -1) { version = version.substring(0, dot); } + } return Integer.parseInt(version); + } +} diff --git a/build.gradle b/build.gradle index 51633402..4cd16fe6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,13 @@ buildscript { repositories { - jcenter() + mavenCentral() + maven { + url = "https://plugins.gradle.org/m2/" + } } dependencies { classpath 'com.netflix.nebula:gradle-ospackage-plugin:5.3.0' // RPM & DEB support - classpath 'edu.sc.seis.gradle:launch4j:2.4.4' + classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:2.4.5' classpath 'net.sf.proguard:proguard-gradle:6.1.0' } } @@ -15,7 +18,7 @@ apply plugin: 'edu.sc.seis.launch4j' apply plugin: 'nebula.ospackage' // Common configuration // -rootProject.version='1.6.6' +rootProject.version='1.6.7-rc1' rootProject.ext.set('jdCoreVersion', '1.1.3') targetCompatibility = '1.8' @@ -31,7 +34,7 @@ allprojects { } repositories { - jcenter() + mavenCentral() } configurations { diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 00000000..8808e318 --- /dev/null +++ b/core/.gitignore @@ -0,0 +1,36 @@ +# Java +*.class + +# JD +debug* + +# Idea +.idea/ +out/ +*.ipr +*.iml +*.iws + +# Eclipse +.settings/ +classes/ +.classpath +.project + +# Mac +.DS_Store + +# Windows +Thumbs.db + +# Maven +log/ +target/ + +# Gradle +.gradle/ +build/ +!gradle/wrapper/* + +# WinMerge +*.bak diff --git a/core/LICENSE b/core/LICENSE new file mode 100644 index 00000000..eadd3930 --- /dev/null +++ b/core/LICENSE @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + JD-Core, a JAVA decompiler + Copyright (C) 2008-2019 Emmanuel Dupuy + + 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 . + +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: + + JD-Core Copyright (C) 2008-2019 Emmanuel Dupuy + 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 +. + + 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 +. diff --git a/core/NOTICE b/core/NOTICE new file mode 100644 index 00000000..fdffbb62 --- /dev/null +++ b/core/NOTICE @@ -0,0 +1 @@ +JD-Core license - GPLv3 diff --git a/core/README.md b/core/README.md new file mode 100644 index 00000000..f5cc3a95 --- /dev/null +++ b/core/README.md @@ -0,0 +1,114 @@ +# JD-Core + +JD-Core is a JAVA decompiler written in JAVA. + +- Java Decompiler project home page: +[http://java-decompiler.github.io](https://java-decompiler.github.io) +- JD-Core source code: +[https://github.com/java-decompiler/jd-core](https://github.com/java-decompiler/jd-core) +- JCenter Maven repository: +[https://jcenter.bintray.com/](https://bintray.com/java-decompiler/maven/org.jd%3Ajd-core/_latestVersion) + +## Description +JD-Core is a standalone JAVA library containing the JAVA decompiler of +"Java Decompiler project". It support Java 1.1.8 to Java 12.0, +including Lambda expressions, method references and default methods. +JD-Core is the engine of JD-GUI. + +## How to build JD-Core ? +``` +> git clone https://github.com/java-decompiler/jd-core.git +> cd jd-core +> ./gradlew build +``` +generate _"build/libs/jd-core-x.y.z.jar"_ + +## How to use JD-Core ? + +1. Implement the +_[org.jd.core.loader.Loader](https://github.com/java-decompiler/jd-core/blob/master/src/main/java/org/jd/core/v1/api/loader/Loader.java)_ +interface, +2. Implement the +_[org.jd.core.printer.Printer](https://github.com/java-decompiler/jd-core/blob/master/src/main/java/org/jd/core/v1/api/printer/Printer.java)_ +interface, +3. And call the method _"decompile(loader, printer, internalTypeName);"_ + +## Example + +1. Implement the _Loader_ interface: +```java +Loader loader = new Loader() { + @Override + public byte[] load(String internalName) throws LoaderException { + InputStream is = this.getClass().getResourceAsStream("/" + internalName + ".class"); + + if (is == null) { + return null; + } else { + try (InputStream in=is; ByteArrayOutputStream out=new ByteArrayOutputStream()) { + byte[] buffer = new byte[1024]; + int read = in.read(buffer); + + while (read > 0) { + out.write(buffer, 0, read); + read = in.read(buffer); + } + + return out.toByteArray(); + } catch (IOException e) { + throw new LoaderException(e); + } + } + } + + @Override + public boolean canLoad(String internalName) { + return this.getClass().getResource("/" + internalName + ".class") != null; + } +}; +``` + +2. Implement the _Printer_ interface +```java +Printer printer = new Printer() { + protected static final String TAB = " "; + protected static final String NEWLINE = "\n"; + + protected int indentationCount = 0; + protected StringBuilder sb = new StringBuilder(); + + @Override public String toString() { return sb.toString(); } + + @Override public void start(int maxLineNumber, int majorVersion, int minorVersion) {} + @Override public void end() {} + + @Override public void printText(String text) { sb.append(text); } + @Override public void printNumericConstant(String constant) { sb.append(constant); } + @Override public void printStringConstant(String constant, String ownerInternalName) { sb.append(constant); } + @Override public void printKeyword(String keyword) { sb.append(keyword); } + @Override public void printDeclaration(int type, String internalTypeName, String name, String descriptor) { sb.append(name); } + @Override public void printReference(int type, String internalTypeName, String name, String descriptor, String ownerInternalName) { sb.append(name); } + + @Override public void indent() { this.indentationCount++; } + @Override public void unindent() { this.indentationCount--; } + + @Override public void startLine(int lineNumber) { for (int i=0; i 0) sb.append(NEWLINE); } + + @Override public void startMarker(int type) {} + @Override public void endMarker(int type) {} +}; +``` + +3. And call the method _"decompile(loader, printer, internalTypeName);"_ +```java +ClassFileToJavaSourceDecompiler decompiler = new ClassFileToJavaSourceDecompiler(); + +decompiler.decompile(loader, printer, "path/to/YourClass"); + +String source = printer.toString(); +``` + +## License +Released under the [GNU GPL v3](LICENSE). diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 00000000..a7bf191e --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,75 @@ +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'maven-publish' + +dependencies { + testCompile 'commons-codec:commons-codec:1.13' + testCompile 'org.apache.commons:commons-collections4:4.1' + testCompile 'org.apache.commons:commons-imaging:1.0-alpha1' + testCompile 'org.apache.commons:commons-lang3:3.9' + testCompile 'com.jakewharton:disklrucache:2.0.2' + testCompile 'com.squareup:javapoet:1.11.1' + testCompile 'com.squareup:javawriter:2.5.1' + testCompile 'joda-time:joda-time:2.10.5' + testCompile 'org.joda:joda-convert:2.2.1' + testCompile 'org.jsoup:jsoup:1.12.1' + testCompile 'junit:junit:4.12' + testCompile 'javax.jms:javax.jms-api:2.0.1' + testCompile 'javax.mail:javax.mail-api:1.6.2' + testCompile 'com.squareup.mimecraft:mimecraft:1.1.1' + testCompile 'org.scribe:scribe:1.3.7' + testCompile 'com.sparkjava:spark-core:2.9.1' + testCompile 'log4j:log4j:1.2.17' + testCompile 'com.google.guava:guava:12.0' +} + +version='1.1.4' + +tasks.withType(JavaCompile) { + sourceCompatibility = targetCompatibility = '1.8' + options.compilerArgs << '-Xlint:deprecation' + options.compilerArgs << '-Xlint:unchecked' + options.encoding = 'UTF-8' +} + +buildscript { + repositories { + mavenCentral() + } +} + +repositories { + mavenCentral() +} + +jar { + manifest { + attributes 'JD-Core-Version': version + } +} + +// Publication to JCenter Maven repository +task sourceJar(type: Jar) { + classifier 'sources' + from sourceSets.main.allJava +} + +publishing { + publications { + publicationJdCore(MavenPublication) { + groupId 'org.jd' + artifactId 'jd-core' + version project.version + from components.java + artifact tasks.sourceJar + } + } +} + +// 'cleanIdea' task extension // +cleanIdea.doFirst { + delete project.name + '.iws' + delete 'out' + followSymlinks = true +} diff --git a/core/src/main/java/org/jd/core/v1/ClassFileToJavaSourceDecompiler.java b/core/src/main/java/org/jd/core/v1/ClassFileToJavaSourceDecompiler.java new file mode 100644 index 00000000..be378347 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/ClassFileToJavaSourceDecompiler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1; + +import org.jd.core.v1.api.Decompiler; +import org.jd.core.v1.api.loader.Loader; +import org.jd.core.v1.api.printer.Printer; +import org.jd.core.v1.model.message.Message; +import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor; +import org.jd.core.v1.service.deserializer.classfile.DeserializeClassFileProcessor; +import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.JavaSyntaxToJavaFragmentProcessor; +import org.jd.core.v1.service.layouter.LayoutFragmentProcessor; +import org.jd.core.v1.service.tokenizer.javafragmenttotoken.JavaFragmentToTokenProcessor; +import org.jd.core.v1.service.writer.WriteTokenProcessor; + +import java.util.Map; + +public class ClassFileToJavaSourceDecompiler implements Decompiler { + protected DeserializeClassFileProcessor deserializer = new DeserializeClassFileProcessor(); + protected ClassFileToJavaSyntaxProcessor converter = new ClassFileToJavaSyntaxProcessor(); + protected JavaSyntaxToJavaFragmentProcessor fragmenter = new JavaSyntaxToJavaFragmentProcessor(); + protected LayoutFragmentProcessor layouter = new LayoutFragmentProcessor(); + protected JavaFragmentToTokenProcessor tokenizer = new JavaFragmentToTokenProcessor(); + protected WriteTokenProcessor writer = new WriteTokenProcessor(); + + public void decompile(Loader loader, Printer printer, String internalName) throws Exception { + Message message = new Message(); + + message.setHeader("mainInternalTypeName", internalName); + message.setHeader("loader", loader); + message.setHeader("printer", printer); + + decompile(message); + } + + public void decompile(Loader loader, Printer printer, String internalName, Map configuration) throws Exception { + Message message = new Message(); + + message.setHeader("mainInternalTypeName", internalName); + message.setHeader("configuration", configuration); + message.setHeader("loader", loader); + message.setHeader("printer", printer); + + decompile(message); + } + + protected void decompile(Message message) throws Exception { + this.deserializer.process(message); + this.converter.process(message); + this.fragmenter.process(message); + this.layouter.process(message); + this.tokenizer.process(message); + this.writer.process(message); + } +} diff --git a/core/src/main/java/org/jd/core/v1/api/Decompiler.java b/core/src/main/java/org/jd/core/v1/api/Decompiler.java new file mode 100644 index 00000000..98fa3a40 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/api/Decompiler.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.api; + +import org.jd.core.v1.api.loader.Loader; +import org.jd.core.v1.api.printer.Printer; + +import java.util.Map; + +public interface Decompiler { + void decompile(Loader loader, Printer printer, String internalName) throws Exception; + + void decompile(Loader loader, Printer printer, String internalName, Map configuration) throws Exception; +} diff --git a/core/src/main/java/org/jd/core/v1/api/loader/Loader.java b/core/src/main/java/org/jd/core/v1/api/loader/Loader.java new file mode 100644 index 00000000..d2b97dbe --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/api/loader/Loader.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.api.loader; + +public interface Loader { + boolean canLoad(String internalName); + + byte[] load(String internalName) throws LoaderException; +} diff --git a/core/src/main/java/org/jd/core/v1/api/loader/LoaderException.java b/core/src/main/java/org/jd/core/v1/api/loader/LoaderException.java new file mode 100644 index 00000000..58ab8fc4 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/api/loader/LoaderException.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.api.loader; + + +public class LoaderException extends Exception { + private static final long serialVersionUID = 9506606333927794L; + public LoaderException() {} + + public LoaderException(String msg) { super(msg); } + + public LoaderException(Throwable cause) { super(cause); } +} diff --git a/core/src/main/java/org/jd/core/v1/api/printer/Printer.java b/core/src/main/java/org/jd/core/v1/api/printer/Printer.java new file mode 100644 index 00000000..4f30d48a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/api/printer/Printer.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.api.printer; + + +public interface Printer { + void start(int maxLineNumber, int majorVersion, int minorVersion); + void end(); + + void printText(String text); + void printNumericConstant(String constant); + void printStringConstant(String constant, String ownerInternalName); + void printKeyword(String keyword); + + // Declaration & reference types + int TYPE = 1; + int FIELD = 2; + int METHOD = 3; + int CONSTRUCTOR = 4; + int PACKAGE = 5; + int MODULE = 6; + + void printDeclaration(int type, String internalTypeName, String name, String descriptor); + void printReference(int type, String internalTypeName, String name, String descriptor, String ownerInternalName); + + void indent(); + void unindent(); + + int UNKNOWN_LINE_NUMBER = 0; + + void startLine(int lineNumber); + void endLine(); + void extraLine(int count); + + // Marker types + int COMMENT = 1; + int JAVADOC = 2; + int ERROR = 3; + int IMPORT_STATEMENTS = 4; + + void startMarker(int type); + void endMarker(int type); +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/ClassFile.java b/core/src/main/java/org/jd/core/v1/model/classfile/ClassFile.java new file mode 100644 index 00000000..601ebdf4 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/ClassFile.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile; + + +import org.jd.core.v1.model.classfile.attribute.Attribute; + +import java.util.List; +import java.util.Map; + +import static org.jd.core.v1.model.classfile.Constants.*; + +public class ClassFile { + protected int majorVersion; + protected int minorVersion; + protected int accessFlags; + protected String internalTypeName; + protected String superTypeName; + protected String[] interfaceTypeNames; + protected Field[] fields; + protected Method[] methods; + protected Map attributes; + + protected ClassFile outerClassFile; + protected List innerClassFiles; + + public ClassFile(int majorVersion, int minorVersion, int accessFlags, String internalTypeName, String superTypeName, String[] interfaceTypeNames, Field[] fields, Method[] methods, Map attributes) { + this.majorVersion = majorVersion; + this.minorVersion = minorVersion; + this.accessFlags = accessFlags; + this.internalTypeName = internalTypeName; + this.superTypeName = superTypeName; + this.interfaceTypeNames = interfaceTypeNames; + this.fields = fields; + this.methods = methods; + this.attributes = attributes; + } + + public int getMinorVersion() { return minorVersion; } + public int getMajorVersion() { return majorVersion; } + + public int getAccessFlags() { + return accessFlags; + } + public void setAccessFlags(int accessFlags) { + this.accessFlags = accessFlags; + } + + public boolean isEnum() { return (accessFlags & ACC_ENUM) != 0; } + public boolean isAnnotation() { return (accessFlags & ACC_ANNOTATION) != 0; } + public boolean isInterface() { return (accessFlags & ACC_INTERFACE) != 0; } + public boolean isModule() { return (accessFlags & ACC_MODULE) != 0; } + public boolean isStatic() { return (accessFlags & ACC_STATIC) != 0; } + + public String getInternalTypeName() { + return internalTypeName; + } + + public String getSuperTypeName() { + return superTypeName; + } + + public String[] getInterfaceTypeNames() { + return interfaceTypeNames; + } + + public Field[] getFields() { + return fields; + } + + public Method[] getMethods() { + return methods; + } + + @SuppressWarnings("unchecked") + public T getAttribute(String name) { + return (attributes == null) ? null : (T)attributes.get(name); + } + + public ClassFile getOuterClassFile() { + return outerClassFile; + } + + public void setOuterClassFile(ClassFile outerClassFile) { + this.outerClassFile = outerClassFile; + } + + public List getInnerClassFiles() { + return innerClassFiles; + } + + public void setInnerClassFiles(List innerClassFiles) { + this.innerClassFiles = innerClassFiles; + } + + @Override + public String toString() { + return "ClassFile{" + internalTypeName + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/ConstantPool.java b/core/src/main/java/org/jd/core/v1/model/classfile/ConstantPool.java new file mode 100644 index 00000000..326bda79 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/ConstantPool.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile; + + +import org.jd.core.v1.model.classfile.constant.*; + +public class ConstantPool { + protected Constant[] constants; + + public ConstantPool(Constant[] constants) { + this.constants = constants; + } + + @SuppressWarnings("unchecked") + public T getConstant(int index) { + return (T)constants[index]; + } + + public String getConstantTypeName(int index) { + ConstantClass cc = (ConstantClass)constants[index]; + ConstantUtf8 cutf8 = (ConstantUtf8)constants[cc.getNameIndex()]; + return cutf8.getValue(); + } + + public String getConstantString(int index) { + ConstantString cString = (ConstantString)constants[index]; + ConstantUtf8 cutf8 = (ConstantUtf8)constants[cString.getStringIndex()]; + return cutf8.getValue(); + } + + public String getConstantUtf8(int index) { + ConstantUtf8 cutf8 = (ConstantUtf8)constants[index]; + return cutf8.getValue(); + } + + public ConstantValue getConstantValue(int index) { + Constant constant = constants[index]; + + if ((constant != null) && (constant.getTag() == Constant.CONSTANT_String)) { + constant = constants[((ConstantString)constant).getStringIndex()]; + } + + return (ConstantValue)constant; + } + + @Override + public String toString() { + return "ConstantPool"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/Constants.java b/core/src/main/java/org/jd/core/v1/model/classfile/Constants.java new file mode 100644 index 00000000..c9062cd0 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/Constants.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile; + +public interface Constants { + // Access flags for Class, Field, Method, Nested class, Module, Module Requires, Module Exports, Module Opens + int ACC_PUBLIC = 0x0001; // C F M N . . . . + int ACC_PRIVATE = 0x0002; // . F M N . . . . + int ACC_PROTECTED = 0x0004; // . F M N . . . . + int ACC_STATIC = 0x0008; // C F M N . . . . + int ACC_FINAL = 0x0010; // C F M N . . . . + int ACC_SYNCHRONIZED = 0x0020; // . . M . . . . . + int ACC_SUPER = 0x0020; // C . . . . . . . + int ACC_OPEN = 0x0020; // . . . . Mo . . . + int ACC_TRANSITIVE = 0x0020; // . . . . . MR . . + int ACC_VOLATILE = 0x0040; // . F . . . . . . + int ACC_BRIDGE = 0x0040; // . . M . . . . . + int ACC_STATIC_PHASE = 0x0040; // . . . . . MR . . + int ACC_TRANSIENT = 0x0080; // . F . . . . . . + int ACC_VARARGS = 0x0080; // . . M . . . . . + int ACC_NATIVE = 0x0100; // . . M . . . . . + int ACC_INTERFACE = 0x0200; // C . . N . . . . + int ACC_ABSTRACT = 0x0400; // C . M N . . . . + int ACC_STRICT = 0x0800; // . . M . . . . . + int ACC_SYNTHETIC = 0x1000; // C F M N Mo MR ME MO + int ACC_ANNOTATION = 0x2000; // C . . N . . . . + int ACC_ENUM = 0x4000; // C F . N . . . . + int ACC_MODULE = 0x8000; // C . . . . . . . + int ACC_MANDATED = 0x8000; // . . . . Mo MR ME MO +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/Field.java b/core/src/main/java/org/jd/core/v1/model/classfile/Field.java new file mode 100644 index 00000000..0508f41c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/Field.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile; + +import org.jd.core.v1.model.classfile.attribute.Attribute; + +import java.util.Map; + +public class Field { + protected int accessFlags; + protected String name; + protected String descriptor; + protected Map attributes; + + public Field(int accessFlags, String name, String descriptor, Map attributes) { + this.accessFlags = accessFlags; + this.name = name; + this.descriptor = descriptor; + this.attributes = attributes; + } + + public int getAccessFlags() { + return accessFlags; + } + + public String getName() { + return name; + } + + public String getDescriptor() { + return descriptor; + } + + @SuppressWarnings("unchecked") + public T getAttribute(String name) { + return (attributes == null) ? null : (T)attributes.get(name); + } + + @Override + public String toString() { + return "Field{" + name + " " + descriptor + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/Method.java b/core/src/main/java/org/jd/core/v1/model/classfile/Method.java new file mode 100644 index 00000000..1558a157 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/Method.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile; + +import org.jd.core.v1.model.classfile.attribute.Attribute; + +import java.util.Map; + +public class Method { + protected int accessFlags; + protected String name; + protected String descriptor; + protected Map attributes; + protected ConstantPool constants; + + public Method(int accessFlags, String name, String descriptor, Map attributes, ConstantPool constants) { + this.accessFlags = accessFlags; + this.name = name; + this.descriptor = descriptor; + this.attributes = attributes; + this.constants = constants; + } + + /** + * @see Constants + */ + public int getAccessFlags() { + return accessFlags; + } + + public String getName() { + return name; + } + + public String getDescriptor() { + return descriptor; + } + + @SuppressWarnings("unchecked") + public T getAttribute(String name) { + return (attributes == null) ? null : (T)attributes.get(name); + } + + public ConstantPool getConstants() { + return constants; + } + + @Override + public String toString() { + return "Method{" + name + " " + descriptor + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Annotation.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Annotation.java new file mode 100644 index 00000000..ff9c90a5 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Annotation.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class Annotation { + protected String descriptor; + protected ElementValuePair[] elementValuePairs; + + public Annotation(String descriptor, ElementValuePair[] elementValuePairs) { + this.descriptor = descriptor; + this.elementValuePairs = elementValuePairs; + } + + public String getDescriptor() { + return descriptor; + } + + public ElementValuePair[] getElementValuePairs() { + return elementValuePairs; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Annotations.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Annotations.java new file mode 100644 index 00000000..a028c467 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Annotations.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class Annotations implements Attribute { + protected Annotation[] annotations; + + public Annotations(Annotation[] annotations) { + this.annotations = annotations; + } + + public Annotation[] getAnnotations() { + return annotations; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Attribute.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Attribute.java new file mode 100644 index 00000000..e89e6a29 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/Attribute.java @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public interface Attribute {} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeAnnotationDefault.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeAnnotationDefault.java new file mode 100644 index 00000000..a597343d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeAnnotationDefault.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeAnnotationDefault implements Attribute { + protected ElementValue defaultValue; + + public AttributeAnnotationDefault(ElementValue defaultValue) { + this.defaultValue = defaultValue; + } + + public ElementValue getDefaultValue() { + return defaultValue; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeBootstrapMethods.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeBootstrapMethods.java new file mode 100644 index 00000000..5a7603f1 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeBootstrapMethods.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeBootstrapMethods implements Attribute { + protected BootstrapMethod[] bootstrapMethods; + + public AttributeBootstrapMethods(BootstrapMethod[] bootstrapMethods) { + this.bootstrapMethods = bootstrapMethods; + } + + public BootstrapMethod[] getBootstrapMethods() { + return bootstrapMethods; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeCode.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeCode.java new file mode 100644 index 00000000..1e4dee01 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeCode.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +import java.util.Map; + +public class AttributeCode implements Attribute { + protected int maxStack; + protected int maxLocals; + protected byte[] code; + protected CodeException[] exceptionTable; + protected Map attributes; + + public AttributeCode(int maxStack, int maxLocals, byte[] code, CodeException[] exceptionTable, Map attributes) { + this.maxStack = maxStack; + this.maxLocals = maxLocals; + this.code = code; + this.exceptionTable = exceptionTable; + this.attributes = attributes; + } + + public int getMaxStack() { + return maxStack; + } + + public int getMaxLocals() { + return maxLocals; + } + + public byte[] getCode() { + return code; + } + + public CodeException[] getExceptionTable() { + return exceptionTable; + } + + @SuppressWarnings("unchecked") + public T getAttribute(String name) { + return (attributes == null) ? null : (T)attributes.get(name); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeConstantValue.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeConstantValue.java new file mode 100644 index 00000000..6a4ef317 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeConstantValue.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +import org.jd.core.v1.model.classfile.constant.ConstantValue; + +public class AttributeConstantValue implements Attribute { + protected ConstantValue constantValue; + + public AttributeConstantValue(ConstantValue constantValue) { + this.constantValue = constantValue; + } + + public ConstantValue getConstantValue() { + return constantValue; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeDeprecated.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeDeprecated.java new file mode 100644 index 00000000..d3769ae7 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeDeprecated.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeDeprecated implements Attribute { + public AttributeDeprecated() {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeExceptions.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeExceptions.java new file mode 100644 index 00000000..9788f2ff --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeExceptions.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeExceptions implements Attribute { + protected String[] exceptionTypeNames; + + public AttributeExceptions(String[] exceptionTypeNames) { + this.exceptionTypeNames = exceptionTypeNames; + } + + public String[] getExceptionTypeNames() { + return exceptionTypeNames; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeInnerClasses.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeInnerClasses.java new file mode 100644 index 00000000..b5aa4b26 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeInnerClasses.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeInnerClasses implements Attribute { + protected InnerClass[] classes; + + public AttributeInnerClasses(InnerClass[] classes) { + this.classes = classes; + } + + public InnerClass[] getInnerClasses() { + return classes; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLineNumberTable.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLineNumberTable.java new file mode 100644 index 00000000..2ac5234b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLineNumberTable.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeLineNumberTable implements Attribute { + protected LineNumber[] lineNumberTable; + + public AttributeLineNumberTable(LineNumber[] lineNumberTable) { + this.lineNumberTable = lineNumberTable; + } + + public LineNumber[] getLineNumberTable() { + return lineNumberTable; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLocalVariableTable.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLocalVariableTable.java new file mode 100644 index 00000000..19fd9b1a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLocalVariableTable.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeLocalVariableTable implements Attribute { + protected LocalVariable[] localVariableTable; + + public AttributeLocalVariableTable(LocalVariable[] localVariableTable) { + this.localVariableTable = localVariableTable; + } + + public LocalVariable[] getLocalVariableTable() { + return localVariableTable; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLocalVariableTypeTable.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLocalVariableTypeTable.java new file mode 100644 index 00000000..3954e4e6 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeLocalVariableTypeTable.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeLocalVariableTypeTable implements Attribute { + protected LocalVariableType[] localVariableTypeTable; + + public AttributeLocalVariableTypeTable(LocalVariableType[] localVariableTypeTable) { + this.localVariableTypeTable = localVariableTypeTable; + } + + public LocalVariableType[] getLocalVariableTypeTable() { + return localVariableTypeTable; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeMethodParameters.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeMethodParameters.java new file mode 100644 index 00000000..c4814353 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeMethodParameters.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeMethodParameters implements Attribute { + protected MethodParameter[] parameters; + + public AttributeMethodParameters(MethodParameter[] parameters) { + this.parameters = parameters; + } + + public MethodParameter[] getParameters() { + return parameters; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModule.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModule.java new file mode 100644 index 00000000..7d6ece94 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModule.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +// Example: https://github.com/netroby/jdk9-dev/blob/master/jdk/src/java.management/share/classes/module-info.java +public class AttributeModule implements Attribute { + protected String name; + protected int flags; + protected String version; + + protected ModuleInfo[] requires; + protected PackageInfo[] exports; + protected PackageInfo[] opens; + protected String[] uses; + protected ServiceInfo[] provides; + + public AttributeModule(String name, int flags, String version, ModuleInfo[] requires, PackageInfo[] exports, PackageInfo[] opens, String[] uses, ServiceInfo[] provides) { + this.name = name; + this.flags = flags; + this.version = version; + this.requires = requires; + this.exports = exports; + this.opens = opens; + this.uses = uses; + this.provides = provides; + } + + public String getName() { + return name; + } + + public int getFlags() { + return flags; + } + + public String getVersion() { + return version; + } + + public ModuleInfo[] getRequires() { + return requires; + } + + public PackageInfo[] getExports() { + return exports; + } + + public PackageInfo[] getOpens() { + return opens; + } + + public String[] getUses() { + return uses; + } + + public ServiceInfo[] getProvides() { + return provides; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModuleMainClass.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModuleMainClass.java new file mode 100644 index 00000000..5be61d86 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModuleMainClass.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +import org.jd.core.v1.model.classfile.constant.ConstantClass; + +public class AttributeModuleMainClass implements Attribute { + protected ConstantClass mainClass; + + public AttributeModuleMainClass(ConstantClass mainClass) { + this.mainClass = mainClass; + } + + public ConstantClass getMainClass() { + return mainClass; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModulePackages.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModulePackages.java new file mode 100644 index 00000000..9a933c45 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeModulePackages.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeModulePackages implements Attribute { + protected String[] packageNames; + + public AttributeModulePackages(String[] packageNames) { + this.packageNames = packageNames; + } + + public String[] getPackageNames() { + return packageNames; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeParameterAnnotations.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeParameterAnnotations.java new file mode 100644 index 00000000..a20bcf6f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeParameterAnnotations.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeParameterAnnotations implements Attribute { + protected Annotations[] parameterAnnotations; + + public AttributeParameterAnnotations(Annotations[] parameterAnnotations) { + this.parameterAnnotations = parameterAnnotations; + } + + public Annotations[] getParameterAnnotations() { + return parameterAnnotations; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSignature.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSignature.java new file mode 100644 index 00000000..b0885343 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSignature.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeSignature implements Attribute { + protected String signature; + + public AttributeSignature(String signature) { + this.signature = signature; + } + + public String getSignature() { + return signature; + } + + @Override + public String toString() { + return "AttributeSignature{signature=" + signature + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSourceFile.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSourceFile.java new file mode 100644 index 00000000..5e0cc029 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSourceFile.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeSourceFile implements Attribute { + protected String sourceFile; + + public AttributeSourceFile(String sourceFile) { + this.sourceFile = sourceFile; + } + + public String getSourceFile() { + return sourceFile; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSynthetic.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSynthetic.java new file mode 100644 index 00000000..c60ecfe1 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/AttributeSynthetic.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class AttributeSynthetic implements Attribute { + public AttributeSynthetic() {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/BootstrapMethod.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/BootstrapMethod.java new file mode 100644 index 00000000..c6fa4426 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/BootstrapMethod.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class BootstrapMethod { + protected int bootstrapMethodRef; + protected int bootstrapArguments[]; + + public BootstrapMethod(int bootstrapMethodRef, int[] bootstrapArguments) { + this.bootstrapMethodRef = bootstrapMethodRef; + this.bootstrapArguments = bootstrapArguments; + } + + public int getBootstrapMethodRef() { + return bootstrapMethodRef; + } + + public int[] getBootstrapArguments() { + return bootstrapArguments; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/CodeException.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/CodeException.java new file mode 100644 index 00000000..5258c18b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/CodeException.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class CodeException { + protected int index; + protected int startPc; + protected int endPc; + protected int handlerPc; + protected int catchType; + + public CodeException(int index, int startPc, int endPc, int handlerPc, int catchType) { + this.index = index; + this.startPc = startPc; + this.endPc = endPc; + this.handlerPc = handlerPc; + this.catchType = catchType; + } + + public int getStartPc() { + return startPc; + } + + public int getEndPc() { + return endPc; + } + + public int getHandlerPc() { + return handlerPc; + } + + public int getCatchType() { + return catchType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CodeException that = (CodeException) o; + + if (startPc != that.startPc) return false; + return endPc == that.endPc; + } + + @Override + public int hashCode() { + return 969815374 + 31 * startPc + endPc; + } + + @Override + public String toString() { + return "CodeException{index=" + index + ", startPc=" + startPc + ", endPc=" + endPc + ", handlerPc=" + handlerPc + ", catchType=" + catchType + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValue.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValue.java new file mode 100644 index 00000000..395e0192 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValue.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public interface ElementValue { + void accept(ElementValueVisitor attribute); +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueAnnotationValue.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueAnnotationValue.java new file mode 100644 index 00000000..058ce85f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueAnnotationValue.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ElementValueAnnotationValue implements ElementValue { + protected Annotation annotationValue; + + public ElementValueAnnotationValue(Annotation annotationValue) { + this.annotationValue = annotationValue; + } + + public Annotation getAnnotationValue() { + return annotationValue; + } + + @Override + public void accept(ElementValueVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueArrayValue.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueArrayValue.java new file mode 100644 index 00000000..d820b860 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueArrayValue.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ElementValueArrayValue implements ElementValue { + protected ElementValue[] values; + + public ElementValueArrayValue(ElementValue[] values) { + this.values = values; + } + + public ElementValue[] getValues() { + return values; + } + + @Override + public void accept(ElementValueVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueClassInfo.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueClassInfo.java new file mode 100644 index 00000000..55d1aaed --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueClassInfo.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ElementValueClassInfo implements ElementValue { + protected String classInfo; + + public ElementValueClassInfo(String classInfo) { + this.classInfo = classInfo; + } + + public String getClassInfo() { + return classInfo; + } + + @Override + public void accept(ElementValueVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueEnumConstValue.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueEnumConstValue.java new file mode 100644 index 00000000..1e926e09 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueEnumConstValue.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ElementValueEnumConstValue implements ElementValue { + protected String descriptor; + protected String constName; + + public ElementValueEnumConstValue(String descriptor, String constName) { + this.descriptor = descriptor; + this.constName = constName; + } + + public String getDescriptor() { + return descriptor; + } + + public String getConstName() { + return constName; + } + + @Override + public void accept(ElementValueVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValuePair.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValuePair.java new file mode 100644 index 00000000..9fc91c79 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValuePair.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ElementValuePair { + protected String elementName; + protected ElementValue elementValue; + + public ElementValuePair(String elementName, ElementValue elementValue) { + this.elementName = elementName; + this.elementValue = elementValue; + } + + public String getElementName() { + return elementName; + } + + @SuppressWarnings("unchecked") + public T getElementValue() { + return (T)elementValue; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValuePrimitiveType.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValuePrimitiveType.java new file mode 100644 index 00000000..9c12bb51 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValuePrimitiveType.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +import org.jd.core.v1.model.classfile.constant.ConstantValue; + +public class ElementValuePrimitiveType implements ElementValue { + /* + * type = {'B', 'D', 'F', 'I', 'J', 'S', 'Z', 'C', 's'} + */ + protected int type; + protected ConstantValue constValue; + + public ElementValuePrimitiveType(int type, ConstantValue constValue) { + this.type = type; + this.constValue = constValue; + } + + public int getType() { + return type; + } + + @SuppressWarnings("unchecked") + public T getConstValue() { + return (T)constValue; + } + + @Override + public void accept(ElementValueVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueVisitor.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueVisitor.java new file mode 100644 index 00000000..68653e6f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ElementValueVisitor.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public interface ElementValueVisitor { + void visit(ElementValuePrimitiveType elementValue); + void visit(ElementValueClassInfo elementValue); + void visit(ElementValueAnnotationValue elementValue); + void visit(ElementValueEnumConstValue elementValue); + void visit(ElementValueArrayValue elementValue); +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/InnerClass.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/InnerClass.java new file mode 100644 index 00000000..a20c4f4b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/InnerClass.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class InnerClass { + protected String innerTypeName; + protected String outerTypeName; + protected String innerName; + protected int innerAccessFlags; + + public InnerClass(String innerTypeName, String outerTypeName, String innerName, int innerAccessFlags) { + this.innerTypeName = innerTypeName; + this.outerTypeName = outerTypeName; + this.innerName = innerName; + this.innerAccessFlags = innerAccessFlags; + } + + public String getInnerTypeName() { + return innerTypeName; + } + + public String getOuterTypeName() { + return outerTypeName; + } + + public String getInnerName() { + return innerName; + } + + public int getInnerAccessFlags() { + return innerAccessFlags; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LineNumber.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LineNumber.java new file mode 100644 index 00000000..48142027 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LineNumber.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class LineNumber { + protected int startPc; + protected int lineNumber; + + public LineNumber(int startPc, int lineNumber) { + this.startPc = startPc; + this.lineNumber = lineNumber; + } + + public int getStartPc() { + return startPc; + } + + public int getLineNumber() { + return lineNumber; + } + + @Override + public String toString() { + return "LineNumber{startPc=" + startPc + ", lineNumber=" + lineNumber + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LocalVariable.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LocalVariable.java new file mode 100644 index 00000000..66d8035a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LocalVariable.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class LocalVariable { + protected int startPc; + protected int length; + protected String name; + protected String descriptor; + protected int index; + + public LocalVariable(int startPc, int length, String name, String descriptor, int index) { + this.startPc = startPc; + this.length = length; + this.name = name; + this.descriptor = descriptor; + this.index = index; + } + + public int getStartPc() { + return startPc; + } + + public int getLength() { + return length; + } + + public String getName() { + return name; + } + + public String getDescriptor() { + return descriptor; + } + + public int getIndex() { + return index; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("LocalVariable{index=").append(index); + sb.append(", name=").append(name); + sb.append(", descriptor=").append(descriptor); + sb.append(", startPc=").append(startPc); + sb.append(", length=").append(length); + + return sb.append("}").toString(); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LocalVariableType.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LocalVariableType.java new file mode 100644 index 00000000..830b9383 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/LocalVariableType.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class LocalVariableType { + protected int startPc; + protected int length; + protected String name; + protected String signature; + protected int index; + + public LocalVariableType(int startPc, int length, String name, String signature, int index) { + this.startPc = startPc; + this.length = length; + this.name = name; + this.signature = signature; + this.index = index; + } + + public int getStartPc() { + return startPc; + } + + public int getLength() { + return length; + } + + public String getName() { + return name; + } + + public String getSignature() { + return signature; + } + + public int getIndex() { + return index; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("LocalVariableType{index=").append(index); + sb.append(", name=").append(name); + sb.append(", signature=").append(signature); + sb.append(", index=").append(index); + sb.append(", startPc=").append(startPc); + sb.append(", length=").append(length); + + return sb.append("}").toString(); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/MethodParameter.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/MethodParameter.java new file mode 100644 index 00000000..828cf7a2 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/MethodParameter.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class MethodParameter { + protected String name; + protected int access; + + public MethodParameter(String name, int access) { + this.name = name; + this.access = access; + } + + public String getName() { + return name; + } + + public int getAccess() { + return access; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("Parameter{name=").append(name); + sb.append(", access=").append(access); + + return sb.append("}").toString(); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ModuleInfo.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ModuleInfo.java new file mode 100644 index 00000000..5d95e145 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ModuleInfo.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ModuleInfo { + protected String name; + protected int flags; + protected String version; + + public ModuleInfo(String name, int flags, String version) { + this.name = name; + this.flags = flags; + this.version = version; + } + + public String getName() { + return name; + } + + public int getFlags() { + return flags; + } + + public String getVersion() { + return version; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("ModuleInfo{name=").append(name); + sb.append(", flags=").append(flags); + + if (version != null) { + sb.append(", version=").append(version); + } + + return sb.append("}").toString(); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/PackageInfo.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/PackageInfo.java new file mode 100644 index 00000000..8420f09b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/PackageInfo.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class PackageInfo { + protected String internalName; + protected int flags; + protected String[] moduleInfoNames; + + public PackageInfo(String internalName, int flags, String[] moduleInfoNames) { + this.internalName = internalName; + this.flags = flags; + this.moduleInfoNames = moduleInfoNames; + } + + public String getInternalName() { + return internalName; + } + + public int getFlags() { + return flags; + } + + public String[] getModuleInfoNames() { + return moduleInfoNames; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("PackageInfo{internalName=").append(internalName); + sb.append(", flags=").append(flags); + + if (moduleInfoNames != null) { + sb.append(", moduleInfoNames=").append(moduleInfoNames); + } + + return sb.append("}").toString(); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ServiceInfo.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ServiceInfo.java new file mode 100644 index 00000000..48e19c03 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/ServiceInfo.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class ServiceInfo { + protected String interfaceTypeName; + protected String[] implementationTypeNames; + + public ServiceInfo(String interfaceTypeName, String[] implementationTypeNames) { + this.interfaceTypeName = interfaceTypeName; + this.implementationTypeNames = implementationTypeNames; + } + + public String getInterfaceTypeName() { + return interfaceTypeName; + } + + public String[] getImplementationTypeNames() { + return implementationTypeNames; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("ServiceInfo{interfaceTypeName=").append(interfaceTypeName); + + if (implementationTypeNames != null) { + sb.append(", implementationTypeNames=").append(implementationTypeNames); + } + + return sb.append("}").toString(); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/attribute/UnknownAttribute.java b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/UnknownAttribute.java new file mode 100644 index 00000000..5bcec732 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/attribute/UnknownAttribute.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.attribute; + +public class UnknownAttribute implements Attribute { + public UnknownAttribute() {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/Constant.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/Constant.java new file mode 100644 index 00000000..69286306 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/Constant.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public abstract class Constant { + public static final byte CONSTANT_Unknown = 0; + public static final byte CONSTANT_Utf8 = 1; + public static final byte CONSTANT_Integer = 3; + public static final byte CONSTANT_Float = 4; + public static final byte CONSTANT_Long = 5; + public static final byte CONSTANT_Double = 6; + public static final byte CONSTANT_Class = 7; + public static final byte CONSTANT_String = 8; + public static final byte CONSTANT_FieldRef = 9; + public static final byte CONSTANT_MethodRef = 10; + public static final byte CONSTANT_InterfaceMethodRef = 11; + public static final byte CONSTANT_NameAndType = 12; + public static final byte CONSTANT_MethodHandle = 15; + public static final byte CONSTANT_MethodType = 16; + public static final byte CONSTANT_InvokeDynamic = 18; + public static final byte CONSTANT_MemberRef = 19; // Unofficial constant + + protected byte tag; + + public Constant(byte tag) { + this.tag = tag; + } + + public byte getTag() { + return tag; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantClass.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantClass.java new file mode 100644 index 00000000..bcad1db6 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantClass.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantClass extends Constant { + protected int nameIndex; + + public ConstantClass(int nameIndex) { + super(CONSTANT_Class); + this.nameIndex = nameIndex; + } + + public int getNameIndex() { + return nameIndex; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantDouble.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantDouble.java new file mode 100644 index 00000000..adf3ccea --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantDouble.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantDouble extends ConstantValue { + protected double value; + + public ConstantDouble(double value) { + super(CONSTANT_Double); + this.value = value; + } + + public double getValue() { + return value; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantFloat.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantFloat.java new file mode 100644 index 00000000..f885e9c7 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantFloat.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantFloat extends ConstantValue { + protected float value; + + public ConstantFloat(float value) { + super(CONSTANT_Float); + this.value = value; + } + + public float getValue() { + return value; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantInteger.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantInteger.java new file mode 100644 index 00000000..db850d9e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantInteger.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantInteger extends ConstantValue { + protected int value; + + public ConstantInteger(int value) { + super(CONSTANT_Integer); + this.value = value; + } + + public int getValue() { + return value; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantLong.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantLong.java new file mode 100644 index 00000000..3edba972 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantLong.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantLong extends ConstantValue { + protected long value; + + public ConstantLong(long value) { + super(CONSTANT_Long); + this.value = value; + } + + public long getValue() { + return value; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMemberRef.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMemberRef.java new file mode 100644 index 00000000..596bf090 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMemberRef.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +/** + * POJO for CONSTANT_Fieldref, CONSTANT_Methodref and CONSTANT_InterfaceMethodref. + */ +public class ConstantMemberRef extends Constant { + protected int classIndex; + protected int nameAndTypeIndex; + + public ConstantMemberRef(int classIndex, int nameAndTypeIndex) { + super(CONSTANT_MemberRef); + this.classIndex = classIndex; + this.nameAndTypeIndex = nameAndTypeIndex; + } + + public int getClassIndex() { + return classIndex; + } + + public int getNameAndTypeIndex() { + return nameAndTypeIndex; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMethodHandle.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMethodHandle.java new file mode 100644 index 00000000..7ac49d64 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMethodHandle.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantMethodHandle extends Constant { + protected int referenceKind; + protected int referenceIndex; + + public ConstantMethodHandle(int referenceKind, int referenceIndex) { + super(CONSTANT_MethodHandle); + this.referenceKind = referenceKind; + this.referenceIndex = referenceIndex; + } + + public int getReferenceKind() { + return referenceKind; + } + + public int getReferenceIndex() { + return referenceIndex; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMethodType.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMethodType.java new file mode 100644 index 00000000..fa1420ed --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantMethodType.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantMethodType extends Constant { + protected int descriptorIndex; + + public ConstantMethodType(int descriptorIndex) { + super(CONSTANT_MethodType); + this.descriptorIndex = descriptorIndex; + } + + public int getDescriptorIndex() { + return descriptorIndex; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantNameAndType.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantNameAndType.java new file mode 100644 index 00000000..e928bc78 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantNameAndType.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantNameAndType extends Constant { + protected int nameIndex; + protected int descriptorIndex; + + public ConstantNameAndType(int nameIndex, int descriptorIndex) { + super(CONSTANT_NameAndType); + this.nameIndex = nameIndex; + this.descriptorIndex = descriptorIndex; + } + + public int getNameIndex() { + return nameIndex; + } + + public int getDescriptorIndex() { + return descriptorIndex; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantString.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantString.java new file mode 100644 index 00000000..a585560f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantString.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantString extends Constant { + protected int stringIndex; + + public ConstantString(int stringIndex) { + super(CONSTANT_String); + this.stringIndex = stringIndex; + } + + public int getStringIndex() { + return stringIndex; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantUtf8.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantUtf8.java new file mode 100644 index 00000000..dc497b3b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantUtf8.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public class ConstantUtf8 extends ConstantValue { + protected String value; + + public ConstantUtf8(String value) { + super(CONSTANT_Utf8); + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantValue.java b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantValue.java new file mode 100644 index 00000000..4344b935 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/classfile/constant/ConstantValue.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.classfile.constant; + +public abstract class ConstantValue extends Constant { + protected ConstantValue(byte tag) { + super(tag); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/AbstractNopFlexibleFragmentVisitor.java b/core/src/main/java/org/jd/core/v1/model/fragment/AbstractNopFlexibleFragmentVisitor.java new file mode 100644 index 00000000..c703e8f3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/AbstractNopFlexibleFragmentVisitor.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public abstract class AbstractNopFlexibleFragmentVisitor implements FragmentVisitor { + @Override public void visit(EndFlexibleBlockFragment fragment) {} + @Override public void visit(EndMovableBlockFragment fragment) {} + @Override public void visit(StartFlexibleBlockFragment fragment) {} + @Override public void visit(StartMovableBlockFragment fragment) {} + @Override public void visit(FixedFragment fragment) {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/EndFlexibleBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/EndFlexibleBlockFragment.java new file mode 100644 index 00000000..10f0ea06 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/EndFlexibleBlockFragment.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public abstract class EndFlexibleBlockFragment extends StartFlexibleBlockFragment { + protected EndFlexibleBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/EndMovableBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/EndMovableBlockFragment.java new file mode 100644 index 00000000..b881e8ee --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/EndMovableBlockFragment.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public class EndMovableBlockFragment extends FlexibleFragment { + public EndMovableBlockFragment() { + super(0, 0, 0, 0, "End movable block"); + } + + @Override + public String toString() { + return "{end-movable-block}"; + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/FixedFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/FixedFragment.java new file mode 100644 index 00000000..16889ad0 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/FixedFragment.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public abstract class FixedFragment implements Fragment { + protected final int firstLineNumber; + protected final int lastLineNumber; + + public FixedFragment(int firstLineNumber, int lastLineNumber) { + this.firstLineNumber = firstLineNumber; + this.lastLineNumber = lastLineNumber; + } + + public int getFirstLineNumber() { + return firstLineNumber; + } + + public int getLastLineNumber() { + return lastLineNumber; + } + + @Override + public String toString() { + return "{first-line-number=" + firstLineNumber + ", last-line-number=" + lastLineNumber + "}"; + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/FlexibleFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/FlexibleFragment.java new file mode 100644 index 00000000..77744a15 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/FlexibleFragment.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public abstract class FlexibleFragment implements Fragment { + protected final int minimalLineCount; + protected int maximalLineCount; + protected int initialLineCount; + protected int lineCount; + protected final int weight; + protected final String label; + + public FlexibleFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + this.minimalLineCount = minimalLineCount; + this.maximalLineCount = maximalLineCount; + this.initialLineCount = this.lineCount = lineCount; + this.weight = weight; + this.label = label; + } + + public void resetLineCount() { + lineCount = initialLineCount; + } + + public int getMinimalLineCount() { + return minimalLineCount; + } + + public int getMaximalLineCount() { + return maximalLineCount; + } + + public int getInitialLineCount() { + return initialLineCount; + } + + public int getLineCount() { + return lineCount; + } + + public int getWeight() { + return weight; + } + + public String getLabel() { + return label; + } + + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + return true; + } else { + return false; + } + } + + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + return true; + } else { + return false; + } + } + + @Override + public String toString() { + return "{minimal-line-count=" + getMinimalLineCount() + + ", maximal-line-count=" + getMaximalLineCount() + + ", initial-line-count=" + getInitialLineCount() + + ", line-count=" + getLineCount() + + ", weight=" + getWeight() + + (getLabel() != null ? ", label='" + label + "'}": "}"); + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/Fragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/Fragment.java new file mode 100644 index 00000000..2a8c1d9d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/Fragment.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +/** + * A fragment is a part of a concrete syntax tree. A fragment can be compacted, expanded and/or moved to match the + * original line numbers. + * + * @see FixedFragment + * @see FlexibleFragment + */ +public interface Fragment { + void accept(FragmentVisitor visitor); +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/FragmentVisitor.java b/core/src/main/java/org/jd/core/v1/model/fragment/FragmentVisitor.java new file mode 100644 index 00000000..c0b97778 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/FragmentVisitor.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public interface FragmentVisitor { + void visit(FlexibleFragment fragment); + void visit(EndFlexibleBlockFragment fragment); + void visit(EndMovableBlockFragment fragment); + void visit(SpacerBetweenMovableBlocksFragment fragment); + void visit(StartFlexibleBlockFragment fragment); + void visit(StartMovableBlockFragment fragment); + void visit(FixedFragment fragment); +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/SpacerBetweenMovableBlocksFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/SpacerBetweenMovableBlocksFragment.java new file mode 100644 index 00000000..e375f59a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/SpacerBetweenMovableBlocksFragment.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + + +public class SpacerBetweenMovableBlocksFragment extends FlexibleFragment { + public SpacerBetweenMovableBlocksFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public void setInitialLineCount(int initialLineCount) { + this.initialLineCount = this.lineCount = initialLineCount; + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/StartFlexibleBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/StartFlexibleBlockFragment.java new file mode 100644 index 00000000..d6cccdef --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/StartFlexibleBlockFragment.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public abstract class StartFlexibleBlockFragment extends FlexibleFragment { + + protected StartFlexibleBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/fragment/StartMovableBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/fragment/StartMovableBlockFragment.java new file mode 100644 index 00000000..10c8dbc9 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/fragment/StartMovableBlockFragment.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.fragment; + +public class StartMovableBlockFragment extends FlexibleFragment { + protected int type; + + public StartMovableBlockFragment(int type) { + super(0, 0, 0, 0, "Start movable block"); + this.type = type; + } + + public int getType() { + return type; + } + + @Override + public String toString() { + return "{start-movable-block}"; + } + + @Override + public void accept(FragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBlockFragment.java new file mode 100644 index 00000000..1071773e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBlockFragment.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.EndFlexibleBlockFragment; + +public class EndBlockFragment extends EndFlexibleBlockFragment implements JavaFragment { + protected StartBlockFragment start; + + public EndBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, StartBlockFragment start) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + this.start = start; + start.setEndArrayInitializerBlockFragment(this); + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + public StartBlockFragment getStartArrayInitializerBlockFragment() { + return start; + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + +// if (!force) { +// // Update start body fragment +// if ((lineCount == 1) && (start.getLineCount() == 0)) { +// start.setLineCount(lineCount); +// } +// } + + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + +// if (!force) { +// if (lineCount == 0) { +// start.setLineCount(lineCount); +// } +// } + + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndBlockInParameterFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBlockInParameterFragment.java new file mode 100644 index 00000000..cdd4b4dc --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBlockInParameterFragment.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class EndBlockInParameterFragment extends EndBlockFragment implements JavaFragment { + public EndBlockInParameterFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, StartBlockFragment start) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label, start); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndBodyFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBodyFragment.java new file mode 100644 index 00000000..240c962b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBodyFragment.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.EndFlexibleBlockFragment; + +public class EndBodyFragment extends EndFlexibleBlockFragment implements JavaFragment { + protected final StartBodyFragment start; + + public EndBodyFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, StartBodyFragment start) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + this.start = start; + start.setEndBodyFragment(this); + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + public StartBodyFragment getStartBodyFragment() { + return start; + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + + if (!force) { + // Update start body fragment + if ((lineCount == 1) && (start.getLineCount() == 0)) { + start.setLineCount(lineCount); + } + } + + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + + if (!force) { + if (lineCount == 0) { + start.setLineCount(lineCount); + } + } + + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndBodyInParameterFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBodyInParameterFragment.java new file mode 100644 index 00000000..052acfeb --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndBodyInParameterFragment.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class EndBodyInParameterFragment extends EndBodyFragment implements JavaFragment { + public EndBodyInParameterFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, StartBodyFragment startBodyFragment) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label, startBodyFragment); + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndMovableJavaBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndMovableJavaBlockFragment.java new file mode 100644 index 00000000..e775e36e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndMovableJavaBlockFragment.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.EndMovableBlockFragment; + +public class EndMovableJavaBlockFragment extends EndMovableBlockFragment implements JavaFragment { + public static final EndMovableJavaBlockFragment END_MOVABLE_BLOCK = new EndMovableJavaBlockFragment(); + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndSingleStatementBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndSingleStatementBlockFragment.java new file mode 100644 index 00000000..ac58baf4 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndSingleStatementBlockFragment.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.EndFlexibleBlockFragment; + +public class EndSingleStatementBlockFragment extends EndFlexibleBlockFragment implements JavaFragment { + protected final StartSingleStatementBlockFragment start; + + public EndSingleStatementBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, StartSingleStatementBlockFragment start) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + this.start = start; + start.setEndSingleStatementBlockFragment(this); + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + public StartSingleStatementBlockFragment getStartSingleStatementBlockFragment() { + return start; + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + + if (!force) { + // Update start body fragment + if (start.getLineCount() == 0) { + start.setLineCount(1); + } + } + + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + + if (!force) { + if (lineCount == 0) { + start.setLineCount(0); + } + } + + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/EndStatementsBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/EndStatementsBlockFragment.java new file mode 100644 index 00000000..0b0688f5 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/EndStatementsBlockFragment.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.EndFlexibleBlockFragment; + +public class EndStatementsBlockFragment extends EndFlexibleBlockFragment implements JavaFragment { + protected final StartStatementsBlockFragment.Group group; + + public EndStatementsBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, StartStatementsBlockFragment.Group group) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + this.group = group; + group.add(this); + } + + public StartStatementsBlockFragment.Group getGroup() { + return group; + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/ImportsFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/ImportsFragment.java new file mode 100644 index 00000000..99f7c90f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/ImportsFragment.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.FlexibleFragment; +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + +public class ImportsFragment extends FlexibleFragment implements JavaFragment { + protected static final ImportCountComparator COUNT_COMPARATOR = new ImportCountComparator(); + + protected final HashMap importMap = new HashMap<>(); + + public ImportsFragment(int weight) { + super(0, -1, -1, weight, "Imports"); + } + + public void addImport(String internalName, String qualifiedName) { + Import imp = importMap.get(internalName); + + if (imp == null) { + importMap.put(internalName, new Import(internalName, qualifiedName)); + } else { + imp.incCounter(); + } + } + + public boolean incCounter(String internalName) { + Import imp = importMap.get(internalName); + + if (imp == null) { + return false; + } else { + imp.incCounter(); + return true; + } + } + + public boolean isEmpty() { + return importMap.isEmpty(); + } + + public void initLineCounts() { + maximalLineCount = initialLineCount = lineCount = importMap.size(); + } + + public boolean contains(String internalName) { + return importMap.containsKey(internalName); + } + + @Override + public int getLineCount() { + assert (lineCount != -1) : "Call initLineCounts() before"; + return lineCount; + } + + public Collection getImports() { + int lineCount = getLineCount(); + int size = importMap.size(); + + if (lineCount < size) { + DefaultList imports = new DefaultList<>(importMap.values()); + + imports.sort(COUNT_COMPARATOR); + + // Remove less used imports + List subList = imports.subList(lineCount, size); + + for (Import imp0rt : subList) { + importMap.remove(imp0rt.getInternalName()); + } + + subList.clear(); + + return imports; + } else { + return importMap.values(); + } + } + + public static class Import { + protected String internalName; + protected String qualifiedName; + protected int counter; + + public Import(String internalName, String qualifiedName) { + this.internalName = internalName; + this.qualifiedName = qualifiedName; + this.counter = 1; + } + + public String getInternalName() { + return internalName; + } + public String getQualifiedName() { + return qualifiedName; + } + public int getCounter() { + return counter; + } + public void incCounter() { + counter++; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } + + protected static class ImportCountComparator implements Comparator { + @Override + public int compare(Import tr1, Import tr2) { + return tr2.getCounter() - tr1.getCounter(); + } + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/JavaFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/JavaFragment.java new file mode 100644 index 00000000..25be9c98 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/JavaFragment.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public interface JavaFragment { + void accept(JavaFragmentVisitor visitor); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/JavaFragmentVisitor.java b/core/src/main/java/org/jd/core/v1/model/javafragment/JavaFragmentVisitor.java new file mode 100644 index 00000000..63d87e7b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/JavaFragmentVisitor.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public interface JavaFragmentVisitor { + void visit(EndBodyFragment fragment); + void visit(EndBlockInParameterFragment fragment); + void visit(EndBlockFragment fragment); + void visit(EndBodyInParameterFragment fragment); + void visit(EndMovableJavaBlockFragment fragment); + void visit(EndSingleStatementBlockFragment fragment); + void visit(EndStatementsBlockFragment fragment); + void visit(ImportsFragment fragment); + void visit(LineNumberTokensFragment fragment); + void visit(SpacerBetweenMembersFragment fragment); + void visit(SpacerFragment fragment); + void visit(SpaceSpacerFragment fragment); + void visit(StartBlockFragment fragment); + void visit(StartBodyFragment fragment); + void visit(StartMovableJavaBlockFragment fragment); + void visit(StartSingleStatementBlockFragment fragment); + void visit(StartStatementsBlockFragment fragment); + void visit(StartStatementsDoWhileBlockFragment fragment); + void visit(StartStatementsInfiniteForBlockFragment fragment); + void visit(StartStatementsInfiniteWhileBlockFragment fragment); + void visit(StartStatementsTryBlockFragment fragment); + void visit(TokensFragment fragment); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/LineNumberTokensFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/LineNumberTokensFragment.java new file mode 100644 index 00000000..10187289 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/LineNumberTokensFragment.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.api.printer.Printer; +import org.jd.core.v1.model.fragment.FixedFragment; +import org.jd.core.v1.model.token.AbstractNopTokenVisitor; +import org.jd.core.v1.model.token.LineNumberToken; +import org.jd.core.v1.model.token.NewLineToken; +import org.jd.core.v1.model.token.Token; + +import java.util.Arrays; +import java.util.List; + +public class LineNumberTokensFragment extends FixedFragment implements JavaFragment { + protected List tokens; + + public LineNumberTokensFragment(Token... tokens) { + this(Arrays.asList(tokens)); + } + + public LineNumberTokensFragment(List tokens) { + super(searchFirstLineNumber(tokens), searchLastLineNumber(tokens)); + assert firstLineNumber != Printer.UNKNOWN_LINE_NUMBER : "Uses 'TokensFragment' instead"; + this.tokens = tokens; + } + + public List getTokens() { + return tokens; + } + + protected static int searchFirstLineNumber(List tokens) { + SearchLineNumberVisitor visitor = new SearchLineNumberVisitor(); + + for (Token token : tokens) { + token.accept(visitor); + + if (visitor.lineNumber != Printer.UNKNOWN_LINE_NUMBER) { + return visitor.lineNumber - visitor.newLineCounter; + } + } + + return Printer.UNKNOWN_LINE_NUMBER; + } + + protected static int searchLastLineNumber(List tokens) { + SearchLineNumberVisitor visitor = new SearchLineNumberVisitor(); + int index = tokens.size(); + + while (index-- > 0) { + tokens.get(index).accept(visitor); + + if (visitor.lineNumber != Printer.UNKNOWN_LINE_NUMBER) { + return visitor.lineNumber + visitor.newLineCounter; + } + } + + return Printer.UNKNOWN_LINE_NUMBER; + } + + protected static class SearchLineNumberVisitor extends AbstractNopTokenVisitor { + public int lineNumber; + public int newLineCounter; + + public void reset() { + this.lineNumber = Printer.UNKNOWN_LINE_NUMBER; + this.newLineCounter = 0; + } + + @Override + public void visit(LineNumberToken token) { + lineNumber = token.getLineNumber(); + } + + @Override + public void visit(NewLineToken token) { + newLineCounter++; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/SpaceSpacerFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/SpaceSpacerFragment.java new file mode 100644 index 00000000..8f61c982 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/SpaceSpacerFragment.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class SpaceSpacerFragment extends SpacerFragment implements JavaFragment { + + public SpaceSpacerFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/SpacerBetweenMembersFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/SpacerBetweenMembersFragment.java new file mode 100644 index 00000000..96a2b7b3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/SpacerBetweenMembersFragment.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.SpacerBetweenMovableBlocksFragment; + +public class SpacerBetweenMembersFragment extends SpacerBetweenMovableBlocksFragment implements JavaFragment { + + public SpacerBetweenMembersFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/SpacerFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/SpacerFragment.java new file mode 100644 index 00000000..20e48137 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/SpacerFragment.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.FlexibleFragment; + +public class SpacerFragment extends FlexibleFragment implements JavaFragment { + public SpacerFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartBlockFragment.java new file mode 100644 index 00000000..925bbbba --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartBlockFragment.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.StartFlexibleBlockFragment; + +public class StartBlockFragment extends StartFlexibleBlockFragment implements JavaFragment { + protected EndBlockFragment end; + + public StartBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public EndBlockFragment getEndArrayInitializerBlockFragment() { + return end; + } + + public void setEndArrayInitializerBlockFragment(EndBlockFragment end) { + this.end = end; + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + + if (!force) { + // Update end body fragment + if ((lineCount == 1) && (end.getLineCount() == 0)) { + end.setLineCount(lineCount); + } + } + + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + + if (!force) { + // Update end body fragment + if (lineCount == 1) { + end.setLineCount(lineCount); + } + } + + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartBodyFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartBodyFragment.java new file mode 100644 index 00000000..42eb23b6 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartBodyFragment.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.StartFlexibleBlockFragment; + +public class StartBodyFragment extends StartFlexibleBlockFragment implements JavaFragment { + protected EndBodyFragment end; + + public StartBodyFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public EndBodyFragment getEndBodyFragment() { + return end; + } + + void setEndBodyFragment(EndBodyFragment end) { + this.end = end; + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + + if (!force) { + // Update end body fragment + if ((lineCount == 1) && (end.getLineCount() == 0)) { + end.setLineCount(lineCount); + } + } + + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + + if (!force) { + // Update end body fragment + if (lineCount == 1) { + end.setLineCount(lineCount); + } + } + + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartMovableJavaBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartMovableJavaBlockFragment.java new file mode 100644 index 00000000..8bd073c3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartMovableJavaBlockFragment.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.StartMovableBlockFragment; + +public class StartMovableJavaBlockFragment extends StartMovableBlockFragment implements JavaFragment { + public static final StartMovableJavaBlockFragment START_MOVABLE_TYPE_BLOCK = new StartMovableJavaBlockFragment(1); + public static final StartMovableJavaBlockFragment START_MOVABLE_FIELD_BLOCK = new StartMovableJavaBlockFragment(2); + public static final StartMovableJavaBlockFragment START_MOVABLE_METHOD_BLOCK = new StartMovableJavaBlockFragment(3); + + protected StartMovableJavaBlockFragment(int type) { + super(type); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartSingleStatementBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartSingleStatementBlockFragment.java new file mode 100644 index 00000000..b9a9aa3d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartSingleStatementBlockFragment.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.StartFlexibleBlockFragment; + +public class StartSingleStatementBlockFragment extends StartFlexibleBlockFragment implements JavaFragment { + protected EndSingleStatementBlockFragment end; + + public StartSingleStatementBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + public EndSingleStatementBlockFragment getEndSingleStatementBlockFragment() { + return end; + } + + public void setEndSingleStatementBlockFragment(EndSingleStatementBlockFragment end) { + this.end = end; + } + + @Override + public boolean incLineCount(boolean force) { + if (lineCount < maximalLineCount) { + lineCount++; + + if (!force) { + // Update end body fragment + if (end.getLineCount() == 0) { + end.setLineCount(1); + } + } + + return true; + } else { + return false; + } + } + + @Override + public boolean decLineCount(boolean force) { + if (lineCount > minimalLineCount) { + lineCount--; + + if (!force) { + // Update end body fragment + if (lineCount == 1) { + end.setLineCount(1); + } + } + + return true; + } else { + return false; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsBlockFragment.java new file mode 100644 index 00000000..e3b04860 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsBlockFragment.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.model.fragment.FlexibleFragment; +import org.jd.core.v1.model.fragment.StartFlexibleBlockFragment; +import org.jd.core.v1.util.DefaultList; + +public class StartStatementsBlockFragment extends StartFlexibleBlockFragment implements JavaFragment { + protected Group group; + + public StartStatementsBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + this.group = new Group(this); + } + + public StartStatementsBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, Group group) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + this.group = group; + group.add(this); + } + + public Group getGroup() { + return group; + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } + + public static class Group { + protected DefaultList fragments = new DefaultList<>(); + protected int minimalLineCount = Integer.MAX_VALUE; + + Group(FlexibleFragment fragment) { + this.fragments.add(fragment); + } + + void add(FlexibleFragment fragment) { + fragments.add(fragment); + } + + public int getMinimalLineCount() { + if (minimalLineCount == Integer.MAX_VALUE) { + for (FlexibleFragment fragment : fragments) { + if (minimalLineCount > fragment.getLineCount()) { + minimalLineCount = fragment.getLineCount(); + } + } + } + return minimalLineCount; + } + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsDoWhileBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsDoWhileBlockFragment.java new file mode 100644 index 00000000..17efd3de --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsDoWhileBlockFragment.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class StartStatementsDoWhileBlockFragment extends StartStatementsBlockFragment { + public StartStatementsDoWhileBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public StartStatementsDoWhileBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, Group group) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label, group); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsInfiniteForBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsInfiniteForBlockFragment.java new file mode 100644 index 00000000..80e14b4d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsInfiniteForBlockFragment.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class StartStatementsInfiniteForBlockFragment extends StartStatementsBlockFragment { + public StartStatementsInfiniteForBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public StartStatementsInfiniteForBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, Group group) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label, group); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsInfiniteWhileBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsInfiniteWhileBlockFragment.java new file mode 100644 index 00000000..4c9247b0 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsInfiniteWhileBlockFragment.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class StartStatementsInfiniteWhileBlockFragment extends StartStatementsBlockFragment { + public StartStatementsInfiniteWhileBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public StartStatementsInfiniteWhileBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, Group group) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label, group); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsTryBlockFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsTryBlockFragment.java new file mode 100644 index 00000000..d2cdaeb4 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/StartStatementsTryBlockFragment.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +public class StartStatementsTryBlockFragment extends StartStatementsBlockFragment { + public StartStatementsTryBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label); + } + + public StartStatementsTryBlockFragment(int minimalLineCount, int lineCount, int maximalLineCount, int weight, String label, Group group) { + super(minimalLineCount, lineCount, maximalLineCount, weight, label, group); + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javafragment/TokensFragment.java b/core/src/main/java/org/jd/core/v1/model/javafragment/TokensFragment.java new file mode 100644 index 00000000..3a6dc520 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javafragment/TokensFragment.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javafragment; + +import org.jd.core.v1.api.printer.Printer; +import org.jd.core.v1.model.fragment.FlexibleFragment; +import org.jd.core.v1.model.token.*; + +import java.util.Arrays; +import java.util.List; + +import static org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.visitor.StatementVisitor.RETURN; + +public class TokensFragment extends FlexibleFragment implements JavaFragment { + public static final TokensFragment COMMA = new TokensFragment(TextToken.COMMA); + public static final TokensFragment SEMICOLON = new TokensFragment(TextToken.SEMICOLON); + public static final TokensFragment START_DECLARATION_OR_STATEMENT_BLOCK = new TokensFragment(StartBlockToken.START_DECLARATION_OR_STATEMENT_BLOCK); + public static final TokensFragment END_DECLARATION_OR_STATEMENT_BLOCK = new TokensFragment(EndBlockToken.END_DECLARATION_OR_STATEMENT_BLOCK); + public static final TokensFragment END_DECLARATION_OR_STATEMENT_BLOCK_SEMICOLON = new TokensFragment(EndBlockToken.END_DECLARATION_OR_STATEMENT_BLOCK, TextToken.SEMICOLON); + public static final TokensFragment RETURN_SEMICOLON = new TokensFragment(RETURN, TextToken.SEMICOLON); + + protected List tokens; + + public TokensFragment(Token... tokens) { + this(Arrays.asList(tokens)); + } + + public TokensFragment(List tokens) { + this(getLineCount(tokens), tokens); + } + + protected TokensFragment(int lineCount, List tokens) { + super(lineCount, lineCount, lineCount, 0, "Tokens"); + this.tokens = tokens; + } + + public List getTokens() { + return tokens; + } + + protected static int getLineCount(List tokens) { + LineCountVisitor visitor = new LineCountVisitor(); + + for (Token token : tokens) { + token.accept(visitor); + } + + return visitor.lineCount; + } + + protected static class LineCountVisitor extends AbstractNopTokenVisitor { + public int lineCount = 0; + + @Override + public void visit(LineNumberToken token) { + lineCount++; + assert token.getLineNumber() == Printer.UNKNOWN_LINE_NUMBER : "LineNumberToken cannot have a known line number. Uses 'LineNumberTokensFragment' instead"; + } + } + + @Override + public void accept(JavaFragmentVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/AbstractJavaSyntaxVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/AbstractJavaSyntaxVisitor.java new file mode 100644 index 00000000..ff10e7d8 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/AbstractJavaSyntaxVisitor.java @@ -0,0 +1,719 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax; + +import org.jd.core.v1.model.javasyntax.declaration.*; +import org.jd.core.v1.model.javasyntax.expression.*; +import org.jd.core.v1.model.javasyntax.reference.*; +import org.jd.core.v1.model.javasyntax.statement.*; +import org.jd.core.v1.model.javasyntax.type.*; + +import java.util.Iterator; +import java.util.List; + +public abstract class AbstractJavaSyntaxVisitor extends AbstractTypeArgumentVisitor implements DeclarationVisitor, ExpressionVisitor, ReferenceVisitor, StatementVisitor, TypeVisitor, TypeParameterVisitor { + public void visit(CompilationUnit compilationUnit) { + compilationUnit.getTypeDeclarations().accept(this); + } + + @Override + public void visit(AnnotationDeclaration declaration) { + safeAccept(declaration.getAnnotationDeclarators()); + safeAccept(declaration.getBodyDeclaration()); + safeAccept(declaration.getAnnotationReferences()); + } + + @Override + public void visit(ArrayVariableInitializer declaration) { + acceptListDeclaration(declaration); + } + + @Override + public void visit(BodyDeclaration declaration) { + safeAccept(declaration.getMemberDeclarations()); + } + + @Override + public void visit(ClassDeclaration declaration) { + BaseType superType = declaration.getSuperType(); + + if (superType != null) { + superType.accept(this); + } + + safeAccept(declaration.getTypeParameters()); + safeAccept(declaration.getInterfaces()); + safeAccept(declaration.getAnnotationReferences()); + safeAccept(declaration.getBodyDeclaration()); + } + + @Override public void visit(CommentStatement statement) {} + + @Override public void visit(CommentExpression expression) {} + + @Override + public void visit(ConstructorInvocationExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + safeAccept(expression.getParameters()); + } + + @Override + public void visit(ConstructorDeclaration declaration) { + safeAccept(declaration.getAnnotationReferences()); + safeAccept(declaration.getFormalParameters()); + safeAccept(declaration.getExceptionTypes()); + safeAccept(declaration.getStatements()); + } + + @Override + public void visit(EnumDeclaration declaration) { + visit((TypeDeclaration) declaration); + safeAccept(declaration.getInterfaces()); + safeAcceptListDeclaration(declaration.getConstants()); + safeAccept(declaration.getBodyDeclaration()); + } + + @Override + public void visit(EnumDeclaration.Constant declaration) { + safeAccept(declaration.getAnnotationReferences()); + safeAccept(declaration.getArguments()); + safeAccept(declaration.getBodyDeclaration()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(Expressions list) { + acceptListExpression(list); + } + + @Override + public void visit(ExpressionVariableInitializer declaration) { + declaration.getExpression().accept(this); + } + + @Override + public void visit(FieldDeclaration declaration) { + BaseType type = declaration.getType(); + + type.accept(this); + safeAccept(declaration.getAnnotationReferences()); + declaration.getFieldDeclarators().accept(this); + } + + @Override + public void visit(FieldDeclarator declarator) { + safeAccept(declarator.getVariableInitializer()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(FieldDeclarators list) { + acceptListDeclaration((List)list); + } + + @Override + public void visit(FormalParameter declaration) { + BaseType type = declaration.getType(); + + type.accept(this); + safeAccept(declaration.getAnnotationReferences()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(FormalParameters list) { + acceptListDeclaration(list); + } + + @Override + public void visit(InstanceInitializerDeclaration declaration) { + safeAccept(declaration.getStatements()); + } + + @Override + public void visit(InterfaceDeclaration declaration) { + safeAccept(declaration.getInterfaces()); + safeAccept(declaration.getAnnotationReferences()); + safeAccept(declaration.getBodyDeclaration()); + } + + @Override + public void visit(LocalVariableDeclaration declaration) { + BaseType type = declaration.getType(); + + type.accept(this); + declaration.getLocalVariableDeclarators().accept(this); + } + + @Override + public void visit(LocalVariableDeclarator declarator) { + safeAccept(declarator.getVariableInitializer()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(LocalVariableDeclarators declarators) { + acceptListDeclaration(declarators); + } + + @Override + public void visit(MethodDeclaration declaration) { + BaseType returnedType = declaration.getReturnedType(); + + returnedType.accept(this); + safeAccept(declaration.getAnnotationReferences()); + safeAccept(declaration.getFormalParameters()); + safeAccept(declaration.getExceptionTypes()); + safeAccept(declaration.getStatements()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(MemberDeclarations declarations) { + acceptListDeclaration(declarations); + } + + @Override + public void visit(ModuleDeclaration declarations) {} + + @Override + @SuppressWarnings("unchecked") + public void visit(TypeDeclarations list) { + acceptListDeclaration(list); + } + + @Override + public void visit(ArrayExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + expression.getExpression().accept(this); + expression.getIndex().accept(this); + } + + @Override + public void visit(BinaryOperatorExpression expression) { + expression.getLeftExpression().accept(this); + expression.getRightExpression().accept(this); + } + + @Override + public void visit(BooleanExpression expression) {} + + @Override + public void visit(CastExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + expression.getExpression().accept(this); + } + + @Override + public void visit(ConstructorReferenceExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(DoubleConstantExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(EnumConstantReferenceExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(FieldReferenceExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + safeAccept(expression.getExpression()); + } + + @Override + public void visit(FloatConstantExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(IntegerConstantExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(InstanceOfExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + expression.getExpression().accept(this); + } + + @Override + public void visit(LambdaFormalParametersExpression expression) { + safeAccept(expression.getFormalParameters()); + expression.getStatements().accept(this); + } + + @Override + public void visit(LambdaIdentifiersExpression expression) { + safeAccept(expression.getStatements()); + } + + @Override public void visit(LengthExpression expression) { + expression.getExpression().accept(this); + } + + @Override + public void visit(LocalVariableReferenceExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(LongConstantExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(MethodInvocationExpression expression) { + expression.getExpression().accept(this); + safeAccept(expression.getNonWildcardTypeArguments()); + safeAccept(expression.getParameters()); + } + + @Override + public void visit(MethodReferenceExpression expression) { + expression.getExpression().accept(this); + } + + @Override + public void visit(NewArray expression) { + BaseType type = expression.getType(); + + type.accept(this); + safeAccept(expression.getDimensionExpressionList()); + } + + @Override + public void visit(NewExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + safeAccept(expression.getParameters()); + // safeAccept(expression.getBodyDeclaration()); + } + + @Override + public void visit(NewInitializedArray expression) { + BaseType type = expression.getType(); + + type.accept(this); + safeAccept(expression.getArrayInitializer()); + } + + @Override + public void visit(NoExpression expression) {} + + @Override + public void visit(NullExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(TypeReferenceDotClassExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(ObjectTypeReferenceExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(ParenthesesExpression expression) { + expression.getExpression().accept(this); + } + + @Override + public void visit(PostOperatorExpression expression) { + expression.getExpression().accept(this); + } + + @Override + public void visit(PreOperatorExpression expression) { + expression.getExpression().accept(this); + } + + @Override + public void visit(StringConstantExpression expression) {} + + @Override + public void visit(SuperConstructorInvocationExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + safeAccept(expression.getParameters()); + } + + @Override + public void visit(SuperExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(TernaryOperatorExpression expression) { + expression.getCondition().accept(this); + expression.getTrueExpression().accept(this); + expression.getFalseExpression().accept(this); + } + + @Override + public void visit(ThisExpression expression) { + BaseType type = expression.getType(); + + type.accept(this); + } + + @Override + public void visit(AnnotationReference reference) { + safeAccept(reference.getElementValue()); + safeAccept(reference.getElementValuePairs()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(AnnotationReferences list) { + acceptListReference(list); + } + + @Override + public void visit(ExpressionElementValue reference) { + reference.getExpression().accept(this); + } + + @Override + public void visit(ElementValueArrayInitializerElementValue reference) { + safeAccept(reference.getElementValueArrayInitializer()); + } + + @Override + public void visit(AnnotationElementValue reference) { + safeAccept(reference.getElementValue()); + safeAccept(reference.getElementValuePairs()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(ElementValues list) { + acceptListReference(list); + } + + @Override + public void visit(ElementValuePair reference) { + reference.getElementValue().accept(this); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(ElementValuePairs list) { + acceptListReference(list); + } + + @Override + public void visit(ObjectReference reference) { + visit((ObjectType) reference); + } + + @Override public void visit(InnerObjectReference reference) { + visit((InnerObjectType) reference); + } + + @Override + public void visit(AssertStatement statement) { + statement.getCondition().accept(this); + safeAccept(statement.getMessage()); + } + + @Override + public void visit(BreakStatement statement) {} + + @Override public void visit(ByteCodeStatement statement) {} + + @Override + public void visit(ContinueStatement statement) {} + + @Override + public void visit(DoWhileStatement statement) { + safeAccept(statement.getCondition()); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(ExpressionStatement statement) { + statement.getExpression().accept(this); + } + + @Override + public void visit(ForEachStatement statement) { + BaseType type = statement.getType(); + + type.accept(this); + statement.getExpression().accept(this); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(ForStatement statement) { + safeAccept(statement.getDeclaration()); + safeAccept(statement.getInit()); + safeAccept(statement.getCondition()); + safeAccept(statement.getUpdate()); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(IfStatement statement) { + statement.getCondition().accept(this); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(IfElseStatement statement) { + statement.getCondition().accept(this); + safeAccept(statement.getStatements()); + statement.getElseStatements().accept(this); + } + + @Override + public void visit(LabelStatement statement) { + safeAccept(statement.getStatement()); + } + + @Override + public void visit(LambdaExpressionStatement statement) { + statement.getExpression().accept(this); + } + + @Override + public void visit(LocalVariableDeclarationStatement statement) { + visit((LocalVariableDeclaration) statement); + } + + @Override + public void visit(NoStatement statement) {} + + @Override public void visit(ReturnExpressionStatement statement) { + statement.getExpression().accept(this); + } + + @Override + public void visit(ReturnStatement statement) {} + + @Override + @SuppressWarnings("unchecked") + public void visit(Statements list) { + acceptListStatement(list); + } + + @Override + public void visit(SwitchStatement statement) { + statement.getCondition().accept(this); + acceptListStatement(statement.getBlocks()); + } + + @Override + public void visit(SwitchStatement.DefaultLabel statement) {} + + @Override + public void visit(SwitchStatement.ExpressionLabel statement) { + statement.getExpression().accept(this); + } + + @Override + public void visit(SwitchStatement.LabelBlock statement) { + statement.getLabel().accept(this); + statement.getStatements().accept(this); + } + + @Override + public void visit(SwitchStatement.MultiLabelsBlock statement) { + safeAcceptListStatement(statement.getLabels()); + statement.getStatements().accept(this); + } + + @Override + public void visit(SynchronizedStatement statement) { + statement.getMonitor().accept(this); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(ThrowStatement statement) { + statement.getExpression().accept(this); + } + + @Override + public void visit(TryStatement statement) { + safeAcceptListStatement(statement.getResources()); + statement.getTryStatements().accept(this); + safeAcceptListStatement(statement.getCatchClauses()); + safeAccept(statement.getFinallyStatements()); + } + + @Override + public void visit(TryStatement.CatchClause statement) { + BaseType type = statement.getType(); + + type.accept(this); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(TryStatement.Resource statement) { + BaseType type = statement.getType(); + + type.accept(this); + statement.getExpression().accept(this); + } + + @Override + public void visit(StaticInitializerDeclaration declaration) { + safeAccept(declaration.getStatements()); + } + + @Override + public void visit(TypeDeclarationStatement statement) { + statement.getTypeDeclaration().accept(this); + } + + @Override + public void visit(WhileStatement statement) { + statement.getCondition().accept(this); + safeAccept(statement.getStatements()); + } + + @Override + public void visit(TypeParameter parameter) {} + + @Override + public void visit(TypeParameterWithTypeBounds parameter) { + parameter.getTypeBounds().accept(this); + } + + @Override + public void visit(TypeParameters parameters) { + Iterator iterator = parameters.iterator(); + + while (iterator.hasNext()) + iterator.next().accept(this); + } + + public void visit(TypeDeclaration declaration) { + safeAccept(declaration.getAnnotationReferences()); + } + + @Override + @SuppressWarnings("unchecked") + public void visit(Types types) { + Iterator iterator = types.iterator(); + + while (iterator.hasNext()) { + BaseType type = iterator.next(); + + type.accept(this); + } + } + + public void acceptListDeclaration(List list) { + for (Declaration declaration : list) + declaration.accept(this); + } + + public void acceptListExpression(List list) { + for (Expression expression : list) + expression.accept(this); + } + + public void acceptListReference(List list) { + for (Reference reference : list) + reference.accept(this); + } + + public void acceptListStatement(List list) { + for (Statement statement : list) + statement.accept(this); + } + + public void safeAccept(Declaration declaration) { + if (declaration != null) + declaration.accept(this); + } + + public void safeAccept(BaseExpression expression) { + if (expression != null) + expression.accept(this); + } + + public void safeAccept(Reference reference) { + if (reference != null) + reference.accept(this); + } + + public void safeAccept(BaseStatement list) { + if (list != null) + list.accept(this); + } + + public void safeAccept(BaseType list) { + if (list != null) + list.accept(this); + } + + public void safeAccept(BaseTypeParameter list) { + if (list != null) + list.accept(this); + } + + public void safeAcceptListDeclaration(List list) { + if (list != null) { + for (Declaration declaration : list) + declaration.accept(this); + } + } + + public void safeAcceptListStatement(List list) { + if (list != null) { + for (Statement statement : list) + statement.accept(this); + } + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/CompilationUnit.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/CompilationUnit.java new file mode 100644 index 00000000..588eebb2 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/CompilationUnit.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax; + +import org.jd.core.v1.model.javasyntax.declaration.BaseTypeDeclaration; + +public class CompilationUnit { + protected BaseTypeDeclaration typeDeclarations; + + public CompilationUnit(BaseTypeDeclaration typeDeclarations) { + this.typeDeclarations = typeDeclarations; + } + + public BaseTypeDeclaration getTypeDeclarations() { + return typeDeclarations; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/AbstractNopDeclarationVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/AbstractNopDeclarationVisitor.java new file mode 100644 index 00000000..e4d3f019 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/AbstractNopDeclarationVisitor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public abstract class AbstractNopDeclarationVisitor implements DeclarationVisitor { + @Override public void visit(AnnotationDeclaration declaration) {} + @Override public void visit(ArrayVariableInitializer declaration) {} + @Override public void visit(BodyDeclaration declaration) {} + @Override public void visit(ClassDeclaration declaration) {} + @Override public void visit(ConstructorDeclaration declaration) {} + @Override public void visit(EnumDeclaration declaration) {} + @Override public void visit(EnumDeclaration.Constant declaration) {} + @Override public void visit(ExpressionVariableInitializer declaration) {} + @Override public void visit(FieldDeclaration declaration) {} + @Override public void visit(FieldDeclarator declaration) {} + @Override public void visit(FieldDeclarators declarations) {} + @Override public void visit(FormalParameter declaration) {} + @Override public void visit(FormalParameters declarations) {} + @Override public void visit(InstanceInitializerDeclaration declaration) {} + @Override public void visit(InterfaceDeclaration declaration) {} + @Override public void visit(LocalVariableDeclaration declaration) {} + @Override public void visit(LocalVariableDeclarator declarator) {} + @Override public void visit(LocalVariableDeclarators declarators) {} + @Override public void visit(MemberDeclarations declarations) {} + @Override public void visit(MethodDeclaration declaration) {} + @Override public void visit(ModuleDeclaration declarations) {} + @Override public void visit(StaticInitializerDeclaration declaration) {} + @Override public void visit(TypeDeclarations declaration) {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/AnnotationDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/AnnotationDeclaration.java new file mode 100644 index 00000000..c8cebe38 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/AnnotationDeclaration.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; + +public class AnnotationDeclaration extends TypeDeclaration { + protected BaseFieldDeclarator annotationDeclarators; + + public AnnotationDeclaration(BaseAnnotationReference annotationReferences, int flags, String internalName, String name, BaseFieldDeclarator annotationDeclarators, BodyDeclaration bodyDeclaration) { + super(annotationReferences, flags, internalName, name, bodyDeclaration); + this.annotationDeclarators = annotationDeclarators; + } + + public BaseFieldDeclarator getAnnotationDeclarators() { + return annotationDeclarators; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "AnnotationDeclaration{" + internalTypeName + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ArrayVariableInitializer.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ArrayVariableInitializer.java new file mode 100644 index 00000000..481d0321 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ArrayVariableInitializer.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.type.Type; +import org.jd.core.v1.util.DefaultList; + +public class ArrayVariableInitializer extends DefaultList implements VariableInitializer { + protected Type type; + + public ArrayVariableInitializer(Type type) { + this.type = type; + } + + public Type getType() { + return type; + } + + @Override + public int getLineNumber() { + return isEmpty() ? 0 : get(0).getLineNumber(); + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseFieldDeclarator.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseFieldDeclarator.java new file mode 100644 index 00000000..833c3afa --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseFieldDeclarator.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.Base; + +public interface BaseFieldDeclarator extends Declaration, Base { + void setFieldDeclaration(FieldDeclaration fieldDeclaration); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseFormalParameter.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseFormalParameter.java new file mode 100644 index 00000000..67f1c57c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseFormalParameter.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.Base; + +public interface BaseFormalParameter extends Declaration, Base {} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseLocalVariableDeclarator.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseLocalVariableDeclarator.java new file mode 100644 index 00000000..b1722884 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseLocalVariableDeclarator.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.Base; + +public interface BaseLocalVariableDeclarator extends Declaration, Base { + int getLineNumber(); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseMemberDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseMemberDeclaration.java new file mode 100644 index 00000000..fdcd41ec --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseMemberDeclaration.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.Base; + +public interface BaseMemberDeclaration extends Declaration, Base { + default boolean isClassDeclaration() { return false; } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseTypeDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseTypeDeclaration.java new file mode 100644 index 00000000..385ea64b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BaseTypeDeclaration.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public interface BaseTypeDeclaration extends BaseMemberDeclaration { +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BodyDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BodyDeclaration.java new file mode 100644 index 00000000..dad65f66 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/BodyDeclaration.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public class BodyDeclaration implements Declaration { + protected String internalTypeName; + protected BaseMemberDeclaration memberDeclarations; + + public BodyDeclaration(String internalTypeName, BaseMemberDeclaration memberDeclarations) { + this.internalTypeName = internalTypeName; + this.memberDeclarations = memberDeclarations; + } + + public String getInternalTypeName() { + return internalTypeName; + } + + public BaseMemberDeclaration getMemberDeclarations() { + return memberDeclarations; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ClassDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ClassDeclaration.java new file mode 100644 index 00000000..efa944f2 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ClassDeclaration.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.type.BaseType; +import org.jd.core.v1.model.javasyntax.type.BaseTypeParameter; +import org.jd.core.v1.model.javasyntax.type.ObjectType; + +public class ClassDeclaration extends InterfaceDeclaration { + protected ObjectType superType; + + public ClassDeclaration(int flags, String internalName, String name, BodyDeclaration bodyDeclaration) { + super(null, flags, internalName, name, null, null, bodyDeclaration); + } + + public ClassDeclaration(BaseAnnotationReference annotationReferences, int flags, String internalName, String name, BaseTypeParameter typeParameters, ObjectType superType, BaseType interfaces, BodyDeclaration bodyDeclaration) { + super(annotationReferences, flags, internalName, name, typeParameters, interfaces, bodyDeclaration); + this.superType = superType; + } + + public ObjectType getSuperType() { + return superType; + } + + @Override + public boolean isClassDeclaration() { return true; } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ClassDeclaration{" + internalTypeName + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ConstructorDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ConstructorDeclaration.java new file mode 100644 index 00000000..9c2ea836 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ConstructorDeclaration.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; +import org.jd.core.v1.model.javasyntax.type.BaseType; +import org.jd.core.v1.model.javasyntax.type.BaseTypeParameter; + +import static org.jd.core.v1.model.classfile.Constants.ACC_STATIC; + +public class ConstructorDeclaration implements MemberDeclaration { + protected BaseAnnotationReference annotationReferences; + protected int flags; + protected BaseTypeParameter typeParameters; + protected BaseFormalParameter formalParameters; + protected BaseType exceptionTypes; + protected String descriptor; + protected BaseStatement statements; + + public ConstructorDeclaration(int flags, BaseFormalParameter formalParameters, String descriptor, BaseStatement statements) { + this.flags = flags; + this.formalParameters = formalParameters; + this.descriptor = descriptor; + this.statements = statements; + } + + public ConstructorDeclaration(BaseAnnotationReference annotationReferences, int flags, BaseTypeParameter typeParameters, BaseFormalParameter formalParameters, BaseType exceptionTypes, String descriptor, BaseStatement statements) { + this.annotationReferences = annotationReferences; + this.flags = flags; + this.typeParameters = typeParameters; + this.formalParameters = formalParameters; + this.exceptionTypes = exceptionTypes; + this.descriptor = descriptor; + this.statements = statements; + } + + public int getFlags() { + return flags; + } + public void setFlags(int flags) { + this.flags = flags; + } + + public boolean isStatic() { return (flags & ACC_STATIC) != 0; } + + public BaseAnnotationReference getAnnotationReferences() { + return annotationReferences; + } + + public BaseTypeParameter getTypeParameters() { + return typeParameters; + } + + public BaseFormalParameter getFormalParameters() { + return formalParameters; + } + + public BaseType getExceptionTypes() { + return exceptionTypes; + } + + public String getDescriptor() { + return descriptor; + } + + public BaseStatement getStatements() { + return statements; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ConstructorDeclaration{" + descriptor + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/Declaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/Declaration.java new file mode 100644 index 00000000..e6cfd0c9 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/Declaration.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public interface Declaration { + // Access flags for Class, Field, Method, Nested class, Module, Module Requires, Module Exports, Module Opens + int FLAG_PUBLIC = 0x0001; // C F M N . . . . + int FLAG_PRIVATE = 0x0002; // . F M N . . . . + int FLAG_PROTECTED = 0x0004; // . F M N . . . . + int FLAG_STATIC = 0x0008; // C F M N . . . . + int FLAG_FINAL = 0x0010; // C F M N . . . . + int FLAG_SYNCHRONIZED = 0x0020; // . . M . . . . . + int FLAG_SUPER = 0x0020; // C . . . . . . . + int FLAG_OPEN = 0x0020; // . . . . Mo . . . + int FLAG_TRANSITIVE = 0x0020; // . . . . . MR . . + int FLAG_VOLATILE = 0x0040; // . F . . . . . . + int FLAG_BRIDGE = 0x0040; // . . M . . . . . + int FLAG_STATIC_PHASE = 0x0040; // . . . . . MR . . + int FLAG_TRANSIENT = 0x0080; // . F . . . . . . + int FLAG_VARARGS = 0x0080; // . . M . . . . . + int FLAG_NATIVE = 0x0100; // . . M . . . . . + int FLAG_INTERFACE = 0x0200; // C . . N . . . . + int FLAG_ANONYMOUS = 0x0200; // . . M . . . . . // Custom flag + int FLAG_ABSTRACT = 0x0400; // C . M N . . . . + int FLAG_STRICT = 0x0800; // . . M . . . . . + int FLAG_SYNTHETIC = 0x1000; // C F M N Mo MR ME MO + int FLAG_ANNOTATION = 0x2000; // C . . N . . . . + int FLAG_ENUM = 0x4000; // C F . N . . . . + int FLAG_MODULE = 0x8000; // C . . . . . . . + int FLAG_MANDATED = 0x8000; // . . . . Mo MR ME MO + + // Extension + int FLAG_DEFAULT = 0x10000; // . . M . . . . . + + void accept(DeclarationVisitor visitor); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/DeclarationVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/DeclarationVisitor.java new file mode 100644 index 00000000..90fbfa2e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/DeclarationVisitor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public interface DeclarationVisitor { + void visit(AnnotationDeclaration declaration); + void visit(ArrayVariableInitializer declaration); + void visit(BodyDeclaration declaration); + void visit(ClassDeclaration declaration); + void visit(ConstructorDeclaration declaration); + void visit(EnumDeclaration declaration); + void visit(EnumDeclaration.Constant declaration); + void visit(ExpressionVariableInitializer declaration); + void visit(FieldDeclaration declaration); + void visit(FieldDeclarator declaration); + void visit(FieldDeclarators declarations); + void visit(FormalParameter declaration); + void visit(FormalParameters declarations); + void visit(InstanceInitializerDeclaration declaration); + void visit(InterfaceDeclaration declaration); + void visit(LocalVariableDeclaration declaration); + void visit(LocalVariableDeclarator declarator); + void visit(LocalVariableDeclarators declarators); + void visit(MethodDeclaration declaration); + void visit(MemberDeclarations declarations); + void visit(ModuleDeclaration declarations); + void visit(StaticInitializerDeclaration declaration); + void visit(TypeDeclarations declarations); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/EnumDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/EnumDeclaration.java new file mode 100644 index 00000000..abf427d6 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/EnumDeclaration.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.expression.BaseExpression; +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.type.BaseType; + +import java.util.List; + +public class EnumDeclaration extends TypeDeclaration { + protected BaseType interfaces; + protected List constants; + + public EnumDeclaration(int flags, String internalName, String name, List constants, BodyDeclaration bodyDeclaration) { + super(null, flags, internalName, name, bodyDeclaration); + this.constants = constants; + } + + public EnumDeclaration(BaseAnnotationReference annotationReferences, int flags, String internalName, String name, BaseType interfaces, List constants, BodyDeclaration bodyDeclaration) { + super(annotationReferences, flags, internalName, name, bodyDeclaration); + this.interfaces = interfaces; + this.constants = constants; + } + + public BaseType getInterfaces() { + return interfaces; + } + + public List getConstants() { + return constants; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "EnumDeclaration{" + internalTypeName + "}"; + } + + public static class Constant implements Declaration { + protected int lineNumber; + protected BaseAnnotationReference annotationReferences; + protected String name; + protected BaseExpression arguments; + protected BodyDeclaration bodyDeclaration; + + public Constant(String name) { + this.name = name; + } + + public Constant(int lineNumber, String name) { + this.lineNumber = lineNumber; + this.name = name; + } + + public Constant(String name, BaseExpression arguments) { + this.name = name; + this.arguments = arguments; + } + + public Constant(int lineNumber, String name, BaseExpression arguments) { + this.lineNumber = lineNumber; + this.name = name; + this.arguments = arguments; + } + + public Constant(int lineNumber, String name, BaseExpression arguments, BodyDeclaration bodyDeclaration) { + this.lineNumber = lineNumber; + this.name = name; + this.arguments = arguments; + this.bodyDeclaration = bodyDeclaration; + } + + public Constant(int lineNumber, BaseAnnotationReference annotationReferences, String name, BaseExpression arguments, BodyDeclaration bodyDeclaration) { + this.lineNumber = lineNumber; + this.annotationReferences = annotationReferences; + this.name = name; + this.arguments = arguments; + this.bodyDeclaration = bodyDeclaration; + } + + public int getLineNumber() { + return lineNumber; + } + + public BaseAnnotationReference getAnnotationReferences() { + return annotationReferences; + } + + public String getName() { + return name; + } + + public BaseExpression getArguments() { + return arguments; + } + + public void setArguments(BaseExpression arguments) { + this.arguments = arguments; + } + + public BodyDeclaration getBodyDeclaration() { + return bodyDeclaration; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ExpressionVariableInitializer.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ExpressionVariableInitializer.java new file mode 100644 index 00000000..da76d58c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ExpressionVariableInitializer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class ExpressionVariableInitializer implements VariableInitializer { + protected Expression expression; + + public ExpressionVariableInitializer(Expression expression) { + this.expression = expression; + } + + @Override + public Expression getExpression() { + return expression; + } + + @Override + public int getLineNumber() { + return expression.getLineNumber(); + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ExpressionVariableInitializer)) return false; + + ExpressionVariableInitializer that = (ExpressionVariableInitializer) o; + + if (expression != null ? !expression.equals(that.expression) : that.expression != null) return false; + + return true; + } + + @Override + public int hashCode() { + return 25107399 + (expression != null ? expression.hashCode() : 0); + } + + @Override + public boolean isExpressionVariableInitializer() { return true; } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclaration.java new file mode 100644 index 00000000..2ec31146 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclaration.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class FieldDeclaration implements MemberDeclaration { + protected BaseAnnotationReference annotationReferences; + protected int flags; + protected Type type; + protected BaseFieldDeclarator fieldDeclarators; + + public FieldDeclaration(int flags, Type type, BaseFieldDeclarator fieldDeclarators) { + this.flags = flags; + this.type = type; + this.fieldDeclarators = fieldDeclarators; + fieldDeclarators.setFieldDeclaration(this); + } + + public FieldDeclaration(BaseAnnotationReference annotationReferences, int flags, Type type, BaseFieldDeclarator fieldDeclarators) { + this.flags = flags; + this.annotationReferences = annotationReferences; + this.type = type; + this.fieldDeclarators = fieldDeclarators; + fieldDeclarators.setFieldDeclaration(this); + } + + public int getFlags() { + return flags; + } + + public void setFlags(int flags) { + this.flags = flags; + } + + public BaseAnnotationReference getAnnotationReferences() { + return annotationReferences; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public BaseFieldDeclarator getFieldDeclarators() { + return fieldDeclarators; + } + + public void setFieldDeclarators(BaseFieldDeclarator fieldDeclarators) { + this.fieldDeclarators = fieldDeclarators; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FieldDeclaration)) return false; + + FieldDeclaration that = (FieldDeclaration) o; + + if (flags != that.flags) return false; + if (annotationReferences != null ? !annotationReferences.equals(that.annotationReferences) : that.annotationReferences != null) + return false; + if (!fieldDeclarators.equals(that.fieldDeclarators)) return false; + if (!type.equals(that.type)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = 327494460 + flags; + result = 31 * result + (annotationReferences != null ? annotationReferences.hashCode() : 0); + result = 31 * result + type.hashCode(); + result = 31 * result + fieldDeclarators.hashCode(); + return result; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "FieldDeclaration{" + type + " " + fieldDeclarators + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclarator.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclarator.java new file mode 100644 index 00000000..35527578 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclarator.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public class FieldDeclarator implements BaseFieldDeclarator { + protected FieldDeclaration fieldDeclaration; + protected String name; + protected int dimension; + protected VariableInitializer variableInitializer; + + public FieldDeclarator(String name) { + this.name = name; + } + + public FieldDeclarator(String name, VariableInitializer variableInitializer) { + this.name = name; + this.variableInitializer = variableInitializer; + } + + public FieldDeclarator(String name, int dimension, VariableInitializer variableInitializer) { + this.name = name; + this.dimension = dimension; + this.variableInitializer = variableInitializer; + } + + @Override + public void setFieldDeclaration(FieldDeclaration fieldDeclaration) { + this.fieldDeclaration = fieldDeclaration; + } + + public FieldDeclaration getFieldDeclaration() { + return fieldDeclaration; + } + + public String getName() { + return name; + } + + public int getDimension() { + return dimension; + } + + public VariableInitializer getVariableInitializer() { + return variableInitializer; + } + + public void setVariableInitializer(VariableInitializer variableInitializer) { + this.variableInitializer = variableInitializer; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FieldDeclarator)) return false; + + FieldDeclarator that = (FieldDeclarator) o; + + if (dimension != that.dimension) return false; + if (!name.equals(that.name)) return false; + if (variableInitializer != null ? !variableInitializer.equals(that.variableInitializer) : that.variableInitializer != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = 544278669 + name.hashCode(); + result = 31 * result + dimension; + result = 31 * result + (variableInitializer != null ? variableInitializer.hashCode() : 0); + return result; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "FieldDeclarator{" + name + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclarators.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclarators.java new file mode 100644 index 00000000..30ea9587 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FieldDeclarators.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class FieldDeclarators extends DefaultList implements BaseFieldDeclarator { + public FieldDeclarators() {} + + public FieldDeclarators(int capacity) { + super(capacity); + } + + public FieldDeclarators(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'FieldDeclarator' instead"; + } + + @SuppressWarnings("unchecked") + public FieldDeclarators(FieldDeclarator declarator, FieldDeclarator... declarators) { + super(declarator, declarators); + assert (declarators != null) && (declarators.length > 0) : "Uses 'FieldDeclarator' instead"; + } + + @Override + public void setFieldDeclaration(FieldDeclaration fieldDeclaration) { + for (FieldDeclarator fieldDeclarator : this) { + fieldDeclarator.setFieldDeclaration(fieldDeclaration); + } + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FormalParameter.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FormalParameter.java new file mode 100644 index 00000000..e20d5a34 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FormalParameter.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class FormalParameter implements BaseFormalParameter { + protected BaseAnnotationReference annotationReferences; + protected boolean fina1; + protected Type type; + protected boolean varargs; + protected String name; + + public FormalParameter(Type type, String name) { + this.type = type; + this.name = name; + } + + public FormalParameter(BaseAnnotationReference annotationReferences, Type type, String name) { + this.annotationReferences = annotationReferences; + this.type = type; + this.name = name; + } + + public FormalParameter(Type type, boolean varargs, String name) { + this.type = type; + this.varargs = varargs; + this.name = name; + } + + public FormalParameter(BaseAnnotationReference annotationReferences, Type type, boolean varargs, String name) { + this.annotationReferences = annotationReferences; + this.type = type; + this.varargs = varargs; + this.name = name; + } + + public BaseAnnotationReference getAnnotationReferences() { + return annotationReferences; + } + + public boolean isFinal() { + return fina1; + } + + public void setFinal(boolean fina1) { + this.fina1 = fina1; + } + + public Type getType() { + return type; + } + + public boolean isVarargs() { + return varargs; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + String s = "FormalParameter{"; + + if (annotationReferences != null) + s += annotationReferences + " "; + + if (varargs) + s += type.createType(type.getDimension()-1) + "... "; + else + s += type + " "; + + return s + name + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FormalParameters.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FormalParameters.java new file mode 100644 index 00000000..7e5a4cdd --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/FormalParameters.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class FormalParameters extends DefaultList implements BaseFormalParameter { + public FormalParameters() {} + + public FormalParameters(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'FormalParameter' instead"; + } + + @SuppressWarnings("unchecked") + public FormalParameters(FormalParameter parameter, FormalParameter... parameters) { + super(parameter, parameters); + assert (parameters != null) && (parameters.length > 0) : "Uses 'FormalParameter' instead"; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/InstanceInitializerDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/InstanceInitializerDeclaration.java new file mode 100644 index 00000000..307a4ccb --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/InstanceInitializerDeclaration.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; + +public class InstanceInitializerDeclaration implements MemberDeclaration { + protected String descriptor; + protected BaseStatement statements; + + public InstanceInitializerDeclaration(String descriptor, BaseStatement statements) { + this.descriptor = descriptor; + this.statements = statements; + } + + public String getDescriptor() { + return descriptor; + } + + public BaseStatement getStatements() { + return statements; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "InstanceInitializerDeclaration{}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/InterfaceDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/InterfaceDeclaration.java new file mode 100644 index 00000000..3080f029 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/InterfaceDeclaration.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.type.BaseType; +import org.jd.core.v1.model.javasyntax.type.BaseTypeParameter; + +public class InterfaceDeclaration extends TypeDeclaration { + protected BaseTypeParameter typeParameters; + protected BaseType interfaces; + + public InterfaceDeclaration(int flags, String internalName, String name, BaseType interfaces) { + super(null, flags, internalName, name, null); + this.interfaces = interfaces; + } + + public InterfaceDeclaration(BaseAnnotationReference annotationReferences, int flags, String internalName, String name, BaseTypeParameter typeParameters, BaseType interfaces, BodyDeclaration bodyDeclaration) { + super(annotationReferences, flags, internalName, name, bodyDeclaration); + this.typeParameters = typeParameters; + this.interfaces = interfaces; + } + + public BaseTypeParameter getTypeParameters() { + return typeParameters; + } + + public BaseType getInterfaces() { + return interfaces; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "InterfaceDeclaration{" + internalTypeName + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclaration.java new file mode 100644 index 00000000..870e3fb8 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclaration.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class LocalVariableDeclaration implements Declaration { + protected boolean fina1 = false; + protected Type type; + protected BaseLocalVariableDeclarator localVariableDeclarators; + + public LocalVariableDeclaration(Type type, BaseLocalVariableDeclarator localVariableDeclarators) { + this.type = type; + this.localVariableDeclarators = localVariableDeclarators; + } + + public boolean isFinal() { + return fina1; + } + + public void setFinal(boolean fina1) { + this.fina1 = fina1; + } + + public Type getType() { + return type; + } + + public BaseLocalVariableDeclarator getLocalVariableDeclarators() { + return localVariableDeclarators; + } + + public void setLocalVariableDeclarators(BaseLocalVariableDeclarator localVariableDeclarators) { + this.localVariableDeclarators = localVariableDeclarators; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclarator.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclarator.java new file mode 100644 index 00000000..56f074a3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclarator.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public class LocalVariableDeclarator implements BaseLocalVariableDeclarator { + protected int lineNumber; + protected String name; + protected int dimension; + protected VariableInitializer variableInitializer; + + public LocalVariableDeclarator(String name) { + this.name = name; + } + + public LocalVariableDeclarator(String name, VariableInitializer variableInitializer) { + this.name = name; + this.variableInitializer = variableInitializer; + } + + public LocalVariableDeclarator(int lineNumber, String name, VariableInitializer variableInitializer) { + this.lineNumber = lineNumber; + this.name = name; + this.variableInitializer = variableInitializer; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getDimension() { + return dimension; + } + + public void setDimension(int dimension) { + this.dimension = dimension; + } + + @Override + public int getLineNumber() { + return lineNumber; + } + + public VariableInitializer getVariableInitializer() { + return variableInitializer; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LocalVariableDeclarator{name=" + name + ", dimension" + dimension + ", variableInitializer=" + variableInitializer + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclarators.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclarators.java new file mode 100644 index 00000000..f1f31d0e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/LocalVariableDeclarators.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class LocalVariableDeclarators extends DefaultList implements BaseLocalVariableDeclarator { + + public LocalVariableDeclarators() {} + + public LocalVariableDeclarators(int capacity) { + super(capacity); + } + + public LocalVariableDeclarators(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'LocalVariableDeclarator' instead"; + } + + @Override + public int getLineNumber() { + return isEmpty() ? 0 : get(0).getLineNumber(); + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MemberDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MemberDeclaration.java new file mode 100644 index 00000000..6d35973d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MemberDeclaration.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +public interface MemberDeclaration extends BaseMemberDeclaration { +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MemberDeclarations.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MemberDeclarations.java new file mode 100644 index 00000000..912fd7fe --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MemberDeclarations.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class MemberDeclarations extends DefaultList implements BaseMemberDeclaration { + public MemberDeclarations() {} + + public MemberDeclarations(int capacity) { + super(capacity); + } + + public MemberDeclarations(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'MemberDeclaration' implementation instead"; + } + + @SuppressWarnings("unchecked") + public MemberDeclarations(MemberDeclaration declaration, MemberDeclaration... declarations) { + super(declaration, declarations); + assert (declarations != null) && (declarations.length > 0) : "Uses 'MemberDeclaration' implementation instead"; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MethodDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MethodDeclaration.java new file mode 100644 index 00000000..73818faf --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/MethodDeclaration.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; +import org.jd.core.v1.model.javasyntax.reference.ElementValue; +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; +import org.jd.core.v1.model.javasyntax.type.BaseType; +import org.jd.core.v1.model.javasyntax.type.BaseTypeParameter; +import org.jd.core.v1.model.javasyntax.type.Type; + +import static org.jd.core.v1.model.classfile.Constants.ACC_STATIC; + +public class MethodDeclaration implements MemberDeclaration { + protected BaseAnnotationReference annotationReferences; + protected int flags; + protected String name; + protected BaseTypeParameter typeParameters; + protected Type returnedType; + protected BaseFormalParameter formalParameters; + protected BaseType exceptionTypes; + protected String descriptor; + protected BaseStatement statements; + protected ElementValue defaultAnnotationValue; + + public MethodDeclaration(int flags, String name, Type returnedType, String descriptor) { + this.flags = flags; + this.name = name; + this.returnedType = returnedType; + this.descriptor = descriptor; + } + + public MethodDeclaration(int flags, String name, Type returnedType, String descriptor, BaseStatement statements) { + this.flags = flags; + this.name = name; + this.returnedType = returnedType; + this.descriptor = descriptor; + this.statements = statements; + } + + public MethodDeclaration(int flags, String name, Type returnedType, String descriptor, ElementValue defaultAnnotationValue) { + this.flags = flags; + this.name = name; + this.returnedType = returnedType; + this.descriptor = descriptor; + this.defaultAnnotationValue = defaultAnnotationValue; + } + + public MethodDeclaration(int flags, String name, Type returnedType, BaseFormalParameter formalParameters, String descriptor, BaseStatement statements) { + this.flags = flags; + this.name = name; + this.returnedType = returnedType; + this.formalParameters = formalParameters; + this.descriptor = descriptor; + this.statements = statements; + } + + public MethodDeclaration(int flags, String name, Type returnedType, BaseFormalParameter formalParameters, String descriptor, ElementValue defaultAnnotationValue) { + this.flags = flags; + this.name = name; + this.returnedType = returnedType; + this.formalParameters = formalParameters; + this.descriptor = descriptor; + this.defaultAnnotationValue = defaultAnnotationValue; + } + + public MethodDeclaration(BaseAnnotationReference annotationReferences, int flags, String name, BaseTypeParameter typeParameters, Type returnedType, BaseFormalParameter formalParameters, BaseType exceptionTypes, String descriptor, BaseStatement statements, ElementValue defaultAnnotationValue) { + this.annotationReferences = annotationReferences; + this.flags = flags; + this.name = name; + this.typeParameters = typeParameters; + this.returnedType = returnedType; + this.formalParameters = formalParameters; + this.exceptionTypes = exceptionTypes; + this.descriptor = descriptor; + this.statements = statements; + this.defaultAnnotationValue = defaultAnnotationValue; + } + + public BaseAnnotationReference getAnnotationReferences() { + return annotationReferences; + } + + public int getFlags() { + return flags; + } + + public boolean isStatic() { return (flags & ACC_STATIC) != 0; } + + public String getName() { + return name; + } + + public BaseTypeParameter getTypeParameters() { + return typeParameters; + } + + public Type getReturnedType() { + return returnedType; + } + + public BaseFormalParameter getFormalParameters() { + return formalParameters; + } + + public BaseType getExceptionTypes() { + return exceptionTypes; + } + + public String getDescriptor() { + return descriptor; + } + + public BaseStatement getStatements() { + return statements; + } + + public ElementValue getDefaultAnnotationValue() { + return defaultAnnotationValue; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "MethodDeclaration{" + name + " " + descriptor + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ModuleDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ModuleDeclaration.java new file mode 100644 index 00000000..50617ef2 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/ModuleDeclaration.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import java.util.List; + +public class ModuleDeclaration extends TypeDeclaration { + protected String version; + protected List requires; + protected List exports; + protected List opens; + protected List uses; + protected List provides; + + public ModuleDeclaration(int flags, String internalName, String name, String version, List requires, List exports, List opens, List uses, List provides) { + super(null, flags, internalName, name, null); + this.version = version; + this.requires = requires; + this.exports = exports; + this.opens = opens; + this.uses = uses; + this.provides = provides; + } + + public String getVersion() { return version; } + public List getRequires() { return requires; } + public List getExports() { return exports; } + public List getOpens() { return opens; } + public List getUses() { return uses; } + public List getProvides() { return provides; } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ModuleDeclaration{" + internalTypeName + "}"; + } + + public static class ModuleInfo { + protected String name; + protected int flags; + protected String version; + + public ModuleInfo(String name, int flags, String version) { + this.name = name; + this.flags = flags; + this.version = version; + } + + public String getName() { return name; } + public int getFlags() { return flags; } + public String getVersion() { return version; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("ModuleInfo{name=").append(name); + sb.append(", flags=").append(flags); + + if (version != null) { + sb.append(", version=").append(version); + } + + return sb.append("}").toString(); + } + } + + public static class PackageInfo { + protected String internalName; + protected int flags; + protected List moduleInfoNames; + + public PackageInfo(String internalName, int flags, List moduleInfoNames) { + this.internalName = internalName; + this.flags = flags; + this.moduleInfoNames = moduleInfoNames; + } + + public String getInternalName() { return internalName; } + public int getFlags() { return flags; } + public List getModuleInfoNames() { return moduleInfoNames; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("PackageInfo{internalName=").append(internalName); + sb.append(", flags=").append(flags); + + if (moduleInfoNames != null) { + sb.append(", moduleInfoNames=").append(moduleInfoNames); + } + + return sb.append("}").toString(); + } + } + + public static class ServiceInfo { + protected String interfaceTypeName; + protected List implementationTypeNames; + + public ServiceInfo(String interfaceTypeName, List implementationTypeNames) { + this.interfaceTypeName = interfaceTypeName; + this.implementationTypeNames = implementationTypeNames; + } + + public String getInterfaceTypeName() { return interfaceTypeName; } + public List getImplementationTypeNames() { return implementationTypeNames; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("ServiceInfo{interfaceTypeName=").append(interfaceTypeName); + + if (implementationTypeNames != null) { + sb.append(", implementationTypeNames=").append(implementationTypeNames); + } + + return sb.append("}").toString(); + } + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/StaticInitializerDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/StaticInitializerDeclaration.java new file mode 100644 index 00000000..24e0bd8a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/StaticInitializerDeclaration.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; + +public class StaticInitializerDeclaration implements MemberDeclaration { + protected String descriptor; + protected BaseStatement statements; + + public StaticInitializerDeclaration(String descriptor, BaseStatement statements) { + this.descriptor = descriptor; + this.statements = statements; + } + + public String getDescriptor() { + return descriptor; + } + + public BaseStatement getStatements() { + return statements; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "StaticInitializerDeclaration{}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/TypeDeclaration.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/TypeDeclaration.java new file mode 100644 index 00000000..2554ab28 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/TypeDeclaration.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.reference.BaseAnnotationReference; + +public abstract class TypeDeclaration implements BaseTypeDeclaration, MemberDeclaration { + protected BaseAnnotationReference annotationReferences; + protected int flags; + protected String internalTypeName; + protected String name; + protected BodyDeclaration bodyDeclaration; + + protected TypeDeclaration(BaseAnnotationReference annotationReferences, int flags, String internalTypeName, String name, BodyDeclaration bodyDeclaration) { + this.annotationReferences = annotationReferences; + this.flags = flags; + this.internalTypeName = internalTypeName; + this.name = name; + this.bodyDeclaration = bodyDeclaration; + } + + public BaseAnnotationReference getAnnotationReferences() { + return annotationReferences; + } + + public int getFlags() { + return flags; + } + + public String getInternalTypeName() { + return internalTypeName; + } + + public String getName() { + return name; + } + + public BodyDeclaration getBodyDeclaration() { + return bodyDeclaration; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/TypeDeclarations.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/TypeDeclarations.java new file mode 100644 index 00000000..300c7102 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/TypeDeclarations.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class TypeDeclarations extends DefaultList implements BaseTypeDeclaration { + public TypeDeclarations(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'TypeDeclaration' or sub class instead"; + } + + @Override + public void accept(DeclarationVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/VariableInitializer.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/VariableInitializer.java new file mode 100644 index 00000000..fe2d01d9 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/declaration/VariableInitializer.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.declaration; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +import static org.jd.core.v1.model.javasyntax.expression.NoExpression.NO_EXPRESSION; + +public interface VariableInitializer extends Declaration { + int getLineNumber(); + + default boolean isExpressionVariableInitializer() { return false; } + + default Expression getExpression() { return NO_EXPRESSION; } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLambdaExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLambdaExpression.java new file mode 100644 index 00000000..71a374aa --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLambdaExpression.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; +import org.jd.core.v1.model.javasyntax.type.Type; + +public abstract class AbstractLambdaExpression extends AbstractLineNumberTypeExpression { + protected BaseStatement statements; + + protected AbstractLambdaExpression(Type type, BaseStatement statements) { + super(type); + this.statements = statements; + } + + protected AbstractLambdaExpression(int lineNumber, Type type, BaseStatement statements) { + super(lineNumber, type); + this.statements = statements; + } + + @Override + public int getPriority() { + return 17; + } + + public BaseStatement getStatements() { + return statements; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLineNumberExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLineNumberExpression.java new file mode 100644 index 00000000..38b950bb --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLineNumberExpression.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +public abstract class AbstractLineNumberExpression implements Expression { + protected int lineNumber; + + protected AbstractLineNumberExpression() { + this.lineNumber = UNKNOWN_LINE_NUMBER; + } + + protected AbstractLineNumberExpression(int lineNumber) { + this.lineNumber = lineNumber; + } + + @Override + public int getLineNumber() { + return lineNumber; + } + + @Override + public int getPriority() { + return 0; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLineNumberTypeExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLineNumberTypeExpression.java new file mode 100644 index 00000000..59ea06ff --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractLineNumberTypeExpression.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public abstract class AbstractLineNumberTypeExpression extends AbstractLineNumberExpression { + protected Type type; + + protected AbstractLineNumberTypeExpression(Type type) { + this.type = type; + } + + protected AbstractLineNumberTypeExpression(int lineNumber, Type type) { + super(lineNumber); + this.type = type; + } + + @Override + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractNopExpressionVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractNopExpressionVisitor.java new file mode 100644 index 00000000..71832c3c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/AbstractNopExpressionVisitor.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +public abstract class AbstractNopExpressionVisitor implements ExpressionVisitor { + @Override public void visit(ArrayExpression expression) {} + @Override public void visit(BinaryOperatorExpression expression) {} + @Override public void visit(BooleanExpression expression) {} + @Override public void visit(CastExpression expression) {} + @Override public void visit(CommentExpression expression) {} + @Override public void visit(ConstructorInvocationExpression expression) {} + @Override public void visit(ConstructorReferenceExpression expression) {} + @Override public void visit(DoubleConstantExpression expression) {} + @Override public void visit(EnumConstantReferenceExpression expression) {} + @Override public void visit(Expressions expression) {} + @Override public void visit(FieldReferenceExpression expression) {} + @Override public void visit(FloatConstantExpression expression) {} + @Override public void visit(IntegerConstantExpression expression) {} + @Override public void visit(InstanceOfExpression expression) {} + @Override public void visit(LambdaFormalParametersExpression expression) {} + @Override public void visit(LambdaIdentifiersExpression expression) {} + @Override public void visit(LengthExpression expression) {} + @Override public void visit(LocalVariableReferenceExpression expression) {} + @Override public void visit(LongConstantExpression expression) {} + @Override public void visit(MethodInvocationExpression expression) {} + @Override public void visit(MethodReferenceExpression expression) {} + @Override public void visit(NewArray expression) {} + @Override public void visit(NewExpression expression) {} + @Override public void visit(NewInitializedArray expression) {} + @Override public void visit(NoExpression expression) {} + @Override public void visit(NullExpression expression) {} + @Override public void visit(ObjectTypeReferenceExpression expression) {} + @Override public void visit(ParenthesesExpression expression) {} + @Override public void visit(PostOperatorExpression expression) {} + @Override public void visit(PreOperatorExpression expression) {} + @Override public void visit(StringConstantExpression expression) {} + @Override public void visit(SuperConstructorInvocationExpression expression) {} + @Override public void visit(SuperExpression expression) {} + @Override public void visit(TernaryOperatorExpression expression) {} + @Override public void visit(ThisExpression expression) {} + @Override public void visit(TypeReferenceDotClassExpression expression) {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ArrayExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ArrayExpression.java new file mode 100644 index 00000000..076e613f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ArrayExpression.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +import static org.jd.core.v1.model.javasyntax.type.ObjectType.TYPE_UNDEFINED_OBJECT; + +public class ArrayExpression extends AbstractLineNumberTypeExpression { + protected Expression expression; + protected Expression index; + + public ArrayExpression(Expression expression, Expression index) { + super(createItemType(expression)); + this.expression = expression; + this.index = index; + } + + public ArrayExpression(int lineNumber, Expression expression, Expression index) { + super(lineNumber, createItemType(expression)); + this.expression = expression; + this.index = index; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + public Expression getIndex() { + return index; + } + + public void setIndex(Expression index) { + this.index = index; + } + + @Override + public int getPriority() { + return 1; + } + + protected static Type createItemType(Expression expression) { + Type type = expression.getType(); + int dimension = type.getDimension(); + + return type.createType((dimension > 0) ? dimension-1 : 0); + } + + @Override + public boolean isArrayExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ArrayExpression{" + expression + "[" + index + "]}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BaseExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BaseExpression.java new file mode 100644 index 00000000..f373a94d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BaseExpression.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.util.Base; + +import static org.jd.core.v1.model.javasyntax.expression.NoExpression.NO_EXPRESSION; + +public interface BaseExpression extends Base { + void accept(ExpressionVisitor visitor); + + default boolean isArrayExpression() { return false; } + default boolean isBinaryOperatorExpression() { return false; } + default boolean isBooleanExpression() { return false; } + default boolean isCastExpression() { return false; } + default boolean isConstructorInvocationExpression() { return false; } + default boolean isDoubleConstantExpression() { return false; } + default boolean isFieldReferenceExpression() { return false; } + default boolean isFloatConstantExpression() { return false; } + default boolean isIntegerConstantExpression() { return false; } + default boolean isLengthExpression() { return false; } + default boolean isLocalVariableReferenceExpression() { return false; } + default boolean isLongConstantExpression() { return false; } + default boolean isMethodInvocationExpression() { return false; } + default boolean isNewArray() { return false; } + default boolean isNewExpression() { return false; } + default boolean isNewInitializedArray() { return false; } + default boolean isNullExpression() { return false; } + default boolean isObjectTypeReferenceExpression() { return false; } + default boolean isPostOperatorExpression() { return false; } + default boolean isPreOperatorExpression() { return false; } + default boolean isStringConstantExpression() { return false; } + default boolean isSuperConstructorInvocationExpression() { return false; } + default boolean isSuperExpression() { return false; } + default boolean isTernaryOperatorExpression() { return false; } + default boolean isThisExpression() { return false; } + + default BaseExpression getDimensionExpressionList() { return NO_EXPRESSION; } + default BaseExpression getParameters() { return NO_EXPRESSION; } + + default Expression getCondition() { return NO_EXPRESSION; } + default Expression getExpression() { return NO_EXPRESSION; } + default Expression getTrueExpression() { return NO_EXPRESSION; } + default Expression getFalseExpression() { return NO_EXPRESSION; } + default Expression getIndex() { return NO_EXPRESSION; } + default Expression getLeftExpression() { return NO_EXPRESSION; } + default Expression getRightExpression() { return NO_EXPRESSION; } + + default String getDescriptor() { return ""; } + default double getDoubleValue() { return 0D; } + default float getFloatValue() { return 0F; } + default int getIntegerValue() { return 0; } + default String getInternalTypeName() { return ""; } + default long getLongValue() { return 0L; } + default String getName() { return ""; } + default ObjectType getObjectType() { return ObjectType.TYPE_UNDEFINED_OBJECT; } + default String getOperator() { return ""; } + default String getStringValue() { return ""; } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BinaryOperatorExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BinaryOperatorExpression.java new file mode 100644 index 00000000..cd55570b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BinaryOperatorExpression.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class BinaryOperatorExpression extends AbstractLineNumberTypeExpression { + protected Expression leftExpression; + protected String operator; + protected Expression rightExpression; + protected int priority; + + public BinaryOperatorExpression(int lineNumber, Type type, Expression leftExpression, String operator, Expression rightExpression, int priority) { + super(lineNumber, type); + this.operator = operator; + this.leftExpression = leftExpression; + this.rightExpression = rightExpression; + this.priority = priority; + } + + @Override + public Expression getLeftExpression() { + return leftExpression; + } + + public void setLeftExpression(Expression leftExpression) { + this.leftExpression = leftExpression; + } + + @Override + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + @Override + public Expression getRightExpression() { + return rightExpression; + } + + public void setRightExpression(Expression rightExpression) { + this.rightExpression = rightExpression; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + @Override + public boolean isBinaryOperatorExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "BinaryOperatorExpression{" + leftExpression.toString() + ' ' + operator + ' ' + rightExpression.toString() + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BooleanExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BooleanExpression.java new file mode 100644 index 00000000..1b0afcd8 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/BooleanExpression.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class BooleanExpression extends AbstractLineNumberExpression { + public static final BooleanExpression TRUE = new BooleanExpression(true); + public static final BooleanExpression FALSE = new BooleanExpression(false); + + protected boolean value; + + protected BooleanExpression(boolean value) { + this.value = value; + } + + public BooleanExpression(int lineNumber, boolean value) { + super(lineNumber); + this.value = value; + } + + @Override + public Type getType() { + return PrimitiveType.TYPE_BOOLEAN; + } + + public boolean isTrue() { + return value; + } + + public boolean isFalse() { + return !value; + } + + @Override + public boolean isBooleanExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "BooleanExpression{" + value + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/CastExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/CastExpression.java new file mode 100644 index 00000000..1b91983d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/CastExpression.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class CastExpression extends AbstractLineNumberTypeExpression { + protected Expression expression; + protected boolean explicit; + + public CastExpression(Type type, Expression expression) { + super(type); + this.expression = expression; + this.explicit = true; + } + + public CastExpression(int lineNumber, Type type, Expression expression) { + super(lineNumber, type); + this.expression = expression; + this.explicit = true; + } + + public CastExpression(int lineNumber, Type type, Expression expression, boolean explicit) { + super(lineNumber, type); + this.expression = expression; + this.explicit = explicit; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + public boolean isExplicit() { + return explicit; + } + + public void setExplicit(boolean explicit) { + this.explicit = explicit; + } + + @Override + public int getPriority() { + return 3; + } + + @Override + public boolean isCastExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "CastExpression{cast (" + type + ") " + expression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/CommentExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/CommentExpression.java new file mode 100644 index 00000000..f15c530c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/CommentExpression.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class CommentExpression implements Expression { + protected String text; + + public CommentExpression(String text) { + this.text = text; + } + + @Override + public int getLineNumber() { + return UNKNOWN_LINE_NUMBER; + } + + @Override + public Type getType() { + return PrimitiveType.TYPE_VOID; + } + + public String getText() { + return text; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "CommentExpression{" + text + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ConstructorInvocationExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ConstructorInvocationExpression.java new file mode 100644 index 00000000..bc90d82d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ConstructorInvocationExpression.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; + +public class ConstructorInvocationExpression extends ConstructorReferenceExpression { + protected BaseExpression parameters; + + public ConstructorInvocationExpression(ObjectType type, String descriptor, BaseExpression parameters) { + super(PrimitiveType.TYPE_VOID, type, descriptor); + this.parameters = parameters; + } + + public ConstructorInvocationExpression(int lineNumber, ObjectType type, String descriptor, BaseExpression parameters) { + super(lineNumber, PrimitiveType.TYPE_VOID, type, descriptor); + this.parameters = parameters; + } + + @Override + public BaseExpression getParameters() { + return parameters; + } + + public void setParameters(BaseExpression parameters) { + this.parameters = parameters; + } + + @Override + public int getPriority() { + return 1; + } + + @Override + public boolean isConstructorInvocationExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ConstructorInvocationExpression{call this(" + descriptor + ")}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ConstructorReferenceExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ConstructorReferenceExpression.java new file mode 100644 index 00000000..a478845d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ConstructorReferenceExpression.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class ConstructorReferenceExpression extends AbstractLineNumberTypeExpression { + protected ObjectType objectType; + protected String descriptor; + + public ConstructorReferenceExpression(Type type, ObjectType objectType, String descriptor) { + super(type); + this.objectType = objectType; + this.descriptor = descriptor; + } + + public ConstructorReferenceExpression(int lineNumber, Type type, ObjectType objectType, String descriptor) { + super(lineNumber, type); + this.objectType = objectType; + this.descriptor = descriptor; + } + + @Override + public ObjectType getObjectType() { + return objectType; + } + + @Override + public String getDescriptor() { + return descriptor; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/DoubleConstantExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/DoubleConstantExpression.java new file mode 100644 index 00000000..beeff52b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/DoubleConstantExpression.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; + +public class DoubleConstantExpression extends AbstractLineNumberTypeExpression { + protected double value; + + public DoubleConstantExpression(double value) { + super(PrimitiveType.TYPE_DOUBLE); + this.value = value; + } + + public DoubleConstantExpression(int lineNumber, double value) { + super(lineNumber, PrimitiveType.TYPE_DOUBLE); + this.value = value; + } + + @Override + public double getDoubleValue() { + return value; + } + + @Override + public boolean isDoubleConstantExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "DoubleConstantExpression{" + value + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/EnumConstantReferenceExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/EnumConstantReferenceExpression.java new file mode 100644 index 00000000..521550a5 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/EnumConstantReferenceExpression.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class EnumConstantReferenceExpression extends AbstractLineNumberExpression { + protected ObjectType type; + protected String name; + + public EnumConstantReferenceExpression(ObjectType type, String name) { + this.type = type; + this.name = name; + } + + public EnumConstantReferenceExpression(int lineNumber, ObjectType type, String name) { + super(lineNumber); + this.type = type; + this.name = name; + } + + @Override + public Type getType() { + return type; + } + + @Override + public ObjectType getObjectType() { + return type; + } + + @Override + public String getName() { + return name; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "EnumConstantReferenceExpression{type=" + type + ", name=" + name + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/Expression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/Expression.java new file mode 100644 index 00000000..74954837 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/Expression.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.api.printer.Printer; +import org.jd.core.v1.model.javasyntax.type.Type; + +/* Priority Operator Operation Order of Evaluation + * 0 new Object creation + * 1 [ ] Array index Left to Right + * () Method call + * . Member access + * ++ Postfix increment + * -- Postfix decrement + * 2 ++ Prefix increment Right to Left + * -- Prefix decrement + * + - Unary plus, minus + * ~ Bitwise NOT + * ! Boolean (logical) NOT + * 3 (type) Type cast Right to Left + * 4 + String concatenation Left to Right + * 5 * / % Multiplication, division, remainder Left to Right + * 6 + - Addition, subtraction Left to Right + * 7 << Signed bit shift left to right Left to Right + * >> Signed bit shift right to left + * >>> Unsigned bit shift right to left + * 8 < <= Less than, less than or equal to Left to Right + * > >= Greater than, greater than or equal to + * instanceof Reference test + * 9 == Equal to Left to Right + * != Not equal to + * 10 & Bitwise AND Left to Right + * & Boolean (logical) AND + * 11 ^ Bitwise XOR Left to Right + * ^ Boolean (logical) XOR + * 12 | Bitwise OR Left to Right + * | Boolean (logical) OR + * 13 && Boolean (logical) AND Left to Right + * 14 || Boolean (logical) OR Left to Right + * 15 ? : Conditional Right to Left + * 16 = Assignment Right to Left + * *= /= += Combinated assignment + * -= %= (operation and assignment) + * <<= >>= + * >>>= + * &= ^= |= + * 17 -> Lambda Right to Left + * + * References: + * - http://introcs.cs.princeton.edu/java/11precedence + * - The Java® Language Specification Java SE 8 Edition, 15.2 Forms of Expressions + */ +public interface Expression extends BaseExpression { + int UNKNOWN_LINE_NUMBER = Printer.UNKNOWN_LINE_NUMBER; + + int getLineNumber(); + + Type getType(); + + int getPriority(); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ExpressionVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ExpressionVisitor.java new file mode 100644 index 00000000..0b5c90ca --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ExpressionVisitor.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +public interface ExpressionVisitor { + void visit(ArrayExpression expression); + void visit(BinaryOperatorExpression expression); + void visit(BooleanExpression expression); + void visit(CastExpression expression); + void visit(CommentExpression expression); + void visit(ConstructorInvocationExpression expression); + void visit(ConstructorReferenceExpression expression); + void visit(DoubleConstantExpression expression); + void visit(EnumConstantReferenceExpression expression); + void visit(Expressions expression); + void visit(FieldReferenceExpression expression); + void visit(FloatConstantExpression expression); + void visit(IntegerConstantExpression expression); + void visit(InstanceOfExpression expression); + void visit(LambdaFormalParametersExpression expression); + void visit(LambdaIdentifiersExpression expression); + void visit(LengthExpression expression); + void visit(LocalVariableReferenceExpression expression); + void visit(LongConstantExpression expression); + void visit(MethodInvocationExpression expression); + void visit(MethodReferenceExpression expression); + void visit(NewArray expression); + void visit(NewExpression expression); + void visit(NewInitializedArray expression); + void visit(NoExpression expression); + void visit(NullExpression expression); + void visit(ObjectTypeReferenceExpression expression); + void visit(ParenthesesExpression expression); + void visit(PostOperatorExpression expression); + void visit(PreOperatorExpression expression); + void visit(StringConstantExpression expression); + void visit(SuperConstructorInvocationExpression expression); + void visit(SuperExpression expression); + void visit(TernaryOperatorExpression expression); + void visit(ThisExpression expression); + void visit(TypeReferenceDotClassExpression expression); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/Expressions.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/Expressions.java new file mode 100644 index 00000000..11ef5c19 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/Expressions.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class Expressions extends DefaultList implements BaseExpression { + + public Expressions() {} + + public Expressions(int capacity) { + super(capacity); + } + + public Expressions(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'Expression' or sub class instead"; + } + + @SuppressWarnings("unchecked") + public Expressions(Expression expression, Expression... expressions) { + super(expression, expressions); + assert (expressions != null) && (expressions.length > 0) : "Uses 'Expression' or sub class instead"; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/FieldReferenceExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/FieldReferenceExpression.java new file mode 100644 index 00000000..d5c99579 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/FieldReferenceExpression.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class FieldReferenceExpression extends AbstractLineNumberTypeExpression { + protected Expression expression; + protected String internalTypeName; + protected String name; + protected String descriptor; + + public FieldReferenceExpression(Type type, Expression expression, String internalTypeName, String name, String descriptor) { + super(type); + this.expression = expression; + this.internalTypeName = internalTypeName; + this.name = name; + this.descriptor = descriptor; + } + + public FieldReferenceExpression(int lineNumber, Type type, Expression expression, String internalTypeName, String name, String descriptor) { + super(lineNumber, type); + this.expression = expression; + this.internalTypeName = internalTypeName; + this.name = name; + this.descriptor = descriptor; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public String getInternalTypeName() { + return internalTypeName; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getDescriptor() { + return descriptor; + } + + @Override + public boolean isFieldReferenceExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "FieldReferenceExpression{type=" + type + ", expression=" + expression + ", name=" + name + ", descriptor=" + descriptor + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/FloatConstantExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/FloatConstantExpression.java new file mode 100644 index 00000000..ecdf6840 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/FloatConstantExpression.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; + +public class FloatConstantExpression extends AbstractLineNumberTypeExpression { + protected float value; + + public FloatConstantExpression(float value) { + super(PrimitiveType.TYPE_FLOAT); + this.value = value; + } + + public FloatConstantExpression(int lineNumber, float value) { + super(lineNumber, PrimitiveType.TYPE_FLOAT); + this.value = value; + } + + public float getFloatValue() { + return value; + } + + @Override + public boolean isFloatConstantExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "FloatConstantExpression{" + value + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/InstanceOfExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/InstanceOfExpression.java new file mode 100644 index 00000000..0e389154 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/InstanceOfExpression.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class InstanceOfExpression extends AbstractLineNumberExpression { + protected Expression expression; + protected Type instanceOfType; + + public InstanceOfExpression(Expression expression, ObjectType instanceOfType) { + this.expression = expression; + this.instanceOfType = instanceOfType; + } + + public InstanceOfExpression(int lineNumber, Expression expression, Type instanceOfType) { + super(lineNumber); + this.expression = expression; + this.instanceOfType = instanceOfType; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + public Type getInstanceOfType() { + return instanceOfType; + } + + @Override + public Type getType() { + return PrimitiveType.TYPE_BOOLEAN; + } + + @Override + public int getPriority() { + return 8; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/IntegerConstantExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/IntegerConstantExpression.java new file mode 100644 index 00000000..53c0b6fa --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/IntegerConstantExpression.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; +import org.jd.core.v1.model.javasyntax.type.Type; +import org.jd.core.v1.service.converter.classfiletojavasyntax.util.PrimitiveTypeUtil; + + +public class IntegerConstantExpression extends AbstractLineNumberTypeExpression { + protected int value; + + public IntegerConstantExpression(Type type, int value) { + super(type); + this.value = value; + assert type.isPrimitiveType(); + } + + public IntegerConstantExpression(int lineNumber, Type type, int value) { + super(lineNumber, type); + this.value = value; + assert type.isPrimitiveType(); + } + + @Override + public int getIntegerValue() { + return value; + } + + @Override + public void setType(Type type) { + assert checkType(type) : "IntegerConstantExpression.setType(type) : incompatible types"; + super.setType(type); + } + + protected boolean checkType(Type type) { + if (type.isPrimitiveType()) { + PrimitiveType valueType = PrimitiveTypeUtil.getPrimitiveTypeFromValue(value); + return (((PrimitiveType)type).getFlags() & valueType.getFlags()) != 0; + } + + return false; + } + + @Override + public boolean isIntegerConstantExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "IntegerConstantExpression{type=" + type + ", value=" + value + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LambdaFormalParametersExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LambdaFormalParametersExpression.java new file mode 100644 index 00000000..e8be616b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LambdaFormalParametersExpression.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.declaration.BaseFormalParameter; +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class LambdaFormalParametersExpression extends AbstractLambdaExpression { + protected BaseFormalParameter formalParameters; + + public LambdaFormalParametersExpression(Type type, BaseFormalParameter formalParameters, BaseStatement statements) { + super(type, statements); + this.formalParameters = formalParameters; + } + + public LambdaFormalParametersExpression(int lineNumber, Type type, BaseFormalParameter formalParameters, BaseStatement statements) { + super(lineNumber, type, statements); + this.formalParameters = formalParameters; + } + + public BaseFormalParameter getFormalParameters() { + return formalParameters; + } + + public void setParameters(BaseFormalParameter formalParameters) { + this.formalParameters = formalParameters; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LambdaFormalParametersExpression{" + formalParameters + " -> " + statements + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LambdaIdentifiersExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LambdaIdentifiersExpression.java new file mode 100644 index 00000000..f6014bb7 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LambdaIdentifiersExpression.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.statement.BaseStatement; +import org.jd.core.v1.model.javasyntax.type.Type; + +import java.util.List; + +public class LambdaIdentifiersExpression extends AbstractLambdaExpression { + protected Type returnedType; + protected List parameterNames; + + public LambdaIdentifiersExpression(Type type, Type returnedType, List parameterNames, BaseStatement statements) { + super(type, statements); + this.returnedType = returnedType; + this.parameterNames = parameterNames; + } + + public LambdaIdentifiersExpression(int lineNumber, Type type, Type returnedType, List parameterNames, BaseStatement statements) { + super(lineNumber, type, statements); + this.returnedType = returnedType; + this.parameterNames = parameterNames; + } + + public Type getReturnedType() { + return returnedType; + } + + public List getParameterNames() { + return parameterNames; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LambdaIdentifiersExpression{" + parameterNames + " -> " + statements + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LengthExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LengthExpression.java new file mode 100644 index 00000000..db572c5c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LengthExpression.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class LengthExpression extends AbstractLineNumberExpression { + protected Expression expression; + + public LengthExpression(Expression expression) { + this.expression = expression; + } + + public LengthExpression(int lineNumber, Expression expression) { + super(lineNumber); + this.expression = expression; + } + + @Override + public Type getType() { + return PrimitiveType.TYPE_INT; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public boolean isLengthExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LengthExpression{" + expression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LocalVariableReferenceExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LocalVariableReferenceExpression.java new file mode 100644 index 00000000..35e895d7 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LocalVariableReferenceExpression.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class LocalVariableReferenceExpression extends AbstractLineNumberTypeExpression { + protected String name; + + public LocalVariableReferenceExpression(Type type, String name) { + super(type); + this.name = name; + } + + public LocalVariableReferenceExpression(int lineNumber, Type type, String name) { + super(lineNumber, type); + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isLocalVariableReferenceExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LocalVariableReferenceExpression{type=" + type + ", name=" + name + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LongConstantExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LongConstantExpression.java new file mode 100644 index 00000000..7269cd85 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/LongConstantExpression.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; + +public class LongConstantExpression extends AbstractLineNumberTypeExpression { + protected long value; + + public LongConstantExpression(long value) { + super(PrimitiveType.TYPE_LONG); + this.value = value; + } + + public LongConstantExpression(int lineNumber, long value) { + super(lineNumber, PrimitiveType.TYPE_LONG); + this.value = value; + } + + @Override + public long getLongValue() { + return value; + } + + @Override + public boolean isLongConstantExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LongConstantExpression{" + value + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/MethodInvocationExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/MethodInvocationExpression.java new file mode 100644 index 00000000..e13527ec --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/MethodInvocationExpression.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.BaseTypeArgument; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class MethodInvocationExpression extends MethodReferenceExpression { + protected BaseTypeArgument nonWildcardTypeArguments; + protected BaseExpression parameters; + + public MethodInvocationExpression(Type type, Expression expression, String internalTypeName, String name, String descriptor) { + super(type, expression, internalTypeName, name, descriptor); + } + + public MethodInvocationExpression(int lineNumber, Type type, Expression expression, String internalTypeName, String name, String descriptor) { + super(lineNumber, type, expression, internalTypeName, name, descriptor); + } + + public MethodInvocationExpression(Type type, Expression expression, String internalTypeName, String name, String descriptor, BaseExpression parameters) { + super(type, expression, internalTypeName, name, descriptor); + this.parameters = parameters; + } + + public MethodInvocationExpression(int lineNumber, Type type, Expression expression, String internalTypeName, String name, String descriptor, BaseExpression parameters) { + super(lineNumber, type, expression, internalTypeName, name, descriptor); + this.parameters = parameters; + } + + public BaseTypeArgument getNonWildcardTypeArguments() { + return nonWildcardTypeArguments; + } + + public void setNonWildcardTypeArguments(BaseTypeArgument nonWildcardTypeArguments) { + this.nonWildcardTypeArguments = nonWildcardTypeArguments; + } + + @Override + public BaseExpression getParameters() { + return parameters; + } + + public void setParameters(BaseExpression parameters) { + this.parameters = parameters; + } + + @Override + public int getPriority() { + return 1; + } + + @Override + public boolean isMethodInvocationExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "MethodInvocationExpression{call " + expression + " . " + name + "(" + descriptor + ")}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/MethodReferenceExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/MethodReferenceExpression.java new file mode 100644 index 00000000..6f7813ef --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/MethodReferenceExpression.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class MethodReferenceExpression extends AbstractLineNumberTypeExpression { + protected Expression expression; + protected String internalTypeName; + protected String name; + protected String descriptor; + + public MethodReferenceExpression(Type type, Expression expression, String internalTypeName, String name, String descriptor) { + super(type); + this.expression = expression; + this.internalTypeName = internalTypeName; + this.name = name; + this.descriptor = descriptor; + } + + public MethodReferenceExpression(int lineNumber, Type type, Expression expression, String internalTypeName, String name, String descriptor) { + super(lineNumber, type); + this.expression = expression; + this.internalTypeName = internalTypeName; + this.name = name; + this.descriptor = descriptor; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public String getInternalTypeName() { + return internalTypeName; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getDescriptor() { + return descriptor; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewArray.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewArray.java new file mode 100644 index 00000000..eec6108f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewArray.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class NewArray extends AbstractLineNumberTypeExpression { + protected BaseExpression dimensionExpressionList; + + public NewArray(int lineNumber, Type type, BaseExpression dimensionExpressionList) { + super(lineNumber, type); + this.dimensionExpressionList = dimensionExpressionList; + } + + @Override + public BaseExpression getDimensionExpressionList() { + return dimensionExpressionList; + } + + public void setDimensionExpressionList(BaseExpression dimensionExpressionList) { + this.dimensionExpressionList = dimensionExpressionList; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public boolean isNewArray() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "NewArray{" + type + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewExpression.java new file mode 100644 index 00000000..b9ad13be --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewExpression.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.declaration.BodyDeclaration; +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class NewExpression extends AbstractLineNumberExpression { + protected ObjectType type; + protected String descriptor; + protected BaseExpression parameters; + protected BodyDeclaration bodyDeclaration; + + public NewExpression(int lineNumber, ObjectType type, String descriptor) { + super(lineNumber); + this.type = type; + this.descriptor = descriptor; + } + + public NewExpression(int lineNumber, ObjectType type, String descriptor, BodyDeclaration bodyDeclaration) { + super(lineNumber); + this.type = type; + this.descriptor = descriptor; + this.bodyDeclaration = bodyDeclaration; + } + + @Override + public ObjectType getObjectType() { + return type; + } + + public void setObjectType(ObjectType type) { + this.type = type; + } + + @Override + public Type getType() { + return type; + } + + public void setType(ObjectType type) { + this.type = type; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public String getDescriptor() { + return descriptor; + } + + @Override + public BaseExpression getParameters() { + return parameters; + } + + public void setParameters(BaseExpression parameters) { + this.parameters = parameters; + } + + public BodyDeclaration getBodyDeclaration() { + return bodyDeclaration; + } + + @Override + public boolean isNewExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "NewExpression{new " + type + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewInitializedArray.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewInitializedArray.java new file mode 100644 index 00000000..41168c55 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NewInitializedArray.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.declaration.ArrayVariableInitializer; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class NewInitializedArray extends AbstractLineNumberTypeExpression { + protected ArrayVariableInitializer arrayInitializer; + + public NewInitializedArray(Type type, ArrayVariableInitializer arrayInitializer) { + super(type); + this.arrayInitializer = arrayInitializer; + } + + public NewInitializedArray(int lineNumber, Type type, ArrayVariableInitializer arrayInitializer) { + super(lineNumber, type); + this.arrayInitializer = arrayInitializer; + } + + public ArrayVariableInitializer getArrayInitializer() { + return arrayInitializer; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public boolean isNewInitializedArray() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "NewInitializedArray{new " + type + " [" + arrayInitializer + "]}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NoExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NoExpression.java new file mode 100644 index 00000000..6499f7a3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NoExpression.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; + +public class NoExpression extends AbstractLineNumberTypeExpression { + public static final NoExpression NO_EXPRESSION = new NoExpression(); + + protected NoExpression() { + super(PrimitiveType.TYPE_VOID); + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "NoExpression"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NullExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NullExpression.java new file mode 100644 index 00000000..80cdbb6c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/NullExpression.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class NullExpression extends AbstractLineNumberTypeExpression { + public NullExpression(Type type) { + super(type); + } + + public NullExpression(int lineNumber, Type type) { + super(lineNumber, type); + } + + @Override + public boolean isNullExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "NullExpression{type=" + type + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ObjectTypeReferenceExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ObjectTypeReferenceExpression.java new file mode 100644 index 00000000..2ec73cf0 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ObjectTypeReferenceExpression.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class ObjectTypeReferenceExpression implements Expression { + protected int lineNumber; + protected ObjectType type; + protected boolean explicit; + + public ObjectTypeReferenceExpression(ObjectType type) { + this.type = type; + this.explicit = true; + } + + public ObjectTypeReferenceExpression(int lineNumber, ObjectType type) { + this.lineNumber = lineNumber; + this.type = type; + this.explicit = true; + } + + public ObjectTypeReferenceExpression(ObjectType type, boolean explicit) { + this.type = type; + this.explicit = explicit; + } + + public ObjectTypeReferenceExpression(int lineNumber, ObjectType type, boolean explicit) { + this.lineNumber = lineNumber; + this.type = type; + this.explicit = explicit; + } + + @Override + public int getLineNumber() { + return lineNumber; + } + + @Override + public ObjectType getObjectType() { + return type; + } + + @Override + public Type getType() { + return type; + } + + public boolean isExplicit() { + return explicit; + } + + public void setExplicit(boolean explicit) { + this.explicit = explicit; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public boolean isObjectTypeReferenceExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ObjectTypeReferenceExpression{" + type + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ParenthesesExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ParenthesesExpression.java new file mode 100644 index 00000000..f6b1aeed --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ParenthesesExpression.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class ParenthesesExpression extends AbstractLineNumberExpression { + protected Expression expression; + + public ParenthesesExpression(Expression expression) { + super(expression.getLineNumber()); + this.expression = expression; + } + + @Override + public Type getType() { + return expression.getType(); + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/PostOperatorExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/PostOperatorExpression.java new file mode 100644 index 00000000..3edc0d31 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/PostOperatorExpression.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class PostOperatorExpression extends AbstractLineNumberExpression { + protected String operator; + protected Expression expression; + + public PostOperatorExpression(Expression expression, String operator) { + this.operator = operator; + this.expression = expression; + } + + public PostOperatorExpression(int lineNumber, Expression expression, String operator) { + super(lineNumber); + this.operator = operator; + this.expression = expression; + } + + @Override + public String getOperator() { + return operator; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public Type getType() { + return expression.getType(); + } + + @Override + public int getPriority() { + return 1; + } + + @Override + public boolean isPostOperatorExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "PostOperatorExpression{" + expression + " " + operator + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/PreOperatorExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/PreOperatorExpression.java new file mode 100644 index 00000000..d7afc95a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/PreOperatorExpression.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class PreOperatorExpression extends AbstractLineNumberExpression { + protected String operator; + protected Expression expression; + + public PreOperatorExpression(String operator, Expression expression) { + this.operator = operator; + this.expression = expression; + } + + public PreOperatorExpression(int lineNumber, String operator, Expression expression) { + super(lineNumber); + this.operator = operator; + this.expression = expression; + } + + @Override + public String getOperator() { + return operator; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public Type getType() { + return expression.getType(); + } + + @Override + public int getPriority() { + return 2; + } + + @Override + public boolean isPreOperatorExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "PreOperatorExpression{" + operator + " " + expression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/StringConstantExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/StringConstantExpression.java new file mode 100644 index 00000000..cfc63448 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/StringConstantExpression.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class StringConstantExpression extends AbstractLineNumberExpression { + public static final StringConstantExpression EMPTY_STRING = new StringConstantExpression(""); + + protected String string; + + public StringConstantExpression(String string) { + this.string = string; + } + + public StringConstantExpression(int lineNumber, String string) { + super(lineNumber); + this.string = string; + } + + @Override + public String getStringValue() { + return string; + } + + @Override + public Type getType() { + return ObjectType.TYPE_STRING; + } + + @Override + public boolean isStringConstantExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "StringConstantExpression{\"" + string + "\"}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/SuperConstructorInvocationExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/SuperConstructorInvocationExpression.java new file mode 100644 index 00000000..f22c6a90 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/SuperConstructorInvocationExpression.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; + +public class SuperConstructorInvocationExpression extends ConstructorReferenceExpression { + protected BaseExpression parameters; + + public SuperConstructorInvocationExpression(ObjectType type, String descriptor, BaseExpression parameters) { + super(PrimitiveType.TYPE_VOID, type, descriptor); + this.parameters = parameters; + } + + public SuperConstructorInvocationExpression(int lineNumber, ObjectType type, String descriptor, BaseExpression parameters) { + super(lineNumber, PrimitiveType.TYPE_VOID, type, descriptor); + this.parameters = parameters; + } + + @Override + public BaseExpression getParameters() { + return parameters; + } + + public void setParameters(BaseExpression parameters) { + this.parameters = parameters; + } + + @Override + public int getPriority() { + return 1; + } + + @Override + public boolean isSuperConstructorInvocationExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "SuperConstructorInvocationExpression{call super(" + descriptor + ")}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/SuperExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/SuperExpression.java new file mode 100644 index 00000000..5ffdab1b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/SuperExpression.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class SuperExpression extends AbstractLineNumberExpression { + protected Type type; + + public SuperExpression(Type type) { + this.type = type; + } + + public SuperExpression(int lineNumber, Type type) { + super(lineNumber); + this.type = type; + } + + @Override + public Type getType() { + return type; + } + + @Override + public boolean isSuperExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "SuperExpression{" + type + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/TernaryOperatorExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/TernaryOperatorExpression.java new file mode 100644 index 00000000..93539cce --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/TernaryOperatorExpression.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class TernaryOperatorExpression extends AbstractLineNumberTypeExpression { + protected Expression condition; + protected Expression trueExpression; + protected Expression falseExpression; + + public TernaryOperatorExpression(Type type, Expression condition, Expression trueExpression, Expression falseExpression) { + super(type); + this.condition = condition; + this.trueExpression = trueExpression; + this.falseExpression = falseExpression; + } + + public TernaryOperatorExpression(int lineNumber, Type type, Expression condition, Expression trueExpression, Expression falseExpression) { + super(lineNumber, type); + this.condition = condition; + this.trueExpression = trueExpression; + this.falseExpression = falseExpression; + } + + public Expression getCondition() { + return condition; + } + + public void setCondition(Expression condition) { + this.condition = condition; + } + + @Override + public Expression getTrueExpression() { + return trueExpression; + } + + public void setTrueExpression(Expression trueExpression) { + this.trueExpression = trueExpression; + } + + @Override + public Expression getFalseExpression() { + return falseExpression; + } + + public void setFalseExpression(Expression falseExpression) { + this.falseExpression = falseExpression; + } + + @Override + public int getPriority() { + return 15; + } + + @Override + public boolean isTernaryOperatorExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "TernaryOperatorExpression{" + condition + " ? " + trueExpression + " : " + falseExpression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ThisExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ThisExpression.java new file mode 100644 index 00000000..7ecbf3c5 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/ThisExpression.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.Type; + +public class ThisExpression extends AbstractLineNumberExpression { + protected Type type; + protected boolean explicit; + + public ThisExpression(Type type) { + this.type = type; + this.explicit = true; + } + + public ThisExpression(int lineNumber, Type type) { + super(lineNumber); + this.type = type; + this.explicit = true; + } + + @Override + public Type getType() { + return type; + } + + public boolean isExplicit() { + return explicit; + } + + public void setExplicit(boolean explicit) { + this.explicit = explicit; + } + + @Override + public boolean isThisExpression() { return true; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ThisExpression{" + type + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/TypeReferenceDotClassExpression.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/TypeReferenceDotClassExpression.java new file mode 100644 index 00000000..17168519 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/expression/TypeReferenceDotClassExpression.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.expression; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class TypeReferenceDotClassExpression implements Expression { + protected int lineNumber; + protected Type typeDotClass; + protected Type type; + + public TypeReferenceDotClassExpression(Type typeDotClass) { + this.typeDotClass = typeDotClass; + this.type = ObjectType.TYPE_CLASS.createType(typeDotClass); + } + + public TypeReferenceDotClassExpression(int lineNumber, Type typeDotClass) { + this.lineNumber = lineNumber; + this.typeDotClass = typeDotClass; + this.type = ObjectType.TYPE_CLASS.createType(typeDotClass); + } + + @Override + public int getLineNumber() { + return lineNumber; + } + + public Type getTypeDotClass() { + return typeDotClass; + } + + @Override + public Type getType() { + return type; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "TypeReferenceDotClassExpression{" + typeDotClass + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AbstractNopReferenceVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AbstractNopReferenceVisitor.java new file mode 100644 index 00000000..83bf1783 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AbstractNopReferenceVisitor.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public abstract class AbstractNopReferenceVisitor implements ReferenceVisitor { + @Override public void visit(AnnotationReference reference) {} + @Override public void visit(AnnotationReferences references) {} + @Override public void visit(ElementValues references) {} + @Override public void visit(ElementValuePair reference) {} + @Override public void visit(ElementValuePairs references) {} + @Override public void visit(InnerObjectReference reference) {} + @Override public void visit(ObjectReference reference) {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationElementValue.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationElementValue.java new file mode 100644 index 00000000..80496d2c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationElementValue.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public class AnnotationElementValue extends AnnotationReference implements ElementValue { + + public AnnotationElementValue(AnnotationReference annotationReference) { + super(annotationReference.getType(), + annotationReference.getElementValue(), + annotationReference.getElementValuePairs()); + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "AnnotationElementValue{type=" + type + ", elementValue=" + elementValue + ", elementValuePairs=" + elementValuePairs + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationReference.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationReference.java new file mode 100644 index 00000000..a489cf1e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationReference.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.model.javasyntax.type.ObjectType; + +public class AnnotationReference implements BaseAnnotationReference { + protected ObjectType type; + protected ElementValue elementValue; + protected BaseElementValuePair elementValuePairs; + + public AnnotationReference(ObjectType type) { + this.type = type; + } + + public AnnotationReference(ObjectType type, ElementValue elementValue) { + this.type = type; + this.elementValue = elementValue; + } + + public AnnotationReference(ObjectType type, BaseElementValuePair elementValuePairs) { + this.type = type; + this.elementValuePairs = elementValuePairs; + } + + protected AnnotationReference(ObjectType type, ElementValue elementValue, BaseElementValuePair elementValuePairs) { + this.type = type; + this.elementValue = elementValue; + this.elementValuePairs = elementValuePairs; + } + + public ObjectType getType() { + return type; + } + + public ElementValue getElementValue() { + return elementValue; + } + + public BaseElementValuePair getElementValuePairs() { + return elementValuePairs; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof AnnotationReference)) return false; + + AnnotationReference that = (AnnotationReference) o; + + if (elementValue != null ? !elementValue.equals(that.elementValue) : that.elementValue != null) return false; + if (elementValuePairs != null ? !elementValuePairs.equals(that.elementValuePairs) : that.elementValuePairs != null) + return false; + if (!type.equals(that.type)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = 970748295 + type.hashCode(); + result = 31 * result + (elementValue != null ? elementValue.hashCode() : 0); + result = 31 * result + (elementValuePairs != null ? elementValuePairs.hashCode() : 0); + return result; + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationReferences.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationReferences.java new file mode 100644 index 00000000..59c3ff62 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/AnnotationReferences.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class AnnotationReferences extends DefaultList implements BaseAnnotationReference { + public AnnotationReferences() { + } + + public AnnotationReferences(int capacity) { + super(capacity); + } + + public AnnotationReferences(Collection collection) { + super(collection); + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseAnnotationReference.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseAnnotationReference.java new file mode 100644 index 00000000..567b1de2 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseAnnotationReference.java @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public interface BaseAnnotationReference extends Reference {} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseElementValue.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseElementValue.java new file mode 100644 index 00000000..8f758b9c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseElementValue.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.util.Base; + +public interface BaseElementValue extends Reference, Base {} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseElementValuePair.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseElementValuePair.java new file mode 100644 index 00000000..a4248019 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/BaseElementValuePair.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.util.Base; + +public interface BaseElementValuePair extends Reference, Base {} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValue.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValue.java new file mode 100644 index 00000000..1bec1c1b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValue.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public interface ElementValue extends BaseElementValue { + public static final byte EV_UNKNOWN= 0; + public static final byte EV_PRIMITIVE_TYPE= 1; + public static final byte EV_ENUM_CONST_VALUE= 2; + public static final byte EV_CLASS_INFO= 3; + public static final byte EV_ANNOTATION_VALUE= 4; + public static final byte EV_ARRAY_VALUE= 5; +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValueArrayInitializerElementValue.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValueArrayInitializerElementValue.java new file mode 100644 index 00000000..4a4974e7 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValueArrayInitializerElementValue.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public class ElementValueArrayInitializerElementValue implements ElementValue { + protected BaseElementValue elementValueArrayInitializer; + + public ElementValueArrayInitializerElementValue() { + this.elementValueArrayInitializer = null; + } + + public ElementValueArrayInitializerElementValue(BaseElementValue elementValueArrayInitializer) { + this.elementValueArrayInitializer = elementValueArrayInitializer; + } + + public BaseElementValue getElementValueArrayInitializer() { + return elementValueArrayInitializer; + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ElementValueArrayInitializerElementValue{" + elementValueArrayInitializer + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValuePair.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValuePair.java new file mode 100644 index 00000000..18989532 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValuePair.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public class ElementValuePair implements BaseElementValuePair { + protected String name; + protected ElementValue elementValue; + + public ElementValuePair(String name, ElementValue elementValue) { + this.name = name; + this.elementValue = elementValue; + } + + public String getName() { + return name; + } + + public ElementValue getElementValue() { + return elementValue; + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ElementValuePair{name=" + name + ", elementValue=" + elementValue + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValuePairs.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValuePairs.java new file mode 100644 index 00000000..fd7d08b3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValuePairs.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class ElementValuePairs extends DefaultList implements BaseElementValuePair { + public ElementValuePairs() { + } + + public ElementValuePairs(int capacity) { + super(capacity); + } + + public ElementValuePairs(Collection collection) { + super(collection); + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ElementValuePairs{" + super.toString() + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValues.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValues.java new file mode 100644 index 00000000..3f8d0a34 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ElementValues.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.util.DefaultList; + +import java.util.Collection; + +public class ElementValues extends DefaultList implements BaseElementValue { + public ElementValues() { + } + + public ElementValues(int capacity) { + super(capacity); + } + + public ElementValues(Collection collection) { + super(collection); + assert (collection != null) && (collection.size() > 1) : "Uses 'ElementValue' or sub class instead"; + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ElementValues{" + super.toString() + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ExpressionElementValue.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ExpressionElementValue.java new file mode 100644 index 00000000..d728819f --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ExpressionElementValue.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class ExpressionElementValue implements ElementValue { + protected Expression expression; + + public ExpressionElementValue(Expression expression) { + this.expression = expression; + } + + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ExpressionElementValue{" + expression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/InnerObjectReference.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/InnerObjectReference.java new file mode 100644 index 00000000..5fc46f63 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/InnerObjectReference.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.model.javasyntax.type.BaseTypeArgument; +import org.jd.core.v1.model.javasyntax.type.InnerObjectType; +import org.jd.core.v1.model.javasyntax.type.ObjectType; + +public class InnerObjectReference extends InnerObjectType implements Reference { + + public InnerObjectReference(String internalName, String qualifiedName, String name, ObjectType outerType) { + super(internalName, qualifiedName, name, outerType); + } + + public InnerObjectReference(String internalName, String qualifiedName, String name, int dimension, ObjectType outerType) { + super(internalName, qualifiedName, name, dimension, outerType); + } + + public InnerObjectReference(String internalName, String qualifiedName, String name, BaseTypeArgument typeArguments, ObjectType outerType) { + super(internalName, qualifiedName, name, typeArguments, outerType); + } + + public InnerObjectReference(String internalName, String qualifiedName, String name, BaseTypeArgument typeArguments, int dimension, ObjectType outerType) { + super(internalName, qualifiedName, name, typeArguments, dimension, outerType); + } + + public InnerObjectReference(InnerObjectType iot) { + super(iot); + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ObjectReference.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ObjectReference.java new file mode 100644 index 00000000..29c8a5b8 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ObjectReference.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +import org.jd.core.v1.model.javasyntax.type.BaseTypeArgument; +import org.jd.core.v1.model.javasyntax.type.ObjectType; + +public class ObjectReference extends ObjectType implements Reference { + public ObjectReference(String internalName, String qualifiedName, String name) { + super(internalName, qualifiedName, name); + } + + public ObjectReference(String internalName, String qualifiedName, String name, int dimension) { + super(internalName, qualifiedName, name, dimension); + } + + public ObjectReference(String internalName, String qualifiedName, String name, BaseTypeArgument typeArguments) { + super(internalName, qualifiedName, name, typeArguments); + } + + public ObjectReference(String internalName, String qualifiedName, String name, BaseTypeArgument typeArguments, int dimension) { + super(internalName, qualifiedName, name, typeArguments, dimension); + } + + @Override + public void accept(ReferenceVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/Reference.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/Reference.java new file mode 100644 index 00000000..2f398dfc --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/Reference.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public interface Reference { + void accept(ReferenceVisitor visitor); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ReferenceVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ReferenceVisitor.java new file mode 100644 index 00000000..4f05ae14 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/reference/ReferenceVisitor.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.reference; + +public interface ReferenceVisitor { + void visit(AnnotationElementValue reference); + void visit(AnnotationReference reference); + void visit(AnnotationReferences references); + void visit(ElementValueArrayInitializerElementValue reference); + void visit(ElementValues references); + void visit(ElementValuePair reference); + void visit(ElementValuePairs references); + void visit(ExpressionElementValue reference); + void visit(InnerObjectReference reference); + void visit(ObjectReference reference); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/AbstractNopStatementVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/AbstractNopStatementVisitor.java new file mode 100644 index 00000000..6d49d743 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/AbstractNopStatementVisitor.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public abstract class AbstractNopStatementVisitor implements StatementVisitor { + @Override public void visit(AssertStatement statement) {} + @Override public void visit(BreakStatement statement) {} + @Override public void visit(ByteCodeStatement statement) {} + @Override public void visit(CommentStatement statement) {} + @Override public void visit(ContinueStatement statement) {} + @Override public void visit(DoWhileStatement statement) {} + @Override public void visit(ExpressionStatement statement) {} + @Override public void visit(ForEachStatement statement) {} + @Override public void visit(ForStatement statement) {} + @Override public void visit(IfStatement statement) {} + @Override public void visit(IfElseStatement statement) {} + @Override public void visit(LabelStatement statement) {} + @Override public void visit(LambdaExpressionStatement statement) {} + @Override public void visit(LocalVariableDeclarationStatement statement) {} + @Override public void visit(NoStatement statement) {} + @Override public void visit(ReturnExpressionStatement statement) {} + @Override public void visit(ReturnStatement statement) {} + @Override public void visit(Statements statement) {} + @Override public void visit(SwitchStatement statement) {} + @Override public void visit(SwitchStatement.DefaultLabel statement) {} + @Override public void visit(SwitchStatement.ExpressionLabel statement) {} + @Override public void visit(SwitchStatement.LabelBlock statement) {} + @Override public void visit(SwitchStatement.MultiLabelsBlock statement) {} + @Override public void visit(SynchronizedStatement statement) {} + @Override public void visit(ThrowStatement statement) {} + @Override public void visit(TryStatement statement) {} + @Override public void visit(TryStatement.CatchClause statement) {} + @Override public void visit(TryStatement.Resource statement) {} + @Override public void visit(TypeDeclarationStatement statement) {} + @Override public void visit(WhileStatement statement) {} +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/AssertStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/AssertStatement.java new file mode 100644 index 00000000..01d898ad --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/AssertStatement.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class AssertStatement implements Statement { + protected Expression condition; + protected Expression message; + + public AssertStatement(Expression condition, Expression message) { + this.condition = condition; + this.message = message; + } + + @Override + public Expression getCondition() { + return condition; + } + + public void setCondition(Expression condition) { + this.condition = condition; + } + + public Expression getMessage() { + return message; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/BaseStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/BaseStatement.java new file mode 100644 index 00000000..7c514446 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/BaseStatement.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.BaseExpression; +import org.jd.core.v1.model.javasyntax.expression.Expression; +import org.jd.core.v1.util.Base; +import org.jd.core.v1.util.DefaultList; + +import static org.jd.core.v1.model.javasyntax.expression.Expression.UNKNOWN_LINE_NUMBER; +import static org.jd.core.v1.model.javasyntax.expression.NoExpression.NO_EXPRESSION; +import static org.jd.core.v1.model.javasyntax.statement.NoStatement.NO_STATEMENT; + +public interface BaseStatement extends Base { + void accept(StatementVisitor visitor); + + default boolean isBreakStatement() { return false; } + default boolean isContinueStatement() { return false; } + default boolean isExpressionStatement() { return false; } + default boolean isForStatement() { return false; } + default boolean isIfStatement() { return false; } + default boolean isIfElseStatement() { return false; } + default boolean isLabelStatement() { return false; } + default boolean isLambdaExpressionStatement() { return false; } + default boolean isLocalVariableDeclarationStatement() { return false; } + default boolean isMonitorEnterStatement() { return false; } + default boolean isMonitorExitStatement() { return false; } + default boolean isReturnStatement() { return false; } + default boolean isReturnExpressionStatement() { return false; } + default boolean isStatements() { return false; } + default boolean isSwitchStatement() { return false; } + default boolean isSwitchStatementLabelBlock() { return false; } + default boolean isSwitchStatementMultiLabelsBlock() { return false; } + default boolean isThrowStatement() { return false; } + default boolean isTryStatement() { return false; } + default boolean isWhileStatement() { return false; } + + default Expression getCondition() { return NO_EXPRESSION; } + default Expression getExpression() { return NO_EXPRESSION; } + default Expression getMonitor() { return NO_EXPRESSION; } + + default BaseStatement getElseStatements() { return NO_STATEMENT; } + default BaseStatement getFinallyStatements() { return NO_STATEMENT; } + default BaseStatement getStatements() { return NO_STATEMENT; } + default BaseStatement getTryStatements() { return NO_STATEMENT; } + + default BaseExpression getInit() { return NO_EXPRESSION; } + default BaseExpression getUpdate() { return NO_EXPRESSION; } + + default DefaultList getCatchClauses() { return DefaultList.emptyList(); } + + default int getLineNumber() { return UNKNOWN_LINE_NUMBER; } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/BreakStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/BreakStatement.java new file mode 100644 index 00000000..d7b3d79d --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/BreakStatement.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public class BreakStatement implements Statement { + public static final BreakStatement BREAK = new BreakStatement(); + + protected String label; + + protected BreakStatement() { + this.label = null; + } + + public BreakStatement(String label) { + assert label != null; + + this.label = label; + } + + public String getLabel() { + return label; + } + + @Override + public boolean isBreakStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ByteCodeStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ByteCodeStatement.java new file mode 100644 index 00000000..afb825bc --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ByteCodeStatement.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + + +public class ByteCodeStatement implements Statement { + protected String text; + + public ByteCodeStatement(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/CommentStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/CommentStatement.java new file mode 100644 index 00000000..7e08f205 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/CommentStatement.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public class CommentStatement implements Statement { + protected String text; + + public CommentStatement(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ContinueStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ContinueStatement.java new file mode 100644 index 00000000..17554025 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ContinueStatement.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public class ContinueStatement implements Statement { + public static final ContinueStatement CONTINUE = new ContinueStatement(); + + protected String label; + + protected ContinueStatement() { + this.label = null; + } + + public ContinueStatement(String label) { + assert label != null; + + this.label = label; + } + + public String getLabel() { + return label; + } + + @Override + public boolean isContinueStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/DoWhileStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/DoWhileStatement.java new file mode 100644 index 00000000..b8d46ef7 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/DoWhileStatement.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class DoWhileStatement implements Statement { + protected Expression condition; + protected BaseStatement statements; + + public DoWhileStatement(Expression condition, BaseStatement statements) { + this.condition = condition; + this.statements = statements; + } + + @Override + public Expression getCondition() { + return condition; + } + + public void setCondition(Expression condition) { + this.condition = condition; + } + + @Override + public BaseStatement getStatements() { + return statements; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ExpressionStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ExpressionStatement.java new file mode 100644 index 00000000..1d411ffc --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ExpressionStatement.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class ExpressionStatement implements Statement { + protected Expression expression; + + public ExpressionStatement(Expression expression) { + this.expression = expression; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public boolean isExpressionStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ExpressionStatement{" + expression.toString() + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ForEachStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ForEachStatement.java new file mode 100644 index 00000000..7218eee1 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ForEachStatement.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class ForEachStatement implements Statement { + protected Type type; + protected String name; + protected Expression expression; + protected BaseStatement statements; + + public ForEachStatement(Type type, String name, Expression expression, BaseStatement statements) { + this.type = type; + this.name = name; + this.expression = expression; + this.statements = statements; + } + + public Type getType() { + return type; + } + + public String getName() { + return name; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public BaseStatement getStatements() { + return statements; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ForStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ForStatement.java new file mode 100644 index 00000000..6e3dcc91 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ForStatement.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.declaration.LocalVariableDeclaration; +import org.jd.core.v1.model.javasyntax.expression.BaseExpression; +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class ForStatement implements Statement { + protected LocalVariableDeclaration declaration; + protected BaseExpression init; + protected Expression condition; + protected BaseExpression update; + protected BaseStatement statements; + + public ForStatement(LocalVariableDeclaration declaration, Expression condition, BaseExpression update, BaseStatement statements) { + this.declaration = declaration; + this.condition = condition; + this.update = update; + this.statements = statements; + } + + public ForStatement(BaseExpression init, Expression condition, BaseExpression update, BaseStatement statements) { + this.init = init; + this.condition = condition; + this.update = update; + this.statements = statements; + } + + public LocalVariableDeclaration getDeclaration() { + return declaration; + } + + public void setDeclaration(LocalVariableDeclaration declaration) { + this.declaration = declaration; + } + + @Override + public BaseExpression getInit() { + return init; + } + + public void setInit(BaseExpression init) { + this.init = init; + } + + @Override + public Expression getCondition() { + return condition; + } + + public void setCondition(Expression condition) { + this.condition = condition; + } + + @Override + public BaseExpression getUpdate() { + return update; + } + + public void setUpdate(BaseExpression update) { + this.update = update; + } + + @Override + public BaseStatement getStatements() { + return statements; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ForStatement{" + declaration + " or " + init + "; " + condition + "; " + update + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/IfElseStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/IfElseStatement.java new file mode 100644 index 00000000..9246771e --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/IfElseStatement.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class IfElseStatement extends IfStatement { + protected BaseStatement elseStatements; + + public IfElseStatement(Expression condition, BaseStatement statement, BaseStatement elseStatements) { + super(condition, statement); + this.elseStatements = elseStatements; + } + + @Override + public BaseStatement getElseStatements() { + return elseStatements; + } + + @Override + public boolean isIfElseStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/IfStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/IfStatement.java new file mode 100644 index 00000000..692d4751 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/IfStatement.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class IfStatement implements Statement { + protected Expression condition; + protected BaseStatement statements; + + public IfStatement(Expression condition, BaseStatement statements) { + this.condition = condition; + this.statements = statements; + } + + @Override + public Expression getCondition() { + return condition; + } + + public void setCondition(Expression condition) { + this.condition = condition; + } + + @Override + public BaseStatement getStatements() { + return statements; + } + + @Override + public boolean isIfStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LabelStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LabelStatement.java new file mode 100644 index 00000000..b41ea1fa --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LabelStatement.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public class LabelStatement implements Statement { + protected String label; + protected Statement statement; + + public LabelStatement(String label, Statement statement) { + this.label = label; + this.statement = statement; + } + + public String getLabel() { + return label; + } + + public Statement getStatement() { + return statement; + } + + @Override + public boolean isLabelStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LabelStatement{" + label + ": " + statement + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LambdaExpressionStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LambdaExpressionStatement.java new file mode 100644 index 00000000..2e0d6a56 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LambdaExpressionStatement.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class LambdaExpressionStatement implements Statement { + protected Expression expression; + + public LambdaExpressionStatement(Expression expression) { + this.expression = expression; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public boolean isLambdaExpressionStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LambdaExpressionStatement{" + expression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LocalVariableDeclarationStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LocalVariableDeclarationStatement.java new file mode 100644 index 00000000..2a591294 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/LocalVariableDeclarationStatement.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.declaration.BaseLocalVariableDeclarator; +import org.jd.core.v1.model.javasyntax.declaration.LocalVariableDeclaration; +import org.jd.core.v1.model.javasyntax.type.Type; + +public class LocalVariableDeclarationStatement extends LocalVariableDeclaration implements Statement { + + public LocalVariableDeclarationStatement(Type type, BaseLocalVariableDeclarator localVariableDeclarators) { + super(type, localVariableDeclarators); + } + + @Override + public boolean isLocalVariableDeclarationStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LocalVariableDeclarationStatement{" + type + " " + localVariableDeclarators + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/NoStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/NoStatement.java new file mode 100644 index 00000000..832269a3 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/NoStatement.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public class NoStatement implements Statement { + public static final NoStatement NO_STATEMENT = new NoStatement(); + + protected NoStatement() {} + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "NoStatement"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ReturnExpressionStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ReturnExpressionStatement.java new file mode 100644 index 00000000..3086222b --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ReturnExpressionStatement.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +public class ReturnExpressionStatement implements Statement { + protected int lineNumber; + protected Expression expression; + + public ReturnExpressionStatement(Expression expression) { + this(expression.getLineNumber(), expression); + } + + public ReturnExpressionStatement(int lineNumber, Expression expression) { + this.lineNumber = lineNumber; + this.expression = expression; + assert expression != null; + } + + @Override + public int getLineNumber() { + return lineNumber; + } + + public void setLineNumber(int lineNumber) { + this.lineNumber = lineNumber; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + assert expression != null; + this.expression = expression; + } + + @SuppressWarnings("unchecked") + public T getGenericExpression() { + return (T)expression; + } + + @Override + public boolean isReturnExpressionStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ReturnExpressionStatement{return " + expression + "}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ReturnStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ReturnStatement.java new file mode 100644 index 00000000..efb8d9de --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/ReturnStatement.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public class ReturnStatement implements Statement { + public static final ReturnStatement RETURN = new ReturnStatement(); + + protected ReturnStatement() {} + + @Override + public boolean isReturnStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ReturnStatement{}"; + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/Statement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/Statement.java new file mode 100644 index 00000000..a3100436 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/Statement.java @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public interface Statement extends BaseStatement { +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/StatementVisitor.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/StatementVisitor.java new file mode 100644 index 00000000..bb56c89a --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/StatementVisitor.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +public interface StatementVisitor { + void visit(AssertStatement statement); + void visit(BreakStatement statement); + void visit(ByteCodeStatement statement); + void visit(CommentStatement statement); + void visit(ContinueStatement statement); + void visit(DoWhileStatement statement); + void visit(ExpressionStatement statement); + void visit(ForEachStatement statement); + void visit(ForStatement statement); + void visit(IfStatement statement); + void visit(IfElseStatement statement); + void visit(LabelStatement statement); + void visit(LambdaExpressionStatement statement); + void visit(LocalVariableDeclarationStatement statement); + void visit(NoStatement statement); + void visit(ReturnExpressionStatement statement); + void visit(ReturnStatement statement); + void visit(Statements statement); + void visit(SwitchStatement statement); + void visit(SwitchStatement.DefaultLabel statement); + void visit(SwitchStatement.ExpressionLabel statement); + void visit(SwitchStatement.LabelBlock statement); + void visit(SwitchStatement.MultiLabelsBlock statement); + void visit(SynchronizedStatement statement); + void visit(ThrowStatement statement); + void visit(TryStatement statement); + void visit(TryStatement.Resource statement); + void visit(TryStatement.CatchClause statement); + void visit(TypeDeclarationStatement statement); + void visit(WhileStatement statement); +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/Statements.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/Statements.java new file mode 100644 index 00000000..5409055c --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/Statements.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008, 2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.util.DefaultList; + +import java.util.List; + +public class Statements extends DefaultList implements BaseStatement { + public Statements() {} + + public Statements(int capacity) { + super(capacity); + } + + public Statements(List list) { + super(list); + assert (list != null) && (list.size() > 1) : "Uses 'Statement' implementation instead"; + } + + @SuppressWarnings("unchecked") + public Statements(Statement statement, Statement... statements) { + super(statement, statements); + assert (statements != null) && (statements.length > 0) : "Uses 'Statement' implementation instead"; + } + + @Override + public boolean isStatements() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } +} diff --git a/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/SwitchStatement.java b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/SwitchStatement.java new file mode 100644 index 00000000..83e8f295 --- /dev/null +++ b/core/src/main/java/org/jd/core/v1/model/javasyntax/statement/SwitchStatement.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.core.v1.model.javasyntax.statement; + +import org.jd.core.v1.model.javasyntax.expression.Expression; + +import java.util.List; + +public class SwitchStatement implements Statement { + public static final DefaultLabel DEFAULT_LABEL = new DefaultLabel(); + + protected Expression condition; + protected List blocks; + + public SwitchStatement(Expression condition, List blocks) { + this.condition = condition; + this.blocks = blocks; + } + + @Override + public Expression getCondition() { + return condition; + } + + public void setCondition(Expression condition) { + this.condition = condition; + } + + public List getBlocks() { + return blocks; + } + + @Override + public boolean isSwitchStatement() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + // --- Label --- // + public interface Label extends Statement {} + + public static class DefaultLabel implements Label { + protected DefaultLabel() {} + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "DefaultLabel"; + } + } + + public static class ExpressionLabel implements Label { + protected Expression expression; + + public ExpressionLabel(Expression expression) { + this.expression = expression; + } + + @Override + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "ExpressionLabel{" + expression.toString() + '}'; + } + } + + // --- Block --- // + public static abstract class Block implements Statement { + protected BaseStatement statements; + + protected Block(BaseStatement statements) { + this.statements = statements; + } + + @Override + public BaseStatement getStatements() { + return statements; + } + } + + public static class LabelBlock extends Block { + protected Label label; + + public LabelBlock(Label label, BaseStatement statements) { + super(statements); + this.label = label; + } + + public Label getLabel() { + return label; + } + + @Override + public boolean isSwitchStatementLabelBlock() { return true; } + + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return "LabelBlock{label=" + label.toString() + '}'; + } + } + + public static class MultiLabelsBlock extends Block { + protected List