1/* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24package selectionresolution; 25 26/** 27 * A representation of a method definition. 28 */ 29public class MethodData { 30 31 public enum Access { 32 PUBLIC(1), 33 PACKAGE(0), 34 PROTECTED(4), 35 PRIVATE(2), 36 /** 37 * Placeholder, used solely for printing out the effects of 38 * templates. Don't use. 39 */ 40 PLACEHOLDER(-1); 41 42 public final int flag; 43 44 Access(int flag) { 45 this.flag = flag; 46 } 47 } 48 49 public enum Context { 50 ABSTRACT, 51 INSTANCE, 52 STATIC, 53 /** 54 * Placeholder, used solely for printing out the effects of 55 * templates. Don't use. 56 */ 57 PLACEHOLDER; 58 }; 59 60 /** 61 * Access for the method. 62 */ 63 public final Access access; 64 65 /** 66 * Context (static, instance, abstract) for the method. 67 */ 68 public final Context context; 69 70 /** 71 * Create method data. 72 */ 73 public MethodData(final Access access, 74 final Context context) { 75 76 this.access = access; 77 this.context = context; 78 } 79 80 public String toString() { 81 StringBuilder sb = new StringBuilder(); 82 switch (access) { 83 case PUBLIC: sb.append("public"); break; 84 case PACKAGE: sb.append("package"); break; 85 case PROTECTED: sb.append("protected"); break; 86 case PRIVATE: sb.append("private"); break; 87 case PLACEHOLDER: sb.append(" _"); break; 88 default: throw new RuntimeException("Impossible case"); 89 } 90 91 switch (context) { 92 case STATIC: sb.append(" static"); break; 93 case INSTANCE: sb.append(" instance"); break; 94 case ABSTRACT: sb.append(" abstract"); break; 95 case PLACEHOLDER: sb.append(" _"); break; 96 default: throw new RuntimeException("Impossible case"); 97 } 98 sb.append(" Integer m();"); 99 100 return sb.toString(); 101 } 102 103} 104