use of spoon.reflect.reference.CtTypeReference in project spoon by INRIA.
the class TypeFactory method createWildcardStaticTypeMemberReference.
/**
* Create a wildcard reference to a simple type
*/
public CtTypeReference createWildcardStaticTypeMemberReference(CtTypeReference typeReference) {
CtTypeReference ref = factory.Core().createWildcardStaticTypeMemberReference();
ref.setFactory(this.factory);
if (typeReference.getDeclaringType() != null) {
ref.setDeclaringType(typeReference.getDeclaringType().clone());
}
if (typeReference.getPackage() != null) {
ref.setPackage(typeReference.getPackage().clone());
}
ref.setSimpleName(typeReference.getSimpleName());
return ref;
}
use of spoon.reflect.reference.CtTypeReference in project spoon by INRIA.
the class ExecutableFactory method createReference.
/**
* Creates an executable reference from its signature, as defined by the
* executable reference's toString.
*/
public <T> CtExecutableReference<T> createReference(String signature) {
CtExecutableReference<T> executableRef = factory.Core().createExecutableReference();
String type = signature.substring(0, signature.indexOf(" "));
String declaringType = signature.substring(signature.indexOf(" ") + 1, signature.indexOf(CtExecutable.EXECUTABLE_SEPARATOR));
String executableName = signature.substring(signature.indexOf(CtExecutable.EXECUTABLE_SEPARATOR) + 1, signature.indexOf("("));
executableRef.setSimpleName(executableName);
executableRef.setDeclaringType(factory.Type().createReference(declaringType));
CtTypeReference<T> typeRef = factory.Type().createReference(type);
executableRef.setType(typeRef);
String parameters = signature.substring(signature.indexOf("(") + 1, signature.indexOf(")"));
List<CtTypeReference<?>> params = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY);
StringTokenizer t = new StringTokenizer(parameters, ",");
while (t.hasMoreTokens()) {
String paramType = t.nextToken();
params.add(factory.Type().createReference(paramType));
}
executableRef.setParameters(params);
return executableRef;
}
use of spoon.reflect.reference.CtTypeReference in project spoon by INRIA.
the class JDTTreeBuilderHelper method createModuleProvidedService.
CtProvidedService createModuleProvidedService(ProvidesStatement providesStatement) {
int sourceStart = providesStatement.sourceStart;
int sourceEnd = providesStatement.sourceEnd;
CtTypeReference provideService = this.jdtTreeBuilder.references.getTypeReference(providesStatement.serviceInterface);
List<CtTypeReference> implementations = new ArrayList<>();
for (TypeReference typeReference : providesStatement.implementations) {
implementations.add(this.jdtTreeBuilder.references.getTypeReference(typeReference));
}
CtProvidedService providedService = this.jdtTreeBuilder.getFactory().Module().createProvidedService(provideService);
providedService.setImplementationTypes(implementations);
providedService.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
return providedService;
}
use of spoon.reflect.reference.CtTypeReference in project spoon by INRIA.
the class JDTTreeBuilderHelper method createUsedService.
CtUsedService createUsedService(UsesStatement usesStatement) {
CtTypeReference typeReference = this.jdtTreeBuilder.references.getTypeReference(usesStatement.serviceInterface);
CtUsedService usedService = this.jdtTreeBuilder.getFactory().Module().createUsedService(typeReference);
usedService.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(usesStatement.sourceStart, usesStatement.sourceEnd));
return usedService;
}
use of spoon.reflect.reference.CtTypeReference in project spoon by INRIA.
the class ReferenceBuilder method getTypeReference.
/**
* JDT doesn't return a correct AST with the resolved type of the reference.
* This method try to build a correct Spoon AST from the name of the JDT
* reference, thanks to the parsing of the string, the name parameterized from
* the JDT reference and java convention.
* Returns a complete Spoon AST when the name is correct, otherwise a spoon type
* reference with a name that correspond to the name of the JDT type reference.
*/
<T> CtTypeReference<T> getTypeReference(TypeReference ref) {
CtTypeReference<T> res = null;
CtTypeReference inner = null;
final String[] namesParameterized = CharOperation.charArrayToStringArray(ref.getParameterizedTypeName());
String nameParameterized = CharOperation.toString(ref.getParameterizedTypeName());
String typeName = CharOperation.toString(ref.getTypeName());
int index = namesParameterized.length - 1;
for (; index >= 0; index--) {
// Start at the end to get the class name first.
CtTypeReference main = getTypeReference(namesParameterized[index]);
if (main == null) {
break;
}
if (res == null) {
res = (CtTypeReference<T>) main;
} else {
inner.setDeclaringType((CtTypeReference<?>) main);
}
inner = main;
}
if (res == null) {
return this.jdtTreeBuilder.getFactory().Type().createReference(nameParameterized);
}
if (inner.getPackage() == null) {
PackageFactory packageFactory = this.jdtTreeBuilder.getFactory().Package();
CtPackageReference packageReference = index >= 0 ? packageFactory.getOrCreate(concatSubArray(namesParameterized, index)).getReference() : packageFactory.topLevel();
inner.setPackage(packageReference);
}
if (!res.toString().replace(", ?", ",?").endsWith(nameParameterized)) {
// verify that we did not match a class that have the same name in a different package
return this.jdtTreeBuilder.getFactory().Type().createReference(typeName);
}
return res;
}
Aggregations