use of spoon.reflect.declaration.CtTypeParameter in project spoon by INRIA.
the class TypeFactory method createReference.
/**
* @param includingFormalTypeParameter if true then references to formal type parameters
* are added as actual type arguments of returned {@link CtTypeReference}
*/
public <T> CtTypeReference<T> createReference(CtType<T> type, boolean includingFormalTypeParameter) {
CtTypeReference<T> ref = factory.Core().createTypeReference();
if (type.getDeclaringType() != null) {
ref.setDeclaringType(createReference(type.getDeclaringType(), includingFormalTypeParameter));
} else if (type.getPackage() != null) {
ref.setPackage(factory.Package().createReference(type.getPackage()));
}
ref.setSimpleName(type.getSimpleName());
if (includingFormalTypeParameter) {
for (CtTypeParameter formalTypeParam : type.getFormalCtTypeParameters()) {
ref.addActualTypeArgument(formalTypeParam.getReference());
}
}
return ref;
}
use of spoon.reflect.declaration.CtTypeParameter in project spoon by INRIA.
the class JDTTreeBuilder method visitTypeParameter.
private boolean visitTypeParameter(TypeParameter typeParameter, Scope scope) {
final CtTypeParameter typeParameterRef = factory.Core().createTypeParameter();
typeParameterRef.setSimpleName(CharOperation.charToString(typeParameter.name));
context.enter(typeParameterRef, typeParameter);
return true;
}
use of spoon.reflect.declaration.CtTypeParameter in project spoon by INRIA.
the class ParentExiter method scanCtElement.
@Override
public void scanCtElement(CtElement e) {
if (child instanceof CtAnnotation && this.jdtTreeBuilder.getContextBuilder().annotationValueName.isEmpty()) {
// we check if the current element can have the annotation attached
CtAnnotatedElementType annotatedElementType = CtAnnotation.getAnnotatedElementTypeForCtElement(e);
annotatedElementType = (e instanceof CtTypeParameter || e instanceof CtTypeParameterReference) ? CtAnnotatedElementType.TYPE_USE : annotatedElementType;
// in case of noclasspath, we cannot be 100% sure, so we guess it must be attached...
if (this.jdtTreeBuilder.getFactory().getEnvironment().getNoClasspath() || (annotatedElementType != null && JDTTreeBuilderQuery.hasAnnotationWithType((Annotation) childJDT, annotatedElementType))) {
e.addAnnotation((CtAnnotation<?>) child);
}
// in this case the annotation should be (also) attached to the type
if (e instanceof CtTypedElement && JDTTreeBuilderQuery.hasAnnotationWithType((Annotation) childJDT, CtAnnotatedElementType.TYPE_USE)) {
List<CtAnnotation> annotations = new ArrayList<>();
if (!annotationsMap.containsKey(e)) {
annotationsMap.put((CtTypedElement<?>) e, annotations);
} else {
annotations = annotationsMap.get(e);
}
annotations.add((CtAnnotation) child.clone());
annotationsMap.put((CtTypedElement<?>) e, annotations);
}
}
}
use of spoon.reflect.declaration.CtTypeParameter in project spoon by INRIA.
the class DefaultCoreFactory method createTypeParameter.
@Override
public CtTypeParameter createTypeParameter() {
CtTypeParameter e = new CtTypeParameterImpl();
e.setFactory(getMainFactory());
return e;
}
use of spoon.reflect.declaration.CtTypeParameter in project spoon by INRIA.
the class CtTypeParameterTest method checkType.
private void checkType(CtType<?> type) throws NoSuchFieldException, SecurityException {
List<CtTypeParameter> formalTypeParameters = type.getFormalCtTypeParameters();
for (CtTypeParameter ctTypeParameter : formalTypeParameters) {
checkTypeParamErasureOfType(ctTypeParameter, type.getActualClass());
}
for (CtTypeMember member : type.getTypeMembers()) {
if (member instanceof CtFormalTypeDeclarer) {
CtFormalTypeDeclarer ftDecl = (CtFormalTypeDeclarer) member;
formalTypeParameters = ftDecl.getFormalCtTypeParameters();
if (member instanceof CtExecutable<?>) {
CtExecutable<?> exec = (CtExecutable<?>) member;
for (CtTypeParameter ctTypeParameter : formalTypeParameters) {
checkTypeParamErasureOfExecutable(ctTypeParameter);
}
for (CtParameter<?> param : exec.getParameters()) {
checkParameterErasureOfExecutable(param);
}
} else if (member instanceof CtType<?>) {
CtType<?> nestedType = (CtType<?>) member;
// recursive call for nested type
checkType(nestedType);
}
}
}
}
Aggregations