logic: changed Java type_argument edges to originate in the generic type or method

* added tests for java type argument recording
* implemented recording type arguments for java ExpressionMethodReferences
* changed type_argument edge to originate in generic type
* added type_usage edge for type_arguments that originates in context (e.g. calling method)
This commit is contained in:
mlangkabel
2018-08-20 16:27:53 +02:00
parent 14a8d024b9
commit 36a9d552da
104 changed files with 2136 additions and 893 deletions
+268 -1
View File
@@ -793,7 +793,7 @@ public:
"\n"
" public class B {\n"
" void bar() {\n"
" B b = new A.B();"
" B b = new A.B();\n"
" }\n"
" }\n"
"}\n"
@@ -1018,6 +1018,273 @@ public:
));
}
void test_java_parser_finds_type_argument_of_parameterized_type()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A <T> {\n"
" T t;\n"
"}\n"
"public class B {\n"
" void foo() {\n"
" A<Void> a = null;\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"A<T> -> java.lang.Void <6:5 6:8>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void B.foo() -> java.lang.Void <6:5 6:8>"
));
}
void test_java_parser_finds_type_argument_of_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
" public static void foo() {\n"
" }\n"
"\n"
" public static void bar() {\n"
" foo.X.<Void>foo();\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"static void foo.X.foo() -> java.lang.Void <8:10 8:13>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"static void foo.X.bar() -> java.lang.Void <8:10 8:13>"
));
}
void test_java_parser_finds_type_argument_of_super_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
" public class A\n"
" {\n"
" void bar()\n"
" {\n"
" }\n"
" }\n"
" \n"
" public class B extends A\n"
" {\n"
" void bar()\n"
" {\n"
" super.<Void>bar();\n"
" }\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"void foo.X.A.bar() -> java.lang.Void <15:11 15:14>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void foo.X.B.bar() -> java.lang.Void <15:11 15:14>"
));
}
void test_java_parser_finds_type_argument_of_constructor_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
"package foo;\n"
"public class Bar\n"
"{\n"
" public Bar()\n"
" {\n"
" }\n"
" \n"
" public Bar(int i)\n"
" {\n"
" <Void>this();\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"foo.Bar.Bar() -> java.lang.Void <10:4 10:7>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"foo.Bar.Bar(int) -> java.lang.Void <10:4 10:7>"
));
}
void test_java_parser_finds_type_argument_of_super_constructor_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A\n"
"{\n"
" public class Base\n"
" {\n"
" }\n"
"\n"
" public class Derived extends Base\n"
" {\n"
" public Derived()\n"
" {\n"
" <Void>super();\n"
" }\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"A.Base.Base() -> java.lang.Void <11:5 11:8>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"A.Derived.Derived() -> java.lang.Void <11:5 11:8>"
));
}
void test_java_parser_finds_type_argument_of_creation_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
" {\n"
" public void doSomething();\n"
" }\n"
"\n"
" public class B\n"
" {\n"
" }\n"
"\n"
" void foo()\n"
" {\n"
" Functor method = B::<Void>new;\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"A.B.B() -> java.lang.Void <14:24 14:27>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void A.foo() -> java.lang.Void <14:24 14:27>"
));
}
void test_java_parser_finds_type_argument_of_expression_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
" {\n"
" public void doSomething();\n"
" }\n"
"\n"
" static void bar()\n"
" {\n"
" }\n"
"\n"
" void foo()\n"
" {\n"
" Functor method = A::<Void>bar;\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"static void A.bar() -> java.lang.Void <14:24 14:27>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void A.foo() -> java.lang.Void <14:24 14:27>"
));
}
void test_java_parser_finds_type_argument_of_super_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
" }\n"
"\n"
" public class B {\n"
" <T> void bar() {\n"
" }\n"
" }\n"
"\n"
" public class C extends B {\n"
" void foo() {\n"
" Functor method = super::<Void>bar;\n"
" }\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"void A.B.bar<T>() -> java.lang.Void <13:29 13:32>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void A.C.foo() -> java.lang.Void <13:29 13:32>"
));
}
void test_java_parser_finds_type_argument_of_type_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A {\n"
" \n"
" void foo() {\n"
" Functor method = int []::<Void>clone;\n"
" }\n"
"}\n"
);
// currently we cannot record the typeArguments of array type methods
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void A.foo() -> java.lang.Void <4:29 4:32>"
));
}
void test_java_parser_finds_type_argument_of_class_instance_creation()
{
std::shared_ptr<TestParserClient> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
" }\n"
"\n"
" public class B {\n"
" <T> B() {\n"
" }\n"
" void bar() {\n"
" B b = new <Void>A.B();\n"
" }\n"
" }\n"
"}\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeArguments, L"A.B.B<T>() -> java.lang.Void <10:15 10:18>"
));
TS_ASSERT(utility::containsElement<std::wstring>(
client->typeUses, L"void A.B.bar() -> java.lang.Void <10:15 10:18>"
));
}
void test_java_parser_finds_super_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(