-
-
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.
feat(core): Java method and field extraction with the 'javasource' in…
…clude macro
- Loading branch information
1 parent
fe06f72
commit 858dafe
Showing
22 changed files
with
706 additions
and
42 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Enable auto-env through the sdkman_auto_env config | ||
# Add key=value pairs of SDKs to use below | ||
java=8.0.332-tem | ||
java=11.0.10-open |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.rodnansol</groupId> | ||
<artifactId>single-module-project</artifactId> | ||
<artifactId>asciidoctorj-extensions</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.copyright>Apache-2.0</project.copyright> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version> | ||
|
@@ -42,11 +42,14 @@ | |
<maven-resources-plugin.version>3.3.0</maven-resources-plugin.version> | ||
<jreleaser-github-release.draft>false</jreleaser-github-release.draft> | ||
<jreleaser-nexus-deploy.active>ALWAYS</jreleaser-nexus-deploy.active> | ||
<roaster.version>2.28.0.Final</roaster.version> | ||
<asciidoctorj.version>2.5.7</asciidoctorj.version> | ||
<org.eclipse.jdt.core.version>3.31.0</org.eclipse.jdt.core.version> | ||
</properties> | ||
|
||
<name>Single Module Project</name> | ||
<description>Single Module Project Description</description> | ||
<url>https://github.com/rodnansol/single-module-project</url> | ||
<name>AsciiDoctorJ Extensions</name> | ||
<description>AsciiDoctorJ Extensions</description> | ||
<url>https://github.com/rodnansol/asciidoctorj-extensions</url> | ||
<inceptionYear>2023</inceptionYear> | ||
<developers> | ||
<developer> | ||
|
@@ -69,7 +72,7 @@ | |
<scm> | ||
<connection>scm:git:git@${project.scm.url}</connection> | ||
<developerConnection>scm:git:${project.scm.url}</developerConnection> | ||
<url>[email protected]:rodnansol/single-module-project.git</url> | ||
<url>[email protected]:rodnansol/asciidoctorj-extensions.git</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
|
@@ -86,6 +89,22 @@ | |
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.asciidoctor</groupId> | ||
<artifactId>asciidoctorj</artifactId> | ||
<version>${asciidoctorj.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.roaster</groupId> | ||
<artifactId>roaster-api</artifactId> | ||
<version>${roaster.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.roaster</groupId> | ||
<artifactId>roaster-jdt</artifactId> | ||
<version>${roaster.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
|
@@ -286,7 +305,7 @@ | |
<id>release</id> | ||
<properties> | ||
<ossrh.url>https://s01.oss.sonatype.org</ossrh.url> | ||
<release.tags>#tags</release.tags> | ||
<release.tags>#asciidoctorj #java</release.tags> | ||
</properties> | ||
<distributionManagement> | ||
<snapshotRepository> | ||
|
Empty file.
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
src/main/java/org/rodnansol/asciidoctorj/CodeBlockProcessor.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,24 @@ | ||
package org.rodnansol.asciidoctorj; | ||
|
||
import org.asciidoctor.ast.Document; | ||
import org.asciidoctor.extension.PreprocessorReader; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Interface describes a block processor blueprint that can handle different attributes from the 'javasource' include macro. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.1.0 | ||
*/ | ||
public interface CodeBlockProcessor { | ||
|
||
boolean isActive(Map<String, Object> attributes); | ||
|
||
void process(ExtractCommand extractCommand, | ||
Document document, | ||
PreprocessorReader reader, | ||
String target, | ||
Map<String, Object> attributes); | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/rodnansol/asciidoctorj/ExtractCommand.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,50 @@ | ||
package org.rodnansol.asciidoctorj; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Class that wraps an extraction command. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.1.0 | ||
*/ | ||
public class ExtractCommand { | ||
|
||
private final String sourceCodePath; | ||
private final int spaceSize; | ||
private final boolean withJavaDoc; | ||
private final int lineLength; | ||
|
||
public ExtractCommand(String sourceCodePath, int spaceSize, boolean withJavaDoc, int lineLength) { | ||
this.sourceCodePath = Objects.requireNonNull(sourceCodePath, "sourceCodePath is NULL"); | ||
this.spaceSize = spaceSize; | ||
this.withJavaDoc = withJavaDoc; | ||
this.lineLength = lineLength; | ||
} | ||
|
||
public String getSourceCodePath() { | ||
return sourceCodePath; | ||
} | ||
|
||
public int getSpaceSize() { | ||
return spaceSize; | ||
} | ||
|
||
public boolean isWithJavaDoc() { | ||
return withJavaDoc; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ExtractCommand{" + | ||
"sourceCodePath='" + sourceCodePath + '\'' + | ||
", spaceSize=" + spaceSize + | ||
", withJavaDoc=" + withJavaDoc + | ||
", lineLength=" + lineLength + | ||
'}'; | ||
} | ||
|
||
public int getLineLength() { | ||
return lineLength; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/rodnansol/asciidoctorj/ExtractFieldCommand.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,42 @@ | ||
package org.rodnansol.asciidoctorj; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Class that wraps parameters for field extraction. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.1.0 | ||
*/ | ||
public class ExtractFieldCommand extends ExtractCommand { | ||
|
||
private final String fieldName; | ||
|
||
public ExtractFieldCommand(ExtractCommand extractCommand, String fieldName) { | ||
super(extractCommand.getSourceCodePath(), extractCommand.getSpaceSize(), extractCommand.isWithJavaDoc(), extractCommand.getLineLength()); | ||
this.fieldName = Objects.requireNonNull(fieldName, "fieldName is NULL"); | ||
} | ||
|
||
/** | ||
* @param sourceCodePath Java source file's path. | ||
* @param fieldName field name to extract. | ||
* @param spaceSize space size for indentation. | ||
* @param withJavaDoc | ||
* @param lineLength | ||
*/ | ||
public ExtractFieldCommand(String sourceCodePath, String fieldName, int spaceSize, boolean withJavaDoc, int lineLength) { | ||
super(sourceCodePath, spaceSize, withJavaDoc, lineLength); | ||
this.fieldName = Objects.requireNonNull(fieldName, "fieldName is NULL"); | ||
} | ||
|
||
public String getFieldName() { | ||
return fieldName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ExtractFieldCommand{" + | ||
"fieldName='" + fieldName + '\'' + | ||
"} " + super.toString(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/rodnansol/asciidoctorj/ExtractMethodCommand.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,53 @@ | ||
package org.rodnansol.asciidoctorj; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Class that wraps parameters for method extraction. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.1.0 | ||
*/ | ||
public class ExtractMethodCommand extends ExtractCommand { | ||
|
||
|
||
private final String methodName; | ||
private final String[] paramTypes; | ||
|
||
public ExtractMethodCommand(ExtractCommand extractCommand, String methodName,String... paramTypes) { | ||
super(extractCommand.getSourceCodePath(), extractCommand.getSpaceSize(), extractCommand.isWithJavaDoc(), extractCommand.getLineLength()); | ||
this.methodName = Objects.requireNonNull(methodName, "methodName is NULL"); | ||
this.paramTypes = paramTypes; | ||
} | ||
|
||
/** | ||
* @param sourceCodePath Java source file's path. | ||
* @param spaceSize space size for indentation. | ||
* @param methodName method's name that should be extracted from the source code. | ||
* @param withJavaDoc if the JavaDoc should be included or not. | ||
* @param lineLength | ||
* @param paramTypes list of the method argument types in String values. | ||
*/ | ||
public ExtractMethodCommand(String sourceCodePath, int spaceSize, String methodName, boolean withJavaDoc, int lineLength, String... paramTypes) { | ||
super(sourceCodePath, spaceSize, withJavaDoc, lineLength); | ||
this.methodName = Objects.requireNonNull(methodName, "methodName is NULL"); | ||
this.paramTypes = paramTypes; | ||
} | ||
|
||
public String getMethodName() { | ||
return methodName; | ||
} | ||
|
||
public String[] getParamTypes() { | ||
return paramTypes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ExtractMethodCommand{" + | ||
"methodName='" + methodName + '\'' + | ||
", paramTypes=" + Arrays.toString(paramTypes) + | ||
"} " + super.toString(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/rodnansol/asciidoctorj/JavaFieldCodeBlockProcessor.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,42 @@ | ||
package org.rodnansol.asciidoctorj; | ||
|
||
import org.asciidoctor.ast.Document; | ||
import org.asciidoctor.extension.PreprocessorReader; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Code block processor that extracts the field from the given source path. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.1.0 | ||
*/ | ||
public class JavaFieldCodeBlockProcessor implements CodeBlockProcessor { | ||
|
||
private static final String KEY_FIELD = "field"; | ||
|
||
@Override | ||
public boolean isActive(Map<String, Object> attributes) { | ||
return attributes.containsKey(KEY_FIELD); | ||
} | ||
|
||
@Override | ||
public void process(ExtractCommand extractCommand, Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) { | ||
String field = (String) attributes.get(KEY_FIELD); | ||
if (field != null && !field.isEmpty()) { | ||
try { | ||
String fullField = JavaSourceHelper.getField(new ExtractFieldCommand(extractCommand, field)); | ||
reader.pushInclude( | ||
fullField, | ||
target, | ||
new File(".").getAbsolutePath(), | ||
1, | ||
attributes); | ||
} catch (IOException e) { | ||
throw new JavaSourceCodeExtractionException("Unable to extract field with name:[" + field + "]", e); | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/rodnansol/asciidoctorj/JavaMethodCodeBlockProcessor.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,44 @@ | ||
package org.rodnansol.asciidoctorj; | ||
|
||
import org.asciidoctor.ast.Document; | ||
import org.asciidoctor.extension.PreprocessorReader; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Code block processor that extract the method from the given source path. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.1.0 | ||
*/ | ||
public class JavaMethodCodeBlockProcessor implements CodeBlockProcessor { | ||
|
||
private static final String KEY_METHOD = "method"; | ||
private static final String KEY_METHOD_PARAM_TYPES = "types"; | ||
|
||
@Override | ||
public boolean isActive(Map<String, Object> attributes) { | ||
return attributes.containsKey(KEY_METHOD); | ||
} | ||
|
||
@Override | ||
public void process(ExtractCommand extractCommand, Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) { | ||
String method = (String) attributes.get(KEY_METHOD); | ||
try { | ||
String paramTypeList = (String) attributes.getOrDefault(KEY_METHOD_PARAM_TYPES, ""); | ||
String[] paramTypes = paramTypeList.split(","); | ||
String fullMethod = JavaSourceHelper.getMethod(new ExtractMethodCommand(extractCommand, method, paramTypes)); | ||
|
||
reader.pushInclude( | ||
fullMethod, | ||
target, | ||
new File(".").getAbsolutePath(), | ||
1, | ||
attributes); | ||
} catch (IOException e) { | ||
throw new JavaSourceCodeExtractionException("Unable to extract method with name:[" + method + "]", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.