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.CtField; 9 import spoon.reflect.declaration.CtPackage; 10 import spoon.reflect.declaration.CtSimpleType; 11 import spoon.reflect.reference.CtTypeReference; 12 13 public abstract class CtSimpleTypeImpl<T> extends CtNamedElementImpl implements 14 CtSimpleType<T> { 15 16 List <CtField<?>> fields = new ArrayList <CtField<?>>(); 17 18 Set <CtSimpleType<?>> nestedTypes = new TreeSet <CtSimpleType<?>>(); 19 20 public Class <T> getActualClass() { 21 return getFactory().Type().createReference(this).getActualClass(); 22 } 23 24 public List <CtField<?>> getAllFields() { 25 return getFields(); 26 } 27 28 public CtSimpleType<?> getDeclaringType() { 29 if (parent instanceof CtSimpleType) { 30 return (CtSimpleType) parent; 31 } else { 32 return null; 33 } 34 } 35 36 public CtField<?> getField(String name) { 37 for (CtField<?> f : fields) { 38 if (f.getSimpleName().equals(name)) { 39 return f; 40 } 41 } 42 return null; 43 } 44 45 public List <CtField<?>> getFields() { 46 return fields; 47 } 48 49 public CtSimpleType<?> getNestedType(String name) { 50 for (CtSimpleType<?> t : nestedTypes) { 51 if (t.getSimpleName().equals(name)) { 52 return t; 53 } 54 } 55 return null; 56 } 57 58 public Set <CtSimpleType<?>> getNestedTypes() { 59 return nestedTypes; 60 } 61 62 public CtPackage getPackage() { 63 if (parent instanceof CtPackage) { 64 return (CtPackage) parent; 65 } else if (parent instanceof CtSimpleType) { 66 return ((CtSimpleType<?>) parent).getPackage(); 67 } else { 68 return null; 69 } 70 } 71 72 public String getQualifiedName() { 73 if (getPackage() != null 74 && !getPackage().getSimpleName().equals( 75 CtPackage.TOP_LEVEL_PACKAGE_NAME)) { 76 return getPackage().getQualifiedName() + "." + getSimpleName(); 77 } 78 return getSimpleName(); 79 } 80 81 @Override 82 public CtTypeReference<T> getReference() { 83 return getFactory().Type().createReference(this); 84 } 85 86 public boolean isTopLevel() { 87 return getDeclaringType() == null && getPackage() != null; 88 } 89 90 public void setFields(List <CtField<?>> fields) { 91 this.fields = fields; 92 } 93 94 public void setNestedTypes(Set <CtSimpleType<?>> nestedTypes) { 95 this.nestedTypes = nestedTypes; 96 } 97 } 98 | Popular Tags |