Skip to content

Commit

Permalink
suppress deprecation warnings in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrifonov committed Jun 13, 2019
1 parent 72a44e4 commit fb4a91d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions test-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ task addDependenciesFromAppResourcesLibraries {
}
}

// Uncomment the code bellow to get detailed deprecation warnings
//tasks.withType(JavaCompile) {
// options.compilerArgs << '-Xlint:unchecked'
// options.deprecation = true
//}

tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
if (currentTask =~ /generate.+BuildConfig/) {
currentTask.finalizedBy(extractAllJars)
Expand Down
1 change: 1 addition & 0 deletions test-app/app/src/debug/java/com/tns/ErrorReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ private class Pager extends FragmentStatePagerAdapter {

int tabCount;

@SuppressWarnings("deprecation")
public Pager(FragmentManager fm, int tabCount) {
super(fm);
this.tabCount = tabCount;
Expand Down
6 changes: 4 additions & 2 deletions test-app/app/src/main/java/com/tns/DefaultExtractPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

import androidx.core.content.pm.PackageInfoCompat;

import com.tns.Logger;
import com.tns.ExtractPolicy;
import com.tns.FileExtractor;
Expand Down Expand Up @@ -67,9 +69,9 @@ public String getAssetsThumb(Context context) {
private String generateAssetsThumb(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
int code = packageInfo.versionCode;
long code = PackageInfoCompat.getLongVersionCode(packageInfo);
long updateTime = packageInfo.lastUpdateTime;
return String.valueOf(updateTime) + "-" + String.valueOf(code);
return updateTime + "-" + code;
} catch (NameNotFoundException e) {
logger.write("Error while getting current assets thumb");
e.printStackTrace();
Expand Down
6 changes: 4 additions & 2 deletions test-app/app/src/main/java/com/tns/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;

import androidx.core.content.pm.PackageInfoCompat;

public final class Util {
private Util() {
}

public static String getDexThumb(Context context) throws NameNotFoundException {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
int code = packageInfo.versionCode;
long code = PackageInfoCompat.getLongVersionCode(packageInfo);
long updateTime = packageInfo.lastUpdateTime;
return String.valueOf(updateTime) + "-" + String.valueOf(code);
return updateTime + "-" + code;
}

public static boolean isDebuggableApp(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.apache.bcel.generic.Type;
import org.nativescript.staticbindinggenerator.DefaultValues;
import org.nativescript.staticbindinggenerator.Generator;
import org.nativescript.staticbindinggenerator.Writer;
import org.nativescript.staticbindinggenerator.generating.parsing.methods.ReifiedJavaMethod;
import org.nativescript.staticbindinggenerator.generating.writing.MethodsWriter;
import org.nativescript.staticbindinggenerator.naming.BcelNamingUtil;

import java.util.Arrays;
import java.util.List;

public class MethodsWriterImpl implements MethodsWriter {
Expand Down Expand Up @@ -228,7 +230,25 @@ private void writeIfStatementBeginning(String condition) {
writer.write(CLOSING_ROUND_BRACKET_LITERAL);
}

private boolean isMethodDeprecated(ReifiedJavaMethod method) {
return Arrays.stream(
method
.getMethod()
.getAttributes())
.anyMatch(x ->
x.getClass()
.isAssignableFrom(org.apache.bcel.classfile.Deprecated.class));
}

private void writeSuppressDeprecationsToWriter() {
writer.writeln("@SuppressWarnings( \"deprecation\" )");
}

private void writeMethodSignature(ReifiedJavaMethod method) {
if(isMethodDeprecated(method)) {
writeSuppressDeprecationsToWriter();
}

writer.write(getMethodVisibilityModifier(method));
writer.write(SPACE_LITERAL);
writer.write(method.getOwnGenericArgumentsDeclaration());
Expand Down

0 comments on commit fb4a91d

Please sign in to comment.