Commit 386fc347 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Make Document::Ptr point to a const Document.



Change-Id: I15a36c3f918c0ee16f30bc8366df505e0afac949
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 86f0f930
......@@ -119,9 +119,9 @@ Document::~Document()
delete _engine;
}
Document::Ptr Document::create(const QString &fileName, Language language)
Document::MutablePtr Document::create(const QString &fileName, Language language)
{
Document::Ptr doc(new Document(fileName, language));
Document::MutablePtr doc(new Document(fileName, language));
doc->_ptr = doc;
return doc;
}
......@@ -375,11 +375,11 @@ void Snapshot::remove(const QString &fileName)
}
}
Document::Ptr Snapshot::documentFromSource(const QString &code,
const QString &fileName,
Document::Language language) const
Document::MutablePtr Snapshot::documentFromSource(
const QString &code, const QString &fileName,
Document::Language language) const
{
Document::Ptr newDoc = Document::create(fileName, language);
Document::MutablePtr newDoc = Document::create(fileName, language);
if (Document::Ptr thisDocument = document(fileName)) {
newDoc->_editorRevision = thisDocument->_editorRevision;
......
......@@ -51,7 +51,8 @@ class Snapshot;
class QMLJS_EXPORT Document
{
public:
typedef QSharedPointer<Document> Ptr;
typedef QSharedPointer<const Document> Ptr;
typedef QSharedPointer<Document> MutablePtr;
// used in a 3-bit bitfield
enum Language
......@@ -68,7 +69,7 @@ protected:
public:
~Document();
static Document::Ptr create(const QString &fileName, Language language);
static MutablePtr create(const QString &fileName, Language language);
static Language guessLanguageFromSuffix(const QString &fileName);
Document::Ptr ptr() const;
......@@ -230,7 +231,7 @@ public:
QList<Document::Ptr> documentsInDirectory(const QString &path) const;
LibraryInfo libraryInfo(const QString &path) const;
Document::Ptr documentFromSource(const QString &code,
Document::MutablePtr documentFromSource(const QString &code,
const QString &fileName,
Document::Language language) const;
};
......
......@@ -259,7 +259,7 @@ void ScopeChain::initializeRootScope()
m_globalScope = valueOwner->globalObject();
QHash<Document *, QmlComponentChain *> componentScopes;
QHash<const Document *, QmlComponentChain *> componentScopes;
QmlComponentChain *chain = new QmlComponentChain(m_document);
m_qmlComponentScope = QSharedPointer<const QmlComponentChain>(chain);
......@@ -297,7 +297,7 @@ void ScopeChain::initializeRootScope()
void ScopeChain::makeComponentChain(
QmlComponentChain *target,
const Snapshot &snapshot,
QHash<Document *, QmlComponentChain *> *components)
QHash<const Document *, QmlComponentChain *> *components)
{
Document::Ptr doc = target->document();
if (!doc->qmlProgram())
......
......@@ -108,7 +108,7 @@ private:
void update() const;
void initializeRootScope();
void makeComponentChain(QmlComponentChain *target, const Snapshot &snapshot,
QHash<Document *, QmlComponentChain *> *components);
QHash<const Document *, QmlComponentChain *> *components);
Document::Ptr m_document;
......
......@@ -52,7 +52,7 @@ protected:
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
private:
QmlJS::Document::Ptr m_document;
QmlJS::Document::MutablePtr m_document;
quint32 m_location;
QString m_text;
};
......
......@@ -54,7 +54,7 @@ protected:
void extractFirstObjectDefinition(QmlJS::AST::UiObjectInitializer* ast);
private:
QmlJS::Document::Ptr m_doc;
QmlJS::Document::MutablePtr m_doc;
quint32 m_offset;
QmlJS::AST::UiObjectDefinition *m_firstObjectDefinition;
......
......@@ -52,7 +52,7 @@ protected:
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
private:
QmlJS::Document::Ptr m_doc;
QmlJS::Document::MutablePtr m_doc;
quint32 m_offset;
quint32 m_length;
};
......
......@@ -61,7 +61,7 @@ bool QmlRefactoring::reparseDocument()
// qDebug() << "QmlRefactoring::reparseDocument() new QML source:" << newSource;
Document::Ptr tmpDocument(Document::create("<ModelToTextMerger>", Document::QmlLanguage));
Document::MutablePtr tmpDocument(Document::create("<ModelToTextMerger>", Document::QmlLanguage));
tmpDocument->setSource(newSource);
if (tmpDocument->parseQml()) {
......
......@@ -188,7 +188,7 @@ public:
bool renameId(const QString& oldId, const QString& newId);
const QmlJS::ScopeChain &scopeChain() const;
QmlJS::Document *document() const;
const QmlJS::Document *document() const;
QString convertTypeToImportAlias(const QString &type) const;
......
......@@ -382,7 +382,7 @@ private:
//storing the pointer would not be save
QmlJS::ContextPtr context() const;
QmlJS::Document *document() const;
const Document *document() const;
QPointer<Model> m_model;
static QHash<QString, Pointer> m_nodeMetaInfoCache;
......@@ -496,7 +496,7 @@ QmlJS::ContextPtr NodeMetaInfoPrivate::context() const
return QmlJS::ContextPtr(0);
}
QmlJS::Document *NodeMetaInfoPrivate::document() const
const QmlJS::Document *NodeMetaInfoPrivate::document() const
{
if (m_model && m_model->rewriterView()) {
return m_model->rewriterView()->document();
......
......@@ -229,7 +229,7 @@ void ModelToTextMerger::applyChanges()
if (m_rewriteActions.isEmpty())
return;
Document::Ptr tmpDocument(Document::create(QLatin1String("<ModelToTextMerger>"), Document::QmlLanguage));
Document::MutablePtr tmpDocument(Document::create(QLatin1String("<ModelToTextMerger>"), Document::QmlLanguage));
tmpDocument->setSource(m_rewriterView->textModifier()->text());
if (!tmpDocument->parseQml()) {
qDebug() << "*** Possible problem: QML file wasn't parsed correctly.";
......
......@@ -629,7 +629,7 @@ const QmlJS::ScopeChain &RewriterView::scopeChain() const
return textToModelMerger()->scopeChain();
}
QmlJS::Document *RewriterView::document() const
const QmlJS::Document *RewriterView::document() const
{
return textToModelMerger()->document();
}
......
......@@ -732,7 +732,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
try {
Snapshot snapshot = m_rewriterView->textModifier()->getSnapshot();
const QString fileName = url.toLocalFile();
Document::Ptr doc = Document::create(fileName.isEmpty() ? QLatin1String("<internal>") : fileName, Document::QmlLanguage);
Document::MutablePtr doc = Document::create(fileName.isEmpty() ? QLatin1String("<internal>") : fileName, Document::QmlLanguage);
doc->setSource(data);
doc->parseQml();
......
......@@ -71,7 +71,7 @@ public:
const QmlJS::ScopeChain &scopeChain() const
{ return *m_scopeChain; }
QmlJS::Document *document() const
const QmlJS::Document *document() const
{ return m_document.data(); }
protected:
......
......@@ -136,9 +136,11 @@ QmlJS::AST::ExpressionNode *QmlExpressionUnderCursor::operator()(const QTextCurs
ExpressionUnderCursor expressionUnderCursor;
_text = expressionUnderCursor(cursor);
exprDoc = Document::create(QLatin1String("<expression>"), Document::JavaScriptLanguage);
exprDoc->setSource(_text);
exprDoc->parseExpression();
Document::MutablePtr newDoc = Document::create(
QLatin1String("<expression>"), Document::JavaScriptLanguage);
newDoc->setSource(_text);
newDoc->parseExpression();
exprDoc = newDoc;
_expressionNode = exprDoc->expression();
......
......@@ -810,8 +810,8 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
else
language = QmlJSTools::languageOfFile(fileName);
Document::Ptr newDoc = snapshot.documentFromSource(it.value().first, fileName,
language);
Document::MutablePtr newDoc = snapshot.documentFromSource(
it.value().first, fileName, language);
newDoc->parse();
snapshot.insert(newDoc);
}
......
......@@ -128,10 +128,12 @@ SemanticInfo SemanticInfoUpdater::semanticInfo(const SemanticInfoUpdaterSource &
language = m_lastSemanticInfo.document->language();
else
language = QmlJSTools::languageOfFile(source.fileName);
doc = snapshot.documentFromSource(source.code, source.fileName, language);
doc->setEditorRevision(source.revision);
doc->parse();
snapshot.insert(doc);
QmlJS::Document::MutablePtr newDoc = snapshot.documentFromSource(
source.code, source.fileName, language);
newDoc->setEditorRevision(source.revision);
newDoc->parse();
snapshot.insert(newDoc);
doc = newDoc;
}
SemanticInfo semanticInfo;
......
......@@ -598,7 +598,7 @@ void ModelManager::parse(QFutureInterface<void> &future,
}
}
Document::Ptr doc = Document::create(fileName, language);
Document::MutablePtr doc = Document::create(fileName, language);
doc->setEditorRevision(documentRevision);
doc->setSource(contents);
doc->parse();
......
......@@ -135,8 +135,9 @@ Document::Ptr QmlJSRefactoringFile::qmljsDocument() const
const QString name = fileName();
const Snapshot &snapshot = data()->m_snapshot;
m_qmljsDocument = snapshot.documentFromSource(source, name, languageOfFile(name));
m_qmljsDocument->parse();
Document::MutablePtr newDoc = snapshot.documentFromSource(source, name, languageOfFile(name));
newDoc->parse();
m_qmljsDocument = newDoc;
}
return m_qmljsDocument;
......
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