logic: show real code of signatures in tooltips

* added new location type
* refactored old recording code
* record signature locations for cxx functions and java methods
* added signature locations to sample project indexer tests
* ignore signature locations in ui
* signatures in tooltip with qualified name of the function/method
* added test for finding signature location of constructor with initializer list
This commit is contained in:
mlangkabel
2018-07-20 14:00:08 +02:00
parent 605d07688b
commit c6f9d8f92c
211 changed files with 19809 additions and 19293 deletions
+3 -1
View File
@@ -17,8 +17,10 @@ LocationType intToLocationType(int value)
return LOCATION_QUALIFIER;
case LOCATION_LOCAL_SYMBOL:
return LOCATION_LOCAL_SYMBOL;
case LOCATION_SIGNATURE:
return LOCATION_SIGNATURE;
case LOCATION_ERROR:
return LOCATION_ERROR;
return LOCATION_ERROR;
case LOCATION_FULLTEXT_SEARCH:
return LOCATION_FULLTEXT_SEARCH;
case LOCATION_SCREEN_SEARCH:
+4 -3
View File
@@ -7,9 +7,10 @@ enum LocationType
LOCATION_SCOPE = 1,
LOCATION_QUALIFIER = 2,
LOCATION_LOCAL_SYMBOL = 3,
LOCATION_ERROR = 4,
LOCATION_FULLTEXT_SEARCH = 5,
LOCATION_SCREEN_SEARCH = 6
LOCATION_SIGNATURE = 4,
LOCATION_ERROR = 5,
LOCATION_FULLTEXT_SEARCH = 6,
LOCATION_SCREEN_SEARCH = 7
};
int locationTypeToInt(LocationType type);
+33
View File
@@ -91,6 +91,39 @@ bool SourceLocation::operator>(const SourceLocation& rhs) const
return getLocationId() > rhs.getLocationId();
}
bool SourceLocation::contains(const SourceLocation& other) const
{
const SourceLocation* start = getStartLocation();
const SourceLocation* otherStart = other.getStartLocation();
if (start->getLineNumber() > otherStart->getLineNumber())
{
return false;
}
if (start->getLineNumber() == otherStart->getLineNumber() &&
start->getColumnNumber() > otherStart->getColumnNumber())
{
return false;
}
const SourceLocation* end = getEndLocation();
const SourceLocation* otherEnd = other.getEndLocation();
if (end->getLineNumber() < otherEnd->getLineNumber())
{
return false;
}
if (end->getLineNumber() == otherEnd->getLineNumber() &&
end->getColumnNumber() < otherEnd->getColumnNumber())
{
return false;
}
return true;
}
SourceLocationFile* SourceLocation::getSourceLocationFile() const
{
return m_file;
+2
View File
@@ -24,6 +24,8 @@ public:
bool operator<(const SourceLocation& rhs) const;
bool operator>(const SourceLocation& rhs) const;
bool contains(const SourceLocation& other) const;
SourceLocationFile* getSourceLocationFile() const;
Id getLocationId() const;
+27
View File
@@ -70,6 +70,33 @@ std::wstring ParserClient::addLocationSuffix(
return ss.str();
}
std::wstring ParserClient::addLocationSuffix(
const std::wstring& str, const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation
) {
if (!location.isValid())
{
return addLocationSuffix(str, scopeLocation, signatureLocation);
}
if (!scopeLocation.isValid())
{
return addLocationSuffix(str, location, signatureLocation);
}
if (!signatureLocation.isValid())
{
return addLocationSuffix(str, location, scopeLocation);
}
std::wstringstream ss;
ss << str;
ss << L" <" << scopeLocation.startLineNumber << L":" << scopeLocation.startColumnNumber;
ss << L" <" << signatureLocation.startLineNumber << L":" << signatureLocation.startColumnNumber << L" ";
ss << L" <" << location.startLineNumber << L":" << location.startColumnNumber << L" ";
ss << location.endLineNumber << L":" << location.endColumnNumber << L"> ";
ss << signatureLocation.endLineNumber << L":" << signatureLocation.endColumnNumber << L"> ";
ss << scopeLocation.endLineNumber << L":" << scopeLocation.endColumnNumber << L">";
return ss.str();
}
ParserClient::ParserClient()
: m_hasFatalErrors(false)
{
+13 -2
View File
@@ -24,6 +24,12 @@ public:
static std::wstring addLocationSuffix(const std::wstring& str, const ParseLocation& location);
static std::wstring addLocationSuffix(
const std::wstring& str, const ParseLocation& location, const ParseLocation& scopeLocation);
static std::wstring addLocationSuffix(
const std::wstring& str,
const ParseLocation& location,
const ParseLocation& scopeLocation,
const ParseLocation& signatureLocation
);
ParserClient();
virtual ~ParserClient() = default;
@@ -32,16 +38,21 @@ public:
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual Id recordSymbol(
virtual Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual Id recordSymbol(
virtual Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) = 0;
virtual void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) = 0;
+13 -7
View File
@@ -10,10 +10,6 @@ ParserClientImpl::ParserClientImpl()
{
}
ParserClientImpl::~ParserClientImpl()
{
}
void ParserClientImpl::setStorage(std::shared_ptr<IntermediateStorage> storage)
{
m_storage = storage;
@@ -35,7 +31,7 @@ Id ParserClientImpl::recordSymbol(
return nodeId;
}
Id ParserClientImpl::recordSymbol(
Id ParserClientImpl::recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind
@@ -46,17 +42,27 @@ Id ParserClientImpl::recordSymbol(
return nodeId;
}
Id ParserClientImpl::recordSymbol(
Id ParserClientImpl::recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind
)
{
Id nodeId = recordSymbol(symbolName, symbolKind, location, access, definitionKind);
Id nodeId = recordSymbolWithLocation(symbolName, symbolKind, location, access, definitionKind);
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
return nodeId;
}
Id ParserClientImpl::recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind)
{
Id nodeId = recordSymbolWithLocation(symbolName, symbolKind, location, access, definitionKind);
addSourceLocation(nodeId, signatureLocation, locationTypeToInt(LOCATION_SIGNATURE));
return nodeId;
}
void ParserClientImpl::recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location)
+15 -11
View File
@@ -13,38 +13,42 @@ class ParserClientImpl
{
public:
ParserClientImpl();
virtual ~ParserClientImpl();
void setStorage(std::shared_ptr<IntermediateStorage> storage);
void resetStorage();
virtual Id recordSymbol(
Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) override;
virtual Id recordSymbol(
Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) override;
virtual Id recordSymbol(
Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) override;
virtual void recordReference(
Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) override;
void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) override;
virtual void recordQualifierLocation(
void recordQualifierLocation(
const NameHierarchy& qualifierName, const ParseLocation& location) override;
virtual void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override;
virtual void recordFile(const FileInfo& fileInfo, bool indexed) override;
virtual void recordComment(const ParseLocation& location) override;
void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override;
void recordFile(const FileInfo& fileInfo, bool indexed) override;
void recordComment(const ParseLocation& location) override;
private:
virtual void doRecordError(
void doRecordError(
const ParseLocation& location, const std::wstring& message, bool fatal, bool indexed, const FilePath& sourceFilePath) override;
NodeType symbolKindToNodeType(SymbolKind symbolType) const;
+122 -1
View File
@@ -1391,7 +1391,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
for (const StorageSourceLocation& sourceLocation: m_sqliteIndexStorage.getAllByIds<StorageSourceLocation>(locationIds))
{
const LocationType type = intToLocationType(sourceLocation.type);
if (type == LOCATION_QUALIFIER)
if (type == LOCATION_QUALIFIER || type == LOCATION_SIGNATURE)
{
continue;
}
@@ -1967,6 +1967,127 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
if (nameHierarchy.hasSignature())
{
std::shared_ptr<SourceLocationCollection> locations = m_sqliteIndexStorage.getSourceLocationsForElementIds({ node.id });
SourceLocation* sigLoc = nullptr;
locations->forEachSourceLocation(
[&sigLoc](SourceLocation* location)
{
if (!sigLoc && location->isStartLocation() && location->getType() == LOCATION_SIGNATURE)
{
sigLoc = location;
}
}
);
// if node has a signature location use that one
if (sigLoc)
{
struct Annotation
{
Id locationId = 0;
size_t startPos = 0;
size_t endPos = 0;
};
std::vector<Annotation> annotations;
std::vector<std::string> lines = getFileContent(sigLoc->getFilePath())->getLines(
sigLoc->getLineNumber(), sigLoc->getEndLocation()->getLineNumber());
std::shared_ptr<SourceLocationFile> file = getSourceLocationsForLinesInFile(
sigLoc->getFilePath(),
sigLoc->getStartLocation()->getLineNumber(),
sigLoc->getEndLocation()->getLineNumber()
);
file->forEachStartSourceLocation(
[&sigLoc, &annotations, &lines](SourceLocation* loc)
{
if ((loc->getType() == LOCATION_TOKEN || loc->getType() == LOCATION_QUALIFIER) &&
sigLoc->contains(*loc))
{
Annotation annotation;
annotation.locationId = loc->getLocationId();
for (size_t i = 0; i < loc->getLineNumber() - sigLoc->getLineNumber(); i++)
{
annotation.startPos += lines[i].size();
}
annotation.startPos += loc->getColumnNumber() - sigLoc->getColumnNumber();
for (size_t i = 0; i < loc->getEndLocation()->getLineNumber() - sigLoc->getLineNumber(); i++)
{
annotation.endPos += lines[i].size();
}
annotation.endPos += loc->getEndLocation()->getColumnNumber() - sigLoc->getColumnNumber();
annotations.push_back(annotation);
}
}
);
// remove characters after signature end
lines[lines.size()-1] = lines[lines.size()-1].substr(0, sigLoc->getEndLocation()->getColumnNumber());
// remove characters before signature start
lines[0] = lines[0].substr(sigLoc->getColumnNumber() - 1);
std::wstring code = utility::decodeFromUtf8(utility::join(lines, ""));
// store texts of annotations
std::vector<std::pair<Id, std::wstring>> annotatedTexts;
size_t offset = 0;
for (const Annotation& annotation : annotations)
{
std::wstring text = code.substr(
annotation.startPos + offset,
annotation.endPos - annotation.startPos + 1
);
// if is function name itself, replace with qualified name
if (utility::containsElement(file->getSourceLocationById(annotation.locationId)->getTokenIds(), node.id) &&
text.size() <= nameHierarchy.getRawName().size())
{
std::wstring name = nameHierarchy.getQualifiedName();
offset = name.size() - text.size();
code = code.replace(annotation.startPos, annotation.endPos - annotation.startPos + 1, name);
text = name;
}
else
{
text = utility::convertWhiteSpacesToSingleSpaces(text);
}
annotatedTexts.push_back(std::make_pair(annotation.locationId, text));
}
// format
code = utility::convertWhiteSpacesToSingleSpaces(code);
snippet.code = utility::breakSignature(code, 50, ApplicationSettings::getInstance()->getCodeTabWidth());
// create source locations for annotations via stored texts
size_t pos = 0;
for (const std::pair<Id, std::wstring>& p : annotatedTexts)
{
pos = snippet.code.find(p.second, pos);
if (pos != std::wstring::npos)
{
SourceLocation* loc = file->getSourceLocationById(p.first);
snippet.locationFile->addSourceLocation(
loc->getType(), loc->getLocationId(), loc->getTokenIds(),
1, pos + 1, 1, pos + p.second.size()
);
pos += p.second.size();
}
}
return snippet;
}
// otherwise augment the name with signature with locations for type usages
snippet.code = utility::breakSignature(
nameHierarchy.getSignature().getPrefix(),
nameHierarchy.getQualifiedName(),
@@ -162,7 +162,7 @@ void CxxAstVisitorComponentIndexer::visitTagDecl(clang::TagDecl* d)
}
const SymbolKind symbolKind = utility::convertTagKind(d->getTagKind());
m_client->recordSymbol(
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(d),
symbolKind,
getParseLocation(d->getLocation()),
@@ -237,7 +237,7 @@ void CxxAstVisitorComponentIndexer::visitVarDecl(clang::VarDecl* d)
}
else
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
symbolKind,
getParseLocation(d->getLocation()),
@@ -285,7 +285,7 @@ void CxxAstVisitorComponentIndexer::visitFieldDecl(clang::FieldDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_FIELD,
getParseLocation(d->getLocation()),
@@ -323,14 +323,29 @@ void CxxAstVisitorComponentIndexer::visitFunctionDecl(clang::FunctionDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
getAstVisitor()->getDeclNameCache()->getValue(d),
clang::isa<clang::CXXMethodDecl>(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION,
getParseLocation(d->getNameInfo().getSourceRange()),
getParseLocationOfFunctionBody(d),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
if (d->isFirstDecl())
{
m_client->recordSymbolWithLocationAndScopeAndSignature(
getAstVisitor()->getDeclNameCache()->getValue(d),
clang::isa<clang::CXXMethodDecl>(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION,
getParseLocation(d->getNameInfo().getSourceRange()),
getParseLocationOfFunctionBody(d),
getSignatureLocation(d),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
}
else
{
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(d),
clang::isa<clang::CXXMethodDecl>(d) ? SYMBOL_METHOD : SYMBOL_FUNCTION,
getParseLocation(d->getNameInfo().getSourceRange()),
getParseLocationOfFunctionBody(d),
utility::convertAccessSpecifier(d->getAccess()),
utility::isImplicit(d) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT
);
}
if (d->isFunctionTemplateSpecialization())
{
@@ -381,7 +396,7 @@ void CxxAstVisitorComponentIndexer::visitEnumConstantDecl(clang::EnumConstantDec
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_ENUM_CONSTANT,
getParseLocation(d->getLocation()),
@@ -395,7 +410,7 @@ void CxxAstVisitorComponentIndexer::visitNamespaceDecl(clang::NamespaceDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_NAMESPACE,
getParseLocation(d->getLocation()),
@@ -410,7 +425,7 @@ void CxxAstVisitorComponentIndexer::visitNamespaceAliasDecl(clang::NamespaceAlia
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_NAMESPACE,
getParseLocation(d->getLocation()),
@@ -433,7 +448,7 @@ void CxxAstVisitorComponentIndexer::visitTypedefDecl(clang::TypedefDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
d->getAnonDeclWithTypedefName() == nullptr ? SYMBOL_TYPEDEF : utility::convertTagKind(d->getAnonDeclWithTypedefName()->getTagKind()),
getParseLocation(d->getLocation()),
@@ -447,7 +462,7 @@ void CxxAstVisitorComponentIndexer::visitTypeAliasDecl(clang::TypeAliasDecl* d)
{
if (getAstVisitor()->shouldVisitDecl(d))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
d->getAnonDeclWithTypedefName() == nullptr ? SYMBOL_TYPEDEF : utility::convertTagKind(d->getAnonDeclWithTypedefName()->getTagKind()),
getParseLocation(d->getLocation()),
@@ -493,7 +508,7 @@ void CxxAstVisitorComponentIndexer::visitNonTypeTemplateParmDecl(clang::NonTypeT
{
if (getAstVisitor()->shouldVisitDecl(d) && !d->getName().empty()) // We don't create symbols for unnamed template parameters.
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_TEMPLATE_PARAMETER,
getParseLocation(d->getLocation()),
@@ -507,7 +522,7 @@ void CxxAstVisitorComponentIndexer::visitTemplateTypeParmDecl(clang::TemplateTyp
{
if (getAstVisitor()->shouldVisitDecl(d) && !d->getName().empty()) // We don't create symbols for unnamed template parameters.
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_TEMPLATE_PARAMETER,
getParseLocation(d->getLocation()),
@@ -521,7 +536,7 @@ void CxxAstVisitorComponentIndexer::visitTemplateTemplateParmDecl(clang::Templat
{
if (getAstVisitor()->shouldVisitDecl(d) && !d->getName().empty()) // We don't create symbols for unnamed template parameters.
{
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
getAstVisitor()->getDeclNameCache()->getValue(d),
SYMBOL_TEMPLATE_PARAMETER,
getParseLocation(d->getLocation()),
@@ -701,7 +716,7 @@ void CxxAstVisitorComponentIndexer::visitLambdaExpr(clang::LambdaExpr* s)
clang::CXXMethodDecl* methodDecl = s->getCallOperator();
if (getAstVisitor()->shouldVisitDecl(methodDecl))
{
m_client->recordSymbol(
m_client->recordSymbolWithLocationAndScope(
getAstVisitor()->getDeclNameCache()->getValue(methodDecl),
SYMBOL_FUNCTION,
getParseLocation(s->getLocStart()),
@@ -748,6 +763,51 @@ void CxxAstVisitorComponentIndexer::recordTemplateMemberSpecialization(
}
}
ParseLocation CxxAstVisitorComponentIndexer::getSignatureLocation(clang::FunctionDecl* d)
{
clang::SourceRange signatureRange = d->getSourceRange();
if (d->doesThisDeclarationHaveABody())
{
const clang::TypeSourceInfo *TSI = d->getTypeSourceInfo();
if (!TSI)
{
return ParseLocation();
}
clang::FunctionTypeLoc FTL = TSI->getTypeLoc().IgnoreParens().getAs<clang::FunctionTypeLoc>();
if (FTL.isNull())
{
return ParseLocation();
}
const clang::SourceManager& sm = m_astContext->getSourceManager();
const clang::LangOptions& opts = m_astContext->getLangOpts();
clang::SourceLocation endLoc = FTL.getSourceRange().getEnd();
while (endLoc < signatureRange.getEnd())
{
llvm::Optional<clang::Token> token = clang::Lexer::findNextToken(endLoc, sm, opts);
if (token.hasValue())
{
const clang::tok::TokenKind tokenKind = token.getValue().getKind();
if (tokenKind == clang::tok::l_brace || tokenKind == clang::tok::colon)
{
signatureRange.setEnd(endLoc);
break;
}
endLoc = token.getValue().getLocation();
}
else
{
return ParseLocation();
}
}
}
return getParseLocation(signatureRange);
}
ParseLocation CxxAstVisitorComponentIndexer::getParseLocationOfTagDeclBody(clang::TagDecl* decl) const
{
return getAstVisitor()->getParseLocationOfTagDeclBody(decl);
@@ -52,6 +52,7 @@ private:
SymbolKind symbolKind
);
ParseLocation getSignatureLocation(clang::FunctionDecl* d);
ParseLocation getParseLocationOfTagDeclBody(clang::TagDecl* decl) const;
ParseLocation getParseLocationOfFunctionBody(const clang::FunctionDecl* decl) const;
ParseLocation getParseLocation(const clang::SourceLocation& loc) const;
@@ -76,7 +76,7 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
const NameHierarchy nameHierarchy(utility::decodeFromUtf8(macroNameToken.getIdentifierInfo()->getName().str()), NAME_DELIMITER_CXX);
m_client->recordSymbol(
m_client->recordSymbolWithLocationAndScope(
nameHierarchy,
SYMBOL_MACRO,
getParseLocation(macroNameToken),
+5
View File
@@ -346,6 +346,11 @@ void QtCodeField::createAnnotations(std::shared_ptr<SourceLocationFile> location
locationFile->forEachSourceLocation(
[&](const SourceLocation* location)
{
if (location->getType() == LOCATION_SIGNATURE)
{
return;
}
if (location->getLocationId() && locationIds.find(location->getLocationId()) != locationIds.end())
{
return;
+1 -1
View File
@@ -161,7 +161,7 @@ void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile,
locationFile->forEachStartSourceLocation(
[&](SourceLocation* location)
{
if (location->isScopeLocation())
if (location->isScopeLocation() || location->getType() == LOCATION_SIGNATURE)
{
return;
}
+37 -14
View File
@@ -47,18 +47,19 @@ JavaParser::JavaParser(std::shared_ptr<ParserClient> client)
std::vector<JavaEnvironment::NativeMethod> methods;
methods.push_back({"getInterrupted", "(I)Z", (void*)&JavaParser::GetInterrupted});
methods.push_back({"logInfo", "(ILjava/lang/String;)V", (void*)&JavaParser::LogInfo});
methods.push_back({"logWarning", "(ILjava/lang/String;)V", (void*)&JavaParser::LogWarning});
methods.push_back({"logError", "(ILjava/lang/String;)V", (void*)&JavaParser::LogError});
methods.push_back({"recordSymbol", "(ILjava/lang/String;III)V", (void*)&JavaParser::RecordSymbol});
methods.push_back({"recordSymbolWithLocation", "(ILjava/lang/String;IIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocation});
methods.push_back({"recordSymbolWithLocationAndScope", "(ILjava/lang/String;IIIIIIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocationAndScope});
methods.push_back({"recordReference", "(IILjava/lang/String;Ljava/lang/String;IIII)V", (void*)&JavaParser::RecordReference});
methods.push_back({"recordQualifierLocation", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordQualifierLocation});
methods.push_back({"recordLocalSymbol", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordLocalSymbol});
methods.push_back({"recordComment", "(IIIII)V", (void*)&JavaParser::RecordComment});
methods.push_back({"recordError", "(ILjava/lang/String;IIIIII)V", (void*)&JavaParser::RecordError});
methods.push_back({ "getInterrupted", "(I)Z", (void*)&JavaParser::GetInterrupted });
methods.push_back({ "logInfo", "(ILjava/lang/String;)V", (void*)&JavaParser::LogInfo });
methods.push_back({ "logWarning", "(ILjava/lang/String;)V", (void*)&JavaParser::LogWarning });
methods.push_back({ "logError", "(ILjava/lang/String;)V", (void*)&JavaParser::LogError });
methods.push_back({ "recordSymbol", "(ILjava/lang/String;III)V", (void*)&JavaParser::RecordSymbol });
methods.push_back({ "recordSymbolWithLocation", "(ILjava/lang/String;IIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocation });
methods.push_back({ "recordSymbolWithLocationAndScope", "(ILjava/lang/String;IIIIIIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocationAndScope });
methods.push_back({ "recordSymbolWithLocationAndScopeAndSignature", "(ILjava/lang/String;IIIIIIIIIIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocationAndScopeAndSignature });
methods.push_back({ "recordReference", "(IILjava/lang/String;Ljava/lang/String;IIII)V", (void*)&JavaParser::RecordReference });
methods.push_back({ "recordQualifierLocation", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordQualifierLocation });
methods.push_back({ "recordLocalSymbol", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordLocalSymbol });
methods.push_back({ "recordComment", "(IIIII)V", (void*)&JavaParser::RecordComment });
methods.push_back({ "recordError", "(ILjava/lang/String;IIIIII)V", (void*)&JavaParser::RecordError });
m_javaEnvironment->registerNativeMethods("com/sourcetrail/JavaIndexer", methods);
}
@@ -183,7 +184,7 @@ void JavaParser::doRecordSymbolWithLocation(
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbol(
m_client->recordSymbolWithLocation(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
@@ -202,7 +203,7 @@ void JavaParser::doRecordSymbolWithLocationAndScope(
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbol(
m_client->recordSymbolWithLocationAndScope(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
@@ -212,6 +213,28 @@ void JavaParser::doRecordSymbolWithLocationAndScope(
);
}
void JavaParser::doRecordSymbolWithLocationAndScopeAndSignature(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint scopeBeginLine, jint scopeBeginColumn, jint scopeEndLine, jint scopeEndColumn,
jint signatureBeginLine, jint signatureBeginColumn, jint signatureEndLine, jint signatureEndColumn,
jint jAccess, jint jDefinitionKind
)
{
AccessKind access = intToAccessKind(jAccess);
DefinitionKind definitionKind = intToDefinitionKind(jDefinitionKind);
m_client->recordSymbolWithLocationAndScopeAndSignature(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))),
intToSymbolKind(jSymbolKind),
ParseLocation(m_currentFilePath, beginLine, beginColumn, endLine, endColumn),
ParseLocation(m_currentFilePath, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn),
ParseLocation(m_currentFilePath, signatureBeginLine, signatureBeginColumn, signatureEndLine, signatureEndColumn),
access,
definitionKind
);
}
void JavaParser::doRecordReference(
jint jReferenceKind, jstring jReferencedName, jstring jContextName,
jint beginLine, jint beginColumn, jint endLine, jint endColumn
+66 -37
View File
@@ -62,62 +62,82 @@ private:
#define MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10
#define MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11
#define MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12
#define MAKE_PARAMS_13(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13
#define MAKE_PARAMS_14(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13, t14 arg14
#define MAKE_PARAMS_15(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13, t14 arg14, t15 arg15
#define MAKE_PARAMS_16(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13, t14 arg14, t15 arg15, t16 arg16
//.. add as many MAKE_PARAMS_* as required
#define MAKE_ARGS_0()
#define MAKE_ARGS_1(type) arg1
#define MAKE_ARGS_2(t1, t2) arg1, arg2
#define MAKE_ARGS_3(t1, t2, t3) arg1, arg2, arg3
#define MAKE_ARGS_4(t1, t2, t3, t4) arg1, arg2, arg3, arg4
#define MAKE_ARGS_5(t1, t2, t3, t4, t5) arg1, arg2, arg3, arg4, arg5
#define MAKE_ARGS_6(t1, t2, t3, t4, t5, t6) arg1, arg2, arg3, arg4, arg5, arg6
#define MAKE_ARGS_7(t1, t2, t3, t4, t5, t6, t7) arg1, arg2, arg3, arg4, arg5, arg6, arg7
#define MAKE_ARGS_8(t1, t2, t3, t4, t5, t6, t7, t8) arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8
#define MAKE_ARGS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9) arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
#define MAKE_ARGS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
#define MAKE_ARGS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11
#define MAKE_ARGS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12
#define MAKE_ARGS_1() arg1
#define MAKE_ARGS_2() arg1, arg2
#define MAKE_ARGS_3() arg1, arg2, arg3
#define MAKE_ARGS_4() arg1, arg2, arg3, arg4
#define MAKE_ARGS_5() arg1, arg2, arg3, arg4, arg5
#define MAKE_ARGS_6() arg1, arg2, arg3, arg4, arg5, arg6
#define MAKE_ARGS_7() arg1, arg2, arg3, arg4, arg5, arg6, arg7
#define MAKE_ARGS_8() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8
#define MAKE_ARGS_9() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
#define MAKE_ARGS_10() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
#define MAKE_ARGS_11() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11
#define MAKE_ARGS_12() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12
#define MAKE_ARGS_13() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13
#define MAKE_ARGS_14() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14
#define MAKE_ARGS_15() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15
#define MAKE_ARGS_16() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16
//.. add as many MAKE_ARGS_* as there are MAKE_PARAMS_*
#define DEF_RELAYING_METHOD_0(NAME) \
#define DEF_RELAYING_METHOD_0(NAME) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_0(), MAKE_ARGS_0())
#define DEF_RELAYING_METHOD_1(NAME, t1) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_1(t1), MAKE_ARGS_1(t1))
#define DEF_RELAYING_METHOD_1(NAME, t1) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_1(t1), MAKE_ARGS_1())
#define DEF_RELAYING_METHOD_2(NAME, t1, t2) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_2(t1, t2), MAKE_ARGS_2(t1, t2))
#define DEF_RELAYING_METHOD_2(NAME, t1, t2) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_2(t1, t2), MAKE_ARGS_2())
#define DEF_RELAYING_METHOD_3(NAME, t1, t2, t3) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_3(t1, t2, t3), MAKE_ARGS_3(t1, t2, t3))
#define DEF_RELAYING_METHOD_3(NAME, t1, t2, t3) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_3(t1, t2, t3), MAKE_ARGS_3())
#define DEF_RELAYING_METHOD_4(NAME, t1, t2, t3, t4) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_4(t1, t2, t3, t4), MAKE_ARGS_4(t1, t2, t3, t4))
#define DEF_RELAYING_METHOD_4(NAME, t1, t2, t3, t4) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_4(t1, t2, t3, t4), MAKE_ARGS_4())
#define DEF_RELAYING_METHOD_5(NAME, t1, t2, t3, t4, t5) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_5(t1, t2, t3, t4, t5), MAKE_ARGS_5(t1, t2, t3, t4, t5))
#define DEF_RELAYING_METHOD_5(NAME, t1, t2, t3, t4, t5) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_5(t1, t2, t3, t4, t5), MAKE_ARGS_5())
#define DEF_RELAYING_METHOD_6(NAME, t1, t2, t3, t4, t5, t6) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_6(t1, t2, t3, t4, t5, t6), MAKE_ARGS_6(t1, t2, t3, t4, t5, t6))
#define DEF_RELAYING_METHOD_6(NAME, t1, t2, t3, t4, t5, t6) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_6(t1, t2, t3, t4, t5, t6), MAKE_ARGS_6())
#define DEF_RELAYING_METHOD_7(NAME, t1, t2, t3, t4, t5, t6, t7) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_7(t1, t2, t3, t4, t5, t6, t7), MAKE_ARGS_7(t1, t2, t3, t4, t5, t6, t7))
#define DEF_RELAYING_METHOD_7(NAME, t1, t2, t3, t4, t5, t6, t7) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_7(t1, t2, t3, t4, t5, t6, t7), MAKE_ARGS_7())
#define DEF_RELAYING_METHOD_8(NAME, t1, t2, t3, t4, t5, t6, t7, t8) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_8(t1, t2, t3, t4, t5, t6, t7, t8), MAKE_ARGS_8(t1, t2, t3, t4, t5, t6, t7, t8))
#define DEF_RELAYING_METHOD_8(NAME, t1, t2, t3, t4, t5, t6, t7, t8) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_8(t1, t2, t3, t4, t5, t6, t7, t8), MAKE_ARGS_8())
#define DEF_RELAYING_METHOD_9(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9), MAKE_ARGS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9))
#define DEF_RELAYING_METHOD_9(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9), MAKE_ARGS_9())
#define DEF_RELAYING_METHOD_10(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10), MAKE_ARGS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10))
#define DEF_RELAYING_METHOD_10(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10), MAKE_ARGS_10())
#define DEF_RELAYING_METHOD_11(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11), MAKE_ARGS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11))
#define DEF_RELAYING_METHOD_11(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11), MAKE_ARGS_11())
#define DEF_RELAYING_METHOD_12(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12), MAKE_ARGS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12))
#define DEF_RELAYING_METHOD_12(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12), MAKE_ARGS_12())
#define DEF_RELAYING_METHOD_13(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_13(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13), MAKE_ARGS_13())
#define DEF_RELAYING_METHOD_14(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_14(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14), MAKE_ARGS_14())
#define DEF_RELAYING_METHOD_15(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_15(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15), MAKE_ARGS_15())
#define DEF_RELAYING_METHOD_16(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_16(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16), MAKE_ARGS_16())
#define DEF_RELAYING_METHOD(NAME, PARAMETERS, ARGUMENTS) \
static void NAME(JNIEnv *env, jobject objectOrClass, jint parserId PARAMETERS) \
@@ -139,6 +159,7 @@ private:
DEF_RELAYING_METHOD_4(RecordSymbol, jstring, jint, jint, jint)
DEF_RELAYING_METHOD_8(RecordSymbolWithLocation, jstring, jint, jint, jint, jint, jint, jint, jint)
DEF_RELAYING_METHOD_12(RecordSymbolWithLocationAndScope, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint)
DEF_RELAYING_METHOD_16(RecordSymbolWithLocationAndScopeAndSignature, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint)
DEF_RELAYING_METHOD_7(RecordReference, jint, jstring, jstring, jint, jint, jint, jint)
DEF_RELAYING_METHOD_5(RecordQualifierLocation, jstring, jint, jint, jint, jint)
DEF_RELAYING_METHOD_5(RecordLocalSymbol, jstring, jint, jint, jint, jint)
@@ -192,6 +213,14 @@ private:
jint jAccess, jint jDefinitionKind
);
void doRecordSymbolWithLocationAndScopeAndSignature(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint scopeBeginLine, jint scopeBeginColumn, jint scopeEndLine, jint scopeEndColumn,
jint signatureBeginLine, jint signatureBeginColumn, jint signatureEndLine, jint signatureEndColumn,
jint jAccess, jint jDefinitionKind
);
void doRecordReference(jint jReferenceKind, jstring jReferencedName, jstring jContextName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordQualifierLocation(jstring jQualifierName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordLocalSymbol(jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
+93
View File
@@ -336,6 +336,76 @@ namespace utility
return ret;
}
std::wstring breakSignature(std::wstring signature, size_t maxLineLength, size_t tabWidth)
{
if (signature.size() <= maxLineLength)
{
return signature;
}
size_t parenCount = 0;
size_t parenPos = 0;
size_t openParenPos = 0;
size_t closeParenPos = 0;
while (true)
{
closeParenPos = signature.find(L')', openParenPos);
openParenPos = signature.find(L'(', openParenPos);
if (openParenPos == std::wstring::npos)
{
break;
}
else if (closeParenPos == std::wstring::npos)
{
return signature;
}
else if (closeParenPos < openParenPos)
{
if (parenCount == 0)
{
return signature;
}
parenCount--;
openParenPos = closeParenPos;
}
else
{
if (!parenCount)
{
parenPos = openParenPos;
}
parenCount++;
}
openParenPos++;
}
if (!parenPos)
{
return signature;
}
std::wstring returnPart;
std::wstring namePart = signature.substr(0, parenPos);
std::wstring paramPart = signature.substr(parenPos);
if (namePart.size() && namePart.back() == L' ')
{
namePart.pop_back();
}
size_t splitPos = namePart.rfind(L' ');
if (splitPos != std::wstring::npos)
{
returnPart = namePart.substr(0, splitPos);
namePart = namePart.substr(splitPos + 1);
}
return breakSignature(returnPart, namePart, paramPart, maxLineLength, tabWidth);
}
std::wstring breakSignature(
std::wstring returnPart, std::wstring namePart, std::wstring paramPart,
size_t maxLineLength, size_t tabWidth)
@@ -352,6 +422,11 @@ namespace utility
{
namePart += paramPart[0];
paramPart.erase(0, 1);
if (paramPart.front() == L' ')
{
paramPart.erase(0, 1);
}
}
size_t parenPos = paramPart.rfind(L')');
@@ -491,4 +566,22 @@ namespace utility
return str.substr(0, size - 3) + L"...";
}
}
std::wstring convertWhiteSpacesToSingleSpaces(const std::wstring &str)
{
std::wstring res = replace(str, L"\n", L" ");
res = replace(res, L"\t", L" ");
std::deque<std::wstring> parts = split<std::deque<std::wstring>>(res, L" ");
for (size_t i = 1; i <= parts.size(); i++)
{
if (!parts[i-1].size())
{
parts.erase(parts.begin() + i-1);
i--;
}
}
return join<std::deque<std::wstring>>(parts, L" ");
}
}
+3
View File
@@ -73,6 +73,7 @@ namespace utility
std::wstring replaceBetween(const std::wstring& str, wchar_t startDelimiter, wchar_t endDelimiter, const std::wstring& to);
std::string insertLineBreaksAtBlankSpaces(const std::string& s, size_t maxLineLength);
std::wstring breakSignature(std::wstring signature, size_t maxLineLength, size_t tabWidth);
std::wstring breakSignature(
std::wstring returnPart, std::wstring namePart, std::wstring paramPart,
size_t maxLineLength, size_t tabWidth);
@@ -90,6 +91,8 @@ namespace utility
std::string elide(const std::string& str, ElideMode mode, size_t size);
std::wstring elide(const std::wstring& str, ElideMode mode, size_t size);
std::wstring convertWhiteSpacesToSingleSpaces(const std::wstring &str);
template <typename ContainerType>
ContainerType split(const std::string& str, const std::string& delimiter)
{
+28 -11
View File
@@ -186,7 +186,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->functions, L"int ceil(float) <1:1 <1:5 1:8> 4:1>"
client->functions, L"int ceil(float) <1:1 <1:1 <1:5 1:8> 1:17> 4:1>"
));
}
@@ -200,7 +200,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->functions, L"static int ceil(float) (input.cc) <1:1 <1:12 1:15> 4:1>"
client->functions, L"static int ceil(float) (input.cc) <1:1 <1:1 <1:12 1:15> 1:24> 4:1>"
));
}
@@ -215,7 +215,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public void B::B() <4:2 4:2>"
client->methods, L"public void B::B() <4:2 <4:2 4:2> 4:4>"
));
}
@@ -230,7 +230,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public B & B::operator=(const B &) <4:5 4:13>"
client->methods, L"public B & B::operator=(const B &) <4:2 <4:5 4:13> 4:29>"
));
}
@@ -263,7 +263,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public void B::process() <4:15 4:21>"
client->methods, L"public void B::process() <4:2 <4:15 4:21> 4:23>"
));
}
@@ -278,7 +278,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"protected void B::process() <4:15 4:21>"
client->methods, L"protected void B::process() <4:2 <4:15 4:21> 4:27>"
));
}
@@ -1108,7 +1108,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"private int A<typename T>::foo() <4:6 4:8>"
client->methods, L"private int A<typename T>::foo() <4:2 <4:6 4:8> 4:10>"
));
}
@@ -1225,7 +1225,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->functions, L"int test<int>(int) <2:1 <2:3 2:6> 5:1>"
client->functions, L"int test<int>(int) <2:1 <2:1 <2:3 2:6> 2:11> 5:1>"
));
}
@@ -1436,7 +1436,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->functions, L"int anonymous namespace (input.cc<1:1>)::sum(int, int) <3:6 3:8>"
client->functions, L"int anonymous namespace (input.cc<1:1>)::sum(int, int) <3:2 <3:6 3:8> 3:22>"
));
}
@@ -1453,7 +1453,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"private bool B::C::isGreat() const <5:8 5:14>"
client->methods, L"private bool B::C::isGreat() const <5:3 <5:8 5:14> 5:22>"
));
}
@@ -1664,7 +1664,7 @@ public:
TS_ASSERT(utility::containsElement<std::wstring>(client->methods, L"public void TestClass::TestClass() <1:7 <1:7 1:15> 1:15>"));
TS_ASSERT(utility::containsElement<std::wstring>(client->methods, L"public void TestClass::TestClass(const TestClass &) <1:7 <1:7 1:15> 1:15>"));
TS_ASSERT(utility::containsElement<std::wstring>(client->methods, L"public void TestClass::TestClass(TestClass &&) <1:7 1:15>"));
TS_ASSERT(utility::containsElement<std::wstring>(client->methods, L"public void TestClass::TestClass(TestClass &&) <1:7 <1:7 1:15> 1:15>"));
}
///////////////////////////////////////////////////////////////////////////////
@@ -4187,6 +4187,23 @@ public:
TS_ASSERT_EQUALS(client->localSymbols.size(), 9);
}
void test_cxx_parser_finds_correct_signature_location_of_constructor_with_initializer_list()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class A\n"
"{\n"
" A(const int& foo) : m_foo(foo)\n"
" {\n"
" }\n"
" const int m_foo\n"
"}\n"
);;
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"private void A::A(const int &) <3:2 <3:2 <3:2 3:2> 3:18> 5:2>"
));
}
void test_cxx_parser_catches_error()
{
std::shared_ptr<TestParserClient> client = parseCode(
+4 -4
View File
@@ -149,7 +149,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public foo.A.A() <4:2 <4:9 4:9> 6:2>"
client->methods, L"public foo.A.A() <4:2 <4:2 <4:9 4:9> 4:11> 6:2>"
));
}
@@ -166,7 +166,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public void foo.A.bar(foo.A) <4:2 <4:14 4:16> 6:2>"
client->methods, L"public void foo.A.bar(foo.A) <4:2 <4:2 <4:14 4:16> 4:21> 6:2>"
));
}
@@ -209,7 +209,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public void foo.A.bar.anonymous class (input.cc<10:3>).foo() <11:4 <11:16 11:18> 11:23>"
client->methods, L"public void foo.A.bar.anonymous class (input.cc<10:3>).foo() <11:4 <11:4 <11:16 11:18> 11:20> 11:23>"
));
}
@@ -226,7 +226,7 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public static void foo.A.bar() <4:2 <4:21 4:23> 6:2>"
client->methods, L"public static void foo.A.bar() <4:2 <4:2 <4:21 4:23> 4:25> 6:2>"
));
}
+16 -7
View File
@@ -14,7 +14,7 @@ public:
{
}
virtual Id recordSymbol(
Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) override
{
@@ -22,7 +22,7 @@ public:
return 0;
}
virtual Id recordSymbol(
Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) override
@@ -31,7 +31,7 @@ public:
return 0;
}
virtual Id recordSymbol(
Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) override
@@ -40,6 +40,15 @@ public:
return 0;
}
Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) override
{
recordLine(symbolKindToString(symbolKind) + L" " + addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access) + L" [" + location.filePath.fileName(), location, scopeLocation, signatureLocation) + L"]\n");
return 0;
}
void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) override
@@ -78,17 +87,17 @@ public:
recordLine(L"QUALIFIER: " + addLocationSuffix(qualifierName.getQualifiedNameWithSignature() + L" [" + location.filePath.fileName(), location) + L"]\n");
}
virtual void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override
void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override
{
recordLine(L"LOCAL_SYMBOL: " + addLocationSuffix(name + L" [" + location.filePath.fileName(), location) + L"]\n");
}
virtual void recordFile(const FileInfo& fileInfo, bool indexed) override
void recordFile(const FileInfo& fileInfo, bool indexed) override
{
recordLine(L"FILE: " + fileInfo.path.fileName() + (indexed ? L"" : L" non-indexed") + L"\n");
}
virtual void recordComment(const ParseLocation& location) override
void recordComment(const ParseLocation& location) override
{
recordLine(L"COMMENT: " + addLocationSuffix(L"comment [" + location.filePath.fileName(), location) + L"]\n");
}
@@ -96,7 +105,7 @@ public:
std::wstring m_lines;
private:
virtual void doRecordError(const ParseLocation& location, const std::wstring& message,
void doRecordError(const ParseLocation& location, const std::wstring& message,
bool fatal, bool indexed, const FilePath& translationUnit) override
{
recordLine(L"ERROR: " + addLocationSuffix(message + L" [" + location.filePath.fileName(), location) + L"]\n");
+21 -8
View File
@@ -7,7 +7,7 @@
class TestParserClient: public ParserClient
{
public:
virtual Id recordSymbol(
Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) override
{
@@ -19,7 +19,7 @@ public:
return 0;
}
virtual Id recordSymbol(
Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) override
@@ -32,7 +32,7 @@ public:
return 0;
}
virtual Id recordSymbol(
Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) override
@@ -45,6 +45,19 @@ public:
return 0;
}
Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) override
{
std::vector<std::wstring>* bin = getBinForSymbolKind(symbolKind);
if (bin != nullptr)
{
bin->push_back(addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access), location, scopeLocation, signatureLocation));
}
return 0;
}
void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) override
@@ -102,23 +115,23 @@ public:
}
}
virtual void recordQualifierLocation(
void recordQualifierLocation(
const NameHierarchy& qualifierName, const ParseLocation& location) override
{
qualifiers.push_back(addLocationSuffix(qualifierName.getQualifiedNameWithSignature(), location));
}
virtual void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override
void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override
{
localSymbols.push_back(addLocationSuffix(name, location));
}
virtual void recordFile(const FileInfo& fileInfo, bool indexed) override
void recordFile(const FileInfo& fileInfo, bool indexed) override
{
files.insert(fileInfo.path.wstr());
}
virtual void recordComment(const ParseLocation& location) override
void recordComment(const ParseLocation& location) override
{
comments.push_back(addLocationSuffix(L"comment", location));
}
@@ -162,7 +175,7 @@ public:
std::vector<std::wstring> imports;
private:
virtual void doRecordError(
void doRecordError(
const ParseLocation& location,
const std::wstring& message,
bool fatal,