1 /* 2 * Copyright (C) 2009 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 17 package signature.model.impl; 18 19 import java.io.Serializable; 20 21 import signature.model.IMethod; 22 import signature.model.ITypeReference; 23 import signature.model.Modifier; 24 import signature.model.util.ModelUtil; 25 26 @SuppressWarnings("serial") 27 public class SigMethod extends SigExecutableMember implements IMethod, 28 Serializable { 29 30 private ITypeReference returnType = Uninitialized.unset(); 31 32 public SigMethod(String name) { 33 super(name); 34 } 35 36 37 public ITypeReference getReturnType() { 38 return returnType; 39 } 40 41 public void setReturnType(ITypeReference returnType) { 42 this.returnType = returnType; 43 } 44 45 @Override 46 public String toString() { 47 return SigMethod.toString(this); 48 } 49 50 public static String toString(IMethod method) { 51 StringBuilder builder = new StringBuilder(); 52 builder.append(Modifier.toString(method.getModifiers())); 53 builder.append(method.getReturnType()); 54 builder.append(" "); 55 if (method.getTypeParameters() != null 56 && !method.getTypeParameters().isEmpty()) { 57 builder.append("<"); 58 builder 59 .append(ModelUtil 60 .separate(method.getTypeParameters(), ", ")); 61 builder.append("> "); 62 } 63 builder.append(method.getName()); 64 builder.append("("); 65 builder.append(method.getParameters().isEmpty() ? "" : ModelUtil 66 .separate(method.getParameters(), ", ")); 67 builder.append(")"); 68 if (method.getExceptions() != null 69 && !method.getExceptions().isEmpty()) { 70 builder.append(" throws "); 71 builder.append(ModelUtil.separate(method.getExceptions(), " ")); 72 } 73 return builder.toString(); 74 } 75 } 76