use of org.eclipse.jdt.internal.compiler.ast.UnionTypeReference in project che by eclipse.
the class Util method typeSignature.
/*
* Returns the unresolved type signature of the given type reference, e.g. "QString;", "[int", "[[Qjava.util.Vector;"
*/
public static String typeSignature(TypeReference type) {
String signature = null;
if ((type.bits & ASTNode.IsUnionType) != 0) {
// special treatment for union type reference
UnionTypeReference unionTypeReference = (UnionTypeReference) type;
TypeReference[] typeReferences = unionTypeReference.typeReferences;
int length = typeReferences.length;
String[] typeSignatures = new String[length];
for (int i = 0; i < length; i++) {
char[][] compoundName = typeReferences[i].getParameterizedTypeName();
char[] typeName = CharOperation.concatWith(compoundName, '.');
typeSignatures[i] = Signature.createTypeSignature(typeName, false);
}
signature = Signature.createIntersectionTypeSignature(typeSignatures);
} else {
char[][] compoundName = type.getParameterizedTypeName();
char[] typeName = CharOperation.concatWith(compoundName, '.');
signature = Signature.createTypeSignature(typeName, false);
}
return signature;
}
use of org.eclipse.jdt.internal.compiler.ast.UnionTypeReference in project spoon by INRIA.
the class JDTTreeBuilder method visit.
@Override
public boolean visit(SingleTypeReference singleTypeReference, BlockScope scope) {
if (skipTypeInAnnotation) {
return true;
}
if (context.stack.peekFirst().node instanceof UnionTypeReference) {
if (singleTypeReference.resolvedType == null) {
CtTypeReference typeReference = factory.Type().createReference(singleTypeReference.toString());
CtReference ref = references.getDeclaringReferenceFromImports(singleTypeReference.getLastToken());
references.setPackageOrDeclaringType(typeReference, ref);
context.enter(typeReference, singleTypeReference);
} else {
context.enter(references.<Throwable>getTypeReference(singleTypeReference.resolvedType), singleTypeReference);
}
return true;
} else if (context.stack.peekFirst().element instanceof CtCatch) {
context.enter(helper.createCatchVariable(singleTypeReference), singleTypeReference);
return true;
}
context.enter(factory.Code().createTypeAccessWithoutCloningReference(references.buildTypeReference(singleTypeReference, scope)), singleTypeReference);
return true;
}
use of org.eclipse.jdt.internal.compiler.ast.UnionTypeReference in project spoon by INRIA.
the class JDTTreeBuilderHelper method createCatchVariable.
/**
* Creates a catch variable from a type reference.
*
* @param typeReference
* Correspond to the exception type declared in the catch.
* @return a catch variable.
*/
CtCatchVariable<Throwable> createCatchVariable(TypeReference typeReference) {
final Argument jdtCatch = (Argument) jdtTreeBuilder.getContextBuilder().stack.peekFirst().node;
final Set<CtExtendedModifier> modifiers = getModifiers(jdtCatch.modifiers, false, false);
CtCatchVariable<Throwable> result = jdtTreeBuilder.getFactory().Core().createCatchVariable();
result.<CtCatchVariable>setSimpleName(CharOperation.charToString(jdtCatch.name)).setExtendedModifiers(modifiers);
if (typeReference instanceof UnionTypeReference) {
// do not set type of variable yet. It will be initialized later by visit of multiple types. Each call then ADDs one type
return result;
} else {
CtTypeReference ctTypeReference = jdtTreeBuilder.getReferencesBuilder().<Throwable>getTypeReference(typeReference.resolvedType);
return result.<CtCatchVariable>setType(ctTypeReference);
}
}
Aggregations