2
<one line to give the program's name and a brief idea of what it does.>
3
Copyright (C) <year> <name of author>
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "phphighlighting.h"
21
#include <language/duchain/declaration.h>
22
#include <language/duchain/use.h>
23
#include <language/highlighting/colorcache.h>
24
#include <language/highlighting/configurablecolors.h>
26
#include <KTextEditor/SmartRange>
27
#include <KTextEditor/SmartInterface>
28
#include <KTextEditor/Document>
30
using namespace KDevelop;
32
using namespace KTextEditor;
34
#define LOCK_SMART(range) KTextEditor::SmartInterface* iface = dynamic_cast<KTextEditor::SmartInterface*>(range->document()); QMutexLocker lock(iface ? iface->smartMutex() : 0);
36
class HighlightingInstance : public CodeHighlightingInstance {
38
HighlightingInstance(const CodeHighlighting* highlighting);
39
virtual void highlightDeclaration(Declaration* declaration, const QColor& color) const;
40
virtual void highlightUse(DUContext* context, int index, const QColor& color) const;
44
HighlightingInstance::HighlightingInstance(const CodeHighlighting* highlighting)
45
: CodeHighlightingInstance(highlighting)
49
bool isConstDeclaration(Declaration* decl) {
50
return decl && !decl->isFunctionDeclaration() &&
51
decl->abstractType() && decl->abstractType()->modifiers() & AbstractType::ConstModifier;
54
///TODO: make this easier by rewriting some parts in the KDevplatform CodeHighlightingInstance
55
/// essentially we'd need to overwrite TypeForDeclaration
56
void HighlightingInstance::highlightDeclaration(Declaration* declaration, const QColor& color) const
58
if (isConstDeclaration(declaration)) {
59
// highlight const class members and defines differently from normal variables
60
if (SmartRange* range = declaration->smartRange()) {
62
range->setAttribute(m_highlighting->attributeForType(EnumType, DeclarationContext, color));
65
CodeHighlightingInstance::highlightDeclaration(declaration, color);
69
///TODO: make this easier by rewriting some parts in the KDevplatform CodeHighlightingInstance
70
/// essentially we'd need to overwrite TypeForDeclaration
71
void HighlightingInstance::highlightUse(DUContext* context, int index, const QColor& color) const
73
if (SmartRange* range = context->useSmartRange(index)) {
74
Declaration* decl = context->topContext()->usedDeclarationForIndex(context->uses()[index].m_declarationIndex);
75
if (isConstDeclaration(decl)) {
77
range->setAttribute(m_highlighting->attributeForType(EnumType, ReferenceContext, color));
81
KDevelop::CodeHighlightingInstance::highlightUse(context, index, color);
85
Highlighting::Highlighting(QObject* parent)
86
: CodeHighlighting(parent)
91
CodeHighlightingInstance* Highlighting::createInstance() const
93
return new HighlightingInstance(this);