com.android.tools.lint.detector.api.LintFix Java Examples

The following examples show how to use com.android.tools.lint.detector.api.LintFix. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MissingSourceDetector.java    From aircon with MIT License 5 votes vote down vote up
private LintFix createFix(final UField node) {
	final LintFix.GroupBuilder groupBuilder = LintFix.create()
	                                                 .group();
	groupBuilder.add(addSourceAnnotationFix(node, "field"));
	groupBuilder.add(addSourceAnnotationFix(node.getUastParent(), "feature interface"));
	return groupBuilder.build();
}
 
Example #2
Source File: PreferStubViewDetector.java    From Folivora with Apache License 2.0 5 votes vote down vote up
@Override
public void visitAttribute(@NotNull XmlContext context, @NotNull Attr attribute) {
  Element tag = attribute.getOwnerElement();
  String tagName = tag.getTagName();
  if (sSystemViewNames.contains(tagName)) {
    LintFix fix = LintFix.create().replace().range(context.getLocation(tag))
      .text(tagName).with("cn.cricin.folivora.view." + tagName).build();
    context.report(ISSUE, context.getLocation(tag),
      "Using cn.cricin.folivora.view." + tagName + " instead to support design time preview", fix);
  }
}
 
Example #3
Source File: IssueFixBuilder.java    From aircon with MIT License 5 votes vote down vote up
private LintFix.ReplaceStringBuilder newReplace() {
	return LintFix.create()
	              .replace()
	              .range(mContext.getLocation(mTarget))
	              .shortenNames()
	              .reformat(true);
}
 
Example #4
Source File: IssueFixBuilder.java    From aircon with MIT License 5 votes vote down vote up
public IssueFixBuilder(JavaContext context, T target, String name) {
	mContext = context;
	mTarget = target;
	mGroupBuilder = LintFix.create()
	                       .composite()
	                       .name(name);
}
 
Example #5
Source File: IssueDetector.java    From aircon with MIT License 5 votes vote down vote up
protected LintFix addAnnotationFix(UElement target, String targetName, Class<? extends Annotation> clazz, String annotationContent) {
	final String source = target.asSourceString();
	return replaceFix(target).name(String.format(ADD_ANNOTATION_FIX_FORMAT, clazz.getSimpleName(), targetName))
	                         .text(source)
	                         .with("@" + clazz.getCanonicalName() + "(" + annotationContent + ")" + source)
	                         .build();
}
 
Example #6
Source File: AuxMethodInvalidSignatureDetector.java    From aircon with MIT License 5 votes vote down vote up
private LintFix getFix(final UMethod node, final boolean staticMethod, JvmModifier visibilityModifier) {
	final MethodFixBuilder methodFixBuilder = new MethodFixBuilder(mContext, node, "Change to " + getModifierName(visibilityModifier) + " static method").setVisibility(visibilityModifier);
	if (!staticMethod) {
		methodFixBuilder.addModifier(JvmModifier.STATIC);
	}
	return methodFixBuilder.build();
}
 
Example #7
Source File: AuxMethodInvalidSignatureDetector.java    From aircon with MIT License 5 votes vote down vote up
private LintFix getFix(final UMethod node, final boolean staticMethod) {
	final LintFix.GroupBuilder builder = LintFix.create()
	                                            .group();
	builder.add(getFix(node, staticMethod, JvmModifier.PACKAGE_LOCAL));
	builder.add(getFix(node, staticMethod, JvmModifier.PUBLIC));
	return builder.build();
}
 
Example #8
Source File: SignalLogDetector.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private LintFix quickFixIssueLog(@NotNull UCallExpression logCall) {
  List<UExpression> arguments  = logCall.getValueArguments();
  String            methodName = logCall.getMethodName();
  UExpression       tag        = arguments.get(0);

  String fixSource = "org.thoughtcrime.securesms.logging.Log.";

  switch (arguments.size()) {
    case 2:
      UExpression msgOrThrowable = arguments.get(1);
      fixSource += String.format("%s(%s, %s)", methodName, tag, msgOrThrowable.asSourceString());
      break;

    case 3:
      UExpression msg = arguments.get(1);
      UExpression throwable = arguments.get(2);
      fixSource += String.format("%s(%s, %s, %s)", methodName, tag, msg.asSourceString(), throwable.asSourceString());
      break;

    default:
      throw new IllegalStateException("Log overloads should have 2 or 3 arguments");
  }

  String logCallSource = logCall.asSourceString();
  LintFix.GroupBuilder fixGrouper = fix().group();
  fixGrouper.add(fix().replace().text(logCallSource).shortenNames().reformat(true).with(fixSource).build());
  return fixGrouper.build();
}
 
Example #9
Source File: ConfigValidatorInvalidSignature.java    From aircon with MIT License 4 votes vote down vote up
private LintFix getFix(final UMethod node) {
	return new MethodFixBuilder(mContext, node, "Change return type to boolean").setReturnType("boolean")
	                                                                            .build();
}
 
Example #10
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void report(final UElement node, LintFix lintFix) {
	report(node, mIssue.getExplanation(TextFormat.RAW), lintFix);
}
 
Example #11
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void report(final UElement node, String desc, LintFix lintFix) {
	if (REPORTED_ISSUES.get(node) != mIssue) {
		REPORTED_ISSUES.put(node, mIssue);
		mContext.report(mIssue, node, mContext.getLocation(node), desc, lintFix);
	}
}
 
Example #12
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void reportPsi(final PsiElement node, LintFix lintFix) {
	reportPsi(node, mIssue.getExplanation(TextFormat.RAW), lintFix);
}
 
Example #13
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void reportPsi(final PsiElement node, String desc, LintFix lintFix) {
	if (REPORTED_PSI_ISSUES.get(node) != mIssue) {
		REPORTED_PSI_ISSUES.put(node, mIssue);
		mContext.report(mIssue, node, mContext.getLocation(node), desc, lintFix);
	}
}
 
Example #14
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected LintFix.ReplaceStringBuilder replaceFix(UElement target) {
	return fix().replace()
	            .range(mContext.getLocation(target))
	            .shortenNames()
	            .reformat(true);
}
 
Example #15
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected LintFix.Builder fix() {
	return LintFix.create();
}
 
Example #16
Source File: InvalidDefaultValueResIdDetector.java    From aircon with MIT License 4 votes vote down vote up
private LintFix getFix(final UAnnotation node, String type, final String rClass) {
	return new AnnotationFixBuilder(mContext, node, "Change to " + type + " resource").setValue(rClass + ".")
	                                                                                  .build();
}
 
Example #17
Source File: MissingSourceDetector.java    From aircon with MIT License 4 votes vote down vote up
private LintFix addSourceAnnotationFix(UElement target, String targetName) {
	return addAnnotationFix(target, targetName, Source.class, "SomeConfigSource.class");
}
 
Example #18
Source File: IssueFixBuilder.java    From aircon with MIT License 4 votes vote down vote up
public LintFix build() {
	return mGroupBuilder.build();
}