Search in sources :

Example 1 with UnionTypeReference

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;
}
Also used : UnionTypeReference(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) UnionTypeReference(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference)

Example 2 with UnionTypeReference

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;
}
Also used : CtReference(spoon.reflect.reference.CtReference) CtTypeReference(spoon.reflect.reference.CtTypeReference) UnionTypeReference(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference) CtCatch(spoon.reflect.code.CtCatch)

Example 3 with UnionTypeReference

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);
    }
}
Also used : Argument(org.eclipse.jdt.internal.compiler.ast.Argument) CtTypeReference(spoon.reflect.reference.CtTypeReference) UnionTypeReference(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference) CtCatchVariable(spoon.reflect.code.CtCatchVariable) CtExtendedModifier(spoon.support.reflect.CtExtendedModifier)

Aggregations

UnionTypeReference (org.eclipse.jdt.internal.compiler.ast.UnionTypeReference)3 CtTypeReference (spoon.reflect.reference.CtTypeReference)2 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)1 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)1 CtCatch (spoon.reflect.code.CtCatch)1 CtCatchVariable (spoon.reflect.code.CtCatchVariable)1 CtReference (spoon.reflect.reference.CtReference)1 CtExtendedModifier (spoon.support.reflect.CtExtendedModifier)1