-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not remove annotations that are members of annotations referenced …
…from code Reviewed By: thezhangwei, ssj933 Differential Revision: D66399299 fbshipit-source-id: 020a3c88a73fe48dbe9d32101799c57bf986fda2
- Loading branch information
1 parent
b00898a
commit ad4e79d
Showing
4 changed files
with
132 additions
and
0 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
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 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.redex; | ||
|
||
@interface Funny { | ||
|
||
} | ||
|
||
@interface VeryFunny { | ||
|
||
} | ||
|
||
@interface Zero { | ||
// This is a field on an annotation. Why someone would do this, I don't know. | ||
Funny f = null; | ||
VeryFunny[] a = null; | ||
} | ||
|
||
@interface One { | ||
int x() default 10; | ||
Zero zero(); | ||
} | ||
|
||
@interface Two { | ||
int y(); | ||
One[] one() default {}; | ||
} | ||
|
||
@interface Unused { | ||
int z(); | ||
} | ||
|
||
@Two(y = 1) | ||
class Use {} | ||
|
||
class Main { | ||
public static void go() { | ||
System.out.println(Two.class); | ||
} | ||
} |
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,29 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <gmock/gmock.h> | ||
|
||
#include "Show.h" | ||
#include "verify/VerifyUtil.h" | ||
|
||
using namespace testing; | ||
|
||
TEST_F(PostVerify, VerifyKeptAndRemoved) { | ||
EXPECT_EQ(find_class_named(classes, "Lcom/redex/Unused;"), nullptr) | ||
<< "Should remove type Unused"; | ||
EXPECT_NE(find_class_named(classes, "Lcom/redex/Two;"), nullptr) | ||
<< "Should not remove Two! It has a code reference."; | ||
EXPECT_NE(find_class_named(classes, "Lcom/redex/One;"), nullptr) | ||
<< "Should not remove One! Otherwise we'll have a torn enum, and that's " | ||
"bad :p"; | ||
EXPECT_NE(find_class_named(classes, "Lcom/redex/Zero;"), nullptr) | ||
<< "Should not remove Zero!"; | ||
EXPECT_NE(find_class_named(classes, "Lcom/redex/Funny;"), nullptr) | ||
<< "Should not remove Funny! It is referenced from a static field."; | ||
EXPECT_NE(find_class_named(classes, "Lcom/redex/VeryFunny;"), nullptr) | ||
<< "Should not remove VeryFunny! It is referenced from a static field."; | ||
} |
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,14 @@ | ||
{ | ||
"AnnoKillPass": { | ||
"keep_annos": [ | ||
], | ||
"kill_annos": [ | ||
], | ||
"kill_bad_signatures": true | ||
}, | ||
"redex" : { | ||
"passes" : [ | ||
"AnnoKillPass" | ||
] | ||
} | ||
} |