Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from kindlich/feature/native_types/document_pro…
…cessor (6) Feature/native types/document processor
- Loading branch information
Showing
147 changed files
with
6,669 additions
and
2,736 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
25 changes: 0 additions & 25 deletions
25
...n/java/com/blamejared/crafttweaker_annotation_processors/processors/ReflectionReader.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...crafttweaker_annotation_processors/processors/document/CrafttweakerDocumentationPage.java
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
.../blamejared/crafttweaker_annotation_processors/processors/document/DocumentProcessor.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,116 @@ | ||
package com.blamejared.crafttweaker_annotation_processors.processors.document; | ||
|
||
import com.blamejared.crafttweaker_annotation_processors.processors.document.conversion.ElementConverter; | ||
import com.blamejared.crafttweaker_annotation_processors.processors.document.conversion.element.KnownElementList; | ||
import com.blamejared.crafttweaker_annotation_processors.processors.document.conversion.mods.KnownModList; | ||
import com.blamejared.crafttweaker_annotation_processors.processors.document.dependencies.DependencyContainer; | ||
import com.blamejared.crafttweaker_annotation_processors.processors.document.dependencies.SingletonDependencyContainer; | ||
import com.blamejared.crafttweaker_annotation_processors.processors.document.file.DocsJsonWriter; | ||
import com.blamejared.crafttweaker_annotation_processors.processors.document.file.PageWriter; | ||
import com.sun.source.util.Trees; | ||
import org.reflections.Reflections; | ||
import org.reflections.util.ClasspathHelper; | ||
import org.reflections.util.ConfigurationBuilder; | ||
|
||
import javax.annotation.processing.*; | ||
import javax.lang.model.SourceVersion; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.util.Elements; | ||
import javax.lang.model.util.Types; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
@SupportedAnnotationTypes({"com.blamejared.crafttweaker_annotations.annotations.Document", "net.minecraftforge.fml.common.Mod"}) | ||
@SupportedSourceVersion(SourceVersion.RELEASE_8) | ||
public class DocumentProcessor extends AbstractProcessor { | ||
|
||
private static final File outputDirectory = new File("docsOut"); | ||
|
||
private final DependencyContainer dependencyContainer = new SingletonDependencyContainer(); | ||
private KnownElementList knownElementList; | ||
private KnownModList knownModList; | ||
|
||
@Override | ||
public synchronized void init(ProcessingEnvironment processingEnv) { | ||
super.init(processingEnv); | ||
setupDependencyContainer(processingEnv); | ||
|
||
knownElementList = dependencyContainer.getInstanceOfClass(KnownElementList.class); | ||
knownModList = dependencyContainer.getInstanceOfClass(KnownModList.class); | ||
} | ||
|
||
private void setupDependencyContainer(ProcessingEnvironment processingEnv) { | ||
dependencyContainer.addInstanceAs(dependencyContainer, DependencyContainer.class); | ||
dependencyContainer.addInstanceAs(processingEnv, ProcessingEnvironment.class); | ||
dependencyContainer.addInstanceAs(processingEnv.getMessager(), Messager.class); | ||
dependencyContainer.addInstanceAs(processingEnv.getElementUtils(), Elements.class); | ||
dependencyContainer.addInstanceAs(processingEnv.getTypeUtils(), Types.class); | ||
|
||
setupTrees(processingEnv); | ||
setupReflections(); | ||
} | ||
|
||
private void setupReflections() { | ||
final ConfigurationBuilder configuration = new ConfigurationBuilder().addUrls(ClasspathHelper | ||
.forJavaClassPath()) | ||
.addClassLoaders(ClasspathHelper.contextClassLoader(), ClasspathHelper.staticClassLoader(), getClass() | ||
.getClassLoader()) | ||
.addUrls(ClasspathHelper.forClassLoader()); | ||
|
||
final Reflections reflections = new Reflections(configuration); | ||
dependencyContainer.addInstanceAs(reflections, Reflections.class); | ||
} | ||
|
||
private void setupTrees(ProcessingEnvironment processingEnv) { | ||
final Trees instance = Trees.instance(processingEnv); | ||
dependencyContainer.addInstanceAs(instance, Trees.class); | ||
} | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
if(roundEnv.processingOver()) { | ||
handleLastRound(); | ||
} else { | ||
handleIntermediateRound(roundEnv); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public void handleIntermediateRound(RoundEnvironment roundEnvironment) { | ||
knownModList.fillModIdInfo(roundEnvironment); | ||
knownElementList.addAllForIntermediateRound(roundEnvironment); | ||
} | ||
|
||
public void handleLastRound() { | ||
convertPages(); | ||
writePages(); | ||
writeDocsJsonFile(); | ||
} | ||
|
||
private void writeDocsJsonFile() { | ||
final DocumentRegistry documentRegistry = dependencyContainer.getInstanceOfClass(DocumentRegistry.class); | ||
final DocsJsonWriter docsJsonWriter = new DocsJsonWriter(outputDirectory, documentRegistry); | ||
try { | ||
docsJsonWriter.write(); | ||
} catch(IOException exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
|
||
private void convertPages() { | ||
final ElementConverter elementConverter = dependencyContainer.getInstanceOfClass(ElementConverter.class); | ||
elementConverter.handleElements(knownElementList); | ||
} | ||
|
||
private void writePages() { | ||
final DocumentRegistry documentRegistry = dependencyContainer.getInstanceOfClass(DocumentRegistry.class); | ||
final PageWriter pageWriter = new PageWriter(documentRegistry, new File(outputDirectory, "docs")); | ||
try { | ||
pageWriter.write(); | ||
} catch(IOException exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
} |
Oops, something went wrong.