Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd85660e authored by Paul Duffin's avatar Paul Duffin Committed by Android (Google) Code Review
Browse files

Merge "aapt2: Use android.annotation.Hide instead of @hide" into main

parents f0f7b0fc 0a2e8716
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ struct AnnotationRule {
    kSystemApi = 0x02,
    kTestApi = 0x04,
    kFlaggedApi = 0x08,
    kHide = 0x10,
  };

  StringPiece doc_str;
@@ -58,10 +59,11 @@ struct AnnotationRule {
  bool preserve_params;
};

static std::array<AnnotationRule, 3> sAnnotationRules = {{
static std::array<AnnotationRule, 4> sAnnotationRules = {{
    {"@SystemApi", AnnotationRule::kSystemApi, "@android.annotation.SystemApi", true},
    {"@TestApi", AnnotationRule::kTestApi, "@android.annotation.TestApi", false},
    {"@FlaggedApi", AnnotationRule::kFlaggedApi, "@android.annotation.FlaggedApi", true},
    {"@hide", AnnotationRule::kHide, "@android.annotation.Hide", false},
}};

void AnnotationProcessor::AppendCommentLine(std::string comment, bool add_api_annotations) {
+32 −0
Original line number Diff line number Diff line
@@ -121,6 +121,38 @@ TEST(AnnotationProcessorTest, EmitsTestApiAnnotationAndRemovesFromComment) {
  EXPECT_THAT(annotations, HasSubstr("This is a test API"));
}

TEST(AnnotationProcessorTest, EmitsHideAnnotationAndRemovesFromComment) {
  AnnotationProcessor processor;
  processor.AppendComment("@hide This is an internal API");

  std::string annotations;
  StringOutputStream out(&annotations);
  Printer printer(&out);
  processor.Print(&printer);
  out.Flush();

  EXPECT_THAT(annotations, HasSubstr("@android.annotation.Hide"));
  EXPECT_THAT(annotations, Not(HasSubstr("@hide")));
  EXPECT_THAT(annotations, HasSubstr("This is an internal API"));
}

TEST(AnnotationProcessorTest, EmitsSystemApiAndHideAnnotationAndRemovesFromComment) {
  AnnotationProcessor processor;
  processor.AppendComment("@SystemApi @hide This is a system API");

  std::string annotations;
  StringOutputStream out(&annotations);
  Printer printer(&out);
  processor.Print(&printer);
  out.Flush();

  EXPECT_THAT(annotations, HasSubstr("@android.annotation.SystemApi"));
  EXPECT_THAT(annotations, Not(HasSubstr("@SystemApi")));
  EXPECT_THAT(annotations, HasSubstr("@android.annotation.Hide"));
  EXPECT_THAT(annotations, Not(HasSubstr("@hide")));
  EXPECT_THAT(annotations, HasSubstr("This is a system API"));
}

TEST(AnnotationProcessorTest, NotEmitSystemApiAnnotation) {
  AnnotationProcessor processor;
  processor.AppendComment("@SystemApi This is a system API");
+1 −1
Original line number Diff line number Diff line
@@ -449,7 +449,7 @@ TEST(JavaClassGeneratorTest, CommentsForStyleableHiddenAttributesAreNotPresent)
  EXPECT_THAT(output, Not(HasSubstr("@see #Container_one")));
  EXPECT_THAT(output, HasSubstr("attr name android:one"));
  EXPECT_THAT(output, HasSubstr("attr description"));
  EXPECT_THAT(output, HasSubstr(attr.GetComment()));
  EXPECT_THAT(output, HasSubstr("This is an attribute"));
  EXPECT_THAT(output, HasSubstr(styleable.GetComment()));
}

+3 −3
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ TEST(ManifestClassGeneratorTest, CommentsAndAnnotationsArePresent) {
             @hide
             @SystemApi -->
        <permission android:name="android.permission.SECRET" />
        <!-- @TestApi This is a test only permission. -->
        <!-- @hide @TestApi This is a test only permission. -->
        <permission android:name="android.permission.TEST_ONLY" />
      </manifest>)");

@@ -112,9 +112,9 @@ TEST(ManifestClassGeneratorTest, CommentsAndAnnotationsArePresent) {

  const char* expected_secret = R"(    /**
     * This is a private permission for system only!
     * @hide
     */
    @android.annotation.SystemApi
    @android.annotation.Hide
    public static final String SECRET="android.permission.SECRET";)";
  EXPECT_THAT(actual, HasSubstr(expected_secret));

@@ -122,6 +122,7 @@ TEST(ManifestClassGeneratorTest, CommentsAndAnnotationsArePresent) {
     * This is a test only permission.
     */
    @android.annotation.TestApi
    @android.annotation.Hide
    public static final String TEST_ONLY="android.permission.TEST_ONLY";)";
  EXPECT_THAT(actual, HasSubstr(expected_test));
}
@@ -163,7 +164,6 @@ TEST(ManifestClassGeneratorTest, CommentsAndAnnotationsArePresentButNoApiAnnotat

  const char* expected_secret = R"(    /**
     * This is a private permission for system only!
     * @hide
     */
    public static final String SECRET="android.permission.SECRET";)";
  EXPECT_THAT(actual, HasSubstr(expected_secret));