diff --git a/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/DocumentConversionRegistry.java b/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/DocumentConversionRegistry.java index 2a14a03..35f1a92 100644 --- a/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/DocumentConversionRegistry.java +++ b/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/DocumentConversionRegistry.java @@ -1,7 +1,8 @@ package com.blamejared.crafttweaker.annotation.processor.document.conversion.converter; import com.blamejared.crafttweaker.annotation.processor.document.DocumentRegistry; -import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.event.EventConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.event.NamedEventConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.event.NativeEventConverter; import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.expansion.ExpansionConverter; import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.named_type.NamedTypeConverter; import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.native_registration.NativeRegistrationConverter; @@ -24,7 +25,8 @@ public DocumentConversionRegistry(DocumentRegistry documentRegistry, DependencyC this.documentRegistry = documentRegistry; // // TODO: Add converters - converters.add((dependencyContainer.getInstanceOfClass(EventConverter.class))); + converters.add((dependencyContainer.getInstanceOfClass(NativeEventConverter.class))); + converters.add((dependencyContainer.getInstanceOfClass(NamedEventConverter.class))); converters.add(dependencyContainer.getInstanceOfClass(NativeRegistrationConverter.class)); converters.add(dependencyContainer.getInstanceOfClass(ExpansionConverter.class)); converters.add(dependencyContainer.getInstanceOfClass(NamedTypeConverter.class)); diff --git a/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/NamedEventConverter.java b/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/NamedEventConverter.java new file mode 100644 index 0000000..3f06f4a --- /dev/null +++ b/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/NamedEventConverter.java @@ -0,0 +1,133 @@ +package com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.event; + +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.DocumentConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.comment.CommentConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.member.EnumConstantConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.member.header.GenericParameterConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.member.static_member.StaticMemberConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.named_type.ImplementationConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.named_type.SuperTypeConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.converter.named_type.member.NamedTypeVirtualMemberConverter; +import com.blamejared.crafttweaker.annotation.processor.document.conversion.mods.KnownModList; +import com.blamejared.crafttweaker.annotation.processor.document.page.info.DocumentationPageInfo; +import com.blamejared.crafttweaker.annotation.processor.document.page.info.TypeName; +import com.blamejared.crafttweaker.annotation.processor.document.page.info.TypePageInfo; +import com.blamejared.crafttweaker.annotation.processor.document.page.member.header.DocumentedGenericParameter; +import com.blamejared.crafttweaker.annotation.processor.document.page.member.header.examples.Example; +import com.blamejared.crafttweaker.annotation.processor.document.page.member.static_member.DocumentedStaticMembers; +import com.blamejared.crafttweaker.annotation.processor.document.page.member.virtual_member.DocumentedVirtualMembers; +import com.blamejared.crafttweaker.annotation.processor.document.page.page.DocumentationPage; +import com.blamejared.crafttweaker.annotation.processor.document.page.page.EventPage; +import com.blamejared.crafttweaker.annotation.processor.document.page.type.AbstractTypeInfo; +import com.blamejared.crafttweaker.api.event.ZenEventWrapper; +import org.openzen.zencode.java.ZenCodeType; + +import javax.annotation.Nonnull; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import java.util.List; +import java.util.stream.Collectors; + +public class NamedEventConverter extends DocumentConverter { + + private final GenericParameterConverter genericParameterConverter; + private final SuperTypeConverter superTypeConverter; + private final NamedTypeVirtualMemberConverter namedTypeVirtualMemberConverter; + private final ImplementationConverter implementationConverter; + private final StaticMemberConverter staticMemberConverter; + private final EnumConstantConverter enumConstantConverter; + + public NamedEventConverter(KnownModList knownModList, CommentConverter commentConverter, GenericParameterConverter genericParameterConverter, SuperTypeConverter superTypeConverter, NamedTypeVirtualMemberConverter namedTypeVirtualMemberConverter, ImplementationConverter implementationConverter, StaticMemberConverter staticMemberConverter, EnumConstantConverter enumConstantConverter) { + + super(knownModList, commentConverter); + + this.genericParameterConverter = genericParameterConverter; + this.superTypeConverter = superTypeConverter; + this.namedTypeVirtualMemberConverter = namedTypeVirtualMemberConverter; + this.implementationConverter = implementationConverter; + this.staticMemberConverter = staticMemberConverter; + this.enumConstantConverter = enumConstantConverter; + } + + @Override + public boolean canConvert(TypeElement typeElement) { + + return typeElement.getAnnotation(ZenCodeType.Name.class) != null && ZenEventWrapper.isAnnotated(typeElement); + } + + @Override + protected DocumentationPageInfo prepareConversion(TypeElement element) { + + final DocumentationPageInfo documentationPageInfo = super.prepareConversion(element); + + final TypeName name = getName(element); + final String declaringModId = documentationPageInfo.declaringModId; + final String outputPath = documentationPageInfo.getOutputPath(); + return new TypePageInfo(declaringModId, outputPath, name); + } + + @Nonnull + private TypeName getName(TypeElement element) { + + return new TypeName(element.getAnnotation(ZenCodeType.Name.class).value()); + } + + private boolean isEnum(TypeElement element) { + + return element.getKind() == ElementKind.ENUM; + } + + @Override + protected Example getFallbackThisInformationFor(TypeElement typeElement) { + + final String text = "my" + getName(typeElement).getSimpleName(); + return new Example("this", text); + } + + @Override + public DocumentationPage convert(TypeElement typeElement, DocumentationPageInfo pageInfo) { + + final TypePageInfo typePageInfo = (TypePageInfo) pageInfo; + final DocumentedVirtualMembers virtualMembers = convertVirtualMembers(typeElement, typePageInfo); + final DocumentedStaticMembers staticMembers = convertStaticMembers(typeElement, typePageInfo); + final AbstractTypeInfo superType = convertSuperType(typeElement); + final List implementations = convertImplementations(typeElement); + final List genericParameters = convertGenericParameters(typeElement); + + return new EventPage(typePageInfo, virtualMembers, superType, implementations, staticMembers, genericParameters); + } + + private DocumentedVirtualMembers convertVirtualMembers(TypeElement typeElement, TypePageInfo typePageInfo) { + + return namedTypeVirtualMemberConverter.convertFor(typeElement, typePageInfo); + } + + private DocumentedStaticMembers convertStaticMembers(TypeElement typeElement, TypePageInfo typePageInfo) { + + return staticMemberConverter.convertFor(typeElement, typePageInfo); + } + + private AbstractTypeInfo convertSuperType(TypeElement typeElement) { + + if(isEnum(typeElement)) { + // we should not print redundant information "extending Enum" + return null; + } + + return superTypeConverter.convertSuperTypeFor(typeElement).orElse(null); + } + + private List convertImplementations(TypeElement typeElement) { + + return implementationConverter.convertInterfacesFor(typeElement); + } + + private List convertGenericParameters(TypeElement typeElement) { + + return typeElement.getTypeParameters() + .stream() + .map(genericParameterConverter::convertGenericParameter) + .collect(Collectors.toList()); + } + +} \ No newline at end of file diff --git a/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/EventConverter.java b/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/NativeEventConverter.java similarity index 94% rename from src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/EventConverter.java rename to src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/NativeEventConverter.java index f13993d..d96bfce 100644 --- a/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/EventConverter.java +++ b/src/main/java/com/blamejared/crafttweaker/annotation/processor/document/conversion/converter/event/NativeEventConverter.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.stream.Collectors; -public class EventConverter extends DocumentConverter { +public class NativeEventConverter extends DocumentConverter { private final StaticMemberConverter staticMemberConverter; private final NativeTypeVirtualMemberConverter virtualMemberConverter; @@ -40,7 +40,7 @@ public class EventConverter extends DocumentConverter { private final ClassTypeConverter classTypeConverter; private final EnumConstantConverter enumConstantConverter; - public EventConverter(KnownModList knownModList, CommentConverter commentConverter, StaticMemberConverter staticMemberConverter, NativeTypeVirtualMemberConverter virtualMemberConverter, SuperTypeConverter superTypeConverter, ImplementationConverter implementationConverter, GenericParameterConverter genericParameterConverter, NativeConversionRegistry nativeConversionRegistry, Types typeUtils, ClassTypeConverter classTypeConverter, EnumConstantConverter enumConstantConverter) { + public NativeEventConverter(KnownModList knownModList, CommentConverter commentConverter, StaticMemberConverter staticMemberConverter, NativeTypeVirtualMemberConverter virtualMemberConverter, SuperTypeConverter superTypeConverter, ImplementationConverter implementationConverter, GenericParameterConverter genericParameterConverter, NativeConversionRegistry nativeConversionRegistry, Types typeUtils, ClassTypeConverter classTypeConverter, EnumConstantConverter enumConstantConverter) { super(knownModList, commentConverter); this.staticMemberConverter = staticMemberConverter;