-
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.
- Loading branch information
1 parent
8f0489f
commit 4b7359a
Showing
3 changed files
with
139 additions
and
4 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
133 changes: 133 additions & 0 deletions
133
...tweaker/annotation/processor/document/conversion/converter/event/NamedEventConverter.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,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<AbstractTypeInfo> implementations = convertImplementations(typeElement); | ||
final List<DocumentedGenericParameter> 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<E>" | ||
return null; | ||
} | ||
|
||
return superTypeConverter.convertSuperTypeFor(typeElement).orElse(null); | ||
} | ||
|
||
private List<AbstractTypeInfo> convertImplementations(TypeElement typeElement) { | ||
|
||
return implementationConverter.convertInterfacesFor(typeElement); | ||
} | ||
|
||
private List<DocumentedGenericParameter> convertGenericParameters(TypeElement typeElement) { | ||
|
||
return typeElement.getTypeParameters() | ||
.stream() | ||
.map(genericParameterConverter::convertGenericParameter) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
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