logic: respect class qualifyer in method call for python post processing (#951)

If the class of a called method is explicitly specified ("Base.__init__()"), only record an ambiguous edge to that method.
This commit is contained in:
Malte Langkabel
2020-03-30 21:24:23 +02:00
committed by GitHub
parent 31cbf6c11a
commit f6e8a2125d
8 changed files with 748 additions and 585 deletions
+180 -141
View File
@@ -19,6 +19,182 @@
#include "utilityFile.h"
#include "utilityString.h"
void TaskExecuteCustomCommands::runPythonPostProcessing(PersistentStorage& storage)
{
std::vector<Id> unsolvedLocationIds;
for (const StorageSourceLocation location: storage.getStorageSourceLocations())
{
if (intToLocationType(location.type) ==
LOCATION_UNSOLVED) // FIXME: this doesn't catch unsolved qualifiers -> convert
// Qualifier location type to qualifier edge
{
unsolvedLocationIds.push_back(location.id);
}
}
std::shared_ptr<SourceLocationCollection> locationCollection =
storage.getSourceLocationsForLocationIds(unsolvedLocationIds);
std::map<std::wstring, std::vector<StorageNode>> nodeNameToStorageNodes;
if (locationCollection->getSourceLocationCount() > 0)
{
for (const StorageNode& node: storage.getStorageNodes())
{
nodeNameToStorageNodes[NameHierarchy::deserialize(node.serializedName).back().getName()]
.push_back(node);
}
}
struct DataToInsert
{
StorageEdgeData edgeData;
Id sourceLocationId;
};
storage.setMode(SqliteIndexStorage::STORAGE_MODE_READ);
std::vector<DataToInsert> dataToInsert;
std::vector<StorageOccurrence> occurrencesToDelete;
locationCollection->forEachSourceLocationFile(
[&nodeNameToStorageNodes, &storage, &dataToInsert, &occurrencesToDelete](
std::shared_ptr<SourceLocationFile> locationFile) {
const FilePath filePath = locationFile->getFilePath();
if (filePath.empty())
{
return;
}
if (!filePath.exists())
{
LOG_WARNING(L"Skipping post processing for non-existing file: " + filePath.wstr());
return;
}
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
if (textAccess)
{
locationFile->forEachStartSourceLocation([textAccess,
&nodeNameToStorageNodes,
&storage,
&dataToInsert,
&occurrencesToDelete](
const SourceLocation* startLoc) {
if (!startLoc)
{
return;
}
const SourceLocation* endLoc = startLoc->getOtherLocation();
if (!endLoc)
{
return;
}
const std::string tokenLine = textAccess->getLine(
static_cast<unsigned int>(startLoc->getLineNumber()));
const std::wstring token = utility::decodeFromUtf8(tokenLine.substr(
startLoc->getColumnNumber() - 1,
endLoc->getColumnNumber() - startLoc->getColumnNumber() + 1));
std::string prefixString = tokenLine.substr(0, startLoc->getColumnNumber() - 1);
std::wstring definitionContextName = L"";
{
std::regex regex("\\s([^\\.()\\s]+)\\.$");
std::smatch matches;
std::regex_search(prefixString, matches, regex);
if (!matches.empty())
{
definitionContextName = utility::decodeFromUtf8(matches.str(1));
}
}
{
std::vector<StorageNode> targetNodes;
if (!definitionContextName.empty())
{
for (const StorageNode& node: nodeNameToStorageNodes[token])
{
NameHierarchy nameHierarchy = NameHierarchy::deserialize(
node.serializedName);
if (nameHierarchy.size() > 1 &&
nameHierarchy.getRange(0, nameHierarchy.size() - 1).back().getName() ==
definitionContextName)
{
targetNodes.push_back(node);
}
}
}
if (targetNodes.empty())
{
targetNodes = nodeNameToStorageNodes[token];
}
for (const StorageNode& targetNode: targetNodes)
{
for (const Id elementId: startLoc->getTokenIds())
{
const StorageEdge edge = storage.getEdgeById(elementId);
if (edge.id != 0) // for node elements this condition will fail
{
if (Edge::intToType(edge.type) == Edge::EDGE_INHERITANCE &&
intToNodeKind(targetNode.type) != NODE_CLASS)
{
continue;
}
dataToInsert.push_back(
{StorageEdgeData(edge.type, edge.sourceNodeId, targetNode.id),
startLoc->getLocationId()});
occurrencesToDelete.push_back(
StorageOccurrence(edge.id, startLoc->getLocationId()));
}
}
}
}
});
}
});
storage.setMode(SqliteIndexStorage::STORAGE_MODE_WRITE);
storage.startInjection();
std::vector<StorageEdge> edgesToInsert;
for (const DataToInsert& data: dataToInsert)
{
edgesToInsert.push_back(StorageEdge(0, data.edgeData));
}
const std::vector<Id> ambiguousEdgeIds = storage.addEdges(edgesToInsert);
if (ambiguousEdgeIds.size() == dataToInsert.size())
{
for (size_t i = 0; i < ambiguousEdgeIds.size(); i++)
{
storage.addElementComponent(StorageElementComponent(
ambiguousEdgeIds[i],
elementComponentKindToInt(ElementComponentKind::IS_AMBIGUOUS),
L""));
storage.addOccurrence(
StorageOccurrence(ambiguousEdgeIds[i], dataToInsert[i].sourceLocationId));
}
storage.setMode(SqliteIndexStorage::STORAGE_MODE_CLEAR);
storage.removeOccurrences(occurrencesToDelete);
std::set<Id> edgeIds;
for (const StorageOccurrence& occurrence: occurrencesToDelete)
{
edgeIds.insert(occurrence.elementId);
}
storage.removeElementsWithoutOccurrences(utility::toVector(edgeIds));
storage.finishInjection();
LOG_INFO("Finished Python post processing.");
}
else
{
LOG_ERROR("Error occurred while running Python post processing. Rolling back all changes.");
storage.rollbackInjection();
}
}
TaskExecuteCustomCommands::TaskExecuteCustomCommands(
std::unique_ptr<IndexerCommandProvider> indexerCommandProvider,
std::shared_ptr<PersistentStorage> storage,
@@ -129,6 +305,10 @@ Task::TaskState TaskExecuteCustomCommands::doUpdate(std::shared_ptr<Blackboard>
if (m_hasPythonCommands &&
ApplicationSettings::getInstance()->getPythonPostProcessingEnabled())
{
LOG_INFO("Starting Python post processing.");
m_dialogView->showUnknownProgressDialog(
L"Finish Indexing", L"Run Python Post Processing");
targetStorage.clearCaches();
targetStorage.buildCaches();
runPythonPostProcessing(targetStorage);
@@ -268,144 +448,3 @@ void TaskExecuteCustomCommands::runIndexerCommand(
blackboard->update<int>("indexed_source_file_count", [=](int count) { return count + 1; });
}
}
void TaskExecuteCustomCommands::runPythonPostProcessing(PersistentStorage& storage)
{
LOG_INFO("Starting Python post processing.");
m_dialogView->showUnknownProgressDialog(L"Finish Indexing", L"Run Python Post Processing");
std::vector<Id> unsolvedLocationIds;
for (const StorageSourceLocation location: storage.getStorageSourceLocations())
{
if (intToLocationType(location.type) ==
LOCATION_UNSOLVED) // FIXME: this doesn't catch unsolved qualifiers -> convert
// Qualifier location type to qualifier edge
{
unsolvedLocationIds.push_back(location.id);
}
}
std::shared_ptr<SourceLocationCollection> locationCollection =
storage.getSourceLocationsForLocationIds(unsolvedLocationIds);
std::map<std::wstring, std::vector<StorageNode>> nodeNameToStorageNodes;
if (locationCollection->getSourceLocationCount() > 0)
{
for (const StorageNode& node: storage.getStorageNodes())
{
nodeNameToStorageNodes[NameHierarchy::deserialize(node.serializedName).back().getName()]
.push_back(node);
}
}
struct DataToInsert
{
StorageEdgeData edgeData;
Id sourceLocationId;
};
storage.setMode(SqliteIndexStorage::STORAGE_MODE_READ);
std::vector<DataToInsert> dataToInsert;
std::vector<StorageOccurrence> occurrencesToDelete;
locationCollection->forEachSourceLocationFile(
[&nodeNameToStorageNodes, &storage, &dataToInsert, &occurrencesToDelete](
std::shared_ptr<SourceLocationFile> locationFile) {
const FilePath filePath = locationFile->getFilePath();
if (filePath.empty())
{
return;
}
if (!filePath.exists())
{
LOG_WARNING(L"Skipping post processing for non-existing file: " + filePath.wstr());
return;
}
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
if (textAccess)
{
locationFile->forEachStartSourceLocation(
[textAccess, &nodeNameToStorageNodes, &storage, &dataToInsert, &occurrencesToDelete](
const SourceLocation* startLoc) {
if (!startLoc)
{
return;
}
const SourceLocation* endLoc = startLoc->getOtherLocation();
if (!endLoc)
{
return;
}
const std::wstring token = utility::decodeFromUtf8(
textAccess->getLine(static_cast<unsigned int>(startLoc->getLineNumber()))
.substr(
startLoc->getColumnNumber() - 1,
endLoc->getColumnNumber() - startLoc->getColumnNumber() + 1));
for (const Id elementId: startLoc->getTokenIds())
{
const StorageEdge edge = storage.getEdgeById(elementId);
if (edge.id != 0)
{
for (const StorageNode& targetNode: nodeNameToStorageNodes[token])
{
if (Edge::intToType(edge.type) == Edge::EDGE_INHERITANCE &&
intToNodeKind(targetNode.type) != NODE_CLASS)
{
continue;
}
dataToInsert.push_back(
{StorageEdgeData(edge.type, edge.sourceNodeId, targetNode.id),
startLoc->getLocationId()});
occurrencesToDelete.push_back(
StorageOccurrence(edge.id, startLoc->getLocationId()));
}
}
}
});
}
});
storage.setMode(SqliteIndexStorage::STORAGE_MODE_WRITE);
storage.startInjection();
std::vector<StorageEdge> edgesToInsert;
for (const DataToInsert& data: dataToInsert)
{
edgesToInsert.push_back(StorageEdge(0, data.edgeData));
}
const std::vector<Id> ambiguousEdgeIds = storage.addEdges(edgesToInsert);
if (ambiguousEdgeIds.size() == dataToInsert.size())
{
for (size_t i = 0; i < ambiguousEdgeIds.size(); i++)
{
storage.addElementComponent(StorageElementComponent(
ambiguousEdgeIds[i],
elementComponentKindToInt(ElementComponentKind::IS_AMBIGUOUS),
L""));
storage.addOccurrence(
StorageOccurrence(ambiguousEdgeIds[i], dataToInsert[i].sourceLocationId));
}
storage.setMode(SqliteIndexStorage::STORAGE_MODE_CLEAR);
storage.removeOccurrences(occurrencesToDelete);
std::set<Id> edgeIds;
for (const StorageOccurrence& occurrence: occurrencesToDelete)
{
edgeIds.insert(occurrence.elementId);
}
storage.removeElementsWithoutOccurrences(utility::toVector(edgeIds));
storage.finishInjection();
LOG_INFO("Finished Python post processing.");
}
else
{
LOG_ERROR("Error occurred while running Python post processing. Rolling back all changes.");
storage.rollbackInjection();
}
}
@@ -20,6 +20,8 @@ class TaskExecuteCustomCommands
, public MessageListener<MessageIndexingInterrupted>
{
public:
static void runPythonPostProcessing(PersistentStorage& storage);
TaskExecuteCustomCommands(
std::unique_ptr<IndexerCommandProvider> indexerCommandProvider,
std::shared_ptr<PersistentStorage> storage,
@@ -38,9 +40,7 @@ private:
void executeParallelIndexerCommands(int threadId, std::shared_ptr<Blackboard> blackboard);
void runIndexerCommand(
std::shared_ptr<IndexerCommandCustom> indexerCommand, std::shared_ptr<Blackboard> blackboard);
void runPythonPostProcessing(PersistentStorage& storage);
private:
std::unique_ptr<IndexerCommandProvider> m_indexerCommandProvider;
std::shared_ptr<PersistentStorage> m_storage;
std::shared_ptr<DialogView> m_dialogView;
+2 -1
View File
@@ -3,7 +3,7 @@ add_files(
helper/TestFileRegister.cpp
helper/TestFileRegister.h
helper/TestIntermediateStorage.h
helper/TestStorage.h
test_main.cpp
@@ -25,6 +25,7 @@ add_files(
MatrixDynamicBaseTestSuite.cpp
MessageQueueTestSuite.cpp
NetworkProtocolHelperTestSuite.cpp
PythonIndexerTestSuite.cpp
RefreshInfoGeneratorTestSuite.cpp
SearchIndexTestSuite.cpp
SettingsMigratorTestSuite.cpp
File diff suppressed because it is too large Load Diff
@@ -13,7 +13,7 @@
# include "JavaEnvironmentFactory.h"
# include "JavaParser.h"
# include "ParserClientImpl.h"
# include "TestIntermediateStorage.h"
# include "TestStorage.h"
# include "TextAccess.h"
# include "TimeStamp.h"
# include "utility.h"
@@ -66,9 +66,9 @@ std::shared_ptr<TextAccess> parseCode(
const FilePath& projectDataSrcRoot,
const std::vector<FilePath>& classpath)
{
TestIntermediateStorage storage;
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
JavaParser parser(
std::make_shared<ParserClientImpl>(&storage), std::make_shared<IndexerStateInfo>());
std::make_shared<ParserClientImpl>(storage.get()), std::make_shared<IndexerStateInfo>());
std::shared_ptr<IndexerCommandJava> command = std::make_shared<IndexerCommandJava>(
sourceFilePath, L"12", classpath);
@@ -76,9 +76,7 @@ std::shared_ptr<TextAccess> parseCode(
parser.buildIndex(command);
duration += TimeStamp::now().deltaMS(startTime);
storage.generateStringLists();
return TextAccess::createFromLines(storage.m_lines);
return TextAccess::createFromLines(TestStorage::create(storage)->m_lines);
}
void processSourceFile(
+100 -101
View File
@@ -13,9 +13,9 @@
# include "utilityJava.h"
# include "utilityPathDetection.h"
# include "TestIntermediateStorage.h"
# include "TestStorage.h"
# define REQUIRE_MESSAGE(msg, cond) \
# define REQUIRE_MESSAGE(msg, cond) \
do \
{ \
INFO(msg); \
@@ -55,18 +55,16 @@ std::string setupJavaEnvironmentFactory()
return "";
}
std::shared_ptr<TestIntermediateStorage> parseCode(std::string code, bool logErrors = true)
std::shared_ptr<TestStorage> parseCode(std::string code, bool logErrors = true)
{
setupJavaEnvironmentFactory();
std::shared_ptr<TestIntermediateStorage> storage = std::make_shared<TestIntermediateStorage>();
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
JavaParser parser(
std::make_shared<ParserClientImpl>(storage.get()), std::make_shared<IndexerStateInfo>());
parser.buildIndex(FilePath(L"input.java"), TextAccess::createFromString(code));
storage->generateStringLists();
return storage;
return TestStorage::create(storage);
}
} // namespace
@@ -100,14 +98,14 @@ TEST_CASE("java parser can setup environment factory")
TEST_CASE("java parser finds package declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode("package foo;\n");
std::shared_ptr<TestStorage> client = parseCode("package foo;\n");
REQUIRE(utility::containsElement<std::wstring>(client->packages, L"foo <1:9 1:11>"));
}
TEST_CASE("java parser finds anotation declaration in defaut package")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
"}\n");
@@ -118,7 +116,7 @@ TEST_CASE("java parser finds anotation declaration in defaut package")
TEST_CASE("java parser finds anotation member declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int value() default 0;\n"
@@ -130,7 +128,7 @@ TEST_CASE("java parser finds anotation member declaration")
TEST_CASE("java parser finds class declaration in defaut package")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
"}\n");
@@ -141,7 +139,7 @@ TEST_CASE("java parser finds class declaration in defaut package")
TEST_CASE("java parser finds interface declaration in defaut package")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public interface A\n"
"{\n"
"}\n");
@@ -152,7 +150,7 @@ TEST_CASE("java parser finds interface declaration in defaut package")
TEST_CASE("java parser finds class declaration in named package")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -164,7 +162,7 @@ TEST_CASE("java parser finds class declaration in named package")
TEST_CASE("java parser finds class declaration in nested named package")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -176,7 +174,7 @@ TEST_CASE("java parser finds class declaration in nested named package")
TEST_CASE("java parser finds enum declaration in named package")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public enum A\n"
"{\n"
@@ -188,7 +186,7 @@ TEST_CASE("java parser finds enum declaration in named package")
TEST_CASE("java parser finds enum constant declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public enum A\n"
"{\n"
@@ -201,7 +199,7 @@ TEST_CASE("java parser finds enum constant declaration")
TEST_CASE("java parser finds constructor declaration without parameters")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -216,7 +214,7 @@ TEST_CASE("java parser finds constructor declaration without parameters")
TEST_CASE("java parser finds method declaration with custom type in signature")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -231,7 +229,7 @@ TEST_CASE("java parser finds method declaration with custom type in signature")
TEST_CASE("java parser finds anonymous class declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -248,7 +246,7 @@ TEST_CASE("java parser finds anonymous class declaration")
TEST_CASE("java parser finds method declaration in anonymous class")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -272,7 +270,7 @@ TEST_CASE("java parser finds method declaration in anonymous class")
TEST_CASE("java parser finds method declaration with static keyword in signature")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -287,7 +285,7 @@ TEST_CASE("java parser finds method declaration with static keyword in signature
TEST_CASE("java parser finds field declaration with initial assignment")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -300,7 +298,7 @@ TEST_CASE("java parser finds field declaration with initial assignment")
TEST_CASE("java parser finds public access specifier in field declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -313,7 +311,7 @@ TEST_CASE("java parser finds public access specifier in field declaration")
TEST_CASE("java parser finds protected access specifier in field declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -326,7 +324,7 @@ TEST_CASE("java parser finds protected access specifier in field declaration")
TEST_CASE("java parser finds private access specifier in field declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -339,7 +337,7 @@ TEST_CASE("java parser finds private access specifier in field declaration")
TEST_CASE("java parser finds static keyword in field declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -352,7 +350,7 @@ TEST_CASE("java parser finds static keyword in field declaration")
TEST_CASE("java parser finds declaration of method parameter")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -367,7 +365,7 @@ TEST_CASE("java parser finds declaration of method parameter")
TEST_CASE("java parser finds declaration of local variable")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -382,7 +380,7 @@ TEST_CASE("java parser finds declaration of local variable")
TEST_CASE("java parser finds declaration of type parameter of class")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A <T>\n"
"{\n"
"}\n");
@@ -392,7 +390,7 @@ TEST_CASE("java parser finds declaration of type parameter of class")
TEST_CASE("java parser finds declaration of type parameter of method")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public <T> void foo()\n"
@@ -406,7 +404,7 @@ TEST_CASE("java parser finds declaration of type parameter of method")
TEST_CASE("java parser finds field of interface to be implicitly static")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public interface A\n"
"{\n"
" int b = 5;\n"
@@ -418,7 +416,7 @@ TEST_CASE("java parser finds field of interface to be implicitly static")
TEST_CASE("java parser finds line comment")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"// this is a line comment\n"
"package foo;\n");
@@ -427,7 +425,7 @@ TEST_CASE("java parser finds line comment")
TEST_CASE("java parser finds block comment")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"/* this is a line comment*/\n"
"package foo;\n");
@@ -436,7 +434,7 @@ TEST_CASE("java parser finds block comment")
TEST_CASE("java parser finds missing semicolon as parse error")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode("package foo\n");
std::shared_ptr<TestStorage> client = parseCode("package foo\n");
REQUIRE(utility::containsElement<std::wstring>(
client->errors, L"Syntax error on token \"foo\", ; expected after this token <1:9 1:9>"));
@@ -444,7 +442,7 @@ TEST_CASE("java parser finds missing semicolon as parse error")
TEST_CASE("java parser finds missing import as error")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode("import foo;\n");
std::shared_ptr<TestStorage> client = parseCode("import foo;\n");
REQUIRE(utility::containsElement<std::wstring>(
client->errors, L"The import foo cannot be resolved <1:8 1:8>"));
@@ -456,7 +454,7 @@ TEST_CASE("java parser finds missing import as error")
TEST_CASE("java parser finds class declaration nested in class")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -471,7 +469,7 @@ TEST_CASE("java parser finds class declaration nested in class")
TEST_CASE("java parser finds class declaration nested in method")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -493,7 +491,7 @@ TEST_CASE("java parser finds class declaration nested in method")
TEST_CASE("java parser finds no qualifier location of standalone this expression")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -508,14 +506,14 @@ TEST_CASE("java parser finds no qualifier location of standalone this expression
TEST_CASE("java parser finds qualifier location of import declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode("import foo.bar;\n");
std::shared_ptr<TestStorage> client = parseCode("import foo.bar;\n");
REQUIRE(utility::containsElement<std::wstring>(client->qualifiers, L"foo <1:8 1:10>"));
}
TEST_CASE("java parser finds qualifier location of simple type")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -531,7 +529,7 @@ TEST_CASE("java parser finds qualifier location of simple type")
TEST_CASE("java parser finds qualifier location of field access")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -548,7 +546,7 @@ TEST_CASE("java parser finds qualifier location of field access")
TEST_CASE("java parser finds qualifier location of super field access")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"class A\n"
"{\n"
@@ -570,7 +568,7 @@ TEST_CASE("java parser finds qualifier location of super field access")
TEST_CASE("java parser finds qualifier location of this expression")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"class A\n"
"{\n"
@@ -587,7 +585,7 @@ TEST_CASE("java parser finds qualifier location of this expression")
TEST_CASE("java parser finds qualifier location of method invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -604,7 +602,7 @@ TEST_CASE("java parser finds qualifier location of method invocation")
TEST_CASE("java parser finds qualifier location of method invocation on this")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -619,7 +617,7 @@ TEST_CASE("java parser finds qualifier location of method invocation on this")
TEST_CASE("java parser finds qualifier location of super method invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -650,7 +648,7 @@ TEST_CASE("java parser finds qualifier location of super method invocation")
TEST_CASE("java parser finds qualifier location of creation reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -675,7 +673,7 @@ TEST_CASE("java parser finds qualifier location of creation reference")
TEST_CASE("java parser finds qualifier location of expression method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -701,7 +699,7 @@ TEST_CASE("java parser finds qualifier location of expression method reference")
TEST_CASE("java parser finds qualifier location of super method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -724,7 +722,7 @@ TEST_CASE("java parser finds qualifier location of super method reference")
TEST_CASE("java parser finds qualifier location of class instance creation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -746,7 +744,7 @@ TEST_CASE("java parser finds qualifier location of class instance creation")
TEST_CASE("java parser finds usage of marker annotation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
"}\n"
@@ -762,7 +760,7 @@ TEST_CASE("java parser finds usage of marker annotation")
TEST_CASE("java parser finds usage of single member annotation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int value() default 0;\n"
@@ -779,7 +777,7 @@ TEST_CASE("java parser finds usage of single member annotation")
TEST_CASE("java parser finds usage of normal annotation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int a() default 0;\n"
@@ -797,7 +795,7 @@ TEST_CASE("java parser finds usage of normal annotation")
TEST_CASE("java parser finds usage of normal annotation member in initialization")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int a() default 0;\n"
@@ -815,7 +813,7 @@ TEST_CASE("java parser finds usage of normal annotation member in initialization
TEST_CASE("java parser finds inheritance using extends keyword")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -831,7 +829,7 @@ TEST_CASE("java parser finds inheritance using extends keyword")
TEST_CASE("java parser finds inheritance using implements keyword")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -847,7 +845,7 @@ TEST_CASE("java parser finds inheritance using implements keyword")
TEST_CASE("java parser finds inheritance of anonymous class declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Base\n"
@@ -868,7 +866,7 @@ TEST_CASE("java parser finds inheritance of anonymous class declaration")
TEST_CASE("java parser finds usage of string for var type")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public void foo(){\n"
@@ -882,7 +880,7 @@ TEST_CASE("java parser finds usage of string for var type")
TEST_CASE("java parser finds type parameter in signature of method")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A <T>\n"
"{\n"
" public A<Void> foo(A<Void> a){\n"
@@ -898,7 +896,7 @@ TEST_CASE("java parser finds type parameter in signature of method")
TEST_CASE("parser finds usage of type defined in base class")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class Foo {\n"
" public class Base {\n"
" public class X {\n"
@@ -915,7 +913,7 @@ TEST_CASE("parser finds usage of type defined in base class")
TEST_CASE("java parser finds correct location of qualified type usage")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public class B\n"
@@ -933,7 +931,7 @@ TEST_CASE("java parser finds correct location of qualified type usage")
TEST_CASE("java parser finds type argument of parameterized type")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A <T> {\n"
" T t;\n"
"}\n"
@@ -952,7 +950,7 @@ TEST_CASE("java parser finds type argument of parameterized type")
TEST_CASE("java parser finds type argument of method invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -973,7 +971,7 @@ TEST_CASE("java parser finds type argument of method invocation")
TEST_CASE("java parser finds type argument of super method invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1002,7 +1000,7 @@ TEST_CASE("java parser finds type argument of super method invocation")
TEST_CASE("java parser finds type argument of constructor invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class Bar\n"
"{\n"
@@ -1025,7 +1023,7 @@ TEST_CASE("java parser finds type argument of constructor invocation")
TEST_CASE("java parser finds type argument of super constructor invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public class Base\n"
@@ -1050,7 +1048,7 @@ TEST_CASE("java parser finds type argument of super constructor invocation")
TEST_CASE("java parser finds type argument of creation reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1077,7 +1075,7 @@ TEST_CASE("java parser finds type argument of creation reference")
TEST_CASE("java parser finds type argument of expression method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1104,7 +1102,7 @@ TEST_CASE("java parser finds type argument of expression method reference")
TEST_CASE("java parser finds type argument of super method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -1131,7 +1129,7 @@ TEST_CASE("java parser finds type argument of super method reference")
TEST_CASE("java parser finds type argument of type method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" \n"
" void foo() {\n"
@@ -1147,7 +1145,7 @@ TEST_CASE("java parser finds type argument of type method reference")
TEST_CASE("java parser finds type argument of class instance creation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -1171,7 +1169,7 @@ TEST_CASE("java parser finds type argument of class instance creation")
TEST_CASE("java parser finds super method invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1197,7 +1195,7 @@ TEST_CASE("java parser finds super method invocation")
TEST_CASE("java parser finds constructor invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class Bar\n"
"{\n"
@@ -1217,7 +1215,7 @@ TEST_CASE("java parser finds constructor invocation")
TEST_CASE("java parser finds super constructor invocation")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public class Base\n"
@@ -1239,7 +1237,7 @@ TEST_CASE("java parser finds super constructor invocation")
TEST_CASE("java parser finds invocation of method of anonymous class")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"class Main {\n"
" public interface Interfaze {\n"
" public void foo();\n"
@@ -1263,7 +1261,7 @@ TEST_CASE("java parser finds invocation of method of anonymous class")
TEST_CASE("java parser finds overridden method with same signature")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"class Main {\n"
" public interface Interfaze {\n"
" public void foo(int t);\n"
@@ -1281,7 +1279,7 @@ TEST_CASE("java parser finds overridden method with same signature")
TEST_CASE("java parser finds overridden method with generic signature")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"class Main <X> {\n"
" public interface Interfaze <T> {\n"
" public void foo(T t);\n"
@@ -1301,7 +1299,7 @@ TEST_CASE("java parser finds overridden method with generic signature")
TEST_CASE("java parser finds method usage for creation reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1325,7 +1323,7 @@ TEST_CASE("java parser finds method usage for creation reference")
TEST_CASE("java parser finds method usage for expression method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1352,7 +1350,7 @@ TEST_CASE("java parser finds method usage for expression method reference")
TEST_CASE("java parser finds method usage for super method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -1376,7 +1374,7 @@ TEST_CASE("java parser finds method usage for super method reference")
TEST_CASE("java parser finds no method usage for type method reference")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A {\n"
" void foo() {\n"
" Functor method = int []::clone;\n"
@@ -1389,7 +1387,7 @@ TEST_CASE("java parser finds no method usage for type method reference")
TEST_CASE("java parser finds no usage of field within that fields declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1401,7 +1399,7 @@ TEST_CASE("java parser finds no usage of field within that fields declaration")
TEST_CASE("java parser finds no usage of enum constant within that enum constants declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public enum X\n"
"{\n"
@@ -1413,7 +1411,7 @@ TEST_CASE("java parser finds no usage of enum constant within that enum constant
TEST_CASE("java parser finds usage of field with same name as method parameter")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1430,7 +1428,7 @@ TEST_CASE("java parser finds usage of field with same name as method parameter")
TEST_CASE("java parser does not confuse method name with field name")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1447,7 +1445,7 @@ TEST_CASE("java parser does not confuse method name with field name")
TEST_CASE("java parser finds assignment of method parameter")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -1462,7 +1460,7 @@ TEST_CASE("java parser finds assignment of method parameter")
TEST_CASE("java parser finds assignment of local variable")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -1478,7 +1476,7 @@ TEST_CASE("java parser finds assignment of local variable")
TEST_CASE("java parser finds scope of class declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
"}\n");
@@ -1491,7 +1489,7 @@ TEST_CASE("java parser finds scope of class declaration")
TEST_CASE("java parser finds scope of enum declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public enum A\n"
"{\n"
"}\n");
@@ -1504,7 +1502,7 @@ TEST_CASE("java parser finds scope of enum declaration")
TEST_CASE("java parser finds scope of constructor declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public A()\n"
@@ -1520,7 +1518,7 @@ TEST_CASE("java parser finds scope of constructor declaration")
TEST_CASE("java parser finds scope of method declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public void a()\n"
@@ -1536,7 +1534,7 @@ TEST_CASE("java parser finds scope of method declaration")
TEST_CASE("java parser finds scope of switch statement")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public void a()\n"
@@ -1557,7 +1555,7 @@ TEST_CASE("java parser finds scope of switch statement")
TEST_CASE("java parser finds scope of block statement")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public void a()\n"
@@ -1575,7 +1573,7 @@ TEST_CASE("java parser finds scope of block statement")
TEST_CASE("java parser finds scope of array initialization list")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" private int[] array = {1, 2};\n"
@@ -1589,7 +1587,7 @@ TEST_CASE("java parser finds scope of array initialization list")
TEST_CASE("java parser finds scope of anonymous class declaration")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Base\n"
@@ -1612,7 +1610,7 @@ TEST_CASE("java parser finds scope of anonymous class declaration")
TEST_CASE("java parser finds usage of type parameter of class")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A <T>\n"
"{\n"
" T t;\n"
@@ -1624,7 +1622,7 @@ TEST_CASE("java parser finds usage of type parameter of class")
TEST_CASE("java parser finds usage of type parameter of method")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A\n"
"{\n"
" public <T> void foo(T t){};\n"
@@ -1636,7 +1634,7 @@ TEST_CASE("java parser finds usage of type parameter of method")
TEST_CASE("java parser finds correct location of generic type usage")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A <T>\n"
"{\n"
" A<Void> t;\n"
@@ -1648,7 +1646,7 @@ TEST_CASE("java parser finds correct location of generic type usage")
TEST_CASE("java parser finds bound type of type parameter")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"public class A <T extends Void>\n"
"{\n"
"}\n");
@@ -1659,7 +1657,7 @@ TEST_CASE("java parser finds bound type of type parameter")
TEST_CASE("java parsersupports java 12 switch expression")
{
std::shared_ptr<TestIntermediateStorage> client = parseCode(
std::shared_ptr<TestStorage> client = parseCode(
"package foo;\n"
"\n"
"public class Foo {\n"
@@ -1677,7 +1675,8 @@ TEST_CASE("java parsersupports java 12 switch expression")
" }\n"
"}\n");
REQUIRE(utility::containsElement<std::wstring>(client->usages, L"void foo.Foo.foo() -> foo.Foo.FruitType.PEAR <12:9 12:12>"));
REQUIRE(utility::containsElement<std::wstring>(
client->usages, L"void foo.Foo.foo() -> foo.Foo.FruitType.PEAR <12:9 12:12>"));
}
+122
View File
@@ -0,0 +1,122 @@
#include "catch.hpp"
#include "language_packages.h"
#if BUILD_PYTHON_LANGUAGE_PACKAGE
# include <memory>
# include <fstream>
# include "FileSystem.h"
# include "IndexerCommandCustom.h"
# include "PersistentStorage.h"
# include "ResourcePaths.h"
# include "SqliteIndexStorage.h"
# include "TaskExecuteCustomCommands.h"
# include "TestStorage.h"
# include "utilityApp.h"
namespace
{
void deleteAllContents(const FilePath& tempPath)
{
if (tempPath.recheckExists())
{
for (const FilePath& path: FileSystem::getFilePathsFromDirectory(tempPath))
{
FileSystem::remove(path);
}
}
}
std::shared_ptr<TestStorage> parseCode(std::string code)
{
const FilePath rootPath = FilePath(L"data/PythonIndexerTestSuite/temp/").makeAbsolute();
if (!rootPath.exists())
{
FileSystem::createDirectory(rootPath);
}
deleteAllContents(rootPath);
const FilePath sourceFilePath = rootPath.getConcatenated(L"test.py");
const FilePath tempDbPath = rootPath.getConcatenated(L"temp.srctrldb");
{
std::ofstream codeFile;
codeFile.open(sourceFilePath.str());
codeFile << code;
codeFile.close();
}
{
const std::set<FilePath> indexedPaths = {rootPath};
const std::set<FilePathFilter> excludeFilters;
const std::set<FilePathFilter> includeFilters;
const FilePath workingDirectory(L".");
std::wstring args = L"";
args += L" --source-file-path=%{SOURCE_FILE_PATH}";
args += L" --database-file-path=%{DATABASE_FILE_PATH}";
args += L" --shallow";
std::shared_ptr<IndexerCommandCustom> indexerCommand = std::make_shared<IndexerCommandCustom>(
INDEXER_COMMAND_PYTHON,
L"\"" +
FilePath("../app").getConcatenated(ResourcePaths::getPythonPath()).makeAbsolute().wstr() +
L"SourcetrailPythonIndexer\" index" + args,
rootPath,
tempDbPath,
std::to_wstring(SqliteIndexStorage::getStorageVersion()),
sourceFilePath,
true);
std::wstring errorMessage;
const int result = utility::executeProcessAndGetExitCode(
indexerCommand->getCustomCommand(), {}, rootPath, -1, true, &errorMessage);
REQUIRE(result == 0);
REQUIRE(errorMessage.empty());
}
std::shared_ptr<TestStorage> testStorage;
{
std::shared_ptr<PersistentStorage> persistentStorage = std::make_shared<PersistentStorage>(
tempDbPath, FilePath());
persistentStorage->setup();
persistentStorage->buildCaches();
TaskExecuteCustomCommands::runPythonPostProcessing(*(persistentStorage.get()));
testStorage = TestStorage::create(persistentStorage);
}
deleteAllContents(rootPath);
return testStorage;
}
} // namespace
TEST_CASE("python post processing regards class name in call context when adding ambiguous edges")
{
std::shared_ptr<TestStorage> storage = parseCode(
"class A:\n"
" def init(self):\n"
" pass\n"
"\n"
"class A1(A):\n"
" def init(self):\n"
" A.init()\n"
"\n"
"class B:\n"
" def init(self):\n"
" pass\n");
REQUIRE(storage->calls.size() == 1);
REQUIRE(utility::containsElement<std::wstring>(storage->calls, L"test.A1.init -> test.A.init"));
REQUIRE(
!utility::containsElement<std::wstring>(storage->calls, L"test.A1.init -> test.A1.init"));
REQUIRE(!utility::containsElement<std::wstring>(storage->calls, L"test.A1.init -> test.B.init"));
}
#endif // BUILD_PYTHON_LANGUAGE_PACKAGE
@@ -1,41 +1,43 @@
#ifndef TEST_INTERMEDIATE_STORAGE_H
#define TEST_INTERMEDIATE_STORAGE_H
#ifndef TEST_STORAGE_H
#define TEST_STORAGE_H
#include <boost/filesystem.hpp>
#include "AccessKind.h"
#include "Edge.h"
#include "FilePath.h"
#include "IntermediateStorage.h"
#include "LocationType.h"
#include "NameHierarchy.h"
#include "NodeType.h"
#include "Storage.h"
#include "utilityString.h"
class TestIntermediateStorage: public IntermediateStorage
class TestStorage
{
public:
void generateStringLists()
static std::shared_ptr<TestStorage> create(std::shared_ptr<const Storage> storage)
{
std::shared_ptr<TestStorage> testStorage = std::make_shared<TestStorage>();
std::map<Id, FilePath> filePathMap;
for (const StorageFile& file: getStorageFiles())
for (const StorageFile& file: storage->getStorageFiles())
{
filePathMap.emplace(file.id, FilePath(file.filePath));
files.emplace(file.filePath);
testStorage->files.emplace(file.filePath);
addLine(
testStorage->addLine(
L"FILE: " + FilePath(file.filePath).fileName() +
(file.indexed ? L"" : L" non-indexed"));
}
std::map<Id, StorageComponentAccess> accessMap;
for (const StorageComponentAccess& access: getComponentAccesses())
for (const StorageComponentAccess& access: storage->getComponentAccesses())
{
accessMap.emplace(access.nodeId, access);
}
std::multimap<Id, Id> occurrenceMap;
for (const StorageOccurrence& occurence: getStorageOccurrences())
for (const StorageOccurrence& occurence: storage->getStorageOccurrences())
{
occurrenceMap.emplace(occurence.sourceLocationId, occurence.elementId);
}
@@ -47,7 +49,7 @@ public:
std::multimap<Id, StorageSourceLocation> qualifierLocationMap;
std::multimap<Id, StorageSourceLocation> errorLocationMap;
std::vector<StorageSourceLocation> commentLocations;
for (const StorageSourceLocation& location: getStorageSourceLocations())
for (const StorageSourceLocation& location: storage->getStorageSourceLocations())
{
std::vector<Id> elementIds;
for (auto it = occurrenceMap.find(location.id);
@@ -113,7 +115,7 @@ public:
std::map<Id, StorageNode> nodesMap;
std::set<Id> fileIdMap;
for (const StorageNode& node: getStorageNodes())
for (const StorageNode& node: storage->getStorageNodes())
{
nodesMap.emplace(node.id, node);
@@ -131,13 +133,13 @@ public:
qualifierLocationIt++)
{
std::wstring locStr = addLocationStr(L"", qualifierLocationIt->second);
qualifiers.emplace_back(nameStr + locStr);
addLine(
testStorage->qualifiers.emplace_back(nameStr + locStr);
testStorage->addLine(
L"QUALIFIER: " + nameStr +
addFileName(locStr, filePathMap[qualifierLocationIt->second.fileNodeId]));
}
std::vector<std::wstring>* bin = getBinForNodeType(node.type);
std::vector<std::wstring>* bin = testStorage->getBinForNodeType(node.type);
if (bin != nullptr)
{
auto accessIt = accessMap.find(node.id);
@@ -176,7 +178,7 @@ public:
std::wstring locStr = addLocationStr(
locationStr, scopeLocationIt->second);
bin->emplace_back(nameStr + locStr);
addLine(
testStorage->addLine(
nodeTypeToString(node.type) + L": " + nameStr +
addFileName(locStr, filePathMap[tokenLocationIt->second.fileNodeId]));
added = true;
@@ -186,7 +188,7 @@ public:
if (!added)
{
bin->emplace_back(nameStr + locationStr);
addLine(
testStorage->addLine(
nodeTypeToString(node.type) + L": " + nameStr +
addFileName(locationStr, filePathMap[tokenLocationIt->second.fileNodeId]));
added = true;
@@ -196,12 +198,12 @@ public:
if (!added)
{
bin->emplace_back(nameStr);
addLine(nodeTypeToString(node.type) + L": " + nameStr);
testStorage->addLine(nodeTypeToString(node.type) + L": " + nameStr);
}
}
}
for (const StorageEdge& edge: getStorageEdges())
for (const StorageEdge& edge: storage->getStorageEdges())
{
auto targetIt = nodesMap.find(edge.targetNodeId);
if (targetIt == nodesMap.end())
@@ -218,19 +220,21 @@ public:
const StorageNode& target = targetIt->second;
const StorageNode& source = sourceIt->second;
std::vector<std::wstring>* bin = getBinForEdgeType(edge.type);
std::vector<std::wstring>* bin = testStorage->getBinForEdgeType(edge.type);
if (bin != nullptr)
{
std::wstring sourceName =
NameHierarchy::deserialize(source.serializedName).getQualifiedNameWithSignature();
if (fileIdMap.find(edge.sourceNodeId) != fileIdMap.end() && FilePath(sourceName).exists())
if (fileIdMap.find(edge.sourceNodeId) != fileIdMap.end() &&
FilePath(sourceName).exists())
{
sourceName = FilePath(sourceName).fileName();
}
std::wstring targetName =
NameHierarchy::deserialize(target.serializedName).getQualifiedNameWithSignature();
if (fileIdMap.find(edge.targetNodeId) != fileIdMap.end() && FilePath(targetName).exists())
if (fileIdMap.find(edge.targetNodeId) != fileIdMap.end() &&
FilePath(targetName).exists())
{
targetName = FilePath(targetName).fileName();
}
@@ -244,7 +248,7 @@ public:
{
std::wstring locStr = addLocationStr(L"", tokenLocationIt->second);
bin->emplace_back(nameStr + locStr);
addLine(
testStorage->addLine(
edgeTypeToString(edge.type) + L": " + nameStr +
addFileName(locStr, filePathMap[tokenLocationIt->second.fileNodeId]));
added = true;
@@ -253,12 +257,12 @@ public:
if (!added)
{
bin->emplace_back(nameStr);
addLine(edgeTypeToString(edge.type) + L": " + nameStr);
testStorage->addLine(edgeTypeToString(edge.type) + L": " + nameStr);
}
}
}
for (const StorageLocalSymbol& localSymbol: getStorageLocalSymbols())
for (const StorageLocalSymbol& localSymbol: storage->getStorageLocalSymbols())
{
bool added = false;
for (auto localSymbolLocationIt = localSymbolLocationMap.find(localSymbol.id);
@@ -267,8 +271,8 @@ public:
localSymbolLocationIt++)
{
std::wstring locStr = addLocationStr(L"", localSymbolLocationIt->second);
localSymbols.emplace_back(localSymbol.name + locStr);
addLine(
testStorage->localSymbols.emplace_back(localSymbol.name + locStr);
testStorage->addLine(
L"LOCAL_SYMBOL: " + localSymbol.name +
addFileName(locStr, filePathMap[localSymbolLocationIt->second.fileNodeId]));
added = true;
@@ -276,31 +280,33 @@ public:
if (!added)
{
localSymbols.emplace_back(localSymbol.name);
addLine(L"LOCAL_SYMBOL: " + localSymbol.name);
testStorage->localSymbols.emplace_back(localSymbol.name);
testStorage->addLine(L"LOCAL_SYMBOL: " + localSymbol.name);
}
}
for (const StorageSourceLocation& location: commentLocations)
{
std::wstring locStr = addLocationStr(L"", location);
comments.emplace_back(L"comment" + locStr);
addLine(L"COMMENT: comment" + addFileName(locStr, filePathMap[location.fileNodeId]));
testStorage->comments.emplace_back(L"comment" + locStr);
testStorage->addLine(
L"COMMENT: comment" + addFileName(locStr, filePathMap[location.fileNodeId]));
}
for (const StorageError& error: getErrors())
for (const StorageError& error: storage->getErrors())
{
for (auto errorLocationIt = errorLocationMap.find(error.id);
errorLocationIt != errorLocationMap.end() && errorLocationIt->first == error.id;
errorLocationIt++)
{
std::wstring locStr = addLocationStr(L"", errorLocationIt->second);
errors.emplace_back(error.message + locStr);
addLine(
testStorage->errors.emplace_back(error.message + locStr);
testStorage->addLine(
L"ERROR: " + error.message +
addFileName(locStr, filePathMap[errorLocationIt->second.fileNodeId]));
}
}
return testStorage;
}
std::vector<std::wstring> errors;
@@ -343,7 +349,7 @@ public:
std::vector<std::string> m_lines;
private:
std::wstring nodeTypeToString(int nodeType) const
static std::wstring nodeTypeToString(int nodeType)
{
switch (intToNodeKind(nodeType))
{
@@ -387,7 +393,7 @@ private:
return L"SYMBOL_NON_INDEXED";
}
std::wstring edgeTypeToString(int edgeType) const
static std::wstring edgeTypeToString(int edgeType)
{
switch (Edge::intToType(edgeType))
{
@@ -497,19 +503,19 @@ private:
return nullptr;
}
std::wstring addLocationStr(const std::wstring& locationStr, const StorageSourceLocation& loc) const
static std::wstring addLocationStr(const std::wstring& locationStr, const StorageSourceLocation& loc)
{
return L" <" + std::to_wstring(loc.startLine) + L':' + std::to_wstring(loc.startCol) +
locationStr + L' ' + std::to_wstring(loc.endLine) + L':' + std::to_wstring(loc.endCol) +
L'>';
}
std::wstring addFileName(const std::wstring& locationStr, const FilePath& filePath) const
static std::wstring addFileName(const std::wstring& locationStr, const FilePath& filePath)
{
return L" [" + filePath.fileName() + locationStr + L']';
}
bool containsLocation(const StorageSourceLocation& out, const StorageSourceLocation& in) const
static bool containsLocation(const StorageSourceLocation& out, const StorageSourceLocation& in)
{
if (out.startLine > in.startLine)
{
@@ -540,4 +546,4 @@ private:
}
};
#endif // TEST_INTERMEDIATE_STORAGE_H
#endif // TEST_STORAGE_H