pax_global_header00006660000000000000000000000064125000615420014505gustar00rootroot0000000000000052 comment=8e47ddda929e71386dd94e8a1a36daa130da990b jdeparser2-2.0.0.Final/000077500000000000000000000000001250006154200145755ustar00rootroot00000000000000jdeparser2-2.0.0.Final/.gitignore000066400000000000000000000015241250006154200165670ustar00rootroot00000000000000# ignore .svn metadata files .svn # ignore Maven generated target folders ~ target # ignore eclipse files .project .classpath .settings .metadata # ignore m2e annotation processing files .factorypath # ignore IDEA files *.iml *.ipr *.iws .idea # ignore NetBeans files nbactions.xml nb-configuration.xml catalog.xml # maven-ant-tasks.jar test-output transaction.log # vim files *.swp /.gitk-tmp.* atlassian-ide-plugin.xml # temp files *~ # maven versions plugin pom.xml.versionsBackup # hprof dumps /*.hprof # ignore 'randomly' strewn around logs server.log # ignore java crashes hs_err_pid*.log # H2 databases produced by tests *.h2.db # JBoss transaction generated files PutObjectStoreDirHere # ignore mvn-rpmbuild repo /.m2 # ignore eap repo local-repo-eap #These keep hanging around arquillian/*/server.log* client/shade/dependency-reduced-pom.xml jdeparser2-2.0.0.Final/LICENSE.txt000066400000000000000000000261361250006154200164300ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. jdeparser2-2.0.0.Final/pom.xml000066400000000000000000000045271250006154200161220ustar00rootroot00000000000000 4.0.0 org.jboss.jdeparser jdeparser 2.0.0.Final org.jboss jboss-parent 14 junit junit 4.11 test maven-javadoc-plugin net.gleamynode.apiviz.APIviz org.jboss.apiviz apiviz 1.3.2.GA jdeparser2-2.0.0.Final/src/000077500000000000000000000000001250006154200153645ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/main/000077500000000000000000000000001250006154200163105ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/main/java/000077500000000000000000000000001250006154200172315ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/main/java/org/000077500000000000000000000000001250006154200200205ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/main/java/org/jboss/000077500000000000000000000000001250006154200211405ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/000077500000000000000000000000001250006154200231175ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJAssignableExpr.java000066400000000000000000000067331250006154200305000ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; /** * @author David M. Lloyd */ abstract class AbstractJAssignableExpr extends AbstractJExpr implements JAssignableExpr { private BasicJCommentable commentable; protected AbstractJAssignableExpr(final int prec) { super(prec); } public JExpr preDec() { return new IncDecJExpr($PUNCT.UNOP.MM, this, Prec.PRE_INC_DEC); } public JExpr preInc() { return new IncDecJExpr($PUNCT.UNOP.PP, this, Prec.PRE_INC_DEC); } public JExpr postDec() { return new IncDecJExpr($PUNCT.UNOP.MM, this, Prec.POST_INC_DEC, true); } public JExpr postInc() { return new IncDecJExpr($PUNCT.UNOP.PP, this, Prec.POST_INC_DEC, true); } public JExpr shlAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_SHL, this, (AbstractJExpr) e1); } public JExpr lshrAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_LSHR, this, (AbstractJExpr) e1); } public JExpr shrAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_SHR, this, (AbstractJExpr) e1); } public JExpr xorAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_BXOR, this, (AbstractJExpr) e1); } public JExpr orAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_BOR, this, (AbstractJExpr) e1); } public JExpr andAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_BAND, this, (AbstractJExpr) e1); } public JExpr modAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_MOD, this, (AbstractJExpr) e1); } public JExpr divAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_DIV, this, (AbstractJExpr) e1); } public JExpr mulAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_TIMES, this, (AbstractJExpr) e1); } public JExpr subAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_MINUS, this, (AbstractJExpr) e1); } public JExpr addAssign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN_PLUS, this, (AbstractJExpr) e1); } public JExpr assign(final JExpr e1) { return new AssignmentJExpr($PUNCT.BINOP.ASSIGN, this, (AbstractJExpr) e1); } private BasicJCommentable commentable() { if (commentable == null) { commentable = new BasicJCommentable(); } return commentable; } public JComment lineComment() { return commentable().lineComment(); } public JComment blockComment() { return commentable().blockComment(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJCall.java000066400000000000000000000076071250006154200264450ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ abstract class AbstractJCall extends AbstractJExpr implements JCall, AllowedStatementExpression { private ArrayList typeArgs; private ArrayList args; private BasicJCommentable commentable; AbstractJCall(final int prec) { super(prec); } public JCall diamond() { throw new UnsupportedOperationException("Adding diamond to method call"); } public JCall typeArg(final JType type) { if (typeArgs == null) { typeArgs = new ArrayList<>(); } typeArgs.add((AbstractJType) type); return this; } public JCall typeArg(final String type) { return typeArg(JTypes.typeNamed(type)); } public JCall typeArg(final Class type) { return typeArg(JTypes.typeOf(type)); } public JCall arg(final JExpr expr) { if (args == null) { args = new ArrayList<>(); } args.add((AbstractJExpr) expr); return this; } public JType[] typeArguments() { return typeArgs.toArray(new JType[typeArgs.size()]); } public JExpr[] arguments() { return args.toArray(new JExpr[args.size()]); } public JComment lineComment() { if (commentable == null) { commentable = new BasicJCommentable(); } return commentable.lineComment(); } public JComment blockComment() { if (commentable == null) { commentable = new BasicJCommentable(); } return commentable.blockComment(); } void writeTypeArgs(final SourceFileWriter writer) throws IOException { if (typeArgs != null) { final Iterator iterator = typeArgs.iterator(); if (iterator.hasNext()) { writer.write($PUNCT.ANGLE.OPEN); writer.write(iterator.next()); while (iterator.hasNext()) { writer.write($PUNCT.COMMA); writer.write(FormatPreferences.Space.AFTER_COMMA_TYPE_ARGUMENT); writer.write(iterator.next()); } writer.write($PUNCT.ANGLE.CLOSE); } } } public void write(final SourceFileWriter writer) throws IOException { writer.write(FormatPreferences.Space.BEFORE_PAREN); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION); if (args != null) { final Iterator iterator = args.iterator(); if (iterator.hasNext()) { writer.write(iterator.next()); while (iterator.hasNext()) { writer.write($PUNCT.COMMA); writer.write(FormatPreferences.Space.AFTER_COMMA); writer.write(iterator.next()); } } } writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION); writer.write($PUNCT.PAREN.CLOSE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJClassDef.java000066400000000000000000000331721250006154200272520ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static java.lang.Integer.bitCount; import static org.jboss.jdeparser.Tokens.*; import static org.jboss.jdeparser.JMod.*; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; /** * @author David M. Lloyd */ abstract class AbstractJClassDef extends AbstractJGeneric implements JClassDef, ClassFileContent, ClassContent, Sectionable { private final int mods; private final String name; private final AbstractJClassDef enclosingClass; private final ImplJSourceFile classFile; private final ArrayList content = new ArrayList<>(); private JType _extends; private ArrayList _implements; private JType erased; private JType generic; AbstractJClassDef(final int mods, final String name) { this.mods = mods; this.name = name; this.enclosingClass = null; this.classFile = null; } AbstractJClassDef(final int mods, final AbstractJClassDef enclosingClass, final String name) { this.mods = mods; this.name = name; this.enclosingClass = enclosingClass; this.classFile = enclosingClass.classFile; } AbstractJClassDef(final int mods, final ImplJSourceFile classFile, final String name) { this.mods = mods; this.name = name; this.enclosingClass = null; this.classFile = classFile; } AbstractJClassDef getEnclosingClass() { return enclosingClass; } ImplJSourceFile getClassFile() { return classFile; } int getMods() { return mods; } String getName() { return name; } C add(C item) { return add(content, item); } C add(ArrayList content, C item) { content.add(item); return item; } public JClassDefSection section() { return add(new JClassDefSectionImpl(this)); } public JClassDef _extends(final String name) { return _extends(JTypes.typeNamed(name)); } public JClassDef _extends(final JType type) { _extends = type; return this; } public JClassDef _extends(final Class clazz) { return _extends(JTypes.typeOf(clazz)); } public JClassDef _implements(final String... names) { if (_implements == null) { _implements = new ArrayList<>(names.length); } for (String name : names) { _implements.add(JTypes.typeNamed(name)); } return this; } public JClassDef _implements(final JType... types) { if (_implements == null) { _implements = new ArrayList<>(types.length); } Collections.addAll(_implements, types); return this; } public JClassDef _implements(final Class... classes) { if (_implements == null) { _implements = new ArrayList<>(classes.length); } for (Class clazz : classes) { _implements.add(JTypes.typeOf(clazz)); } return this; } public JClassDef blankLine() { add(BlankLine.getInstance()); return this; } public JType erasedType() { if (erased == null) { erased = JTypes.typeNamed(name); } return erased; } public JType genericType() { if (generic == null) { generic = erasedType().typeArg(typeParamsToArgs()); } return generic; } public JTypeParamDef typeParam(final String name) { generic = null; return super.typeParam(name); } public final JBlock init() { return init(content); } public JBlock init(final ArrayList content) { return add(content, new InitJBlock()); } public final JBlock staticInit() { return staticInit(content); } public JBlock staticInit(final ArrayList content) { if (allAreSet(mods, JMod.INNER)) { throw new UnsupportedOperationException("Inner classes cannot have static init blocks"); } return add(content, new StaticInitJBlock()); } public JEnumConstant _enum(final String name) { throw new UnsupportedOperationException("Enum constants may only be added to enums"); } public JVarDeclaration field(final ArrayList content, final int mods, final JType type, final String name, final JExpr init) { if (allAreSet(this.mods, JMod.INNER) && allAreSet(mods, JMod.STATIC)) { throw new UnsupportedOperationException("Inner classes cannot have static members"); } if (anyAreSet(mods, STRICTFP | ABSTRACT | PRIVATE_BITS)) { throw new IllegalArgumentException("Invalid field modifier(s) given"); } if (bitCount(mods & (PUBLIC | PROTECTED | PRIVATE)) > 1) { throw new IllegalArgumentException("Only one of 'public', 'protected', or 'private' may be given"); } return add(content, new FirstJVarDeclaration(mods, type, name, init)); } public final JVarDeclaration field(final int mods, final JType type, final String name) { return field(mods, type, name, null); } public final JVarDeclaration field(final int mods, final JType type, final String name, final JExpr init) { return field(content, mods, type, name, init); } public final JVarDeclaration field(final int mods, final Class type, final String name) { return field(mods, JTypes.typeOf(type), name); } public final JVarDeclaration field(final int mods, final Class type, final String name, final JExpr init) { return field(mods, JTypes.typeOf(type), name, init); } public final JVarDeclaration field(final int mods, final String type, final String name) { return field(mods, JTypes.typeNamed(type), name); } public final JVarDeclaration field(final int mods, final String type, final String name, final JExpr init) { return field(mods, JTypes.typeNamed(type), name, init); } public JMethodDef method(final ArrayList content, final int mods, final JType returnType, final String name) { if (allAreSet(this.mods, JMod.INNER) && allAreSet(mods, JMod.STATIC)) { throw new UnsupportedOperationException("Inner classes cannot have static members"); } if (bitCount(mods & (ABSTRACT | FINAL)) > 1) { throw new IllegalArgumentException("Only one of 'abstract' or 'final' may be given"); } if (bitCount(mods & (PUBLIC | PROTECTED | PRIVATE)) > 1) { throw new IllegalArgumentException("Only one of 'public', 'protected', or 'private' may be given"); } if (anyAreSet(mods, TRANSIENT | VOLATILE | PRIVATE_BITS)) { throw new IllegalArgumentException("Invalid method modifier(s) given"); } return add(content, new MethodJMethodDef(this, mods, returnType, name)); } public final JMethodDef method(final int mods, final JType returnType, final String name) { return method(content, mods, returnType, name); } public final JMethodDef method(final int mods, final Class returnType, final String name) { return method(mods, JTypes.typeOf(returnType), name); } public final JMethodDef method(final int mods, final String returnType, final String name) { return method(mods, JTypes.typeNamed(returnType), name); } boolean methodCanHaveBody(final int mods) { return allAreClear(mods, ABSTRACT | NATIVE); } boolean hasInterfaceStyleExtends() { return false; } boolean supportsCompactInitOnly() { return true; } public JMethodDef constructor(final ArrayList content, final int mods) { if (bitCount(mods & (PUBLIC | PROTECTED | PRIVATE)) > 1) { throw new IllegalArgumentException("Only one of 'public', 'protected', or 'private' may be given"); } if (anyAreSet(mods, TRANSIENT | VOLATILE | ABSTRACT | FINAL | PRIVATE_BITS)) { throw new IllegalArgumentException("Invalid constructor modifier(s) given"); } return add(content, new ConstructorJMethodDef(this, mods)); } public final JMethodDef constructor(final int mods) { return constructor(content, mods); } public JClassDef _class(final ArrayList content, final int mods, final String name) { return add(content, new PlainJClassDef(mods, this, name)); } public JClassDef _enum(final ArrayList content, final int mods, final String name) { return add(content, new EnumJClassDef(mods, this, name)); } public JClassDef _interface(final ArrayList content, final int mods, final String name) { return add(content, new InterfaceJClassDef(mods, this, name)); } public JClassDef annotationInterface(final ArrayList content, final int mods, final String name) { return add(content, new AnnotationJClassDef(mods, this, name)); } public final JClassDef _class(final int mods, final String name) { return _class(content, mods, name); } public final JClassDef _enum(final int mods, final String name) { return _enum(content, mods, name); } public final JClassDef _interface(final int mods, final String name) { return _interface(content, mods, name); } public final JClassDef annotationInterface(final int mods, final String name) { return annotationInterface(content, mods, name); } Iterable getContent() { return content; } JType getExtends() { return _extends; } Iterable getImplements() { return _implements; } abstract $KW designation(); FormatPreferences.Indentation getMemberIndentation() { return FormatPreferences.Indentation.MEMBERS_TOP_LEVEL; } public void write(final SourceFileWriter writer) throws IOException { writeDocComments(writer); writeComments(writer); writeAnnotations(writer, FormatPreferences.Space.AFTER_ANNOTATION); writer.pushThisType(AbstractJType.of(genericType())); try { writeClassHeader(writer); writeContentBlock(writer); } finally { writer.popThisType(AbstractJType.of(genericType())); } } void writeContentBlock(final SourceFileWriter sourceFileWriter) throws IOException { sourceFileWriter.write(FormatPreferences.Space.BEFORE_BRACE_CLASS); sourceFileWriter.write($PUNCT.BRACE.OPEN); final boolean hasOption = sourceFileWriter.getFormat().hasOption(FormatPreferences.Opt.COMPACT_INIT_ONLY_CLASS); if (supportsCompactInitOnly() && hasOption && content.size() == 1 && content.get(0) instanceof InitJBlock) { writeContent(sourceFileWriter); sourceFileWriter.write($PUNCT.BRACE.CLOSE); } else { sourceFileWriter.pushIndent(getMemberIndentation()); try { sourceFileWriter.nl(); writeContent(sourceFileWriter); } finally { sourceFileWriter.popIndent(getMemberIndentation()); } sourceFileWriter.nl(); sourceFileWriter.write($PUNCT.BRACE.CLOSE); sourceFileWriter.nl(); } } void writeClassHeader(final SourceFileWriter sourceFileWriter) throws IOException { JMod.write(sourceFileWriter, mods); sourceFileWriter.write(designation()); sourceFileWriter.writeClass(name); writeTypeParams(sourceFileWriter); final boolean ifExt = hasInterfaceStyleExtends(); if (! ifExt && _extends != null) { sourceFileWriter.write($KW.EXTENDS); sourceFileWriter.write(_extends); } if (_implements != null) { final Iterator iterator = _implements.iterator(); if (iterator.hasNext()) { sourceFileWriter.write(ifExt ? $KW.EXTENDS : $KW.IMPLEMENTS); sourceFileWriter.write(iterator.next()); while (iterator.hasNext()) { sourceFileWriter.write($PUNCT.COMMA); sourceFileWriter.write(iterator.next()); } } } } void writeContent(final SourceFileWriter sourceFileWriter) throws IOException { Iterator iterator = content.iterator(); if (iterator.hasNext()) { iterator.next().write(sourceFileWriter); while (iterator.hasNext()) { sourceFileWriter.nl(); iterator.next().write(sourceFileWriter); } } } public int getModifiers() { return mods; } public boolean hasAllModifiers(final int mods) { return (this.mods & mods) == mods; } public boolean hasAnyModifier(final int mods) { return (this.mods & mods) != 0; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJComment.java000066400000000000000000000166521250006154200271740ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * @author David M. Lloyd */ abstract class AbstractJComment implements JComment, Writable { static final CommentContent NL_CONTENT = new CommentContent() { public void write(final SourceFileWriter writer) throws IOException { writer.nl(); } }; static final CommentTextContent HASH_CONTENT = new CommentTextContent("#"); static final CommentTextContent OPEN_PAREN_CONTENT = new CommentTextContent("("); static final CommentTextContent COMMA_CONTENT = new CommentTextContent(","); static final CommentTextContent CLOSE_PAREN_CONTENT = new CommentTextContent(")"); static final InlineDocTagCommentContent DOC_ROOT_CONTENT = new InlineDocTagCommentContent("docRoot"); private List content; void addItemDirectly(Writable item) { if (item != null) { List content = this.content; if (content == null) { content = this.content = new ArrayList<>(); } content.add(item); } } protected T add(T item) { addItemDirectly(item); return item; } public JComment text(final String text) { int c; int s = 0; int i; for (i = 0; i < text.length(); i = text.offsetByCodePoints(i, 1)) { c = text.codePointAt(i); if (c == '\n') { if (i - s > 0) { add(new CommentTextContent(text.substring(s, i))); } add(NL_CONTENT); s = i + 1; } else if (Character.isWhitespace(c)) { if (i - s > 0) { add(new CommentTextContent(text.substring(s, i))); } add(NonTrailingSpaceContent.getInstance()); s = i + 1; } } if (i - s > 0) { add(new CommentTextContent(text.substring(s, i))); } return this; } public JComment sp() { add(NonTrailingSpaceContent.getInstance()); return this; } public JComment typeName(final JType type) { add(new JTypeCommentContent(type)); return this; } public JComment block() { return this.add(new NestedCommentContent()); } public JComment inlineDocTag(final String tag, final String body) { InlineDocTagCommentContent content = new InlineDocTagCommentContent(tag); add(content).text(body); return this; } public JComment inlineDocTag(final String tag) { return add(new InlineDocTagCommentContent(tag)); } public JComment linkType(boolean plain, final JType targetType) { InlineDocTagCommentContent link = new InlineDocTagCommentContent(plain ? "linkplain" : "link"); link.typeName(targetType); link.sp(); return add(link); } public JComment linkField(boolean plain, final JType targetType, final String targetField) { InlineDocTagCommentContent item = new InlineDocTagCommentContent(plain ? "linkplain" : "link"); item.typeName(targetType); item.add(HASH_CONTENT); item.text(targetField); item.sp(); return add(item); } public JComment linkConstructor(boolean plain, final JType targetType, final JType... params) { InlineDocTagCommentContent item = new InlineDocTagCommentContent(plain ? "linkplain" : "link"); item.typeName(targetType); item.add(HASH_CONTENT); item.typeName(targetType); item.add(OPEN_PAREN_CONTENT); for (int i = 0; i < params.length;) { item.add(new JTypeCommentContent(params[i].erasure())); for (; i < params.length; i ++) { item.add(COMMA_CONTENT); item.add(new JTypeCommentContent(params[i].erasure())); } } item.add(CLOSE_PAREN_CONTENT); item.sp(); return add(item); } public JComment linkMethod(boolean plain, final JType targetType, final String targetMethod, final JType... params) { InlineDocTagCommentContent item = new InlineDocTagCommentContent(plain ? "linkplain" : "link"); item.typeName(targetType); item.add(HASH_CONTENT); item.text(targetMethod); item.add(OPEN_PAREN_CONTENT); for (int i = 0; i < params.length;) { item.add(new JTypeCommentContent(params[i].erasure())); for (; i < params.length; i ++) { item.add(COMMA_CONTENT); item.add(new JTypeCommentContent(params[i].erasure())); } } item.add(CLOSE_PAREN_CONTENT); item.sp(); return add(item); } public JComment linkMethod(boolean plain, final JMethodDef methodDef) { if (methodDef instanceof AbstractJMethodDef) { AbstractJMethodDef abstractJMethodDef = (AbstractJMethodDef) methodDef; AbstractJClassDef clazz = abstractJMethodDef.clazz(); JTypeCommentContent typeContent = new JTypeCommentContent(clazz.erasedType()); CommentContent name; if (methodDef instanceof MethodJMethodDef) { name = new CommentTextContent(((MethodJMethodDef) methodDef).getName()); } else { assert methodDef instanceof ConstructorJMethodDef; name = typeContent; } InlineDocTagCommentContent item = new InlineDocTagCommentContent(plain ? "linkplain" : "link"); item.add(typeContent); item.add(HASH_CONTENT); item.add(name); item.add(OPEN_PAREN_CONTENT); JParamDeclaration[] params = abstractJMethodDef.params(); if (params.length > 0) { item.add(new JTypeCommentContent(params[0].type().erasure())); for (int i = 1; i < params.length; i ++) { item.add(COMMA_CONTENT); item.add(new JTypeCommentContent(params[i].type().erasure())); } } item.add(CLOSE_PAREN_CONTENT); item.sp(); return add(item); } else { throw new IllegalArgumentException(); } } public JComment code() { return inlineDocTag("code"); } public JComment docRoot() { add(DOC_ROOT_CONTENT); return this; } public JComment nl() { add(NL_CONTENT); return this; } public void write(final SourceFileWriter writer) throws IOException { for (Writable item : content) { item.write(writer); } } List getContent() { return content; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJDocComment.java000066400000000000000000000060751250006154200276200ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License");a * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** * @author David M. Lloyd */ abstract class AbstractJDocComment extends AbstractJHtmlComment implements JDocComment { private Map> docTags; public JDocComment block() { return (JDocComment) super.block(); } public JDocComment sp() { super.sp(); return this; } public JDocComment nl() { super.nl(); return this; } public JDocComment typeName(final JType type) { super.typeName(type); return this; } public JDocComment text(final String text) { super.text(text); return this; } public JDocComment inlineDocTag(final String tag, final String body) { super.inlineDocTag(tag, body); return this; } public JDocComment docRoot() { super.docRoot(); return this; } public JDocComment p() { super.p(); return this; } public JDocComment br() { super.br(); return this; } public JDocComment value(final JType type, final String fieldName) { super.value(type, fieldName); return this; } public JHtmlComment docTag(final String tag) { Map> docTags = this.docTags; if (docTags == null) { docTags = this.docTags = new LinkedHashMap<>(); } List tagList = docTags.get(tag); if (tagList == null) { docTags.put(tag, tagList = new ArrayList()); } DocTagJHtmlComment tagComment = new DocTagJHtmlComment(tag); tagList.add(tagComment); return tagComment; } public JHtmlComment docTag(final String tag, final String firstWord) { JHtmlComment docTag = docTag(tag); docTag.text(firstWord).sp(); return docTag; } public JHtmlComment _return() { return docTag("return"); } public JHtmlComment _throws(final JType exceptionType) { return docTag("throws"); } public JHtmlComment param(final String name) { return docTag("param", name); } Map> getDocTags() { return docTags; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJDocCommentable.java000066400000000000000000000026621250006154200304420ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ abstract class AbstractJDocCommentable extends BasicJCommentable implements JDocCommentable { private ImplJDocComment docComment; public JDocComment docComment() { if (docComment == null) { docComment = new ImplJDocComment(); } return docComment; } public JComment deprecated() { return docComment().docTag("deprecated"); } void writeDocComments(SourceFileWriter writer) throws IOException { final ImplJDocComment docComment = this.docComment; if (docComment != null) { docComment.write(writer); } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJExpr.java000066400000000000000000000154021250006154200265000ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; /** * @author David M. Lloyd */ abstract class AbstractJExpr implements JExpr, Writable { private final int prec; protected AbstractJExpr(final int prec) { this.prec = prec; } static AbstractJExpr of(final JExpr expr) { if (expr instanceof AbstractJExpr) { return (AbstractJExpr) expr; } throw new IllegalArgumentException("Expression from different implementation"); } public JExpr plus(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.PLUS, this, (AbstractJExpr) e1, Prec.ADDITIVE); } public JExpr minus(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.MINUS, this, (AbstractJExpr) e1, Prec.ADDITIVE); } public JExpr times(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.TIMES, this, (AbstractJExpr) e1, Prec.MULTIPLICATIVE); } public JExpr div(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.DIV, this, (AbstractJExpr) e1, Prec.MULTIPLICATIVE); } public JExpr mod(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.MOD, this, (AbstractJExpr) e1, Prec.MULTIPLICATIVE); } public JExpr neg() { return new UnaryJExpr($PUNCT.UNOP.MINUS, this); } public JExpr band(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.BAND, this, (AbstractJExpr) e1, Prec.BIT_AND); } public JExpr bor(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.BOR, this, (AbstractJExpr) e1, Prec.BIT_OR); } public JExpr bxor(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.BXOR, this, (AbstractJExpr) e1, Prec.BIT_XOR); } public JExpr shr(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.SHR, this, (AbstractJExpr) e1, Prec.SHIFT); } public JExpr lshr(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.LSHR, this, (AbstractJExpr) e1, Prec.SHIFT); } public JExpr shl(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.SHL, this, (AbstractJExpr) e1, Prec.SHIFT); } public JExpr comp() { return new UnaryJExpr($PUNCT.UNOP.COMP, this); } public JExpr and(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.LAND, this, (AbstractJExpr) e1, Prec.LOG_AND); } public JExpr or(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.LOR, this, (AbstractJExpr) e1, Prec.LOG_OR); } public JExpr not() { return new UnaryJExpr($PUNCT.UNOP.NOT, this); } public JExpr eq(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.EQ, this, (AbstractJExpr) e1, Prec.EQUALITY); } public JExpr ne(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.NE, this, (AbstractJExpr) e1, Prec.EQUALITY); } public JExpr lt(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.LT, this, (AbstractJExpr) e1, Prec.RELATIONAL); } public JExpr gt(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.GT, this, (AbstractJExpr) e1, Prec.RELATIONAL); } public JExpr le(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.LE, this, (AbstractJExpr) e1, Prec.RELATIONAL); } public JExpr ge(final JExpr e1) { return new BinaryJExpr($PUNCT.BINOP.GE, this, (AbstractJExpr) e1, Prec.RELATIONAL); } public JExpr cond(final JExpr ifTrue, final JExpr ifFalse) { return new CondJExpr(this, (AbstractJExpr) ifTrue, (AbstractJExpr) ifFalse); } public JExpr paren() { return new ParenJExpr(this); } public JExpr _instanceof(final String type) { return _instanceof(JTypes.typeNamed(type)); } public JExpr _instanceof(final JType type) { return new InstanceOfJExpr(this, type); } public JExpr _instanceof(final Class type) { return _instanceof(JTypes.typeOf(type)); } public JExpr cast(final String type) { return new CastJExpr(this, JTypes.typeNamed(type)); } public JExpr cast(final JType type) { return new CastJExpr(this, type); } public JExpr cast(final Class type) { return new CastJExpr(this, JTypes.typeOf(type)); } public JCall call(final String name) { return new InstanceJCall(this, name); } public JCall _new(final String type) { return new InnerNewJCall(this, JTypes.typeNamed(type)); } public JCall _new(final JType type) { return new InnerNewJCall(this, type); } public JCall _new(final Class type) { return new InnerNewJCall(this, JTypes.typeOf(type)); } public JAnonymousClassDef _newAnon(final String type) { return new InnerJAnonymousClassDef(this, JTypes.typeNamed(type)); } public JAnonymousClassDef _newAnon(final JType type) { return new InnerJAnonymousClassDef(this, type); } public JAnonymousClassDef _newAnon(final Class type) { return new InnerJAnonymousClassDef(this, JTypes.typeOf(type)); } private CachingLinkedHashMap fieldCache; public JAssignableExpr field(final String name) { CachingLinkedHashMap map = fieldCache; if (map == null) { map = fieldCache = new CachingLinkedHashMap<>(); } JAssignableExpr expr = map.get(name); if (expr == null) { map.put(name, expr = new FieldRefJExpr(this, name)); } return expr; } public JAssignableExpr $v(final String name) { return field(name); } public JAssignableExpr idx(final JExpr idx) { return new ArrayLookupJExpr(this, (AbstractJExpr) idx); } public JExpr idx(final int idx) { return new ArrayLookupJExpr(this, (AbstractJExpr) JExprs.decimal(idx)); } private JExpr length; public JExpr length() { JExpr length = this.length; if (length == null) { length = this.length = new FieldRefJExpr(this, "length"); } return length; } public int prec() { return prec; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJGeneric.java000066400000000000000000000054451250006154200271440ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ abstract class AbstractJGeneric extends BasicJAnnotatable implements JGenericDef { private ArrayList typeParamDefs; private ImplJTypeParamDef add(ImplJTypeParamDef item) { if (typeParamDefs == null) { typeParamDefs = new ArrayList<>(); } typeParamDefs.add(item); return item; } public JTypeParamDef typeParam(final String name) { return add(new ImplJTypeParamDef(name)); } public JTypeParamDef[] typeParams() { return typeParamDefs.toArray(new JTypeParamDef[typeParamDefs.size()]); } JType[] typeParamsToArgs() { final ArrayList typeParamDefs = this.typeParamDefs; if (typeParamDefs == null) { return JType.NONE; } final JType[] jTypes = new JType[typeParamDefs.size()]; int i = 0; for (ImplJTypeParamDef paramDef : typeParamDefs) { jTypes[i++] = JTypes.typeNamed(paramDef.getName()); } return jTypes; } void writeTypeParams(final SourceFileWriter sourceFileWriter) throws IOException { if (typeParamDefs != null) { final Iterator iterator = typeParamDefs.iterator(); if (iterator.hasNext()) { if (sourceFileWriter.getState() instanceof $KW) { sourceFileWriter.sp(); } sourceFileWriter.write($PUNCT.ANGLE.OPEN); ImplJTypeParamDef def = iterator.next(); def.write(sourceFileWriter); while (iterator.hasNext()) { sourceFileWriter.write($PUNCT.COMMA); def = iterator.next(); def.write(sourceFileWriter); } sourceFileWriter.write($PUNCT.ANGLE.CLOSE); sourceFileWriter.sp(); } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJHtmlComment.java000066400000000000000000000071511250006154200300130ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.Locale; /** * @author David M. Lloyd */ abstract class AbstractJHtmlComment extends AbstractJComment implements JHtmlComment { protected T add(final T item) { addItemDirectly(item); return item; } public JHtmlComment block() { return this.add(new NestedHtmlCommentContent()); } public JHtmlComment sp() { super.sp(); return this; } public JHtmlComment nl() { super.nl(); return this; } public JHtmlComment typeName(final JType type) { super.typeName(type); return this; } public JHtmlComment text(final String text) { super.text(text); return this; } public JHtmlComment inlineDocTag(final String tag, final String body) { super.inlineDocTag(tag, body); return this; } public JHtmlComment docRoot() { super.docRoot(); return this; } public JHtmlComment p() { nl(); htmlTag("p", false); nl(); return this; } public JHtmlComment br() { htmlTag("br", false); nl(); return this; } public JHtmlComment value(final JType type, final String fieldName) { inlineDocTag("value").typeName(type).text("#").text(fieldName); return this; } public JHtmlTag htmlLink(final String url) { return htmlTag("a", false).attribute("href", url); } public JHtmlTag htmlTag(final String tag, final boolean newLine) { boolean writeClose; switch (tag.toLowerCase(Locale.US)) { // content forbidden case "area": case "base": case "basefont": case "br": case "col": case "frame": case "hr": case "img": case "input": case "isindex": case "link": case "meta": case "param": // end tag optional case "body": case "colgroup": case "dd": case "dt": case "head": case "html": case "li": case "option": case "p": case "tbody": case "td": case "textarea": case "tfoot": case "th": case "thead": case "tr": { writeClose = false; break; } default: { writeClose = true; break; } } final ImplJHtmlTag htmlTag = new ImplJHtmlTag(tag, newLine, writeClose); return add(htmlTag); } public JComment preformattedCode() { JComment main = htmlTag("pre", false).code().nl(); JComment block = main.block(); main.nl(); return block; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJMethodDef.java000066400000000000000000000157531250006154200274320ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ abstract class AbstractJMethodDef extends AbstractJGeneric implements JMethodDef, ClassContent { private final AbstractJClassDef clazz; private int mods; private ArrayList params; private ArrayList _throws; private BasicJBlock body; AbstractJMethodDef(final AbstractJClassDef clazz, final int mods) { this.clazz = clazz; this.mods = mods; } public JBlock _default() { throw new UnsupportedOperationException("Default method implementation"); } public JMethodDef _default(final JExpr expr) { throw new UnsupportedOperationException("Default method value"); } public JBlock body() { if (! writeBody()) { throw new UnsupportedOperationException("Method body on abstract method"); } if (body == null) { body = new BasicJBlock(null, JBlock.Braces.REQUIRED); } return body; } public JComment returnsDoc() { return null; } private ImplJParamDeclaration add(ImplJParamDeclaration item) { if (params == null) { params = new ArrayList<>(); } params.add(item); return item; } public JParamDeclaration param(final int mods, final JType type, final String name) { if (JMod.anyAreSet(this.mods, JMod.VARARGS)) { throw new IllegalStateException("Vararg parameter already added"); } return add(new ImplJParamDeclaration(mods, type, name)); } public JParamDeclaration param(final JType type, final String name) { return param(0, type, name); } public JParamDeclaration param(final int mods, final String type, final String name) { return param(mods, JTypes.typeNamed(type), name); } public JParamDeclaration param(final String type, final String name) { return param(JTypes.typeNamed(type), name); } public JParamDeclaration param(final int mods, final Class type, final String name) { return param(mods, JTypes.typeOf(type), name); } public JParamDeclaration param(final Class type, final String name) { return param(JTypes.typeOf(type), name); } public JParamDeclaration varargParam(final int mods, final JType type, final String name) { if (JMod.anyAreSet(this.mods, JMod.VARARGS)) { throw new IllegalStateException("Vararg parameter already added"); } this.mods |= JMod.VARARGS; return add(new ImplJParamDeclaration(mods | JMod.VARARGS, type, name)); } public JParamDeclaration varargParam(final JType type, final String name) { return varargParam(0, type, name); } public JParamDeclaration varargParam(final int mods, final String type, final String name) { return varargParam(mods, JTypes.typeNamed(type), name); } public JParamDeclaration varargParam(final String type, final String name) { return varargParam(JTypes.typeNamed(type), name); } public JParamDeclaration varargParam(final int mods, final Class type, final String name) { return varargParam(mods, JTypes.typeOf(type), name); } public JParamDeclaration varargParam(final Class type, final String name) { return varargParam(JTypes.typeOf(type), name); } public JParamDeclaration[] params() { return params.toArray(new JParamDeclaration[params.size()]); } public JComment _throws(final String type) { return _throws(JTypes.typeNamed(type)); } public JComment _throws(final JType type) { if (_throws == null) { _throws = new ArrayList<>(); } _throws.add(AbstractJType.of(type)); // todo return null; } public JComment _throws(final Class type) { return _throws(JTypes.typeOf(type)); } int getModifiers() { return mods; } boolean writeBody() { return clazz.methodCanHaveBody(mods); } public void write(final SourceFileWriter writer) throws IOException { writer.write(FormatPreferences.Space.BEFORE_PAREN_METHOD_DECLARATION); writer.write($PUNCT.PAREN.OPEN); if (params != null) { writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION); final Iterator iterator = params.iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.write(FormatPreferences.Space.BEFORE_COMMA); writer.write($PUNCT.COMMA); writer.write(FormatPreferences.Space.AFTER_COMMA); iterator.next().write(writer); } } } else { writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION_EMPTY); } writer.write($PUNCT.PAREN.CLOSE); if (_throws != null) { final Iterator iterator = _throws.iterator(); if (iterator.hasNext()) { writer.sp(); writer.write($KW.THROWS); writer.write(iterator.next()); while (iterator.hasNext()) { writer.write(FormatPreferences.Space.BEFORE_COMMA); writer.write($PUNCT.COMMA); writer.write(FormatPreferences.Space.AFTER_COMMA); writer.write(iterator.next()); } } } writePostfix(writer); if (! writeBody()) { writer.write($PUNCT.SEMI); } else { writer.write(FormatPreferences.Space.BEFORE_BRACE_METHOD); if (body == null) { writer.write($PUNCT.BRACE.OPEN); writer.write(FormatPreferences.Space.WITHIN_BRACES_EMPTY); writer.write($PUNCT.BRACE.CLOSE); } else { body.write(writer); } } } void writePostfix(final SourceFileWriter writer) throws IOException { } AbstractJClassDef clazz() { return clazz; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractJType.java000066400000000000000000000134761250006154200265140ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; /** * @author David M. Lloyd */ abstract class AbstractJType implements JType { private ArrayJType array; private WildcardJType wildcardExtends; private WildcardJType wildcardSuper; static AbstractJType of(JType type) { if (type instanceof AbstractJType) { return (AbstractJType) type; } throw new IllegalArgumentException("Using a JType from a different implementation"); } String qualifiedName(SourceFileWriter writer) { return simpleName(); } public abstract String simpleName(); public abstract String toString(); public JExpr _class() { throw new UnsupportedOperationException("Adding .class to " + this); } public JExpr _this() { throw new UnsupportedOperationException("Adding .this to " + this); } public JExpr _super() { throw new UnsupportedOperationException("Adding .super to " + this); } public JType array() { if (array == null) { array = new ArrayJType(this); } return array; } public JCall _new() { throw new UnsupportedOperationException("Instantiating a " + this + " as a class"); } public JExpr _new(final JExpr dim) { throw new UnsupportedOperationException("Instantiating a " + this + " as an array"); } public JExpr _new(final int dim) { return _new(JExprs.decimal(dim)); } public JArrayExpr _newArray() { throw new UnsupportedOperationException("Instantiating a " + this + " as an array"); } public JAnonymousClassDef _newAnon() { throw new UnsupportedOperationException("Instantiating a " + this + " as a class"); } public JType typeArg(final String... args) { final JType[] types = new JType[args.length]; for (int i = 0, argsLength = args.length; i < argsLength; i++) { types[i] = JTypes.typeNamed(args[i]); } return typeArg(types); } public JType typeArg(final JType... args) { throw new UnsupportedOperationException("Adding type arguments to " + this); } public JType typeArg(final Class... args) { final JType[] types = new JType[args.length]; for (int i = 0, argsLength = args.length; i < argsLength; i++) { types[i] = JTypes.typeOf(args[i]); } return typeArg(types); } public JType[] typeArgs() { return NONE; } public JType erasure() { return this; } public JType elementType() { throw new UnsupportedOperationException("Getting element type from " + this); } public JType box() { return this; } public JType unbox() { return this; } public JType wildcardExtends() { if (wildcardExtends == null) { wildcardExtends = new WildcardJType(this, true); } return wildcardExtends; } public JType wildcardSuper() { if (wildcardSuper == null) { wildcardSuper = new WildcardJType(this, false); } return wildcardSuper; } public JType nestedType(final String name) { throw new UnsupportedOperationException("Lookup of nested type on " + this); } public JType $t(final String name) { return nestedType(name); } private CachingLinkedHashMap staticRefs; public JAssignableExpr field(final String name) { CachingLinkedHashMap map = staticRefs; if (map == null) { map = staticRefs = new CachingLinkedHashMap<>(); } JAssignableExpr expr = map.get(name); if (expr == null) { map.put(name, expr = new StaticRefJExpr(this, name)); } return expr; } public JAssignableExpr $v(final String name) { return field(name); } public JCall call(final String name) { return new StaticJCall(this, name); } public JCall call(final ExecutableElement method) { final ElementKind kind = method.getKind(); if (kind == ElementKind.METHOD && ! method.getModifiers().contains(Modifier.STATIC)) { final String name = method.getSimpleName().toString(); return call(name); } throw new IllegalArgumentException("Unsupported element for call: " + method); } public JExpr methodRef(final String name) { return new MethodRefJExpr(this, name); } public JExpr methodRef(final ExecutableElement method) { final ElementKind kind = method.getKind(); if (kind == ElementKind.METHOD && ! method.getModifiers().contains(Modifier.STATIC)) { final String name = method.getSimpleName().toString(); return methodRef(name); } throw new IllegalArgumentException("Unsupported element for method ref: " + method); } abstract void writeDirect(SourceFileWriter sourceFileWriter) throws IOException; } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AbstractMethodJCall.java000066400000000000000000000024111250006154200275720ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ abstract class AbstractMethodJCall extends AbstractJCall { private final String name; public AbstractMethodJCall(final String name) { super(Prec.METHOD_CALL); this.name = name; } String getName() { return name; } public void write(final SourceFileWriter writer) throws IOException { super.writeTypeArgs(writer); writer.writeEscaped(name); super.write(writer); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AllowedStatementExpression.java000066400000000000000000000015321250006154200313170ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface AllowedStatementExpression { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AnnotationJClassDef.java000066400000000000000000000057331250006154200276230ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.ArrayList; /** * @author David M. Lloyd */ class AnnotationJClassDef extends AbstractJClassDef implements JClassItem { AnnotationJClassDef(final int mods, final ImplJSourceFile classFile, final String name) { super(mods, classFile, name); } AnnotationJClassDef(final int mods, final AbstractJClassDef enclosingClass, final String name) { super(mods, enclosingClass, name); } Tokens.$KW designation() { return Tokens.$KW.AT_INTERFACE; } public JClassDef _extends(final String name) { throw new UnsupportedOperationException("extends on @interface"); } public JClassDef _extends(final JType type) { throw new UnsupportedOperationException("extends on @interface"); } public JClassDef _extends(final Class clazz) { throw new UnsupportedOperationException("extends on @interface"); } public JClassDef _implements(final String... names) { throw new UnsupportedOperationException("implements on @interface"); } public JClassDef _implements(final JType... types) { throw new UnsupportedOperationException("implements on @interface"); } public JClassDef _implements(final Class... classes) { throw new UnsupportedOperationException("implements on @interface"); } public JBlock init(final ArrayList content) { throw new UnsupportedOperationException("init block on @interface"); } boolean methodCanHaveBody(final int mods) { return false; } public JMethodDef constructor(final ArrayList content, final int mods) { throw new UnsupportedOperationException("constructor on @interface"); } public JTypeParamDef typeParam(final String name) { throw new UnsupportedOperationException("type parameters on @interface"); } public JMethodDef method(final ArrayList content, final int mods, final JType returnType, final String name) { return add(content, new AnnotationJMethodDef(this, mods, returnType, name)); } public Kind getItemKind() { return Kind.ANNOTATION_INTERFACE; } public String getName() { return super.getName(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AnnotationJMethodDef.java000066400000000000000000000042201250006154200277640ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.$KW; import java.io.IOException; /** * @author David M. Lloyd */ class AnnotationJMethodDef extends MethodJMethodDef { private JExpr defaultVal; AnnotationJMethodDef(final AbstractJClassDef enclosingClass, final int mods, final JType returnType, final String name) { super(enclosingClass, mods, returnType, name); } public JBlock body() { throw new UnsupportedOperationException("body on annotation interface method"); } public JParamDeclaration param(final int mods, final JType type, final String name) { throw new UnsupportedOperationException("param on annotation interface method"); } public JParamDeclaration varargParam(final int mods, final JType type, final String name) { throw new UnsupportedOperationException("param on annotation interface method"); } public JComment _throws(final JType type) { throw new UnsupportedOperationException("throws on annotation interface method"); } public JMethodDef _default(final JExpr defaultVal) { this.defaultVal = defaultVal; return this; } boolean writeBody() { return false; } void writePostfix(final SourceFileWriter writer) throws IOException { if (defaultVal != null) { writer.write($KW.DEFAULT); writer.write(defaultVal); } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AnonymousJClassDef.java000066400000000000000000000026421250006154200274750ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class AnonymousJClassDef extends AbstractJClassDef { AnonymousJClassDef(ImplJAnonymousClassDef anonymousClassDef) { super(0, anonymousClassDef.type().simpleName()); } Tokens.$KW designation() { // not used return Tokens.$KW.NEW; } void writeTypeParams(final SourceFileWriter sourceFileWriter) throws IOException { // none } void writeAnnotations(final SourceFileWriter writer) throws IOException { // none } void writeClassHeader(final SourceFileWriter sourceFileWriter) throws IOException { // none } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ArrayJType.java000066400000000000000000000040731250006154200260200ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ArrayJType extends AbstractJType { private final AbstractJType elementType; private StaticRefJExpr classExpr; ArrayJType(final AbstractJType elementType) { this.elementType = elementType; } public JType elementType() { return elementType; } void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException { sourceFileWriter.write(elementType); sourceFileWriter.write($PUNCT.BRACKET.OPEN); sourceFileWriter.write($PUNCT.BRACKET.CLOSE); } String qualifiedName(final SourceFileWriter writer) { return elementType.qualifiedName(writer); } public JExpr _new(final JExpr dim) { return new NewDimJArrayExpr(this, AbstractJExpr.of(dim)); } public JArrayExpr _newArray() { return new NewUndimJArrayExpr(this); } public String simpleName() { return elementType.simpleName(); } public String toString() { return elementType.toString() + "[]"; } public JExpr _class() { StaticRefJExpr expr = classExpr; if (expr == null) { expr = classExpr = new StaticRefJExpr(this, "class"); } return expr; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ArrayLookupJExpr.java000066400000000000000000000026761250006154200272160ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ArrayLookupJExpr extends AbstractJAssignableExpr { private final AbstractJExpr expr; private final AbstractJExpr idx; ArrayLookupJExpr(final AbstractJExpr expr, final AbstractJExpr idx) { super(Prec.ARRAY_ACCESS); this.expr = expr.prec() < Prec.ARRAY_ACCESS ? new ParenJExpr(expr) : expr; this.idx = idx; } public void write(final SourceFileWriter writer) throws IOException { writer.write(expr); writer.write($PUNCT.BRACKET.OPEN); writer.write(idx); writer.write($PUNCT.BRACKET.CLOSE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AssertMessageJStatement.java000066400000000000000000000027771250006154200305440ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class AssertMessageJStatement extends KeywordExprJStatement { private final JExpr message; AssertMessageJStatement(final JExpr expr, final JExpr message) { super($KW.ASSERT, expr); this.message = message; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.ASSERT); writer.write(getExpression()); writer.write(FormatPreferences.Space.BEFORE_COLON); writer.write($PUNCT.COLON); writer.write(FormatPreferences.Space.AFTER_COLON); writer.write(message); writer.write($PUNCT.SEMI); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Assertions.java000066400000000000000000000026161250006154200261210ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import sun.reflect.Reflection; /** * @author David M. Lloyd */ class Assertions { static boolean callerIs(Class clazz) { try { return Reflection.getCallerClass(3) == clazz; } catch (Throwable ignored) {} // dunno return true; } @SuppressWarnings("ConstantConditions") static boolean alwaysTrue(boolean expr) { assert expr : "Expected expression to be true"; return expr; } @SuppressWarnings("ConstantConditions") static boolean alwaysFalse(boolean expr) { assert ! expr : "Expected expression to be false"; return expr; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/AssignmentJExpr.java000066400000000000000000000021121250006154200270370ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; /** * @author David M. Lloyd */ class AssignmentJExpr extends BinaryJExpr implements AllowedStatementExpression { AssignmentJExpr(final $PUNCT.BINOP op, final AbstractJExpr e1, final AbstractJExpr e2) { super(op, e1, e2, Prec.ASSIGN, Assoc.RIGHT); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Assoc.java000066400000000000000000000015321250006154200250330ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ enum Assoc { LEFT, RIGHT, ; } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BasicJAnnotatable.java000066400000000000000000000035751250006154200273000ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.lang.annotation.Annotation; import java.util.ArrayList; import org.jboss.jdeparser.FormatPreferences.Space; /** * @author David M. Lloyd */ class BasicJAnnotatable extends AbstractJDocCommentable implements JAnnotatable { private ArrayList annotations; private ImplJAnnotation add(ImplJAnnotation item) { if (annotations == null) { annotations = new ArrayList<>(3); } annotations.add(item); return item; } public JAnnotation annotate(final String type) { return annotate(JTypes.typeNamed(type)); } public JAnnotation annotate(final JType type) { return add(new ImplJAnnotation(type)); } public JAnnotation annotate(final Class type) { return annotate(JTypes.typeOf(type)); } void writeAnnotations(final SourceFileWriter writer, final Space space) throws IOException { if (annotations != null) for (ImplJAnnotation annotation : annotations) { annotation.write(writer); writer.write(space); } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BasicJBlock.java000066400000000000000000000362531250006154200261010ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; /** * @author David M. Lloyd */ class BasicJBlock extends BasicJCommentable implements JBlock, BlockContent { private final BasicJBlock parent; private final ArrayList content = new ArrayList<>(); private final Braces braces; private int tmpId = 1; BasicJBlock(final BasicJBlock parent, final Braces braces) { this.parent = parent; this.braces = braces; } private T add(T s) { content.add(s); return s; } private ExpressionJStatement add(T item) { final ExpressionJStatement statement = new ExpressionJStatement(item); content.add(statement); return statement; } private T add(T item) { content.add(new ExpressionJStatement(item)); return item; } public JBlock blankLine() { add(BlankLine.getInstance()); return this; } public JBlock block(final Braces braces) { return add(new BasicJBlock(this, braces)); } public JIf _if(final JExpr cond) { return add(new ImplJIf(this, cond)); } public JBlock _while(final JExpr cond) { return add(new WhileJBlock(this, cond)); } public JBlock _do(final JExpr cond) { return add(new DoJBlock(this, cond)); } public JLabel label(final String name) { return add(new ImplJLabel(name)); } public JLabel anonLabel() { return add(new ImplJLabel(tempName())); } public JLabel forwardLabel() { return new ImplJLabel(); } public JLabel label(final JLabel label, final String name) { ImplJLabel label1 = (ImplJLabel) label; if (label1.isResolved()) { throw new IllegalStateException("Label " + label + " is already resolved"); } label1.setName(name); return add(label1); } public JLabel anonLabel(final JLabel label) { ImplJLabel label1 = (ImplJLabel) label; if (label1.isResolved()) { throw new IllegalStateException("Label " + label + " is already resolved"); } label1.setName(tempName()); return add(label1); } public JStatement _continue() { return add(new KeywordJStatement($KW.CONTINUE)); } public JStatement _continue(final JLabel label) { return add(new GotoJStatement($KW.CONTINUE, label)); } public JStatement _break() { return add(new KeywordJStatement($KW.BREAK)); } public JStatement _break(final JLabel label) { return add(new GotoJStatement($KW.BREAK, label)); } public JBlock forEach(final int mods, final String type, final String name, final JExpr iterable) { return forEach(mods, JTypes.typeNamed(type), name, iterable); } public JBlock forEach(final int mods, final JType type, final String name, final JExpr iterable) { return add(new ForEachJBlock(this, mods, type, name, iterable)); } public JBlock forEach(final int mods, final Class type, final String name, final JExpr iterable) { return forEach(mods, JTypes.typeOf(type), name, iterable); } public JFor _for() { return add(new ForJBlock(this)); } public JSwitch _switch(final JExpr expr) { return add(new ImplJSwitch(parent, expr)); } public JStatement _return(final JExpr expr) { return add(new KeywordExprJStatement($KW.RETURN, expr)); } public JStatement _return() { return add(new KeywordJStatement($KW.RETURN)); } public JStatement _assert(final JExpr expr) { return add(new KeywordExprJStatement($KW.ASSERT, expr)); } public JStatement _assert(final JExpr expr, final JExpr message) { return add(new AssertMessageJStatement(expr, message)); } public JCall callThis() { return add(new KeywordJCall($KW.THIS)); } public JCall callSuper() { return add(new KeywordJCall($KW.SUPER)); } public JStatement add(final JExpr expr) { if (expr instanceof AllowedStatementExpression) { return add(new ExpressionJStatement(AbstractJExpr.of(expr))); } else { throw new IllegalArgumentException("Expression <<" + expr + ">> is not a valid statement"); } } public JCall call(final ExecutableElement element) { final ElementKind kind = element.getKind(); if (kind == ElementKind.METHOD) { final String name = element.getSimpleName().toString(); return call(name); } throw new IllegalArgumentException("Unsupported element for call: " + element); } public JCall call(final JExpr obj, final ExecutableElement element) { final ElementKind kind = element.getKind(); if (kind == ElementKind.METHOD) { final String name = element.getSimpleName().toString(); return call(obj, name); } throw new IllegalArgumentException("Unsupported element for call: " + element); } public JCall call(final String name) { return add(new DirectJCall(name)); } public JCall call(final JExpr obj, final String name) { return add(new InstanceJCall(obj, name)); } public JCall callStatic(final ExecutableElement element) { final ElementKind kind = element.getKind(); if (kind == ElementKind.METHOD && element.getModifiers().contains(Modifier.STATIC)) { final String name = element.getSimpleName().toString(); final JType enclosingType = JTypes.typeOf(element.getEnclosingElement().asType()); return callStatic(enclosingType, name); } throw new IllegalArgumentException("Unsupported element for callStatic: " + element); } public JCall callStatic(final String type, final String name) { return callStatic(JTypes.typeNamed(type), name); } public JCall callStatic(final JType type, final String name) { return add(new StaticJCall(type, name)); } public JCall callStatic(final Class type, final String name) { return callStatic(JTypes.typeOf(type), name); } public JCall _new(final String type) { return _new(JTypes.typeNamed(type)); } public JCall _new(final JType type) { return add(new NewJCall(AbstractJType.of(type))); } public JCall _new(final Class type) { return _new(JTypes.typeOf(type)); } public JAnonymousClassDef _newAnon(final String type) { return _newAnon(JTypes.typeNamed(type)); } public JAnonymousClassDef _newAnon(final JType type) { return add(new ImplJAnonymousClassDef(type)); } public JAnonymousClassDef _newAnon(final Class type) { return _newAnon(JTypes.typeOf(type)); } public JClassDef _class(final int mods, final String name) { return add(new PlainJClassDef(mods, (ImplJSourceFile) null, name)); } public JBlock _synchronized(final JExpr synchExpr) { return add(new SynchJBlock(this, PlainJArrayExpr.of(synchExpr))); } public JStatement assign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement addAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_PLUS, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement subAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_MINUS, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement mulAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_TIMES, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement divAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_DIV, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement modAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_MOD, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement andAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_BAND, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement orAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_BOR, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement xorAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_BXOR, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement shrAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_SHR, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement lshrAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_LSHR, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement shlAssign(final JAssignableExpr target, final JExpr e1) { return add(new AssignmentJExpr($PUNCT.BINOP.ASSIGN_SHL, AbstractJExpr.of(target), AbstractJExpr.of(e1))); } public JStatement postInc(final JAssignableExpr target) { return add(new IncDecJExpr($PUNCT.UNOP.PP, AbstractJExpr.of(target), Prec.POST_INC_DEC, true)); } public JStatement postDec(final JAssignableExpr target) { return add(new IncDecJExpr($PUNCT.UNOP.MM, AbstractJExpr.of(target), Prec.POST_INC_DEC, true)); } public JStatement preInc(final JAssignableExpr target) { return add(new IncDecJExpr($PUNCT.UNOP.PP, AbstractJExpr.of(target), Prec.PRE_INC_DEC, false)); } public JStatement preDec(final JAssignableExpr target) { return add(new IncDecJExpr($PUNCT.UNOP.MM, AbstractJExpr.of(target), Prec.PRE_INC_DEC, false)); } public JStatement empty() { return add(new EmptyJStatement()); } public JStatement _throw(final JExpr expr) { return add(new KeywordExprJStatement($KW.THROW, expr)); } public JTry _try() { return add(new ImplJTry(this)); } public JVarDeclaration var(final int mods, final String type, final String name, final JExpr value) { return var(mods, JTypes.typeNamed(type), name, value); } public JVarDeclaration var(final int mods, final JType type, final String name, final JExpr value) { return add(new FirstJVarDeclaration(mods, type, name, value)); } public JVarDeclaration var(final int mods, final Class type, final String name, final JExpr value) { return var(mods, JTypes.typeOf(type), name, value); } public JVarDeclaration var(final int mods, final String type, final String name) { return var(mods, JTypes.typeNamed(type), name); } public JVarDeclaration var(final int mods, final JType type, final String name) { return add(new FirstJVarDeclaration(mods, type, name, null)); } public JVarDeclaration var(final int mods, final Class type, final String name) { return var(mods, JTypes.typeOf(type), name); } public JExpr tempVar(final String type, final JExpr value) { return tempVar(JTypes.typeNamed(type), value); } public JExpr tempVar(final JType type, final JExpr value) { final String name = tempName(); final NameJExpr expr = new NameJExpr(name); var(0, type, name, value); return expr; } public JExpr tempVar(final Class type, final JExpr value) { return tempVar(JTypes.typeOf(type), value); } public String tempName() { final BasicJBlock parent = getParent(); return parent != null ? parent.tempName() : "anon$$$" + tmpId++; } BasicJBlock getParent() { return parent; } int size() { return content.size(); } BlockContent get(int idx) { return content.get(idx); } void write(final SourceFileWriter writer, final FormatPreferences.Space beforeBrace) throws IOException { write(writer, beforeBrace, braces); } void write(final SourceFileWriter writer, final FormatPreferences.Space beforeBrace, Braces braces) throws IOException { if (braces == Braces.REQUIRED || braces == Braces.IF_MULTILINE && content.size() != 1) { writer.write(beforeBrace); writer.write($PUNCT.BRACE.OPEN); writer.pushIndent(FormatPreferences.Indentation.LINE); try { final Iterator iterator = content.iterator(); if (iterator.hasNext()) { writer.write(FormatPreferences.Space.WITHIN_BRACES_CODE); if (iterator.hasNext()) { BlockContent statement = iterator.next(); statement.write(writer); while (iterator.hasNext()) { writer.nl(); statement = iterator.next(); statement.write(writer); } } writer.write(FormatPreferences.Space.WITHIN_BRACES_CODE); } else { writer.write(FormatPreferences.Space.WITHIN_BRACES_EMPTY); } } finally { writer.popIndent(FormatPreferences.Indentation.LINE); } writer.write($PUNCT.BRACE.CLOSE); } else { if (beforeBrace != null && content.size() == 1 && ! (content.get(0) instanceof EmptyJStatement)) { writer.sp(); } for (BlockContent statement : content) { statement.write(writer); writer.nl(); } } } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); write(writer, FormatPreferences.Space.BEFORE_BRACE); } boolean hasSingleItemOfType(Class type) { return size() == 1 && type.isInstance(get(0)); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BasicJCommentable.java000066400000000000000000000034051250006154200272660ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.ArrayList; /** * @author David M. Lloyd */ class BasicJCommentable implements JCommentable { private ArrayList comments; BasicJCommentable() { } public JComment lineComment() { if (comments == null) { comments = new ArrayList<>(); } final AbstractJComment comment = new LineJComment(); comments.add(comment); return comment; } public JComment blockComment() { if (comments == null) { comments = new ArrayList<>(); } final AbstractJComment comment = new BlockJComment(); comments.add(comment); return comment; } void writeComments(final SourceFileWriter writer) throws IOException { final ArrayList comments = this.comments; if (comments != null) { for (AbstractJComment comment : comments) { comment.write(writer); } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BasicJStatement.java000066400000000000000000000016311250006154200270030ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ class BasicJStatement extends BasicJCommentable implements JStatement { BasicJStatement() { } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BinaryJExpr.java000066400000000000000000000036551250006154200261700ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class BinaryJExpr extends AbstractJExpr { private final $PUNCT.BINOP op; private final AbstractJExpr e1; private final AbstractJExpr e2; private final Assoc assoc; BinaryJExpr(final $PUNCT.BINOP op, final AbstractJExpr e1, final AbstractJExpr e2, final int prec) { this(op, e1, e2, prec, Assoc.LEFT); } BinaryJExpr(final $PUNCT.BINOP op, final AbstractJExpr e1, final AbstractJExpr e2, final int prec, final Assoc assoc) { super(prec); this.op = op; this.e1 = e1.prec() > prec ? new ParenJExpr(e1) : e1; this.e2 = e2.prec() > prec ? new ParenJExpr(e2) : e2; this.assoc = assoc; } AbstractJExpr getExpr1() { return e1; } AbstractJExpr getExpr2() { return e2; } Assoc getAssoc() { return assoc; } public void write(final SourceFileWriter writer) throws IOException { writer.write(e1); writer.write(op.getSpacingRule()); writer.write(op); writer.write(op.getSpacingRule()); writer.write(e2); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BlankLine.java000066400000000000000000000030161250006154200256210ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class BlankLine implements ClassFileContent, ClassContent, BlockContent, JClassItem { private static final BlankLine INSTANCE = new BlankLine(); private BlankLine() { } static BlankLine getInstance() { return INSTANCE; } public void write(final SourceFileWriter writer) throws IOException { writer.nl(); } public Kind getItemKind() { return Kind.BLANK_LINE; } public int getModifiers() { return 0; } public boolean hasAllModifiers(final int mods) { return false; } public boolean hasAnyModifier(final int mods) { return false; } public String getName() { return null; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BlockContent.java000066400000000000000000000015341250006154200263520ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface BlockContent extends Writable { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BlockJComment.java000066400000000000000000000036221250006154200264540ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.List; /** * @author David M. Lloyd */ class BlockJComment extends AbstractJComment implements ClassContent, ClassFileContent, BlockContent, JClassItem { public void write(final SourceFileWriter writer) throws IOException { writer.addIndent(); writer.writeEscaped("/*"); writer.pushIndent(CommentIndentation.BLOCK); try { final List contents = getContent(); if (contents != null && ! contents.isEmpty()) { writer.nl(); super.write(writer); } } finally { writer.popIndent(CommentIndentation.BLOCK); } writer.nl(); writer.addIndent(); writer.writeEscaped(" */"); writer.nl(); } public Kind getItemKind() { return Kind.BLOCK_COMMENT; } public int getModifiers() { return 0; } public boolean hasAllModifiers(final int mods) { return false; } public boolean hasAnyModifier(final int mods) { return false; } public String getName() { return null; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/BooleanJExpr.java000066400000000000000000000023361250006154200263160ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class BooleanJExpr extends AbstractJExpr { private final boolean value; BooleanJExpr(final boolean value) { super(0); this.value = value; } boolean value() { return value; } public void write(final SourceFileWriter writer) throws IOException { writer.write(value ? $KW.TRUE : $KW.FALSE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CachingLinkedHashMap.java000066400000000000000000000020551250006154200277110ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.LinkedHashMap; import java.util.Map; /** * @author David M. Lloyd */ @SuppressWarnings("serial") class CachingLinkedHashMap extends LinkedHashMap { protected boolean removeEldestEntry(final Map.Entry eldest) { return size() > 12; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CachingThreadLocal.java000066400000000000000000000020031250006154200274140ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.LinkedHashMap; /** * @author David M. Lloyd */ class CachingThreadLocal extends ThreadLocal> { protected LinkedHashMap initialValue() { return new CachingLinkedHashMap<>(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CaseJBlock.java000066400000000000000000000032431250006154200257240ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class CaseJBlock extends BasicJBlock { private final JExpr expr; CaseJBlock(final ImplJSwitch _switch, final JExpr expr) { super(_switch.getParent(), Braces.OPTIONAL); this.expr = expr; } JExpr getExpression() { return expr; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.pushIndent(FormatPreferences.Indentation.CASE_LABELS); try { writer.write($KW.CASE); writer.write(expr); writer.write($PUNCT.COLON); } finally { writer.popIndent(FormatPreferences.Indentation.CASE_LABELS); } writer.write(FormatPreferences.Space.AFTER_LABEL); super.write(writer, FormatPreferences.Space.BEFORE_BRACE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CastJExpr.java000066400000000000000000000032651250006154200256330ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class CastJExpr extends AbstractJExpr { private final AbstractJExpr expr; private final JType type; CastJExpr(final AbstractJExpr expr, final JType type) { super(Prec.CAST); this.expr = expr.prec() < Prec.CAST ? new ParenJExpr(expr) : expr; this.type = type; } AbstractJExpr getExpression() { return expr; } JType getType() { return type; } public void write(final SourceFileWriter writer) throws IOException { writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_CAST); writer.write(type); writer.write(FormatPreferences.Space.WITHIN_PAREN_CAST); writer.write($PUNCT.PAREN.CLOSE); writer.write(FormatPreferences.Space.AFTER_CAST); writer.write(expr); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CharJExpr.java000066400000000000000000000021331250006154200256070ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; final class CharJExpr extends AbstractJExpr { private final int val; CharJExpr(int val) { super(0); this.val = val; } public void write(final SourceFileWriter writer) throws IOException { writer.writeUnescaped('\''); writer.writeUnescaped((char) val); writer.writeUnescaped('\''); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ClassContent.java000066400000000000000000000015341250006154200263650ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface ClassContent extends Writable { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ClassFileContent.java000066400000000000000000000015401250006154200271620ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface ClassFileContent extends Writable { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CommentContent.java000066400000000000000000000015501250006154200267200ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface CommentContent extends HtmlCommentContent { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CommentIndentation.java000066400000000000000000000037541250006154200275720ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ enum CommentIndentation implements Indent { LINE("// "), BLOCK(" * ") { public void escape(final Indent next, final StringBuilder b, final int idx) { for (int i = idx > 0 ? idx : idx + 1; i < b.length();) { if (b.charAt(i - 1) == '*' && b.charAt(i) == '/') { b.insert(idx, (char) 0x8205); } i++; } next.escape(next, b, idx); } }, ; private final String text; CommentIndentation(final String text) { this.text = text; } String getText() { return text; } public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) { next.addIndent(next, preferences, lineBuffer); final int idx = lineBuffer.length(); lineBuffer.append(text); next.escape(next, lineBuffer, idx); } public void escape(final Indent next, final StringBuilder b, final int idx) { next.escape(next, b, idx); } public void unescaped(final Indent next, final StringBuilder b, final int idx) { // escape at next level next.escape(next, b, idx); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CommentTextContent.java000066400000000000000000000022511250006154200275640ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class CommentTextContent implements CommentContent { private final String text; CommentTextContent(final String text) { super(); this.text = text; } String getText() { return text; } public void write(final SourceFileWriter writer) throws IOException { writer.writeEscaped(text); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CondJExpr.java000066400000000000000000000036111250006154200256170ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class CondJExpr extends AbstractJExpr { private final AbstractJExpr cond; private final AbstractJExpr ifTrue; private final AbstractJExpr ifFalse; CondJExpr(final AbstractJExpr cond, final AbstractJExpr ifTrue, final AbstractJExpr ifFalse) { super(Prec.COND); this.cond = cond.prec() < Prec.COND ? new ParenJExpr(cond) : cond; this.ifTrue = ifTrue.prec() < Prec.COND ? new ParenJExpr(ifTrue) : ifTrue; this.ifFalse = ifFalse.prec() < Prec.COND ? new ParenJExpr(ifFalse) : ifFalse; } public void write(final SourceFileWriter writer) throws IOException { writer.write(cond); writer.write(FormatPreferences.Space.BEFORE_TERNARY_Q); writer.write($PUNCT.Q); writer.write(FormatPreferences.Space.AFTER_TERNARY_Q); writer.write(ifTrue); writer.write(FormatPreferences.Space.BEFORE_TERNARY_COLON); writer.write($PUNCT.COLON); writer.write(FormatPreferences.Space.AFTER_TERNARY_COLON); writer.write(ifFalse); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ConditionJBlock.java000066400000000000000000000021241250006154200267740ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ abstract class ConditionJBlock extends BasicJBlock { private final JExpr cond; ConditionJBlock(final BasicJBlock parent, final Braces braces, final JExpr cond) { super(parent, braces); this.cond = cond; } JExpr getCondition() { return cond; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ConfigIndent.java000066400000000000000000000033341250006154200263340ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ class ConfigIndent implements Indent { private final FormatPreferences.Indentation indentation; ConfigIndent(final FormatPreferences.Indentation indentation) { this.indentation = indentation; } FormatPreferences.Indentation getIndentation() { return indentation; } public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) { if (! preferences.isIndentAbsolute(indentation)) next.addIndent(next, preferences, lineBuffer); final int indent = preferences.getIndent(indentation); for (int i = 0; i < indent; i ++) { lineBuffer.append(' '); } } public void escape(final Indent next, final StringBuilder b, final int idx) { next.escape(next, b, idx); } public void unescaped(final Indent next, final StringBuilder b, final int idx) { next.unescaped(next, b, idx); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ConstructorJMethodDef.java000066400000000000000000000035061250006154200302050ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import org.jboss.jdeparser.FormatPreferences.Space; /** * @author David M. Lloyd */ class ConstructorJMethodDef extends AbstractJMethodDef implements JClassItem { ConstructorJMethodDef(final AbstractJClassDef classDef, final int mods) { super(classDef, mods); } public void write(final SourceFileWriter writer) throws IOException { writeDocComments(writer); writeComments(writer); writeAnnotations(writer, Space.AFTER_ANNOTATION); JMod.write(writer, getModifiers()); writeTypeParams(writer); writer.write(clazz().erasedType()); super.write(writer); } public Kind getItemKind() { return Kind.METHOD; } public int getModifiers() { return super.getModifiers(); } public boolean hasAllModifiers(final int mods) { return (getModifiers() & mods) == mods; } public boolean hasAnyModifier(final int mods) { return (getModifiers() & mods) != 0; } public String getName() { return null; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/CountingWriter.java000066400000000000000000000113461250006154200267520ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.io.Writer; /** * @author David M. Lloyd */ class CountingWriter extends Writer { private final char[] buffer = new char[4096]; private final Writer out; private int line = 1; private int column = 1; private int bsz; CountingWriter(final Writer out) { this.out = out; } public void write(final char[] chars, final int off, final int len) throws IOException { int line = this.line, column = this.column, bsz = this.bsz; final char[] buffer = this.buffer; try { char ch; for (int i = 0; i < len; i ++) { ch = chars[off + i]; if (ch == '\n') { line++; column = 1; } else if (ch == '\r') { column = 1; } else { column ++; } buffer[bsz++] = ch; if (bsz == buffer.length) { out.write(buffer, 0, bsz); bsz = 0; } } } finally { this.line = line; this.column = column; this.bsz = bsz; } } public void write(final int c) throws IOException { if (c == '\n') { line ++; column = 1; } else { column ++; } buffer[bsz++] = (char) c; if (bsz == buffer.length) { out.write(buffer, 0, bsz); bsz = 0; } } public void write(final char[] cbuf) throws IOException { write(cbuf, 0, cbuf.length); } public void write(final String str, final int off, final int len) throws IOException { int line = this.line, column = this.column, bsz = this.bsz; final char[] buffer = this.buffer; try { char ch; for (int i = 0; i < len; i ++) { ch = str.charAt(off + i); if (ch == '\n') { line ++; column = 1; } else if (ch == '\r') { column = 1; } else { column ++; } buffer[bsz++] = ch; if (bsz == buffer.length) { out.write(buffer, 0, bsz); bsz = 0; } } } finally { this.line = line; this.column = column; this.bsz = bsz; } } public void write(final String str) throws IOException { write(str, 0, str.length()); } public void write(final StringBuilder b, final int off, final int len) throws IOException { int line = this.line, column = this.column, bsz = this.bsz; final char[] buffer = this.buffer; try { char ch; for (int i = 0; i < len; i ++) { ch = b.charAt(off + i); if (ch == '\n') { line ++; column = 1; } else if (ch == '\r') { column = 1; } else { column ++; } buffer[bsz++] = ch; if (bsz == buffer.length) { out.write(buffer, 0, bsz); bsz = 0; } } } finally { this.line = line; this.column = column; this.bsz = bsz; } } public void write(final StringBuilder b) throws IOException { write(b, 0, b.length()); } public void flush() throws IOException { int bsz = this.bsz; this.bsz = 0; out.write(buffer, 0, bsz); out.flush(); } public void close() throws IOException { int bsz = this.bsz; this.bsz = 0; out.write(buffer, 0, bsz); out.close(); } int getLine() { return line; } int getColumn() { return column; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DecimalDoubleJExpr.java000066400000000000000000000021161250006154200274240ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; final class DecimalDoubleJExpr extends AbstractJExpr { private final double val; DecimalDoubleJExpr(final double val) { super(0); this.val = val; } public void write(final SourceFileWriter writer) throws IOException { writer.writeUnescaped(String.format("%gf", Double.valueOf(val))); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DecimalFloatJExpr.java000066400000000000000000000021111250006154200272520ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; final class DecimalFloatJExpr extends AbstractJExpr { private final float val; DecimalFloatJExpr(final float val) { super(0); this.val = val; } public void write(final SourceFileWriter writer) throws IOException { writer.writeUnescaped(String.format("%gf", Float.valueOf(val))); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DefaultJBlock.java000066400000000000000000000025041250006154200264340ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class DefaultJBlock extends BasicJBlock { DefaultJBlock(final ImplJSwitch parent) { super(parent.getParent(), Braces.OPTIONAL); } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.DEFAULT); writer.write($PUNCT.COLON); writer.write(FormatPreferences.Space.AFTER_LABEL); super.write(writer, FormatPreferences.Space.BEFORE_BRACE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DirectJCall.java000066400000000000000000000020701250006154200261010ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ class DirectJCall extends AbstractMethodJCall { public JCall typeArg(final JType type) { throw new UnsupportedOperationException("Adding type arg to direct (unqualified) call"); } DirectJCall(final String name) { super(name); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DoJBlock.java000066400000000000000000000032601250006154200254120ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class DoJBlock extends ConditionJBlock { DoJBlock(final BasicJBlock parent, final JExpr cond) { super(parent, Braces.REQUIRED, cond); } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.DO); super.write(writer, FormatPreferences.Space.BEFORE_BRACE_DO); writer.write(FormatPreferences.Space.BEFORE_KEYWORD_WHILE); writer.write($KW.WHILE); writer.write(FormatPreferences.Space.BEFORE_PAREN_WHILE); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_WHILE); writer.write(getCondition()); writer.write(FormatPreferences.Space.WITHIN_PAREN_WHILE); writer.write($PUNCT.PAREN.CLOSE); writer.write($PUNCT.SEMI); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DocCommentContent.java000066400000000000000000000015421250006154200273470ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface DocCommentContent extends Writable { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/DocTagJHtmlComment.java000066400000000000000000000024261250006154200274110ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class DocTagJHtmlComment extends AbstractJHtmlComment { private final String tag; DocTagJHtmlComment(final String tag) { this.tag = tag; } String getTag() { return tag; } public void write(final SourceFileWriter writer) throws IOException { writer.nl(); writer.writeUnescaped("@"); writer.writeUnescaped(tag); writer.sp(); super.write(writer); writer.nl(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ElseJBlock.java000066400000000000000000000025731250006154200257460ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.$KW; import java.io.IOException; /** * @author David M. Lloyd */ class ElseJBlock extends BasicJBlock { ElseJBlock(final ImplJIf _if) { this(_if, Braces.IF_MULTILINE); } ElseJBlock(final ImplJIf _if, final Braces braces) { super(_if.getParent(), braces); } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write(FormatPreferences.Space.BEFORE_KEYWORD_ELSE); writer.write($KW.ELSE); super.write(writer, FormatPreferences.Space.BEFORE_BRACE_ELSE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/EmptyJStatement.java000066400000000000000000000021541250006154200270610ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class EmptyJStatement extends BasicJStatement implements BlockContent { public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($PUNCT.SEMI); writer.nl(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/EnumConstantJClassDef.java000066400000000000000000000025601250006154200301220ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class EnumConstantJClassDef extends AbstractJClassDef { EnumConstantJClassDef(final ImplJEnumConstant enumConstant) { super(0, enumConstant.getClassDef(), enumConstant.getName()); } Tokens.$KW designation() { // not used return Tokens.$KW.ENUM; } void writeAnnotations(final SourceFileWriter writer) throws IOException { // nothing (already written in an earlier stage) } void writeClassHeader(final SourceFileWriter sourceFileWriter) throws IOException { // nothing } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/EnumIntMap.java000066400000000000000000000036601250006154200260040ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.Arrays; /** * @author David M. Lloyd */ class EnumIntMap> { private final Class type; private final E[] keys; private final int[] values; private static final ClassValue cvo = new ClassValue() { protected Object computeValue(final Class type) { return type.getEnumConstants(); } }; @SuppressWarnings("unchecked") EnumIntMap(Class type, int defaultVal) { this.type = type; keys = (E[]) cvo.get(type); values = new int[keys.length]; Arrays.fill(values, defaultVal); } EnumIntMap(EnumIntMap orig) { this.type = orig.type; keys = orig.keys; values = orig.values.clone(); } public int get(E key) { return values[type.cast(key).ordinal()]; } public int put(E key, int val) { final int idx = type.cast(key).ordinal(); try { return values[idx]; } finally { values[idx] = val; } } public static > EnumIntMap of(final Class enumClass) { return new EnumIntMap<>(enumClass, 0); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/EnumJClassDef.java000066400000000000000000000060461250006154200264130ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; /** * @author David M. Lloyd */ class EnumJClassDef extends AbstractJClassDef implements JClassItem { private final Map constants = new LinkedHashMap<>(); EnumJClassDef(final int mods, final ImplJSourceFile classFile, final String name) { super(mods, classFile, name); } EnumJClassDef(final int mods, final AbstractJClassDef enclosingClass, final String name) { super(mods, enclosingClass, name); } Tokens.$KW designation() { return Tokens.$KW.ENUM; } public JEnumConstant _enum(final String name) { final ImplJEnumConstant c = new ImplJEnumConstant(this, name); constants.put(name, c); return c; } public JClassDef _extends(final String name) { throw new UnsupportedOperationException("extends on enum"); } public JClassDef _extends(final JType type) { throw new UnsupportedOperationException("extends on enum"); } public JClassDef _extends(final Class clazz) { throw new UnsupportedOperationException("extends on enum"); } void writeContent(final SourceFileWriter sourceFileWriter) throws IOException { final Iterator iterator = constants.values().iterator(); if (iterator.hasNext()) { iterator.next().writeDirect(sourceFileWriter); while (iterator.hasNext()) { sourceFileWriter.write(Tokens.$PUNCT.COMMA); sourceFileWriter.write(FormatPreferences.Space.AFTER_COMMA_ENUM_CONSTANT); iterator.next().writeDirect(sourceFileWriter); } if (sourceFileWriter.getFormat().hasOption(FormatPreferences.Opt.ENUM_TRAILING_COMMA)) { sourceFileWriter.write(Tokens.$PUNCT.COMMA); sourceFileWriter.write(FormatPreferences.Space.AFTER_COMMA_ENUM_CONSTANT); } } sourceFileWriter.write(Tokens.$PUNCT.SEMI); sourceFileWriter.write(FormatPreferences.Space.AFTER_SEMICOLON); super.writeContent(sourceFileWriter); } public Kind getItemKind() { return Kind.ENUM; } public String getName() { return super.getName(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ExpressionJStatement.java000066400000000000000000000024021250006154200301160ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ExpressionJStatement extends BasicJCommentable implements JStatement, BlockContent { private final AbstractJExpr expr; ExpressionJStatement(final AbstractJExpr expr) { this.expr = expr; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write(expr); writer.write($PUNCT.SEMI); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/FieldRefJExpr.java000066400000000000000000000027101250006154200264130ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class FieldRefJExpr extends AbstractJAssignableExpr { private final AbstractJExpr expr; private final String refName; FieldRefJExpr(final AbstractJExpr expr, final String refName) { super(Prec.MEMBER_ACCESS); this.expr = expr; this.refName = refName; } public void write(final SourceFileWriter writer) throws IOException { writer.write(expr); writer.write($PUNCT.DOT); writer.writeEscaped(refName); } AbstractJExpr getExpr() { return expr; } String getName() { return refName; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/FinallyJBlock.java000066400000000000000000000026361250006154200264540ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.$KW; import java.io.IOException; /** * @author David M. Lloyd */ class FinallyJBlock extends BasicJBlock { private final ImplJTry _try; FinallyJBlock(final ImplJTry _try) { super(_try.getParent(), Braces.REQUIRED); this._try = _try; } ImplJTry getTry() { return _try; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write(FormatPreferences.Space.BEFORE_KEYWORD_FINALLY); writer.write($KW.FINALLY); super.write(writer, FormatPreferences.Space.BEFORE_BRACE_FINALLY); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/FirstJVarDeclaration.java000066400000000000000000000100131250006154200277750ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; /** * @author David M. Lloyd */ class FirstJVarDeclaration extends BasicJAnnotatable implements JVarDeclaration, BlockContent, ClassContent, JClassItem { private final int mods; private final JType type; private final String name; private final JExpr value; private ArrayList successors; FirstJVarDeclaration(final int mods, final JType type, final String name, final JExpr value) { this.mods = mods; this.type = type; this.name = name; this.value = value; } public void write(final SourceFileWriter writer) throws IOException { write(writer, null); } void write(final SourceFileWriter writer, final FormatPreferences.Space beforeSemicolon) throws IOException { writeNoSemi(writer); writer.write(beforeSemicolon); writer.write($PUNCT.SEMI); } void writeNoSemi(final SourceFileWriter writer) throws IOException { writeComments(writer); super.writeAnnotations(writer, FormatPreferences.Space.AFTER_ANNOTATION); JMod.write(writer, mods); writer.write(type); writer.sp(); String name = this.name; JExpr value = this.value; writer.writeEscapedWord(name); if (value != null) { writer.write($PUNCT.BINOP.ASSIGN.getSpacingRule()); writer.write($PUNCT.BINOP.ASSIGN); writer.write($PUNCT.BINOP.ASSIGN.getSpacingRule()); writer.write(value); } if (successors != null) for (SuccessorJVarDeclaration successor : successors) { writer.write(FormatPreferences.Space.BEFORE_COMMA); writer.write($PUNCT.COMMA); writer.write(FormatPreferences.Space.AFTER_COMMA); writer.writeEscapedWord(successor.name()); value = successor.getValue(); if (value != null) { writer.write($PUNCT.BINOP.ASSIGN.getSpacingRule()); writer.write($PUNCT.BINOP.ASSIGN); writer.write($PUNCT.BINOP.ASSIGN.getSpacingRule()); writer.write(value); } } } public JType type() { return type; } public String name() { return name; } int mods() { return mods; } public JVarDeclaration add(final String name, final JExpr init) { if (successors == null) successors = new ArrayList<>(); final SuccessorJVarDeclaration s = new SuccessorJVarDeclaration(this, name, init); successors.add(s); return s; } public JVarDeclaration add(final String name) { if (successors == null) successors = new ArrayList<>(); final SuccessorJVarDeclaration s = new SuccessorJVarDeclaration(this, name, null); successors.add(s); return s; } public Kind getItemKind() { return Kind.FIELD; } public int getModifiers() { return mods; } public boolean hasAllModifiers(final int mods) { return (this.mods & mods) == mods; } public boolean hasAnyModifier(final int mods) { return (this.mods & mods) != 0; } public String getName() { return name; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ForEachJBlock.java000066400000000000000000000041031250006154200263540ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ForEachJBlock extends BasicJBlock { private final int mods; private final JType type; private final String name; private final JExpr iterable; ForEachJBlock(final BasicJBlock parent, final int mods, final JType type, final String name, final JExpr iterable) { super(parent, Braces.IF_MULTILINE); this.mods = mods; this.type = type; this.name = name; this.iterable = iterable; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.FOR); writer.write(FormatPreferences.Space.BEFORE_PAREN_FOR); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_FOR); JMod.write(writer, mods); writer.write(type); writer.writeEscaped(name); writer.write(FormatPreferences.Space.BEFORE_COLON); writer.write($PUNCT.COLON); writer.write(FormatPreferences.Space.AFTER_COLON); writer.write(iterable); writer.write(FormatPreferences.Space.WITHIN_PAREN_FOR); writer.write($PUNCT.PAREN.CLOSE); super.write(writer, FormatPreferences.Space.BEFORE_BRACE_FOR); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ForJBlock.java000066400000000000000000000053451250006154200256040ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ForJBlock extends BasicJBlock implements JFor { private FirstJVarDeclaration init; private JExpr test; private JExpr update; ForJBlock(final BasicJBlock parent) { super(parent, Braces.IF_MULTILINE); } public JVarDeclaration init(final int mods, final String type, final String name, final JExpr value) { return init(mods, JTypes.typeNamed(type), name, value); } public JVarDeclaration init(final int mods, final JType type, final String name, final JExpr value) { return init = new FirstJVarDeclaration(mods, type, name, value); } public JVarDeclaration init(final int mods, final Class type, final String name, final JExpr value) { return init(mods, JTypes.typeOf(type), name, value); } public JFor test(final JExpr expr) { test = expr; return this; } public JFor update(final JExpr updateExpr) { update = updateExpr; return this; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.FOR); writer.write(FormatPreferences.Space.BEFORE_PAREN_FOR); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_FOR); if (init != null) init.writeNoSemi(writer); writer.write(FormatPreferences.Space.BEFORE_SEMICOLON); writer.write($PUNCT.SEMI); writer.write(FormatPreferences.Space.AFTER_SEMICOLON); writer.write(test); writer.write(FormatPreferences.Space.BEFORE_SEMICOLON); writer.write($PUNCT.SEMI); writer.write(FormatPreferences.Space.AFTER_SEMICOLON); writer.write(update); writer.write(FormatPreferences.Space.WITHIN_PAREN_FOR); writer.write($PUNCT.PAREN.CLOSE); super.write(writer, FormatPreferences.Space.BEFORE_BRACE_FOR); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/FormatPreferences.java000066400000000000000000000552031250006154200274010ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.FormatPreferences.Space.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.Collections; import java.util.EnumMap; import java.util.EnumSet; import java.util.Locale; import java.util.Properties; import javax.annotation.processing.Filer; import javax.tools.StandardLocation; /** * Formatter preferences. * * @author David M. Lloyd */ public final class FormatPreferences { private static final String PROPERTIES_FILE_NAME = "jdeparser.properties"; private static final EnumIntMap DEFAULT_INDENTS; private static final EnumSet DEFAULT_ABS_INDENTS; private static final EnumMap DEFAULT_SPACE_TYPES; private static final EnumSet DEFAULT_OPTS; private static final EnumMap DEFAULT_WRAPPING; static { EnumIntMap ind = new EnumIntMap<>(Indentation.class, 0); ind.put(Indentation.LINE, 4); ind.put(Indentation.LINE_CONTINUATION, 4); ind.put(Indentation.MEMBERS_TOP_LEVEL, 4); ind.put(Indentation.LABELS, 0); ind.put(Indentation.CASE_LABELS, 0); ind.put(Indentation.HTML_TAG, 2); DEFAULT_INDENTS = ind; DEFAULT_ABS_INDENTS = EnumSet.noneOf(Indentation.class); EnumMap spaceTypes = new EnumMap<>(Space.class); spaceTypes.put(AFTER_COMMA, SpaceType.SPACE); spaceTypes.put(AFTER_COMMA_TYPE_ARGUMENT, SpaceType.SPACE); spaceTypes.put(AFTER_COMMA_ENUM_CONSTANT, SpaceType.NEWLINE); spaceTypes.put(AFTER_LABEL, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_IF, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_FOR, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_WHILE, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_SWITCH, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_TRY, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_CATCH, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_SYNCHRONIZED, SpaceType.SPACE); spaceTypes.put(BEFORE_PAREN_CAST, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_ANNOTATION_ARRAY_INIT, SpaceType.NONE); spaceTypes.put(BEFORE_BRACE_ARRAY_INIT, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_CATCH, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_CLASS, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_DO, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_ELSE, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_FINALLY, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_FOR, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_IF, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_METHOD, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_SWITCH, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_SYNCHRONIZE, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_TRY, SpaceType.SPACE); spaceTypes.put(BEFORE_BRACE_WHILE, SpaceType.SPACE); spaceTypes.put(AFTER_SEMICOLON, SpaceType.SPACE); spaceTypes.put(BEFORE_KEYWORD_ELSE, SpaceType.SPACE); spaceTypes.put(BEFORE_KEYWORD_WHILE, SpaceType.SPACE); spaceTypes.put(BEFORE_KEYWORD_CATCH, SpaceType.SPACE); spaceTypes.put(BEFORE_KEYWORD_FINALLY, SpaceType.SPACE); spaceTypes.put(AROUND_ADDITIVE, SpaceType.SPACE); spaceTypes.put(AROUND_MULTIPLICATIVE, SpaceType.SPACE); spaceTypes.put(AROUND_SHIFT, SpaceType.SPACE); spaceTypes.put(AROUND_BITWISE, SpaceType.SPACE); spaceTypes.put(AROUND_ASSIGN, SpaceType.SPACE); spaceTypes.put(AROUND_LOGICAL, SpaceType.SPACE); spaceTypes.put(AROUND_EQUALITY, SpaceType.SPACE); spaceTypes.put(AROUND_RANGE, SpaceType.SPACE); spaceTypes.put(AROUND_ARROW, SpaceType.SPACE); spaceTypes.put(WITHIN_BRACES_CODE, SpaceType.NEWLINE); spaceTypes.put(WITHIN_BRACES_ARRAY_INIT, SpaceType.SPACE); spaceTypes.put(BEFORE_TERNARY_Q, SpaceType.SPACE); spaceTypes.put(AFTER_TERNARY_Q, SpaceType.SPACE); spaceTypes.put(BEFORE_TERNARY_COLON, SpaceType.SPACE); spaceTypes.put(AFTER_TERNARY_COLON, SpaceType.SPACE); spaceTypes.put(BEFORE_COLON, SpaceType.SPACE); spaceTypes.put(AFTER_COLON, SpaceType.SPACE); spaceTypes.put(AFTER_ANNOTATION, SpaceType.NEWLINE); spaceTypes.put(AFTER_PARAM_ANNOTATION, SpaceType.SPACE); DEFAULT_SPACE_TYPES = spaceTypes; DEFAULT_OPTS = EnumSet.of(Opt.COMPACT_INIT_ONLY_CLASS); EnumMap wm = new EnumMap<>(Wrapping.class); wm.put(Wrapping.EXCEPTION_LIST, WrappingMode.WRAP_ONLY_IF_LONG); DEFAULT_WRAPPING = wm; } private final EnumIntMap indents; private final EnumSet absoluteIndents; private final EnumMap spaceTypes; private final EnumSet options; private final EnumMap wrapping; private int lineLength = 140; // ===================================================================== /** * Construct a new instance using default values. */ public FormatPreferences() { indents = new EnumIntMap<>(DEFAULT_INDENTS); absoluteIndents = EnumSet.copyOf(DEFAULT_ABS_INDENTS); spaceTypes = new EnumMap<>(DEFAULT_SPACE_TYPES); options = EnumSet.copyOf(DEFAULT_OPTS); wrapping = new EnumMap<>(DEFAULT_WRAPPING); } /** * Construct a new instance, mapping the given properties to the formatter configurations. * * @param properties the properties to map */ public FormatPreferences(final Properties properties) { // initialize this(); final ArrayList l = new ArrayList<>(); for (String name : properties.stringPropertyNames()) { split(l, '.', name); // unknown properties are ignored for forward/backward compat final String value = properties.getProperty(name); switch (l.size()) { case 1: { switch (l.get(0)) { case "line-length": { try { lineLength = Integer.parseInt(value); } catch (IllegalArgumentException ignored) { } break; } } break; } case 2: { switch (l.get(0)) { case "indent": { try { final Indentation i = Indentation.valueOf(xf(l.get(1))); final int v = Integer.parseInt(value); indents.put(i, v); } catch (IllegalArgumentException ignored) { } break; } case "wrapping": { try { final Wrapping w = Wrapping.valueOf(xf(l.get(1))); final WrappingMode m = WrappingMode.valueOf(xf(value)); wrapping.put(w, m); } catch (IllegalArgumentException ignored) { } break; } case "space": { try { final Space s = Space.valueOf(xf(l.get(1))); final SpaceType t = SpaceType.valueOf(xf(value)); spaceTypes.put(s, t); } catch (IllegalArgumentException ignored) { } break; } case "optimization": { try { final Opt o = Opt.valueOf(xf(l.get(1))); final boolean v = Boolean.parseBoolean(value); if (v) options.add(o); else options.remove(o); } catch (IllegalArgumentException ignored) { } break; } } break; } case 3: { switch (l.get(0)) { case "indent": { switch (l.get(2)) { case "absolute": { try { final Indentation i = Indentation.valueOf(xf(l.get(1))); final boolean v = Boolean.parseBoolean(value); if (v) absoluteIndents.add(i); else absoluteIndents.remove(i); } catch (IllegalArgumentException ignored) { } break; } } break; } } } } } } /** * Construct a new instance using a properties file loaded from the given class loader. * * @param classLoader the class loader * @throws IOException if an error occurs while reading the properties */ public FormatPreferences(final ClassLoader classLoader) throws IOException { this(fnf(classLoader.getResourceAsStream(PROPERTIES_FILE_NAME))); } /** * Construct a new instance using a properties file loaded from the given annotation processing filer. * * @param filer the filer to read from * @param name the name of the properties file to read * @throws IOException if an error occurs while reading the properties */ public FormatPreferences(final Filer filer, final String name) throws IOException { this(filer.getResource(StandardLocation.ANNOTATION_PROCESSOR_PATH, "", name).openInputStream()); } /** * Construct a new instance using a properties file loaded from the given annotation processing filer. * * @param filer the filer to read from * @throws IOException if an error occurs while reading the properties */ public FormatPreferences(final Filer filer) throws IOException { this(filer, PROPERTIES_FILE_NAME); } /** * Construct a new instance using a properties file loaded from the given file name. * * @param file the name of the properties file to read * @throws IOException if an error occurs while reading the properties */ public FormatPreferences(final File file) throws IOException { this(new FileInputStream(file)); } /** * Construct a new instance using a properties read from the given stream. * * @param inputStream the stream to read properties from * @throws IOException if an error occurs while reading the properties */ public FormatPreferences(final InputStream inputStream) throws IOException { this(new InputStreamReader(inputStream, "utf-8")); } /** * Construct a new instance using a properties read from the given stream. * * @param reader the stream to read properties from * @throws IOException if an error occurs while reading the properties */ public FormatPreferences(final Reader reader) throws IOException { this(load(reader)); } // ===================================================================== private static InputStream fnf(InputStream stream) throws IOException { if (stream == null) throw new FileNotFoundException(PROPERTIES_FILE_NAME); return stream; } private static String xf(String name) { return name.toUpperCase(Locale.US).replace('-', '_'); } private static void split(ArrayList dest, char delim, String s) { dest.clear(); int st = 0, i; i = s.indexOf(delim); for (;;) { if (i == -1) { dest.add(s.substring(st)); return; } dest.add(s.substring(st, i)); st = i + 1; i = s.indexOf(delim, st); } } private static Properties load(Reader reader) throws IOException { final Properties properties = new Properties(); properties.load(reader); return properties; } // ===================================================================== private T def(T val, T def) { return val == null ? def : val; } // ===================================================================== /** * Get the configured line length. * * @return the configured line length */ public int getLineLength() { return lineLength; } // --------------------------------------------------------------------- /** * Get the configured indentation for the given context. * * @param indentation the indentation context * @return the indentation */ public int getIndent(Indentation indentation) { return indents.get(indentation); } /** * Set the configured indentation for the given context. * * @param indentation the indentation context * @param value the indentation * @return the previous indentation */ public int setIndent(Indentation indentation, int value) { return indents.put(indentation, value); } // --------------------------------------------------------------------- /** * Determine whether the indentation for the given context is absolute or relative. * * @param indentation the indentation context * @return {@code true} if absolute, {@code false} if relative */ public boolean isIndentAbsolute(Indentation indentation) { return absoluteIndents.contains(indentation); } /** * Set absolute indentation for the given context. * * @param indentation the indentation context */ public void setIndentAbsolute(Indentation indentation) { absoluteIndents.add(indentation); } /** * Clear absolute indentation for the given context. * * @param indentation the indentation context */ public void clearIndentAbsolute(Indentation indentation) { absoluteIndents.remove(indentation); } // --------------------------------------------------------------------- /** * Set the spacing type for the given space context. * * @param space the space context * @param spaceType the space type * @return the previous space type */ public SpaceType setSpaceType(Space space, SpaceType spaceType) { if (space == null) { throw new IllegalArgumentException("space is null"); } if (spaceType == null) { throw new IllegalArgumentException("spaceType is null"); } return def(spaceTypes.put(space, spaceType), SpaceType.NONE); } /** * Set several space contexts to the same spacing type. * * @param toType the type to set to * @param spaces the space contexts */ public void setAllSpaceTypes(SpaceType toType, Space... spaces) { if (toType == null) { throw new IllegalArgumentException("toType is null"); } if (spaces != null) for (Space space : spaces) { def(spaceTypes.put(space, toType), SpaceType.NONE); } } /** * Get the spacing type for a given space context. * * @param space the space context * @return the spacing type */ public SpaceType getSpaceType(Space space) { if (space == null) { throw new IllegalArgumentException("space is null"); } return def(spaceTypes.get(space), SpaceType.NONE); } // --------------------------------------------------------------------- /** * Get the wrapping mode for the given wrapping context. * * @param wrapping the wrapping context * @return the current wrapping mode */ public WrappingMode getWrapMode(Wrapping wrapping) { return def(this.wrapping.get(wrapping), WrappingMode.WRAP_ONLY_IF_LONG); } /** * Set the wrapping mode for the given wrapping context. * * @param wrapping the wrapping context * @param mode the wrapping mode * @return the previous wrapping mode */ public WrappingMode setWrapMode(Wrapping wrapping, WrappingMode mode) { return def(this.wrapping.put(wrapping, mode), WrappingMode.WRAP_ONLY_IF_LONG); } // --------------------------------------------------------------------- /** * Add option flags to these preferences. * * @param opts the flags to add */ public void addOption(Opt... opts) { Collections.addAll(this.options, opts); } /** * Remove option flags from these preferences. * * @param opts the flags to remove */ public void removeOption(Opt... opts) { for (Opt opt : opts) { this.options.remove(opt); } } /** * Determine whether the given option flag is set on these preferences. * * @param opt the flag to check * @return {@code true} if the flag is present, {@code false} if it is absent */ public boolean hasOption(Opt opt) { return options.contains(opt); } // ===================================================================== /** * The type of space to apply. * * @apiviz.exclude */ public enum SpaceType { NONE, SPACE, NEWLINE, } /** * The location or position of a space. * * @apiviz.exclude */ public enum Space { // default for all parens BEFORE_PAREN, // single-line statements BEFORE_STATEMENT, // paren sites BEFORE_PAREN_METHOD_CALL, BEFORE_PAREN_METHOD_DECLARATION, BEFORE_PAREN_IF, BEFORE_PAREN_FOR, BEFORE_PAREN_WHILE, BEFORE_PAREN_SWITCH, BEFORE_PAREN_TRY, BEFORE_PAREN_CATCH, BEFORE_PAREN_SYNCHRONIZED, BEFORE_PAREN_ANNOTATION_PARAM, BEFORE_PAREN_CAST, // default for all binary operators AROUND_OPERATORS, // specific operator categories AROUND_ASSIGN, AROUND_LOGICAL, AROUND_EQUALITY, AROUND_RANGE, AROUND_BITWISE, AROUND_ADDITIVE, AROUND_MULTIPLICATIVE, AROUND_SHIFT, AROUND_ARROW, AROUND_METHOD_REF, // default for all unary operators AT_UNARY, // default for all braces BEFORE_BRACE, // specific braces sites BEFORE_BRACE_CLASS, BEFORE_BRACE_METHOD, BEFORE_BRACE_IF, BEFORE_BRACE_ELSE, BEFORE_BRACE_FOR, BEFORE_BRACE_WHILE, BEFORE_BRACE_DO, BEFORE_BRACE_SWITCH, BEFORE_BRACE_TRY, BEFORE_BRACE_CATCH, BEFORE_BRACE_FINALLY, BEFORE_BRACE_SYNCHRONIZE, BEFORE_BRACE_ARRAY_INIT, BEFORE_BRACE_ANNOTATION_ARRAY_INIT, BEFORE_KEYWORD_ELSE, BEFORE_KEYWORD_WHILE, BEFORE_KEYWORD_CATCH, BEFORE_KEYWORD_FINALLY, // within... WITHIN_BRACES_CODE, WITHIN_BRACES_EMPTY, WITHIN_BRACES_ARRAY_INIT, WITHIN_BRACKETS, WITHIN_PAREN_EXPR, WITHIN_PAREN_METHOD_CALL, WITHIN_PAREN_METHOD_CALL_EMPTY, WITHIN_PAREN_METHOD_DECLARATION, WITHIN_PAREN_METHOD_DECLARATION_EMPTY, WITHIN_PAREN_IF, WITHIN_PAREN_FOR, WITHIN_PAREN_WHILE, WITHIN_PAREN_SWITCH, WITHIN_PAREN_TRY, WITHIN_PAREN_CATCH, WITHIN_PAREN_SYNCHRONIZED, WITHIN_PAREN_CAST, WITHIN_PAREN_ANNOTATION, // ternary BEFORE_TERNARY_Q, AFTER_TERNARY_Q, BEFORE_TERNARY_COLON, AFTER_TERNARY_COLON, // type arguments AFTER_COMMA_TYPE_ARGUMENT, // comma BEFORE_COMMA, AFTER_COMMA, // colon (assert, foreach) BEFORE_COLON, AFTER_COLON, // enum AFTER_COMMA_ENUM_CONSTANT, // semi BEFORE_SEMICOLON, AFTER_SEMICOLON, // cast AFTER_CAST, // colon (label, case, default) AFTER_LABEL, // annotations AFTER_ANNOTATION, AFTER_PARAM_ANNOTATION, ; } // --------------------------------------------------------------------- /** * A category of indentation. * * @apiviz.exclude */ public enum Indentation { MEMBERS_TOP_LEVEL, LABELS, CASE_LABELS, LINE_CONTINUATION, LINE, HTML_TAG, ; private final Indent indent; Indentation() { indent = new ConfigIndent(this); } Indent getIndent() { return indent; } } // --------------------------------------------------------------------- /** * Categories for wrapping rules. * * @apiviz.exclude */ public enum Wrapping { EXCEPTION_LIST, } // --------------------------------------------------------------------- /** * The wrapping mode. * * @apiviz.exclude */ public enum WrappingMode { ALWAYS_WRAP, WRAP_ONLY_IF_LONG, NEVER, ; } // --------------------------------------------------------------------- /** * Option flags. * * @apiviz.exclude */ public enum Opt { ENUM_TRAILING_COMMA, ENUM_EMPTY_PARENS, COMPACT_INIT_ONLY_CLASS, } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/GotoJStatement.java000066400000000000000000000025201250006154200266700ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class GotoJStatement extends KeywordJStatement { private final JLabel label; GotoJStatement($KW keyword, JLabel label) { super(keyword); this.label = label; } JLabel getLabel() { return label; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write(getKeyword()); writer.writeEscaped(label.name()); writer.write($PUNCT.SEMI); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/HexDoubleJExpr.java000066400000000000000000000021061250006154200266110ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; final class HexDoubleJExpr extends AbstractJExpr { private final double val; HexDoubleJExpr(final double val) { super(0); this.val = val; } public void write(final SourceFileWriter writer) throws IOException { writer.writeUnescaped(String.format("%af", Double.valueOf(val))); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/HexFloatJExpr.java000066400000000000000000000021011250006154200264370ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; final class HexFloatJExpr extends AbstractJExpr { private final float val; HexFloatJExpr(final float val) { super(0); this.val = val; } public void write(final SourceFileWriter writer) throws IOException { writer.writeUnescaped(String.format("%af", Float.valueOf(val))); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/HtmlCommentContent.java000066400000000000000000000015541250006154200275510ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * @author David M. Lloyd */ interface HtmlCommentContent extends DocCommentContent { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJAnnotation.java000066400000000000000000000134131250006154200270320ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.lang.annotation.Annotation; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import static org.jboss.jdeparser.FormatPreferences.Space; import static org.jboss.jdeparser.Tokens.$PUNCT; /** * @author David M. Lloyd */ class ImplJAnnotation implements JAnnotation, Writable { private final JType type; private LinkedHashMap properties; ImplJAnnotation(final JType type) { this.type = type; } public JAnnotation value(final JExpr expr) { return value("value", expr); } public JAnnotation value(final String literal) { return value(JExprs.str(literal)); } public JAnnotation annotationValue(final String type) { return annotationValue(JTypes.typeNamed(type)); } public JAnnotation annotationValue(final JType type) { return annotationValue("value", type); } public JAnnotation annotationValue(final Class type) { return annotationValue(JTypes.typeOf(type)); } public JAnnotationArray annotationArrayValue(final String type) { return annotationArrayValue(JTypes.typeNamed(type)); } public JAnnotationArray annotationArrayValue(final JType type) { return annotationArrayValue("value", type); } public JAnnotationArray annotationArrayValue(final Class type) { return annotationArrayValue(JTypes.typeOf(type)); } public JAnnotation value(final String name, final String literal) { return value(name, JExprs.str(literal)); } public JAnnotation value(final String name, final JExpr expr) { LinkedHashMap properties = this.properties; if (properties == null) { properties = this.properties = new LinkedHashMap<>(); } properties.put(name, (AbstractJExpr) expr); return this; } public JAnnotation annotationValue(final String name, final String type) { return annotationValue(name, JTypes.typeNamed(type)); } public JAnnotation annotationValue(final String name, final JType type) { LinkedHashMap properties = this.properties; if (properties == null) { properties = this.properties = new LinkedHashMap<>(); } final ImplJAnnotation annotation = new ImplJAnnotation(type); properties.put(name, annotation); return annotation; } public JAnnotation annotationValue(final String name, final Class type) { return annotationValue(name, JTypes.typeOf(type)); } public JAnnotationArray annotationArrayValue(final String name, final String type) { return annotationArrayValue(name, JTypes.typeNamed(type)); } public JAnnotationArray annotationArrayValue(final String name, final JType type) { LinkedHashMap properties = this.properties; if (properties == null) { properties = this.properties = new LinkedHashMap<>(); } final ImplJAnnotationArray array = new ImplJAnnotationArray(type); properties.put(name, array); return array; } public JAnnotationArray annotationArrayValue(final String name, final Class type) { return annotationArrayValue(name, JTypes.typeOf(type)); } public void write(final SourceFileWriter writer) throws IOException { writer.write($PUNCT.AT); writer.write(type); final LinkedHashMap properties = this.properties; if (properties != null && ! properties.isEmpty()) { writer.write($PUNCT.PAREN.OPEN); writer.pushIndent(FormatPreferences.Indentation.LINE); try { writer.write(Space.WITHIN_PAREN_ANNOTATION); if (properties.size() == 1 && properties.containsKey("value")) { properties.get("value").write(writer); } else { Iterator> iterator = properties.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry entry = iterator.next(); writer.writeEscapedWord(entry.getKey()); writer.write(Space.AROUND_ASSIGN); writer.write($PUNCT.BINOP.ASSIGN); writer.write(Space.AROUND_ASSIGN); entry.getValue().write(writer); if (iterator.hasNext()) { writer.write(Space.BEFORE_COMMA); writer.write($PUNCT.COMMA); writer.write(Space.AFTER_COMMA); } } } } finally { writer.popIndent(FormatPreferences.Indentation.LINE); } writer.write(Space.WITHIN_PAREN_ANNOTATION); writer.write($PUNCT.PAREN.CLOSE); } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJAnnotationArray.java000066400000000000000000000053361250006154200300360ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import static org.jboss.jdeparser.FormatPreferences.Indentation; import static org.jboss.jdeparser.FormatPreferences.Space; import static org.jboss.jdeparser.Tokens.$PUNCT; class ImplJAnnotationArray implements JAnnotationArray, Writable { private final JType type; private ArrayList list; ImplJAnnotationArray(final JType type) { this.type = type; } public JAnnotation add() { ArrayList list = this.list; if (list == null) { list = this.list = new ArrayList<>(); } final ImplJAnnotation annotation = new ImplJAnnotation(type); list.add(annotation); return annotation; } public void write(final SourceFileWriter writer) throws IOException { writer.write($PUNCT.BRACE.OPEN); if (size() > 0) { writer.pushIndent(Indentation.LINE); try { writer.write(Space.WITHIN_BRACES_ARRAY_INIT); writeBare(writer); } finally { writer.popIndent(Indentation.LINE); } writer.write(Space.WITHIN_BRACES_ARRAY_INIT); } writer.write($PUNCT.BRACE.CLOSE); } int size() { final ArrayList list = this.list; return list == null ? 0 : list.size(); } void writeBare(final SourceFileWriter writer) throws IOException { final ArrayList list = this.list; if (list != null) { final Iterator iterator = list.iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.write(Space.BEFORE_COMMA); writer.write($PUNCT.COMMA); writer.write(Space.AFTER_COMMA); iterator.next().write(writer); } } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJAnonymousClassDef.java000066400000000000000000000130321250006154200303120ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.$KW; import java.io.IOException; import java.lang.annotation.Annotation; /** * @author David M. Lloyd */ class ImplJAnonymousClassDef extends AbstractJCall implements JAnonymousClassDef { private final AnonymousJClassDef classDef; private final JType type; ImplJAnonymousClassDef(final JType type) { super(Prec.METHOD_CALL); this.type = type; classDef = new AnonymousJClassDef(this); } public JType type() { return type; } public void write(final SourceFileWriter writer) throws IOException { writer.write($KW.NEW); writer.write(type); super.write(writer); writer.write(FormatPreferences.Space.BEFORE_BRACE_CLASS); classDef.write(writer); } // delegation public JClassDefSection section() { return classDef.section(); } public JClassDef _extends(final String name) { return classDef._extends(name); } public JClassDef _extends(final JType type) { return classDef._extends(type); } public JClassDef _extends(final Class clazz) { return classDef._extends(clazz); } public JClassDef _implements(final String... names) { return classDef._implements(names); } public JClassDef _implements(final JType... types) { return classDef._implements(types); } public JClassDef _implements(final Class... classes) { return classDef._implements(classes); } public JType erasedType() { return classDef.erasedType(); } public JClassDef blankLine() { return classDef.blankLine(); } public JType genericType() { return classDef.genericType(); } public JTypeParamDef typeParam(final String name) { return classDef.typeParam(name); } public JBlock init() { return classDef.init(); } public JBlock staticInit() { return classDef.staticInit(); } public JEnumConstant _enum(final String name) { return classDef._enum(name); } public JVarDeclaration field(final int mods, final JType type, final String name) { return classDef.field(mods, type, name); } public JVarDeclaration field(final int mods, final JType type, final String name, final JExpr init) { return classDef.field(mods, type, name, init); } public JVarDeclaration field(final int mods, final Class type, final String name) { return classDef.field(mods, type, name); } public JVarDeclaration field(final int mods, final Class type, final String name, final JExpr init) { return classDef.field(mods, type, name, init); } public JVarDeclaration field(final int mods, final String type, final String name) { return classDef.field(mods, type, name); } public JVarDeclaration field(final int mods, final String type, final String name, final JExpr init) { return classDef.field(mods, type, name, init); } public JMethodDef method(final int mods, final JType returnType, final String name) { return classDef.method(mods, returnType, name); } public JMethodDef method(final int mods, final Class returnType, final String name) { return classDef.method(mods, returnType, name); } public JMethodDef method(final int mods, final String returnType, final String name) { return classDef.method(mods, returnType, name); } public JMethodDef constructor(final int mods) { throw new UnsupportedOperationException("constructor on anonymous class"); } public JTypeParamDef[] typeParams() { return classDef.typeParams(); } public JAnnotation annotate(final String type) { return classDef.annotate(type); } public JAnnotation annotate(final JType type) { return classDef.annotate(type); } public JAnnotation annotate(final Class type) { return classDef.annotate(type); } public JDocComment docComment() { return classDef.docComment(); } public JComment deprecated() { return classDef.deprecated(); } public JComment lineComment() { return classDef.lineComment(); } public JComment blockComment() { return classDef.blockComment(); } public JClassDef _class(final int mods, final String name) { return classDef._class(mods, name); } public JClassDef _enum(final int mods, final String name) { return classDef._enum(mods, name); } public JClassDef _interface(final int mods, final String name) { return classDef._interface(mods, name); } public JClassDef annotationInterface(final int mods, final String name) { return classDef._interface(mods, name); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJCatch.java000066400000000000000000000100741250006154200257420ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Assertions.*; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ class ImplJCatch extends BasicJBlock implements JCatch { private final ImplJTry _try; private final int mods; private final String var; private final ArrayList types = new ArrayList<>(1); ImplJCatch(final ImplJTry _try, final int mods, final JType type, final String var) { super(_try.getParent(), Braces.REQUIRED); this.mods = mods; this.var = var; types.add(type); this._try = _try; } public JCatch or(final JType orType) { types.add(orType); return this; } public JCatch or(final String orType) { return or(JTypes.typeNamed(orType)); } public JCatch or(final Class orType) { return or(JTypes.typeOf(orType)); } public JVarDeclaration with(final int mods, final String type, final String var, final JExpr init) { return _try.with(mods, type, var, init); } public JVarDeclaration with(final int mods, final JType type, final String var, final JExpr init) { return _try.with(mods, type, var, init); } public JVarDeclaration with(final int mods, final Class type, final String var, final JExpr init) { return _try.with(mods, type, var, init); } public JCatch _catch(final int mods, final String type, final String var) { return _try._catch(mods, type, var); } public JCatch _catch(final int mods, final Class type, final String var) { return _try._catch(mods, type, var); } public JCatch _catch(final int mods, final JType type, final String var) { return _try._catch(mods, type, var); } public JTry ignore(final String type) { _try.ignore(type); return this; } public JTry ignore(final Class type) { _try.ignore(type); return this; } public JTry ignore(final JType type) { _try.ignore(type); return this; } public JBlock _finally() { return _try._finally(); } ImplJTry getTry() { return _try; } ArrayList getTypes() { return types; } int getMods() { return mods; } String getVar() { return var; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.CATCH); writer.write(FormatPreferences.Space.BEFORE_PAREN_CATCH); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_CATCH); JMod.write(writer, mods); final Iterator iterator = types.iterator(); if (alwaysTrue(iterator.hasNext())) { writer.write(iterator.next()); while (iterator.hasNext()) { writer.write($PUNCT.BINOP.BOR); writer.write(iterator.next()); } } writer.writeEscaped(var); writer.write(FormatPreferences.Space.WITHIN_PAREN_CATCH); writer.write($PUNCT.PAREN.CLOSE); super.write(writer, FormatPreferences.Space.BEFORE_BRACE_CATCH); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJDocComment.java000066400000000000000000000131601250006154200267470ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.List; import java.util.Map; /** * @author David M. Lloyd */ class ImplJDocComment extends AbstractJDocComment implements JDocComment { private static final Indent escIndent = new Indent() { public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) { final int idx = lineBuffer.length(); next.addIndent(next, preferences, lineBuffer); next.escape(next, lineBuffer, idx); } public void escape(final Indent next, final StringBuilder b, final int idx) { int c; int end; for (int i = idx; i < b.length();) { c = b.codePointAt(i); end = b.offsetByCodePoints(i, 1); switch (c) { // only use entities where necessary or very common practice case '<': b.replace(i, end, "<"); i += 4; break; case '>': b.replace(i, end, ">"); i += 4; break; case '&': b.replace(i, end, "&"); i += 5; break; case '@': b.replace(i, end, "@"); i += 5; break; case 0xAD: b.replace(i, end, "­"); i += 5; break; case 0x200D: b.replace(i, end, "‍"); i += 5; break; case 0x200E: b.replace(i, end, "‎"); i += 5; break; case 0x200F: b.replace(i, end, "‏"); i += 5; break; case 0xA0: b.replace(i, end, " "); i += 6; break; case 0x2002: b.replace(i, end, " "); i += 6; break; case 0x2003: b.replace(i, end, " "); i += 6; break; case 0x200C: b.replace(i, end, "‌"); i += 6; break; case 0x2009: b.replace(i, end, "&thisp;"); i += 7; break; // special cases case ' ': i++; break; case '\n': i++; break; // otherwise escape it default: { switch (Character.getType(c)) { case Character.UNASSIGNED: case Character.CONTROL: case Character.FORMAT: case Character.SURROGATE: case Character.NON_SPACING_MARK: case Character.COMBINING_SPACING_MARK: // also DIRECTIONALITY_NONSPACING_MARK case Character.ENCLOSING_MARK: case Character.LINE_SEPARATOR: case Character.PARAGRAPH_SEPARATOR: case Character.SPACE_SEPARATOR: { b.replace(i, end, "&#x"); final String hs = Integer.toHexString(c); b.insert(i += 3, hs); b.insert(i += hs.length(), ';'); break; } default: { i ++; break; } } break; } } } next.escape(next, b, idx); } public void unescaped(final Indent next, final StringBuilder b, final int idx) { // escape at next level next.escape(next, b, idx); } }; public void write(final SourceFileWriter writer) throws IOException { writer.addIndent(); writer.writeEscaped("/**"); writer.pushIndent(CommentIndentation.BLOCK); try { writer.pushIndent(escIndent); try { final List contents = getContent(); if (contents != null && ! contents.isEmpty()) { writer.nl(); for (Writable content : contents) { content.write(writer); } } final Map> docTags = getDocTags(); if (docTags != null) { for (Map.Entry> entry : docTags.entrySet()) { final List values = entry.getValue(); if (values != null) for (DocTagJHtmlComment value : values) { value.write(writer); } } } } finally { writer.popIndent(escIndent); } } finally { writer.popIndent(CommentIndentation.BLOCK); } writer.nl(); writer.addIndent(); writer.writeEscaped(" */"); writer.nl(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJEnumConstant.java000066400000000000000000000065451250006154200273460ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.$PUNCT; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ class ImplJEnumConstant extends BasicJAnnotatable implements JEnumConstant, JClassItem { private final EnumJClassDef classDef; private final String name; private ArrayList args; private EnumConstantJClassDef body; ImplJEnumConstant(final EnumJClassDef classDef, final String name) { this.classDef = classDef; this.name = name; } EnumJClassDef getClassDef() { return classDef; } public String getName() { return name; } public JEnumConstant arg(final JExpr expr) { if (args == null) { args = new ArrayList<>(); } args.add((AbstractJExpr) expr); return this; } public JClassDef body() { return body != null ? body : (body = new EnumConstantJClassDef(this)); } public JExpr[] arguments() { return args.toArray(new JExpr[args.size()]); } void writeDirect(final SourceFileWriter writer) throws IOException { writeComments(writer); if (args == null || args.isEmpty()) { if (writer.getFormat().hasOption(FormatPreferences.Opt.ENUM_EMPTY_PARENS)) { writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL_EMPTY); writer.write($PUNCT.PAREN.CLOSE); } } else { writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION); final Iterator iterator = args.iterator(); if (iterator.hasNext()) { writer.write(iterator.next()); while (iterator.hasNext()) { writer.write($PUNCT.COMMA); writer.write(FormatPreferences.Space.AFTER_COMMA); writer.write(iterator.next()); } } writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_DECLARATION); writer.write($PUNCT.PAREN.CLOSE); } if (body != null) { writer.write(FormatPreferences.Space.BEFORE_BRACE_CLASS); body.write(writer); } } public Kind getItemKind() { return Kind.ENUM_CONSTANT; } public int getModifiers() { return 0; } public boolean hasAllModifiers(final int mods) { return false; } public boolean hasAnyModifier(final int mods) { return false; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJHtmlTag.java000066400000000000000000000070521250006154200262620ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; /** * @author David M. Lloyd */ class ImplJHtmlTag extends AbstractJHtmlComment implements JHtmlTag, HtmlCommentContent { private final String tag; private final boolean newLine; private final boolean writeClose; private Map attributes; ImplJHtmlTag(final String tag, final boolean newLine, final boolean writeClose) { this.tag = tag; this.newLine = newLine; this.writeClose = writeClose; } String getTag() { return tag; } boolean isNewLine() { return newLine; } public JHtmlTag attribute(final String name) { doAdd(name, null); return this; } public JHtmlTag attribute(final String name, final String value) { doAdd(name, value); return this; } private void doAdd(final String name, final String value) { Map attributes = this.attributes; if (attributes == null) { this.attributes = attributes = new LinkedHashMap<>(); } attributes.put(name, value); } Iterable> attributes() { Map attributes = this.attributes; return attributes == null ? Collections.>emptySet() : attributes.entrySet(); } void writeOpenTag(SourceFileWriter writer) throws IOException { if (newLine) writer.nl(); writer.writeUnescaped('<'); writer.writeEscaped(tag); final Map attributes = this.attributes; if (attributes != null) for (final Map.Entry entry : attributes.entrySet()) { writer.sp(); writer.writeEscaped(entry.getKey()); final String value = entry.getValue(); if (value != null) { writer.writeUnescaped('='); writer.writeUnescaped('"'); writer.writeEscaped(value); writer.writeUnescaped('"'); } } writer.writeUnescaped('>'); if (newLine) { writer.nl(); } } void writeCloseTag(SourceFileWriter writer) throws IOException { if (writeClose) { if (newLine) writer.nl(); writer.writeEscaped('<'); writer.writeEscaped('/'); writer.writeEscaped(tag); writer.writeEscaped('>'); } } public void write(final SourceFileWriter writer) throws IOException { writeOpenTag(writer); writer.pushIndent(FormatPreferences.Indentation.HTML_TAG); try { super.write(writer); } finally { writer.popIndent(FormatPreferences.Indentation.HTML_TAG); } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJIf.java000066400000000000000000000044131250006154200252560ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ImplJIf extends ConditionJBlock implements JIf { private ElseJBlock _else; ImplJIf(final BasicJBlock parent, final JExpr cond) { super(parent, Braces.IF_MULTILINE, cond); } public JBlock _else() { // todo: analyze tree to see if we need to force brackets on our main block // e.g. if (cond) if (cond2) abc else xyz // ---> if (cond) { if (cond2) abc } else xyz // ---> if (cond) { if (cond2) abc else xyz } if (_else == null) { return _else = new ElseJBlock(this); } throw new IllegalStateException("else block already added"); } public JIf elseIf(final JExpr cond) { return _else()._if(cond); } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.IF); writer.write(FormatPreferences.Space.BEFORE_PAREN_IF); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_IF); writer.write(getCondition()); writer.write(FormatPreferences.Space.WITHIN_PAREN_IF); writer.write($PUNCT.PAREN.CLOSE); super.write(writer); if (_else != null) { if (hasSingleItemOfType(ImplJIf.class)) { _else.write(writer, null, Braces.REQUIRED); } else { _else.write(writer); } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJLabel.java000066400000000000000000000032661250006154200257440ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class ImplJLabel extends BasicJCommentable implements JLabel, JStatement, BlockContent { private String name; ImplJLabel(final String name) { this.name = name; } ImplJLabel() { } boolean isResolved() { return name != null; } public String name() { return name; } void setName(final String name) { this.name = name; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.pushIndent(FormatPreferences.Indentation.LABELS); try { writer.writeEscaped(name); writer.write($PUNCT.COLON); } finally { writer.popIndent(FormatPreferences.Indentation.LABELS); } writer.write(FormatPreferences.Space.AFTER_LABEL); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJParamDeclaration.java000066400000000000000000000040371250006154200301300ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import org.jboss.jdeparser.FormatPreferences.Space; /** * @author David M. Lloyd */ class ImplJParamDeclaration extends BasicJAnnotatable implements JParamDeclaration { private final JType type; private final String name; private final int mods; ImplJParamDeclaration(final int mods, final JType type, final String name) { this.mods = mods; this.type = type; this.name = name; } public JType type() { return type; } public String name() { return name; } public int mods() { return mods & ~JMod.PRIVATE_BITS; } public boolean varargs() { return JMod.allAreSet(mods, JMod.VARARGS); } public JComment doc() { return null; } void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writeAnnotations(writer, Space.AFTER_PARAM_ANNOTATION); JMod.write(writer, mods()); writer.write(type); if (varargs()) { // todo maybe a separate token type writer.write(Tokens.$PUNCT.DOT); writer.write(Tokens.$PUNCT.DOT); writer.write(Tokens.$PUNCT.DOT); } writer.sp(); writer.writeEscapedWord(name); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJSourceFile.java000066400000000000000000000163231250006154200267630ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * @author David M. Lloyd */ class ImplJSourceFile extends BasicJCommentable implements JSourceFile { private final ImplJSources sources; private final Map imports = new HashMap<>(); private final Map staticImports = new HashMap<>(); private final ArrayList content = new ArrayList<>(); private final String packageName; private final String fileName; private boolean packageWritten; ImplJSourceFile(final ImplJSources sources, final String packageName, final String fileName) { this.sources = sources; this.packageName = packageName; this.fileName = fileName; } private C add(C item) { content.add(item); return item; } private void checkPackage() { if (! packageWritten) { content.add(new ClassFileContent() { public void write(final SourceFileWriter writer) throws IOException { writer.write($KW.PACKAGE); writer.sp(); writer.writeEscaped(packageName); writer.write($PUNCT.SEMI); writer.nl(); final Map imports = ImplJSourceFile.this.imports; if (imports != null) { final Iterator iterator = imports.values().iterator(); if (iterator.hasNext()) { writer.nl(); do { final ReferenceJType _import = iterator.next(); writer.write($KW.IMPORT); writer.writeClass(_import.qualifiedName(writer)); writer.write($PUNCT.SEMI); writer.nl(); } while (iterator.hasNext()); writer.nl(); } } final Map staticImports = ImplJSourceFile.this.staticImports; if (staticImports != null) { final Iterator iterator = staticImports.values().iterator(); if (iterator.hasNext()) { writer.nl(); do { final StaticRefJExpr staticImport = iterator.next(); writer.write($KW.IMPORT); writer.write($KW.STATIC); writer.write(staticImport); writer.write($PUNCT.SEMI); writer.nl(); } while (iterator.hasNext()); writer.nl(); } } } }); packageWritten = true; } } boolean hasImport(final String name) { return imports.containsKey(name); } boolean hasImport(final JType type, final SourceFileWriter writer) { if (type instanceof ReferenceJType) { ReferenceJType referenceJType = (ReferenceJType) type; final String name = referenceJType.simpleName(); if (imports.containsKey(name) && imports.get(name).qualifiedName(writer).equals(referenceJType.qualifiedName(writer))) { return true; } } return false; } boolean hasStaticImport(final String name) { return staticImports.containsKey(name); } boolean hasStaticImport(final JExpr expr, final SourceFileWriter writer) { if (! (expr instanceof StaticRefJExpr)) return false; final StaticRefJExpr staticRefJExpr = (StaticRefJExpr) expr; final String refName = staticRefJExpr.getRefName(); return staticImports.containsKey(refName) && staticImports.get(refName).getType().qualifiedName(writer).equals(staticRefJExpr.getType().qualifiedName(writer)); } public JSourceFile _import(final String type) { return _import(JTypes.typeNamed(type)); } public JSourceFile _import(final JType type) { checkPackage(); if (! (type instanceof ReferenceJType)) { return this; } if (imports.containsKey(type.simpleName())) { return this; } imports.put(type.simpleName(), (ReferenceJType) type); return this; } public JSourceFile _import(final Class type) { return _import(JTypes.typeOf(type)); } public JSourceFile importStatic(final String type, final String member) { return importStatic(JTypes.typeNamed(type), member); } public JSourceFile importStatic(final JType type, final String member) { checkPackage(); staticImports.put(member, new StaticRefJExpr(AbstractJType.of(type), member)); return this; } public JSourceFile importStatic(final Class type, final String member) { return importStatic(JTypes.typeOf(type), member); } public JSourceFile blankLine() { checkPackage(); add(BlankLine.getInstance()); return this; } public JClassDef _class(final int mods, final String name) { checkPackage(); return add(new PlainJClassDef(mods, this, name)); } public JClassDef _enum(final int mods, final String name) { checkPackage(); return add(new EnumJClassDef(mods, this, name)); } public JClassDef _interface(final int mods, final String name) { checkPackage(); return add(new InterfaceJClassDef(mods, this, name)); } public JClassDef annotationInterface(final int mods, final String name) { checkPackage(); return add(new AnnotationJClassDef(mods, this, name)); } String getPackageName() { return packageName; } String getFileName() { return fileName; } void write(final SourceFileWriter sourceFileWriter) throws IOException { sourceFileWriter.setClassFile(this); for (ClassFileContent item : content) { item.write(sourceFileWriter); } sourceFileWriter.setClassFile(null); } ImplJSources getSources() { return sources; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJSources.java000066400000000000000000000052241250006154200263440ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; /** * @author David M. Lloyd */ class ImplJSources implements JSources { private final JFiler filer; private final FormatPreferences format; private final List classFiles = new ArrayList<>(); private final Map classes = new HashMap<>(); private final Map qualifiedNames = new IdentityHashMap<>(); ImplJSources(final JFiler filer, final FormatPreferences format) { this.filer = filer; this.format = format; } void addClassDef(String qualifiedName, AbstractJClassDef classDef) { classes.put(qualifiedName, classDef); qualifiedNames.put(classDef, qualifiedName); } boolean hasClass(String qualifiedName) { return classes.containsKey(qualifiedName); } String qualifiedNameOf(AbstractJClassDef classDef) { return qualifiedNames.get(classDef); } public JSourceFile createSourceFile(final String packageName, final String fileName) { final ImplJSourceFile classFile = new ImplJSourceFile(this, packageName, fileName); classFiles.add(classFile); return classFile; } public JPackageInfoFile createPackageInfoFile(final String packageName) { throw new UnsupportedOperationException("package-info.java"); } public void writeSources() throws IOException { for (ImplJSourceFile classFile : classFiles) { try (Writer writer = filer.openWriter(classFile.getPackageName(), classFile.getFileName())) { try (SourceFileWriter sourceFileWriter = new SourceFileWriter(format, writer)) { classFile.write(sourceFileWriter); } } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJSwitch.java000066400000000000000000000057411250006154200261660ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; /** * @author David M. Lloyd */ class ImplJSwitch extends BasicJCommentable implements JSwitch, BlockContent { private final BasicJBlock parent; private final JExpr expr; private final ArrayList cases = new ArrayList<>(); private DefaultJBlock _default; ImplJSwitch(final BasicJBlock parent, final JExpr expr) { this.parent = parent; this.expr = expr; } private T add(T item) { cases.add(item); return item; } public JBlock _case(final JExpr expr) { return add(new CaseJBlock(this, expr)); } public JBlock _case(final String constName) { return _case(JExprs.name(constName)); } public JBlock _default() { if (_default == null) { _default = new DefaultJBlock(this); } return _default; } JExpr getExpression() { return expr; } BasicJBlock getParent() { return parent; } ArrayList getCases() { return cases; } DefaultJBlock getDefault() { return _default; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); writer.write($KW.SWITCH); writer.write(FormatPreferences.Space.BEFORE_PAREN_SWITCH); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_SWITCH); writer.write(expr); writer.write($PUNCT.PAREN.CLOSE); writer.write(FormatPreferences.Space.BEFORE_BRACE_SWITCH); writer.write($PUNCT.BRACE.OPEN); writer.pushIndent(FormatPreferences.Indentation.LINE); try { writer.write(FormatPreferences.Space.WITHIN_BRACES_CODE); for (CaseJBlock _case : cases) { _case.write(writer); } if (_default != null) { _default.write(writer); } } finally { writer.popIndent(FormatPreferences.Indentation.LINE); } writer.write(FormatPreferences.Space.WITHIN_BRACES_CODE); writer.write($PUNCT.BRACE.CLOSE); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJTry.java000066400000000000000000000110071250006154200254730ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ class ImplJTry extends BasicJBlock implements JTry { private ArrayList catches; private ArrayList resources; private FinallyJBlock finallyBlock; ImplJTry(final BasicJBlock parent) { super(parent, Braces.REQUIRED); } public JVarDeclaration with(final int mods, final String type, final String var, final JExpr init) { return with(mods, JTypes.typeNamed(type), var, init); } public JVarDeclaration with(final int mods, final JType type, final String var, final JExpr init) { return add(new TryJVarDeclaration(mods, type, var, init, this)); } public JVarDeclaration with(final int mods, final Class type, final String var, final JExpr init) { return with(mods, JTypes.typeOf(type), var, init); } private T add(T item) { if (resources == null) resources = new ArrayList<>(); resources.add(item); return item; } public JCatch _catch(final int mods, final String type, final String var) { return _catch(mods, JTypes.typeNamed(type), var); } public JCatch _catch(final int mods, final Class type, final String var) { return _catch(mods, JTypes.typeOf(type), var); } public JCatch _catch(final int mods, final JType type, final String var) { return add(new ImplJCatch(this, mods, type, var)); } private T add(T item) { if (catches == null) catches = new ArrayList<>(); catches.add(item); return item; } public JTry ignore(final String type) { return ignore(JTypes.typeNamed(type)); } public JTry ignore(final Class type) { return ignore(JTypes.typeOf(type)); } public JTry ignore(final JType type) { _catch(0, type, "ignored"); return this; } public JBlock _finally() { if (finallyBlock == null) { finallyBlock = new FinallyJBlock(this); } return finallyBlock; } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); if ((catches == null || catches.isEmpty()) && (resources == null || resources.isEmpty()) && finallyBlock == null) { super.write(writer, null); } else { writer.write($KW.TRY); if (resources != null) { final Iterator iterator = resources.iterator(); if (iterator.hasNext()) { writer.write(FormatPreferences.Space.BEFORE_PAREN_TRY); writer.write($PUNCT.PAREN.OPEN); writer.write(FormatPreferences.Space.WITHIN_PAREN_TRY); iterator.next().writeNoSemi(writer); while (iterator.hasNext()) { writer.write(FormatPreferences.Space.BEFORE_SEMICOLON); writer.write($PUNCT.SEMI); writer.write(FormatPreferences.Space.AFTER_SEMICOLON); iterator.next().writeNoSemi(writer); } } writer.write(FormatPreferences.Space.WITHIN_PAREN_TRY); writer.write($PUNCT.PAREN.CLOSE); } super.write(writer, FormatPreferences.Space.BEFORE_BRACE_TRY); if (catches != null) for (ImplJCatch _catch : catches) { _catch.write(writer); } if (finallyBlock != null) { finallyBlock.write(writer); } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ImplJTypeParamDef.java000066400000000000000000000065571250006154200272540ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ class ImplJTypeParamDef implements JTypeParamDef { private final String name; private ArrayList _extends; private ArrayList _super; ImplJTypeParamDef(final String name) { this.name = name; } public JTypeParamDef _extends(final String type) { return _extends(JTypes.typeNamed(type)); } public JTypeParamDef _extends(final JType type) { if (_super != null) { throw new IllegalArgumentException("Cannot mix extends and super bounds"); } if (_extends == null) { _extends = new ArrayList<>(); } _extends.add(type); return this; } public JTypeParamDef _extends(final Class type) { return _extends(JTypes.typeOf(type)); } public JTypeParamDef _super(final String type) { return _super(JTypes.typeNamed(type)); } public JTypeParamDef _super(final JType type) { if (_extends != null) { throw new IllegalArgumentException("Cannot mix extends and super bounds"); } if (_super == null) { _super = new ArrayList<>(); } _super.add(type); return this; } public JTypeParamDef _super(final Class type) { return _super(JTypes.typeOf(type)); } String getName() { return name; } Iterable getExtends() { return _extends; } Iterable getSuper() { return _super; } private void writeList(final SourceFileWriter sourceFileWriter, ArrayList list, $KW keyword) throws IOException { if (list == null) { return; } final Iterator iterator = list.iterator(); if (! iterator.hasNext()) { return; } JType type = iterator.next(); sourceFileWriter.write(keyword); sourceFileWriter.write(type); while (iterator.hasNext()) { type = iterator.next(); sourceFileWriter.write(FormatPreferences.Space.AROUND_BITWISE); sourceFileWriter.write($PUNCT.BINOP.BAND); sourceFileWriter.write(FormatPreferences.Space.AROUND_BITWISE); sourceFileWriter.write(type); } } void write(final SourceFileWriter sourceFileWriter) throws IOException { sourceFileWriter.writeClass(name); writeList(sourceFileWriter, _extends, $KW.EXTENDS); writeList(sourceFileWriter, _super, $KW.SUPER); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/IncDecJExpr.java000066400000000000000000000022741250006154200260650ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; /** * @author David M. Lloyd */ class IncDecJExpr extends UnaryJExpr implements AllowedStatementExpression { IncDecJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr, final int prec) { super(op, expr, prec); } IncDecJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr, final int prec, final boolean postfix) { super(op, expr, prec, postfix); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Indent.java000066400000000000000000000017071250006154200252100ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; interface Indent { void addIndent(Indent next, FormatPreferences preferences, StringBuilder lineBuffer); void escape(Indent next, StringBuilder b, int idx); void unescaped(Indent next, StringBuilder b, int idx); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InitJBlock.java000066400000000000000000000027121250006154200257540ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class InitJBlock extends BasicJBlock implements ClassContent, JClassItem { InitJBlock() { super(null, Braces.REQUIRED); } public void write(final SourceFileWriter writer) throws IOException { writeComments(writer); super.write(writer, null); } public Kind getItemKind() { return Kind.INIT_BLOCK; } public int getModifiers() { return 0; } public boolean hasAllModifiers(final int mods) { return false; } public boolean hasAnyModifier(final int mods) { return false; } public String getName() { return null; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InlineDocTagCommentContent.java000066400000000000000000000050711250006154200311430ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class InlineDocTagCommentContent extends AbstractJComment implements CommentContent { static final Indent INDENT = new Indent() { public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) { next.addIndent(next, preferences, lineBuffer); } public void escape(final Indent next, final StringBuilder b, final int idx) { char ch; for (int i = idx; i < b.length();) { ch = b.charAt(i); // not pretty but always renders correctly switch (ch) { case '}': b.replace(i, i + 1, "}"); i += 6; break; case '{': b.replace(i, i + 1, "{"); i += 6; break; default: i++; break; } } } public void unescaped(final Indent next, final StringBuilder b, final int idx) { // next level is escaped next.escape(next, b, idx); } }; private final String tagName; InlineDocTagCommentContent(final String tagName) { this.tagName = tagName; } String getTagName() { return tagName; } public void write(final SourceFileWriter writer) throws IOException { writer.writeUnescaped("{@"); writer.pushIndent(INDENT); try { writer.writeEscaped(tagName); writer.sp(); super.write(writer); } finally { writer.popIndent(INDENT); } writer.writeUnescaped("}"); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InnerJAnonymousClassDef.java000066400000000000000000000023051250006154200304650ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import static org.jboss.jdeparser.Tokens.$PUNCT; class InnerJAnonymousClassDef extends ImplJAnonymousClassDef { private final AbstractJExpr expr; InnerJAnonymousClassDef(final AbstractJExpr expr, final JType type) { super(type); this.expr = expr; } public void write(final SourceFileWriter writer) throws IOException { writer.write(expr); writer.write($PUNCT.DOT); super.write(writer); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InnerNewJCall.java000066400000000000000000000024101250006154200264120ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class InnerNewJCall extends NewJCall { private final AbstractJExpr target; InnerNewJCall(final AbstractJExpr target, final JType type) { super(AbstractJType.of(type)); this.target = target; } public void write(final SourceFileWriter writer) throws IOException { writer.write(target); writer.write($PUNCT.DOT); super.write(writer); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InstanceJCall.java000066400000000000000000000024721250006154200264410ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class InstanceJCall extends AbstractMethodJCall { private final JExpr target; InstanceJCall(final JExpr target, final String name) { super(name); this.target = target; } JExpr getTarget() { return target; } public void write(final SourceFileWriter writer) throws IOException { writer.write(AbstractJExpr.of(target)); writer.write($PUNCT.DOT); super.write(writer); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InstanceOfJExpr.java000066400000000000000000000027441250006154200267730ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; import java.io.IOException; /** * @author David M. Lloyd */ class InstanceOfJExpr extends AbstractJExpr { private final AbstractJExpr expr; private final JType type; InstanceOfJExpr(final AbstractJExpr expr, final JType type) { super(Prec.INSTANCEOF); this.expr = expr.prec() > Prec.INSTANCEOF ? new ParenJExpr(expr) : expr; this.type = type; } AbstractJExpr getExpression() { return expr; } JType getType() { return type; } public void write(final SourceFileWriter writer) throws IOException { writer.write(expr); writer.write($KW.INSTANCEOF); writer.write(type); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/IntegerJExpr.java000066400000000000000000000027451250006154200263400ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; /** * @author David M. Lloyd */ class IntegerJExpr extends AbstractJExpr implements JExpr { private final int val; private final int radix; IntegerJExpr(final int val, final int radix) { super(0); this.val = val; this.radix = radix; } public void write(final SourceFileWriter writer) throws IOException { writer.addWordSpace(); writer.write(Tokens.$NUMBER); switch (radix) { case 2: writer.writeEscaped("0b"); break; case 16: writer.writeEscaped("0x"); break; } writer.writeEscaped(Integer.toString(val, radix)); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/InterfaceJClassDef.java000066400000000000000000000043501250006154200274030ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.ArrayList; /** * @author David M. Lloyd */ class InterfaceJClassDef extends AbstractJClassDef implements JClassItem { InterfaceJClassDef(final int mods, final ImplJSourceFile classFile, final String name) { super(mods, classFile, name); } InterfaceJClassDef(final int mods, final AbstractJClassDef enclosingClass, final String name) { super(mods, enclosingClass, name); } Tokens.$KW designation() { return Tokens.$KW.INTERFACE; } public JClassDef _extends(final String name) { return super._implements(name); } public JClassDef _extends(final JType type) { return super._implements(type); } public JClassDef _extends(final Class clazz) { return super._implements(clazz); } boolean hasInterfaceStyleExtends() { return true; } public JBlock init(final ArrayList content) { throw new UnsupportedOperationException("Interfaces cannot have init blocks"); } public JMethodDef constructor(final ArrayList content, final int mods) { throw new UnsupportedOperationException("Interfaces cannot have constructors"); } boolean supportsCompactInitOnly() { return false; } boolean methodCanHaveBody(final int mods) { return false; } public Kind getItemKind() { return Kind.INTERFACE; } public String getName() { return super.getName(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnnotatable.java000066400000000000000000000027171250006154200263330ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.lang.annotation.Annotation; /** * A program element which can be annotated. * * @author David M. Lloyd */ public interface JAnnotatable { /** * Add an annotation. * * @param type the type of the annotation to add * @return the new annotation */ JAnnotation annotate(String type); /** * Add an annotation. * * @param type the type of the annotation to add * @return the new annotation */ JAnnotation annotate(JType type); /** * Add an annotation. * * @param type the type of the annotation to add * @return the new annotation */ JAnnotation annotate(Class type); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnnotation.java000066400000000000000000000120511250006154200262050ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.lang.annotation.Annotation; /** * An annotation. * * @author David M. Lloyd */ public interface JAnnotation { /** * Set the "value" property of this annotation. To set an array of values, see {@link JExprs#array(JExpr...)}. * * @param expr the annotation value * @return this annotation */ JAnnotation value(JExpr expr); /** * Set the "value" property of this annotation to a string. * * @param literal the annotation value string * @return this annotation */ JAnnotation value(String literal); /** * Set the "value" property of this annotation to a nested annotation of the given type. * * @param type the annotation type * @return the nested annotation */ JAnnotation annotationValue(String type); /** * Set the "value" property of this annotation to a nested annotation of the given type. * * @param type the annotation type * @return the nested annotation */ JAnnotation annotationValue(JType type); /** * Set the "value" property of this annotation to a nested annotation of the given type. * * @param type the annotation type * @return the nested annotation */ JAnnotation annotationValue(Class type); /** * Set the "value" property of this annotation to an array of nested annotations of the given type. * * @param type the annotation array element type * @return the nested annotation */ JAnnotationArray annotationArrayValue(String type); /** * Set the "value" property of this annotation to an array of nested annotations of the given type. * * @param type the annotation array element type * @return the nested annotation */ JAnnotationArray annotationArrayValue(JType type); /** * Set the "value" property of this annotation to an array of nested annotations of the given type. * * @param type the annotation array element type * @return the nested annotation */ JAnnotationArray annotationArrayValue(Class type); /** * Set the named property of this annotation. To set an array of values, see {@link JExprs#array(JExpr...)}. * * @param name the annotation property name * @param expr the annotation value * @return this annotation */ JAnnotation value(String name, JExpr expr); /** * Set the named property of this annotation to a string. * * @param name the annotation property name * @param literal the annotation value string * @return this annotation */ JAnnotation value(String name, String literal); /** * Set the named property of this annotation to a nested annotation of the given type. * * @param type the annotation type * @return the nested annotation */ JAnnotation annotationValue(String name, String type); /** * Set the named property of this annotation to a nested annotation of the given type. * * @param type the annotation type * @return the nested annotation */ JAnnotation annotationValue(String name, JType type); /** * Set the named property of this annotation to a nested annotation of the given type. * * @param type the annotation type * @return the nested annotation */ JAnnotation annotationValue(String name, Class type); /** * Set the named property of this annotation to an array of nested annotations of the given type. * * @param type the annotation array element type * @return the nested annotation */ JAnnotationArray annotationArrayValue(String name, String type); /** * Set the named property of this annotation to an array of nested annotations of the given type. * * @param type the annotation array element type * @return the nested annotation */ JAnnotationArray annotationArrayValue(String name, JType type); /** * Set the named property of this annotation to an array of nested annotations of the given type. * * @param type the annotation array element type * @return the nested annotation */ JAnnotationArray annotationArrayValue(String name, Class type); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnnotationArray.java000066400000000000000000000017721250006154200272140ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * An array of annotations. * * @author David M. Lloyd */ public interface JAnnotationArray { /** * Add an annotation of the array's type to the array. * @return the new annotation */ JAnnotation add(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnonymousClassDef.java000066400000000000000000000017631250006154200275000ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * An anonymous class definition. Anonymous classes have characteristics of both constructor calls and class * definitions. * * @author David M. Lloyd */ public interface JAnonymousClassDef extends JCall, JClassDef { } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JArrayExpr.java000066400000000000000000000022741250006154200260160ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * An array expression, which can have more values added to it. */ public interface JArrayExpr extends JExpr { // originals /** * Add an element to this array. Returns this array. * * @param value the value to add * @return this array expression */ JArrayExpr add(JExpr value); /** * Get the current number of elements added to this array. * * @return the number of elements */ int elementCount(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAssignableExpr.java000066400000000000000000000100311250006154200267760ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * An expression which is assignable (that is, is a valid "lvalue"). * * @author David M. Lloyd */ public interface JAssignableExpr extends JExpr, JStatement { // assign /** * Combine this expression with another using the binary {@code =} operator. * * @param e1 the other expression * @return the combined expression */ JExpr assign(JExpr e1); /** * Combine this expression with another using the binary {@code +=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr addAssign(JExpr e1); /** * Combine this expression with another using the binary {@code -=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr subAssign(JExpr e1); /** * Combine this expression with another using the binary {@code *=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr mulAssign(JExpr e1); /** * Combine this expression with another using the binary {@code /=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr divAssign(JExpr e1); /** * Combine this expression with another using the binary {@code %=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr modAssign(JExpr e1); /** * Combine this expression with another using the binary {@code &=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr andAssign(JExpr e1); /** * Combine this expression with another using the binary {@code |=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr orAssign(JExpr e1); /** * Combine this expression with another using the binary {@code ^=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr xorAssign(JExpr e1); /** * Combine this expression with another using the binary {@code >>=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr shrAssign(JExpr e1); /** * Combine this expression with another using the binary {@code >>>=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr lshrAssign(JExpr e1); /** * Combine this expression with another using the binary {@code <<=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr shlAssign(JExpr e1); // inc/dec /** * Apply the postfix {@code ++} operator to this expression. * * @return the new expression */ JExpr postInc(); /** * Apply the postfix {@code --} operator to this expression. * * @return the new expression */ JExpr postDec(); /** * Apply the prefix {@code ++} operator to this expression. * * @return the new expression */ JExpr preInc(); /** * Apply the prefix {@code --} operator to this expression. * * @return the new expression */ JExpr preDec(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JBlock.java000066400000000000000000000442561250006154200251410ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import javax.lang.model.element.ExecutableElement; /** * A block of code, to which statements may be added. * * @author David M. Lloyd */ public interface JBlock extends JStatement, JCommentable { /** * Insert a blank line at this point. * * @return this block */ JBlock blankLine(); /** * Create a nested sub-block at this point. * * @param braces the rule for adding braces * @return the nested block */ JBlock block(Braces braces); // program flow /** * Insert an {@code if} statement at this point. * * @param cond the {@code if} condition * @return the {@code if} statement */ JIf _if(JExpr cond); /** * Insert a {@code while} statement at this point. * * @param cond the {@code while} condition * @return the {@code while} statement */ JBlock _while(JExpr cond); /** * Insert a {@code do}/{@code while} statement at this point. * * @param cond the {@code while} condition * @return the {@code while} statement */ JBlock _do(JExpr cond); /** * Add a label at this point, which may be used for future branch instructions. * * @param name the label name * @return the label */ JLabel label(String name); /** * Add a label at this point whose unique name is automatically generated. * * @return the label */ JLabel anonLabel(); /** * Create a forward label that can be named and attached later. * * @return the forward label */ JLabel forwardLabel(); /** * Name and attach a forward label. * * @param label the label to name and attach * @param name the label name * @return the attached label */ JLabel label(JLabel label, String name); /** * Name and attach a forward label as anonymous. * * @param label the label to name and attach * @return the attached label */ JLabel anonLabel(JLabel label); /** * Insert a {@code continue} statement at this point. * * @return the statement */ JStatement _continue(); /** * Insert a labelled {@code continue} statement at this point. * * @param label the label * @return the statement */ JStatement _continue(JLabel label); /** * Insert a {@code break} statement at this point. * * @return the statement */ JStatement _break(); /** * Insert a labelled {@code break} statement at this point. * * @param label the label * @return the statement */ JStatement _break(JLabel label); /** * Insert a "for-each" style {@code for} loop at this point. * * @param mods the item variable modifiers * @param type the item variable type * @param name the item variable name * @param iterable the iterable or array expression * @return the body of the {@code for} loop */ JBlock forEach(int mods, String type, String name, JExpr iterable); /** * Insert a "for-each" style {@code for} loop at this point. * * @param mods the item variable modifiers * @param type the item variable type * @param name the item variable name * @param iterable the iterable or array expression * @return the body of the {@code for} loop */ JBlock forEach(int mods, JType type, String name, JExpr iterable); /** * Insert a "for-each" style {@code for} loop at this point. * * @param mods the item variable modifiers * @param type the item variable type * @param name the item variable name * @param iterable the iterable or array expression * @return the body of the {@code for} loop */ JBlock forEach(int mods, Class type, String name, JExpr iterable); /** * Insert a {@code for} loop at this point. * * @return the {@code for} loop */ JFor _for(); /** * Insert a {@code switch} statement at this point. * * @param expr the {@code switch} expression * @return the {@code switch} statement */ JSwitch _switch(JExpr expr); /** * Insert a {@code return} statement at this point. * * @param expr the expression to return * @return the statement */ JStatement _return(JExpr expr); /** * Insert a {@code void} {@code return} statement at this point. * * @return the statement */ JStatement _return(); // assert /** * Insert an {@code assert} statement at this point. * * @param expr the expression to assert * @return the statement */ JStatement _assert(JExpr expr); /** * Insert an {@code assert} statement at this point with a message. * * @param expr the expression to assert * @param message the assertion message * @return the statement */ JStatement _assert(JExpr expr, JExpr message); // constructor invocations /** * Insert a {@code this()} call at this point. * * @return the call */ JCall callThis(); /** * Insert a {@code super()} call at this point. * * @return the call */ JCall callSuper(); // expression /** * Insert an expression statement at this point. Expressions which are invalid statements may generate an * error at the time this method is called, or at compile time. * * @param expr the expression to add * @return the statement */ JStatement add(JExpr expr); // invocations /** * Insert a method invocation at this point. * * Note that these two invocations are identical: * *
{@code
    block.call(element);
    block.add(JExprs.call(element));
}
* * @param element the program element whose name to use * @return the method call */ JCall call(ExecutableElement element); /** * Insert a method invocation at this point. * * @param obj the expression upon which to invoke * @param element the program element whose name to use * @return the method call */ JCall call(JExpr obj, ExecutableElement element); /** * Insert a method invocation at this point. * * Note that these two invocations are identical: * *
{@code
    block.call(methodName);
    block.add(JExprs.call(methodName));
}
* * @param name the method name * @return the method call */ JCall call(String name); /** * Insert a method invocation at this point. * * @param obj the expression upon which to invoke * @param name the method name * @return the method call */ JCall call(JExpr obj, String name); /** * Insert a type-qualified static method invocation at this point. * * @param element the program element whose name and type to use * @return the method call */ JCall callStatic(ExecutableElement element); /** * Insert a type-qualified static method invocation at this point. * * @param type the type upon which to invoke * @param name the method name * @return the method call */ JCall callStatic(String type, String name); /** * Insert a type-qualified static method invocation at this point. * * @param type the type upon which to invoke * @param name the method name * @return the method call */ JCall callStatic(JType type, String name); /** * Insert a type-qualified static method invocation at this point. * * @param type the type upon which to invoke * @param name the method name * @return the method call */ JCall callStatic(Class type, String name); // raw construction /** * Insert an object construction statement at this point. * * @param type the type to instantiate * @return the constructor call */ JCall _new(String type); /** * Insert an object construction statement at this point. * * @param type the type to instantiate * @return the constructor call */ JCall _new(JType type); /** * Insert an object construction statement at this point. * * @param type the type to instantiate * @return the constructor call */ JCall _new(Class type); /** * Insert an object construction statement for an anonymous class at this point. * * @param type the type to instantiate * @return the anonymous class definition */ JAnonymousClassDef _newAnon(String type); /** * Insert an object construction statement for an anonymous class at this point. * * @param type the type to instantiate * @return the anonymous class definition */ JAnonymousClassDef _newAnon(JType type); /** * Insert an object construction statement for an anonymous class at this point. * * @param type the type to instantiate * @return the anonymous class definition */ JAnonymousClassDef _newAnon(Class type); // local class definition /** * Insert a local class definition at this point. * * @param mods the class modifiers * @param name the local class name * @return the local class definition */ JClassDef _class(int mods, String name); // synch /** * Insert a {@code synchronized} block at this point. * * @param synchExpr the lock expression * @return the {@code synchronized} block */ JBlock _synchronized(JExpr synchExpr); // assignment /** * Insert an assignment ({@code =}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement assign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code +=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement addAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code -=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement subAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code *=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement mulAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code /=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement divAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code %=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement modAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code &=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement andAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code |=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement orAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code ^=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement xorAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code >>=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement shrAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code >>>=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement lshrAssign(JAssignableExpr target, JExpr e1); /** * Insert an assignment ({@code <<=}) expression at this point. * * @param target the assignment target * @param e1 the expression to apply * @return the statement */ JStatement shlAssign(JAssignableExpr target, JExpr e1); // inc/dec /** * Insert a postfix {@code ++} expression at this point. * * @param target the target expression * @return the statement */ JStatement postInc(JAssignableExpr target); /** * Insert a postfix {@code --} expression at this point. * * @param target the target expression * @return the statement */ JStatement postDec(JAssignableExpr target); /** * Insert a prefix {@code ++} expression at this point. * * @param target the target expression * @return the statement */ JStatement preInc(JAssignableExpr target); /** * Insert a prefix {@code --} expression at this point. * * @param target the target expression * @return the statement */ JStatement preDec(JAssignableExpr target); // empty /** * Insert an empty statement at this point (just a semicolon). * * @return the statement */ JStatement empty(); // exceptions /** * Insert a {@code throw} statement at this point. * * @param expr the expression to throw * @return the statement */ JStatement _throw(JExpr expr); /** * Insert a {@code try} block at this point. * * @return the {@code try} block */ JTry _try(); // declarations /** * Insert a local variable declaration at this point. * * @param mods the variable modifiers * @param type the local variable type * @param name the local variable name * @param value the local variable's initializer expression * @return the local variable declaration */ JVarDeclaration var(int mods, String type, String name, JExpr value); /** * Insert a local variable declaration at this point. * * @param mods the variable modifiers * @param type the local variable type * @param name the local variable name * @param value the local variable's initializer expression * @return the local variable declaration */ JVarDeclaration var(int mods, JType type, String name, JExpr value); /** * Insert a local variable declaration at this point. * * @param mods the variable modifiers * @param type the local variable type * @param name the local variable name * @param value the local variable's initializer expression * @return the local variable declaration */ JVarDeclaration var(int mods, Class type, String name, JExpr value); /** * Insert a local variable declaration at this point. * * @param mods the variable modifiers * @param type the local variable type * @param name the local variable name * @return the local variable declaration */ JVarDeclaration var(int mods, String type, String name); /** * Insert a local variable declaration at this point. * * @param mods the variable modifiers * @param type the local variable type * @param name the local variable name * @return the local variable declaration */ JVarDeclaration var(int mods, JType type, String name); /** * Insert a local variable declaration at this point. * * @param mods the variable modifiers * @param type the local variable type * @param name the local variable name * @return the local variable declaration */ JVarDeclaration var(int mods, Class type, String name); /** * Insert a local variable declaration at this point with a generated name. * * @param type the local variable type * @param value the local variable's initializer expression * @return the local variable expression */ JExpr tempVar(String type, JExpr value); /** * Insert a local variable declaration at this point with a generated name. * * @param type the local variable type * @param value the local variable's initializer expression * @return the local variable expression */ JExpr tempVar(JType type, JExpr value); /** * Insert a local variable declaration at this point with a generated name. * * @param type the local variable type * @param value the local variable's initializer expression * @return the local variable expression */ JExpr tempVar(Class type, JExpr value); /** * Generate a temporary variable name. * * @return the generated name */ String tempName(); /** * Braces mode. * * @apiviz.exclude */ enum Braces { /** * Braces are optional and won't be rendered unless forced. */ OPTIONAL, /** * Braces are only required if the block contains more or less than one statement. */ IF_MULTILINE, /** * Braces should always be used. */ REQUIRED, ; } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JCall.java000066400000000000000000000035051250006154200247520ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A method or constructor call. * * @author David M. Lloyd */ public interface JCall extends JExpr, JSimpleArgs { /** * Use the "diamond" {@code <>} syntax to specify inferred type arguments. * * @return this call */ JCall diamond(); /** * Add a type argument to this call. * * @param type the type to add * @return this call */ JCall typeArg(JType type); /** * Add a type argument to this call. * * @param type the type to add * @return this call */ JCall typeArg(String type); /** * Add a type argument to this call. * * @param type the type to add * @return this call */ JCall typeArg(Class type); /** * Add an actual parameter argument to this call. * * @param expr the argument expression * @return this call */ JCall arg(JExpr expr); /** * Get the type arguments defined thus far. * * @return the type arguments */ JType[] typeArguments(); JExpr[] arguments(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JCatch.java000066400000000000000000000027021250006154200251170ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A {@code catch} branch for a {@code try} block. * * @author David M. Lloyd */ public interface JCatch extends JTry { /** * Add another type option to this catch branch. * * @param orType the alternative type * @return this catch block */ JCatch or(JType orType); /** * Add another type option to this catch branch. * * @param orType the alternative type * @return this catch block */ JCatch or(String orType); /** * Add another type option to this catch branch. * * @param orType the alternative type * @return this catch block */ JCatch or(Class orType); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassDef.java000066400000000000000000000055321250006154200255650ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A type definition, which can be a class, interface, annotation type, etc. * * @author David M. Lloyd */ public interface JClassDef extends JAnnotatable, JDocCommentable, JGenericDef, JClassDefSection { /** * Add a blank line at this point of the type. * * @return this type definition */ JClassDef blankLine(); /** * Add an {@code extends} type to this type. * * @param name the type name * @return this type definition */ JClassDef _extends(String name); /** * Add an {@code extends} type to this type. * * @param type the type * @return this type definition */ JClassDef _extends(JType type); /** * Add an {@code extends} type to this type. * * @param clazz the type * @return this type definition */ JClassDef _extends(Class clazz); /** * Add one or more {@code implements} type(s) to this type. * * @param name the type name * @return this type definition */ JClassDef _implements(String... name); /** * Add one or more {@code implements} type(s) to this type. * * @param type the type * @return this type definition */ JClassDef _implements(JType... type); /** * Add one or more {@code implements} type(s) to this type. * * @param clazz the type * @return this type definition */ JClassDef _implements(Class... clazz); /** * Get the erased type corresponding to this type definition. * * @return the erased type */ JType erasedType(); /** * Get a generic type for this type definition, where the type arguments are the same as the type parameters of this * type (as defined at the time this method is called). * * @return the generic type */ JType genericType(); /** * Add an enum constant. If the class being defined is not an enum, an exception is thrown. * * @param name the constant name * @return the call for enum construction */ JEnumConstant _enum(String name); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassDefSection.java000066400000000000000000000122251250006154200271070ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A section of a class definition, to which members, comments, and blank lines may be added. * * @author David M. Lloyd */ public interface JClassDefSection extends JCommentable { /** * Create a section at this point, into which additional items may be added. * * @return the new section to add */ JClassDefSection section(); /** * Add a blank line at this point of the type. * * @return this type definition */ JClassDefSection blankLine(); /** * Add a "raw" initialization block to this type definition. * * @return the initialization block */ JBlock init(); /** * Add a static initialization block to this type definition. * * @return the static initialization block */ JBlock staticInit(); /** * Add a field to this type. * * @param mods the modifiers * @param type the field type * @param name the field name * @return the field declaration */ JVarDeclaration field(int mods, JType type, String name); /** * Add a field to this type. * * @param mods the modifiers * @param type the field type * @param name the field name * @param init the field assigned value * @return the field declaration */ JVarDeclaration field(int mods, JType type, String name, JExpr init); /** * Add a field to this type. * * @param mods the modifiers * @param type the field type * @param name the field name * @return the field declaration */ JVarDeclaration field(int mods, Class type, String name); /** * Add a field to this type. * * @param mods the modifiers * @param type the field type * @param name the field name * @param init the field assigned value * @return the field declaration */ JVarDeclaration field(int mods, Class type, String name, JExpr init); /** * Add a field to this type. * * @param mods the modifiers * @param type the field type * @param name the field name * @return the field declaration */ JVarDeclaration field(int mods, String type, String name); /** * Add a field to this type. * * @param mods the modifiers * @param type the field type * @param name the field name * @param init the field assigned value * @return the field declaration */ JVarDeclaration field(int mods, String type, String name, JExpr init); /** * Add a method to this type. * * @param mods the modifiers * @param returnType the method return type * @param name the method name * @return the method definition */ JMethodDef method(int mods, JType returnType, String name); /** * Add a method to this type. * * @param mods the modifiers * @param returnType the method return type * @param name the method name * @return the method definition */ JMethodDef method(int mods, Class returnType, String name); /** * Add a method to this type. * * @param mods the modifiers * @param returnType the method return type * @param name the method name * @return the method definition */ JMethodDef method(int mods, String returnType, String name); /** * Add a constructor to this type. * * @param mods the modifiers * @return the constructor definition */ JMethodDef constructor(int mods); /** * Add a nested class to this type. * * @param mods the class modifiers * @param name the class name * @return the nested class */ JClassDef _class(int mods, String name); /** * Add a nested enum to this type. * * @param mods the enum modifiers * @param name the enum name * @return the nested enum */ JClassDef _enum(int mods, String name); /** * Add a nested interface to this type. * * @param mods the interface modifiers * @param name the interface name * @return the nested interface */ JClassDef _interface(int mods, String name); /** * Add a nested annotation interface to this type. * * @param mods the annotation interface modifiers * @param name the annotation interface name * @return the nested annotation interface */ JClassDef annotationInterface(int mods, String name); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassDefSectionImpl.java000066400000000000000000000104001250006154200277220ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; /** * @author David M. Lloyd */ class JClassDefSectionImpl implements JClassDefSection, ClassContent { private final Sectionable sectionable; private final ArrayList content = new ArrayList<>(); JClassDefSectionImpl(final Sectionable sectionable) { this.sectionable = sectionable; } C add(C item) { content.add(item); return item; } public JClassDefSection section() { return add(new JClassDefSectionImpl(sectionable)); } public JClassDefSection blankLine() { add(BlankLine.getInstance()); return this; } public JBlock init() { return sectionable.init(content); } public JBlock staticInit() { return sectionable.staticInit(content); } public JVarDeclaration field(final int mods, final JType type, final String name) { return sectionable.field(content, mods, type, name, null); } public JVarDeclaration field(final int mods, final JType type, final String name, final JExpr init) { return sectionable.field(content, mods, type, name, init); } public JVarDeclaration field(final int mods, final Class type, final String name) { return field(mods, JTypes.typeOf(type), name); } public JVarDeclaration field(final int mods, final Class type, final String name, final JExpr init) { return field(mods, JTypes.typeOf(type), name, init); } public JVarDeclaration field(final int mods, final String type, final String name) { return field(mods, JTypes.typeNamed(type), name); } public JVarDeclaration field(final int mods, final String type, final String name, final JExpr init) { return field(mods, JTypes.typeNamed(type), name, init); } public JMethodDef method(final int mods, final JType returnType, final String name) { return sectionable.method(content, mods, returnType, name); } public JMethodDef method(final int mods, final Class returnType, final String name) { return method(mods, JTypes.typeOf(returnType), name); } public JMethodDef method(final int mods, final String returnType, final String name) { return method(mods, JTypes.typeNamed(returnType), name); } public JMethodDef constructor(final int mods) { return sectionable.constructor(content, mods); } public JClassDef _class(final int mods, final String name) { return sectionable._class(content, mods, name); } public JClassDef _enum(final int mods, final String name) { return sectionable._enum(content, mods, name); } public JClassDef _interface(final int mods, final String name) { return sectionable._interface(content, mods, name); } public JClassDef annotationInterface(final int mods, final String name) { return sectionable.annotationInterface(content, mods, name); } public JComment lineComment() { return add(new LineJComment()); } public JComment blockComment() { return add(new BlockJComment()); } public void write(final SourceFileWriter writer) throws IOException { Iterator iterator = content.iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.nl(); iterator.next().write(writer); } } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassItem.java000066400000000000000000000207521250006154200257660ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2015 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static java.lang.Integer.signum; import java.util.Comparator; import java.util.EnumSet; /** * An item contained within a class. * * @author David M. Lloyd */ public interface JClassItem { /** * Get the kind of item. * * @return the item kind */ Kind getItemKind(); /** * Get the modifiers of this item. * * @return the modifiers * @see JMod */ int getModifiers(); /** * Determine whether this item has all of the modifiers specified by the given bitwise-OR-joined argument. * * @param mods the modifier(s) * @return {@code true} if all of the modifiers are present, {@code false} otherwise */ boolean hasAllModifiers(int mods); /** * Determine whether this item has any of the modifiers specified by the given bitwise-OR-joined argument. * * @param mods the modifier(s) * @return {@code true} if any if the modifiers are present, {@code false} otherwise */ boolean hasAnyModifier(int mods); /** * Get the name of this element, if there is one. * * @return the name, or {@code null} if there is none */ String getName(); Comparator SMART_NAME_SORT = new Comparator() { private int rankOf(JClassItem item) { return item.getItemKind().ordinal(); } public int compare(final JClassItem o1, final JClassItem o2) { int r1, r2; r1 = rankOf(o1); r2 = rankOf(o2); if (r1 != r2) return signum(r2 - r1); String n1, n2; n1 = o1.getName(); n2 = o2.getName(); if (o1.getItemKind() == Kind.METHOD) { boolean s1 = o1.hasAllModifiers(JMod.STATIC); boolean s2 = o2.hasAllModifiers(JMod.STATIC); if (s1 != s2) { return s1 ? -1 : 1; } String p1, p2; int v1, v2; boolean f1 = true, f2 = true; if (n1.startsWith("get")) { v1 = 0; p1 = n1.substring(3); } else if (n1.startsWith("is")) { v1 = 0; p1 = n1.substring(2); } else if (n1.startsWith("set")) { v1 = 1; p1 = n1.substring(3); } else { f1 = false; v1 = 0; p1 = n1; } if (n2.startsWith("get")) { v2 = 0; p2 = n2.substring(3); } else if (n2.startsWith("is")) { v2 = 0; p2 = n2.substring(2); } else if (n2.startsWith("set")) { v2 = 2; p2 = n2.substring(3); } else { f2 = false; v2 = 0; p2 = n2; } if (f1 != f2) { return f1 ? -1 : 1; } int m = p1.compareTo(p2); return m != 0 ? m : signum(v2 - v1); } else if (o1.getItemKind() == Kind.FIELD) { boolean s1 = o1.hasAllModifiers(JMod.STATIC); boolean s2 = o2.hasAllModifiers(JMod.STATIC); return s1 != s2 ? s1 ? -1 : 1 : n1.compareTo(n2); } if (n1 != null && n2 != null) { return n1.compareTo(n2); } return 0; } }; /** * The kind of class item. */ enum Kind { /** * A line comment. The item will implement {@link JComment}. */ LINE_COMMENT, /** * A block comment. The item will implement {@link JComment}. */ BLOCK_COMMENT, /** * A blank line. */ BLANK_LINE, /** * An enum constant. The item will implement {@link JEnumConstant}. */ ENUM_CONSTANT, /** * A field. The item will implement {@link JVarDeclaration}. */ FIELD, /** * An initialization block. The item will implement {@link JBlock}. The block may be static; examine * the modifiers to make this determination. */ INIT_BLOCK, /** * A constructor. The item will implement {@link JMethodDef}. */ CONSTRUCTOR, /** * A constructor. The item will implement {@link JMethodDef}. */ METHOD, /** * A nested enum. The item will implement {@link JClassDef}. */ ENUM, /** * A nested annotation interface. The item will implement {@link JClassDef}. */ ANNOTATION_INTERFACE, /** * A nested interface. The item will implement {@link JClassDef}. */ INTERFACE, /** * A nested class. The item will implement {@link JClassDef}. */ CLASS, ; private static final int fullSize = Kind.values().length; /** * Determine whether the given set is fully populated (or "full"), meaning it contains all possible values. * * @param set the set * * @return {@code true} if the set is full, {@code false} otherwise */ public static boolean isFull(final EnumSet set) { return set != null && set.size() == fullSize; } /** * Determine whether this instance is equal to one of the given instances. * * @param v1 the first instance * * @return {@code true} if one of the instances matches this one, {@code false} otherwise */ public boolean in(final Kind v1) { return this == v1; } /** * Determine whether this instance is equal to one of the given instances. * * @param v1 the first instance * @param v2 the second instance * * @return {@code true} if one of the instances matches this one, {@code false} otherwise */ public boolean in(final Kind v1, final Kind v2) { return this == v1 || this == v2; } /** * Determine whether this instance is equal to one of the given instances. * * @param v1 the first instance * @param v2 the second instance * @param v3 the third instance * * @return {@code true} if one of the instances matches this one, {@code false} otherwise */ public boolean in(final Kind v1, final Kind v2, final Kind v3) { return this == v1 || this == v2 || this == v3; } /** * Determine whether this instance is equal to one of the given instances. * * @param v1 the first instance * @param v2 the second instance * @param v3 the third instance * @param v4 the fourth instance * * @return {@code true} if one of the instances matches this one, {@code false} otherwise */ public boolean in(final Kind v1, final Kind v2, final Kind v3, final Kind v4) { return this == v1 || this == v2 || this == v3 || this == v4; } /** * Determine whether this instance is equal to one of the given instances. * * @param values the possible values * * @return {@code true} if one of the instances matches this one, {@code false} otherwise */ public boolean in(final Kind... values) { if (values != null) for (Kind value : values) { if (this == value) return true; } return false; } } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JComment.java000066400000000000000000000111271250006154200255000ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A source comment or tag body. * * @author David M. Lloyd */ public interface JComment { /** * Add some text to the end of this comment. No formatting or line breaks are inserted. * * @param text the text to add * @return this comment */ JComment text(String text); /** * Add a non-trailing space. If no content follows, the space will be omitted. * * @return this comment */ JComment sp(); /** * Add a newline. * * @return this comment */ JComment nl(); /** * Add a type name to the end of this comment. If the type is imported, it will emit as a simple name, otherwise * it will emit as a qualified name. * * @param type the type name to add * @return this comment */ JComment typeName(JType type); /** * Add a comment sub-block at this location. The block has no visual representation but allows text to be inserted * at the point of the block even after more content was appended after it. * * @return the comment sub-block */ JComment block(); /** * Add an inline doc tag with simple content. * * @param tag the tag name (without the leading {@code @} sign) * @param body the complete tag body * @return this comment */ JComment inlineDocTag(String tag, String body); /** * Add an inline doc tag. * * @param tag the tag name (without the leading {@code @} sign) * @return the body of the doc tag */ JComment inlineDocTag(String tag); /** * Add an inline code tag. * * @return the code tag content */ JComment code(); /** * Add the {@code {@docRoot}} tag at this position. * * @return this comment */ JComment docRoot(); /** * Add an inline {@code @link} to a type. * * @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font * @param targetType the target type to link to * @return the body of the link tag */ JComment linkType(boolean plain, JType targetType); /** * Add an inline {@code @link} to a field of a type. * * @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font * @param targetType the target type to link to * @param targetField the target field to link to * @return the body of the link tag */ JComment linkField(boolean plain, JType targetType, String targetField); /** * Add an inline {@code @link} to a constructor. * * @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font * @param targetType the target type to link to * @param targetConstructorArgumentTypes the argument types of the constructor to link to * @return the body of the link tag */ JComment linkConstructor(boolean plain, JType targetType, JType... targetConstructorArgumentTypes); /** * Add an inline {@code @link} to a method. * * @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font * @param targetType the target type to link to * @param targetMethod the name of the method to link to * @param targetMethodArgumentTypes the argument types of the method to link to * @return the body of the link tag */ JComment linkMethod(boolean plain, JType targetType, String targetMethod, JType... targetMethodArgumentTypes); /** * Add an inline {@code @link} to a method. * * @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font * @param methodDef the method to link to * @return the body of the link tag */ JComment linkMethod(boolean plain, JMethodDef methodDef); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JCommentable.java000066400000000000000000000021751250006154200263270ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A program element which can have comments attached to it. * * @author David M. Lloyd */ public interface JCommentable { /** * Add a line comment. * * @return the line comment body */ JComment lineComment(); /** * Add a block comment. * * @return the block comment body */ JComment blockComment(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JDeparser.java000066400000000000000000000034341250006154200256450ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * The main entry point for this library. Use this class to construct a collection of source files which can be * generated and stored. * * @author David M. Lloyd */ public final class JDeparser { private JDeparser() { } /** * Create a new source generation collection. * * @param filer the filer to use to store generated sources * @param format the formatting preferences to use for these sources * @return the source collection */ public static JSources createSources(final JFiler filer, final FormatPreferences format) { return new ImplJSources(filer, format); } /** * Drop all thread-local caches. This can be done to save memory or avoid GC problems after source generation * has been completed. Call within a {@code finally} block to ensure that resources are released regardless of * the outcome of intervening operations. */ public static void dropCaches() { JExprs.cache.remove(); JTypes.cache.remove(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JDocComment.java000066400000000000000000000045151250006154200261310ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A JavaDoc comment. * * @author David M. Lloyd */ public interface JDocComment extends JHtmlComment { /** {@inheritDoc} */ JDocComment text(String text); /** {@inheritDoc} */ JDocComment block(); /** {@inheritDoc} */ JDocComment inlineDocTag(String tag, String body); /** {@inheritDoc} */ JComment inlineDocTag(String tag); /** {@inheritDoc} */ JDocComment sp(); /** {@inheritDoc} */ JDocComment nl(); /** {@inheritDoc} */ JDocComment p(); /** {@inheritDoc} */ JDocComment br(); /** {@inheritDoc} */ JDocComment typeName(JType type); /** {@inheritDoc} */ JDocComment docRoot(); /** {@inheritDoc} */ JDocComment value(JType type, String fieldName); /** * Add a block tag. * * @param tag the tag name * @return the block tag comment block */ JHtmlComment docTag(String tag); /** * Add a block tag. * * @param tag the tag name * @param firstWord the tag body first word * @return the block tag comment block */ JHtmlComment docTag(String tag, String firstWord); /** * Add a {@code @return} tag. * * @return the tag body */ JHtmlComment _return(); /** * Add a {@code @throws} tag. * * @param exceptionType the type of exception * @return the tag body */ JHtmlComment _throws(JType exceptionType); /** * Add a {@code @param} tag. * * @param name the parameter name * @return the tag body */ JHtmlComment param(String name); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JDocCommentable.java000066400000000000000000000023251250006154200267520ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A program element which can have a documentation tag associated with it. * * @author David M. Lloyd */ public interface JDocCommentable extends JCommentable { /** * Get or create the doc comment for this element. * * @return the doc comment body */ JDocComment docComment(); /** * Mark this program element as deprecated. * * @return the deprecation tag body */ JComment deprecated(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JEnumConstant.java000066400000000000000000000022001250006154200265040ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * An enum constant definition. * * @author David M. Lloyd */ public interface JEnumConstant extends JSimpleArgs, JAnnotatable, JDocCommentable { /** {@inheritDoc} */ JEnumConstant arg(JExpr expr); /** * Add an implementation body to this enum constant. * * @return the implementation class definition */ JClassDef body(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JExpr.java000066400000000000000000000250641250006154200250210ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import static org.jboss.jdeparser.Tokens.*; /** * A modelled expression. Constructed complex expressions are reusable (their contents will be copied at every * use site). The minimum number of parentheses will automatically be added as needed. For convenience methods to * construct common expressions, also see the {@link JExprs} class. * * @author David M. Lloyd */ public interface JExpr { /** * The constant expression for {@code false}. */ JExpr FALSE = new BooleanJExpr(false); /** * The constant expression for {@code true}. */ JExpr TRUE = new BooleanJExpr(true); /** * The constant expression for {@code this}. */ JExpr THIS = new KeywordJExpr($KW.THIS); /** * The constant expression for {@code null}. */ JExpr NULL = new KeywordJExpr($KW.NULL); /** * The constant expression for the integer zero. */ JExpr ZERO = new IntegerJExpr(0, 10); /** * The constant expression for the integer one. */ JExpr ONE = new IntegerJExpr(1, 10); // arithmetic /** * Combine this expression with another using the binary {@code +} operator. * * @param e1 the other expression * @return the combined expression */ JExpr plus(JExpr e1); /** * Combine this expression with another using the binary {@code -} operator. * * @param e1 the other expression * @return the combined expression */ JExpr minus(JExpr e1); /** * Combine this expression with another using the binary {@code *} operator. * * @param e1 the other expression * @return the combined expression */ JExpr times(JExpr e1); /** * Combine this expression with another using the binary {@code /} operator. * * @param e1 the other expression * @return the combined expression */ JExpr div(JExpr e1); /** * Combine this expression with another using the binary {@code %} operator. * * @param e1 the other expression * @return the combined expression */ JExpr mod(JExpr e1); /** * Negate this expression using the unary {@code -} operator. * * @return the new expression */ JExpr neg(); // bitwise /** * Combine this expression with another using the binary {@code &} operator. * * @param e1 the other expression * @return the combined expression */ JExpr band(JExpr e1); /** * Combine this expression with another using the binary {@code |} operator. * * @param e1 the other expression * @return the combined expression */ JExpr bor(JExpr e1); /** * Combine this expression with another using the binary {@code ^} operator. * * @param e1 the other expression * @return the combined expression */ JExpr bxor(JExpr e1); /** * Combine this expression with another using the binary {@code >>} operator. * * @param e1 the other expression * @return the combined expression */ JExpr shr(JExpr e1); /** * Combine this expression with another using the binary {@code >>>} operator. * * @param e1 the other expression * @return the combined expression */ JExpr lshr(JExpr e1); /** * Combine this expression with another using the binary {@code <<} operator. * * @param e1 the other expression * @return the combined expression */ JExpr shl(JExpr e1); /** * Invert this expression using the unary {@code ~} operator. * * @return the new expression */ JExpr comp(); // logic /** * Combine this expression with another using the binary {@code &&} operator. * * @param e1 the other expression * @return the combined expression */ JExpr and(JExpr e1); /** * Combine this expression with another using the binary {@code ||} operator. * * @param e1 the other expression * @return the combined expression */ JExpr or(JExpr e1); /** * Invert this expression using the unary {@code !} operator. * * @return the new expression */ JExpr not(); // equality /** * Combine this expression with another using the binary {@code ==} operator. * * @param e1 the other expression * @return the combined expression */ JExpr eq(JExpr e1); /** * Combine this expression with another using the binary {@code !=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr ne(JExpr e1); // range /** * Combine this expression with another using the binary {@code <} operator. * * @param e1 the other expression * @return the combined expression */ JExpr lt(JExpr e1); /** * Combine this expression with another using the binary {@code >} operator. * * @param e1 the other expression * @return the combined expression */ JExpr gt(JExpr e1); /** * Combine this expression with another using the binary {@code <=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr le(JExpr e1); /** * Combine this expression with another using the binary {@code >=} operator. * * @param e1 the other expression * @return the combined expression */ JExpr ge(JExpr e1); // ternary /** * Combine this expression with two others using the ternary {@code ? :} operator. * * @param ifTrue the {@code true} expression branch * @param ifFalse the {@code false} expression branch * @return the combined expression */ JExpr cond(JExpr ifTrue, JExpr ifFalse); // paren /** * Explicitly wrap this expression in parentheses. * * @return the wrapped expression */ JExpr paren(); // instance /** * Get a type-testing expression using the {@code instanceof} operator. * * @param type the type to test * @return the expression */ JExpr _instanceof(String type); /** * Get a type-testing expression using the {@code instanceof} operator. * * @param type the type to test * @return the expression */ JExpr _instanceof(JType type); /** * Get a type-testing expression using the {@code instanceof} operator. * * @param type the type to test * @return the expression */ JExpr _instanceof(Class type); // cast /** * Get an expression which is a cast of this expression to the given type. * * @param type the type to cast to * @return the expression */ JExpr cast(String type); /** * Get an expression which is a cast of this expression to the given type. * * @param type the type to cast to * @return the expression */ JExpr cast(JType type); /** * Get an expression which is a cast of this expression to the given type. * * @param type the type to cast to * @return the expression */ JExpr cast(Class type); // invoke /** * Call the given method on this expression. * * @param name the method name * @return the method call */ JCall call(String name); // construct inner /** * Get an expression to construct a new inner class instance of this instance expression. * * @param type the inner class type to construct * @return the {@code new} constructor call */ JCall _new(String type); /** * Get an expression to construct a new inner class instance of this instance expression. * * @param type the inner class type to construct * @return the {@code new} constructor call */ JCall _new(JType type); /** * Get an expression to construct a new inner class instance of this instance expression. * * @param type the inner class type to construct * @return the {@code new} constructor call */ JCall _new(Class type); /** * Construct a new anonymous subclass of the given type, which must be an inner class of the type of this * expression. * * @param type the type of object to construct * @return the anonymous subclass definition */ JAnonymousClassDef _newAnon(String type); /** * Construct a new anonymous subclass of the given type, which must be an inner class of the type of this * expression. * * @param type the type of object to construct * @return the anonymous subclass definition */ JAnonymousClassDef _newAnon(JType type); /** * Construct a new anonymous subclass of the given type, which must be an inner class of the type of this * expression. * * @param type the type of object to construct * @return the anonymous subclass definition */ JAnonymousClassDef _newAnon(Class type); // field /** * Get a field of this object instance. * * @param name the field name * @return the expression */ JAssignableExpr field(String name); /** * Get a field of this object instance (shorthand for {@link #field(String)}. * * @param name the field name * @return the expression */ JAssignableExpr $v(String name); // array /** * Get an element of this array expression. * * @param idx the array index expression * @return the array dereference expression */ JAssignableExpr idx(JExpr idx); /** * Get an element of this array expression. * * @param idx the array index * @return the array dereference expression */ JExpr idx(int idx); /** * Get the {@code length} expression of this array expression. * * @return the {@code length} expression */ JExpr length(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JExprs.java000066400000000000000000000230731250006154200252020ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.util.LinkedHashMap; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; /** * The factory for generating simple expressions. */ public final class JExprs { private JExprs() {} /** * Generate an {@code int} value in decimal base. * * @param val the value * @return the value expression */ public static JExpr decimal(int val) { return new IntegerJExpr(val, 10); } /** * Generate a {@code long} value in decimal base. * * @param val the value * @return the value expression */ public static JExpr decimal(long val) { return new LongJExpr(val, 10); } /** * Generate a {@code float} value in decimal base. * * @param val the value * @return the value expression */ public static JExpr decimal(float val) { return new DecimalFloatJExpr(val); } /** * Generate a {@code double} value in decimal base. * * @param val the value * @return the value expression */ public static JExpr decimal(double val) { return new DecimalDoubleJExpr(val); } /** * Generate an {@code int} value in hexadecimal base. * * @param val the value * @return the value expression */ public static JExpr hex(int val) { return new IntegerJExpr(val, 16); } /** * Generate a {@code long} value in hexadecimal base. * * @param val the value * @return the value expression */ public static JExpr hex(long val) { return new LongJExpr(val, 16); } /** * Generate a {@code float} value in hexadecimal base. * * @param val the value * @return the value expression */ public static JExpr hex(float val) { return new HexFloatJExpr(val); } /** * Generate a {@code double} value in hexadecimal base. * * @param val the value * @return the value expression */ public static JExpr hex(double val) { return new HexDoubleJExpr(val); } /** * Generate an {@code int} value in binary base. * * @param val the value * @return the value expression */ public static JExpr binary(int val) { return new IntegerJExpr(val, 2); } /** * Generate a {@code long} value in binary base. * * @param val the value * @return the value expression */ public static JExpr binary(long val) { return new LongJExpr(val, 2); } /** * Generate a string constant value. * * @param string the string * @return the string expression */ public static JExpr str(String string) { return new StringJExpr(string); } /** * Generate a {@code char} value constant. * * @param val the value * @return the value expression */ public static JExpr ch(int val) { return new CharJExpr(val); } /** * Generate a method call expression to the given element. * * @param element the method to call * @return the method call */ public static JCall call(final ExecutableElement element) { final ElementKind kind = element.getKind(); if (kind == ElementKind.METHOD) { final String name = element.getSimpleName().toString(); return call(name); } throw new IllegalArgumentException("Unsupported element for call: " + element); } /** * Generate a method call expression to the given method name. * * @param name the name of the method to call * @return the method call */ public static JCall call(String name) { return new DirectJCall(name); } /** * Generate a method call expression to a method on the given static type. * * @param type the type to call against * @param name the name of the method to call * @return the method call */ public static JCall callStatic(final String type, final String name) { return callStatic(JTypes.typeNamed(type), name); } /** * Generate a method call expression to a method on the given static type. * * @param type the type to call against * @param name the name of the method to call * @return the method call */ public static JCall callStatic(final JType type, final String name) { return new StaticJCall(type, name); } /** * Generate a method call expression to a method on the given static type. * * @param type the type to call against * @param name the name of the method to call * @return the method call */ public static JCall callStatic(final Class type, final String name) { return callStatic(JTypes.typeOf(type), name); } /** * Return a name expression. This method is a shortcut for {@link #name(String)}. * * @param name the name * @return the expression */ public static JAssignableExpr $v(String name) { return name(name); } /** * Return a name expression from an annotation processor parameter declaration. * * @param paramDeclaration the method parameter * @return the expression */ public static JAssignableExpr $v(JParamDeclaration paramDeclaration) { return name(paramDeclaration.name()); } /** * Return a name expression from an annotation processor variable declaration. * * @param varDeclaration the variable declaration * @return the expression */ public static JAssignableExpr $v(JVarDeclaration varDeclaration) { return name(varDeclaration.name()); } static final ThreadLocal> cache = new CachingThreadLocal<>(); /** * Return a name expression. * * @param name the name * @return the expression */ public static JAssignableExpr name(String name) { final LinkedHashMap map = cache.get(); JAssignableExpr ret = map.get(name); if (ret == null) { map.put(name, ret = new NameJExpr(name)); } return ret; } /** * Return a name expression from an annotation processor parameter declaration. * * @param paramDeclaration the method parameter * @return the expression */ public static JAssignableExpr name(JParamDeclaration paramDeclaration) { return name(paramDeclaration.name()); } /** * Return a name expression from an annotation processor variable declaration. * * @param varDeclaration the variable declaration * @return the expression */ public static JAssignableExpr name(JVarDeclaration varDeclaration) { return name(varDeclaration.name()); } /** * Return a new array expression. The array is initially empty. * * @return an array expression */ public static JArrayExpr array() { return new PlainJArrayExpr(); } /** * Return a new array expression. The array is initially filled with the given members. * * @param members the initial members of the array * @return an array expression */ public static JArrayExpr array(JExpr... members) { return new PlainJArrayExpr(members); } /** * Return a new array expression. The array is initially filled with the given strings. * * @param members the initial members of the array * @return an array expression */ public static JArrayExpr array(String... members) { final JExpr[] exprs = new JExpr[members.length]; for (int i = 0; i < members.length; i++) { exprs[i] = str(members[i]); } return new PlainJArrayExpr(exprs); } /** * Return a new array expression. The array is initially filled with the given integers. * * @param members the initial members of the array * @return an array expression */ public static JArrayExpr array(int... members) { final JExpr[] exprs = new JExpr[members.length]; for (int i = 0; i < members.length; i++) { exprs[i] = decimal(members[i]); } return new PlainJArrayExpr(exprs); } /** * Return a new array expression. The array is initially filled with the given integers. * * @param members the initial members of the array * @return an array expression */ public static JArrayExpr array(long... members) { final JExpr[] exprs = new JExpr[members.length]; for (int i = 0; i < members.length; i++) { exprs[i] = decimal(members[i]); } return new PlainJArrayExpr(exprs); } /** * Return a lambda expression. The expression is initially empty. * * @return the lambda expression */ public static JLambda lambda() { return new JLambdaImpl(); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JFiler.java000066400000000000000000000074421250006154200251440ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import javax.annotation.processing.Filer; /** * A file manager for writing out source files. * * @author David M. Lloyd */ public abstract class JFiler { /** * Get an instance which uses an underlying {@link javax.annotation.processing.Filer}. * * @param filer the annotation processing filer * @return the JDeparser filer */ public static JFiler newInstance(final Filer filer) { return new JFiler() { public OutputStream openStream(final String packageName, final String fileName) throws IOException { // Create the FQCN final StringBuilder sb = new StringBuilder(packageName); if (sb.charAt(sb.length() -1) != '.') { sb.append('.'); } sb.append(fileName); return filer.createSourceFile(sb).openOutputStream(); } }; } /** * Get an instance which writes to the filesystem. * * @param target the target source path * @return the JDeparser filer */ public static JFiler newInstance(final File target) { return new JFiler() { public OutputStream openStream(final String packageName, final String fileName) throws IOException { final File dir = new File(target, packageName.replace('.', File.separatorChar)); dir.mkdirs(); return new FileOutputStream(new File(dir, fileName + ".java")); } }; } /** * Construct a new instance. */ protected JFiler() { } private String encoding = "utf-8"; /** * Get the file encoding to use. * * @return the file encoding */ public String getEncoding() { return encoding; } /** * Set the file encoding to use. * * @param encoding the file encoding */ public void setEncoding(final String encoding) { this.encoding = encoding; } /** * Open an output stream for writing the given file. * * @param packageName the package name * @param fileName the file name * @return the output stream * @throws IOException if an error occurs during write */ public abstract OutputStream openStream(String packageName, String fileName) throws IOException; /** * Open a writer for the given file. The default implementation calls {@link #openStream(String, String)} and wraps * the result with an {@link OutputStreamWriter} using the configured file encoding. * * @param packageName the package name * @param fileName the file name * @return the writer * @throws IOException if an error occurs during write */ public Writer openWriter(String packageName, String fileName) throws IOException { return new OutputStreamWriter(openStream(packageName, fileName), encoding); } } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JFor.java000066400000000000000000000050011250006154200246160ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A {@code for} loop. * * @author David M. Lloyd */ public interface JFor extends JBlock { /** * Add a loop initializer. * * @param mods the modifiers for the initializer variable declaration * @param type the type of the initializer variables * @param name the name of the first initializer variable * @param value the initial value for the first initializer variable * @return the initializer variable declaration */ JVarDeclaration init(int mods, String type, String name, JExpr value); /** * Add a loop initializer. * * @param mods the modifiers for the initializer variable declaration * @param type the type of the initializer variables * @param name the name of the first initializer variable * @param value the initial value for the first initializer variable * @return the initializer variable declaration */ JVarDeclaration init(int mods, JType type, String name, JExpr value); /** * Add a loop initializer. * * @param mods the modifiers for the initializer variable declaration * @param type the type of the initializer variables * @param name the name of the first initializer variable * @param value the initial value for the first initializer variable * @return the initializer variable declaration */ JVarDeclaration init(int mods, Class type, String name, JExpr value); /** * Add a test expression. * * @param expr the test expression * @return this {@code for} loop */ JFor test(JExpr expr); /** * Add an update expression. * * @param updateExpr the update expression * @return this {@code for} loop */ JFor update(JExpr updateExpr); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JGenericDef.java000066400000000000000000000023311250006154200260660ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A generic type or method definition. * * @author David M. Lloyd */ public interface JGenericDef { /** * Define a type parameter. * * @param name the type parameter name * @return the type parameter definition */ JTypeParamDef typeParam(String name); /** * Get all the type parameters defined at the time of invocation. * * @return the type parameters */ JTypeParamDef[] typeParams(); } jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JHtmlComment.java000066400000000000000000000046161250006154200263320ustar00rootroot00000000000000/* * JBoss, Home of Professional Open Source. * Copyright 2014 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.jdeparser; /** * A comment that supports HTML content. * * @author David M. Lloyd */ public interface JHtmlComment extends JComment { /** {@inheritDoc} */ JHtmlComment block(); /** {@inheritDoc} */ JHtmlComment text(String text); /** {@inheritDoc} */ JHtmlComment inlineDocTag(String tag, String body); /** {@inheritDoc} */ JHtmlComment sp(); /** {@inheritDoc} */ JHtmlComment nl(); /** {@inheritDoc} */ JHtmlComment typeName(JType type); /** {@inheritDoc} */ JHtmlComment docRoot(); /** * Add a paragraph separator. * * @return this HTML comment */ JHtmlComment p(); /** * Add a line separator. * * @return this HTML comment */ JHtmlComment br(); /** * Add a {@code @value} inline tag. * * @param type the value type * @param fieldName the value field name * @return this HTML comment */ JHtmlComment value(JType type, String fieldName); /** * Add an HTML link ({@code <a>} tag). * * @param url the URL to link to * @return the link tag body */ JHtmlTag htmlLink(String url); /** * Add an HTML tag. The given tag should be a valid HTML 4 or 5 tag. * * @param tag the HTML tag * @param newLine {@code true} to add a newline after the opening tag and before the closing tag * @return the tag body */ JHtmlTag htmlTag(String tag, boolean newLine); /** * Add an inline {@code @code} tag within a {@code
} block.
     *
     * @return the preformatted code block content
     */
    JComment preformattedCode();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JHtmlTag.java000066400000000000000000000016741250006154200254440ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * @author David M. Lloyd
 */
public interface JHtmlTag extends JHtmlComment {
    JHtmlTag attribute(String name);

    JHtmlTag attribute(String name, String value);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JIf.java000066400000000000000000000023221250006154200244310ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * An {@code if} statement.
 *
 * @author David M. Lloyd
 */
public interface JIf extends JBlock {

    /**
     * Get the {@code else} condition block.
     *
     * @return the {@code else} block
     */
    JBlock _else();

    /**
     * Add an {@code if} statement to the {@code else} block.
     *
     * @param cond the subsequent {@code if} condition
     * @return the subsequent {@code if} statement
     */
    JIf elseIf(JExpr cond);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JLabel.java000066400000000000000000000021101250006154200251050ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A source label.  Labels may be defined when created, or defined later on.
 *
 * @author David M. Lloyd
 */
public interface JLabel {

    /**
     * Get the label name.  If the label is anonymous, or not defined yet, an exception is thrown.
     *
     * @return the label name
     */
    String name();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JLambda.java000066400000000000000000000042461250006154200252620ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2015 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A Java 8 lambda.
 *
 * @author David M. Lloyd
 */
public interface JLambda extends JExpr {

    /**
     * Add a declared-type parameter to this lambda.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return this lambda
     */
    JLambda param(JType type, String name);

    /**
     * Add a declared-type parameter to this lambda.
     *
     * @param typeName the parameter type name
     * @param name the parameter name
     * @return this lambda
     */
    JLambda param(String typeName, String name);

    /**
     * Add a declared-type parameter to this lambda.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return this lambda
     */
    JLambda param(Class type, String name);

    /**
     * Add an inferred-type parameter to this lambda.  If one parameter is inferred, all will be, despite any declared
     * parameter type.
     *
     * @param name the parameter name
     * @return this lambda
     */
    JLambda param(String name);

    /**
     * Get the lambda body as a block.  Clears any expression body.
     *
     * @return the lambda body
     */
    JBlock body();

    /**
     * Set the lambda body as an expression.  Clears any block body or previously set expression body.
     *
     * @param expr the expression body of this lambda
     * @return this lambda
     */
    JLambda body(JExpr expr);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JLambdaImpl.java000066400000000000000000000100221250006154200260710ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2015 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author David M. Lloyd
 */
class JLambdaImpl extends AbstractJExpr implements JLambda {
    private BasicJBlock blockBody;
    private AbstractJExpr exprBody;
    private boolean hasInferred;
    private ArrayList params;

    JLambdaImpl() {
        super(Prec.METHOD_CALL);
    }

    public JLambda param(final JType type, final String name) {
        if (name != null) {
            if (type == null) {
                hasInferred = true;
            }
            if (params == null) {
                params = new ArrayList<>();
            }
            params.add(new Param(type, name));
        }
        return this;
    }

    public JLambda param(final String typeName, final String name) {
        return param(JTypes.typeNamed(typeName), name);
    }

    public JLambda param(final Class type, final String name) {
        return param(JTypes.typeOf(type), name);
    }

    public JLambda param(final String name) {
        return param((JType) null, name);
    }

    public JBlock body() {
        exprBody = null;
        if (blockBody == null) {
            blockBody = new BasicJBlock(null, JBlock.Braces.REQUIRED);
        }
        return blockBody;
    }

    public JLambda body(JExpr expression) {
        blockBody = null;
        exprBody = AbstractJExpr.of(expression);
        return this;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(Tokens.$PUNCT.PAREN.OPEN);
        if (params == null) {
            writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL_EMPTY);
        } else {
            writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL);
            final Iterator iterator = params.iterator();
            while (iterator.hasNext()) {
                final Param param = iterator.next();
                if (!hasInferred) {
                    writer.write(param.type);
                    writer.sp();
                }
                writer.writeEscaped(param.name);
                if (iterator.hasNext()) {
                    writer.write(Tokens.$PUNCT.COMMA);
                    writer.write(FormatPreferences.Space.AFTER_COMMA);
                }
            }
            writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL);
        }
        writer.write(Tokens.$PUNCT.PAREN.CLOSE);
        writer.write(FormatPreferences.Space.AROUND_ARROW);
        writer.write(Tokens.$PUNCT.BINOP.ARROW);
        writer.write(FormatPreferences.Space.AROUND_ARROW);
        if (exprBody != null) {
            exprBody.write(writer);
        } else if (blockBody != null) {
            blockBody.write(writer, null);
        } else {
            writer.write(Tokens.$PUNCT.BRACE.OPEN);
            writer.write(FormatPreferences.Space.WITHIN_BRACES_EMPTY);
            writer.write(Tokens.$PUNCT.BRACE.CLOSE);
        }
    }

    static class Param {
        private final JType type;
        private final String name;

        public Param(final JType type, final String name) {
            this.type = type;
            this.name = name;
        }

        public JType getType() {
            return type;
        }

        public String getName() {
            return name;
        }
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JMethodDef.java000066400000000000000000000124551250006154200257420ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A method or constructor definition.
 *
 * @author David M. Lloyd
 */
public interface JMethodDef extends JGenericDef, JAnnotatable, JDocCommentable {

    /**
     * A default method body for a JDK 8+ interface method.
     *
     * @return the method body
     */
    JBlock _default();

    /**
     * A default value for an annotation method.
     *
     * @param expr the value
     * @return this method definition
     */
    JMethodDef _default(JExpr expr);

    /**
     * Get the method body.
     *
     * @return the method body
     */
    JBlock body();

    /**
     * Get the {@code @return} doc comment block.
     *
     * @return the comment block
     */
    JComment returnsDoc();

    /**
     * Add a parameter to this method.
     *
     * @param mods the parameter modifiers
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration param(int mods, JType type, String name);

    /**
     * Add a parameter to this method.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration param(JType type, String name);

    /**
     * Add a parameter to this method.
     *
     * @param mods the parameter modifiers
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration param(int mods, String type, String name);

    /**
     * Add a parameter to this method.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration param(String type, String name);

    /**
     * Add a parameter to this method.
     *
     * @param mods the parameter modifiers
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration param(int mods, Class type, String name);

    /**
     * Add a parameter to this method.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration param(Class type, String name);

    /**
     * Add a vararg parameter to this method.
     *
     * @param mods the parameter modifiers
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration varargParam(int mods, JType type, String name);

    /**
     * Add a vararg parameter to this method.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration varargParam(JType type, String name);

    /**
     * Add a vararg parameter to this method.
     *
     * @param mods the parameter modifiers
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration varargParam(int mods, String type, String name);

    /**
     * Add a vararg parameter to this method.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration varargParam(String type, String name);

    /**
     * Add a vararg parameter to this method.
     *
     * @param mods the parameter modifiers
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration varargParam(int mods, Class type, String name);

    /**
     * Add a vararg parameter to this method.
     *
     * @param type the parameter type
     * @param name the parameter name
     * @return the parameter declaration
     */
    JParamDeclaration varargParam(Class type, String name);

    /**
     * Get the list of parameters defined thus far.
     *
     * @return the parameter list
     */
    JParamDeclaration[] params();

    /**
     * Get a {@code @throws} doc comment block.
     *
     * @param type the exception type
     * @return the doc comment block
     */
    JComment _throws(String type);

    /**
     * Get a {@code @throws} doc comment block.
     *
     * @param type the exception type
     * @return the doc comment block
     */
    JComment _throws(JType type);

    /**
     * Get a {@code @throws} doc comment block.
     *
     * @param type the exception type
     * @return the doc comment block
     */
    JComment _throws(Class type);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JMod.java000066400000000000000000000174221250006154200246210ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static java.lang.Integer.bitCount;
import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;

/**
 * The set of modifiers for types and members.
 */
public final class JMod {

    /**
     * The {@code abstract} modifier.
     */
    public static final int ABSTRACT    = 1 << 0;
    /**
     * The {@code final} modifier.
     */
    public static final int FINAL       = 1 << 1;
    /**
     * The {@code native} modifier.
     */
    public static final int NATIVE      = 1 << 2;
    /**
     * The {@code private} modifier.
     */
    public static final int PRIVATE     = 1 << 3;
    /**
     * The {@code protected} modifier.
     */
    public static final int PROTECTED   = 1 << 4;
    /**
     * The {@code public} modifier.
     */
    public static final int PUBLIC      = 1 << 5;
    /**
     * The {@code static} modifier.
     */
    public static final int STATIC      = 1 << 6;
    /**
     * The {@code strictfp} modifier.
     */
    public static final int STRICTFP    = 1 << 7;
    /**
     * The {@code synchronized} modifier.
     */
    public static final int SYNCHRONIZED= 1 << 8;
    /**
     * The {@code transient} modifier.
     */
    public static final int TRANSIENT   = 1 << 9;
    /**
     * The {@code volatile} modifier.
     */
    public static final int VOLATILE    = 1 << 10;
    /**
     * The {@code default} modifier found in Java 8 and later.
     */
    public static final int DEFAULT     = 1 << 11;

    static final int PRIVATE_BITS       = ~((1 << 12) - 1);

    static final int INNER              = 1 << 30;
    static final int VARARGS            = 1 << 31;

    /**
     * Test to see if exactly one modifier of the given set is present in the test value.
     *
     * @param set the set of modifiers to test against
     * @param test the modifier set to test
     * @return {@code true} if exactly one of {@code set} is present in {@code test}, {@code false} otherwise
     */
    public static boolean oneIsSet(int set, int test) {
        return bitCount(set & test) == 1;
    }

    /**
     * Test to see if all modifiers in the given set are present in the test value.
     *
     * @param set the set of modifiers to test against
     * @param test the modifier set to test
     * @return {@code true} if all the modifiers in {@code set} are present in {@code test}, {@code false} otherwise
     */
    public static boolean allAreSet(int set, int test) {
        return (set & test) == test;
    }

    /**
     * Test to see if all modifiers in the given set are absent in the test value.
     *
     * @param set the set of modifiers to test against
     * @param test the modifier set to test
     * @return {@code true} if all the modifiers in {@code set} are absent in {@code test}, {@code false} otherwise
     */
    public static boolean allAreClear(int set, int test) {
        return (set & test) == 0;
    }

    /**
     * Test to see if any of the modifiers in the given set are present in the test value.
     *
     * @param set the set of modifiers to test against
     * @param test the modifier set to test
     * @return {@code true} if any of the modifiers in {@code set} are present in {@code test}, {@code false} otherwise
     */
    public static boolean anyAreSet(int set, int test) {
        return (set & test) != 0;
    }

    /**
     * Test to see if any of the modifiers in the given set are absent in the test value.
     *
     * @param set the set of modifiers to test against
     * @param test the modifier set to test
     * @return {@code true} if any of the modifiers in {@code set} are absent in {@code test}, {@code false} otherwise
     */
    public static boolean anyAreClear(int set, int test) {
        return (set & test) != test;
    }

    /**
     * Returns an integer which results in the appropriate modifier based on the element.
     *
     * @param element the element to check the modifiers on
     *
     * @return an integer representing the modifiers
     */
    public static int of(final Element element) {
        int result = 0;
        for (Modifier modifier : element.getModifiers()) {
            switch (modifier.name()) {
                case "ABSTRACT": {
                    result = result | ABSTRACT;
                    break;
                }
                case "FINAL": {
                    result = result | FINAL;
                    break;
                }
                case "NATIVE": {
                    result = result | NATIVE;
                    break;
                }
                case "PRIVATE": {
                    result = result | PRIVATE;
                    break;
                }
                case "PROTECTED": {
                    result = result | PROTECTED;
                    break;
                }
                case "PUBLIC": {
                    result = result | PUBLIC;
                    break;
                }
                case "STATIC": {
                    result = result | STATIC;
                    break;
                }
                case "STRICTFP": {
                    result = result | STRICTFP;
                    break;
                }
                case "SYNCHRONIZED": {
                    result = result | SYNCHRONIZED;
                    break;
                }
                case "TRANSIENT": {
                    result = result | TRANSIENT;
                    break;
                }
                case "VOLATILE": {
                    result = result | VOLATILE;
                    break;
                }
                case "DEFAULT": {
                    result = result | DEFAULT;
                    break;
                }
            }
        }
        if (element instanceof ExecutableElement && ((ExecutableElement) element).isVarArgs()) {
            result = result | VARARGS;
        }
        return result;
    }

    static void write(final SourceFileWriter writer, final int mods) throws IOException {
        if (allAreSet(mods, PUBLIC)) {
            writer.write($KW.PUBLIC);
        }
        if (allAreSet(mods, PROTECTED)) {
            writer.write($KW.PROTECTED);
        }
        if (allAreSet(mods, PRIVATE)) {
            writer.write($KW.PRIVATE);
        }
        if (allAreSet(mods, ABSTRACT)) {
            writer.write($KW.ABSTRACT);
        }
        if (allAreSet(mods, STATIC)) {
            writer.write($KW.STATIC);
        }
        if (allAreSet(mods, FINAL)) {
            writer.write($KW.FINAL);
        }
        if (allAreSet(mods, TRANSIENT)) {
            writer.write($KW.TRANSIENT);
        }
        if (allAreSet(mods, VOLATILE)) {
            writer.write($KW.VOLATILE);
        }
        if (allAreSet(mods, SYNCHRONIZED)) {
            writer.write($KW.SYNCHRONIZED);
        }
        if (allAreSet(mods, NATIVE)) {
            writer.write($KW.NATIVE);
        }
        if (allAreSet(mods, STRICTFP)) {
            writer.write($KW.STRICTFP);
        }
        if (allAreSet(mods, DEFAULT)) {
            writer.write($KW.DEFAULT);
        }
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JPackageInfoFile.java000066400000000000000000000016571250006154200270540ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A {@code package-info.java} file definition.
 *
 * @author David M. Lloyd
 */
public interface JPackageInfoFile extends JDocCommentable, JAnnotatable {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JParamDeclaration.java000066400000000000000000000030371250006154200273050ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A parameter declaration.
 *
 * @author David M. Lloyd
 */
public interface JParamDeclaration extends JAnnotatable {

    /**
     * Get the parameter type.
     *
     * @return the parameter type
     */
    JType type();

    /**
     * Get the parameter name.
     *
     * @return the parameter name
     */
    String name();

    /**
     * Get the parameter modifiers.
     *
     * @return the parameter modifiers
     */
    int mods();

    /**
     * Determine whether the parameter is a vararg parameter.
     *
     * @return {@code true} if the parameter is vararg, {@code false} otherwise
     */
    boolean varargs();

    /**
     * Get the {@code @param} JavaDoc block for this parameter.
     *
     * @return the comment block
     */
    JComment doc();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSimpleArgs.java000066400000000000000000000022431250006154200261430ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A program element which supports simple arguments.
 *
 * @author David M. Lloyd
 */
public interface JSimpleArgs {

    /**
     * Add an argument.
     *
     * @param expr the argument expression
     * @return this program element
     */
    JSimpleArgs arg(JExpr expr);

    /**
     * Get the arguments defined thus far.
     *
     * @return the arguments
     */
    JExpr[] arguments();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSourceFile.java000066400000000000000000000063661250006154200261470ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A source file.
 *
 * @author David M. Lloyd
 */
public interface JSourceFile extends JCommentable {

    /**
     * Add a type import to this source file.
     *
     * @param type the type to import
     * @return this source file
     */
    JSourceFile _import(String type);

    /**
     * Add a type import to this source file.
     *
     * @param type the type to import
     * @return this source file
     */
    JSourceFile _import(JType type);

    /**
     * Add a type import to this source file.
     *
     * @param type the type to import
     * @return this source file
     */
    JSourceFile _import(Class type);

    /**
     * Add a static member import to this source file.
     *
     * @param type the type to import from
     * @param member the member name
     * @return this source file
     */
    JSourceFile importStatic(String type, String member);

    /**
     * Add a static member import to this source file.
     *
     * @param type the type to import from
     * @param member the member name
     * @return this source file
     */
    JSourceFile importStatic(JType type, String member);

    /**
     * Add a static member import to this source file.
     *
     * @param type the type to import from
     * @param member the member name
     * @return this source file
     */
    JSourceFile importStatic(Class type, String member);

    /**
     * Add a blank line to this source file.  If sorting is enabled, blank lines may be lost.
     *
     * @return this source file
     */
    JSourceFile blankLine();

    /**
     * Add a class definition to this source file.
     *
     * @param mods the modifiers
     * @param name the class name
     * @return the class definition
     */
    JClassDef _class(int mods, String name);

    /**
     * Add an enum definition to this source file.
     *
     * @param mods the modifiers
     * @param name the enum name
     * @return the enum definition
     */
    JClassDef _enum(int mods, String name);

    /**
     * Add an interface definition to this source file.
     *
     * @param mods the modifiers
     * @param name the interface name
     * @return the interface definition
     */
    JClassDef _interface(int mods, String name);

    /**
     * Add an annotation interface definition to this source file.
     *
     * @param mods the modifiers
     * @param name the annotation interface name
     * @return the annotation interface definition
     */
    JClassDef annotationInterface(int mods, String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSources.java000066400000000000000000000030371250006154200255220ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * A repository of source files.
 *
 * @author David M. Lloyd
 */
public interface JSources {

    /**
     * Create a source file.
     *
     * @param packageName the package name of the source file
     * @param fileName the source file name (excluding {@code .java} suffix)
     * @return the source file
     */
    JSourceFile createSourceFile(String packageName, String fileName);

    /**
     * Create a {@code package-info.java} file.
     *
     * @param packageName the package name
     * @return the source file
     */
    JDocCommentable createPackageInfoFile(String packageName);

    /**
     * Write the source files.
     *
     * @throws IOException if a write operation fails
     */
    void writeSources() throws IOException;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JStatement.java000066400000000000000000000016051250006154200260420ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A statement in a program.
 *
 * @author David M. Lloyd
 */
public interface JStatement extends JCommentable {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSwitch.java000066400000000000000000000025441250006154200253420ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A {@code switch} statement.
 *
 * @author David M. Lloyd
 */
public interface JSwitch extends JStatement {

    /**
     * Add a switch case.
     *
     * @param expr the case expression
     * @return a sub-block for the case logic
     */
    JBlock _case(JExpr expr);

    /**
     * Add a switch case for an {@code enum} constant.
     *
     * @param constName the constant name
     * @return a sub-block for the case logic
     */
    JBlock _case(String constName);

    /**
     * Add the default block.
     *
     * @return the default sub-block
     */
    JBlock _default();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTry.java000066400000000000000000000072031250006154200246540ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A {@code try} block.
 *
 * @author David M. Lloyd
 */
public interface JTry extends JBlock {

    /**
     * Add a resource for {@code try}-with-resources constructs.
     *
     * @param mods the resource variable modifiers
     * @param type the resource variable type
     * @param var the resource variable name
     * @param init the resource variable initialization value
     * @return the variable declaration
     */
    JVarDeclaration with(int mods, String type, String var, JExpr init);

    /**
     * Add a resource for {@code try}-with-resources constructs.
     *
     * @param mods the resource variable modifiers
     * @param type the resource variable type
     * @param var the resource variable name
     * @param init the resource variable initialization value
     * @return the variable declaration
     */
    JVarDeclaration with(int mods, JType type, String var, JExpr init);

    /**
     * Add a resource for {@code try}-with-resources constructs.
     *
     * @param mods the resource variable modifiers
     * @param type the resource variable type
     * @param var the resource variable name
     * @param init the resource variable initialization value
     * @return the variable declaration
     */
    JVarDeclaration with(int mods, Class type, String var, JExpr init);

    /**
     * Add a {@code catch} block.
     *
     * @param mods the catch block modifiers
     * @param type the exception type
     * @param var the exception variable name
     * @return the {@code catch} sub-block
     */
    JCatch _catch(int mods, String type, String var);

    /**
     * Add a {@code catch} block.
     *
     * @param mods the catch block modifiers
     * @param type the exception type
     * @param var the exception variable name
     * @return the {@code catch} sub-block
     */
    JCatch _catch(int mods, Class type, String var);

    /**
     * Add a {@code catch} block.
     *
     * @param mods the catch block modifiers
     * @param type the exception type
     * @param var the exception variable name
     * @return the {@code catch} sub-block
     */
    JCatch _catch(int mods, JType type, String var);

    /**
     * Add a {@code catch} for an ignored exception.
     *
     * @param type the exception type
     * @return this {@code try} block
     */
    JTry ignore(String type);

    /**
     * Add a {@code catch} for an ignored exception.
     *
     * @param type the exception type
     * @return this {@code try} block
     */
    JTry ignore(Class type);

    /**
     * Add a {@code catch} for an ignored exception.
     *
     * @param type the exception type
     * @return this {@code try} block
     */
    JTry ignore(JType type);

    /**
     * Add the {@code finally} block for this {@code try}.
     *
     * @return the {@code finally} sub-block
     */
    JBlock _finally();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JType.java000066400000000000000000000157711250006154200250300ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import javax.lang.model.element.ExecutableElement;

/**
 * A type specification.  See also {@link JTypes}.
 *
 * @author David M. Lloyd
 */
public interface JType {

    /**
     * An empty array of types.
     */
    JType[] NONE = new JType[0];

    /**
     * A special type that always renders to the type of the class it is encountered in.
     */
    JType THIS = new ThisJType();

    /**
     * The {@code void} type.
     */
    JType VOID = new PrimitiveJType("void", "Void");

    /**
     * The {@code boolean} primitive type.
     */
    JType BOOLEAN = new PrimitiveJType("boolean", "Boolean");

    /**
     * The {@code float} primitive type.
     */
    JType FLOAT = new PrimitiveJType("float", "Float");

    /**
     * The {@code double} primitive type.
     */
    JType DOUBLE = new PrimitiveJType("double", "Double");

    /**
     * The {@code char} primitive type.
     */
    JType CHAR = new PrimitiveJType("char", "Char");

    /**
     * The {@code byte} primitive type.
     */
    JType BYTE = new PrimitiveJType("byte", "Byte");

    /**
     * The {@code short} primitive type.
     */
    JType SHORT = new PrimitiveJType("short", "Short");

    /**
     * The {@code int} primitive type.
     */
    JType INT = new PrimitiveJType("int", "Integer");

    /**
     * The {@code long} primitive type.
     */
    JType LONG = new PrimitiveJType("long", "Long");

    /**
     * The type of {@code java.lang.Object}.
     */
    JType OBJECT = new ReferenceJType("java.lang", "Object");

    /**
     * The wildcard type of {@code }, also known as {@code }.
     */
    JType WILDCARD = OBJECT.wildcardExtends();

    /**
     * Get the simple name of this type.
     *
     * @return the type's simple name
     */
    String simpleName();

    /**
     * An expression of the form {@code ThisType.class}.
     *
     * @return the expression
     */
    JExpr _class();

    /**
     * An expression of the form {@code ThisType.this}.  If the type is an array type, an exception is thrown.
     *
     * @return the expression
     */
    JExpr _this();

    /**
     * An expression of the form {@code ThisType.super}.  If the type is an array type, an exception is thrown.
     *
     * @return the expression
     */
    JExpr _super();

    /**
     * An array of this type.
     *
     * @return the array type
     */
    JType array();

    /**
     * Construct a new instance of this non-array type.  If the type is an array type, an exception is thrown.
     *
     * @return the construction call
     */
    JCall _new();

    /**
     * Construct a new instance of this array type.  If the type is not an array type, an exception is thrown.
     *
     * @param dim the array size
     * @return the construction call
     */
    JExpr _new(JExpr dim);

    /**
     * Construct a new instance of this array type.  If the type is not an array type, an exception is thrown.
     *
     * @param dim the array size
     * @return the construction call
     */
    JExpr _new(int dim);

    /**
     * Create a new array of this type which is inline-initialized.
     *
     * @return the array, initially with zero elements
     */
    JArrayExpr _newArray();

    /**
     * Construct a new anonymous subclass of this type.
     *
     * @return the anonymous subclass definition
     */
    JAnonymousClassDef _newAnon();

    /**
     * This type, with the given generic type arguments.
     *
     * @param args the type arguments
     * @return the generic type
     */
    JType typeArg(String... args);

    /**
     * This type, with the given generic type arguments.
     *
     * @param args the type arguments
     * @return the generic type
     */
    JType typeArg(JType... args);

    /**
     * This type, with the given generic type arguments.
     *
     * @param args the type arguments
     * @return the generic type
     */
    JType typeArg(Class... args);

    /**
     * Get the type arguments of this type.
     *
     * @return the type arguments of this type
     */
    JType[] typeArgs();

    /**
     * The primitive-boxed version of this type.
     *
     * @return the boxed version of this type
     */
    JType box();

    /**
     * The primitive-unboxed version of this type.
     *
     * @return the unboxed version of this type
     */
    JType unbox();

    /**
     * The erasure of this type.
     *
     * @return the erasure of this type
     */
    JType erasure();

    /**
     * The element type, if this an array (otherwise {@code null}).
     *
     * @return the element type, or {@code null} if it is not an array
     */
    JType elementType();

    /**
     * Get a wildcard that extends this type.
     *
     * @return the wildcard
     */
    JType wildcardExtends();

    /**
     * Get a wildcard that this type extends.
     *
     * @return the wildcard
     */
    JType wildcardSuper();

    /**
     * Get a nested type within this reference type.
     *
     * @param name the name of the nested type
     * @return the nested type
     */
    JType nestedType(String name);

    /**
     * Get a nested type within this reference type.
     *
     * @param name the name of the nested type
     * @return the nested type
     */
    JType $t(String name);

    /**
     * Look up a static field on this type.
     *
     * @param name the field name
     * @return the field expression
     */
    JAssignableExpr field(String name);

    /**
     * Look up a static field on this type.
     *
     * @param name the field name
     * @return the field expression
     */
    JAssignableExpr $v(String name);

    /**
     * Call a static method on this type.
     *
     * @param name the method to call
     * @return the method call
     */
    JCall call(String name);

    /**
     * Call a static method on this type.
     *
     * @param method the method to call
     * @return the method call
     */
    JCall call(ExecutableElement method);

    /**
     * Get a method reference of this type.
     *
     * @param name the method name
     * @return the method reference expression
     */
    JExpr methodRef(String name);

    /**
     * Get a method reference of this type.
     *
     * @param method the method element
     * @return the method reference expression
     */
    JExpr methodRef(ExecutableElement method);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTypeCommentContent.java000066400000000000000000000022201250006154200276670ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class JTypeCommentContent implements CommentContent {

    private final JType type;

    JTypeCommentContent(final JType type) {
        this.type = type;
    }

    JType getType() {
        return type;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(type);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTypeParamDef.java000066400000000000000000000040311250006154200264130ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A type parameter definition.
 *
 * @author David M. Lloyd
 */
public interface JTypeParamDef {

    /**
     * Add an {@code extends} bound to this parameter.
     *
     * @param type the bound type
     * @return this type parameter definition
     */
    JTypeParamDef _extends(String type);

    /**
     * Add an {@code extends} bound to this parameter.
     *
     * @param type the bound type
     * @return this type parameter definition
     */
    JTypeParamDef _extends(JType type);

    /**
     * Add an {@code extends} bound to this parameter.
     *
     * @param type the bound type
     * @return this type parameter definition
     */
    JTypeParamDef _extends(Class type);

    /**
     * Add a {@code super} bound to this parameter.
     *
     * @param type the bound type
     * @return this type parameter definition
     */
    JTypeParamDef _super(String type);

    /**
     * Add a {@code super} bound to this parameter.
     *
     * @param type the bound type
     * @return this type parameter definition
     */
    JTypeParamDef _super(JType type);

    /**
     * Add a {@code super} bound to this parameter.
     *
     * @param type the bound type
     * @return this type parameter definition
     */
    JTypeParamDef _super(Class type);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTypes.java000066400000000000000000000143771250006154200252140ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.util.LinkedHashMap;
import java.util.List;

import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;

/**
 * The factory for generating simple types.
 */
public final class JTypes {
    private JTypes() {}

    /**
     * Return the erased type of a class definition.
     *
     * @param classDef the class definition
     * @return the type
     */
    public static JType $t(JClassDef classDef) {
        return typeOf(classDef);
    }

    /**
     * Return the type corresponding to the given class.
     *
     * @param clazz the class
     * @return the type
     */
    public static JType $t(Class clazz) {
        return typeOf(clazz);
    }

    /**
     * Return a type corresponding to a class with the given name.
     *
     * @param name the class name
     * @return the type
     */
    public static JType $t(String name) {
        return typeNamed(name);
    }

    /**
     * Return the erased type of a class definition.
     *
     * @param classDef the class definition
     * @return the type
     */
    public static JType typeOf(JClassDef classDef) {
        return classDef.erasedType();
    }

    /**
     * Return the type corresponding to the given class.
     *
     * @param clazz the class
     * @return the type
     */
    public static JType typeOf(Class clazz) {
        final Class enclosingClass = clazz.getEnclosingClass();
        if (enclosingClass != null) {
            return $t(enclosingClass).$t(clazz.getSimpleName());
        } else {
            return $t(clazz.getName());
        }
    }

    static final ThreadLocal> cache = new CachingThreadLocal<>();

    /**
     * Return a type corresponding to a class with the given name.
     *
     * @param name the class name
     * @return the type
     */
    public static JType typeNamed(String name) {
        if (name.endsWith("[]")) {
            return typeNamed(name.substring(0, name.length() - 2)).array();
        }
        final LinkedHashMap map = cache.get();
        JType type = map.get(name);
        if (type == null) {
            final int idx = name.lastIndexOf('.');
            map.put(name, type = new ReferenceJType(idx == -1 ? "" : name.substring(0, idx), name.substring(idx + 1)));
        }
        return type;
    }

    /**
     * Get a {@code JType} that corresponds to the given {@code TypeMirror} for annotation processors.
     *
     * @param typeMirror the type mirror
     * @return the {@code JType}
     */
    public static JType typeOf(TypeMirror typeMirror) {
        if (typeMirror instanceof ArrayType) {
            return typeOf(((ArrayType) typeMirror).getComponentType()).array();
        } else if (typeMirror instanceof WildcardType) {
            final WildcardType wildcardType = (WildcardType) typeMirror;
            final TypeMirror extendsBound = wildcardType.getExtendsBound();
            final TypeMirror superBound = wildcardType.getSuperBound();
            return extendsBound != null ? typeOf(extendsBound).wildcardExtends() : superBound != null ? typeOf(superBound).wildcardSuper() : JType.WILDCARD;
        } else if (typeMirror instanceof TypeVariable) {
            final TypeVariable typeVariable = (TypeVariable) typeMirror;
            final String name = typeVariable.asElement().getSimpleName().toString();
            return typeNamed(name);
        } else if (typeMirror instanceof DeclaredType) {
            final DeclaredType declaredType = (DeclaredType) typeMirror;
            final TypeElement typeElement = (TypeElement) declaredType.asElement();
            final TypeMirror enclosingType = declaredType.getEnclosingType();
            if (enclosingType != null && enclosingType.getKind() == TypeKind.DECLARED) {
                return typeOf(enclosingType).nestedType(typeElement.getSimpleName().toString());
            }
            final String name = typeElement.getQualifiedName().toString();
            final JType rawType = JTypes.typeNamed(name);
            final List typeArguments = declaredType.getTypeArguments();
            if (typeArguments.isEmpty()) {
                return rawType;
            }
            JType[] args = new JType[typeArguments.size()];
            for (int i = 0; i < typeArguments.size(); i++) {
                final TypeMirror argument = typeArguments.get(i);
                args[i] = typeOf(argument);
            }
            return rawType.typeArg(args);
        } else if (typeMirror instanceof NoType) {
            switch (typeMirror.getKind()) {
                case VOID:      return JType.VOID;
            }
            // fall out
        } else if (typeMirror instanceof PrimitiveType) {
            switch (typeMirror.getKind()) {
                case BOOLEAN:   return JType.BOOLEAN;
                case BYTE:      return JType.BYTE;
                case SHORT:     return JType.SHORT;
                case INT:       return JType.INT;
                case LONG:      return JType.LONG;
                case CHAR:      return JType.CHAR;
                case FLOAT:     return JType.FLOAT;
                case DOUBLE:    return JType.DOUBLE;
            }
            // fall out
        }
        throw new IllegalArgumentException(String.format("Cannot find equivalent type to %s", typeMirror));
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JVarDeclaration.java000066400000000000000000000032141250006154200267720ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * A variable declaration.
 *
 * @author David M. Lloyd
 */
public interface JVarDeclaration extends JAnnotatable, JDocCommentable {

    /**
     * Get the variable type.
     *
     * @return the variable type
     */
    JType type();

    /**
     * Get the variable name.
     *
     * @return the variable name
     */
    String name();

    /**
     * Add another item to this declaration.  Subsequent items always have the same type as this item.
     *
     * @param name the variable name
     * @param init the variable initializer
     * @return the subsequent declaration
     */
    JVarDeclaration add(String name, JExpr init);

    /**
     * Add another item to this declaration.  Subsequent items always have the same type as this item.
     *
     * @param name the variable name
     * @return the subsequent declaration
     */
    JVarDeclaration add(String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordExprJStatement.java000066400000000000000000000025551250006154200302530ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class KeywordExprJStatement extends KeywordJStatement {

    private final JExpr expr;

    KeywordExprJStatement(final $KW keyword, final JExpr expr) {
        super(keyword);
        this.expr = expr;
    }

    JExpr getExpression() {
        return expr;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writeComments(writer);
        writer.write(getKeyword());
        writer.sp();
        writer.write(expr);
        writer.write($PUNCT.SEMI);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordJCall.java000066400000000000000000000023471250006154200263220ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class KeywordJCall extends AbstractJCall {

    private final $KW keyword;

    KeywordJCall(final $KW keyword) {
        super(Prec.METHOD_CALL);
        this.keyword = keyword;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        super.writeTypeArgs(writer);
        writer.write(keyword);
        super.write(writer);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordJExpr.java000066400000000000000000000022111250006154200263530ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.$KW;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class KeywordJExpr extends AbstractJExpr {

    private final $KW name;

    KeywordJExpr(final $KW name) {
        super(0);
        this.name = name;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(name);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordJStatement.java000066400000000000000000000024321250006154200274060ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class KeywordJStatement extends BasicJStatement implements BlockContent {

    private final $KW keyword;

    KeywordJStatement($KW keyword) {
        this.keyword = keyword;
    }

    $KW getKeyword() {
        return keyword;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writeComments(writer);
        writer.write(keyword);
        writer.write($PUNCT.SEMI);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/LineJComment.java000066400000000000000000000031151250006154200263060ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class LineJComment extends AbstractJComment implements ClassContent, ClassFileContent, BlockContent, JClassItem {

    public void write(final SourceFileWriter writer) throws IOException {
        writer.writeEscaped("// ");
        writer.pushIndent(CommentIndentation.LINE);
        try {
            super.write(writer);
        } finally {
            writer.popIndent(CommentIndentation.LINE);
        }
    }

    public Kind getItemKind() {
        return Kind.LINE_COMMENT;
    }

    public int getModifiers() {
        return 0;
    }

    public boolean hasAllModifiers(final int mods) {
        return false;
    }

    public boolean hasAnyModifier(final int mods) {
        return false;
    }

    public String getName() {
        return null;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/LongJExpr.java000066400000000000000000000027441250006154200256410ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class LongJExpr extends AbstractJExpr implements JExpr {

    private final long val;
    private final int radix;

    LongJExpr(final long val, final int radix) {
        super(0);
        this.val = val;
        this.radix = radix;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.addWordSpace();
        writer.write(Tokens.$NUMBER);
        switch (radix) {
            case 2:
                writer.writeEscaped("0b");
                break;
            case 16:
                writer.writeEscaped("0x");
                break;
        }
        writer.writeEscaped(Long.toString(val, radix) + "L");
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/MethodJMethodDef.java000066400000000000000000000041251250006154200270760ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

import org.jboss.jdeparser.FormatPreferences.Space;

/**
 * @author David M. Lloyd
 */
class MethodJMethodDef extends AbstractJMethodDef implements JClassItem {

    private final JType returnType;
    private final String name;

    MethodJMethodDef(final AbstractJClassDef clazz, final int mods, final JType returnType, final String name) {
        super(clazz, mods);
        this.returnType = returnType;
        this.name = name;
    }

    JType getReturnType() {
        return returnType;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writeDocComments(writer);
        writeComments(writer);
        writeAnnotations(writer, Space.AFTER_ANNOTATION);
        JMod.write(writer, getModifiers());
        writeTypeParams(writer);
        writer.write(returnType);
        writer.sp();
        writer.writeEscapedWord(name);
        super.write(writer);
    }

    public String getName() {
        return name;
    }

    public int getModifiers() {
        return super.getModifiers();
    }

    public Kind getItemKind() {
        return Kind.METHOD;
    }

    public boolean hasAllModifiers(final int mods) {
        return (getModifiers() & mods) == mods;
    }

    public boolean hasAnyModifier(final int mods) {
        return (getModifiers() & mods) != 0;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/MethodRefJExpr.java000066400000000000000000000024321250006154200266110ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class MethodRefJExpr extends AbstractJExpr {

    private final AbstractJType type;
    private final String name;

    MethodRefJExpr(final AbstractJType type, final String name) {
        super(0);
        this.type = type;
        this.name = name;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(type);
        writer.write(Tokens.$PUNCT.BINOP.DBL_COLON);
        writer.writeEscapedWord(name);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NameJExpr.java000066400000000000000000000021531250006154200256140ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class NameJExpr extends AbstractJAssignableExpr {

    private final String name;

    NameJExpr(final String name) {
        super(0);
        this.name = name;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.writeEscaped(name);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NarrowedJType.java000066400000000000000000000070031250006154200265170ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;
import java.util.Arrays;

/**
 * @author David M. Lloyd
 */
class NarrowedJType extends AbstractJType {

    private final AbstractJType erased;
    private final JType[] args;

    public NarrowedJType(final AbstractJType erased, final JType[] args) {
        this.erased = erased;
        this.args = args;
    }

    public String simpleName() {
        return erased.simpleName();
    }

    public JExpr _class() {
        return erased._class();
    }

    public JExpr _this() {
        return erased._this();
    }

    public JExpr _super() {
        return erased._super();
    }

    public JCall _new() {
        return new NewJCall(this);
    }

    public JCall _new(final JExpr dim) {
        final JCall call = erasure()._new();
        for (JType arg : args) {
            call.typeArg(arg);
        }
        return call;
    }

    public JType typeArg(final JType... args) {
        return new NarrowedJType(erased, concat(this.args, args));
    }

    private static JType[] concat(JType[] a, JType[] b) {
        if (a.length == 0) return b;
        final int al = a.length;
        final int bl = b.length;
        final JType[] c = Arrays.copyOf(a, al + bl);
        System.arraycopy(b, 0, c, al, bl);
        return c;
    }

    public JType[] typeArgs() {
        return args;
    }

    public JType erasure() {
        return erased;
    }

    public JCall call(final String name) {
        return erasure().call(name);
    }

    public JType nestedType(final String name) {
        return erasure().nestedType(name);
    }

    void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
        sourceFileWriter.write(erasure());
        final JType[] args = this.args;
        final int len = args.length;
        if (len > 0) {
            sourceFileWriter.write($PUNCT.ANGLE.OPEN);
            JType type = args[0];
            sourceFileWriter.write(type);
            for (int i = 1; i < len; i ++) {
                sourceFileWriter.write(FormatPreferences.Space.BEFORE_COMMA);
                sourceFileWriter.write($PUNCT.COMMA);
                sourceFileWriter.write(FormatPreferences.Space.AFTER_COMMA_TYPE_ARGUMENT);
                type = args[i];
                sourceFileWriter.write(type);
            }
            sourceFileWriter.write($PUNCT.ANGLE.CLOSE);
        }
    }

    public String toString() {
        final StringBuilder b = new StringBuilder(erased.toString());
        b.append('<');
        for (int i = 0; i < args.length; i++) {
            JType arg = args[i];
            b.append(arg);
            if (i < args.length - 1) {
                b.append(",");
            }
        }
        b.append('>');
        return b.toString();
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedCommentContent.java000066400000000000000000000016021250006154200300610ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * @author David M. Lloyd
 */
class NestedCommentContent extends AbstractJComment implements CommentContent {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedDocCommentContent.java000066400000000000000000000016131250006154200305110ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * @author David M. Lloyd
 */
class NestedDocCommentContent extends AbstractJDocComment implements DocCommentContent {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedHtmlCommentContent.java000066400000000000000000000016161250006154200307130ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * @author David M. Lloyd
 */
class NestedHtmlCommentContent extends AbstractJHtmlComment implements HtmlCommentContent {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedJType.java000066400000000000000000000057431250006154200261710ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.$PUNCT;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class NestedJType extends AbstractJType {

    private final AbstractJType enclosingType;
    private final String name;
    private StaticRefJExpr classExpr;
    private StaticRefJExpr thisExpr;
    private StaticRefJExpr superExpr;
    private CachingLinkedHashMap nestedTypes;

    NestedJType(final AbstractJType enclosingType, final String name) {
        this.enclosingType = enclosingType;
        this.name = name;
    }

    public JExpr _class() {
        StaticRefJExpr expr = classExpr;
        if (expr == null) {
            expr = classExpr = new StaticRefJExpr(this, "class");
        }
        return expr;
    }

    public JExpr _this() {
        StaticRefJExpr expr = thisExpr;
        if (expr == null) {
            expr = thisExpr = new StaticRefJExpr(this, "this");
        }
        return expr;
    }

    public JExpr _super() {
        StaticRefJExpr expr = superExpr;
        if (expr == null) {
            expr = superExpr = new StaticRefJExpr(this, "super");
        }
        return expr;
    }

    public JCall _new(final JExpr dim) {
        return new NewJCall(this);
    }

    public JAnonymousClassDef _newAnon() {
        return new ImplJAnonymousClassDef(this);
    }

    public String simpleName() {
        return name;
    }

    public JType typeArg(final JType... args) {
        return new NarrowedJType(this, args);
    }

    public JType nestedType(final String name) {
        CachingLinkedHashMap nestedTypes = this.nestedTypes;
        if (nestedTypes == null) {
            nestedTypes = this.nestedTypes = new CachingLinkedHashMap<>();
        }
        NestedJType nestedType = nestedTypes.get(name);
        if (nestedType == null) {
            nestedTypes.put(name, nestedType = new NestedJType(this, name));
        }
        return nestedType;
    }

    public String toString() {
        return "Nested type " + name + " of " + enclosingType;
    }

    void writeDirect(final SourceFileWriter writer) throws IOException {
        enclosingType.writeDirect(writer);
        writer.write($PUNCT.DOT);
        writer.writeClass(name);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NewDimJArrayExpr.java000066400000000000000000000032031250006154200271130ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class NewDimJArrayExpr extends AbstractJExpr {

    private final ArrayJType type;
    private final AbstractJExpr dim;

    NewDimJArrayExpr(final ArrayJType type, final AbstractJExpr dim) {
        super(Prec.METHOD_CALL);
        this.type = type;
        this.dim = dim;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write($KW.NEW);
        writer.write(type.elementType());
        writer.write($PUNCT.BRACKET.OPEN);
        writer.write(FormatPreferences.Space.WITHIN_BRACKETS);
        writer.write(dim);
        writer.write(FormatPreferences.Space.WITHIN_BRACKETS);
        writer.write($PUNCT.BRACKET.CLOSE);
    }

    public String toString() {
        return "new " + type.elementType() + "[" + dim + "]";
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NewJCall.java000066400000000000000000000027421250006154200254260ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class NewJCall extends AbstractJCall {

    private final AbstractJType type;
    private boolean diamond;

    NewJCall(final AbstractJType type) {
        super(Prec.NEW);
        this.type = type;
    }

    public JCall diamond() {
        diamond = true;
        return this;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(Tokens.$KW.NEW);
        writer.write(type);
        if (diamond) {
            writer.write(Tokens.$PUNCT.ANGLE.OPEN);
            writer.write(Tokens.$PUNCT.ANGLE.CLOSE);
        } else {
            super.writeTypeArgs(writer);
        }
        super.write(writer);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NewUndimJArrayExpr.java000066400000000000000000000023601250006154200274610ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

import static org.jboss.jdeparser.FormatPreferences.Space;
import static org.jboss.jdeparser.Tokens.$KW;

class NewUndimJArrayExpr extends PlainJArrayExpr {
    private final ArrayJType type;

    NewUndimJArrayExpr(final ArrayJType type) {
        this.type = type;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write($KW.NEW);
        writer.write(type);
        writer.write(Space.BEFORE_BRACE_ARRAY_INIT);
        super.write(writer);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NonTrailingSpaceContent.java000066400000000000000000000022401250006154200305130ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class NonTrailingSpaceContent implements CommentContent {

    private static final NonTrailingSpaceContent INSTANCE = new NonTrailingSpaceContent();

    static NonTrailingSpaceContent getInstance() {
        return INSTANCE;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.ntsp();
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ParenJExpr.java000066400000000000000000000026651250006154200260110ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class ParenJExpr extends AbstractJExpr {

    private final AbstractJExpr expr;

    ParenJExpr(final AbstractJExpr expr) {
        super(Prec.PAREN);
        this.expr = expr;
    }

    AbstractJExpr getExpression() {
        return expr;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write($PUNCT.PAREN.OPEN);
        writer.write(FormatPreferences.Space.WITHIN_PAREN_EXPR);
        writer.write(expr);
        writer.write(FormatPreferences.Space.WITHIN_PAREN_EXPR);
        writer.write($PUNCT.PAREN.CLOSE);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/PlainJArrayExpr.java000066400000000000000000000052711250006154200270020ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.FormatPreferences.Space;
import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author David M. Lloyd
 */
class PlainJArrayExpr extends AbstractJExpr implements JArrayExpr {

    private ArrayList members;

    PlainJArrayExpr() {
        super(0);
    }

    PlainJArrayExpr(final JExpr... members) {
        super(0);
        if (members != null) {
            final ArrayList list = new ArrayList<>(members.length);
            for (JExpr expr : members) {
                if (expr != null) {
                    list.add(expr);
                }
            }
            if (list.size() > 0) {
                this.members = list;
            }
        }
    }

    public JArrayExpr add(final JExpr value) {
        if (value != null) {
            ArrayList members = this.members;
            if (members == null) {
                this.members = members = new ArrayList<>();
            }
            members.add(value);
        }
        return this;
    }

    public int elementCount() {
        final ArrayList members = this.members;
        return members == null ? 0 : members.size();
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write($PUNCT.BRACE.OPEN);
        final ArrayList members = this.members;
        if (members != null) {
            final Iterator iterator = members.iterator();
            if (iterator.hasNext()) {
                writer.write(Space.WITHIN_BRACES_ARRAY_INIT);
                writer.write(iterator.next());
                while (iterator.hasNext()) {
                    writer.write($PUNCT.COMMA);
                    writer.write(iterator.next());
                }
                writer.write(Space.WITHIN_BRACES_ARRAY_INIT);
            }
        }
        writer.write($PUNCT.BRACE.CLOSE);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/PlainJClassDef.java000066400000000000000000000026141250006154200265470ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

/**
 * @author David M. Lloyd
 */
class PlainJClassDef extends AbstractJClassDef implements BlockContent, JClassItem {

    PlainJClassDef(final int mods, final ImplJSourceFile classFile, final String name) {
        super(mods, classFile, name);
    }

    PlainJClassDef(final int mods, final AbstractJClassDef enclosingClass, final String name) {
        super(mods, enclosingClass, name);
    }

    $KW designation() {
        return $KW.CLASS;
    }

    public Kind getItemKind() {
        return Kind.CLASS;
    }

    public String getName() {
        return super.getName();
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Prec.java000066400000000000000000000031131250006154200246510ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * @author David M. Lloyd
 */
final class Prec {
    static final int PAREN = 0;
    static final int ARRAY_ACCESS = 1;
    static final int MEMBER_ACCESS = 1;
    static final int METHOD_CALL = 1;
    static final int POST_INC_DEC = 1;
    static final int PRE_INC_DEC = 2;
    static final int UNARY = 2;
    static final int CAST = 3;
    static final int NEW = 3;
    static final int MULTIPLICATIVE = 4;
    static final int ADDITIVE = 5;
    static final int SHIFT = 6;
    static final int RELATIONAL = 7;
    static final int INSTANCEOF = 7;
    static final int EQUALITY = 8;
    static final int BIT_AND = 9;
    static final int BIT_XOR = 10;
    static final int BIT_OR = 11;
    static final int LOG_AND = 12;
    static final int LOG_OR = 13;
    static final int COND = 14;
    static final int ASSIGN = 15;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/PrimitiveJType.java000066400000000000000000000046111250006154200267100ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class PrimitiveJType extends AbstractJType {
    private final String simpleName;
    private final ReferenceJType boxed;
    private StaticRefJExpr classExpr;

    PrimitiveJType(final String simpleName, final String boxed) {
        this.simpleName = simpleName;
        this.boxed = boxed == null ? null : new ReferenceJType("java.lang", boxed, this);
    }

    public JType box() {
        return boxed;
    }

    void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
        switch (simpleName) {
            case "boolean": sourceFileWriter.write($KW.BOOLEAN); return;
            case "byte": sourceFileWriter.write($KW.BYTE); return;
            case "short": sourceFileWriter.write($KW.SHORT); return;
            case "int": sourceFileWriter.write($KW.INT); return;
            case "long": sourceFileWriter.write($KW.LONG); return;
            case "char": sourceFileWriter.write($KW.CHAR); return;
            case "float": sourceFileWriter.write($KW.FLOAT); return;
            case "double": sourceFileWriter.write($KW.DOUBLE); return;
            case "void": sourceFileWriter.write($KW.VOID); return;
            default: throw new IllegalStateException();
        }
    }

    public JExpr _class() {
        StaticRefJExpr expr = classExpr;
        if (expr == null) {
            expr = classExpr = new StaticRefJExpr(this, "class");
        }
        return expr;
    }

    public String simpleName() {
        return simpleName;
    }

    public String toString() {
        return simpleName;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ReferenceJType.java000066400000000000000000000111301250006154200266300ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class ReferenceJType extends AbstractJType {

    private final PrimitiveJType unboxed;
    private final String packageName;
    private final String simpleName;
    private StaticRefJExpr classExpr;
    private StaticRefJExpr thisExpr;
    private StaticRefJExpr superExpr;
    private CachingLinkedHashMap nestedTypes;

    ReferenceJType(final String packageName, final String simpleName) {
        this.packageName = packageName;
        this.simpleName = simpleName;
        this.unboxed = null;
    }

    ReferenceJType(final String packageName, final String simpleName, final PrimitiveJType unboxed) {
        this.packageName = packageName;
        this.simpleName = simpleName;
        this.unboxed = unboxed;
    }

    static ReferenceJType of(JType type) {
        final AbstractJType type1 = AbstractJType.of(type);
        if (type1 instanceof ReferenceJType) {
            return (ReferenceJType) type1;
        }
        throw new IllegalArgumentException("Expected a reference type");
    }

    @Override
    String qualifiedName(final SourceFileWriter writer) {
        if (packageName.isEmpty()) {
            return simpleName;
        }
        return packageName + "." + simpleName;
    }

    public String simpleName() {
        return simpleName;
    }

    public JExpr _class() {
        StaticRefJExpr expr = classExpr;
        if (expr == null) {
            expr = classExpr = new StaticRefJExpr(this, "class");
        }
        return expr;
    }

    public JExpr _this() {
        StaticRefJExpr expr = thisExpr;
        if (expr == null) {
            expr = thisExpr = new StaticRefJExpr(this, "this");
        }
        return expr;
    }

    public JExpr _super() {
        StaticRefJExpr expr = superExpr;
        if (expr == null) {
            expr = superExpr = new StaticRefJExpr(this, "super");
        }
        return expr;
    }

    public JCall _new() {
        return new NewJCall(this);
    }

    public JAnonymousClassDef _newAnon() {
        return new ImplJAnonymousClassDef(this);
    }

    public JType unbox() {
        return unboxed == null ? this : unboxed;
    }

    void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
        final ImplJSourceFile cf = sourceFileWriter.getClassFile();
        final String currentPackageName = cf.getPackageName();
        final boolean packageMatches = currentPackageName.equals(packageName);
        if (packageMatches && cf.hasImport(simpleName())) {
            // an explicit import masks the implicit import
            sourceFileWriter.writeClass(qualifiedName(sourceFileWriter));
        } else if (packageName.equals("java.lang") && ! sourceFileWriter.getClassFile().getSources().hasClass(currentPackageName + "." + simpleName()) || packageMatches) {
            // implicit import
            sourceFileWriter.writeClass(simpleName());
        } else if (cf.hasImport(simpleName())) {
            // explicit import
            sourceFileWriter.writeClass(simpleName());
        } else {
            sourceFileWriter.writeClass(qualifiedName(sourceFileWriter));
        }
    }

    public JType typeArg(final JType... args) {
        if (unboxed != null) return super.typeArg(args);
        return new NarrowedJType(this, args);
    }

    public JType nestedType(final String name) {
        CachingLinkedHashMap nestedTypes = this.nestedTypes;
        if (nestedTypes == null) {
            nestedTypes = this.nestedTypes = new CachingLinkedHashMap<>();
        }
        NestedJType nestedType = nestedTypes.get(name);
        if (nestedType == null) {
            nestedTypes.put(name, nestedType = new NestedJType(this, name));
        }
        return nestedType;
    }

    public String toString() {
        return "Reference of type " + simpleName();
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Sectionable.java000066400000000000000000000027471250006154200262240ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2015 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.util.ArrayList;

interface Sectionable {

    JBlock init(ArrayList content);

    JBlock staticInit(ArrayList content);

    JVarDeclaration field(ArrayList content, int mods, JType type, String name, JExpr init);

    JMethodDef method(ArrayList content, int mods, JType returnType, String name);

    JMethodDef constructor(ArrayList content, int mods);

    JClassDef _class(ArrayList content, int mods, String name);

    JClassDef _enum(ArrayList content, int mods, String name);

    JClassDef _interface(ArrayList content, int mods, String name);

    JClassDef annotationInterface(ArrayList content, int mods, String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SourceFileWriter.java000066400000000000000000000211001250006154200272110ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.ListIterator;

/**
 * @author David M. Lloyd
 */
class SourceFileWriter implements Flushable, Closeable {

    private final FormatPreferences format;
    private final CountingWriter countingWriter;
    private final StringBuilder lineBuffer = new StringBuilder();
    private final String lineSep;
    private final ArrayDeque thisTypeStack = new ArrayDeque<>();
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") // IDEA bug http://youtrack.jetbrains.com/issue/IDEA-128168
    private final ArrayList indentStack = new ArrayList<>();
    private final ListIterator stackIterator = indentStack.listIterator(0);
    private final Indent nextIndent = new Indent() {

        public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) {
            if (stackIterator.hasPrevious()) {
                final Indent n = stackIterator.previous();
                try {
                    n.addIndent(next, preferences, lineBuffer);
                } finally {
                    stackIterator.next();
                }
            }
        }

        public void escape(final Indent next, final StringBuilder b, final int idx) {
            if (stackIterator.hasPrevious()) {
                final Indent n = stackIterator.previous();
                try {
                    n.escape(this, b, idx);
                } finally {
                    stackIterator.next();
                }
            }
        }

        public void unescaped(final Indent next, final StringBuilder b, final int idx) {
            if (stackIterator.hasPrevious()) {
                final Indent n = stackIterator.previous();
                try {
                    n.unescaped(this, b, idx);
                } finally {
                    stackIterator.next();
                }
            }
        }
    };
    private Token state = $START;
    private int spaceState;
    private ImplJSourceFile classFile;

    private static final int SS_NONE = 0;
    private static final int SS_NEEDED = 1;
    private static final int SS_ADDED = 2;
    private static final int SS_NEEDS_INDENT = 3;

    SourceFileWriter(final FormatPreferences format, final Writer writer) {
        this.format = format;
        this.countingWriter = new CountingWriter(writer);
        // todo use preferences/config
        lineSep = System.lineSeparator();
    }

    void nl() throws IOException {
        countingWriter.write(lineBuffer);
        countingWriter.write(lineSep);
        lineBuffer.setLength(0);
        spaceState = SS_NEEDS_INDENT;
    }

    /**
     * Force a space if one hasn't already been added.
     *
     * @throws IOException etc.
     */
    void sp() throws IOException {
        if (spaceState == SS_NEEDS_INDENT) {
            addIndent();
        } else if (spaceState != SS_ADDED) {
            spaceState = SS_ADDED;
            lineBuffer.append(' ');
        }
    }

    /**
     * A non-trailing space.
     */
    void ntsp() throws IOException {
        if (spaceState == SS_NONE) spaceState = SS_NEEDED;
    }

    int getLine() {
        return countingWriter.getLine();
    }

    int getColumn() {
        return countingWriter.getColumn();
    }

    void processSpacing() throws IOException {
        switch (spaceState) {
            case SS_NEEDS_INDENT: {
                nextIndent.addIndent(nextIndent, format, lineBuffer);
                spaceState = SS_ADDED;
                break;
            }
            case SS_NEEDED: {
                sp();
                break;
            }
        }
    }

    void addIndent() throws IOException {
        assert spaceState == SS_NEEDS_INDENT; // it was a new line
        nextIndent.addIndent(nextIndent, format, lineBuffer);
        spaceState = SS_ADDED;
    }

    void writeEscaped(String item) throws IOException {
        processSpacing();
        final int idx = lineBuffer.length();
        lineBuffer.append(item);
        nextIndent.escape(nextIndent, lineBuffer, idx);
        spaceState = SS_NONE;
    }

    void writeEscaped(final char item) throws IOException {
        processSpacing();
        final int idx = lineBuffer.length();
        lineBuffer.append(item);
        nextIndent.escape(nextIndent, lineBuffer, idx);
        spaceState = SS_NONE;
    }

    void writeUnescaped(String item) throws IOException {
        processSpacing();
        final int idx = lineBuffer.length();
        lineBuffer.append(item);
        nextIndent.unescaped(nextIndent, lineBuffer, idx);
        spaceState = SS_NONE;
    }

    void writeUnescaped(char item) throws IOException {
        processSpacing();
        final int idx = lineBuffer.length();
        lineBuffer.append(item);
        nextIndent.unescaped(nextIndent, lineBuffer, idx);
        spaceState = SS_NONE;
    }

    void write(FormatPreferences.Space rule) throws IOException {
        if (rule == null) {
            return;
        }
        if (format.getSpaceType(rule) == FormatPreferences.SpaceType.NEWLINE) {
            if (spaceState != SS_NEEDS_INDENT) {
                // must not be directly after a newline
                nl();
            }
        } else {
            if (format.getSpaceType(rule) == FormatPreferences.SpaceType.SPACE) {
                ntsp();
            }
        }
    }

    void writeClass(final String nameToWrite) throws IOException {
        processSpacing();
        addWordSpace();
        writeEscaped(nameToWrite);
        this.state = $WORD;
        spaceState = SS_NONE;
    }

    void addWordSpace() throws IOException {
        if (state instanceof $KW || state == $WORD || state == $NUMBER) {
            ntsp();
        }
    }

    void write(final Token state) throws IOException {
        processSpacing();
        state.write(this);
        this.state = state;
        spaceState = SS_NONE;
    }

    void writeEscapedWord(final String rawText) throws IOException {
        writeEscaped(rawText);
        this.state = $WORD;
    }

    public void flush() throws IOException {
        countingWriter.flush();
    }

    public void close() throws IOException {
        countingWriter.close();
    }

    void write(final JType type) throws IOException {
        if (type != null) AbstractJType.of(type).writeDirect(this);
    }

    void write(final AbstractJType type) throws IOException {
        if (type != null) type.writeDirect(this);
    }

    void write(final JExpr expr) throws IOException {
        if (expr != null) AbstractJExpr.of(expr).write(this);
    }

    void write(final AbstractJExpr expr) throws IOException {
        if (expr != null) expr.write(this);
    }

    void pushIndent(FormatPreferences.Indentation indentation) {
        pushIndent(indentation.getIndent());
    }

    void pushIndent(Indent indent) {
        stackIterator.add(indent);
    }

    void popIndent(FormatPreferences.Indentation indentation) {
        popIndent(indentation.getIndent());
    }

    void popIndent(Indent indent) {
        final Indent pop = stackIterator.previous();
        stackIterator.remove();
        assert pop == indent;
    }

    AbstractJType getThisType() {
        return thisTypeStack.peek();
    }

    void pushThisType(final AbstractJType thisType) {
        thisTypeStack.push(thisType);
    }

    void popThisType(final AbstractJType thisType) {
        final AbstractJType pop = thisTypeStack.pop();
        assert pop == thisType;
    }

    void setClassFile(final ImplJSourceFile classFile) {
        this.classFile = classFile;
    }

    Token getState() {
        return state;
    }

    ImplJSourceFile getClassFile() {
        return classFile;
    }

    FormatPreferences getFormat() {
        return format;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SourceWriter.java000066400000000000000000000016451250006154200264250ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
abstract class SourceWriter {

    abstract void writeRaw(int ch) throws IOException;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StaticInitJBlock.java000066400000000000000000000032011250006154200271160ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class StaticInitJBlock extends BasicJBlock implements ClassContent, JClassItem {

    StaticInitJBlock() {
        super(null, Braces.REQUIRED);
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writeComments(writer);
        writer.write($KW.STATIC);
        super.write(writer, FormatPreferences.Space.BEFORE_BRACE_METHOD);
    }

    public Kind getItemKind() {
        return Kind.INIT_BLOCK;
    }

    public int getModifiers() {
        return JMod.STATIC;
    }

    public boolean hasAllModifiers(final int mods) {
        return (mods & JMod.STATIC) == mods;
    }

    public boolean hasAnyModifier(final int mods) {
        return (mods & JMod.STATIC) != 0;
    }

    public String getName() {
        return null;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StaticJCall.java000066400000000000000000000024501250006154200261200ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class StaticJCall extends AbstractMethodJCall {

    private final JType type;

    StaticJCall(final JType type, final String name) {
        super(name);
        this.type = type;
    }

    JType getType() {
        return type;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(AbstractJType.of(type));
        writer.write($PUNCT.DOT);
        super.write(writer);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StaticRefJExpr.java000066400000000000000000000033251250006154200266220ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class StaticRefJExpr extends AbstractJAssignableExpr {

    private final AbstractJType type;
    private final String refName;

    StaticRefJExpr(final AbstractJType type, final String refName) {
        super(Prec.MEMBER_ACCESS);
        if (type == null) {
            throw new IllegalArgumentException("type is null");
        }
        if (refName == null) {
            throw new IllegalArgumentException("refName is null");
        }
        this.type = type;
        this.refName = refName;
    }

    AbstractJType getType() {
        return type;
    }

    String getRefName() {
        return refName;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write(type);
        writer.write($PUNCT.DOT);
        writer.writeEscaped(refName);
    }

    String getName() {
        return refName;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StringJExpr.java000066400000000000000000000064211250006154200262040ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class StringJExpr extends AbstractJExpr {

    private final String val;

    StringJExpr(final String val) {
        super(0);
        this.val = val;
    }

    static final Indent ESC = new Indent() {
        public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) {
            next.addIndent(next, preferences, lineBuffer);
            lineBuffer.append('"');
        }

        public void escape(final Indent next, final StringBuilder b, final int idx) {
            char c;
            int i = idx;
            while (i < b.length()) {
                c = b.charAt(i);
                switch (c) {
                    case '"':
                    case '\\': {
                        b.insert(i, '\\');
                        i += 2;
                        break;
                    }
                    case '\n': {
                        b.replace(i, i + 1, "\\n");
                        i += 2;
                        break;
                    }
                    case '\r': {
                        b.replace(i, i + 1, "\\r");
                        i += 2;
                        break;
                    }
                    case '\t': {
                        b.replace(i, i + 1, "\\t");
                        i += 2;
                        break;
                    }
                    case '\b': {
                        b.replace(i, i + 1, "\\b");
                        i += 2;
                        break;
                    }
                    case '\f': {
                        b.replace(i, i + 1, "\\f");
                        i += 2;
                        break;
                    }
                    case 0: {
                        b.replace(i, i + 1, "\\0");
                        i += 2;
                        break;
                    }
                    default: {
                        i++;
                    }
                }
            }
        }

        public void unescaped(final Indent next, final StringBuilder b, final int idx) {
            // next is escaped
            next.escape(next, b, idx);
        }
    };

    public void write(final SourceFileWriter writer) throws IOException {
        writer.addWordSpace();
        writer.writeEscaped('"');
        writer.pushIndent(ESC);
        try {
            writer.writeEscaped(val);
        } finally {
            writer.popIndent(ESC);
        }
        writer.writeEscaped('"');
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SuccessorJVarDeclaration.java000066400000000000000000000042571250006154200306740ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.lang.annotation.Annotation;

/**
 * @author David M. Lloyd
 */
class SuccessorJVarDeclaration implements JVarDeclaration {

    private final FirstJVarDeclaration first;
    private final String name;
    private final JExpr value;

    SuccessorJVarDeclaration(final FirstJVarDeclaration first, final String name, final JExpr value) {
        this.first = first;
        this.name = name;
        this.value = value;
    }

    public String name() {
        return name;
    }

    JExpr getValue() {
        return value;
    }

    public JComment blockComment() {
        return first.blockComment();
    }

    public JComment lineComment() {
        return first.lineComment();
    }

    public JComment deprecated() {
        return first.deprecated();
    }

    public JDocComment docComment() {
        return first.docComment();
    }

    public JAnnotation annotate(final Class type) {
        return first.annotate(type);
    }

    public JAnnotation annotate(final JType type) {
        return first.annotate(type);
    }

    public JAnnotation annotate(final String type) {
        return first.annotate(type);
    }

    public JVarDeclaration add(final String name) {
        return first.add(name);
    }

    public JVarDeclaration add(final String name, final JExpr init) {
        return first.add(name, init);
    }

    public JType type() {
        return first.type();
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SynchJBlock.java000066400000000000000000000027631250006154200261430ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class SynchJBlock extends BasicJBlock {

    private final AbstractJExpr synchExpr;

    SynchJBlock(final BasicJBlock parent, final AbstractJExpr synchExpr) {
        super(parent, Braces.REQUIRED);
        this.synchExpr = synchExpr;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writer.write($KW.SYNCHRONIZED);
        writer.write(FormatPreferences.Space.BEFORE_PAREN_SYNCHRONIZED);
        writer.write($PUNCT.PAREN.OPEN);
        writer.write(synchExpr);
        writer.write($PUNCT.PAREN.CLOSE);
        super.write(writer, FormatPreferences.Space.BEFORE_BRACE_SYNCHRONIZE);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ThisJType.java000066400000000000000000000031221250006154200256430ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class ThisJType extends AbstractJType {

    ThisJType() {
    }

    public String simpleName() {
        return "<>";
    }

    public String toString() {
        return "<>";
    }

    public JExpr _class() {
        return new StaticRefJExpr(this, "class");
    }

    public JExpr _this() {
        return new StaticRefJExpr(this, "this");
    }

    public JExpr _super() {
        return new StaticRefJExpr(this, "super");
    }

    public JCall _new() {
        return new NewJCall(this);
    }

    public JAnonymousClassDef _newAnon() {
        return new ImplJAnonymousClassDef(this);
    }

    void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
        sourceFileWriter.write(sourceFileWriter.getThisType());
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Token.java000066400000000000000000000015251250006154200250450ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

/**
 * @author David M. Lloyd
 */
interface Token extends Writable {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Tokens.java000066400000000000000000000213001250006154200252210ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.FormatPreferences.Space;

import java.io.IOException;
import java.util.Locale;

/**
* @author David M. Lloyd
*/
enum Tokens implements Token {
    /**
     * Cursor is at a new file.
     */
    $START,
    $COMMENT,
    $STRING_LIT,
    $WORD,
    $NUMBER,
    ;

    public void write(final SourceFileWriter writer) throws IOException {
        // n/a
    }

    enum $PUNCT implements Token {
        SEMI(';'),

        DOT('.'),

        Q('?'),
        COLON(':'),

        AT('@'),
        COMMA(','),
        ;
        private final char ch;

        $PUNCT(final char ch) {
            this.ch = ch;
        }

        public void write(final SourceFileWriter writer) throws IOException {
            writer.writeEscaped(ch);
        }

        public char getChar() {
            return ch;
        }

        enum COMMENT implements Token {
            LINE("//"),
            OPEN("/*"),
            CLOSE("*/"),
            ;
            private final String str;

            COMMENT(final String str) {
                this.str = str;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(str);
            }
        }

        enum UNOP implements Token {
            COMP("~"),
            NOT("!"),
            MINUS("-"),
            PP("++"),
            MM("--"),
            ;

            private final String str;

            UNOP(final String str) {
                this.str = str;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(str);
            }
        }

        enum BINOP implements Token {
            PLUS("+", Space.AROUND_ADDITIVE),
            MINUS("-", Space.AROUND_ADDITIVE),
            TIMES("*", Space.AROUND_MULTIPLICATIVE),
            DIV("/", Space.AROUND_MULTIPLICATIVE),
            MOD("%", Space.AROUND_MULTIPLICATIVE),

            BAND("&", Space.AROUND_BITWISE),
            BOR("|", Space.AROUND_BITWISE),
            BXOR("^", Space.AROUND_BITWISE),

            LAND("&&", Space.AROUND_LOGICAL),
            LOR("||", Space.AROUND_LOGICAL),

            SHR(">>", Space.AROUND_SHIFT),
            LSHR(">>>", Space.AROUND_SHIFT),
            SHL("<<", Space.AROUND_SHIFT),

            EQ("==", Space.AROUND_EQUALITY),
            NE("!=", Space.AROUND_EQUALITY),

            LT("<", Space.AROUND_RANGE),
            GT(">", Space.AROUND_RANGE),
            LE("<=", Space.AROUND_RANGE),
            GE(">=", Space.AROUND_RANGE),

            ASSIGN("=", Space.AROUND_ASSIGN),

            ASSIGN_PLUS("+=", Space.AROUND_ASSIGN),
            ASSIGN_MINUS("-=", Space.AROUND_ASSIGN),
            ASSIGN_TIMES("*=", Space.AROUND_ASSIGN),
            ASSIGN_DIV("/=", Space.AROUND_ASSIGN),
            ASSIGN_MOD("%=", Space.AROUND_ASSIGN),

            ASSIGN_BAND("&=", Space.AROUND_ASSIGN),
            ASSIGN_BOR("|=", Space.AROUND_ASSIGN),
            ASSIGN_BXOR("^=", Space.AROUND_ASSIGN),

            ASSIGN_SHR(">>=", Space.AROUND_ASSIGN),
            ASSIGN_LSHR(">>>=", Space.AROUND_ASSIGN),
            ASSIGN_SHL("<<=", Space.AROUND_ASSIGN),

            DBL_COLON("::", null),
            ARROW("->", Space.AROUND_ARROW),
            ;

            private final String str;
            private final Space spacingRule;

            BINOP(final String str, final Space spacingRule) {
                this.str = str;
                this.spacingRule = spacingRule;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(str);
            }

            public Space getSpacingRule() {
                return spacingRule;
            }
        }

        enum PAREN implements Token {
            OPEN('('),
            CLOSE(')'),
            ;
            private final char ch;

            PAREN(final char ch) {
                this.ch = ch;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(ch);
            }
        }

        enum ANGLE implements Token {
            OPEN('<'),
            CLOSE('>'),
            ;

            private final char ch;

            ANGLE(final char ch) {
                this.ch = ch;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(ch);
            }
        }

        enum BRACE implements Token {
            OPEN('{'),
            CLOSE('}'),
            ;

            private final char ch;

            BRACE(final char ch) {
                this.ch = ch;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(ch);
            }
        }

        enum BRACKET implements Token {
            OPEN('['),
            CLOSE(']'),
            ;
            private final char ch;

            BRACKET(final char ch) {
                this.ch = ch;
            }

            public void write(final SourceFileWriter writer) throws IOException {
                writer.writeEscaped(ch);
            }
        }
    }

    enum $KW implements Token {
        AT_INTERFACE("@interface", null, null),

        ABSTRACT(null, null),
        ASSERT(null, null),
        BOOLEAN(null, null),
        BREAK(null, null),
        BYTE(null, null),
        CASE(null, null),
        CATCH(Space.BEFORE_KEYWORD_CATCH, null),
        CHAR(null, null),
        CLASS(null, null),
        CONST(null, null),
        CONTINUE(null, null),
        DEFAULT(null, null),
        DO(null, null),
        DOUBLE(null, null),
        ELSE(Space.BEFORE_KEYWORD_ELSE, null),
        ENUM(null, null),
        EXTENDS(null, null),
        FINAL(null, null),
        FINALLY(Space.BEFORE_KEYWORD_FINALLY, null),
        FLOAT(null, null),
        FOR(null, null),
        GOTO(null, null),
        IF(null, null),
        IMPLEMENTS(null, null),
        IMPORT(null, null),
        INSTANCEOF(null, null),
        INT(null, null),
        INTERFACE(null, null),
        LONG(null, null),
        NATIVE(null, null),
        NEW(null, null),
        PACKAGE(null, null),
        PRIVATE(null, null),
        PROTECTED(null, null),
        PUBLIC(null, null),
        RETURN(null, null),
        SHORT(null, null),
        STATIC(null, null),
        STRICTFP(null, null),
        SUPER(null, null),
        SWITCH(null, null),
        SYNCHRONIZED(null, null),
        THIS(null, null),
        THROW(null, null),
        THROWS(null, null),
        TRANSIENT(null, null),
        TRY(null, null),
        VOID(null, null),
        VOLATILE(null, null),
        WHILE(Space.BEFORE_KEYWORD_WHILE, null),

        FALSE(null, null),
        TRUE(null, null),

        NULL(null, null),
        ;

        private final String kw;
        private final Space before;
        private final Space after;

        $KW(final Space before, final Space after) {
            this.before = before;
            this.after = after;
            this.kw = name().toLowerCase(Locale.US);
        }

        $KW(final String name, final Space before, final Space after) {
            this.before = before;
            this.after = after;
            this.kw = name;
        }

        String getKeyword() {
            return kw;
        }

        public void write(final SourceFileWriter writer) throws IOException {
            final Token writerState = writer.getState();
            if (writerState == $WORD || writerState == $NUMBER || writerState instanceof $KW) {
                writer.sp();
            }
            if (before != null) writer.write(before);
            writer.writeEscapedWord(kw);
            if (after != null) writer.write(after);
        }

        static Token forName(final String keyword) {
            switch (keyword) {
                case "@interface": return AT_INTERFACE;
                default: return valueOf(keyword.toUpperCase(Locale.US));
            }
        }
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/TryJVarDeclaration.java000066400000000000000000000024471250006154200275000ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

class TryJVarDeclaration extends FirstJVarDeclaration {

    private final ImplJTry owner;

    TryJVarDeclaration(final int mods, final JType type, final String name, final JExpr value, final ImplJTry owner) {
        super(mods, type, name, value);
        this.owner = owner;
    }

    public JVarDeclaration add(final String name, final JExpr init) {
        return owner.with(mods(), type(), name, init);
    }

    public JVarDeclaration add(final String name) {
        throw new IllegalArgumentException("Cannot add uninitialized variable to try-with-resources");
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/UnaryJExpr.java000066400000000000000000000035671250006154200260440ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class UnaryJExpr extends AbstractJExpr {

    private final $PUNCT.UNOP op;
    private final AbstractJExpr expr;
    private final boolean postfix;

    UnaryJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr) {
        this(op, expr, Prec.UNARY, false);
    }

    UnaryJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr, final int prec) {
        this(op, expr, prec, false);
    }

    UnaryJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr, final int prec, boolean postfix) {
        super(prec);
        this.op = op;
        this.expr = expr.prec() > prec ? new ParenJExpr(expr) : expr;
        this.postfix = postfix;
    }

    AbstractJExpr getExpression() {
        return expr;
    }

    boolean isPostfix() {
        return postfix;
    }

    public void write(final SourceFileWriter writer) throws IOException {
        if (isPostfix()) {
            writer.write(expr);
            writer.write(op);
        } else {
            writer.write(op);
            writer.write(expr);
        }
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/WhileJBlock.java000066400000000000000000000030701250006154200261170ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class WhileJBlock extends ConditionJBlock {

    WhileJBlock(final BasicJBlock parent, final JExpr cond) {
        super(parent, Braces.IF_MULTILINE, cond);
    }

    public void write(final SourceFileWriter writer) throws IOException {
        writeComments(writer);
        writer.write($KW.WHILE);
        writer.write(FormatPreferences.Space.BEFORE_PAREN_WHILE);
        writer.write($PUNCT.PAREN.OPEN);
        writer.write(FormatPreferences.Space.WITHIN_PAREN_WHILE);
        writer.write(getCondition());
        writer.write(FormatPreferences.Space.WITHIN_PAREN_WHILE);
        writer.write($PUNCT.PAREN.CLOSE);
        super.write(writer, FormatPreferences.Space.BEFORE_BRACE_WHILE);
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/WildcardJType.java000066400000000000000000000044241250006154200264730ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.Tokens.*;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
class WildcardJType extends AbstractJType {

    private final AbstractJType targetType;
    private final boolean extendsNotSuper;

    public WildcardJType(final AbstractJType targetType, final boolean extendsNotSuper) {
        this.targetType = targetType;
        this.extendsNotSuper = extendsNotSuper;
    }

    public String simpleName() {
        return targetType.simpleName();
    }

    public JType array() {
        throw new UnsupportedOperationException("array of wildcard type not allowed");
    }

    public JType wildcardExtends() {
        if (extendsNotSuper) return this;
        throw new UnsupportedOperationException("wildcard extends of wildcard super not allowed");
    }

    public JType wildcardSuper() {
        if (! extendsNotSuper) return this;
        throw new UnsupportedOperationException("wildcard super of wildcard extends not allowed");
    }

    void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
        sourceFileWriter.write($PUNCT.Q);
        sourceFileWriter.sp();
        sourceFileWriter.write(extendsNotSuper ? $KW.EXTENDS : $KW.SUPER);
        sourceFileWriter.write(getTargetType());
    }

    public String toString() {
        return "? " + (extendsNotSuper ? "extends " : "super ") + targetType;
    }

    AbstractJType getTargetType() {
        return targetType;
    }

    boolean isExtendsNotSuper() {
        return extendsNotSuper;
    }
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Writable.java000066400000000000000000000016401250006154200255340ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.IOException;

/**
 * @author David M. Lloyd
 */
interface Writable {
    void write(SourceFileWriter writer) throws IOException;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/package-info.java000066400000000000000000000016461250006154200263150ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * The primary package for JDeparser classes.  To get started, see {@link org.jboss.jdeparser.JDeparser JDeparser}.
 *
 * @author David M. Lloyd
 */
package org.jboss.jdeparser;
jdeparser2-2.0.0.Final/src/test/000077500000000000000000000000001250006154200163435ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/test/java/000077500000000000000000000000001250006154200172645ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/test/java/org/000077500000000000000000000000001250006154200200535ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/test/java/org/jboss/000077500000000000000000000000001250006154200211735ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/test/java/org/jboss/jdeparser/000077500000000000000000000000001250006154200231525ustar00rootroot00000000000000jdeparser2-2.0.0.Final/src/test/java/org/jboss/jdeparser/AbstractGeneratingTestCase.java000066400000000000000000000056611250006154200312300ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author David M. Lloyd
 */
public abstract class AbstractGeneratingTestCase {
    private final ConcurrentMap sourceFiles = new ConcurrentHashMap<>();

    private final JFiler filer = new JFiler() {
        public OutputStream openStream(final String packageName, final String fileName) throws IOException {
            final Key key = new Key(packageName, fileName + ".java");
            if (! sourceFiles.containsKey(key)) {
                final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                if (sourceFiles.putIfAbsent(key, stream) == null) {
                    return stream;
                }
            }
            throw new IOException("Already exists");
        }
    };

    public JFiler getFiler() {
        return filer;
    }

    public ByteArrayInputStream openFile(String packageName, String fileName) throws FileNotFoundException {
        final ByteArrayOutputStream out = sourceFiles.get(new Key(packageName, fileName));
        if (out == null) throw new FileNotFoundException("No file found for package " + packageName + " file " + fileName);
        return new ByteArrayInputStream(out.toByteArray());
    }

    static final class Key {
        private final String packageName;
        private final String fileName;

        Key(final String packageName, final String fileName) {
            this.packageName = packageName;
            this.fileName = fileName;
        }

        public boolean equals(final Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            final Key key = (Key) o;

            return fileName.equals(key.fileName) && packageName.equals(key.packageName);
        }

        public int hashCode() {
            int result = packageName.hashCode();
            result = 31 * result + fileName.hashCode();
            return result;
        }
    }
}
jdeparser2-2.0.0.Final/src/test/java/org/jboss/jdeparser/SimpleExampleTestCase.java000066400000000000000000000114241250006154200302200ustar00rootroot00000000000000/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.jdeparser;

import static org.jboss.jdeparser.JExprs.$v;
import static org.jboss.jdeparser.JExprs.str;
import static org.jboss.jdeparser.JMod.FINAL;
import static org.jboss.jdeparser.JMod.PUBLIC;
import static org.jboss.jdeparser.JMod.STATIC;
import static org.jboss.jdeparser.JMod.VARARGS;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Properties;

import org.junit.Test;

/**
 * @author David M. Lloyd
 */
public class SimpleExampleTestCase extends AbstractGeneratingTestCase {

    @Test
    public void testSimple() throws IOException {
        final JSources sources = JDeparser.createSources(getFiler(), new FormatPreferences(new Properties()));
        final JSourceFile bazFile = sources.createSourceFile("org.foo.bar", "Baz");
        bazFile._import(BigDecimal.class);
        final JClassDef baz = bazFile._class(PUBLIC | FINAL, "Baz");
        final JMethodDef getString = baz.method(PUBLIC | FINAL, String.class, "getString");
        getString.docComment().text("Hello\nthere!");
        getString.docComment().htmlTag("ul", true).attribute("class", "banana").htmlTag("li", false).text("A line item");
        getString.docComment().docTag("author", "Someone");
        getString._throws(IllegalStateException.class);
        getString.typeParam("T")._extends(JTypes.typeOf(String.class));
        baz.field(PUBLIC | STATIC | FINAL, JType.INT, "_foo", JExpr.ONE);
        final JVarDeclaration field = baz.field(PUBLIC | FINAL, JType.INT, "localVar");
        baz.constructor(JMod.PUBLIC).body().assign(JExprs.$v(field), JExpr.ONE);
        final JParamDeclaration theTee = getString.param(FINAL, "T", "theTee");
        JParamDeclaration vap = getString.param(FINAL | VARARGS, Object.class, "whatever");
        final JBlock body = getString.body();
        JVarDeclaration t = body.var(0, String.class, "test", JExpr.NULL);
        JIf jIf = body._if(JExprs.$v(t).eq(JExpr.NULL));
        jIf.assign(JExprs.$v(t), str("new Value"));
        jIf._else().assign(JExprs.$v(t), str("other value"));

        // Reference an enclosing class
        body.var(0, JTypes.$t(Map.Entry.class).typeArg(String.class, Object.class), "mapEntry", JExpr.NULL);
        bazFile._import(Map.class);

        body.call(JTypes.$t(System.class).$v("out"), "println").arg(JExprs.$v(theTee));
        body.add(JTypes.$t(System.class).$v("out").call("println").arg($v("theTee"))).blockComment().text("Hello\nagain!");
        final JExpr tmp1 = body.tempVar(JTypes.$t(int.class), JExprs.decimal(123).plus(JExprs.decimal(456)).times(JExprs.decimal(246)));
        body.var(FINAL, JTypes.$t(String.class), "foo", JExprs.str("boo")).add("bar", JExprs.str("zoo")). add("baz");
        body.add(JTypes.$t(System.class).$v("out").call("println").arg(tmp1));
        final JAnonymousClassDef anon = JTypes.$t(Runnable.class)._newAnon();
        anon.init().add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.str("Bananas!")));
        body.add(anon);
        body.add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.lambda().param("foo").param("bar").body(JExprs.str("Super bananas!"))));
        body.add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.lambda().param(int.class, "foo").param(int.class, "bar").body(JExprs.str("Super duper bananas!"))));
        final JLambda lambda = JExprs.lambda().param(int.class, "foo").param(int.class, "bar");
        final JBlock lambdaBody = lambda.body();
        lambdaBody.add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.str("Bananamus Maximus!")));
        body.add(JTypes.$t(System.class).$v("out").call("println").arg(lambda));
        sources.writeSources();
        final ByteArrayInputStream inputStream = openFile("org.foo.bar", "Baz.java");
        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    }
}