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 java.util.Locale; 20 import org.apache.bcel.Const; 21 import org.apache.bcel.classfile.FieldOrMethod; 22 import org.apache.bcel.classfile.JavaClass; 23 24 /** 25 * Encapsulates context for a single annotation on a class. 26 */ 27 public class AnnotatedClassContext extends AnnotationContext { 28 29 public final String signatureFormatString; 30 AnnotatedClassContext( Status status, JavaClass definingClass, String signatureFormatString)31 public AnnotatedClassContext( 32 Status status, 33 JavaClass definingClass, 34 String signatureFormatString) { 35 super(status, definingClass); 36 this.signatureFormatString = signatureFormatString; 37 } 38 39 @Override getMemberDescriptor()40 public String getMemberDescriptor() { 41 return String.format(Locale.US, signatureFormatString, getClassDescriptor()); 42 } 43 44 @Override reportError(String message, Object... args)45 public void reportError(String message, Object... args) { 46 Formatter error = new Formatter(); 47 error 48 .format("%s: %s: ", definingClass.getSourceFileName(), definingClass.getClassName()) 49 .format(Locale.US, message, args); 50 51 status.error(error.toString()); 52 } 53 54 } 55