Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force BEPs to return a specific type
- Loading branch information
Showing
12 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...crafttweaker_annotation_processors/processors/BracketHandlerCheckValidationProcessor.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,45 @@ | ||
package com.blamejared.crafttweaker_annotation_processors.processors; | ||
|
||
import javax.annotation.processing.AbstractProcessor; | ||
import javax.annotation.processing.RoundEnvironment; | ||
import javax.annotation.processing.SupportedAnnotationTypes; | ||
import javax.annotation.processing.SupportedSourceVersion; | ||
import javax.lang.model.SourceVersion; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ExecutableElement; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.element.VariableElement; | ||
import javax.lang.model.type.TypeMirror; | ||
import javax.tools.Diagnostic; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@SupportedAnnotationTypes({"com.blamejared.crafttweaker.api.annotations.BracketResolver"}) | ||
@SupportedSourceVersion(SourceVersion.RELEASE_8) | ||
public class BracketHandlerCheckValidationProcessor extends AbstractProcessor { | ||
private static final String BEPReturnTypeCanonicalName = "com.blamejared.crafttweaker.api.brackets.CommandStringDisplayable"; | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
for (TypeElement annotation : annotations) { | ||
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) { | ||
if(!(element instanceof ExecutableElement)) { | ||
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "How is this annotated?", element); | ||
continue; | ||
} | ||
|
||
ExecutableElement executableElement = (ExecutableElement) element; | ||
final List<? extends VariableElement> parameters = executableElement.getParameters(); | ||
if(parameters.size() != 1 || !this.processingEnv.getTypeUtils().isSameType(parameters.get(0).asType(), this.processingEnv.getElementUtils().getTypeElement(String.class.getCanonicalName()).asType())) { | ||
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Element is annotated as BEP but does not accept a String as its only parameter.", element); | ||
} | ||
|
||
if(!this.processingEnv.getTypeUtils().isAssignable(executableElement.getReturnType(), this.processingEnv.getElementUtils().getTypeElement(BEPReturnTypeCanonicalName).asType())){ | ||
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Element is annotated as BEP but does not return " + BEPReturnTypeCanonicalName + " or any subtype.", element); | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...ion_Processors/src/main/resources/META-INF/services/javax.annotation.processing.Processor
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,2 +1,3 @@ | ||
com.blamejared.crafttweaker_annotation_processors.processors.DocumentProcessor | ||
com.blamejared.crafttweaker_annotation_processors.processors.AsIActionProcessor | ||
com.blamejared.crafttweaker_annotation_processors.processors.AsIActionProcessor | ||
com.blamejared.crafttweaker_annotation_processors.processors.BracketHandlerCheckValidationProcessor |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/blamejared/crafttweaker/api/brackets/CommandStringDisplayable.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,21 @@ | ||
package com.blamejared.crafttweaker.api.brackets; | ||
|
||
import com.blamejared.crafttweaker.api.annotations.ZenRegister; | ||
import com.blamejared.crafttweaker_annotations.annotations.Document; | ||
import org.openzen.zencode.java.ZenCodeType; | ||
|
||
/** | ||
* This is A helper interface for every item that is returned by a BEP! | ||
* | ||
* @docParam this null | ||
*/ | ||
@ZenRegister | ||
@ZenCodeType.Name("crafttweaker.api.brackets.CommandStringDisplayable") | ||
@Document("vanilla/brackets/CommandStringDisplayable") | ||
public interface CommandStringDisplayable { | ||
/** | ||
* Returns the BEP to get this thingy | ||
*/ | ||
@ZenCodeType.Getter("commandString") | ||
String getCommandString(); | ||
} |
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
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
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