Skip to content

Commit

Permalink
Add support for validating overwrite annotation javadoc decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Jan 7, 2016
1 parent 853f7bd commit 30e2530
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,25 @@ public void registerOverwrite(ExecutableElement method, AnnotationMirror overwri
String obfName = obfMethod.name.substring(obfMethod.name.lastIndexOf('/') + 1);
this.addMethodMapping(type, mcpName, obfName, mcpSignature, obfMethod.sig);
}

if ("true".equalsIgnoreCase(this.mixins.getOption(SupportedOptions.DISABLE_OVERWRITE_CHECKER))) {
Kind overwriteErrorKind = "error".equalsIgnoreCase(this.mixins.getOption(SupportedOptions.OVERWRITE_ERROR_LEVEL))
? Kind.ERROR : Kind.WARNING;

String javadoc = this.mixins.getJavadoc(method);
if (javadoc == null) {
this.mixins.printMessage(overwriteErrorKind, "@Overwrite is missing javadoc comment", method);
return;
}

if (!javadoc.toLowerCase().contains("@author")) {
this.mixins.printMessage(overwriteErrorKind, "@Overwrite is missing an @author tag", method);
}

if (!javadoc.toLowerCase().contains("@reason")) {
this.mixins.printMessage(overwriteErrorKind, "@Overwrite is missing an @reason tag", method);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,17 @@ public TypeHandle getTypeHandle(String name) {
return null;
}

/**
* Get javadoc on element
*
* @param element Element to fetch javadoc for
* @return javadoc
*/
public String getJavadoc(Element element) {
Elements elements = this.processingEnv.getElementUtils();
return elements.getDocComment(element);
}

/**
* Get the mixin manager instance for this environment
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@

public final class SupportedOptions {

public static final String REOBF_SRG_FILE = "reobfSrgFile";
public static final String REOBF_NOTCH_FILE = "reobfNotchSrgFile";
public static final String OUT_SRG_SRG_FILE = "outSrgFile";
public static final String OUT_NOTCH_SRG_FILE = "outNotchSrgFile";
public static final String OUT_REFMAP_FILE = "outRefMapFile";
public static final String DISABLE_TARGET_VALIDATOR = "disableTargetValidator";
public static final String DISABLE_TARGET_EXPORT = "disableTargetExport";
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";
public static final String REOBF_SRG_FILE = "reobfSrgFile";
public static final String REOBF_NOTCH_FILE = "reobfNotchSrgFile";
public static final String OUT_SRG_SRG_FILE = "outSrgFile";
public static final String OUT_NOTCH_SRG_FILE = "outNotchSrgFile";
public static final String OUT_REFMAP_FILE = "outRefMapFile";
public static final String DISABLE_TARGET_VALIDATOR = "disableTargetValidator";
public static final String DISABLE_TARGET_EXPORT = "disableTargetExport";
public static final String DISABLE_OVERWRITE_CHECKER = "disableOverwriteChecker";
public static final String OVERWRITE_ERROR_LEVEL = "overwriteErrorLevel";
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";

public static final Set<String> all = ImmutableSet.<String>of(
SupportedOptions.REOBF_SRG_FILE,
Expand All @@ -47,6 +49,8 @@ public final class SupportedOptions {
SupportedOptions.OUT_REFMAP_FILE,
SupportedOptions.DISABLE_TARGET_VALIDATOR,
SupportedOptions.DISABLE_TARGET_EXPORT,
SupportedOptions.DISABLE_OVERWRITE_CHECKER,
SupportedOptions.OVERWRITE_ERROR_LEVEL,
SupportedOptions.DEFAULT_OBFUSCATION_ENV
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public MethodData getObfMethod(MemberInfo method) {

// Get a type handle for the declared method owner
TypeHandle type = this.typeProvider.getTypeHandle(method.owner);
if (type.isImaginary()) {
if (type == null || type.isImaginary()) {
return null;
}

Expand Down

0 comments on commit 30e2530

Please sign in to comment.