QList< TypePtr< StructureType > > ExpressionVisitor::possibleStructureTypes(AbstractType::Ptr type)
{
    QList< TypePtr< StructureType > > result;
    type = Helper::resolveType(type);
    if ( ! type ) {
        return result;
    }
    if ( type->whichType() == KDevelop::AbstractType::TypeUnsure ) {
        AbstractType::Ptr current;
        UnsureType::Ptr possible = type.cast<UnsureType>();
        int amount = possible->typesSize();
        for ( int i = 0; i < amount; i++ ) {
            StructureType::Ptr current = Helper::resolveType(possible->types()[i].abstractType()).cast<StructureType>();
            if ( current ) {
                result << current;
            }
        }
    }
    else {
        StructureType::Ptr c = type.cast<StructureType>();
        if ( c ) {
            result << c;
        }
    }
    return result;
}
예제 #2
0
파일: context.cpp 프로젝트: KDE/kdev-ruby
QList<CompletionTreeItemPointer> CodeCompletionContext::getCompletionItemsFromType(AbstractType::Ptr type, bool scoped)
{
    QList<CompletionTreeItemPointer> res;
    if (type->whichType() == AbstractType::TypeUnsure) {
        UnsureType::Ptr unsure = type.cast<UnsureType>();
        int count = unsure->typesSize();
        for (int i = 0; i < count; i++) {
            res.append(getCompletionItemsForOneType(unsure->types()[i].abstractType(), scoped));
        }
    } else {
        res = getCompletionItemsForOneType(type, scoped);
    }
    return res;
}
예제 #3
0
void DeclarationBuilder::visitSingletonClass(Ast *node)
{
    ExpressionVisitor ev(currentContext(), m_editor);
    Node *aux = node->tree;

    node->tree = node->tree->r;
    ev.visitNode(node);
    if (ev.lastType()) {
        DeclarationPointer d = ev.lastDeclaration();
        if (d) {
            m_instance = false;
            if (!d->internalContext()) {
                StructureType::Ptr sType;
                UnsureType::Ptr ut = ev.lastType().cast<UnsureType>();
                if (ut && ut->typesSize() > 0) {
                    sType = ut->types()[0].type<StructureType>();
                } else {
                    sType = StructureType::Ptr::dynamicCast(ev.lastType());
                }
                if (sType) {
                    DUChainWriteLocker lock;
                    d = sType->declaration(topContext());
                    m_instance = true;
                } else {
                    d = DeclarationPointer();
                }
            }
            if (d) {
                m_classDeclarations.push(d);
                m_injected = true;
                injectContext(d->internalContext());
            }
        }
    }

    node->tree = aux;
    m_accessPolicy.push(Declaration::Public);
    AstVisitor::visitSingletonClass(node);
    m_accessPolicy.pop();
    if (m_injected) {
        closeInjectedContext();
        m_injected = false;
        m_classDeclarations.pop();
    }
}