1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.class2greylist;
17 
18 import java.util.Formatter;
19 import org.apache.bcel.Const;
20 import org.apache.bcel.classfile.FieldOrMethod;
21 import org.apache.bcel.classfile.JavaClass;
22 
23 import java.util.Locale;
24 
25 /**
26  * Encapsulates context for a single annotation on a class member.
27  */
28 public class AnnotatedMemberContext extends AnnotationContext {
29 
30     public final FieldOrMethod member;
31     public final String signatureFormatString;
32 
AnnotatedMemberContext( Status status, JavaClass definingClass, FieldOrMethod member, String signatureFormatString)33     public AnnotatedMemberContext(
34         Status status,
35         JavaClass definingClass,
36         FieldOrMethod member,
37         String signatureFormatString) {
38         super(status, definingClass);
39         this.member = member;
40         this.signatureFormatString = signatureFormatString;
41     }
42 
43     @Override
getMemberDescriptor()44     public String getMemberDescriptor() {
45         return String.format(Locale.US, signatureFormatString,
46             getClassDescriptor(), member.getName(), member.getSignature());
47     }
48 
49     @Override
reportError(String message, Object... args)50     public void reportError(String message, Object... args) {
51         Formatter error = new Formatter();
52         error
53             .format("%s: %s.%s: ", definingClass.getSourceFileName(),
54                 definingClass.getClassName(), member.getName())
55             .format(Locale.US, message, args);
56 
57         status.error(error.toString());
58     }
59 }
60