1 /*
2     SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef PHPDUCHAINHELPER_H
8 #define PHPDUCHAINHELPER_H
9 
10 #include "phpduchainexport.h"
11 
12 #include <language/duchain/identifier.h>
13 #include <language/duchain/ducontext.h>
14 #include <language/duchain/types/abstracttype.h>
15 #include <serialization/indexedstring.h>
16 
17 namespace KDevelop
18 {
19 class Declaration;
20 class DUContext;
21 }
22 namespace Php
23 {
24 struct UnaryExpressionAst;
25 struct AstNode;
26 struct CommonScalarAst;
27 struct NamespacedIdentifierAst;
28 struct ParameterAst;
29 struct GenericTypeHintAst;
30 struct ReturnTypeAst;
31 struct ClassStatementAst;
32 struct PropertyTypeHintAst;
33 class EditorIntegrator;
34 
35 enum DeclarationType {
36     ClassDeclarationType,
37     FunctionDeclarationType,
38     ConstantDeclarationType,
39     GlobalVariableDeclarationType,
40     NamespaceDeclarationType
41 };
42 
43 enum DeclarationScope {
44     GlobalScope,
45     LocalScope
46 };
47 
48 KDEVPHPDUCHAIN_EXPORT bool isMatch(KDevelop::Declaration* declaration, DeclarationType declarationType);
49 
50 KDEVPHPDUCHAIN_EXPORT bool isGenericClassTypehint(NamespacedIdentifierAst* genericType, EditorIntegrator *editor);
51 
52 KDEVPHPDUCHAIN_EXPORT bool isClassTypehint(GenericTypeHintAst* parameterType, EditorIntegrator *editor);
53 
54 KDEVPHPDUCHAIN_EXPORT bool isClassTypehint(PropertyTypeHintAst* propertyType, EditorIntegrator *editor);
55 
56 KDEVPHPDUCHAIN_EXPORT KDevelop::DeclarationPointer findDeclarationImportHelper(KDevelop::DUContext* currentContext,
57                                                                                const KDevelop::QualifiedIdentifier& id,
58                                                                                DeclarationType declarationType);
59 
60 KDEVPHPDUCHAIN_EXPORT KDevelop::DeclarationPointer findDeclarationInPST(KDevelop::DUContext* currentContext,
61                                                                         KDevelop::QualifiedIdentifier id,
62                                                                         DeclarationType declarationType);
63 
64 KDEVPHPDUCHAIN_EXPORT QByteArray formatComment(AstNode* node, EditorIntegrator* editor);
65 
66 KDEVPHPDUCHAIN_EXPORT CommonScalarAst* findCommonScalar(AstNode* node);
67 
68 KDEVPHPDUCHAIN_EXPORT KDevelop::IndexedString getIncludeFileForNode(UnaryExpressionAst* node, EditorIntegrator* editor);
69 
70 KDEVPHPDUCHAIN_EXPORT QString prettyName(KDevelop::Declaration* dec);
71 
72 KDEVPHPDUCHAIN_EXPORT const KDevelop::IndexedString& internalFunctionFile();
73 
74 KDEVPHPDUCHAIN_EXPORT const KDevelop::IndexedString& internalTestFile();
75 
76 /// Indexed string for 'Php', identifies environment files from this language plugin
77 KDEVPHPDUCHAIN_EXPORT const KDevelop::IndexedString& phpLanguageString();
78 
79 /**
80  * Get proper QualifiedIdentifier for a NamespacedIdentifierAst.
81  *
82  * Identifier will be all lowercase except for the last identifier if @p lastIsConstIdentifier is set to true.
83  */
84 KDEVPHPDUCHAIN_EXPORT KDevelop::QualifiedIdentifier identifierForNamespace(NamespacedIdentifierAst* node, EditorIntegrator* editor,
85                                                                            bool lastIsConstIdentifier = false);
86 
87 /**
88  * Get proper QualifiedIdentifier for a basic identifier.
89  */
90 KDEVPHPDUCHAIN_EXPORT KDevelop::QualifiedIdentifier identifierWithNamespace(const KDevelop::QualifiedIdentifier& base, KDevelop::DUContext* context);
91 
92 KDEVPHPDUCHAIN_EXPORT KDevelop::AbstractType::Ptr parameterType(const ParameterAst* node, KDevelop::AbstractType::Ptr phpDocTypehint, EditorIntegrator* editor, KDevelop::DUContext *currentContext);
93 KDEVPHPDUCHAIN_EXPORT KDevelop::AbstractType::Ptr propertyType(const ClassStatementAst* node, KDevelop::AbstractType::Ptr phpDocTypehint, EditorIntegrator* editor, KDevelop::DUContext *currentContext);
94 KDEVPHPDUCHAIN_EXPORT KDevelop::AbstractType::Ptr returnType(const ReturnTypeAst* node, KDevelop::AbstractType::Ptr phpDocTypehint, EditorIntegrator* editor, KDevelop::DUContext *currentContext);
95 
96 }
97 #endif
98