forked from cqfn/astranaut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generating 'package-info.java' files
- Loading branch information
Showing
4 changed files
with
143 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/cqfn/astranaut/codegen/java/JavaFileGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Ivan Kniazkov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cqfn.astranaut.codegen.java; | ||
|
||
import org.cqfn.astranaut.exceptions.BaseException; | ||
|
||
/** | ||
* Entity that represents and generates whole Java files. | ||
* @since 1.0.0 | ||
*/ | ||
public interface JavaFileGenerator extends Entity { | ||
/** | ||
* Generates the source code of the entity as a string. | ||
* @return Source code of the entity | ||
* @throws BaseException If there are any problems during code generation | ||
*/ | ||
default String generateJavaCode() throws BaseException { | ||
final SourceCodeBuilder code = new SourceCodeBuilder(); | ||
this.build(0, code); | ||
return code.toString(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/org/cqfn/astranaut/codegen/java/PackageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 Ivan Kniazkov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cqfn.astranaut.codegen.java; | ||
|
||
import org.cqfn.astranaut.exceptions.BaseException; | ||
|
||
/** | ||
* Describes 'package-info.java' file. | ||
* @since 1.0.0 | ||
*/ | ||
public final class PackageInfo implements JavaFileGenerator { | ||
/** | ||
* License. | ||
*/ | ||
private final License license; | ||
|
||
/** | ||
* Documentation. | ||
*/ | ||
private final JavaDoc doc; | ||
|
||
/** | ||
* Package itself. | ||
*/ | ||
private final Package pkg; | ||
|
||
/** | ||
* Constructor. | ||
* @param license License | ||
* @param brief Brief description of the package | ||
* @param pkg Package itself | ||
*/ | ||
public PackageInfo(final License license, final String brief, final Package pkg) { | ||
this.license = license; | ||
this.doc = new JavaDoc(brief); | ||
this.pkg = pkg; | ||
} | ||
|
||
/** | ||
* Sets the version number. It will be added to JavaDoc. | ||
* @param value Version number | ||
*/ | ||
public void setVersion(final String value) { | ||
this.doc.setVersion(value); | ||
} | ||
|
||
@Override | ||
public void build(final int indent, final SourceCodeBuilder code) throws BaseException { | ||
this.license.build(indent, code); | ||
code.add(indent, ""); | ||
this.doc.build(indent, code); | ||
this.pkg.build(indent, code); | ||
} | ||
} |