1 package spoon.support.reflect.declaration; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.Set ; 6 import java.util.TreeSet ; 7 8 import spoon.reflect.declaration.CtMethod; 9 import spoon.reflect.declaration.CtType; 10 import spoon.reflect.reference.CtTypeReference; 11 12 15 public abstract class CtTypeImpl<T> extends CtSimpleTypeImpl<T> implements 16 CtType<T> { 17 18 List <CtTypeReference<?>> formalTypeParameters = new ArrayList <CtTypeReference<?>>(); 19 20 Set <CtTypeReference<?>> interfaces = new TreeSet <CtTypeReference<?>>(); 21 22 Set <CtMethod<?>> methods = new TreeSet <CtMethod<?>>(); 23 24 public CtTypeImpl() { 25 super(); 26 } 27 28 public List <CtTypeReference<?>> getFormalTypeParameters() { 29 return formalTypeParameters; 30 } 31 32 @SuppressWarnings ("unchecked") 33 public <R> CtMethod<R> getMethod(CtTypeReference<R> returnType, 34 String name, CtTypeReference<?>... parameterTypes) { 35 for (CtMethod mm : methods) { 36 CtMethod<R> m = (CtMethod<R>) mm; 37 if (m.getSimpleName().equals(name)) { 38 if (!m.getType().equals(returnType)) 39 continue; 40 boolean cont = m.getParameters().size() == parameterTypes.length; 41 for (int i = 0; cont && i < m.getParameters().size() 42 && i < parameterTypes.length; i++) { 43 if (!m.getParameters().get(i).getType().getQualifiedName() 44 .equals(parameterTypes[i].getQualifiedName())) { 45 cont = false; 46 } 47 } 48 if (cont) { 49 return m; 50 } 51 } 52 } 53 return null; 54 } 55 56 public CtMethod<?> getMethod(String name, 57 CtTypeReference<?>... parameterTypes) { 58 for (CtMethod<?> m : methods) { 59 if (m.getSimpleName().equals(name)) { 60 boolean cont = m.getParameters().size() == parameterTypes.length; 61 for (int i = 0; cont && i < m.getParameters().size() 62 && i < parameterTypes.length; i++) { 63 if (!m.getParameters().get(i).getType().equals(parameterTypes[i])) { 66 cont = false; 67 } 68 } 69 if (cont) { 70 return m; 71 } 72 } 73 } 74 return null; 75 } 76 77 public Set <CtMethod<?>> getMethods() { 78 return methods; 79 } 80 81 @Override 82 public String getQualifiedName() { 83 if (isTopLevel()) 84 return super.getQualifiedName(); 85 if (getDeclaringType() != null) 86 return getDeclaringType().getQualifiedName() + INNERTTYPE_SEPARATOR 87 + getSimpleName(); 88 else 89 return getSimpleName(); 90 } 91 92 public Set <CtTypeReference<?>> getSuperInterfaces() { 93 return interfaces; 94 } 95 96 public void setFormalTypeParameters( 97 List <CtTypeReference<?>> formalTypeParameters) { 98 this.formalTypeParameters = formalTypeParameters; 99 } 100 101 public void setMethods(Set <CtMethod<?>> methods) { 102 this.methods = methods; 103 } 104 105 public void setSuperInterfaces(Set <CtTypeReference<?>> interfaces) { 106 this.interfaces = interfaces; 107 } 108 109 } 110 | Popular Tags |