81
81
iType = IntegralType::TypeNull;
82
82
} else if (lType == "void") {
83
83
iType = IntegralType::TypeVoid;
84
} else if (lType == "self" || lType == "this") {
85
DUChainReadLocker lock(DUChain::lock());
86
if ( currentContext()->type() == DUContext::Class && currentContext()->owner() ) {
87
return currentContext()->owner()->abstractType();
85
90
//don't use openTypeFromName as it uses cursor for findDeclarations
86
91
Declaration* decl = findDeclarationImport(ClassDeclarationType, QualifiedIdentifier(type.toLower()), node);
128
* Find all (or only one - see @p docCommentName) values for a given needle
129
* in a doc-comment. Needle has to start a line in the doccomment,
132
* * @docCommentName value
136
* /// @docCommentName value
138
QStringList findInDocComment(const QString &docComment, const QString &docCommentName, const bool onlyOne)
141
// optimization that does not require potentially slow regexps
142
// old code was something like this:
144
if (!docComment.isEmpty()) {
145
QRegExp rx("\\*\\s+@param\\s([^\\s]*)");
147
while ((pos = rx.indexIn(docComment, pos)) != -1) {
148
ret << parseType(rx.cap(1), node);
149
pos += rx.matchedLength();
154
for ( int i = 0, size = docComment.size(); i < size; ++i ) {
155
if ( docComment[i].isSpace() || docComment[i] == '*' || docComment[i] == '/' ) {
156
// skip whitespace and comment-marker at beginning of line
158
} else if ( docComment[i] == '@' && docComment.midRef(i + 1, docCommentName.size()) == docCommentName ) {
159
// find @return or similar
160
i += docCommentName.size() + 1;
161
// skip whitespace (at least one is required)
162
if ( i >= size || !docComment[i].isSpace() ) {
164
i = docComment.indexOf('\n', i);
169
} else if ( docComment[i] == '\n' ) {
172
++i; // at least one whitespace
173
while ( i < size && docComment[i].isSpace() ) {
176
// finally get the typename
178
while ( pos < size && !docComment[pos].isSpace() ) {
182
matches << docComment.mid(i, pos - i);
191
i = docComment.indexOf('\n', i);
122
200
AbstractType::Ptr TypeBuilder::parseDocComment(AstNode* node, const QString& docCommentName)
124
202
m_gotTypeFromDocComment = false;
125
QString docComment = editor()->parseSession()->docComment(node->startToken);
126
if (!docComment.isEmpty()) {
127
QRegExp rx("(?:\\*|///)\\s+@" + QRegExp::escape(docCommentName) + "\\s+([^\\s]*)");
128
if (rx.indexIn(docComment) != -1) {
203
const QString& docComment = editor()->parseSession()->docComment(node->startToken);
205
if ( !docComment.isEmpty() ) {
206
const QStringList& matches = findInDocComment(docComment, docCommentName, true);
207
if ( !matches.isEmpty() ) {
129
208
AbstractType::Ptr type;
130
if (rx.cap(1) == "$this") {
209
if (matches.first() == "$this") {
131
210
DUChainReadLocker lock(DUChain::lock());
132
211
if (currentContext()->owner()) {
133
212
type = currentContext()->owner()->abstractType();
136
type = injectParseType(rx.cap(1), node);
215
type = injectParseType(matches.first(), node);
139
218
m_gotTypeFromDocComment = true;
144
223
return AbstractType::Ptr();
148
226
QList<AbstractType::Ptr> TypeBuilder::parseDocCommentParams(AstNode* node)
150
228
QList<AbstractType::Ptr> ret;
151
229
QString docComment = editor()->parseSession()->docComment(node->startToken);
152
if (!docComment.isEmpty()) {
153
QRegExp rx("\\*\\s+@param\\s([^\\s]*)");
155
while ((pos = rx.indexIn(docComment, pos)) != -1) {
156
ret << parseType(rx.cap(1), node);
157
pos += rx.matchedLength();
230
if ( !docComment.isEmpty() ) {
231
const QStringList& matches = findInDocComment(docComment, "param", false);
232
if ( !matches.isEmpty() ) {
233
foreach ( const QString& type, matches ) {
234
ret << parseType(type, node);