001: /*
002: * Spoon - http://spoon.gforge.inria.fr/
003: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004: *
005: * This software is governed by the CeCILL-C License under French law and
006: * abiding by the rules of distribution of free software. You can use, modify
007: * and/or redistribute the software under the terms of the CeCILL-C license as
008: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013: *
014: * The fact that you are presently reading this means that you have had
015: * knowledge of the CeCILL-C license and that you accept its terms.
016: */
017:
018: package spoon.support.reflect.declaration;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022: import java.util.Set;
023: import java.util.TreeSet;
024:
025: import spoon.reflect.declaration.CtMethod;
026: import spoon.reflect.declaration.CtType;
027: import spoon.reflect.reference.CtTypeReference;
028:
029: /**
030: * The implementation for {@link spoon.reflect.declaration.CtType}.
031: */
032: public abstract class CtTypeImpl<T> extends CtSimpleTypeImpl<T>
033: implements CtType<T> {
034:
035: List<CtTypeReference<?>> formalTypeParameters = new ArrayList<CtTypeReference<?>>();
036:
037: Set<CtTypeReference<?>> interfaces = new TreeSet<CtTypeReference<?>>();
038:
039: Set<CtMethod<?>> methods = new TreeSet<CtMethod<?>>();
040:
041: public CtTypeImpl() {
042: super ();
043: }
044:
045: public List<CtTypeReference<?>> getFormalTypeParameters() {
046: return formalTypeParameters;
047: }
048:
049: @SuppressWarnings("unchecked")
050: public <R> CtMethod<R> getMethod(CtTypeReference<R> returnType,
051: String name, CtTypeReference<?>... parameterTypes) {
052: for (CtMethod mm : methods) {
053: CtMethod<R> m = mm;
054: if (m.getSimpleName().equals(name)) {
055: if (!m.getType().equals(returnType)) {
056: continue;
057: }
058: boolean cont = m.getParameters().size() == parameterTypes.length;
059: for (int i = 0; cont && (i < m.getParameters().size())
060: && (i < parameterTypes.length); i++) {
061: if (!m.getParameters().get(i).getType()
062: .getQualifiedName().equals(
063: parameterTypes[i]
064: .getQualifiedName())) {
065: cont = false;
066: }
067: }
068: if (cont) {
069: return m;
070: }
071: }
072: }
073: return null;
074: }
075:
076: public CtMethod<?> getMethod(String name,
077: CtTypeReference<?>... parameterTypes) {
078: for (CtMethod<?> m : methods) {
079: if (m.getSimpleName().equals(name)) {
080: boolean cont = m.getParameters().size() == parameterTypes.length;
081: for (int i = 0; cont && (i < m.getParameters().size())
082: && (i < parameterTypes.length); i++) {
083: // String
084: // s1=m.getParameters().get(i).getType().getQualifiedName();
085: // String s2=parameterTypes[i].getQualifiedName();
086: if (!m.getParameters().get(i).getType().equals(
087: parameterTypes[i])) {
088: cont = false;
089: }
090: }
091: if (cont) {
092: return m;
093: }
094: }
095: }
096: return null;
097: }
098:
099: public Set<CtMethod<?>> getMethods() {
100: return methods;
101: }
102:
103: @Override
104: public String getQualifiedName() {
105: if (isTopLevel()) {
106: return super .getQualifiedName();
107: }
108: if (getDeclaringType() != null) {
109: return getDeclaringType().getQualifiedName()
110: + INNERTTYPE_SEPARATOR + getSimpleName();
111: }
112: return getSimpleName();
113: }
114:
115: public Set<CtTypeReference<?>> getSuperInterfaces() {
116: return interfaces;
117: }
118:
119: public void setFormalTypeParameters(
120: List<CtTypeReference<?>> formalTypeParameters) {
121: this .formalTypeParameters = formalTypeParameters;
122: }
123:
124: public void setMethods(Set<CtMethod<?>> methods) {
125: this .methods = methods;
126: }
127:
128: public void setSuperInterfaces(Set<CtTypeReference<?>> interfaces) {
129: this.interfaces = interfaces;
130: }
131:
132: }
|