예제 #1
0
QList<QVariant> DUChainItemData::highlighting() const
{
  DUChainReadLocker lock;;

  Declaration* decl = m_item.m_item.data();
  if(!decl) {
    return QList<QVariant>();
  }

  if(FunctionDefinition* def = dynamic_cast<FunctionDefinition*>(decl)) {
    if(def->declaration()) {
      decl = def->declaration();
    }
  }

  QTextCharFormat boldFormat;
  boldFormat.setFontWeight(QFont::Bold);
  QTextCharFormat normalFormat;

  int prefixLength = 0;

  QString signature;
  TypePtr<FunctionType> function = decl->type<FunctionType>();
  if(function) {
    signature = function->partToString( FunctionType::SignatureArguments );
  }

  //Only highlight the last part of the qualified identifier, so the scope doesn't distract too much
  QualifiedIdentifier id = decl->qualifiedIdentifier();
  QString fullId = id.toString();
  QString lastId;
  if(!id.isEmpty()) {
    lastId = id.last().toString();
  }

  prefixLength += fullId.length() - lastId.length();

  QList<QVariant> ret;
  ret << 0;
  ret << prefixLength;
  ret << QVariant(normalFormat);
  ret << prefixLength;
  ret << lastId.length();
  ret << QVariant(boldFormat);
  if(!signature.isEmpty()) {
    ret << prefixLength + lastId.length();
    ret << signature.length();
    ret << QVariant(normalFormat);
  }

  return ret;

}
예제 #2
0
파일: cpptypes.cpp 프로젝트: krf/kdevelop
QString CppClassType::toString() const
{
  QualifiedIdentifier id = qualifiedIdentifier();
  if (!id.isEmpty()) {
    if(declarationId().specialization().index())
      return AbstractType::toString() + Cpp::IndexedInstantiationInformation(declarationId().specialization()).information().applyToIdentifier(id).toString();
    else
    return AbstractType::toString() + id.toString();
  }

  //This path usually is not taken
  QString type = "class";

  return QString("<%1>%2").arg(type).arg(AbstractType::toString(true));
}
예제 #3
0
QString ClassSpecializationType::toString() const
{
    QualifiedIdentifier id = qualifiedIdentifier();
    if (!id.isEmpty()) {
        QString result = AbstractType::toString() + strippedQid(id) + QLatin1String("< ");
        bool first = true;
        for (const auto& param : templateParameters()) {
            if (first) {
                first = false;
            } else {
                result += QLatin1String(", ");
            }
            result += param.abstractType()->toString();
        }
        result += QLatin1String(" >");
        return result;
    }

    return StructureType::toString();
}
예제 #4
0
void TestIdentifier::testQualifiedIdentifier()
{
  QFETCH(QString, stringId);
  const QStringList list = stringId.split(QStringLiteral("::"), QString::SkipEmptyParts);

  QualifiedIdentifier id(stringId);
  QCOMPARE(id.isEmpty(), stringId.isEmpty());
  QCOMPARE(id, QualifiedIdentifier(stringId));
  QVERIFY(!(id != QualifiedIdentifier(stringId)));
  QCOMPARE(id, QualifiedIdentifier(stringId));
  if (list.size() == 1) {
    QCOMPARE(id, QualifiedIdentifier(Identifier(list.last())));
  } else if (list.isEmpty()) {
    QualifiedIdentifier empty{Identifier()};
    QCOMPARE(id, empty);
    QVERIFY(empty.isEmpty());
    QVERIFY(empty.inRepository());
  }
  QCOMPARE(id.toString(), stringId);
  QCOMPARE(id.toStringList(), list);
  QCOMPARE(id.top(), Identifier(list.isEmpty() ? QString() : list.last()));

  if (stringId.isEmpty()) {
    QVERIFY(id.inRepository());
    QVERIFY(QualifiedIdentifier(id).inRepository());
  }

  QualifiedIdentifier copy = id;
  QCOMPARE(copy, id);
  copy = copy;
  QCOMPARE(copy, id);
  copy = QualifiedIdentifier();
  QVERIFY(copy.isEmpty());
  copy = id;
  QCOMPARE(copy, id);

  IndexedQualifiedIdentifier indexedId(id);
  QVERIFY(indexedId == id);
  QCOMPARE(indexedId, IndexedQualifiedIdentifier(id));
  QCOMPARE(indexedId.isValid(), !stringId.isEmpty());
  QCOMPARE(indexedId.identifier(), id);
  IndexedQualifiedIdentifier indexedCopy = indexedId;
  QCOMPARE(indexedCopy, indexedId);
  indexedCopy = indexedCopy;
  QCOMPARE(indexedCopy, indexedId);
  indexedCopy = IndexedQualifiedIdentifier();
  QVERIFY(!indexedCopy.isValid());
  indexedCopy = indexedId;
  QCOMPARE(indexedCopy, indexedId);

  QualifiedIdentifier moved = std::move(id);
  QVERIFY(id.isEmpty());
  QCOMPARE(moved, copy);

  IndexedQualifiedIdentifier movedIndexed = std::move(indexedId);
  QVERIFY(indexedId.isEmpty());
  QCOMPARE(movedIndexed, indexedCopy);

  copy.clear();
  QVERIFY(copy.isEmpty());

  copy.push(moved);
  QCOMPARE(copy, moved);

  copy.push(Identifier(QStringLiteral("lalala")));
  QCOMPARE(copy.count(), moved.count() + 1);
}