Commit 4c571f40 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Simplify creation of JobRequest

Do what can be done in the constructor instead of relying on the
clients.

Change-Id: I5f475b5309afb37e34d228e54ad3c12f1698d72b
Reviewed-by: Ivan Donchevskii's avatarIvan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 3b415dbd
......@@ -41,6 +41,8 @@
#include <clangsupport/followsymbolmessage.h>
#include <clangsupport/referencesmessage.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
#include <ostream>
......@@ -51,6 +53,7 @@ namespace ClangBackEnd {
static const char *JobRequestTypeToText(JobRequest::Type type)
{
switch (type) {
RETURN_TEXT_FOR_CASE(Invalid);
RETURN_TEXT_FOR_CASE(UpdateDocumentAnnotations);
RETURN_TEXT_FOR_CASE(ParseSupportiveTranslationUnit);
RETURN_TEXT_FOR_CASE(ReparseSupportiveTranslationUnit);
......@@ -112,15 +115,66 @@ QDebug operator<<(QDebug debug, const JobRequest &jobRequest)
return debug.space();
}
JobRequest::JobRequest()
static JobRequest::ExpirationReasons expirationReasonsForType(JobRequest::Type type)
{
using Type = JobRequest::Type;
using ExpirationReason = JobRequest::ExpirationReason;
using ExpirationReasons = JobRequest::ExpirationReasons;
switch (type) {
case Type::UpdateDocumentAnnotations:
return ExpirationReasons(ExpirationReason::AnythingChanged);
case Type::RequestReferences:
case Type::RequestDocumentAnnotations:
case Type::FollowSymbol:
return ExpirationReasons(ExpirationReason::DocumentClosed)
| ExpirationReasons(ExpirationReason::DocumentRevisionChanged);
default:
return ExpirationReason::DocumentClosed;
}
}
static JobRequest::Conditions conditionsForType(JobRequest::Type type)
{
using Type = JobRequest::Type;
using Condition = JobRequest::Condition;
using Conditions = JobRequest::Conditions;
if (type == Type::SuspendDocument) {
return Conditions(Condition::DocumentUnsuspended)
| Conditions(Condition::DocumentNotVisible);
}
if (type == Type::ResumeDocument) {
return Conditions(Condition::DocumentSuspended)
| Conditions(Condition::DocumentVisible);
}
Conditions conditions = Conditions(Condition::DocumentUnsuspended)
| Conditions(Condition::DocumentVisible);
if (type == Type::RequestReferences)
conditions |= Condition::CurrentDocumentRevision;
return conditions;
}
JobRequest::JobRequest(Type type)
{
static quint64 idCounter = 0;
id = ++idCounter;
this->type = type;
conditions = conditionsForType(type);
expirationReasons = expirationReasonsForType(type);
}
IAsyncJob *JobRequest::createJob() const
{
switch (type) {
case JobRequest::Type::Invalid:
QTC_CHECK(false && "Cannot create job for invalid job request.");
break;
case JobRequest::Type::UpdateDocumentAnnotations:
return new UpdateDocumentAnnotationsJob();
case JobRequest::Type::ParseSupportiveTranslationUnit:
......@@ -152,6 +206,7 @@ void JobRequest::cancelJob(ClangCodeModelClientInterface &client) const
// must get back some results in order to clean up the state there.
switch (type) {
case JobRequest::Type::Invalid:
case JobRequest::Type::UpdateDocumentAnnotations:
case JobRequest::Type::ParseSupportiveTranslationUnit:
case JobRequest::Type::ReparseSupportiveTranslationUnit:
......@@ -198,40 +253,4 @@ bool JobRequest::operator==(const JobRequest &other) const
&& ticketNumber == other.ticketNumber;
}
JobRequest::ExpirationReasons JobRequest::expirationReasonsForType(Type type)
{
switch (type) {
case Type::UpdateDocumentAnnotations:
return ExpirationReasons(ExpirationReason::AnythingChanged);
case Type::RequestReferences:
case Type::RequestDocumentAnnotations:
case Type::FollowSymbol:
return ExpirationReasons(ExpirationReason::DocumentClosed)
| ExpirationReasons(ExpirationReason::DocumentRevisionChanged);
default:
return ExpirationReason::DocumentClosed;
}
}
JobRequest::Conditions JobRequest::conditionsForType(JobRequest::Type type)
{
if (type == Type::SuspendDocument) {
return Conditions(Condition::DocumentUnsuspended)
| Conditions(Condition::DocumentNotVisible);
}
if (type == Type::ResumeDocument) {
return Conditions(Condition::DocumentSuspended)
| Conditions(Condition::DocumentVisible);
}
Conditions conditions = Conditions(Condition::DocumentUnsuspended)
| Conditions(Condition::DocumentVisible);
if (type == Type::RequestReferences)
conditions |= Condition::CurrentDocumentRevision;
return conditions;
}
} // namespace ClangBackEnd
......@@ -47,6 +47,8 @@ class JobRequest
{
public:
enum class Type {
Invalid,
UpdateDocumentAnnotations,
CreateInitialDocumentPreamble,
......@@ -88,10 +90,7 @@ public:
Q_DECLARE_FLAGS(ExpirationReasons, ExpirationReason)
public:
static ExpirationReasons expirationReasonsForType(Type type);
static Conditions conditionsForType(Type type);
JobRequest();
JobRequest(Type type = Type::Invalid);
IAsyncJob *createJob() const;
void cancelJob(ClangCodeModelClientInterface &client) const;
......
......@@ -76,10 +76,7 @@ JobRequest Jobs::createJobRequest(const Document &document,
JobRequest::Type type,
PreferredTranslationUnit preferredTranslationUnit) const
{
JobRequest jobRequest;
jobRequest.type = type;
jobRequest.expirationReasons = JobRequest::expirationReasonsForType(type);
jobRequest.conditions = JobRequest::conditionsForType(type);
JobRequest jobRequest(type);
jobRequest.filePath = document.filePath();
jobRequest.projectPartId = document.projectPart().id();
jobRequest.unsavedFilesChangeTimePoint = m_unsavedFiles.lastChangeTimePoint();
......
......@@ -49,10 +49,7 @@ void ClangAsyncJobTest::BaseSetUp(ClangBackEnd::JobRequest::Type jobRequestType,
JobRequest ClangAsyncJobTest::createJobRequest(const Utf8String &filePath,
JobRequest::Type type) const
{
JobRequest jobRequest;
jobRequest.type = type;
jobRequest.expirationReasons = JobRequest::expirationReasonsForType(type);
jobRequest.conditions = JobRequest::conditionsForType(type);
JobRequest jobRequest(type);
jobRequest.filePath = filePath;
jobRequest.projectPartId = projectPartId;
jobRequest.unsavedFilesChangeTimePoint = unsavedFiles.lastChangeTimePoint();
......
......@@ -538,10 +538,7 @@ JobRequest JobQueue::createJobRequest(
JobRequest::Type type,
PreferredTranslationUnit preferredTranslationUnit) const
{
JobRequest jobRequest;
jobRequest.type = type;
jobRequest.expirationReasons = JobRequest::expirationReasonsForType(type);
jobRequest.conditions = JobRequest::conditionsForType(type);
JobRequest jobRequest(type);
jobRequest.filePath = filePath;
jobRequest.projectPartId = projectPartId;
jobRequest.unsavedFilesChangeTimePoint = unsavedFiles.lastChangeTimePoint();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment