tools/icheck/parser/src/plugins/cpptools/cppmodelmanagerinterface.h
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef CPPMODELMANAGERINTERFACE_H
       
    43 #define CPPMODELMANAGERINTERFACE_H
       
    44 
       
    45 #include <cpptools/cpptools_global.h>
       
    46 #include <cplusplus/CppDocument.h>
       
    47 #include <QtCore/QObject>
       
    48 #include <QtCore/QHash>
       
    49 #include <QtCore/QPointer>
       
    50 #include <QtCore/QStringList>
       
    51 
       
    52 namespace ProjectExplorer {
       
    53     class Project;
       
    54 }
       
    55 
       
    56 namespace CppTools {
       
    57 
       
    58 class AbstractEditorSupport;
       
    59 
       
    60 class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
       
    61 {
       
    62     Q_OBJECT
       
    63 
       
    64 public:
       
    65     class ProjectInfo
       
    66     {
       
    67     public:
       
    68         ProjectInfo()
       
    69         { }
       
    70 
       
    71         ProjectInfo(QPointer<ProjectExplorer::Project> project)
       
    72             : project(project)
       
    73         { }
       
    74 
       
    75         operator bool() const
       
    76         { return ! project.isNull(); }
       
    77 
       
    78         bool isValid() const
       
    79         { return ! project.isNull(); }
       
    80 
       
    81         bool isNull() const
       
    82         { return project.isNull(); }
       
    83 
       
    84     public: // attributes
       
    85         QPointer<ProjectExplorer::Project> project;
       
    86         QString projectPath;
       
    87         QByteArray defines;
       
    88         QStringList sourceFiles;
       
    89         QStringList includePaths;
       
    90         QStringList frameworkPaths;
       
    91         QStringList precompiledHeaders;
       
    92     };
       
    93 
       
    94     class WorkingCopy
       
    95     {
       
    96     public:
       
    97         void insert(const QString &fileName, const QString &source, unsigned revision = 0)
       
    98         { _elements.insert(fileName, qMakePair(source, revision)); }
       
    99 
       
   100         bool contains(const QString &fileName) const
       
   101         { return _elements.contains(fileName); }
       
   102 
       
   103         QString source(const QString &fileName) const
       
   104         { return _elements.value(fileName).first; }
       
   105 
       
   106         QPair<QString, unsigned> get(const QString &fileName) const
       
   107         { return _elements.value(fileName); }
       
   108 
       
   109     private:
       
   110         typedef QHash<QString, QPair<QString, unsigned> > Table;
       
   111         Table _elements;
       
   112     };
       
   113 
       
   114 public:
       
   115     CppModelManagerInterface(QObject *parent = 0) : QObject(parent) {}
       
   116     virtual ~CppModelManagerInterface() {}
       
   117 
       
   118     static CppModelManagerInterface *instance();
       
   119 
       
   120     virtual WorkingCopy workingCopy() const = 0;
       
   121     virtual CPlusPlus::Snapshot snapshot() const = 0;
       
   122 
       
   123     virtual QList<ProjectInfo> projectInfos() const = 0;
       
   124     virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0;
       
   125     virtual void updateProjectInfo(const ProjectInfo &pinfo) = 0;
       
   126 
       
   127     virtual QStringList includesInPath(const QString &path) const = 0;
       
   128 
       
   129     virtual void addEditorSupport(AbstractEditorSupport *editorSupport) = 0;
       
   130     virtual void removeEditorSupport(AbstractEditorSupport *editorSupport) = 0;
       
   131 
       
   132     virtual QList<int> references(CPlusPlus::Symbol *symbol,
       
   133                                   CPlusPlus::Document::Ptr doc,
       
   134                                   const CPlusPlus::Snapshot &snapshot) = 0;
       
   135 
       
   136     virtual void renameUsages(CPlusPlus::Symbol *symbol) = 0;
       
   137     virtual void findUsages(CPlusPlus::Symbol *symbol) = 0;
       
   138 
       
   139     virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0;
       
   140 
       
   141 public Q_SLOTS:
       
   142     void updateModifiedSourceFiles();
       
   143     virtual void updateSourceFiles(const QStringList &sourceFiles) = 0;
       
   144     virtual void GC() = 0;
       
   145 };
       
   146 
       
   147 class CPPTOOLS_EXPORT AbstractEditorSupport
       
   148 {
       
   149 public:
       
   150     explicit AbstractEditorSupport(CppModelManagerInterface *modelmanager);
       
   151     virtual ~AbstractEditorSupport();
       
   152 
       
   153     virtual QByteArray contents() const = 0;
       
   154     virtual QString fileName() const = 0;
       
   155 
       
   156     void updateDocument();
       
   157 
       
   158     // TODO: find a better place for common utility functions
       
   159     static QString functionAt(const CppModelManagerInterface *mm,
       
   160                               const QString &fileName,
       
   161                               int line, int column);
       
   162 
       
   163     static QString licenseTemplate();
       
   164 
       
   165 private:
       
   166     CppModelManagerInterface *m_modelmanager;
       
   167 };
       
   168 
       
   169 } // namespace CppTools
       
   170 
       
   171 #endif // CPPMODELMANAGERINTERFACE_H